diff --git a/src/plugins/texteditor/colorschemeedit.cpp b/src/plugins/texteditor/colorschemeedit.cpp index 0bd0c54015f..bd4c5b97ae4 100644 --- a/src/plugins/texteditor/colorschemeedit.cpp +++ b/src/plugins/texteditor/colorschemeedit.cpp @@ -6,13 +6,13 @@ #include "texteditortr.h" #include +#include #include #include #include #include #include -#include #include #include #include @@ -25,14 +25,6 @@ namespace TextEditor::Internal { const int layoutSpacing = 6; -static QString colorButtonStyleSheet(const QColor &bgColor) -{ - QString rc("border-width: 2px; border-radius: 2px; border-color: black; "); - rc += bgColor.isValid() ? "border-style: solid; background:" + bgColor.name() + ";" - : QString("border-style: dotted;"); - return rc; -} - class FormatsModel : public QAbstractListModel { public: @@ -132,7 +124,7 @@ ColorSchemeEdit::ColorSchemeEdit(QWidget *parent) : resize(513, 416); auto colorButton = [] () { - auto tb = new QToolButton; + auto tb = new Utils::QtColorButton; tb->setMinimumWidth(56); return tb; }; @@ -245,9 +237,9 @@ ColorSchemeEdit::ColorSchemeEdit(QWidget *parent) : connect(m_itemList->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ColorSchemeEdit::currentItemChanged); - connect(m_foregroundToolButton, &QAbstractButton::clicked, + connect(m_foregroundToolButton, &Utils::QtColorButton::colorChanged, this, &ColorSchemeEdit::changeForeColor); - connect(m_backgroundToolButton, &QAbstractButton::clicked, + connect(m_backgroundToolButton, &Utils::QtColorButton::colorChanged, this, &ColorSchemeEdit::changeBackColor); connect(m_eraseBackgroundToolButton, &QAbstractButton::clicked, this, &ColorSchemeEdit::eraseBackColor); @@ -265,7 +257,7 @@ ColorSchemeEdit::ColorSchemeEdit(QWidget *parent) : this, &ColorSchemeEdit::checkCheckBoxes); connect(m_italicCheckBox, &QAbstractButton::toggled, this, &ColorSchemeEdit::checkCheckBoxes); - connect(m_underlineColorToolButton, &QToolButton::clicked, + connect(m_underlineColorToolButton, &Utils::QtColorButton::colorChanged, this, &ColorSchemeEdit::changeUnderlineColor); connect(m_eraseUnderlineColorToolButton, &QToolButton::clicked, this, &ColorSchemeEdit::eraseUnderlineColor); @@ -347,7 +339,7 @@ void ColorSchemeEdit::updateForegroundControls() m_foregroundToolButton->setVisible(isVisible); m_eraseForegroundToolButton->setVisible(isVisible); - m_foregroundToolButton->setStyleSheet(colorButtonStyleSheet(format.foreground())); + m_foregroundToolButton->setColor(format.foreground()); m_eraseForegroundToolButton->setEnabled(!m_readOnly && m_curItem > 0 && format.foreground().isValid()); @@ -366,7 +358,7 @@ void ColorSchemeEdit::updateBackgroundControls() m_backgroundToolButton->setVisible(isVisible); m_eraseBackgroundToolButton->setVisible(isVisible); - m_backgroundToolButton->setStyleSheet(colorButtonStyleSheet(format.background())); + m_backgroundToolButton->setColor(format.background()); m_eraseBackgroundToolButton->setEnabled(!m_readOnly && m_curItem > 0 && format.background().isValid()); @@ -466,7 +458,7 @@ void ColorSchemeEdit::updateUnderlineControls() m_eraseUnderlineColorToolButton->setVisible(isVisible); m_underlineComboBox->setVisible(isVisible); - m_underlineColorToolButton->setStyleSheet(colorButtonStyleSheet(format.underlineColor())); + m_underlineColorToolButton->setColor(format.underlineColor()); m_eraseUnderlineColorToolButton->setEnabled(!m_readOnly && m_curItem > 0 && format.underlineColor().isValid()); @@ -478,11 +470,8 @@ void ColorSchemeEdit::changeForeColor() { if (m_curItem == -1) return; - QColor color = m_scheme.formatFor(m_descriptions[m_curItem].id()).foreground(); - const QColor newColor = QColorDialog::getColor(color, m_boldCheckBox->window()); - if (!newColor.isValid()) - return; - m_foregroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + + const QColor newColor = m_foregroundToolButton->color(); m_eraseForegroundToolButton->setEnabled(true); for (const QModelIndex &index : m_itemList->selectionModel()->selectedRows()) { @@ -498,11 +487,8 @@ void ColorSchemeEdit::changeBackColor() { if (m_curItem == -1) return; - QColor color = m_scheme.formatFor(m_descriptions[m_curItem].id()).background(); - const QColor newColor = QColorDialog::getColor(color, m_boldCheckBox->window()); - if (!newColor.isValid()) - return; - m_backgroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + + const QColor newColor = m_backgroundToolButton->color(); m_eraseBackgroundToolButton->setEnabled(true); for (const QModelIndex &index : m_itemList->selectionModel()->selectedRows()) { @@ -521,14 +507,13 @@ void ColorSchemeEdit::eraseBackColor() { if (m_curItem == -1) return; - QColor newColor; - m_backgroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + m_backgroundToolButton->setColor({}); m_eraseBackgroundToolButton->setEnabled(false); const QList indexes = m_itemList->selectionModel()->selectedRows(); for (const QModelIndex &index : indexes) { const TextStyle category = m_descriptions[index.row()].id(); - m_scheme.formatFor(category).setBackground(newColor); + m_scheme.formatFor(category).setBackground({}); m_formatsModel->emitDataChanged(index); } @@ -539,14 +524,13 @@ void ColorSchemeEdit::eraseForeColor() { if (m_curItem == -1) return; - QColor newColor; - m_foregroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + m_foregroundToolButton->setColor({}); m_eraseForegroundToolButton->setEnabled(false); const QList indexes = m_itemList->selectionModel()->selectedRows(); for (const QModelIndex &index : indexes) { const TextStyle category = m_descriptions[index.row()].id(); - m_scheme.formatFor(category).setForeground(newColor); + m_scheme.formatFor(category).setForeground({}); m_formatsModel->emitDataChanged(index); } @@ -635,11 +619,8 @@ void ColorSchemeEdit::changeUnderlineColor() { if (m_curItem == -1) return; - QColor color = m_scheme.formatFor(m_descriptions[m_curItem].id()).underlineColor(); - const QColor newColor = QColorDialog::getColor(color, m_boldCheckBox->window()); - if (!newColor.isValid()) - return; - m_underlineColorToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + + const QColor newColor = m_underlineColorToolButton->color(); m_eraseUnderlineColorToolButton->setEnabled(true); for (const QModelIndex &index : m_itemList->selectionModel()->selectedRows()) { @@ -653,13 +634,12 @@ void ColorSchemeEdit::eraseUnderlineColor() { if (m_curItem == -1) return; - QColor newColor; - m_underlineColorToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + m_underlineColorToolButton->setColor({}); m_eraseUnderlineColorToolButton->setEnabled(false); for (const QModelIndex &index : m_itemList->selectionModel()->selectedRows()) { const TextStyle category = m_descriptions[index.row()].id(); - m_scheme.formatFor(category).setUnderlineColor(newColor); + m_scheme.formatFor(category).setUnderlineColor({}); m_formatsModel->emitDataChanged(index); } } diff --git a/src/plugins/texteditor/colorschemeedit.h b/src/plugins/texteditor/colorschemeedit.h index 645ece9efe7..a2d57970795 100644 --- a/src/plugins/texteditor/colorschemeedit.h +++ b/src/plugins/texteditor/colorschemeedit.h @@ -20,6 +20,8 @@ class QScrollArea; class QToolButton; QT_END_NAMESPACE +namespace Utils { class QtColorButton; } + namespace TextEditor::Internal { class FormatsModel; @@ -80,10 +82,10 @@ private: QLabel *m_builtinSchemeLabel; QWidget *m_fontProperties; QLabel *m_foregroundLabel; - QToolButton *m_foregroundToolButton; + Utils::QtColorButton *m_foregroundToolButton; QAbstractButton *m_eraseForegroundToolButton; QLabel *m_backgroundLabel; - QToolButton *m_backgroundToolButton; + Utils::QtColorButton *m_backgroundToolButton; QAbstractButton *m_eraseBackgroundToolButton; QLabel *m_relativeForegroundHeadline; QLabel *m_foregroundLightnessLabel; @@ -100,7 +102,7 @@ private: QCheckBox *m_italicCheckBox; QLabel *m_underlineHeadline; QLabel *m_underlineLabel; - QToolButton *m_underlineColorToolButton; + Utils::QtColorButton *m_underlineColorToolButton; QAbstractButton *m_eraseUnderlineColorToolButton; QComboBox *m_underlineComboBox;