2
* Copyright (C) 2009 by Ana Cecília Martins <anaceciliamb@gmail.com>
3
* Copyright (C) 2010 by Chani Armitage <chani@kde.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Library/Lesser General Public License
7
* version 2, or (at your option) any later version, as published by the
8
* Free Software Foundation
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/Lesser General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include "appleticon.h"
23
#include <KIconLoader>
26
AppletIconWidget::AppletIconWidget(PlasmaAppletItem *appletItem)
28
m_runningIcon("dialog-ok")
30
setAppletItem(appletItem);
33
AppletIconWidget::~AppletIconWidget()
37
PlasmaAppletItem *AppletIconWidget::appletItem()
39
return m_appletItem.data();
42
void AppletIconWidget::setAppletItem(PlasmaAppletItem *appletItem)
45
QStandardItemModel *model = m_appletItem.data()->model();
47
disconnect(model, 0, this, 0);
51
m_appletItem = appletItem;
53
kDebug() << "Applet item!" << appletItem << appletItem->name() << appletItem->model();
54
setName(appletItem->name());
55
QStandardItemModel *model = appletItem->model();
57
connect(model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(itemChanged(QStandardItem*)));
61
setDraggable(appletItem);
65
void AppletIconWidget::itemChanged(QStandardItem *item)
67
if (item == m_appletItem.data()) {
72
QPixmap AppletIconWidget::pixmap(const QSize &size)
75
return appletItem()->icon().pixmap(size);
80
QMimeData* AppletIconWidget::mimeData()
83
return m_appletItem.data()->mimeData();
88
void AppletIconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
90
AbstractIcon::paint(painter, option, widget);
92
PlasmaAppletItem *appletItem = m_appletItem.data();
97
const QRectF rect = contentsRect();
98
const int width = rect.width();
100
QRect iconRect(rect.x() + qMax(0, (width / 2) - (iconSize() / 2)), rect.y(), iconSize(), iconSize());
102
if (appletItem->running() > 0) {
103
QSize runningIconSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall);
104
painter->drawPixmap(iconRect.bottomLeft().x(), iconRect.bottomLeft().y() - runningIconSize.height(),
105
m_runningIcon.pixmap(runningIconSize));
111
#include "appleticon.moc"