Warning, /utilities/notae/src/ui/main.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Felipe Kinoshita <kinofhek@gmail.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003
0004 import QtQuick 2.15
0005 import QtQuick.Controls 2.15 as QQC2
0006 import QtQuick.Layouts 1.15
0007 import Qt.labs.platform 1.1
0008
0009 import org.kde.kirigami 2.20 as Kirigami
0010
0011 import org.kde.notae 1.0
0012
0013 QQC2.ApplicationWindow {
0014 id: root
0015
0016 visible: true
0017 title: i18n("Notae")
0018
0019 width: Kirigami.Units.gridUnit * 25
0020 height: Kirigami.Units.gridUnit * 33
0021 minimumWidth: Kirigami.Units.gridUnit * 25
0022 minimumHeight: Kirigami.Units.gridUnit * 15
0023
0024 Timer {
0025 id: saveWindowGeometryTimer
0026 interval: 1000
0027 onTriggered: App.saveWindowGeometry(root)
0028 }
0029
0030 Connections {
0031 id: saveWindowGeometryConnections
0032 enabled: root.visible
0033 target: root
0034
0035 function onClosing() { App.saveWindowGeometry(root) }
0036 function onWidthChanged() { saveWindowGeometryTimer.restart() }
0037 function onHeightChanged() { saveWindowGeometryTimer.restart() }
0038 function onXChanged() { saveWindowGeometryTimer.restart() }
0039 function onYChanged() { saveWindowGeometryTimer.restart() }
0040 }
0041
0042 component ToolBar : Item {
0043 default property alias children: headerLayout.children
0044
0045 width: root.width
0046 height: headerLayout.implicitHeight + (headerLayout.anchors.margins * 2)
0047
0048 Kirigami.AbstractApplicationHeader {
0049 id: headerToolbar
0050
0051 anchors.top: parent.top
0052 anchors.bottom: separator.top
0053 width: parent.width
0054 visible: true
0055
0056 contentItem: RowLayout {
0057 id: headerLayout
0058
0059 anchors.fill: parent
0060 anchors.margins: Kirigami.Units.smallSpacing
0061
0062 spacing: Kirigami.Units.smallSpacing
0063 }
0064 }
0065 Kirigami.Separator {
0066 id: separator
0067
0068 visible: !headerToolbar.visible
0069 anchors.bottom: parent.bottom
0070 width: parent.width
0071 }
0072 }
0073
0074 FileDialog {
0075 id: openDialog
0076
0077 nameFilters: ["Markdown files (*.md)", "Text files (*.txt)"]
0078
0079 onAccepted: textEditor.document.fileUrl = currentFile
0080 }
0081
0082 FileDialog {
0083 id: saveDialog
0084
0085 fileMode: FileDialog.SaveFile
0086 onAccepted: textEditor.document.saveAs(currentFile)
0087 }
0088
0089 header: Loader {
0090 active: true
0091 sourceComponent: ToolBar {
0092 QQC2.ToolButton {
0093 focusPolicy: Qt.NoFocus
0094 display: QQC2.AbstractButton.IconOnly
0095
0096 action: Kirigami.Action {
0097 text: i18n("New")
0098 icon.name: "document-new"
0099 shortcut: StandardKey.New
0100 onTriggered: {
0101 textEditor.document.saveAs(textEditor.document.fileUrl)
0102 textEditor.document.fileUrl = ""
0103 textEditor.body.text = ""
0104 }
0105 }
0106
0107 QQC2.ToolTip.visible: hovered
0108 QQC2.ToolTip.text: i18n("Create new document (Ctrl+N)")
0109 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0110 }
0111
0112 QQC2.ToolButton {
0113 focusPolicy: Qt.NoFocus
0114 display: QQC2.AbstractButton.IconOnly
0115
0116 action: Kirigami.Action {
0117 text: i18n("Open…")
0118 icon.name: "document-open"
0119 shortcut: StandardKey.Open
0120 onTriggered: openDialog.open()
0121 }
0122
0123 QQC2.ToolTip.visible: hovered
0124 QQC2.ToolTip.text: i18n("Open an existing note (Ctrl+O)")
0125 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0126 }
0127
0128 QQC2.ToolButton {
0129 focusPolicy: Qt.NoFocus
0130 display: QQC2.AbstractButton.IconOnly
0131
0132 action: Kirigami.Action {
0133 text: textEditor.document.fileUrl == "" ? i18n("Save As…") : i18n("Save")
0134 icon.name: textEditor.document.fileUrl == "" ? "document-save-as" : "document-save"
0135 shortcut: StandardKey.Save
0136 onTriggered: {
0137 if (textEditor.document.fileUrl == "") {
0138 saveDialog.open()
0139 return
0140 }
0141
0142 textEditor.document.saveAs(textEditor.document.fileUrl)
0143 }
0144 }
0145
0146 QQC2.ToolTip.visible: hovered
0147 QQC2.ToolTip.text: textEditor.document.fileUrl == "" ? i18n("Save new document (Ctrl+Shift+S)") : i18n("Save document (Ctrl+S)")
0148 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0149 }
0150
0151 QQC2.ToolSeparator {
0152 Layout.leftMargin: Kirigami.Units.largeSpacing
0153 Layout.rightMargin: Kirigami.Units.largeSpacing
0154 }
0155
0156 QQC2.ToolButton {
0157 focusPolicy: Qt.NoFocus
0158
0159 display: QQC2.AbstractButton.IconOnly
0160 action: Kirigami.Action {
0161 text: i18n("Cut")
0162 icon.name: "edit-cut"
0163 shortcut: StandardKey.Cut
0164 enabled: !textEditor.body.selectedText.length <= 0
0165 onTriggered: textEditor.body.cut()
0166 }
0167
0168 QQC2.ToolTip.visible: hovered
0169 QQC2.ToolTip.text: i18n("Cut selection to clipboard (Ctrl+X)")
0170 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0171 }
0172
0173 QQC2.ToolButton {
0174 focusPolicy: Qt.NoFocus
0175
0176 display: QQC2.AbstractButton.IconOnly
0177 action: Kirigami.Action {
0178 text: i18n("Copy")
0179 icon.name: "edit-copy"
0180 shortcut: StandardKey.Copy
0181 enabled: textEditor.body.selectedText.length > 0
0182 onTriggered: textEditor.body.copy()
0183 }
0184
0185 QQC2.ToolTip.visible: hovered
0186 QQC2.ToolTip.text: i18n("Copy selection to clipboard (Ctrl+C)")
0187 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0188 }
0189
0190 QQC2.ToolButton {
0191 focusPolicy: Qt.NoFocus
0192
0193 display: QQC2.AbstractButton.IconOnly
0194 action: Kirigami.Action {
0195 text: i18n("Paste")
0196 icon.name: "edit-paste"
0197 shortcut: StandardKey.Paste
0198 enabled: textEditor.canPaste
0199 onTriggered: textEditor.body.paste()
0200 }
0201
0202 QQC2.ToolTip.visible: hovered
0203 QQC2.ToolTip.text: i18n("Paste clipboard content (Ctrl+V)")
0204 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0205 }
0206
0207 QQC2.ToolSeparator {
0208 Layout.leftMargin: Kirigami.Units.largeSpacing
0209 Layout.rightMargin: Kirigami.Units.largeSpacing
0210 }
0211
0212 QQC2.ToolButton {
0213 display: QQC2.AbstractButton.IconOnly
0214 action: Kirigami.Action {
0215 text: i18n("Undo")
0216 icon.name: "edit-undo"
0217 shortcut: StandardKey.Undo
0218 enabled: textEditor.canUndo
0219 onTriggered: textEditor.body.undo()
0220 }
0221
0222 QQC2.ToolTip.visible: hovered
0223 QQC2.ToolTip.text: i18n("Undo last action (Ctrl+Z)")
0224 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0225 }
0226
0227 QQC2.ToolButton {
0228 focusPolicy: Qt.NoFocus
0229
0230 display: QQC2.AbstractButton.IconOnly
0231 action: Kirigami.Action {
0232 text: i18n("Redo")
0233 icon.name: "edit-redo"
0234 shortcut: StandardKey.Redo
0235 enabled: textEditor.canRedo
0236 onTriggered: textEditor.body.redo()
0237 }
0238
0239 QQC2.ToolTip.visible: hovered
0240 QQC2.ToolTip.text: i18n("Redo last undone action (Ctrl+Shift+Z)")
0241 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0242 }
0243
0244 QQC2.ToolSeparator {
0245 Layout.leftMargin: Kirigami.Units.largeSpacing
0246 Layout.rightMargin: Kirigami.Units.largeSpacing
0247 }
0248
0249 Item {
0250 Layout.fillWidth: true
0251 }
0252 }
0253 }
0254
0255 TextEditor {
0256 id: textEditor
0257
0258 anchors.fill: parent
0259
0260 body.font.family: "Monospace"
0261 document.tabSpace: Kirigami.Units.gridUnit * 2
0262 document.enableSyntaxHighlighting: true
0263 document.autoSave: false//Config.autoSave
0264 }
0265 }