Changeset View
Changeset View
Standalone View
Standalone View
kded/configvalueprovider.cpp
Show All 17 Lines | |||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include <QFont> | 21 | #include <QFont> | ||
22 | #include <QString> | 22 | #include <QString> | ||
23 | #include <QColor> | 23 | #include <QColor> | ||
24 | #include <QMap> | 24 | #include <QMap> | ||
25 | #include <QList> | 25 | #include <QList> | ||
26 | #include <QSvgGenerator> | ||||
27 | #include <QDir> | ||||
26 | 28 | | |||
27 | #include <KConfig> | 29 | #include <KConfig> | ||
28 | #include <KIconTheme> | 30 | #include <KIconTheme> | ||
29 | #include <KSharedConfig> | 31 | #include <KSharedConfig> | ||
30 | #include <KConfigGroup> | 32 | #include <KConfigGroup> | ||
31 | #include <KColorScheme> | 33 | #include <KColorScheme> | ||
32 | #include <KColorUtils> | 34 | #include <KColorUtils> | ||
33 | 35 | | |||
34 | #include <gtk/gtk.h> | 36 | #include <gtk/gtk.h> | ||
35 | 37 | | |||
38 | #include "dummydecorationbridge.h" | ||||
36 | #include "configvalueprovider.h" | 39 | #include "configvalueprovider.h" | ||
37 | 40 | | |||
38 | ConfigValueProvider::ConfigValueProvider() : | 41 | ConfigValueProvider::ConfigValueProvider() : | ||
39 | kdeglobalsConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))), | 42 | kdeglobalsConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))), | ||
40 | inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))), | 43 | inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))), | ||
41 | kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc"))) | 44 | kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc"))) | ||
42 | { | 45 | { | ||
43 | 46 | | |||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | 171 | { | |||
169 | KConfigGroup colorsConfigGroup = kdeglobalsConfig->group(QStringLiteral("Colors:Window")); | 172 | KConfigGroup colorsConfigGroup = kdeglobalsConfig->group(QStringLiteral("Colors:Window")); | ||
170 | QColor windowBackgroundColor = colorsConfigGroup.readEntry(QStringLiteral("BackgroundNormal"), QColor(239, 240, 241)); | 173 | QColor windowBackgroundColor = colorsConfigGroup.readEntry(QStringLiteral("BackgroundNormal"), QColor(239, 240, 241)); | ||
171 | const int windowBackgroundGray = qGray(windowBackgroundColor.rgb()); | 174 | const int windowBackgroundGray = qGray(windowBackgroundColor.rgb()); | ||
172 | 175 | | |||
173 | // We use heuristic to determine if current color scheme is dark or not | 176 | // We use heuristic to determine if current color scheme is dark or not | ||
174 | return windowBackgroundGray < 192; | 177 | return windowBackgroundGray < 192; | ||
175 | } | 178 | } | ||
176 | 179 | | |||
180 | QStringList ConfigValueProvider::windowDecorationsButtonsImages() const | ||||
181 | { | ||||
182 | static const QVector<QString> buttonTypes { | ||||
183 | QStringLiteral("close"), | ||||
184 | QStringLiteral("maximize"), | ||||
185 | QStringLiteral("maximized"), | ||||
186 | QStringLiteral("minimize"), | ||||
187 | }; | ||||
188 | | ||||
189 | static const QVector<QString> buttonStates { | ||||
190 | QStringLiteral("normal"), | ||||
191 | QStringLiteral("active"), // aka pressed | ||||
192 | QStringLiteral("hover"), | ||||
193 | }; | ||||
194 | | ||||
195 | KConfigGroup decorationGroup = kwinConfig->group(QStringLiteral("org.kde.kdecoration2")); | ||||
196 | const QString themeName = decorationGroup.readEntry(QStringLiteral("theme"), QStringLiteral("Breeze")); | ||||
197 | | ||||
198 | KDecoration2::DummyDecorationBridge kwinBridge {themeName}; | ||||
199 | QStringList decorationsImages {}; | ||||
200 | | ||||
201 | for (const auto &buttonType : buttonTypes) { | ||||
202 | for (const auto &buttonState : buttonStates) { | ||||
203 | QSvgGenerator svgGenerator {}; | ||||
204 | | ||||
205 | const QString fileDirPath = QDir::tempPath() + QStringLiteral("/plasma-csd-generator"); | ||||
206 | QDir(fileDirPath).mkpath(QStringLiteral(".")); | ||||
207 | QString filePath = QStringLiteral("%1/%2-%3.svg").arg(fileDirPath, buttonType, buttonState); | ||||
208 | | ||||
209 | svgGenerator.setFileName(filePath); | ||||
210 | svgGenerator.setViewBox(KDecoration2::DummyDecorationBridge::ButtonGeometry); | ||||
211 | | ||||
212 | QPainter painter {&svgGenerator}; | ||||
213 | kwinBridge.paintButton(painter, buttonType, buttonState); | ||||
214 | painter.end(); | ||||
215 | | ||||
216 | decorationsImages.append(filePath); | ||||
217 | } | ||||
218 | } | ||||
219 | | ||||
220 | return decorationsImages; | ||||
221 | } | ||||
222 | | ||||
177 | QString ConfigValueProvider::windowDecorationsButtonsOrder() const | 223 | QString ConfigValueProvider::windowDecorationsButtonsOrder() const | ||
178 | { | 224 | { | ||
179 | KConfigGroup configGroup = kwinConfig->group(QStringLiteral("org.kde.kdecoration2")); | 225 | KConfigGroup configGroup = kwinConfig->group(QStringLiteral("org.kde.kdecoration2")); | ||
180 | QString buttonsOnLeftKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnLeft"), "MS"); | 226 | QString buttonsOnLeftKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnLeft"), "MS"); | ||
181 | QString buttonsOnRightKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnRight"), "HIAX"); | 227 | QString buttonsOnRightKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnRight"), "HIAX"); | ||
182 | 228 | | |||
183 | QString buttonsOnLeftInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnLeftKdeConfigValue); | 229 | QString buttonsOnLeftInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnLeftKdeConfigValue); | ||
184 | QString buttonsOnRightInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnRightKdeConfigValue); | 230 | QString buttonsOnRightInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnRightKdeConfigValue); | ||
▲ Show 20 Lines • Show All 226 Lines • Show Last 20 Lines |