43 int channel2): QWidget(parent), m_d(new
Private)
45 m_d->dimension = dimension;
46 int maxchannel = parent->selectorModel()->colorSpace()->colorChannelCount()-1;
47 m_d->channel1 = qBound(0, channel1, maxchannel);
48 m_d->channel2 = qBound(0, channel2, maxchannel);
49 m_d->channelMask = 1 << channel1;
51 m_d->channelMask |= 1 << channel2;
53 this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
56 setContextMenuPolicy(Qt::PreventContextMenu);
64 return m_d->currentCoordinates;
69 QPointF newPos(qBound(0.0, position.x(), 1.0), qBound(0.0, position.y(), 1.0));
70 if (newPos !=
m_d->currentCoordinates)
72 m_d->currentCoordinates = newPos;
74 m_d->currentChannelValues[
m_d->channel1] = newPos.x();
76 m_d->currentChannelValues[
m_d->channel2] = newPos.y();
88 m_d->currentChannelValues = channelValues;
89 bool setCursor = channelFlags &
m_d->channelMask;
91 m_d->currentCoordinates = QPointF(qBound(0.f, channelValues[
m_d->channel1], 1.f),
92 qBound(0.f, channelValues[
m_d->channel2], 1.f));
96 m_d->currentChannelValues[
m_d->channel1] =
m_d->currentCoordinates.x();
98 m_d->currentChannelValues[
m_d->channel2] =
m_d->currentCoordinates.y();
101 m_d->imagesNeedUpdate =
m_d->imagesNeedUpdate || channelFlags & ~m_d->channelMask;
107 m_d->acceptTabletEvents = on;
114 &&
m_d->channel1 == 0;
125 m_d->alphaNeedsUpdate =
true;
126 m_d->imagesNeedUpdate =
true;
144 return selectorWidget;
158 if (
m_d->imagesNeedUpdate) {
163 m_d->imagesNeedUpdate =
false;
165 return m_d->gradient;
171 Q_ASSERT(bufferSize == imgSize.width() * imgSize.height() * colorSpace->
pixelSize());
180 image = QImage(width(), height(), QImage::Format_ARGB32);
181 image.fill(Qt::black);
194 const qreal deviceDivider = 1.0 / devicePixelRatioF();
195 const int deviceWidth = qCeil(width() * devicePixelRatioF());
196 const int deviceHeight = qCeil(height() * devicePixelRatioF());
198 QScopedArrayPointer<quint8> raw(
new quint8[imageSize] {});
199 quint8 *dataPtr = raw.data();
200 QVector4D coordinates = channelValues;
203 bool checkAlpha = !alpha.isNull() && alpha.valid(deviceWidth - 1, deviceHeight - 1);
209 for (
int y = 0; y < deviceHeight; y++) {
210 const uchar *alphaLine = checkAlpha ? alpha.scanLine(y) : 0;
211 for (
int x=0; x < deviceWidth; x++) {
212 if (!checkAlpha || alphaLine[x]) {
214 coordinates[
m_d->channel1] = newcoordinate.x();
216 coordinates[
m_d->channel2] = newcoordinate.y();
219 memcpy(dataPtr, c.
data(), pixelSize);
224 memcpy(dataPtr, filler.
data(), pixelSize);
226 dataPtr += pixelSize;
229 QImage image =
convertImageMap(raw.data(), imageSize, QSize(deviceWidth, deviceHeight));
230 image.setDevicePixelRatio(devicePixelRatioF());
232 if (!alpha.isNull()) {
233 QPainter painter(&image);
235 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
236 painter.drawImage(0, 0, alpha);
247 if (
m_d->alphaNeedsUpdate) {
249 if (!staticAlpha.isNull()) {
250 QVector4D neutralValues(1, 1, 1, 1);
255 neutralValues.setZ(0.5f);
263 m_d->alphaNeedsUpdate =
false;
265 if (
m_d->alphaMask.isNull()) {
266 return m_d->staticBackground;
270 if (!
m_d->staticBackground.isNull()) {
271 QPainter painter(&bgImage);
273 painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
274 painter.drawImage(0, 0,
m_d->staticBackground);
297 if (e->button() == Qt::LeftButton) {
298 m_d->dragStart = e->localPos();
310 if (e->buttons() & Qt::LeftButton) {
320 if (e->button() == Qt::LeftButton) {
331 if (
m_d->acceptTabletEvents &&
332 (event->button() == Qt::LeftButton || (event->buttons() & Qt::LeftButton)))
335 switch (event->type()) {
336 case QEvent::TabletPress: {
337 QMouseEvent mouseEvent(QEvent::MouseButtonPress, event->posF(), event->posF(),
338 event->globalPosF(), event->button(), event->buttons(),
339 event->modifiers(), Qt::MouseEventSynthesizedByApplication);
343 case QEvent::TabletMove: {
344 QMouseEvent mouseEvent(QEvent::MouseMove, event->posF(), event->posF(),
345 event->globalPosF(), event->button(), event->buttons(),
346 event->modifiers(), Qt::MouseEventSynthesizedByApplication);
350 case QEvent::TabletRelease: {
351 QMouseEvent mouseEvent(QEvent::MouseButtonRelease, event->posF(), event->posF(),
352 event->globalPosF(), event->button(), event->buttons(),
353 event->modifiers(), Qt::MouseEventSynthesizedByApplication);
365 QPainter painter(
this);
368 if (!fullSelector.isNull()) {
369 painter.drawImage(0, 0, fullSelector);
375 painter.setRenderHint(QPainter::Antialiasing);
395 return m_d->dimension;
410 if (dimension == 0) {
411 return m_d->channel1;
414 return m_d->channel2;
421 return m_d->channelMask;
The KisVisualColorModel class allows manipulating a KoColor using various color models.
const KoColorSpace * colorSpace() const
KoColor convertChannelValuesToKoColor(const QVector4D &values) const
KisVisualColorModel * selectorModel() const
void setCursorPosition(QPointF position, bool signal=false)
setCursorPosition Set the cursor to normalized shape coordinates. This will only repaint the cursor.
void setChannelValues(QVector4D channelValues, quint32 channelFlags)
setChannelValues Set the current channel values; Note that channel values controlled by the shape its...
void mouseReleaseEvent(QMouseEvent *e) override
KisVisualColorSelector * colorSelector() const
virtual bool supportsGamutMask() const
void mouseMoveEvent(QMouseEvent *e) override
void forceImageUpdate()
forceImageUpdate force the image to recache.
virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPointF coordinate) const =0
convertWidgetCoordinateToShapeCoordinate Convert a coordinate in the widget's height/width to a shape...
QPointF getCursorPosition() const
getCursorPosition
virtual void drawCursor(QPainter &painter)=0
int channel(int dimension) const
channel Get the channel index associated with a selector shape dimension
virtual QImage renderStaticAlphaMask() const
virtual QImage renderBackground(const QVector4D &channelValues, const QImage &alpha) const
renderBackground Render the widget background visible inside the widget's mask in current color space...
virtual QImage compositeBackground() const
virtual QImage renderAlphaMask() const
render the alpha mask for the widget background the returned image is expected to be QImage::Format_A...
quint32 channelMask() const
void mousePressEvent(QMouseEvent *e) override
void setAcceptTabletEvents(bool on)
~KisVisualColorSelectorShape() override
virtual void updateGamutMask()
Notify shape that the gamut mask changed.
QColor getColorFromConverter(KoColor c)
getColorFromConverter
virtual void drawGamutMask(QPainter &painter)
void tabletEvent(QTabletEvent *event) override
virtual QRegion getMaskMap()=0
getPixmap
KoColor getCurrentColor()
getCurrentColor
void sigCursorMoved(QPointF pos)
const QScopedPointer< Private > m_d
bool isHueControl() const
void paintEvent(QPaintEvent *) override
KisVisualColorSelectorShape(KisVisualColorSelector *parent, KisVisualColorSelectorShape::Dimensions dimension, int channel1, int channel2)
Dimensions getDimensions() const
getDimensions
virtual QPointF mousePositionToShapeCoordinate(const QPointF &pos, const QPointF &dragStart) const
default implementation just calls convertWidgetCoordinateToShapeCoordinate(pos)
QImage convertImageMap(const quint8 *rawColor, quint32 bufferSize, QSize imgSize) const
convertImageMap convert image data containing raw KoColor data into a QImage
Dimensions
The Dimensions enum Whether or not the shape is single or two dimensional.
const QImage & getImageMap()
getImageMap returns the updated base image
void resizeEvent(QResizeEvent *) override
The KisVisualColorSelector class.
void sigInteraction(bool active)
sigInteraction is emitted whenever mouse interaction status changes
const KoColorDisplayRendererInterface * displayRenderer() const
KisVisualColorModelSP selectorModel() const
virtual QColor toQColor(const KoColor &c, bool proofToPaintColors=false) const =0
virtual QImage toQImage(const KoColorSpace *srcColorSpace, const quint8 *data, QSize size, bool proofPaintColors=false) const =0
Convert a consecutive block of pixel data to an ARGB32 QImage.
virtual quint32 pixelSize() const =0
#define KIS_SAFE_ASSERT_RECOVER(cond)
QVector4D currentChannelValues
QPointF currentCoordinates