Skip to content

Commit 5407ae8

Browse files
committed
[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
1 parent a2fe4c4 commit 5407ae8

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

python/gui/qgscompoundcolorwidget.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* \note Added in version 2.16
77
*/
88

9-
class QgsCompoundColorWidget : QWidget
9+
class QgsCompoundColorWidget : QgsPanelWidget
1010
{
1111
%TypeHeaderCode
1212
#include <qgscompoundcolorwidget.h>

src/gui/qgscolorbutton.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ const QPixmap& QgsColorButton::transparentBackground()
9494

9595
void QgsColorButton::showColorDialog()
9696
{
97+
if ( QgsPanelWidget* panel = QgsPanelWidget::findParentPanel( this ) )
98+
{
99+
QgsCompoundColorWidget* colorWidget = new QgsCompoundColorWidget( panel, color() );
100+
colorWidget->setPanelTitle( mColorDialogTitle );
101+
colorWidget->setAllowAlpha( mAllowAlpha );
102+
connect( colorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SLOT( setValidTemporaryColor( QColor ) ) );
103+
connect( colorWidget, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( panelAccepted( QgsPanelWidget* ) ) );
104+
panel->openPanel( colorWidget );
105+
return;
106+
}
107+
97108
QColor newColor;
98109
QSettings settings;
99110

@@ -358,6 +369,22 @@ void QgsColorButton::setValidColor( const QColor& newColor )
358369
}
359370
}
360371

372+
void QgsColorButton::setValidTemporaryColor( const QColor& newColor )
373+
{
374+
if ( newColor.isValid() )
375+
{
376+
setColor( newColor );
377+
}
378+
}
379+
380+
void QgsColorButton::panelAccepted( QgsPanelWidget* widget )
381+
{
382+
if ( QgsCompoundColorWidget* colorWidget = qobject_cast< QgsCompoundColorWidget* >( widget ) )
383+
{
384+
addRecentColor( colorWidget->color() );
385+
}
386+
}
387+
361388
QPixmap QgsColorButton::createMenuIcon( const QColor &color, const bool showChecks )
362389
{
363390
//create an icon pixmap

src/gui/qgscolorbutton.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
class QMimeData;
2323
class QgsColorSchemeRegistry;
24+
class QgsPanelWidget;
2425

2526
/** \ingroup gui
2627
* \class QgsColorButton
@@ -419,6 +420,14 @@ class GUI_EXPORT QgsColorButton : public QToolButton
419420
*/
420421
void setValidColor( const QColor& newColor );
421422

423+
/** Sets color for button, if valid. The color is treated as a temporary color, and is not
424+
* added to the recent colors list.
425+
*/
426+
void setValidTemporaryColor( const QColor& newColor );
427+
428+
//! Called when a color widget panel is accepted, and adds the final color to the recent colors list
429+
void panelAccepted( QgsPanelWidget* widget );
430+
422431
/** Adds a color to the recent colors list
423432
* @param color to add to recent colors list
424433
*/

src/gui/qgscompoundcolorwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& color )
34-
: QWidget( parent )
34+
: QgsPanelWidget( parent )
3535
, mAllowAlpha( true )
3636
, mLastCustomColorIndex( 0 )
3737
, mPickingColor( false )

src/gui/qgscompoundcolorwidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define QGSCOMPOUNDCOLORWIDGET_H
1818

1919
#include "qgisgui.h"
20+
#include "qgspanelwidget.h"
2021
#include "ui_qgscompoundcolorwidget.h"
2122

2223
/** \ingroup gui
@@ -26,7 +27,7 @@
2627
* \note Added in version 2.16
2728
*/
2829

29-
class GUI_EXPORT QgsCompoundColorWidget : public QWidget, private Ui::QgsCompoundColorWidgetBase
30+
class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::QgsCompoundColorWidgetBase
3031
{
3132

3233
Q_OBJECT

0 commit comments

Comments
 (0)