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();
68 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) 69 mSchemeList->setColumnWidth( 0, static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().width(
'X' ) * 6 ) );
71 mSchemeList->setColumnWidth( 0, static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6 ) );
76 refreshSchemeComboBox();
80 int activeScheme = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), 0 ).toInt();
81 activeScheme = activeScheme >= mSchemeComboBox->count() ? 0 : activeScheme;
83 mSchemeList->setScheme( schemeList.at( activeScheme ) );
85 mSchemeComboBox->setCurrentIndex( activeScheme );
86 updateActionsForCurrentScheme();
89 connect( mSchemeList->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCompoundColorWidget::listSelectionChanged );
91 mActionCopyColors->setEnabled(
false );
97 connect( mActionImportPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::importPalette );
98 connect( mActionRemovePalette, &QAction::triggered,
this, &QgsCompoundColorWidget::removePalette );
99 connect( mActionNewPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::newPalette );
102 QMenu *schemeMenu =
new QMenu( mSchemeToolButton );
103 schemeMenu->addAction( mActionCopyColors );
104 schemeMenu->addAction( mActionPasteColors );
105 schemeMenu->addSeparator();
106 schemeMenu->addAction( mActionImportColors );
107 schemeMenu->addAction( mActionExportColors );
108 schemeMenu->addSeparator();
109 schemeMenu->addAction( mActionNewPalette );
110 schemeMenu->addAction( mActionImportPalette );
111 schemeMenu->addAction( mActionRemovePalette );
112 schemeMenu->addAction( mActionShowInButtons );
113 mSchemeToolButton->setMenu( schemeMenu );
115 connect( mSchemeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsCompoundColorWidget::schemeIndexChanged );
118 mOldColorLabel->hide();
121 mVerticalRamp->setInteriorMargin( 2 );
122 mVerticalRamp->setShowFrame(
true );
132 mSwatchButton1->setShowMenu(
false );
134 mSwatchButton2->setShowMenu(
false );
136 mSwatchButton3->setShowMenu(
false );
138 mSwatchButton4->setShowMenu(
false );
140 mSwatchButton5->setShowMenu(
false );
142 mSwatchButton6->setShowMenu(
false );
144 mSwatchButton7->setShowMenu(
false );
146 mSwatchButton8->setShowMenu(
false );
148 mSwatchButton9->setShowMenu(
false );
150 mSwatchButton10->setShowMenu(
false );
152 mSwatchButton11->setShowMenu(
false );
154 mSwatchButton12->setShowMenu(
false );
156 mSwatchButton13->setShowMenu(
false );
158 mSwatchButton14->setShowMenu(
false );
160 mSwatchButton15->setShowMenu(
false );
162 mSwatchButton16->setShowMenu(
false );
165 mSwatchButton1->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( QColor() ) ).value<QColor>() );
166 mSwatchButton2->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( QColor() ) ).value<QColor>() );
167 mSwatchButton3->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( QColor() ) ).value<QColor>() );
168 mSwatchButton4->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( QColor() ) ).value<QColor>() );
169 mSwatchButton5->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( QColor() ) ).value<QColor>() );
170 mSwatchButton6->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( QColor() ) ).value<QColor>() );
171 mSwatchButton7->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( QColor() ) ).value<QColor>() );
172 mSwatchButton8->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( QColor() ) ).value<QColor>() );
173 mSwatchButton9->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( QColor() ) ).value<QColor>() );
174 mSwatchButton10->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( QColor() ) ).value<QColor>() );
175 mSwatchButton11->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( QColor() ) ).value<QColor>() );
176 mSwatchButton12->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( QColor() ) ).value<QColor>() );
177 mSwatchButton13->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( QColor() ) ).value<QColor>() );
178 mSwatchButton14->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( QColor() ) ).value<QColor>() );
179 mSwatchButton15->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( QColor() ) ).value<QColor>() );
180 mSwatchButton16->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( QColor() ) ).value<QColor>() );
183 mSpinBoxRadius->setValue( settings.
value( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), 1 ).toInt() );
184 mSamplePreview->setColor( QColor() );
187 const int swatchWidth =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.9 * mSwatchButton1->fontMetrics().height(), 38.0 ) ) );
188 const int swatchHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.5 * mSwatchButton1->fontMetrics().height(), 30.0 ) ) );
189 mSwatchButton1->setMinimumSize( swatchWidth, swatchHeight );
190 mSwatchButton1->setMaximumSize( swatchWidth, swatchHeight );
191 mSwatchButton2->setMinimumSize( swatchWidth, swatchHeight );
192 mSwatchButton2->setMaximumSize( swatchWidth, swatchHeight );
193 mSwatchButton3->setMinimumSize( swatchWidth, swatchHeight );
194 mSwatchButton3->setMaximumSize( swatchWidth, swatchHeight );
195 mSwatchButton4->setMinimumSize( swatchWidth, swatchHeight );
196 mSwatchButton4->setMaximumSize( swatchWidth, swatchHeight );
197 mSwatchButton5->setMinimumSize( swatchWidth, swatchHeight );
198 mSwatchButton5->setMaximumSize( swatchWidth, swatchHeight );
199 mSwatchButton6->setMinimumSize( swatchWidth, swatchHeight );
200 mSwatchButton6->setMaximumSize( swatchWidth, swatchHeight );
201 mSwatchButton7->setMinimumSize( swatchWidth, swatchHeight );
202 mSwatchButton7->setMaximumSize( swatchWidth, swatchHeight );
203 mSwatchButton8->setMinimumSize( swatchWidth, swatchHeight );
204 mSwatchButton8->setMaximumSize( swatchWidth, swatchHeight );
205 mSwatchButton9->setMinimumSize( swatchWidth, swatchHeight );
206 mSwatchButton9->setMaximumSize( swatchWidth, swatchHeight );
207 mSwatchButton10->setMinimumSize( swatchWidth, swatchHeight );
208 mSwatchButton10->setMaximumSize( swatchWidth, swatchHeight );
209 mSwatchButton11->setMinimumSize( swatchWidth, swatchHeight );
210 mSwatchButton11->setMaximumSize( swatchWidth, swatchHeight );
211 mSwatchButton12->setMinimumSize( swatchWidth, swatchHeight );
212 mSwatchButton12->setMaximumSize( swatchWidth, swatchHeight );
213 mSwatchButton13->setMinimumSize( swatchWidth, swatchHeight );
214 mSwatchButton13->setMaximumSize( swatchWidth, swatchHeight );
215 mSwatchButton14->setMinimumSize( swatchWidth, swatchHeight );
216 mSwatchButton14->setMaximumSize( swatchWidth, swatchHeight );
217 mSwatchButton15->setMinimumSize( swatchWidth, swatchHeight );
218 mSwatchButton15->setMaximumSize( swatchWidth, swatchHeight );
219 mSwatchButton16->setMinimumSize( swatchWidth, swatchHeight );
220 mSwatchButton16->setMaximumSize( swatchWidth, swatchHeight );
221 const int previewHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 2.0 * mSwatchButton1->fontMetrics().height(), 40.0 ) ) );
222 mColorPreview->setMinimumSize( 0, previewHeight );
223 mPreviewWidget->setMaximumHeight( previewHeight * 2 );
224 const int swatchAddSize =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.4 * mSwatchButton1->fontMetrics().height(), 28.0 ) ) );
225 mAddCustomColorButton->setMinimumWidth( swatchAddSize );
226 mAddCustomColorButton->setMaximumWidth( swatchAddSize );
229 mTabWidget->setIconSize( QSize( iconSize, iconSize ) );
231 if ( color.isValid() )
237 int activeRadio = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), 2 ).toInt();
238 switch ( activeRadio )
241 mHueRadio->setChecked(
true );
244 mSaturationRadio->setChecked(
true );
247 mValueRadio->setChecked(
true );
250 mRedRadio->setChecked(
true );
253 mGreenRadio->setChecked(
true );
256 mBlueRadio->setChecked(
true );
259 int currentTab = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeTab" ), 0 ).toInt();
260 mTabWidget->setCurrentIndex( currentTab );
306 return mColorPreview->color();
311 mAllowAlpha = allowOpacity;
312 mAlphaLabel->setVisible( allowOpacity );
313 mAlphaSlider->setVisible( allowOpacity );
316 mAlphaLayout->setContentsMargins( 0, 0, 0, 0 );
317 mAlphaLayout->setSpacing( 0 );
321 void QgsCompoundColorWidget::refreshSchemeComboBox()
323 mSchemeComboBox->blockSignals(
true );
324 mSchemeComboBox->clear();
326 QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
327 for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
329 mSchemeComboBox->addItem( ( *schemeIt )->schemeName() );
331 mSchemeComboBox->blockSignals(
false );
338 QString lastDir = s.
value( QStringLiteral(
"/UI/lastGplPaletteDir" ), QDir::homePath() ).toString();
339 QString filePath = QFileDialog::getOpenFileName( parent, tr(
"Select Palette File" ), lastDir, QStringLiteral(
"GPL (*.gpl);;All files (*.*)" ) );
341 parent->activateWindow();
342 if ( filePath.isEmpty() )
348 QFileInfo fileInfo( filePath );
349 if ( !fileInfo.exists() || !fileInfo.isReadable() )
351 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Error, file does not exist or is not readable." ) );
355 s.
setValue( QStringLiteral(
"/UI/lastGplPaletteDir" ), fileInfo.absolutePath() );
356 QFile file( filePath );
364 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"Palette file is not readable." ) );
368 if ( importedColors.length() == 0 )
371 QMessageBox::critical(
nullptr, tr(
"Import Color Palette" ), tr(
"No colors found in palette file." ) );
377 importedScheme->
setName( paletteName );
378 importedScheme->
setColors( importedColors );
381 return importedScheme;
384 void QgsCompoundColorWidget::importPalette()
389 refreshSchemeComboBox();
390 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
397 if ( QMessageBox::question( parent, tr(
"Remove Color Palette" ),
398 QString( tr(
"Are you sure you want to remove %1?" ) ).arg( scheme->
schemeName() ),
399 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
406 if ( !scheme->
erase() )
417 void QgsCompoundColorWidget::removePalette()
421 int prevIndex = mSchemeComboBox->currentIndex();
422 if ( prevIndex >= schemeList.length() )
436 refreshSchemeComboBox();
437 prevIndex = std::max( std::min( prevIndex, mSchemeComboBox->count() - 1 ), 0 );
438 mSchemeComboBox->setCurrentIndex( prevIndex );
445 QString name = QInputDialog::getText( parent, tr(
"Create New Palette" ), tr(
"Enter a name for the new palette:" ),
446 QLineEdit::Normal, tr(
"New palette" ), &ok );
448 if ( !ok || name.isEmpty() )
455 QDir palettePath( gplFilePath() );
456 QRegExp badChars(
"[,^@={}\\[\\]~!?:&*\"|#%<>$\"'();`' /\\\\]" );
457 QString filename = name.simplified().toLower().replace( badChars, QStringLiteral(
"_" ) );
458 if ( filename.isEmpty() )
460 filename = tr(
"new_palette" );
462 QFileInfo destFileInfo( palettePath.filePath( filename +
".gpl" ) );
464 while ( destFileInfo.exists() )
467 destFileInfo = QFileInfo( palettePath.filePath( filename + QStringLiteral(
"%1.gpl" ).arg( fileNumber ) ) );
478 void QgsCompoundColorWidget::newPalette()
483 refreshSchemeComboBox();
484 mSchemeComboBox->setCurrentIndex( mSchemeComboBox->count() - 1 );
488 QString QgsCompoundColorWidget::gplFilePath()
493 if ( !localDir.mkpath( palettesDir ) )
501 void QgsCompoundColorWidget::schemeIndexChanged(
int index )
504 if ( mSchemeList->isDirty() )
506 mSchemeList->saveColorsToScheme();
511 if ( index >= schemeList.length() )
517 mSchemeList->setScheme( scheme );
519 updateActionsForCurrentScheme();
522 mActionCopyColors->setEnabled(
false );
525 void QgsCompoundColorWidget::listSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
527 Q_UNUSED( deselected )
528 mActionCopyColors->setEnabled( selected.length() > 0 );
531 void QgsCompoundColorWidget::mAddCustomColorButton_clicked()
533 switch ( mLastCustomColorIndex )
536 mSwatchButton1->setColor( mColorPreview->color() );
539 mSwatchButton2->setColor( mColorPreview->color() );
542 mSwatchButton3->setColor( mColorPreview->color() );
545 mSwatchButton4->setColor( mColorPreview->color() );
548 mSwatchButton5->setColor( mColorPreview->color() );
551 mSwatchButton6->setColor( mColorPreview->color() );
554 mSwatchButton7->setColor( mColorPreview->color() );
557 mSwatchButton8->setColor( mColorPreview->color() );
560 mSwatchButton9->setColor( mColorPreview->color() );
563 mSwatchButton10->setColor( mColorPreview->color() );
566 mSwatchButton11->setColor( mColorPreview->color() );
569 mSwatchButton12->setColor( mColorPreview->color() );
572 mSwatchButton13->setColor( mColorPreview->color() );
575 mSwatchButton14->setColor( mColorPreview->color() );
578 mSwatchButton15->setColor( mColorPreview->color() );
581 mSwatchButton16->setColor( mColorPreview->color() );
584 mLastCustomColorIndex++;
585 if ( mLastCustomColorIndex >= 16 )
587 mLastCustomColorIndex = 0;
591 void QgsCompoundColorWidget::mSampleButton_clicked()
597 mPickingColor =
true;
598 setMouseTracking(
true );
601 void QgsCompoundColorWidget::mTabWidget_currentChanged(
int index )
604 bool enabled = index == 0;
605 mRedRadio->setEnabled( enabled );
606 mBlueRadio->setEnabled( enabled );
607 mGreenRadio->setEnabled( enabled );
608 mHueRadio->setEnabled( enabled );
609 mSaturationRadio->setEnabled( enabled );
610 mValueRadio->setEnabled( enabled );
613 void QgsCompoundColorWidget::mActionShowInButtons_toggled(
bool state )
622 QScreen *QgsCompoundColorWidget::findScreenAt( QPoint pos )
624 const QList< QScreen * > screens = QGuiApplication::screens();
625 for ( QScreen *screen : screens )
627 if ( screen->geometry().contains( pos ) )
635 void QgsCompoundColorWidget::saveSettings()
638 if ( mSchemeList->isDirty() )
640 mSchemeList->saveColorsToScheme();
647 if ( mHueRadio->isChecked() )
649 if ( mSaturationRadio->isChecked() )
651 if ( mValueRadio->isChecked() )
653 if ( mRedRadio->isChecked() )
655 if ( mGreenRadio->isChecked() )
657 if ( mBlueRadio->isChecked() )
659 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), activeRadio );
662 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), mSchemeComboBox->currentIndex() );
665 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/activeTab" ), mTabWidget->currentIndex() );
668 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( mSwatchButton1->color() ) );
669 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( mSwatchButton2->color() ) );
670 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( mSwatchButton3->color() ) );
671 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( mSwatchButton4->color() ) );
672 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( mSwatchButton5->color() ) );
673 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( mSwatchButton6->color() ) );
674 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( mSwatchButton7->color() ) );
675 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( mSwatchButton8->color() ) );
676 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( mSwatchButton9->color() ) );
677 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( mSwatchButton10->color() ) );
678 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( mSwatchButton11->color() ) );
679 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( mSwatchButton12->color() ) );
680 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( mSwatchButton13->color() ) );
681 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( mSwatchButton14->color() ) );
682 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( mSwatchButton15->color() ) );
683 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( mSwatchButton16->color() ) );
686 settings.
setValue( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), mSpinBoxRadius->value() );
689 void QgsCompoundColorWidget::stopPicking( QPoint eventPos,
const bool takeSample )
695 setMouseTracking(
false );
696 mPickingColor =
false;
705 QColor snappedColor = sampleColor( eventPos );
706 mSamplePreview->setColor( snappedColor );
707 mColorPreview->setColor( snappedColor,
true );
712 if ( !color.isValid() )
717 QColor fixedColor = QColor( color );
721 fixedColor.setAlpha( 255 );
723 QList<QgsColorWidget *> colorWidgets = this->findChildren<QgsColorWidget *>();
724 const auto constColorWidgets = colorWidgets;
727 if ( widget == mSamplePreview )
731 widget->blockSignals(
true );
732 widget->setColor( fixedColor );
733 widget->blockSignals(
false );
740 mOldColorLabel->setVisible( color.isValid() );
741 mColorPreview->setColor2( color );
753 QWidget::mousePressEvent( e );
756 QColor QgsCompoundColorWidget::averageColor(
const QImage &image )
const 764 for (
int heightIndex = 0; heightIndex < image.height(); ++heightIndex )
766 const QRgb *scanLine =
reinterpret_cast< const QRgb *
>( image.constScanLine( heightIndex ) );
767 for (
int widthIndex = 0; widthIndex < image.width(); ++widthIndex )
769 tmpRgb = scanLine[widthIndex];
770 sumRed += qRed( tmpRgb );
771 sumBlue += qBlue( tmpRgb );
772 sumGreen += qGreen( tmpRgb );
777 double avgRed =
static_cast<double>( sumRed ) / ( 255.0 * colorCount );
778 double avgGreen =
static_cast<double>( sumGreen ) / ( 255.0 * colorCount );
779 double avgBlue =
static_cast<double>( sumBlue ) / ( 255.0 * colorCount );
782 return QColor::fromRgbF( avgRed, avgGreen, avgBlue );
785 QColor QgsCompoundColorWidget::sampleColor( QPoint point )
const 787 int sampleRadius = mSpinBoxRadius->value() - 1;
788 QScreen *screen = findScreenAt( point );
793 QPixmap snappedPixmap = screen->grabWindow( QApplication::desktop()->winId(),
794 point.x() - sampleRadius,
795 point.y() - sampleRadius,
796 1 + sampleRadius * 2,
797 1 + sampleRadius * 2 );
798 QImage snappedImage = snappedPixmap.toImage();
800 return averageColor( snappedImage );
809 QColor hoverColor = sampleColor( e->globalPos() );
810 mSamplePreview->setColor( hoverColor );
816 QWidget::mouseMoveEvent( e );
824 stopPicking( e->globalPos() );
829 QWidget::mouseReleaseEvent( e );
834 if ( !mPickingColor )
842 stopPicking( QCursor::pos(), e->key() == Qt::Key_Space );
845 void QgsCompoundColorWidget::mHueRadio_toggled(
bool checked )
854 void QgsCompoundColorWidget::mSaturationRadio_toggled(
bool checked )
863 void QgsCompoundColorWidget::mValueRadio_toggled(
bool checked )
872 void QgsCompoundColorWidget::mRedRadio_toggled(
bool checked )
881 void QgsCompoundColorWidget::mGreenRadio_toggled(
bool checked )
890 void QgsCompoundColorWidget::mBlueRadio_toggled(
bool checked )
899 void QgsCompoundColorWidget::mAddColorToSchemeButton_clicked()
904 void QgsCompoundColorWidget::updateActionsForCurrentScheme()
908 mActionImportColors->setEnabled( scheme->
isEditable() );
909 mActionPasteColors->setEnabled( scheme->
isEditable() );
910 mAddColorToSchemeButton->setEnabled( scheme->
isEditable() );
911 mRemoveColorsFromSchemeButton->setEnabled( scheme->
isEditable() );
914 mActionRemovePalette->setEnabled( static_cast< bool >( userScheme ) );
917 mActionShowInButtons->setEnabled(
true );
923 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:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.
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.
QList< QgsColorScheme * > schemes() const
Returns all color schemes in 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.
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.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
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.
virtual bool isEditable() const
Returns whether the color scheme is editable.
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.