~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/widgets/KoDockWidgetTitleBarButton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#include "KoDockWidgetTitleBarButton.h"
 
22
 
 
23
#include <kdebug.h>
 
24
#include <kicon.h>
 
25
 
 
26
#include <QAbstractButton>
 
27
#include <QAction>
 
28
#include <QLabel>
 
29
#include <QLayout>
 
30
#include <QStyle>
 
31
#include <QStylePainter>
 
32
#include <QStyleOptionFrame>
 
33
 
 
34
class KoDockWidgetTitleBarButton::Private
 
35
{
 
36
public:
 
37
    Private() : styleSize(0, 0), iconSize(0) {}
 
38
    QSize styleSize;
 
39
    int iconSize;
 
40
};
 
41
 
 
42
KoDockWidgetTitleBarButton::KoDockWidgetTitleBarButton(QWidget *parent)
 
43
        : QAbstractButton(parent), d(new Private())
 
44
{
 
45
    setFocusPolicy(Qt::NoFocus);
 
46
}
 
47
 
 
48
KoDockWidgetTitleBarButton::~KoDockWidgetTitleBarButton()
 
49
{
 
50
    delete d;
 
51
}
 
52
 
 
53
QSize KoDockWidgetTitleBarButton::sizeHint() const
 
54
{
 
55
    ensurePolished();
 
56
 
 
57
    const int margin = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this);
 
58
    if (icon().isNull())
 
59
        return QSize(margin, margin);
 
60
 
 
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);
 
66
    }
 
67
    return d->styleSize;
 
68
}
 
69
 
 
70
QSize KoDockWidgetTitleBarButton::minimumSizeHint() const
 
71
{
 
72
    return sizeHint();
 
73
}
 
74
 
 
75
// redraw the button when the mouse enters or leaves it
 
76
void KoDockWidgetTitleBarButton::enterEvent(QEvent *event)
 
77
{
 
78
    if (isEnabled())
 
79
        update();
 
80
    QAbstractButton::enterEvent(event);
 
81
}
 
82
 
 
83
void KoDockWidgetTitleBarButton::leaveEvent(QEvent *event)
 
84
{
 
85
    if (isEnabled())
 
86
        update();
 
87
    QAbstractButton::leaveEvent(event);
 
88
}
 
89
 
 
90
void KoDockWidgetTitleBarButton::paintEvent(QPaintEvent *)
 
91
{
 
92
    QPainter p(this);
 
93
 
 
94
    QRect r = rect();
 
95
    QStyleOptionToolButton opt;
 
96
    opt.init(this);
 
97
    opt.state |= QStyle::State_AutoRaise;
 
98
 
 
99
    if (isEnabled() && underMouse() && !isChecked() && !isDown())
 
100
        opt.state |= QStyle::State_Raised;
 
101
    if (isChecked())
 
102
        opt.state |= QStyle::State_On;
 
103
    if (isDown())
 
104
        opt.state |= QStyle::State_Sunken;
 
105
    style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, &p, this);
 
106
 
 
107
    opt.icon = icon();
 
108
    opt.subControls = 0;
 
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);
 
115
}
 
116
 
 
117
#include <KoDockWidgetTitleBarButton.moc>