Skip to content

Commit

Permalink
Ability to enter exact font size numerically
Browse files Browse the repository at this point in the history
Address #305
  • Loading branch information
Cuperino committed Nov 28, 2024
1 parent 07f4389 commit e28e084
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 38 deletions.
110 changes: 77 additions & 33 deletions src/kirigami_ui/EditorToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,15 @@ ToolBar {
}
}
RowLayout {
visible: height>0
height: (parseInt(viewport.prompter.state)===Prompter.States.Editing) ? implicitHeight : 0
clip: true
ToolButton {
enabled: !fontSizeDirectInput.editText
text: "\uF088"
//visible: showSliderIcons
checkable: true
checked: !viewport.prompter.__wysiwyg
checked: !viewport.prompter.wysiwyg
onClicked: {
viewport.prompter.toggleWysiwyg()
paragraphSpacingSlider.update()
Expand All @@ -878,47 +882,87 @@ ToolBar {
font.family: iconFont.name
font.pointSize: 13
}
RowLayout {
visible: height>0
height: (parseInt(viewport.prompter.state)===Prompter.States.Editing) ? implicitHeight : 0
clip: true
Label {
visible: !viewport.prompter.__wysiwyg
text: i18nc("Font size 100% (083)", "Font size <pre>%1% (%2)</pre>", (fontSizeSlider.value/1000).toFixed(3).slice(2), viewport.prompter.fontSize)
color: Kirigami.Theme.textColor
Layout.topMargin: 4
Layout.bottomMargin: -14
Layout.rightMargin: 3
Layout.leftMargin: 1
MouseArea {
id: fontSizeDirectInput
property bool editText: false
height: fontSizeLabel.height
width: fontSizeDirectInput.editText ? fontSizeTextField.width : fontSizeLabel.width
onDoubleClicked: {
fontSizeDirectInput.editText = true;
}
function percentageFromFontSize(fontSize: double): double {
if (viewport.prompter.wysiwyg)
// Inverse of: fontSize = (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185)*prompter.__vw/10
return Math.pow((fontSize * 10 / prompter.__vw) / 185, 1/4) * 185
else
// Inverse of: fontSize = (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185)
return Math.pow(fontSize / 185, 1/4) * 185
}
Slider {
id: fontSizeSlider
visible: !viewport.prompter.__wysiwyg
focusPolicy: Qt.TabFocus
from: 90
value: 100
to: 158
stepSize: 1
onMoved: paragraphSpacingSlider.update()
TextField {
id: fontSizeTextField
anchors.fill: parent
visible: fontSizeDirectInput.editText
readOnly: !visible
text: ""
onVisibleChanged: {
if (visible)
text = viewport.prompter.fontSize;
}
onAccepted: {
const value = fontSizeDirectInput.percentageFromFontSize(text);
if (value > 0) {
if (viewport.prompter.wysiwyg)
fontWYSIWYGSizeSlider.value = value;
else
fontSizeSlider.value = value;
}
}
onEditingFinished: {
fontSizeDirectInput.editText = false;
}
Material.theme: Material.Dark
}
Label {
visible: viewport.prompter.__wysiwyg
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))
id: fontSizeLabel
visible: !fontSizeDirectInput.editText
text: viewport.prompter.wysiwyg ?
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))
: i18nc("Font size 100% (083)", "Font size <pre>%1% (%2)</pre>", (fontSizeSlider.value/1000).toFixed(3).slice(2), viewport.prompter.fontSize)
color: Kirigami.Theme.textColor
Layout.topMargin: 4
Layout.bottomMargin: -14
Layout.rightMargin: 3
Layout.leftMargin: 1
}
Slider {
id: fontWYSIWYGSizeSlider
visible: viewport.prompter.__wysiwyg
from: 90
value: 144
to: 180 // 200
stepSize: 0.5
focusPolicy: Qt.TabFocus
onMoved: paragraphSpacingSlider.update()
}
Slider {
id: fontSizeSlider
visible: !viewport.prompter.wysiwyg
focusPolicy: Qt.TabFocus
from: 90
value: 100
to: 158
stepSize: 1
onMoved: {
if (visible) {
paragraphSpacingSlider.update();
fontSizeDirectInput.editText = false;
}
}
}
Slider {
id: fontWYSIWYGSizeSlider
visible: viewport.prompter.wysiwyg
from: 90
value: 144
to: 180 // 200
stepSize: 0.5
focusPolicy: Qt.TabFocus
onMoved: {
if (visible) {
paragraphSpacingSlider.update();
fontSizeDirectInput.editText = false;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/prompter/Prompter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Flickable {
property bool __invertArrowKeys: root.__invertArrowKeys
property bool __invertScrollDirection: root.__invertScrollDirection
property bool __noScroll: root.__noScroll
property bool __wysiwyg: true
property bool wysiwyg: true
property bool __play: true
property int __i: __iDefault
property int __iBackup: 0
Expand Down Expand Up @@ -449,7 +449,7 @@ Flickable {
const lastPosition = editor.cursorPosition;

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

// Resize text
viewport.prompter.__wysiwyg = !viewport.prompter.__wysiwyg;
viewport.prompter.wysiwyg = !viewport.prompter.wysiwyg;

if (p0_lineStart <= lastPosition) {
//console.log(1, "test last");
Expand Down
4 changes: 2 additions & 2 deletions src/prompter/PrompterView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ Item {
z: 1
textColor: colorDialog.color
textBackground: highlightDialog.color
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
// fontSize: (!prompter.__wysiwyg) ? (Math.pow(editorToolbar.fontSizeSlider.value/185,4)*185) : (Math.pow(editorToolbar.fontWYSIWYGSizeSlider.value/185,4)*185)*prompter.__vw/10
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
// 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
letterSpacing: fontSize * editorToolbar.letterSpacingSlider.value / 81
wordSpacing: fontSize * editorToolbar.wordSpacingSlider.value / 81
//Math.pow((fontSizeSlider.value*prompter.__vw),3)
Expand Down

0 comments on commit e28e084

Please sign in to comment.