fallback when there is no corona

autonomous positioning when there is no corona (usually relies on addoffscreenwidget and popupposition from it)
This commit is contained in:
Marco Martin 2011-11-02 18:15:17 +01:00
parent 67ab75c0fd
commit 270b6296b9
2 changed files with 67 additions and 1 deletions

View File

@ -20,7 +20,9 @@
#include "dialog.h"
#include "declarativeitemcontainer_p.h"
#include <QApplication>
#include <QDeclarativeItem>
#include <QDesktopWidget>
#include <QGraphicsObject>
#include <QGraphicsWidget>
#include <QTimer>
@ -31,6 +33,9 @@
#include <Plasma/WindowEffects>
int DialogProxy::offscreenX = 0;
int DialogProxy::offscreenY = 0;
DialogMargins::DialogMargins(Plasma::Dialog *dialog, QObject *parent)
: QObject(parent),
m_dialog(dialog)
@ -171,6 +176,12 @@ void DialogProxy::syncMainItem()
}
}
m_dialog->setGraphicsWidget(widget);
if (!qobject_cast<Plasma::Corona *>(scene)) {
offscreenX -= 1024;
offscreenY -= 1024;
widget->setPos(offscreenX, offscreenY);
}
}
bool DialogProxy::isVisible() const
@ -199,7 +210,60 @@ QPoint DialogProxy::popupPosition(QGraphicsObject *item, int alignment) const
if (corona) {
return corona->popupPosition(item, m_dialog->size(), (Qt::AlignmentFlag)alignment);
} else {
return QPoint();
QList<QGraphicsView*> views = item->scene()->views();
if (views.size() < 1) {
return QPoint();
}
QGraphicsView *view = 0;
if (views.size() == 1) {
view = views[0];
} else {
QGraphicsView *found = 0;
QGraphicsView *possibleFind = 0;
foreach (QGraphicsView *v, views) {
if (v->sceneRect().intersects(item->sceneBoundingRect()) ||
v->sceneRect().contains(item->scenePos())) {
if (v->isActiveWindow()) {
found = v;
} else {
possibleFind = v;
}
}
}
view = found ? found : possibleFind;
}
if (!view) {
return QPoint();
}
//swap direction if necessary
if (QApplication::isRightToLeft() && alignment != Qt::AlignCenter) {
if (alignment == Qt::AlignRight) {
alignment = Qt::AlignLeft;
} else {
alignment = Qt::AlignRight;
}
}
int xOffset = 0;
if (alignment == Qt::AlignCenter) {
xOffset = item->boundingRect().width()/2 - m_dialog->width()/2;
} else if (alignment == Qt::AlignRight) {
xOffset = item->boundingRect().width() - m_dialog->width();
}
const QRect avail = QApplication::desktop()->availableGeometry(view);
QPoint menuPos = view->mapToGlobal(view->mapFromScene(item->scenePos()+QPoint(xOffset, item->boundingRect().height())));
if (menuPos.y() + m_dialog->height() > avail.bottom()) {
menuPos = view->mapToGlobal(view->mapFromScene(item->scenePos() - QPoint(-xOffset, m_dialog->height())));
}
return menuPos;
}
}

View File

@ -148,6 +148,8 @@ private:
DialogMargins *m_margins;
bool m_activeWindow;
Plasma::Location m_location;
static int offscreenX;
static int offscreenY;
};
#endif