Index: kcms/colors/CMakeLists.txt =================================================================== --- kcms/colors/CMakeLists.txt +++ kcms/colors/CMakeLists.txt @@ -1,12 +1,62 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kcmcolors\") -set(kcm_colors_SRCS ../krdb/krdb.cpp colorscm.cpp previewwidget.cpp setpreviewwidget.cpp) +set(scheme_editor_SRCS + kcolorschemeeditor.cpp + scmeditordialog.cpp + scmeditoroptions.cpp + scmeditorcolors.cpp + scmeditoreffects.cpp + previewwidget.cpp + setpreviewwidget.cpp + ) + +ki18n_wrap_ui(scheme_editor_SRCS + scmeditordialog.ui + scmeditoroptions.ui + scmeditorcolors.ui + scmeditoreffects.ui + preview.ui + setpreview.ui + ) + +add_executable(kcolorschemeeditor ${scheme_editor_SRCS}) + +target_link_libraries(kcolorschemeeditor + KF5::KCMUtils + KF5::GuiAddons + KF5::I18n + KF5::KIOCore + KF5::CoreAddons + KF5::NewStuff + ) +install(TARGETS kcolorschemeeditor DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}) +install(FILES kcolorschemeeditor.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) + +# ---------------- + +set(kcm_colors_SRCS + ../krdb/krdb.cpp + colorscm.cpp + scmeditordialog.cpp + scmeditoroptions.cpp + scmeditorcolors.cpp + scmeditoreffects.cpp + previewwidget.cpp + setpreviewwidget.cpp + ) set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml) qt5_add_dbus_interface(kcm_colors_SRCS ${klauncher_xml} klauncher_iface) -ki18n_wrap_ui(kcm_colors_SRCS colorsettings.ui preview.ui setpreview.ui) +ki18n_wrap_ui(kcm_colors_SRCS + colorsettings.ui + scmeditordialog.ui + scmeditoroptions.ui + scmeditorcolors.ui + scmeditoreffects.ui + preview.ui + setpreview.ui) add_library(kcm_colors MODULE ${kcm_colors_SRCS}) target_link_libraries(kcm_colors Index: kcms/colors/colorscm.h =================================================================== --- kcms/colors/colorscm.h +++ kcms/colors/colorscm.h @@ -1,6 +1,7 @@ /* KDE Display color scheme setup module * Copyright (C) 2007 Matthew Woehlke * Copyright (C) 2007 Jeremy Whiting + * Copyright (C) 2016 Olivier Churlaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,13 +23,15 @@ #define __COLORSCM_H__ #include -#include #include "ui_colorsettings.h" class QStackedWidget; class QListWidgetItem; +class KColorButton; + + /** * The Desktop/Colors tab in kcontrol. */ @@ -42,169 +45,92 @@ public Q_SLOTS: - /// load the settings from the config + /** + * load the settings from the config + */ virtual void load(); - /// save the current settings + /** + * save the current settings + */ virtual void save(); - /// sets the configuration to sensible default values. + /** + * sets the configuration to sensible default values. + */ virtual void defaults(); private Q_SLOTS: - /** set the colortable color buttons up according to the current colorset */ - void updateColorTable(); - - /** slot called when color on a KColorButton changes */ - void colorChanged( const QColor &newColor ); - /** slot called when any varies button is clicked */ - void variesClicked(); - - /** slot called when the schemeList selection changes */ + /** + * slot called when the schemeList selection changes. + * + * It loads the scheme with loadScheme(KSharedConfigPtr), which updates the + * config (updateConfig()) + */ void loadScheme(QListWidgetItem *currentItem, QListWidgetItem *previousItem); - /** reselect the previously selected scheme in schemeList without loading it */ + /** + * Reselect the previously selected scheme in schemeList without loading it + */ void selectPreviousSchemeAgain(); - /** slot called when the remove button is clicked*/ + /** + * Slot called when the remove button is clicked + */ void on_schemeRemoveButton_clicked(); - /** slot called when the save button is clicked */ - void on_schemeSaveButton_clicked(); - - /** slot called when the import button is clicked */ + /** + * Slot called when the import button is clicked + */ void on_schemeImportButton_clicked(); - /** slot called when the get new schemes button is clicked */ + /** + * slot called when the get new schemes button is clicked + */ void on_schemeKnsButton_clicked(); - /** slot called when the upload scheme button is clicked */ - void on_schemeKnsUploadButton_clicked(); - - /** null slot to emit changed(true) */ - void emitChanged(); - - // options slots - void on_contrastSlider_valueChanged(int value); - void on_shadeSortedColumn_stateChanged(int state); - void on_inactiveSelectionEffect_stateChanged(int state); - void on_useInactiveEffects_stateChanged(int state); - - // effects page slots - void on_inactiveIntensityBox_currentIndexChanged(int index); - void on_inactiveIntensitySlider_valueChanged(int value); - void on_inactiveColorBox_currentIndexChanged(int index); - void on_inactiveColorSlider_valueChanged(int value); - void on_inactiveColorButton_changed(const QColor & color); - void on_inactiveContrastBox_currentIndexChanged(int index); - void on_inactiveContrastSlider_valueChanged(int value); - - void on_disabledIntensityBox_currentIndexChanged(int index); - void on_disabledIntensitySlider_valueChanged(int value); - void on_disabledColorBox_currentIndexChanged(int index); - void on_disabledColorSlider_valueChanged(int value); - void on_disabledColorButton_changed(const QColor & color); - void on_disabledContrastBox_currentIndexChanged(int index); - void on_disabledContrastSlider_valueChanged(int value); - + /** + * Slot called when the Edit button is clicked. + * + * It opens a dialog for the edition/creation. + */ + void on_schemeEditButton_clicked(); private: - class WindecoColors { - public: - enum Role { - ActiveForeground = 0, - ActiveBackground = 1, - InactiveForeground = 2, - InactiveBackground = 3, - ActiveBlend = 4, - InactiveBlend = 5 - }; - - WindecoColors() {} - WindecoColors(const KSharedConfigPtr&); - virtual ~WindecoColors() {} - - void load(const KSharedConfigPtr&); - QColor color(Role) const; - private: - QColor m_colors[6]; - }; - - /** create a preview of a color scheme */ - static QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config); - /** load options from global */ - void loadOptions(); + /** + * Create a preview icon of a color scheme + */ + static QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config); - /** load from global */ - void loadInternal(bool loadOptions); + /** + * Load from global. + */ + void loadInternal(); - /** load a scheme from a config file at a given path */ + /** + * load a scheme from a config file at a given path and updates the + * config (updateConfig()) + */ void loadScheme(KSharedConfigPtr config); - /** populate the schemeList with color schemes found on the system */ + /** + * Populate the schemeList with color schemes found on the system + */ void populateSchemeList(); - /** update m_colorSchemes contents from the values in m_config */ - void updateColorSchemes(); - - /** update the effects page from the values in m_config */ - void updateEffectsPage(); - - /** update all preview panes from the values in m_config */ - void updatePreviews(); - - /** setup the colortable with its buttons and labels */ - void setupColorTable(); - - /** helper to create color entries */ - void createColorEntry(const QString &text, - const QString &key, - QList &list, - int index); - - /** copy color entries from color schemes into m_config */ - void updateFromColorSchemes(); - - /** copy effects page entries from controls into m_config */ - void updateFromEffectsPage(); - - /** copy options from controls into m_config */ - void updateFromOptions(); - - void changeColor(int row, const QColor &newColor); + /** + * Update all keys of the Global config with the theme ones. + */ + void updateConfig(KSharedConfigPtr config); - /** get the groupKey for the given colorSet */ - static QString colorSetGroupKey(int colorSet); - /** save the current scheme with the given name - @param name name to save the scheme as - */ - void saveScheme(const QString &name); - - void setCommonForeground(KColorScheme::ForegroundRole role, - int stackIndex, - int buttonIndex); - void setCommonDecoration(KColorScheme::DecorationRole role, - int stackIndex, - int buttonIndex); - - QList m_backgroundButtons; - QList m_foregroundButtons; - QList m_decorationButtons; - QList m_commonColorButtons; - QList m_stackedWidgets; - QStringList m_colorKeys; - - QList m_colorSchemes; - WindecoColors m_wmColors; QString m_currentColorScheme; + // The global config KSharedConfigPtr m_config; - bool m_disableUpdates; - bool m_loadedSchemeHasUnsavedChanges; // don't (re)load the scheme, only select it in schemeList bool m_dontLoadSelectedScheme; Index: kcms/colors/colorscm.cpp =================================================================== --- kcms/colors/colorscm.cpp +++ kcms/colors/colorscm.cpp @@ -1,6 +1,7 @@ /* KDE Display color scheme setup module * Copyright (C) 2007 Matthew Woehlke * Copyright (C) 2007 Jeremy Whiting + * Copyright (C) 2016 Olivier Churlaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,10 +22,10 @@ #include "colorscm.h" #include "../krdb/krdb.h" +#include "scmeditordialog.h" #include #include -#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include @@ -43,39 +43,14 @@ #include #include #include -#include -#include +#include K_PLUGIN_FACTORY( KolorFactory, registerPlugin(); ) K_EXPORT_PLUGIN( KolorFactory("kcmcolors") ) -//BEGIN WindecoColors -KColorCm::WindecoColors::WindecoColors(const KSharedConfigPtr &config) -{ - load(config); -} - -void KColorCm::WindecoColors::load(const KSharedConfigPtr &config) -{ - // NOTE: keep this in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp - KConfigGroup group(config, "WM"); - m_colors[ActiveBackground] = group.readEntry("activeBackground", QColor(48, 174, 232)); - m_colors[ActiveForeground] = group.readEntry("activeForeground", QColor(255, 255, 255)); - m_colors[InactiveBackground] = group.readEntry("inactiveBackground", QColor(224, 223, 222)); - m_colors[InactiveForeground] = group.readEntry("inactiveForeground", QColor(75, 71, 67)); - m_colors[ActiveBlend] = group.readEntry("activeBlend", m_colors[ActiveForeground]); - m_colors[InactiveBlend] = group.readEntry("inactiveBlend", m_colors[InactiveForeground]); -} - -QColor KColorCm::WindecoColors::color(WindecoColors::Role role) const -{ - return m_colors[role]; -} -//END WindecoColors - KColorCm::KColorCm(QWidget *parent, const QVariantList &) - : KCModule( parent ), m_disableUpdates(false), - m_loadedSchemeHasUnsavedChanges(false), m_dontLoadSelectedScheme(false), + : KCModule( parent ), + m_dontLoadSelectedScheme(false), m_previousSchemeItem(0) { KAboutData* about = new KAboutData( @@ -91,15 +66,10 @@ m_config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); setupUi(this); - schemeKnsButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); - schemeKnsUploadButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); - connect(colorSet, static_cast(&QComboBox::currentIndexChanged), this, &KColorCm::updateColorTable); + connect(applyToAlien, &QCheckBox::toggled, [=](){ emit changed(true); }); connect(schemeList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(loadScheme(QListWidgetItem*,QListWidgetItem*))); - connect(applyToAlien, &QCheckBox::toggled, this, &KColorCm::emitChanged); - - // only needs to be called once - setupColorTable(); + schemeKnsButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); } KColorCm::~KColorCm() @@ -156,93 +126,13 @@ icon = createSchemePreviewIcon(m_config); schemeList->insertItem(0, new QListWidgetItem(icon, i18nc("Default color scheme", "Default"))); m_config->setReadDefaults(false); - - // add current scheme entry - icon = createSchemePreviewIcon(m_config); - QListWidgetItem *currentitem = new QListWidgetItem(icon, i18nc("Current color scheme", "Current")); - schemeList->insertItem(0, currentitem); - schemeList->blockSignals(true); // don't emit changed signals - schemeList->setCurrentItem(currentitem); - schemeList->blockSignals(false); -} - -void KColorCm::updatePreviews() -{ - schemePreview->setPalette(m_config); - colorPreview->setPalette(m_config); - // setPreview->setPalette(m_config, (KColorScheme::ColorSet)(colorSet->currentIndex() - 1)); - inactivePreview->setPalette(m_config, QPalette::Inactive); - disabledPreview->setPalette(m_config, QPalette::Disabled); } -void KColorCm::updateEffectsPage() -{ - m_disableUpdates = true; - - // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp - KConfigGroup groupI(m_config, "ColorEffects:Inactive"); - inactiveIntensityBox->setCurrentIndex(abs(groupI.readEntry("IntensityEffect", 0))); - inactiveIntensitySlider->setValue(int(groupI.readEntry("IntensityAmount", 0.0) * 20.0) + 20); - inactiveColorBox->setCurrentIndex(abs(groupI.readEntry("ColorEffect", 2))); - if (inactiveColorBox->currentIndex() > 1) - { - inactiveColorSlider->setValue(int(groupI.readEntry("ColorAmount", 0.025) * 40.0)); - } - else - { - inactiveColorSlider->setValue(int(groupI.readEntry("ColorAmount", 0.05) * 20.0) + 20); - } - inactiveColorButton->setColor(groupI.readEntry("Color", QColor(112, 111, 110))); - inactiveContrastBox->setCurrentIndex(abs(groupI.readEntry("ContrastEffect", 2))); - inactiveContrastSlider->setValue(int(groupI.readEntry("ContrastAmount", 0.1) * 20.0)); - - // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp - KConfigGroup groupD(m_config, "ColorEffects:Disabled"); - disabledIntensityBox->setCurrentIndex(groupD.readEntry("IntensityEffect", 2)); - disabledIntensitySlider->setValue(int(groupD.readEntry("IntensityAmount", 0.1) * 20.0) + 20); - disabledColorBox->setCurrentIndex(groupD.readEntry("ColorEffect", 0)); - if (disabledColorBox->currentIndex() > 1) - { - disabledColorSlider->setValue(int(groupD.readEntry("ColorAmount", 0.0) * 40.0)); - } - else - { - disabledColorSlider->setValue(int(groupD.readEntry("ColorAmount", 0.0) * 20.0) + 20); - } - disabledColorButton->setColor(groupD.readEntry("Color", QColor(56, 56, 56))); - disabledContrastBox->setCurrentIndex(groupD.readEntry("ContrastEffect", 1)); - disabledContrastSlider->setValue(int(groupD.readEntry("ContrastAmount", 0.65) * 20.0)); - - m_disableUpdates = false; - - // enable/disable controls - inactiveIntensitySlider->setDisabled(inactiveIntensityBox->currentIndex() == 0); - disabledIntensitySlider->setDisabled(disabledIntensityBox->currentIndex() == 0); - inactiveColorSlider->setDisabled(inactiveColorBox->currentIndex() == 0); - disabledColorSlider->setDisabled(disabledColorBox->currentIndex() == 0); - inactiveColorButton->setDisabled(inactiveColorBox->currentIndex() < 2); - disabledColorButton->setDisabled(disabledColorBox->currentIndex() < 2); - inactiveContrastSlider->setDisabled(inactiveContrastBox->currentIndex() == 0); - disabledContrastSlider->setDisabled(disabledContrastBox->currentIndex() == 0); -} void KColorCm::loadScheme(KSharedConfigPtr config) // const QString &path) { - KSharedConfigPtr temp = m_config; - m_config = config; - - updateColorSchemes(); - updateEffectsPage(); // intentionally before swapping back m_config - updatePreviews(); - - m_config = temp; - updateFromColorSchemes(); - updateFromEffectsPage(); - updateFromOptions(); - updateColorTable(); - - m_loadedSchemeHasUnsavedChanges = false; - //m_changed = false; + schemePreview->setPalette(config); + updateConfig(config); } void KColorCm::selectPreviousSchemeAgain() @@ -258,34 +148,19 @@ if (m_dontLoadSelectedScheme) { + qDebug() << "dontload"; return; } if (currentItem != NULL) { - if (m_loadedSchemeHasUnsavedChanges) // if changes made to loaded scheme - { - if (KMessageBox::Continue != KMessageBox::warningContinueCancel(this, - i18n("Selecting another scheme will discard any changes you have made"), - i18n("Are you sure?"), - KStandardGuiItem::cont(), - KStandardGuiItem::cancel(), - QStringLiteral("noDiscardWarning"))) // if the user decides to cancel - { - QTimer::singleShot(0, this, &KColorCm::selectPreviousSchemeAgain); - return; - } - } - // load it - const QString name = currentItem->text(); m_currentColorScheme = name; const QString fileBaseName = currentItem->data(Qt::UserRole).toString(); if (name == i18nc("Default color scheme", "Default")) { schemeRemoveButton->setEnabled(false); - schemeKnsUploadButton->setEnabled(false); KSharedConfigPtr config = m_config; config->setReadDefaults(true); @@ -294,12 +169,6 @@ // load the default scheme emit changed(true); } - else if (name == i18nc("Current color scheme", "Current")) - { - schemeRemoveButton->setEnabled(false); - schemeKnsUploadButton->setEnabled(false); - loadInternal(false); - } else { const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, @@ -309,7 +178,6 @@ const bool canWrite = (permissions & QFile::WriteUser); qDebug() << "checking permissions of " << path; schemeRemoveButton->setEnabled(canWrite); - schemeKnsUploadButton->setEnabled(true); KSharedConfigPtr config = KSharedConfig::openConfig(path); loadScheme(config); @@ -327,6 +195,7 @@ "color-schemes/" + schemeList->currentItem()->data(Qt::UserRole).toString() + ".colors"); KIO::DeleteJob *job = KIO::del(QUrl::fromLocalFile(path)); + qDebug() << path; job->uiDelegate()->setParent(this); if (job->exec()) { @@ -345,251 +214,77 @@ // get the path to the scheme to import QUrl url = QUrl::fromLocalFile(QFileDialog::getOpenFileName(this, i18n("Import Color Scheme"))); - if(url.isValid()) - { - // TODO: possibly untar or uncompress it - // open it - - // load the scheme - KSharedConfigPtr config = KSharedConfig::openConfig(url.path()); - - if (config->groupList().contains(QStringLiteral("Color Scheme"))) - { - if (KMessageBox::Continue != KMessageBox::warningContinueCancel(this, - i18n("The scheme you have selected appears to be a KDE3 scheme.\n\n" - "KDE will attempt to import this scheme, however many color roles have been added since KDE3. " - "Some manual work will likely be required.\n\n" - "This scheme will not be saved automatically."), - i18n("Notice"))) - { - return; - } - - // convert KDE3 scheme to new scheme - KConfigGroup g(config, "Color Scheme"); - KConfigGroup generalGroup(KSharedConfig::openConfig(), "General"); - - colorSet->setCurrentIndex(0); - contrastSlider->setValue(g.readEntry("contrast", KColorScheme::contrast())); - shadeSortedColumn->setChecked(g.readEntry("shadeSortColumn", generalGroup.readEntry("shadeSortColumn", true))); - - m_commonColorButtons[0]->setColor(g.readEntry("windowBackground", m_colorSchemes[KColorScheme::View].background().color())); - m_commonColorButtons[1]->setColor(g.readEntry("windowForeground", m_colorSchemes[KColorScheme::View].foreground().color())); - m_commonColorButtons[2]->setColor(g.readEntry("background", m_colorSchemes[KColorScheme::Window].background().color())); - m_commonColorButtons[3]->setColor(g.readEntry("foreground", m_colorSchemes[KColorScheme::Window].foreground().color())); - m_commonColorButtons[4]->setColor(g.readEntry("buttonBackground", m_colorSchemes[KColorScheme::Button].background().color())); - m_commonColorButtons[5]->setColor(g.readEntry("buttonForeground", m_colorSchemes[KColorScheme::Button].foreground().color())); - m_commonColorButtons[6]->setColor(g.readEntry("selectBackground", m_colorSchemes[KColorScheme::Selection].background().color())); - m_commonColorButtons[7]->setColor(g.readEntry("selectForeground", m_colorSchemes[KColorScheme::Selection].foreground().color())); - m_commonColorButtons[8]->setColor(KColorUtils::mix(m_colorSchemes[KColorScheme::Selection].foreground().color(), - m_colorSchemes[KColorScheme::Selection].background().color())); - m_commonColorButtons[9]->setColor(KColorUtils::mix(m_colorSchemes[KColorScheme::View].foreground().color(), - m_colorSchemes[KColorScheme::View].background().color())); - // doesn't exist in KDE3: 10 ActiveText - m_commonColorButtons[11]->setColor(g.readEntry("linkColor", m_colorSchemes[KColorScheme::View].foreground(KColorScheme::LinkText).color())); - m_commonColorButtons[12]->setColor(g.readEntry("visitedLinkColor", m_colorSchemes[KColorScheme::View].foreground(KColorScheme::VisitedText).color())); - // doesn't exist in KDE3: 13-15 PositiveText, NeutralText, NegativeText - m_commonColorButtons[16]->setColor(g.readEntry("windowForeground", m_colorSchemes[KColorScheme::View].decoration(KColorScheme::FocusColor).color())); - m_commonColorButtons[17]->setColor(g.readEntry("selectBackground", m_colorSchemes[KColorScheme::View].decoration(KColorScheme::HoverColor).color())); - m_commonColorButtons[18]->setColor(g.readEntry("windowBackground", m_colorSchemes[KColorScheme::Tooltip].background().color())); - m_commonColorButtons[19]->setColor(g.readEntry("windowForeground", m_colorSchemes[KColorScheme::Tooltip].foreground().color())); - m_commonColorButtons[20]->setColor(g.readEntry("activeBackground", m_wmColors.color(WindecoColors::ActiveBackground))); - m_commonColorButtons[21]->setColor(g.readEntry("activeForeground", m_wmColors.color(WindecoColors::ActiveForeground))); - m_commonColorButtons[22]->setColor(g.readEntry("activeBlend", m_wmColors.color(WindecoColors::ActiveBlend))); - m_commonColorButtons[23]->setColor(g.readEntry("inactiveBackground", m_wmColors.color(WindecoColors::InactiveBackground))); - m_commonColorButtons[24]->setColor(g.readEntry("inactiveForeground", m_wmColors.color(WindecoColors::InactiveForeground))); - m_commonColorButtons[25]->setColor(g.readEntry("inactiveBlend", m_wmColors.color(WindecoColors::InactiveBlend))); - - colorSet->setCurrentIndex(1); - m_backgroundButtons[KColorScheme::AlternateBackground]->setColor(g.readEntry("alternateBackground", - m_colorSchemes[KColorScheme::View].background(KColorScheme::AlternateBackground).color())); - colorSet->setCurrentIndex(0); - } - else - { - // load scheme - loadScheme(config); - - // save it - saveScheme(url.fileName()); - } - } -} - -void KColorCm::on_schemeKnsButton_clicked() -{ - KNS3::DownloadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); - dialog.exec(); - if ( ! dialog.changedEntries().isEmpty() ) + if(!url.isValid()) { - populateSchemeList(); + return; } -} - -void KColorCm::on_schemeKnsUploadButton_clicked() -{ - if (schemeList->currentItem() != NULL) - { - // check if the currently loaded scheme has unsaved changes - if (m_loadedSchemeHasUnsavedChanges) - { - KMessageBox::sorry(this, i18n("Please save the color scheme before uploading it."), - i18n("Please save")); - return; - } + // TODO: possibly untar or uncompress it + // open it - // find path - const QString basename = schemeList->currentItem()->data(Qt::UserRole).toString(); - const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, - "color-schemes/" + basename + ".colors"); - if (path.isEmpty() ) // if the color scheme file wasn't found - { - qDebug() << "path for color scheme " << basename << " couldn't be found"; - return; - } - - // upload - KNS3::UploadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); - dialog.setUploadFile(QUrl::fromLocalFile(path) ); - dialog.exec(); - } -} + // load the scheme + KSharedConfigPtr config = KSharedConfig::openConfig(url.path()); -void KColorCm::on_schemeSaveButton_clicked() -{ - QString previousName; - if (schemeList->currentItem() != NULL && schemeList->currentRow() > 1) - { - previousName = schemeList->currentItem()->data(Qt::DisplayRole).toString(); - } - // prompt for the name to save as - bool ok; - QString name = QInputDialog::getText(this, i18n("Save Color Scheme"), - i18n("&Enter a name for the color scheme:"), QLineEdit::Normal, previousName, &ok); - if (ok) + if (config->groupList().contains(QStringLiteral("Color Scheme"))) { - saveScheme(name); + KMessageBox::sorry(this, + i18n("The scheme you have selected appears to be a KDE3 scheme.\n\n" + "This is not supported anymore."), + i18n("Notice")); + return; } -} -void KColorCm::saveScheme(const QString &name) -{ - QString filename = name; - filename.remove('\''); // So Foo's does not become FooS - QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); - int offset; - while ((offset = fixer.indexIn(filename)) >= 0) - filename.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); - filename.replace(0, 1, filename.at(0).toUpper()); - - // check if that name is already in the list - const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, - "color-schemes/" + filename + ".colors"); + // Do not overwrite another scheme + KConfigGroup group(config, "General"); + QString name = group.readEntry("Name"); - QFile file(path); - const int permissions = file.permissions(); - const bool canWrite = (permissions & QFile::WriteUser); - // or if we can overwrite it if it exists - if (path.isEmpty() || !file.exists() || canWrite) + int increment = 0; + QString newName = name; + QString testpath = ""; + do { - if(canWrite){ - int ret = KMessageBox::questionYesNo(this, - i18n("A color scheme with that name already exists.\nDo you want to overwrite it?"), - i18n("Save Color Scheme"), - KStandardGuiItem::overwrite(), - KStandardGuiItem::cancel()); - //on don't overwrite, select the already existing name. - if(ret == KMessageBox::No){ - QList foundItems = schemeList->findItems(name, Qt::MatchExactly); - if (foundItems.size() == 1) - schemeList->setCurrentRow(schemeList->row(foundItems[0])); - return; - } - } - - // go ahead and save it - QString newpath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) - + "/color-schemes/"; - QDir dir; - dir.mkpath(newpath); - newpath += filename + ".colors"; - KSharedConfigPtr temp = m_config; - m_config = KSharedConfig::openConfig(newpath); - // then copy current colors into new config - updateFromColorSchemes(); - updateFromEffectsPage(); - KConfigGroup group(m_config, "General"); - group.writeEntry("Name", name); - // sync it - m_config->sync(); - - m_loadedSchemeHasUnsavedChanges = false; - - QList foundItems = schemeList->findItems(name, Qt::MatchExactly); - QIcon icon = createSchemePreviewIcon(m_config); - if (foundItems.size() < 1) - { - // add it to the list since it's not in there already - populateSchemeList(); - - // then select the new item - schemeList->setCurrentItem(schemeList->findItems(name, Qt::MatchExactly).at(0)); - } - else - { - // update the icon of the one that's in the list - foundItems[0]->setIcon(icon); - schemeList->setCurrentRow(schemeList->row(foundItems[0])); + if (increment) { + newName = name + QString::number(increment); } + testpath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + "color-schemes/" + newName + ".colors"); + increment++; + } while (!testpath.isEmpty()); - // set m_config back to the system one - m_config = temp; + QString newpath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + "/color-schemes/"; + QDir dir; + dir.mkpath(newpath); + newpath += newName + ".colors"; + QFile::copy(url.toLocalFile(), newpath); - // store colorscheme name in global settings - m_currentColorScheme = name; - group = KConfigGroup(m_config, "General"); - group.writeEntry("ColorScheme", m_currentColorScheme); + // Update name + KSharedConfigPtr config2 = KSharedConfig::openConfig(newpath); + KConfigGroup group2(config2, "General"); + group2.writeEntry("Name", newName); + config2->sync(); - emit changed(true); - } - else if (!canWrite && file.exists()) + this->populateSchemeList(); + QList itemList = schemeList->findItems(newName, Qt::MatchExactly); + if (!itemList.isEmpty()) { - // give error message if !canWrite && file.exists() - KMessageBox::error(this, i18n("You do not have permission to overwrite that scheme"), i18n("Error")); + schemeList->setCurrentItem(itemList.first()); } } -void KColorCm::createColorEntry(const QString &text, const QString &key, QList &list, int index) -{ - KColorButton *button = new KColorButton(this); - button->setObjectName(QString::number(index)); - connect(button, &KColorButton::changed, this, &KColorCm::colorChanged); - list.append(button); - - m_colorKeys.insert(index, key); - - QTableWidgetItem *label = new QTableWidgetItem(text); - colorTable->setItem(index, 0, label); - colorTable->setCellWidget(index, 1, button); - colorTable->setRowHeight(index, button->sizeHint().height()); -} - -void KColorCm::variesClicked() +void KColorCm::on_schemeKnsButton_clicked() { - // find which button was changed - const int row = sender()->objectName().toInt(); - - QColor color = QColorDialog::getColor(QColor(), this); - if(color.isValid()) + KNS3::DownloadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); + dialog.exec(); + if ( ! dialog.changedEntries().isEmpty() ) { - changeColor(row, color); - m_stackedWidgets[row - 9]->setCurrentIndex(0); + populateSchemeList(); + for ( auto t : dialog.installedEntries()) + qDebug() << t.name(); } } QPixmap KColorCm::createSchemePreviewIcon(const KSharedConfigPtr &config) { - const WindecoColors wm(config); const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b }; const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff }; const QSize bitsSize(24,2); @@ -601,6 +296,13 @@ QPainter p(&pixmap); + KConfigGroup group(config, "WM"); + // NOTE: keep this in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp + QColor activeBackground = group.readEntry("activeBackground", QColor(48, 174, 232)); + QColor activeForeground = group.readEntry("activeForeground", QColor(255, 255, 255)); + QColor inactiveBackground = group.readEntry("inactiveBackground", QColor(224, 223, 222)); + QColor inactiveForeground = group.readEntry("inactiveForeground", QColor(75, 71, 67)); + KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config); p.fillRect( 1, 1, 7, 7, windowScheme.background()); p.fillRect( 2, 2, 5, 2, QBrush(windowScheme.foreground().color(), b1)); @@ -609,8 +311,8 @@ p.fillRect( 8, 1, 7, 7, buttonScheme.background()); p.fillRect( 9, 2, 5, 2, QBrush(buttonScheme.foreground().color(), b1)); - p.fillRect(15, 1, 7, 7, wm.color(WindecoColors::ActiveBackground)); - p.fillRect(16, 2, 5, 2, QBrush(wm.color(WindecoColors::ActiveForeground), b1)); + p.fillRect(15, 1, 7, 7, activeBackground); + p.fillRect(16, 2, 5, 2, QBrush(activeForeground, b1)); KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config); p.fillRect( 1, 8, 7, 7, viewScheme.background()); @@ -620,606 +322,27 @@ p.fillRect( 8, 8, 7, 7, selectionScheme.background()); p.fillRect( 9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2)); - p.fillRect(15, 8, 7, 7, wm.color(WindecoColors::InactiveBackground)); - p.fillRect(16, 12, 5, 2, QBrush(wm.color(WindecoColors::InactiveForeground), b2)); + p.fillRect(15, 8, 7, 7, inactiveBackground); + p.fillRect(16, 12, 5, 2, QBrush(inactiveForeground, b2)); p.end(); return pixmap; } -void KColorCm::updateColorSchemes() -{ - m_colorSchemes.clear(); - - m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::View, m_config)); - m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Window, m_config)); - m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Button, m_config)); - m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Selection, m_config)); - m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Tooltip, m_config)); - m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Complementary, m_config)); - - m_wmColors.load(m_config); -} - -void KColorCm::updateFromColorSchemes() -{ - // store colorscheme name in global settings - KConfigGroup group(m_config, "General"); - group.writeEntry("ColorScheme", m_currentColorScheme); - - for (int i = KColorScheme::View; i <= KColorScheme::Tooltip; ++i) - { - KConfigGroup group(m_config, colorSetGroupKey(i)); - group.writeEntry("BackgroundNormal", m_colorSchemes[i].background(KColorScheme::NormalBackground).color()); - group.writeEntry("BackgroundAlternate", m_colorSchemes[i].background(KColorScheme::AlternateBackground).color()); - group.writeEntry("ForegroundNormal", m_colorSchemes[i].foreground(KColorScheme::NormalText).color()); - group.writeEntry("ForegroundInactive", m_colorSchemes[i].foreground(KColorScheme::InactiveText).color()); - group.writeEntry("ForegroundActive", m_colorSchemes[i].foreground(KColorScheme::ActiveText).color()); - group.writeEntry("ForegroundLink", m_colorSchemes[i].foreground(KColorScheme::LinkText).color()); - group.writeEntry("ForegroundVisited", m_colorSchemes[i].foreground(KColorScheme::VisitedText).color()); - group.writeEntry("ForegroundNegative", m_colorSchemes[i].foreground(KColorScheme::NegativeText).color()); - group.writeEntry("ForegroundNeutral", m_colorSchemes[i].foreground(KColorScheme::NeutralText).color()); - group.writeEntry("ForegroundPositive", m_colorSchemes[i].foreground(KColorScheme::PositiveText).color()); - group.writeEntry("DecorationFocus", m_colorSchemes[i].decoration(KColorScheme::FocusColor).color()); - group.writeEntry("DecorationHover", m_colorSchemes[i].decoration(KColorScheme::HoverColor).color()); - } - - KConfigGroup WMGroup(m_config, "WM"); - WMGroup.writeEntry("activeBackground", m_wmColors.color(WindecoColors::ActiveBackground)); - WMGroup.writeEntry("activeForeground", m_wmColors.color(WindecoColors::ActiveForeground)); - WMGroup.writeEntry("inactiveBackground", m_wmColors.color(WindecoColors::InactiveBackground)); - WMGroup.writeEntry("inactiveForeground", m_wmColors.color(WindecoColors::InactiveForeground)); - WMGroup.writeEntry("activeBlend", m_wmColors.color(WindecoColors::ActiveBlend)); - WMGroup.writeEntry("inactiveBlend", m_wmColors.color(WindecoColors::InactiveBlend)); -} - -void KColorCm::updateFromOptions() -{ - KConfigGroup groupK(m_config, "KDE"); - groupK.writeEntry("contrast", contrastSlider->value()); - - KConfigGroup groupG(m_config, "General"); - groupG.writeEntry("shadeSortColumn", shadeSortedColumn->isChecked()); - - KConfigGroup groupI(m_config, "ColorEffects:Inactive"); - groupI.writeEntry("Enable", useInactiveEffects->isChecked()); - // only write this setting if it is not the default; this way we can change the default more easily in later KDE - // the setting will still written by explicitly checking/unchecking the box - if (inactiveSelectionEffect->isChecked()) - { - groupI.writeEntry("ChangeSelectionColor", true); - } - else - { - groupI.deleteEntry("ChangeSelectionColor"); - } -} - -void KColorCm::updateFromEffectsPage() -{ - if (m_disableUpdates) - { - // don't write the config as we are reading it! - return; - } - - KConfigGroup groupI(m_config, "ColorEffects:Inactive"); - KConfigGroup groupD(m_config, "ColorEffects:Disabled"); - - // intensity - groupI.writeEntry("IntensityEffect", inactiveIntensityBox->currentIndex()); - groupD.writeEntry("IntensityEffect", disabledIntensityBox->currentIndex()); - groupI.writeEntry("IntensityAmount", qreal(inactiveIntensitySlider->value() - 20) * 0.05); - groupD.writeEntry("IntensityAmount", qreal(disabledIntensitySlider->value() - 20) * 0.05); - - // color - groupI.writeEntry("ColorEffect", inactiveColorBox->currentIndex()); - groupD.writeEntry("ColorEffect", disabledColorBox->currentIndex()); - if (inactiveColorBox->currentIndex() > 1) - { - groupI.writeEntry("ColorAmount", qreal(inactiveColorSlider->value()) * 0.025); - } - else - { - groupI.writeEntry("ColorAmount", qreal(inactiveColorSlider->value() - 20) * 0.05); - } - if (disabledColorBox->currentIndex() > 1) - { - groupD.writeEntry("ColorAmount", qreal(disabledColorSlider->value()) * 0.025); - } - else - { - groupD.writeEntry("ColorAmount", qreal(disabledColorSlider->value() - 20) * 0.05); - } - groupI.writeEntry("Color", inactiveColorButton->color()); - groupD.writeEntry("Color", disabledColorButton->color()); - - // contrast - groupI.writeEntry("ContrastEffect", inactiveContrastBox->currentIndex()); - groupD.writeEntry("ContrastEffect", disabledContrastBox->currentIndex()); - groupI.writeEntry("ContrastAmount", qreal(inactiveContrastSlider->value()) * 0.05); - groupD.writeEntry("ContrastAmount", qreal(disabledContrastSlider->value()) * 0.05); - - // enable/disable controls - inactiveIntensitySlider->setDisabled(inactiveIntensityBox->currentIndex() == 0); - disabledIntensitySlider->setDisabled(disabledIntensityBox->currentIndex() == 0); - inactiveColorSlider->setDisabled(inactiveColorBox->currentIndex() == 0); - disabledColorSlider->setDisabled(disabledColorBox->currentIndex() == 0); - inactiveColorButton->setDisabled(inactiveColorBox->currentIndex() < 2); - disabledColorButton->setDisabled(disabledColorBox->currentIndex() < 2); - inactiveContrastSlider->setDisabled(inactiveContrastBox->currentIndex() == 0); - disabledContrastSlider->setDisabled(disabledContrastBox->currentIndex() == 0); -} - -void KColorCm::setupColorTable() -{ - // first setup the common colors table - commonColorTable->verticalHeader()->hide(); - commonColorTable->horizontalHeader()->hide(); - commonColorTable->setShowGrid(false); - commonColorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - int minWidth = QPushButton(i18n("Varies")).minimumSizeHint().width(); - commonColorTable->horizontalHeader()->setMinimumSectionSize(minWidth); - commonColorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); - - for (int i = 0; i < 26; ++i) - { - KColorButton * button = new KColorButton(this); - commonColorTable->setRowHeight(i, button->sizeHint().height()); - button->setObjectName(QString::number(i)); - connect(button, &KColorButton::changed, this, &KColorCm::colorChanged); - m_commonColorButtons << button; - - if (i > 8 && i < 18) - { - // Inactive Text row through Positive Text role all need a varies button - QPushButton * variesButton = new QPushButton(NULL); - variesButton->setText(i18n("Varies")); - variesButton->setObjectName(QString::number(i)); - connect(variesButton, &QPushButton::clicked, this, &KColorCm::variesClicked); - - QStackedWidget * widget = new QStackedWidget(this); - widget->addWidget(button); - widget->addWidget(variesButton); - m_stackedWidgets.append(widget); - - commonColorTable->setCellWidget(i, 1, widget); - } - else - { - commonColorTable->setCellWidget(i, 1, button); - } - } - - // then the colorTable that the colorSets will use - colorTable->verticalHeader()->hide(); - colorTable->horizontalHeader()->hide(); - colorTable->setShowGrid(false); - colorTable->setRowCount(12); - colorTable->horizontalHeader()->setMinimumSectionSize(minWidth); - colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); - - createColorEntry(i18n("Normal Background"), QStringLiteral("BackgroundNormal"), m_backgroundButtons, 0); - createColorEntry(i18n("Alternate Background"), QStringLiteral("BackgroundAlternate"), m_backgroundButtons, 1); - createColorEntry(i18n("Normal Text"), QStringLiteral("ForegroundNormal"), m_foregroundButtons, 2); - createColorEntry(i18n("Inactive Text"), QStringLiteral("ForegroundInactive"), m_foregroundButtons, 3); - createColorEntry(i18n("Active Text"), QStringLiteral("ForegroundActive"), m_foregroundButtons, 4); - createColorEntry(i18n("Link Text"), QStringLiteral("ForegroundLink"), m_foregroundButtons, 5); - createColorEntry(i18n("Visited Text"), QStringLiteral("ForegroundVisited"), m_foregroundButtons, 6); - createColorEntry(i18n("Negative Text"), QStringLiteral("ForegroundNegative"), m_foregroundButtons, 7); - createColorEntry(i18n("Neutral Text"), QStringLiteral("ForegroundNeutral"), m_foregroundButtons, 8); - createColorEntry(i18n("Positive Text"), QStringLiteral("ForegroundPositive"), m_foregroundButtons, 9); - createColorEntry(i18n("Focus Decoration"), QStringLiteral("DecorationFocus"), m_decorationButtons, 10); - createColorEntry(i18n("Hover Decoration"), QStringLiteral("DecorationHover"), m_decorationButtons, 11); - - colorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); - - updateColorSchemes(); - updateColorTable(); -} - -void KColorCm::setCommonForeground(KColorScheme::ForegroundRole role, int stackIndex, - int buttonIndex) -{ - QColor color = m_colorSchemes[KColorScheme::View].foreground(role).color(); - for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) - { - if (i == KColorScheme::Selection && role == KColorScheme::InactiveText) - break; - - if (m_colorSchemes[i].foreground(role).color() != color) - { - m_stackedWidgets[stackIndex]->setCurrentIndex(1); - return; - } - } - - m_stackedWidgets[stackIndex]->setCurrentIndex(0); - m_commonColorButtons[buttonIndex]->setColor(color); - m_loadedSchemeHasUnsavedChanges = true; -} - -void KColorCm::setCommonDecoration(KColorScheme::DecorationRole role, int stackIndex, - int buttonIndex) -{ - QColor color = m_colorSchemes[KColorScheme::View].decoration(role).color(); - for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) - { - if (m_colorSchemes[i].decoration(role).color() != color) - { - m_stackedWidgets[stackIndex]->setCurrentIndex(1); - return; - } - } - - m_stackedWidgets[stackIndex]->setCurrentIndex(0); - m_commonColorButtons[buttonIndex]->setColor(color); - m_loadedSchemeHasUnsavedChanges = true; -} - -void KColorCm::updateColorTable() -{ - // subtract one here since the 0 item is "Common Colors" - const int currentSet = colorSet->currentIndex() - 1; - - if (currentSet == -1) - { - // common colors is selected - stackColors->setCurrentIndex(0); - // stackPreview->setCurrentIndex(0); - - KColorButton * button; - foreach (button, m_commonColorButtons) - { - button->blockSignals(true); - } - - m_commonColorButtons[0]->setColor(m_colorSchemes[KColorScheme::View].background(KColorScheme::NormalBackground).color()); - m_commonColorButtons[1]->setColor(m_colorSchemes[KColorScheme::View].foreground(KColorScheme::NormalText).color()); - m_commonColorButtons[2]->setColor(m_colorSchemes[KColorScheme::Window].background(KColorScheme::NormalBackground).color()); - m_commonColorButtons[3]->setColor(m_colorSchemes[KColorScheme::Window].foreground(KColorScheme::NormalText).color()); - m_commonColorButtons[4]->setColor(m_colorSchemes[KColorScheme::Button].background(KColorScheme::NormalBackground).color()); - m_commonColorButtons[5]->setColor(m_colorSchemes[KColorScheme::Button].foreground(KColorScheme::NormalText).color()); - m_commonColorButtons[6]->setColor(m_colorSchemes[KColorScheme::Selection].background(KColorScheme::NormalBackground).color()); - m_commonColorButtons[7]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::NormalText).color()); - m_commonColorButtons[8]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::InactiveText).color()); - - setCommonForeground(KColorScheme::InactiveText, 0, 9); - setCommonForeground(KColorScheme::ActiveText, 1, 10); - setCommonForeground(KColorScheme::LinkText, 2, 11); - setCommonForeground(KColorScheme::VisitedText, 3, 12); - setCommonForeground(KColorScheme::NegativeText, 4, 13); - setCommonForeground(KColorScheme::NeutralText, 5, 14); - setCommonForeground(KColorScheme::PositiveText, 6, 15); - - setCommonDecoration(KColorScheme::FocusColor, 7, 16); - setCommonDecoration(KColorScheme::HoverColor, 8, 17); - - m_commonColorButtons[18]->setColor(m_colorSchemes[KColorScheme::Tooltip].background(KColorScheme::NormalBackground).color()); - m_commonColorButtons[19]->setColor(m_colorSchemes[KColorScheme::Tooltip].foreground(KColorScheme::NormalText).color()); - - m_commonColorButtons[20]->setColor(m_wmColors.color(WindecoColors::ActiveBackground)); - m_commonColorButtons[21]->setColor(m_wmColors.color(WindecoColors::ActiveForeground)); - m_commonColorButtons[22]->setColor(m_wmColors.color(WindecoColors::ActiveBlend)); - m_commonColorButtons[23]->setColor(m_wmColors.color(WindecoColors::InactiveBackground)); - m_commonColorButtons[24]->setColor(m_wmColors.color(WindecoColors::InactiveForeground)); - m_commonColorButtons[25]->setColor(m_wmColors.color(WindecoColors::InactiveBlend)); - - foreach (button, m_commonColorButtons) - { - button->blockSignals(false); - } - } - else - { - // a real color set is selected - // setPreview->setPalette(m_config, (KColorScheme::ColorSet)currentSet); - stackColors->setCurrentIndex(1); - // stackPreview->setCurrentIndex(1); - - for (int i = KColorScheme::NormalBackground; i <= KColorScheme::AlternateBackground; ++i) - { - m_backgroundButtons[i]->blockSignals(true); - m_backgroundButtons[i]->setColor(m_colorSchemes[currentSet].background(KColorScheme::BackgroundRole(i)).color()); - m_backgroundButtons[i]->blockSignals(false); - } - - for (int i = KColorScheme::NormalText; i <= KColorScheme::PositiveText; ++i) - { - m_foregroundButtons[i]->blockSignals(true); - m_foregroundButtons[i]->setColor(m_colorSchemes[currentSet].foreground(KColorScheme::ForegroundRole(i)).color()); - m_foregroundButtons[i]->blockSignals(false); - } - - for (int i = KColorScheme::FocusColor; i <= KColorScheme::HoverColor; ++i) - { - m_decorationButtons[i]->blockSignals(true); - m_decorationButtons[i]->setColor(m_colorSchemes[currentSet].decoration(KColorScheme::DecorationRole(i)).color()); - m_decorationButtons[i]->blockSignals(false); - } - } -} - -void KColorCm::colorChanged( const QColor &newColor ) -{ - // find which button was changed - const int row = sender()->objectName().toInt(); - changeColor(row, newColor); -} - -void KColorCm::changeColor(int row, const QColor &newColor) -{ - // update the m_colorSchemes for the selected colorSet - const int currentSet = colorSet->currentIndex() - 1; - - if (currentSet == -1) - { - // common colors is selected - switch (row) - { - case 0: - // View Background button - KConfigGroup(m_config, "Colors:View").writeEntry("BackgroundNormal", newColor); - break; - case 1: - // View Text button - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNormal", newColor); - break; - case 2: - // Window Background Button - KConfigGroup(m_config, "Colors:Window").writeEntry("BackgroundNormal", newColor); - break; - case 3: - // Window Text Button - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNormal", newColor); - break; - case 4: - // Button Background button - KConfigGroup(m_config, "Colors:Button").writeEntry("BackgroundNormal", newColor); - break; - case 5: - // Button Text button - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNormal", newColor); - break; - case 6: - // Selection Background Button - KConfigGroup(m_config, "Colors:Selection").writeEntry("BackgroundNormal", newColor); - break; - case 7: - // Selection Text Button - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNormal", newColor); - break; - case 8: - // Selection Inactive Text Button - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundInactive", newColor); - break; - - // buttons that could have varies in their place - case 9: - // Inactive Text Button (set all but Selection Inactive Text color) - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundInactive", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundInactive", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundInactive", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundInactive", newColor); - break; - case 10: - // Active Text Button (set all active text colors) - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundActive", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundActive", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundActive", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundActive", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundActive", newColor); - break; - case 11: - // Link Text Button (set all link text colors) - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundLink", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundLink", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundLink", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundLink", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundLink", newColor); - break; - case 12: - // Visited Text Button (set all visited text colors) - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundVisited", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundVisited", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundVisited", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundVisited", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundVisited", newColor); - break; - case 13: - // Negative Text Button (set all negative text colors) - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNegative", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNegative", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNegative", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNegative", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNegative", newColor); - break; - case 14: - // Neutral Text Button (set all neutral text colors) - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNeutral", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNeutral", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNeutral", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNeutral", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNeutral", newColor); - break; - case 15: - // Positive Text Button (set all positive text colors) - KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundPositive", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundPositive", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundPositive", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundPositive", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundPositive", newColor); - break; - - case 16: - // Focus Decoration Button (set all focus decoration colors) - KConfigGroup(m_config, "Colors:View").writeEntry("DecorationFocus", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationFocus", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationFocus", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationFocus", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationFocus", newColor); - break; - case 17: - // Hover Decoration Button (set all hover decoration colors) - KConfigGroup(m_config, "Colors:View").writeEntry("DecorationHover", newColor); - KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationHover", newColor); - KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationHover", newColor); - KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationHover", newColor); - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationHover", newColor); - break; - - case 18: - // Tooltip Background button - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("BackgroundNormal", newColor); - break; - case 19: - // Tooltip Text button - KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNormal", newColor); - break; - case 20: - // Active Title Background - KConfigGroup(m_config, "WM").writeEntry("activeBackground", newColor); - break; - case 21: - // Active Title Text - KConfigGroup(m_config, "WM").writeEntry("activeForeground", newColor); - break; - case 22: - // Active Title Secondary - KConfigGroup(m_config, "WM").writeEntry("activeBlend", newColor); - break; - case 23: - // Inactive Title Background - KConfigGroup(m_config, "WM").writeEntry("inactiveBackground", newColor); - break; - case 24: - // Inactive Title Text - KConfigGroup(m_config, "WM").writeEntry("inactiveForeground", newColor); - break; - case 25: - // Inactive Title Secondary - KConfigGroup(m_config, "WM").writeEntry("inactiveBlend", newColor); - break; - } - m_commonColorButtons[row]->blockSignals(true); - m_commonColorButtons[row]->setColor(newColor); - m_commonColorButtons[row]->blockSignals(false); - } - else - { - QString group = colorSetGroupKey(currentSet); - KConfigGroup(m_config, group).writeEntry(m_colorKeys[row], newColor); - } - - QIcon icon = createSchemePreviewIcon(m_config); - schemeList->item(0)->setIcon(icon); - updateColorSchemes(); - updatePreviews(); - - m_loadedSchemeHasUnsavedChanges = true; - m_currentColorScheme = i18nc("Current color scheme", "Current"); - KConfigGroup group(m_config, "General"); - group.writeEntry("ColorScheme", m_currentColorScheme); - schemeRemoveButton->setEnabled(false); - schemeKnsUploadButton->setEnabled(false); - schemeList->blockSignals(true); // don't emit changed signals - schemeList->setCurrentRow(0); - schemeList->blockSignals(false); - - emit changed(true); -} - -QString KColorCm::colorSetGroupKey(int colorSet) -{ - QString group; - switch (colorSet) { - case KColorScheme::Window: - group = QStringLiteral("Colors:Window"); - break; - case KColorScheme::Button: - group = QStringLiteral("Colors:Button"); - break; - case KColorScheme::Selection: - group = QStringLiteral("Colors:Selection"); - break; - case KColorScheme::Tooltip: - group = QStringLiteral("Colors:Tooltip"); - break; - default: - group = QStringLiteral("Colors:View"); - } - return group; -} - -void KColorCm::on_contrastSlider_valueChanged(int value) -{ - KConfigGroup group(m_config, "KDE"); - group.writeEntry("contrast", value); - - updatePreviews(); - - emit changed(true); -} - -void KColorCm::on_shadeSortedColumn_stateChanged(int state) -{ - KConfigGroup group(m_config, "General"); - group.writeEntry("shadeSortColumn", bool(state != Qt::Unchecked)); - - emit changed(true); -} - -void KColorCm::on_useInactiveEffects_stateChanged(int state) -{ - KConfigGroup group(m_config, "ColorEffects:Inactive"); - group.writeEntry("Enable", bool(state != Qt::Unchecked)); - - m_disableUpdates = true; - printf("re-init\n"); - inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", bool(state != Qt::Unchecked))); - m_disableUpdates = false; - - if ((state != Qt::Unchecked) && tabWidget->count() < 5) { - tabWidget->insertTab(4, pageInactive, i18n("Inactive")); - } else if ((state == Qt::Unchecked) && tabWidget->count() > 4) { - tabWidget->removeTab(4); - } - - emit changed(true); -} - -void KColorCm::on_inactiveSelectionEffect_stateChanged(int state) -{ - if (m_disableUpdates) - { - // don't write the config as we are reading it! - return; - } - - KConfigGroup group(m_config, "ColorEffects:Inactive"); - group.writeEntry("ChangeSelectionColor", bool(state != Qt::Unchecked)); - - emit changed(true); -} - void KColorCm::load() { - loadInternal(true); + loadInternal(); // get colorscheme name from global settings KConfigGroup group(m_config, "General"); m_currentColorScheme = group.readEntry("ColorScheme"); - if (m_currentColorScheme == i18nc("Current color scheme", "Current")) - { - m_loadedSchemeHasUnsavedChanges = true; - } + QList itemList = schemeList->findItems(m_currentColorScheme, Qt::MatchExactly); - if(!itemList.isEmpty()) // "Current" is already selected, so don't handle the case that itemList is empty + if(!itemList.isEmpty()) // "Default" is already selected, so don't handle the case that itemList is empty schemeList->setCurrentItem(itemList.at(0)); - KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); + KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); group = KConfigGroup(&cfg, "X11"); applyToAlien->blockSignals(true); // don't emit SIGNAL(toggled(bool)) which would call SLOT(emitChanged()) @@ -1227,47 +350,17 @@ applyToAlien->blockSignals(false); } -void KColorCm::loadOptions() -{ - KConfigGroup generalGroup(KSharedConfig::openConfig(), "General"); - contrastSlider->setValue(KColorScheme::contrast()); - shadeSortedColumn->setChecked(generalGroup.readEntry("shadeSortColumn", true)); - - KConfigGroup group(m_config, "ColorEffects:Inactive"); - useInactiveEffects->setChecked(group.readEntry("Enable", false)); - if (useInactiveEffects->isChecked() && tabWidget->count() < 5) { - tabWidget->insertTab(4, pageInactive, i18n("Inactive")); - } else if (!useInactiveEffects->isChecked() && tabWidget->count() > 4) { - tabWidget->removeTab(4); - } - // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp - // NOTE: remove extra logic from updateFromOptions and on_useInactiveEffects_stateChanged when this changes! - inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true))); -} - -void KColorCm::loadInternal(bool loadOptions_) +void KColorCm::loadInternal() { // clean the config, in case we have changed the in-memory kconfig m_config->markAsClean(); m_config->reparseConfiguration(); - // update the color table - updateColorSchemes(); - updateColorTable(); - // fill in the color scheme list populateSchemeList(); - if (loadOptions_) - loadOptions(); - - updateEffectsPage(); - - updatePreviews(); - - m_loadedSchemeHasUnsavedChanges = false; - + schemePreview->setPalette(m_config); emit changed(false); } @@ -1276,32 +369,27 @@ QIcon icon = createSchemePreviewIcon(m_config); schemeList->item(0)->setIcon(icon); - KConfigGroup groupI(m_config, "ColorEffects:Inactive"); - - groupI.writeEntry("Enable", useInactiveEffects->isChecked()); - groupI.writeEntry("IntensityEffect", inactiveIntensityBox->currentIndex()); - groupI.writeEntry("ColorEffect", inactiveColorBox->currentIndex()); - groupI.writeEntry("ContrastEffect", inactiveContrastBox->currentIndex()); - m_config->sync(); - KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); + + KConfig cfg(QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals); KConfigGroup displayGroup(&cfg, "X11"); displayGroup.writeEntry("exportKDEColors", applyToAlien->isChecked()); - cfg.sync(); + cfg.sync(); + qDebug() << KRdbExportQtColors << KRdbExportGtkTheme << KRdbExportColors ; runRdb(KRdbExportQtColors | KRdbExportGtkTheme | ( applyToAlien->isChecked() ? KRdbExportColors : 0 ) ); - + qDebug() << "icic"; QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange") ); QList args; args.append(0);//previous KGlobalSettings::PaletteChanged. This is now private API in khintsettings args.append(0);//unused in palette changed but needed for the DBus signature message.setArguments(args); + qDebug() << KConfigGroup(m_config, "General").readEntry("Name"); QDBusConnection::sessionBus().send(message); if (qApp->platformName() == QStringLiteral("xcb")) { // Send signal to all kwin instances - QDBusMessage message = - QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); + QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); QDBusConnection::sessionBus().send(message); } @@ -1324,189 +412,102 @@ } } - // Reset options (not part of scheme) - m_config->setReadDefaults(true); - loadOptions(); - m_config->setReadDefaults(false); - applyToAlien->setChecked(Qt::Checked); - KCModule::defaults(); emit changed(true); } -void KColorCm::emitChanged() -{ - emit changed(true); -} - -// inactive effects slots -void KColorCm::on_inactiveIntensityBox_currentIndexChanged(int index) -{ - Q_UNUSED( index ); - - updateFromEffectsPage(); - inactivePreview->setPalette(m_config, QPalette::Inactive); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_inactiveIntensitySlider_valueChanged(int value) -{ - Q_UNUSED( value ); - - updateFromEffectsPage(); - inactivePreview->setPalette(m_config, QPalette::Inactive); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_inactiveColorBox_currentIndexChanged(int index) -{ - Q_UNUSED( index ); - - updateFromEffectsPage(); - inactivePreview->setPalette(m_config, QPalette::Inactive); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_inactiveColorSlider_valueChanged(int value) -{ - Q_UNUSED( value ); - - updateFromEffectsPage(); - inactivePreview->setPalette(m_config, QPalette::Inactive); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_inactiveColorButton_changed(const QColor& color) -{ - Q_UNUSED( color ); - - updateFromEffectsPage(); - inactivePreview->setPalette(m_config, QPalette::Inactive); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_inactiveContrastBox_currentIndexChanged(int index) -{ - Q_UNUSED( index ); - - updateFromEffectsPage(); - inactivePreview->setPalette(m_config, QPalette::Inactive); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_inactiveContrastSlider_valueChanged(int value) -{ - Q_UNUSED( value ); - - updateFromEffectsPage(); - inactivePreview->setPalette(m_config, QPalette::Inactive); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -// disabled effects slots -void KColorCm::on_disabledIntensityBox_currentIndexChanged(int index) +void KColorCm::on_schemeEditButton_clicked() { - Q_UNUSED( index ); - - updateFromEffectsPage(); - disabledPreview->setPalette(m_config, QPalette::Disabled); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_disabledIntensitySlider_valueChanged(int value) -{ - Q_UNUSED( value ); - - updateFromEffectsPage(); - disabledPreview->setPalette(m_config, QPalette::Disabled); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_disabledColorBox_currentIndexChanged(int index) -{ - Q_UNUSED( index ); - - updateFromEffectsPage(); - disabledPreview->setPalette(m_config, QPalette::Disabled); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); -} - -void KColorCm::on_disabledColorSlider_valueChanged(int value) -{ - Q_UNUSED( value ); - - updateFromEffectsPage(); - disabledPreview->setPalette(m_config, QPalette::Disabled); - - m_loadedSchemeHasUnsavedChanges = true; - - emit changed(true); + QListWidgetItem *currentItem = schemeList->currentItem(); + const QString fileBaseName = currentItem->data(Qt::UserRole).toString(); + const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + "color-schemes/" + fileBaseName + ".colors"); + if (path.isEmpty()) { + KMessageBox::sorry(this, i18n("This scheme was not found."), i18n("File not found")); + return; + } + SchemeEditorDialog* dialog = new SchemeEditorDialog(path, this); + dialog->setModal(true); + dialog->show(); + connect(dialog, &SchemeEditorDialog::accepted, [=](){ this->populateSchemeList(); }); + connect(dialog, &SchemeEditorDialog::rejected, [=](){ this->populateSchemeList(); }); } -void KColorCm::on_disabledColorButton_changed(const QColor& color) +void KColorCm::updateConfig(KSharedConfigPtr config) { - Q_UNUSED( color ); - - updateFromEffectsPage(); - disabledPreview->setPalette(m_config, QPalette::Disabled); + // store colorscheme name in global settings + KConfigGroup groupOut(m_config, "General"); + groupOut.writeEntry("ColorScheme", m_currentColorScheme); + + QStringList colorItemList; + colorItemList << "BackgroundNormal" + << "BackgroundAlternate" + << "ForegroundNormal" + << "ForegroundInactive" + << "ForegroundActive" + << "ForegroundLink" + << "ForegroundVisited" + << "ForegroundNegative" + << "ForegroundNeutral" + << "ForegroundPositive" + << "DecorationFocus" + << "DecorationHover"; + + QStringList colorSetGroupList; + colorSetGroupList << "Colors:Window" + << "Colors:Button" + << "Colors:Selection" + << "Colors:Tooltip" + << "Colors:View"; + for (const QString &colorSetGroup : colorSetGroupList) + { + KConfigGroup groupOut(m_config, colorSetGroup); + KConfigGroup groupTheme(config, colorSetGroup); + + for (const QString &coloritem : colorItemList) + { + groupOut.writeEntry(coloritem, groupTheme.readEntry(coloritem)); + } + } - m_loadedSchemeHasUnsavedChanges = true; + KConfigGroup groupWMTheme(config, "WM"); + KConfigGroup groupWMOut(m_config, "WM"); - emit changed(true); -} + QStringList colorItemListWM; + colorItemListWM << "activeBackground" + << "activeForeground" + << "inactiveBackground" + << "inactiveForeground" + << "activeBlend" + << "inactiveBlend"; -void KColorCm::on_disabledContrastBox_currentIndexChanged(int index) -{ - Q_UNUSED( index ); - - updateFromEffectsPage(); - disabledPreview->setPalette(m_config, QPalette::Disabled); + for (const QString &coloritem : colorItemListWM) + { + groupWMOut.writeEntry(coloritem, groupWMTheme.readEntry(coloritem)); + } - m_loadedSchemeHasUnsavedChanges = true; + QStringList groupNameList; + groupNameList << "ColorEffects:Inactive" << "ColorEffects:Disabled"; - emit changed(true); -} + QStringList effectList; + effectList << "IntensityEffect" + << "IntensityAmount" + << "ColorEffect" + << "ColorAmount" + << "Color" + << "ContrastEffect" + << "ContrastAmount"; -void KColorCm::on_disabledContrastSlider_valueChanged(int value) -{ - Q_UNUSED( value ); + for (const QString &groupName : groupNameList) + { - updateFromEffectsPage(); - disabledPreview->setPalette(m_config, QPalette::Disabled); + KConfigGroup groupEffectOut(m_config, groupName); + KConfigGroup groupEffectTheme(config, groupName); - m_loadedSchemeHasUnsavedChanges = true; + for (const QString &effect : effectList) { + groupEffectOut.writeEntry(effect, groupEffectTheme.readEntry("effect")); - emit changed(true); + } + } } - #include "colorscm.moc" Index: kcms/colors/colorsettings.ui =================================================================== --- kcms/colors/colorsettings.ui +++ kcms/colors/colorsettings.ui @@ -6,7 +6,7 @@ 0 0 - 477 + 736 422 @@ -24,1160 +24,117 @@ 0 - - - 0 - - - - &Scheme - - - - - - - 0 - 0 - - - - - 23 - 16 - - - - - - - - Get new color schemes from the Internet - - - Get &New Scheme - - - - - - - Import a color scheme from a file - - - &Install from File - - - - - - - false - - - Share the selected scheme on the Internet - - - Upload Scheme - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Save the current color scheme - - - Save Scheme - - - - - - - false - - - Remove the selected scheme - - - Remove Scheme - - - - - - - - 0 - 0 - - - - - 0 - 10 - - - - - - - - - Options - - - - - - Apply inactive window color &effects - - - - - - - In&active selection changes color - - - - - - - Shade sorted column &in lists - - - - - - - true - - - Apply colors to &non-Qt applications - - - - - - - Shading of frames and lighting ("3D") effects - - - Shading - - - - 12 - - - 0 - - - - - Minimum - - - - - - - Qt::Horizontal - - - - 198 - 20 - - - - - - - - Maximum - - - - - - - Contrast - - - - - - - 10 - - - 5 - - - Qt::Horizontal - - - - - - - - - - Qt::Vertical - - - - 20 - 141 - - - - - - - - - Colors - - - - - - - 0 - 0 - - - - Color set: - - - - - - - - 0 - 0 - - - - Colorset to view/modify - - - - Common Colors - - - - - View - - - - - Window - - - - - Button - - - - - Selection - - - - - Tooltip - - - - - Complementary - - - - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - 2 - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - New Row - - - - - 0 - - - - - 1 - - - - - View Background - - - - - View Text - - - - - Window Background - - - - - Window Text - - - - - Button Background - - - - - Button Text - - - - - Selection Background - - - - - Selection Text - - - - - Selection Inactive Text - - - - - Inactive Text - - - - - Active Text - - - - - Link Text - - - - - Visited Text - - - - - Negative Text - - - - - Neutral Text - - - - - Positive Text - - - - - Focus Decoration - - - - - Hover Decoration - - - - - Tooltip Background - - - - - Tooltip Text - - - - - Active Titlebar - - - - - Active Titlebar Text - - - - - Active Titlebar Secondary - - - - - Inactive Titlebar - - - - - Inactive Titlebar Text - - - - - Inactive Titlebar Secondary - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - true - - - 2 - - - - - - - - - - - - - - 0 - 0 - - - - - 0 - 10 - - - - - - - - - Disabled - - - - - - Intensity: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Disabled intensity effect type - - - - None - - - - - Shade - - - - - Darken - - - - - Lighten - - - - - - - - false - - - Disabled intensity effect amount - - - 40 - - - 10 - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 69 - 22 - - - - - - - - Color: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Disabled color effect type - - - - None - - - - - Desaturate - - - - - Fade - - - - - Tint - - - - - - - - false - - - Disabled color effect amount - - - 40 - - - 10 - - - Qt::Horizontal - - - - - - - false - - - Disabled color - - - - - - - Contrast: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Disabled contrast type - - - - None - - - - - Fade - - - - - Tint - - - - - - - - false - - - Disabled contrast amount - - - 20 - - - 10 - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 69 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - 0 - 0 - - - - - 0 - 10 - - - - - - - - - Inactive - - - - - - Intensity: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Inactive intensity effect type - - - - None - - - - - Shade - - - - - Darken - - - - - Lighten - - - - - - - - false - - - Inactive intensity effect amount - - - 40 - - - 10 - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 69 - 22 - - - - - - - - Color: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Inactive color effect type - - - - None - - - - - Desaturate - - - - - Fade - - - - - Tint - - - - - - - - false - - - Inactive color amount - - - 40 - - - 10 - - - Qt::Horizontal - - - - - - - false - - - Inactive color - - - - - - - Contrast: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Inactive contrast effect type - - - - None - - - - - Fade - - - - - Tint - - - - - - - - false - - - Inactive contrast effect amount - - - 20 - - - 5 - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 69 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - 0 - 0 - - - - - 0 - 10 - - - - - - - + + + + + Configure the current color scheme + + + Edit Scheme + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Remove the selected scheme + + + Remove Scheme + + + false + + + + + + + Get new color schemes from the Internet + + + Get &New Scheme + + + + + + + + 0 + 0 + + + + + 23 + 16 + + + + + + + + + 0 + 0 + + + + + 0 + 10 + + + + + + + + Import a color scheme from a file + + + &Install from File + + + + + + + true + + + Apply colors to &non-Qt applications + + + + - KColorButton - QPushButton -
kcolorbutton.h
-
- PreviewWidget QWidget
previewwidget.h
@@ -1186,28 +143,6 @@
schemeList - useInactiveEffects - inactiveSelectionEffect - shadeSortedColumn - applyToAlien - contrastSlider - colorSet - commonColorTable - inactiveIntensityBox - inactiveIntensitySlider - inactiveColorBox - inactiveColorSlider - inactiveContrastBox - inactiveContrastSlider - inactiveColorButton - disabledIntensityBox - disabledIntensitySlider - disabledColorBox - disabledColorSlider - disabledContrastBox - disabledContrastSlider - disabledColorButton - colorTable Index: kcms/colors/kcolorschemeeditor.cpp =================================================================== --- /dev/null +++ kcms/colors/kcolorschemeeditor.cpp @@ -0,0 +1,76 @@ +/* KDE Display scheme editor + * Copyright (C) 2016 Olivier Churlaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "scmeditordialog.h" + +#include +#include +#include + +#include + +int main(int argc, char* argv[]) +{ + + QApplication app(argc, argv); + + KAboutData aboutData( + QStringLiteral("kcolorschemeeditor"), + i18n("KColorSchemeEditor"), + QStringLiteral("0.1"), + i18n("Utility to edit and create color schemes"), + KAboutLicense::GPL_V3 + ); + aboutData.addAuthor(i18n("Olivier Churlaud"), i18n("Utility creation"), + QStringLiteral("olivier@churlaud.com")); + aboutData.addAuthor(i18n("Jeremy Whiting"), i18n("KCM code (reused in here)"), + QStringLiteral("jpwhiting@kde.org")); + aboutData.addAuthor(i18n("Matthew Woehlke"), i18n("KCM code (reused in here)"), + QStringLiteral("mw_triad@users.sourceforge.net")); + KAboutData::setApplicationData(aboutData); + + QCommandLineParser parser; + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("theme", i18n("Scheme to edit or to use as a base."), + QStringLiteral("kcolorschemeeditor ThemeName")); + aboutData.setupCommandLine(&parser); + parser.process(app); + aboutData.processCommandLine(&parser); + + const QStringList args = parser.positionalArguments(); + QString path = ""; + if (args.count() == 1) + { + const QString fileBaseName(args.at(0)); + path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + "color-schemes/" + fileBaseName + ".colors"); + } + if (path.isEmpty()) + { + QTextStream out(stderr); + out << i18n("Scheme not found, falling back to current one.\n"); + } + + SchemeEditorDialog dialog(path); + + dialog.show(); + + return app.exec(); +} Index: kcms/colors/kcolorschemeeditor.desktop =================================================================== --- /dev/null +++ kcms/colors/kcolorschemeeditor.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +GenericName=Color scheme editor +Name=KColorSchemeEditor +Comment=Plasma color scheme editor +MimeType=text/plain; +Exec=kcolorschemeeditor +StartupNotify=true +Icon=preferences-desktop-color +Type=Application +Terminal=false +Categories=Qt;KDE;X-KDE-settings-looknfeel; Index: kcms/colors/scmeditorcolors.h =================================================================== --- /dev/null +++ kcms/colors/scmeditorcolors.h @@ -0,0 +1,121 @@ +/* ColorEdit widget for KDE Display color scheme setup module + * Copyright (C) 2016 Olivier Churlaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SCMEDITORCOLORS_H__ +#define __SCMEDITORCOLORS_H__ + +#include +#include + +#include +#include +#include + +#include "colorscm.h" + +#include "ui_scmeditorcolors.h" + +class KColorButton; + +class SchemeEditorColors : public QWidget, public Ui::ScmEditorColors +{ + Q_OBJECT + +public: + SchemeEditorColors(KSharedConfigPtr config, QWidget *parent = Q_NULLPTR); + void updateValues(); + void updateFromColorSchemes(); + +Q_SIGNALS: + void changed(bool); + +private Q_SLOTS: + + /** slot called when any varies button is clicked */ + void variesClicked(); + + /** slot called when color on a KColorButton changes */ + void colorChanged( const QColor &newColor ); + + /** set the colortable color buttons up according to the current colorset */ + void updateColorTable(); + + /** update m_colorSchemes contents from the values in m_config */ + void updateColorSchemes(); + + /** setup the colortable with its buttons and labels */ + void setupColorTable(); + +private: + class WindecoColors { + public: + enum Role { + ActiveForeground = 0, + ActiveBackground = 1, + InactiveForeground = 2, + InactiveBackground = 3, + ActiveBlend = 4, + InactiveBlend = 5 + }; + + WindecoColors() {} + WindecoColors(const KSharedConfigPtr&); + virtual ~WindecoColors() {} + + void load(const KSharedConfigPtr&); + QColor color(Role) const; + private: + QColor m_colors[6]; + }; + + void changeColor(int row, const QColor &newColor); + + /** helper to create color entries */ + void createColorEntry(const QString &text, + const QString &key, + QList &list, + int index); + + void setCommonForeground(KColorScheme::ForegroundRole role, + int stackIndex, + int buttonIndex); + void setCommonDecoration(KColorScheme::DecorationRole role, + int stackIndex, + int buttonIndex); + + /** get the groupKey for the given colorSet */ + static QString colorSetGroupKey(int colorSet); + + QList m_backgroundButtons; + QList m_foregroundButtons; + QList m_decorationButtons; + QList m_commonColorButtons; + QList m_colorSchemes; + QList m_stackedWidgets; + + QStringList m_colorKeys; + + WindecoColors m_wmColors; + + KSharedConfigPtr m_config; + + +}; + +#endif Index: kcms/colors/scmeditorcolors.cpp =================================================================== --- /dev/null +++ kcms/colors/scmeditorcolors.cpp @@ -0,0 +1,519 @@ +/* KDE Display color scheme setup module + * Copyright (C) 2007 Matthew Woehlke + * Copyright (C) 2007 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "scmeditorcolors.h" + +#include + +#include +#include + +//BEGIN WindecoColors +SchemeEditorColors::WindecoColors::WindecoColors(const KSharedConfigPtr &config) +{ + load(config); +} + +void SchemeEditorColors::WindecoColors::load(const KSharedConfigPtr &config) +{ + // NOTE: keep this in sync with kdelibs/kdeui/kernel/kglobalsettings.cpp + KConfigGroup group(config, "WM"); + m_colors[ActiveBackground] = group.readEntry("activeBackground", QColor(48, 174, 232)); + m_colors[ActiveForeground] = group.readEntry("activeForeground", QColor(255, 255, 255)); + m_colors[InactiveBackground] = group.readEntry("inactiveBackground", QColor(224, 223, 222)); + m_colors[InactiveForeground] = group.readEntry("inactiveForeground", QColor(75, 71, 67)); + m_colors[ActiveBlend] = group.readEntry("activeBlend", m_colors[ActiveForeground]); + m_colors[InactiveBlend] = group.readEntry("inactiveBlend", m_colors[InactiveForeground]); +} + +QColor SchemeEditorColors::WindecoColors::color(WindecoColors::Role role) const +{ + return m_colors[role]; +} +//END WindecoColors + + +SchemeEditorColors::SchemeEditorColors(KSharedConfigPtr config, QWidget *parent) + : QWidget( parent ) + , m_config( config ) +{ + setupUi(this); + setupColorTable(); +} + +void SchemeEditorColors::updateValues() +{ + preview->setPalette(m_config); +} + +void SchemeEditorColors::setupColorTable() +{ + // first setup the common colors table + commonColorTable->verticalHeader()->hide(); + commonColorTable->horizontalHeader()->hide(); + commonColorTable->setShowGrid(false); + commonColorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); + int minWidth = QPushButton(i18n("Varies")).minimumSizeHint().width(); + commonColorTable->horizontalHeader()->setMinimumSectionSize(minWidth); + commonColorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + + for (int i = 0; i < 26; ++i) + { + KColorButton * button = new KColorButton(this); + commonColorTable->setRowHeight(i, button->sizeHint().height()); + button->setObjectName(QString::number(i)); + connect(button, &KColorButton::changed, this, &SchemeEditorColors::colorChanged); + m_commonColorButtons << button; + + if (i > 8 && i < 18) + { + // Inactive Text row through Positive Text role all need a varies button + QPushButton * variesButton = new QPushButton(NULL); + variesButton->setText(i18n("Varies")); + variesButton->setObjectName(QString::number(i)); + connect(variesButton, &QPushButton::clicked, this, &SchemeEditorColors::variesClicked); + + QStackedWidget * widget = new QStackedWidget(this); + widget->addWidget(button); + widget->addWidget(variesButton); + m_stackedWidgets.append(widget); + + commonColorTable->setCellWidget(i, 1, widget); + } + else + { + commonColorTable->setCellWidget(i, 1, button); + } + } + + // then the colorTable that the colorSets will use + colorTable->verticalHeader()->hide(); + colorTable->horizontalHeader()->hide(); + colorTable->setShowGrid(false); + colorTable->setRowCount(12); + colorTable->horizontalHeader()->setMinimumSectionSize(minWidth); + colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + + createColorEntry(i18n("Normal Background"), QStringLiteral("BackgroundNormal"), m_backgroundButtons, 0); + createColorEntry(i18n("Alternate Background"), QStringLiteral("BackgroundAlternate"), m_backgroundButtons, 1); + createColorEntry(i18n("Normal Text"), QStringLiteral("ForegroundNormal"), m_foregroundButtons, 2); + createColorEntry(i18n("Inactive Text"), QStringLiteral("ForegroundInactive"), m_foregroundButtons, 3); + createColorEntry(i18n("Active Text"), QStringLiteral("ForegroundActive"), m_foregroundButtons, 4); + createColorEntry(i18n("Link Text"), QStringLiteral("ForegroundLink"), m_foregroundButtons, 5); + createColorEntry(i18n("Visited Text"), QStringLiteral("ForegroundVisited"), m_foregroundButtons, 6); + createColorEntry(i18n("Negative Text"), QStringLiteral("ForegroundNegative"), m_foregroundButtons, 7); + createColorEntry(i18n("Neutral Text"), QStringLiteral("ForegroundNeutral"), m_foregroundButtons, 8); + createColorEntry(i18n("Positive Text"), QStringLiteral("ForegroundPositive"), m_foregroundButtons, 9); + createColorEntry(i18n("Focus Decoration"), QStringLiteral("DecorationFocus"), m_decorationButtons, 10); + createColorEntry(i18n("Hover Decoration"), QStringLiteral("DecorationHover"), m_decorationButtons, 11); + + colorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); + colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + + updateColorSchemes(); + updateColorTable(); +} + +void SchemeEditorColors::createColorEntry(const QString &text, const QString &key, QList &list, int index) +{ + KColorButton *button = new KColorButton(this); + button->setObjectName(QString::number(index)); + connect(button, &KColorButton::changed, this, &SchemeEditorColors::colorChanged); + list.append(button); + + m_colorKeys.insert(index, key); + + QTableWidgetItem *label = new QTableWidgetItem(text); + colorTable->setItem(index, 0, label); + colorTable->setCellWidget(index, 1, button); + colorTable->setRowHeight(index, button->sizeHint().height()); +} + +void SchemeEditorColors::variesClicked() +{ + // find which button was changed + const int row = sender()->objectName().toInt(); + + QColor color = QColorDialog::getColor(QColor(), this); + if(color.isValid()) + { + changeColor(row, color); + m_stackedWidgets[row - 9]->setCurrentIndex(0); + } +} + +void SchemeEditorColors::colorChanged( const QColor &newColor ) +{ + // find which button was changed + const int row = sender()->objectName().toInt(); + changeColor(row, newColor); +} + +void SchemeEditorColors::changeColor(int row, const QColor &newColor) +{ + // update the m_colorSchemes for the selected colorSet + const int currentSet = colorSet->currentIndex() - 1; + + if (currentSet == -1) + { + // common colors is selected + switch (row) + { + case 0: + // View Background button + KConfigGroup(m_config, "Colors:View").writeEntry("BackgroundNormal", newColor); + break; + case 1: + // View Text button + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNormal", newColor); + break; + case 2: + // Window Background Button + KConfigGroup(m_config, "Colors:Window").writeEntry("BackgroundNormal", newColor); + break; + case 3: + // Window Text Button + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNormal", newColor); + break; + case 4: + // Button Background button + KConfigGroup(m_config, "Colors:Button").writeEntry("BackgroundNormal", newColor); + break; + case 5: + // Button Text button + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNormal", newColor); + break; + case 6: + // Selection Background Button + KConfigGroup(m_config, "Colors:Selection").writeEntry("BackgroundNormal", newColor); + break; + case 7: + // Selection Text Button + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNormal", newColor); + break; + case 8: + // Selection Inactive Text Button + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundInactive", newColor); + break; + + // buttons that could have varies in their place + case 9: + // Inactive Text Button (set all but Selection Inactive Text color) + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundInactive", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundInactive", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundInactive", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundInactive", newColor); + break; + case 10: + // Active Text Button (set all active text colors) + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundActive", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundActive", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundActive", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundActive", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundActive", newColor); + break; + case 11: + // Link Text Button (set all link text colors) + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundLink", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundLink", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundLink", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundLink", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundLink", newColor); + break; + case 12: + // Visited Text Button (set all visited text colors) + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundVisited", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundVisited", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundVisited", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundVisited", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundVisited", newColor); + break; + case 13: + // Negative Text Button (set all negative text colors) + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNegative", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNegative", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNegative", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNegative", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNegative", newColor); + break; + case 14: + // Neutral Text Button (set all neutral text colors) + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNeutral", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNeutral", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNeutral", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNeutral", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNeutral", newColor); + break; + case 15: + // Positive Text Button (set all positive text colors) + KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundPositive", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundPositive", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundPositive", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundPositive", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundPositive", newColor); + break; + + case 16: + // Focus Decoration Button (set all focus decoration colors) + KConfigGroup(m_config, "Colors:View").writeEntry("DecorationFocus", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationFocus", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationFocus", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationFocus", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationFocus", newColor); + break; + case 17: + // Hover Decoration Button (set all hover decoration colors) + KConfigGroup(m_config, "Colors:View").writeEntry("DecorationHover", newColor); + KConfigGroup(m_config, "Colors:Window").writeEntry("DecorationHover", newColor); + KConfigGroup(m_config, "Colors:Selection").writeEntry("DecorationHover", newColor); + KConfigGroup(m_config, "Colors:Button").writeEntry("DecorationHover", newColor); + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("DecorationHover", newColor); + break; + + case 18: + // Tooltip Background button + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("BackgroundNormal", newColor); + break; + case 19: + // Tooltip Text button + KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNormal", newColor); + break; + case 20: + // Active Title Background + KConfigGroup(m_config, "WM").writeEntry("activeBackground", newColor); + break; + case 21: + // Active Title Text + KConfigGroup(m_config, "WM").writeEntry("activeForeground", newColor); + break; + case 22: + // Active Title Secondary + KConfigGroup(m_config, "WM").writeEntry("activeBlend", newColor); + break; + case 23: + // Inactive Title Background + KConfigGroup(m_config, "WM").writeEntry("inactiveBackground", newColor); + break; + case 24: + // Inactive Title Text + KConfigGroup(m_config, "WM").writeEntry("inactiveForeground", newColor); + break; + case 25: + // Inactive Title Secondary + KConfigGroup(m_config, "WM").writeEntry("inactiveBlend", newColor); + break; + } + m_commonColorButtons[row]->blockSignals(true); + m_commonColorButtons[row]->setColor(newColor); + m_commonColorButtons[row]->blockSignals(false); + } + else + { + QString group = colorSetGroupKey(currentSet); + KConfigGroup(m_config, group).writeEntry(m_colorKeys[row], newColor); + } + + updateColorSchemes(); + + emit changed(true); +} + +QString SchemeEditorColors::colorSetGroupKey(int colorSet) +{ + QString group; + switch (colorSet) { + case KColorScheme::Window: + group = QStringLiteral("Colors:Window"); + break; + case KColorScheme::Button: + group = QStringLiteral("Colors:Button"); + break; + case KColorScheme::Selection: + group = QStringLiteral("Colors:Selection"); + break; + case KColorScheme::Tooltip: + group = QStringLiteral("Colors:Tooltip"); + break; + default: + group = QStringLiteral("Colors:View"); + } + return group; +} + +void SchemeEditorColors::updateColorSchemes() +{ + m_colorSchemes.clear(); + + m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::View, m_config)); + m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Window, m_config)); + m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Button, m_config)); + m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Selection, m_config)); + m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Tooltip, m_config)); + m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Complementary, m_config)); + + m_wmColors.load(m_config); +} + +void SchemeEditorColors::updateColorTable() +{ + // subtract one here since the 0 item is "Common Colors" + const int currentSet = colorSet->currentIndex() - 1; + + if (currentSet == -1) + { + // common colors is selected + stackColors->setCurrentIndex(0); + // stackPreview->setCurrentIndex(0); + + KColorButton * button; + foreach (button, m_commonColorButtons) + { + button->blockSignals(true); + } + + m_commonColorButtons[0]->setColor(m_colorSchemes[KColorScheme::View].background(KColorScheme::NormalBackground).color()); + m_commonColorButtons[1]->setColor(m_colorSchemes[KColorScheme::View].foreground(KColorScheme::NormalText).color()); + m_commonColorButtons[2]->setColor(m_colorSchemes[KColorScheme::Window].background(KColorScheme::NormalBackground).color()); + m_commonColorButtons[3]->setColor(m_colorSchemes[KColorScheme::Window].foreground(KColorScheme::NormalText).color()); + m_commonColorButtons[4]->setColor(m_colorSchemes[KColorScheme::Button].background(KColorScheme::NormalBackground).color()); + m_commonColorButtons[5]->setColor(m_colorSchemes[KColorScheme::Button].foreground(KColorScheme::NormalText).color()); + m_commonColorButtons[6]->setColor(m_colorSchemes[KColorScheme::Selection].background(KColorScheme::NormalBackground).color()); + m_commonColorButtons[7]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::NormalText).color()); + m_commonColorButtons[8]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::InactiveText).color()); + + setCommonForeground(KColorScheme::InactiveText, 0, 9); + setCommonForeground(KColorScheme::ActiveText, 1, 10); + setCommonForeground(KColorScheme::LinkText, 2, 11); + setCommonForeground(KColorScheme::VisitedText, 3, 12); + setCommonForeground(KColorScheme::NegativeText, 4, 13); + setCommonForeground(KColorScheme::NeutralText, 5, 14); + setCommonForeground(KColorScheme::PositiveText, 6, 15); + + setCommonDecoration(KColorScheme::FocusColor, 7, 16); + setCommonDecoration(KColorScheme::HoverColor, 8, 17); + + m_commonColorButtons[18]->setColor(m_colorSchemes[KColorScheme::Tooltip].background(KColorScheme::NormalBackground).color()); + m_commonColorButtons[19]->setColor(m_colorSchemes[KColorScheme::Tooltip].foreground(KColorScheme::NormalText).color()); + + m_commonColorButtons[20]->setColor(m_wmColors.color(WindecoColors::ActiveBackground)); + m_commonColorButtons[21]->setColor(m_wmColors.color(WindecoColors::ActiveForeground)); + m_commonColorButtons[22]->setColor(m_wmColors.color(WindecoColors::ActiveBlend)); + m_commonColorButtons[23]->setColor(m_wmColors.color(WindecoColors::InactiveBackground)); + m_commonColorButtons[24]->setColor(m_wmColors.color(WindecoColors::InactiveForeground)); + m_commonColorButtons[25]->setColor(m_wmColors.color(WindecoColors::InactiveBlend)); + + foreach (button, m_commonColorButtons) + { + button->blockSignals(false); + } + } + else + { + // a real color set is selected + stackColors->setCurrentIndex(1); + + for (int i = KColorScheme::NormalBackground; i <= KColorScheme::AlternateBackground; ++i) + { + m_backgroundButtons[i]->blockSignals(true); + m_backgroundButtons[i]->setColor(m_colorSchemes[currentSet].background(KColorScheme::BackgroundRole(i)).color()); + m_backgroundButtons[i]->blockSignals(false); + } + + for (int i = KColorScheme::NormalText; i <= KColorScheme::PositiveText; ++i) + { + m_foregroundButtons[i]->blockSignals(true); + m_foregroundButtons[i]->setColor(m_colorSchemes[currentSet].foreground(KColorScheme::ForegroundRole(i)).color()); + m_foregroundButtons[i]->blockSignals(false); + } + + for (int i = KColorScheme::FocusColor; i <= KColorScheme::HoverColor; ++i) + { + m_decorationButtons[i]->blockSignals(true); + m_decorationButtons[i]->setColor(m_colorSchemes[currentSet].decoration(KColorScheme::DecorationRole(i)).color()); + m_decorationButtons[i]->blockSignals(false); + } + } +} + + +void SchemeEditorColors::setCommonForeground(KColorScheme::ForegroundRole role, int stackIndex, + int buttonIndex) +{ + QColor color = m_colorSchemes[KColorScheme::View].foreground(role).color(); + for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) + { + if (i == KColorScheme::Selection && role == KColorScheme::InactiveText) + break; + + if (m_colorSchemes[i].foreground(role).color() != color) + { + m_stackedWidgets[stackIndex]->setCurrentIndex(1); + return; + } + } + + m_stackedWidgets[stackIndex]->setCurrentIndex(0); + m_commonColorButtons[buttonIndex]->setColor(color); +} + +void SchemeEditorColors::setCommonDecoration(KColorScheme::DecorationRole role, int stackIndex, + int buttonIndex) +{ + QColor color = m_colorSchemes[KColorScheme::View].decoration(role).color(); + for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i) + { + if (m_colorSchemes[i].decoration(role).color() != color) + { + m_stackedWidgets[stackIndex]->setCurrentIndex(1); + return; + } + } + + m_stackedWidgets[stackIndex]->setCurrentIndex(0); + m_commonColorButtons[buttonIndex]->setColor(color); +} + +void SchemeEditorColors::updateFromColorSchemes() +{ + for (int i = KColorScheme::View; i <= KColorScheme::Tooltip; ++i) + { + KConfigGroup group(m_config, colorSetGroupKey(i)); + group.writeEntry("BackgroundNormal", m_colorSchemes[i].background(KColorScheme::NormalBackground).color()); + group.writeEntry("BackgroundAlternate", m_colorSchemes[i].background(KColorScheme::AlternateBackground).color()); + group.writeEntry("ForegroundNormal", m_colorSchemes[i].foreground(KColorScheme::NormalText).color()); + group.writeEntry("ForegroundInactive", m_colorSchemes[i].foreground(KColorScheme::InactiveText).color()); + group.writeEntry("ForegroundActive", m_colorSchemes[i].foreground(KColorScheme::ActiveText).color()); + group.writeEntry("ForegroundLink", m_colorSchemes[i].foreground(KColorScheme::LinkText).color()); + group.writeEntry("ForegroundVisited", m_colorSchemes[i].foreground(KColorScheme::VisitedText).color()); + group.writeEntry("ForegroundNegative", m_colorSchemes[i].foreground(KColorScheme::NegativeText).color()); + group.writeEntry("ForegroundNeutral", m_colorSchemes[i].foreground(KColorScheme::NeutralText).color()); + group.writeEntry("ForegroundPositive", m_colorSchemes[i].foreground(KColorScheme::PositiveText).color()); + group.writeEntry("DecorationFocus", m_colorSchemes[i].decoration(KColorScheme::FocusColor).color()); + group.writeEntry("DecorationHover", m_colorSchemes[i].decoration(KColorScheme::HoverColor).color()); + } + + KConfigGroup WMGroup(m_config, "WM"); + WMGroup.writeEntry("activeBackground", m_wmColors.color(WindecoColors::ActiveBackground)); + WMGroup.writeEntry("activeForeground", m_wmColors.color(WindecoColors::ActiveForeground)); + WMGroup.writeEntry("inactiveBackground", m_wmColors.color(WindecoColors::InactiveBackground)); + WMGroup.writeEntry("inactiveForeground", m_wmColors.color(WindecoColors::InactiveForeground)); + WMGroup.writeEntry("activeBlend", m_wmColors.color(WindecoColors::ActiveBlend)); + WMGroup.writeEntry("inactiveBlend", m_wmColors.color(WindecoColors::InactiveBlend)); +} Index: kcms/colors/scmeditorcolors.ui =================================================================== --- /dev/null +++ kcms/colors/scmeditorcolors.ui @@ -0,0 +1,437 @@ + + + ScmEditorColors + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + 0 + 0 + + + + Color set: + + + + + + + + 0 + 0 + + + + Colorset to view/modify + + + + Common Colors + + + + + View + + + + + Window + + + + + Button + + + + + Selection + + + + + Tooltip + + + + + Complementary + + + + + + + + + 0 + 0 + + + + + 0 + 10 + + + + + + + + 0 + + + + + 0 + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + 2 + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + 0 + + + + + 1 + + + + + View Background + + + + + View Text + + + + + Window Background + + + + + Window Text + + + + + Button Background + + + + + Button Text + + + + + Selection Background + + + + + Selection Text + + + + + Selection Inactive Text + + + + + Inactive Text + + + + + Active Text + + + + + Link Text + + + + + Visited Text + + + + + Negative Text + + + + + Neutral Text + + + + + Positive Text + + + + + Focus Decoration + + + + + Hover Decoration + + + + + Tooltip Background + + + + + Tooltip Text + + + + + Active Titlebar + + + + + Active Titlebar Text + + + + + Active Titlebar Secondary + + + + + Inactive Titlebar + + + + + Inactive Titlebar Text + + + + + Inactive Titlebar Secondary + + + + + + + + + + 0 + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + 2 + + + + + + + + + + + + + + PreviewWidget + QWidget +
previewwidget.h
+ 1 +
+
+ + +
Index: kcms/colors/scmeditordialog.h =================================================================== --- /dev/null +++ kcms/colors/scmeditordialog.h @@ -0,0 +1,81 @@ +/* ColorEdit widget for KDE Display color scheme setup module + * Copyright (C) 2016 Olivier Churlaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SCMEDITORDIALOG_H__ +#define __SCMEDITORDIALOG_H__ + +#include +#include + +#include +#include +#include + +#include "ui_scmeditordialog.h" + +#include "colorscm.h" + +class SchemeEditorOptions; +class SchemeEditorColors; +class SchemeEditorEffects; + +class SchemeEditorDialog : public QDialog, public Ui::ScmEditorDialog +{ + Q_OBJECT + +public: + SchemeEditorDialog(const QString &path, QWidget *parent=Q_NULLPTR); + +Q_SIGNALS: + void changed(bool); + +private Q_SLOTS: + + /** slot called when the upload scheme button is clicked */ + void on_schemeKnsUploadButton_clicked(); + + void on_buttonBox_clicked(QAbstractButton *button); + + void updateTabs(bool byUser=false); + +private: + + enum IndexTabs { + OptionTab = 0, + ColorTab, + DisabledTab, + InactiveTab + }; + /** save the current scheme */ + void saveScheme(); + void setUnsavedChanges(bool changes); + + const QString m_filePath; + QString m_schemeName; + KSharedConfigPtr m_config; + bool m_disableUpdates; + bool m_unsavedChanges; + + SchemeEditorOptions *m_optionTab; + SchemeEditorColors *m_colorTab; + SchemeEditorEffects *m_disabledTab; + SchemeEditorEffects *m_inactiveTab; +}; + +#endif Index: kcms/colors/scmeditordialog.cpp =================================================================== --- /dev/null +++ kcms/colors/scmeditordialog.cpp @@ -0,0 +1,230 @@ +/* ColorEdit widget for KDE Display color scheme setup module + * Copyright (C) 2016 Olivier Churlaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "scmeditordialog.h" +#include "scmeditoroptions.h" +#include "scmeditorcolors.h" +#include "scmeditoreffects.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +SchemeEditorDialog::SchemeEditorDialog(const QString &path, QWidget *parent) + : QDialog( parent ) + , m_disableUpdates(false) + , m_filePath(path) + , m_unsavedChanges(false) +{ + m_config = KSharedConfig::openConfig(path); + m_schemeName = KConfigGroup(m_config, "General").readEntry("Name"); + + setupUi(this); + this->setWindowTitle(m_schemeName); + + schemeKnsUploadButton->setIcon( QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")) ); + + m_optionTab = new SchemeEditorOptions(m_config); + m_colorTab = new SchemeEditorColors(m_config); + m_disabledTab = new SchemeEditorEffects(m_config, QPalette::Disabled); + m_inactiveTab = new SchemeEditorEffects(m_config, QPalette::Inactive); + tabWidget->insertTab(OptionTab, m_optionTab, i18n("Options")); + tabWidget->insertTab(ColorTab, m_colorTab, i18n("Colors")); + tabWidget->insertTab(DisabledTab, m_disabledTab, i18n("Disabled")); + + connect(m_optionTab, &SchemeEditorOptions::changed, this, &SchemeEditorDialog::updateTabs); + connect(m_colorTab, &SchemeEditorColors::changed, this, &SchemeEditorDialog::updateTabs); + connect(m_disabledTab, &SchemeEditorEffects::changed, this, &SchemeEditorDialog::updateTabs); + connect(m_inactiveTab, &SchemeEditorEffects::changed, this, &SchemeEditorDialog::updateTabs); + + buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); + buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); + updateTabs(); +} + +void SchemeEditorDialog::on_schemeKnsUploadButton_clicked() +{ + if (m_unsavedChanges) + { + KMessageBox::ButtonCode reallyUpload = KMessageBox::questionYesNo( + this, i18n("This colour scheme was not saved. Continue?"), + i18n("Do you really want to upload?")); + if (reallyUpload == KMessageBox::No) { + return; + } + } + + // find path + const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + "color-schemes/" + m_schemeName + ".colors"); + if (path.isEmpty() ) // if the color scheme file wasn't found + { + qDebug() << "path for color scheme " << m_schemeName << " couldn't be found"; + return; + } + + // upload + KNS3::UploadDialog dialog(QStringLiteral("colorschemes.knsrc"), this); + dialog.setUploadFile(QUrl::fromLocalFile(path) ); + dialog.exec(); +} + +void SchemeEditorDialog::on_buttonBox_clicked(QAbstractButton *button) +{ + if (buttonBox->standardButton(button) == QDialogButtonBox::Reset) + { + m_config->markAsClean();; + m_config->reparseConfiguration(); + updateTabs(); + setUnsavedChanges(false); + } + else if (buttonBox->standardButton(button) == QDialogButtonBox::Save) + { + saveScheme(); + } + else if (buttonBox->standardButton(button) == QDialogButtonBox::Close) + { + if (m_unsavedChanges) { + KMessageBox::ButtonCode ans = KMessageBox::questionYesNo( + this, i18n("You have unsaved changes. Do you really want to quit?"), + i18n("Unsaved changes")); + if (ans == KMessageBox::No) + { + return; + } + } + this->accept(); + } +} + +void SchemeEditorDialog::saveScheme() +{ + // prompt for the name to save as + bool ok; + QString schemeName = KConfigGroup(m_config, "General").readEntry("Name"); + QString name = QInputDialog::getText(this, i18n("Save Color Scheme"), + i18n("&Enter a name for the color scheme:"), QLineEdit::Normal, m_schemeName, &ok); + if (!ok) { + return; + } + + QString filename = name; + filename.remove('\''); // So Foo's does not become FooS + QRegExp fixer(QStringLiteral("[\\W,.-]+(.?)")); + int offset; + while ((offset = fixer.indexIn(filename)) >= 0) + filename.replace(offset, fixer.matchedLength(), fixer.cap(1).toUpper()); + filename.replace(0, 1, filename.at(0).toUpper()); + + // check if that name is already in the list + const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + "color-schemes/" + filename + ".colors"); + + QFile file(path); + const int permissions = file.permissions(); + const bool canWrite = (permissions & QFile::WriteUser); + // or if we can overwrite it if it exists + if (path.isEmpty() || !file.exists() || canWrite) + { + if(canWrite){ + int ret = KMessageBox::questionYesNo(this, + i18n("A color scheme with that name already exists.\nDo you want to overwrite it?"), + i18n("Save Color Scheme"), + KStandardGuiItem::overwrite(), + KStandardGuiItem::cancel()); + + //on don't overwrite, call again the functionn + if(ret == KMessageBox::No){ + this->saveScheme(); + return; + } + } + + // go ahead and save it + QString newpath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + "/color-schemes/"; + QDir dir; + dir.mkpath(newpath); + newpath += filename + ".colors"; + + KConfig *config = m_config->copyTo(newpath); + KConfigGroup group(config, "General"); + group.writeEntry("Name", name); + + // sync it and delete pointer + config->sync(); + delete config; + // reopen and update window + m_config = KSharedConfig::openConfig(newpath); + m_schemeName = name; + setWindowTitle(name); + + setUnsavedChanges(false); + } + else if (!canWrite && file.exists()) + { + KMessageBox::error(this, i18n("You do not have permission to overwrite that scheme"), i18n("Error")); + } +} + +void SchemeEditorDialog::updateTabs(bool madeByUser) +{ + if (madeByUser) + { + setUnsavedChanges(true); + } + KConfigGroup group(m_config, "ColorEffects:Inactive"); + bool hideInactiveTab = group.readEntry("Enable", QVariant(true)).toBool(); + if ( hideInactiveTab ) + { + tabWidget->insertTab(InactiveTab, m_inactiveTab, i18n("Inactive")); + } + else + { + tabWidget->removeTab(InactiveTab); + } + + m_optionTab->updateValues(); + m_colorTab->updateValues(); + m_inactiveTab->updateValues(); + m_disabledTab->updateValues(); +} + +void SchemeEditorDialog::setUnsavedChanges(bool changes) +{ + m_unsavedChanges = changes; + if (changes) + { + buttonBox->button(QDialogButtonBox::Save)->setEnabled(true); + buttonBox->button(QDialogButtonBox::Reset)->setEnabled(true); + } + else + { + buttonBox->button(QDialogButtonBox::Save)->setEnabled(false); + buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); + } +} Index: kcms/colors/scmeditordialog.ui =================================================================== --- /dev/null +++ kcms/colors/scmeditordialog.ui @@ -0,0 +1,74 @@ + + + ScmEditorDialog + + + + 0 + 0 + 477 + 422 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + -1 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + Share the selected scheme on the Internet + + + Upload Scheme + + + + + + + QDialogButtonBox::Close|QDialogButtonBox::Reset|QDialogButtonBox::Save + + + + + + + + + + Index: kcms/colors/scmeditoreffects.h =================================================================== --- /dev/null +++ kcms/colors/scmeditoreffects.h @@ -0,0 +1,68 @@ +/* ColorEdit widget for KDE Display color scheme setup module + * Copyright (C) 2016 Olivier Churlaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SCMEDITOREFFECTS_H__ +#define __SCMEDITOREFFECTS_H__ + +#include +#include + +#include +#include +#include + +#include "ui_scmeditoreffects.h" + + +class SchemeEditorEffects : public QWidget, public Ui::ScmEditorEffects +{ + Q_OBJECT + +public: + SchemeEditorEffects(KSharedConfigPtr config, QPalette::ColorGroup palette, QWidget *parent = Q_NULLPTR); + void updateValues(); + void updateFromEffectsPage(); + +Q_SIGNALS: + void changed(bool); + +private Q_SLOTS: + + void on_intensityBox_currentIndexChanged(int index); + + void on_intensitySlider_valueChanged(int value); + + void on_colorBox_currentIndexChanged(int index); + + void on_colorSlider_valueChanged(int value); + + void on_colorButton_changed(const QColor& color); + + void on_contrastBox_currentIndexChanged(int index); + + void on_contrastSlider_valueChanged(int value); + +private: + QPalette::ColorGroup m_palette; + KSharedConfigPtr m_config; + bool m_disableUpdates; + +}; + +#endif Index: kcms/colors/scmeditoreffects.cpp =================================================================== --- /dev/null +++ kcms/colors/scmeditoreffects.cpp @@ -0,0 +1,186 @@ +/* KDE Display color scheme setup module + * Copyright (C) 2007 Matthew Woehlke + * Copyright (C) 2007 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "scmeditoreffects.h" + +#include +#include + +SchemeEditorEffects::SchemeEditorEffects(KSharedConfigPtr config, QPalette::ColorGroup palette, QWidget *parent) + : QWidget( parent ) + , m_config(config) + , m_palette(palette) +{ + setupUi(this); +} + +void SchemeEditorEffects::on_intensityBox_currentIndexChanged(int index) +{ + Q_UNUSED( index ); + updateFromEffectsPage(); +} + +void SchemeEditorEffects::on_intensitySlider_valueChanged(int value) +{ + Q_UNUSED( value ); + updateFromEffectsPage(); +} + +void SchemeEditorEffects::on_colorBox_currentIndexChanged(int index) +{ + Q_UNUSED( index ); + updateFromEffectsPage(); +} + +void SchemeEditorEffects::on_colorSlider_valueChanged(int value) +{ + Q_UNUSED( value ); + updateFromEffectsPage(); +} + +void SchemeEditorEffects::on_colorButton_changed(const QColor& color) +{ + Q_UNUSED( color ); + updateFromEffectsPage(); +} + +void SchemeEditorEffects::on_contrastBox_currentIndexChanged(int index) +{ + Q_UNUSED( index ); + updateFromEffectsPage(); +} + +void SchemeEditorEffects::on_contrastSlider_valueChanged(int value) +{ + Q_UNUSED( value ); + updateFromEffectsPage(); +} + +void SchemeEditorEffects::updateValues() +{ + m_disableUpdates = true; + + // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp + if (m_palette == QPalette::Inactive) + { + KConfigGroup group(m_config, "ColorEffects:Inactive"); + intensityBox->setCurrentIndex(abs(group.readEntry("IntensityEffect", 0))); + intensitySlider->setValue(int(group.readEntry("IntensityAmount", 0.0) * 20.0) + 20); + colorBox->setCurrentIndex(abs(group.readEntry("ColorEffect", 2))); + if (colorBox->currentIndex() > 1) + { + colorSlider->setValue(int(group.readEntry("ColorAmount", 0.025) * 40.0)); + } + else + { + colorSlider->setValue(int(group.readEntry("ColorAmount", 0.05) * 20.0) + 20); + } + colorButton->setColor(group.readEntry("Color", QColor(112, 111, 110))); + contrastBox->setCurrentIndex(abs(group.readEntry("ContrastEffect", 2))); + contrastSlider->setValue(int(group.readEntry("ContrastAmount", 0.1) * 20.0)); + + } + else if (m_palette == QPalette::Disabled) + { + KConfigGroup group(m_config, "ColorEffects:Disabled"); + intensityBox->setCurrentIndex(group.readEntry("IntensityEffect", 2)); + intensitySlider->setValue(int(group.readEntry("IntensityAmount", 0.1) * 20.0) + 20); + colorBox->setCurrentIndex(group.readEntry("ColorEffect", 0)); + if (colorBox->currentIndex() > 1) + { + colorSlider->setValue(int(group.readEntry("ColorAmount", 0.0) * 40.0)); + } + else + { + colorSlider->setValue(int(group.readEntry("ColorAmount", 0.0) * 20.0) + 20); + } + colorButton->setColor(group.readEntry("Color", QColor(56, 56, 56))); + contrastBox->setCurrentIndex(group.readEntry("ContrastEffect", 1)); + contrastSlider->setValue(int(group.readEntry("ContrastAmount", 0.65) * 20.0)); + } + else + { + return; + } + + m_disableUpdates = false; + + // enable/disable controls + intensitySlider->setDisabled(intensityBox->currentIndex() == 0); + colorSlider->setDisabled(colorBox->currentIndex() == 0); + colorButton->setDisabled(colorBox->currentIndex() < 2); + contrastSlider->setDisabled(contrastBox->currentIndex() == 0); + preview->setPalette(m_config, m_palette); +} + +void SchemeEditorEffects::updateFromEffectsPage() +{ + if (m_disableUpdates) + { + // don't write the config as we are reading it! + return; + } + + QString groupName = ""; + if (m_palette == QPalette::Inactive) + { + groupName = "ColorEffects:Inactive"; + } + else if (m_palette == QPalette::Disabled) + { + groupName = "ColorEffects:Disabled"; + } + else + { + return; + } + KConfigGroup group(m_config, groupName); + + // intensity + group.writeEntry("IntensityEffect", intensityBox->currentIndex()); + group.writeEntry("IntensityAmount", qreal(intensitySlider->value() - 20) * 0.05); + + // color + group.writeEntry("ColorEffect", colorBox->currentIndex()); + if (colorBox->currentIndex() > 1) + { + group.writeEntry("ColorAmount", qreal(colorSlider->value()) * 0.025); + } + else + { + group.writeEntry("ColorAmount", qreal(colorSlider->value() - 20) * 0.05); + } + + group.writeEntry("Color", colorButton->color()); + + // contrast + group.writeEntry("ContrastEffect", contrastBox->currentIndex()); + group.writeEntry("ContrastAmount", qreal(contrastSlider->value()) * 0.05); + + // enable/disable controls + intensitySlider->setDisabled(intensityBox->currentIndex() == 0); + colorSlider->setDisabled(colorBox->currentIndex() == 0); + colorButton->setDisabled(colorBox->currentIndex() < 2); + contrastSlider->setDisabled(contrastBox->currentIndex() == 0); + + preview->setPalette(m_config, m_palette); + + emit changed(true); +} Index: kcms/colors/scmeditoreffects.ui =================================================================== --- /dev/null +++ kcms/colors/scmeditoreffects.ui @@ -0,0 +1,268 @@ + + + ScmEditorEffects + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Color: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Intensity: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Disabled color effect type + + + + None + + + + + Desaturate + + + + + Fade + + + + + Tint + + + + + + + + Disabled intensity effect type + + + + None + + + + + Shade + + + + + Darken + + + + + Lighten + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 69 + 22 + + + + + + + + Contrast: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + Disabled color effect amount + + + 40 + + + 10 + + + Qt::Horizontal + + + + + + + false + + + Disabled intensity effect amount + + + 40 + + + 10 + + + Qt::Horizontal + + + + + + + false + + + Disabled color + + + + + + + + 0 + 0 + + + + + 0 + 10 + + + + + + + + Disabled contrast type + + + + None + + + + + Fade + + + + + Tint + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 69 + 20 + + + + + + + + false + + + Disabled contrast amount + + + 20 + + + 10 + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + KColorButton + QPushButton +
kcolorbutton.h
+
+ + PreviewWidget + QWidget +
previewwidget.h
+ 1 +
+
+ + +
Index: kcms/colors/scmeditoroptions.h =================================================================== --- /dev/null +++ kcms/colors/scmeditoroptions.h @@ -0,0 +1,67 @@ +/* ColorEdit widget for KDE Display color scheme setup module + * Copyright (C) 2016 Olivier Churlaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SCMEDITOROPTIONS_H__ +#define __SCMEDITOROPTIONS_H__ + +#include +#include + +#include +#include +#include + +#include "ui_scmeditoroptions.h" + +class SchemeEditorOptions : public QWidget, public Ui::ScmEditorOptions +{ + Q_OBJECT + +public: + SchemeEditorOptions(KSharedConfigPtr config, QWidget *parent = Q_NULLPTR); + void updateValues(); + +Q_SIGNALS: + void changed(bool); + +private Q_SLOTS: + + // options slots + void on_contrastSlider_valueChanged(int value); + void on_shadeSortedColumn_stateChanged(int state); + void on_inactiveSelectionEffect_stateChanged(int state); + void on_useInactiveEffects_stateChanged(int state); + +private: + + /** load options from global */ + void loadOptions(); + void setCommonForeground(KColorScheme::ForegroundRole role, + int stackIndex, + int buttonIndex); + void setCommonDecoration(KColorScheme::DecorationRole role, + int stackIndex, + int buttonIndex); + + KSharedConfigPtr m_config; + bool m_disableUpdates; + +}; + +#endif Index: kcms/colors/scmeditoroptions.cpp =================================================================== --- /dev/null +++ kcms/colors/scmeditoroptions.cpp @@ -0,0 +1,100 @@ +/* KDE Display color scheme setup module + * Copyright (C) 2007 Matthew Woehlke + * Copyright (C) 2007 Jeremy Whiting + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "scmeditoroptions.h" + +#include +#include + +SchemeEditorOptions::SchemeEditorOptions(KSharedConfigPtr config, QWidget *parent) + : QWidget( parent ) + , m_config( config ) +{ + setupUi(this); + m_disableUpdates = false; + loadOptions(); +} + +void SchemeEditorOptions::updateValues() +{ + loadOptions(); +} + +void SchemeEditorOptions::loadOptions() +{ + KConfigGroup generalGroup(KSharedConfig::openConfig(), "General"); + shadeSortedColumn->setChecked(generalGroup.readEntry("shadeSortColumn", true)); + + KConfigGroup KDEgroup(m_config, "KDE"); + contrastSlider->setValue(KDEgroup.readEntry("contrast", KColorScheme::contrast())); + + KConfigGroup group(m_config, "ColorEffects:Inactive"); + useInactiveEffects->setChecked(group.readEntry("Enable", false)); + + // NOTE: keep this in sync with kdelibs/kdeui/colors/kcolorscheme.cpp + // NOTE: remove extra logic from updateFromOptions and on_useInactiveEffects_stateChanged when this changes! + inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", group.readEntry("Enable", true))); +} + +// Option slot +void SchemeEditorOptions::on_contrastSlider_valueChanged(int value) +{ + KConfigGroup group(m_config, "KDE"); + group.writeEntry("contrast", value); + + emit changed(true); +} + +void SchemeEditorOptions::on_shadeSortedColumn_stateChanged(int state) +{ + if (m_disableUpdates) + return; + KConfigGroup group(m_config, "General"); + group.writeEntry("shadeSortColumn", bool(state != Qt::Unchecked)); + + emit changed(true); +} + +void SchemeEditorOptions::on_useInactiveEffects_stateChanged(int state) +{ + KConfigGroup group(m_config, "ColorEffects:Inactive"); + group.writeEntry("Enable", bool(state != Qt::Unchecked)); + + m_disableUpdates = true; + printf("re-init\n"); + inactiveSelectionEffect->setChecked(group.readEntry("ChangeSelectionColor", bool(state != Qt::Unchecked))); + m_disableUpdates = false; + + emit changed(true); +} + +void SchemeEditorOptions::on_inactiveSelectionEffect_stateChanged(int state) +{ + if (m_disableUpdates) + { + // don't write the config as we are reading it! + return; + } + + KConfigGroup group(m_config, "ColorEffects:Inactive"); + group.writeEntry("ChangeSelectionColor", bool(state != Qt::Unchecked)); + + emit changed(true); +} Index: kcms/colors/scmeditoroptions.ui =================================================================== --- /dev/null +++ kcms/colors/scmeditoroptions.ui @@ -0,0 +1,120 @@ + + + ScmEditorOptions + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Apply inactive window color &effects + + + + + + + In&active selection changes color + + + + + + + Shade sorted column &in lists + + + + + + + Shading of frames and lighting ("3D") effects + + + Shading + + + + 12 + + + 0 + + + + + Minimum + + + + + + + Qt::Horizontal + + + + 198 + 20 + + + + + + + + Maximum + + + + + + + Contrast + + + + + + + 10 + + + 5 + + + Qt::Horizontal + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +