Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_selection_actions_panel_button.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 Luna Lovecraft <ciubix8514@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
8
9#include "kis_icon_utils.h"
10#include <qapplication.h>
11#include <qpainter.h>
12#include <qpainterpath.h>
13
14static constexpr int ICON_SIZE_OFFSET = 6;
15
16KisSelectionActionsPanelButton::KisSelectionActionsPanelButton(const QString& iconName, const QString &tooltip, int size, QWidget *parent)
17 : QAbstractButton(parent)
18{
19 setIcon(KisIconUtils::loadIcon(iconName));
20 setFixedSize(size, size);
21 setToolTip(tooltip);
22 setCursor(Qt::PointingHandCursor);
23 setIconSize(QSize(size - ICON_SIZE_OFFSET, size - ICON_SIZE_OFFSET));
24}
25
30
32{
33 QRect rect = geometry();
34 //Draw an outline when the button is pressed
35 if(this->isDown()) {
36 QColor bgColor = qApp->palette().window().color();
37 //Invert the background color
38 bgColor.setRed(255 - bgColor.red());
39 bgColor.setGreen(255 - bgColor.green());
40 bgColor.setBlue(255 - bgColor.blue());
41
42 QPainterPath path;
43 path.addRoundedRect(rect, 3, 3);
44 QPen pen = bgColor;
45 pen.setWidth(2);
46
47 painter.setPen(pen);
48 painter.drawPath(path) ;
49 }
50
51 QPixmap map = this->icon().pixmap(iconSize());
52 painter.drawPixmap(rect.x() + ICON_SIZE_OFFSET / 2.0 , rect.y() + ICON_SIZE_OFFSET / 2.0, map);
53}
54
55
56//Dummy paint event, so that this class isn't treated like an abstract class
58{
59 Q_UNUSED(e);
60}
61
int iconSize(qreal width, qreal height)
KisSelectionActionsPanelButton(const QString &iconName, const QString &tooltip, int size, QWidget *parent)
static constexpr int ICON_SIZE_OFFSET
QIcon loadIcon(const QString &name)