improve contextmenu placement for containments

pull/14/head
Michail Vourlakos 5 years ago
parent 87b5dff9b5
commit 72ebfe1aae

@ -71,25 +71,10 @@ void ContextMenu::menuAboutToHide()
emit menuChanged(); emit menuChanged();
} }
QPoint ContextMenu::popUpTopLeft(const QRect &parentItem, const QRect popUpRect) QPoint ContextMenu::popUpRelevantToParent(const QRect &parentItem, const QRect popUpRect)
{ {
QPoint resultPoint; QPoint resultPoint;
if (m_latteView->behaveAsPlasmaPanel() && m_latteView->normalThickness() > 96) {
if (m_latteView->location() == Plasma::Types::TopEdge) {
resultPoint.setX(popUpRect.x());
resultPoint.setY(popUpRect.y() + 1);
} else if (m_latteView->location() == Plasma::Types::BottomEdge) {
resultPoint.setX(popUpRect.x());
resultPoint.setY(popUpRect.y() - popUpRect.height() - 1);
} else if (m_latteView->location() == Plasma::Types::LeftEdge) {
resultPoint.setX(popUpRect.x() + 1);
resultPoint.setY(popUpRect.y());
} else if (m_latteView->location() == Plasma::Types::RightEdge) {
resultPoint.setX(popUpRect.x() - popUpRect.width() - 1);
resultPoint.setY(popUpRect.y());
}
} else {
if (m_latteView->location() == Plasma::Types::TopEdge) { if (m_latteView->location() == Plasma::Types::TopEdge) {
resultPoint.setX(parentItem.left()); resultPoint.setX(parentItem.left());
resultPoint.setY(parentItem.bottom()); resultPoint.setY(parentItem.bottom());
@ -103,23 +88,49 @@ QPoint ContextMenu::popUpTopLeft(const QRect &parentItem, const QRect popUpRect)
resultPoint.setX(parentItem.left() - popUpRect.width()); resultPoint.setX(parentItem.left() - popUpRect.width());
resultPoint.setY(parentItem.top()); resultPoint.setY(parentItem.top());
} }
return resultPoint;
}
QPoint ContextMenu::popUpRelevantToGlobalPoint(const QRect &parentItem, const QRect popUpRect)
{
QPoint resultPoint;
if (m_latteView->location() == Plasma::Types::TopEdge) {
resultPoint.setX(popUpRect.x());
resultPoint.setY(popUpRect.y() + 1);
} else if (m_latteView->location() == Plasma::Types::BottomEdge) {
resultPoint.setX(popUpRect.x());
resultPoint.setY(popUpRect.y() - popUpRect.height() - 1);
} else if (m_latteView->location() == Plasma::Types::LeftEdge) {
resultPoint.setX(popUpRect.x() + 1);
resultPoint.setY(popUpRect.y());
} else if (m_latteView->location() == Plasma::Types::RightEdge) {
resultPoint.setX(popUpRect.x() - popUpRect.width() - 1);
resultPoint.setY(popUpRect.y());
} }
return resultPoint; return resultPoint;
} }
QPoint ContextMenu::popUpTopLeft(const Plasma::Applet *applet, const QRect popUpRect) QPoint ContextMenu::popUpTopLeft(Plasma::Applet *applet, const QRect popUpRect)
{ {
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>(); PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
QRect globalItemRect; QRect globalItemRect = m_latteView->absoluteGeometry();
if (ai) { if (ai && applet != m_latteView->containment()) {
QPointF appletGlobalTopLeft = ai->mapToGlobal(QPointF(ai->x(), ai->y())); QPointF appletGlobalTopLeft = ai->mapToGlobal(QPointF(ai->x(), ai->y()));
globalItemRect = QRect(appletGlobalTopLeft.x(), appletGlobalTopLeft.y(), ai->width(), ai->height()); globalItemRect = QRect(appletGlobalTopLeft.x(), appletGlobalTopLeft.y(), ai->width(), ai->height());
} }
return popUpTopLeft(globalItemRect, popUpRect); if ((m_latteView->behaveAsPlasmaPanel() && m_latteView->normalThickness() > 96)
|| (applet == m_latteView->containment())
|| (m_latteView && m_latteView->layout() && m_latteView->layout()->isInternalContainment(applet)) ) {
return popUpRelevantToGlobalPoint(globalItemRect, popUpRect);
} else {
return popUpRelevantToParent(globalItemRect, popUpRect);
}
} }
@ -306,7 +317,7 @@ bool ContextMenu::mousePressEvent(QMouseEvent *event)
if (applet) { if (applet) {
globalPos = popUpTopLeft(applet, popUpRect); globalPos = popUpTopLeft(applet, popUpRect);
} else { } else {
globalPos = popUpTopLeft(QRect(0,0,0,0), popUpRect); globalPos = popUpRelevantToGlobalPoint(QRect(0,0,0,0), popUpRect);
} }
//qDebug() << "7..."; //qDebug() << "7...";

@ -63,8 +63,10 @@ private:
void addContainmentActions(QMenu *desktopMenu, QEvent *event); void addContainmentActions(QMenu *desktopMenu, QEvent *event);
void updateAppletContainsMethod(); void updateAppletContainsMethod();
QPoint popUpTopLeft(const QRect &parentItem, const QRect popUpRect); QPoint popUpRelevantToParent(const QRect &parentItem, const QRect popUpRect);
QPoint popUpTopLeft(const Plasma::Applet *applet, const QRect popUpRect); QPoint popUpRelevantToGlobalPoint(const QRect &parentItem, const QRect popUpRect);
QPoint popUpTopLeft(Plasma::Applet *applet, const QRect popUpRect);
Plasma::Containment *containmentById(uint id); Plasma::Containment *containmentById(uint id);

Loading…
Cancel
Save