2 * Copyright 2007 Frerich Raabe <raabe@kde.org>
3 * Copyright 2007 Aaron Seigo <aseigo@kde.org
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <plasma/containment.h>
30 #include <KStandardDirs>
31 #include <KIconLoader>
33 #include <QResizeEvent>
35 using namespace Plasma
;
37 FullView::FullView(const QString
&ff
, const QString
&loc
, QWidget
*parent
)
38 : QGraphicsView(parent
),
39 m_formfactor(Plasma::Planar
),
40 m_location(Plasma::Floating
),
44 setFrameStyle(QFrame::NoFrame
);
45 QString formfactor
= ff
.toLower();
46 if (formfactor
.isEmpty() || formfactor
== "planar") {
47 m_formfactor
= Plasma::Planar
;
48 } else if (formfactor
== "vertical") {
49 m_formfactor
= Plasma::Vertical
;
50 } else if (formfactor
== "horizontal") {
51 m_formfactor
= Plasma::Horizontal
;
52 } else if (formfactor
== "mediacenter") {
53 m_formfactor
= Plasma::MediaCenter
;
56 QString location
= loc
.toLower();
57 if (loc
.isEmpty() || loc
== "floating") {
58 m_location
= Plasma::Floating
;
59 } else if (loc
== "desktop") {
60 m_location
= Plasma::Desktop
;
61 } else if (loc
== "fullscreen") {
62 m_location
= Plasma::FullScreen
;
63 } else if (loc
== "top") {
64 m_location
= Plasma::TopEdge
;
65 } else if (loc
== "bottom") {
66 m_location
= Plasma::BottomEdge
;
67 } else if (loc
== "right") {
68 m_location
= Plasma::RightEdge
;
69 } else if (loc
== "left") {
70 m_location
= Plasma::LeftEdge
;
74 connect(&m_corona
, SIGNAL(sceneRectChanged(QRectF
)),
75 this, SLOT(sceneRectChanged(QRectF
)));
76 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
77 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
78 setAlignment(Qt::AlignLeft
| Qt::AlignTop
);
81 void FullView::addApplet(const QString
&a
, const QVariantList
&args
)
83 m_containment
= m_corona
.addContainment("null");
84 m_containment
->setFormFactor(m_formfactor
);
85 m_containment
->setLocation(m_location
);
86 m_applet
= m_containment
->addApplet(a
, args
, QRectF(0, 0, -1, -1));
87 m_applet
->setFlag(QGraphicsItem::ItemIsMovable
, false);
89 setSceneRect(m_applet
->geometry());
90 setWindowTitle(m_applet
->name());
91 setWindowIcon(SmallIcon(m_applet
->icon()));
94 void FullView::resizeEvent(QResizeEvent
*event
)
96 QGraphicsView::resizeEvent(event
);
99 kDebug() << "no applet";
103 // The applet always keeps its aspect ratio, so let's respect it.
107 if (m_applet
->aspectRatioMode() == Plasma::KeepAspectRatio
) {
108 float ratio
= event
->oldSize().width() / event
->oldSize().height();
109 float newPossibleWidth
= size().height() * ratio
;
110 if (newPossibleWidth
> size().width()) {
111 newHeight
= size().width() / ratio
;
112 newWidth
= newHeight
* ratio
;
114 newWidth
= newPossibleWidth
;
115 newHeight
= newWidth
/ ratio
;
118 newWidth
= size().width();
119 newHeight
= size().height();
122 m_containment
->resize(size());
123 kDebug() << "New Containment size:" << m_containment
->geometry().width() << m_containment
->geometry().height();
124 m_applet
->resize(QSizeF(newWidth
, newHeight
));
127 void FullView::sceneRectChanged(const QRectF
&rect
)
131 setSceneRect(m_applet
->geometry());
135 //#include "fullview.moc"