Changeset View
Changeset View
Standalone View
Standalone View
kcms/colors/colorscm.cpp
1 | /* KDE Display color scheme setup module | 1 | /* KDE Display color scheme setup module | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> | 2 | * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> | ||
3 | * Copyright (C) 2007 Jeremy Whiting <jpwhiting@kde.org> | 3 | * Copyright (C) 2007 Jeremy Whiting <jpwhiting@kde.org> | ||
4 | * Copyright (C) 2016 Olivier Churlaud <olivier@churlaud.com> | ||||
4 | * | 5 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by | ||
Context not available. | |||||
21 | #include "colorscm.h" | 22 | #include "colorscm.h" | ||
22 | 23 | | |||
23 | #include "../krdb/krdb.h" | 24 | #include "../krdb/krdb.h" | ||
25 | #include "scmeditordialog.h" | ||||
24 | 26 | | |||
25 | #include <QFileInfo> | 27 | #include <QFileInfo> | ||
26 | #include <QFileDialog> | 28 | #include <QFileDialog> | ||
27 | #include <QTimer> | | |||
28 | #include <QHeaderView> | 29 | #include <QHeaderView> | ||
29 | #include <QInputDialog> | 30 | #include <QInputDialog> | ||
30 | #include <QStackedWidget> | 31 | #include <QStackedWidget> | ||
Context not available. | |||||
32 | #include <QPainter> | 33 | #include <QPainter> | ||
33 | #include <QBitmap> | 34 | #include <QBitmap> | ||
34 | #include <QtDBus/QtDBus> | 35 | #include <QtDBus/QtDBus> | ||
35 | #include <QColorDialog> | | |||
36 | 36 | | |||
37 | #include <KAboutData> | 37 | #include <KAboutData> | ||
38 | #include <KColorButton> | 38 | #include <KColorButton> | ||
Context not available. | |||||
43 | #include <KPluginFactory> | 43 | #include <KPluginFactory> | ||
44 | #include <KJobUiDelegate> | 44 | #include <KJobUiDelegate> | ||
45 | #include <KIO/DeleteJob> | 45 | #include <KIO/DeleteJob> | ||
46 | #include <KNewStuff3/KNS3/DownloadDialog> | 46 | #include <KNS3/DownloadDialog> | ||
47 | #include <KNewStuff3/KNS3/UploadDialog> | | |||
48 | 47 | | |||
49 | K_PLUGIN_FACTORY( KolorFactory, registerPlugin<KColorCm>(); ) | 48 | K_PLUGIN_FACTORY( KolorFactory, registerPlugin<KColorCm>(); ) | ||
50 | K_EXPORT_PLUGIN( KolorFactory("kcmcolors") ) | 49 | K_EXPORT_PLUGIN( KolorFactory("kcmcolors") ) | ||
51 | 50 | | |||
52 | //BEGIN WindecoColors | | |||
53 | KColorCm::WindecoColors::WindecoColors(const KSharedConfigPtr &config) | | |||
54 | { | | |||
55 | load(config); | | |||
56 | } | | |||
57 | | ||||
58 | void KColorCm::WindecoColors::load(const KSharedConfigPtr &config) | | |||
59 | { | | |||
60 | // NOTE: keep this in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp | | |||
61 | KConfigGroup group(config, "WM"); | | |||
62 | m_colors[ActiveBackground] = group.readEntry("activeBackground", QColor(48, 174, 232)); | | |||
63 | m_colors[ActiveForeground] = group.readEntry("activeForeground", QColor(255, 255, 255)); | | |||
64 | m_colors[InactiveBackground] = group.readEntry("inactiveBackground", QColor(224, 223, 222)); | | |||
65 | m_colors[InactiveForeground] = group.readEntry("inactiveForeground", QColor(75, 71, 67)); | | |||
66 | m_colors[ActiveBlend] = group.readEntry("activeBlend", m_colors[ActiveForeground]); | | |||
67 | m_colors[InactiveBlend] = group.readEntry("inactiveBlend", m_colors[InactiveForeground]); | | |||
68 | } | | |||
69 | | ||||
70 | QColor KColorCm::WindecoColors::color(WindecoColors::Role role) const | | |||
71 | { | | |||
72 | return m_colors[role]; | | |||
73 | } | | |||
74 | //END WindecoColors | | |||
75 | | ||||
76 | KColorCm::KColorCm(QWidget *parent, const QVariantList &) | 51 | KColorCm::KColorCm(QWidget *parent, const QVariantList &) | ||
77 | : KCModule( parent ), m_disableUpdates(false), | 52 | : KCModule( parent ), | ||
78 | m_loadedSchemeHasUnsavedChanges(false), m_dontLoadSelectedScheme(false), | 53 | m_dontLoadSelectedScheme(false), | ||
79 | m_previousSchemeItem(0) | 54 | m_previousSchemeItem(0) | ||
80 | { | 55 | { | ||
81 | KAboutData* about = new KAboutData( | 56 | KAboutData* about = new KAboutData( | ||
Context not available. | |||||
91 | m_config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); | 66 | m_config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); | ||
92 | 67 | | |||
93 | setupUi(this); | 68 | setupUi(this); | ||
94 | schemeKnsButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); | 69 | connect(applyToAlien, &QCheckBox::toggled, [=](){ emit changed(true); }); | ||
95 | schemeKnsUploadButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); | | |||
96 | connect(colorSet, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KColorCm::updateColorTable); | | |||
97 | connect(schemeList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), | 70 | connect(schemeList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), | ||
98 | this, SLOT(loadScheme(QListWidgetItem*,QListWidgetItem*))); | 71 | this, SLOT(loadScheme(QListWidgetItem*,QListWidgetItem*))); | ||
99 | connect(applyToAlien, &QCheckBox::toggled, this, &KColorCm::emitChanged); | 72 | schemeKnsButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); | ||
100 | | ||||
101 | // only needs to be called once | | |||
102 | setupColorTable(); | | |||
103 | } | 73 | } | ||
104 | 74 | | |||
105 | KColorCm::~KColorCm() | 75 | KColorCm::~KColorCm() | ||
Context not available. | |||||
156 | icon = createSchemePreviewIcon(m_config); | 126 | icon = createSchemePreviewIcon(m_config); | ||
157 | schemeList->insertItem(0, new QListWidgetItem(icon, i18nc("Default color scheme", "Default"))); | 127 | schemeList->insertItem(0, new QListWidgetItem(icon, i18nc("Default color scheme", "Default"))); | ||
158 | m_config->setReadDefaults(false); | 128 | m_config->setReadDefaults(false); | ||
159 | | ||||
160 | // add current scheme entry | | |||
161 | icon = createSchemePreviewIcon(m_config); | | |||
162 | QListWidgetItem *currentitem = new QListWidgetItem(icon, i18nc("Current color scheme", "Current")); | | |||
163 | schemeList->insertItem(0, currentitem); | | |||
164 | schemeList->blockSignals(true); // don't emit changed signals | | |||
165 | schemeList->setCurrentItem(currentitem); | | |||
166 | schemeList->blockSignals(false); | | |||
167 | } | | |||
168 | | ||||
169 | void KColorCm::updatePreviews() | | |||
170 | { | | |||
171 | schemePreview->setPalette(m_config); | | |||
172 | colorPreview->setPalette(m_config); | | |||
173 | // setPreview->setPalette(m_config, (KColorScheme::ColorSet)(colorSet->currentIndex() - 1)); | | |||
174 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
175 | disabledPreview->setPalette(m_config, QPalette::Disabled); | | |||
176 | } | 129 | } | ||
177 | 130 | | |||
178 | void KColorCm::updateEffectsPage() | | |||
179 | { | | |||
180 | m_disableUpdates = true; | | |||
181 | | ||||
182 | // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp | | |||
183 | KConfigGroup groupI(m_config, "ColorEffects:Inactive"); | | |||
184 | inactiveIntensityBox->setCurrentIndex(abs(groupI.readEntry("IntensityEffect", 0))); | | |||
185 | inactiveIntensitySlider->setValue(int(groupI.readEntry("IntensityAmount", 0.0) * 20.0) + 20); | | |||
186 | inactiveColorBox->setCurrentIndex(abs(groupI.readEntry("ColorEffect", 2))); | | |||
187 | if (inactiveColorBox->currentIndex() > 1) | | |||
188 | { | | |||
189 | inactiveColorSlider->setValue(int(groupI.readEntry("ColorAmount", 0.025) * 40.0)); | | |||
190 | } | | |||
191 | else | | |||
192 | { | | |||
193 | inactiveColorSlider->setValue(int(groupI.readEntry("ColorAmount", 0.05) * 20.0) + 20); | | |||
194 | } | | |||
195 | inactiveColorButton->setColor(groupI.readEntry("Color", QColor(112, 111, 110))); | | |||
196 | inactiveContrastBox->setCurrentIndex(abs(groupI.readEntry("ContrastEffect", 2))); | | |||
197 | inactiveContrastSlider->setValue(int(groupI.readEntry("ContrastAmount", 0.1) * 20.0)); | | |||
198 | | ||||
199 | // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp | | |||
200 | KConfigGroup groupD(m_config, "ColorEffects:Disabled"); | | |||
201 | disabledIntensityBox->setCurrentIndex(groupD.readEntry("IntensityEffect", 2)); | | |||
202 | disabledIntensitySlider->setValue(int(groupD.readEntry("IntensityAmount", 0.1) * 20.0) + 20); | | |||
203 | disabledColorBox->setCurrentIndex(groupD.readEntry("ColorEffect", 0)); | | |||
204 | if (disabledColorBox->currentIndex() > 1) | | |||
205 | { | | |||
206 | disabledColorSlider->setValue(int(groupD.readEntry("ColorAmount", 0.0) * 40.0)); | | |||
207 | } | | |||
208 | else | | |||
209 | { | | |||
210 | disabledColorSlider->setValue(int(groupD.readEntry("ColorAmount", 0.0) * 20.0) + 20); | | |||
211 | } | | |||
212 | disabledColorButton->setColor(groupD.readEntry("Color", QColor(56, 56, 56))); | | |||
213 | disabledContrastBox->setCurrentIndex(groupD.readEntry("ContrastEffect", 1)); | | |||
214 | disabledContrastSlider->setValue(int(groupD.readEntry("ContrastAmount", 0.65) * 20.0)); | | |||
215 | | ||||
216 | m_disableUpdates = false; | | |||
217 | | ||||
218 | // enable/disable controls | | |||
219 | inactiveIntensitySlider->setDisabled(inactiveIntensityBox->currentIndex() == 0); | | |||
220 | disabledIntensitySlider->setDisabled(disabledIntensityBox->currentIndex() == 0); | | |||
221 | inactiveColorSlider->setDisabled(inactiveColorBox->currentIndex() == 0); | | |||
222 | disabledColorSlider->setDisabled(disabledColorBox->currentIndex() == 0); | | |||
223 | inactiveColorButton->setDisabled(inactiveColorBox->currentIndex() < 2); | | |||
224 | disabledColorButton->setDisabled(disabledColorBox->currentIndex() < 2); | | |||
225 | inactiveContrastSlider->setDisabled(inactiveContrastBox->currentIndex() == 0); | | |||
226 | disabledContrastSlider->setDisabled(disabledContrastBox->currentIndex() == 0); | | |||
227 | } | | |||
228 | 131 | | |||
229 | void KColorCm::loadScheme(KSharedConfigPtr config) // const QString &path) | 132 | void KColorCm::loadScheme(KSharedConfigPtr config) // const QString &path) | ||
230 | { | 133 | { | ||
231 | KSharedConfigPtr temp = m_config; | 134 | schemePreview->setPalette(config); | ||
232 | m_config = config; | 135 | updateConfig(config); | ||
233 | | ||||
234 | updateColorSchemes(); | | |||
235 | updateEffectsPage(); // intentionally before swapping back m_config | | |||
236 | updatePreviews(); | | |||
237 | | ||||
238 | m_config = temp; | | |||
239 | updateFromColorSchemes(); | | |||
240 | updateFromEffectsPage(); | | |||
241 | updateFromOptions(); | | |||
242 | updateColorTable(); | | |||
243 | | ||||
244 | m_loadedSchemeHasUnsavedChanges = false; | | |||
245 | //m_changed = false; | | |||
246 | } | 136 | } | ||
247 | 137 | | |||
248 | void KColorCm::selectPreviousSchemeAgain() | 138 | void KColorCm::selectPreviousSchemeAgain() | ||
Context not available. | |||||
258 | 148 | | |||
259 | if (m_dontLoadSelectedScheme) | 149 | if (m_dontLoadSelectedScheme) | ||
260 | { | 150 | { | ||
151 | qDebug() << "dontload"; | ||||
261 | return; | 152 | return; | ||
262 | } | 153 | } | ||
263 | 154 | | |||
264 | if (currentItem != NULL) | 155 | if (currentItem != NULL) | ||
265 | { | 156 | { | ||
266 | if (m_loadedSchemeHasUnsavedChanges) // if changes made to loaded scheme | | |||
267 | { | | |||
268 | if (KMessageBox::Continue != KMessageBox::warningContinueCancel(this, | | |||
269 | i18n("Selecting another scheme will discard any changes you have made"), | | |||
270 | i18n("Are you sure?"), | | |||
271 | KStandardGuiItem::cont(), | | |||
272 | KStandardGuiItem::cancel(), | | |||
273 | QStringLiteral("noDiscardWarning"))) // if the user decides to cancel | | |||
274 | { | | |||
275 | QTimer::singleShot(0, this, &KColorCm::selectPreviousSchemeAgain); | | |||
276 | return; | | |||
277 | } | | |||
278 | } | | |||
279 | | ||||
280 | // load it | 157 | // load it | ||
281 | | ||||
282 | const QString name = currentItem->text(); | 158 | const QString name = currentItem->text(); | ||
283 | m_currentColorScheme = name; | 159 | m_currentColorScheme = name; | ||
284 | const QString fileBaseName = currentItem->data(Qt::UserRole).toString(); | 160 | const QString fileBaseName = currentItem->data(Qt::UserRole).toString(); | ||
285 | if (name == i18nc("Default color scheme", "Default")) | 161 | if (name == i18nc("Default color scheme", "Default")) | ||
286 | { | 162 | { | ||
287 | schemeRemoveButton->setEnabled(false); | 163 | schemeRemoveButton->setEnabled(false); | ||
288 | schemeKnsUploadButton->setEnabled(false); | | |||
289 | 164 | | |||
290 | KSharedConfigPtr config = m_config; | 165 | KSharedConfigPtr config = m_config; | ||
291 | config->setReadDefaults(true); | 166 | config->setReadDefaults(true); | ||
Context not available. | |||||
294 | // load the default scheme | 169 | // load the default scheme | ||
295 | emit changed(true); | 170 | emit changed(true); | ||
296 | } | 171 | } | ||
297 | else if (name == i18nc("Current color scheme", "Current")) | | |||
298 | { | | |||
299 | schemeRemoveButton->setEnabled(false); | | |||
300 | schemeKnsUploadButton->setEnabled(false); | | |||
301 | loadInternal(false); | | |||
302 | } | | |||
303 | else | 172 | else | ||
304 | { | 173 | { | ||
305 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | 174 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | ||
Context not available. | |||||
309 | const bool canWrite = (permissions & QFile::WriteUser); | 178 | const bool canWrite = (permissions & QFile::WriteUser); | ||
310 | qDebug() << "checking permissions of " << path; | 179 | qDebug() << "checking permissions of " << path; | ||
311 | schemeRemoveButton->setEnabled(canWrite); | 180 | schemeRemoveButton->setEnabled(canWrite); | ||
312 | schemeKnsUploadButton->setEnabled(true); | | |||
313 | 181 | | |||
314 | KSharedConfigPtr config = KSharedConfig::openConfig(path); | 182 | KSharedConfigPtr config = KSharedConfig::openConfig(path); | ||
315 | loadScheme(config); | 183 | loadScheme(config); | ||
Context not available. | |||||
327 | "color-schemes/" + schemeList->currentItem()->data(Qt::UserRole).toString() + | 195 | "color-schemes/" + schemeList->currentItem()->data(Qt::UserRole).toString() + | ||
328 | ".colors"); | 196 | ".colors"); | ||
329 | KIO::DeleteJob *job = KIO::del(QUrl::fromLocalFile(path)); | 197 | KIO::DeleteJob *job = KIO::del(QUrl::fromLocalFile(path)); | ||
198 | qDebug() << path; | ||||
330 | job->uiDelegate()->setParent(this); | 199 | job->uiDelegate()->setParent(this); | ||
331 | if (job->exec()) | 200 | if (job->exec()) | ||
332 | { | 201 | { | ||
Context not available. | |||||
345 | // get the path to the scheme to import | 214 | // get the path to the scheme to import | ||
346 | QUrl url = QUrl::fromLocalFile(QFileDialog::getOpenFileName(this, i18n("Import Color Scheme"))); | 215 | QUrl url = QUrl::fromLocalFile(QFileDialog::getOpenFileName(this, i18n("Import Color Scheme"))); | ||
347 | 216 | | |||
348 | if(url.isValid()) | 217 | if(!url.isValid()) | ||
349 | { | | |||
350 | // TODO: possibly untar or uncompress it | | |||
351 | // open it | | |||
352 | | ||||
353 | // load the scheme | | |||
354 | KSharedConfigPtr config = KSharedConfig::openConfig(url.path()); | | |||
355 | | ||||
356 | if (config->groupList().contains(QStringLiteral("Color Scheme"))) | | |||
357 | { | | |||
358 | if (KMessageBox::Continue != KMessageBox::warningContinueCancel(this, | | |||
359 | i18n("The scheme you have selected appears to be a KDE3 scheme.\n\n" | | |||
360 | "KDE will attempt to import this scheme, however many color roles have been added since KDE3. " | | |||
361 | "Some manual work will likely be required.\n\n" | | |||
362 | "This scheme will not be saved automatically."), | | |||
363 | i18n("Notice"))) | | |||
364 | { | | |||
365 | return; | | |||
366 | } | | |||
367 | | ||||
368 | // convert KDE3 scheme to new scheme | | |||
369 | KConfigGroup g(config, "Color Scheme"); | | |||
370 | KConfigGroup generalGroup(KSharedConfig::openConfig(), "General"); | | |||
371 | | ||||
372 | colorSet->setCurrentIndex(0); | | |||
373 | contrastSlider->setValue(g.readEntry("contrast", KColorScheme::contrast())); | | |||
374 | shadeSortedColumn->setChecked(g.readEntry("shadeSortColumn", generalGroup.readEntry("shadeSortColumn", true))); | | |||
375 | | ||||
376 | m_commonColorButtons[0]->setColor(g.readEntry("windowBackground", m_colorSchemes[KColorScheme::View].background().color())); | | |||
377 | m_commonColorButtons[1]->setColor(g.readEntry("windowForeground", m_colorSchemes[KColorScheme::View].foreground().color())); | | |||
378 | m_commonColorButtons[2]->setColor(g.readEntry("background", m_colorSchemes[KColorScheme::Window].background().color())); | | |||
379 | m_commonColorButtons[3]->setColor(g.readEntry("foreground", m_colorSchemes[KColorScheme::Window].foreground().color())); | | |||
380 | m_commonColorButtons[4]->setColor(g.readEntry("buttonBackground", m_colorSchemes[KColorScheme::Button].background().color())); | | |||
381 | m_commonColorButtons[5]->setColor(g.readEntry("buttonForeground", m_colorSchemes[KColorScheme::Button].foreground().color())); | | |||
382 | m_commonColorButtons[6]->setColor(g.readEntry("selectBackground", m_colorSchemes[KColorScheme::Selection].background().color())); | | |||
383 | m_commonColorButtons[7]->setColor(g.readEntry("selectForeground", m_colorSchemes[KColorScheme::Selection].foreground().color())); | | |||
384 | m_commonColorButtons[8]->setColor(KColorUtils::mix(m_colorSchemes[KColorScheme::Selection].foreground().color(), | | |||
385 | m_colorSchemes[KColorScheme::Selection].background().color())); | | |||
386 | m_commonColorButtons[9]->setColor(KColorUtils::mix(m_colorSchemes[KColorScheme::View].foreground().color(), | | |||
387 | m_colorSchemes[KColorScheme::View].background().color())); | | |||
388 | // doesn't exist in KDE3: 10 ActiveText | | |||
389 | m_commonColorButtons[11]->setColor(g.readEntry("linkColor", m_colorSchemes[KColorScheme::View].foreground(KColorScheme::LinkText).color())); | | |||
390 | m_commonColorButtons[12]->setColor(g.readEntry("visitedLinkColor", m_colorSchemes[KColorScheme::View].foreground(KColorScheme::VisitedText).color())); | | |||
391 | // doesn't exist in KDE3: 13-15 PositiveText, NeutralText, NegativeText | | |||
392 | m_commonColorButtons[16]->setColor(g.readEntry("windowForeground", m_colorSchemes[KColorScheme::View].decoration(KColorScheme::FocusColor).color())); | | |||
393 | m_commonColorButtons[17]->setColor(g.readEntry("selectBackground", m_colorSchemes[KColorScheme::View].decoration(KColorScheme::HoverColor).color())); | | |||
394 | m_commonColorButtons[18]->setColor(g.readEntry("windowBackground", m_colorSchemes[KColorScheme::Tooltip].background().color())); | | |||
395 | m_commonColorButtons[19]->setColor(g.readEntry("windowForeground", m_colorSchemes[KColorScheme::Tooltip].foreground().color())); | | |||
396 | m_commonColorButtons[20]->setColor(g.readEntry("activeBackground", m_wmColors.color(WindecoColors::ActiveBackground))); | | |||
397 | m_commonColorButtons[21]->setColor(g.readEntry("activeForeground", m_wmColors.color(WindecoColors::ActiveForeground))); | | |||
398 | m_commonColorButtons[22]->setColor(g.readEntry("activeBlend", m_wmColors.color(WindecoColors::ActiveBlend))); | | |||
399 | m_commonColorButtons[23]->setColor(g.readEntry("inactiveBackground", m_wmColors.color(WindecoColors::InactiveBackground))); | | |||
400 | m_commonColorButtons[24]->setColor(g.readEntry("inactiveForeground", m_wmColors.color(WindecoColors::InactiveForeground))); | | |||
401 | m_commonColorButtons[25]->setColor(g.readEntry("inactiveBlend", m_wmColors.color(WindecoColors::InactiveBlend))); | | |||
402 | | ||||
403 | colorSet->setCurrentIndex(1); | | |||
404 | m_backgroundButtons[KColorScheme::AlternateBackground]->setColor(g.readEntry("alternateBackground", | | |||
405 | m_colorSchemes[KColorScheme::View].background(KColorScheme::AlternateBackground).color())); | | |||
406 | colorSet->setCurrentIndex(0); | | |||
407 | } | | |||
408 | else | | |||
409 | { | | |||
410 | // load scheme | | |||
411 | loadScheme(config); | | |||
412 | | ||||
413 | // save it | | |||
414 | saveScheme(url.fileName()); | | |||
415 | } | | |||
416 | } | | |||
417 | } | | |||
418 | | ||||
419 | void KColorCm::on_schemeKnsButton_clicked() | | |||
420 | { | | |||
421 | KNS3::DownloadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); | | |||
422 | dialog.exec(); | | |||
423 | if ( ! dialog.changedEntries().isEmpty() ) | | |||
424 | { | 218 | { | ||
425 | populateSchemeList(); | 219 | return; | ||
426 | } | 220 | } | ||
427 | } | 221 | // TODO: possibly untar or uncompress it | ||
428 | 222 | // open it | |||
429 | void KColorCm::on_schemeKnsUploadButton_clicked() | | |||
430 | { | | |||
431 | if (schemeList->currentItem() != NULL) | | |||
432 | { | | |||
433 | // check if the currently loaded scheme has unsaved changes | | |||
434 | if (m_loadedSchemeHasUnsavedChanges) | | |||
435 | { | | |||
436 | KMessageBox::sorry(this, i18n("Please save the color scheme before uploading it."), | | |||
437 | i18n("Please save")); | | |||
438 | return; | | |||
439 | } | | |||
440 | 223 | | |||
441 | // find path | 224 | // load the scheme | ||
442 | const QString basename = schemeList->currentItem()->data(Qt::UserRole).toString(); | 225 | KSharedConfigPtr config = KSharedConfig::openConfig(url.path()); | ||
443 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | | |||
444 | "color-schemes/" + basename + ".colors"); | | |||
445 | if (path.isEmpty() ) // if the color scheme file wasn't found | | |||
446 | { | | |||
447 | qDebug() << "path for color scheme " << basename << " couldn't be found"; | | |||
448 | return; | | |||
449 | } | | |||
450 | | ||||
451 | // upload | | |||
452 | KNS3::UploadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); | | |||
453 | dialog.setUploadFile(QUrl::fromLocalFile(path) ); | | |||
454 | dialog.exec(); | | |||
455 | } | | |||
456 | } | | |||
457 | 226 | | |||
458 | void KColorCm::on_schemeSaveButton_clicked() | 227 | if (config->groupList().contains(QStringLiteral("Color Scheme"))) | ||
459 | { | | |||
460 | QString previousName; | | |||
461 | if (schemeList->currentItem() != NULL && schemeList->currentRow() > 1) | | |||
462 | { | | |||
463 | previousName = schemeList->currentItem()->data(Qt::DisplayRole).toString(); | | |||
464 | } | | |||
465 | // prompt for the name to save as | | |||
466 | bool ok; | | |||
467 | QString name = QInputDialog::getText(this, i18n("Save Color Scheme"), | | |||
468 | i18n("&Enter a name for the color scheme:"), QLineEdit::Normal, previousName, &ok); | | |||
469 | if (ok) | | |||
470 | { | 228 | { | ||
471 | saveScheme(name); | 229 | KMessageBox::sorry(this, | ||
230 | i18n("The scheme you have selected appears to be a KDE3 scheme.\n\n" | ||||
231 | "This is not supported anymore."), | ||||
232 | i18n("Notice")); | ||||
233 | return; | ||||
472 | } | 234 | } | ||
473 | } | | |||
474 | 235 | | |||
475 | void KColorCm::saveScheme(const QString &name) | 236 | // Do not overwrite another scheme | ||
476 | { | 237 | KConfigGroup group(config, "General"); | ||
477 | QString filename = name; | 238 | QString name = group.readEntry("Name"); | ||
478 | filename.remove('\''); // So Foo's does not become FooS | | |||
479 | QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); | | |||
480 | int offset; | | |||
481 | while ((offset = fixer.indexIn(filename)) >= 0) | | |||
482 | filename.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); | | |||
483 | filename.replace(0, 1, filename.at(0).toUpper()); | | |||
484 | | ||||
485 | // check if that name is already in the list | | |||
486 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | | |||
487 | "color-schemes/" + filename + ".colors"); | | |||
488 | 239 | | |||
489 | QFile file(path); | 240 | int increment = 0; | ||
490 | const int permissions = file.permissions(); | 241 | QString newName = name; | ||
491 | const bool canWrite = (permissions & QFile::WriteUser); | 242 | QString testpath = ""; | ||
492 | // or if we can overwrite it if it exists | 243 | do | ||
493 | if (path.isEmpty() || !file.exists() || canWrite) | | |||
494 | { | 244 | { | ||
495 | if(canWrite){ | 245 | if (increment) { | ||
496 | int ret = KMessageBox::questionYesNo(this, | 246 | newName = name + QString::number(increment); | ||
497 | i18n("A color scheme with that name already exists.\nDo you want to overwrite it?"), | | |||
498 | i18n("Save Color Scheme"), | | |||
499 | KStandardGuiItem::overwrite(), | | |||
500 | KStandardGuiItem::cancel()); | | |||
501 | //on don't overwrite, select the already existing name. | | |||
502 | if(ret == KMessageBox::No){ | | |||
503 | QList<QListWidgetItem*> foundItems = schemeList->findItems(name, Qt::MatchExactly); | | |||
504 | if (foundItems.size() == 1) | | |||
505 | schemeList->setCurrentRow(schemeList->row(foundItems[0])); | | |||
506 | return; | | |||
507 | } | | |||
508 | } | | |||
509 | | ||||
510 | // go ahead and save it | | |||
511 | QString newpath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) | | |||
512 | + "/color-schemes/"; | | |||
513 | QDir dir; | | |||
514 | dir.mkpath(newpath); | | |||
515 | newpath += filename + ".colors"; | | |||
516 | KSharedConfigPtr temp = m_config; | | |||
517 | m_config = KSharedConfig::openConfig(newpath); | | |||
518 | // then copy current colors into new config | | |||
519 | updateFromColorSchemes(); | | |||
520 | updateFromEffectsPage(); | | |||
521 | KConfigGroup group(m_config, "General"); | | |||
522 | group.writeEntry("Name", name); | | |||
523 | // sync it | | |||
524 | m_config->sync(); | | |||
525 | | ||||
526 | m_loadedSchemeHasUnsavedChanges = false; | | |||
527 | | ||||
528 | QList<QListWidgetItem*> foundItems = schemeList->findItems(name, Qt::MatchExactly); | | |||
529 | QIcon icon = createSchemePreviewIcon(m_config); | | |||
530 | if (foundItems.size() < 1) | | |||
531 | { | | |||
532 | // add it to the list since it's not in there already | | |||
533 | populateSchemeList(); | | |||
534 | | ||||
535 | // then select the new item | | |||
536 | schemeList->setCurrentItem(schemeList->findItems(name, Qt::MatchExactly).at(0)); | | |||
537 | } | | |||
538 | else | | |||
539 | { | | |||
540 | // update the icon of the one that's in the list | | |||
541 | foundItems[0]->setIcon(icon); | | |||
542 | schemeList->setCurrentRow(schemeList->row(foundItems[0])); | | |||
543 | } | 247 | } | ||
248 | testpath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | ||||
249 | "color-schemes/" + newName + ".colors"); | ||||
250 | increment++; | ||||
251 | } while (!testpath.isEmpty()); | ||||
544 | 252 | | |||
545 | // set m_config back to the system one | 253 | QString newpath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) | ||
546 | m_config = temp; | 254 | + "/color-schemes/"; | ||
255 | QDir dir; | ||||
256 | dir.mkpath(newpath); | ||||
257 | newpath += newName + ".colors"; | ||||
258 | QFile::copy(url.toLocalFile(), newpath); | ||||
547 | 259 | | |||
548 | // store colorscheme name in global settings | 260 | // Update name | ||
549 | m_currentColorScheme = name; | 261 | KSharedConfigPtr config2 = KSharedConfig::openConfig(newpath); | ||
550 | group = KConfigGroup(m_config, "General"); | 262 | KConfigGroup group2(config2, "General"); | ||
551 | group.writeEntry("ColorScheme", m_currentColorScheme); | 263 | group2.writeEntry("Name", newName); | ||
264 | config2->sync(); | ||||
552 | 265 | | |||
553 | emit changed(true); | 266 | this->populateSchemeList(); | ||
554 | } | 267 | QList<QListWidgetItem*> itemList = schemeList->findItems(newName, Qt::MatchExactly); | ||
555 | else if (!canWrite && file.exists()) | 268 | if (!itemList.isEmpty()) | ||
556 | { | 269 | { | ||
557 | // give error message if !canWrite && file.exists() | 270 | schemeList->setCurrentItem(itemList.first()); | ||
558 | KMessageBox::error(this, i18n("You do not have permission to overwrite that scheme"), i18n("Error")); | | |||
559 | } | 271 | } | ||
560 | } | 272 | } | ||
561 | 273 | | |||
562 | void KColorCm::createColorEntry(const QString &text, const QString &key, QList<KColorButton *> &list, int index) | 274 | void KColorCm::on_schemeKnsButton_clicked() | ||
563 | { | | |||
564 | KColorButton *button = new KColorButton(this); | | |||
565 | button->setObjectName(QString::number(index)); | | |||
566 | connect(button, &KColorButton::changed, this, &KColorCm::colorChanged); | | |||
567 | list.append(button); | | |||
568 | | ||||
569 | m_colorKeys.insert(index, key); | | |||
570 | | ||||
571 | QTableWidgetItem *label = new QTableWidgetItem(text); | | |||
572 | colorTable->setItem(index, 0, label); | | |||
573 | colorTable->setCellWidget(index, 1, button); | | |||
574 | colorTable->setRowHeight(index, button->sizeHint().height()); | | |||
575 | } | | |||
576 | | ||||
577 | void KColorCm::variesClicked() | | |||
578 | { | 275 | { | ||
579 | // find which button was changed | 276 | KNS3::DownloadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); | ||
580 | const int row = sender()->objectName().toInt(); | 277 | dialog.exec(); | ||
581 | 278 | if ( ! dialog.changedEntries().isEmpty() ) | |||
582 | QColor color = QColorDialog::getColor(QColor(), this); | | |||
583 | if(color.isValid()) | | |||
584 | { | 279 | { | ||
585 | changeColor(row, color); | 280 | populateSchemeList(); | ||
586 | m_stackedWidgets[row - 9]->setCurrentIndex(0); | 281 | for ( auto t : dialog.installedEntries()) | ||
282 | qDebug() << t.name(); | ||||
587 | } | 283 | } | ||
588 | } | 284 | } | ||
589 | 285 | | |||
590 | QPixmap KColorCm::createSchemePreviewIcon(const KSharedConfigPtr &config) | 286 | QPixmap KColorCm::createSchemePreviewIcon(const KSharedConfigPtr &config) | ||
591 | { | 287 | { | ||
592 | const WindecoColors wm(config); | | |||
593 | const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b }; | 288 | const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b }; | ||
594 | const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff }; | 289 | const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff }; | ||
595 | const QSize bitsSize(24,2); | 290 | const QSize bitsSize(24,2); | ||
Context not available. | |||||
601 | 296 | | |||
602 | QPainter p(&pixmap); | 297 | QPainter p(&pixmap); | ||
603 | 298 | | |||
299 | KConfigGroup group(config, "WM"); | ||||
300 | // NOTE: keep this in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp | ||||
301 | QColor activeBackground = group.readEntry("activeBackground", QColor(48, 174, 232)); | ||||
302 | QColor activeForeground = group.readEntry("activeForeground", QColor(255, 255, 255)); | ||||
303 | QColor inactiveBackground = group.readEntry("inactiveBackground", QColor(224, 223, 222)); | ||||
304 | QColor inactiveForeground = group.readEntry("inactiveForeground", QColor(75, 71, 67)); | ||||
305 | | ||||
604 | KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config); | 306 | KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config); | ||
605 | p.fillRect( 1, 1, 7, 7, windowScheme.background()); | 307 | p.fillRect( 1, 1, 7, 7, windowScheme.background()); | ||
606 | p.fillRect( 2, 2, 5, 2, QBrush(windowScheme.foreground().color(), b1)); | 308 | p.fillRect( 2, 2, 5, 2, QBrush(windowScheme.foreground().color(), b1)); | ||
Context not available. | |||||
609 | p.fillRect( 8, 1, 7, 7, buttonScheme.background()); | 311 | p.fillRect( 8, 1, 7, 7, buttonScheme.background()); | ||
610 | p.fillRect( 9, 2, 5, 2, QBrush(buttonScheme.foreground().color(), b1)); | 312 | p.fillRect( 9, 2, 5, 2, QBrush(buttonScheme.foreground().color(), b1)); | ||
611 | 313 | | |||
612 | p.fillRect(15, 1, 7, 7, wm.color(WindecoColors::ActiveBackground)); | 314 | p.fillRect(15, 1, 7, 7, activeBackground); | ||
613 | p.fillRect(16, 2, 5, 2, QBrush(wm.color(WindecoColors::ActiveForeground), b1)); | 315 | p.fillRect(16, 2, 5, 2, QBrush(activeForeground, b1)); | ||
614 | 316 | | |||
615 | KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config); | 317 | KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config); | ||
616 | p.fillRect( 1, 8, 7, 7, viewScheme.background()); | 318 | p.fillRect( 1, 8, 7, 7, viewScheme.background()); | ||
Context not available. | |||||
620 | p.fillRect( 8, 8, 7, 7, selectionScheme.background()); | 322 | p.fillRect( 8, 8, 7, 7, selectionScheme.background()); | ||
621 | p.fillRect( 9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2)); | 323 | p.fillRect( 9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2)); | ||
622 | 324 | | |||
623 | p.fillRect(15, 8, 7, 7, wm.color(WindecoColors::InactiveBackground)); | 325 | p.fillRect(15, 8, 7, 7, inactiveBackground); | ||
624 | p.fillRect(16, 12, 5, 2, QBrush(wm.color(WindecoColors::InactiveForeground), b2)); | 326 | p.fillRect(16, 12, 5, 2, QBrush(inactiveForeground, b2)); | ||
625 | 327 | | |||
626 | p.end(); | 328 | p.end(); | ||
627 | 329 | | |||
628 | return pixmap; | 330 | return pixmap; | ||
629 | } | 331 | } | ||
630 | 332 | | |||
631 | void KColorCm::updateColorSchemes() | | |||
632 | { | | |||
633 | m_colorSchemes.clear(); | | |||
634 | | ||||
635 | m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::View, m_config)); | | |||
636 | m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Window, m_config)); | | |||
637 | m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Button, m_config)); | | |||
638 | m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Selection, m_config)); | | |||
639 | m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Tooltip, m_config)); | | |||
640 | m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Complementary, m_config)); | | |||
641 | | ||||
642 | m_wmColors.load(m_config); | | |||
643 | } | | |||
644 | | ||||
645 | void KColorCm::updateFromColorSchemes() | | |||
646 | { | | |||
647 | // store colorscheme name in global settings | | |||
648 | KConfigGroup group(m_config, "General"); | | |||
649 | group.writeEntry("ColorScheme", m_currentColorScheme); | | |||
650 | | ||||
651 | for (int i = KColorScheme::View; i <= KColorScheme::Tooltip; ++i) | | |||
652 | { | | |||
653 | KConfigGroup group(m_config, colorSetGroupKey(i)); | | |||
654 | group.writeEntry("BackgroundNormal", m_colorSchemes[i].background(KColorScheme::NormalBackground).color()); | | |||
655 | group.writeEntry("BackgroundAlternate", m_colorSchemes[i].background(KColorScheme::AlternateBackground).color()); | | |||
656 | group.writeEntry("ForegroundNormal", m_colorSchemes[i].foreground(KColorScheme::NormalText).color()); | | |||
657 | group.writeEntry("ForegroundInactive", m_colorSchemes[i].foreground(KColorScheme::InactiveText).color()); | | |||
658 | group.writeEntry("ForegroundActive", m_colorSchemes[i].foreground(KColorScheme::ActiveText).color()); | | |||
659 | group.writeEntry("ForegroundLink", m_colorSchemes[i].foreground(KColorScheme::LinkText).color()); | | |||
660 | group.writeEntry("ForegroundVisited", m_colorSchemes[i].foreground(KColorScheme::VisitedText).color()); | | |||
661 | group.writeEntry("ForegroundNegative", m_colorSchemes[i].foreground(KColorScheme::NegativeText).color()); | | |||
662 | group.writeEntry("ForegroundNeutral", m_colorSchemes[i].foreground(KColorScheme::NeutralText).color()); | | |||
663 | group.writeEntry("ForegroundPositive", m_colorSchemes[i].foreground(KColorScheme::PositiveText).color()); | | |||
664 | group.writeEntry("DecorationFocus", m_colorSchemes[i].decoration(KColorScheme::FocusColor).color()); | | |||
665 | group.writeEntry("DecorationHover", m_colorSchemes[i].decoration(KColorScheme::HoverColor).color()); | | |||
666 | } | | |||
667 | | ||||
668 | KConfigGroup WMGroup(m_config, "WM"); | | |||
669 | WMGroup.writeEntry("activeBackground", m_wmColors.color(WindecoColors::ActiveBackground)); | | |||
670 | WMGroup.writeEntry("activeForeground", m_wmColors.color(WindecoColors::ActiveForeground)); | | |||
671 | WMGroup.writeEntry("inactiveBackground", m_wmColors.color(WindecoColors::InactiveBackground)); | | |||
672 | WMGroup.writeEntry("inactiveForeground", m_wmColors.color(WindecoColors::InactiveForeground)); | | |||
673 | WMGroup.writeEntry("activeBlend", m_wmColors.color(WindecoColors::ActiveBlend)); | | |||
674 | WMGroup.writeEntry("inactiveBlend", m_wmColors.color(WindecoColors::InactiveBlend)); | | |||
675 | } | | |||
676 | | ||||
677 | void KColorCm::updateFromOptions() | | |||
678 | { | | |||
679 | KConfigGroup groupK(m_config, "KDE"); | | |||
680 | groupK.writeEntry("contrast", contrastSlider->value()); | | |||
681 | | ||||
682 | KConfigGroup groupG(m_config, "General"); | | |||
683 | groupG.writeEntry("shadeSortColumn", shadeSortedColumn->isChecked()); | | |||
684 | | ||||
685 | KConfigGroup groupI(m_config, "ColorEffects:Inactive"); | | |||
686 | groupI.writeEntry("Enable", useInactiveEffects->isChecked()); | | |||
687 | // only write this setting if it is not the default; this way we can change the default more easily in later KDE | | |||
688 | // the setting will still written by explicitly checking/unchecking the box | | |||
689 | if (inactiveSelectionEffect->isChecked()) | | |||
690 | { | | |||
691 | groupI.writeEntry("ChangeSelectionColor", true); | | |||
692 | } | | |||
693 | else | | |||
694 | { | | |||
695 | groupI.deleteEntry("ChangeSelectionColor"); | | |||
696 | } | | |||
697 | } | | |||
698 | | ||||
699 | void KColorCm::updateFromEffectsPage() | | |||
700 | { | | |||
701 | if (m_disableUpdates) | | |||
702 | { | | |||
703 | // don't write the config as we are reading it! | | |||
704 | return; | | |||
705 | } | | |||
706 | | ||||
707 | KConfigGroup groupI(m_config, "ColorEffects:Inactive"); | | |||
708 | KConfigGroup groupD(m_config, "ColorEffects:Disabled"); | | |||
709 | | ||||
710 | // intensity | | |||
711 | groupI.writeEntry("IntensityEffect", inactiveIntensityBox->currentIndex()); | | |||
712 | groupD.writeEntry("IntensityEffect", disabledIntensityBox->currentIndex()); | | |||
713 | groupI.writeEntry("IntensityAmount", qreal(inactiveIntensitySlider->value() - 20) * 0.05); | | |||
714 | groupD.writeEntry("IntensityAmount", qreal(disabledIntensitySlider->value() - 20) * 0.05); | | |||
715 | | ||||
716 | // color | | |||
717 | groupI.writeEntry("ColorEffect", inactiveColorBox->currentIndex()); | | |||
718 | groupD.writeEntry("ColorEffect", disabledColorBox->currentIndex()); | | |||
719 | if (inactiveColorBox->currentIndex() > 1) | | |||
720 | { | | |||
721 | groupI.writeEntry("ColorAmount", qreal(inactiveColorSlider->value()) * 0.025); | | |||
722 | } | | |||
723 | else | | |||
724 | { | | |||
725 | groupI.writeEntry("ColorAmount", qreal(inactiveColorSlider->value() - 20) * 0.05); | | |||
726 | } | | |||
727 | if (disabledColorBox->currentIndex() > 1) | | |||
728 | { | | |||
729 | groupD.writeEntry("ColorAmount", qreal(disabledColorSlider->value()) * 0.025); | | |||
730 | } | | |||
731 | else | | |||
732 | { | | |||
733 | groupD.writeEntry("ColorAmount", qreal(disabledColorSlider->value() - 20) * 0.05); | | |||
734 | } | | |||
735 | groupI.writeEntry("Color", inactiveColorButton->color()); | | |||
736 | groupD.writeEntry("Color", disabledColorButton->color()); | | |||
737 | | ||||
738 | // contrast | | |||
739 | groupI.writeEntry("ContrastEffect", inactiveContrastBox->currentIndex()); | | |||
740 | groupD.writeEntry("ContrastEffect", disabledContrastBox->currentIndex()); | | |||
741 | groupI.writeEntry("ContrastAmount", qreal(inactiveContrastSlider->value()) * 0.05); | | |||
742 | groupD.writeEntry("ContrastAmount", qreal(disabledContrastSlider->value()) * 0.05); | | |||
743 | | ||||
744 | // enable/disable controls | | |||
745 | inactiveIntensitySlider->setDisabled(inactiveIntensityBox->currentIndex() == 0); | | |||
746 | disabledIntensitySlider->setDisabled(disabledIntensityBox->currentIndex() == 0); | | |||
747 | inactiveColorSlider->setDisabled(inactiveColorBox->currentIndex() == 0); | | |||
748 | disabledColorSlider->setDisabled(disabledColorBox->currentIndex() == 0); | | |||
749 | inactiveColorButton->setDisabled(inactiveColorBox->currentIndex() < 2); | | |||
750 | disabledColorButton->setDisabled(disabledColorBox->currentIndex() < 2); | | |||
751 | inactiveContrastSlider->setDisabled(inactiveContrastBox->currentIndex() == 0); | | |||
752 | disabledContrastSlider->setDisabled(disabledContrastBox->currentIndex() == 0); | | |||
753 | } | | |||
754 | | ||||
755 | void KColorCm::setupColorTable() | | |||
756 | { | | |||
757 | // first setup the common colors table | | |||
758 | commonColorTable->verticalHeader()->hide(); | | |||
759 | commonColorTable->horizontalHeader()->hide(); | | |||
760 | commonColorTable->setShowGrid(false); | | |||
761 | commonColorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); | | |||
762 | int minWidth = QPushButton(i18n("Varies")).minimumSizeHint().width(); | | |||
763 | commonColorTable->horizontalHeader()->setMinimumSectionSize(minWidth); | | |||
764 | commonColorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); | | |||
765 | | ||||
766 | for (int i = 0; i < 26; ++i) | | |||
767 | { | | |||
768 | KColorButton * button = new KColorButton(this); | | |||
769 | commonColorTable->setRowHeight(i, button->sizeHint().height()); | | |||
770 | button->setObjectName(QString::number(i)); | | |||
771 | connect(button, &KColorButton::changed, this, &KColorCm::colorChanged); | | |||
772 | m_commonColorButtons << button; | | |||
773 | | ||||
774 | if (i > 8 && i < 18) | | |||
775 | { | | |||
776 | // Inactive Text row through Positive Text role all need a varies button | | |||
777 | QPushButton * variesButton = new QPushButton(NULL); | | |||
778 | variesButton->setText(i18n("Varies")); | | |||
779 | variesButton->setObjectName(QString::number(i)); | | |||
780 | connect(variesButton, &QPushButton::clicked, this, &KColorCm::variesClicked); | | |||
781 | | ||||
782 | QStackedWidget * widget = new QStackedWidget(this); | | |||
783 | widget->addWidget(button); | | |||
784 | widget->addWidget(variesButton); | | |||
785 | m_stackedWidgets.append(widget); | | |||
786 | | ||||
787 | commonColorTable->setCellWidget(i, 1, widget); | | |||
788 | } | | |||
789 | else | | |||
790 | { | | |||
791 | commonColorTable->setCellWidget(i, 1, button); | | |||
792 | } | | |||
793 | } | | |||
794 | | ||||
795 | // then the colorTable that the colorSets will use | | |||
796 | colorTable->verticalHeader()->hide(); | | |||
797 | colorTable->horizontalHeader()->hide(); | | |||
798 | colorTable->setShowGrid(false); | | |||
799 | colorTable->setRowCount(12); | | |||
800 | colorTable->horizontalHeader()->setMinimumSectionSize(minWidth); | | |||
801 | colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); | | |||
802 | | ||||
803 | createColorEntry(i18n("Normal Background"), QStringLiteral("BackgroundNormal"), m_backgroundButtons, 0); | | |||
804 | createColorEntry(i18n("Alternate Background"), QStringLiteral("BackgroundAlternate"), m_backgroundButtons, 1); | | |||
805 | createColorEntry(i18n("Normal Text"), QStringLiteral("ForegroundNormal"), m_foregroundButtons, 2); | | |||
806 | createColorEntry(i18n("Inactive Text"), QStringLiteral("ForegroundInactive"), m_foregroundButtons, 3); | | |||
807 | createColorEntry(i18n("Active Text"), QStringLiteral("ForegroundActive"), m_foregroundButtons, 4); | | |||
808 | createColorEntry(i18n("Link Text"), QStringLiteral("ForegroundLink"), m_foregroundButtons, 5); | | |||
809 | createColorEntry(i18n("Visited Text"), QStringLiteral("ForegroundVisited"), m_foregroundButtons, 6); | | |||
810 | createColorEntry(i18n("Negative Text"), QStringLiteral("ForegroundNegative"), m_foregroundButtons, 7); | | |||
811 | createColorEntry(i18n("Neutral Text"), QStringLiteral("ForegroundNeutral"), m_foregroundButtons, 8); | | |||
812 | createColorEntry(i18n("Positive Text"), QStringLiteral("ForegroundPositive"), m_foregroundButtons, 9); | | |||
813 | createColorEntry(i18n("Focus Decoration"), QStringLiteral("DecorationFocus"), m_decorationButtons, 10); | | |||
814 | createColorEntry(i18n("Hover Decoration"), QStringLiteral("DecorationHover"), m_decorationButtons, 11); | | |||
815 | | ||||
816 | colorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); | | |||
817 | colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); | | |||
818 | | ||||
819 | updateColorSchemes(); | | |||
820 | updateColorTable(); | | |||
821 | } | | |||
822 | | ||||
823 | void KColorCm::setCommonForeground(KColorScheme::ForegroundRole role, int stackIndex, | | |||
824 | int buttonIndex) | | |||
825 | { | | |||
826 | QColor color = m_colorSchemes[KColorScheme::View].foreground(role).color(); | | |||
827 | for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) | | |||
828 | { | | |||
829 | if (i == KColorScheme::Selection && role == KColorScheme::InactiveText) | | |||
830 | break; | | |||
831 | | ||||
832 | if (m_colorSchemes[i].foreground(role).color() != color) | | |||
833 | { | | |||
834 | m_stackedWidgets[stackIndex]->setCurrentIndex(1); | | |||
835 | return; | | |||
836 | } | | |||
837 | } | | |||
838 | | ||||
839 | m_stackedWidgets[stackIndex]->setCurrentIndex(0); | | |||
840 | m_commonColorButtons[buttonIndex]->setColor(color); | | |||
841 | m_loadedSchemeHasUnsavedChanges = true; | | |||
842 | } | | |||
843 | | ||||
844 | void KColorCm::setCommonDecoration(KColorScheme::DecorationRole role, int stackIndex, | | |||
845 | int buttonIndex) | | |||
846 | { | | |||
847 | QColor color = m_colorSchemes[KColorScheme::View].decoration(role).color(); | | |||
848 | for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) | | |||
849 | { | | |||
850 | if (m_colorSchemes[i].decoration(role).color() != color) | | |||
851 | { | | |||
852 | m_stackedWidgets[stackIndex]->setCurrentIndex(1); | | |||
853 | return; | | |||
854 | } | | |||
855 | } | | |||
856 | | ||||
857 | m_stackedWidgets[stackIndex]->setCurrentIndex(0); | | |||
858 | m_commonColorButtons[buttonIndex]->setColor(color); | | |||
859 | m_loadedSchemeHasUnsavedChanges = true; | | |||
860 | } | | |||
861 | | ||||
862 | void KColorCm::updateColorTable() | | |||
863 | { | | |||
864 | // subtract one here since the 0 item is "Common Colors" | | |||
865 | const int currentSet = colorSet->currentIndex() - 1; | | |||
866 | | ||||
867 | if (currentSet == -1) | | |||
868 | { | | |||
869 | // common colors is selected | | |||
870 | stackColors->setCurrentIndex(0); | | |||
871 | // stackPreview->setCurrentIndex(0); | | |||
872 | | ||||
873 | KColorButton * button; | | |||
874 | foreach (button, m_commonColorButtons) | | |||
875 | { | | |||
876 | button->blockSignals(true); | | |||
877 | } | | |||
878 | | ||||
879 | m_commonColorButtons[0]->setColor(m_colorSchemes[KColorScheme::View].background(KColorScheme::NormalBackground).color()); | | |||
880 | m_commonColorButtons[1]->setColor(m_colorSchemes[KColorScheme::View].foreground(KColorScheme::NormalText).color()); | | |||
881 | m_commonColorButtons[2]->setColor(m_colorSchemes[KColorScheme::Window].background(KColorScheme::NormalBackground).color()); | | |||
882 | m_commonColorButtons[3]->setColor(m_colorSchemes[KColorScheme::Window].foreground(KColorScheme::NormalText).color()); | | |||
883 | m_commonColorButtons[4]->setColor(m_colorSchemes[KColorScheme::Button].background(KColorScheme::NormalBackground).color()); | | |||
884 | m_commonColorButtons[5]->setColor(m_colorSchemes[KColorScheme::Button].foreground(KColorScheme::NormalText).color()); | | |||
885 | m_commonColorButtons[6]->setColor(m_colorSchemes[KColorScheme::Selection].background(KColorScheme::NormalBackground).color()); | | |||
886 | m_commonColorButtons[7]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::NormalText).color()); | | |||
887 | m_commonColorButtons[8]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::InactiveText).color()); | | |||
888 | | ||||
889 | setCommonForeground(KColorScheme::InactiveText, 0, 9); | | |||
890 | setCommonForeground(KColorScheme::ActiveText, 1, 10); | | |||
891 | setCommonForeground(KColorScheme::LinkText, 2, 11); | | |||
892 | setCommonForeground(KColorScheme::VisitedText, 3, 12); | | |||
893 | setCommonForeground(KColorScheme::NegativeText, 4, 13); | | |||
894 | setCommonForeground(KColorScheme::NeutralText, 5, 14); | | |||
895 | setCommonForeground(KColorScheme::PositiveText, 6, 15); | | |||
896 | | ||||
897 | setCommonDecoration(KColorScheme::FocusColor, 7, 16); | | |||
898 | setCommonDecoration(KColorScheme::HoverColor, 8, 17); | | |||
899 | | ||||
900 | m_commonColorButtons[18]->setColor(m_colorSchemes[KColorScheme::Tooltip].background(KColorScheme::NormalBackground).color()); | | |||
901 | m_commonColorButtons[19]->setColor(m_colorSchemes[KColorScheme::Tooltip].foreground(KColorScheme::NormalText).color()); | | |||
902 | | ||||
903 | m_commonColorButtons[20]->setColor(m_wmColors.color(WindecoColors::ActiveBackground)); | | |||
904 | m_commonColorButtons[21]->setColor(m_wmColors.color(WindecoColors::ActiveForeground)); | | |||
905 | m_commonColorButtons[22]->setColor(m_wmColors.color(WindecoColors::ActiveBlend)); | | |||
906 | m_commonColorButtons[23]->setColor(m_wmColors.color(WindecoColors::InactiveBackground)); | | |||
907 | m_commonColorButtons[24]->setColor(m_wmColors.color(WindecoColors::InactiveForeground)); | | |||
908 | m_commonColorButtons[25]->setColor(m_wmColors.color(WindecoColors::InactiveBlend)); | | |||
909 | | ||||
910 | foreach (button, m_commonColorButtons) | | |||
911 | { | | |||
912 | button->blockSignals(false); | | |||
913 | } | | |||
914 | } | | |||
915 | else | | |||
916 | { | | |||
917 | // a real color set is selected | | |||
918 | // setPreview->setPalette(m_config, (KColorScheme::ColorSet)currentSet); | | |||
919 | stackColors->setCurrentIndex(1); | | |||
920 | // stackPreview->setCurrentIndex(1); | | |||
921 | | ||||
922 | for (int i = KColorScheme::NormalBackground; i <= KColorScheme::AlternateBackground; ++i) | | |||
923 | { | | |||
924 | m_backgroundButtons[i]->blockSignals(true); | | |||
925 | m_backgroundButtons[i]->setColor(m_colorSchemes[currentSet].background(KColorScheme::BackgroundRole(i)).color()); | | |||
926 | m_backgroundButtons[i]->blockSignals(false); | | |||
927 | } | | |||
928 | | ||||
929 | for (int i = KColorScheme::NormalText; i <= KColorScheme::PositiveText; ++i) | | |||
930 | { | | |||
931 | m_foregroundButtons[i]->blockSignals(true); | | |||
932 | m_foregroundButtons[i]->setColor(m_colorSchemes[currentSet].foreground(KColorScheme::ForegroundRole(i)).color()); | | |||
933 | m_foregroundButtons[i]->blockSignals(false); | | |||
934 | } | | |||
935 | | ||||
936 | for (int i = KColorScheme::FocusColor; i <= KColorScheme::HoverColor; ++i) | | |||
937 | { | | |||
938 | m_decorationButtons[i]->blockSignals(true); | | |||
939 | m_decorationButtons[i]->setColor(m_colorSchemes[currentSet].decoration(KColorScheme::DecorationRole(i)).color()); | | |||
940 | m_decorationButtons[i]->blockSignals(false); | | |||
941 | } | | |||
942 | } | | |||
943 | } | | |||
944 | | ||||
945 | void KColorCm::colorChanged( const QColor &newColor ) | | |||
946 | { | | |||
947 | // find which button was changed | | |||
948 | const int row = sender()->objectName().toInt(); | | |||
949 | changeColor(row, newColor); | | |||
950 | } | | |||
951 | | ||||
952 | void KColorCm::changeColor(int row, const QColor &newColor) | | |||
953 | { | | |||
954 | // update the m_colorSchemes for the selected colorSet | | |||
955 | const int currentSet = colorSet->currentIndex() - 1; | | |||
956 | | ||||
957 | if (currentSet == -1) | | |||
958 | { | | |||
959 | // common colors is selected | | |||
960 | switch (row) | | |||
961 | { | | |||
962 | case 0: | | |||
963 | // View Background button | | |||
964 | KConfigGroup(m_config, "Colors:View").writeEntry("BackgroundNormal", newColor); | | |||
965 | break; | | |||
966 | case 1: | | |||
967 | // View Text button | | |||
968 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNormal", newColor); | | |||
969 | break; | | |||
970 | case 2: | | |||
971 | // Window Background Button | | |||
972 | KConfigGroup(m_config, "Colors:Window").writeEntry("BackgroundNormal", newColor); | | |||
973 | break; | | |||
974 | case 3: | | |||
975 | // Window Text Button | | |||
976 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNormal", newColor); | | |||
977 | break; | | |||
978 | case 4: | | |||
979 | // Button Background button | | |||
980 | KConfigGroup(m_config, "Colors:Button").writeEntry("BackgroundNormal", newColor); | | |||
981 | break; | | |||
982 | case 5: | | |||
983 | // Button Text button | | |||
984 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNormal", newColor); | | |||
985 | break; | | |||
986 | case 6: | | |||
987 | // Selection Background Button | | |||
988 | KConfigGroup(m_config, "Colors:Selection").writeEntry("BackgroundNormal", newColor); | | |||
989 | break; | | |||
990 | case 7: | | |||
991 | // Selection Text Button | | |||
992 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNormal", newColor); | | |||
993 | break; | | |||
994 | case 8: | | |||
995 | // Selection Inactive Text Button | | |||
996 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundInactive", newColor); | | |||
997 | break; | | |||
998 | | ||||
999 | // buttons that could have varies in their place | | |||
1000 | case 9: | | |||
1001 | // Inactive Text Button (set all but Selection Inactive Text color) | | |||
1002 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundInactive", newColor); | | |||
1003 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundInactive", newColor); | | |||
1004 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundInactive", newColor); | | |||
1005 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundInactive", newColor); | | |||
1006 | break; | | |||
1007 | case 10: | | |||
1008 | // Active Text Button (set all active text colors) | | |||
1009 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundActive", newColor); | | |||
1010 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundActive", newColor); | | |||
1011 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundActive", newColor); | | |||
1012 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundActive", newColor); | | |||
1013 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundActive", newColor); | | |||
1014 | break; | | |||
1015 | case 11: | | |||
1016 | // Link Text Button (set all link text colors) | | |||
1017 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundLink", newColor); | | |||
1018 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundLink", newColor); | | |||
1019 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundLink", newColor); | | |||
1020 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundLink", newColor); | | |||
1021 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundLink", newColor); | | |||
1022 | break; | | |||
1023 | case 12: | | |||
1024 | // Visited Text Button (set all visited text colors) | | |||
1025 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundVisited", newColor); | | |||
1026 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundVisited", newColor); | | |||
1027 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundVisited", newColor); | | |||
1028 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundVisited", newColor); | | |||
1029 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundVisited", newColor); | | |||
1030 | break; | | |||
1031 | case 13: | | |||
1032 | // Negative Text Button (set all negative text colors) | | |||
1033 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNegative", newColor); | | |||
1034 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNegative", newColor); | | |||
1035 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNegative", newColor); | | |||
1036 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNegative", newColor); | | |||
1037 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNegative", newColor); | | |||
1038 | break; | | |||
1039 | case 14: | | |||
1040 | // Neutral Text Button (set all neutral text colors) | | |||
1041 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNeutral", newColor); | | |||
1042 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNeutral", newColor); | | |||
1043 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNeutral", newColor); | | |||
1044 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNeutral", newColor); | | |||
1045 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNeutral", newColor); | | |||
1046 | break; | | |||
1047 | case 15: | | |||
1048 | // Positive Text Button (set all positive text colors) | | |||
1049 | KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundPositive", newColor); | | |||
1050 | KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundPositive", newColor); | | |||
1051 | KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundPositive", newColor); | | |||
1052 | KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundPositive", newColor); | | |||
1053 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundPositive", newColor); | | |||
1054 | break; | | |||
1055 | | ||||
1056 | case 16: | | |||
1057 | // Focus Decoration Button (set all focus decoration colors) | | |||
1058 | KConfigGroup(m_config, "Colors:View").writeEntry("DecorationFocus", newColor); | | |||
1059 | KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationFocus", newColor); | | |||
1060 | KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationFocus", newColor); | | |||
1061 | KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationFocus", newColor); | | |||
1062 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationFocus", newColor); | | |||
1063 | break; | | |||
1064 | case 17: | | |||
1065 | // Hover Decoration Button (set all hover decoration colors) | | |||
1066 | KConfigGroup(m_config, "Colors:View").writeEntry("DecorationHover", newColor); | | |||
1067 | KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationHover", newColor); | | |||
1068 | KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationHover", newColor); | | |||
1069 | KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationHover", newColor); | | |||
1070 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationHover", newColor); | | |||
1071 | break; | | |||
1072 | | ||||
1073 | case 18: | | |||
1074 | // Tooltip Background button | | |||
1075 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("BackgroundNormal", newColor); | | |||
1076 | break; | | |||
1077 | case 19: | | |||
1078 | // Tooltip Text button | | |||
1079 | KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNormal", newColor); | | |||
1080 | break; | | |||
1081 | case 20: | | |||
1082 | // Active Title Background | | |||
1083 | KConfigGroup(m_config, "WM").writeEntry("activeBackground", newColor); | | |||
1084 | break; | | |||
1085 | case 21: | | |||
1086 | // Active Title Text | | |||
1087 | KConfigGroup(m_config, "WM").writeEntry("activeForeground", newColor); | | |||
1088 | break; | | |||
1089 | case 22: | | |||
1090 | // Active Title Secondary | | |||
1091 | KConfigGroup(m_config, "WM").writeEntry("activeBlend", newColor); | | |||
1092 | break; | | |||
1093 | case 23: | | |||
1094 | // Inactive Title Background | | |||
1095 | KConfigGroup(m_config, "WM").writeEntry("inactiveBackground", newColor); | | |||
1096 | break; | | |||
1097 | case 24: | | |||
1098 | // Inactive Title Text | | |||
1099 | KConfigGroup(m_config, "WM").writeEntry("inactiveForeground", newColor); | | |||
1100 | break; | | |||
1101 | case 25: | | |||
1102 | // Inactive Title Secondary | | |||
1103 | KConfigGroup(m_config, "WM").writeEntry("inactiveBlend", newColor); | | |||
1104 | break; | | |||
1105 | } | | |||
1106 | m_commonColorButtons[row]->blockSignals(true); | | |||
1107 | m_commonColorButtons[row]->setColor(newColor); | | |||
1108 | m_commonColorButtons[row]->blockSignals(false); | | |||
1109 | } | | |||
1110 | else | | |||
1111 | { | | |||
1112 | QString group = colorSetGroupKey(currentSet); | | |||
1113 | KConfigGroup(m_config, group).writeEntry(m_colorKeys[row], newColor); | | |||
1114 | } | | |||
1115 | | ||||
1116 | QIcon icon = createSchemePreviewIcon(m_config); | | |||
1117 | schemeList->item(0)->setIcon(icon); | | |||
1118 | updateColorSchemes(); | | |||
1119 | updatePreviews(); | | |||
1120 | | ||||
1121 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1122 | m_currentColorScheme = i18nc("Current color scheme", "Current"); | | |||
1123 | KConfigGroup group(m_config, "General"); | | |||
1124 | group.writeEntry("ColorScheme", m_currentColorScheme); | | |||
1125 | schemeRemoveButton->setEnabled(false); | | |||
1126 | schemeKnsUploadButton->setEnabled(false); | | |||
1127 | schemeList->blockSignals(true); // don't emit changed signals | | |||
1128 | schemeList->setCurrentRow(0); | | |||
1129 | schemeList->blockSignals(false); | | |||
1130 | | ||||
1131 | emit changed(true); | | |||
1132 | } | | |||
1133 | | ||||
1134 | QString KColorCm::colorSetGroupKey(int colorSet) | | |||
1135 | { | | |||
1136 | QString group; | | |||
1137 | switch (colorSet) { | | |||
1138 | case KColorScheme::Window: | | |||
1139 | group = QStringLiteral("Colors:Window"); | | |||
1140 | break; | | |||
1141 | case KColorScheme::Button: | | |||
1142 | group = QStringLiteral("Colors:Button"); | | |||
1143 | break; | | |||
1144 | case KColorScheme::Selection: | | |||
1145 | group = QStringLiteral("Colors:Selection"); | | |||
1146 | break; | | |||
1147 | case KColorScheme::Tooltip: | | |||
1148 | group = QStringLiteral("Colors:Tooltip"); | | |||
1149 | break; | | |||
1150 | default: | | |||
1151 | group = QStringLiteral("Colors:View"); | | |||
1152 | } | | |||
1153 | return group; | | |||
1154 | } | | |||
1155 | | ||||
1156 | void KColorCm::on_contrastSlider_valueChanged(int value) | | |||
1157 | { | | |||
1158 | KConfigGroup group(m_config, "KDE"); | | |||
1159 | group.writeEntry("contrast", value); | | |||
1160 | | ||||
1161 | updatePreviews(); | | |||
1162 | | ||||
1163 | emit changed(true); | | |||
1164 | } | | |||
1165 | | ||||
1166 | void KColorCm::on_shadeSortedColumn_stateChanged(int state) | | |||
1167 | { | | |||
1168 | KConfigGroup group(m_config, "General"); | | |||
1169 | group.writeEntry("shadeSortColumn", bool(state != Qt::Unchecked)); | | |||
1170 | | ||||
1171 | emit changed(true); | | |||
1172 | } | | |||
1173 | | ||||
1174 | void KColorCm::on_useInactiveEffects_stateChanged(int state) | | |||
1175 | { | | |||
1176 | KConfigGroup group(m_config, "ColorEffects:Inactive"); | | |||
1177 | group.writeEntry("Enable", bool(state != Qt::Unchecked)); | | |||
1178 | | ||||
1179 | m_disableUpdates = true; | | |||
1180 | printf("re-init\n"); | | |||
1181 | inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", bool(state != Qt::Unchecked))); | | |||
1182 | m_disableUpdates = false; | | |||
1183 | | ||||
1184 | if ((state != Qt::Unchecked) && tabWidget->count() < 5) { | | |||
1185 | tabWidget->insertTab(4, pageInactive, i18n("Inactive")); | | |||
1186 | } else if ((state == Qt::Unchecked) && tabWidget->count() > 4) { | | |||
1187 | tabWidget->removeTab(4); | | |||
1188 | } | | |||
1189 | | ||||
1190 | emit changed(true); | | |||
1191 | } | | |||
1192 | | ||||
1193 | void KColorCm::on_inactiveSelectionEffect_stateChanged(int state) | | |||
1194 | { | | |||
1195 | if (m_disableUpdates) | | |||
1196 | { | | |||
1197 | // don't write the config as we are reading it! | | |||
1198 | return; | | |||
1199 | } | | |||
1200 | | ||||
1201 | KConfigGroup group(m_config, "ColorEffects:Inactive"); | | |||
1202 | group.writeEntry("ChangeSelectionColor", bool(state != Qt::Unchecked)); | | |||
1203 | | ||||
1204 | emit changed(true); | | |||
1205 | } | | |||
1206 | | ||||
1207 | void KColorCm::load() | 333 | void KColorCm::load() | ||
1208 | { | 334 | { | ||
1209 | loadInternal(true); | 335 | loadInternal(); | ||
1210 | 336 | | |||
1211 | // get colorscheme name from global settings | 337 | // get colorscheme name from global settings | ||
1212 | KConfigGroup group(m_config, "General"); | 338 | KConfigGroup group(m_config, "General"); | ||
1213 | m_currentColorScheme = group.readEntry("ColorScheme"); | 339 | m_currentColorScheme = group.readEntry("ColorScheme"); | ||
1214 | if (m_currentColorScheme == i18nc("Current color scheme", "Current")) | 340 | | ||
1215 | { | | |||
1216 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1217 | } | | |||
1218 | QList<QListWidgetItem*> itemList = schemeList->findItems(m_currentColorScheme, Qt::MatchExactly); | 341 | QList<QListWidgetItem*> itemList = schemeList->findItems(m_currentColorScheme, Qt::MatchExactly); | ||
1219 | if(!itemList.isEmpty()) // "Current" is already selected, so don't handle the case that itemList is empty | 342 | if(!itemList.isEmpty()) // "Default" is already selected, so don't handle the case that itemList is empty | ||
1220 | schemeList->setCurrentItem(itemList.at(0)); | 343 | schemeList->setCurrentItem(itemList.at(0)); | ||
1221 | 344 | | |||
1222 | KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); | 345 | KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); | ||
1223 | group = KConfigGroup(&cfg, "X11"); | 346 | group = KConfigGroup(&cfg, "X11"); | ||
1224 | 347 | | |||
1225 | applyToAlien->blockSignals(true); // don't emit SIGNAL(toggled(bool)) which would call SLOT(emitChanged()) | 348 | applyToAlien->blockSignals(true); // don't emit SIGNAL(toggled(bool)) which would call SLOT(emitChanged()) | ||
Context not available. | |||||
1227 | applyToAlien->blockSignals(false); | 350 | applyToAlien->blockSignals(false); | ||
1228 | } | 351 | } | ||
1229 | 352 | | |||
1230 | void KColorCm::loadOptions() | | |||
1231 | { | | |||
1232 | KConfigGroup generalGroup(KSharedConfig::openConfig(), "General"); | | |||
1233 | contrastSlider->setValue(KColorScheme::contrast()); | | |||
1234 | shadeSortedColumn->setChecked(generalGroup.readEntry("shadeSortColumn", true)); | | |||
1235 | | ||||
1236 | KConfigGroup group(m_config, "ColorEffects:Inactive"); | | |||
1237 | useInactiveEffects->setChecked(group.readEntry("Enable", false)); | | |||
1238 | 353 | | |||
1239 | if (useInactiveEffects->isChecked() && tabWidget->count() < 5) { | 354 | void KColorCm::loadInternal() | ||
1240 | tabWidget->insertTab(4, pageInactive, i18n("Inactive")); | | |||
1241 | } else if (!useInactiveEffects->isChecked() && tabWidget->count() > 4) { | | |||
1242 | tabWidget->removeTab(4); | | |||
1243 | } | | |||
1244 | // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp | | |||
1245 | // NOTE: remove extra logic from updateFromOptions and on_useInactiveEffects_stateChanged when this changes! | | |||
1246 | inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true))); | | |||
1247 | } | | |||
1248 | | ||||
1249 | void KColorCm::loadInternal(bool loadOptions_) | | |||
1250 | { | 355 | { | ||
1251 | // clean the config, in case we have changed the in-memory kconfig | 356 | // clean the config, in case we have changed the in-memory kconfig | ||
1252 | m_config->markAsClean(); | 357 | m_config->markAsClean(); | ||
1253 | m_config->reparseConfiguration(); | 358 | m_config->reparseConfiguration(); | ||
1254 | 359 | | |||
1255 | // update the color table | | |||
1256 | updateColorSchemes(); | | |||
1257 | updateColorTable(); | | |||
1258 | | ||||
1259 | // fill in the color scheme list | 360 | // fill in the color scheme list | ||
1260 | populateSchemeList(); | 361 | populateSchemeList(); | ||
1261 | 362 | | |||
1262 | if (loadOptions_) | 363 | schemePreview->setPalette(m_config); | ||
1263 | loadOptions(); | | |||
1264 | | ||||
1265 | updateEffectsPage(); | | |||
1266 | | ||||
1267 | updatePreviews(); | | |||
1268 | | ||||
1269 | m_loadedSchemeHasUnsavedChanges = false; | | |||
1270 | | ||||
1271 | emit changed(false); | 364 | emit changed(false); | ||
1272 | } | 365 | } | ||
1273 | 366 | | |||
Context not available. | |||||
1276 | QIcon icon = createSchemePreviewIcon(m_config); | 369 | QIcon icon = createSchemePreviewIcon(m_config); | ||
1277 | schemeList->item(0)->setIcon(icon); | 370 | schemeList->item(0)->setIcon(icon); | ||
1278 | 371 | | |||
1279 | KConfigGroup groupI(m_config, "ColorEffects:Inactive"); | | |||
1280 | | ||||
1281 | groupI.writeEntry("Enable", useInactiveEffects->isChecked()); | | |||
1282 | groupI.writeEntry("IntensityEffect", inactiveIntensityBox->currentIndex()); | | |||
1283 | groupI.writeEntry("ColorEffect", inactiveColorBox->currentIndex()); | | |||
1284 | groupI.writeEntry("ContrastEffect", inactiveContrastBox->currentIndex()); | | |||
1285 | | ||||
1286 | m_config->sync(); | 372 | m_config->sync(); | ||
1287 | KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); | 373 | | ||
374 | KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); | ||||
1288 | KConfigGroup displayGroup(&cfg, "X11"); | 375 | KConfigGroup displayGroup(&cfg, "X11"); | ||
1289 | 376 | | |||
1290 | displayGroup.writeEntry("exportKDEColors", applyToAlien->isChecked()); | 377 | displayGroup.writeEntry("exportKDEColors", applyToAlien->isChecked()); | ||
1291 | cfg.sync(); | | |||
1292 | 378 | | |||
379 | cfg.sync(); | ||||
380 | qDebug() << KRdbExportQtColors << KRdbExportGtkTheme << KRdbExportColors ; | ||||
1293 | runRdb(KRdbExportQtColors | KRdbExportGtkTheme | ( applyToAlien->isChecked() ? KRdbExportColors : 0 ) ); | 381 | runRdb(KRdbExportQtColors | KRdbExportGtkTheme | ( applyToAlien->isChecked() ? KRdbExportColors : 0 ) ); | ||
1294 | 382 | qDebug() << "icic"; | |||
1295 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange") ); | 383 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange") ); | ||
1296 | QList<QVariant> args; | 384 | QList<QVariant> args; | ||
1297 | args.append(0);//previous KGlobalSettings::PaletteChanged. This is now private API in khintsettings | 385 | args.append(0);//previous KGlobalSettings::PaletteChanged. This is now private API in khintsettings | ||
1298 | args.append(0);//unused in palette changed but needed for the DBus signature | 386 | args.append(0);//unused in palette changed but needed for the DBus signature | ||
1299 | message.setArguments(args); | 387 | message.setArguments(args); | ||
388 | qDebug() << KConfigGroup(m_config, "General").readEntry("Name"); | ||||
1300 | QDBusConnection::sessionBus().send(message); | 389 | QDBusConnection::sessionBus().send(message); | ||
1301 | if (qApp->platformName() == QStringLiteral("xcb")) { | 390 | if (qApp->platformName() == QStringLiteral("xcb")) { | ||
1302 | // Send signal to all kwin instances | 391 | // Send signal to all kwin instances | ||
1303 | QDBusMessage message = | 392 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); | ||
1304 | QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); | | |||
1305 | QDBusConnection::sessionBus().send(message); | 393 | QDBusConnection::sessionBus().send(message); | ||
1306 | } | 394 | } | ||
1307 | 395 | | |||
Context not available. | |||||
1324 | } | 412 | } | ||
1325 | } | 413 | } | ||
1326 | 414 | | |||
1327 | // Reset options (not part of scheme) | | |||
1328 | m_config->setReadDefaults(true); | | |||
1329 | loadOptions(); | | |||
1330 | m_config->setReadDefaults(false); | | |||
1331 | applyToAlien->setChecked(Qt::Checked); | | |||
1332 | | ||||
1333 | KCModule::defaults(); | 415 | KCModule::defaults(); | ||
1334 | emit changed(true); | 416 | emit changed(true); | ||
1335 | } | 417 | } | ||
1336 | 418 | | |||
1337 | void KColorCm::emitChanged() | 419 | void KColorCm::on_schemeEditButton_clicked() | ||
1338 | { | | |||
1339 | emit changed(true); | | |||
1340 | } | | |||
1341 | | ||||
1342 | // inactive effects slots | | |||
1343 | void KColorCm::on_inactiveIntensityBox_currentIndexChanged(int index) | | |||
1344 | { | | |||
1345 | Q_UNUSED( index ); | | |||
1346 | | ||||
1347 | updateFromEffectsPage(); | | |||
1348 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
1349 | | ||||
1350 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1351 | | ||||
1352 | emit changed(true); | | |||
1353 | } | | |||
1354 | | ||||
1355 | void KColorCm::on_inactiveIntensitySlider_valueChanged(int value) | | |||
1356 | { | | |||
1357 | Q_UNUSED( value ); | | |||
1358 | | ||||
1359 | updateFromEffectsPage(); | | |||
1360 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
1361 | | ||||
1362 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1363 | | ||||
1364 | emit changed(true); | | |||
1365 | } | | |||
1366 | | ||||
1367 | void KColorCm::on_inactiveColorBox_currentIndexChanged(int index) | | |||
1368 | { | | |||
1369 | Q_UNUSED( index ); | | |||
1370 | | ||||
1371 | updateFromEffectsPage(); | | |||
1372 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
1373 | | ||||
1374 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1375 | | ||||
1376 | emit changed(true); | | |||
1377 | } | | |||
1378 | | ||||
1379 | void KColorCm::on_inactiveColorSlider_valueChanged(int value) | | |||
1380 | { | | |||
1381 | Q_UNUSED( value ); | | |||
1382 | | ||||
1383 | updateFromEffectsPage(); | | |||
1384 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
1385 | | ||||
1386 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1387 | | ||||
1388 | emit changed(true); | | |||
1389 | } | | |||
1390 | | ||||
1391 | void KColorCm::on_inactiveColorButton_changed(const QColor& color) | | |||
1392 | { | | |||
1393 | Q_UNUSED( color ); | | |||
1394 | | ||||
1395 | updateFromEffectsPage(); | | |||
1396 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
1397 | | ||||
1398 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1399 | | ||||
1400 | emit changed(true); | | |||
1401 | } | | |||
1402 | | ||||
1403 | void KColorCm::on_inactiveContrastBox_currentIndexChanged(int index) | | |||
1404 | { | | |||
1405 | Q_UNUSED( index ); | | |||
1406 | | ||||
1407 | updateFromEffectsPage(); | | |||
1408 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
1409 | | ||||
1410 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1411 | | ||||
1412 | emit changed(true); | | |||
1413 | } | | |||
1414 | | ||||
1415 | void KColorCm::on_inactiveContrastSlider_valueChanged(int value) | | |||
1416 | { | | |||
1417 | Q_UNUSED( value ); | | |||
1418 | | ||||
1419 | updateFromEffectsPage(); | | |||
1420 | inactivePreview->setPalette(m_config, QPalette::Inactive); | | |||
1421 | | ||||
1422 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1423 | | ||||
1424 | emit changed(true); | | |||
1425 | } | | |||
1426 | | ||||
1427 | // disabled effects slots | | |||
1428 | void KColorCm::on_disabledIntensityBox_currentIndexChanged(int index) | | |||
1429 | { | 420 | { | ||
1430 | Q_UNUSED( index ); | 421 | QListWidgetItem *currentItem = schemeList->currentItem(); | ||
1431 | 422 | const QString fileBaseName = currentItem->data(Qt::UserRole).toString(); | |||
1432 | updateFromEffectsPage(); | 423 | const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, | ||
1433 | disabledPreview->setPalette(m_config, QPalette::Disabled); | 424 | "color-schemes/" + fileBaseName + ".colors"); | ||
1434 | 425 | if (path.isEmpty()) { | |||
1435 | m_loadedSchemeHasUnsavedChanges = true; | 426 | KMessageBox::sorry(this, i18n("This scheme was not found."), i18n("File not found")); | ||
1436 | 427 | return; | |||
1437 | emit changed(true); | 428 | } | ||
1438 | } | 429 | SchemeEditorDialog* dialog = new SchemeEditorDialog(path, this); | ||
1439 | 430 | dialog->setModal(true); | |||
1440 | void KColorCm::on_disabledIntensitySlider_valueChanged(int value) | 431 | dialog->show(); | ||
1441 | { | 432 | connect(dialog, &SchemeEditorDialog::accepted, [=](){ this->populateSchemeList(); }); | ||
1442 | Q_UNUSED( value ); | 433 | connect(dialog, &SchemeEditorDialog::rejected, [=](){ this->populateSchemeList(); }); | ||
1443 | | ||||
1444 | updateFromEffectsPage(); | | |||
1445 | disabledPreview->setPalette(m_config, QPalette::Disabled); | | |||
1446 | | ||||
1447 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1448 | | ||||
1449 | emit changed(true); | | |||
1450 | } | | |||
1451 | | ||||
1452 | void KColorCm::on_disabledColorBox_currentIndexChanged(int index) | | |||
1453 | { | | |||
1454 | Q_UNUSED( index ); | | |||
1455 | | ||||
1456 | updateFromEffectsPage(); | | |||
1457 | disabledPreview->setPalette(m_config, QPalette::Disabled); | | |||
1458 | | ||||
1459 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1460 | | ||||
1461 | emit changed(true); | | |||
1462 | } | | |||
1463 | | ||||
1464 | void KColorCm::on_disabledColorSlider_valueChanged(int value) | | |||
1465 | { | | |||
1466 | Q_UNUSED( value ); | | |||
1467 | | ||||
1468 | updateFromEffectsPage(); | | |||
1469 | disabledPreview->setPalette(m_config, QPalette::Disabled); | | |||
1470 | | ||||
1471 | m_loadedSchemeHasUnsavedChanges = true; | | |||
1472 | | ||||
1473 | emit changed(true); | | |||
1474 | } | 434 | } | ||
1475 | 435 | | |||
1476 | void KColorCm::on_disabledColorButton_changed(const QColor& color) | 436 | void KColorCm::updateConfig(KSharedConfigPtr config) | ||
1477 | { | 437 | { | ||
1478 | Q_UNUSED( color ); | 438 | // store colorscheme name in global settings | ||
1479 | 439 | KConfigGroup groupOut(m_config, "General"); | |||
1480 | updateFromEffectsPage(); | 440 | groupOut.writeEntry("ColorScheme", m_currentColorScheme); | ||
1481 | disabledPreview->setPalette(m_config, QPalette::Disabled); | 441 | | ||
442 | QStringList colorItemList; | ||||
443 | colorItemList << "BackgroundNormal" | ||||
444 | << "BackgroundAlternate" | ||||
445 | << "ForegroundNormal" | ||||
446 | << "ForegroundInactive" | ||||
447 | << "ForegroundActive" | ||||
448 | << "ForegroundLink" | ||||
449 | << "ForegroundVisited" | ||||
450 | << "ForegroundNegative" | ||||
451 | << "ForegroundNeutral" | ||||
452 | << "ForegroundPositive" | ||||
453 | << "DecorationFocus" | ||||
454 | << "DecorationHover"; | ||||
455 | | ||||
456 | QStringList colorSetGroupList; | ||||
457 | colorSetGroupList << "Colors:Window" | ||||
458 | << "Colors:Button" | ||||
459 | << "Colors:Selection" | ||||
460 | << "Colors:Tooltip" | ||||
461 | << "Colors:View"; | ||||
462 | for (const QString &colorSetGroup : colorSetGroupList) | ||||
463 | { | ||||
464 | KConfigGroup groupOut(m_config, colorSetGroup); | ||||
465 | KConfigGroup groupTheme(config, colorSetGroup); | ||||
466 | | ||||
467 | for (const QString &coloritem : colorItemList) | ||||
468 | { | ||||
469 | groupOut.writeEntry(coloritem, groupTheme.readEntry(coloritem)); | ||||
470 | } | ||||
471 | } | ||||
1482 | 472 | | |||
1483 | m_loadedSchemeHasUnsavedChanges = true; | 473 | KConfigGroup groupWMTheme(config, "WM"); | ||
474 | KConfigGroup groupWMOut(m_config, "WM"); | ||||
1484 | 475 | | |||
1485 | emit changed(true); | 476 | QStringList colorItemListWM; | ||
1486 | } | 477 | colorItemListWM << "activeBackground" | ||
478 | << "activeForeground" | ||||
479 | << "inactiveBackground" | ||||
480 | << "inactiveForeground" | ||||
481 | << "activeBlend" | ||||
482 | << "inactiveBlend"; | ||||
1487 | 483 | | |||
1488 | void KColorCm::on_disabledContrastBox_currentIndexChanged(int index) | 484 | for (const QString &coloritem : colorItemListWM) | ||
1489 | { | 485 | { | ||
1490 | Q_UNUSED( index ); | 486 | groupWMOut.writeEntry(coloritem, groupWMTheme.readEntry(coloritem)); | ||
1491 | 487 | } | |||
1492 | updateFromEffectsPage(); | | |||
1493 | disabledPreview->setPalette(m_config, QPalette::Disabled); | | |||
1494 | 488 | | |||
1495 | m_loadedSchemeHasUnsavedChanges = true; | 489 | QStringList groupNameList; | ||
490 | groupNameList << "ColorEffects:Inactive" << "ColorEffects:Disabled"; | ||||
1496 | 491 | | |||
1497 | emit changed(true); | 492 | QStringList effectList; | ||
1498 | } | 493 | effectList << "IntensityEffect" | ||
494 | << "IntensityAmount" | ||||
495 | << "ColorEffect" | ||||
496 | << "ColorAmount" | ||||
497 | << "Color" | ||||
498 | << "ContrastEffect" | ||||
499 | << "ContrastAmount"; | ||||
1499 | 500 | | |||
1500 | void KColorCm::on_disabledContrastSlider_valueChanged(int value) | 501 | for (const QString &groupName : groupNameList) | ||
1501 | { | 502 | { | ||
1502 | Q_UNUSED( value ); | | |||
1503 | 503 | | |||
1504 | updateFromEffectsPage(); | 504 | KConfigGroup groupEffectOut(m_config, groupName); | ||
1505 | disabledPreview->setPalette(m_config, QPalette::Disabled); | 505 | KConfigGroup groupEffectTheme(config, groupName); | ||
1506 | 506 | | |||
1507 | m_loadedSchemeHasUnsavedChanges = true; | 507 | for (const QString &effect : effectList) { | ||
508 | groupEffectOut.writeEntry(effect, groupEffectTheme.readEntry("effect")); | ||||
1508 | 509 | | |||
1509 | emit changed(true); | 510 | } | ||
511 | } | ||||
1510 | } | 512 | } | ||
1511 | | ||||
1512 | #include "colorscm.moc" | 513 | #include "colorscm.moc" | ||
Context not available. |