Skip to content

Commit

Permalink
Combine color wheel shape and angle settings
Browse files Browse the repository at this point in the history
Since having a single menu with four options is just easier to use than
two menus with two options each.
  • Loading branch information
askmeaboutlo0m committed Aug 24, 2024
1 parent 9a3ce18 commit 5f4221c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 51 deletions.
120 changes: 69 additions & 51 deletions src/desktop/docks/colorspinner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ namespace docks {

struct ColorSpinnerDock::Private {
widgets::GroupedToolButton *menuButton = nullptr;
QAction *shapeTriangleAction = nullptr;
QAction *shapeSquareAction = nullptr;
QAction *shapeRotatingTriangleAction = nullptr;
QAction *shapeRotatingSquareAction = nullptr;
QAction *shapeFixedTriangleAction = nullptr;
QAction *shapeFixedSquareAction = nullptr;
QAction *angleFixedAction = nullptr;
QAction *angleRotatingAction = nullptr;
QAction *colorSpaceHsvAction = nullptr;
Expand Down Expand Up @@ -46,49 +48,64 @@ ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent)
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);
d->shapeRotatingTriangleAction =
shapeMenu->addAction(tr("Rotating triangle"));
d->shapeRotatingTriangleAction->setCheckable(true);
shapeGroup->addAction(d->shapeRotatingTriangleAction);
connect(
d->shapeTriangleAction, &QAction::toggled, this, [this](bool toggled) {
d->shapeRotatingTriangleAction, &QAction::toggled, this,
[this](bool toggled) {
if(toggled && !d->updating) {
dpApp().settings().setColorWheelShape(
desktop::settings::Settings &settings = dpApp().settings();
settings.setColorWheelShape(
color_widgets::ColorWheel::ShapeTriangle);
settings.setColorWheelAngle(
color_widgets::ColorWheel::AngleRotating);
}
});

d->shapeSquareAction = shapeMenu->addAction(tr("Square"));
d->shapeSquareAction->setCheckable(true);
shapeGroup->addAction(d->shapeSquareAction);
d->shapeRotatingSquareAction = shapeMenu->addAction(tr("Rotating square"));
d->shapeRotatingSquareAction->setCheckable(true);
shapeGroup->addAction(d->shapeRotatingSquareAction);
connect(
d->shapeSquareAction, &QAction::toggled, this, [this](bool toggled) {
d->shapeRotatingSquareAction, &QAction::toggled, this,
[this](bool toggled) {
if(toggled && !d->updating) {
dpApp().settings().setColorWheelShape(
desktop::settings::Settings &settings = dpApp().settings();
settings.setColorWheelShape(
color_widgets::ColorWheel::ShapeSquare);
settings.setColorWheelAngle(
color_widgets::ColorWheel::AngleRotating);
}
});

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->shapeFixedTriangleAction = shapeMenu->addAction(tr("Fixed triangle"));
d->shapeFixedTriangleAction->setCheckable(true);
shapeGroup->addAction(d->shapeFixedTriangleAction);
connect(
d->shapeFixedTriangleAction, &QAction::toggled, this,
[this](bool toggled) {
if(toggled && !d->updating) {
desktop::settings::Settings &settings = dpApp().settings();
settings.setColorWheelShape(
color_widgets::ColorWheel::ShapeTriangle);
settings.setColorWheelAngle(
color_widgets::ColorWheel::AngleFixed);
}
});

d->angleRotatingAction = angleMenu->addAction(tr("Rotating"));
d->angleRotatingAction->setCheckable(true);
angleGroup->addAction(d->angleRotatingAction);
d->shapeFixedSquareAction = shapeMenu->addAction(tr("Fixed square"));
d->shapeFixedSquareAction->setCheckable(true);
shapeGroup->addAction(d->shapeFixedSquareAction);
connect(
d->angleRotatingAction, &QAction::toggled, this, [this](bool toggled) {
d->shapeFixedSquareAction, &QAction::toggled, this,
[this](bool toggled) {
if(toggled && !d->updating) {
dpApp().settings().setColorWheelAngle(
color_widgets::ColorWheel::AngleRotating);
desktop::settings::Settings &settings = dpApp().settings();
settings.setColorWheelShape(
color_widgets::ColorWheel::ShapeSquare);
settings.setColorWheelAngle(
color_widgets::ColorWheel::AngleFixed);
}
});

Expand Down Expand Up @@ -261,32 +278,16 @@ void ColorSpinnerDock::setLastUsedColors(const color_widgets::ColorPalette &pal)
void ColorSpinnerDock::setShape(color_widgets::ColorWheel::ShapeEnum shape)
{
QScopedValueRollback<bool> 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;
}
d->colorwheel->setSelectorShape(shape);
updateShapeAction();
}

void ColorSpinnerDock::setAngle(color_widgets::ColorWheel::AngleEnum angle)
{
QScopedValueRollback<bool> 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;
}
d->colorwheel->setRotatingSelector(
angle != color_widgets::ColorWheel::AngleFixed);
updateShapeAction();
}

void ColorSpinnerDock::setColorSpace(
Expand Down Expand Up @@ -342,4 +343,21 @@ void ColorSpinnerDock::setPreview(int preview)
d->colorwheel->setPreviewInner(enabled);
}

void ColorSpinnerDock::updateShapeAction()
{
QAction *action;
bool rotating = d->colorwheel->rotatingSelector();
switch(d->colorwheel->selectorShape()) {
case color_widgets::ColorWheel::ShapeSquare:
action =
rotating ? d->shapeRotatingSquareAction : d->shapeFixedSquareAction;
break;
default:
action = rotating ? d->shapeRotatingTriangleAction
: d->shapeFixedTriangleAction;
break;
}
action->setChecked(true);
}

}
2 changes: 2 additions & 0 deletions src/desktop/docks/colorspinner.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public slots:
void colorSelected(const QColor &color);

private:
void updateShapeAction();

struct Private;
Private *d;
};
Expand Down

0 comments on commit 5f4221c

Please sign in to comment.