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

libplasma

view.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "view.h"
00021 
00022 #include <KGlobal>
00023 #include <KWindowSystem>
00024 #include <KActionCollection>
00025 
00026 #include "corona.h"
00027 #include "containment.h"
00028 
00029 using namespace Plasma;
00030 
00031 namespace Plasma
00032 {
00033 
00034 class ViewPrivate
00035 {
00036 public:
00037     ViewPrivate(View *view, int uniqueId)
00038         : q(view),
00039           containment(0),
00040           drawWallpaper(true),
00041           trackChanges(true),
00042           desktop(-1),
00043           viewId(0)
00044     {
00045         if (uniqueId > s_maxViewId) {
00046             s_maxViewId = uniqueId;
00047             viewId = uniqueId;
00048         }
00049 
00050         if (viewId == 0) {
00051             // we didn't get a sane value assigned to us, so lets
00052             // grab the next available id
00053             viewId = ++s_maxViewId;
00054         }
00055     }
00056 
00057     ~ViewPrivate()
00058     {
00059     }
00060 
00061     void updateSceneRect()
00062     {
00063         if (!containment || !trackChanges) {
00064             return;
00065         }
00066 
00067         kDebug() << "!!!!!!!!!!!!!!!!! setting the scene rect to"
00068                  << containment->sceneBoundingRect()
00069                  << "associated screen is" << containment->screen();
00070 
00071         emit q->sceneRectAboutToChange();
00072         if (q->transform().isIdentity()) { //we're not zoomed out
00073             q->setSceneRect(containment->sceneBoundingRect());
00074         } else {
00075             //kDebug() << "trying to show the containment nicely";
00076             q->ensureVisible(containment->sceneBoundingRect());
00077             //q->centerOn(containment);
00078         }
00079         emit q->sceneRectChanged();
00080     }
00081 
00082     void initGraphicsView()
00083     {
00084         q->setFrameShape(QFrame::NoFrame);
00085         q->setAutoFillBackground(true);
00086         q->setDragMode(QGraphicsView::NoDrag);
00087         //setCacheMode(QGraphicsView::CacheBackground);
00088         q->setInteractive(true);
00089         q->setAcceptDrops(true);
00090         q->setAlignment(Qt::AlignLeft | Qt::AlignTop);
00091         q->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00092         q->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00093     }
00094 
00095     Plasma::View *q;
00096     Plasma::Containment *containment;
00097     bool drawWallpaper;
00098     bool trackChanges;
00099     int desktop;
00100     int viewId;
00101     static int s_maxViewId;
00102 };
00103 
00104 int ViewPrivate::s_maxViewId(0);
00105 
00106 View::View(Containment *containment, QWidget *parent)
00107     : QGraphicsView(parent),
00108       d(new ViewPrivate(this, 0))
00109 {
00110     Q_ASSERT(containment);
00111     d->initGraphicsView();
00112     setScene(containment->scene());
00113     setContainment(containment);
00114 }
00115 
00116 View::View(Containment *containment, int viewId, QWidget *parent)
00117     : QGraphicsView(parent),
00118       d(new ViewPrivate(this, viewId))
00119 {
00120     Q_ASSERT(containment);
00121     d->initGraphicsView();
00122     setScene(containment->scene());
00123     setContainment(containment);
00124 }
00125 
00126 
00127 View::~View()
00128 {
00129     delete d;
00130 }
00131 
00132 void View::setScreen(int screen)
00133 {
00134     if (screen > -1) {
00135         Corona *corona = qobject_cast<Corona*>(scene());
00136 
00137         if (!corona) {
00138             return;
00139         }
00140 
00141         Containment *containment = corona->containmentForScreen(screen);
00142         if (containment) {
00143             d->containment = 0; //so that we don't end up on the old containment's screen
00144             setContainment(containment);
00145         }
00146     }
00147 }
00148 
00149 int View::screen() const
00150 {
00151     if (d->containment) {
00152         return d->containment->screen();
00153     }
00154 
00155     return -1;
00156 }
00157 
00158 void View::setDesktop(int desktop)
00159 {
00160     // -1 == All desktops
00161     if (desktop < -1 || desktop > KWindowSystem::numberOfDesktops() - 1) {
00162         desktop = -1;
00163     }
00164 
00165     d->desktop = desktop;
00166 }
00167 
00168 int View::desktop() const
00169 {
00170     return d->desktop;
00171 }
00172 
00173 int View::effectiveDesktop() const
00174 {
00175     return d->desktop > -1 ? d->desktop : KWindowSystem::currentDesktop();
00176 }
00177 
00178 void View::setContainment(Containment *containment)
00179 {
00180     if (containment == d->containment) {
00181         return;
00182     }
00183 
00184     if (d->containment) {
00185         disconnect(d->containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
00186         d->containment->removeAssociatedWidget(this);
00187     }
00188 
00189     if (!containment) {
00190         d->containment = 0;
00191         return;
00192     }
00193 
00194     Containment *oldContainment = d->containment;
00195 
00196     int screen = -1;
00197     if (oldContainment) {
00198         screen = d->containment->screen();
00199     }
00200 
00201     d->containment = containment;
00202 
00203     //add keyboard-shortcut actions
00204     d->containment->addAssociatedWidget(this);
00205 
00206     int otherScreen = containment->screen();
00207 
00208     if (screen > -1) {
00209         containment->setScreen(screen);
00210     }
00211 
00212     if (oldContainment && otherScreen > -1) {
00213         oldContainment->setScreen(otherScreen);
00214     }
00215 
00216     /*
00217     if (oldContainment) {
00218         kDebug() << (QObject*)oldContainment << screen << oldContainment->screen()
00219                  << (QObject*)containment << otherScreen << containment->screen();
00220     }
00221     */
00222 
00223     if (containment->screen() > -1 && d->desktop < -1) {
00224         // we want to set it to "all desktops" if we get ownership of
00225         // a screen but don't have a desktop explicitly set
00226         d->desktop = -1;
00227     }
00228 
00229     d->updateSceneRect();
00230     connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
00231 }
00232 
00233 Containment* View::containment() const
00234 {
00235     return d->containment;
00236 }
00237 
00238 KConfigGroup View::config() const
00239 {
00240     KConfigGroup views(KGlobal::config(), "PlasmaViews");
00241     return KConfigGroup(&views, QString::number(d->viewId));
00242 }
00243 
00244 int View::id() const
00245 {
00246     return d->viewId;
00247 }
00248 
00249 void View::setWallpaperEnabled(bool draw)
00250 {
00251     d->drawWallpaper = draw;
00252 }
00253 
00254 bool View::isWallpaperEnabled() const
00255 {
00256     return d->drawWallpaper;
00257 }
00258 
00259 void View::setTrackContainmentChanges(bool trackChanges)
00260 {
00261     d->trackChanges = trackChanges;
00262 }
00263 
00264 bool View::trackContainmentChanges()
00265 {
00266     return d->trackChanges;
00267 }
00268 
00269 View * View::topLevelViewAt(const QPoint & pos)
00270 {
00271     QWidget *w = QApplication::topLevelAt(pos);
00272     if (w) {
00273         Plasma::View *v = qobject_cast<Plasma::View *>(w);
00274         return v;
00275     } else {
00276         return 0;
00277     }
00278 }
00279 
00280 } // namespace Plasma
00281 
00282 #include "view.moc"
00283 

libplasma

Skip menu "libplasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

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