LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
tooltipitem.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2010-2013 Oleg Linkin <MaledictusDeMagog@gmail.com>
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "tooltipitem.h"
10 #include <QToolTip>
11 #include <QtDebug>
12 
13 namespace LC::Util
14 {
15  ToolTipItem::ToolTipItem (QQuickItem *parent)
16  : QQuickItem (parent)
17  {
18  setAcceptHoverEvents (true);
19  connect (&ShowTimer_,
20  &QTimer::timeout,
21  this,
23  ShowTimer_.setSingleShot (true);
24  }
25 
26  void ToolTipItem::SetText (const QString& text)
27  {
28  if (Text_ != text)
29  {
30  Text_ = text;
31  emit textChanged ();
32  }
33  }
34 
35  QString ToolTipItem::GetText () const
36  {
37  return Text_;
38  }
39 
40  bool ToolTipItem::ContainsMouse () const
41  {
42  return ContainsMouse_;
43  }
44 
45  void ToolTipItem::ShowToolTip (const QString& text) const
46  {
47  QToolTip::showText (cursor ().pos (), text);
48  }
49 
50  void ToolTipItem::hoverEnterEvent (QHoverEvent *event)
51  {
52  ShowTimer_.start (1000);
53  ContainsMouse_ = true;
54  emit containsMouseChanged ();
55  QQuickItem::hoverEnterEvent (event);
56  }
57 
58  void ToolTipItem::hoverLeaveEvent (QHoverEvent *event)
59  {
60  ShowTimer_.stop ();
61  ContainsMouse_ = false;
62  emit containsMouseChanged ();
63  QQuickItem::hoverLeaveEvent (event);
64  }
65 
67  {
68  ShowToolTip (Text_);
69  }
70 }
LC::Util
Definition: icoreproxy.h:33
LC::Util::ToolTipItem::containsMouseChanged
void containsMouseChanged()
Emitted when the containsMouse property changes.
LC::Util::ToolTipItem::textChanged
void textChanged()
Emitted when the text of this tooltip changes.
LC::Util::ToolTipItem::showToolTip
void showToolTip()
Shows the tooltip immediately.
Definition: tooltipitem.cpp:72
LC::Util::ToolTipItem::hoverLeaveEvent
void hoverLeaveEvent(QHoverEvent *) override
Definition: tooltipitem.cpp:64
LC::Util::ToolTipItem::ContainsMouse
bool ContainsMouse() const
Returns whether the tooltip contains the mouse.
Definition: tooltipitem.cpp:46
LC::Util::ToolTipItem::ShowToolTip
void ShowToolTip(const QString &text) const
Shows tooltip with the given text immediately.
Definition: tooltipitem.cpp:51
LC::Util::ToolTipItem::text
QString text
The text of this tooltip item (rich text supported).
Definition: tooltipitem.h:68
LC::Util::ToolTipItem::hoverEnterEvent
void hoverEnterEvent(QHoverEvent *) override
Definition: tooltipitem.cpp:56
tooltipitem.h
LC::Util::ToolTipItem::SetText
void SetText(const QString &text)
Sets the text contained in this tooltip to text.
Definition: tooltipitem.cpp:32
LC::Util::ToolTipItem::ToolTipItem
ToolTipItem(QQuickItem *parent=nullptr)
Constructs the tooltip with the given parent item.
Definition: tooltipitem.cpp:21
LC::Util::ToolTipItem::GetText
QString GetText() const
Returns the text of this tooltip.
Definition: tooltipitem.cpp:41