~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/plasmagenericshell/widgetsexplorer/appleticon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2009 by Ana Cecília Martins <anaceciliamb@gmail.com>
 
3
 *   Copyright (C) 2010 by Chani Armitage <chani@kde.org>
 
4
 *
 
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
 
9
 *
 
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
 
14
 *
 
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.
 
19
 */
 
20
 
 
21
#include "appleticon.h"
 
22
 
 
23
#include <KIconLoader>
 
24
#include <KIcon>
 
25
 
 
26
AppletIconWidget::AppletIconWidget(PlasmaAppletItem *appletItem)
 
27
    : AbstractIcon(0),
 
28
      m_runningIcon("dialog-ok")
 
29
{
 
30
    setAppletItem(appletItem);
 
31
}
 
32
 
 
33
AppletIconWidget::~AppletIconWidget()
 
34
{
 
35
}
 
36
 
 
37
PlasmaAppletItem *AppletIconWidget::appletItem()
 
38
{
 
39
    return m_appletItem.data();
 
40
}
 
41
 
 
42
void AppletIconWidget::setAppletItem(PlasmaAppletItem *appletItem)
 
43
{
 
44
    if (m_appletItem) {
 
45
        QStandardItemModel *model = m_appletItem.data()->model();
 
46
        if (model) {
 
47
            disconnect(model, 0, this, 0);
 
48
        }
 
49
    }
 
50
 
 
51
    m_appletItem = appletItem;
 
52
    if (appletItem) {
 
53
        kDebug() << "Applet item!" << appletItem << appletItem->name() << appletItem->model();
 
54
        setName(appletItem->name());
 
55
        QStandardItemModel *model = appletItem->model();
 
56
        if (model) {
 
57
            connect(model, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(itemChanged(QStandardItem*)));
 
58
        }
 
59
    }
 
60
 
 
61
    setDraggable(appletItem);
 
62
    update();
 
63
}
 
64
 
 
65
void AppletIconWidget::itemChanged(QStandardItem *item)
 
66
{
 
67
    if (item == m_appletItem.data()) {
 
68
        update();
 
69
    }
 
70
}
 
71
 
 
72
QPixmap AppletIconWidget::pixmap(const QSize &size)
 
73
{
 
74
    if (m_appletItem) {
 
75
        return appletItem()->icon().pixmap(size);
 
76
    }
 
77
    return QPixmap();
 
78
}
 
79
 
 
80
QMimeData* AppletIconWidget::mimeData()
 
81
{
 
82
    if (m_appletItem) {
 
83
        return m_appletItem.data()->mimeData();
 
84
    }
 
85
    return 0;
 
86
}
 
87
 
 
88
void AppletIconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 
89
{
 
90
    AbstractIcon::paint(painter, option, widget);
 
91
 
 
92
    PlasmaAppletItem *appletItem = m_appletItem.data();
 
93
    if (!appletItem) {
 
94
        return;
 
95
    }
 
96
 
 
97
    const QRectF rect = contentsRect();
 
98
    const int width = rect.width();
 
99
 
 
100
    QRect iconRect(rect.x() + qMax(0, (width / 2) - (iconSize() / 2)), rect.y(), iconSize(), iconSize());
 
101
 
 
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));
 
106
    }
 
107
 
 
108
}
 
109
 
 
110
 
 
111
#include "appleticon.moc"
 
112