LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
unhoverdeletemixin.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
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
10#include <QWidget>
11#include <QEvent>
12#include <QTimer>
13#include <QtDebug>
14#include <QApplication>
15#include <QStyle>
16
17namespace LC::Util
18{
19 UnhoverDeleteMixin::UnhoverDeleteMixin (QObject *watched, const char *slot)
20 : QObject (watched)
21 , LeaveTimer_ (new QTimer (this))
22 {
23 watched->installEventFilter (this);
24
25 LeaveTimer_->setSingleShot (true);
26 connect (LeaveTimer_,
27 SIGNAL (timeout ()),
28 watched,
29 slot);
30 }
31
32 namespace
33 {
34 int DefaultTimeout ()
35 {
36 return QApplication::style ()->styleHint (QStyle::SH_ToolTip_WakeUpDelay) * 2;
37 }
38 }
39
40 void UnhoverDeleteMixin::Start (std::optional<int> timeout)
41 {
42 if (!ContainsMouse_)
43 LeaveTimer_->start (timeout.value_or (DefaultTimeout ()));
44 }
45
47 {
48 LeaveTimer_->stop ();
49 }
50
51 bool UnhoverDeleteMixin::eventFilter (QObject*, QEvent *event)
52 {
53 switch (event->type ())
54 {
55 case QEvent::Enter:
56 ContainsMouse_ = true;
57 LeaveTimer_->stop ();
58 break;
59 case QEvent::Leave:
60 ContainsMouse_ = false;
61 LeaveTimer_->start (DefaultTimeout ());
62 break;
63 default:
64 break;
65 }
66
67 return false;
68 }
69}
void UTIL_GUI_API Start(std::optional< int > timeout={})
Manually starts the timer.
void UTIL_GUI_API Stop()
Stops the previously started timer.
bool eventFilter(QObject *, QEvent *) override
UTIL_GUI_API UnhoverDeleteMixin(QObject *parent, const char *slot=SLOT(deleteLater()))
Creates the mixin for the given parent widget.