Krita Source Code Documentation
Loading...
Searching...
No Matches
KoDockWidgetTitleBarButton.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2007 Marijn Kruisselbrink <mkruisselbrink@kde.org>
3 SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
9
10#include <WidgetsDebug.h>
11
12#include <QAbstractButton>
13#include <QAction>
14#include <QLayout>
15#include <QStyle>
16#include <QStylePainter>
17#include <QStyleOptionFrame>
18
20{
21public:
22 Private() : styleSize(0, 0), iconSize(0) {}
23 QSize styleSize;
25};
26
28 : QAbstractButton(parent), d(new Private())
29{
30 setFocusPolicy(Qt::NoFocus);
31}
32
37
39{
40 ensurePolished();
41
42 const int margin = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this);
43 if (icon().isNull()) {
44 return QSize(18, 18);
45 }
46
47 int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
48 if (iconSize != d->iconSize) {
49 const_cast<KoDockWidgetTitleBarButton*>(this)->d->iconSize = iconSize;
50 const QPixmap pm = icon().pixmap(iconSize);
51 const_cast<KoDockWidgetTitleBarButton*>(this)->d->styleSize = QSize(pm.width() + margin, pm.height() + margin);
52 }
53 return d->styleSize;
54}
55
57{
58 return sizeHint();
59}
60
61// redraw the button when the mouse enters or leaves it
62#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
64#else
66#endif
67{
68 if (isEnabled())
69 update();
70 QAbstractButton::enterEvent(event);
71}
72
74{
75 if (isEnabled())
76 update();
77 QAbstractButton::leaveEvent(event);
78}
79
81{
82 QPainter p(this);
83
84 QStyleOptionToolButton opt;
85 opt.initFrom(this);
86 opt.state |= QStyle::State_AutoRaise;
87
88 if (isEnabled() && underMouse() && !isChecked() && !isDown())
89 opt.state |= QStyle::State_Raised;
90 if (isChecked())
91 opt.state |= QStyle::State_On;
92 if (isDown())
93 opt.state |= QStyle::State_Sunken;
94 style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, &p, this);
95
96 opt.icon = icon();
97 opt.features = QStyleOptionToolButton::None;
98 opt.arrowType = Qt::NoArrow;
99 int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
100 opt.iconSize = QSize(size, size);
101 style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this);
102}
const Params2D p
int iconSize(qreal width, qreal height)
A custom title bar button for dock widgets.
void paintEvent(QPaintEvent *event) override
QSize sizeHint() const override
reimplemented from QWidget
QSize minimumSizeHint() const override
reimplemented from QWidget
void enterEvent(QEnterEvent *e) override
void leaveEvent(QEvent *event) override