2007-11-15 09:22:58 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "view.h"
|
2008-02-23 00:41:44 +01:00
|
|
|
|
|
|
|
#include <KWindowSystem>
|
|
|
|
|
2007-11-15 09:22:58 +01:00
|
|
|
#include "corona.h"
|
|
|
|
#include "containment.h"
|
|
|
|
|
|
|
|
using namespace Plasma;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class View::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private()
|
|
|
|
: drawWallpaper(true),
|
2008-02-23 00:41:44 +01:00
|
|
|
desktop(-1),
|
2007-11-15 09:22:58 +01:00
|
|
|
containment(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~Private()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool drawWallpaper;
|
2008-02-23 00:41:44 +01:00
|
|
|
int desktop;
|
2007-11-15 09:22:58 +01:00
|
|
|
Plasma::Containment *containment;
|
|
|
|
};
|
|
|
|
|
|
|
|
View::View(Containment *containment, QWidget *parent)
|
|
|
|
: QGraphicsView(parent),
|
|
|
|
d(new Private)
|
|
|
|
{
|
2008-02-23 00:41:44 +01:00
|
|
|
Q_ASSERT(containment);
|
2007-12-30 08:32:48 +01:00
|
|
|
initGraphicsView();
|
2007-11-15 09:22:58 +01:00
|
|
|
setScene(containment->scene());
|
2007-11-15 10:15:53 +01:00
|
|
|
setContainment(containment);
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 08:32:48 +01:00
|
|
|
void View::initGraphicsView()
|
|
|
|
{
|
|
|
|
setFrameShape(QFrame::NoFrame);
|
|
|
|
setAutoFillBackground(true);
|
2008-02-13 03:45:45 +01:00
|
|
|
setDragMode(QGraphicsView::NoDrag);
|
2007-12-30 08:32:48 +01:00
|
|
|
//setCacheMode(QGraphicsView::CacheBackground);
|
|
|
|
setInteractive(true);
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
}
|
|
|
|
|
2007-11-15 09:22:58 +01:00
|
|
|
View::~View()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::setScreen(int screen)
|
|
|
|
{
|
|
|
|
if (screen > -1) {
|
|
|
|
Corona *corona = qobject_cast<Corona*>(scene());
|
|
|
|
|
|
|
|
if (!corona) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-18 00:49:01 +01:00
|
|
|
Containment *containment = corona->containmentForScreen(screen);
|
|
|
|
if (containment) {
|
|
|
|
d->containment = 0; //so that we don't end up on the old containment's screen
|
|
|
|
setContainment(containment);
|
|
|
|
}
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int View::screen() const
|
|
|
|
{
|
2008-03-12 21:40:02 +01:00
|
|
|
if (d->containment) {
|
|
|
|
return d->containment->screen();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2008-02-23 00:41:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::setDesktop(int desktop)
|
|
|
|
{
|
|
|
|
// -1 == All desktops
|
|
|
|
if (desktop < -1 || desktop > KWindowSystem::numberOfDesktops() - 1) {
|
|
|
|
desktop = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->desktop = desktop;
|
|
|
|
}
|
|
|
|
|
|
|
|
int View::desktop() const
|
|
|
|
{
|
|
|
|
return d->desktop;
|
|
|
|
}
|
|
|
|
|
|
|
|
int View::effectiveDesktop() const
|
|
|
|
{
|
|
|
|
return d->desktop > -1 ? d->desktop : KWindowSystem::currentDesktop();
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::setContainment(Containment *containment)
|
|
|
|
{
|
2008-03-31 16:56:55 +02:00
|
|
|
if (containment == d->containment) {
|
2007-11-17 21:50:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-18 00:49:01 +01:00
|
|
|
int screen = -1;
|
|
|
|
|
2007-11-17 21:50:57 +01:00
|
|
|
if (d->containment) {
|
2007-11-16 09:52:09 +01:00
|
|
|
disconnect(d->containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
|
2008-03-18 00:49:01 +01:00
|
|
|
screen = d->containment->screen();
|
2007-11-16 09:52:09 +01:00
|
|
|
}
|
2007-11-17 21:50:57 +01:00
|
|
|
|
2007-11-15 09:22:58 +01:00
|
|
|
d->containment = containment;
|
2008-03-31 16:56:55 +02:00
|
|
|
if (! containment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-18 00:49:01 +01:00
|
|
|
if (screen > -1) {
|
|
|
|
containment->setScreen(screen);
|
|
|
|
}
|
2008-03-12 21:40:02 +01:00
|
|
|
|
2008-03-16 08:19:27 +01:00
|
|
|
if (containment->screen() > -1 && d->desktop < -1) {
|
|
|
|
// we want to set it to "all desktops" if we get ownership of
|
|
|
|
// a screen but don't have a desktop explicitly set
|
|
|
|
d->desktop = -1;
|
2008-03-12 21:40:02 +01:00
|
|
|
}
|
2008-03-16 08:19:27 +01:00
|
|
|
|
|
|
|
updateSceneRect();
|
|
|
|
connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment* View::containment() const
|
|
|
|
{
|
|
|
|
return d->containment;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::setDrawWallpaper(bool draw)
|
|
|
|
{
|
|
|
|
d->drawWallpaper = draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool View::drawWallpaper() const
|
|
|
|
{
|
|
|
|
return d->drawWallpaper;
|
|
|
|
}
|
|
|
|
|
2007-11-15 10:15:53 +01:00
|
|
|
void View::updateSceneRect()
|
|
|
|
{
|
2008-03-12 21:40:02 +01:00
|
|
|
if (!d->containment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-16 08:19:27 +01:00
|
|
|
kDebug() << "!!!!!!!!!!!!!!!!! setting the scene rect to"
|
|
|
|
<< d->containment->sceneBoundingRect()
|
|
|
|
<< "associated screen is" << d->containment->screen();
|
|
|
|
|
2008-03-05 01:02:37 +01:00
|
|
|
emit sceneRectAboutToChange();
|
2007-11-15 10:15:53 +01:00
|
|
|
setSceneRect(d->containment->sceneBoundingRect());
|
2008-03-05 01:02:37 +01:00
|
|
|
emit sceneRectChanged();
|
2007-11-15 10:15:53 +01:00
|
|
|
}
|
|
|
|
|
2007-11-15 09:22:58 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "view.moc"
|
|
|
|
|