diff --git a/ChangeLog b/ChangeLog index d58f9fbb90..5acb9fc713 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Unreleased Version 2.2.2-pre * Fix: Center soft brushes on the cursor better, they got offset to the top-left from correcting for size discontinuity before. Thanks Meiren for reporting. * Fix: Don't mess up gridmap settings when opening brush settings dialog and initially changing a value in it. Thanks Blozzom for reporting. * Fix: Default "confirm action" to both the regular enter key as well as the one on the numpad. Thanks MachKerman for reporting. + * Feature: Add settings button to color wheel, sliders and palette at the top-left of the dock. For the wheel, this allows changing the settings here now instead of having to go into the preferences. For the sliders, you can now toggle the color space here and decide whether to show all sliders and the hex input. For the palette, this just moves the menu button that used to be in the row below. Thanks MachKerman for suggesting. 2024-08-09 Version 2.2.2-beta.3 * Fix: Use more accurate timers for performance profiles if the platform supports it. diff --git a/src/desktop/dialogs/settingsdialog/tools.cpp b/src/desktop/dialogs/settingsdialog/tools.cpp index 3e1822f8b4..f3a653a914 100644 --- a/src/desktop/dialogs/settingsdialog/tools.cpp +++ b/src/desktop/dialogs/settingsdialog/tools.cpp @@ -39,41 +39,12 @@ void Tools::setUp(desktop::settings::Settings &settings, QVBoxLayout *layout) utils::addFormSeparator(layout); initGeneralTools(settings, utils::addFormSection(layout)); utils::addFormSeparator(layout); - initColorWheel(settings, layout); + initColorSpace(settings, utils::addFormSection(layout)); } -void Tools::initColorWheel( - desktop::settings::Settings &settings, QVBoxLayout *layout) +void Tools::initColorSpace( + desktop::settings::Settings &settings, QFormLayout *form) { - QHBoxLayout *section = new QHBoxLayout; - layout->addLayout(section); - - QFormLayout *form = utils::addFormSection(section); - - auto *shape = utils::addRadioGroup( - form, tr("Shape:"), true, - {{tr("Triangle"), color_widgets::ColorWheel::ShapeEnum::ShapeTriangle}, - {tr("Square"), color_widgets::ColorWheel::ShapeEnum::ShapeSquare}}); - settings.bindColorWheelShape(shape); - - utils::addFormSpacer(form); - - auto *angle = utils::addRadioGroup( - form, tr("Angle:"), true, - {{tr("Fixed"), color_widgets::ColorWheel::AngleEnum::AngleFixed}, - {tr("Rotating"), - color_widgets::ColorWheel::AngleEnum::AngleRotating}}); - settings.bindColorWheelAngle(angle); - - utils::addFormSpacer(form); - - auto *mirror = utils::addRadioGroup( - form, tr("Direction:"), true, - {{tr("Ascending"), true}, {tr("Descending"), false}}); - settings.bindColorWheelMirror(mirror); - - utils::addFormSpacer(form); - auto *space = utils::addRadioGroup( form, tr("Color space:"), false, {{tr("HSV (Hue–Saturation–Value)"), @@ -83,18 +54,6 @@ void Tools::initColorWheel( {tr("HCL (Hue–Chroma–Luminance)"), color_widgets::ColorWheel::ColorSpaceEnum::ColorLCH}}); settings.bindColorWheelSpace(space); - - auto *preview = new color_widgets::ColorWheel; - preview->setMinimumWidth(150); - settings.bindColorWheelShape( - preview, &color_widgets::ColorWheel::setSelectorShape); - settings.bindColorWheelAngle( - preview, &color_widgets::ColorWheel::setRotatingSelector); - settings.bindColorWheelMirror( - preview, &color_widgets::ColorWheel::setMirroredSelector); - settings.bindColorWheelSpace( - preview, &color_widgets::ColorWheel::setColorSpace); - section->addWidget(preview); } void Tools::initGeneralTools( diff --git a/src/desktop/dialogs/settingsdialog/tools.h b/src/desktop/dialogs/settingsdialog/tools.h index f04aa8dedd..53d93002f5 100644 --- a/src/desktop/dialogs/settingsdialog/tools.h +++ b/src/desktop/dialogs/settingsdialog/tools.h @@ -25,7 +25,7 @@ class Tools final : public Page { private: void - initColorWheel(desktop::settings::Settings &settings, QVBoxLayout *layout); + initColorSpace(desktop::settings::Settings &settings, QFormLayout *form); void initGeneralTools(desktop::settings::Settings &settings, QFormLayout *form); diff --git a/src/desktop/docks/colorpalette.cpp b/src/desktop/docks/colorpalette.cpp index 82a1f13433..93e407ffac 100644 --- a/src/desktop/docks/colorpalette.cpp +++ b/src/desktop/docks/colorpalette.cpp @@ -112,6 +112,28 @@ ColorPaletteDock::ColorPaletteDock(const QString &title, QWidget *parent) TitleWidget *titlebar = new TitleWidget(this); setTitleBarWidget(titlebar); + widgets::GroupedToolButton *menuButton = new widgets::GroupedToolButton; + menuButton->setIcon(QIcon::fromTheme("application-menu")); + + QMenu *paletteMenu = new QMenu(this); + paletteMenu->addAction( + tr("New palette"), this, &ColorPaletteDock::addPalette); + paletteMenu->addAction( + tr("Duplicate palette"), this, &ColorPaletteDock::copyPalette); + paletteMenu->addAction( + tr("Delete palette"), this, &ColorPaletteDock::deletePalette); + paletteMenu->addAction( + tr("Rename palette"), this, &ColorPaletteDock::renamePalette); +#ifndef __EMSCRIPTEN__ + paletteMenu->addSeparator(); + paletteMenu->addAction( + tr("Import palette…"), this, &ColorPaletteDock::importPalette); + paletteMenu->addAction( + tr("Export palette…"), this, &ColorPaletteDock::exportPalette); +#endif + menuButton->setMenu(paletteMenu); + menuButton->setPopupMode(QToolButton::InstantPopup); + d->lastUsedSwatch = new color_widgets::Swatch(titlebar); d->lastUsedSwatch->setForcedRows(1); d->lastUsedSwatch->setForcedColumns( @@ -120,9 +142,10 @@ ColorPaletteDock::ColorPaletteDock(const QString &title, QWidget *parent) d->lastUsedSwatch->setBorder(Qt::NoPen); d->lastUsedSwatch->setMinimumHeight(24); - titlebar->addSpace(24); + titlebar->addCustomWidget(menuButton); + titlebar->addSpace(4); titlebar->addCustomWidget(d->lastUsedSwatch, true); - titlebar->addSpace(24); + titlebar->addSpace(4); connect( d->lastUsedSwatch, &color_widgets::Swatch::colorSelected, this, @@ -136,7 +159,7 @@ ColorPaletteDock::ColorPaletteDock(const QString &title, QWidget *parent) setWidget(widget); QHBoxLayout *choiceLayout = new QHBoxLayout; - choiceLayout->setContentsMargins(0, 0, 0, 0); + choiceLayout->setContentsMargins(2, 0, 0, 0); choiceLayout->setSpacing(0); layout->addLayout(choiceLayout); @@ -170,10 +193,6 @@ ColorPaletteDock::ColorPaletteDock(const QString &title, QWidget *parent) choiceLayout->addSpacing(4); - widgets::GroupedToolButton *menuButton = new widgets::GroupedToolButton; - menuButton->setIcon(QIcon::fromTheme("application-menu")); - choiceLayout->addWidget(menuButton); - d->paletteWidget = new widgets::PaletteWidget{this}; d->paletteWidget->setMinimumHeight(20); layout->addWidget(d->paletteWidget, 1); @@ -184,24 +203,6 @@ ColorPaletteDock::ColorPaletteDock(const QString &title, QWidget *parent) d->paletteWidget, &widgets::PaletteWidget::columnsChanged, this, &ColorPaletteDock::updateColumnButtons); - QMenu *paletteMenu = new QMenu(this); - paletteMenu->addAction(tr("New"), this, &ColorPaletteDock::addPalette); - paletteMenu->addAction( - tr("Duplicate"), this, &ColorPaletteDock::copyPalette); - paletteMenu->addAction( - tr("Delete"), this, &ColorPaletteDock::deletePalette); - paletteMenu->addAction( - tr("Rename"), this, &ColorPaletteDock::renamePalette); -#ifndef __EMSCRIPTEN__ - paletteMenu->addSeparator(); - paletteMenu->addAction( - tr("Import..."), this, &ColorPaletteDock::importPalette); - paletteMenu->addAction( - tr("Export..."), this, &ColorPaletteDock::exportPalette); -#endif - menuButton->setMenu(paletteMenu); - menuButton->setPopupMode(QToolButton::InstantPopup); - connect( d->paletteChoiceBox, QOverload::of(&QComboBox::currentIndexChanged), this, diff --git a/src/desktop/docks/colorsliders.cpp b/src/desktop/docks/colorsliders.cpp index 4b71860849..424ca18ea3 100644 --- a/src/desktop/docks/colorsliders.cpp +++ b/src/desktop/docks/colorsliders.cpp @@ -4,12 +4,16 @@ #include "desktop/docks/titlewidget.h" #include "desktop/docks/toolsettingsdock.h" #include "desktop/main.h" +#include "desktop/utils/widgetutils.h" #include "desktop/widgets/groupedtoolbutton.h" +#include +#include #include #include #include #include #include +#include #include #include #include @@ -23,10 +27,18 @@ namespace docks { struct ColorSliderDock::Private { + widgets::GroupedToolButton *menuButton = nullptr; + QAction *colorSpaceHsvAction = nullptr; + QAction *colorSpaceHslAction = nullptr; + QAction *colorSpaceHclAction = nullptr; + QAction *showAllSlidersAction = nullptr; + QAction *showInputAction = nullptr; + QColor lastColor = Qt::black; color_widgets::Swatch *lastUsedSwatch = nullptr; - QStackedWidget *stack = nullptr; + QWidget *hsvWidget = nullptr; + QWidget *rgbWidget = nullptr; QLabel *hueLabel = nullptr; color_widgets::HueSlider *hue = nullptr; @@ -46,6 +58,7 @@ struct ColorSliderDock::Private { QSpinBox *bluebox = nullptr; widgets::GroupedToolButton *hsvButton = nullptr; + widgets::GroupedToolButton *rgbButton = nullptr; QButtonGroup *group = nullptr; color_widgets::ColorLineEdit *lineEdit = nullptr; @@ -60,9 +73,59 @@ ColorSliderDock::ColorSliderDock(const QString &title, QWidget *parent) , d(new Private) { // Create title bar widget - auto *titlebar = new TitleWidget(this); + TitleWidget *titlebar = new TitleWidget(this); setTitleBarWidget(titlebar); + QMenu *menu = new QMenu(this); + QMenu *colorSpaceMenu = menu->addMenu(tr("Color space")); + QActionGroup *colorSpaceGroup = new QActionGroup(this); + + d->colorSpaceHsvAction = colorSpaceMenu->addAction(tr("HSV")); + d->colorSpaceHsvAction->setCheckable(true); + colorSpaceGroup->addAction(d->colorSpaceHsvAction); + connect( + d->colorSpaceHsvAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelSpace( + color_widgets::ColorWheel::ColorHSV); + } + }); + + d->colorSpaceHslAction = colorSpaceMenu->addAction(tr("HSL")); + d->colorSpaceHslAction->setCheckable(true); + colorSpaceGroup->addAction(d->colorSpaceHslAction); + connect( + d->colorSpaceHslAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelSpace( + color_widgets::ColorWheel::ColorHSL); + } + }); + + d->colorSpaceHclAction = colorSpaceMenu->addAction(tr("HCL")); + d->colorSpaceHclAction->setCheckable(true); + colorSpaceGroup->addAction(d->colorSpaceHclAction); + connect( + d->colorSpaceHclAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelSpace( + color_widgets::ColorWheel::ColorLCH); + } + }); + + desktop::settings::Settings &settings = dpApp().settings(); + + d->showAllSlidersAction = menu->addAction(tr("Show all sliders at once")); + d->showAllSlidersAction->setCheckable(true); + + d->showInputAction = menu->addAction(tr("Show hex input")); + d->showInputAction->setCheckable(true); + + d->menuButton = new widgets::GroupedToolButton(this); + d->menuButton->setIcon(QIcon::fromTheme("application-menu")); + d->menuButton->setPopupMode(QToolButton::InstantPopup); + d->menuButton->setMenu(menu); + d->lastUsedSwatch = new color_widgets::Swatch(titlebar); d->lastUsedSwatch->setForcedRows(1); d->lastUsedSwatch->setForcedColumns( @@ -71,9 +134,10 @@ ColorSliderDock::ColorSliderDock(const QString &title, QWidget *parent) d->lastUsedSwatch->setBorder(Qt::NoPen); d->lastUsedSwatch->setMinimumHeight(24); - titlebar->addSpace(24); + titlebar->addCustomWidget(d->menuButton); + titlebar->addSpace(4); titlebar->addCustomWidget(d->lastUsedSwatch, true); - titlebar->addSpace(24); + titlebar->addSpace(4); connect( d->lastUsedSwatch, &color_widgets::Swatch::colorSelected, this, @@ -82,16 +146,14 @@ ColorSliderDock::ColorSliderDock(const QString &title, QWidget *parent) // Create main UI widget QWidget *w = new QWidget; QVBoxLayout *layout = new QVBoxLayout(w); + layout->setSpacing(3); - d->stack = new QStackedWidget; - d->stack->setContentsMargins(0, 0, 0, 0); - layout->addWidget(d->stack); - - QWidget *hsvWidget = new QWidget; - QGridLayout *hsvGrid = new QGridLayout(hsvWidget); + d->hsvWidget = new QWidget; + QGridLayout *hsvGrid = new QGridLayout(d->hsvWidget); hsvGrid->setContentsMargins(0, 0, 0, 0); hsvGrid->setSpacing(3); - d->stack->addWidget(hsvWidget); + d->hsvWidget->hide(); + layout->addWidget(d->hsvWidget); d->hueLabel = new QLabel; d->hue = new color_widgets::HueSlider; @@ -123,11 +185,12 @@ ColorSliderDock::ColorSliderDock(const QString &title, QWidget *parent) hsvGrid->addWidget(d->value, 2, 1); hsvGrid->addWidget(d->valuebox, 2, 2); - QWidget *rgbWidget = new QWidget; - QGridLayout *rgbGrid = new QGridLayout(rgbWidget); + d->rgbWidget = new QWidget; + QGridLayout *rgbGrid = new QGridLayout(d->rgbWidget); rgbGrid->setContentsMargins(0, 0, 0, 0); rgbGrid->setSpacing(3); - d->stack->addWidget(rgbWidget); + d->rgbWidget->hide(); + layout->addWidget(d->rgbWidget); d->red = new color_widgets::GradientSlider; d->red->setMaximum(255); @@ -168,21 +231,24 @@ ColorSliderDock::ColorSliderDock(const QString &title, QWidget *parent) new widgets::GroupedToolButton(widgets::GroupedToolButton::GroupLeft); d->hsvButton->setCheckable(true); d->hsvButton->setChecked(true); + d->hsvButton->hide(); buttonsLayout->addWidget(d->hsvButton); - widgets::GroupedToolButton *rgbButton = + d->rgbButton = new widgets::GroupedToolButton(widgets::GroupedToolButton::GroupRight); - rgbButton->setCheckable(true); - rgbButton->setText(tr("RGB")); - buttonsLayout->addWidget(rgbButton); + d->rgbButton->setCheckable(true); + d->rgbButton->setText(tr("RGB")); + d->rgbButton->hide(); + buttonsLayout->addWidget(d->rgbButton); d->group = new QButtonGroup(w); d->group->addButton(d->hsvButton, 0); - d->group->addButton(rgbButton, 1); + d->group->addButton(d->rgbButton, 1); buttonsLayout->addSpacing(3); d->lineEdit = new color_widgets::ColorLineEdit; + d->lineEdit->hide(); buttonsLayout->addWidget(d->lineEdit); layout->addStretch(1); @@ -245,9 +311,18 @@ ColorSliderDock::ColorSliderDock(const QString &title, QWidget *parent) d->lineEdit, &color_widgets::ColorLineEdit::colorEditingFinished, this, &ColorSliderDock::updateFromLineEditFinished); - dpApp().settings().bindColorWheelSpace( - this, &ColorSliderDock::setColorSpace); - dpApp().settings().bindColorSlidersMode(this, &ColorSliderDock::setMode); + settings.bindColorSlidersShowAll(d->showAllSlidersAction); + settings.bindColorSlidersShowInput(d->showInputAction); + settings.bindColorWheelSpace(this, &ColorSliderDock::setColorSpace); + settings.bindColorSlidersMode(this, &ColorSliderDock::setMode); + updateWidgetVisibilities(); + + connect( + d->showAllSlidersAction, &QAction::toggled, this, + &ColorSliderDock::updateWidgetVisibilities); + connect( + d->showInputAction, &QAction::toggled, this, + &ColorSliderDock::updateWidgetVisibilities); } ColorSliderDock::~ColorSliderDock() @@ -333,8 +408,10 @@ void ColorSliderDock::updateFromLineEditFinished(const QColor &color) void ColorSliderDock::setColorSpace( color_widgets::ColorWheel::ColorSpaceEnum colorSpace) { + QScopedValueRollback guard(d->updating, true); switch(colorSpace) { case color_widgets::ColorWheel::ColorHSL: + d->colorSpaceHslAction->setChecked(true); d->colorSpace = color_widgets::ColorWheel::ColorHSL; //: The "Hue" H of HSL. d->hueLabel->setText(tr("H", "HSL")); @@ -346,6 +423,7 @@ void ColorSliderDock::setColorSpace( d->hsvButton->setText(tr("HSL")); break; case color_widgets::ColorWheel::ColorLCH: + d->colorSpaceHclAction->setChecked(true); d->colorSpace = color_widgets::ColorWheel::ColorLCH; //: The "Hue" H of HCL. d->hueLabel->setText(tr("H", "HCL")); @@ -357,6 +435,7 @@ void ColorSliderDock::setColorSpace( d->hsvButton->setText(tr("HCL")); break; default: + d->colorSpaceHsvAction->setChecked(true); d->colorSpace = color_widgets::ColorWheel::ColorHSV; //: The "Hue" H of HSV. d->hueLabel->setText(tr("H", "HSV")); @@ -368,7 +447,6 @@ void ColorSliderDock::setColorSpace( d->hsvButton->setText(tr("HSV")); break; } - QScopedValueRollback guard{d->updating, true}; updateSaturationSlider(d->lastColor, false); updateValueSlider(d->lastColor, false); } @@ -378,13 +456,29 @@ void ColorSliderDock::setMode(int mode) if(mode == 0 || mode == 1) { QSignalBlocker blocker(d->group); d->group->button(mode)->setChecked(true); - d->stack->setCurrentIndex(mode); dpApp().settings().setColorSlidersMode(mode); + updateWidgetVisibilities(); } else { qWarning("Unknown color slider mode %d", mode); } } +void ColorSliderDock::updateWidgetVisibilities() +{ + utils::ScopedUpdateDisabler disabler(this); + d->hsvWidget->hide(); + d->rgbWidget->hide(); + d->hsvButton->hide(); + d->rgbButton->hide(); + d->lineEdit->hide(); + bool allSliders = d->showAllSlidersAction->isChecked(); + d->hsvWidget->setVisible(allSliders || d->group->checkedId() == 0); + d->rgbWidget->setVisible(allSliders || d->group->checkedId() == 1); + d->hsvButton->setVisible(!allSliders); + d->rgbButton->setVisible(!allSliders); + d->lineEdit->setVisible(d->showInputAction->isChecked()); +} + void ColorSliderDock::updateColor( const QColor &color, bool fromHsvSelection, bool selected) { diff --git a/src/desktop/docks/colorsliders.h b/src/desktop/docks/colorsliders.h index b5866fa873..1b9c936e26 100644 --- a/src/desktop/docks/colorsliders.h +++ b/src/desktop/docks/colorsliders.h @@ -31,6 +31,7 @@ private slots: void updateFromLineEditFinished(const QColor &color); void setColorSpace(color_widgets::ColorWheel::ColorSpaceEnum colorSpace); void setMode(int mode); + void updateWidgetVisibilities(); signals: void colorSelected(const QColor &color); diff --git a/src/desktop/docks/colorspinner.cpp b/src/desktop/docks/colorspinner.cpp index 88740f8547..431ec19bed 100644 --- a/src/desktop/docks/colorspinner.cpp +++ b/src/desktop/docks/colorspinner.cpp @@ -4,14 +4,29 @@ #include "desktop/docks/titlewidget.h" #include "desktop/docks/toolsettingsdock.h" #include "desktop/main.h" -#include +#include "desktop/widgets/groupedtoolbutton.h" +#include +#include +#include +#include #include namespace docks { struct ColorSpinnerDock::Private { + widgets::GroupedToolButton *menuButton = nullptr; + QAction *shapeTriangleAction = nullptr; + QAction *shapeSquareAction = nullptr; + QAction *angleFixedAction = nullptr; + QAction *angleRotatingAction = nullptr; + QAction *colorSpaceHsvAction = nullptr; + QAction *colorSpaceHslAction = nullptr; + QAction *colorSpaceHclAction = nullptr; + QAction *directionAscendingAction = nullptr; + QAction *directionDescendingAction = nullptr; color_widgets::Swatch *lastUsedSwatch = nullptr; color_widgets::ColorWheel *colorwheel = nullptr; + bool updating = false; }; ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent) @@ -22,6 +37,123 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent) TitleWidget *titlebar = new TitleWidget(this); setTitleBarWidget(titlebar); + QMenu *menu = new QMenu(this); + + QMenu *shapeMenu = menu->addMenu(tr("Shape")); + QActionGroup *shapeGroup = new QActionGroup(this); + + d->shapeTriangleAction = shapeMenu->addAction(tr("Triangle")); + d->shapeTriangleAction->setCheckable(true); + shapeGroup->addAction(d->shapeTriangleAction); + connect( + d->shapeTriangleAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelShape( + color_widgets::ColorWheel::ShapeTriangle); + } + }); + + d->shapeSquareAction = shapeMenu->addAction(tr("Square")); + d->shapeSquareAction->setCheckable(true); + shapeGroup->addAction(d->shapeSquareAction); + connect( + d->shapeSquareAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelShape( + color_widgets::ColorWheel::ShapeSquare); + } + }); + + QMenu *angleMenu = menu->addMenu(tr("Angle")); + QActionGroup *angleGroup = new QActionGroup(this); + + d->angleFixedAction = angleMenu->addAction(tr("Fixed")); + d->angleFixedAction->setCheckable(true); + angleGroup->addAction(d->angleFixedAction); + connect(d->angleFixedAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelAngle( + color_widgets::ColorWheel::AngleFixed); + } + }); + + d->angleRotatingAction = angleMenu->addAction(tr("Rotating")); + d->angleRotatingAction->setCheckable(true); + angleGroup->addAction(d->angleRotatingAction); + connect( + d->angleRotatingAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelAngle( + color_widgets::ColorWheel::AngleRotating); + } + }); + + QMenu *colorSpaceMenu = menu->addMenu(tr("Color space")); + QActionGroup *colorSpaceGroup = new QActionGroup(this); + + d->colorSpaceHsvAction = colorSpaceMenu->addAction(tr("HSV")); + d->colorSpaceHsvAction->setCheckable(true); + colorSpaceGroup->addAction(d->colorSpaceHsvAction); + connect( + d->colorSpaceHsvAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelSpace( + color_widgets::ColorWheel::ColorHSV); + } + }); + + d->colorSpaceHslAction = colorSpaceMenu->addAction(tr("HSL")); + d->colorSpaceHslAction->setCheckable(true); + colorSpaceGroup->addAction(d->colorSpaceHslAction); + connect( + d->colorSpaceHslAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelSpace( + color_widgets::ColorWheel::ColorHSL); + } + }); + + d->colorSpaceHclAction = colorSpaceMenu->addAction(tr("HCL")); + d->colorSpaceHclAction->setCheckable(true); + colorSpaceGroup->addAction(d->colorSpaceHclAction); + connect( + d->colorSpaceHclAction, &QAction::toggled, this, [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelSpace( + color_widgets::ColorWheel::ColorLCH); + } + }); + + QMenu *directionMenu = menu->addMenu(tr("Direction")); + QActionGroup *directionGroup = new QActionGroup(this); + + d->directionAscendingAction = directionMenu->addAction(tr("Ascending")); + d->directionAscendingAction->setCheckable(true); + directionGroup->addAction(d->directionAscendingAction); + connect( + d->directionAscendingAction, &QAction::toggled, this, + [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelMirror(true); + } + }); + + d->directionDescendingAction = directionMenu->addAction(tr("Descending")); + d->directionDescendingAction->setCheckable(true); + directionGroup->addAction(d->directionDescendingAction); + connect( + d->directionDescendingAction, &QAction::toggled, this, + [this](bool toggled) { + if(toggled && !d->updating) { + dpApp().settings().setColorWheelMirror(false); + } + }); + + d->menuButton = new widgets::GroupedToolButton(this); + d->menuButton->setIcon(QIcon::fromTheme("application-menu")); + d->menuButton->setPopupMode(QToolButton::InstantPopup); + d->menuButton->setMenu(menu); + d->lastUsedSwatch = new color_widgets::Swatch(titlebar); d->lastUsedSwatch->setForcedRows(1); d->lastUsedSwatch->setForcedColumns( @@ -30,9 +162,10 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent) d->lastUsedSwatch->setBorder(Qt::NoPen); d->lastUsedSwatch->setMinimumHeight(24); - titlebar->addSpace(24); + titlebar->addCustomWidget(d->menuButton); + titlebar->addSpace(4); titlebar->addCustomWidget(d->lastUsedSwatch, true); - titlebar->addSpace(24); + titlebar->addSpace(4); connect( d->lastUsedSwatch, &color_widgets::Swatch::colorSelected, this, @@ -48,18 +181,10 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent) &ColorSpinnerDock::colorSelected); desktop::settings::Settings &settings = dpApp().settings(); - settings.bindColorWheelShape( - d->colorwheel, &color_widgets::ColorWheel::setSelectorShape, - &color_widgets::ColorWheel::selectorShapeChanged); - settings.bindColorWheelAngleAs( - d->colorwheel, &color_widgets::ColorWheel::setRotatingSelector, - &color_widgets::ColorWheel::rotatingSelectorChanged); - settings.bindColorWheelSpace( - d->colorwheel, &color_widgets::ColorWheel::setColorSpace, - &color_widgets::ColorWheel::colorSpaceChanged); - settings.bindColorWheelMirror( - d->colorwheel, &color_widgets::ColorWheel::setMirroredSelector, - &color_widgets::ColorWheel::mirroredSelectorChanged); + settings.bindColorWheelShape(this, &ColorSpinnerDock::setShape); + settings.bindColorWheelAngle(this, &ColorSpinnerDock::setAngle); + settings.bindColorWheelSpace(this, &ColorSpinnerDock::setColorSpace); + settings.bindColorWheelMirror(this, &ColorSpinnerDock::setMirror); } ColorSpinnerDock::~ColorSpinnerDock() @@ -83,4 +208,67 @@ void ColorSpinnerDock::setLastUsedColors(const color_widgets::ColorPalette &pal) findPaletteColor(d->lastUsedSwatch->palette(), d->colorwheel->color())); } +void ColorSpinnerDock::setShape(color_widgets::ColorWheel::ShapeEnum shape) +{ + QScopedValueRollback guard(d->updating, true); + switch(shape) { + case color_widgets::ColorWheel::ShapeSquare: + d->shapeSquareAction->setChecked(true); + d->colorwheel->setSelectorShape(color_widgets::ColorWheel::ShapeSquare); + break; + default: + d->shapeTriangleAction->setChecked(true); + d->colorwheel->setSelectorShape( + color_widgets::ColorWheel::ShapeTriangle); + break; + } +} + +void ColorSpinnerDock::setAngle(color_widgets::ColorWheel::AngleEnum angle) +{ + QScopedValueRollback guard(d->updating, true); + switch(angle) { + case color_widgets::ColorWheel::AngleFixed: + d->angleFixedAction->setChecked(true); + d->colorwheel->setRotatingSelector(false); + break; + default: + d->angleRotatingAction->setChecked(true); + d->colorwheel->setRotatingSelector(true); + break; + } +} + +void ColorSpinnerDock::setColorSpace( + color_widgets::ColorWheel::ColorSpaceEnum colorSpace) +{ + QScopedValueRollback guard(d->updating, true); + switch(colorSpace) { + case color_widgets::ColorWheel::ColorHSL: + d->colorSpaceHslAction->setChecked(true); + d->colorwheel->setColorSpace(color_widgets::ColorWheel::ColorHSL); + break; + case color_widgets::ColorWheel::ColorLCH: + d->colorSpaceHclAction->setChecked(true); + d->colorwheel->setColorSpace(color_widgets::ColorWheel::ColorLCH); + break; + default: + d->colorSpaceHsvAction->setChecked(true); + d->colorwheel->setColorSpace(color_widgets::ColorWheel::ColorHSV); + break; + } +} + +void ColorSpinnerDock::setMirror(bool mirror) +{ + QScopedValueRollback guard(d->updating, true); + if(mirror) { + d->directionAscendingAction->setChecked(true); + d->colorwheel->setMirroredSelector(true); + } else { + d->directionDescendingAction->setChecked(true); + d->colorwheel->setMirroredSelector(false); + } +} + } diff --git a/src/desktop/docks/colorspinner.h b/src/desktop/docks/colorspinner.h index ffe30ed106..60cf9157c6 100644 --- a/src/desktop/docks/colorspinner.h +++ b/src/desktop/docks/colorspinner.h @@ -2,6 +2,7 @@ #ifndef DESKTOP_DOCKS_COLORSPINNER_H #define DESKTOP_DOCKS_COLORSPINNER_H #include "desktop/docks/dockbase.h" +#include namespace color_widgets { class ColorPalette; @@ -18,6 +19,10 @@ class ColorSpinnerDock final : public DockBase { public slots: void setColor(const QColor &color); void setLastUsedColors(const color_widgets::ColorPalette &pal); + void setShape(color_widgets::ColorWheel::ShapeEnum shape); + void setAngle(color_widgets::ColorWheel::AngleEnum angle); + void setColorSpace(color_widgets::ColorWheel::ColorSpaceEnum colorSpace); + void setMirror(bool mirror); signals: void colorSelected(const QColor &color); diff --git a/src/desktop/docks/titlewidget.cpp b/src/desktop/docks/titlewidget.cpp index daea08934c..2bd34f3d0f 100644 --- a/src/desktop/docks/titlewidget.cpp +++ b/src/desktop/docks/titlewidget.cpp @@ -20,7 +20,7 @@ TitleWidget::TitleWidget(QDockWidget *parent) : QWidget(parent) m_layout = new QHBoxLayout; m_layout->setSpacing(0); - m_layout->setContentsMargins(6, 2, 1, 2); + m_layout->setContentsMargins(2, 2, 1, 2); setLayout(m_layout); m_button = new widgets::GroupedToolButton{ diff --git a/src/desktop/settings_table.h b/src/desktop/settings_table.h index b79d4bc112..ef3e2dbf20 100644 --- a/src/desktop/settings_table.h +++ b/src/desktop/settings_table.h @@ -70,6 +70,8 @@ SETTING(canvasShortcuts , CanvasShortcuts , "settings/canvas #ifdef Q_OS_ANDROID SETTING(captureVolumeRocker , CaptureVolumeRocker , "settings/android/capturevolumerocker" , true) #endif +SETTING(colorSlidersShowAll , ColorSlidersShowAll , "settings/colorsliders/showall" , false) +SETTING(colorSlidersShowInput , ColorSlidersShowInput , "settings/colorsliders/showinput" , true) SETTING(colorSlidersMode , ColorSlidersMode , "settings/colorsliders/mode" , 0) SETTING(colorWheelAngle , ColorWheelAngle , "settings/colorwheel/rotate" , color_widgets::ColorWheel::AngleEnum::AngleRotating) SETTING(colorWheelMirror , ColorWheelMirror , "settings/colorwheel/mirror" , true)