62 mRgbGroup =
new QButtonGroup(
this );
64 for (
auto colorRadio : mRgbRadios )
65 mRgbGroup->addButton( colorRadio.first, i++ );
67 mCmykGroup =
new QButtonGroup(
this );
69 for (
auto colorRadio : mCmykRadios )
70 mCmykGroup->addButton( colorRadio.first, i++ );
72 connect( mRgbGroup, &QButtonGroup::idToggled,
this, &QgsCompoundColorWidget::onColorButtonGroupToggled );
73 connect( mCmykGroup, &QButtonGroup::idToggled,
this, &QgsCompoundColorWidget::onColorButtonGroupToggled );
74 connect( mAddColorToSchemeButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddColorToSchemeButton_clicked );
75 connect( mAddCustomColorButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mAddCustomColorButton_clicked );
76 connect( mSampleButton, &QPushButton::clicked,
this, &QgsCompoundColorWidget::mSampleButton_clicked );
77 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsCompoundColorWidget::mTabWidget_currentChanged );
78 connect( mActionShowInButtons, &QAction::toggled,
this, &QgsCompoundColorWidget::mActionShowInButtons_toggled );
80 mColorModel->addItem( tr(
"RGB" ), QColor::Spec::Rgb );
81 mColorModel->addItem( tr(
"CMYK" ), QColor::Spec::Cmyk );
82 connect( mColorModel,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) {
83 const QColor::Spec spec =
static_cast<QColor::Spec
>( mColorModel->currentData().toInt() );
84 if ( spec == QColor::Spec::Cmyk )
95 QVBoxLayout *newLayout =
new QVBoxLayout();
96 newLayout->setContentsMargins( 0, 0, 0, 0 );
97 newLayout->addWidget( mTabWidget );
98 newLayout->addWidget( mSlidersWidget );
99 newLayout->addWidget( mPreviewWidget );
100 newLayout->addWidget( mSwatchesWidget );
102 setLayout( newLayout );
107 mSchemeList->header()->hide();
108 mSchemeList->setColumnWidth( 0,
static_cast<int>(
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6 ) );
111 refreshSchemeComboBox();
115 int activeScheme = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeScheme" ), 0 ).toInt();
116 activeScheme = activeScheme >= mSchemeComboBox->count() ? 0 : activeScheme;
118 mSchemeList->setScheme( schemeList.at( activeScheme ) );
120 mSchemeComboBox->setCurrentIndex( activeScheme );
121 updateActionsForCurrentScheme();
124 connect( mSchemeList->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCompoundColorWidget::listSelectionChanged );
126 mActionCopyColors->setEnabled(
false );
132 connect( mActionImportPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::importPalette );
133 connect( mActionRemovePalette, &QAction::triggered,
this, &QgsCompoundColorWidget::removePalette );
134 connect( mActionNewPalette, &QAction::triggered,
this, &QgsCompoundColorWidget::newPalette );
137 QMenu *schemeMenu =
new QMenu( mSchemeToolButton );
138 schemeMenu->addAction( mActionCopyColors );
139 schemeMenu->addAction( mActionPasteColors );
140 schemeMenu->addSeparator();
141 schemeMenu->addAction( mActionImportColors );
142 schemeMenu->addAction( mActionExportColors );
143 schemeMenu->addSeparator();
144 schemeMenu->addAction( mActionNewPalette );
145 schemeMenu->addAction( mActionImportPalette );
146 schemeMenu->addAction( mActionRemovePalette );
147 schemeMenu->addAction( mActionShowInButtons );
148 mSchemeToolButton->setMenu( schemeMenu );
150 connect( mSchemeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsCompoundColorWidget::schemeIndexChanged );
153 mOldColorLabel->hide();
156 mVerticalRamp->setInteriorMargin( 2 );
157 mVerticalRamp->setShowFrame(
true );
171 mSwatchButton1->setShowMenu(
false );
173 mSwatchButton2->setShowMenu(
false );
175 mSwatchButton3->setShowMenu(
false );
177 mSwatchButton4->setShowMenu(
false );
179 mSwatchButton5->setShowMenu(
false );
181 mSwatchButton6->setShowMenu(
false );
183 mSwatchButton7->setShowMenu(
false );
185 mSwatchButton8->setShowMenu(
false );
187 mSwatchButton9->setShowMenu(
false );
189 mSwatchButton10->setShowMenu(
false );
191 mSwatchButton11->setShowMenu(
false );
193 mSwatchButton12->setShowMenu(
false );
195 mSwatchButton13->setShowMenu(
false );
197 mSwatchButton14->setShowMenu(
false );
199 mSwatchButton15->setShowMenu(
false );
201 mSwatchButton16->setShowMenu(
false );
204 mSwatchButton1->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor1" ), QVariant( QColor() ) ).value<QColor>() );
205 mSwatchButton2->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor2" ), QVariant( QColor() ) ).value<QColor>() );
206 mSwatchButton3->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor3" ), QVariant( QColor() ) ).value<QColor>() );
207 mSwatchButton4->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor4" ), QVariant( QColor() ) ).value<QColor>() );
208 mSwatchButton5->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor5" ), QVariant( QColor() ) ).value<QColor>() );
209 mSwatchButton6->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor6" ), QVariant( QColor() ) ).value<QColor>() );
210 mSwatchButton7->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor7" ), QVariant( QColor() ) ).value<QColor>() );
211 mSwatchButton8->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor8" ), QVariant( QColor() ) ).value<QColor>() );
212 mSwatchButton9->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor9" ), QVariant( QColor() ) ).value<QColor>() );
213 mSwatchButton10->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor10" ), QVariant( QColor() ) ).value<QColor>() );
214 mSwatchButton11->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor11" ), QVariant( QColor() ) ).value<QColor>() );
215 mSwatchButton12->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor12" ), QVariant( QColor() ) ).value<QColor>() );
216 mSwatchButton13->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor13" ), QVariant( QColor() ) ).value<QColor>() );
217 mSwatchButton14->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor14" ), QVariant( QColor() ) ).value<QColor>() );
218 mSwatchButton15->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor15" ), QVariant( QColor() ) ).value<QColor>() );
219 mSwatchButton16->setColor( settings.
value( QStringLiteral(
"Windows/ColorDialog/customColor16" ), QVariant( QColor() ) ).value<QColor>() );
222 mSpinBoxRadius->setValue( settings.
value( QStringLiteral(
"Windows/ColorDialog/sampleRadius" ), 1 ).toInt() );
223 mSamplePreview->setColor( QColor() );
226 const int swatchWidth =
static_cast<int>( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.9 * mSwatchButton1->fontMetrics().height(), 38.0 ) ) );
227 const int swatchHeight =
static_cast<int>( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.5 * mSwatchButton1->fontMetrics().height(), 30.0 ) ) );
228 mSwatchButton1->setMinimumSize( swatchWidth, swatchHeight );
229 mSwatchButton1->setMaximumSize( swatchWidth, swatchHeight );
230 mSwatchButton2->setMinimumSize( swatchWidth, swatchHeight );
231 mSwatchButton2->setMaximumSize( swatchWidth, swatchHeight );
232 mSwatchButton3->setMinimumSize( swatchWidth, swatchHeight );
233 mSwatchButton3->setMaximumSize( swatchWidth, swatchHeight );
234 mSwatchButton4->setMinimumSize( swatchWidth, swatchHeight );
235 mSwatchButton4->setMaximumSize( swatchWidth, swatchHeight );
236 mSwatchButton5->setMinimumSize( swatchWidth, swatchHeight );
237 mSwatchButton5->setMaximumSize( swatchWidth, swatchHeight );
238 mSwatchButton6->setMinimumSize( swatchWidth, swatchHeight );
239 mSwatchButton6->setMaximumSize( swatchWidth, swatchHeight );
240 mSwatchButton7->setMinimumSize( swatchWidth, swatchHeight );
241 mSwatchButton7->setMaximumSize( swatchWidth, swatchHeight );
242 mSwatchButton8->setMinimumSize( swatchWidth, swatchHeight );
243 mSwatchButton8->setMaximumSize( swatchWidth, swatchHeight );
244 mSwatchButton9->setMinimumSize( swatchWidth, swatchHeight );
245 mSwatchButton9->setMaximumSize( swatchWidth, swatchHeight );
246 mSwatchButton10->setMinimumSize( swatchWidth, swatchHeight );
247 mSwatchButton10->setMaximumSize( swatchWidth, swatchHeight );
248 mSwatchButton11->setMinimumSize( swatchWidth, swatchHeight );
249 mSwatchButton11->setMaximumSize( swatchWidth, swatchHeight );
250 mSwatchButton12->setMinimumSize( swatchWidth, swatchHeight );
251 mSwatchButton12->setMaximumSize( swatchWidth, swatchHeight );
252 mSwatchButton13->setMinimumSize( swatchWidth, swatchHeight );
253 mSwatchButton13->setMaximumSize( swatchWidth, swatchHeight );
254 mSwatchButton14->setMinimumSize( swatchWidth, swatchHeight );
255 mSwatchButton14->setMaximumSize( swatchWidth, swatchHeight );
256 mSwatchButton15->setMinimumSize( swatchWidth, swatchHeight );
257 mSwatchButton15->setMaximumSize( swatchWidth, swatchHeight );
258 mSwatchButton16->setMinimumSize( swatchWidth, swatchHeight );
259 mSwatchButton16->setMaximumSize( swatchWidth, swatchHeight );
260 const int previewHeight =
static_cast<int>( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 2.0 * mSwatchButton1->fontMetrics().height(), 40.0 ) ) );
261 mColorPreview->setMinimumSize( 0, previewHeight );
262 mPreviewWidget->setMaximumHeight( previewHeight * 2 );
263 const int swatchAddSize =
static_cast<int>( std::round( std::max(
Qgis::UI_SCALE_FACTOR * 1.4 * mSwatchButton1->fontMetrics().height(), 28.0 ) ) );
264 mAddCustomColorButton->setMinimumWidth( swatchAddSize );
265 mAddCustomColorButton->setMaximumWidth( swatchAddSize );
268 mTabWidget->setIconSize( QSize( iconSize, iconSize ) );
273 const int activeRgbRadio = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeComponent" ), 2 ).toInt();
274 if ( QAbstractButton *rgbRadio = mRgbGroup->button( activeRgbRadio ) )
275 rgbRadio->setChecked(
true );
277 const int activeCmykRadio = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeCmykComponent" ), 0 ).toInt();
278 if ( QAbstractButton *cmykRadio = mCmykGroup->button( activeCmykRadio ) )
279 cmykRadio->setChecked(
true );
281 const int currentTab = settings.
value( QStringLiteral(
"Windows/ColorDialog/activeTab" ), 0 ).toInt();
282 mTabWidget->setCurrentIndex( currentTab );