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

(cherry-picked from 5407ae8)
  • Loading branch information
nyalldawson committed Aug 17, 2016
1 parent 9bd1e75 commit 7c4db385db073246c769497ae41b81e8fa627e2e
@@ -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& 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;

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

class QMimeData;
class QgsColorSchemeRegistry;
class QgsPanelWidget;

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

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