[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/plasma/plasma
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2007-05-31 22:17:58
Message-ID: 1180649878.916609.2567.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 670270 by aseigo:
Corona was a View but had lots of model stuff in it; besides being "wrong" this \
complicated a lot of things like how to get constraint information to the applets. so \
now Corona is a Scene and the View stuff has been moved to the new CoronaView class.
M +1 -0 CMakeLists.txt
M +113 -96 corona.cpp
M +21 -22 corona.h
A coronaview.cpp [License: LGPL (v2)]
A coronaview.h [License: LGPL (v2)]
M +8 -5 rootwidget.cpp
M +2 -2 rootwidget.h
--- trunk/KDE/kdebase/workspace/plasma/plasma/CMakeLists.txt #670269:670270
@@ -3,6 +3,7 @@
set(plasma_SRCS
controlbox.cpp
corona.cpp
+ coronaview.cpp
main.cpp
plasmaapp.cpp
rootwidget.cpp
--- trunk/KDE/kdebase/workspace/plasma/plasma/corona.cpp #670269:670270
@@ -19,27 +19,25 @@
#include "corona.h"
-#include <QGraphicsView>
-#include <QGraphicsScene>
-#include <QVBoxLayout>
+#include <QApplication>
#include <QDesktopWidget>
-#include <QApplication>
-#include <QDebug>
-#include <QGLWidget>
+#include <QGraphicsSceneDragDropEvent>
+#include <QMimeData>
#include <QProcess>
-#include <QContextMenuEvent>
+
+#include <KLocale>
+#include <KMenu>
#include <KWindowSystem>
-#include <KMenu>
-#include <KLocale>
-#include <KLibrary>
-#include <KLibLoader>
-#include <QFile>
-
#include "applet.h"
#include "dataengine.h"
-#include "svg.h"
#include "widgets/vboxlayout.h"
+
+#ifdef ICON_DEMO
+#include "widgets/icon.h"
+#endif
+
+#include "corona.h"
#include "plasmaapp.h"
using namespace Plasma;
@@ -47,34 +45,71 @@
typedef QGraphicsItem* (*loadKaramba)(const KUrl &theme, QGraphicsView *view);
}
-Corona::Corona(QWidget *parent)
- : QGraphicsView(parent),
- m_formFactor(Plasma::Planar),
- m_location(Plasma::Floating),
- m_layout(0)
+namespace Plasma
{
- setFrameShape(QFrame::NoFrame);
+
+class Corona::Private
+{
+public:
+ Private()
+ : formFactor(Planar),
+ location(Floating),
+ layout(0),
+ engineExplorerAction(0)
+ {
+ }
+
+ Applet::List applets;
+ FormFactor formFactor;
+ Location location;
+ Layout* layout;
+ QAction *engineExplorerAction;
+};
+
+Corona::Corona(QObject * parent)
+ : QGraphicsScene(parent),
+ d(new Private)
+{
+ init();
+}
+
+Corona::Corona(const QRectF & sceneRect, QObject * parent )
+ : QGraphicsScene(sceneRect, parent),
+ d(new Private)
+{
+ init();
+}
+
+Corona::Corona(qreal x, qreal y, qreal width, qreal height, QObject * parent)
+ : QGraphicsScene(x, y, width, height, parent),
+ d(new Private)
+{
+ init();
+}
+
+void Corona::init()
+{
/* setBackgroundMode(Qt::NoBackground);*/
- setAutoFillBackground(true);
/* QPalette pal = palette();
pal.setBrush(QPalette::Base, Qt::transparent);
setPalette(pal);*/
//setViewport(new QGLWidget ( QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel) \
));
- m_graphicsScene = new QGraphicsScene(rect());
- m_graphicsScene->setItemIndexMethod(QGraphicsScene::NoIndex);
- setScene(m_graphicsScene);
- setDragMode(QGraphicsView::RubberBandDrag);
- setCacheMode(QGraphicsView::CacheBackground);
- setInteractive(true);
- setAcceptDrops(true);
+#ifdef ICON_DEMO
+ Icon* icon = new Icon();
+ icon->setIcon("plasmagik");
+ icon->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ addItem(icon);
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-
+ icon = new Icon();
+ icon->setIcon("user-home");
+ icon->setSize(64, 64);
+ icon->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ addItem(icon);
+#endif
/*
- KPluginInfo::List applets = Plasma::Applet::knownApplets();
+ KPluginInfo::List applets = Applet::knownApplets();
kDebug() << "======= Applets =========" << endl;
foreach (KPluginInfo* info, applets) {
kDebug() << info->pluginName() << ": " << info->name() << endl;
@@ -99,71 +134,61 @@
}
*/
- m_background = new Plasma::Svg("background/dialog", this);
-
- connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, \
SLOT(displayContextMenu(QPoint)));
- m_engineExplorerAction = new QAction(i18n("Engine Explorer"), this);
- connect(m_engineExplorerAction, SIGNAL(triggered(bool)), this, \
SLOT(launchExplorer(bool)));
- setContextMenuPolicy(Qt::CustomContextMenu);
+// connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, \
SLOT(displayContextMenu(QPoint))); + d->engineExplorerAction = new \
QAction(i18n("Engine Explorer"), this); + connect(d->engineExplorerAction, \
SIGNAL(triggered(bool)), this, SLOT(launchExplorer(bool))); +// \
setContextMenuPolicy(Qt::CustomContextMenu); }
Corona::~Corona()
{
- while(!m_applets.isEmpty())
- delete m_applets.takeFirst();
+ while (!d->applets.isEmpty()) {
+ delete d->applets.takeFirst();
+ }
}
-Plasma::Location Corona::location() const
+Location Corona::location() const
{
- return m_location;
+ return d->location;
}
-void Corona::setLocation(Plasma::Location location)
+void Corona::setLocation(Location location)
{
- m_location = location;
+ d->location = location;
}
-Plasma::FormFactor Corona::formFactor() const
+FormFactor Corona::formFactor() const
{
- return m_formFactor;
+ return d->formFactor;
}
-void Corona::setFormFactor(Plasma::FormFactor formFactor)
+void Corona::setFormFactor(FormFactor formFactor)
{
- if (m_formFactor == formFactor) {
+ if (d->formFactor == formFactor) {
return;
}
- m_formFactor = formFactor;
- delete m_layout;
- m_layout = 0;
+ d->formFactor = formFactor;
+ delete d->layout;
+ d->layout = 0;
- switch (m_formFactor) {
- case Plasma::Planar:
+ switch (d->formFactor) {
+ case Planar:
break;
- case Plasma::Horizontal:
- //m_layout = new Plasma::HBoxLayout;
+ case Horizontal:
+ //d->layout = new HBoxLayout;
break;
- case Plasma::Vertical:
- m_layout = new Plasma::VBoxLayout;
+ case Vertical:
+ d->layout = new VBoxLayout;
break;
- case Plasma::MediaCenter:
+ case MediaCenter:
break;
default:
kDebug() << "This can't be happening!" << endl;
break;
}
- if (!m_layout) {
- return;
- }
-
- foreach (Applet* applet, m_applets) {
- //FIXME: the applet needs a way to query for its constraints
- // currently there is no framework for this!
- // so we tell them the constraints are updated, and they should
- // in turn query for what they are and do any layouting changes
- // they need to.....
+ foreach (Applet* applet, d->applets) {
applet->constraintsUpdated();
}
}
@@ -171,30 +196,18 @@
void Corona::addPlasmoid(const QString& name)
{
- Plasma::Applet* applet = Plasma::Applet::loadApplet(name);
+ Applet* applet = Applet::loadApplet(name);
if (applet) {
- m_graphicsScene->addItem(applet);
- m_applets << applet;
+ addItem(applet);
+ d->applets << applet;
} else {
kDebug() << "Plasmoid " << name << " could not be loaded." << endl;
}
}
-void Corona::drawBackground(QPainter * painter, const QRectF &)
+void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event)
{
- m_background->paint(painter, rect());
-}
-
-void Corona::resizeEvent(QResizeEvent* event)
-{
- Q_UNUSED(event);
- m_graphicsScene->setSceneRect(rect());
- m_background->resize(width(), height());
-}
-
-void Corona::dragEnterEvent(QDragEnterEvent* event)
-{
- kDebug() << "Corona::dragEnterEvent(QDragEnterEvent* event)" << endl;
+ kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)" << \
endl; if (event->mimeData()->hasFormat("text/x-plasmoidservicename")) {
event->acceptProposedAction();
//TODO Create the applet, move to mouse position then send the
@@ -206,35 +219,37 @@
// keeping its settings etc.
}
-void Corona::dragLeaveEvent(QDragLeaveEvent* event)
+void Corona::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
- kDebug() << "Corona::dragLeaveEvent(QDragLeaveEvent* event)" << endl;
+ Q_UNUSED(event);
+ kDebug() << "Corona::dragLeaveEvent(QGraphicsSceneDragDropEvent* event)" << \
endl;
//TODO If an established Applet is dragged out of the Corona, remove it and
// create a QDrag type thing to keep the Applet's settings
}
-void Corona::dragMoveEvent(QDragMoveEvent* event)
+void Corona::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
+ Q_UNUSED(event);
kDebug() << "Corona::dragMoveEvent(QDragMoveEvent* event)" << endl;
}
-void Corona::dropEvent(QDropEvent* event)
+void Corona::dropEvent(QGraphicsSceneDragDropEvent *event)
{
kDebug() << "Corona::dropEvent(QDropEvent* event)" << endl;
if (event->mimeData()->hasFormat("text/x-plasmoidservicename")) {
//TODO This will pretty much move into dragEnterEvent()
QString plasmoidName;
plasmoidName = event->mimeData()->data("text/x-plasmoidservicename");
- kDebug() << acceptDrops() << endl;
addPlasmoid(plasmoidName);
- m_applets.last()->setPos(event->pos());
+ d->applets.last()->setPos(event->pos());
event->acceptProposedAction();
}
}
-void Corona::displayContextMenu(const QPoint& point)
+void Corona::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
{
+ QPointF point = contextMenuEvent->pos();
/*
* example for displaying the SuperKaramba context menu
QGraphicsItem *item = itemAt(point);
@@ -248,14 +263,14 @@
}
*/
- Plasma::Applet* applet = qgraphicsitem_cast<Plasma::Applet*>( itemAt( point ) );
- KMenu desktopMenu(this);
+ Applet* applet = qgraphicsitem_cast<Applet*>(itemAt(point));
+ KMenu desktopMenu;
if(!applet) {
desktopMenu.setTitle("Corona");
desktopMenu.addAction("The");
desktopMenu.addAction("desktop");
desktopMenu.addAction("menu");
- desktopMenu.addAction(m_engineExplorerAction);
+ desktopMenu.addAction(d->engineExplorerAction);
} else {
//desktopMenu.setTitle( applet->name() ); //This isn't implemented in Applet \
yet... desktopMenu.addAction("Widget");
@@ -268,7 +283,7 @@
applet, SLOT(configureDialog())); //This isn't implemented in Applet \
yet... desktopMenu.addAction(configureApplet);
}
- desktopMenu.exec(point);
+ desktopMenu.exec(point.toPoint());
}
void Corona::launchExplorer(bool /*param*/)
@@ -276,5 +291,7 @@
QProcess::execute("plasmaengineexplorer");
}
+} // namespace Plasma
+
#include "corona.moc"
--- trunk/KDE/kdebase/workspace/plasma/plasma/corona.h #670269:670270
@@ -19,29 +19,33 @@
#ifndef CORONA_H
#define CORONA_H
-#include <QGraphicsView>
+#include <QGraphicsScene>
#include "plasma.h"
#include "applet.h"
-class QGraphicsScene;
namespace Plasma
{
class Layout;
class Svg;
}
+namespace Plasma
+{
+
/**
* @short The view that displays the all the desktop
*/
-class Corona : public QGraphicsView
+class Corona : public QGraphicsScene
{
-Q_OBJECT
+ Q_OBJECT
//typedef QHash<QString, QList<Plasma::Applet*> > layouts;
public:
- Corona(QWidget *parent = 0);
+ explicit Corona(QObject * parent = 0);
+ explicit Corona(const QRectF & sceneRect, QObject * parent = 0);
+ explicit Corona(qreal x, qreal y, qreal width, qreal height, QObject * parent = \
0); ~Corona();
/**
@@ -56,7 +60,7 @@
*
* @param location the new location of this Corona
*/
- void setLocation(Plasma::Location location);
+ void setLocation(Location location);
/**
* The current form factor for this Corona. @see Plasma::FormFactor
@@ -68,35 +72,30 @@
* the arrangement of Applets as well as the display choices of individual
* Applets.
*/
- void setFormFactor(Plasma::FormFactor formFactor);
+ void setFormFactor(FormFactor formFactor);
public Q_SLOTS:
void addPlasmoid(const QString& name);
protected:
- void resizeEvent(QResizeEvent* event);
- void dragEnterEvent(QDragEnterEvent* event);
- void dragLeaveEvent(QDragLeaveEvent* event);
- void dragMoveEvent(QDragMoveEvent* event);
- void dropEvent(QDropEvent* event);
- void drawBackground(QPainter * painter, const QRectF & rect);
+ void dragEnterEvent(QGraphicsSceneDragDropEvent* event);
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
+ void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
+ void dropEvent(QGraphicsSceneDragDropEvent* event);
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
protected Q_SLOTS:
- void displayContextMenu(const QPoint& point);
void launchExplorer(bool /*param*/);
private:
- QGraphicsScene *m_graphicsScene;
- QAction *m_engineExplorerAction;
- Plasma::Applet::List m_applets;
- Plasma::FormFactor m_formFactor;
- Plasma::Location m_location;
- Plasma::Layout* m_layout;
+ void init();
- //TODO: replace m_background with something actually useful.
- Plasma::Svg* m_background;
+ class Private;
+ Private * const d;
};
+} // namespace Plasma
+
#endif
--- trunk/KDE/kdebase/workspace/plasma/plasma/rootwidget.cpp #670269:670270
@@ -25,8 +25,11 @@
#include <KWindowSystem>
+#include "corona.h"
+#include "plasma.h"
#include "svg.h"
-#include "corona.h"
+
+#include "coronaview.h"
#include "controlbox.h"
RootWidget::RootWidget()
@@ -42,9 +45,9 @@
rootLayout->setMargin(0);
rootLayout->setSpacing(0);
- m_view = new Corona(this);
- m_view->setFormFactor(Plasma::Planar);
- m_view->setLocation(Plasma::Desktop);
+ m_view = new CoronaView(this);
+ m_view->corona()->setFormFactor(Plasma::Planar);
+ m_view->corona()->setLocation(Plasma::Desktop);
rootLayout->addWidget(m_view);
m_view->show();
@@ -52,7 +55,7 @@
m_controlBox = new ControlBox(this);
m_controlBox->show();
- connect(m_controlBox, SIGNAL(addPlasmoid(const QString&)), m_view, \
SLOT(addPlasmoid(const QString&))); + connect(m_controlBox, \
SIGNAL(addPlasmoid(const QString&)), m_view->corona(), SLOT(addPlasmoid(const \
QString&))); }
RootWidget::~RootWidget()
--- trunk/KDE/kdebase/workspace/plasma/plasma/rootwidget.h #670269:670270
@@ -22,7 +22,7 @@
#include <QWidget>
-class Corona;
+class CoronaView;
class ControlBox;
/**
@@ -40,7 +40,7 @@
void adjustSize();
private:
- Corona* m_view;
+ CoronaView* m_view;
ControlBox* m_controlBox;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic