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"
|
2008-08-20 10:07:09 +02:00
|
|
|
#include "wallpaper.h"
|
2007-11-15 09:22:58 +01:00
|
|
|
|
|
|
|
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();
|
2008-07-28 00:38:58 +02:00
|
|
|
if (q->transform().isIdentity()) { //we're not zoomed out
|
|
|
|
q->setSceneRect(containment->sceneBoundingRect());
|
|
|
|
} else {
|
|
|
|
//kDebug() << "trying to show the containment nicely";
|
|
|
|
q->ensureVisible(containment->sceneBoundingRect());
|
|
|
|
//q->centerOn(containment);
|
|
|
|
}
|
2008-04-18 19:40:57 +02:00
|
|
|
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
|
|
|
{
|
2008-04-18 19:40:57 +02:00
|
|
|
d->initGraphicsView();
|
2008-08-25 21:25:15 +02:00
|
|
|
|
|
|
|
if (containment) {
|
|
|
|
setScene(containment->scene());
|
|
|
|
setContainment(containment);
|
|
|
|
}
|
2008-04-07 11:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-04-18 19:40:57 +02:00
|
|
|
d->initGraphicsView();
|
2008-08-25 21:25:15 +02:00
|
|
|
|
|
|
|
if (containment) {
|
|
|
|
setScene(containment->scene());
|
|
|
|
setContainment(containment);
|
|
|
|
}
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
View::~View()
|
|
|
|
{
|
|
|
|
delete d;
|
2008-08-21 12:22:32 +02:00
|
|
|
// FIXME FIX a focus crash but i wasn't able to reproduce in a simple test case for Qt guys
|
2008-08-23 23:59:27 +02:00
|
|
|
// NB: this is also done in Corona
|
2008-08-21 12:22:32 +02:00
|
|
|
clearFocus();
|
2007-11-15 09:22:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-08-25 15:16:31 +02:00
|
|
|
void View::setContainment(Plasma::Containment *containment)
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
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();
|
2008-08-25 21:25:15 +02:00
|
|
|
} else {
|
|
|
|
setScene(containment->scene());
|
2008-07-04 22:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
Containment *View::containment() const
|
2007-11-15 09:22:58 +01:00
|
|
|
{
|
|
|
|
return d->containment;
|
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
Containment *View::swapContainment(const QString &name, const QVariantList &args)
|
2008-08-20 10:07:09 +02:00
|
|
|
{
|
2008-08-20 15:13:03 +02:00
|
|
|
Containment *old = d->containment;
|
2008-10-11 18:19:04 +02:00
|
|
|
Plasma::Corona *corona = old->corona();
|
2008-08-20 10:07:09 +02:00
|
|
|
Plasma::Containment *c = corona->addContainment(name, args);
|
|
|
|
if (c) {
|
2008-08-24 09:43:04 +02:00
|
|
|
KConfigGroup oldConfig = old->config();
|
|
|
|
KConfigGroup newConfig = c->config();
|
|
|
|
|
2008-08-20 15:13:03 +02:00
|
|
|
// ensure that the old containments configuration is up to date
|
2008-08-24 09:43:04 +02:00
|
|
|
old->save(oldConfig);
|
|
|
|
|
|
|
|
// set our containment to the new one
|
|
|
|
setContainment(c);
|
|
|
|
|
|
|
|
// Copy configuration to new containment
|
|
|
|
oldConfig.copyTo(&newConfig);
|
2008-08-20 15:13:03 +02:00
|
|
|
|
|
|
|
// load the configuration of the old containment into the new one
|
2008-08-24 09:43:04 +02:00
|
|
|
c->restore(newConfig);
|
2008-10-11 18:19:04 +02:00
|
|
|
foreach (Applet *applet, c->applets()) {
|
2008-08-25 14:44:03 +02:00
|
|
|
applet->init();
|
|
|
|
// We have to flush the applet constraints manually
|
|
|
|
applet->flushPendingConstraintsEvents();
|
2008-08-20 10:07:09 +02:00
|
|
|
}
|
2008-08-20 15:13:03 +02:00
|
|
|
|
|
|
|
// destroy the old one
|
2008-08-21 04:57:42 +02:00
|
|
|
old->destroy(false);
|
2008-08-20 15:13:03 +02:00
|
|
|
|
|
|
|
// and now save the config
|
2008-08-24 09:43:04 +02:00
|
|
|
c->save(newConfig);
|
2008-08-20 15:13:03 +02:00
|
|
|
corona->requestConfigSync();
|
|
|
|
|
2008-08-20 10:07:09 +02:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
|