diff options
author | Marco Bubke <marco.bubke@qt.io> | 2016-09-27 11:52:18 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2016-09-28 09:10:35 +0000 |
commit | e24eb9796932af84846a0b824f4ff989e641de86 (patch) | |
tree | 9965d713fbe3210495f7d0f043f10a63ae25ffe7 /src/plugins/texteditor/colorschemeedit.cpp | |
parent | cbcc556614c30f52073c1586b96f92b12bd96d80 (diff) |
TextEditor: Relative colors
We introduce relative colors to make it possible to change for
example the color of a declaration slightly.
Change-Id: I8c1991a8907207d3616be954504c68ea18c6deb1
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/colorschemeedit.cpp')
-rw-r--r-- | src/plugins/texteditor/colorschemeedit.cpp | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/plugins/texteditor/colorschemeedit.cpp b/src/plugins/texteditor/colorschemeedit.cpp index 22bbbd27da..b096c18e67 100644 --- a/src/plugins/texteditor/colorschemeedit.cpp +++ b/src/plugins/texteditor/colorschemeedit.cpp @@ -166,6 +166,14 @@ ColorSchemeEdit::ColorSchemeEdit(QWidget *parent) : this, &ColorSchemeEdit::eraseBackColor); connect(m_ui->eraseForegroundToolButton, &QAbstractButton::clicked, this, &ColorSchemeEdit::eraseForeColor); + connect(m_ui->foregroundSaturationSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &ColorSchemeEdit::changeRelativeForeColor); + connect(m_ui->foregroundLightnessSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &ColorSchemeEdit::changeRelativeForeColor); + connect(m_ui->backgroundSaturationSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &ColorSchemeEdit::changeRelativeBackColor); + connect(m_ui->backgroundLightnessSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &ColorSchemeEdit::changeRelativeBackColor); connect(m_ui->boldCheckBox, &QAbstractButton::toggled, this, &ColorSchemeEdit::checkCheckBoxes); connect(m_ui->italicCheckBox, &QAbstractButton::toggled, @@ -211,6 +219,16 @@ void ColorSchemeEdit::setReadOnly(bool readOnly) m_ui->backgroundToolButton->setEnabled(enabled); m_ui->eraseBackgroundToolButton->setEnabled(enabled); m_ui->eraseForegroundToolButton->setEnabled(enabled); + m_ui->relativeForegroundLabel->setEnabled(enabled); + m_ui->foregroundSaturationLabel->setEnabled(enabled); + m_ui->foregroundLightnessLabel->setEnabled(enabled); + m_ui->foregroundSaturationSpinBox->setEnabled(enabled); + m_ui->foregroundLightnessSpinBox->setEnabled(enabled); + m_ui->relativeBackgroundLabel->setEnabled(enabled); + m_ui->backgroundSaturationLabel->setEnabled(enabled); + m_ui->backgroundLightnessLabel->setEnabled(enabled); + m_ui->backgroundSaturationSpinBox->setEnabled(enabled); + m_ui->backgroundLightnessSpinBox->setEnabled(enabled); m_ui->boldCheckBox->setEnabled(enabled); m_ui->italicCheckBox->setEnabled(enabled); m_ui->underlineColorToolButton->setEnabled(enabled); @@ -244,6 +262,8 @@ void ColorSchemeEdit::updateControls() { updateForegroundControls(); updateBackgroundControls(); + updateRelativeForegroundControls(); + updateRelativeBackgroundControls(); updateFontControls(); updateUnderlineControls(); } @@ -282,6 +302,46 @@ void ColorSchemeEdit::updateBackgroundControls() && format.background().isValid()); } +void ColorSchemeEdit::updateRelativeForegroundControls() +{ + const auto &formatDescription = m_descriptions[m_curItem]; + const Format &format = m_scheme.formatFor(formatDescription.id()); + + QSignalBlocker saturationSignalBlocker(m_ui->foregroundSaturationSpinBox); + QSignalBlocker lightnessSignalBlocker(m_ui->foregroundLightnessSpinBox); + + bool isVisible = formatDescription.showControl(FormatDescription::ShowRelativeForegroundControl); + + m_ui->relativeForegroundLabel->setVisible(isVisible); + m_ui->foregroundSaturationLabel->setVisible(isVisible); + m_ui->foregroundLightnessLabel->setVisible(isVisible); + m_ui->foregroundSaturationSpinBox->setVisible(isVisible); + m_ui->foregroundLightnessSpinBox->setVisible(isVisible); + + m_ui->foregroundSaturationSpinBox->setValue(format.relativeForegroundSaturation()); + m_ui->foregroundLightnessSpinBox->setValue(format.relativeForegroundLightness()); +} + +void ColorSchemeEdit::updateRelativeBackgroundControls() +{ + const auto &formatDescription = m_descriptions[m_curItem]; + const Format &format = m_scheme.formatFor(formatDescription.id()); + + QSignalBlocker saturationSignalBlocker(m_ui->backgroundSaturationSpinBox); + QSignalBlocker lightnessSignalBlocker(m_ui->backgroundLightnessSpinBox); + + bool isVisible = formatDescription.showControl(FormatDescription::ShowRelativeBackgroundControl); + + m_ui->relativeBackgroundLabel->setVisible(isVisible); + m_ui->backgroundSaturationLabel->setVisible(isVisible); + m_ui->backgroundLightnessLabel->setVisible(isVisible); + m_ui->backgroundSaturationSpinBox->setVisible(isVisible); + m_ui->backgroundLightnessSpinBox->setVisible(isVisible); + + m_ui->backgroundSaturationSpinBox->setValue(format.relativeBackgroundSaturation()); + m_ui->backgroundLightnessSpinBox->setValue(format.relativeBackgroundLightness()); +} + void ColorSchemeEdit::updateFontControls() { const auto formatDescription = m_descriptions[m_curItem]; @@ -391,6 +451,70 @@ void ColorSchemeEdit::eraseForeColor() } } +void ColorSchemeEdit::changeRelativeForeColor() +{ + if (m_curItem == -1) + return; + + double saturation = m_ui->foregroundSaturationSpinBox->value(); + double lightness = m_ui->foregroundLightnessSpinBox->value(); + + for (const QModelIndex &index : m_ui->itemList->selectionModel()->selectedRows()) { + const TextStyle category = m_descriptions[index.row()].id(); + m_scheme.formatFor(category).setRelativeForegroundSaturation(saturation); + m_scheme.formatFor(category).setRelativeForegroundLightness(lightness); + m_formatsModel->emitDataChanged(index); + } +} + +void ColorSchemeEdit::changeRelativeBackColor() +{ + if (m_curItem == -1) + return; + + double saturation = m_ui->backgroundSaturationSpinBox->value(); + double lightness = m_ui->backgroundLightnessSpinBox->value(); + + for (const QModelIndex &index : m_ui->itemList->selectionModel()->selectedRows()) { + const TextStyle category = m_descriptions[index.row()].id(); + m_scheme.formatFor(category).setRelativeBackgroundSaturation(saturation); + m_scheme.formatFor(category).setRelativeBackgroundLightness(lightness); + m_formatsModel->emitDataChanged(index); + } +} + +void ColorSchemeEdit::eraseRelativeForeColor() +{ + if (m_curItem == -1) + return; + + m_ui->foregroundSaturationSpinBox->setValue(0.0); + m_ui->foregroundLightnessSpinBox->setValue(0.0); + + foreach (const QModelIndex &index, m_ui->itemList->selectionModel()->selectedRows()) { + const TextStyle category = m_descriptions[index.row()].id(); + m_scheme.formatFor(category).setRelativeForegroundSaturation(0.0); + m_scheme.formatFor(category).setRelativeForegroundLightness(0.0); + m_formatsModel->emitDataChanged(index); + } +} + +void ColorSchemeEdit::eraseRelativeBackColor() +{ + if (m_curItem == -1) + return; + + m_ui->backgroundSaturationSpinBox->setValue(0.0); + m_ui->backgroundLightnessSpinBox->setValue(0.0); + + foreach (const QModelIndex &index, m_ui->itemList->selectionModel()->selectedRows()) { + const TextStyle category = m_descriptions[index.row()].id(); + m_scheme.formatFor(category).setRelativeBackgroundSaturation(0.0); + m_scheme.formatFor(category).setRelativeBackgroundLightness(0.0); + m_formatsModel->emitDataChanged(index); + } +} + void ColorSchemeEdit::checkCheckBoxes() { if (m_curItem == -1) |