QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
imagetransparentcolordialog.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef IMAGE_TRANSPARENT_COLOR_DIALOG_H
19#define IMAGE_TRANSPARENT_COLOR_DIALOG_H
20
21#include <QDialog>
22#include <QImage>
23#include <QColor>
24#include <QLabel>
25#include <QList>
26
27class QVBoxLayout;
28class QPushButton;
29class QMouseEvent;
30
40class ClickableImageLabel : public QLabel
41{
42 Q_OBJECT
43
44 public:
45 explicit ClickableImageLabel(const QImage &sourceImage, QWidget *parent = nullptr);
46
56 QImage displayImage() const { return m_displayImage; }
57
58 signals:
59 void colorPicked(const QColor &color);
60
61 protected:
62 void mousePressEvent(QMouseEvent *event) override;
63
64 private:
65 QImage m_source;
67 qreal m_displayScale = 1.0;
68};
69
87class ImageTransparentColorDialog : public QDialog
88{
89 Q_OBJECT
90
91 public:
97 {
98 QColor color;
100 };
101
111 explicit ImageTransparentColorDialog(const QPixmap &basePixmap,
112 const QList<PickedColor> &existingColors = {}, QWidget *parent = nullptr);
113
117 QPixmap resultPixmap() const;
122 QList<PickedColor> pickedColors() const { return m_pickedColors; }
123
135 static QImage applyColorKey(const QImage &source, const QList<PickedColor> &keyColors);
136
137 private slots:
138 void onColorPicked(const QColor &color);
139
140 private:
141 void setToleranceForIndex(int index, int value);
142 void removeColor(int index);
143 void rebuildSwatches();
144 void updatePreview();
145 void updateOkEnabled();
146 static QPixmap onCheckerboard(const QImage &image);
147
149 QImage m_previewSourceImage; // downsampled -- see ClickableImageLabel::displayImage()'s comment for why
150 QList<PickedColor> m_pickedColors;
151 bool m_startedWithColors = false; // whether existingColors was non-empty -- see updateOkEnabled()'s comment for why this matters
152 int m_lastToleranceUsed = 10; // seeds a newly-picked colour's own tolerance, so successive picks in one session feel consistent rather than each resetting to some fixed default
153
156 QVBoxLayout *m_swatchesLayout; // one row per picked colour, stacked vertically -- each row now carries its own slider, too wide to lay out side by side the way plain swatches once were
157 QLabel *m_hintLabel;
158 QPushButton *m_okButton;
159};
160
161#endif // IMAGE_TRANSPARENT_COLOR_DIALOG_H
The ClickableImageLabel class Displays an image scaled to fit a reasonable dialog size,...
Definition imagetransparentcolordialog.h:41
QImage displayImage() const
Definition imagetransparentcolordialog.h:56
qreal m_displayScale
Definition imagetransparentcolordialog.h:67
QImage m_source
Definition imagetransparentcolordialog.h:65
void mousePressEvent(QMouseEvent *event) override
ClickableImageLabel::mousePressEvent Maps the click back to the original, full-resolution image befor...
Definition imagetransparentcolordialog.cpp:66
void colorPicked(const QColor &color)
ClickableImageLabel(const QImage &sourceImage, QWidget *parent=nullptr)
ClickableImageLabel::ClickableImageLabel.
Definition imagetransparentcolordialog.cpp:44
QImage m_displayImage
Definition imagetransparentcolordialog.h:66
void setToleranceForIndex(int index, int value)
ImageTransparentColorDialog::setToleranceForIndex Updates one colour's own tolerance in place – delib...
Definition imagetransparentcolordialog.cpp:185
QImage m_sourceImage
Definition imagetransparentcolordialog.h:148
QLabel * m_hintLabel
Definition imagetransparentcolordialog.h:157
static QPixmap onCheckerboard(const QImage &image)
ImageTransparentColorDialog::onCheckerboard Composites image over a light/dark checkerboard,...
Definition imagetransparentcolordialog.cpp:385
void rebuildSwatches()
ImageTransparentColorDialog::rebuildSwatches Rebuilds the list of picked-colour rows from scratch aga...
Definition imagetransparentcolordialog.cpp:241
void removeColor(int index)
ImageTransparentColorDialog::removeColor Removes one colour from the set – the counterpart onColorPic...
Definition imagetransparentcolordialog.cpp:217
void onColorPicked(const QColor &color)
ImageTransparentColorDialog::onColorPicked Adds to the set of picked colours rather than replacing th...
Definition imagetransparentcolordialog.cpp:163
QList< PickedColor > m_pickedColors
Definition imagetransparentcolordialog.h:150
QPixmap resultPixmap() const
ImageTransparentColorDialog::resultPixmap.
Definition imagetransparentcolordialog.cpp:316
QImage m_previewSourceImage
Definition imagetransparentcolordialog.h:149
ImageTransparentColorDialog(const QPixmap &basePixmap, const QList< PickedColor > &existingColors={}, QWidget *parent=nullptr)
ImageTransparentColorDialog::ImageTransparentColorDialog.
Definition imagetransparentcolordialog.cpp:102
QPushButton * m_okButton
Definition imagetransparentcolordialog.h:158
void updateOkEnabled()
ImageTransparentColorDialog::updateOkEnabled OK is disabled only for the one case where accepting wou...
Definition imagetransparentcolordialog.cpp:205
static QImage applyColorKey(const QImage &source, const QList< PickedColor > &keyColors)
ImageTransparentColorDialog::applyColorKey Binary transparency within tolerance, not a smooth falloff...
Definition imagetransparentcolordialog.cpp:339
QVBoxLayout * m_swatchesLayout
Definition imagetransparentcolordialog.h:156
bool m_startedWithColors
Definition imagetransparentcolordialog.h:151
int m_lastToleranceUsed
Definition imagetransparentcolordialog.h:152
ClickableImageLabel * m_sourceLabel
Definition imagetransparentcolordialog.h:154
void updatePreview()
ImageTransparentColorDialog::updatePreview Recomputes the checkerboard-backed preview against the cur...
Definition imagetransparentcolordialog.cpp:303
QList< PickedColor > pickedColors() const
Definition imagetransparentcolordialog.h:122
QLabel * m_previewLabel
Definition imagetransparentcolordialog.h:155
Definition imagetransparentcolordialog.h:97
int tolerance
Definition imagetransparentcolordialog.h:99
QColor color
Definition imagetransparentcolordialog.h:98