Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/core/tooltipdialog.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 57 | if (!m_qmlObject->rootObject()) { | |||
---|---|---|---|---|---|
64 | } | 64 | } | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | return qobject_cast<QQuickItem *>(m_qmlObject->rootObject()); | 67 | return qobject_cast<QQuickItem *>(m_qmlObject->rootObject()); | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | void ToolTipDialog::showEvent(QShowEvent *event) | 70 | void ToolTipDialog::showEvent(QShowEvent *event) | ||
71 | { | 71 | { | ||
72 | if (m_autoShowHide) { | ||||
72 | m_showTimer->start(m_hideTimeout); | 73 | m_showTimer->start(m_hideTimeout); | ||
74 | } else { | ||||
75 | m_showTimer->stop(); | ||||
76 | } | ||||
73 | 77 | | |||
74 | Dialog::showEvent(event); | 78 | Dialog::showEvent(event); | ||
75 | } | 79 | } | ||
76 | 80 | | |||
77 | void ToolTipDialog::hideEvent(QHideEvent *event) | 81 | void ToolTipDialog::hideEvent(QHideEvent *event) | ||
78 | { | 82 | { | ||
79 | m_showTimer->stop(); | 83 | m_showTimer->stop(); | ||
80 | 84 | | |||
81 | Dialog::hideEvent(event); | 85 | Dialog::hideEvent(event); | ||
82 | } | 86 | } | ||
83 | 87 | | |||
84 | void ToolTipDialog::resizeEvent(QResizeEvent *re) | 88 | void ToolTipDialog::resizeEvent(QResizeEvent *re) | ||
85 | { | 89 | { | ||
86 | Dialog::resizeEvent(re); | 90 | Dialog::resizeEvent(re); | ||
87 | } | 91 | } | ||
88 | 92 | | |||
89 | bool ToolTipDialog::event(QEvent *e) | 93 | bool ToolTipDialog::event(QEvent *e) | ||
90 | { | 94 | { | ||
91 | if (e->type() == QEvent::Enter) { | 95 | if (e->type() == QEvent::Enter) { | ||
96 | setContainsMouse(true); | ||||
92 | if (m_interactive) { | 97 | if (m_interactive) { | ||
93 | m_showTimer->stop(); | 98 | m_showTimer->stop(); | ||
94 | } | 99 | } | ||
95 | } else if (e->type() == QEvent::Leave) { | 100 | } else if (e->type() == QEvent::Leave) { | ||
96 | dismiss(); | 101 | setContainsMouse(false); | ||
102 | if (m_autoShowHide) { | ||||
103 | dismiss(m_owner); | ||||
104 | } | ||||
97 | } | 105 | } | ||
98 | 106 | | |||
99 | bool ret = Dialog::event(e); | 107 | bool ret = Dialog::event(e); | ||
100 | Qt::WindowFlags flags = Qt::ToolTip | Qt::WindowDoesNotAcceptFocus | Qt::WindowStaysOnTopHint; | 108 | Qt::WindowFlags flags = Qt::ToolTip | Qt::WindowDoesNotAcceptFocus | Qt::WindowStaysOnTopHint; | ||
101 | if (KWindowSystem::isPlatformX11()) { | 109 | if (KWindowSystem::isPlatformX11()) { | ||
102 | flags = flags | Qt::BypassWindowManagerHint; | 110 | flags = flags | Qt::BypassWindowManagerHint; | ||
103 | } | 111 | } | ||
104 | setFlags(flags); | 112 | setFlags(flags); | ||
105 | return ret; | 113 | return ret; | ||
106 | } | 114 | } | ||
107 | 115 | | |||
108 | QObject *ToolTipDialog::owner() const | 116 | QObject *ToolTipDialog::owner() const | ||
109 | { | 117 | { | ||
110 | return m_owner; | 118 | return m_owner; | ||
111 | } | 119 | } | ||
112 | 120 | | |||
113 | void ToolTipDialog::setOwner(QObject *owner) | 121 | void ToolTipDialog::setOwner(QObject *owner) | ||
114 | { | 122 | { | ||
123 | if(m_owner != owner) { | ||||
115 | m_owner = owner; | 124 | m_owner = owner; | ||
125 | m_showTimer->stop(); // if the owner changes then don't hide the dialog | ||||
126 | } | ||||
116 | } | 127 | } | ||
117 | 128 | | |||
118 | void ToolTipDialog::dismiss() | 129 | void ToolTipDialog::dismiss(QObject *owner) | ||
119 | { | 130 | { | ||
131 | if(m_owner == owner) { // only dismiss if the dialog is owned by the requester | ||||
120 | m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms | 132 | m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms | ||
121 | } | 133 | } | ||
134 | } | ||||
122 | 135 | | |||
123 | void ToolTipDialog::keepalive() | 136 | void ToolTipDialog::keepalive() | ||
124 | { | 137 | { | ||
138 | if(m_autoShowHide) { | ||||
125 | m_showTimer->start(m_hideTimeout); | 139 | m_showTimer->start(m_hideTimeout); | ||
140 | } else { | ||||
141 | m_showTimer->stop(); | ||||
142 | } | ||||
126 | } | 143 | } | ||
127 | 144 | | |||
128 | bool ToolTipDialog::interactive() | 145 | bool ToolTipDialog::interactive() | ||
129 | { | 146 | { | ||
130 | return m_interactive; | 147 | return m_interactive; | ||
131 | } | 148 | } | ||
132 | 149 | | |||
133 | void ToolTipDialog::setInteractive(bool interactive) | 150 | void ToolTipDialog::setInteractive(bool interactive) | ||
134 | { | 151 | { | ||
135 | m_interactive = interactive; | 152 | m_interactive = interactive; | ||
136 | setOutputOnly(!interactive); | 153 | setOutputOnly(!interactive); | ||
137 | } | 154 | } | ||
138 | 155 | | |||
139 | void ToolTipDialog::valueChanged(const QVariant &value) | 156 | void ToolTipDialog::valueChanged(const QVariant &value) | ||
140 | { | 157 | { | ||
141 | setPosition(value.toPoint()); | 158 | setPosition(value.toPoint()); | ||
142 | } | 159 | } | ||
143 | 160 | | |||
161 | bool ToolTipDialog::autoShowHide() | ||||
162 | { | ||||
163 | return m_autoShowHide; | ||||
164 | } | ||||
165 | | ||||
166 | void ToolTipDialog::setAutoShowHide(bool autoShowHide) | ||||
167 | { | ||||
168 | m_autoShowHide = autoShowHide; | ||||
169 | } | ||||
170 | | ||||
171 | bool ToolTipDialog::containsMouse() | ||||
172 | { | ||||
173 | return m_containsMouse; | ||||
174 | } | ||||
175 | | ||||
176 | void ToolTipDialog::setContainsMouse(bool contains) | ||||
177 | { | ||||
178 | if (m_containsMouse != contains) { | ||||
179 | m_containsMouse = contains; | ||||
180 | emit containsMouseChanged(); | ||||
181 | } | ||||
182 | } | ||||
183 | | ||||
144 | #include "moc_tooltipdialog.cpp" | 184 | #include "moc_tooltipdialog.cpp" |