Skip to content

Commit 7c4db38

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 (cherry-picked from 5407ae8)
1 parent 9bd1e75 commit 7c4db38

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/qgscolorbuttonv2.cpp

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

9595
void QgsColorButtonV2::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

@@ -368,6 +379,22 @@ void QgsColorButtonV2::setValidColor( const QColor& newColor )
368379
}
369380
}
370381

382+
void QgsColorButtonV2::setValidTemporaryColor( const QColor& newColor )
383+
{
384+
if ( newColor.isValid() )
385+
{
386+
setColor( newColor );
387+
}
388+
}
389+
390+
void QgsColorButtonV2::panelAccepted( QgsPanelWidget* widget )
391+
{
392+
if ( QgsCompoundColorWidget* colorWidget = qobject_cast< QgsCompoundColorWidget* >( widget ) )
393+
{
394+
addRecentColor( colorWidget->color() );
395+
}
396+
}
397+
371398
QPixmap QgsColorButtonV2::createMenuIcon( const QColor &color, const bool showChecks )
372399
{
373400
//create an icon pixmap

src/gui/qgscolorbuttonv2.h

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

2323
class QMimeData;
2424
class QgsColorSchemeRegistry;
25+
class QgsPanelWidget;
2526

2627
/** \ingroup gui
2728
* \class QgsColorButtonV2
@@ -420,6 +421,14 @@ class GUI_EXPORT QgsColorButtonV2 : public QToolButton
420421
*/
421422
void setValidColor( const QColor& newColor );
422423

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

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)