simpler and more correct border calculation

This commit is contained in:
Marco Martin 2013-10-18 17:20:59 +02:00
parent 9423ad57f2
commit f81fbea365
2 changed files with 41 additions and 31 deletions

View File

@ -57,6 +57,10 @@ DialogProxy::DialogProxy(QQuickItem *parent)
m_syncTimer->setInterval(250); m_syncTimer->setInterval(250);
connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize); 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 //HACK: this property is invoked due to the initialization that gets done to contentItem() in the getter
property("data"); property("data");
//Create the FrameSvg background. //Create the FrameSvg background.
@ -129,41 +133,17 @@ bool DialogProxy::isVisible() const
void DialogProxy::setVisible(const bool visible) void DialogProxy::setVisible(const bool visible)
{ {
//QRect avail = QRect(400, 300, 1200, 800); // FIXME
QRect avail;
if (visible) { if (visible) {
syncToMainItemSize(); if (location() == Plasma::Types::FullScreen) {
if (!m_visualParent.isNull() && m_visualParent.data()->window()) { m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::NoBorder);
avail = m_visualParent.data()->window()->screen()->availableGeometry(); setGeometry(screen()->availableGeometry());
if (location() == Plasma::Types::FullScreen) {
m_frameSvgItem->setEnabledBorders(Plasma::FrameSvg::NoBorder);
setGeometry(avail);
} 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 { } else {
// no visual parent or window -> center on screen //syncToMainItemSize();
setPosition((avail.width() - width()) / 2, (avail.height() - height()) / 2); setPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter));
syncBorders();
} }
raise(); raise();
} }
DialogShadows::self()->addWindow(this, m_frameSvgItem->enabledBorders()); DialogShadows::self()->addWindow(this, m_frameSvgItem->enabledBorders());
@ -346,6 +326,7 @@ void DialogProxy::syncToMainItemSize()
resize(s); resize(s);
emit widthChanged(s.width()); emit widthChanged(s.width());
emit heightChanged(s.height()); emit heightChanged(s.height());
syncBorders();
} }
/* /*
@ -422,5 +403,31 @@ void DialogProxy::showEvent(QShowEvent *event)
QQuickWindow::showEvent(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" #include "dialog.moc"

View File

@ -156,6 +156,9 @@ protected:
QWeakPointer<QQuickItem> m_mainItem; QWeakPointer<QQuickItem> m_mainItem;
QWeakPointer<QQuickItem> m_visualParent; QWeakPointer<QQuickItem> m_visualParent;
private Q_SLOTS:
void syncBorders();
private: private:
Qt::WindowFlags m_flags; Qt::WindowFlags m_flags;
bool m_activeWindow; bool m_activeWindow;