1
/***************************************************************************
2
* Copyright (C) 2004 by Alexander Dymo *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU Library General Public License as *
7
* published by the Free Software Foundation; either version 2 of the *
8
* 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 Library General Public *
16
* License along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
25
#include <qapplication.h>
28
#include <kiconloader.h>
30
#include "buttonbar.h"
34
Button::Button(ButtonBar *parent, const QString text, const QIconSet &icon,
35
const QString &description)
36
:QPushButton(icon, text, parent), m_buttonBar(parent), m_description(description),
37
m_place(parent->place()), m_realText(text), m_realIconSet(icon)
41
setToggleButton(true);
42
setFocusPolicy(NoFocus);
43
setDescription(m_description);
44
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
46
fixDimensions(Ideal::Bottom);
48
QToolTip::add(this, m_realText);
53
// m_buttonBar->removeButton(this);
56
void Button::setDescription(const QString &description)
58
m_description = description;
59
QToolTip::remove(this);
60
QToolTip::add(this, m_description);
63
QString Button::description() const
68
void Button::drawButton(QPainter *p)
76
sh.setHeight(r.width());
77
sh.setWidth(r.height());
81
QStyle::SFlags flags = QStyle::Style_Default;
83
flags |= QStyle::Style_Enabled;
85
flags |= QStyle::Style_HasFocus;
87
flags |= QStyle::Style_Down;
89
flags |= QStyle::Style_On;
90
if (! isFlat() && ! isDown())
91
flags |= QStyle::Style_Raised;
93
flags |= QStyle::Style_ButtonDefault;
95
QPixmap pm(sh.width(), sh.height());
96
pm.fill(eraseColor());
99
style().drawControl(QStyle::CE_PushButton,&p2,this, QRect(0,0,pm.width(),pm.height()), colorGroup(),flags);
101
style().drawControl(QStyle::CE_PushButtonLabel, &p2, this,
102
QRect(0,0,pm.width(),pm.height()),
103
colorGroup(), flags, QStyleOption());
109
p->drawPixmap(1-pm.width(), 0, pm);
113
p->drawPixmap(0, 1-pm.height(), pm);
116
p->drawPixmap(0, 0, pm);
121
void Button::drawButtonLabel(QPainter */*p*/)
125
ButtonMode Button::mode()
127
return m_buttonBar->mode();
130
void Button::setPlace(Ideal::Place place)
132
Place oldPlace = m_place;
134
fixDimensions(oldPlace);
137
void Button::fixDimensions(Place oldPlace)
143
if ((oldPlace == Ideal::Bottom) || (oldPlace == Ideal::Top))
145
setFixedWidth(height());
146
setMinimumHeight(sizeHint().width());
147
setMaximumHeight(32767);
152
if ((oldPlace == Ideal::Left) || (oldPlace == Ideal::Right))
154
setFixedHeight(width());
155
setMinimumWidth(sizeHint().height());
156
setMaximumWidth(32767);
162
QSize Button::sizeHint() const
164
return sizeHint(text());
167
QSize Button::sizeHint(const QString &text) const
172
if ( iconSet() && !iconSet()->isNull() && (m_buttonBar->mode() != Text) ) {
173
int iw = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 4;
174
int ih = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height();
178
if ( isMenuButton() )
179
w += style().pixelMetric(QStyle::PM_MenuButtonIndicator, this);
181
QPixmap *pm = (QPixmap *)pixmap();
184
} else if (m_buttonBar->mode() != Icons) {
186
bool empty = s.isEmpty();
188
s = QString::fromLatin1("XXXX");
189
QFontMetrics fm = fontMetrics();
190
QSize sz = fm.size( ShowPrefix, s );
194
h = QMAX(h, sz.height());
197
return (style().sizeFromContents(QStyle::CT_ToolButton, this, QSize(w, h)).
198
expandedTo(QApplication::globalStrut()));
201
void Ideal::Button::updateSize()
207
setMinimumHeight(sizeHint().width());
208
resize(sizeHint().height(), sizeHint().width());
212
resize(sizeHint().width(), sizeHint().height());
217
QString Button::realText() const
222
void Button::setMode(Ideal::ButtonMode mode)
241
void Button::enableIconSet()
245
if (m_realIconSet.isNull())
246
m_realIconSet = SmallIcon("file_new");
247
setIconSet(m_realIconSet);
251
void Button::disableIconSet()
253
setIconSet(QIconSet());
256
void Button::disableText()
258
if (text().length() > 0)
262
void Button::enableText()
269
#include "button.moc"