summaryrefslogtreecommitdiff
path: root/lxqt-base/lxqt-config/files/lxqt-config-0.15.0-window-colour-option.patch
blob: 813cd7e4bca89f9c29053450a448d17118c50177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
From 0edcc373698189f27ac24fb0985570ef2ecd8b0d Mon Sep 17 00:00:00 2001
From: Tsu Jan <tsujan2000@gmail.com>
Date: Sun, 31 May 2020 18:04:48 +0430
Subject: [PATCH 1/4] Added an option to change window color
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It is in LXQt Appearance Configuration → Widget Style.

Note: For the option to work, lxqt-qtplugin 0.15.1 should be installed; otherwise, it will have no effect.
---
 lxqt-config-appearance/CMakeLists.txt  |  1 +
 lxqt-config-appearance/colorLabel.cpp  | 65 ++++++++++++++++++++++++++
 lxqt-config-appearance/colorLabel.h    | 53 +++++++++++++++++++++
 lxqt-config-appearance/styleconfig.cpp | 16 ++++++-
 lxqt-config-appearance/styleconfig.ui  | 34 ++++++++++++++
 5 files changed, 168 insertions(+), 1 deletion(-)
 create mode 100644 lxqt-config-appearance/colorLabel.cpp
 create mode 100644 lxqt-config-appearance/colorLabel.h

diff --git a/lxqt-config-appearance/CMakeLists.txt b/lxqt-config-appearance/CMakeLists.txt
index 184a8309..1ec118b7 100644
--- a/lxqt-config-appearance/CMakeLists.txt
+++ b/lxqt-config-appearance/CMakeLists.txt
@@ -27,6 +27,7 @@ set(CPP_FILES
     styleconfig.cpp
     fontconfigfile.cpp
     configothertoolkits.cpp
+    colorLabel.cpp
 )
 
 set(UI_FILES
diff --git a/lxqt-config-appearance/colorLabel.cpp b/lxqt-config-appearance/colorLabel.cpp
new file mode 100644
index 00000000..a3e22df0
--- /dev/null
+++ b/lxqt-config-appearance/colorLabel.cpp
@@ -0,0 +1,65 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * LXQt - a lightweight, Qt based, desktop toolset
+ * https://lxqt.org/
+ *
+ * Copyright: 2020 LXQt team
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#include "colorLabel.h"
+#include <QColorDialog>
+
+ColorLabel::ColorLabel(QWidget* parent, Qt::WindowFlags f)
+    : QLabel(parent, f)
+{
+    setFrameStyle(QFrame::Panel | QFrame::Sunken);
+    setFixedWidth(100);
+    setToolTip(tr("Click to change color."));
+}
+
+ColorLabel::~ColorLabel() {}
+
+void ColorLabel::setColor(const QColor& color)
+{
+    if (!color.isValid())
+        return;
+    stylesheetColor_ = color;
+    // ignore translucency
+    stylesheetColor_.setAlpha(255);
+    setStyleSheet(QStringLiteral("QLabel{background-color: rgb(%1, %2, %3);}")
+                  .arg(color.red()).arg(color.green()).arg(color.blue()));
+}
+
+QColor ColorLabel::getColor() const
+{
+    if (stylesheetColor_.isValid())
+        return stylesheetColor_; // the window color may be different from the stylesheet color
+    return palette().color(QPalette::Window);
+}
+
+void ColorLabel::mousePressEvent(QMouseEvent* /*event*/) {
+    QColor prevColor = getColor();
+    QColor color = QColorDialog::getColor(prevColor, window(), tr("Select Color"));
+    if (color.isValid() && color != prevColor)
+    {
+        emit colorChanged();
+        setColor(color);
+    }
+}
diff --git a/lxqt-config-appearance/colorLabel.h b/lxqt-config-appearance/colorLabel.h
new file mode 100644
index 00000000..1ea1b62c
--- /dev/null
+++ b/lxqt-config-appearance/colorLabel.h
@@ -0,0 +1,53 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * LXQt - a lightweight, Qt based, desktop toolset
+ * https://lxqt.org/
+ *
+ * Copyright: 2020 LXQt team
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#ifndef COLORLABEL_H
+#define COLORLABEL_H
+
+#include <QLabel>
+#include <QWidget>
+#include <Qt>
+
+class ColorLabel : public QLabel {
+    Q_OBJECT
+
+public:
+    explicit ColorLabel(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
+    ~ColorLabel();
+
+    void setColor(const QColor& color);
+    QColor getColor() const;
+
+signals:
+    void colorChanged();
+
+protected:
+    void mousePressEvent(QMouseEvent* event);
+
+private:
+    QColor stylesheetColor_;
+};
+
+#endif // COLORLABEL_H
diff --git a/lxqt-config-appearance/styleconfig.cpp b/lxqt-config-appearance/styleconfig.cpp
index 73f336e7..ce10aff1 100644
--- a/lxqt-config-appearance/styleconfig.cpp
+++ b/lxqt-config-appearance/styleconfig.cpp
@@ -61,6 +61,7 @@ StyleConfig::StyleConfig(LXQt::Settings* settings, QSettings* qtSettings, LXQt::
     connect(ui->gtk3ComboBox, QOverload<int>::of(&QComboBox::activated), this, &StyleConfig::settingsChanged);
     connect(ui->toolButtonStyle, QOverload<int>::of(&QComboBox::activated), this, &StyleConfig::settingsChanged);
     connect(ui->singleClickActivate, &QAbstractButton::clicked, this, &StyleConfig::settingsChanged);
+    connect(ui->winColorLabel, &ColorLabel::colorChanged, this, &StyleConfig::settingsChanged);
 }
 
 
@@ -97,7 +98,6 @@ void StyleConfig::initControls()
     // activate item views with single click
     ui->singleClickActivate->setChecked( mSettings->value(QStringLiteral("single_click_activate"), false).toBool());
 
-
     // Fill Qt themes
     ui->qtComboBox->clear();
     ui->qtComboBox->addItems(qtThemes);
@@ -108,8 +108,16 @@ void StyleConfig::initControls()
 
     ui->gtk2ComboBox->setCurrentText(mConfigOtherToolKits->getGTKThemeFromRCFile(QStringLiteral("2.0")));
     ui->gtk3ComboBox->setCurrentText(mConfigOtherToolKits->getGTKThemeFromRCFile(QStringLiteral("3.0")));
+
     mSettings->beginGroup(QLatin1String("Qt"));
+    // Qt style
     ui->qtComboBox->setCurrentText(mSettings->value(QStringLiteral("style")).toString());
+    // Qt window color
+    QColor color;
+    color.setNamedColor(mSettings->value(QStringLiteral("window_color")).toString());
+    if (!color.isValid())
+        color = QGuiApplication::palette().color(QPalette::Active,QPalette::Window);
+    ui->winColorLabel->setColor(color);
     mSettings->endGroup();
 
     update();
@@ -122,6 +130,12 @@ void StyleConfig::applyStyle()
     mQtSettings->beginGroup(QLatin1String("Qt"));
     if(mQtSettings->value(QStringLiteral("style")).toString() != themeName)
         mQtSettings->setValue(QStringLiteral("style"), themeName);
+    // Qt window color
+    QColor winColor = ui->winColorLabel->getColor();
+    QColor oldWinColor;
+    oldWinColor.setNamedColor(mQtSettings->value(QStringLiteral("window_color")).toString());
+    if (winColor != oldWinColor)
+        mQtSettings->setValue(QStringLiteral("window_color"), winColor.name());
     mQtSettings->endGroup();
 
     // single click setting
diff --git a/lxqt-config-appearance/styleconfig.ui b/lxqt-config-appearance/styleconfig.ui
index 15394024..6edbe470 100644
--- a/lxqt-config-appearance/styleconfig.ui
+++ b/lxqt-config-appearance/styleconfig.ui
@@ -146,8 +146,42 @@ Make sure 'xsettingsd' is installed to help GTK applications apply themes on the
      </property>
     </widget>
    </item>
+   <item row="2" column="0" colspan="2">
+    <layout class="QFormLayout" name="formLayout_3">
+     <property name="horizontalSpacing">
+      <number>5</number>
+     </property>
+     <property name="topMargin">
+      <number>10</number>
+     </property>
+     <property name="bottomMargin">
+      <number>10</number>
+     </property>
+     <item row="0" column="0">
+      <widget class="QLabel" name="label_6">
+       <property name="text">
+        <string>Window Color:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <widget class="ColorLabel" name="winColorLabel">
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ColorLabel</class>
+   <extends>QLabel</extends>
+   <header>colorLabel.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>

From 99ecfabccceb827256b7ef32c75c6aa6434d2d9f Mon Sep 17 00:00:00 2001
From: Tsu Jan <tsujan2000@gmail.com>
Date: Mon, 1 Jun 2020 23:46:49 +0430
Subject: [PATCH 2/4] Added a distinguishable border to the color label

---
 lxqt-config-appearance/colorLabel.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lxqt-config-appearance/colorLabel.cpp b/lxqt-config-appearance/colorLabel.cpp
index a3e22df0..c3b69d8d 100644
--- a/lxqt-config-appearance/colorLabel.cpp
+++ b/lxqt-config-appearance/colorLabel.cpp
@@ -43,8 +43,10 @@ void ColorLabel::setColor(const QColor& color)
     stylesheetColor_ = color;
     // ignore translucency
     stylesheetColor_.setAlpha(255);
-    setStyleSheet(QStringLiteral("QLabel{background-color: rgb(%1, %2, %3);}")
-                  .arg(color.red()).arg(color.green()).arg(color.blue()));
+    QString borderColor = qGray(stylesheetColor_.rgb()) < 255 / 2
+                            ? QStringLiteral("white") : QStringLiteral("black");
+    setStyleSheet(QStringLiteral("QLabel{background-color: rgb(%1, %2, %3); border: 1px solid %4;}}")
+                  .arg(color.red()).arg(color.green()).arg(color.blue()).arg(borderColor));
 }
 
 QColor ColorLabel::getColor() const

From 37f55579da91bfd78310a0e2c28c8551ad484414 Mon Sep 17 00:00:00 2001
From: Tsu Jan <tsujan2000@gmail.com>
Date: Thu, 4 Jun 2020 15:47:22 +0430
Subject: [PATCH 3/4] Removed an extra curly bracket in stylesheet

---
 lxqt-config-appearance/colorLabel.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxqt-config-appearance/colorLabel.cpp b/lxqt-config-appearance/colorLabel.cpp
index c3b69d8d..de730baf 100644
--- a/lxqt-config-appearance/colorLabel.cpp
+++ b/lxqt-config-appearance/colorLabel.cpp
@@ -45,7 +45,7 @@ void ColorLabel::setColor(const QColor& color)
     stylesheetColor_.setAlpha(255);
     QString borderColor = qGray(stylesheetColor_.rgb()) < 255 / 2
                             ? QStringLiteral("white") : QStringLiteral("black");
-    setStyleSheet(QStringLiteral("QLabel{background-color: rgb(%1, %2, %3); border: 1px solid %4;}}")
+    setStyleSheet(QStringLiteral("QLabel{background-color: rgb(%1, %2, %3); border: 1px solid %4;}")
                   .arg(color.red()).arg(color.green()).arg(color.blue()).arg(borderColor));
 }
 

From 30cf8267ce4af08f9953b169f9d8109fb9437f7d Mon Sep 17 00:00:00 2001
From: Tsu Jan <tsujan2000@gmail.com>
Date: Sat, 6 Jun 2020 14:15:53 +0430
Subject: [PATCH 4/4] A small improvement

---
 lxqt-config-appearance/colorLabel.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxqt-config-appearance/colorLabel.cpp b/lxqt-config-appearance/colorLabel.cpp
index de730baf..98d01729 100644
--- a/lxqt-config-appearance/colorLabel.cpp
+++ b/lxqt-config-appearance/colorLabel.cpp
@@ -46,7 +46,7 @@ void ColorLabel::setColor(const QColor& color)
     QString borderColor = qGray(stylesheetColor_.rgb()) < 255 / 2
                             ? QStringLiteral("white") : QStringLiteral("black");
     setStyleSheet(QStringLiteral("QLabel{background-color: rgb(%1, %2, %3); border: 1px solid %4;}")
-                  .arg(color.red()).arg(color.green()).arg(color.blue()).arg(borderColor));
+                  .arg(QString::number(color.red()), QString::number(color.green()), QString::number(color.blue()), borderColor));
 }
 
 QColor ColorLabel::getColor() const