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