Changeset View
Changeset View
Standalone View
Standalone View
applets/notes/package/contents/ui/main.qml
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. | ||
14 | 14 | | |||
15 | You should have received a copy of the GNU General Public License along | 15 | You should have received a copy of the GNU General Public License along | ||
16 | with this program; if not, write to the Free Software Foundation, Inc., | 16 | with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.1 | 20 | import QtQuick 2.6 | ||
21 | import QtQuick.Controls 2.5 as QQC2 | 21 | import QtQuick.Controls 2.5 as QQC2 | ||
22 | import QtQuick.Layouts 1.1 | 22 | import QtQuick.Layouts 1.1 | ||
23 | 23 | | |||
24 | import org.kde.draganddrop 2.0 as DragDrop | 24 | import org.kde.draganddrop 2.0 as DragDrop | ||
25 | 25 | | |||
26 | import org.kde.plasma.core 2.0 as PlasmaCore | 26 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
27 | import org.kde.plasma.components 2.0 as PlasmaComponents | 27 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
28 | import org.kde.plasma.components 3.0 as PlasmaComponents3 | ||||
28 | import org.kde.plasma.extras 2.0 as PlasmaExtras | 29 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||
29 | import org.kde.plasma.plasmoid 2.0 | 30 | import org.kde.plasma.plasmoid 2.0 | ||
30 | 31 | | |||
31 | // so we can override the textColor... | 32 | // so we can override the textColor... | ||
32 | import QtQuick.Controls.Styles.Plasma 2.0 as PlasmaStyle | 33 | import QtQuick.Controls.Styles.Plasma 2.0 as PlasmaStyle | ||
33 | 34 | | |||
34 | import org.kde.plasma.private.notes 0.1 | 35 | import org.kde.plasma.private.notes 0.1 | ||
35 | 36 | | |||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 138 | FocusScope { | |||
139 | anchors { | 140 | anchors { | ||
140 | fill: parent | 141 | fill: parent | ||
141 | leftMargin: horizontalMargins | 142 | leftMargin: horizontalMargins | ||
142 | rightMargin: horizontalMargins | 143 | rightMargin: horizontalMargins | ||
143 | topMargin: verticalMargins | 144 | topMargin: verticalMargins | ||
144 | bottomMargin: verticalMargins | 145 | bottomMargin: verticalMargins | ||
145 | } | 146 | } | ||
146 | 147 | | |||
147 | PlasmaComponents.TextArea { | 148 | QQC2.ScrollView { | ||
148 | id: mainTextArea | | |||
149 | anchors { | 149 | anchors { | ||
150 | top: parent.top | 150 | top: parent.top | ||
151 | left: parent.left | 151 | left: parent.left | ||
152 | right: parent.right | 152 | right: parent.right | ||
153 | bottom: fontButtons.top | 153 | bottom: fontButtons.top | ||
154 | bottomMargin: Math.round(units.largeSpacing / 2) | 154 | bottomMargin: Math.round(units.largeSpacing / 2) | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | backgroundVisible: false | 157 | clip: true | ||
158 | frameVisible: false | | |||
159 | textFormat: TextEdit.RichText | | |||
160 | 158 | | |||
159 | PlasmaComponents3.TextArea { | ||||
160 | id: mainTextArea | ||||
161 | | ||||
162 | textFormat: TextEdit.RichText | ||||
161 | onLinkActivated: Qt.openUrlExternally(link) | 163 | onLinkActivated: Qt.openUrlExternally(link) | ||
164 | background: Rectangle { color: "transparent" } | ||||
165 | color: textIconColor | ||||
166 | persistentSelection: true | ||||
167 | wrapMode: TextEdit.Wrap | ||||
162 | 168 | | |||
163 | Keys.onPressed: { | 169 | Keys.onPressed: { | ||
164 | if(event.key === Qt.Key_Escape) { | 170 | if(event.key === Qt.Key_Escape) { | ||
165 | plasmoid.expanded = false; | 171 | plasmoid.expanded = false; | ||
166 | event.accepted = true; | 172 | event.accepted = true; | ||
167 | } else if(event.modifiers === Qt.ControlModifier) { | 173 | } else if(event.modifiers === Qt.ControlModifier) { | ||
168 | if(event.key === Qt.Key_B) { | 174 | if(event.key === Qt.Key_B) { | ||
169 | documentHandler.bold = !documentHandler.bold; | 175 | documentHandler.bold = !documentHandler.bold; | ||
170 | event.accepted = true; | 176 | event.accepted = true; | ||
171 | } else if(event.key === Qt.Key_I) { | 177 | } else if(event.key === Qt.Key_I) { | ||
172 | documentHandler.italic = !documentHandler.italic; | 178 | documentHandler.italic = !documentHandler.italic; | ||
173 | event.accepted = true; | 179 | event.accepted = true; | ||
174 | } else if(event.key === Qt.Key_U) { | 180 | } else if(event.key === Qt.Key_U) { | ||
175 | documentHandler.underline = !documentHandler.underline; | 181 | documentHandler.underline = !documentHandler.underline; | ||
176 | event.accepted = true; | 182 | event.accepted = true; | ||
177 | } else if(event.key === Qt.Key_S) { | 183 | } else if(event.key === Qt.Key_S) { | ||
178 | documentHandler.strikeOut = !documentHandler.strikeOut; | 184 | documentHandler.strikeOut = !documentHandler.strikeOut; | ||
179 | event.accepted = true; | 185 | event.accepted = true; | ||
186 | } else if(event.matches(StandardKey.Paste)) { | ||||
187 | documentHandler.pasteWithoutFormatting(); | ||||
188 | documentHandler.reset(); | ||||
189 | event.accepted = true; | ||||
190 | } else if(event.matches(StandardKey.Cut)) { | ||||
191 | mainTextArea.cut(); | ||||
192 | documentHandler.reset(); | ||||
193 | event.accepted = true; | ||||
180 | } | 194 | } | ||
181 | } | 195 | } | ||
182 | } | 196 | } | ||
183 | 197 | | |||
184 | style: PlasmaStyle.TextAreaStyle { | | |||
185 | textColor: textIconColor | | |||
186 | } | | |||
187 | | ||||
188 | // update the note if the source changes, but only if the user isn't editing it currently | 198 | // update the note if the source changes, but only if the user isn't editing it currently | ||
189 | Binding { | 199 | Binding { | ||
190 | target: mainTextArea | 200 | target: mainTextArea | ||
191 | property: "text" | 201 | property: "text" | ||
192 | value: note.noteText | 202 | value: note.noteText | ||
193 | when: !mainTextArea.activeFocus | 203 | when: !mainTextArea.activeFocus | ||
194 | } | 204 | } | ||
195 | 205 | | |||
196 | onActiveFocusChanged: { | 206 | onActiveFocusChanged: { | ||
197 | if (activeFocus) { | 207 | if (activeFocus) { | ||
198 | plasmoid.status = PlasmaCore.Types.AcceptingInputStatus | 208 | plasmoid.status = PlasmaCore.Types.AcceptingInputStatus | ||
199 | } else { | 209 | } else { | ||
200 | plasmoid.status = PlasmaCore.Types.ActiveStatus | 210 | plasmoid.status = PlasmaCore.Types.ActiveStatus | ||
201 | note.save(mainTextArea.text); | 211 | note.save(mainTextArea.text); | ||
202 | } | 212 | } | ||
203 | } | 213 | } | ||
214 | | ||||
215 | onPressed: { | ||||
216 | if (event.button === Qt.RightButton) { | ||||
217 | event.accepted = true; | ||||
218 | contextMenu.popup(); | ||||
219 | mainTextArea.forceActiveFocus(); | ||||
220 | } | ||||
221 | } | ||||
222 | | ||||
223 | QQC2.Menu { | ||||
224 | id: contextMenu | ||||
225 | | ||||
226 | ShortcutMenuItem { | ||||
227 | _sequence: StandardKey.Undo | ||||
228 | _enabled: mainTextArea.canUndo | ||||
229 | _iconName: "edit-undo" | ||||
230 | _text: i18n("Undo") | ||||
231 | onTriggered: contextMenu.retFocus(() => mainTextArea.undo()) | ||||
232 | } | ||||
233 | | ||||
234 | ShortcutMenuItem { | ||||
235 | _sequence: StandardKey.Redo | ||||
236 | _enabled: mainTextArea.canRedo | ||||
237 | _iconName: "edit-redo" | ||||
238 | _text: i18n("Redo") | ||||
davidedmundson: Where does this libplasma5 domain come from? | |||||
I think I copied from here: https://git.reviewboard.kde.org/r/121698/diff/1/#. Is it outdated maybe? luc4: I think I copied from here: https://git.reviewboard.kde.org/r/121698/diff/1/#. Is it outdated… | |||||
~ish. To explain what it's doing. i18n("hello") will return a translated version of the word "hello" based on the currently loaded domain, which is done automatically for applets and applications, but there's some issues with library code. i18nd("somePotFile", "hello") will explicitly load the pot file "somePotFile" then translate the word hello. In this particular case, everything used is within the applet, so you can just use i18n davidedmundson: ~ish.
To explain what it's doing.
i18n("hello")
will return a translated version of the… | |||||
239 | onTriggered: contextMenu.retFocus(() => mainTextArea.redo()) | ||||
240 | } | ||||
241 | | ||||
242 | QQC2.MenuSeparator {} | ||||
243 | | ||||
244 | ShortcutMenuItem { | ||||
245 | _sequence: StandardKey.Cut | ||||
246 | _enabled: mainTextArea.selectedText.length > 0 | ||||
247 | _iconName: "edit-cut" | ||||
248 | _text: i18n("Cut") | ||||
249 | onTriggered: contextMenu.retFocus(() => mainTextArea.cut()) | ||||
250 | } | ||||
251 | | ||||
252 | ShortcutMenuItem { | ||||
253 | _sequence: StandardKey.Copy | ||||
254 | _enabled: mainTextArea.selectedText.length > 0 | ||||
255 | _iconName: "edit-copy" | ||||
256 | _text: i18n("Copy") | ||||
257 | onTriggered: contextMenu.retFocus(() => mainTextArea.copy()) | ||||
258 | } | ||||
259 | | ||||
260 | ShortcutMenuItem { | ||||
261 | _sequence: StandardKey.Paste | ||||
262 | _enabled: mainTextArea.canPaste | ||||
263 | _iconName: "edit-paste" | ||||
264 | _text: i18n("Paste Without Formatting") | ||||
265 | onTriggered: contextMenu.retFocus(() => documentHandler.pasteWithoutFormatting()) | ||||
266 | } | ||||
267 | | ||||
268 | ShortcutMenuItem { | ||||
269 | _enabled: mainTextArea.canPaste | ||||
270 | _text: i18n("Paste") | ||||
271 | _iconName: "edit-paste" | ||||
272 | onTriggered: contextMenu.retFocus(() => mainTextArea.paste()) | ||||
273 | } | ||||
274 | | ||||
275 | ShortcutMenuItem { | ||||
276 | _sequence: StandardKey.Delete | ||||
277 | _enabled: mainTextArea.selectedText.length > 0 | ||||
278 | _iconName: "edit-delete" | ||||
279 | _text: i18n("Delete") | ||||
280 | onTriggered: contextMenu.retFocus(() => mainTextArea.remove(mainTextArea.selectionStart, mainTextArea.selectionEnd)) | ||||
281 | } | ||||
282 | | ||||
283 | ShortcutMenuItem { | ||||
284 | _enabled: mainTextArea.text.length > 0 | ||||
285 | _iconName: "edit-clear" | ||||
286 | _text: i18n("Clear") | ||||
287 | onTriggered: contextMenu.retFocus(() => mainTextArea.clear()) | ||||
288 | } | ||||
289 | | ||||
290 | QQC2.MenuSeparator {} | ||||
291 | | ||||
292 | ShortcutMenuItem { | ||||
293 | _sequence: StandardKey.SelectAll | ||||
294 | _enabled: mainTextArea.text.length > 0 | ||||
295 | _iconName: "edit-select-all" | ||||
296 | _text: i18n("Select All") | ||||
297 | onTriggered: contextMenu.retFocus(() => mainTextArea.selectAll()) | ||||
298 | } | ||||
299 | | ||||
300 | function retFocus(f) { | ||||
301 | f() | ||||
302 | documentHandler.reset() | ||||
303 | mainTextArea.forceActiveFocus() | ||||
304 | } | ||||
305 | } | ||||
306 | } | ||||
204 | } | 307 | } | ||
205 | 308 | | |||
206 | DragDrop.DropArea { | 309 | DragDrop.DropArea { | ||
207 | id: dropArea | 310 | id: dropArea | ||
208 | anchors.fill: mainTextArea | 311 | anchors.fill: mainTextArea | ||
209 | 312 | | |||
210 | function positionOfDrop(event) { | 313 | function positionOfDrop(event) { | ||
211 | return mainTextArea.positionAt(event.x, event.y + mainTextArea.flickableItem.contentY) | 314 | return mainTextArea.positionAt(event.x, event.y + mainTextArea.flickableItem.contentY) | ||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |
Where does this libplasma5 domain come from?