Use Qt API for figuring out the dialog screen

At the moment it's trying to translate the item position and iterating
through all screens, but we can get the screen through the item's window.

REVIEW: 119603
This commit is contained in:
Aleix Pol 2014-08-05 19:48:28 +02:00
parent 3db176041b
commit d7a7a4fb83

View File

@ -71,7 +71,6 @@ public:
Window
};
QScreen *screenForItem(QQuickItem *item) const;
void updateInputShape();
//SLOTS
@ -107,18 +106,6 @@ public:
QWeakPointer <QObject> mainItemLayout;
};
//find the screen which contains the item
QScreen *DialogPrivate::screenForItem(QQuickItem *item) const
{
const QPoint globalPosition = item->window()->mapToGlobal(item->position().toPoint());
foreach (QScreen *screen, QGuiApplication::screens()) {
if (screen->geometry().contains(globalPosition)) {
return screen;
}
}
return QGuiApplication::primaryScreen();
}
void DialogPrivate::syncBorders()
{
// FIXME: QWindow::screen() never ever changes if the window is moved across
@ -589,7 +576,7 @@ QPoint Dialog::popupPosition(QQuickItem *item, const QSize &size)
//If no item was specified try to align at the center of the parent view
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
if (parentItem) {
QScreen *screen = d->screenForItem(parentItem);
QScreen *screen = parentItem->window()->screen();
switch (d->location) {
case Plasma::Types::TopEdge:
@ -658,7 +645,7 @@ QPoint Dialog::popupPosition(QQuickItem *item, const QSize &size)
//we do not rely on item->window()->screen() because
//QWindow::screen() is always only the screen where the window gets first created
//not actually the current window. See QWindow::screen() documentation
QRect avail = d->screenForItem(item)->availableGeometry();
QRect avail = item->window()->screen()->availableGeometry();
if (outsideParentWindow && d->frameSvgItem->enabledBorders() != Plasma::FrameSvg::AllBorders) {
//make the panel look it's inside the panel, in order to not make it look cutted