1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-26 23:21:37 +03:00

override Dialog::popupPosition

--instead of adjustGeometry we now use
popupPosition which is used in more places
in order to place the PlasmaQuick popups
correctly based on Latte requirements
This commit is contained in:
Michail Vourlakos 2021-05-09 20:47:17 +03:00
parent 15d384e812
commit 690ce51d75
2 changed files with 69 additions and 2 deletions

View File

@ -95,6 +95,71 @@ void Dialog::updatePopUpEnabledBorders()
}
}
QPoint Dialog::popupPosition(QQuickItem *item, const QSize &size)
{
auto visualparent = item;
if (visualparent && visualparent->window() && visualparent->window()->screen()) {
updatePopUpEnabledBorders();
QPointF parenttopleftf = visualparent->mapToGlobal(QPointF(0, 0));
QPoint parenttopleft = parenttopleftf.toPoint();
QScreen *screen = visualparent->window()->screen();
QRect screengeometry = screen->geometry();
int x = 0;
int y = 0;
if (m_edge == Plasma::Types::LeftEdge || m_edge == Plasma::Types::RightEdge) {
y = parenttopleft.y() + (visualparent->height()/2) - (size.height()/2);
} else {
x = parenttopleft.x() + (visualparent->width()/2) - (size.width()/2);
}
int popupmargin = qMax(0, appletsPopUpMargin());
if (m_edge == Plasma::Types::LeftEdge) {
x = parenttopleft.x() + visualparent->width() + popupmargin;
} else if (m_edge == Plasma::Types::RightEdge) {
x = parenttopleft.x() - size.width() - popupmargin;
} else if (m_edge == Plasma::Types::TopEdge) {
y = parenttopleft.y() + visualparent->height() + popupmargin;
} else { // bottom case
y = parenttopleft.y() - size.height() - popupmargin;
}
x = qBound(screengeometry.x(), x, screengeometry.right()-1);
y = qBound(screengeometry.y(), y, screengeometry.bottom()-1);
QRect appletslayoutgeometry = appletsLayoutGeometryFromContainment();
if (isRespectingAppletsLayoutGeometry() && !appletslayoutgeometry.isEmpty()) {
QPoint appletsglobaltopleft = visualparent->window()->mapToGlobal(appletslayoutgeometry.topLeft());
QRect appletsglobalgeometry(appletsglobaltopleft.x(), appletsglobaltopleft.y(), appletslayoutgeometry.width(), appletslayoutgeometry.height());
if (m_edge == Plasma::Types::LeftEdge || m_edge == Plasma::Types::RightEdge) {
int bottomy = appletsglobalgeometry.bottom()-size.height();
if (appletsglobalgeometry.height() >= size.height()) {
y = qBound(appletsglobalgeometry.y(), y, bottomy + 1);
}
} else {
int rightx = appletsglobalgeometry.right()-size.width();
if (appletsglobalgeometry.width() >= size.width()) {
x = qBound(appletsglobalgeometry.x(), x, rightx + 1);
}
}
}
return QPoint(x,y);
}
return PlasmaQuick::Dialog::popupPosition(item, size);
}
/*
void Dialog::adjustGeometry(const QRect &geom)
{
auto visualparent = visualParent();
@ -160,7 +225,7 @@ void Dialog::adjustGeometry(const QRect &geom)
PlasmaQuick::Dialog::adjustGeometry(geom);
}
*/
bool Dialog::event(QEvent *e)
{

View File

@ -46,12 +46,14 @@ public:
Plasma::Types::Location edge() const;
void setEdge(const Plasma::Types::Location &edge);
QPoint popupPosition(QQuickItem *item, const QSize &size) override;
signals:
void containsMouseChanged();
void edgeChanged();
protected:
void adjustGeometry(const QRect &geom) override;
// void adjustGeometry(const QRect &geom) override;
bool event(QEvent *e) override;