Skip to content

Commit

Permalink
Add menu button to color docks title bar
Browse files Browse the repository at this point in the history
For the color wheel, this moves the settings for shape, angle and
direction to here instead of being in the tools preferences. Color space
is in both places, since it affects more than just the wheel.

For the color sliders, this adds settings for the color space, which
sliders to show and whether to show the color input.

For the color palette, this moves the menu that used to be in the row
below.

Also changes the left-side spacing of the titlebar to 2 instead of 6
pixels, since that makes it match up better with stuff in the second
row. I think.
  • Loading branch information
askmeaboutlo0m committed Aug 23, 2024
1 parent d3b40dc commit 4aace61
Show file tree
Hide file tree
Showing 10 changed files with 361 additions and 110 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
47 changes: 3 additions & 44 deletions src/desktop/dialogs/settingsdialog/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/dialogs/settingsdialog/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
51 changes: 26 additions & 25 deletions src/desktop/docks/colorpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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<int>::of(&QComboBox::currentIndexChanged), this,
Expand Down
Loading

0 comments on commit 4aace61

Please sign in to comment.