Skip to content

Commit

Permalink
Auto-format colorspinner.{cpp,h}
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Aug 23, 2024
1 parent 1d8f8a1 commit d3b40dc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
53 changes: 33 additions & 20 deletions src/desktop/docks/colorspinner.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "desktop/main.h"
#include "desktop/docks/colorspinner.h"
#include "desktop/docks/colorpalette.h"
#include "desktop/docks/titlewidget.h"
#include "desktop/docks/toolsettingsdock.h"

#include <QtColorWidgets/swatch.hpp>
#include "desktop/main.h"
#include <QtColorWidgets/color_wheel.hpp>
#include <QtColorWidgets/swatch.hpp>

namespace docks {

Expand All @@ -16,16 +14,18 @@ struct ColorSpinnerDock::Private {
color_widgets::ColorWheel *colorwheel = nullptr;
};

ColorSpinnerDock::ColorSpinnerDock(const QString& title, QWidget *parent)
: DockBase(title, parent), d(new Private)
ColorSpinnerDock::ColorSpinnerDock(const QString &title, QWidget *parent)
: DockBase(title, parent)
, d(new Private)
{
// Create title bar widget
auto *titlebar = new TitleWidget(this);
TitleWidget *titlebar = new TitleWidget(this);
setTitleBarWidget(titlebar);

d->lastUsedSwatch = new color_widgets::Swatch(titlebar);
d->lastUsedSwatch->setForcedRows(1);
d->lastUsedSwatch->setForcedColumns(docks::ToolSettings::LASTUSED_COLOR_COUNT);
d->lastUsedSwatch->setForcedColumns(
docks::ToolSettings::LASTUSED_COLOR_COUNT);
d->lastUsedSwatch->setReadOnly(true);
d->lastUsedSwatch->setBorder(Qt::NoPen);
d->lastUsedSwatch->setMinimumHeight(24);
Expand All @@ -34,30 +34,43 @@ ColorSpinnerDock::ColorSpinnerDock(const QString& title, QWidget *parent)
titlebar->addCustomWidget(d->lastUsedSwatch, true);
titlebar->addSpace(24);

connect(d->lastUsedSwatch, &color_widgets::Swatch::colorSelected, this, &ColorSpinnerDock::colorSelected);
connect(
d->lastUsedSwatch, &color_widgets::Swatch::colorSelected, this,
&ColorSpinnerDock::colorSelected);

// Create main widget
d->colorwheel = new color_widgets::ColorWheel(this);
d->colorwheel->setMinimumSize(64, 64);
setWidget(d->colorwheel);

connect(d->colorwheel, &color_widgets::ColorWheel::colorSelected, this, &ColorSpinnerDock::colorSelected);

auto &settings = dpApp().settings();
settings.bindColorWheelShape(d->colorwheel, &color_widgets::ColorWheel::setSelectorShape, &color_widgets::ColorWheel::selectorShapeChanged);
settings.bindColorWheelAngleAs<bool>(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);
connect(
d->colorwheel, &color_widgets::ColorWheel::colorSelected, this,
&ColorSpinnerDock::colorSelected);

desktop::settings::Settings &settings = dpApp().settings();
settings.bindColorWheelShape(
d->colorwheel, &color_widgets::ColorWheel::setSelectorShape,
&color_widgets::ColorWheel::selectorShapeChanged);
settings.bindColorWheelAngleAs<bool>(
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);
}

ColorSpinnerDock::~ColorSpinnerDock()
{
delete d;
}

void ColorSpinnerDock::setColor(const QColor& color)
void ColorSpinnerDock::setColor(const QColor &color)
{
d->lastUsedSwatch->setSelected(findPaletteColor(d->lastUsedSwatch->palette(), color));
d->lastUsedSwatch->setSelected(
findPaletteColor(d->lastUsedSwatch->palette(), color));

if(d->colorwheel->color() != color)
d->colorwheel->setColor(color);
Expand All @@ -66,8 +79,8 @@ void ColorSpinnerDock::setColor(const QColor& color)
void ColorSpinnerDock::setLastUsedColors(const color_widgets::ColorPalette &pal)
{
d->lastUsedSwatch->setPalette(pal);
d->lastUsedSwatch->setSelected(findPaletteColor(d->lastUsedSwatch->palette(), d->colorwheel->color()));
d->lastUsedSwatch->setSelected(
findPaletteColor(d->lastUsedSwatch->palette(), d->colorwheel->color()));
}

}

15 changes: 6 additions & 9 deletions src/desktop/docks/colorspinner.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef COLORSPINNERDOCK_H
#define COLORSPINNERDOCK_H

#ifndef DESKTOP_DOCKS_COLORSPINNER_H
#define DESKTOP_DOCKS_COLORSPINNER_H
#include "desktop/docks/dockbase.h"

namespace color_widgets {
class ColorPalette;
class ColorPalette;
}

namespace docks {

class ColorSpinnerDock final : public DockBase {
Q_OBJECT
public:
ColorSpinnerDock(const QString& title, QWidget *parent);
ColorSpinnerDock(const QString &title, QWidget *parent);
~ColorSpinnerDock() override;

public slots:
void setColor(const QColor& color);
void setColor(const QColor &color);
void setLastUsedColors(const color_widgets::ColorPalette &pal);

signals:
void colorSelected(const QColor& color);
void colorSelected(const QColor &color);

private:
struct Private;
Expand All @@ -32,4 +30,3 @@ public slots:
}

#endif

0 comments on commit d3b40dc

Please sign in to comment.