Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/core/tooltip.cpp
Show All 34 Lines | |||||
35 | 35 | | |||
36 | ToolTip::ToolTip(QQuickItem *parent) | 36 | ToolTip::ToolTip(QQuickItem *parent) | ||
37 | : QQuickItem(parent), | 37 | : QQuickItem(parent), | ||
38 | m_tooltipsEnabledGlobally(false), | 38 | m_tooltipsEnabledGlobally(false), | ||
39 | m_containsMouse(false), | 39 | m_containsMouse(false), | ||
40 | m_location(Plasma::Types::Floating), | 40 | m_location(Plasma::Types::Floating), | ||
41 | m_textFormat(Qt::AutoText), | 41 | m_textFormat(Qt::AutoText), | ||
42 | m_active(true), | 42 | m_active(true), | ||
43 | m_autoShowHide(true), | ||||
43 | m_interactive(false), | 44 | m_interactive(false), | ||
44 | m_usingDialog(false) | 45 | m_usingDialog(false) | ||
45 | { | 46 | { | ||
46 | setAcceptHoverEvents(true); | 47 | setAcceptHoverEvents(true); | ||
47 | setFiltersChildMouseEvents(true); | 48 | setFiltersChildMouseEvents(true); | ||
48 | 49 | | |||
49 | m_showTimer = new QTimer(this); | 50 | m_showTimer = new QTimer(this); | ||
50 | m_showTimer->setSingleShot(true); | 51 | m_showTimer->setSingleShot(true); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 151 | if (mainItem()) { | |||
152 | mainItem()->setVisible(true); | 153 | mainItem()->setVisible(true); | ||
153 | } | 154 | } | ||
154 | 155 | | |||
155 | dlg->setOwner(this); | 156 | dlg->setOwner(this); | ||
156 | dlg->setLocation(location); | 157 | dlg->setLocation(location); | ||
157 | dlg->setVisualParent(this); | 158 | dlg->setVisualParent(this); | ||
158 | dlg->setMainItem(mainItem()); | 159 | dlg->setMainItem(mainItem()); | ||
159 | dlg->setInteractive(m_interactive); | 160 | dlg->setInteractive(m_interactive); | ||
161 | dlg->SetAutoShowHide(m_autoShowHide); | ||||
162 | connect(dlg, &ToolTipDialog:.containtsMouseChanged, this, &ToolTip::toolTipWindowContainsMouseChangedSlot); | ||||
davidedmundson: doing a connect inside show() probably isn't what you want, you'll connect multiple times. | |||||
160 | dlg->setVisible(true); | 163 | dlg->setVisible(true); | ||
161 | } | 164 | } | ||
162 | 165 | | |||
163 | QString ToolTip::mainText() const | 166 | QString ToolTip::mainText() const | ||
164 | { | 167 | { | ||
165 | return m_mainText; | 168 | return m_mainText; | ||
166 | } | 169 | } | ||
167 | 170 | | |||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 234 | { | |||
235 | 238 | | |||
236 | m_active = active; | 239 | m_active = active; | ||
237 | if (!active) { | 240 | if (!active) { | ||
238 | tooltipDialogInstance()->dismiss(); | 241 | tooltipDialogInstance()->dismiss(); | ||
239 | } | 242 | } | ||
240 | emit activeChanged(); | 243 | emit activeChanged(); | ||
241 | } | 244 | } | ||
242 | 245 | | |||
246 | void ToolTip::setAutoShowHide(bool autoShowHide) | ||||
247 | { | ||||
248 | if (m_autoShowHide == autoShowHide) { | ||||
249 | return; | ||||
250 | } | ||||
251 | | ||||
252 | m_autoShowHide = autoShowHide; | ||||
253 | emit autoShowHideChanged(); | ||||
254 | } | ||||
255 | | ||||
243 | void ToolTip::setInteractive(bool interactive) | 256 | void ToolTip::setInteractive(bool interactive) | ||
244 | { | 257 | { | ||
245 | if (m_interactive == interactive) { | 258 | if (m_interactive == interactive) { | ||
246 | return; | 259 | return; | ||
247 | } | 260 | } | ||
248 | 261 | | |||
249 | m_interactive = interactive; | 262 | m_interactive = interactive; | ||
250 | 263 | | |||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
301 | } | 314 | } | ||
302 | 315 | | |||
303 | void ToolTip::setContainsMouse(bool contains) | 316 | void ToolTip::setContainsMouse(bool contains) | ||
304 | { | 317 | { | ||
305 | if (m_containsMouse != contains) { | 318 | if (m_containsMouse != contains) { | ||
306 | m_containsMouse = contains; | 319 | m_containsMouse = contains; | ||
307 | emit containsMouseChanged(); | 320 | emit containsMouseChanged(); | ||
308 | } | 321 | } | ||
309 | if (!contains) { | 322 | if (!contains && m_autoShowHide) { | ||
310 | tooltipDialogInstance()->dismiss(); | 323 | tooltipDialogInstance()->dismiss(this); | ||
311 | } | 324 | } | ||
312 | } | 325 | } | ||
313 | 326 | | |||
327 | bool ToolTip::toolTipWindowContainsMouse() const | ||||
328 | { | ||||
329 | return m_toolTipWindowContainsMouse; | ||||
330 | } | ||||
331 | | ||||
332 | void ToolTip::toolTipWindowContainsMouseChangedSlot() { | ||||
333 | m_toolTipWindowContainsMouse = tooltipDialogInstance()->containsMouse(); | ||||
334 | emit toolTipWindowContainsMouseChanged(); | ||||
335 | } | ||||
336 | | ||||
314 | void ToolTip::hoverEnterEvent(QHoverEvent *event) | 337 | void ToolTip::hoverEnterEvent(QHoverEvent *event) | ||
315 | { | 338 | { | ||
316 | Q_UNUSED(event) | 339 | Q_UNUSED(event) | ||
317 | setContainsMouse(true); | 340 | setContainsMouse(true); | ||
318 | 341 | | |||
319 | if (!m_tooltipsEnabledGlobally) { | 342 | if (!m_tooltipsEnabledGlobally) { | ||
320 | return; | 343 | return; | ||
321 | } | 344 | } | ||
322 | 345 | | |||
323 | if (!isValid()) { | 346 | if (!isValid()) { | ||
324 | return; | 347 | return; | ||
325 | } | 348 | } | ||
326 | 349 | | |||
350 | if(m_autoShowHide) { | ||||
327 | if (tooltipDialogInstance()->isVisible()) { | 351 | if (tooltipDialogInstance()->isVisible()) { | ||
328 | // We signal the tooltipmanager that we're "potentially interested, | 352 | // We signal the tooltipmanager that we're "potentially interested, | ||
329 | // and ask to keep it open for a bit, so other items get the chance | 353 | // and ask to keep it open for a bit, so other items get the chance | ||
330 | // to update the content before the tooltip hides -- this avoids | 354 | // to update the content before the tooltip hides -- this avoids | ||
331 | // flickering | 355 | // flickering | ||
332 | // It need to be considered only when other items can deal with tooltip area | 356 | // It need to be considered only when other items can deal with tooltip area | ||
333 | if (m_active) { | 357 | if (m_active) { | ||
334 | tooltipDialogInstance()->keepalive(); | 358 | tooltipDialogInstance()->keepalive(); | ||
335 | //FIXME: showToolTip needs to be renamed in sync or something like that | 359 | //FIXME: showToolTip needs to be renamed in sync or something like that | ||
336 | showToolTip(); | 360 | showToolTip(); | ||
337 | } | 361 | } | ||
338 | } else { | 362 | } else { | ||
339 | m_showTimer->start(m_interval); | 363 | m_showTimer->start(m_interval); | ||
340 | } | 364 | } | ||
341 | } | 365 | } | ||
366 | } | ||||
342 | 367 | | |||
343 | void ToolTip::hoverLeaveEvent(QHoverEvent *event) | 368 | void ToolTip::hoverLeaveEvent(QHoverEvent *event) | ||
344 | { | 369 | { | ||
345 | Q_UNUSED(event) | 370 | Q_UNUSED(event) | ||
346 | setContainsMouse(false); | 371 | setContainsMouse(false); | ||
347 | m_showTimer->stop(); | 372 | m_showTimer->stop(); | ||
348 | } | 373 | } | ||
349 | 374 | | |||
Show All 9 Lines |
doing a connect inside show() probably isn't what you want, you'll connect multiple times.
Also that signal name has a typo