Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRoundHudButton Class Reference

#include <kis_round_hud_button.h>

+ Inheritance diagram for KisRoundHudButton:

Classes

struct  Private
 

Public Member Functions

 KisRoundHudButton (QWidget *parent)
 
void setOnOffIcons (const QIcon &on, const QIcon &off)
 
 ~KisRoundHudButton () override
 

Protected Member Functions

bool hitButton (const QPoint &pos) const override
 
void leaveEvent (QEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 15 of file kis_round_hud_button.h.

Constructor & Destructor Documentation

◆ KisRoundHudButton()

KisRoundHudButton::KisRoundHudButton ( QWidget * parent)

Definition at line 25 of file kis_round_hud_button.cpp.

26 : QAbstractButton(parent),
27 m_d(new Private)
28{
29 setMouseTracking(true);
30}
const QScopedPointer< Private > m_d

◆ ~KisRoundHudButton()

KisRoundHudButton::~KisRoundHudButton ( )
override

Definition at line 32 of file kis_round_hud_button.cpp.

33{
34}

Member Function Documentation

◆ hitButton()

bool KisRoundHudButton::hitButton ( const QPoint & pos) const
overrideprotected

Definition at line 84 of file kis_round_hud_button.cpp.

85{
86 const int borderWidth = 3;
87 const QPointF center = QRectF(rect()).center();
88 const qreal radius = 0.5 * (center.x() + center.y()) - borderWidth;
89
90 return kisDistance(center, pos) < radius;
91}
qreal kisDistance(const QPointF &pt1, const QPointF &pt2)
Definition kis_global.h:190

References kisDistance().

◆ leaveEvent()

void KisRoundHudButton::leaveEvent ( QEvent * event)
overrideprotected

Definition at line 104 of file kis_round_hud_button.cpp.

105{
106 Q_UNUSED(event);
107 if (m_d->isHighlighted) {
108 m_d->isHighlighted = false;
109 update();
110 }
111
112 QAbstractButton::leaveEvent(event);
113}
bool update(QSpinBox *spinBox)

References m_d.

◆ mouseMoveEvent()

void KisRoundHudButton::mouseMoveEvent ( QMouseEvent * event)
overrideprotected

Definition at line 93 of file kis_round_hud_button.cpp.

94{
95 bool isOver = hitButton(event->pos());
96 if (isOver != m_d->isHighlighted) {
97 m_d->isHighlighted = isOver;
98 update();
99 }
100
101 QAbstractButton::mouseMoveEvent(event);
102}
bool hitButton(const QPoint &pos) const override

References hitButton(), and m_d.

◆ paintEvent()

void KisRoundHudButton::paintEvent ( QPaintEvent * event)
overrideprotected

Definition at line 42 of file kis_round_hud_button.cpp.

43{
44 const int borderWidth = 3;
45 const QPointF center = QRectF(rect()).center();
46 const qreal radius = 0.5 * (center.x() + center.y()) - borderWidth;
47
48 const QPen fgPen(palette().color(m_d->isHighlighted ? QPalette::Highlight : QPalette::WindowText), borderWidth);
49 const QBrush bgBrush(palette().brush(isDown() || (isCheckable() && isChecked()) ? QPalette::Mid : QPalette::Window));
50
51 QPainter painter(this);
52 painter.setPen(fgPen);
53 painter.setBrush(bgBrush);
54 painter.setRenderHints(QPainter::Antialiasing);
55
56 painter.drawEllipse(center, radius, radius);
57
58 if (!icon().isNull()) {
59 const QIcon::Mode mode = isEnabled() ? QIcon::Normal : QIcon::Disabled;
60 const QIcon::State state = isCheckable() && isChecked() ? QIcon::On : QIcon::Off;
61 const QSize size = iconSize();
62
63 QPixmap pixmap = icon().pixmap(size, mode, state);
64
65 QPointF iconOffset(0.5 * (width() - size.width()),
66 0.5 * (height() - size.height()));
67
68 painter.drawPixmap(iconOffset, pixmap);
69 }
70
71 if (!m_d->onIcon.isNull()) {
72 const QIcon::Mode mode = isEnabled() ? QIcon::Normal : QIcon::Disabled;
73 const QIcon icon = isCheckable() && isChecked() ? m_d->onIcon : m_d->offIcon;
74 const QSize size = iconSize();
75
76 QPixmap pixmap = icon.pixmap(size, mode);
77 QPointF iconOffset(0.5 * (width() - size.width()),
78 0.5 * (height() - size.height()));
79
80 painter.drawPixmap(iconOffset, pixmap);
81 }
82}
int iconSize(qreal width, qreal height)
int size(const Forest< T > &forest)
Definition KisForest.h:1232
rgba palette[MAX_PALETTE]
Definition palette.c:35

References iconSize(), m_d, and palette.

◆ setOnOffIcons()

void KisRoundHudButton::setOnOffIcons ( const QIcon & on,
const QIcon & off )

Definition at line 36 of file kis_round_hud_button.cpp.

37{
38 m_d->onIcon = on;
39 m_d->offIcon = off;
40}

References m_d.

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisRoundHudButton::m_d
private

Definition at line 32 of file kis_round_hud_button.h.


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