From b233c6e735e0877833aff8f4865fd26255381953 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 9 Jan 2014 16:36:59 +0100 Subject: [PATCH] simplify --- src/declarativeimports/core/dialog.cpp | 16 ++++----- src/declarativeimports/core/dialog.h | 2 +- src/declarativeimports/core/tooltipdialog.cpp | 35 ++++++------------- src/declarativeimports/core/tooltipdialog.h | 2 +- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/declarativeimports/core/dialog.cpp b/src/declarativeimports/core/dialog.cpp index 9545186b9..2ab823c0c 100644 --- a/src/declarativeimports/core/dialog.cpp +++ b/src/declarativeimports/core/dialog.cpp @@ -118,7 +118,7 @@ void DialogProxy::setVisualParent(QQuickItem *visualParent) m_visualParent = visualParent; emit visualParentChanged(); if (visualParent && isVisible()) { - adjustPosition(popupPosition(visualParent, Qt::AlignCenter)); + adjustGeometry(QRect(popupPosition(visualParent, Qt::AlignCenter), size())); } } @@ -142,9 +142,7 @@ void DialogProxy::onVisibleChanged() syncMainItemToSize(); m_cachedGeometry = QRect(); } - if (m_visualParent) { - adjustPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter)); - } + syncToMainItemSize(); } } @@ -317,9 +315,9 @@ QObject *DialogProxy::margins() const return m_frameSvgItem->margins(); } -void DialogProxy::adjustPosition(const QPoint &point) +void DialogProxy::adjustGeometry(const QRect &geom) { - setPosition(point); + setGeometry(geom); } void DialogProxy::resizeEvent(QResizeEvent *re) @@ -353,9 +351,11 @@ void DialogProxy::syncToMainItemSize() const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height()) + QSize(m_frameSvgItem->margins()->left() + m_frameSvgItem->margins()->right(), m_frameSvgItem->margins()->top() + m_frameSvgItem->margins()->bottom()); - resize(s); + if (visualParent()) { - adjustPosition(popupPosition(visualParent(), Qt::AlignCenter)); + adjustGeometry(QRect(popupPosition(visualParent(), Qt::AlignCenter), s)); + } else { + resize(s); } emit widthChanged(s.width()); diff --git a/src/declarativeimports/core/dialog.h b/src/declarativeimports/core/dialog.h index 382e9fc8b..35036d9be 100644 --- a/src/declarativeimports/core/dialog.h +++ b/src/declarativeimports/core/dialog.h @@ -108,7 +108,7 @@ public: /* * set the dialog position. subclasses may change it. ToolTipDialog adjusts the position in an animated way */ - virtual void adjustPosition(const QPoint &point); + virtual void adjustGeometry(const QRect &geom); /** * @returns The suggested screen position for the popup diff --git a/src/declarativeimports/core/tooltipdialog.cpp b/src/declarativeimports/core/tooltipdialog.cpp index 9f32eefa0..bce0c7dca 100644 --- a/src/declarativeimports/core/tooltipdialog.cpp +++ b/src/declarativeimports/core/tooltipdialog.cpp @@ -100,38 +100,22 @@ void ToolTipDialog::hideEvent(QHideEvent *event) void ToolTipDialog::resizeEvent(QResizeEvent *re) { - //TODO: less duplication - if (!m_animation) { - m_animation = new QPropertyAnimation(this); - connect(m_animation, SIGNAL(valueChanged(QVariant)), - this, SLOT(valueChanged(QVariant))); - m_animation->setTargetObject(this); - m_animation->setEasingCurve(QEasingCurve::InOutQuad); - m_animation->setDuration(250); - } - m_animation->stop(); + DialogProxy::resizeEvent(re); +} +void ToolTipDialog::adjustGeometry(const QRect &geom) +{ switch (m_direction) { case Plasma::Types::Right: - setX(x() + (re->oldSize().width() - re->size().width())); + setX(x() + (size().width() - geom.size().width())); break; case Plasma::Types::Up: - setY(y() + (re->oldSize().height() - re->size().height())); + setY(y() + (size().height() - geom.size().height())); break; default: break; } - if (isVisible()) { - m_animation->setStartValue(position()); - m_animation->setEndValue(popupPosition(visualParent(), Qt::AlignCenter)); - m_animation->start(); - } - DialogProxy::resizeEvent(re); -} - -void ToolTipDialog::adjustPosition(const QPoint &point) -{ if (isVisible()) { if (!m_animation) { m_animation = new QPropertyAnimation(this); @@ -142,11 +126,14 @@ void ToolTipDialog::adjustPosition(const QPoint &point) m_animation->setDuration(250); } + + resize(geom.size()); + m_animation->setStartValue(position()); - m_animation->setEndValue(point); + m_animation->setEndValue(geom.topLeft()); m_animation->start(); } else { - setPosition(point); + setGeometry(geom); } } diff --git a/src/declarativeimports/core/tooltipdialog.h b/src/declarativeimports/core/tooltipdialog.h index 3525edda2..5e7960263 100644 --- a/src/declarativeimports/core/tooltipdialog.h +++ b/src/declarativeimports/core/tooltipdialog.h @@ -53,7 +53,7 @@ public: /** * animate the position change if visible */ - virtual void adjustPosition(const QPoint &point); + virtual void adjustGeometry(const QRect &geom); static ToolTipDialog* instance();