]>
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>
32 SelectionToggle::SelectionToggle(QWidget
* parent
) :
33 QAbstractButton(parent
),
39 parent
->installEventFilter(this);
41 m_icon
= KIconLoader::global()->loadIcon("dialog-ok",
43 KIconLoader::SizeSmall
);
46 SelectionToggle::~SelectionToggle()
50 QSize
SelectionToggle::sizeHint() const
55 void SelectionToggle::reset()
61 void SelectionToggle::setFileItem(const KFileItem
& item
)
69 KFileItem
SelectionToggle::fileItem() const
74 void SelectionToggle::setVisible(bool visible
)
76 QAbstractButton::setVisible(visible
);
85 bool SelectionToggle::eventFilter(QObject
* obj
, QEvent
* event
)
87 if ((obj
== parent()) && (event
->type() == QEvent::Leave
)) {
90 return QAbstractButton::eventFilter(obj
, event
);
93 void SelectionToggle::enterEvent(QEvent
* event
)
95 QAbstractButton::enterEvent(event
);
97 // if the mouse cursor is above the selection toggle, display
98 // it immediately without fading timer
100 if (m_fadingTimeLine
!= 0) {
101 m_fadingTimeLine
->stop();
107 void SelectionToggle::leaveEvent(QEvent
* event
)
109 QAbstractButton::leaveEvent(event
);
114 void SelectionToggle::paintEvent(QPaintEvent
* event
)
116 QPainter
painter(this);
117 painter
.setClipRect(event
->rect());
120 KIconEffect iconEffect
;
121 QPixmap activeIcon
= iconEffect
.apply(m_icon
, KIconLoader::Desktop
, KIconLoader::ActiveState
);
122 painter
.drawPixmap(0, 0, activeIcon
);
124 if (m_fadingValue
< 255) {
125 // apply an alpha mask respecting the fading value to the icon
126 QPixmap icon
= m_icon
;
127 QPixmap
alphaMask(icon
.width(), icon
.height());
128 const QColor
color(m_fadingValue
, m_fadingValue
, m_fadingValue
);
129 alphaMask
.fill(color
);
130 icon
.setAlphaChannel(alphaMask
);
131 painter
.drawPixmap(0, 0, icon
);
133 // no fading is required
134 painter
.drawPixmap(0, 0, m_icon
);
139 void SelectionToggle::setFadingValue(int value
)
141 m_fadingValue
= value
;
142 if (m_fadingValue
>= 255) {
143 Q_ASSERT(m_fadingTimeLine
!= 0);
144 m_fadingTimeLine
->stop();
149 void SelectionToggle::startFading()
151 Q_ASSERT(m_fadingTimeLine
== 0);
153 m_fadingTimeLine
= new QTimeLine(2000, this);
154 connect(m_fadingTimeLine
, SIGNAL(frameChanged(int)),
155 this, SLOT(setFadingValue(int)));
156 m_fadingTimeLine
->setFrameRange(0, 255);
157 m_fadingTimeLine
->start();
161 void SelectionToggle::stopFading()
163 if (m_fadingTimeLine
!= 0) {
164 m_fadingTimeLine
->stop();
165 delete m_fadingTimeLine
;
166 m_fadingTimeLine
= 0;
171 #include "selectiontoggle.moc"