Ok, here comes a new version of the patch. I think I took into account all your comments: the new methods in Corona have a default implementation, I removed the ViewerCorona class, moved popupPosition to Corona, removed the convenience methods from View and Applet. The only remaining problem, I think, is the ToolTipManager stuff. I think if it remains a singleton the only way to access the corona from it is to have the corona register itself when created. Ok to commit? g
2008/10/27 Aaron J. Seigo <[EMAIL PROTECTED]>: > On Monday 27 October 2008, Guillaume Pothier wrote: >> 2008/10/27 Aaron J. Seigo <[EMAIL PROTECTED]>: >> >> The latter should probably return a QRegion instead, according to what >> >> you said about toolbox placement. >> > >> > yes, it should be a QRegion. >> >> ok, I'll use QRegion in the API, but for now the region will be >> rectangular and the toolbox positioning code will rely on the region's >> bounding box. Later I'll see how to improve that. Is that ok? > > absolutely. it's a good pragmatic "one step at a time" approach > > >> >> - Added a ViewerCorona class to plasmoidviewer, as Plasma::Corona is >> >> now has pure virtual methods. >> > >> > shouldn't be necessary if they aren't pure virtual. that you had to do >> > this work was probably a good hint something could be better =) >> >> I think plasmoidviewer needs its own corona anyway so as to report the >> actual window size instead of a meaningless value? > > no; it should just set the sceneRect to be equal to the window size. i'm > pretty sure it already does that, actually. > > -- > Aaron J. Seigo > humru othro a kohnu se > GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA EE75 D6B7 2EB1 A7F1 DB43 > > KDE core developer sponsored by Qt Software > > > _______________________________________________ > Plasma-devel mailing list > Plasma-devel@kde.org > https://mail.kde.org/mailman/listinfo/plasma-devel > >
Index: workspace/libs/plasma/applet.cpp =================================================================== --- workspace/libs/plasma/applet.cpp (revision 876782) +++ workspace/libs/plasma/applet.cpp (working copy) @@ -501,7 +501,7 @@ QPoint Applet::popupPosition(const QSize &s) const { - return Plasma::popupPosition(this, s); + return containment()->corona()->popupPosition(this, s); } void Applet::updateConstraints(Plasma::Constraints constraints) Index: workspace/libs/plasma/containment.cpp =================================================================== --- workspace/libs/plasma/containment.cpp (revision 876782) +++ 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).boundingRect(); + 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 876782) +++ workspace/libs/plasma/corona.cpp (working copy) @@ -22,6 +22,7 @@ #include "corona.h" #include <QApplication> +#include <QGraphicsView> #include <QGraphicsSceneDragDropEvent> #include <QGraphicsGridLayout> #include <QMimeData> @@ -34,7 +35,9 @@ #include <KMimeType> #include "containment.h" +#include "view.h" #include "private/applet_p.h" +#include "tooltipmanager.h" using namespace Plasma; @@ -191,6 +194,7 @@ d(new CoronaPrivate(this)) { d->init(); + ToolTipManager::self()->m_corona = this; //setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel))); } @@ -399,6 +403,79 @@ } } +int Corona::numScreens() const +{ + return 1; +} + +QRect Corona::screenGeometry(int id) const +{ + return sceneRect().toRect(); +} + +QRegion Corona::availableScreenRegion(int id) const +{ + return QRegion(screenGeometry(id)); +} + +QPoint Corona::popupPosition(const QGraphicsItem *item, const QSize &s) +{ + QGraphicsView *v = viewFor(item); + + if (!v) { + return QPoint(0, 0); + } + + QPoint pos = v->mapFromScene(item->scenePos()); + pos = v->mapToGlobal(pos); + //kDebug() << "==> position is" << item->scenePos() << v->mapFromScene(item->scenePos()) << pos; + Plasma::View *pv = dynamic_cast<Plasma::View *>(v); + + Plasma::Location loc = Floating; + if (pv && pv->containment()) { + loc = pv->containment()->location(); + } + + switch (loc) { + case BottomEdge: + pos = QPoint(pos.x(), pos.y() - s.height()); + break; + case TopEdge: + pos = QPoint(pos.x(), pos.y() + (int)item->boundingRect().size().height()); + break; + case LeftEdge: + pos = QPoint(pos.x() + (int)item->boundingRect().size().width(), pos.y()); + break; + case RightEdge: + pos = QPoint(pos.x() - s.width(), pos.y()); + break; + default: + if (pos.y() - s.height() > 0) { + pos = QPoint(pos.x(), pos.y() - s.height()); + } else { + pos = QPoint(pos.x(), pos.y() + (int)item->boundingRect().size().height()); + } + } + + //are we out of screen? + QRect screenRect = + 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()) { + pos.rx() -= ((pos.rx() + s.width()) - screenRect.right()); + } + + if (pos.ry() + s.height() > screenRect.bottom()) { + pos.ry() -= ((pos.ry() + s.height()) - screenRect.bottom()); + } + + pos.rx() = qMax(0, pos.rx()); + return pos; +} + + + void Corona::loadDefaultLayout() { } Index: workspace/libs/plasma/corona.h =================================================================== --- workspace/libs/plasma/corona.h (revision 876782) +++ workspace/libs/plasma/corona.h (working copy) @@ -111,6 +111,39 @@ */ void removeOffscreenWidget(QGraphicsWidget *widget); + /** + * Returns the number of screens available to plasma. + * Subclasses should override this method as the default + * implementation returns a meaningless value. + */ + virtual int numScreens() const; + + /** + * Returns the geometry of a given screen. + * Valid screen ids are 0 to numScreen()-1, or -1 for the full desktop geometry. + * Subclasses should override this method as the default + * implementation returns a meaningless value. + */ + virtual QRect screenGeometry(int id) const; + + /** + * Returns the available region for a given screen. + * The available region excludes panels and similar windows. + * Valid screen ids are 0 to numScreens()-1. + * By default this method returns a rectangular region + * equal to screenGeometry(id); subclasses that need another + * behavior should override this method. + */ + virtual QRegion availableScreenRegion(int id) const; + + /** + * Reccomended position for a popup window like a menu or a tooltip + * given its size + * @param s size of the popup + * @returns reccomended position + */ + QPoint popupPosition(const QGraphicsItem *item, const QSize &s); + 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 876782) +++ workspace/libs/plasma/plasma.cpp (working copy) @@ -19,7 +19,6 @@ #include <plasma/plasma.h> -#include <QDesktopWidget> #include <QGraphicsScene> #include <QGraphicsView> @@ -68,62 +67,6 @@ return Down; } -QPoint popupPosition(const QGraphicsItem *item, const QSize &s) -{ - QGraphicsView *v = viewFor(item); - - if (!v) { - return QPoint(0, 0); - } - - QPoint pos = v->mapFromScene(item->scenePos()); - pos = v->mapToGlobal(pos); - //kDebug() << "==> position is" << item->scenePos() << v->mapFromScene(item->scenePos()) << pos; - Plasma::View *pv = dynamic_cast<Plasma::View *>(v); - - Plasma::Location loc = Floating; - if (pv && pv->containment()) { - loc = pv->containment()->location(); - } - - switch (loc) { - case BottomEdge: - pos = QPoint(pos.x(), pos.y() - s.height()); - break; - case TopEdge: - pos = QPoint(pos.x(), pos.y() + (int)item->boundingRect().size().height()); - break; - case LeftEdge: - pos = QPoint(pos.x() + (int)item->boundingRect().size().width(), pos.y()); - break; - case RightEdge: - pos = QPoint(pos.x() - s.width(), pos.y()); - break; - default: - if (pos.y() - s.height() > 0) { - pos = QPoint(pos.x(), pos.y() - s.height()); - } else { - pos = QPoint(pos.x(), pos.y() + (int)item->boundingRect().size().height()); - } - } - - //are we out of screen? - QRect screenRect = - QApplication::desktop()->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()) { - pos.rx() -= ((pos.rx() + s.width()) - screenRect.right()); - } - - if (pos.ry() + s.height() > screenRect.bottom()) { - pos.ry() -= ((pos.ry() + s.height()) - screenRect.bottom()); - } - - pos.rx() = qMax(0, pos.rx()); - return pos; -} - QGraphicsView *viewFor(const QGraphicsItem *item) { if (!item->scene()) { Index: workspace/libs/plasma/plasma.h =================================================================== --- workspace/libs/plasma/plasma.h (revision 876782) +++ workspace/libs/plasma/plasma.h (working copy) @@ -249,14 +249,6 @@ PLASMA_EXPORT Direction locationToDirection(Location location); /** - * Reccomended position for a popup window like a menu or a tooltip - * given its size - * @param s size of the popup - * @returns reccomended position - */ -PLASMA_EXPORT QPoint popupPosition(const QGraphicsItem *item, const QSize &s); - -/** * Returns the most appropriate QGraphicsView for the item. * * @arg item the QGraphicsItem to locate a view for Index: workspace/libs/plasma/popupapplet.cpp =================================================================== --- workspace/libs/plasma/popupapplet.cpp (revision 876782) +++ workspace/libs/plasma/popupapplet.cpp (working copy) @@ -26,7 +26,6 @@ #include <QVBoxLayout> #include <QTimer> #include <QApplication> -#include <QDesktopWidget> #include <KIcon> #include <KIconLoader> @@ -446,9 +445,9 @@ KConfigGroup sizeGroup = q->config(); sizeGroup = KConfigGroup(&sizeGroup, "PopupApplet"); const int width = qMin(sizeGroup.readEntry("DialogWidth", 0), - QApplication::desktop()->screen()->width() - 50); + q->containment()->corona()->screenGeometry(-1).width() - 50); const int height = qMin(sizeGroup.readEntry("DialogHeight", 0), - QApplication::desktop()->screen()->height() - 50); + q->containment()->corona()->screenGeometry(-1).height() - 50); QSize saved(width, height); @@ -501,7 +500,7 @@ //are we out of screen? QRect screenRect = - QApplication::desktop()->screenGeometry(q->containment() ? q->containment()->screen() : -1); + q->containment()->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 876782) +++ workspace/libs/plasma/tooltipmanager.cpp (working copy) @@ -40,6 +40,7 @@ //Plasma #include <applet.h> #include <containment.h> +#include <corona.h> #include <panelsvg.h> #include <theme.h> #include <view.h> @@ -371,7 +372,7 @@ tooltip->hide(); //kDebug() << "about to show" << justCreated; tooltip->prepareShowing(!justCreated); - tooltip->move(popupPosition(currentWidget, tooltip->size())); + tooltip->move(ToolTipManager::self()->m_corona->popupPosition(currentWidget, tooltip->size())); isShown = true; //ToolTip is visible tooltip->show(); Index: workspace/libs/plasma/tooltipmanager.h =================================================================== --- workspace/libs/plasma/tooltipmanager.h (revision 876782) +++ workspace/libs/plasma/tooltipmanager.h (working copy) @@ -31,6 +31,7 @@ class ToolTipManagerPrivate; class Applet; +class Corona; /** * @class ToolTipManager plasma/tooltipmanager.h <Plasma/ToolTipManager> @@ -203,9 +204,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/plasma/applets/kickoff/applet/applet.cpp =================================================================== --- workspace/plasma/applets/kickoff/applet/applet.cpp (revision 876782) +++ 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 876782) +++ 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 876782) +++ 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(dynamic_cast<Plasma::Corona*>(scene())->popupPosition(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(dynamic_cast<Plasma::Corona*>(scene())->popupPosition(this, menu.size())); } } Index: workspace/plasma/applets/tasks/windowtaskitem.cpp =================================================================== --- workspace/plasma/applets/tasks/windowtaskitem.cpp (revision 876782) +++ 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(dynamic_cast<Plasma::Corona*>(scene())->popupPosition(this, menu.size())); delete a; } Index: workspace/plasma/applets/trash/trash.cpp =================================================================== --- workspace/plasma/applets/trash/trash.cpp (revision 876782) +++ 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 876782) +++ workspace/plasma/shells/desktop/desktopcorona.cpp (working copy) @@ -73,6 +73,22 @@ m_numScreens = numScreens; } +int DesktopCorona::numScreens() const +{ + return QApplication::desktop()->numScreens(); +} + +QRect DesktopCorona::screenGeometry(int id) const +{ + return QApplication::desktop()->screenGeometry(id); +} + +QRegion DesktopCorona::availableScreenRegion(int id) const +{ + // TODO: more precise implementation needed + return QRegion(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 876782) +++ 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 QRegion availableScreenRegion(int id) const; + protected Q_SLOTS: void screenResized(int); Index: workspace/plasma/shells/mid/midcorona.cpp =================================================================== --- workspace/plasma/shells/mid/midcorona.cpp (revision 876782) +++ workspace/plasma/shells/mid/midcorona.cpp (working copy) @@ -131,5 +131,23 @@ } } +int MidCorona::numScreens() const +{ + return QApplication::desktop()->numScreens(); +} + +QRect MidCorona::screenGeometry(int id) const +{ + return QApplication::desktop()->screenGeometry(id); +} + +QRegion MidCorona::availableScreenRegion(int id) const +{ + // TODO: more precise implementation needed + return QRegion(QApplication::desktop()->availableGeometry(id)); +} + + + #include "midcorona.moc" Index: workspace/plasma/shells/mid/midcorona.h =================================================================== --- workspace/plasma/shells/mid/midcorona.h (revision 876782) +++ 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 QRegion availableScreenRegion(int id) const; + protected Q_SLOTS: void screenResized(int); Index: workspace/plasma/shells/screensaver/savercorona.cpp =================================================================== --- workspace/plasma/shells/screensaver/savercorona.cpp (revision 876782) +++ workspace/plasma/shells/screensaver/savercorona.cpp (working copy) @@ -74,5 +74,15 @@ } +int SaverCorona::numScreens() const +{ + return QApplication::desktop()->numScreens(); +} + +QRect SaverCorona::screenGeometry(int id) const +{ + return QApplication::desktop()->screenGeometry(id); +} + #include "savercorona.moc" Index: workspace/plasma/shells/screensaver/savercorona.h =================================================================== --- workspace/plasma/shells/screensaver/savercorona.h (revision 876782) +++ workspace/plasma/shells/screensaver/savercorona.h (working copy) @@ -39,6 +39,9 @@ **/ void loadDefaultLayout(); + virtual int numScreens() const; + virtual QRect screenGeometry(int id) const; + protected Q_SLOTS: private: Index: workspace/plasma/shells/screensaver/saverview.cpp =================================================================== --- workspace/plasma/shells/screensaver/saverview.cpp (revision 876782) +++ 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