Skip to content

Commit

Permalink
Preview selected color in color wheel dock
Browse files Browse the repository at this point in the history
Can be toggled in the dock menu.
  • Loading branch information
askmeaboutlo0m committed Aug 24, 2024
1 parent f8b4be2 commit d8ebb09
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased Version 2.2.2-pre
* 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.
* Feature: Allow aligning the color wheel to the top of the dock instead of the center. Can be toggled in the dock's menu. Thanks MorrowShore for suggesting.
* Fix: Scale outer color wheel ring with the size of the widget. Thanks MorrowShore for reporting.
* Feature: Preview selected color on the color wheel. Can be toggled in the dock's menu. Thanks MorrowShore for suggesting.

2024-08-09 Version 2.2.2-beta.3
* Fix: Use more accurate timers for performance profiles if the platform supports it.
Expand Down
28 changes: 27 additions & 1 deletion src/desktop/docks/colorspinner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct ColorSpinnerDock::Private {
QAction *directionDescendingAction = nullptr;
QAction *alignTopAction = nullptr;
QAction *alignCenterAction = nullptr;
QAction *previewAction = nullptr;
color_widgets::Swatch *lastUsedSwatch = nullptr;
color_widgets::ColorWheel *colorwheel = nullptr;
bool updating = false;
Expand Down Expand Up @@ -174,6 +175,14 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent)
}
});

d->previewAction = menu->addAction(tr("Preview selected color"));
d->previewAction->setCheckable(true);
connect(d->previewAction, &QAction::toggled, this, [this](bool toggled) {
if(!d->updating) {
dpApp().settings().setColorWheelPreview(toggled ? 1 : 0);
}
});

d->menuButton = new widgets::GroupedToolButton(this);
d->menuButton->setIcon(QIcon::fromTheme("application-menu"));
d->menuButton->setPopupMode(QToolButton::InstantPopup);
Expand Down Expand Up @@ -219,6 +228,7 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent)
settings.bindColorWheelSpace(this, &ColorSpinnerDock::setColorSpace);
settings.bindColorWheelMirror(this, &ColorSpinnerDock::setMirror);
settings.bindColorWheelAlign(this, &ColorSpinnerDock::setAlign);
settings.bindColorWheelPreview(this, &ColorSpinnerDock::setPreview);
}

ColorSpinnerDock::~ColorSpinnerDock()
Expand All @@ -231,15 +241,22 @@ void ColorSpinnerDock::setColor(const QColor &color)
d->lastUsedSwatch->setSelected(
findPaletteColor(d->lastUsedSwatch->palette(), color));

if(d->colorwheel->color() != color)
if(!d->colorwheel->comparisonColor().isValid()) {
d->colorwheel->setComparisonColor(color);
}

if(d->colorwheel->color() != color) {
d->colorwheel->setColor(color);
}
}

void ColorSpinnerDock::setLastUsedColors(const color_widgets::ColorPalette &pal)
{
d->lastUsedSwatch->setPalette(pal);
d->lastUsedSwatch->setSelected(
findPaletteColor(d->lastUsedSwatch->palette(), d->colorwheel->color()));
d->colorwheel->setComparisonColor(
pal.count() == 0 ? d->colorwheel->color() : pal.colorAt(0));
}

void ColorSpinnerDock::setShape(color_widgets::ColorWheel::ShapeEnum shape)
Expand Down Expand Up @@ -317,4 +334,13 @@ void ColorSpinnerDock::setAlign(int align)
}
}

void ColorSpinnerDock::setPreview(int preview)
{
QScopedValueRollback<bool> guard(d->updating, true);
bool enabled = preview != 0;
d->previewAction->setChecked(enabled);
d->colorwheel->setPreviewOuter(enabled);
d->colorwheel->setPreviewInner(enabled);
}

}
1 change: 1 addition & 0 deletions src/desktop/docks/colorspinner.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public slots:
void setColorSpace(color_widgets::ColorWheel::ColorSpaceEnum colorSpace);
void setMirror(bool mirror);
void setAlign(int align);
void setPreview(int preview);

signals:
void colorSelected(const QColor &color);
Expand Down
1 change: 1 addition & 0 deletions src/desktop/settings_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SETTING(colorSlidersMode , ColorSlidersMode , "settings/colors
SETTING(colorWheelAngle , ColorWheelAngle , "settings/colorwheel/rotate" , color_widgets::ColorWheel::AngleEnum::AngleRotating)
SETTING(colorWheelAlign , ColorWheelAlign , "settings/colorwheel/align" , int(Qt::AlignVCenter))
SETTING(colorWheelMirror , ColorWheelMirror , "settings/colorwheel/mirror" , true)
SETTING(colorWheelPreview , ColorWheelPreview , "settings/colorwheel/preview" , 1)
SETTING(colorWheelShape , ColorWheelShape , "settings/colorwheel/shape" , color_widgets::ColorWheel::ShapeEnum::ShapeTriangle)
SETTING(colorWheelSpace , ColorWheelSpace , "settings/colorwheel/space" , color_widgets::ColorWheel::ColorSpaceEnum::ColorHSV)
SETTING(compactChat , CompactChat , "history/compactchat" , false)
Expand Down

0 comments on commit d8ebb09

Please sign in to comment.