2 * Copyright 2007 Frerich Raabe <raabe@kde.org>
3 * Copyright 2007 Aaron Seigo <aseigo@kde.org>
4 * Copyright 2008 Aleix Pol <aleixpol@gmail.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <Plasma/Containment>
31 #include <Plasma/Wallpaper>
32 #include <KStandardDirs>
33 #include <KIconLoader>
35 #include <QResizeEvent>
37 using namespace Plasma
;
39 FullView::FullView(const QString
&ff
, const QString
&loc
, QWidget
*parent
)
40 : QGraphicsView(parent
),
41 m_formfactor(Plasma::Planar
),
42 m_location(Plasma::Floating
),
46 setFrameStyle(QFrame::NoFrame
);
47 QString formfactor
= ff
.toLower();
48 if (formfactor
.isEmpty() || formfactor
== "planar") {
49 m_formfactor
= Plasma::Planar
;
50 } else if (formfactor
== "vertical") {
51 m_formfactor
= Plasma::Vertical
;
52 } else if (formfactor
== "horizontal") {
53 m_formfactor
= Plasma::Horizontal
;
54 } else if (formfactor
== "mediacenter") {
55 m_formfactor
= Plasma::MediaCenter
;
58 QString location
= loc
.toLower();
59 if (loc
.isEmpty() || loc
== "floating") {
60 m_location
= Plasma::Floating
;
61 } else if (loc
== "desktop") {
62 m_location
= Plasma::Desktop
;
63 } else if (loc
== "fullscreen") {
64 m_location
= Plasma::FullScreen
;
65 } else if (loc
== "top") {
66 m_location
= Plasma::TopEdge
;
67 } else if (loc
== "bottom") {
68 m_location
= Plasma::BottomEdge
;
69 } else if (loc
== "right") {
70 m_location
= Plasma::RightEdge
;
71 } else if (loc
== "left") {
72 m_location
= Plasma::LeftEdge
;
76 connect(&m_corona
, SIGNAL(sceneRectChanged(QRectF
)), this, SLOT(sceneRectChanged(QRectF
)));
77 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
78 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
79 setAlignment(Qt::AlignLeft
| Qt::AlignTop
);
82 void FullView::addApplet(const QString
&a
, const QString
&containment
, const QString
& wallpaper
, const QVariantList
&args
)
84 kDebug() << "adding applet" << a
<< "in" << containment
;
85 m_containment
= m_corona
.addContainment(containment
);
86 connect(m_containment
, SIGNAL(appletRemoved(Plasma::Applet
*)), this, SLOT(appletRemoved()));
88 if (!wallpaper
.isEmpty()) {
89 m_containment
->setWallpaper(wallpaper
);
92 m_containment
->setFormFactor(m_formfactor
);
93 m_containment
->setLocation(m_location
);
94 setScene(m_containment
->scene());
96 m_applet
= m_containment
->addApplet(a
, args
, QRectF(0, 0, -1, -1));
97 m_applet
->setFlag(QGraphicsItem::ItemIsMovable
, false);
99 setSceneRect(m_applet
->geometry());
100 setWindowTitle(m_applet
->name());
101 setWindowIcon(SmallIcon(m_applet
->icon()));
104 void FullView::appletRemoved()
109 void FullView::resizeEvent(QResizeEvent
*event
)
111 QGraphicsView::resizeEvent(event
);
114 kDebug() << "no applet";
118 //kDebug() << size();
122 if (m_applet
->aspectRatioMode() == Plasma::KeepAspectRatio
) {
123 // The applet always keeps its aspect ratio, so let's respect it.
124 qreal ratio
= m_applet
->size().width() / m_applet
->size().height();
125 qreal widthForCurrentHeight
= (qreal
)size().height() * ratio
;
126 if (widthForCurrentHeight
> size().width()) {
127 newHeight
= size().width() / ratio
;
128 newWidth
= newHeight
* ratio
;
130 newWidth
= widthForCurrentHeight
;
131 newHeight
= newWidth
/ ratio
;
134 newWidth
= size().width();
135 newHeight
= size().height();
137 QSizeF
newSize(newWidth
, newHeight
);
139 m_containment
->resize(size());
140 // check if the rect is valid, or else it seems to try to allocate
141 // up to infinity memory in exponential increments
142 if (newSize
.isValid()) {
143 m_applet
->resize(QSizeF(newWidth
, newHeight
));
147 void FullView::sceneRectChanged(const QRectF
&rect
)
151 //kDebug() << m_applet->geometry();
152 setSceneRect(m_applet
->geometry());
156 #include "fullview.moc"