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
|
|
|
|
2008-04-07 11:17:10 +02:00
|
|
|
#include <KGlobal>
|
2008-02-23 00:41:44 +01:00
|
|
|
#include <KWindowSystem>
|
2008-05-17 05:39:24 +02:00
|
|
|
#include <KActionCollection>
|
2008-02-23 00:41:44 +01:00
|
|
|
|
2007-11-15 09:22:58 +01:00
|
|
|
#include "corona.h"
|
|
|
|
#include "containment.h"
|
|
|
|
|
|
|
|
using namespace Plasma;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class ViewPrivate
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
|
|
|
public:
|
2008-07-01 20:56:43 +02:00
|
|
|
ViewPrivate(View *view, int uniqueId)
|
2008-07-06 11:45:31 +02:00
|
|
|
: q(view),
|
|
|
|
containment(0),
|
|
|
|
drawWallpaper(true),
|
2008-04-28 21:14:28 +02:00
|
|
|
trackChanges(true),
|
2008-02-23 00:41:44 +01:00
|
|
|
desktop(-1),
|
2008-06-10 18:57:09 +02:00
|
|
|
viewId(0)
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
2008-06-10 18:57:09 +02:00
|
|
|
if (uniqueId > s_maxViewId) {
|
2008-04-07 11:17:10 +02:00
|
|
|
s_maxViewId = uniqueId;
|
2008-04-08 12:21:11 +02:00
|
|
|
viewId = uniqueId;
|
2008-04-07 11:17:10 +02:00
|
|
|
}
|
2008-06-10 18:57:09 +02:00
|
|
|
|
|
|
|
if (viewId == 0) {
|
|
|
|
// we didn't get a sane value assigned to us, so lets
|
|
|
|
// grab the next available id
|
|
|
|
viewId = ++s_maxViewId;
|
|
|
|
}
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
~ViewPrivate()
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-18 19:40:57 +02:00
|
|
|
void updateSceneRect()
|
|
|
|
{
|
2008-04-28 21:14:28 +02:00
|
|
|
if (!containment || !trackChanges) {
|
2008-04-18 19:40:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
kDebug() << "!!!!!!!!!!!!!!!!! setting the scene rect to"
|
|
|
|
<< containment->sceneBoundingRect()
|
|
|
|
<< "associated screen is" << containment->screen();
|
|
|
|
|
|
|
|
emit q->sceneRectAboutToChange();
|
|
|
|
q->setSceneRect(containment->sceneBoundingRect());
|
|
|
|
emit q->sceneRectChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void initGraphicsView()
|
|
|
|
{
|
|
|
|
q->setFrameShape(QFrame::NoFrame);
|
|
|
|
q->setAutoFillBackground(true);
|
|
|
|
q->setDragMode(QGraphicsView::NoDrag);
|
|
|
|
//setCacheMode(QGraphicsView::CacheBackground);
|
|
|
|
q->setInteractive(true);
|
|
|
|
q->setAcceptDrops(true);
|
|
|
|
q->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
q->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
q->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
}
|
|
|
|
|
2008-07-06 11:45:31 +02:00
|
|
|
Plasma::View *q;
|
|
|
|
Plasma::Containment *containment;
|
2007-11-15 09:22:58 +01:00
|
|
|
bool drawWallpaper;
|
2008-04-28 21:14:28 +02:00
|
|
|
bool trackChanges;
|
2008-02-23 00:41:44 +01:00
|
|
|
int desktop;
|
2008-04-07 11:17:10 +02:00
|
|
|
int viewId;
|
|
|
|
static int s_maxViewId;
|
2007-11-15 09:22:58 +01:00
|
|
|
};
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
int ViewPrivate::s_maxViewId(0);
|
2008-04-07 11:17:10 +02:00
|
|
|
|
2007-11-15 09:22:58 +01:00
|
|
|
View::View(Containment *containment, QWidget *parent)
|
|
|
|
: QGraphicsView(parent),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new ViewPrivate(this, 0))
|
2008-04-07 11:17:10 +02:00
|
|
|
{
|
|
|
|
Q_ASSERT(containment);
|
2008-04-18 19:40:57 +02:00
|
|
|
d->initGraphicsView();
|
2008-04-07 11:17:10 +02:00
|
|
|
setScene(containment->scene());
|
|
|
|
setContainment(containment);
|
|
|
|
}
|
|
|
|
|
|
|
|
View::View(Containment *containment, int viewId, QWidget *parent)
|
|
|
|
: QGraphicsView(parent),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new ViewPrivate(this, viewId))
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
2008-02-23 00:41:44 +01:00
|
|
|
Q_ASSERT(containment);
|
2008-04-18 19:40:57 +02:00
|
|
|
d->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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->containment) {
|
2007-11-16 09:52:09 +01:00
|
|
|
disconnect(d->containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
|
2008-05-17 05:39:24 +02:00
|
|
|
d->containment->removeAssociatedWidget(this);
|
2007-11-16 09:52:09 +01:00
|
|
|
}
|
2007-11-17 21:50:57 +01:00
|
|
|
|
2008-06-30 16:40:59 +02:00
|
|
|
if (!containment) {
|
2008-07-04 22:39:45 +02:00
|
|
|
d->containment = 0;
|
2008-03-31 16:56:55 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-05-17 05:39:24 +02:00
|
|
|
|
2008-07-04 22:39:45 +02:00
|
|
|
Containment *oldContainment = d->containment;
|
|
|
|
|
|
|
|
int screen = -1;
|
|
|
|
if (oldContainment) {
|
|
|
|
screen = d->containment->screen();
|
|
|
|
}
|
|
|
|
|
|
|
|
d->containment = containment;
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
//add keyboard-shortcut actions
|
|
|
|
d->containment->addAssociatedWidget(this);
|
|
|
|
|
2008-06-30 16:40:59 +02:00
|
|
|
int otherScreen = containment->screen();
|
2008-07-04 22:39:45 +02:00
|
|
|
|
|
|
|
if (screen > -1) {
|
|
|
|
containment->setScreen(screen);
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:40:59 +02:00
|
|
|
if (oldContainment && otherScreen > -1) {
|
|
|
|
oldContainment->setScreen(otherScreen);
|
|
|
|
}
|
|
|
|
|
2008-07-04 22:39:45 +02:00
|
|
|
/*
|
|
|
|
if (oldContainment) {
|
|
|
|
kDebug() << (QObject*)oldContainment << screen << oldContainment->screen()
|
|
|
|
<< (QObject*)containment << otherScreen << containment->screen();
|
2008-03-18 00:49:01 +01:00
|
|
|
}
|
2008-07-04 22:39:45 +02:00
|
|
|
*/
|
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
|
|
|
|
2008-04-18 19:40:57 +02:00
|
|
|
d->updateSceneRect();
|
2008-04-14 12:48:32 +02:00
|
|
|
connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment* View::containment() const
|
|
|
|
{
|
|
|
|
return d->containment;
|
|
|
|
}
|
|
|
|
|
2008-04-07 11:17:10 +02:00
|
|
|
KConfigGroup View::config() const
|
|
|
|
{
|
|
|
|
KConfigGroup views(KGlobal::config(), "PlasmaViews");
|
|
|
|
return KConfigGroup(&views, QString::number(d->viewId));
|
|
|
|
}
|
|
|
|
|
|
|
|
int View::id() const
|
|
|
|
{
|
|
|
|
return d->viewId;
|
|
|
|
}
|
|
|
|
|
2008-04-18 19:40:57 +02:00
|
|
|
void View::setWallpaperEnabled(bool draw)
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
|
|
|
d->drawWallpaper = draw;
|
|
|
|
}
|
|
|
|
|
2008-04-18 19:40:57 +02:00
|
|
|
bool View::isWallpaperEnabled() const
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
|
|
|
return d->drawWallpaper;
|
|
|
|
}
|
|
|
|
|
2008-04-28 22:37:10 +02:00
|
|
|
void View::setTrackContainmentChanges(bool trackChanges)
|
|
|
|
{
|
|
|
|
d->trackChanges = trackChanges;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool View::trackContainmentChanges()
|
|
|
|
{
|
|
|
|
return d->trackChanges;
|
|
|
|
}
|
|
|
|
|
2008-05-12 00:02:35 +02:00
|
|
|
View * View::topLevelViewAt(const QPoint & pos)
|
|
|
|
{
|
|
|
|
QWidget *w = QApplication::topLevelAt(pos);
|
|
|
|
if (w) {
|
|
|
|
Plasma::View *v = qobject_cast<Plasma::View *>(w);
|
|
|
|
return v;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-04-28 22:37:10 +02:00
|
|
|
|
2007-11-15 09:22:58 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "view.moc"
|
|
|
|
|