Skip to content

Commit

Permalink
[FEATURE] Color dialog can be embedded in layer style panel
Browse files Browse the repository at this point in the history
Now clicking color buttons inside the layer style panel causes
the color picker dialog to be opened inside the style panel itself
rather than as a separate dialog

(cherry-picked from 5407ae8)
  • Loading branch information
nyalldawson committed Aug 17, 2016
1 parent 9bd1e75 commit 7c4db38
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgscompoundcolorwidget.sip
Expand Up @@ -6,7 +6,7 @@
* \note Added in version 2.16
*/

class QgsCompoundColorWidget : QWidget
class QgsCompoundColorWidget : QgsPanelWidget
{
%TypeHeaderCode
#include <qgscompoundcolorwidget.h>
Expand Down
27 changes: 27 additions & 0 deletions src/gui/qgscolorbuttonv2.cpp
Expand Up @@ -94,6 +94,17 @@ const QPixmap& QgsColorButtonV2::transparentBackground()

void QgsColorButtonV2::showColorDialog()
{
if ( QgsPanelWidget* panel = QgsPanelWidget::findParentPanel( this ) )
{
QgsCompoundColorWidget* colorWidget = new QgsCompoundColorWidget( panel, color() );
colorWidget->setPanelTitle( mColorDialogTitle );
colorWidget->setAllowAlpha( mAllowAlpha );
connect( colorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( setValidTemporaryColor( QColor ) ) );
connect( colorWidget, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( panelAccepted( QgsPanelWidget* ) ) );
panel->openPanel( colorWidget );
return;
}

QColor newColor;
QSettings settings;

Expand Down Expand Up @@ -368,6 +379,22 @@ void QgsColorButtonV2::setValidColor( const QColor& newColor )
}
}

void QgsColorButtonV2::setValidTemporaryColor( const QColor& newColor )
{
if ( newColor.isValid() )
{
setColor( newColor );
}
}

void QgsColorButtonV2::panelAccepted( QgsPanelWidget* widget )
{
if ( QgsCompoundColorWidget* colorWidget = qobject_cast< QgsCompoundColorWidget* >( widget ) )
{
addRecentColor( colorWidget->color() );
}
}

QPixmap QgsColorButtonV2::createMenuIcon( const QColor &color, const bool showChecks )
{
//create an icon pixmap
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgscolorbuttonv2.h
Expand Up @@ -22,6 +22,7 @@

class QMimeData;
class QgsColorSchemeRegistry;
class QgsPanelWidget;

/** \ingroup gui
* \class QgsColorButtonV2
Expand Down Expand Up @@ -420,6 +421,14 @@ class GUI_EXPORT QgsColorButtonV2 : public QToolButton
*/
void setValidColor( const QColor& newColor );

/** Sets color for button, if valid. The color is treated as a temporary color, and is not
* added to the recent colors list.
*/
void setValidTemporaryColor( const QColor& newColor );

//! Called when a color widget panel is accepted, and adds the final color to the recent colors list
void panelAccepted( QgsPanelWidget* widget );

/** Adds a color to the recent colors list
* @param color to add to recent colors list
*/
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgscompoundcolorwidget.cpp
Expand Up @@ -31,7 +31,7 @@


QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& color )
: QWidget( parent )
: QgsPanelWidget( parent )
, mAllowAlpha( true )
, mLastCustomColorIndex( 0 )
, mPickingColor( false )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgscompoundcolorwidget.h
Expand Up @@ -17,6 +17,7 @@
#define QGSCOMPOUNDCOLORWIDGET_H

#include "qgisgui.h"
#include "qgspanelwidget.h"
#include "ui_qgscompoundcolorwidget.h"

/** \ingroup gui
Expand All @@ -26,7 +27,7 @@
* \note Added in version 2.16
*/

class GUI_EXPORT QgsCompoundColorWidget : public QWidget, private Ui::QgsCompoundColorWidgetBase
class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::QgsCompoundColorWidgetBase
{

Q_OBJECT
Expand Down

0 comments on commit 7c4db38

Please sign in to comment.