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

« back to all changes in this revision

Viewing changes to plasma/generic/shells/plasma-windowed/singleview.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 2007-2008 Aaron Seigo <aseigo@kde.org>
 
3
 *   Copyright 2009 Marco Martin <notmart@gmail.com>
 
4
 *
 
5
 *   This program is free software; you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU Library General Public License version 2 as
 
7
 *   published by the Free Software Foundation
 
8
 *
 
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
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License 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
 */
 
19
 
 
20
#include "singleview.h"
 
21
 
 
22
#include <QAction>
 
23
#include <QDir>
 
24
#include <QFileInfo>
 
25
 
 
26
#include <KDebug>
 
27
#include <KStandardAction>
 
28
#include <KAction>
 
29
#include <KIconLoader>
 
30
 
 
31
 
 
32
#include <Plasma/Applet>
 
33
#include <Plasma/Containment>
 
34
#include <Plasma/Corona>
 
35
#include <Plasma/PopupApplet>
 
36
#include <Plasma/WindowEffects>
 
37
 
 
38
SingleView::SingleView(Plasma::Corona *corona, Plasma::Containment *containment, const QString &pluginName, int appletId, const QVariantList &appletArgs, QWidget *parent)
 
39
    : QGraphicsView(parent),
 
40
      m_applet(0),
 
41
      m_containment(containment),
 
42
      m_corona(corona)
 
43
{
 
44
    setScene(m_corona);
 
45
    QFileInfo info(pluginName);
 
46
    if (!info.isAbsolute()) {
 
47
        info = QFileInfo(QDir::currentPath() + '/' + pluginName);
 
48
    }
 
49
 
 
50
    if (info.exists()) {
 
51
        m_applet = Plasma::Applet::loadPlasmoid(info.absoluteFilePath(), appletId, appletArgs);
 
52
    }
 
53
 
 
54
    if (!m_applet) {
 
55
        m_applet = Plasma::Applet::load(pluginName, appletId, appletArgs);
 
56
    }
 
57
 
 
58
    if (!m_applet) {
 
59
        kDebug() << "failed to load" << pluginName;
 
60
        return;
 
61
    }
 
62
 
 
63
    m_containment->addApplet(m_applet, QPointF(-1, -1), false);
 
64
    m_containment->resize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
 
65
 
 
66
    m_applet->setPos(0, 0);
 
67
    m_applet->setFlag(QGraphicsItem::ItemIsMovable, false);
 
68
    setSceneRect(m_applet->sceneBoundingRect());
 
69
    setWindowTitle(m_applet->name());
 
70
    setWindowIcon(SmallIcon(m_applet->icon()));
 
71
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
72
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
73
    setFrameStyle(QFrame::NoFrame);
 
74
 
 
75
    QAction *action = m_applet->action("remove");
 
76
    delete action;
 
77
 
 
78
    m_applet->addAction(QString("remove"), KStandardAction::quit(this, SLOT(hide()), m_applet));
 
79
    // enforce the applet being our size
 
80
    connect(m_applet, SIGNAL(geometryChanged()), this, SLOT(updateGeometry()));
 
81
}
 
82
 
 
83
SingleView::~SingleView()
 
84
{
 
85
    m_containment->destroy(false);
 
86
}
 
87
 
 
88
 
 
89
void SingleView::setContainment(Plasma::Containment *c)
 
90
{
 
91
    if (m_containment) {
 
92
        disconnect(m_containment, 0, this, 0);
 
93
    }
 
94
 
 
95
    m_containment = c;
 
96
    updateGeometry();
 
97
}
 
98
 
 
99
 
 
100
void SingleView::resizeEvent(QResizeEvent *event)
 
101
{
 
102
    Q_UNUSED(event)
 
103
    updateGeometry();
 
104
    emit geometryChanged();
 
105
}
 
106
 
 
107
void SingleView::hideEvent(QHideEvent *event)
 
108
{
 
109
    Q_UNUSED(event)
 
110
    if (m_applet) {
 
111
        KConfigGroup dummy;
 
112
        m_containment->save(dummy);
 
113
        emit storeApplet(m_applet);
 
114
        m_applet = 0;
 
115
    }
 
116
 
 
117
    deleteLater();
 
118
}
 
119
 
 
120
Plasma::Applet *SingleView::applet()
 
121
{
 
122
    return m_applet;
 
123
}
 
124
 
 
125
Plasma::Location SingleView::location() const
 
126
{
 
127
    return m_containment->location();
 
128
}
 
129
 
 
130
Plasma::FormFactor SingleView::formFactor() const
 
131
{
 
132
    return m_containment->formFactor();
 
133
}
 
134
 
 
135
void SingleView::updateGeometry()
 
136
{
 
137
    if (!m_containment) {
 
138
        return;
 
139
    }
 
140
 
 
141
    //kDebug() << "New applet geometry is" << m_applet->geometry();
 
142
 
 
143
    if (m_applet && m_applet->size().toSize() != size()) {
 
144
        if (m_applet) {
 
145
            m_applet->resize(size());
 
146
        }
 
147
 
 
148
        setSceneRect(m_applet->sceneBoundingRect());
 
149
 
 
150
    }
 
151
 
 
152
    if ((windowFlags() & Qt::FramelessWindowHint) &&
 
153
            applet()->backgroundHints() != Plasma::Applet::NoBackground) {
 
154
 
 
155
        // TODO: Use the background's mask for blur
 
156
        QRegion mask;
 
157
        mask += QRect(QPoint(), size());
 
158
 
 
159
        Plasma::WindowEffects::enableBlurBehind(winId(), true, mask);
 
160
    }
 
161
}
 
162
 
 
163
#include "singleview.moc"
 
164