MauiKit TextEditor

ColorSchemesPage.qml
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import org.mauikit.controls as Maui
6import org.mauikit.texteditor as TE
7
8/**
9 * @brief A settings page with the available color schemes for the syntax highlighting.
10 *
11 * @image html colors.png
12 *
13 * @code
14 * Maui.SettingsDialog
15 * {
16 * id: _settings
17 * Component
18 * {
19 * id: _colorsComponent
20 * TE.ColorSchemesPage
21 * {
22 * backgroundColor: _editor.document.backgroundColor
23 * currentTheme: _editor.document.theme
24 *
25 * onCurrentThemeChanged: _editor.document.theme = currentTheme
26 * onColorsPicked: (background, text) =>
27 * {
28 * _editor.Maui.Theme.backgroundColor = background
29 * _editor.body.color = text
30 * }
31 * }
32 * }
33 *
34 * Maui.SectionItem
35 * {
36 * text: "Color scheme"
37 * onClicked: _settings.addPage(_colorsComponent)
38 * }
39 * }
40 *
41 * TE.TextEditor
42 * {
43 * id: _editor
44 * anchors.fill: parent
45 * body.wrapMode: Text.NoWrap
46 * document.enableSyntaxHighlighting: true
47 * }
48 * @endcode
49 */
50Maui.SettingsPage
51{
52 id: control
53 title: i18n("Colors")
55 /**
56 * @brief The current theme being used or currently picked by the user
57 */
58 property string currentTheme
59
60 /**
61 * The current background color used in the text area or the one currently picked by the user
62 */
63 property color backgroundColor
65 /**
66 * @brief Emitted when a new background color has been picked
67 * @param backgroundColor the picked background color
68 * @param textColor a suited text color for the background color picked
69 */
70 signal colorsPicked(string backgroundColor, string textColor)
71
72 Maui.SectionGroup
73 {
74 title: i18n("Colors")
75 description: i18n("Configure the style of the syntax highlighting. This configuration in not applied for rich text formats.")
76
77 Maui.SectionItem
78 {
79 label1.text: i18n("Color")
80 label2.text: i18n("Editor background color.")
81
82 Maui.ColorsRow
83 {
84 spacing: Maui.Style.space.medium
85 currentColor: control.backgroundColor
86 colors: ["#333", "#fafafa", "#fff3e6", "#4c425b"]
87
88 onColorPicked:
89 {
90 currentColor = color
91
92 var textColor
93
94 switch(color)
95 {
96 case "#333": textColor = "#fafafa"; break;
97 case "#fafafa": textColor = "#333"; break;
98 case "#fff3e6": textColor = Qt.darker(color, 2); break;
99 case "#4c425b": textColor = Qt.lighter(color, 2.5); break;
100 default: textColor = Maui.Theme.textColor;
101 }
102
103 control.colorsPicked(color, textColor)
104 }
105 }
106 }
107
108 Maui.SectionItem
109 {
110 label1.text: i18n("Theme")
111 label2.text: i18n("Editor color scheme style.")
112
113 GridLayout
114 {
115 columns: 3
116 Layout.fillWidth: true
117 opacity: enabled ? 1 : 0.5
118
119 Repeater
120 {
121 model: TE.ColorSchemesModel {}
122
123 delegate: Maui.GridBrowserDelegate
124 {
125 Layout.fillWidth: true
126 checked: model.name === control.currentTheme
127 onClicked: control.currentTheme = model.name
128 label1.text: model.name
129
130 template.iconComponent: Rectangle
131 {
132 implicitHeight: Math.max(_layout.implicitHeight + topPadding + bottomPadding, 64)
133
134 color: control.backgroundColor
135 radius: Maui.Style.radiusV
136
137 Column
138 {
139 id: _layout
140 anchors.fill: parent
141 anchors.margins: Maui.Style.space.small
142
143 spacing: 2
144
145 Text
146 {
147 wrapMode: Text.NoWrap
148 elide: Text.ElideLeft
149 width: parent.width
150 text: "QWERTY { @ }"
151 color: model.foreground
152 font.family: "Monospace"
153 }
154
155 Rectangle
156 {
157 radius: 2
158 height: 8
159 width: parent.width
160 color: model.highlight
161 }
162
163 Rectangle
164 {
165 radius: 2
166 height: 8
167 width: parent.width
168 color: model.color3
169 }
170
171 Rectangle
172 {
173 radius: 2
174 height: 8
175 width: parent.width
176 color: model.color4
177 }
178
179 Rectangle
180 {
181 radius: 2
182 height: 8
183 width: parent.width
184 color: model.color5
185 }
186 }
187 }
188 }
189 }
190 }
191 }
192 }
193}
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.