Facilitate creation of OrgText based Items

This commit is contained in:
Renaud Casenave-Péré 2022-12-07 23:04:49 +01:00
parent 6544071718
commit d595cbe273
6 changed files with 70 additions and 45 deletions

View file

@ -13,8 +13,9 @@
(define-roles #.|Qt.UserRole|
+nodetype-role+
+content-role+
+depth-role+)
+rawtext-role+
+depth-role+
+title-role+)
(defvar *current-pathname* nil)
@ -91,15 +92,18 @@
(#.+nodetype-role+
(qvariant-from-value (string-downcase (symbol-name (type-of item)))
"QString"))
(#.+content-role+
(#.+rawtext-role+
(qvariant-from-value (raw-text-of item) "QString"))
(#.+depth-role+
(qvariant-from-value (depth-of item) "int"))))))))
(qvariant-from-value (depth-of item) "int"))
(#.+title-role+
(qvariant-from-value (title-of item) "QString"))))))))
(qoverride model "roleNames()"
(lambda ()
(list (cons +nodetype-role+ "nodeType")
(cons +content-role+ "content")
(cons +depth-role+ "depth"))))
(cons +rawtext-role+ "rawtext")
(cons +depth-role+ "depth")
(cons +title-role+ "title"))))
(when *org-model*
(qdelete *org-model*))
(setf *org-model* model)

View file

@ -6,11 +6,11 @@ TextArea {
id: orgEdit
property string sentinelChar: "" // there is an invisible char here
property string lastText: index >= 0 ? content : ""
property string lastText: index >= 0 ? rawtext : ""
property bool textModified: false
property int fixedCursorPosition: -1
text: index > 0 ? sentinelChar + content : (index == 0 ? content : "")
text: index > 0 ? sentinelChar + rawtext : (index == 0 ? rawtext : "")
anchors {
top: parent.top
@ -55,7 +55,7 @@ TextArea {
document.focusedIndex = index + 1
} else {
lastText = getText()
textModified = lastText != content
textModified = lastText != rawtext
undo.enabled = textModified || Lisp.call("models:can-undo-p")
redo.enabled = !textModified && Lisp.call("models:can-redo-p")
save.enabled = textModified || Lisp.call("models:can-save-p")

View file

@ -1,40 +1,47 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Item {
OrgText {
id: orgHeadline
height: label.visible ? label.contentHeight : edit.height
anchors {
left: parent.left
right: parent.right
}
contentHeight: titleLabel.contentHeight
editing: orgItem.focused
Label {
id: label
id: bullet
anchors {
top: parent.top
left: parent.left
right: parent.right
rightMargin: Theme.paddingSmall
leftMargin: Theme.paddingMedium * depth
}
font {
pixelSize: depth == 1 ? Theme.fontSizeExtraLarge : Theme.fontSizeLarge
pixelSize: Theme.fontSizeLarge
bold: true
family: Theme.fontFamilyHeading
}
visible: !orgItem.focused
text: edit.getText()
text: "*"
}
Label {
id: titleLabel
anchors {
top: parent.top
left: bullet.right
right: parent.right
leftMargin: Theme.paddingMedium
rightMargin: Theme.paddingSmall
}
font {
bold: true
family: Theme.fontFamilyHeading
}
visible: !orgItem.focused
text: title
wrapMode: Text.Wrap
}
OrgEdit {
id: edit
visible: !label.visible
}
function forceCommit () { edit.forceCommit() }
function setCursorPositionAt (x, y) { edit.setCursorPositionAt(x, y) }
function setCursorPositionAtEnd (fix) { edit.setCursorPositionAtEnd(fix) }
}

View file

@ -1,14 +1,11 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Item {
OrgText {
id: orgLine
height: label.visible ? label.contentHeight : edit.height
anchors {
left: parent.left
right: parent.right
}
contentHeight: label.contentHeight
editing: orgItem.focused
Label {
id: label
@ -20,16 +17,7 @@ Item {
}
visible: !orgItem.focused
text: edit.getText()
text: rawtext
wrapMode: Text.Wrap
}
OrgEdit {
id: edit
visible: !label.visible
}
function forceCommit () { edit.forceCommit() }
function setCursorPositionAt (x, y) { edit.setCursorPositionAt(x, y) }
function setCursorPositionAtEnd (fix) { edit.setCursorPositionAtEnd(fix) }
}

View file

@ -0,0 +1,25 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Item {
id: orgText
property int contentHeight
property bool editing: false
height: editing ? edit.height : contentHeight
anchors {
left: parent.left
right: parent.right
}
OrgEdit {
id: edit
visible: editing
}
function forceCommit () { edit.forceCommit() }
function setCursorPositionAt (x, y) { edit.setCursorPositionAt(x, y) }
function setCursorPositionAtEnd (fix) { edit.setCursorPositionAtEnd(fix) }
}

View file

@ -59,6 +59,7 @@ DISTFILES += qml/harbour-sextant.qml \
qml/components/ListTextField.qml \
qml/components/OrgDelegate.qml \
qml/components/OrgLine.qml \
qml/components/OrgText.qml \
qml/components/OrgEdit.qml \
qml/components/OverwriteDialog.qml \
qml/pages/FirstPage.qml \