Commit d9fc35c3 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Add anti-cursor resetting measures, and add docs.

The cursor won't flip about when desaturated, but saturation itself is
still very tricky. Either way, outside updates won't affect a thing.
parent d09605cb
......@@ -89,11 +89,11 @@ void KisVisualColorSelector::slotsetColorSpace(const KoColorSpace *cs)
KisVisualRectangleSelectorShape *bar = new KisVisualRectangleSelectorShape(this,
KisVisualRectangleSelectorShape::onedimensional,
KisVisualColorSelectorShape::HSV,
cs, 0, 0,
cs, 2, 2,
m_d->displayRenderer);
KisVisualRectangleSelectorShape *block = new KisVisualRectangleSelectorShape(this, KisVisualRectangleSelectorShape::twodimensional,
KisVisualColorSelectorShape::HSV,
cs, 1, 2,
cs, 0, 1,
m_d->displayRenderer);
bar->setMaximumWidth(width()*0.1);
bar->setMaximumHeight(height());
......@@ -186,6 +186,9 @@ struct KisVisualColorSelectorShape::Private
KisSignalCompressor *updateTimer;
bool mousePressActive = false;
const KoColorDisplayRendererInterface *displayRenderer = 0;
qreal hue = 0.0;
qreal sat = 0.0;
};
KisVisualColorSelectorShape::KisVisualColorSelectorShape(QWidget *parent,
......@@ -235,6 +238,7 @@ void KisVisualColorSelectorShape::setColor(KoColor c)
}
m_d->currentColor = c;
updateCursor();
convertShapeCoordinateToKoColor(getCursorPosition(), true);
m_d->pixmapsNeedUpdate = true;
update();
}
......@@ -317,7 +321,7 @@ QPixmap KisVisualColorSelectorShape::getPixmap()
return m_d->gradient;
}
KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coordinates)
KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coordinates, bool cursor)
{
KoColor c = m_d->currentColor;
QVector <float> channelValues (c.colorSpace()->channelCount());
......@@ -353,10 +357,12 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
*/
QVector <float> inbetween(3);
RGBToHSV(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
inbetween[m_d->channel1] = coordinates.x()*huedivider;
if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y()*huedivider2;
}
if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));}
HSVToRGB(qMax(inbetween[0],(float)0.0), inbetween[1], inbetween[2], &channelValues[2], &channelValues[1], &channelValues[0]);
} else if (m_d->model == ColorModel::HSL) {
/*
......@@ -365,10 +371,12 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
*/
QVector <float> inbetween(3);
RGBToHSL(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
inbetween[m_d->channel1] = coordinates.x()*huedivider;
if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y()*huedivider2;
}
if (cursor==true){setHSX(convertvectorfloatToqreal(inbetween));}
HSLToRGB(inbetween[0], inbetween[1], inbetween[2],&channelValues[2],&channelValues[1], &channelValues[0]);
} else if (m_d->model == ColorModel::HSI) {
/*
......@@ -377,10 +385,12 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSI(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween = getHSX(inbetween);
inbetween[m_d->channel1] = coordinates.x();
if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y();
}
if (cursor==true){setHSX(inbetween);}
HSIToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[2],&chan2[1], &chan2[0]);
channelValues = convertvectorqrealTofloat(chan2);
} else /*if (m_d->model == ColorModel::HSY)*/ {
......@@ -394,10 +404,12 @@ KoColor KisVisualColorSelectorShape::convertShapeCoordinateToKoColor(QPointF coo
QVector <qreal> inbetween(3);
RGBToHSY(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2],
luma[0], luma[1], luma[2]);
inbetween = getHSX(inbetween);
inbetween[m_d->channel1] = coordinates.x();
if (m_d->dimension == Dimensions::twodimensional) {
inbetween[m_d->channel2] = coordinates.y();
}
if (cursor==true){setHSX(inbetween);}
HSYToRGB(inbetween[0], inbetween[1], inbetween[2],&chan2[2],&chan2[1], &chan2[0],
luma[0], luma[1], luma[2]);
channelValues = convertvectorqrealTofloat(chan2);
......@@ -449,6 +461,7 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)
if (m_d->model == ColorModel::HSV){
QVector <float> inbetween(3);
RGBToHSV(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
coordinates.setX(inbetween[m_d->channel1]/huedivider);
if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]/huedivider2);
......@@ -456,6 +469,7 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)
} else if (m_d->model == ColorModel::HSL) {
QVector <float> inbetween(3);
RGBToHSL(channelValues[2],channelValues[1], channelValues[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween = convertvectorqrealTofloat(getHSX(convertvectorfloatToqreal(inbetween)));
coordinates.setX(inbetween[m_d->channel1]/huedivider);
if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]/huedivider2);
......@@ -464,6 +478,7 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSI(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2]);
inbetween = getHSX(inbetween);
coordinates.setX(inbetween[m_d->channel1]);
if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]);
......@@ -473,6 +488,7 @@ QPointF KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)
QVector <qreal> chan2 = convertvectorfloatToqreal(channelValues);
QVector <qreal> inbetween(3);
RGBToHSY(chan2[2],chan2[1], chan2[0], &inbetween[0], &inbetween[1], &inbetween[2], luma[0], luma[1], luma[2]);
inbetween = getHSX(inbetween);
coordinates.setX(inbetween[m_d->channel1]);
if (m_d->dimension == Dimensions::twodimensional) {
coordinates.setY(inbetween[m_d->channel2]);
......@@ -567,6 +583,27 @@ KoColor KisVisualColorSelectorShape::getCurrentColor()
return m_d->currentColor;
}
QVector <qreal> KisVisualColorSelectorShape::getHSX(QVector<qreal> hsx)
{
if ((hsx[2]<=0.0 || hsx[2]>=1.0) && m_d->channel1!=2 && m_d->channel2!=2) {
hsx[1] = m_d->sat;
hsx[0]=m_d->hue;
} else if (hsx[1]<=0.0 && m_d->channel1!=1 && m_d->channel2!=1){
hsx[0]=m_d->hue;
}
return hsx;
}
void KisVisualColorSelectorShape::setHSX(QVector<qreal> hsx)
{
if (hsx[2]>0.0 && hsx[2<1.0]){
m_d->sat = hsx[1];
}
if (hsx[1]>0.0) {
m_d->hue = hsx[0];
}
}
/*-----------Rectangle Shape------------*/
KisVisualRectangleSelectorShape::KisVisualRectangleSelectorShape(QWidget *parent,
......
......@@ -66,6 +66,21 @@ private:
//kis_visual_color_selector_shape
/**
* @brief The KisVisualColorSelectorShape class
* A 2d widget can represent at maximum 2 coordinates.
* So first decide howmany coordinates you need. (onedimensional, or twodimensional)
* Then the model, (Channel, HSV, HSL, HSI, YUV). Channel is the raw color channels.
* When it finds a non-implemented feature it'll return to Channel.
* Then, select the channels you wish to be affected. This uses the model, so for cmyk
* the channel is c=0, m=1, y=2, k=3, but for hsv, hue=0, sat=1, and val=2
* These can also be set with 'slotsetactive channels'.
* Then finally, connect the displayrenderer, you can also do this with 'setdisplayrenderer'
*
* Either way, this class is made to be subclassed, with a few virtuals so that the geometry
* can be calculated properly.
*/
class KisVisualColorSelectorShape : public QWidget
{
Q_OBJECT
......@@ -73,8 +88,7 @@ public:
/**
* @brief The Dimensions enum
* Wether or not the shape is single or two dimensional.
* A 2d widget can represent at maximum 2 coordinates.
*/
**/
enum Dimensions{onedimensional, twodimensional};
enum ColorModel{Channel, HSV, HSL, HSI, HSY, YUV};
explicit KisVisualColorSelectorShape(QWidget *parent,
......@@ -85,22 +99,79 @@ public:
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance());
~KisVisualColorSelectorShape();
/**
* @brief getCursorPosition
* @return current cursor position in shape-coordinates.
*/
QPointF getCursorPosition();
/**
* @brief getDimensions
* @return whether this is a single or twodimensional widget.
*/
Dimensions getDimensions();
/**
* @brief getColorModel
* @return the model of this widget.
*/
ColorModel getColorModel();
/**
* @brief getPixmap
* @return the pixmap of the gradient, for drawing on with a subclass.
* the pixmap will not change unless 'm_d->setPixmap=true' which is toggled by
* refresh and update functions.
*/
QPixmap getPixmap();
/**
* @brief setFullImage
* Set the full widget image to be painted.
* @param full this should be the full image.
*/
void setFullImage(QPixmap full);
/**
* @brief getCurrentColor
* @return the current kocolor
*/
KoColor getCurrentColor();
/**
* @brief setDisplayRenderer
* disconnect the old display renderer if needed and connect the new one.
* @param displayRenderer
*/
void setDisplayRenderer (const KoColorDisplayRendererInterface *displayRenderer);
/**
* @brief getColorFromConverter
* @param c a koColor.
* @return get the qcolor from the given kocolorusing this widget's display renderer.
*/
QColor getColorFromConverter(KoColor c);
Q_SIGNALS:
void sigNewColor(KoColor col);
public Q_SLOTS:
/**
* @brief setColor
* Set this widget's current color and chang ethe cursor position.
* @param c
*/
void setColor(KoColor c);
/**
* @brief setColorFromSibling
* set this widget's current color, but don't change the cursor position,
* instead sent out a signal of the new color.
* @param c
*/
void setColorFromSibling(KoColor c);
/**
* @brief slotSetActiveChannels
* Change the active channels if necessary.
* @param channel1 used by single and twodimensional widgets.
* @param channel2 only used by twodimensional widgets.
*/
void slotSetActiveChannels(int channel1, int channel2);
/**
* @brief updateFromChangedDisplayRenderer
* for updating from the display renderer... not sure why this one is public.
*/
void updateFromChangedDisplayRenderer();
protected:
void mousePressEvent(QMouseEvent *e);
......@@ -112,6 +183,21 @@ private:
struct Private;
const QScopedPointer<Private> m_d;
/**
* @brief setHSX
* This is for the cursor not to change when selecting
* black, white, and desaturated values. Will not change the non-native values.
* @param hsx the hsx value.
*/
void setHSX(QVector <qreal> hsx);
/**
* @brief getHSX sets the sat and hue so they won't
* switch around much.
* @param hsx the hsx values.
* @return returns hsx, corrected.
*/
QVector <qreal> getHSX(QVector <qreal> hsx);
/**
* @brief convertShapeCoordinateToWidgetCoordinate
* @return take the position in the shape and convert it to screen coordinates.
......@@ -132,7 +218,7 @@ private:
void updateCursor();
QPointF convertKoColorToShapeCoordinate(KoColor c);
KoColor convertShapeCoordinateToKoColor(QPointF coordinates);
KoColor convertShapeCoordinateToKoColor(QPointF coordinates, bool cursor=false);
/**
* @brief getPixmap
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment