animated tooltips are back

This commit is contained in:
Marco Martin 2014-01-09 12:10:22 +01:00
parent bb7157a59e
commit 5836128789
4 changed files with 51 additions and 5 deletions

View File

@ -118,7 +118,7 @@ void DialogProxy::setVisualParent(QQuickItem *visualParent)
m_visualParent = visualParent;
emit visualParentChanged();
if (visualParent && isVisible()) {
setPosition(popupPosition(visualParent, Qt::AlignCenter));
adjustPosition(popupPosition(visualParent, Qt::AlignCenter));
}
}
@ -143,7 +143,7 @@ void DialogProxy::onVisibleChanged()
m_cachedGeometry = QRect();
}
if (m_visualParent) {
setPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter));
adjustPosition(popupPosition(m_visualParent.data(), Qt::AlignCenter));
}
syncToMainItemSize();
}
@ -317,6 +317,11 @@ QObject *DialogProxy::margins() const
return m_frameSvgItem->margins();
}
void DialogProxy::adjustPosition(const QPoint &point)
{
setPosition(point);
}
void DialogProxy::resizeEvent(QResizeEvent *re)
{
syncMainItemToSize();
@ -350,7 +355,7 @@ void DialogProxy::syncToMainItemSize()
m_frameSvgItem->margins()->top() + m_frameSvgItem->margins()->bottom());
resize(s);
if (visualParent()) {
setPosition(popupPosition(visualParent(), Qt::AlignCenter));
adjustPosition(popupPosition(visualParent(), Qt::AlignCenter));
}
emit widthChanged(s.width());

View File

@ -105,6 +105,11 @@ public:
QObject *margins() const;
/*
* set the dialog position. subclasses may change it. ToolTipDialog adjusts the position in an animated way
*/
virtual void adjustPosition(const QPoint &point);
/**
* @returns The suggested screen position for the popup
* @arg item the item the popup has to be positioned relatively to. if null, the popup will be positioned in the center of the window

View File

@ -22,6 +22,7 @@
#include <QQmlEngine>
#include <QQuickItem>
#include <QDebug>
#include <QPropertyAnimation>
#include "framesvgitem.h"
@ -32,6 +33,7 @@ Q_GLOBAL_STATIC(ToolTipDialog, toolTipDialogInstance)
ToolTipDialog::ToolTipDialog(QQuickItem *parent)
: DialogProxy(parent),
m_qmlObject(0),
m_animation(0),
m_hideTimeout(4000)
{
setFlags(Qt::ToolTip);
@ -75,6 +77,26 @@ void ToolTipDialog::showEvent(QShowEvent *event)
DialogProxy::showEvent(event);
}
void ToolTipDialog::adjustPosition(const QPoint &point)
{
if (isVisible()) {
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->setStartValue(position());
m_animation->setEndValue(point);
m_animation->start();
} else {
setPosition(point);
}
}
void ToolTipDialog::dismiss()
{
m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms
@ -85,10 +107,14 @@ void ToolTipDialog::keepalive()
m_showTimer->start(m_hideTimeout);
}
void ToolTipDialog::valueChanged(const QVariant &value)
{
setPosition(value.value<QPoint>());
}
ToolTipDialog* ToolTipDialog::instance()
{
return toolTipDialogInstance();
}
#include "moc_tooltipdialog.cpp"

View File

@ -30,6 +30,7 @@
class QQuickItem;
class QGraphicsWidget;
class QmlObject;
class QPropertyAnimation;
/**
* QML wrapper for kdelibs Plasma::ToolTipDialog
@ -46,6 +47,11 @@ public:
QQuickItem *loadDefaultItem();
/**
* animate the position change if visible
*/
virtual void adjustPosition(const QPoint &point);
static ToolTipDialog* instance();
void dismiss();
@ -54,9 +60,13 @@ public:
protected:
void showEvent(QShowEvent *event);
private Q_SLOTS:
void valueChanged(const QVariant &value);
private:
QmlObject *m_qmlObject;
QTimer *m_showTimer;
QPropertyAnimation *m_animation;
int m_hideTimeout;
};