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

Custom widget for selection actions panel buttons, to prevent them being drawn over the pop-up palette. More...

#include <kis_selection_actions_panel_button.h>

+ Inheritance diagram for KisSelectionActionsPanelButton:

Public Member Functions

void draw (QPainter &painter)
 
 KisSelectionActionsPanelButton (const QString &iconName, const QString &tooltip, int size, QWidget *parent)
 
 ~KisSelectionActionsPanelButton ()
 

Protected Member Functions

bool event (QEvent *event) override
 
void paintEvent (QPaintEvent *e) override
 
void tabletEvent (QTabletEvent *e) override
 

Detailed Description

Custom widget for selection actions panel buttons, to prevent them being drawn over the pop-up palette.

Definition at line 13 of file kis_selection_actions_panel_button.h.

Constructor & Destructor Documentation

◆ KisSelectionActionsPanelButton()

KisSelectionActionsPanelButton::KisSelectionActionsPanelButton ( const QString & iconName,
const QString & tooltip,
int size,
QWidget * parent )

Definition at line 17 of file kis_selection_actions_panel_button.cpp.

18 : QAbstractButton(parent)
19{
20 setIcon(KisIconUtils::loadIcon(iconName));
21 setFixedSize(size, size);
22 setToolTip(tooltip);
23 setCursor(Qt::PointingHandCursor);
24 setIconSize(QSize(size - ICON_SIZE_OFFSET, size - ICON_SIZE_OFFSET));
25 setAttribute(Qt::WA_AcceptTouchEvents);
26}
static constexpr int ICON_SIZE_OFFSET
QIcon loadIcon(const QString &name)

References ICON_SIZE_OFFSET, and KisIconUtils::loadIcon().

◆ ~KisSelectionActionsPanelButton()

KisSelectionActionsPanelButton::~KisSelectionActionsPanelButton ( )

Definition at line 28 of file kis_selection_actions_panel_button.cpp.

29{
30
31}

Member Function Documentation

◆ draw()

void KisSelectionActionsPanelButton::draw ( QPainter & painter)

Definition at line 33 of file kis_selection_actions_panel_button.cpp.

34{
35 QRect rect = geometry();
36 //Draw an outline when the button is pressed
37 if(this->isDown()) {
38 QPainterPath path;
39 path.addRoundedRect(rect, 3, 3);
40 QPen pen = qApp->palette().highlight().color();
41 pen.setWidth(2);
42
43 painter.setPen(pen);
44 painter.drawPath(path) ;
45 }
46
47 int padding = ICON_SIZE_OFFSET / 2;
48 icon().paint(&painter, rect.marginsRemoved(QMargins(padding, padding, padding, padding)));
49}

References ICON_SIZE_OFFSET.

◆ event()

bool KisSelectionActionsPanelButton::event ( QEvent * event)
overrideprotected

Definition at line 83 of file kis_selection_actions_panel_button.cpp.

84{
85 //Manually handle the button being pressed on touch
86 if (e->type() == QEvent::TouchBegin) {
87 QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e);
88#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
89 int pointsCount = touchEvent->points().count();
90#else
91 int pointsCount = touchEvent->touchPoints().count();
92#endif
93 if (pointsCount == 1) {
94 this->animateClick();
95 e->accept();
96 return true;
97 }
98 }
99 return QAbstractButton::event(e);
100}

◆ paintEvent()

void KisSelectionActionsPanelButton::paintEvent ( QPaintEvent * e)
overrideprotected

Definition at line 53 of file kis_selection_actions_panel_button.cpp.

54{
55 Q_UNUSED(e);
56}

◆ tabletEvent()

void KisSelectionActionsPanelButton::tabletEvent ( QTabletEvent * e)
overrideprotected

Definition at line 60 of file kis_selection_actions_panel_button.cpp.

61{
62 if (e->type() == QEvent::TabletPress) {
63 QMouseEvent mouseEvent(QEvent::MouseButtonPress,
64 e->posF(),
65 e->globalPosF(),
66 e->button(),
67 e->buttons(),
68 e->modifiers());
69 QAbstractButton::mousePressEvent(&mouseEvent);
70 e->accept();
71 } else if (e->type() == QEvent::TabletRelease) {
72 QMouseEvent mouseEvent(QEvent::MouseButtonRelease,
73 e->posF(),
74 e->globalPosF(),
75 e->button(),
76 e->buttons(),
77 e->modifiers());
78 QAbstractButton::mouseReleaseEvent(&mouseEvent);
79 e->accept();
80 }
81}

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