Skip to content
Permalink
Browse files

Ensure that colors are always added to recent color list from style p…

…anel
  • Loading branch information
nyalldawson committed Sep 14, 2016
1 parent 5b6bf82 commit 31e16610063169eac070e580a1d2fc957391c0e9
@@ -41,6 +41,13 @@ class QgsCompoundColorWidget : QgsPanelWidget
*/
void setAllowAlpha( const bool allowAlpha );

/** Sets whether the widget's color has been "discarded" and the selected color should not
* be stored in the recent color list.
* @param discarded set to true to avoid adding color to recent color list on widget destruction.
* @note added in QGIS 3.0
*/
void setDiscarded( bool discarded );

signals:

/** Emitted when the dialog's color changes
@@ -101,7 +101,6 @@ void QgsColorButton::showColorDialog()
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;
}
@@ -141,7 +140,6 @@ void QgsColorButton::showColorDialog()
if ( newColor.isValid() )
{
setValidColor( newColor );
addRecentColor( newColor );
}

// reactivate button's window
@@ -378,14 +376,6 @@ void QgsColorButton::setValidTemporaryColor( const QColor& 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
@@ -425,9 +425,6 @@ class GUI_EXPORT QgsColorButton : public QToolButton
*/
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
*/
@@ -55,6 +55,7 @@ QgsColorDialog::QgsColorDialog( QWidget *parent, Qt::WindowFlags fl, const QColo
mColorWidget->setAllowAlpha( true );

connect( mColorWidget, SIGNAL( currentColorChanged( QColor ) ), this, SIGNAL( currentColorChanged( QColor ) ) );
connect( this, SIGNAL( rejected() ), this, SLOT( discardColor() ) );
}

QgsColorDialog::~QgsColorDialog()
@@ -174,6 +175,11 @@ void QgsColorDialog::on_mButtonBox_clicked( QAbstractButton * button )
}
}

void QgsColorDialog::discardColor()
{
mColorWidget->setDiscarded( true );
}

void QgsColorDialog::saveSettings()
{
QSettings settings;
@@ -111,6 +111,7 @@ class GUI_EXPORT QgsColorDialog : public QDialog, private Ui::QgsColorDialogBase
void on_mButtonBox_accepted();
void on_mButtonBox_rejected();
void on_mButtonBox_clicked( QAbstractButton * button );
void discardColor();

private:

@@ -35,6 +35,7 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& c
, mAllowAlpha( true )
, mLastCustomColorIndex( 0 )
, mPickingColor( false )
, mDiscarded( false )
{
setupUi( this );

@@ -240,6 +241,10 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor& c
QgsCompoundColorWidget::~QgsCompoundColorWidget()
{
saveSettings();
if ( !mDiscarded )
{
QgsRecentColorScheme::addRecentColor( color() );
}
}

QColor QgsCompoundColorWidget::color() const
@@ -61,6 +61,13 @@ class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::Qgs
*/
void setAllowAlpha( const bool allowAlpha );

/** Sets whether the widget's color has been "discarded" and the selected color should not
* be stored in the recent color list.
* @param discarded set to true to avoid adding color to recent color list on widget destruction.
* @note added in QGIS 3.0
*/
void setDiscarded( bool discarded ) { mDiscarded = discarded; }

signals:

/** Emitted when the dialog's color changes
@@ -125,6 +132,8 @@ class GUI_EXPORT QgsCompoundColorWidget : public QgsPanelWidget, private Ui::Qgs

bool mPickingColor;

bool mDiscarded;

/** Saves all widget settings
*/
void saveSettings();

0 comments on commit 31e1661

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