add view id and config (the latter relying on the former)

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=794394
This commit is contained in:
Aaron J. Seigo 2008-04-07 09:17:10 +00:00
parent 0cee130c4e
commit 30b0cef28a
2 changed files with 67 additions and 3 deletions

View File

@ -19,6 +19,7 @@
#include "view.h"
#include <KGlobal>
#include <KWindowSystem>
#include "corona.h"
@ -32,11 +33,16 @@ namespace Plasma
class View::Private
{
public:
Private()
Private(int uniqueId)
: drawWallpaper(true),
desktop(-1),
containment(0)
{
if (uniqueId == 0) {
viewId = ++s_maxViewId;
} else if (uniqueId > s_maxViewId) {
s_maxViewId = uniqueId;
}
}
~Private()
@ -45,12 +51,26 @@ public:
bool drawWallpaper;
int desktop;
int viewId;
Plasma::Containment *containment;
static int s_maxViewId;
};
int View::Private::s_maxViewId(0);
View::View(Containment *containment, QWidget *parent)
: QGraphicsView(parent),
d(new Private)
d(new Private(0))
{
Q_ASSERT(containment);
initGraphicsView();
setScene(containment->scene());
setContainment(containment);
}
View::View(Containment *containment, int viewId, QWidget *parent)
: QGraphicsView(parent),
d(new Private(viewId))
{
Q_ASSERT(containment);
initGraphicsView();
@ -159,6 +179,17 @@ Containment* View::containment() const
return d->containment;
}
KConfigGroup View::config() const
{
KConfigGroup views(KGlobal::config(), "PlasmaViews");
return KConfigGroup(&views, QString::number(d->viewId));
}
int View::id() const
{
return d->viewId;
}
void View::setDrawWallpaper(bool draw)
{
d->drawWallpaper = draw;

35
view.h
View File

@ -22,6 +22,8 @@
#include <QtGui/QGraphicsView>
#include <KDE/KConfigGroup>
#include <plasma/plasma_export.h>
namespace Plasma
@ -31,14 +33,35 @@ class Containment;
class Corona;
/**
* @short A QGraphicsView for Plasma::Applets
* @short A QGraphicsView for Plasma::Applets. Each View is associated with
* a Plasma::Containment and tracks geometry changes, maps to the current desktop
* (if any) among other helpful utilities. It isn't stricly required to use
* a Plasma::View with Plasma enabled applications, but it can make some
* things easier.
*/
class PLASMA_EXPORT View : public QGraphicsView
{
Q_OBJECT
public:
/**
* Constructs a view for a given contanment. An Id is automatically
* assigned to the View.
*
* @arg containment the containment to center the view on
* @arg parent the parent object for this view
*/
explicit View(Containment *containment, QWidget *parent = 0);
/**
* Constructs a view for a given contanment.
*
* @arg containment the containment to center the view on
* @arg viewId the id to assign to this view
* @arg parent the parent object for this view
*/
View(Containment *containment, int viewId, QWidget *parent = 0);
~View();
/**
@ -101,6 +124,16 @@ public:
*/
Containment* containment() const;
/**
* @return a KConfigGroup for this application unique to the view
*/
KConfigGroup config() const;
/**
* @return the id of the View set in the constructor
*/
int id() const;
Q_SIGNALS:
/**
* This signal is emitted whenever the containment being viewed has