Dekko
Loading...
Searching...
No Matches
HtmlEditorToolbar.qml
1/* Copyright (C) 2025 CIT-Services <info@cit-services.eu>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18import QtQuick 2.4
19import QtQuick.Controls.Suru 2.2
20import Lomiri.Components 1.3
21import Lomiri.Components.Popups 1.3
22import Dekko.Lomiri.Constants 1.0
24Rectangle {
25 id: toolbar
26
27 property var editor: null
28 property string currentFontSize: "11pt"
29 property color currentTextColor: "#202124"
30 property color currentHighlightColor: "transparent"
31
32 signal fontSizeClicked()
33 signal textColorClicked()
34 signal highlightColorClicked()
35 signal linkClicked()
36
37 height: units.gu(5.2)
38 color: theme.palette.normal.background
39
40 Flickable {
41 anchors.fill: parent
42 contentWidth: toolbarRow.width + units.gu(2)
43 contentHeight: height
44 flickableDirection: Flickable.HorizontalFlick
45 clip: true
46
47 Row {
48 id: toolbarRow
49 x: units.gu(1)
50 anchors.verticalCenter: parent.verticalCenter
51 spacing: units.gu(0.6)
52
53 // Bold
54 Button {
55 width: units.gu(4.2)
56 height: units.gu(3.8)
57 text: "B"
58 font.bold: true
59 color: editor && editor.font.bold ? Suru.highlightColor : theme.palette.normal.foreground
60 onClicked: {
61 if (editor) {
62 editor.font.bold = !editor.font.bold
63 }
64 }
65 }
66
67 // Italic
68 Button {
69 width: units.gu(4.2)
70 height: units.gu(3.8)
71 text: "I"
72 font.italic: true
73 color: editor && editor.font.italic ? Suru.highlightColor : theme.palette.normal.foreground
74 onClicked: {
75 if (editor) {
76 editor.font.italic = !editor.font.italic
77 }
78 }
79 }
80
81 // Underline
82 Button {
83 width: units.gu(4.2)
84 height: units.gu(3.8)
85 text: "U"
86 font.underline: true
87 color: editor && editor.font.underline ? Suru.highlightColor : theme.palette.normal.foreground
88 onClicked: {
89 if (editor) {
90 editor.font.underline = !editor.font.underline
91 }
92 }
93 }
94
96
97 // Font Size
98 Button {
99 width: units.gu(6.8)
100 height: units.gu(3.8)
101 text: currentFontSize
102 color: theme.palette.normal.foreground
103 onClicked: toolbar.fontSizeClicked()
104 }
105
106 // Text Color
107 Button {
108 width: units.gu(4.2)
109 height: units.gu(3.8)
110 text: "A"
111 font.bold: true
112 color: theme.palette.normal.foreground
113 Rectangle {
114 anchors {
115 bottom: parent.bottom
116 bottomMargin: units.dp(4)
117 horizontalCenter: parent.horizontalCenter
118 }
119 width: units.gu(2.2)
120 height: units.dp(3)
121 radius: units.dp(1)
122 color: toolbar.currentTextColor
123 }
124 onClicked: toolbar.textColorClicked()
125 }
126
127 // Highlight Color
128 Button {
129 width: units.gu(4.2)
130 height: units.gu(3.8)
131 color: theme.palette.normal.foreground
132 Rectangle {
133 anchors.centerIn: parent
134 width: units.gu(2.2)
135 height: units.gu(1.6)
136 radius: units.dp(2)
137 color: toolbar.currentHighlightColor === "transparent" ? "#fff9c4" : toolbar.currentHighlightColor
138 border.width: units.dp(1)
139 border.color: theme.palette.normal.baseText
140 }
141 onClicked: toolbar.highlightColorClicked()
142 }
143
145
146 // Alignment Left
147 Button {
148 width: units.gu(4.2)
149 height: units.gu(3.8)
150 property bool isActive: editor && editor.textAlignment === Text.AlignLeft
151 color: isActive ? Suru.highlightColor : theme.palette.normal.foreground
152 property color iconColor: isActive ? "white" : theme.palette.normal.baseText
153 Column {
154 anchors.centerIn: parent
155 spacing: units.dp(2)
156 Rectangle { width: units.gu(2.4); height: units.dp(2); color: parent.parent.iconColor; anchors.left: parent.left }
157 Rectangle { width: units.gu(1.6); height: units.dp(2); color: parent.parent.iconColor; anchors.left: parent.left }
158 Rectangle { width: units.gu(2.0); height: units.dp(2); color: parent.parent.iconColor; anchors.left: parent.left }
159 Rectangle { width: units.gu(1.2); height: units.dp(2); color: parent.parent.iconColor; anchors.left: parent.left }
160 }
161 onClicked: if (editor) editor.setTextAlignment(Text.AlignLeft)
162 }
163
164 // Alignment Center
165 Button {
166 width: units.gu(4.2)
167 height: units.gu(3.8)
168 property bool isActive: editor && editor.textAlignment === Text.AlignHCenter
169 color: isActive ? Suru.highlightColor : theme.palette.normal.foreground
170 property color iconColor: isActive ? "white" : theme.palette.normal.baseText
171 Column {
172 anchors.centerIn: parent
173 spacing: units.dp(2)
174 Rectangle { width: units.gu(2.4); height: units.dp(2); color: parent.parent.iconColor; anchors.horizontalCenter: parent.horizontalCenter }
175 Rectangle { width: units.gu(1.6); height: units.dp(2); color: parent.parent.iconColor; anchors.horizontalCenter: parent.horizontalCenter }
176 Rectangle { width: units.gu(2.0); height: units.dp(2); color: parent.parent.iconColor; anchors.horizontalCenter: parent.horizontalCenter }
177 Rectangle { width: units.gu(1.2); height: units.dp(2); color: parent.parent.iconColor; anchors.horizontalCenter: parent.horizontalCenter }
178 }
179 onClicked: if (editor) editor.setTextAlignment(Text.AlignHCenter)
180 }
181
182 // Alignment Right
183 Button {
184 width: units.gu(4.2)
185 height: units.gu(3.8)
186 property bool isActive: editor && editor.textAlignment === Text.AlignRight
187 color: isActive ? Suru.highlightColor : theme.palette.normal.foreground
188 property color iconColor: isActive ? "white" : theme.palette.normal.baseText
189 Column {
190 anchors.centerIn: parent
191 spacing: units.dp(2)
192 Rectangle { width: units.gu(2.4); height: units.dp(2); color: parent.parent.iconColor; anchors.right: parent.right }
193 Rectangle { width: units.gu(1.6); height: units.dp(2); color: parent.parent.iconColor; anchors.right: parent.right }
194 Rectangle { width: units.gu(2.0); height: units.dp(2); color: parent.parent.iconColor; anchors.right: parent.right }
195 Rectangle { width: units.gu(1.2); height: units.dp(2); color: parent.parent.iconColor; anchors.right: parent.right }
196 }
197 onClicked: if (editor) editor.setTextAlignment(Text.AlignRight)
198 }
199
200 // Alignment Justify
201 Button {
202 width: units.gu(4.2)
203 height: units.gu(3.8)
204 property bool isActive: editor && editor.textAlignment === Text.AlignJustify
205 color: isActive ? Suru.highlightColor : theme.palette.normal.foreground
206 property color iconColor: isActive ? "white" : theme.palette.normal.baseText
207 Column {
208 anchors.centerIn: parent
209 spacing: units.dp(2)
210 Rectangle { width: units.gu(2.4); height: units.dp(2); color: parent.parent.iconColor }
211 Rectangle { width: units.gu(2.4); height: units.dp(2); color: parent.parent.iconColor }
212 Rectangle { width: units.gu(2.4); height: units.dp(2); color: parent.parent.iconColor }
213 Rectangle { width: units.gu(2.4); height: units.dp(2); color: parent.parent.iconColor }
214 }
215 onClicked: if (editor) editor.setTextAlignment(Text.AlignJustify)
216 }
217
219
220 // Unordered List
221 Button {
222 width: units.gu(4.2)
223 height: units.gu(3.8)
224 color: theme.palette.normal.foreground
225 text: "• "
226 onClicked: if (editor) editor.makeUnorderedList()
227 }
228
229 // Ordered List
230 Button {
231 width: units.gu(4.2)
232 height: units.gu(3.8)
233 color: theme.palette.normal.foreground
234 text: "1."
235 onClicked: if (editor) editor.makeOrderedList()
236 }
237
239
240 // Link
241 Button {
242 width: units.gu(4.2)
243 height: units.gu(3.8)
244 color: theme.palette.normal.foreground
245 iconName: "insert-link"
246 onClicked: toolbar.linkClicked()
247 }
248
250
251 // Undo
252 Button {
253 width: units.gu(4.2)
254 height: units.gu(3.8)
255 color: theme.palette.normal.foreground
256 iconName: "edit-undo"
257 onClicked: if (editor) editor.undo()
258 }
259
260 // Redo
261 Button {
262 width: units.gu(4.2)
263 height: units.gu(3.8)
264 color: theme.palette.normal.foreground
265 iconName: "edit-redo"
266 onClicked: if (editor) editor.redo()
267 }
268
270
271 // Clear Formatting
272 Button {
273 width: units.gu(4.8)
274 height: units.gu(3.8)
275 color: theme.palette.normal.foreground
276 iconName: "edit-clear"
277 onClicked: if (editor) editor.removeAllFormatting()
278 }
279 }
280 }
281}