Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / libs / plasma / view.cpp
blob3b2ec8e20914ef4a6b64f0cf17b42a4a14b5bb79
1 /*
2 * Copyright 2007 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "view.h"
22 #include <KWindowSystem>
24 #include "corona.h"
25 #include "containment.h"
27 using namespace Plasma;
29 namespace Plasma
32 class View::Private
34 public:
35 Private()
36 : drawWallpaper(true),
37 desktop(-1),
38 containment(0)
42 ~Private()
46 bool drawWallpaper;
47 int desktop;
48 Plasma::Containment *containment;
51 View::View(int screen, Corona *corona, QWidget *parent)
52 : QGraphicsView(parent),
53 d(new Private)
55 initGraphicsView();
56 setScene(corona);
57 setScreen(screen);
60 View::View(Containment *containment, QWidget *parent)
61 : QGraphicsView(parent),
62 d(new Private)
64 Q_ASSERT(containment);
65 initGraphicsView();
66 setScene(containment->scene());
67 setContainment(containment);
70 void View::initGraphicsView()
72 setFrameShape(QFrame::NoFrame);
73 setAutoFillBackground(true);
74 setDragMode(QGraphicsView::NoDrag);
75 //setCacheMode(QGraphicsView::CacheBackground);
76 setInteractive(true);
77 setAcceptDrops(true);
78 setAlignment(Qt::AlignLeft | Qt::AlignTop);
79 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
80 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
83 View::~View()
85 delete d;
88 void View::setScreen(int screen)
90 if (screen > -1) {
91 Corona *corona = qobject_cast<Corona*>(scene());
93 if (!corona) {
94 return;
97 setContainment(corona->containmentForScreen(screen));
98 if (d->desktop < -1) {
99 // we want to set it to "all desktops" if we get ownership of
100 // a screen but don't have a desktop set
101 d->desktop = -1;
106 int View::screen() const
108 return d->containment->screen();
111 void View::setDesktop(int desktop)
113 // -1 == All desktops
114 if (desktop < -1 || desktop > KWindowSystem::numberOfDesktops() - 1) {
115 desktop = -1;
118 d->desktop = desktop;
121 int View::desktop() const
123 return d->desktop;
126 int View::effectiveDesktop() const
128 return d->desktop > -1 ? d->desktop : KWindowSystem::currentDesktop();
131 void View::setContainment(Containment *containment)
133 if (!containment) {
134 return;
137 if (d->containment) {
138 disconnect(d->containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
141 d->containment = containment;
142 updateSceneRect();
143 connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
146 Containment* View::containment() const
148 return d->containment;
151 void View::setDrawWallpaper(bool draw)
153 d->drawWallpaper = draw;
156 bool View::drawWallpaper() const
158 return d->drawWallpaper;
161 void View::updateSceneRect()
163 setSceneRect(d->containment->sceneBoundingRect());
166 } // namespace Plasma
168 #include "view.moc"