Skip to content

Commit 04d01bd

Browse files
committed
Ability to enter exact font size numerically
Address #305
1 parent 09c162a commit 04d01bd

File tree

3 files changed

+82
-38
lines changed

3 files changed

+82
-38
lines changed

src/kirigami_ui/EditorToolbar.qml

Lines changed: 77 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,15 @@ ToolBar {
865865
}
866866
}
867867
RowLayout {
868+
visible: height>0
869+
height: (parseInt(viewport.prompter.state)===Prompter.States.Editing) ? implicitHeight : 0
870+
clip: true
868871
ToolButton {
872+
enabled: !fontSizeDirectInput.editText
869873
text: "\uF088"
870874
//visible: showSliderIcons
871875
checkable: true
872-
checked: !viewport.prompter.__wysiwyg
876+
checked: !viewport.prompter.wysiwyg
873877
onClicked: {
874878
viewport.prompter.toggleWysiwyg()
875879
paragraphSpacingSlider.update()
@@ -878,47 +882,87 @@ ToolBar {
878882
font.family: iconFont.name
879883
font.pointSize: 13
880884
}
881-
RowLayout {
882-
visible: height>0
883-
height: (parseInt(viewport.prompter.state)===Prompter.States.Editing) ? implicitHeight : 0
884-
clip: true
885-
Label {
886-
visible: !viewport.prompter.__wysiwyg
887-
text: i18nc("Font size 100% (083)", "Font size <pre>%1% (%2)</pre>", (fontSizeSlider.value/1000).toFixed(3).slice(2), viewport.prompter.fontSize)
888-
color: Kirigami.Theme.textColor
889-
Layout.topMargin: 4
890-
Layout.bottomMargin: -14
891-
Layout.rightMargin: 3
892-
Layout.leftMargin: 1
885+
MouseArea {
886+
id: fontSizeDirectInput
887+
property bool editText: false
888+
height: fontSizeLabel.height
889+
width: fontSizeDirectInput.editText ? fontSizeTextField.width : fontSizeLabel.width
890+
onDoubleClicked: {
891+
fontSizeDirectInput.editText = true;
892+
}
893+
function percentageFromFontSize(fontSize: double): double {
894+
if (viewport.prompter.wysiwyg)
895+
// Inverse of: fontSize = (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185)*prompter.__vw/10
896+
return Math.pow((fontSize * 10 / prompter.__vw) / 185, 1/4) * 185
897+
else
898+
// Inverse of: fontSize = (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185)
899+
return Math.pow(fontSize / 185, 1/4) * 185
893900
}
894-
Slider {
895-
id: fontSizeSlider
896-
visible: !viewport.prompter.__wysiwyg
897-
focusPolicy: Qt.TabFocus
898-
from: 90
899-
value: 100
900-
to: 158
901-
stepSize: 1
902-
onMoved: paragraphSpacingSlider.update()
901+
TextField {
902+
id: fontSizeTextField
903+
anchors.fill: parent
904+
visible: fontSizeDirectInput.editText
905+
readOnly: !visible
906+
text: ""
907+
onVisibleChanged: {
908+
if (visible)
909+
text = viewport.prompter.fontSize;
910+
}
911+
onAccepted: {
912+
const value = fontSizeDirectInput.percentageFromFontSize(text);
913+
if (value > 0) {
914+
if (viewport.prompter.wysiwyg)
915+
fontWYSIWYGSizeSlider.value = value;
916+
else
917+
fontSizeSlider.value = value;
918+
}
919+
}
920+
onEditingFinished: {
921+
fontSizeDirectInput.editText = false;
922+
}
923+
Material.theme: Material.Dark
903924
}
904925
Label {
905-
visible: viewport.prompter.__wysiwyg
906-
text: i18nc("Font size 100% (083)", "Font size <pre>%1% (%2)</pre>", (fontWYSIWYGSizeSlider.value/1440).toFixed(3).slice(2), (viewport.prompter.fontSize/1000).toFixed(3).slice(2))
926+
id: fontSizeLabel
927+
visible: !fontSizeDirectInput.editText
928+
text: viewport.prompter.wysiwyg ?
929+
i18nc("Font size 100% (083)", "Font size <pre>%1% (%2)</pre>", (fontWYSIWYGSizeSlider.value/1440).toFixed(3).slice(2), (viewport.prompter.fontSize/1000).toFixed(3).slice(2))
930+
: i18nc("Font size 100% (083)", "Font size <pre>%1% (%2)</pre>", (fontSizeSlider.value/1000).toFixed(3).slice(2), viewport.prompter.fontSize)
907931
color: Kirigami.Theme.textColor
908932
Layout.topMargin: 4
909933
Layout.bottomMargin: -14
910934
Layout.rightMargin: 3
911935
Layout.leftMargin: 1
912936
}
913-
Slider {
914-
id: fontWYSIWYGSizeSlider
915-
visible: viewport.prompter.__wysiwyg
916-
from: 90
917-
value: 144
918-
to: 180 // 200
919-
stepSize: 0.5
920-
focusPolicy: Qt.TabFocus
921-
onMoved: paragraphSpacingSlider.update()
937+
}
938+
Slider {
939+
id: fontSizeSlider
940+
visible: !viewport.prompter.wysiwyg
941+
focusPolicy: Qt.TabFocus
942+
from: 90
943+
value: 100
944+
to: 158
945+
stepSize: 1
946+
onMoved: {
947+
if (visible) {
948+
paragraphSpacingSlider.update();
949+
fontSizeDirectInput.editText = false;
950+
}
951+
}
952+
}
953+
Slider {
954+
id: fontWYSIWYGSizeSlider
955+
visible: viewport.prompter.wysiwyg
956+
from: 90
957+
value: 144
958+
to: 180 // 200
959+
stepSize: 0.5
960+
focusPolicy: Qt.TabFocus
961+
onMoved: {
962+
if (visible) {
963+
paragraphSpacingSlider.update();
964+
fontSizeDirectInput.editText = false;
965+
}
922966
}
923967
}
924968
}

src/prompter/Prompter.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Flickable {
151151
property bool __invertArrowKeys: root.__invertArrowKeys
152152
property bool __invertScrollDirection: root.__invertScrollDirection
153153
property bool __noScroll: root.__noScroll
154-
property bool __wysiwyg: true
154+
property bool wysiwyg: true
155155
property bool __play: true
156156
property int __i: __iDefault
157157
property int __iBackup: 0
@@ -449,7 +449,7 @@ Flickable {
449449
const lastPosition = editor.cursorPosition;
450450

451451
// If leaving WYSIWYG mode or cursor is fully out of the viewport visible bounds,
452-
if (viewport.prompter.__wysiwyg
452+
if (viewport.prompter.wysiwyg
453453
|| lastPosition > editor.positionAt(editor.width, prompter.position+overlay.height-editor.cursorRectangle.height+editor.cursorRectangle.height)
454454
|| lastPosition < editor.positionAt(0, prompter.position)) {
455455
// use reading region to place cursor.
@@ -460,7 +460,7 @@ Flickable {
460460
//console.log("\n\nPos:", p0_lineStart, lastPosition, p0_lineStart<lastPosition, "\n");
461461

462462
// Resize text
463-
viewport.prompter.__wysiwyg = !viewport.prompter.__wysiwyg;
463+
viewport.prompter.wysiwyg = !viewport.prompter.wysiwyg;
464464

465465
if (p0_lineStart <= lastPosition) {
466466
//console.log(1, "test last");

src/prompter/PrompterView.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ Item {
107107
z: 1
108108
textColor: colorDialog.color
109109
textBackground: highlightDialog.color
110-
fontSize: (parseInt(prompter.state)===Prompter.States.Editing && !prompter.__wysiwyg) ? (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185) : (Math.pow(editorToolbar.fontWYSIWYGSizeSlider.value/185,4)*185)*prompter.__vw/10
111-
// fontSize: (!prompter.__wysiwyg) ? (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185) : (Math.pow(editorToolbar.fontWYSIWYGSizeSlider.value/185,4)*185)*prompter.__vw/10
110+
fontSize: (parseInt(prompter.state)===Prompter.States.Editing && !prompter.wysiwyg) ? (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185) : (Math.pow(editorToolbar.fontWYSIWYGSizeSlider.value/185,4)*185)*prompter.__vw/10
111+
// fontSize: (parseInt(prompter.state)===Prompter.States.Editing && !prompter.wysiwyg) ? (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185) : (Math.pow(editorToolbar.fontWYSIWYGSizeSlider.value/185,4)*185)*prompter.__vw/10
112112
letterSpacing: fontSize * editorToolbar.letterSpacingSlider.value / 81
113113
wordSpacing: fontSize * editorToolbar.wordSpacingSlider.value / 81
114114
//Math.pow((fontSizeSlider.value*prompter.__vw),3)

0 commit comments

Comments
 (0)