Krita Source Code Documentation
Loading...
Searching...
No Matches
KDcrawIface::RColorSelector Class Reference

#include <rwidgetutils.h>

+ Inheritance diagram for KDcrawIface::RColorSelector:

Signals

void signalColorSelected (const QColor &)
 

Public Member Functions

QColor color () const
 
 Private ()
 
 RColorSelector (QWidget *const parent=0)
 
void setColor (const QColor &color)
 
 ~RColorSelector () override
 

Public Attributes

QColor color
 

Private Slots

void slotBtnClicked ()
 

Private Member Functions

void paintEvent (QPaintEvent *) override
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

A widget to chosse a color from a palette.

Definition at line 514 of file rwidgetutils.cpp.

Constructor & Destructor Documentation

◆ RColorSelector()

KDcrawIface::RColorSelector::RColorSelector ( QWidget *const parent = 0)
explicit

Definition at line 525 of file rwidgetutils.cpp.

526 : QPushButton(parent),
527 d(new Private)
528{
529 connect(this, SIGNAL(clicked()),
530 this, SLOT(slotBtnClicked()));
531}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))

References connect(), and slotBtnClicked().

◆ ~RColorSelector()

KDcrawIface::RColorSelector::~RColorSelector ( )
override

Definition at line 533 of file rwidgetutils.cpp.

534{
535 delete d;
536}

References d.

Member Function Documentation

◆ color()

QColor KDcrawIface::RColorSelector::color ( ) const

◆ paintEvent()

void KDcrawIface::RColorSelector::paintEvent ( QPaintEvent * )
overrideprivate

Definition at line 563 of file rwidgetutils.cpp.

564{
565 QPainter painter(this);
566 QStyle* const style = QWidget::style();
567
568 QStyleOptionButton opt;
569
570 opt.initFrom(this);
571 opt.state |= isDown() ? QStyle::State_Sunken : QStyle::State_Raised;
572 opt.features = QStyleOptionButton::None;
573 opt.icon = QIcon();
574 opt.text.clear();
575
576 style->drawControl(QStyle::CE_PushButtonBevel, &opt, &painter, this);
577
578 QRect labelRect = style->subElementRect(QStyle::SE_PushButtonContents, &opt, this);
579 int shift = style->pixelMetric(QStyle::PM_ButtonMargin, &opt, this) / 2;
580 labelRect.adjust(shift, shift, -shift, -shift);
581 int x, y, w, h;
582 labelRect.getRect(&x, &y, &w, &h);
583
584 if (isChecked() || isDown())
585 {
586 x += style->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &opt, this);
587 y += style->pixelMetric(QStyle::PM_ButtonShiftVertical, &opt, this);
588 }
589
590 QColor fillCol = isEnabled() ? d->color : palette().color(backgroundRole());
591 qDrawShadePanel(&painter, x, y, w, h, palette(), true, 1, 0);
592
593 if (fillCol.isValid())
594 {
595 const QRect rect(x + 1, y + 1, w - 2, h - 2);
596
597 if (fillCol.alpha() < 255)
598 {
599 QPixmap chessboardPattern(16, 16);
600 QPainter patternPainter(&chessboardPattern);
601 patternPainter.fillRect(0, 0, 8, 8, Qt::black);
602 patternPainter.fillRect(8, 8, 8, 8, Qt::black);
603 patternPainter.fillRect(0, 8, 8, 8, Qt::white);
604 patternPainter.fillRect(8, 0, 8, 8, Qt::white);
605 patternPainter.end();
606 painter.fillRect(rect, QBrush(chessboardPattern));
607 }
608
609 painter.fillRect(rect, fillCol);
610 }
611
612 if (hasFocus())
613 {
614 QRect focusRect = style->subElementRect(QStyle::SE_PushButtonFocusRect, &opt, this);
615 QStyleOptionFocusRect focusOpt;
616 focusOpt.initFrom(this);
617 focusOpt.rect = focusRect;
618 focusOpt.backgroundColor = palette().window().color();
619 style->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpt, &painter, this);
620 }
621}
rgba palette[MAX_PALETTE]
Definition palette.c:35

References d, and palette.

◆ Private()

KDcrawIface::RColorSelector::Private ( )
inline

Definition at line 518 of file rwidgetutils.cpp.

519 {
520 }

◆ setColor()

void KDcrawIface::RColorSelector::setColor ( const QColor & color)

Definition at line 538 of file rwidgetutils.cpp.

539{
540 if (color.isValid())
541 {
542 d->color = color;
543 update();
544 }
545}
bool update(QSpinBox *spinBox)

References color, and d.

◆ signalColorSelected

void KDcrawIface::RColorSelector::signalColorSelected ( const QColor & )
signal

◆ slotBtnClicked

void KDcrawIface::RColorSelector::slotBtnClicked ( )
privateslot

Definition at line 552 of file rwidgetutils.cpp.

553{
554 QColor color = QColorDialog::getColor(d->color);
555
556 if (color.isValid())
557 {
560 }
561}
void signalColorSelected(const QColor &)
void setColor(const QColor &color)

References color, d, setColor(), and signalColorSelected().

Member Data Documentation

◆ color

QColor KDcrawIface::RColorSelector::color

Definition at line 522 of file rwidgetutils.cpp.

◆ d

Private* const KDcrawIface::RColorSelector::d
private

Definition at line 250 of file rwidgetutils.h.


The documentation for this class was generated from the following files: