64 mRgbGroup =
new QButtonGroup(
this );
66 for (
auto colorRadio : mRgbRadios )
67 mRgbGroup->addButton( colorRadio.first, i++ );
69 mCmykGroup =
new QButtonGroup(
this );
71 for (
auto colorRadio : mCmykRadios )
72 mCmykGroup->addButton( colorRadio.first, i++ );
74 connect( mRgbGroup, &QButtonGroup::idToggled,
this, &QgsCompoundColorWidget::onColorButtonGroupToggled );
75 connect( mCmykGroup, &QButtonGroup::idToggled,
this, &QgsCompoundColorWidget::onColorButtonGroupToggled );
76 connect( mAddColorToSchemeButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddColorToSchemeButton_clicked );
77 connect( mAddCustomColorButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddCustomColorButton_clicked );
78 connect( mSampleButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mSampleButton_clicked );
79 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsCompoundColorWidget::mTabWidget_currentChanged );
80 connect( mActionShowInButtons, &QAction::toggled,
this, &QgsCompoundColorWidget::mActionShowInButtons_toggled );
82 mColorModel->addItem( tr(
"RGB" ), QColor::Spec::Rgb );
83 mColorModel->addItem( tr(
"CMYK" ), QColor::Spec::Cmyk );
84 connect( mColorModel,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this](
int )
86 const QColor::Spec spec =
static_cast< QColor::Spec
>( mColorModel->currentData().toInt() );
87 if ( spec == QColor::Spec::Cmyk )
98 QVBoxLayout *newLayout =
new QVBoxLayout();
99 newLayout->setContentsMargins( 0, 0, 0, 0 );
100 newLayout->addWidget( mTabWidget );
101 newLayout->addWidget( mSlidersWidget );
102 newLayout->addWidget( mPreviewWidget );
103 newLayout->addWidget( mSwatchesWidget );
105 setLayout( newLayout );
110 mSchemeList->header()->hide();
111 mSchemeList->setColumnWidth( 0,
static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6 ) );
114 refreshSchemeComboBox();
118 int activeScheme = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), 0 ).toInt();
119 activeScheme = activeScheme >= mSchemeComboBox->count() ? 0 : activeScheme;
121 mSchemeList->setScheme( schemeList.at( activeScheme ) );
123 mSchemeComboBox->setCurrentIndex( activeScheme );
124 updateActionsForCurrentScheme();
127 connect( mSchemeList->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCompoundColorWidget::listSelectionChanged );
129 mActionCopyColors->setEnabled(
false );
135 connect( mActionImportPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::importPalette );
136 connect( mActionRemovePalette, &QAction::triggered,
this, &QgsCompoundColorWidget::removePalette );
137 connect( mActionNewPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::newPalette );
140 QMenu *schemeMenu =
new QMenu( mSchemeToolButton );
141 schemeMenu->addAction( mActionCopyColors );
142 schemeMenu->addAction( mActionPasteColors );
143 schemeMenu->addSeparator();
144 schemeMenu->addAction( mActionImportColors );
145 schemeMenu->addAction( mActionExportColors );
146 schemeMenu->addSeparator();
147 schemeMenu->addAction( mActionNewPalette );
148 schemeMenu->addAction( mActionImportPalette );
149 schemeMenu->addAction( mActionRemovePalette );
150 schemeMenu->addAction( mActionShowInButtons );
151 mSchemeToolButton->setMenu( schemeMenu );
153 connect( mSchemeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsCompoundColorWidget::schemeIndexChanged );
156 mOldColorLabel->hide();
159 mVerticalRamp->setInteriorMargin( 2 );
160 mVerticalRamp->setShowFrame(
true );
174 mSwatchButton1->setShowMenu(
false );
176 mSwatchButton2->setShowMenu(
false );
178 mSwatchButton3->setShowMenu(
false );
180 mSwatchButton4->setShowMenu(
false );
182 mSwatchButton5->setShowMenu(
false );
184 mSwatchButton6->setShowMenu(
false );
186 mSwatchButton7->setShowMenu(
false );
188 mSwatchButton8->setShowMenu(
false );
190 mSwatchButton9->setShowMenu(
false );
192 mSwatchButton10->setShowMenu(
false );
194 mSwatchButton11->setShowMenu(
false );
196 mSwatchButton12->setShowMenu(
false );
198 mSwatchButton13->setShowMenu(
false );
200 mSwatchButton14->setShowMenu(
false );
202 mSwatchButton15->setShowMenu(
false );
204 mSwatchButton16->setShowMenu(
false );
207 mSwatchButton1->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( QColor() ) ).value<QColor>() );
208 mSwatchButton2->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( QColor() ) ).value<QColor>() );
209 mSwatchButton3->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( QColor() ) ).value<QColor>() );
210 mSwatchButton4->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( QColor() ) ).value<QColor>() );
211 mSwatchButton5->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( QColor() ) ).value<QColor>() );
212 mSwatchButton6->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( QColor() ) ).value<QColor>() );
213 mSwatchButton7->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( QColor() ) ).value<QColor>() );
214 mSwatchButton8->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( QColor() ) ).value<QColor>() );
215 mSwatchButton9->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( QColor() ) ).value<QColor>() );
216 mSwatchButton10->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( QColor() ) ).value<QColor>() );
217 mSwatchButton11->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( QColor() ) ).value<QColor>() );
218 mSwatchButton12->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( QColor() ) ).value<QColor>() );
219 mSwatchButton13->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( QColor() ) ).value<QColor>() );
220 mSwatchButton14->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( QColor() ) ).value<QColor>() );
221 mSwatchButton15->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( QColor() ) ).value<QColor>() );
222 mSwatchButton16->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( QColor() ) ).value<QColor>() );
225 mSpinBoxRadius->setValue( settings.
value( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), 1 ).toInt() );
226 mSamplePreview->setColor( QColor() );
229 const int swatchWidth =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.9 * mSwatchButton1->fontMetrics().height(), 38.0 ) ) );
230 const int swatchHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.5 * mSwatchButton1->fontMetrics().height(), 30.0 ) ) );
231 mSwatchButton1->setMinimumSize( swatchWidth, swatchHeight );
232 mSwatchButton1->setMaximumSize( swatchWidth, swatchHeight );
233 mSwatchButton2->setMinimumSize( swatchWidth, swatchHeight );
234 mSwatchButton2->setMaximumSize( swatchWidth, swatchHeight );
235 mSwatchButton3->setMinimumSize( swatchWidth, swatchHeight );
236 mSwatchButton3->setMaximumSize( swatchWidth, swatchHeight );
237 mSwatchButton4->setMinimumSize( swatchWidth, swatchHeight );
238 mSwatchButton4->setMaximumSize( swatchWidth, swatchHeight );
239 mSwatchButton5->setMinimumSize( swatchWidth, swatchHeight );
240 mSwatchButton5->setMaximumSize( swatchWidth, swatchHeight );
241 mSwatchButton6->setMinimumSize( swatchWidth, swatchHeight );
242 mSwatchButton6->setMaximumSize( swatchWidth, swatchHeight );
243 mSwatchButton7->setMinimumSize( swatchWidth, swatchHeight );
244 mSwatchButton7->setMaximumSize( swatchWidth, swatchHeight );
245 mSwatchButton8->setMinimumSize( swatchWidth, swatchHeight );
246 mSwatchButton8->setMaximumSize( swatchWidth, swatchHeight );
247 mSwatchButton9->setMinimumSize( swatchWidth, swatchHeight );
248 mSwatchButton9->setMaximumSize( swatchWidth, swatchHeight );
249 mSwatchButton10->setMinimumSize( swatchWidth, swatchHeight );
250 mSwatchButton10->setMaximumSize( swatchWidth, swatchHeight );
251 mSwatchButton11->setMinimumSize( swatchWidth, swatchHeight );
252 mSwatchButton11->setMaximumSize( swatchWidth, swatchHeight );
253 mSwatchButton12->setMinimumSize( swatchWidth, swatchHeight );
254 mSwatchButton12->setMaximumSize( swatchWidth, swatchHeight );
255 mSwatchButton13->setMinimumSize( swatchWidth, swatchHeight );
256 mSwatchButton13->setMaximumSize( swatchWidth, swatchHeight );
257 mSwatchButton14->setMinimumSize( swatchWidth, swatchHeight );
258 mSwatchButton14->setMaximumSize( swatchWidth, swatchHeight );
259 mSwatchButton15->setMinimumSize( swatchWidth, swatchHeight );
260 mSwatchButton15->setMaximumSize( swatchWidth, swatchHeight );
261 mSwatchButton16->setMinimumSize( swatchWidth, swatchHeight );
262 mSwatchButton16->setMaximumSize( swatchWidth, swatchHeight );
263 const int previewHeight =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 2.0 * mSwatchButton1->fontMetrics().height(), 40.0 ) ) );
264 mColorPreview->setMinimumSize( 0, previewHeight );
265 mPreviewWidget->setMaximumHeight( previewHeight * 2 );
266 const int swatchAddSize =
static_cast< int >( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.4 * mSwatchButton1->fontMetrics().height(), 28.0 ) ) );
267 mAddCustomColorButton->setMinimumWidth( swatchAddSize );
268 mAddCustomColorButton->setMaximumWidth( swatchAddSize );
271 mTabWidget->setIconSize( QSize( iconSize, iconSize ) );
276 const int activeRgbRadio = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), 2 ).toInt();
277 if ( QAbstractButton *rgbRadio = mRgbGroup->button( activeRgbRadio ) )
278 rgbRadio->setChecked(
true );
280 const int activeCmykRadio = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeCmykComponent" ), 0 ).toInt();
281 if ( QAbstractButton *cmykRadio = mCmykGroup->button( activeCmykRadio ) )
282 cmykRadio->setChecked(
true );
284 const int currentTab = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeTab" ), 0 ).toInt();
285 mTabWidget->setCurrentIndex( currentTab );