21 #include "qgssettings.h"
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->setContentsMargins( 0, 0, 0, 0 );
56 newLayout->addWidget( mTabWidget );
57 newLayout->addWidget( mSlidersWidget );
58 newLayout->addWidget( mPreviewWidget );
59 newLayout->addWidget( mSwatchesWidget );
61 setLayout( newLayout );
66 mSchemeList->header()->hide();
67 mSchemeList->setColumnWidth( 0,
static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6 ) );
70 refreshSchemeComboBox();
74 int activeScheme = settings.value( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), 0 ).toInt();
75 activeScheme = activeScheme >= mSchemeComboBox->count() ? 0 : activeScheme;
77 mSchemeList->setScheme( schemeList.at( activeScheme ) );
79 mSchemeComboBox->setCurrentIndex( activeScheme );
80 updateActionsForCurrentScheme();
83 connect( mSchemeList->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCompoundColorWidget::listSelectionChanged );
85 mActionCopyColors->setEnabled(
false );
91 connect( mActionImportPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::importPalette );
92 connect( mActionRemovePalette, &QAction::triggered,
this, &QgsCompoundColorWidget::removePalette );
93 connect( mActionNewPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::newPalette );
96 QMenu *schemeMenu =
new QMenu( mSchemeToolButton );
97 schemeMenu->addAction( mActionCopyColors );
98 schemeMenu->addAction( mActionPasteColors );
99 schemeMenu->addSeparator();
100 schemeMenu->addAction( mActionImportColors );
101 schemeMenu->addAction( mActionExportColors );
102 schemeMenu->addSeparator();
103 schemeMenu->addAction( mActionNewPalette );
104 schemeMenu->addAction( mActionImportPalette );
105 schemeMenu->addAction( mActionRemovePalette );
106 schemeMenu->addAction( mActionShowInButtons );
107 mSchemeToolButton->setMenu( schemeMenu );
109 connect( mSchemeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsCompoundColorWidget::schemeIndexChanged );
112 mOldColorLabel->hide();
115 mVerticalRamp->setInteriorMargin( 2 );
116 mVerticalRamp->setShowFrame(
true );
126 mSwatchButton1->setShowMenu(
false );
128 mSwatchButton2->setShowMenu(
false );
130 mSwatchButton3->setShowMenu(
false );
132 mSwatchButton4->setShowMenu(
false );
134 mSwatchButton5->setShowMenu(
false );
136 mSwatchButton6->setShowMenu(
false );
138 mSwatchButton7->setShowMenu(
false );
140 mSwatchButton8->setShowMenu(
false );
142 mSwatchButton9->setShowMenu(
false );
144 mSwatchButton10->setShowMenu(
false );
146 mSwatchButton11->setShowMenu(
false );
148 mSwatchButton12->setShowMenu(
false );
150 mSwatchButton13->setShowMenu(
false );
152 mSwatchButton14->setShowMenu(
false );
154 mSwatchButton15->setShowMenu(
false );
156 mSwatchButton16->setShowMenu(
false );
159 mSwatchButton1->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( QColor() ) ).value<QColor>() );
160 mSwatchButton2->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( QColor() ) ).value<QColor>() );
161 mSwatchButton3->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( QColor() ) ).value<QColor>() );
162 mSwatchButton4->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( QColor() ) ).value<QColor>() );
163 mSwatchButton5->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( QColor() ) ).value<QColor>() );
164 mSwatchButton6->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( QColor() ) ).value<QColor>() );
165 mSwatchButton7->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( QColor() ) ).value<QColor>() );
166 mSwatchButton8->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( QColor() ) ).value<QColor>() );
167 mSwatchButton9->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( QColor() ) ).value<QColor>() );
168 mSwatchButton10->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( QColor() ) ).value<QColor>() );
169 mSwatchButton11->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( QColor() ) ).value<QColor>() );
170 mSwatchButton12->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( QColor() ) ).value<QColor>() );
171 mSwatchButton13->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( QColor() ) ).value<QColor>() );
172 mSwatchButton14->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( QColor() ) ).value<QColor>() );
173 mSwatchButton15->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( QColor() ) ).value<QColor>() );
174 mSwatchButton16->setColor( settings.value( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( QColor() ) ).value<QColor>() );
177 mSpinBoxRadius->setValue( settings.value( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), 1 ).toInt() );
178 mSamplePreview->setColor( QColor() );
181 const int swatchWidth =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.9 * mSwatchButton1->fontMetrics().height(), 38.0 ) ) );
182 const int swatchHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.5 * mSwatchButton1->fontMetrics().height(), 30.0 ) ) );
183 mSwatchButton1->setMinimumSize( swatchWidth, swatchHeight );
184 mSwatchButton1->setMaximumSize( swatchWidth, swatchHeight );
185 mSwatchButton2->setMinimumSize( swatchWidth, swatchHeight );
186 mSwatchButton2->setMaximumSize( swatchWidth, swatchHeight );
187 mSwatchButton3->setMinimumSize( swatchWidth, swatchHeight );
188 mSwatchButton3->setMaximumSize( swatchWidth, swatchHeight );
189 mSwatchButton4->setMinimumSize( swatchWidth, swatchHeight );
190 mSwatchButton4->setMaximumSize( swatchWidth, swatchHeight );
191 mSwatchButton5->setMinimumSize( swatchWidth, swatchHeight );
192 mSwatchButton5->setMaximumSize( swatchWidth, swatchHeight );
193 mSwatchButton6->setMinimumSize( swatchWidth, swatchHeight );
194 mSwatchButton6->setMaximumSize( swatchWidth, swatchHeight );
195 mSwatchButton7->setMinimumSize( swatchWidth, swatchHeight );
196 mSwatchButton7->setMaximumSize( swatchWidth, swatchHeight );
197 mSwatchButton8->setMinimumSize( swatchWidth, swatchHeight );
198 mSwatchButton8->setMaximumSize( swatchWidth, swatchHeight );
199 mSwatchButton9->setMinimumSize( swatchWidth, swatchHeight );
200 mSwatchButton9->setMaximumSize( swatchWidth, swatchHeight );
201 mSwatchButton10->setMinimumSize( swatchWidth, swatchHeight );
202 mSwatchButton10->setMaximumSize( swatchWidth, swatchHeight );
203 mSwatchButton11->setMinimumSize( swatchWidth, swatchHeight );
204 mSwatchButton11->setMaximumSize( swatchWidth, swatchHeight );
205 mSwatchButton12->setMinimumSize( swatchWidth, swatchHeight );
206 mSwatchButton12->setMaximumSize( swatchWidth, swatchHeight );
207 mSwatchButton13->setMinimumSize( swatchWidth, swatchHeight );
208 mSwatchButton13->setMaximumSize( swatchWidth, swatchHeight );
209 mSwatchButton14->setMinimumSize( swatchWidth, swatchHeight );
210 mSwatchButton14->setMaximumSize( swatchWidth, swatchHeight );
211 mSwatchButton15->setMinimumSize( swatchWidth, swatchHeight );
212 mSwatchButton15->setMaximumSize( swatchWidth, swatchHeight );
213 mSwatchButton16->setMinimumSize( swatchWidth, swatchHeight );
214 mSwatchButton16->setMaximumSize( swatchWidth, swatchHeight );
215 const int previewHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 2.0 * mSwatchButton1->fontMetrics().height(), 40.0 ) ) );
216 mColorPreview->setMinimumSize( 0, previewHeight );
217 mPreviewWidget->setMaximumHeight( previewHeight * 2 );
218 const int swatchAddSize =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.4 * mSwatchButton1->fontMetrics().height(), 28.0 ) ) );
219 mAddCustomColorButton->setMinimumWidth( swatchAddSize );
220 mAddCustomColorButton->setMaximumWidth( swatchAddSize );
225 if (
color.isValid() )
231 int activeRadio = settings.value( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), 2 ).toInt();
232 switch ( activeRadio )
235 mHueRadio->setChecked(
true );
238 mSaturationRadio->setChecked(
true );
241 mValueRadio->setChecked(
true );
244 mRedRadio->setChecked(
true );
247 mGreenRadio->setChecked(
true );
250 mBlueRadio->setChecked(
true );
253 int currentTab = settings.value( QStringLiteral(
"Windows/ColorDialog/activeTab" ), 0 ).toInt();
254 mTabWidget->setCurrentIndex( currentTab );
299 return mColorPreview->color();
304 mAllowAlpha = allowOpacity;
305 mAlphaLabel->setVisible( allowOpacity );
306 mAlphaSlider->setVisible( allowOpacity );
309 mAlphaLayout->setContentsMargins( 0, 0, 0, 0 );
310 mAlphaLayout->setSpacing( 0 );
314 void QgsCompoundColorWidget::refreshSchemeComboBox()
316 mSchemeComboBox->blockSignals(
true );
317 mSchemeComboBox->clear();
319 QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
320 for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
322 mSchemeComboBox->addItem( ( *schemeIt )->schemeName() );
324 mSchemeComboBox->blockSignals(
false );
331 QString lastDir = s.value( QStringLiteral(
"/UI/lastGplPaletteDir" ), QDir::homePath() ).toString();
332 QString filePath = QFileDialog::getOpenFileName( parent, tr(
"Select Palette File" ), lastDir, QStringLiteral(
"GPL (*.gpl);;All files (*.*)" ) );
334 parent->activateWindow();
335 if ( filePath.isEmpty() )
341 QFileInfo fileInfo( filePath );
342 if ( !fileInfo.exists() || !fileInfo.isReadable() )
344 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Error, file does not exist or is not readable." ) );
348 s.setValue( QStringLiteral(
"/UI/lastGplPaletteDir" ), fileInfo.absolutePath() );
349 QFile file( filePath );
357 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Palette file is not readable." ) );
361 if ( importedColors.length() == 0 )
364 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"No colors found in palette file." ) );
370 importedScheme->
setName( paletteName );
371 importedScheme->
setColors( importedColors );
374 return importedScheme;
377 void QgsCompoundColorWidget::importPalette()
382 refreshSchemeComboBox();
383 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
390 if ( QMessageBox::question( parent, tr(
"Remove Color Palette" ),
391 tr(
"Are you sure you want to remove %1?" ).arg( scheme->
schemeName() ),
392 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
399 if ( !scheme->
erase() )
410 void QgsCompoundColorWidget::removePalette()
414 int prevIndex = mSchemeComboBox->currentIndex();
415 if ( prevIndex >= schemeList.length() )
429 refreshSchemeComboBox();
430 prevIndex = std::max( std::min( prevIndex, mSchemeComboBox->count() - 1 ), 0 );
431 mSchemeComboBox->setCurrentIndex( prevIndex );
438 QString name = QInputDialog::getText( parent, tr(
"Create New Palette" ), tr(
"Enter a name for the new palette:" ),
439 QLineEdit::Normal, tr(
"New palette" ), &ok );
441 if ( !ok || name.isEmpty() )
448 QDir palettePath( gplFilePath() );
449 QRegExp badChars(
"[,^@={}\\[\\]~!?:&*\"|#%<>$\"'();`' /\\\\]" );
450 QString filename = name.simplified().toLower().replace( badChars, QStringLiteral(
"_" ) );
451 if ( filename.isEmpty() )
453 filename = tr(
"new_palette" );
455 QFileInfo destFileInfo( palettePath.filePath( filename +
".gpl" ) );
457 while ( destFileInfo.exists() )
460 destFileInfo = QFileInfo( palettePath.filePath( filename + QStringLiteral(
"%1.gpl" ).arg( fileNumber ) ) );
471 void QgsCompoundColorWidget::newPalette()
476 refreshSchemeComboBox();
477 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
481 QString QgsCompoundColorWidget::gplFilePath()
486 if ( !localDir.mkpath( palettesDir ) )
494 void QgsCompoundColorWidget::schemeIndexChanged(
int index )
497 if ( mSchemeList->isDirty() )
499 mSchemeList->saveColorsToScheme();
504 if ( index >= schemeList.length() )
510 mSchemeList->setScheme( scheme );
512 updateActionsForCurrentScheme();
515 mActionCopyColors->setEnabled(
false );
518 void QgsCompoundColorWidget::listSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
520 Q_UNUSED( deselected )
521 mActionCopyColors->setEnabled( selected.length() > 0 );
524 void QgsCompoundColorWidget::mAddCustomColorButton_clicked()
526 switch ( mLastCustomColorIndex )
529 mSwatchButton1->setColor( mColorPreview->color() );
532 mSwatchButton2->setColor( mColorPreview->color() );
535 mSwatchButton3->setColor( mColorPreview->color() );
538 mSwatchButton4->setColor( mColorPreview->color() );
541 mSwatchButton5->setColor( mColorPreview->color() );
544 mSwatchButton6->setColor( mColorPreview->color() );
547 mSwatchButton7->setColor( mColorPreview->color() );
550 mSwatchButton8->setColor( mColorPreview->color() );
553 mSwatchButton9->setColor( mColorPreview->color() );
556 mSwatchButton10->setColor( mColorPreview->color() );
559 mSwatchButton11->setColor( mColorPreview->color() );
562 mSwatchButton12->setColor( mColorPreview->color() );
565 mSwatchButton13->setColor( mColorPreview->color() );
568 mSwatchButton14->setColor( mColorPreview->color() );
571 mSwatchButton15->setColor( mColorPreview->color() );
574 mSwatchButton16->setColor( mColorPreview->color() );
577 mLastCustomColorIndex++;
578 if ( mLastCustomColorIndex >= 16 )
580 mLastCustomColorIndex = 0;
584 void QgsCompoundColorWidget::mSampleButton_clicked()
590 mPickingColor =
true;
591 setMouseTracking(
true );
594 void QgsCompoundColorWidget::mTabWidget_currentChanged(
int index )
597 bool enabled = index == 0;
598 mRedRadio->setEnabled( enabled );
599 mBlueRadio->setEnabled( enabled );
600 mGreenRadio->setEnabled( enabled );
601 mHueRadio->setEnabled( enabled );
602 mSaturationRadio->setEnabled( enabled );
603 mValueRadio->setEnabled( enabled );
606 void QgsCompoundColorWidget::mActionShowInButtons_toggled(
bool state )
615 QScreen *QgsCompoundColorWidget::findScreenAt( QPoint pos )
617 const QList< QScreen * > screens = QGuiApplication::screens();
618 for ( QScreen *screen : screens )
620 if ( screen->geometry().contains( pos ) )
628 void QgsCompoundColorWidget::saveSettings()
631 if ( mSchemeList->isDirty() )
633 mSchemeList->saveColorsToScheme();
636 QgsSettings settings;
640 if ( mHueRadio->isChecked() )
642 if ( mSaturationRadio->isChecked() )
644 if ( mValueRadio->isChecked() )
646 if ( mRedRadio->isChecked() )
648 if ( mGreenRadio->isChecked() )
650 if ( mBlueRadio->isChecked() )
652 settings.setValue( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), activeRadio );
655 settings.setValue( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), mSchemeComboBox->currentIndex() );
658 settings.setValue( QStringLiteral(
"Windows/ColorDialog/activeTab" ), mTabWidget->currentIndex() );
661 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( mSwatchButton1->color() ) );
662 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( mSwatchButton2->color() ) );
663 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( mSwatchButton3->color() ) );
664 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( mSwatchButton4->color() ) );
665 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( mSwatchButton5->color() ) );
666 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( mSwatchButton6->color() ) );
667 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( mSwatchButton7->color() ) );
668 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( mSwatchButton8->color() ) );
669 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( mSwatchButton9->color() ) );
670 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( mSwatchButton10->color() ) );
671 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( mSwatchButton11->color() ) );
672 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( mSwatchButton12->color() ) );
673 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( mSwatchButton13->color() ) );
674 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( mSwatchButton14->color() ) );
675 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( mSwatchButton15->color() ) );
676 settings.setValue( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( mSwatchButton16->color() ) );
679 settings.setValue( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), mSpinBoxRadius->value() );
682 void QgsCompoundColorWidget::stopPicking( QPoint eventPos,
const bool takeSample )
688 setMouseTracking(
false );
689 mPickingColor =
false;
698 QColor snappedColor = sampleColor( eventPos );
699 mSamplePreview->setColor( snappedColor );
700 mColorPreview->setColor( snappedColor,
true );
705 if ( !
color.isValid() )
710 QColor fixedColor = QColor(
color );
714 fixedColor.setAlpha( 255 );
716 QList<QgsColorWidget *> colorWidgets = this->findChildren<QgsColorWidget *>();
717 const auto constColorWidgets = colorWidgets;
720 if ( widget == mSamplePreview )
724 widget->blockSignals(
true );
725 widget->setColor( fixedColor );
726 widget->blockSignals(
false );
733 mOldColorLabel->setVisible(
color.isValid() );
734 mColorPreview->setColor2(
color );
740 QWidget::hideEvent( e );
752 QWidget::mousePressEvent( e );
755 QColor QgsCompoundColorWidget::averageColor(
const QImage &image )
const
763 for (
int heightIndex = 0; heightIndex < image.height(); ++heightIndex )
765 const QRgb *scanLine =
reinterpret_cast< const QRgb *
>( image.constScanLine( heightIndex ) );
766 for (
int widthIndex = 0; widthIndex < image.width(); ++widthIndex )
768 tmpRgb = scanLine[widthIndex];
769 sumRed += qRed( tmpRgb );
770 sumBlue += qBlue( tmpRgb );
771 sumGreen += qGreen( tmpRgb );
776 double avgRed =
static_cast<double>( sumRed ) / ( 255.0 * colorCount );
777 double avgGreen =
static_cast<double>( sumGreen ) / ( 255.0 * colorCount );
778 double avgBlue =
static_cast<double>( sumBlue ) / ( 255.0 * colorCount );
781 return QColor::fromRgbF( avgRed, avgGreen, avgBlue );
784 QColor QgsCompoundColorWidget::sampleColor( QPoint point )
const
786 int sampleRadius = mSpinBoxRadius->value() - 1;
787 QScreen *screen = findScreenAt( point );
792 QPixmap snappedPixmap = screen->grabWindow( QApplication::desktop()->winId(),
793 point.x() - sampleRadius,
794 point.y() - sampleRadius,
795 1 + sampleRadius * 2,
796 1 + sampleRadius * 2 );
797 QImage snappedImage = snappedPixmap.toImage();
799 return averageColor( snappedImage );
808 QColor hoverColor = sampleColor( e->globalPos() );
809 mSamplePreview->setColor( hoverColor );
815 QWidget::mouseMoveEvent( e );
823 stopPicking( e->globalPos() );
828 QWidget::mouseReleaseEvent( e );
833 if ( !mPickingColor )
841 stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
844 void QgsCompoundColorWidget::mHueRadio_toggled(
bool checked )
853 void QgsCompoundColorWidget::mSaturationRadio_toggled(
bool checked )
862 void QgsCompoundColorWidget::mValueRadio_toggled(
bool checked )
871 void QgsCompoundColorWidget::mRedRadio_toggled(
bool checked )
880 void QgsCompoundColorWidget::mGreenRadio_toggled(
bool checked )
889 void QgsCompoundColorWidget::mBlueRadio_toggled(
bool checked )
898 void QgsCompoundColorWidget::mAddColorToSchemeButton_clicked()
903 void QgsCompoundColorWidget::updateActionsForCurrentScheme()
907 mActionImportColors->setEnabled( scheme->
isEditable() );
908 mActionPasteColors->setEnabled( scheme->
isEditable() );
909 mAddColorToSchemeButton->setEnabled( scheme->
isEditable() );
910 mRemoveColorsFromSchemeButton->setEnabled( scheme->
isEditable() );
913 mActionRemovePalette->setEnabled(
static_cast< bool >( userScheme ) );
916 mActionShowInButtons->setEnabled(
true );
922 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.
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.