void DzMainWindow
::positionUIPopUp( QWidget* posWgt
) {
if(!posWgt)
return;
DzUIPopUpWgt* popupWgt = getUIPopUp();
if(!popupWgt)
return;
dzApp->processEvents();
// Find a parent widget that has an orientation
Qt::Orientation orient = Qt::Horizontal;
if(QWidget* parentWgt
= posWgt
->parentWidget
()) {
do
{
QVariant data
= parentWgt
->property
("orientation");
if(data.isValid())
{
orient = Qt::Orientation(data.value<int>());
break;
}
parentWgt = parentWgt->parentWidget();
} while (parentWgt);
}
// Split screen into quadrants
QRect screenRect
= desktop
->availableGeometry
(posWgtGlobalPos
);
int screenMidX = screenRect.x() + (screenRect.width() / 2);
int screenMidY = screenRect.y() + (screenRect.height() / 2);
QRect topLeft
= screenRect;
topLeft.setRight(screenMidX);
topLeft.setBottom(screenMidY);
QRect topRight
= screenRect;
topRight.setLeft(screenMidX);
topRight.setBottom(screenMidY);
QRect bottomLeft
= screenRect;
bottomLeft.setRight(screenMidX);
bottomLeft.setTop(screenMidY);
QRect bottomRight
= screenRect;
bottomRight.setLeft(screenMidX);
bottomRight.setTop(screenMidY);
// Position the popup widget based on the quadrant posWgt is in
int popX = posWgtGlobalPos.x();
int popY = posWgtGlobalPos.y();
if(topLeft.contains( posWgtGlobalPos ))
{
if (orient == Qt::Horizontal)
{
popY += posWgt->height();
}
else
{
popX += posWgt->width();
}
}
else if(topRight.contains( posWgtGlobalPos ))
{
popX -= popupWgt->width();
if (orient == Qt::Horizontal)
{
popX += posWgt->width();
popY += posWgt->height();
}
}
else if(bottomRight.contains( posWgtGlobalPos ))
{
popX -= popupWgt->width();
popY -= popupWgt->height();
if (orient == Qt::Horizontal)
{
popX += posWgt->width();
}
else
{
popY += posWgt->height();
}
}
else if(bottomLeft.contains( posWgtGlobalPos ))
{
popY -= popupWgt->height();
if (orient == Qt::Vertical)
{
popX += posWgt->width();
popY += posWgt->height();
}
}
QPoint popPnt
= popupWgt
->mapFromGlobal
(QPoint(popX, popY
));
popupWgt->setGeometry(
popupWgt->x() + popPnt.x(),
popupWgt->y() + popPnt.y(),
popupWgt->width(),
popupWgt->height());
//popupWgt->move(popupWgt->x() + popPnt.x(), popupWgt->y() + popPnt.y());
}
Bookmarks