From: Juergen Spitzmueller Date: Sat, 22 Dec 2018 17:44:58 +0000 (+0100) Subject: Allow to restore default UI colors in prefs X-Git-Tag: 2.3.3~100 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6145cb798d8744f0813d77231cf40f327c4169c7;p=features.git Allow to restore default UI colors in prefs Patch by Daniel Ramöller (racoon), with slight modifications of mine. Fixes: #10062 (cherry picked from commit 81e4f8dfb610ae8e6a5cc79a869030b229587b26 with minor adaptations) --- diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 8e4dbcde6a..58810dfb85 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1230,6 +1230,10 @@ PrefColors::PrefColors(GuiPreferences * form) connect(colorChangePB, SIGNAL(clicked()), this, SLOT(changeColor())); + connect(colorResetPB, SIGNAL(clicked()), + this, SLOT(resetColor())); + connect(colorResetAllPB, SIGNAL(clicked()), + this, SLOT(resetAllColor())); connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()), this, SLOT(changeLyxObjectsSelection())); connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)), @@ -1257,15 +1261,17 @@ void PrefColors::applyRC(LyXRC & rc) const void PrefColors::updateRC(LyXRC const & rc) { - for (unsigned int i = 0; i < lcolors_.size(); ++i) { + for (size_type i = 0; i < lcolors_.size(); ++i) { QColor color = QColor(guiApp->colorCache().get(lcolors_[i], false)); QPixmap coloritem(32, 32); coloritem.fill(color); - lyxObjectsLW->item(i)->setIcon(QIcon(coloritem)); + lyxObjectsLW->item(int(i))->setIcon(QIcon(coloritem)); newcolors_[i] = curcolors_[i] = color.name(); } syscolorsCB->setChecked(rc.use_system_colors); changeLyxObjectsSelection(); + + setDisabledResets(); } @@ -1277,25 +1283,115 @@ void PrefColors::changeColor() if (row < 0) return; - QString const color = newcolors_[row]; - QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget()); + QString const color = newcolors_[size_t(row)]; + QColor const c = QColorDialog::getColor(QColor(color), qApp->focusWidget()); - if (c.isValid() && c.name() != color) { - newcolors_[row] = c.name(); - QPixmap coloritem(32, 32); - coloritem.fill(c); - lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem)); + if (setColor(row, c, color)) { + setDisabledResets(); // emit signal changed(); } } + +void PrefColors::resetColor() +{ + int const row = lyxObjectsLW->currentRow(); + + // just to be sure + if (row < 0) + return; + + QString const color = newcolors_[size_t(row)]; + QColor const c = getDefaultColorByRow(row); + + if (setColor(row, c, color)) { + setDisabledResets(); + // emit signal + changed(); + } +} + + +void PrefColors::resetAllColor() +{ + bool isChanged = false; + + colorResetAllPB->setDisabled(true); + + for (int irow = 0, count = lyxObjectsLW->count(); irow < count; ++irow) { + QString const color = newcolors_[size_t(irow)]; + QColor const c = getDefaultColorByRow(irow); + + if (setColor(irow, c, color)) + isChanged = true; + } + + if (isChanged) { + setDisabledResets(); + // emit signal + changed(); + } +} + + +bool PrefColors::setColor(int const row, QColor const new_color, + QString const old_color) +{ + if (new_color.isValid() && new_color.name() != old_color) { + newcolors_[size_t(row)] = new_color.name(); + QPixmap coloritem(32, 32); + coloritem.fill(new_color); + lyxObjectsLW->item(row)->setIcon(QIcon(coloritem)); + return true; + } + return false; +} + + +void PrefColors::setDisabledResets() +{ + int const row = lyxObjectsLW->currentRow(); + // set disable reset buttons ... + if (row >= 0) + colorResetPB->setDisabled(isDefaultColor(row, newcolors_[size_t(row)])); + + colorResetAllPB->setDisabled(true); + + // ... in between process qt events to give quicker visual feedback to the user ... + guiApp->processEvents(); + + // ... set disable Reset All button + for (int irow = 0, count = lyxObjectsLW->count(); irow < count; ++irow) { + if (!isDefaultColor(irow, newcolors_[size_t(irow)])) { + colorResetAllPB->setDisabled(false); + // the break condition might hide performance issues + // if a non-default color is at the top of the list + break; + } + } +} + + +bool PrefColors::isDefaultColor(int const row, QString const color) +{ + return color == getDefaultColorByRow(row).name(); +} + + +QColor PrefColors::getDefaultColorByRow(int const row) +{ + ColorSet const defaultcolor; + return defaultcolor.getX11Name(lcolors_[size_t(row)]).c_str(); +} + + void PrefColors::changeSysColor() { for (int row = 0 ; row < lyxObjectsLW->count() ; ++row) { // skip colors that are taken from system palette bool const disable = syscolorsCB->isChecked() - && guiApp->colorCache().isSystem(lcolors_[row]); + && guiApp->colorCache().isSystem(lcolors_[size_t(row)]); QListWidgetItem * const item = lyxObjectsLW->item(row); Qt::ItemFlags const flags = item->flags(); @@ -1307,9 +1403,17 @@ void PrefColors::changeSysColor() } } + void PrefColors::changeLyxObjectsSelection() { - colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0); + int currentRow = lyxObjectsLW->currentRow(); + colorChangePB->setDisabled(currentRow < 0); + + if (currentRow < 0) + colorResetPB->setDisabled(true); + else + colorResetPB->setDisabled( + isDefaultColor(currentRow, newcolors_[size_t(currentRow)])); } diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index 8f43a37e53..b36f2e60c3 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -259,12 +259,23 @@ public: private Q_SLOTS: void changeColor(); + void resetColor(); + void resetAllColor(); void changeSysColor(); void changeLyxObjectsSelection(); + bool setColor(int const row, QColor const new_color, + QString const old_color); + bool isDefaultColor(int const row, QString const color); + void setDisabledResets(); private: + /// + QColor getDefaultColorByRow(int const row); + /// std::vector lcolors_; + /// std::vector curcolors_; + /// std::vector newcolors_; }; diff --git a/src/frontends/qt4/ui/PrefColorsUi.ui b/src/frontends/qt4/ui/PrefColorsUi.ui index e7c89c2e5e..7ce2248e58 100644 --- a/src/frontends/qt4/ui/PrefColorsUi.ui +++ b/src/frontends/qt4/ui/PrefColorsUi.ui @@ -1,3 +1,4 @@ + PrefColorsUi @@ -5,7 +6,7 @@ 0 0 - 339 + 397 254 @@ -19,9 +20,19 @@ + + + + Use the color scheme of your Operating System/Desktop Environment + + + &Use system colors + + + - + @@ -42,12 +53,35 @@ 0 + + Change the selected color + A&lter... + + + Reset the selected color to its original value + + + Reset to &Default + + + + + + + Reset all colors to their original value + + + Reset A&ll + + + + Qt::Vertical @@ -62,26 +96,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &Use system colors - - - diff --git a/status.23x b/status.23x index 6ee0c6fe27..26cb69799e 100644 --- a/status.23x +++ b/status.23x @@ -37,6 +37,9 @@ What's new - Add "Reset" and "Reset All Fields" buttons to Text Properties dialog (bug 11415). +- Add "Reset to Default" and "Reset All" buttons to Color Preferences + (bug 10062). + - Insert new graphics inset on the correct cursor position. - Fix regression where spaces are disappearing when editing text (bug 11412).