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, QWidget *parent)
00038 : QGraphicsView(parent),
00039 m_formfactor(Plasma::Planar),
00040 m_containment(0),
00041 m_applet(0)
00042 {
00043 QString formfactor = ff.toLower();
00044 if (formfactor.isEmpty() || formfactor == "planar") {
00045 m_formfactor = Plasma::Planar;
00046 } else if (formfactor == "vertical") {
00047 m_formfactor = Plasma::Vertical;
00048 } else if (formfactor == "horizontal") {
00049 m_formfactor = Plasma::Horizontal;
00050 } else if (formfactor == "mediacenter") {
00051 m_formfactor = Plasma::MediaCenter;
00052 }
00053
00054 setScene(&m_corona);
00055 connect(&m_corona, SIGNAL(sceneRectChanged(QRectF)),
00056 this, SLOT(sceneRectChanged(QRectF)));
00057 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00058 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00059 setAlignment(Qt::AlignLeft | Qt::AlignTop);
00060
00061 QPixmap bg(KStandardDirs::locate("appdata", "checker.png"));
00062 m_corona.setBackgroundBrush(bg);
00063 }
00064
00065 void FullView::addApplet(const QString &a)
00066 {
00067 m_containment = m_corona.addContainment("null");
00068 m_containment->setFormFactor(m_formfactor);
00069 m_applet = m_containment->addApplet(a, QVariantList(),
00070 0, QRectF(0, 0, -1, -1));
00071 m_applet->setFlag(QGraphicsItem::ItemIsMovable, false);
00072 if (m_applet->failedToLaunch()) {
00073
00074 m_applet->setFailedToLaunch(true,
00075 i18n("The applet '%1' could not be loaded", a));
00076 }
00077
00078 setSceneRect(m_corona.sceneRect());
00079 setWindowTitle(m_applet->name());
00080 setWindowIcon(SmallIcon(m_applet->icon()));
00081 }
00082
00083 void FullView::resizeEvent(QResizeEvent *event)
00084 {
00085 if (!m_applet) {
00086 kDebug() << "no applet";
00087 return;
00088 }
00089
00090
00091 float ratio = event->oldSize().width() / event->oldSize().height();
00092 float newPossibleWidth = size().height()*ratio;
00093 int newWidth;
00094 int newHeight;
00095 if (newPossibleWidth > size().width()) {
00096 newHeight = (int)(size().width()/ratio);
00097 newWidth = (int)(newHeight*ratio);
00098 } else {
00099 newWidth = (int)newPossibleWidth;
00100 newHeight = (int)(newWidth/ratio);
00101 }
00102 m_containment->resize(QSize(newWidth, newHeight));
00103 m_applet->setGeometry(QRectF(QPoint(0, 0), QSize(newWidth, newHeight)));
00104
00105
00106 event->accept();
00107
00108
00109
00110 }
00111
00112 void FullView::sceneRectChanged(const QRectF &rect)
00113 {
00114 setSceneRect(rect);
00115 }
00116
00117 #include "fullview.moc"
00118