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

This commit is contained in:
Nyall Dawson 2014-09-30 20:37:28 +10:00
parent fb7415c3ff
commit fd92dd95aa
3 changed files with 30 additions and 0 deletions

View File

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

View File

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

View File

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