new property: interactive (default false)
if interactive is true, when the mouse cursor leavesthe tooltiparea and enters the tooltip, it won't hide, so it will be possible to interacti with it
This commit is contained in:
parent
63c62d6da8
commit
a4f14a966a
@ -33,7 +33,8 @@ ToolTip::ToolTip(QQuickItem *parent)
|
||||
: QQuickItem(parent),
|
||||
m_containsMouse(false),
|
||||
m_location(Plasma::Types::Floating),
|
||||
m_active(true)
|
||||
m_active(true),
|
||||
m_interactive(false)
|
||||
{
|
||||
m_showTimer = new QTimer(this);
|
||||
m_showTimer->setSingleShot(true);
|
||||
@ -124,6 +125,7 @@ void ToolTip::showToolTip()
|
||||
dlg->setLocation(location);
|
||||
dlg->setMainItem(mainItem());
|
||||
dlg->setVisualParent(this);
|
||||
dlg->setInteractive(m_interactive);
|
||||
dlg->setVisible(true);
|
||||
}
|
||||
|
||||
@ -184,6 +186,17 @@ void ToolTip::setActive(bool active)
|
||||
emit activeChanged();
|
||||
}
|
||||
|
||||
void ToolTip::setInteractive(bool interactive)
|
||||
{
|
||||
if (m_interactive == interactive) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_interactive = interactive;
|
||||
|
||||
emit interactiveChanged();
|
||||
}
|
||||
|
||||
QVariant ToolTip::icon() const
|
||||
{
|
||||
if (m_icon.isValid()) {
|
||||
|
@ -107,6 +107,12 @@ class ToolTip : public QQuickItem
|
||||
*/
|
||||
Q_PROPERTY(bool active MEMBER m_active WRITE setActive NOTIFY activeChanged)
|
||||
|
||||
/**
|
||||
* if interactive is false (default), the tooltip will automatically hide
|
||||
* itself as soon as the mouse leaves the tooltiparea, if is true, if the mouse leaves tooltiparea and goes over the tooltip itself, the tooltip won't hide, so it will be possible to interact with tooltip contents
|
||||
*/
|
||||
Q_PROPERTY(bool interactive MEMBER m_interactive WRITE setInteractive NOTIFY interactiveChanged)
|
||||
|
||||
public:
|
||||
ToolTip(QQuickItem *parent = 0);
|
||||
~ToolTip();
|
||||
@ -136,6 +142,8 @@ public:
|
||||
|
||||
void setActive(bool active);
|
||||
|
||||
void setInteractive(bool interactive);
|
||||
|
||||
protected:
|
||||
bool childMouseEventFilter(QQuickItem *item, QEvent *event);
|
||||
void hoverEnterEvent(QHoverEvent *event);
|
||||
@ -151,6 +159,7 @@ Q_SIGNALS:
|
||||
void containsMouseChanged();
|
||||
void locationChanged();
|
||||
void activeChanged();
|
||||
void interactiveChanged();
|
||||
|
||||
private:
|
||||
bool m_containsMouse;
|
||||
@ -162,6 +171,7 @@ private:
|
||||
QVariant m_image;
|
||||
QVariant m_icon;
|
||||
bool m_active;
|
||||
bool m_interactive;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -35,7 +35,8 @@ ToolTipDialog::ToolTipDialog(QQuickItem *parent)
|
||||
m_qmlObject(0),
|
||||
m_animation(0),
|
||||
m_hideTimeout(4000),
|
||||
m_direction(Plasma::Types::Up)
|
||||
m_direction(Plasma::Types::Up),
|
||||
m_interactive(false)
|
||||
{
|
||||
setFlags(Qt::ToolTip);
|
||||
setLocation(Plasma::Types::Floating);
|
||||
@ -92,6 +93,7 @@ void ToolTipDialog::setDirection(Plasma::Types::Direction dir)
|
||||
void ToolTipDialog::showEvent(QShowEvent *event)
|
||||
{
|
||||
m_showTimer->start(m_hideTimeout);
|
||||
|
||||
m_animation->stop();
|
||||
DialogProxy::showEvent(event);
|
||||
setFlags(Qt::ToolTip);
|
||||
@ -110,6 +112,18 @@ void ToolTipDialog::resizeEvent(QResizeEvent *re)
|
||||
DialogProxy::resizeEvent(re);
|
||||
}
|
||||
|
||||
bool ToolTipDialog::event(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::Enter) {
|
||||
if (m_interactive) {
|
||||
m_showTimer->stop();
|
||||
}
|
||||
} else if (e->type() == QEvent::Leave) {
|
||||
dismiss();
|
||||
}
|
||||
return DialogProxy::event(e);
|
||||
}
|
||||
|
||||
void ToolTipDialog::adjustGeometry(const QRect &geom)
|
||||
{
|
||||
switch (m_direction) {
|
||||
@ -126,7 +140,6 @@ void ToolTipDialog::adjustGeometry(const QRect &geom)
|
||||
if (isVisible()) {
|
||||
|
||||
resize(geom.size());
|
||||
|
||||
m_animation->setStartValue(position());
|
||||
m_animation->setEndValue(geom.topLeft());
|
||||
m_animation->start();
|
||||
@ -145,6 +158,16 @@ void ToolTipDialog::keepalive()
|
||||
m_showTimer->start(m_hideTimeout);
|
||||
}
|
||||
|
||||
bool ToolTipDialog::interactive()
|
||||
{
|
||||
return m_interactive;
|
||||
}
|
||||
|
||||
void ToolTipDialog::setInteractive(bool interactive)
|
||||
{
|
||||
m_interactive = interactive;
|
||||
}
|
||||
|
||||
void ToolTipDialog::valueChanged(const QVariant &value)
|
||||
{
|
||||
setPosition(value.value<QPoint>());
|
||||
|
@ -64,10 +64,14 @@ public:
|
||||
void dismiss();
|
||||
void keepalive();
|
||||
|
||||
bool interactive();
|
||||
void setInteractive(bool interactive);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event);
|
||||
void hideEvent(QHideEvent *event);
|
||||
void resizeEvent(QResizeEvent *re);
|
||||
bool event(QEvent *e);
|
||||
|
||||
private Q_SLOTS:
|
||||
void valueChanged(const QVariant &value);
|
||||
@ -78,6 +82,7 @@ private:
|
||||
QPropertyAnimation *m_animation;
|
||||
int m_hideTimeout;
|
||||
Plasma::Types::Direction m_direction;
|
||||
bool m_interactive;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user