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 #include "fullview.h"
00028
00029 #include <plasma/containment.h>
00030 #include <KStandardDirs>
00031 #include <KIconLoader>
00032 #include <QIcon>
00033 #include <QResizeEvent>
00034
00035 using namespace Plasma;
00036
00037 FullView::FullView(const QString &ff, const QString &loc, QWidget *parent)
00038 : QGraphicsView(parent),
00039 m_formfactor(Plasma::Planar),
00040 m_location(Plasma::Floating),
00041 m_containment(0),
00042 m_applet(0)
00043 {
00044 setFrameStyle(QFrame::NoFrame);
00045 QString formfactor = ff.toLower();
00046 if (formfactor.isEmpty() || formfactor == "planar") {
00047 m_formfactor = Plasma::Planar;
00048 } else if (formfactor == "vertical") {
00049 m_formfactor = Plasma::Vertical;
00050 } else if (formfactor == "horizontal") {
00051 m_formfactor = Plasma::Horizontal;
00052 } else if (formfactor == "mediacenter") {
00053 m_formfactor = Plasma::MediaCenter;
00054 }
00055
00056 QString location = loc.toLower();
00057 if (loc.isEmpty() || loc == "floating") {
00058 m_location = Plasma::Floating;
00059 } else if (loc == "desktop") {
00060 m_location = Plasma::Desktop;
00061 } else if (loc == "fullscreen") {
00062 m_location = Plasma::FullScreen;
00063 } else if (loc == "top") {
00064 m_location = Plasma::TopEdge;
00065 } else if (loc == "bottom") {
00066 m_location = Plasma::BottomEdge;
00067 } else if (loc == "right") {
00068 m_location = Plasma::RightEdge;
00069 } else if (loc == "left") {
00070 m_location = Plasma::LeftEdge;
00071 }
00072
00073 setScene(&m_corona);
00074 connect(&m_corona, SIGNAL(sceneRectChanged(QRectF)),
00075 this, SLOT(sceneRectChanged(QRectF)));
00076 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00077 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00078 setAlignment(Qt::AlignLeft | Qt::AlignTop);
00079 }
00080
00081 void FullView::addApplet(const QString &a, const QVariantList &args)
00082 {
00083 m_containment = m_corona.addContainment("null");
00084 m_containment->setFormFactor(m_formfactor);
00085 m_containment->setLocation(m_location);
00086 m_applet = m_containment->addApplet(a, args, QRectF(0, 0, -1, -1));
00087 m_applet->setFlag(QGraphicsItem::ItemIsMovable, false);
00088
00089 setSceneRect(m_corona.sceneRect());
00090 setWindowTitle(m_applet->name());
00091 setWindowIcon(SmallIcon(m_applet->icon()));
00092 }
00093
00094 void FullView::resizeEvent(QResizeEvent *event)
00095 {
00096 QGraphicsView::resizeEvent(event);
00097
00098 if (!m_applet) {
00099 kDebug() << "no applet";
00100 return;
00101 }
00102
00103
00104 qreal newWidth = 0;
00105 qreal newHeight = 0;
00106
00107 if (m_applet->aspectRatioMode() == Plasma::KeepAspectRatio) {
00108 float ratio = event->oldSize().width() / event->oldSize().height();
00109 float newPossibleWidth = size().height() * ratio;
00110 if (newPossibleWidth > size().width()) {
00111 newHeight = size().width() / ratio;
00112 newWidth = newHeight * ratio;
00113 } else {
00114 newWidth = newPossibleWidth;
00115 newHeight = newWidth / ratio;
00116 }
00117 } else {
00118 newWidth = size().width();
00119 newHeight = size().height();
00120 }
00121
00122 m_containment->resize(size());
00123 m_applet->resize(QSizeF(newWidth, newHeight));
00124 }
00125
00126 void FullView::sceneRectChanged(const QRectF &rect)
00127 {
00128 setSceneRect(rect);
00129 }
00130
00131 #include "fullview.moc"
00132