Skip to content
Permalink
Browse files

[color picker] Clicking the previous color should reset to that color

  • Loading branch information
nyalldawson committed Sep 30, 2014
1 parent fb7415c commit fd92dd95aaf8f83a1b3b72eec8ee97cf9da20f23
Showing with 30 additions and 0 deletions.
  1. +3 −0 python/gui/qgscolorwidgets.sip
  2. +24 −0 src/gui/qgscolorwidgets.cpp
  3. +3 −0 src/gui/qgscolorwidgets.h
@@ -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 );

@@ -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
@@ -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 );

0 comments on commit fd92dd9

Please sign in to comment.
You can’t perform that action at this time.