17#include "colorslider.h"
21#include <QStyleOption>
30ColorSlider::~ColorSlider()
35void ColorSlider::init(ColorSpecType specType, ColorType type,
const QColor &color, qreal min, qreal max)
48 drawColorBox(mColor,
size());
51 painter.drawPixmap(0, 0, mBoxPixmapSource);
62 return hsvGradient(color);
64 return rgbGradient(color);
76 for (; val < mMax; val += 1)
85 for (; val < mMax; val += 1)
94 for (; val < mMax; val += 1)
103 for (; val < mMax; val += 1)
123 for (; val < mMax; val += 1)
132 for (; val < mMax; val += 1)
141 for (; val < mMax; val += 1)
150 for (; val < mMax; val += 1)
164void ColorSlider::drawColorBox(
const QColor &color,
QSize size)
169 QBrush backgroundBrush = option.palette.window();
173 QPainter painter(&mBoxPixmapSource);
176 painter.fillRect(mBoxPixmapSource.
rect(), backgroundBrush);
179 mGradient = setColorSpec(color);
184 painter.begin(&mBoxPixmapSource);
187 painter.setBrush(brush2);
192 painter.setPen(pen2);
193 painter.drawRoundedRect(0,
195 mBoxPixmapSource.
width(),
196 mBoxPixmapSource.
height(),
198 mBoxPixmapSource.
width(),
199 Qt::SizeMode::AbsoluteSize);
203 painter.begin(&mBoxPixmapSource);
213 painter.setBrush(brush);
215 painter.drawRoundedRect(0,
217 mBoxPixmapSource.
width(),
218 mBoxPixmapSource.
height(),
220 mBoxPixmapSource.
width(),
221 Qt::SizeMode::AbsoluteSize);
225QSize ColorSlider::sizeHint()
const
230void ColorSlider::mouseMoveEvent(
QMouseEvent* event)
232 colorPicked(
event->pos());
235void ColorSlider::mousePressEvent(
QMouseEvent *event)
237 colorPicked(
event->pos());
240void ColorSlider::drawPicker(
const QColor &color)
266 if (color.
value() < 127 && color.
alpha() > 127)
282 val = color.
redF() * (mBoxPixmapSource.
width() - mPickerSize.
width());
285 if (color.
alpha() > 127)
292 if (color.
alpha() > 127)
296 val = color.
blueF() * (mBoxPixmapSource.
width() - mPickerSize.
width());
307 if (mColorType == ALPHA)
309 if (color.
alpha() > 127)
317 painter.drawRect(
static_cast<int>(val), 0, mPickerSize.
width(), mPickerSize.
height());
321void ColorSlider::colorPicked(
QPoint point)
323 QColor colorPicked = mColor;
324 int colorMax =
static_cast<int>(mMax);
326 int colorVal = point.
x() * colorMax / mBoxPixmapSource.
width();
328 colorVal = (colorVal > colorMax) ? colorMax : colorVal;
329 colorVal = (colorVal < 0) ? 0 : colorVal;
418 mColor = colorPicked;
419 emit valueChanged(mColor);
qreal alphaF() const const
qreal blueF() const const
QColor fromHsv(int h, int s, int v, int a)
qreal greenF() const const
qreal hsvHueF() const const
int hsvSaturation() const const
qreal hsvSaturationF() const const
qreal valueF() const const
void setColorAt(qreal position, const QColor &color)
void setColor(const QColor &color)
void setCosmetic(bool cosmetic)
void setWidthF(qreal width)
void initFrom(const QWidget *widget)