From f81fbea365f182ea5980e1e2984d7fcadafb9f2c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 18 Oct 2013 17:20:59 +0200 Subject: [PATCH] simpler and more correct border calculation --- src/declarativeimports/core/dialog.cpp | 69 ++++++++++++++------------ src/declarativeimports/core/dialog.h | 3 ++ 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/declarativeimports/core/dialog.cpp b/src/declarativeimports/core/dialog.cpp index a88f2d345..0eda0b736 100644 --- a/src/declarativeimports/core/dialog.cpp +++ b/src/declarativeimports/core/dialog.cpp @@ -57,6 +57,10 @@ DialogProxy::DialogProxy(QQuickItem *parent) m_syncTimer->setInterval(250); connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize); + //Can't just connect to start() since it can't resolve the overload + connect(this, &QWindow::xChanged, [=](){m_syncTimer->start();}); + connect(this, &QWindow::yChanged, [=](){m_syncTimer->start();}); + //HACK: this property is invoked due to the initialization that gets done to contentItem() in the getter property("data"); //Create the FrameSvg background. @@ -129,41 +133,17 @@ bool DialogProxy::isVisible() const void DialogProxy::setVisible(const bool visible) { - //QRect avail = QRect(400, 300, 1200, 800); // FIXME - QRect avail; if (visible) { - syncToMainItemSize(); - if (!m_visualParent.isNull() && m_visualParent.data()->window()) { - avail = m_visualParent.data()->window()->screen()->availableGeometry(); - if (location() == Plasma::Types::FullScreen) { - m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::NoBorder); - setGeometry(avail); + if (location() == Plasma::Types::FullScreen) { + m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::NoBorder); + setGeometry(screen()->availableGeometry()); - } else { - m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::AllBorders); - QPoint p = popupPosition(m_visualParent.data(), Qt::AlignCenter); - - int borders = Plasma::FrameSvg::AllBorders; - if (p.x() <= 0) { - borders = borders & ~Plasma::FrameSvg::LeftBorder; - } - if (p.y() <= 0) { - borders = borders & ~Plasma::FrameSvg::TopBorder; - } - if (avail.width() <= p.x() + m_visualParent.data()->width()) { - borders = borders & ~Plasma::FrameSvg::RightBorder; - } - if (avail.height() <= p.y() + m_visualParent.data()->height()) { - borders = borders & ~Plasma::FrameSvg::BottomBorder; - } - m_frameSvgItem->setEnabledBorders((Plasma::FrameSvg::EnabledBorder)borders); - syncToMainItemSize(); - setPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter)); - } } else { - // no visual parent or window -> center on screen - setPosition((avail.width() - width()) / 2, (avail.height() - height()) / 2); + //syncToMainItemSize(); + setPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter)); + syncBorders(); } + raise(); } DialogShadows::self()->addWindow(this, m_frameSvgItem->enabledBorders()); @@ -346,6 +326,7 @@ void DialogProxy::syncToMainItemSize() resize(s); emit widthChanged(s.width()); emit heightChanged(s.height()); + syncBorders(); } /* @@ -422,5 +403,31 @@ void DialogProxy::showEvent(QShowEvent *event) QQuickWindow::showEvent(event); } +void DialogProxy::syncBorders() +{ + //syncToMainItemSize(); + + const QRect avail = screen()->availableGeometry(); + + m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::AllBorders); + + int borders = Plasma::FrameSvg::AllBorders; + if (x() <= avail.x()) { + borders = borders & ~Plasma::FrameSvg::LeftBorder; + } + if (y() <= avail.y()) { + borders = borders & ~Plasma::FrameSvg::TopBorder; + } + if (avail.right() <= x() + width()) { + borders = borders & ~Plasma::FrameSvg::RightBorder; + } + if (avail.bottom() <= y() + height()) { + borders = borders & ~Plasma::FrameSvg::BottomBorder; + } + m_frameSvgItem->setEnabledBorders((Plasma::FrameSvg::EnabledBorder)borders); + DialogShadows::self()->addWindow(this, m_frameSvgItem->enabledBorders()); + //syncToMainItemSize(); +} + #include "dialog.moc" diff --git a/src/declarativeimports/core/dialog.h b/src/declarativeimports/core/dialog.h index 58e3c0255..890e16fcf 100644 --- a/src/declarativeimports/core/dialog.h +++ b/src/declarativeimports/core/dialog.h @@ -156,6 +156,9 @@ protected: QWeakPointer m_mainItem; QWeakPointer m_visualParent; +private Q_SLOTS: + void syncBorders(); + private: Qt::WindowFlags m_flags; bool m_activeWindow;