2
* Copyright 2007-2008 Aaron Seigo <aseigo@kde.org>
3
* Copyright 2009 Marco Martin <notmart@gmail.com>
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
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 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.
20
#include "singleview.h"
27
#include <KStandardAction>
29
#include <KIconLoader>
32
#include <Plasma/Applet>
33
#include <Plasma/Containment>
34
#include <Plasma/Corona>
35
#include <Plasma/PopupApplet>
36
#include <Plasma/WindowEffects>
38
SingleView::SingleView(Plasma::Corona *corona, Plasma::Containment *containment, const QString &pluginName, int appletId, const QVariantList &appletArgs, QWidget *parent)
39
: QGraphicsView(parent),
41
m_containment(containment),
45
QFileInfo info(pluginName);
46
if (!info.isAbsolute()) {
47
info = QFileInfo(QDir::currentPath() + '/' + pluginName);
51
m_applet = Plasma::Applet::loadPlasmoid(info.absoluteFilePath(), appletId, appletArgs);
55
m_applet = Plasma::Applet::load(pluginName, appletId, appletArgs);
59
kDebug() << "failed to load" << pluginName;
63
m_containment->addApplet(m_applet, QPointF(-1, -1), false);
64
m_containment->resize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
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);
75
QAction *action = m_applet->action("remove");
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()));
83
SingleView::~SingleView()
85
m_containment->destroy(false);
89
void SingleView::setContainment(Plasma::Containment *c)
92
disconnect(m_containment, 0, this, 0);
100
void SingleView::resizeEvent(QResizeEvent *event)
104
emit geometryChanged();
107
void SingleView::hideEvent(QHideEvent *event)
112
m_containment->save(dummy);
113
emit storeApplet(m_applet);
120
Plasma::Applet *SingleView::applet()
125
Plasma::Location SingleView::location() const
127
return m_containment->location();
130
Plasma::FormFactor SingleView::formFactor() const
132
return m_containment->formFactor();
135
void SingleView::updateGeometry()
137
if (!m_containment) {
141
//kDebug() << "New applet geometry is" << m_applet->geometry();
143
if (m_applet && m_applet->size().toSize() != size()) {
145
m_applet->resize(size());
148
setSceneRect(m_applet->sceneBoundingRect());
152
if ((windowFlags() & Qt::FramelessWindowHint) &&
153
applet()->backgroundHints() != Plasma::Applet::NoBackground) {
155
// TODO: Use the background's mask for blur
157
mask += QRect(QPoint(), size());
159
Plasma::WindowEffects::enableBlurBehind(winId(), true, mask);
163
#include "singleview.moc"