1
/* This file is part of the KDE project
2
Copyright (C) 2003-2004 Nadeem Hasan <nhasan@kde.org>
3
Copyright (C) 2004 Aaron J. Seigo <aseigo@kde.org>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU 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 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 GNU
13
General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; see the file COPYING. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
21
#include "hidebutton.h"
25
#include <QResizeEvent>
29
#include <kglobalsettings.h>
30
#include <kiconeffect.h>
31
#include <kiconloader.h>
32
#include <kicontheme.h>
33
#include <kstandarddirs.h>
35
HideButton::HideButton(QWidget *parent)
36
: QAbstractButton(parent),
38
m_arrow(Qt::LeftArrow)
40
setBackgroundOrigin(AncestorOrigin);
42
connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), SLOT(slotSettingsChanged(int)));
43
connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), SLOT(slotIconChanged(int)));
45
slotSettingsChanged(KGlobalSettings::SETTINGS_MOUSE);
48
void HideButton::paintEvent(QPaintEvent*)
50
QPainter painter( this );
51
drawButton( &painter );
54
void HideButton::drawButton(QPainter *p)
56
if (m_arrow == Qt::LeftArrow)
58
p->setPen(palette().color(QPalette::Mid));
59
p->drawLine(width()-1, 0, width()-1, height());
61
else if (m_arrow == Qt::RightArrow)
63
p->setPen(palette().color(QPalette::Mid));
64
p->drawLine(0, 0, 0, height());
66
else if (m_arrow == Qt::UpArrow)
68
p->setPen(palette().color(QPalette::Mid));
69
p->drawLine(0, height()-1, width(), height()-1);
71
else if (m_arrow == Qt::DownArrow)
73
p->setPen(palette().color(QPalette::Mid));
74
p->drawLine(0, 0, width(), 0);
80
void HideButton::drawButtonLabel(QPainter *p)
82
QPixmap pix = m_highlight ? m_activeIcon : m_normalIcon;
84
if (isChecked() || isDown())
93
int ph = pix.height();
97
origin.setY(origin.y() + ((h - ph) / 2));
102
origin.setX(origin.x() + ((w - pw) / 2));
105
p->drawPixmap(origin, pix);
108
void HideButton::setPixmap(const QPixmap &pix)
114
void HideButton::setArrowType(Qt::ArrowType arrow)
120
setPixmap(SmallIcon("arrow-left"));
124
setPixmap(SmallIcon("arrow-right"));
128
setPixmap(SmallIcon("arrow-up"));
133
setPixmap(SmallIcon("arrow-down"));
138
void HideButton::generateIcons()
142
m_normalIcon = QPixmap();
143
m_activeIcon = QPixmap();
147
QPixmap pix = icon().pixmap();
148
pix = pix.scaled(size() - QSize(4, 4), Qt::KeepAspectRatio, Qt::SmoothTransformation);
151
m_normalIcon = effect.apply(pix, KIconLoader::Panel, KIconLoader::DefaultState);
152
m_activeIcon = effect.apply(pix, KIconLoader::Panel, KIconLoader::ActiveState);
155
void HideButton::slotSettingsChanged(int category)
157
if (category != KGlobalSettings::SETTINGS_MOUSE)
162
bool changeCursor = KGlobalSettings::changeCursorOverIcon();
166
setCursor(Qt::PointingHandCursor);
174
void HideButton::slotIconChanged(int group)
176
if (group != KIconLoader::Panel)
185
void HideButton::enterEvent(QEvent *e)
190
QAbstractButton::enterEvent(e);
193
void HideButton::leaveEvent(QEvent *e)
198
QAbstractButton::enterEvent(e);
201
void HideButton::resizeEvent(QResizeEvent *)
206
#include "hidebutton.moc"