Skip to content

Commit fd92dd9

Browse files
committedSep 30, 2014
[color picker] Clicking the previous color should reset to that color
1 parent fb7415c commit fd92dd9

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
 

‎python/gui/qgscolorwidgets.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ class QgsColorPreviewWidget : QgsColorWidget
421421
//reimplemented to allow dragging colors
422422
void mousePressEvent( QMouseEvent* e );
423423

424+
//reimplemented to click colors
425+
void mouseReleaseEvent( QMouseEvent* e );
426+
424427
//reimplemented to allow dragging colors
425428
void mouseMoveEvent( QMouseEvent *e );
426429

‎src/gui/qgscolorwidgets.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,30 @@ void QgsColorPreviewWidget::mousePressEvent( QMouseEvent *e )
15911591
QWidget::mousePressEvent( e );
15921592
}
15931593

1594+
void QgsColorPreviewWidget::mouseReleaseEvent( QMouseEvent *e )
1595+
{
1596+
if (( e->pos() - mDragStartPosition ).manhattanLength() >= QApplication::startDragDistance() )
1597+
{
1598+
//mouse moved, so a drag. nothing to do here
1599+
QWidget::mouseReleaseEvent( e );
1600+
return;
1601+
}
1602+
1603+
//work out which color was clicked
1604+
QColor clickedColor = mCurrentColor;
1605+
if ( mColor2.isValid() )
1606+
{
1607+
//two color sections, check if dragged color was the second color
1608+
int verticalSplit = qRound( height() / 2.0 );
1609+
if ( mDragStartPosition.y() >= verticalSplit )
1610+
{
1611+
clickedColor = mColor2;
1612+
}
1613+
}
1614+
emit colorChanged( clickedColor );
1615+
1616+
}
1617+
15941618
void QgsColorPreviewWidget::mouseMoveEvent( QMouseEvent *e )
15951619
{
15961620
//handle dragging colors from button

‎src/gui/qgscolorwidgets.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ class GUI_EXPORT QgsColorPreviewWidget : public QgsColorWidget
632632
//reimplemented to allow dragging colors
633633
void mousePressEvent( QMouseEvent* e );
634634

635+
//reimplemented to click colors
636+
void mouseReleaseEvent( QMouseEvent* e );
637+
635638
//reimplemented to allow dragging colors
636639
void mouseMoveEvent( QMouseEvent *e );
637640

0 commit comments

Comments
 (0)
Please sign in to comment.