Skip to content

Commit

Permalink
Align color wheel to the top by default
Browse files Browse the repository at this point in the history
With an option in the dock menu to center it again.
  • Loading branch information
askmeaboutlo0m committed Aug 23, 2024
1 parent ee72d3e commit 06f56b9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased Version 2.2.2-pre
* 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.
* Feature: Align color wheel to the top of the dock instead of the center by default. 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
52 changes: 49 additions & 3 deletions src/desktop/docks/colorspinner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QActionGroup>
#include <QMenu>
#include <QScopedValueRollback>
#include <QVBoxLayout>
#include <QtColorWidgets/swatch.hpp>

namespace docks {
Expand All @@ -24,6 +25,8 @@ struct ColorSpinnerDock::Private {
QAction *colorSpaceHclAction = nullptr;
QAction *directionAscendingAction = nullptr;
QAction *directionDescendingAction = nullptr;
QAction *alignTopAction = nullptr;
QAction *alignCenterAction = nullptr;
color_widgets::Swatch *lastUsedSwatch = nullptr;
color_widgets::ColorWheel *colorwheel = nullptr;
bool updating = false;
Expand Down Expand Up @@ -149,6 +152,28 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent)
}
});

QMenu *alignMenu = menu->addMenu(tr("Alignment"));
QActionGroup *alignGroup = new QActionGroup(this);

d->alignTopAction = alignMenu->addAction(tr("Top"));
d->alignTopAction->setCheckable(true);
alignGroup->addAction(d->alignTopAction);
connect(d->alignTopAction, &QAction::toggled, this, [this](bool toggled) {
if(toggled && !d->updating) {
dpApp().settings().setColorWheelAlign(int(Qt::AlignTop));
}
});

d->alignCenterAction = alignMenu->addAction(tr("Center"));
d->alignCenterAction->setCheckable(true);
alignGroup->addAction(d->alignCenterAction);
connect(
d->alignCenterAction, &QAction::toggled, this, [this](bool toggled) {
if(toggled && !d->updating) {
dpApp().settings().setColorWheelAlign(int(Qt::AlignCenter));
}
});

d->menuButton = new widgets::GroupedToolButton(this);
d->menuButton->setIcon(QIcon::fromTheme("application-menu"));
d->menuButton->setPopupMode(QToolButton::InstantPopup);
Expand All @@ -171,10 +196,18 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent)
d->lastUsedSwatch, &color_widgets::Swatch::colorSelected, this,
&ColorSpinnerDock::colorSelected);

// Create main widget
d->colorwheel = new color_widgets::ColorWheel(this);
QWidget *widget = new QWidget(this);
widget->setContentsMargins(0, 0, 0, 0);

QVBoxLayout *layout = new QVBoxLayout(widget);
layout->setContentsMargins(4, 4, 4, 4);
layout->setSpacing(0);

d->colorwheel = new color_widgets::ColorWheel;
d->colorwheel->setMinimumSize(64, 64);
setWidget(d->colorwheel);
layout->addWidget(d->colorwheel);

setWidget(widget);

connect(
d->colorwheel, &color_widgets::ColorWheel::colorSelected, this,
Expand All @@ -185,6 +218,7 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent)
settings.bindColorWheelAngle(this, &ColorSpinnerDock::setAngle);
settings.bindColorWheelSpace(this, &ColorSpinnerDock::setColorSpace);
settings.bindColorWheelMirror(this, &ColorSpinnerDock::setMirror);
settings.bindColorWheelAlign(this, &ColorSpinnerDock::setAlign);
}

ColorSpinnerDock::~ColorSpinnerDock()
Expand Down Expand Up @@ -271,4 +305,16 @@ void ColorSpinnerDock::setMirror(bool mirror)
}
}

void ColorSpinnerDock::setAlign(int align)
{
QScopedValueRollback<bool> guard(d->updating, true);
if(align & int(Qt::AlignTop)) {
d->alignTopAction->setChecked(true);
d->colorwheel->setAlignTop(true);
} else {
d->alignCenterAction->setChecked(true);
d->colorwheel->setAlignTop(false);
}
}

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

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 @@ -74,6 +74,7 @@ SETTING(colorSlidersShowAll , ColorSlidersShowAll , "settings/colors
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(colorWheelAlign , ColorWheelAlign , "settings/colorwheel/align" , int(Qt::AlignTop))
SETTING(colorWheelMirror , ColorWheelMirror , "settings/colorwheel/mirror" , true)
SETTING(colorWheelShape , ColorWheelShape , "settings/colorwheel/shape" , color_widgets::ColorWheel::ShapeEnum::ShapeTriangle)
SETTING(colorWheelSpace , ColorWheelSpace , "settings/colorwheel/space" , color_widgets::ColorWheel::ColorSpaceEnum::ColorHSV)
Expand Down

0 comments on commit 06f56b9

Please sign in to comment.