1
/***************************************************************************
2
* Copyright (C) 2010-2011 by Francesco Cecconi *
3
* francesco.cecconi@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
20
#include "qpushbuttonorientated.h"
22
#include <QtGui/QStylePainter>
23
#include <QtGui/QMenu>
25
QPushButtonOrientated::QPushButtonOrientated(QWidget* parent)
31
QPushButtonOrientated::QPushButtonOrientated(const QString& text, QWidget* parent)
32
: QPushButton(text, parent)
37
QPushButtonOrientated::QPushButtonOrientated(const QIcon& icon, const QString& text, QWidget* parent)
38
: QPushButton(icon, text, parent)
43
QPushButtonOrientated::~QPushButtonOrientated()
47
void QPushButtonOrientated::initObject()
49
_orientation = Qt::Horizontal;
53
Qt::Orientation QPushButtonOrientated::getOrientation() const
58
void QPushButtonOrientated::setOrientation(Qt::Orientation orientation)
60
_orientation = orientation;
64
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
68
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
73
bool QPushButtonOrientated::mirrored() const
78
void QPushButtonOrientated::setMirrored(bool mirrored)
83
QSize QPushButtonOrientated::sizeHint() const
85
QSize size = QPushButton::sizeHint();
87
if (_orientation == Qt::Vertical)
95
QSize QPushButtonOrientated::minimumSizeHint() const
97
QSize size = QPushButton::minimumSizeHint();
99
if (_orientation == Qt::Vertical)
107
void QPushButtonOrientated::paintEvent(QPaintEvent* event)
110
QStylePainter painter(this);
112
switch (_orientation)
118
painter.translate(-width(), -height());
126
painter.translate(-height(), 0);
131
painter.translate(0, -width());
136
painter.drawControl(QStyle::CE_PushButton, getStyleOption());
139
QStyleOptionButton QPushButtonOrientated::getStyleOption() const
141
QStyleOptionButton option;
142
option.initFrom(this);
143
if (_orientation == Qt::Vertical)
145
QSize size = option.rect.size();
147
option.rect.setSize(size);
149
option.features = QStyleOptionButton::None;
153
option.features |= QStyleOptionButton::Flat;
158
option.features |= QStyleOptionButton::HasMenu;
161
if (autoDefault() || isDefault())
163
option.features |= QStyleOptionButton::AutoDefaultButton;
168
option.features |= QStyleOptionButton::DefaultButton;
171
if (isDown() || (menu() && menu()->isVisible()))
173
option.state |= QStyle::State_Sunken;
178
option.state |= QStyle::State_On;
181
if (!isFlat() && !isDown())
183
option.state |= QStyle::State_Raised;
186
option.text = text();
187
option.icon = icon();
188
option.iconSize = iconSize();