Plasma
fullview.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "fullview.h"
00029
00030 #include <Plasma/Containment>
00031 #include <Plasma/Wallpaper>
00032 #include <KStandardDirs>
00033 #include <KIconLoader>
00034 #include <QIcon>
00035 #include <QResizeEvent>
00036
00037 using namespace Plasma;
00038
00039 FullView::FullView(const QString &ff, const QString &loc, QWidget *parent)
00040 : QGraphicsView(parent),
00041 m_formfactor(Plasma::Planar),
00042 m_location(Plasma::Floating),
00043 m_containment(0),
00044 m_applet(0)
00045 {
00046 setFrameStyle(QFrame::NoFrame);
00047 QString formfactor = ff.toLower();
00048 if (formfactor.isEmpty() || formfactor == "planar") {
00049 m_formfactor = Plasma::Planar;
00050 } else if (formfactor == "vertical") {
00051 m_formfactor = Plasma::Vertical;
00052 } else if (formfactor == "horizontal") {
00053 m_formfactor = Plasma::Horizontal;
00054 } else if (formfactor == "mediacenter") {
00055 m_formfactor = Plasma::MediaCenter;
00056 }
00057
00058 QString location = loc.toLower();
00059 if (loc.isEmpty() || loc == "floating") {
00060 m_location = Plasma::Floating;
00061 } else if (loc == "desktop") {
00062 m_location = Plasma::Desktop;
00063 } else if (loc == "fullscreen") {
00064 m_location = Plasma::FullScreen;
00065 } else if (loc == "top") {
00066 m_location = Plasma::TopEdge;
00067 } else if (loc == "bottom") {
00068 m_location = Plasma::BottomEdge;
00069 } else if (loc == "right") {
00070 m_location = Plasma::RightEdge;
00071 } else if (loc == "left") {
00072 m_location = Plasma::LeftEdge;
00073 }
00074
00075 setScene(&m_corona);
00076 connect(&m_corona, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(sceneRectChanged(QRectF)));
00077 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00078 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00079 setAlignment(Qt::AlignLeft | Qt::AlignTop);
00080 }
00081
00082 void FullView::addApplet(const QString &a, const QString &containment, const QString& wallpaper, const QVariantList &args)
00083 {
00084 kDebug() << "adding applet" << a << "in" << containment;
00085 m_containment = m_corona.addContainment(containment);
00086 connect(m_containment, SIGNAL(appletRemoved(Plasma::Applet*)), this, SLOT(appletRemoved()));
00087
00088 if (!wallpaper.isEmpty()) {
00089 m_containment->setWallpaper(wallpaper);
00090 }
00091
00092 m_containment->setFormFactor(m_formfactor);
00093 m_containment->setLocation(m_location);
00094 setScene(m_containment->scene());
00095
00096 m_applet = m_containment->addApplet(a, args, QRectF(0, 0, -1, -1));
00097 m_applet->setFlag(QGraphicsItem::ItemIsMovable, false);
00098
00099 setSceneRect(m_applet->geometry());
00100 setWindowTitle(m_applet->name());
00101 setWindowIcon(SmallIcon(m_applet->icon()));
00102 }
00103
00104 void FullView::appletRemoved()
00105 {
00106 m_applet = 0;
00107 }
00108
00109 void FullView::resizeEvent(QResizeEvent *event)
00110 {
00111 QGraphicsView::resizeEvent(event);
00112
00113 if (!m_applet) {
00114 kDebug() << "no applet";
00115 return;
00116 }
00117
00118
00119 qreal newWidth = 0;
00120 qreal newHeight = 0;
00121
00122 if (m_applet->aspectRatioMode() == Plasma::KeepAspectRatio) {
00123
00124 qreal ratio = m_applet->size().width() / m_applet->size().height();
00125 qreal widthForCurrentHeight = (qreal)size().height() * ratio;
00126 if (widthForCurrentHeight > size().width()) {
00127 newHeight = size().width() / ratio;
00128 newWidth = newHeight * ratio;
00129 } else {
00130 newWidth = widthForCurrentHeight;
00131 newHeight = newWidth / ratio;
00132 }
00133 } else {
00134 newWidth = size().width();
00135 newHeight = size().height();
00136 }
00137 QSizeF newSize(newWidth, newHeight);
00138
00139 m_containment->resize(size());
00140
00141
00142 if (newSize.isValid()) {
00143 m_applet->resize(QSizeF(newWidth, newHeight));
00144 }
00145 }
00146
00147 void FullView::sceneRectChanged(const QRectF &rect)
00148 {
00149 Q_UNUSED(rect)
00150 if (m_applet) {
00151
00152 setSceneRect(m_applet->geometry());
00153 }
00154 }
00155
00156 #include "fullview.moc"
00157