a common view class
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=736997
This commit is contained in:
parent
3b6b25445d
commit
030ca6d6d2
@ -42,6 +42,7 @@ set(plasma_LIB_SRCS
|
||||
svg.cpp
|
||||
theme.cpp
|
||||
uiloader.cpp
|
||||
view.cpp
|
||||
widgets/boxlayout.cpp
|
||||
widgets/borderlayout.cpp
|
||||
widgets/checkbox.cpp
|
||||
@ -118,7 +119,8 @@ set(plasma_LIB_INCLUDES
|
||||
shadowitem_p.h
|
||||
svg.h
|
||||
theme.h
|
||||
uiloader.h)
|
||||
uiloader.h
|
||||
view.h)
|
||||
|
||||
if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
|
||||
set(plasma_LIB_INCLUDES
|
||||
@ -157,7 +159,9 @@ install(FILES
|
||||
install(FILES
|
||||
includes/AbstractRunner
|
||||
includes/Applet
|
||||
includes/AppletBrowser
|
||||
includes/ConfigXml
|
||||
includes/Containment
|
||||
includes/Phase
|
||||
includes/Plasma
|
||||
includes/Package
|
||||
@ -170,8 +174,7 @@ install(FILES
|
||||
includes/Svg
|
||||
includes/UiLoader
|
||||
includes/PackageMetadata
|
||||
includes/Containment
|
||||
includes/AppletBrowser
|
||||
includes/View
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/KDE/Plasma)
|
||||
|
||||
if(QT_QTOPENGL_FOUND AND OPENGL_FOUND)
|
||||
|
126
view.cpp
Normal file
126
view.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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"
|
||||
#include "corona.h"
|
||||
#include "containment.h"
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class View::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: drawWallpaper(true),
|
||||
screen(-1),
|
||||
containment(0)
|
||||
{
|
||||
}
|
||||
|
||||
~Private()
|
||||
{
|
||||
}
|
||||
|
||||
bool drawWallpaper;
|
||||
int screen;
|
||||
Plasma::Containment *containment;
|
||||
};
|
||||
|
||||
View::View(int screen, Corona *corona, QWidget *parent)
|
||||
: QGraphicsView(parent),
|
||||
d(new Private)
|
||||
{
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setAutoFillBackground(true);
|
||||
setDragMode(QGraphicsView::RubberBandDrag);
|
||||
//setCacheMode(QGraphicsView::CacheBackground);
|
||||
setInteractive(true);
|
||||
setAcceptDrops(true);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
setScene(corona);
|
||||
setScreen(screen);
|
||||
}
|
||||
|
||||
View::View(Containment *containment, QWidget *parent)
|
||||
: QGraphicsView(parent),
|
||||
d(new Private)
|
||||
{
|
||||
d->containment = containment;
|
||||
setScene(containment->scene());
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void View::setScreen(int screen)
|
||||
{
|
||||
if (screen > -1) {
|
||||
Corona *corona = qobject_cast<Corona*>(scene());
|
||||
|
||||
if (!corona) {
|
||||
return;
|
||||
}
|
||||
|
||||
setContainment(corona->containmentForScreen(screen));
|
||||
} else {
|
||||
// reseting the screen who knows what.
|
||||
d->screen = screen;
|
||||
}
|
||||
}
|
||||
|
||||
int View::screen() const
|
||||
{
|
||||
return d->screen;
|
||||
}
|
||||
|
||||
void View::setContainment(Containment *containment)
|
||||
{
|
||||
disconnect(d->containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
|
||||
d->containment = containment;
|
||||
d->screen = containment->screen();
|
||||
setSceneRect(containment->geometry());
|
||||
connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
|
||||
}
|
||||
|
||||
Containment* View::containment() const
|
||||
{
|
||||
return d->containment;
|
||||
}
|
||||
|
||||
void View::setDrawWallpaper(bool draw)
|
||||
{
|
||||
d->drawWallpaper = draw;
|
||||
}
|
||||
|
||||
bool View::drawWallpaper() const
|
||||
{
|
||||
return d->drawWallpaper;
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "view.moc"
|
||||
|
93
view.h
Normal file
93
view.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef VIEW_H
|
||||
#define VIEW_H
|
||||
|
||||
#include <QtGui/QGraphicsView>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Containment;
|
||||
class Corona;
|
||||
|
||||
/**
|
||||
* @short A QGraphicsScene for Plasma::Applets
|
||||
*/
|
||||
class PLASMA_EXPORT View : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
View(int screen, Corona *corona, QWidget *parent = 0);
|
||||
explicit View(Containment *containment, QWidget *parent = 0);
|
||||
~View();
|
||||
|
||||
/**
|
||||
* Sets whether or not to draw the containment wallpaper when painting
|
||||
* on this item
|
||||
*/
|
||||
void setDrawWallpaper(bool draw);
|
||||
|
||||
/**
|
||||
* @return whether or not containments should draw wallpaper
|
||||
*/
|
||||
bool drawWallpaper() const;
|
||||
|
||||
/**
|
||||
* Sets which screen this view is associated with, if any.
|
||||
* This will also set the containment if a valid screen is specified
|
||||
*
|
||||
* @arg screen the xinerama screen number; -1 for no screen
|
||||
*/
|
||||
void setScreen(int screen);
|
||||
|
||||
/**
|
||||
* Returns the screen this view is associated with
|
||||
*
|
||||
* @return the xinerama screen number, or -1 for none
|
||||
*/
|
||||
int screen() const;
|
||||
|
||||
/**
|
||||
* Sets the containment for this view, which will also cause the view
|
||||
* to track the geometry of the containment.
|
||||
*
|
||||
* @arg containment the containment to center the view on
|
||||
*/
|
||||
void setContainment(Containment *containment);
|
||||
|
||||
/**
|
||||
* @return the containment associated with this view, or 0 if none is
|
||||
*/
|
||||
Containment* containment() const;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private * const d;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user