198 QPainter painter(
this);
199 QStyle *style = QWidget::style();
202 QStyleOptionButton butOpt;
204 style->drawControl(QStyle::CE_PushButtonBevel, &butOpt, &painter,
this);
208 QRect labelRect = style->subElementRect(QStyle::SE_PushButtonContents,
210 int shift = style->pixelMetric(QStyle::PM_ButtonMargin, &butOpt,
this) / 2;
211 labelRect.adjust(shift, shift, -shift, -shift);
213 labelRect.getRect(&x, &y, &w, &h);
215 if (isChecked() || isDown()) {
216 x += style->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &butOpt,
this);
217 y += style->pixelMetric(QStyle::PM_ButtonShiftVertical, &butOpt,
this);
221 qDrawShadePanel(&painter, x, y, w, h,
palette(),
true, 1, NULL);
222 if (fillCol.isValid()) {
223 const QRect
rect(x + 1, y + 1, w - 2, h - 2);
224 if (fillCol.alpha() < 255) {
225 QPixmap chessboardPattern(16, 16);
226 QPainter patternPainter(&chessboardPattern);
227 patternPainter.fillRect(0, 0, 8, 8, Qt::black);
228 patternPainter.fillRect(8, 8, 8, 8, Qt::black);
229 patternPainter.fillRect(0, 8, 8, 8, Qt::white);
230 patternPainter.fillRect(8, 0, 8, 8, Qt::white);
231 patternPainter.end();
232 painter.fillRect(
rect, QBrush(chessboardPattern));
234 painter.fillRect(
rect, fillCol);
238 QRect focusRect = style->subElementRect(QStyle::SE_PushButtonFocusRect, &butOpt,
this);
239 QStyleOptionFocusRect focusOpt;
240 focusOpt.initFrom(
this);
241 focusOpt.rect = focusRect;
242 focusOpt.backgroundColor =
palette().window().color();
243 style->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpt, &painter,
this);
311 KConfigGroup cfg = KSharedConfig::openConfig()->group(
"colorselector");
312 bool usePlatformDialog = cfg.readEntry(
"UsePlatformColorDialog",
false);
314 if (!usePlatformDialog) {
318 dialog->setPreviousColor(q->color());
319 auto setColorFn = [
this, dialog]() { q->setColor(dialog->getCurrentColor()); };
321 connect(dialog, &QDialog::accepted, setColorFn);
324 QColorDialog *dialog =
new QColorDialog(q);
325 dialog->setOption(QColorDialog::ShowAlphaChannel, m_alphaChannel);
326 dialog->setCurrentColor(q->color().toQColor());
327 auto setColorFn = [
this, dialog]()
333 connect(dialog, &QColorDialog::currentColorChanged, setColorFn);
334 connect(dialog, &QDialog::accepted, setColorFn);
338 KoColor colorBeforeColorDialogChanges = col;
339 connect(m_dialog, &QDialog::rejected, [colorBeforeColorDialogChanges,
this](){ q->setColor(colorBeforeColorDialogChanges); });
340 m_dialog->setAttribute(Qt::WA_DeleteOnClose);
343 m_dialog->activateWindow();