• Skip to content
  • Skip to link menu
KDE 4.2 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  * Copyright 2008 Aleix Pol <aleixpol@gmail.com>
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00020  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00021  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00022  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00023  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00025  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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     //kDebug() << size();
00119     qreal newWidth = 0;
00120     qreal newHeight = 0;
00121 
00122     if (m_applet->aspectRatioMode() == Plasma::KeepAspectRatio) {
00123         // The applet always keeps its aspect ratio, so let's respect it.
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     // check if the rect is valid, or else it seems to try to allocate
00141     // up to infinity memory in exponential increments
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         //kDebug() << m_applet->geometry();
00152         setSceneRect(m_applet->geometry());
00153     }
00154 }
00155 
00156 #include "fullview.moc"
00157 

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
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
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