]>
cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistselectiontoggle.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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 "kitemlistselectiontoggle.h"
22 #include <KIconEffect>
23 #include <KIconLoader>
28 KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem
* parent
) :
29 QGraphicsWidget(parent
, 0),
33 setAcceptHoverEvents(true);
36 KItemListSelectionToggle::~KItemListSelectionToggle()
40 void KItemListSelectionToggle::setChecked(bool checked
)
42 if (m_checked
!= checked
) {
49 bool KItemListSelectionToggle::isChecked() const
54 void KItemListSelectionToggle::paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
)
59 if (m_pixmap
.isNull()) {
63 const qreal x
= (size().width() - qreal(m_pixmap
.width())) / 2;
64 const qreal y
= (size().height() - qreal(m_pixmap
.height())) / 2;
65 painter
->drawPixmap(x
, y
, m_pixmap
);
68 void KItemListSelectionToggle::hoverEnterEvent(QGraphicsSceneHoverEvent
* event
)
70 QGraphicsWidget::hoverEnterEvent(event
);
75 void KItemListSelectionToggle::hoverLeaveEvent(QGraphicsSceneHoverEvent
* event
)
77 QGraphicsWidget::hoverLeaveEvent(event
);
82 void KItemListSelectionToggle::updatePixmap()
84 const char* icon
= m_checked
? "list-remove" : "list-add";
86 int iconSize
= qMin(size().width(), size().height());
87 if (iconSize
< KIconLoader::SizeSmallMedium
) {
88 iconSize
= KIconLoader::SizeSmall
;
89 } else if (iconSize
< KIconLoader::SizeMedium
) {
90 iconSize
= KIconLoader::SizeSmallMedium
;
91 } else if (iconSize
< KIconLoader::SizeLarge
) {
92 iconSize
= KIconLoader::SizeMedium
;
93 } else if (iconSize
< KIconLoader::SizeHuge
) {
94 iconSize
= KIconLoader::SizeLarge
;
95 } else if (iconSize
< KIconLoader::SizeEnormous
) {
96 iconSize
= KIconLoader::SizeHuge
;
99 m_pixmap
= KIconLoader::global()->loadIcon(QLatin1String(icon
), KIconLoader::NoGroup
, iconSize
);
102 KIconLoader::global()->iconEffect()->apply(m_pixmap
, KIconLoader::Desktop
, KIconLoader::ActiveState
);
106 #include "kitemlistselectiontoggle.moc"