Rename OrgText into OrgLine and separate OrgEdit
This commit is contained in:
parent
36e350f368
commit
a5bc9ba86b
5 changed files with 157 additions and 148 deletions
|
|
@ -19,7 +19,7 @@ ListItem {
|
|||
|
||||
source: {
|
||||
if (nodeType == "org-line")
|
||||
return "OrgText.qml";
|
||||
return "OrgLine.qml";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
118
qml/components/OrgEdit.qml
Normal file
118
qml/components/OrgEdit.qml
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
import EQL5 1.0
|
||||
|
||||
TextArea {
|
||||
id: orgEdit
|
||||
|
||||
property string sentinelChar: "" // there is an invisible char here
|
||||
property string lastText: index >= 0 ? content : ""
|
||||
property bool textModified: false
|
||||
property int fixedCursorPosition: -1
|
||||
property int contentHeight
|
||||
|
||||
text: index > 0 ? sentinelChar + content : (index == 0 ? content : "")
|
||||
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
height: contentHeight + _bottomMargin
|
||||
|
||||
textMargin: 0
|
||||
textTopMargin: 0
|
||||
wrapMode: Text.Wrap
|
||||
labelVisible: false
|
||||
inputMethodHints: Qt.ImhNoAutoUppercase
|
||||
|
||||
onCursorPositionChanged: {
|
||||
if (index > 0 && cursorPosition == 0)
|
||||
cursorPosition = 1
|
||||
}
|
||||
|
||||
onSelectionStartChanged: {
|
||||
if (index > 0 && selectionStart == 0)
|
||||
select(1, selectionEnd)
|
||||
}
|
||||
|
||||
onTextChanged: {
|
||||
if (visible) {
|
||||
if (fixedCursorPosition != -1) {
|
||||
cursorPosition = fixedCursorPosition
|
||||
fixedCursorPosition = -1
|
||||
}
|
||||
if (index >= 0) {
|
||||
if (index > 0 && text[0] != sentinelChar) {
|
||||
var textEmpty = text.length != 0
|
||||
forceCommit()
|
||||
document.focusedIndex = index - 1
|
||||
document.focusedItem.setCursorPositionAtEnd(textEmpty)
|
||||
Lisp.call("models:join-node", index - 1)
|
||||
} else {
|
||||
var split = text.indexOf("\n")
|
||||
if (split != -1) {
|
||||
forceCommit()
|
||||
Lisp.call("models:split-node", index, text.substring(index > 0 ? 1 : 0, split), text.substring(split + 1))
|
||||
document.focusedIndex = index + 1
|
||||
} else {
|
||||
lastText = getText()
|
||||
textModified = lastText != content
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onActiveFocusChanged: {
|
||||
if (!activeFocus) {
|
||||
forceCommit()
|
||||
|
||||
if (document.focusedIndex == index)
|
||||
document.focusedIndex = -1
|
||||
}
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
forceActiveFocus()
|
||||
if (index > 0 && cursorPosition == 0)
|
||||
cursorPosition = 1
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (visible) {
|
||||
forceActiveFocus()
|
||||
if (index > 0 && cursorPosition == 0)
|
||||
cursorPosition = 1
|
||||
}
|
||||
}
|
||||
|
||||
function getText () {
|
||||
return index > 0 ? text.substring(1) : text
|
||||
}
|
||||
|
||||
function forceCommit () {
|
||||
if (textModified) {
|
||||
Lisp.call("models:modify-text", index, lastText)
|
||||
textModified = false
|
||||
}
|
||||
}
|
||||
|
||||
function setCursorPositionAt(x, y) {
|
||||
cursorPosition = positionAt(x, y)
|
||||
}
|
||||
|
||||
function setCursorPositionAtEnd (fix) {
|
||||
if (fix) {
|
||||
fixedCursorPosition = text.length
|
||||
} else {
|
||||
cursorPosition = text.length
|
||||
}
|
||||
}
|
||||
}
|
||||
36
qml/components/OrgLine.qml
Normal file
36
qml/components/OrgLine.qml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
Item {
|
||||
id: orgLine
|
||||
height: label.visible ? label.contentHeight : edit.height
|
||||
anchors {
|
||||
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
Label {
|
||||
id: label
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
rightMargin: Theme.paddingSmall
|
||||
}
|
||||
|
||||
visible: !orgItem.focused
|
||||
text: edit.getText()
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
OrgEdit {
|
||||
id: edit
|
||||
contentHeight: label.contentHeight
|
||||
visible: !label.visible
|
||||
}
|
||||
|
||||
function forceCommit () { edit.forceCommit() }
|
||||
function setCursorPositionAt (x, y) { edit.setCursorPositionAt(x, y) }
|
||||
function setCursorPositionAtEnd (fix) { edit.setCursorPositionAtEnd(fix) }
|
||||
}
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
import EQL5 1.0
|
||||
|
||||
Item {
|
||||
id: orgText
|
||||
height: label.visible ? label.contentHeight : edit.height
|
||||
anchors {
|
||||
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
Label {
|
||||
id: label
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
rightMargin: Theme.paddingSmall
|
||||
}
|
||||
|
||||
visible: !orgItem.focused
|
||||
text: edit.getText()
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
TextArea {
|
||||
id: edit
|
||||
|
||||
property string sentinelChar: "" // there is an invisible char here
|
||||
property string lastText: index >= 0 ? content : ""
|
||||
property bool textModified: false
|
||||
property int fixedCursorPosition: -1
|
||||
|
||||
text: index > 0 ? sentinelChar + content : (index == 0 ? content : "")
|
||||
visible: !label.visible
|
||||
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
height: label.contentHeight + _bottomMargin
|
||||
|
||||
textMargin: 0
|
||||
textTopMargin: 0
|
||||
wrapMode: Text.Wrap
|
||||
labelVisible: false
|
||||
inputMethodHints: Qt.ImhNoAutoUppercase
|
||||
|
||||
onCursorPositionChanged: {
|
||||
if (index > 0 && cursorPosition == 0)
|
||||
cursorPosition = 1
|
||||
}
|
||||
|
||||
onSelectionStartChanged: {
|
||||
if (index > 0 && selectionStart == 0)
|
||||
select(1, selectionEnd)
|
||||
}
|
||||
|
||||
onTextChanged: {
|
||||
if (visible) {
|
||||
if (fixedCursorPosition != -1) {
|
||||
cursorPosition = fixedCursorPosition
|
||||
fixedCursorPosition = -1
|
||||
}
|
||||
if (index >= 0) {
|
||||
if (index > 0 && text[0] != sentinelChar) {
|
||||
var textEmpty = text.length != 0
|
||||
forceCommit()
|
||||
document.focusedIndex = index - 1
|
||||
document.focusedItem.setCursorPositionAtEnd(textEmpty)
|
||||
Lisp.call("models:join-node", index - 1)
|
||||
} else {
|
||||
var split = text.indexOf("\n")
|
||||
if (split != -1) {
|
||||
forceCommit()
|
||||
Lisp.call("models:split-node", index, text.substring(index > 0 ? 1 : 0, split), text.substring(split + 1))
|
||||
document.focusedIndex = index + 1
|
||||
} else {
|
||||
lastText = getText()
|
||||
textModified = lastText != content
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onActiveFocusChanged: {
|
||||
if (!activeFocus) {
|
||||
forceCommit()
|
||||
|
||||
if (document.focusedIndex == index)
|
||||
document.focusedIndex = -1
|
||||
}
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
forceActiveFocus()
|
||||
if (index > 0 && cursorPosition == 0)
|
||||
cursorPosition = 1
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (visible) {
|
||||
forceActiveFocus()
|
||||
if (index > 0 && cursorPosition == 0)
|
||||
cursorPosition = 1
|
||||
}
|
||||
}
|
||||
|
||||
function getText () {
|
||||
return index > 0 ? text.substring(1) : text
|
||||
}
|
||||
|
||||
function forceCommit () {
|
||||
if (textModified) {
|
||||
Lisp.call("models:modify-text", index, lastText)
|
||||
textModified = false
|
||||
}
|
||||
}
|
||||
|
||||
function setCursorPositionAt(x, y) {
|
||||
cursorPosition = positionAt(x, y)
|
||||
}
|
||||
|
||||
function setCursorPositionAtEnd (fix) {
|
||||
if (fix) {
|
||||
fixedCursorPosition = text.length
|
||||
} else {
|
||||
cursorPosition = text.length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function forceCommit () { edit.forceCommit() }
|
||||
function setCursorPositionAt (x, y) { edit.setCursorPositionAt(x, y) }
|
||||
function setCursorPositionAtEnd (fix) { edit.setCursorPositionAtEnd(fix) }
|
||||
}
|
||||
|
|
@ -58,7 +58,8 @@ DISTFILES += qml/harbour-sextant.qml \
|
|||
qml/cover/CoverPage.qml \
|
||||
qml/components/ListTextField.qml \
|
||||
qml/components/OrgDelegate.qml \
|
||||
qml/components/OrgText.qml \
|
||||
qml/components/OrgLine.qml \
|
||||
qml/components/OrgEdit.qml \
|
||||
qml/components/OverwriteDialog.qml \
|
||||
qml/pages/FirstPage.qml \
|
||||
qml/pages/SecondPage.qml \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue