Skip to content

Commit

Permalink
[color picker] Clicking the previous color should reset to that color
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 30, 2014
1 parent fb7415c commit fd92dd9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/gui/qgscolorwidgets.sip
Expand Up @@ -421,6 +421,9 @@ class QgsColorPreviewWidget : QgsColorWidget
//reimplemented to allow dragging colors
void mousePressEvent( QMouseEvent* e );

//reimplemented to click colors
void mouseReleaseEvent( QMouseEvent* e );

//reimplemented to allow dragging colors
void mouseMoveEvent( QMouseEvent *e );

Expand Down
24 changes: 24 additions & 0 deletions src/gui/qgscolorwidgets.cpp
Expand Up @@ -1591,6 +1591,30 @@ void QgsColorPreviewWidget::mousePressEvent( QMouseEvent *e )
QWidget::mousePressEvent( e );
}

void QgsColorPreviewWidget::mouseReleaseEvent( QMouseEvent *e )
{
if (( e->pos() - mDragStartPosition ).manhattanLength() >= QApplication::startDragDistance() )
{
//mouse moved, so a drag. nothing to do here
QWidget::mouseReleaseEvent( e );
return;
}

//work out which color was clicked
QColor clickedColor = mCurrentColor;
if ( mColor2.isValid() )
{
//two color sections, check if dragged color was the second color
int verticalSplit = qRound( height() / 2.0 );
if ( mDragStartPosition.y() >= verticalSplit )
{
clickedColor = mColor2;
}
}
emit colorChanged( clickedColor );

}

void QgsColorPreviewWidget::mouseMoveEvent( QMouseEvent *e )
{
//handle dragging colors from button
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgscolorwidgets.h
Expand Up @@ -632,6 +632,9 @@ class GUI_EXPORT QgsColorPreviewWidget : public QgsColorWidget
//reimplemented to allow dragging colors
void mousePressEvent( QMouseEvent* e );

//reimplemented to click colors
void mouseReleaseEvent( QMouseEvent* e );

//reimplemented to allow dragging colors
void mouseMoveEvent( QMouseEvent *e );

Expand Down

0 comments on commit fd92dd9

Please sign in to comment.