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, const KoColorDisplayRendererInterface *displayRendererInterface)
 
 KisSelectionActionsPanelButton (const QString &iconName, const QString &tooltip, int size, QWidget *parent)
 
 ~KisSelectionActionsPanelButton ()
 

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *event) override
 
bool event (QEvent *event) override
 
void mousePressEvent (QMouseEvent *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 15 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 19 of file kis_selection_actions_panel_button.cpp.

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

References KisLongPressEventFilter::ENABLED_PROPERTY, ICON_SIZE_OFFSET, and KisIconUtils::loadIcon().

◆ ~KisSelectionActionsPanelButton()

KisSelectionActionsPanelButton::~KisSelectionActionsPanelButton ( )

Definition at line 31 of file kis_selection_actions_panel_button.cpp.

32{
33
34}

Member Function Documentation

◆ contextMenuEvent()

void KisSelectionActionsPanelButton::contextMenuEvent ( QContextMenuEvent * event)
overrideprotected

Definition at line 129 of file kis_selection_actions_panel_button.cpp.

130{
131 Q_EMIT customContextMenuRequested(mapToGlobal(event->pos()));
132 event->accept();
133}

References event().

◆ draw()

void KisSelectionActionsPanelButton::draw ( QPainter & painter,
const KoColorDisplayRendererInterface * displayRendererInterface )

Definition at line 36 of file kis_selection_actions_panel_button.cpp.

37{
38 QRect rect = geometry();
39 //Draw an outline when the button is pressed
40
41
42 QPainterPath rectAroundButton;
43 rectAroundButton.addRoundedRect(rect, 3, 3);
44
45 if (isCheckable() && isChecked()) {
46 painter.save();
47 QBrush brush = displayRendererInterface->systemPaletteForDisplayColorSpace().base();
48 QColor color = brush.color();
49 color.setAlphaF(0.5);
50 brush.setColor(color);
51 painter.setBrush(brush);
52 painter.setPen(Qt::NoPen);
53 painter.drawPath(rectAroundButton);
54 painter.restore();
55 }
56
57 if (!isCheckable() && isDown()) {
58 QPen pen = displayRendererInterface->systemPaletteForDisplayColorSpace().highlight().color();
59 pen.setWidth(2);
60
61 painter.setPen(pen);
62 painter.drawPath(rectAroundButton);
63 }
64
65 int padding = ICON_SIZE_OFFSET / 2;
66
67#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
68 icon().paint(&painter, rect.marginsRemoved(QMargins(padding, padding, padding, padding)));
69#else
70 QImage ic = displayRendererInterface->convertImageToDisplayColorSpace(icon().pixmap(rect.width()-(padding*2), rect.height()-(padding*2)).toImage());
71 QRect target = QRect(QPoint(0, 0), ic.deviceIndependentSize().toSize());
72 target.moveCenter(rect.center());
73 painter.drawImage(target.intersected(rect.marginsRemoved(QMargins(padding, padding, padding, padding))), ic);
74#endif
75
76}
KisMagneticGraph::vertex_descriptor target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
virtual QImage convertImageToDisplayColorSpace(const QImage source) const =0
convertImageToDisplayColorSpace
virtual QPalette systemPaletteForDisplayColorSpace() const =0
systemPaletteForDisplayColorSpace

References KoColorDisplayRendererInterface::convertImageToDisplayColorSpace(), ICON_SIZE_OFFSET, KoColorDisplayRendererInterface::systemPaletteForDisplayColorSpace(), and target().

◆ event()

bool KisSelectionActionsPanelButton::event ( QEvent * event)
overrideprotected

Definition at line 110 of file kis_selection_actions_panel_button.cpp.

111{
112 //Manually handle the button being pressed on touch
113 if (e->type() == QEvent::TouchBegin) {
114 QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e);
115#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
116 int pointsCount = touchEvent->points().count();
117#else
118 int pointsCount = touchEvent->touchPoints().count();
119#endif
120 if (pointsCount == 1) {
121 this->animateClick();
122 e->accept();
123 return true;
124 }
125 }
126 return QAbstractButton::event(e);
127}

◆ mousePressEvent()

void KisSelectionActionsPanelButton::mousePressEvent ( QMouseEvent * event)
overrideprotected

Definition at line 135 of file kis_selection_actions_panel_button.cpp.

136{
137 //Do not propagate the rmb event, to prevent other tool context menus from appearing
138 if (event->button() == Qt::RightButton) {
139 event->accept();
140 } else {
141 QAbstractButton::mousePressEvent(event);
142 }
143}

References event().

◆ paintEvent()

void KisSelectionActionsPanelButton::paintEvent ( QPaintEvent * e)
overrideprotected

Definition at line 80 of file kis_selection_actions_panel_button.cpp.

81{
82 Q_UNUSED(e);
83}

◆ tabletEvent()

void KisSelectionActionsPanelButton::tabletEvent ( QTabletEvent * e)
overrideprotected

Definition at line 87 of file kis_selection_actions_panel_button.cpp.

88{
89 if (e->type() == QEvent::TabletPress) {
90 QMouseEvent mouseEvent(QEvent::MouseButtonPress,
91 e->posF(),
92 e->globalPosF(),
93 e->button(),
94 e->buttons(),
95 e->modifiers());
96 QAbstractButton::mousePressEvent(&mouseEvent);
97 e->accept();
98 } else if (e->type() == QEvent::TabletRelease) {
99 QMouseEvent mouseEvent(QEvent::MouseButtonRelease,
100 e->posF(),
101 e->globalPosF(),
102 e->button(),
103 e->buttons(),
104 e->modifiers());
105 QAbstractButton::mouseReleaseEvent(&mouseEvent);
106 e->accept();
107 }
108}

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