]>
cloud.milkyroute.net Git - dolphin.git/blob - src/selectiontoggle.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "selectiontoggle.h"
23 #include <kiconloader.h>
24 #include <kiconeffect.h>
27 #include <QPaintEvent>
33 SelectionToggle::SelectionToggle(QWidget
* parent
) :
34 QAbstractButton(parent
),
40 parent
->installEventFilter(this);
42 m_icon
= KIconLoader::global()->loadIcon("dialog-ok",
44 KIconLoader::SizeSmall
);
45 m_timer
= new QTimer(this);
46 connect(m_timer
, SIGNAL(timeout()),
47 this, SLOT(showIcon()));
50 SelectionToggle::~SelectionToggle()
54 QSize
SelectionToggle::sizeHint() const
59 void SelectionToggle::setVisible(bool visible
)
61 QAbstractButton::setVisible(visible
);
70 bool SelectionToggle::eventFilter(QObject
* obj
, QEvent
* event
)
72 if ((obj
== parent()) && (event
->type() == QEvent::Leave
)) {
75 return QAbstractButton::eventFilter(obj
, event
);
78 void SelectionToggle::enterEvent(QEvent
* event
)
80 QAbstractButton::enterEvent(event
);
86 void SelectionToggle::leaveEvent(QEvent
* event
)
88 QAbstractButton::leaveEvent(event
);
93 void SelectionToggle::paintEvent(QPaintEvent
* event
)
95 QPainter
painter(this);
96 painter
.setClipRect(event
->rect());
99 KIconEffect iconEffect
;
100 QPixmap activeIcon
= iconEffect
.apply(m_icon
, KIconLoader::Desktop
, KIconLoader::ActiveState
);
101 painter
.drawPixmap(0, 0, activeIcon
);
102 } else if (m_showIcon
) {
103 painter
.drawPixmap(0, 0, m_icon
);
107 void SelectionToggle::showIcon()
113 #include "selectiontoggle.moc"