commit ac7f11b4dd720bf05a7282ce90f3445815c8a863
Author: Koji Yokota <[email protected]>
Date:   Sun Apr 6 11:14:37 2025 +0900

    Redesign PrefColors dialog
---
 src/frontends/qt/GuiPrefs.cpp       | 369 +++++++++++++++++---------------
 src/frontends/qt/GuiPrefs.h         |  72 ++++---
 src/frontends/qt/ui/PrefColorsUi.ui | 409 +++++++++++++++++++++---------------
 3 files changed, 483 insertions(+), 367 deletions(-)

diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index 6a19c204a0..56ec8f1502 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -1035,13 +1035,6 @@ PrefColors::PrefColors(GuiPreferences * form)
        QShortcut* sc_search =
                new QShortcut(QKeySequence(QKeySequence::Find), this);
 
-       header_labels_ << qt_("Light")
-                      << qt_("Dark")
-                      << qt_("Object/Element")
-                      << qt_("Light")
-                      << qt_("Dark");
-       reset_label_ = qt_("Reset");
-
        initializeColorsTV();
        initializeThemesLW();
        initializeThemeMenu();
@@ -1051,12 +1044,20 @@ PrefColors::PrefColors(GuiPreferences * form)
        connect(autoapplyCB, SIGNAL(toggled(bool)),
                this, SLOT(changeAutoapply()));
 
-       connect(colorsTV, SIGNAL(pressed(QModelIndex)),
-               this, SLOT(pressedColorsTV(QModelIndex)));
+       connect(bothColorResetPB, SIGNAL(clicked()),
+               this, SLOT(resetColors()));
        connect(colorsTV, SIGNAL(clicked(QModelIndex)),
                this, SLOT(clickedColorsTV(QModelIndex)));
        connect(colorResetAllPB, SIGNAL(clicked()),
                this, SLOT(resetAllColor()));
+       connect(darkColorEditPB, SIGNAL(clicked()),
+               this, SLOT(editDarkColor()));
+       connect(darkColorResetPB, SIGNAL(clicked()),
+               this, SLOT(resetDarkColor()));
+       connect(lightColorEditPB, SIGNAL(clicked()),
+               this, SLOT(editLightColor()));
+       connect(lightColorResetPB, SIGNAL(clicked()),
+               this, SLOT(resetLightColor()));
        connect(redoColorPB, SIGNAL(clicked()),
                undo_stack_, SLOT(redo()));
        connect(removeThemePB, SIGNAL(clicked()),
@@ -1071,6 +1072,9 @@ PrefColors::PrefColors(GuiPreferences * form)
                undo_stack_, SLOT(undo()));
        connect(searchStringEdit, SIGNAL(textEdited(QString)),
                this, SLOT(filterColorItem(QString)));
+       connect(&selection_model_,
+               SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
+               this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
        connect(syscolorsCB, SIGNAL(toggled(bool)),
                this, SIGNAL(changed()));
        connect(syscolorsCB, SIGNAL(toggled(bool)),
@@ -1112,60 +1116,68 @@ void PrefColors::updateRC(LyXRC const & rc)
                setSwatches(i, colors);
        }
 
-       for (int row=0; row<(int)lcolors_.size(); ++row) {
-               colorsTV_model_.item(row, 
LightColorResetColumn)->setFlags(Qt::NoItemFlags);
-               colorsTV_model_.item(row, 
DarkColorResetColumn)->setFlags(Qt::NoItemFlags);
-       }
        syscolorsCB->setChecked(rc.use_system_colors);
        colorsTV->update();
 }
 
 
-void PrefColors::pressedColorsTV(const QModelIndex index)
+void PrefColors::clickedColorsTV(const QModelIndex index)
 {
        if (!index.flags().testFlag(Qt::ItemIsEnabled))
                return;
 
-       Column const column = (Column)index.column();
+       int const row = index.row();
+       int const column = index.column();
 
-       if (column == LightColorResetColumn || column == DarkColorResetColumn) {
-               mouse_pressed_ = true;
-               update();
-       }
+       if (column < 2)
+               changeColor(row, column);
+
+       setResetButtonStatus(row);
 }
 
 
-void PrefColors::clickedColorsTV(const QModelIndex index)
+void PrefColors::editLightColor()
 {
-       if (!index.flags().testFlag(Qt::ItemIsEnabled))
-               return;
+       int last_selected_row = selected_indexes_.back().row();
 
-       int const row = index.row();
-       Column const column = (Column)index.column();
+       changeColor(last_selected_row, false);
+}
 
-       if (column == LightColorResetColumn || column == DarkColorResetColumn) {
-               mouse_pressed_ = false;
-               resetColor(row, column);
-       } else
-               changeColor(row, column);
+
+void PrefColors::editDarkColor()
+{
+       int last_selected_row = selected_indexes_.back().row();
+
+       changeColor(last_selected_row, true);
 }
 
 
-void PrefColors::changeColor(int const &row, Column const &column)
+void PrefColors::selectionChanged(const QItemSelection &selected,
+                                  const QItemSelection &deselected)
+{
+       selection_model_.select(deselected,
+                               QItemSelectionModel::Deselect);
+       selection_model_.select(selected,
+                               QItemSelectionModel::Current |
+                               QItemSelectionModel::Select);
+       selected_indexes_ = selection_model_.selectedIndexes();
+}
+
+
+void PrefColors::changeColor(int const &row, bool const &is_dark_mode)
 {
        QString color;
 
-       if (column == LightColorColumn)
-               color = newcolors_[size_t(row)].first;
-       else if (column == DarkColorColumn)
+       if (is_dark_mode)
                color = newcolors_[size_t(row)].second;
        else
-               return;
+               color = newcolors_[size_t(row)].first;
 
        QColor const c = form_->getColor(QColor(color));
 
-       if (setColor(colorsTV_model_.item(row, column), c, color)) {
-               // setEnabledReset(row, column);
+       if (setColor(colorsTV_model_.item(row, is_dark_mode), c, color)) {
+               themesLW->setCurrentRow(themesLW->currentRow(),
+                                       QItemSelectionModel::Deselect);
                // emit signal
                changed();
        }
@@ -1190,36 +1202,51 @@ bool PrefColors::setSwatches(size_type const &row, 
ColorPair colors)
 
 void PrefColors::updateAllSwatches()
 {
-       for (size_type row = 0; row < lcolors_.size(); ++row) {
+       for (size_type row = 0; row < lcolors_.size(); ++row)
                setSwatches(row, toqcolor(newcolors_[row]));
-       }
 }
 
 
-bool PrefColors::resetColor(int const &row, Column const &column)
+bool PrefColors::resetColor(bool const is_dark_color)
 {
-       QColor const c = getCurrentThemeColor(row, column);
+       bool result = true;
+       bool item_result;
+
+       for (QModelIndex selected : std::as_const(selected_indexes_))
+       {
+               int const row = selected.row();
+               item_result = resetColor(row, is_dark_color);
+               result &= item_result;
+       }
+
+       return result;
+}
 
+
+bool PrefColors::resetColor(int const row, bool const is_dark_color)
+{
+       QColor const c = getCurrentThemeColor(row, is_dark_color);
        if (!c.isValid()) return false;
 
        QStandardItem *item; // ColorColumn
        bool result;
 
-       if (column == LightColorResetColumn) {
-               item = colorsTV_model_.item(row, LightColorColumn);
-               result = setColor(item, c, newcolors_[size_t(row)].first);
+       item = colorsTV_model_.item(row, is_dark_color);
 
-       } else if (column == DarkColorResetColumn) {
-               item = colorsTV_model_.item(row, DarkColorColumn);
+       if (is_dark_color)
                result = setColor(item, c, newcolors_[size_t(row)].second);
+       else
+               result = setColor(item, c, newcolors_[size_t(row)].first);
 
-       } else
-               result = false;
+       return result;
+}
 
-       if (result)
-               // ResetColumn
-               colorsTV_model_.item(row, column)->setFlags(Qt::NoItemFlags);
 
+bool PrefColors::resetColors()
+{
+       bool result = true;
+       result &= resetColor(true);
+       result &= resetColor(false);
        return result;
 }
 
@@ -1231,11 +1258,12 @@ bool PrefColors::resetAllColor()
        bool isChanged = false;
 
        colorResetAllPB->setDisabled(true);
-
+       lightColorResetPB->setDisabled(true);
+       darkColorResetPB->setDisabled(true);
 
        for (int row = 0, count = colorsTV_model_.rowCount(); row < count; 
++row) {
-               isChanged |= resetColor(row, LightColorResetColumn);
-               isChanged |= resetColor(row, DarkColorResetColumn);
+               isChanged |= resetColor(row, false);
+               isChanged |= resetColor(row, true);
        }
 
        if (isChanged) {
@@ -1262,31 +1290,67 @@ bool PrefColors::setColor(QStandardItem *pitem,
 }
 
 
-void PrefColors::setEnabledReset(int const &row, Column const &column)
+void PrefColors::setUndoRedoButtonStatuses(bool isUndoing)
 {
-       QColor theme_color;
-       QColor new_color;
-       QStandardItem *item;
+       // Undo button
+       if ((!isUndoing && undo_stack_->index() >= 0) ||
+               (isUndoing && undo_stack_->index() >= 2))
+               undoColorPB->setEnabled(true);
+       else
+               undoColorPB->setDisabled(true);
+
+       // Redo button
+       if ((!isUndoing &&
+            undo_stack_->index() < undo_stack_->count() - 1) ||
+               (isUndoing &&
+                undo_stack_->index() <= undo_stack_->count()))
+               redoColorPB->setEnabled(true);
+       else
+               redoColorPB->setDisabled(true);
+}
 
-       if (column == LightColorColumn || column == LightColorResetColumn) {
-               theme_color = getCurrentThemeColor(lcolors_[row], 
LightColorColumn);
-               new_color = (QColor)newcolors_[size_t(row)].first;
-               item = colorsTV_model_.item(row, LightColorResetColumn);
-               Qt::ItemFlags const flags = item->flags();
-               if (new_color != theme_color) {
-                       item->setFlags(flags | Qt::ItemIsEnabled);
-               } else {
-                       item->setFlags(flags & ~Qt::ItemIsEnabled);
-               }
-       } else if (column == DarkColorColumn || column == DarkColorResetColumn) 
{
-               theme_color = getCurrentThemeColor(lcolors_[row], 
DarkColorColumn);
-               new_color = (QColor)newcolors_[size_t(row)].second;
-               if (new_color != theme_color) {
-                       item = colorsTV_model_.item(row, DarkColorResetColumn);
-                       item->setFlags(Qt::ItemIsEnabled);
-               }
-       } else
-               return;
+
+void PrefColors::setResetButtonStatus(int const &row, bool is_undoing)
+{
+       // light color
+       QColor theme_color = getCurrentThemeColor(row, false);
+       QColor new_color = (QColor)newcolors_[size_t(row)].first;
+       if (new_color != theme_color)
+               lightColorResetPB->setEnabled(true);
+       else
+               lightColorResetPB->setEnabled(false);
+
+       // dark color
+       theme_color = getCurrentThemeColor(row, true);
+       new_color = (QColor)newcolors_[size_t(row)].second;
+       if (new_color != theme_color)
+               darkColorResetPB->setEnabled(true);
+       else
+               darkColorResetPB->setEnabled(false);
+
+       // both color button
+       if (lightColorResetPB->isEnabled() && darkColorResetPB->isEnabled())
+               bothColorResetPB->setEnabled(true);
+       else
+               bothColorResetPB->setEnabled(false);
+
+       // reset all button
+       if ((!is_undoing && undo_stack_->index() < 0) ||
+               (is_undoing && undo_stack_->index() < 2))
+               colorResetAllPB->setEnabled(false);
+       else
+               colorResetAllPB->setEnabled(true);
+
+       changed();
+}
+
+
+void PrefColors::setResetButtonStatus(bool is_undoing)
+{
+       QModelIndex index = selection_model_.currentIndex();
+       int const row = index.row();
+
+       setResetButtonStatus(row, is_undoing);
 }
 
 
@@ -1621,10 +1685,6 @@ void PrefColors::initializeColorsTV()
                                item->setToolTip(qt_("Click here to change the 
color in the light mode"));
                        else if (column == DarkColorColumn)
                                item->setToolTip(qt_("Click here to change the 
color in the dark mode"));
-                       else if (column == LightColorResetColumn)
-                               item->setToolTip(qt_("Reset the light color to 
the one set last"));
-                       else if (column == DarkColorResetColumn)
-                               item->setToolTip(qt_("Reset the dark color to 
the one set last"));
                        colorsTV_model_.setItem(row, column, item);
                }
        }
@@ -1651,13 +1711,43 @@ void PrefColors::initializeColorsTV()
        horizontal_header->setDefaultSectionSize(swatch_width_);
        colorsTV->setHorizontalHeader(horizontal_header);
 
-       colorsTV->setColumnWidth(LightColorColumn, swatch_width_ + 2 * 
swatch_hmargin_);
-       colorsTV->setColumnWidth(DarkColorColumn, swatch_width_ + 2 * 
swatch_hmargin_);
-       colorsTV->setColumnWidth(LightColorResetColumn, reset_pb_width_);
-       colorsTV->setColumnWidth(DarkColorResetColumn, reset_pb_width_);
-       colorsTV->setSelectionMode(QAbstractItemView::NoSelection);
+       QFont font;
+       QFontMetrics fm(font);
+       int col_width = 
max(fm.horizontalAdvance(header_labels_[LightColorColumn]),
+                           swatch_width_);
+       colorsTV->setColumnWidth(LightColorColumn, col_width);
+       col_width = max(fm.horizontalAdvance(header_labels_[DarkColorColumn]),
+                       swatch_width_);
+       colorsTV->setColumnWidth(DarkColorColumn, col_width);
+       colorsTV->setSelectionMode(QAbstractItemView::ExtendedSelection);
+       colorsTV->setSelectionBehavior(QAbstractItemView::SelectRows);
 
        colorsTV->resizeRowsToContents();
+       for (int column=0; column < 2; ++column)
+               colorsTV->resizeColumnToContents(column);
+
+       // Selection
+       selection_model_.setModel(&colorsTV_model_);
+       colorsTV->setSelectionModel(&selection_model_);
+
+       undo_stack_->clear();
+       undo_stack_->setClean();
+
+       // initialize control buttons
+       if (undo_stack_->canUndo())
+               undoColorPB->setEnabled(true);
+       else
+               undoColorPB->setDisabled(true);
+       if (undo_stack_->canRedo())
+               redoColorPB->setEnabled(true);
+       else
+               redoColorPB->setDisabled(true);
+       // Below buttons are unabled as no colors are selected
+       lightColorResetPB->setDisabled(true);
+       darkColorResetPB->setDisabled(true);
+       bothColorResetPB->setDisabled(true);
+       colorResetAllPB->setDisabled(true);
+
        colorsTV->show();
 }
 
@@ -1668,23 +1758,27 @@ QColor PrefColors::getCurrentColor(ColorCode 
color_code, bool is_dark_mode)
 }
 
 
-QColor PrefColors::getCurrentThemeColor(int const &row, Column const &column)
+QColor PrefColors::getCurrentThemeColor(int const &row,
+                                        bool const &is_dark_color)
 {
-       Q_ASSERT(column == LightColorColumn || column == DarkColorColumn ||
-                column == LightColorResetColumn || column == 
DarkColorResetColumn);
-
        QColor color;
 
        if (!theme_colors_.empty()) {
-               if (column == LightColorColumn || column == 
LightColorResetColumn)
-                       color = (QColor)theme_colors_[row].first;
-               else if (column == DarkColorColumn || column == 
DarkColorResetColumn)
+               if (is_dark_color)
                        color = (QColor)theme_colors_[row].second;
+               else
+                       color = (QColor)theme_colors_[row].first;
        }
        return color;
 }
 
 
+ColorPair PrefColors::getCurrentThemeColors(int const &row)
+{
+       return theme_colors_[row];
+}
+
+
 void PrefColors::changeSysColor()
 {
        for (int row = 0 ; row < colorsTV_model_.rowCount() ; ++row) {
@@ -1719,7 +1813,8 @@ void PrefColors::filterColorItem(const QString &text)
 {
        search_string_ = text;
        items_found_ =
-               colorsTV_model_.findItems(search_string_, Qt::MatchContains, 
ColorNameColumn);
+               colorsTV_model_.findItems(search_string_, Qt::MatchContains,
+                                         ColorNameColumn);
        if (items_found_.empty())
                return;
        for (size_type row = 0; row < lcolors_.size(); ++row)
@@ -4280,8 +4375,7 @@ SetColor::SetColor(QStandardItem *item, QColor const 
&new_color,
                    QUndoCommand* uc_parent)
     : PrefColors(color_module->form_), QUndoCommand(uc_parent),
       autoapply_(autoapply), item_(*item), new_color_(new_color),
-      old_color_(old_color), newcolors_(new_color_list),
-      parent_(color_module)
+      old_color_(old_color), newcolors_(new_color_list), parent_(color_module)
 {
        setText(QString("Color %1 is changed to %2 (light) and %3 (dark)")
                .arg(lcolors_[item_.row()])
@@ -4292,14 +4386,20 @@ SetColor::SetColor(QStandardItem *item, QColor const 
&new_color,
 void SetColor::redo()
 {
        setColor(new_color_);
-       setStateOfResetButtons(false);
+
+       // set button statuses
+       parent_->setResetButtonStatus(false);
+       parent_->setUndoRedoButtonStatuses(false);
 }
 
 
 void SetColor::undo()
 {
        setColor(old_color_);
-       setStateOfResetButtons(true);
+
+       // set button statuses
+       parent_->setResetButtonStatus(true);
+       parent_->setUndoRedoButtonStatuses(true);
 }
 
 
@@ -4323,42 +4423,6 @@ void SetColor::setColor(QColor const &color)
 }
 
 
-void SetColor::setStateOfResetButtons(bool doingUndo)
-{
-       int const row = item_.row();
-       Column const column = (Column)item_.column();
-
-       Column colorcolumn, resetcolumn;
-       switch (column) {
-       case LightColorColumn:
-       case LightColorResetColumn:
-               colorcolumn = LightColorColumn;
-               resetcolumn = LightColorResetColumn;
-               break;
-       case DarkColorColumn:
-       case DarkColorResetColumn:
-               colorcolumn = DarkColorColumn;
-               resetcolumn = DarkColorResetColumn;
-               break;
-       default:
-               return;
-       }
-
-       QColor const color_to_compare = doingUndo ? QColor(old_color_) : 
new_color_;
-       QColor const theme_color = parent_->getCurrentThemeColor(row, 
colorcolumn);
-       QStandardItem const * reset_item = colorsTV_model_.item(row, 
resetcolumn);
-       Qt::ItemFlags const flags = reset_item->flags();
-       if (color_to_compare == theme_color)
-               parent_->colorsTV_model_.item(row, resetcolumn)->
-                       setFlags(flags & ~Qt::ItemIsEnabled);
-       else
-               parent_->colorsTV_model_.item(row, resetcolumn)->
-                       setFlags(flags | Qt::ItemIsEnabled);
-
-       changed();
-}
-
-
 /////////////////////////////////////////////////////////////////////
 //
 // ColorSwatchDelegate
@@ -4384,10 +4448,9 @@ void ColorSwatchDelegate::paint(QPainter *painter,
 
        const QWidget *widget = option.widget;
        QStyle *style = widget ? widget->style() : QApplication::style();
-       PrefColors::Column const column = (PrefColors::Column)index.column();
+       int const column = index.column();
 
-       if (column == PrefColors::LightColorColumn ||
-               column == PrefColors::DarkColorColumn) {
+       if (column < 2) {
                opt.rect = option.rect;
                QPixmap pixmap(pane_->swatch_width_, pane_->swatch_height_);
                QColor color =
@@ -4402,40 +4465,6 @@ void ColorSwatchDelegate::paint(QPainter *painter,
                        pixmap.fill(QColor("transparent"));
 #endif
                style->drawItemPixmap(painter, opt.rect, Qt::AlignCenter, 
pixmap);
-       } else if (column == PrefColors::LightColorResetColumn ||
-                  column == PrefColors::DarkColorResetColumn) {
-               QStyleOptionButton pb_opt_;
-               pb_opt_.text = pane_->reset_label_;
-               pb_opt_.features = QStyleOptionButton::None;
-               pb_opt_.rect = option.rect;
-
-               if (guiApp->isInDarkMode()) {
-                       // Dark mode
-                       if (index.flags().testFlag(Qt::ItemIsEnabled)) {
-                               // Button enabled
-                               if (pane_->mouse_pressed_)
-                                       
button_->setStyleSheet(activePressedPB_style_dark_);
-                               else
-                                       
button_->setStyleSheet(activePB_style_dark_);
-                       } else {
-                               // Button disabled
-                               button_->setStyleSheet(inactivePB_style_dark_);
-                       }
-               } else {
-                       // Light mode
-                       if (index.flags().testFlag(Qt::ItemIsEnabled)) {
-                               // Button enabled
-                               if (pane_->mouse_pressed_)
-                                       
button_->setStyleSheet(activePressedPB_style_light_);
-                               else
-                                       
button_->setStyleSheet(activePB_style_light_);
-                       } else {
-                               // Button disabled
-                               button_->setStyleSheet(inactivePB_style_light_);
-                       }
-               }
-               button_->style()->drawControl(QStyle::CE_PushButton, &pb_opt_,
-                                                    painter, button_.data());
        } else {
                opt.displayAlignment = Qt::AlignVCenter;
                style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 
widget);
diff --git a/src/frontends/qt/GuiPrefs.h b/src/frontends/qt/GuiPrefs.h
index b0e2a984ac..7b5ebf3320 100644
--- a/src/frontends/qt/GuiPrefs.h
+++ b/src/frontends/qt/GuiPrefs.h
@@ -50,6 +50,7 @@
 #include <QtWidgets/qmenu.h>
 #include <QStandardItemModel>
 #include <QStyledItemDelegate>
+#include <QTableView>
 #include <QUndoCommand>
 
 
@@ -259,9 +260,7 @@ public:
        enum Column {
                LightColorColumn,
                DarkColorColumn,
-               ColorNameColumn,
-               LightColorResetColumn,
-               DarkColorResetColumn
+               ColorNameColumn
        };
 
        PrefColors(GuiPreferences * form);
@@ -271,15 +270,24 @@ public:
        QColor getCurrentColor(ColorCode color_code, bool is_dark_mode);
 
 private Q_SLOTS:
-       // void changeColor();
-       void pressedColorsTV(const QModelIndex index);
        void clickedColorsTV(const QModelIndex index);
+       void selectionChanged(const QItemSelection &selected,
+                             const QItemSelection &deselected);
        bool resetAllColor();
        void changeSysColor();
        void changeAutoapply();
        bool setColor(QStandardItem *item, QColor const &new_color,
                      QString const &old_color);
-       void setEnabledReset(int const &row, Column const &column);
+       /// Change the light color of the selected row
+       void editLightColor();
+       /// Change the dark color of the selected row
+       void editDarkColor();
+       /// Reset light and dark colors to the previously set theme colors
+       bool resetColors();
+       /// Reset light color to the previously set theme colors
+       bool resetLightColor(){ return resetColor(false); }
+       /// Reset dark color to the previously set theme colors
+       bool resetDarkColor() { return resetColor(true);  }
        void openThemeMenu();
        void saveTheme();
        void loadTheme(QListWidgetItem* current_item,
@@ -292,42 +300,51 @@ private Q_SLOTS:
 
 private:
        /// Change color at (row, column).
-       void changeColor(int const &row, Column const &column);
-       /// Reset color to the previously set theme color.
-       bool resetColor(int const &row, Column const &column);
+       void changeColor(int const &row, bool const &is_dark_mode);
+       /// Reset color to the previously set theme color
+       bool resetColor(bool const is_dark_color);
+       /// Reset color to the previously set theme color
+       bool resetColor(int const row, bool const is_dark_color);
+       /// Set availability of reset buttons of a given row
+       void setResetButtonStatus(int const &row, bool is_undoing = false);
+       /// Set availability of reset buttons of the selected row
+       void setResetButtonStatus(bool is_undoing = false);
        /// Get default color of current theme at (row, column) in the colorsTV.
        /// If theme_colors_ is empty, this returns an invalid QColor.
-       QColor getCurrentThemeColor(int const &row, Column const &column);
+       QColor getCurrentThemeColor(int const &row, bool const &is_dark_color);
+       ///
+       ColorPair getCurrentThemeColors(int const &row);
        /// Set color swatches for both light and dark colors by row.
        bool setSwatches(size_type const &row, ColorPair colors);
        /// Set color swatch at item.
        bool setSwatch(QStandardItem *item, QColor const &color);
        ///
        void updateAllSwatches();
-       /// This initializes the theme list widget.
+       ///
+       void setUndoRedoButtonStatuses(bool isUndoing);
+       ///
        void initializeThemesLW();
        /// This initializes the extension menu for theme including exports and
        /// imports.
        void initializeThemeMenu();
        /// This initializes the color setting table view.
        void initializeColorsTV();
-       ///
+       /// Common algorithm between saving and exporting
        void saveExportThemeCommon(QString file_path);
-       ///
+       /// Common algorithm between loading and importing
        void loadImportThemeCommon(support::FileName filename);
-       ///
+       /// Ask the user a theme name
        bool askThemeName(bool porting);
        ///
        bool wantToOverwrite();
        ///
        ColorPair toqcolor(ColorNamePair);
 
-       QStringList header_labels_;
-       QString reset_label_;
+       QStringList header_labels_ =
+                       {qt_("Light"), qt_("Dark"), qt_("Object/Element")};
+       QString reset_label_ = qt_("Reset");
        int const swatch_width_  = 32;
        int const swatch_height_ = 18;
-       int const swatch_hmargin_ = 2;
-       int const reset_pb_width_ = 50;
 
        std::vector<ColorCode> lcolors_;
        ColorNamePairs curcolors_;
@@ -335,9 +352,8 @@ private:
        ColorNamePairs theme_colors_;
 
        QStandardItemModel colorsTV_model_;
-
-       std::vector<QPersistentModelIndex> light_color_index_;
-       std::vector<QPersistentModelIndex> dark_color_index_;
+       QItemSelectionModel selection_model_;
+       QModelIndexList selected_indexes_;
 
        QList<QStandardItem *> items_found_;
        QString search_string_;
@@ -353,9 +369,8 @@ private:
        /// holds filename of currently selected theme
        QString theme_filename_;
 
-       bool mouse_pressed_;
-
        friend class SetColor;
+       friend class ColorTableView;
        friend class ColorSwatchDelegate;
 };
 
@@ -648,21 +663,16 @@ public:
 class SetColor : public PrefColors, public QUndoCommand
 {
 public:
-       SetColor(QStandardItem *item, QColor const &new_color,
-                QString const &old_color,
+       SetColor(QStandardItem *item,
+                QColor const &new_color, QString const &old_color,
                 ColorNamePairs &new_color_list,
-                bool const autoapply,
-                PrefColors* color_module,
+                bool const autoapply, PrefColors* color_module,
                 QUndoCommand* uc_parent = nullptr);
        ~SetColor(){};
 
        void redo() override;
        void undo() override;
        void setColor(QColor const &color);
-       /// If new_color_ (when doingUndo is false) or old_color_ (when 
doingUndo is
-       /// true) is different from theme's color, enable the reset button. If 
not,
-       /// disable it.
-       void setStateOfResetButtons(bool doingUndo);
 
 private:
        bool const autoapply_;
diff --git a/src/frontends/qt/ui/PrefColorsUi.ui 
b/src/frontends/qt/ui/PrefColorsUi.ui
index bcd7ada8b5..38e3229bc3 100644
--- a/src/frontends/qt/ui/PrefColorsUi.ui
+++ b/src/frontends/qt/ui/PrefColorsUi.ui
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>656</width>
+    <width>701</width>
     <height>439</height>
    </rect>
   </property>
@@ -20,6 +20,19 @@
    <string/>
   </property>
   <layout class="QGridLayout" name="gridLayout_2">
+   <item row="3" column="2">
+    <spacer name="hsBottomRight">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>40</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
    <item row="3" column="0">
     <widget class="QCheckBox" name="syscolorsCB">
      <property name="sizePolicy">
@@ -32,23 +45,10 @@
       <string>Use the color scheme of your Operating System/Desktop 
Environment</string>
      </property>
      <property name="text">
-      <string>&amp;Use system colors</string>
+      <string>Use &amp;system colors</string>
      </property>
     </widget>
    </item>
-   <item row="3" column="2">
-    <spacer name="hsBottomRight">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="sizeHint" stdset="0">
-      <size>
-       <width>40</width>
-       <height>20</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
    <item row="3" column="1">
     <widget class="QCheckBox" name="autoapplyCB">
      <property name="toolTip">
@@ -60,32 +60,134 @@
     </widget>
    </item>
    <item row="1" column="0" colspan="4">
-    <layout class="QGridLayout" name="gridLayout" rowstretch="0,0" 
columnstretch="0,0,0">
-     <item row="0" column="2">
-      <layout class="QHBoxLayout" name="horizontalLayout">
-       <property name="spacing">
-        <number>0</number>
+    <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0" 
columnstretch="0,0,0,0">
+     <item row="0" column="0">
+      <widget class="QLabel" name="themesLabel">
+       <property name="text">
+        <string>&amp;Themes:</string>
        </property>
-       <property name="rightMargin">
+       <property name="alignment">
+        <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
+       </property>
+       <property name="buddy">
+        <cstring>themesLW</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="0" rowspan="7">
+      <layout class="QGridLayout" name="gridLayoutThemes">
+       <property name="spacing">
         <number>0</number>
        </property>
-       <item>
-        <spacer name="horizontalSpacerLeft">
+       <item row="1" column="3">
+        <spacer name="horizontalSpacer">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
          <property name="sizeType">
-          <enum>QSizePolicy::MinimumExpanding</enum>
+          <enum>QSizePolicy::Preferred</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
-           <width>13</width>
+           <width>40</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
+       <item row="1" column="2">
+        <widget class="QToolButton" name="removeThemePB">
+         <property name="toolTip">
+          <string>Remove a selected color theme</string>
+         </property>
+         <property name="text">
+          <string>Remo&amp;ve</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="4">
+        <widget class="QToolButton" name="themesMenuPB">
+         <property name="toolTip">
+          <string>Other menus to handle themes</string>
+         </property>
+         <property name="text">
+          <string>&amp;More...</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1">
+        <widget class="QToolButton" name="saveThemePB">
+         <property name="toolTip">
+          <string>Add the current color set as a theme</string>
+         </property>
+         <property name="text">
+          <string>A&amp;dd</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="1" colspan="4">
+        <widget class="QListWidget" name="themesLW">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Maximum" vsizetype="Expanding">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>200</width>
+           <height>16777215</height>
+          </size>
+         </property>
+         <property name="baseSize">
+          <size>
+           <width>150</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item row="2" column="3">
+      <layout class="QHBoxLayout" name="editHorizontalLayout">
+       <property name="spacing">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="QToolButton" name="lightColorEditPB">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>&amp;Light</string>
+         </property>
+        </widget>
+       </item>
        <item>
+        <widget class="QToolButton" name="darkColorEditPB">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>&amp;Dark</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item row="0" column="2">
+      <layout class="QGridLayout" name="ResetGridLayout">
+       <property name="spacing">
+        <number>0</number>
+       </property>
+       <item row="1" column="1">
         <widget class="QLineEdit" name="searchStringEdit">
          <property name="sizePolicy">
           <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
@@ -95,13 +197,13 @@
          </property>
          <property name="minimumSize">
           <size>
-           <width>200</width>
-           <height>16</height>
+           <width>150</width>
+           <height>0</height>
           </size>
          </property>
          <property name="maximumSize">
           <size>
-           <width>500</width>
+           <width>200</width>
            <height>16777215</height>
           </size>
          </property>
@@ -116,59 +218,21 @@
          </property>
         </widget>
        </item>
-       <item>
-        <spacer name="horizontalSpacerMiddleLeft">
+       <item row="1" column="0">
+        <spacer name="horizontalSpacerButtomLeft">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
-         <property name="sizeType">
-          <enum>QSizePolicy::Fixed</enum>
-         </property>
          <property name="sizeHint" stdset="0">
           <size>
-           <width>6</width>
+           <width>40</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
-       <item>
-        <widget class="QToolButton" name="undoColorPB">
-         <property name="toolTip">
-          <string>Undo</string>
-         </property>
-         <property name="text">
-          <string>&amp;Undo</string>
-         </property>
-         <property name="iconSize">
-          <size>
-           <width>16</width>
-           <height>16</height>
-          </size>
-         </property>
-         <property name="arrowType">
-          <enum>Qt::NoArrow</enum>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QToolButton" name="redoColorPB">
-         <property name="toolTip">
-          <string>Redo</string>
-         </property>
-         <property name="text">
-          <string>Re&amp;do</string>
-         </property>
-         <property name="iconSize">
-          <size>
-           <width>16</width>
-           <height>16</height>
-          </size>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="horizontalSpacerMiddleRight">
+       <item row="1" column="2">
+        <spacer name="horizontalSpacerRight">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
@@ -183,24 +247,28 @@
          </property>
         </spacer>
        </item>
-       <item>
-        <widget class="QToolButton" name="colorResetAllPB">
+       <item row="1" column="3">
+        <widget class="QToolButton" name="undoColorPB">
          <property name="toolTip">
-          <string>Reset all colors to theme</string>
+          <string>Undo</string>
          </property>
          <property name="text">
-          <string>Reset A&amp;ll</string>
+          <string>&amp;Undo</string>
          </property>
-         <property name="iconSize">
-          <size>
-           <width>16</width>
-           <height>16</height>
-          </size>
+        </widget>
+       </item>
+       <item row="1" column="4">
+        <widget class="QToolButton" name="redoColorPB">
+         <property name="toolTip">
+          <string>Redo</string>
+         </property>
+         <property name="text">
+          <string>R&amp;edo</string>
          </property>
         </widget>
        </item>
-       <item>
-        <spacer name="horizontalSpacerRight">
+       <item row="1" column="5">
+        <spacer name="horizontalSpacer_2">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
@@ -217,130 +285,139 @@
        </item>
       </layout>
      </item>
-     <item row="1" column="0">
-      <layout class="QGridLayout" name="gridLayoutThemes">
+     <item row="4" column="3">
+      <widget class="QLabel" name="resetLabel">
+       <property name="text">
+        <string>Reset</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <widget class="QLabel" name="colorLabel">
+       <property name="text">
+        <string>&amp;Color Settings:</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
+       </property>
+       <property name="buddy">
+        <cstring>colorsTV</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1" rowspan="7" colspan="2">
+      <widget class="QTableView" name="colorsTV">
+       <property name="alternatingRowColors">
+        <bool>true</bool>
+       </property>
+       <property name="selectionBehavior">
+        <enum>QAbstractItemView::SelectRows</enum>
+       </property>
+       <property name="showGrid">
+        <bool>false</bool>
+       </property>
+       <property name="gridStyle">
+        <enum>Qt::NoPen</enum>
+       </property>
+      </widget>
+     </item>
+     <item row="7" column="3">
+      <spacer name="lowerVerticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="5" column="3">
+      <layout class="QHBoxLayout" name="resetHorizontalLayout">
        <property name="spacing">
         <number>0</number>
        </property>
-       <item row="1" column="3">
-        <spacer name="horizontalSpacer">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-         <property name="sizeType">
-          <enum>QSizePolicy::Preferred</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>40</width>
-           <height>20</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-       <item row="1" column="2">
-        <widget class="QToolButton" name="removeThemePB">
+       <item>
+        <widget class="QToolButton" name="lightColorResetPB">
          <property name="toolTip">
-          <string>Remove a selected color theme</string>
+          <string>Reset selected light-mode color to the last saved</string>
          </property>
          <property name="text">
-          <string>&amp;Remove</string>
-         </property>
-         <property name="shortcut">
-          <string notr="true">Ctrl+R</string>
+          <string>Ligh&amp;t</string>
          </property>
         </widget>
        </item>
-       <item row="1" column="4">
-        <widget class="QToolButton" name="themesMenuPB">
+       <item>
+        <widget class="QToolButton" name="darkColorResetPB">
          <property name="toolTip">
-          <string>Other menus to handle themes</string>
+          <string>Reset selected dark-mode color to the last saved</string>
          </property>
          <property name="text">
-          <string>&amp;More...</string>
+          <string>Dar&amp;k</string>
          </property>
         </widget>
        </item>
-       <item row="1" column="1">
-        <widget class="QToolButton" name="saveThemePB">
-         <property name="toolTip">
-          <string>Add the current color set as a theme</string>
-         </property>
+       <item>
+        <widget class="QToolButton" name="bothColorResetPB">
          <property name="text">
-          <string>&amp;Add</string>
-         </property>
-         <property name="shortcut">
-          <string>Ctrl+S</string>
-         </property>
-        </widget>
-       </item>
-       <item row="0" column="1" colspan="4">
-        <widget class="QListWidget" name="themesLW">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Maximum" vsizetype="Expanding">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="maximumSize">
-          <size>
-           <width>200</width>
-           <height>16777215</height>
-          </size>
-         </property>
-         <property name="baseSize">
-          <size>
-           <width>150</width>
-           <height>0</height>
-          </size>
+          <string>&amp;Both</string>
          </property>
         </widget>
        </item>
       </layout>
      </item>
-     <item row="0" column="1">
-      <widget class="QLabel" name="colorLabel">
-       <property name="text">
-        <string>&amp;Color Settings:</string>
+     <item row="6" column="3">
+      <widget class="QToolButton" name="colorResetAllPB">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
        </property>
-       <property name="alignment">
-        <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
+       <property name="toolTip">
+        <string>Reset all colors in the table to the last saved</string>
        </property>
-       <property name="buddy">
-        <cstring>colorsTV</cstring>
+       <property name="text">
+        <string>Reset &amp;All Colors</string>
        </property>
       </widget>
      </item>
-     <item row="0" column="0">
-      <widget class="QLabel" name="themesLabel">
+     <item row="1" column="3">
+      <widget class="QLabel" name="label">
        <property name="text">
-        <string>&amp;Themes:</string>
+        <string>Edit</string>
        </property>
        <property name="alignment">
-        <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
-       </property>
-       <property name="buddy">
-        <cstring>themesLW</cstring>
+        <set>Qt::AlignCenter</set>
        </property>
       </widget>
      </item>
-     <item row="1" column="1" colspan="2">
-      <widget class="QTableView" name="colorsTV">
-       <property name="alternatingRowColors">
-        <bool>true</bool>
+     <item row="3" column="3">
+      <spacer name="middleVerticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
        </property>
-       <property name="showGrid">
-        <bool>false</bool>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
        </property>
-      </widget>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>3</height>
+        </size>
+       </property>
+      </spacer>
      </item>
     </layout>
    </item>
   </layout>
  </widget>
  <tabstops>
-  <tabstop>undoColorPB</tabstop>
-  <tabstop>redoColorPB</tabstop>
   <tabstop>syscolorsCB</tabstop>
   <tabstop>autoapplyCB</tabstop>
  </tabstops>
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to