23 #include <QHeaderView> 24 #include <QPushButton> 26 #include <QToolButton> 27 #include <QFileDialog> 28 #include <QMessageBox> 29 #include <QDesktopWidget> 30 #include <QMouseEvent> 32 #include <QInputDialog> 33 #include <QVBoxLayout> 39 connect( mHueRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mHueRadio_toggled );
40 connect( mSaturationRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mSaturationRadio_toggled );
41 connect( mValueRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mValueRadio_toggled );
42 connect( mRedRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mRedRadio_toggled );
43 connect( mGreenRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mGreenRadio_toggled );
44 connect( mBlueRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mBlueRadio_toggled );
45 connect( mAddColorToSchemeButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddColorToSchemeButton_clicked );
46 connect( mAddCustomColorButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddCustomColorButton_clicked );
47 connect( mSampleButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mSampleButton_clicked );
48 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsCompoundColorWidget::mTabWidget_currentChanged );
49 connect( mActionShowInButtons, &QAction::toggled,
this, &QgsCompoundColorWidget::mActionShowInButtons_toggled );
54 QVBoxLayout *newLayout =
new QVBoxLayout();
55 newLayout->setMargin( 0 );
56 newLayout->setContentsMargins( 0, 0, 0, 0 );
57 newLayout->addWidget( mTabWidget );
58 newLayout->addWidget( mSlidersWidget );
59 newLayout->addWidget( mPreviewWidget );
60 newLayout->addWidget( mSwatchesWidget );
62 setLayout( newLayout );
67 mSchemeList->header()->hide();
71 refreshSchemeComboBox();
75 int activeScheme = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), 0 ).toInt();
76 activeScheme = activeScheme >= mSchemeComboBox->count() ? 0 : activeScheme;
78 mSchemeList->setScheme( schemeList.at( activeScheme ) );
80 mSchemeComboBox->setCurrentIndex( activeScheme );
81 updateActionsForCurrentScheme();
84 connect( mSchemeList->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCompoundColorWidget::listSelectionChanged );
86 mActionCopyColors->setEnabled(
false );
92 connect( mActionImportPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::importPalette );
93 connect( mActionRemovePalette, &QAction::triggered,
this, &QgsCompoundColorWidget::removePalette );
94 connect( mActionNewPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::newPalette );
97 QMenu *schemeMenu =
new QMenu( mSchemeToolButton );
98 schemeMenu->addAction( mActionCopyColors );
99 schemeMenu->addAction( mActionPasteColors );
100 schemeMenu->addSeparator();
101 schemeMenu->addAction( mActionImportColors );
102 schemeMenu->addAction( mActionExportColors );
103 schemeMenu->addSeparator();
104 schemeMenu->addAction( mActionNewPalette );
105 schemeMenu->addAction( mActionImportPalette );
106 schemeMenu->addAction( mActionRemovePalette );
107 schemeMenu->addAction( mActionShowInButtons );
108 mSchemeToolButton->setMenu( schemeMenu );
110 connect( mSchemeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsCompoundColorWidget::schemeIndexChanged );
113 mOldColorLabel->hide();
116 mVerticalRamp->setInteriorMargin( 2 );
117 mVerticalRamp->setShowFrame(
true );
127 mSwatchButton1->setShowMenu(
false );
129 mSwatchButton2->setShowMenu(
false );
131 mSwatchButton3->setShowMenu(
false );
133 mSwatchButton4->setShowMenu(
false );
135 mSwatchButton5->setShowMenu(
false );
137 mSwatchButton6->setShowMenu(
false );
139 mSwatchButton7->setShowMenu(
false );
141 mSwatchButton8->setShowMenu(
false );
143 mSwatchButton9->setShowMenu(
false );
145 mSwatchButton10->setShowMenu(
false );
147 mSwatchButton11->setShowMenu(
false );
149 mSwatchButton12->setShowMenu(
false );
151 mSwatchButton13->setShowMenu(
false );
153 mSwatchButton14->setShowMenu(
false );
155 mSwatchButton15->setShowMenu(
false );
157 mSwatchButton16->setShowMenu(
false );
160 mSwatchButton1->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( QColor() ) ).value<QColor>() );
161 mSwatchButton2->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( QColor() ) ).value<QColor>() );
162 mSwatchButton3->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( QColor() ) ).value<QColor>() );
163 mSwatchButton4->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( QColor() ) ).value<QColor>() );
164 mSwatchButton5->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( QColor() ) ).value<QColor>() );
165 mSwatchButton6->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( QColor() ) ).value<QColor>() );
166 mSwatchButton7->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( QColor() ) ).value<QColor>() );
167 mSwatchButton8->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( QColor() ) ).value<QColor>() );
168 mSwatchButton9->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( QColor() ) ).value<QColor>() );
169 mSwatchButton10->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( QColor() ) ).value<QColor>() );
170 mSwatchButton11->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( QColor() ) ).value<QColor>() );
171 mSwatchButton12->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( QColor() ) ).value<QColor>() );
172 mSwatchButton13->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( QColor() ) ).value<QColor>() );
173 mSwatchButton14->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( QColor() ) ).value<QColor>() );
174 mSwatchButton15->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( QColor() ) ).value<QColor>() );
175 mSwatchButton16->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( QColor() ) ).value<QColor>() );
178 mSpinBoxRadius->setValue( settings.
value( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), 1 ).toInt() );
179 mSamplePreview->setColor( QColor() );
182 const int swatchWidth =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.9 * mSwatchButton1->fontMetrics().height(), 38.0 ) ) );
183 const int swatchHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.5 * mSwatchButton1->fontMetrics().height(), 30.0 ) ) );
184 mSwatchButton1->setMinimumSize( swatchWidth, swatchHeight );
185 mSwatchButton1->setMaximumSize( swatchWidth, swatchHeight );
186 mSwatchButton2->setMinimumSize( swatchWidth, swatchHeight );
187 mSwatchButton2->setMaximumSize( swatchWidth, swatchHeight );
188 mSwatchButton3->setMinimumSize( swatchWidth, swatchHeight );
189 mSwatchButton3->setMaximumSize( swatchWidth, swatchHeight );
190 mSwatchButton4->setMinimumSize( swatchWidth, swatchHeight );
191 mSwatchButton4->setMaximumSize( swatchWidth, swatchHeight );
192 mSwatchButton5->setMinimumSize( swatchWidth, swatchHeight );
193 mSwatchButton5->setMaximumSize( swatchWidth, swatchHeight );
194 mSwatchButton6->setMinimumSize( swatchWidth, swatchHeight );
195 mSwatchButton6->setMaximumSize( swatchWidth, swatchHeight );
196 mSwatchButton7->setMinimumSize( swatchWidth, swatchHeight );
197 mSwatchButton7->setMaximumSize( swatchWidth, swatchHeight );
198 mSwatchButton8->setMinimumSize( swatchWidth, swatchHeight );
199 mSwatchButton8->setMaximumSize( swatchWidth, swatchHeight );
200 mSwatchButton9->setMinimumSize( swatchWidth, swatchHeight );
201 mSwatchButton9->setMaximumSize( swatchWidth, swatchHeight );
202 mSwatchButton10->setMinimumSize( swatchWidth, swatchHeight );
203 mSwatchButton10->setMaximumSize( swatchWidth, swatchHeight );
204 mSwatchButton11->setMinimumSize( swatchWidth, swatchHeight );
205 mSwatchButton11->setMaximumSize( swatchWidth, swatchHeight );
206 mSwatchButton12->setMinimumSize( swatchWidth, swatchHeight );
207 mSwatchButton12->setMaximumSize( swatchWidth, swatchHeight );
208 mSwatchButton13->setMinimumSize( swatchWidth, swatchHeight );
209 mSwatchButton13->setMaximumSize( swatchWidth, swatchHeight );
210 mSwatchButton14->setMinimumSize( swatchWidth, swatchHeight );
211 mSwatchButton14->setMaximumSize( swatchWidth, swatchHeight );
212 mSwatchButton15->setMinimumSize( swatchWidth, swatchHeight );
213 mSwatchButton15->setMaximumSize( swatchWidth, swatchHeight );
214 mSwatchButton16->setMinimumSize( swatchWidth, swatchHeight );
215 mSwatchButton16->setMaximumSize( swatchWidth, swatchHeight );
216 const int previewHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 2.0 * mSwatchButton1->fontMetrics().height(), 40.0 ) ) );
217 mColorPreview->setMinimumSize( 0, previewHeight );
218 mPreviewWidget->setMaximumHeight( previewHeight * 2 );
219 const int swatchAddSize =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.4 * mSwatchButton1->fontMetrics().height(), 28.0 ) ) );
220 mAddCustomColorButton->setMinimumWidth( swatchAddSize );
221 mAddCustomColorButton->setMaximumWidth( swatchAddSize );
224 mTabWidget->setIconSize( QSize( iconSize, iconSize ) );
226 if ( color.isValid() )
232 int activeRadio = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), 2 ).toInt();
233 switch ( activeRadio )
236 mHueRadio->setChecked(
true );
239 mSaturationRadio->setChecked(
true );
242 mValueRadio->setChecked(
true );
245 mRedRadio->setChecked(
true );
248 mGreenRadio->setChecked(
true );
251 mBlueRadio->setChecked(
true );
254 int currentTab = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeTab" ), 0 ).toInt();
255 mTabWidget->setCurrentIndex( currentTab );
301 return mColorPreview->color();
306 mAllowAlpha = allowOpacity;
307 mAlphaLabel->setVisible( allowOpacity );
308 mAlphaSlider->setVisible( allowOpacity );
311 mAlphaLayout->setContentsMargins( 0, 0, 0, 0 );
312 mAlphaLayout->setSpacing( 0 );
316 void QgsCompoundColorWidget::refreshSchemeComboBox()
318 mSchemeComboBox->blockSignals(
true );
319 mSchemeComboBox->clear();
321 QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
322 for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
324 mSchemeComboBox->addItem( ( *schemeIt )->schemeName() );
326 mSchemeComboBox->blockSignals(
false );
333 QString lastDir = s.
value( QStringLiteral(
"/UI/lastGplPaletteDir" ), QDir::homePath() ).toString();
334 QString filePath = QFileDialog::getOpenFileName( parent, tr(
"Select Palette File" ), lastDir, QStringLiteral(
"GPL (*.gpl);;All files (*.*)" ) );
336 parent->activateWindow();
337 if ( filePath.isEmpty() )
343 QFileInfo fileInfo( filePath );
344 if ( !fileInfo.exists() || !fileInfo.isReadable() )
346 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Error, file does not exist or is not readable." ) );
350 s.
setValue( QStringLiteral(
"/UI/lastGplPaletteDir" ), fileInfo.absolutePath() );
351 QFile file( filePath );
359 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Palette file is not readable." ) );
363 if ( importedColors.length() == 0 )
366 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"No colors found in palette file." ) );
372 importedScheme->
setName( paletteName );
373 importedScheme->
setColors( importedColors );
376 return importedScheme;
379 void QgsCompoundColorWidget::importPalette()
384 refreshSchemeComboBox();
385 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
392 if ( QMessageBox::question( parent, tr(
"Remove Color Palette" ),
393 QString( tr(
"Are you sure you want to remove %1?" ) ).arg( scheme->
schemeName() ),
394 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
401 if ( !scheme->
erase() )
412 void QgsCompoundColorWidget::removePalette()
416 int prevIndex = mSchemeComboBox->currentIndex();
417 if ( prevIndex >= schemeList.length() )
431 refreshSchemeComboBox();
432 prevIndex = std::max( std::min( prevIndex, mSchemeComboBox->count() - 1 ), 0 );
433 mSchemeComboBox->setCurrentIndex( prevIndex );
440 QString name = QInputDialog::getText( parent, tr(
"Create New Palette" ), tr(
"Enter a name for the new palette:" ),
441 QLineEdit::Normal, tr(
"New palette" ), &ok );
443 if ( !ok || name.isEmpty() )
450 QDir palettePath( gplFilePath() );
451 QRegExp badChars(
"[,^@={}\\[\\]~!?:&*\"|#%<>$\"'();`' /\\\\]" );
452 QString filename = name.simplified().toLower().replace( badChars, QStringLiteral(
"_" ) );
453 if ( filename.isEmpty() )
455 filename = tr(
"new_palette" );
457 QFileInfo destFileInfo( palettePath.filePath( filename +
".gpl" ) );
459 while ( destFileInfo.exists() )
462 destFileInfo = QFileInfo( palettePath.filePath( filename + QStringLiteral(
"%1.gpl" ).arg( fileNumber ) ) );
473 void QgsCompoundColorWidget::newPalette()
478 refreshSchemeComboBox();
479 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
483 QString QgsCompoundColorWidget::gplFilePath()
488 if ( !localDir.mkpath( palettesDir ) )
496 void QgsCompoundColorWidget::schemeIndexChanged(
int index )
499 if ( mSchemeList->isDirty() )
501 mSchemeList->saveColorsToScheme();
506 if ( index >= schemeList.length() )
512 mSchemeList->setScheme( scheme );
514 updateActionsForCurrentScheme();
517 mActionCopyColors->setEnabled(
false );
520 void QgsCompoundColorWidget::listSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
522 Q_UNUSED( deselected );
523 mActionCopyColors->setEnabled( selected.length() > 0 );
526 void QgsCompoundColorWidget::mAddCustomColorButton_clicked()
528 switch ( mLastCustomColorIndex )
531 mSwatchButton1->setColor( mColorPreview->color() );
534 mSwatchButton2->setColor( mColorPreview->color() );
537 mSwatchButton3->setColor( mColorPreview->color() );
540 mSwatchButton4->setColor( mColorPreview->color() );
543 mSwatchButton5->setColor( mColorPreview->color() );
546 mSwatchButton6->setColor( mColorPreview->color() );
549 mSwatchButton7->setColor( mColorPreview->color() );
552 mSwatchButton8->setColor( mColorPreview->color() );
555 mSwatchButton9->setColor( mColorPreview->color() );
558 mSwatchButton10->setColor( mColorPreview->color() );
561 mSwatchButton11->setColor( mColorPreview->color() );
564 mSwatchButton12->setColor( mColorPreview->color() );
567 mSwatchButton13->setColor( mColorPreview->color() );
570 mSwatchButton14->setColor( mColorPreview->color() );
573 mSwatchButton15->setColor( mColorPreview->color() );
576 mSwatchButton16->setColor( mColorPreview->color() );
579 mLastCustomColorIndex++;
580 if ( mLastCustomColorIndex >= 16 )
582 mLastCustomColorIndex = 0;
586 void QgsCompoundColorWidget::mSampleButton_clicked()
592 mPickingColor =
true;
593 setMouseTracking(
true );
596 void QgsCompoundColorWidget::mTabWidget_currentChanged(
int index )
599 bool enabled = index == 0;
600 mRedRadio->setEnabled( enabled );
601 mBlueRadio->setEnabled( enabled );
602 mGreenRadio->setEnabled( enabled );
603 mHueRadio->setEnabled( enabled );
604 mSaturationRadio->setEnabled( enabled );
605 mValueRadio->setEnabled( enabled );
608 void QgsCompoundColorWidget::mActionShowInButtons_toggled(
bool state )
617 QScreen *QgsCompoundColorWidget::findScreenAt( QPoint pos )
619 for ( QScreen *screen : QGuiApplication::screens() )
621 if ( screen->geometry().contains( pos ) )
629 void QgsCompoundColorWidget::saveSettings()
632 if ( mSchemeList->isDirty() )
634 mSchemeList->saveColorsToScheme();
641 if ( mHueRadio->isChecked() )
643 if ( mSaturationRadio->isChecked() )
645 if ( mValueRadio->isChecked() )
647 if ( mRedRadio->isChecked() )
649 if ( mGreenRadio->isChecked() )
651 if ( mBlueRadio->isChecked() )
653 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), activeRadio );
656 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), mSchemeComboBox->currentIndex() );
659 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeTab" ), mTabWidget->currentIndex() );
662 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( mSwatchButton1->color() ) );
663 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( mSwatchButton2->color() ) );
664 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( mSwatchButton3->color() ) );
665 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( mSwatchButton4->color() ) );
666 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( mSwatchButton5->color() ) );
667 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( mSwatchButton6->color() ) );
668 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( mSwatchButton7->color() ) );
669 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( mSwatchButton8->color() ) );
670 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( mSwatchButton9->color() ) );
671 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( mSwatchButton10->color() ) );
672 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( mSwatchButton11->color() ) );
673 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( mSwatchButton12->color() ) );
674 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( mSwatchButton13->color() ) );
675 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( mSwatchButton14->color() ) );
676 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( mSwatchButton15->color() ) );
677 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( mSwatchButton16->color() ) );
680 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), mSpinBoxRadius->value() );
683 void QgsCompoundColorWidget::stopPicking( QPoint eventPos,
const bool takeSample )
689 setMouseTracking(
false );
690 mPickingColor =
false;
699 QColor snappedColor = sampleColor( eventPos );
700 mSamplePreview->setColor( snappedColor );
701 mColorPreview->setColor( snappedColor,
true );
706 if ( !color.isValid() )
711 QColor fixedColor = QColor( color );
715 fixedColor.setAlpha( 255 );
717 QList<QgsColorWidget *> colorWidgets = this->findChildren<QgsColorWidget *>();
720 if ( widget == mSamplePreview )
724 widget->blockSignals(
true );
726 widget->blockSignals(
false );
733 mOldColorLabel->setVisible( color.isValid() );
734 mColorPreview->setColor2( color );
746 QWidget::mousePressEvent( e );
749 QColor QgsCompoundColorWidget::averageColor(
const QImage &image )
const 757 for (
int heightIndex = 0; heightIndex < image.height(); ++heightIndex )
759 QRgb *scanLine = ( QRgb * )image.constScanLine( heightIndex );
760 for (
int widthIndex = 0; widthIndex < image.width(); ++widthIndex )
762 tmpRgb = scanLine[widthIndex];
763 sumRed += qRed( tmpRgb );
764 sumBlue += qBlue( tmpRgb );
765 sumGreen += qGreen( tmpRgb );
770 double avgRed =
static_cast<double>( sumRed ) / ( 255.0 * colorCount );
771 double avgGreen =
static_cast<double>( sumGreen ) / ( 255.0 * colorCount );
772 double avgBlue =
static_cast<double>( sumBlue ) / ( 255.0 * colorCount );
775 return QColor::fromRgbF( avgRed, avgGreen, avgBlue );
778 QColor QgsCompoundColorWidget::sampleColor( QPoint point )
const 780 int sampleRadius = mSpinBoxRadius->value() - 1;
781 QScreen *screen = findScreenAt( point );
786 QPixmap snappedPixmap = screen->grabWindow( QApplication::desktop()->winId(),
787 point.x() - sampleRadius,
788 point.y() - sampleRadius,
789 1 + sampleRadius * 2,
790 1 + sampleRadius * 2 );
791 QImage snappedImage = snappedPixmap.toImage();
793 return averageColor( snappedImage );
802 QColor hoverColor = sampleColor( e->globalPos() );
803 mSamplePreview->setColor( hoverColor );
809 QWidget::mouseMoveEvent( e );
817 stopPicking( e->globalPos() );
822 QWidget::mouseReleaseEvent( e );
827 if ( !mPickingColor )
835 stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
838 void QgsCompoundColorWidget::mHueRadio_toggled(
bool checked )
847 void QgsCompoundColorWidget::mSaturationRadio_toggled(
bool checked )
856 void QgsCompoundColorWidget::mValueRadio_toggled(
bool checked )
865 void QgsCompoundColorWidget::mRedRadio_toggled(
bool checked )
874 void QgsCompoundColorWidget::mGreenRadio_toggled(
bool checked )
883 void QgsCompoundColorWidget::mBlueRadio_toggled(
bool checked )
892 void QgsCompoundColorWidget::mAddColorToSchemeButton_clicked()
897 void QgsCompoundColorWidget::updateActionsForCurrentScheme()
901 mActionImportColors->setEnabled( scheme->
isEditable() );
902 mActionPasteColors->setEnabled( scheme->
isEditable() );
903 mAddColorToSchemeButton->setEnabled( scheme->
isEditable() );
904 mRemoveColorsFromSchemeButton->setEnabled( scheme->
isEditable() );
907 mActionRemovePalette->setEnabled( static_cast< bool >( userScheme ) );
910 mActionShowInButtons->setEnabled(
true );
916 mActionShowInButtons->setEnabled(
false );
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
void setName(const QString &name)
Sets the name for the scheme.
void colorSelected(const QColor &color)
Emitted when a color is selected from the list.
bool erase()
Erases the associated gpl palette file from the users "palettes" folder.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
void removeSelection()
Removes any selected colors from the list.
static const double UI_SCALE_FACTOR
UI scaling factor.
This class is a composition of two QSettings instances:
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
Abstract base class for color schemes.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsColorScheme::SchemeFlags flags() const override
Returns the current flags for the color scheme.
void pasteColors()
Pastes colors from clipboard to the list.
Show scheme in color button drop-down menu.
bool removeColorScheme(QgsColorScheme *scheme)
Removes all matching color schemes from the registry.
void showExportColorsDialog()
Displays a file picker dialog allowing users to export colors from the list into a file...
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file.
virtual bool isEditable() const
Returns whether the color scheme is editable.
void setShowSchemeInMenu(bool show)
Sets whether a this scheme should be shown in color button menus.
void showImportColorsDialog()
Displays a file picker dialog allowing users to import colors into the list from a file...
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
void addColorScheme(QgsColorScheme *scheme)
Adds a color scheme to the registry.
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
Show scheme in color picker dialog.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes. ...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QString schemeName() const override
Gets the name for the color scheme.
void copyColors()
Copies colors from the list to the clipboard.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.