Skip to content
Permalink
Browse files

[FEATURE] Color dialog can be embedded in layer style panel

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 5407ae8a6ad2a3599081588d1b3f04bbe4c6fe4b
@@ -6,7 +6,7 @@
* \note Added in version 2.16
*/

class QgsCompoundColorWidget : QWidget
class QgsCompoundColorWidget : QgsPanelWidget
{
%TypeHeaderCode
#include <qgscompoundcolorwidget.h>
@@ -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;

@@ -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
@@ -21,6 +21,7 @@

class QMimeData;
class QgsColorSchemeRegistry;
class QgsPanelWidget;

/** \ingroup gui
* \class QgsColorButton
@@ -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
*/
@@ -31,7 +31,7 @@


QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& color )
: QWidget( parent )
: QgsPanelWidget( parent )
, mAllowAlpha( true )
, mLastCustomColorIndex( 0 )
, mPickingColor( false )
@@ -17,6 +17,7 @@
#define QGSCOMPOUNDCOLORWIDGET_H

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

/** \ingroup gui
@@ -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

0 comments on commit 5407ae8

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