This commit is contained in:
Marco Martin 2014-01-09 16:36:59 +01:00
parent 1f2f706c10
commit b233c6e735
4 changed files with 21 additions and 34 deletions

View File

@ -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());

View File

@ -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

View File

@ -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);
}
}

View File

@ -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();