• Skip to content
  • Skip to link menu
KDE 4.1 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, 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     // The applet always keeps its aspect ratio, so let's respect it.
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 

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
  •   libsolidcontrol
  •   libtaskmanager
  • 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