• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

fullview.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2007 Frerich Raabe <raabe@kde.org>
00003  * Copyright 2007 Aaron Seigo <aseigo@kde.org
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00017  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00018  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00019  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00020  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00021  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00022  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00024  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         // TODO Can we give a better error message somehow?
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     // The applet always keeps its aspect ratio, so let's respect it.
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 //    kDebug() << "oooooooooooooooooo";
00105 
00106     event->accept();
00107 
00108 //     m_containment->resize(size());
00109 //     m_applet->setGeometry(QRectF(QPoint(0, 0), size()));
00110 }
00111 
00112 void FullView::sceneRectChanged(const QRectF &rect)
00113 {
00114     setSceneRect(rect);
00115 }
00116 
00117 #include "fullview.moc"
00118 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal