33#include <QInputDialog>
35#include <QRegularExpression>
44 connect( mHueRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mHueRadio_toggled );
45 connect( mSaturationRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mSaturationRadio_toggled );
46 connect( mValueRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mValueRadio_toggled );
47 connect( mRedRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mRedRadio_toggled );
48 connect( mGreenRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mGreenRadio_toggled );
49 connect( mBlueRadio, &QRadioButton::toggled,
this, &QgsCompoundColorWidget::mBlueRadio_toggled );
50 connect( mAddColorToSchemeButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddColorToSchemeButton_clicked );
51 connect( mAddCustomColorButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddCustomColorButton_clicked );
52 connect( mSampleButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mSampleButton_clicked );
53 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsCompoundColorWidget::mTabWidget_currentChanged );
54 connect( mActionShowInButtons, &QAction::toggled,
this, &QgsCompoundColorWidget::mActionShowInButtons_toggled );
59 QVBoxLayout *newLayout =
new QVBoxLayout();
60 newLayout->setContentsMargins( 0, 0, 0, 0 );
61 newLayout->addWidget( mTabWidget );
62 newLayout->addWidget( mSlidersWidget );
63 newLayout->addWidget( mPreviewWidget );
64 newLayout->addWidget( mSwatchesWidget );
66 setLayout( newLayout );
71 mSchemeList->header()->hide();
72 mSchemeList->setColumnWidth( 0,
static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6 ) );
75 refreshSchemeComboBox();
79 int activeScheme = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), 0 ).toInt();
80 activeScheme = activeScheme >= mSchemeComboBox->count() ? 0 : activeScheme;
82 mSchemeList->setScheme( schemeList.at( activeScheme ) );
84 mSchemeComboBox->setCurrentIndex( activeScheme );
85 updateActionsForCurrentScheme();
88 connect( mSchemeList->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCompoundColorWidget::listSelectionChanged );
90 mActionCopyColors->setEnabled(
false );
96 connect( mActionImportPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::importPalette );
97 connect( mActionRemovePalette, &QAction::triggered,
this, &QgsCompoundColorWidget::removePalette );
98 connect( mActionNewPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::newPalette );
101 QMenu *schemeMenu =
new QMenu( mSchemeToolButton );
102 schemeMenu->addAction( mActionCopyColors );
103 schemeMenu->addAction( mActionPasteColors );
104 schemeMenu->addSeparator();
105 schemeMenu->addAction( mActionImportColors );
106 schemeMenu->addAction( mActionExportColors );
107 schemeMenu->addSeparator();
108 schemeMenu->addAction( mActionNewPalette );
109 schemeMenu->addAction( mActionImportPalette );
110 schemeMenu->addAction( mActionRemovePalette );
111 schemeMenu->addAction( mActionShowInButtons );
112 mSchemeToolButton->setMenu( schemeMenu );
114 connect( mSchemeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsCompoundColorWidget::schemeIndexChanged );
117 mOldColorLabel->hide();
120 mVerticalRamp->setInteriorMargin( 2 );
121 mVerticalRamp->setShowFrame(
true );
131 mSwatchButton1->setShowMenu(
false );
133 mSwatchButton2->setShowMenu(
false );
135 mSwatchButton3->setShowMenu(
false );
137 mSwatchButton4->setShowMenu(
false );
139 mSwatchButton5->setShowMenu(
false );
141 mSwatchButton6->setShowMenu(
false );
143 mSwatchButton7->setShowMenu(
false );
145 mSwatchButton8->setShowMenu(
false );
147 mSwatchButton9->setShowMenu(
false );
149 mSwatchButton10->setShowMenu(
false );
151 mSwatchButton11->setShowMenu(
false );
153 mSwatchButton12->setShowMenu(
false );
155 mSwatchButton13->setShowMenu(
false );
157 mSwatchButton14->setShowMenu(
false );
159 mSwatchButton15->setShowMenu(
false );
161 mSwatchButton16->setShowMenu(
false );
164 mSwatchButton1->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( QColor() ) ).value<QColor>() );
165 mSwatchButton2->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( QColor() ) ).value<QColor>() );
166 mSwatchButton3->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( QColor() ) ).value<QColor>() );
167 mSwatchButton4->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( QColor() ) ).value<QColor>() );
168 mSwatchButton5->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( QColor() ) ).value<QColor>() );
169 mSwatchButton6->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( QColor() ) ).value<QColor>() );
170 mSwatchButton7->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( QColor() ) ).value<QColor>() );
171 mSwatchButton8->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( QColor() ) ).value<QColor>() );
172 mSwatchButton9->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( QColor() ) ).value<QColor>() );
173 mSwatchButton10->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( QColor() ) ).value<QColor>() );
174 mSwatchButton11->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( QColor() ) ).value<QColor>() );
175 mSwatchButton12->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( QColor() ) ).value<QColor>() );
176 mSwatchButton13->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( QColor() ) ).value<QColor>() );
177 mSwatchButton14->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( QColor() ) ).value<QColor>() );
178 mSwatchButton15->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( QColor() ) ).value<QColor>() );
179 mSwatchButton16->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( QColor() ) ).value<QColor>() );
182 mSpinBoxRadius->setValue( settings.
value( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), 1 ).toInt() );
183 mSamplePreview->setColor( QColor() );
186 const int swatchWidth =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.9 * mSwatchButton1->fontMetrics().height(), 38.0 ) ) );
187 const int swatchHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.5 * mSwatchButton1->fontMetrics().height(), 30.0 ) ) );
188 mSwatchButton1->setMinimumSize( swatchWidth, swatchHeight );
189 mSwatchButton1->setMaximumSize( swatchWidth, swatchHeight );
190 mSwatchButton2->setMinimumSize( swatchWidth, swatchHeight );
191 mSwatchButton2->setMaximumSize( swatchWidth, swatchHeight );
192 mSwatchButton3->setMinimumSize( swatchWidth, swatchHeight );
193 mSwatchButton3->setMaximumSize( swatchWidth, swatchHeight );
194 mSwatchButton4->setMinimumSize( swatchWidth, swatchHeight );
195 mSwatchButton4->setMaximumSize( swatchWidth, swatchHeight );
196 mSwatchButton5->setMinimumSize( swatchWidth, swatchHeight );
197 mSwatchButton5->setMaximumSize( swatchWidth, swatchHeight );
198 mSwatchButton6->setMinimumSize( swatchWidth, swatchHeight );
199 mSwatchButton6->setMaximumSize( swatchWidth, swatchHeight );
200 mSwatchButton7->setMinimumSize( swatchWidth, swatchHeight );
201 mSwatchButton7->setMaximumSize( swatchWidth, swatchHeight );
202 mSwatchButton8->setMinimumSize( swatchWidth, swatchHeight );
203 mSwatchButton8->setMaximumSize( swatchWidth, swatchHeight );
204 mSwatchButton9->setMinimumSize( swatchWidth, swatchHeight );
205 mSwatchButton9->setMaximumSize( swatchWidth, swatchHeight );
206 mSwatchButton10->setMinimumSize( swatchWidth, swatchHeight );
207 mSwatchButton10->setMaximumSize( swatchWidth, swatchHeight );
208 mSwatchButton11->setMinimumSize( swatchWidth, swatchHeight );
209 mSwatchButton11->setMaximumSize( swatchWidth, swatchHeight );
210 mSwatchButton12->setMinimumSize( swatchWidth, swatchHeight );
211 mSwatchButton12->setMaximumSize( swatchWidth, swatchHeight );
212 mSwatchButton13->setMinimumSize( swatchWidth, swatchHeight );
213 mSwatchButton13->setMaximumSize( swatchWidth, swatchHeight );
214 mSwatchButton14->setMinimumSize( swatchWidth, swatchHeight );
215 mSwatchButton14->setMaximumSize( swatchWidth, swatchHeight );
216 mSwatchButton15->setMinimumSize( swatchWidth, swatchHeight );
217 mSwatchButton15->setMaximumSize( swatchWidth, swatchHeight );
218 mSwatchButton16->setMinimumSize( swatchWidth, swatchHeight );
219 mSwatchButton16->setMaximumSize( swatchWidth, swatchHeight );
220 const int previewHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 2.0 * mSwatchButton1->fontMetrics().height(), 40.0 ) ) );
221 mColorPreview->setMinimumSize( 0, previewHeight );
222 mPreviewWidget->setMaximumHeight( previewHeight * 2 );
223 const int swatchAddSize =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.4 * mSwatchButton1->fontMetrics().height(), 28.0 ) ) );
224 mAddCustomColorButton->setMinimumWidth( swatchAddSize );
225 mAddCustomColorButton->setMaximumWidth( swatchAddSize );
230 if (
color.isValid() )
236 const int activeRadio = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), 2 ).toInt();
237 switch ( activeRadio )
240 mHueRadio->setChecked(
true );
243 mSaturationRadio->setChecked(
true );
246 mValueRadio->setChecked(
true );
249 mRedRadio->setChecked(
true );
252 mGreenRadio->setChecked(
true );
255 mBlueRadio->setChecked(
true );
258 const int currentTab = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeTab" ), 0 ).toInt();
259 mTabWidget->setCurrentIndex( currentTab );
304 return mColorPreview->color();
309 mAllowAlpha = allowOpacity;
310 mAlphaLabel->setVisible( allowOpacity );
311 mAlphaSlider->setVisible( allowOpacity );
312 mColorText->setAllowOpacity( allowOpacity );
315 mAlphaLayout->setContentsMargins( 0, 0, 0, 0 );
316 mAlphaLayout->setSpacing( 0 );
320void QgsCompoundColorWidget::refreshSchemeComboBox()
322 mSchemeComboBox->blockSignals(
true );
323 mSchemeComboBox->clear();
325 QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
326 for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
328 mSchemeComboBox->addItem( ( *schemeIt )->schemeName() );
330 mSchemeComboBox->blockSignals(
false );
337 const QString lastDir = s.
value( QStringLiteral(
"/UI/lastGplPaletteDir" ), QDir::homePath() ).toString();
338 const QString filePath = QFileDialog::getOpenFileName( parent, tr(
"Select Palette File" ), lastDir, QStringLiteral(
"GPL (*.gpl);;All files (*.*)" ) );
340 parent->activateWindow();
341 if ( filePath.isEmpty() )
347 const QFileInfo fileInfo( filePath );
348 if ( !fileInfo.exists() || !fileInfo.isReadable() )
350 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Error, file does not exist or is not readable." ) );
354 s.
setValue( QStringLiteral(
"/UI/lastGplPaletteDir" ), fileInfo.absolutePath() );
355 QFile file( filePath );
363 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Palette file is not readable." ) );
367 if ( importedColors.length() == 0 )
370 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"No colors found in palette file." ) );
376 importedScheme->
setName( paletteName );
377 importedScheme->
setColors( importedColors );
380 return importedScheme;
383void QgsCompoundColorWidget::importPalette()
388 refreshSchemeComboBox();
389 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
396 if ( QMessageBox::question( parent, tr(
"Remove Color Palette" ),
397 tr(
"Are you sure you want to remove %1?" ).arg( scheme->
schemeName() ),
398 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
405 if ( !scheme->
erase() )
416void QgsCompoundColorWidget::removePalette()
420 int prevIndex = mSchemeComboBox->currentIndex();
421 if ( prevIndex >= schemeList.length() )
435 refreshSchemeComboBox();
436 prevIndex = std::max( std::min( prevIndex, mSchemeComboBox->count() - 1 ), 0 );
437 mSchemeComboBox->setCurrentIndex( prevIndex );
444 const QString name = QInputDialog::getText( parent, tr(
"Create New Palette" ), tr(
"Enter a name for the new palette:" ),
445 QLineEdit::Normal, tr(
"New palette" ), &ok );
447 if ( !ok || name.isEmpty() )
454 const QDir palettePath( gplFilePath() );
455 const thread_local QRegularExpression badChars(
"[,^@={}\\[\\]~!?:&*\"|#%<>$\"'();`' /\\\\]" );
456 QString filename = name.simplified().toLower().replace( badChars, QStringLiteral(
"_" ) );
457 if ( filename.isEmpty() )
459 filename = tr(
"new_palette" );
461 QFileInfo destFileInfo( palettePath.filePath( filename +
".gpl" ) );
463 while ( destFileInfo.exists() )
466 destFileInfo = QFileInfo( palettePath.filePath( filename + QStringLiteral(
"%1.gpl" ).arg( fileNumber ) ) );
477void QgsCompoundColorWidget::newPalette()
482 refreshSchemeComboBox();
483 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
487QString QgsCompoundColorWidget::gplFilePath()
492 if ( !localDir.mkpath( palettesDir ) )
500void QgsCompoundColorWidget::schemeIndexChanged(
int index )
503 if ( mSchemeList->isDirty() )
505 mSchemeList->saveColorsToScheme();
510 if ( index >= schemeList.length() )
516 mSchemeList->setScheme( scheme );
518 updateActionsForCurrentScheme();
521 mActionCopyColors->setEnabled(
false );
524void QgsCompoundColorWidget::listSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
526 Q_UNUSED( deselected )
527 mActionCopyColors->setEnabled( selected.length() > 0 );
530void QgsCompoundColorWidget::mAddCustomColorButton_clicked()
532 switch ( mLastCustomColorIndex )
535 mSwatchButton1->setColor( mColorPreview->color() );
538 mSwatchButton2->setColor( mColorPreview->color() );
541 mSwatchButton3->setColor( mColorPreview->color() );
544 mSwatchButton4->setColor( mColorPreview->color() );
547 mSwatchButton5->setColor( mColorPreview->color() );
550 mSwatchButton6->setColor( mColorPreview->color() );
553 mSwatchButton7->setColor( mColorPreview->color() );
556 mSwatchButton8->setColor( mColorPreview->color() );
559 mSwatchButton9->setColor( mColorPreview->color() );
562 mSwatchButton10->setColor( mColorPreview->color() );
565 mSwatchButton11->setColor( mColorPreview->color() );
568 mSwatchButton12->setColor( mColorPreview->color() );
571 mSwatchButton13->setColor( mColorPreview->color() );
574 mSwatchButton14->setColor( mColorPreview->color() );
577 mSwatchButton15->setColor( mColorPreview->color() );
580 mSwatchButton16->setColor( mColorPreview->color() );
583 mLastCustomColorIndex++;
584 if ( mLastCustomColorIndex >= 16 )
586 mLastCustomColorIndex = 0;
590void QgsCompoundColorWidget::mSampleButton_clicked()
596 mPickingColor =
true;
597 setMouseTracking(
true );
600void QgsCompoundColorWidget::mTabWidget_currentChanged(
int index )
603 const bool enabled = index == 0;
604 mRedRadio->setEnabled( enabled );
605 mBlueRadio->setEnabled( enabled );
606 mGreenRadio->setEnabled( enabled );
607 mHueRadio->setEnabled( enabled );
608 mSaturationRadio->setEnabled( enabled );
609 mValueRadio->setEnabled( enabled );
612void QgsCompoundColorWidget::mActionShowInButtons_toggled(
bool state )
621QScreen *QgsCompoundColorWidget::findScreenAt( QPoint pos )
623 const QList< QScreen * > screens = QGuiApplication::screens();
624 for ( QScreen *screen : screens )
626 if ( screen->geometry().contains( pos ) )
634void QgsCompoundColorWidget::saveSettings()
637 if ( mSchemeList->isDirty() )
639 mSchemeList->saveColorsToScheme();
646 if ( mHueRadio->isChecked() )
648 if ( mSaturationRadio->isChecked() )
650 if ( mValueRadio->isChecked() )
652 if ( mRedRadio->isChecked() )
654 if ( mGreenRadio->isChecked() )
656 if ( mBlueRadio->isChecked() )
658 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), activeRadio );
661 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), mSchemeComboBox->currentIndex() );
664 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeTab" ), mTabWidget->currentIndex() );
667 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( mSwatchButton1->color() ) );
668 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( mSwatchButton2->color() ) );
669 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( mSwatchButton3->color() ) );
670 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( mSwatchButton4->color() ) );
671 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( mSwatchButton5->color() ) );
672 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( mSwatchButton6->color() ) );
673 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( mSwatchButton7->color() ) );
674 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( mSwatchButton8->color() ) );
675 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( mSwatchButton9->color() ) );
676 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( mSwatchButton10->color() ) );
677 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( mSwatchButton11->color() ) );
678 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( mSwatchButton12->color() ) );
679 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( mSwatchButton13->color() ) );
680 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( mSwatchButton14->color() ) );
681 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( mSwatchButton15->color() ) );
682 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( mSwatchButton16->color() ) );
685 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), mSpinBoxRadius->value() );
688void QgsCompoundColorWidget::stopPicking( QPoint eventPos,
const bool takeSample )
694 setMouseTracking(
false );
695 mPickingColor =
false;
704 const QColor snappedColor = sampleColor( eventPos );
705 mSamplePreview->setColor( snappedColor );
706 mColorPreview->setColor( snappedColor,
true );
711 if ( !
color.isValid() )
716 QColor fixedColor = QColor(
color );
720 fixedColor.setAlpha( 255 );
722 const QList<QgsColorWidget *> colorWidgets = this->findChildren<QgsColorWidget *>();
723 const auto constColorWidgets = colorWidgets;
726 if ( widget == mSamplePreview )
730 widget->blockSignals(
true );
731 widget->setColor( fixedColor );
732 widget->blockSignals(
false );
739 mOldColorLabel->setVisible(
color.isValid() );
740 mColorPreview->setColor2(
color );
746 QWidget::hideEvent( e );
758 QWidget::mousePressEvent( e );
761QColor QgsCompoundColorWidget::averageColor(
const QImage &image )
const
769 for (
int heightIndex = 0; heightIndex < image.height(); ++heightIndex )
771 const QRgb *scanLine =
reinterpret_cast< const QRgb *
>( image.constScanLine( heightIndex ) );
772 for (
int widthIndex = 0; widthIndex < image.width(); ++widthIndex )
774 tmpRgb = scanLine[widthIndex];
775 sumRed += qRed( tmpRgb );
776 sumBlue += qBlue( tmpRgb );
777 sumGreen += qGreen( tmpRgb );
782 const double avgRed =
static_cast<double>( sumRed ) / ( 255.0 * colorCount );
783 const double avgGreen =
static_cast<double>( sumGreen ) / ( 255.0 * colorCount );
784 const double avgBlue =
static_cast<double>( sumBlue ) / ( 255.0 * colorCount );
787 return QColor::fromRgbF( avgRed, avgGreen, avgBlue );
790QColor QgsCompoundColorWidget::sampleColor( QPoint point )
const
792 const int sampleRadius = mSpinBoxRadius->value() - 1;
793 QScreen *screen = findScreenAt( point );
799 const int x = point.x() - screen->geometry().left();
800 const int y = point.y() - screen->geometry().top();
801 const QPixmap snappedPixmap = screen->grabWindow( 0,
804 1 + sampleRadius * 2,
805 1 + sampleRadius * 2 );
806 const QImage snappedImage = snappedPixmap.toImage();
808 return averageColor( snappedImage );
817 const QColor hoverColor = sampleColor( e->globalPos() );
818 mSamplePreview->setColor( hoverColor );
824 QWidget::mouseMoveEvent( e );
832 stopPicking( e->globalPos() );
837 QWidget::mouseReleaseEvent( e );
842 if ( !mPickingColor )
850 stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
853void QgsCompoundColorWidget::mHueRadio_toggled(
bool checked )
862void QgsCompoundColorWidget::mSaturationRadio_toggled(
bool checked )
871void QgsCompoundColorWidget::mValueRadio_toggled(
bool checked )
880void QgsCompoundColorWidget::mRedRadio_toggled(
bool checked )
889void QgsCompoundColorWidget::mGreenRadio_toggled(
bool checked )
898void QgsCompoundColorWidget::mBlueRadio_toggled(
bool checked )
907void QgsCompoundColorWidget::mAddColorToSchemeButton_clicked()
912void QgsCompoundColorWidget::updateActionsForCurrentScheme()
916 mActionImportColors->setEnabled( scheme->
isEditable() );
917 mActionPasteColors->setEnabled( scheme->
isEditable() );
918 mAddColorToSchemeButton->setEnabled( scheme->
isEditable() );
919 mRemoveColorsFromSchemeButton->setEnabled( scheme->
isEditable() );
922 mActionRemovePalette->setEnabled(
static_cast< bool >( userScheme ) );
925 mActionShowInButtons->setEnabled(
true );
931 mActionShowInButtons->setEnabled(
false );
static const double UI_SCALE_FACTOR
UI scaling factor.
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
void pasteColors()
Pastes colors from clipboard to the list.
void removeSelection()
Removes any selected colors from the list.
void copyColors()
Copies colors from the list to the clipboard.
void showExportColorsDialog()
Displays a file picker dialog allowing users to export colors from the list into a file.
void colorSelected(const QColor &color)
Emitted when a color is selected from the list.
void showImportColorsDialog()
Displays a file picker dialog allowing users to import colors into the list from a file.
void addColorScheme(QgsColorScheme *scheme)
Adds a color scheme to the registry.
QList< QgsColorScheme * > schemes() const
Returns all color schemes in the registry.
bool removeColorScheme(QgsColorScheme *scheme)
Removes all matching color schemes from the registry.
Abstract base class for color schemes.
@ ShowInColorButtonMenu
Show scheme in color button drop-down menu.
@ ShowInColorDialog
Show scheme in color picker dialog.
virtual bool isEditable() const
Returns whether the color scheme is editable.
bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor()) override
Sets the colors for the scheme.
static void addRecentColor(const QColor &color)
Adds a color to the list of recent colors.
A utility class for dynamic handling of changes to screen properties.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file.
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
A color scheme which stores its colors in a gpl palette file within the "palettes" subfolder off the ...
QString schemeName() const override
Gets the name for the color scheme.
void setName(const QString &name)
Sets the name for the scheme.
QgsColorScheme::SchemeFlags flags() const override
Returns the current flags for the color scheme.
bool erase()
Erases the associated gpl palette file from the users "palettes" folder.
void setShowSchemeInMenu(bool show)
Sets whether a this scheme should be shown in color button menus.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.