Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ HEADERS += \
src/basewidget.h \
src/appearance.h \
src/buttonappearancewatcher.h \
src/colorpreviewwidget.h \
src/importlayersdialog.h \
src/importpositiondialog.h \
src/layeropacitydialog.h \
Expand Down Expand Up @@ -136,6 +137,7 @@ SOURCES += \
src/addtransparencytopaperdialog.cpp \
src/basewidget.cpp \
src/buttonappearancewatcher.cpp \
src/colorpreviewwidget.cpp \
src/importlayersdialog.cpp \
src/importpositiondialog.cpp \
src/layeropacitydialog.cpp \
Expand Down
33 changes: 13 additions & 20 deletions app/src/colorinspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,15 @@ void ColorInspector::initUI()
}
onColorSpecChanged();

ui->redSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::RED, mCurrentColor, 0.0, 255.0);
ui->greenSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::GREEN, mCurrentColor, 0.0, 255.0);
ui->blueSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::BLUE, mCurrentColor, 0.0, 255.0);
ui->rgbAlphaSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::ALPHA, mCurrentColor, 0.0, 255.0);
ui->redSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::RED, mCurrentColor);
ui->greenSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::GREEN, mCurrentColor);
ui->blueSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::BLUE, mCurrentColor);
ui->rgbAlphaSlider->init(ColorSlider::ColorSpecType::RGB, ColorSlider::ColorType::ALPHA, mCurrentColor);

ui->hueSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::HUE, mCurrentColor, 0.0, 359.0);
ui->saturationSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::SAT, mCurrentColor, 0.0, 255.0);
ui->valueSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::VAL, mCurrentColor, 0.0, 255.0);
ui->hsvAlphaSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::ALPHA, mCurrentColor, 0.0, 255.0);

QPalette p1 = ui->colorWrapper->palette();
p1.setBrush(QPalette::Window, QBrush(QImage(":/background/checkerboard.png")));
ui->colorWrapper->setPalette(p1);

QPalette p2 = ui->color->palette();
p2.setColor(QPalette::Window, mCurrentColor);
ui->color->setPalette(p2);
ui->hueSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::HUE, mCurrentColor);
ui->saturationSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::SAT, mCurrentColor);
ui->valueSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::VAL, mCurrentColor);
ui->hsvAlphaSlider->init(ColorSlider::ColorSpecType::HSV, ColorSlider::ColorType::ALPHA, mCurrentColor);

connect(ui->colorSpecTabWidget, &QTabWidget::currentChanged, this, &ColorInspector::onColorSpecChanged);

Expand Down Expand Up @@ -179,9 +171,8 @@ void ColorInspector::updateControls()
ui->valueSpinBox->setValue(qRound(mCurrentColor.value() / 2.55));
ui->hsvAlphaSpinBox->setValue(qRound(mCurrentColor.alpha() / 2.55));

QPalette p = ui->color->palette();
p.setColor(QPalette::Window, mCurrentColor);
ui->color->setPalette(p);

ui->colorPreview->setColor(mCurrentColor);

update();
}
Expand All @@ -200,7 +191,9 @@ void ColorInspector::onColorSpecChanged()
}
else
{
mCurrentColor = mCurrentColor.toHsv();
if (mCurrentColor.hue() != -1) {
mCurrentColor = mCurrentColor.toHsv();
}
}

updateControls();
Expand Down
43 changes: 43 additions & 0 deletions app/src/colorpreviewwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*

Pencil2D - Traditional Animation Software
Copyright (C) 2026 Oliver Stevns Larsen

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

*/
#include "colorpreviewwidget.h"

#include <QPainter>
#include <QPaintEvent>

ColorPreviewWidget::ColorPreviewWidget(QWidget*)
{

}

void ColorPreviewWidget::setColor(const QColor& color)
{
if (color == mColor) { return; }

mColor = color;
update();
}

void ColorPreviewWidget::paintEvent(QPaintEvent* event)
{
QPainter painter(this);

painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(mCheckerboard));
painter.drawRect(event->rect());

painter.fillRect(event->rect(), mColor);
}
41 changes: 41 additions & 0 deletions app/src/colorpreviewwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*

Pencil2D - Traditional Animation Software
Copyright (C) 2026 Oliver Stevns Larsen

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

*/
#ifndef COLORPREVIEWWIDGET_H
#define COLORPREVIEWWIDGET_H

#include <QObject>
#include <QWidget>

class ColorPreviewWidget: public QWidget
{
Q_OBJECT
public:
explicit ColorPreviewWidget(QWidget* = nullptr);

void setColor(const QColor& color);

protected:
void paintEvent(QPaintEvent* event) override;

private:

QPixmap mColorPreviewPixmap;
QPixmap mCheckerboard = QPixmap(":/background/checkerboard.png");

QColor mColor;
};

#endif // COLORPREVIEWWIDGET_H
Loading
Loading