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 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
68 mSchemeList->setColumnWidth( 0,
static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().width(
'X' ) * 6 ) );
70 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 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 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 );
314 mAlphaLayout->setContentsMargins( 0, 0, 0, 0 );
315 mAlphaLayout->setSpacing( 0 );
319 void QgsCompoundColorWidget::refreshSchemeComboBox()
321 mSchemeComboBox->blockSignals(
true );
322 mSchemeComboBox->clear();
324 QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
325 for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
327 mSchemeComboBox->addItem( ( *schemeIt )->schemeName() );
329 mSchemeComboBox->blockSignals(
false );
336 QString lastDir = s.
value( QStringLiteral(
"/UI/lastGplPaletteDir" ), QDir::homePath() ).toString();
337 QString filePath = QFileDialog::getOpenFileName( parent, tr(
"Select Palette File" ), lastDir, QStringLiteral(
"GPL (*.gpl);;All files (*.*)" ) );
339 parent->activateWindow();
340 if ( filePath.isEmpty() )
346 QFileInfo fileInfo( filePath );
347 if ( !fileInfo.exists() || !fileInfo.isReadable() )
349 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Error, file does not exist or is not readable." ) );
353 s.
setValue( QStringLiteral(
"/UI/lastGplPaletteDir" ), fileInfo.absolutePath() );
354 QFile file( filePath );
362 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Palette file is not readable." ) );
366 if ( importedColors.length() == 0 )
369 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"No colors found in palette file." ) );
375 importedScheme->
setName( paletteName );
376 importedScheme->
setColors( importedColors );
379 return importedScheme;
382 void QgsCompoundColorWidget::importPalette()
387 refreshSchemeComboBox();
388 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
395 if ( QMessageBox::question( parent, tr(
"Remove Color Palette" ),
396 tr(
"Are you sure you want to remove %1?" ).arg( scheme->
schemeName() ),
397 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
404 if ( !scheme->
erase() )
415 void QgsCompoundColorWidget::removePalette()
419 int prevIndex = mSchemeComboBox->currentIndex();
420 if ( prevIndex >= schemeList.length() )
434 refreshSchemeComboBox();
435 prevIndex = std::max( std::min( prevIndex, mSchemeComboBox->count() - 1 ), 0 );
436 mSchemeComboBox->setCurrentIndex( prevIndex );
443 QString name = QInputDialog::getText( parent, tr(
"Create New Palette" ), tr(
"Enter a name for the new palette:" ),
444 QLineEdit::Normal, tr(
"New palette" ), &ok );
446 if ( !ok || name.isEmpty() )
453 QDir palettePath( gplFilePath() );
454 QRegExp badChars(
"[,^@={}\\[\\]~!?:&*\"|#%<>$\"'();`' /\\\\]" );
455 QString filename = name.simplified().toLower().replace( badChars, QStringLiteral(
"_" ) );
456 if ( filename.isEmpty() )
458 filename = tr(
"new_palette" );
460 QFileInfo destFileInfo( palettePath.filePath( filename +
".gpl" ) );
462 while ( destFileInfo.exists() )
465 destFileInfo = QFileInfo( palettePath.filePath( filename + QStringLiteral(
"%1.gpl" ).arg( fileNumber ) ) );
476 void QgsCompoundColorWidget::newPalette()
481 refreshSchemeComboBox();
482 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
486 QString QgsCompoundColorWidget::gplFilePath()
491 if ( !localDir.mkpath( palettesDir ) )
499 void QgsCompoundColorWidget::schemeIndexChanged(
int index )
502 if ( mSchemeList->isDirty() )
504 mSchemeList->saveColorsToScheme();
509 if ( index >= schemeList.length() )
515 mSchemeList->setScheme( scheme );
517 updateActionsForCurrentScheme();
520 mActionCopyColors->setEnabled(
false );
523 void QgsCompoundColorWidget::listSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
525 Q_UNUSED( deselected )
526 mActionCopyColors->setEnabled( selected.length() > 0 );
529 void QgsCompoundColorWidget::mAddCustomColorButton_clicked()
531 switch ( mLastCustomColorIndex )
534 mSwatchButton1->setColor( mColorPreview->color() );
537 mSwatchButton2->setColor( mColorPreview->color() );
540 mSwatchButton3->setColor( mColorPreview->color() );
543 mSwatchButton4->setColor( mColorPreview->color() );
546 mSwatchButton5->setColor( mColorPreview->color() );
549 mSwatchButton6->setColor( mColorPreview->color() );
552 mSwatchButton7->setColor( mColorPreview->color() );
555 mSwatchButton8->setColor( mColorPreview->color() );
558 mSwatchButton9->setColor( mColorPreview->color() );
561 mSwatchButton10->setColor( mColorPreview->color() );
564 mSwatchButton11->setColor( mColorPreview->color() );
567 mSwatchButton12->setColor( mColorPreview->color() );
570 mSwatchButton13->setColor( mColorPreview->color() );
573 mSwatchButton14->setColor( mColorPreview->color() );
576 mSwatchButton15->setColor( mColorPreview->color() );
579 mSwatchButton16->setColor( mColorPreview->color() );
582 mLastCustomColorIndex++;
583 if ( mLastCustomColorIndex >= 16 )
585 mLastCustomColorIndex = 0;
589 void QgsCompoundColorWidget::mSampleButton_clicked()
595 mPickingColor =
true;
596 setMouseTracking(
true );
599 void QgsCompoundColorWidget::mTabWidget_currentChanged(
int index )
602 bool enabled = index == 0;
603 mRedRadio->setEnabled( enabled );
604 mBlueRadio->setEnabled( enabled );
605 mGreenRadio->setEnabled( enabled );
606 mHueRadio->setEnabled( enabled );
607 mSaturationRadio->setEnabled( enabled );
608 mValueRadio->setEnabled( enabled );
611 void QgsCompoundColorWidget::mActionShowInButtons_toggled(
bool state )
620 QScreen *QgsCompoundColorWidget::findScreenAt( QPoint pos )
622 const QList< QScreen * > screens = QGuiApplication::screens();
623 for ( QScreen *screen : screens )
625 if ( screen->geometry().contains( pos ) )
633 void QgsCompoundColorWidget::saveSettings()
636 if ( mSchemeList->isDirty() )
638 mSchemeList->saveColorsToScheme();
645 if ( mHueRadio->isChecked() )
647 if ( mSaturationRadio->isChecked() )
649 if ( mValueRadio->isChecked() )
651 if ( mRedRadio->isChecked() )
653 if ( mGreenRadio->isChecked() )
655 if ( mBlueRadio->isChecked() )
657 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), activeRadio );
660 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), mSchemeComboBox->currentIndex() );
663 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeTab" ), mTabWidget->currentIndex() );
666 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( mSwatchButton1->color() ) );
667 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( mSwatchButton2->color() ) );
668 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( mSwatchButton3->color() ) );
669 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( mSwatchButton4->color() ) );
670 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( mSwatchButton5->color() ) );
671 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( mSwatchButton6->color() ) );
672 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( mSwatchButton7->color() ) );
673 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( mSwatchButton8->color() ) );
674 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( mSwatchButton9->color() ) );
675 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( mSwatchButton10->color() ) );
676 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( mSwatchButton11->color() ) );
677 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( mSwatchButton12->color() ) );
678 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( mSwatchButton13->color() ) );
679 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( mSwatchButton14->color() ) );
680 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( mSwatchButton15->color() ) );
681 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( mSwatchButton16->color() ) );
684 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), mSpinBoxRadius->value() );
687 void QgsCompoundColorWidget::stopPicking( QPoint eventPos,
const bool takeSample )
693 setMouseTracking(
false );
694 mPickingColor =
false;
703 QColor snappedColor = sampleColor( eventPos );
704 mSamplePreview->setColor( snappedColor );
705 mColorPreview->setColor( snappedColor,
true );
710 if ( !
color.isValid() )
715 QColor fixedColor = QColor(
color );
719 fixedColor.setAlpha( 255 );
721 QList<QgsColorWidget *> colorWidgets = this->findChildren<QgsColorWidget *>();
722 const auto constColorWidgets = colorWidgets;
725 if ( widget == mSamplePreview )
729 widget->blockSignals(
true );
730 widget->setColor( fixedColor );
731 widget->blockSignals(
false );
738 mOldColorLabel->setVisible(
color.isValid() );
739 mColorPreview->setColor2(
color );
745 QWidget::hideEvent( e );
757 QWidget::mousePressEvent( e );
760 QColor QgsCompoundColorWidget::averageColor(
const QImage &image )
const
768 for (
int heightIndex = 0; heightIndex < image.height(); ++heightIndex )
770 const QRgb *scanLine =
reinterpret_cast< const QRgb *
>( image.constScanLine( heightIndex ) );
771 for (
int widthIndex = 0; widthIndex < image.width(); ++widthIndex )
773 tmpRgb = scanLine[widthIndex];
774 sumRed += qRed( tmpRgb );
775 sumBlue += qBlue( tmpRgb );
776 sumGreen += qGreen( tmpRgb );
781 double avgRed =
static_cast<double>( sumRed ) / ( 255.0 * colorCount );
782 double avgGreen =
static_cast<double>( sumGreen ) / ( 255.0 * colorCount );
783 double avgBlue =
static_cast<double>( sumBlue ) / ( 255.0 * colorCount );
786 return QColor::fromRgbF( avgRed, avgGreen, avgBlue );
789 QColor QgsCompoundColorWidget::sampleColor( QPoint point )
const
791 int sampleRadius = mSpinBoxRadius->value() - 1;
792 QScreen *screen = findScreenAt( point );
797 QPixmap snappedPixmap = screen->grabWindow( QApplication::desktop()->winId(),
798 point.x() - sampleRadius,
799 point.y() - sampleRadius,
800 1 + sampleRadius * 2,
801 1 + sampleRadius * 2 );
802 QImage snappedImage = snappedPixmap.toImage();
804 return averageColor( snappedImage );
813 QColor hoverColor = sampleColor( e->globalPos() );
814 mSamplePreview->setColor( hoverColor );
820 QWidget::mouseMoveEvent( e );
828 stopPicking( e->globalPos() );
833 QWidget::mouseReleaseEvent( e );
838 if ( !mPickingColor )
846 stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
849 void QgsCompoundColorWidget::mHueRadio_toggled(
bool checked )
858 void QgsCompoundColorWidget::mSaturationRadio_toggled(
bool checked )
867 void QgsCompoundColorWidget::mValueRadio_toggled(
bool checked )
876 void QgsCompoundColorWidget::mRedRadio_toggled(
bool checked )
885 void QgsCompoundColorWidget::mGreenRadio_toggled(
bool checked )
894 void QgsCompoundColorWidget::mBlueRadio_toggled(
bool checked )
903 void QgsCompoundColorWidget::mAddColorToSchemeButton_clicked()
908 void QgsCompoundColorWidget::updateActionsForCurrentScheme()
912 mActionImportColors->setEnabled( scheme->
isEditable() );
913 mActionPasteColors->setEnabled( scheme->
isEditable() );
914 mAddColorToSchemeButton->setEnabled( scheme->
isEditable() );
915 mRemoveColorsFromSchemeButton->setEnabled( scheme->
isEditable() );
918 mActionRemovePalette->setEnabled(
static_cast< bool >( userScheme ) );
921 mActionShowInButtons->setEnabled(
true );
927 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.
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.