1
/* This file is part of the KDE project
2
Copyright (c) 2007 Marijn Kruisselbrink <m.kruisselbrink@student.tue.nl>
3
Copyright (C) 2007 Thomas Zander <zander@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
21
#include "KoDockWidgetTitleBarButton.h"
26
#include <QAbstractButton>
31
#include <QStylePainter>
32
#include <QStyleOptionFrame>
34
class KoDockWidgetTitleBarButton::Private
37
Private() : styleSize(0, 0), iconSize(0) {}
42
KoDockWidgetTitleBarButton::KoDockWidgetTitleBarButton(QWidget *parent)
43
: QAbstractButton(parent), d(new Private())
45
setFocusPolicy(Qt::NoFocus);
48
KoDockWidgetTitleBarButton::~KoDockWidgetTitleBarButton()
53
QSize KoDockWidgetTitleBarButton::sizeHint() const
57
const int margin = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this);
59
return QSize(margin, margin);
61
int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
62
if (iconSize != d->iconSize) {
63
const_cast<KoDockWidgetTitleBarButton*>(this)->d->iconSize = iconSize;
64
const QPixmap pm = icon().pixmap(iconSize);
65
const_cast<KoDockWidgetTitleBarButton*>(this)->d->styleSize = QSize(pm.width() + margin, pm.height() + margin);
70
QSize KoDockWidgetTitleBarButton::minimumSizeHint() const
75
// redraw the button when the mouse enters or leaves it
76
void KoDockWidgetTitleBarButton::enterEvent(QEvent *event)
80
QAbstractButton::enterEvent(event);
83
void KoDockWidgetTitleBarButton::leaveEvent(QEvent *event)
87
QAbstractButton::leaveEvent(event);
90
void KoDockWidgetTitleBarButton::paintEvent(QPaintEvent *)
95
QStyleOptionToolButton opt;
97
opt.state |= QStyle::State_AutoRaise;
99
if (isEnabled() && underMouse() && !isChecked() && !isDown())
100
opt.state |= QStyle::State_Raised;
102
opt.state |= QStyle::State_On;
104
opt.state |= QStyle::State_Sunken;
105
style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, &p, this);
109
opt.activeSubControls = 0;
110
opt.features = QStyleOptionToolButton::None;
111
opt.arrowType = Qt::NoArrow;
112
int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
113
opt.iconSize = QSize(size, size);
114
style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this);
117
#include <KoDockWidgetTitleBarButton.moc>