2 Gwenview: an image viewer
3 Copyright 2007 Aurélien Gâteau <aurelien.gateau@free.fr>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "expandbutton.h"
24 #include <QStyleOption>
25 #include <QStylePainter>
29 static const int INDICATOR_SIZE
= 9; // ### hardcoded in qcommonstyle.cpp
31 ExpandButton::ExpandButton(QWidget
* parent
)
32 : QToolButton(parent
) {
33 setToolButtonStyle(Qt::ToolButtonTextBesideIcon
);
38 QSize
ExpandButton::sizeHint() const {
39 QSize size
= QToolButton::sizeHint();
40 size
.setWidth(size
.width() + 2*INDICATOR_SIZE
);
41 size
.setHeight(fontMetrics().height());
45 void ExpandButton::paintEvent(QPaintEvent
*) {
46 QStylePainter
painter(this);
49 option
.initFrom(this);
51 // Paint branch indicator
52 // Code comes from Designer, sheet_delegate.cpp
53 QStyleOption branchOption
;
54 QRect r
= option
.rect
;
55 branchOption
.rect
= QRect(r
.left() + INDICATOR_SIZE
/2, r
.top() + (r
.height() - INDICATOR_SIZE
)/2, INDICATOR_SIZE
, INDICATOR_SIZE
);
56 branchOption
.palette
= option
.palette
;
57 branchOption
.state
= QStyle::State_Children
;
60 branchOption
.state
|= QStyle::State_Open
;
63 style()->drawPrimitive(QStyle::PE_IndicatorBranch
, &branchOption
, &painter
, this);
66 QRect textRect
= rect();
67 textRect
.setLeft(INDICATOR_SIZE
* 2);
69 painter
.drawItemText(textRect
, Qt::TextShowMnemonic
| Qt::AlignVCenter
, option
.palette
, isEnabled(), text());