Commit 418ebf10 authored by Mathias Wein's avatar Mathias Wein

Limit cursor drag in mirror mode elliptic selector shape

Without any kind of barrier between left and right half,
it was not really possible to select the min or max value
as you could in a bar control.
With this change, the cursor coordinate will be limited
to the side where mouse dragging started.
parent f83ba656
......@@ -50,6 +50,7 @@ struct KisVisualColorSelectorShape::Private
bool alphaNeedsUpdate { true };
bool acceptTabletEvents { false };
QPointF currentCoordinates; // somewhat redundant?
QPointF dragStart;
QVector4D currentChannelValues;
Dimensions dimension;
const KoColorSpace *colorSpace;
......@@ -274,10 +275,17 @@ QImage KisVisualColorSelectorShape::renderAlphaMask() const
return QImage();
}
QPointF KisVisualColorSelectorShape::mousePositionToShapeCoordinate(const QPointF &pos, const QPointF &dragStart) const
{
Q_UNUSED(dragStart)
return convertWidgetCoordinateToShapeCoordinate(pos);
}
void KisVisualColorSelectorShape::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->localPos());
m_d->dragStart = e->localPos();
QPointF coordinates = mousePositionToShapeCoordinate(e->localPos(), m_d->dragStart);
setCursorPosition(coordinates, true);
}
else {
......@@ -288,7 +296,7 @@ void KisVisualColorSelectorShape::mousePressEvent(QMouseEvent *e)
void KisVisualColorSelectorShape::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->localPos());
QPointF coordinates = mousePositionToShapeCoordinate(e->localPos(), m_d->dragStart);
setCursorPosition(coordinates, true);
} else {
e->ignore();
......
......@@ -192,6 +192,10 @@ protected:
* the returned image is expected to be QImage::Format_Alpha8
*/
virtual QImage renderAlphaMask() const;
/**
* @brief default implementation just calls convertWidgetCoordinateToShapeCoordinate(pos)
*/
virtual QPointF mousePositionToShapeCoordinate(const QPointF &pos, const QPointF &dragStart) const;
void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
......
......@@ -64,6 +64,7 @@ QSize KisVisualEllipticalSelectorShape::sizeHint() const
{
return QSize(180,180);
}
void KisVisualEllipticalSelectorShape::setBorderWidth(int width)
{
m_barWidth = width;
......@@ -168,6 +169,20 @@ QPointF KisVisualEllipticalSelectorShape::convertWidgetCoordinateToShapeCoordina
return QPointF(x, y);
}
QPointF KisVisualEllipticalSelectorShape::mousePositionToShapeCoordinate(const QPointF &pos, const QPointF &dragStart) const
{
QPointF pos2(pos);
if (m_type == KisVisualEllipticalSelectorShape::borderMirrored) {
qreal h_center = width()/2.0;
bool start_left = dragStart.x() < h_center;
bool cursor_left = pos.x() < h_center;
if (start_left != cursor_left) {
pos2.setX(h_center);
}
}
return convertWidgetCoordinateToShapeCoordinate(pos2);
}
QRegion KisVisualEllipticalSelectorShape::getMaskMap()
{
QRegion mask = QRegion(0,0,width(),height(), QRegion::Ellipse);
......
......@@ -57,12 +57,12 @@ public:
QRect getSpaceForTriangle(QRect geom) override;
protected:
QImage renderAlphaMask() const override;
QPointF mousePositionToShapeCoordinate(const QPointF &pos, const QPointF &dragStart) const override;
private:
QPointF convertShapeCoordinateToWidgetCoordinate(QPointF coordinate) const override;
QPointF convertWidgetCoordinateToShapeCoordinate(QPointF coordinate) const override;
singelDTypes m_type;
int m_barWidth;
QRegion getMaskMap() override;
......
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