Skip to content

Commit

Permalink
Allow copying selected palette colors in color picker dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 25, 2014
1 parent b837223 commit f1de497
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/gui/qgscolordialog.cpp
Expand Up @@ -84,19 +84,26 @@ QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const Q
//get schemes with ShowInColorDialog set
refreshSchemeComboBox();
QList<QgsColorScheme *> schemeList = QgsColorSchemeRegistry::instance()->schemes( QgsColorScheme::ShowInColorDialog );

//choose a reasonable starting scheme
int activeScheme = settings.value( "/Windows/ColorDialog/activeScheme", 0 ).toInt();
if ( activeScheme < mSchemeComboBox->count() )
{
mSchemeList->setScheme( schemeList.at( activeScheme ) );
mSchemeComboBox->setCurrentIndex( activeScheme );
mActionImportColors->setEnabled( schemeList.at( activeScheme )->isEditable() );
mActionPasteColors->setEnabled( schemeList.at( activeScheme )->isEditable() );
mAddColorToSchemeButton->setEnabled( schemeList.at( activeScheme )->isEditable() );
mRemoveColorsFromSchemeButton->setEnabled( schemeList.at( activeScheme )->isEditable() );
QgsUserColorScheme* userScheme = dynamic_cast<QgsUserColorScheme*>( schemeList.at( activeScheme ) );
mActionRemovePalette->setEnabled( userScheme ? true : false );
}
activeScheme = activeScheme >= mSchemeComboBox->count() ? 0 : activeScheme;

mSchemeList->setScheme( schemeList.at( activeScheme ) );
mSchemeComboBox->setCurrentIndex( activeScheme );
mActionImportColors->setEnabled( schemeList.at( activeScheme )->isEditable() );
mActionPasteColors->setEnabled( schemeList.at( activeScheme )->isEditable() );
mAddColorToSchemeButton->setEnabled( schemeList.at( activeScheme )->isEditable() );
mRemoveColorsFromSchemeButton->setEnabled( schemeList.at( activeScheme )->isEditable() );
QgsUserColorScheme* userScheme = dynamic_cast<QgsUserColorScheme*>( schemeList.at( activeScheme ) );
mActionRemovePalette->setEnabled( userScheme ? true : false );

//listen out for selection changes in list, so we can enable/disable the copy colors option
connect( mSchemeList->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this, SLOT( listSelectionChanged( QItemSelection, QItemSelection ) ) );
//copy action defaults to disabled
mActionCopyColors->setEnabled( false );

connect( mActionCopyColors, SIGNAL( triggered() ), mSchemeList, SLOT( copyColors() ) );
connect( mActionPasteColors, SIGNAL( triggered() ), mSchemeList, SLOT( pasteColors() ) );
connect( mActionExportColors, SIGNAL( triggered() ), this, SLOT( exportColors() ) );
connect( mActionImportColors, SIGNAL( triggered() ), this, SLOT( importColors() ) );
Expand All @@ -106,7 +113,9 @@ QgsColorDialogV2::QgsColorDialogV2( QWidget *parent, Qt::WindowFlags fl, const Q
connect( mRemoveColorsFromSchemeButton, SIGNAL( clicked() ), mSchemeList, SLOT( removeSelection() ) );

QMenu* schemeMenu = new QMenu( mSchemeToolButton );
schemeMenu->addAction( mActionCopyColors );
schemeMenu->addAction( mActionPasteColors );
schemeMenu->addSeparator();
schemeMenu->addAction( mActionImportColors );
schemeMenu->addAction( mActionExportColors );
schemeMenu->addSeparator();
Expand Down Expand Up @@ -596,6 +605,15 @@ void QgsColorDialogV2::schemeIndexChanged( int index )
mRemoveColorsFromSchemeButton->setEnabled( scheme->isEditable() );
QgsUserColorScheme* userScheme = dynamic_cast<QgsUserColorScheme*>( scheme );
mActionRemovePalette->setEnabled( userScheme ? true : false );

//copy action defaults to disabled
mActionCopyColors->setEnabled( false );
}

void QgsColorDialogV2::listSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected );
mActionCopyColors->setEnabled( selected.length() > 0 );
}

void QgsColorDialogV2::on_mAddCustomColorButton_clicked()
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgscolordialog.h
Expand Up @@ -165,6 +165,7 @@ class GUI_EXPORT QgsColorDialogV2 : public QDialog, private Ui::QgsColorDialogBa
void newPalette();

void schemeIndexChanged( int index );
void listSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );

void on_mAddCustomColorButton_clicked();

Expand Down
8 changes: 8 additions & 0 deletions src/ui/qgscolordialog.ui
Expand Up @@ -835,6 +835,14 @@
<string>Create a new palette</string>
</property>
</action>
<action name="mActionCopyColors">
<property name="text">
<string>Copy Colors</string>
</property>
<property name="toolTip">
<string>Copy selected colors</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down

0 comments on commit f1de497

Please sign in to comment.