2008/10/23 Aaron J. Seigo <[EMAIL PROTECTED]>: > On Wednesday 22 October 2008, Guillaume Pothier wrote: >> Just tell me if you want me to go ahead. > > please do =)
Ok, here comes the patch. In summary: - Added three methods to Corona: int numScreens() QRect screenGeometry(int) QRect availableScreenGeometry(int) The latter should probably return a QRegion instead, according to what you said about toolbox placement. - QDesktopWidget is not used anymore in libplasma, entirely replaced by calls to the new Corona methods. - Added Corona* parameter to Plasma::popupPosition - Added a corona() method to Plasma::Applet. This is needed for calls to Plasma::popupPosition. - Also added a corona() method to Plasma::View for consistency's sake. - Corona is friends with ToolTipManager, as ToolTipManager needs to call Plasma::popupPosition and thus needs a Corona. Thus, Corona registers itself with the ToolTipManager. I think this is the ugliest part of the patch, please tell me if there is a better solution. - Added a ViewerCorona class to plasmoidviewer, as Plasma::Corona is now has pure virtual methods. Ok to commit? g
Index: workspace/libs/plasma/applet.cpp =================================================================== --- workspace/libs/plasma/applet.cpp (revision 875440) +++ workspace/libs/plasma/applet.cpp (working copy) @@ -499,9 +499,14 @@ return view->mapFromScene(mapToScene(rect)).boundingRect().adjusted(0, 0, -1, -1); } +Corona *Applet::corona() const +{ + return dynamic_cast<Corona*>(scene()); +} + QPoint Applet::popupPosition(const QSize &s) const { - return Plasma::popupPosition(this, s); + return Plasma::popupPosition(corona(), this, s); } void Applet::updateConstraints(Plasma::Constraints constraints) Index: workspace/libs/plasma/applet.h =================================================================== --- workspace/libs/plasma/applet.h (revision 875440) +++ workspace/libs/plasma/applet.h (working copy) @@ -612,6 +612,11 @@ virtual void init(); /** + * Returns the Corona (if any) that this Applet is hosted by + */ + Corona *corona() const; + + /** * Called when applet configuration values has changed. */ virtual void configChanged(); Index: workspace/libs/plasma/containment.cpp =================================================================== --- workspace/libs/plasma/containment.cpp (revision 875440) +++ workspace/libs/plasma/containment.cpp (working copy) @@ -22,7 +22,6 @@ #include "private/containment_p.h" #include <QAction> -#include <QDesktopWidget> #include <QFile> #include <QGraphicsSceneContextMenuEvent> #include <QGraphicsView> @@ -767,8 +766,7 @@ } //kDebug() << "setting screen to" << screen << "and we are a" << containmentType(); - QDesktopWidget *desktop = QApplication::desktop(); - int numScreens = desktop->numScreens(); + int numScreens = corona()->numScreens(); if (screen < -1) { screen = -1; } @@ -777,7 +775,7 @@ if (screen < numScreens && screen > -1) { if (containmentType() == DesktopContainment || containmentType() >= CustomContainment) { - resize(desktop->screenGeometry(screen).size()); + resize(corona()->screenGeometry(screen).size()); } } @@ -1368,7 +1366,7 @@ //FIXME: this should probably be based on whether any views care or not! // sth like: foreach (view) { view->requires(this); } if (d->type != PanelContainment && d->type != CustomPanelContainment && - (d->screen != -1 || d->screen >= QApplication::desktop()->numScreens())) { + (d->screen != -1 || d->screen >= corona()->numScreens())) { kDebug() << (QObject*)this << "containment has a screen number?" << d->screen; return; } @@ -1495,9 +1493,8 @@ //TODO: we should probably get these values from the Plasma app itself // so we actually know what the available space *is* // perhaps a virtual method in Corona for this? - QDesktopWidget *desktop = QApplication::desktop(); - QRectF avail = desktop->availableGeometry(screen); - QRectF screenGeom = desktop->screenGeometry(screen); + QRectF avail = q->corona()->availableScreenRegion(screen); + QRectF screenGeom = q->corona()->screenGeometry(screen); // Transform to the containment's coordinate system. avail.translate(-screenGeom.topLeft()); Index: workspace/libs/plasma/corona.cpp =================================================================== --- workspace/libs/plasma/corona.cpp (revision 875440) +++ workspace/libs/plasma/corona.cpp (working copy) @@ -35,6 +35,7 @@ #include "containment.h" #include "private/applet_p.h" +#include "tooltipmanager.h" using namespace Plasma; @@ -191,6 +192,7 @@ d(new CoronaPrivate(this)) { d->init(); + ToolTipManager::self()->m_corona = this; //setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel))); } Index: workspace/libs/plasma/corona.h =================================================================== --- workspace/libs/plasma/corona.h (revision 875440) +++ workspace/libs/plasma/corona.h (working copy) @@ -111,6 +111,26 @@ */ void removeOffscreenWidget(QGraphicsWidget *widget); + /** + * Returns the number of screens available to plasma. + */ + virtual int numScreens() const = 0; + + /** + * Returns the geometry of a given screen. + * Valid screen ids are 0 to numScreen()-1, or -1 for the full desktop geometry. + */ + virtual QRect screenGeometry(int id) const = 0; + + /** + * Returns the available region for a given screen. + * The available region excludes panels and similar windows. + * Valid screen ids are 0 to numScreens()-1. + * TODO: replace QRect by QRegion + */ + virtual QRect availableScreenRegion(int id) const = 0; + + public Q_SLOTS: /** * Initializes the layout from a config file. This will first clear any existing Index: workspace/libs/plasma/plasma.cpp =================================================================== --- workspace/libs/plasma/plasma.cpp (revision 875440) +++ workspace/libs/plasma/plasma.cpp (working copy) @@ -19,12 +19,12 @@ #include <plasma/plasma.h> -#include <QDesktopWidget> #include <QGraphicsScene> #include <QGraphicsView> #include <plasma/containment.h> #include <plasma/view.h> +#include <plasma/corona.h> namespace Plasma { @@ -68,7 +68,7 @@ return Down; } -QPoint popupPosition(const QGraphicsItem *item, const QSize &s) +QPoint popupPosition(const Corona *corona, const QGraphicsItem *item, const QSize &s) { QGraphicsView *v = viewFor(item); @@ -109,7 +109,7 @@ //are we out of screen? QRect screenRect = - QApplication::desktop()->screenGeometry((pv && pv->containment()) ? pv->containment()->screen() : -1); + corona->screenGeometry((pv && pv->containment()) ? pv->containment()->screen() : -1); //kDebug() << "==> rect for" << (pv ? pv->containment()->screen() : -1) << "is" << screenRect; if (pos.rx() + s.width() > screenRect.right()) { Index: workspace/libs/plasma/plasma.h =================================================================== --- workspace/libs/plasma/plasma.h (revision 875440) +++ workspace/libs/plasma/plasma.h (working copy) @@ -34,6 +34,8 @@ */ namespace Plasma { + +class Corona; /** * The Constraint enumeration lists the various constraints that Plasma @@ -254,7 +256,7 @@ * @param s size of the popup * @returns reccomended position */ -PLASMA_EXPORT QPoint popupPosition(const QGraphicsItem *item, const QSize &s); +PLASMA_EXPORT QPoint popupPosition(const Corona *corona, const QGraphicsItem *item, const QSize &s); /** * Returns the most appropriate QGraphicsView for the item. Index: workspace/libs/plasma/popupapplet.cpp =================================================================== --- workspace/libs/plasma/popupapplet.cpp (revision 875440) +++ workspace/libs/plasma/popupapplet.cpp (working copy) @@ -26,7 +26,6 @@ #include <QVBoxLayout> #include <QTimer> #include <QApplication> -#include <QDesktopWidget> #include <KIcon> #include <KIconLoader> @@ -438,9 +437,9 @@ KConfigGroup sizeGroup = q->config(); sizeGroup = KConfigGroup(&sizeGroup, "PopupApplet"); const int width = qMin(sizeGroup.readEntry("DialogWidth", 0), - QApplication::desktop()->screen()->width() - 50); + q->corona()->screenGeometry(-1).width() - 50); const int height = qMin(sizeGroup.readEntry("DialogHeight", 0), - QApplication::desktop()->screen()->height() - 50); + q->corona()->screenGeometry(-1).height() - 50); QSize saved(width, height); @@ -493,7 +492,7 @@ //are we out of screen? QRect screenRect = - QApplication::desktop()->screenGeometry(q->containment() ? q->containment()->screen() : -1); + q->corona()->screenGeometry(q->containment() ? q->containment()->screen() : -1); //kDebug() << "==> rect for" // << (containment() ? containment()->screen() : -1) // << "is" << screenRect; Index: workspace/libs/plasma/tooltipmanager.cpp =================================================================== --- workspace/libs/plasma/tooltipmanager.cpp (revision 875440) +++ workspace/libs/plasma/tooltipmanager.cpp (working copy) @@ -370,7 +370,7 @@ tooltip->setVisible(false); //kDebug() << "about to show" << justCreated; tooltip->prepareShowing(!justCreated); - tooltip->move(popupPosition(currentWidget, tooltip->size())); + tooltip->move(popupPosition(ToolTipManager::self()->m_corona, currentWidget, tooltip->size())); isShown = true; //ToolTip is visible tooltip->setVisible(true); } Index: workspace/libs/plasma/tooltipmanager.h =================================================================== --- workspace/libs/plasma/tooltipmanager.h (revision 875440) +++ workspace/libs/plasma/tooltipmanager.h (working copy) @@ -201,9 +201,13 @@ ~ToolTipManager(); friend class ToolTipManagerSingleton; + friend class Corona; // The corona needs to register itself + friend class ToolTipManagerPrivate; bool eventFilter(QObject *watched, QEvent *event); ToolTipManagerPrivate *const d; + Corona* m_corona; + Q_PRIVATE_SLOT(d, void showToolTip()) Q_PRIVATE_SLOT(d, void resetShownState()) Q_PRIVATE_SLOT(d, void onWidgetDestroyed(QObject*)) Index: workspace/libs/plasma/view.cpp =================================================================== --- workspace/libs/plasma/view.cpp (revision 875440) +++ workspace/libs/plasma/view.cpp (working copy) @@ -251,6 +251,11 @@ return d->containment; } +Corona *View::corona() const +{ + return dynamic_cast<Corona*>(scene()); +} + Containment *View::swapContainment(const QString &name, const QVariantList &args) { return swapContainment(d->containment, name, args); Index: workspace/libs/plasma/view.h =================================================================== --- workspace/libs/plasma/view.h (revision 875440) +++ workspace/libs/plasma/view.h (working copy) @@ -120,6 +120,11 @@ * @return the containment associated with this view, or 0 if none is */ Containment *containment() const; + + /** + * @return the corona associated with this view, or 0 if not available. + */ + Corona *corona() const; /** * Swaps one containment with another. Index: workspace/plasma/applets/kickoff/applet/applet.cpp =================================================================== --- workspace/plasma/applets/kickoff/applet/applet.cpp (revision 875440) +++ workspace/plasma/applets/kickoff/applet/applet.cpp (working copy) @@ -23,7 +23,6 @@ // Qt #include <QAction> #include <QApplication> -#include <QDesktopWidget> #include <QGraphicsView> #include <QCheckBox> #include <QVBoxLayout> Index: workspace/plasma/applets/kickoff/ui/launcher.cpp =================================================================== --- workspace/plasma/applets/kickoff/ui/launcher.cpp (revision 875440) +++ workspace/plasma/applets/kickoff/ui/launcher.cpp (working copy) @@ -25,7 +25,6 @@ // Qt #include <QApplication> -#include <QDesktopWidget> #include <QKeyEvent> #include <QLabel> #include <QMouseEvent> Index: workspace/plasma/applets/tasks/taskgroupitem.cpp =================================================================== --- workspace/plasma/applets/tasks/taskgroupitem.cpp (revision 875440) +++ workspace/plasma/applets/tasks/taskgroupitem.cpp (working copy) @@ -49,6 +49,7 @@ #include "plasma/theme.h" #include "plasma/panelsvg.h" #include "plasma/tooltipmanager.h" +#include "plasma/corona.h" #include "tasks.h" #include "layoutwidget.h" @@ -330,7 +331,7 @@ TaskManager::BasicMenu menu(qobject_cast<QWidget*>(this), m_group, &m_applet->groupManager(), actionList); menu.adjustSize(); - menu.exec(Plasma::popupPosition(this, menu.size())); + menu.exec(Plasma::popupPosition(dynamic_cast<Plasma::Corona*>(scene()), this, menu.size())); } @@ -448,7 +449,7 @@ if (m_isCollapsed) { TaskManager::GroupPopupMenu menu(qobject_cast<QWidget*>(this), m_group, &m_applet->groupManager()); menu.adjustSize(); - menu.exec(Plasma::popupPosition(this, menu.size())); + menu.exec(Plasma::popupPosition(dynamic_cast<Plasma::Corona*>(scene()), this, menu.size())); } } Index: workspace/plasma/applets/tasks/windowtaskitem.cpp =================================================================== --- workspace/plasma/applets/tasks/windowtaskitem.cpp (revision 875440) +++ workspace/plasma/applets/tasks/windowtaskitem.cpp (working copy) @@ -45,6 +45,7 @@ #include "plasma/theme.h" #include "plasma/panelsvg.h" #include "plasma/tooltipmanager.h" +#include "plasma/corona.h" #include "tasks.h" @@ -267,7 +268,7 @@ TaskManager::BasicMenu menu(0, m_task, &m_applet->groupManager(), actionList); menu.adjustSize(); - menu.exec(Plasma::popupPosition(this, menu.size())); + menu.exec(Plasma::popupPosition(dynamic_cast<Plasma::Corona*>(scene()), this, menu.size())); delete a; } Index: workspace/plasma/applets/trash/trash.cpp =================================================================== --- workspace/plasma/applets/trash/trash.cpp (revision 875440) +++ workspace/plasma/applets/trash/trash.cpp (working copy) @@ -21,7 +21,6 @@ //QT #include <QGraphicsSceneDragDropEvent> -#include <QDesktopWidget> #include <QApplication> #include <QGraphicsLinearLayout> Index: workspace/plasma/shells/desktop/desktopcorona.cpp =================================================================== --- workspace/plasma/shells/desktop/desktopcorona.cpp (revision 875440) +++ workspace/plasma/shells/desktop/desktopcorona.cpp (working copy) @@ -73,6 +73,21 @@ m_numScreens = numScreens; } +int DesktopCorona::numScreens() const +{ + return QApplication::desktop()->numScreens(); +} + +QRect DesktopCorona::screenGeometry(int id) const +{ + return QApplication::desktop()->screenGeometry(id); +} + +QRect DesktopCorona::availableScreenRegion(int id) const +{ + return QApplication::desktop()->availableGeometry(id); +} + void DesktopCorona::loadDefaultLayout() { QString defaultConfig = KStandardDirs::locate("appdata", "plasma-default-layoutrc"); Index: workspace/plasma/shells/desktop/desktopcorona.h =================================================================== --- workspace/plasma/shells/desktop/desktopcorona.h (revision 875440) +++ workspace/plasma/shells/desktop/desktopcorona.h (working copy) @@ -49,6 +49,10 @@ */ void checkScreens(); + virtual int numScreens() const; + virtual QRect screenGeometry(int id) const; + virtual QRect availableScreenRegion(int id) const; + protected Q_SLOTS: void screenResized(int); Index: workspace/plasma/shells/mid/midcorona.cpp =================================================================== --- workspace/plasma/shells/mid/midcorona.cpp (revision 875440) +++ workspace/plasma/shells/mid/midcorona.cpp (working copy) @@ -131,5 +131,22 @@ } } +int MidCorona::numScreens() const +{ + return QApplication::desktop()->numScreens(); +} + +QRect MidCorona::screenGeometry(int id) const +{ + return QApplication::desktop()->screenGeometry(id); +} + +QRect MidCorona::availableScreenRegion(int id) const +{ + return QApplication::desktop()->availableGeometry(id); +} + + + #include "midcorona.moc" Index: workspace/plasma/shells/mid/midcorona.h =================================================================== --- workspace/plasma/shells/mid/midcorona.h (revision 875440) +++ workspace/plasma/shells/mid/midcorona.h (working copy) @@ -49,6 +49,10 @@ */ void checkScreens(); + virtual int numScreens() const; + virtual QRect screenGeometry(int id) const; + virtual QRect availableScreenRegion(int id) const; + protected Q_SLOTS: void screenResized(int); Index: workspace/plasma/shells/plasmoidviewer/CMakeLists.txt =================================================================== --- workspace/plasma/shells/plasmoidviewer/CMakeLists.txt (revision 875440) +++ workspace/plasma/shells/plasmoidviewer/CMakeLists.txt (working copy) @@ -1,5 +1,6 @@ set(plasmoidviewer_SRCS fullview.cpp + viewercorona.cpp main.cpp ) Index: workspace/plasma/shells/plasmoidviewer/fullview.cpp =================================================================== --- workspace/plasma/shells/plasmoidviewer/fullview.cpp (revision 875440) +++ workspace/plasma/shells/plasmoidviewer/fullview.cpp (working copy) @@ -41,7 +41,8 @@ m_formfactor(Plasma::Planar), m_location(Plasma::Floating), m_containment(0), - m_applet(0) + m_applet(0), + m_corona(this) { setFrameStyle(QFrame::NoFrame); QString formfactor = ff.toLower(); Index: workspace/plasma/shells/plasmoidviewer/fullview.h =================================================================== --- workspace/plasma/shells/plasmoidviewer/fullview.h (revision 875440) +++ workspace/plasma/shells/plasmoidviewer/fullview.h (working copy) @@ -26,7 +26,7 @@ #ifndef FULLVIEW_H #define FULLVIEW_H -#include <plasma/corona.h> +#include "viewercorona.h" #include <QGraphicsView> @@ -44,7 +44,7 @@ void resizeEvent(QResizeEvent *event); private: - Plasma::Corona m_corona; + ViewerCorona m_corona; Plasma::FormFactor m_formfactor; Plasma::Location m_location; Plasma::Containment *m_containment; Index: workspace/plasma/shells/plasmoidviewer/viewercorona.cpp =================================================================== --- workspace/plasma/shells/plasmoidviewer/viewercorona.cpp (revision 0) +++ workspace/plasma/shells/plasmoidviewer/viewercorona.cpp (revision 0) @@ -0,0 +1,46 @@ +/* + * Copyright 2008 Aaron Seigo <[EMAIL PROTECTED]> + * + * 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 "viewercorona.h" + +#include <QWidget> + +ViewerCorona::ViewerCorona(QWidget *view, QObject *parent) + : Plasma::Corona(parent), + m_view(view) +{ +} + +int ViewerCorona::numScreens() const +{ + return 1; +} + +QRect ViewerCorona::screenGeometry(int id) const +{ + return m_view->geometry(); +} + +QRect ViewerCorona::availableScreenRegion(int id) const +{ + return screenGeometry(id); +} + +#include "viewercorona.moc" + Index: workspace/plasma/shells/plasmoidviewer/viewercorona.h =================================================================== --- workspace/plasma/shells/plasmoidviewer/viewercorona.h (revision 0) +++ workspace/plasma/shells/plasmoidviewer/viewercorona.h (revision 0) @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Aaron Seigo <[EMAIL PROTECTED]> + * + * 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 VIEWERCORONA_H +#define VIEWERCORONA_H + +#include <QtGui/QGraphicsScene> + +#include <plasma/corona.h> + +namespace Plasma +{ + class Applet; +} // namespace Plasma + +class QWidget; + +/** + * @short A Corona for plasmoidviewer + */ +class ViewerCorona : public Plasma::Corona +{ + Q_OBJECT + +public: + explicit ViewerCorona(QWidget *view, QObject * parent = 0); + + virtual int numScreens() const; + virtual QRect screenGeometry(int id) const; + virtual QRect availableScreenRegion(int id) const; + +private: + QWidget *m_view; +}; + +#endif + + Index: workspace/plasma/shells/screensaver/savercorona.cpp =================================================================== --- workspace/plasma/shells/screensaver/savercorona.cpp (revision 875440) +++ workspace/plasma/shells/screensaver/savercorona.cpp (working copy) @@ -74,5 +74,20 @@ } +int SaverCorona::numScreens() const +{ + return QApplication::desktop()->numScreens(); +} + +QRect SaverCorona::screenGeometry(int id) const +{ + return QApplication::desktop()->screenGeometry(id); +} + +QRect SaverCorona::availableScreenRegion(int id) const +{ + return QApplication::desktop()->availableGeometry(id); +} + #include "savercorona.moc" Index: workspace/plasma/shells/screensaver/savercorona.h =================================================================== --- workspace/plasma/shells/screensaver/savercorona.h (revision 875440) +++ workspace/plasma/shells/screensaver/savercorona.h (working copy) @@ -39,6 +39,10 @@ **/ void loadDefaultLayout(); + virtual int numScreens() const; + virtual QRect screenGeometry(int id) const; + virtual QRect availableScreenRegion(int id) const; + protected Q_SLOTS: private: Index: workspace/plasma/shells/screensaver/saverview.cpp =================================================================== --- workspace/plasma/shells/screensaver/saverview.cpp (revision 875440) +++ workspace/plasma/shells/screensaver/saverview.cpp (working copy) @@ -23,7 +23,6 @@ #include "saverview.h" #include <QAction> -#include <QDesktopWidget> #include <QKeyEvent> #include <QTimer>
_______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel