Added screen management methods to Corona and removed usage of QDesktopWidget in plasmalibs.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=877451
This commit is contained in:
parent
0f3987cd9a
commit
bd7e7b10c9
@ -501,7 +501,9 @@ QRect Applet::mapToView(const QGraphicsView *view, const QRectF &rect) const
|
||||
|
||||
QPoint Applet::popupPosition(const QSize &s) const
|
||||
{
|
||||
return Plasma::popupPosition(this, s);
|
||||
Q_ASSERT(containment());
|
||||
Q_ASSERT(containment()->corona());
|
||||
return containment()->corona()->popupPosition(this, s);
|
||||
}
|
||||
|
||||
void Applet::updateConstraints(Plasma::Constraints constraints)
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "private/containment_p.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFile>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
#include <QGraphicsView>
|
||||
@ -767,8 +766,8 @@ void Containment::setScreen(int screen)
|
||||
}
|
||||
|
||||
//kDebug() << "setting screen to" << screen << "and we are a" << containmentType();
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
int numScreens = desktop->numScreens();
|
||||
Q_ASSERT(corona());
|
||||
int numScreens = corona()->numScreens();
|
||||
if (screen < -1) {
|
||||
screen = -1;
|
||||
}
|
||||
@ -777,7 +776,7 @@ void Containment::setScreen(int screen)
|
||||
if (screen < numScreens && screen > -1) {
|
||||
if (containmentType() == DesktopContainment ||
|
||||
containmentType() >= CustomContainment) {
|
||||
resize(desktop->screenGeometry(screen).size());
|
||||
resize(corona()->screenGeometry(screen).size());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1367,8 +1366,9 @@ void Containment::destroy(bool confirm)
|
||||
//don't remove a desktop that's in use
|
||||
//FIXME: this should probably be based on whether any views care or not!
|
||||
// sth like: foreach (view) { view->requires(this); }
|
||||
Q_ASSERT(corona());
|
||||
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 +1495,9 @@ void ContainmentPrivate::positionToolBox()
|
||||
//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);
|
||||
Q_ASSERT(q->corona());
|
||||
QRectF avail = q->corona()->availableScreenRegion(screen).boundingRect();
|
||||
QRectF screenGeom = q->corona()->screenGeometry(screen);
|
||||
|
||||
// Transform to the containment's coordinate system.
|
||||
avail.translate(-screenGeom.topLeft());
|
||||
|
78
corona.cpp
78
corona.cpp
@ -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 @@ Corona::Corona(QObject *parent)
|
||||
d(new CoronaPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
ToolTipManager::self()->m_corona = this;
|
||||
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
|
||||
}
|
||||
|
||||
@ -399,6 +403,80 @@ void Corona::removeOffscreenWidget(QGraphicsWidget *widget)
|
||||
}
|
||||
}
|
||||
|
||||
int Corona::numScreens() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QRect Corona::screenGeometry(int id) const
|
||||
{
|
||||
Q_UNUSED(id);
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
33
corona.h
33
corona.h
@ -111,6 +111,39 @@ public:
|
||||
*/
|
||||
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
|
||||
|
57
plasma.cpp
57
plasma.cpp
@ -19,7 +19,6 @@
|
||||
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
|
||||
@ -68,62 +67,6 @@ Direction locationToDirection(Location location)
|
||||
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()) {
|
||||
|
8
plasma.h
8
plasma.h
@ -248,14 +248,6 @@ PLASMA_EXPORT qreal scalingFactor(ZoomLevel level);
|
||||
**/
|
||||
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.
|
||||
*
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#include <KIcon>
|
||||
#include <KIconLoader>
|
||||
@ -445,10 +444,13 @@ void PopupAppletPrivate::updateDialogPosition()
|
||||
|
||||
KConfigGroup sizeGroup = q->config();
|
||||
sizeGroup = KConfigGroup(&sizeGroup, "PopupApplet");
|
||||
|
||||
Q_ASSERT(q->containment());
|
||||
Q_ASSERT(q->containment()->corona());
|
||||
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 +503,7 @@ void PopupAppletPrivate::updateDialogPosition()
|
||||
//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;
|
||||
|
@ -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 @@ void ToolTipManagerPrivate::showToolTip()
|
||||
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();
|
||||
|
||||
|
@ -31,6 +31,7 @@ namespace Plasma
|
||||
|
||||
class ToolTipManagerPrivate;
|
||||
class Applet;
|
||||
class Corona;
|
||||
|
||||
/**
|
||||
* @class ToolTipManager plasma/tooltipmanager.h <Plasma/ToolTipManager>
|
||||
@ -203,9 +204,13 @@ private:
|
||||
~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*))
|
||||
|
Loading…
Reference in New Issue
Block a user