Krita Source Code Documentation
Loading...
Searching...
No Matches
KisStretchedIconButton.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QIcon>
10#include <QLabel>
11#include <QHBoxLayout>
12#include <QAction>
13#include <QWindow>
14
15#include <kis_debug.h>
16
18 : QToolButton(parent),
19 m_label(new QLabel(this))
20{
21 m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
22 QHBoxLayout *layout = new QHBoxLayout();
23 layout->addWidget(m_label);
24 setLayout(layout);
26}
27
31
33{
34 m_stretchedIcon = icon;
36}
37
42
44{
46 m_action = action;
47 if (action) {
48 m_actionConnections.addConnection(action, &QAction::changed,
50 m_actionConnections.addConnection(this, &KisStretchedIconButton::clicked,
51 action, &QAction::trigger);
52 }
54}
55
57{
58 return m_action;
59}
60
61void KisStretchedIconButton::resizeEvent(QResizeEvent *event)
62{
63 QToolButton::resizeEvent(event);
65}
66
68{
69#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
70 m_label->setPixmap(m_stretchedIcon.pixmap(this->windowHandle(), m_label->size()));
71#else
72 m_label->setPixmap(m_stretchedIcon.pixmap(m_label->size(), this->window()->devicePixelRatio()));
73#endif
74}
75
77{
78 setStretchedIcon(m_action ? m_action->icon() : QIcon());
79 setText("");
80 setToolTip(m_action ? m_action->toolTip() : "");
81 setStatusTip(m_action ? m_action->statusTip() : "");
82 setWhatsThis(m_action ? m_action->whatsThis() : "");
83 setEnabled(m_action && m_action->isEnabled());
84 setVisible(m_action && m_action->isVisible());
85}
void addConnection(Sender sender, Signal signal, Receiver receiver, Method method, Qt::ConnectionType type=Qt::AutoConnection)
KisStretchedIconButton(QWidget *parent)
void setStretchedIcon(const QIcon &icon)
void resizeEvent(QResizeEvent *event)
KisSignalAutoConnectionsStore m_actionConnections
void setAssociatedAction(QAction *action)