Skip to content
Permalink
Browse files

[bugfix] Restore color picker from layer styling panel

Fixes #17721

Successfully tested on Windows 10 and Linux with Qt 5.10
  • Loading branch information
elpaso committed Feb 15, 2018
1 parent 19ab0c8 commit 948452b78ab6976665bca19a25e65c9c7a9a1adb
Showing with 24 additions and 15 deletions.
  1. +19 −13 src/gui/qgscolorbutton.cpp
  2. +5 −2 src/gui/qgscolorbutton.h
@@ -239,10 +239,7 @@ void QgsColorButton::mouseMoveEvent( QMouseEvent *e )
QScreen *screen = findScreenAt( e->globalPos() );
if ( screen )
{
QPixmap snappedPixmap = screen->grabWindow( QApplication::desktop()->winId(), e->globalPos().x(), e->globalPos().y(), 1, 1 );
QImage snappedImage = snappedPixmap.toImage();
QColor hoverColor = snappedImage.pixel( 0, 0 );
setButtonBackground( hoverColor );
setButtonBackground( sampleColor( e->globalPos() ) );
}
}
e->accept();
@@ -286,26 +283,22 @@ void QgsColorButton::mouseReleaseEvent( QMouseEvent *e )
QToolButton::mouseReleaseEvent( e );
}

void QgsColorButton::stopPicking( QPointF eventPos, bool sampleColor )
void QgsColorButton::stopPicking( QPoint eventPos, bool samplingColor )
{
//release mouse and keyboard, and reset cursor
releaseMouse();
releaseKeyboard();
unsetCursor();
QgsApplication::restoreOverrideCursor();
setMouseTracking( false );
mPickingColor = false;

if ( !sampleColor )
if ( !samplingColor )
{
//not sampling color, nothing more to do
return;
}

//grab snapshot of pixel under mouse cursor
QPixmap snappedPixmap = QApplication::desktop()->screen()->grab( QRect( eventPos.x(), eventPos.y(), 1, 1 ) );
QImage snappedImage = snappedPixmap.toImage();
//extract color from pixel and set color
setColor( snappedImage.pixel( 0, 0 ) );
setColor( sampleColor( eventPos ) );
addRecentColor( mColor );
}

@@ -356,6 +349,19 @@ void QgsColorButton::dropEvent( QDropEvent *e )
}
}

QColor QgsColorButton::sampleColor( QPoint point ) const
{

QScreen *screen = findScreenAt( point );
if ( ! screen )
{
return QColor();
}
QPixmap snappedPixmap = screen->grabWindow( QApplication::desktop()->winId(), point.x(), point.y(), 1, 1 );
QImage snappedImage = snappedPixmap.toImage();
return snappedImage.pixel( 0, 0 );
}

QScreen *QgsColorButton::findScreenAt( QPoint pos )
{
for ( QScreen *screen : QGuiApplication::screens() )
@@ -680,7 +686,7 @@ void QgsColorButton::pasteColor()
void QgsColorButton::activatePicker()
{
//activate picker color
setCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::Sampler ) );
QApplication::setOverrideCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::Sampler ) );
grabMouse();
grabKeyboard();
mPickingColor = true;
@@ -399,6 +399,9 @@ class GUI_EXPORT QgsColorButton : public QToolButton

private:


QColor sampleColor( QPoint point ) const;

static QScreen *findScreenAt( QPoint pos );
Behavior mBehavior = QgsColorButton::ShowDialog;
QString mColorDialogTitle;
@@ -436,10 +439,10 @@ class GUI_EXPORT QgsColorButton : public QToolButton
/**
* Ends a color picking operation
* \param eventPos global position of pixel to sample color from
* \param sampleColor set to true to actually sample the color, false to just cancel
* \param samplingColor set to true to actually sample the color, false to just cancel
* the color picking operation
*/
void stopPicking( QPointF eventPos, bool sampleColor = true );
void stopPicking( QPoint eventPos, bool samplingColor = true );

/**
* Create a color icon for display in the drop-down menu

0 comments on commit 948452b

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