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
  • Loading branch information
nyalldawson committed Aug 15, 2016
1 parent a2fe4c4 commit 5407ae8
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/qgscolorbutton.cpp
Expand Up @@ -94,6 +94,17 @@ const QPixmap& QgsColorButton::transparentBackground()

void QgsColorButton::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 @@ -358,6 +369,22 @@ void QgsColorButton::setValidColor( const QColor& newColor )
}
}

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

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

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

class QMimeData;
class QgsColorSchemeRegistry;
class QgsPanelWidget;

/** \ingroup gui
* \class QgsColorButton
Expand Down Expand Up @@ -419,6 +420,14 @@ class GUI_EXPORT QgsColorButton : 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 5407ae8

Please sign in to comment.