11#include <QAbstractScrollArea>
19 KCursorPrivate::self()->setAutoHideCursor(w, enable, customEventFilter);
24 KCursorPrivate::self()->eventFilter(o, e);
29 KCursorPrivate::self()->hideCursorDelay = ms;
34 return KCursorPrivate::self()->hideCursorDelay;
39KCursorPrivateAutoHideEventFilter::KCursorPrivateAutoHideEventFilter(
QWidget *widget)
41 , m_wasMouseTracking(m_widget->hasMouseTracking())
42 , m_isCursorHidden(false)
43 , m_isOwnCursor(false)
45 mouseWidget()->setMouseTracking(
true);
46 connect(&m_autoHideTimer, &
QTimer::timeout,
this, &KCursorPrivateAutoHideEventFilter::hideCursor);
49KCursorPrivateAutoHideEventFilter::~KCursorPrivateAutoHideEventFilter()
51 if (m_widget !=
nullptr) {
52 mouseWidget()->setMouseTracking(m_wasMouseTracking);
56void KCursorPrivateAutoHideEventFilter::resetWidget()
61void KCursorPrivateAutoHideEventFilter::hideCursor()
63 m_autoHideTimer.stop();
65 if (m_isCursorHidden) {
69 m_isCursorHidden =
true;
81void KCursorPrivateAutoHideEventFilter::unhideCursor()
83 m_autoHideTimer.stop();
85 if (!m_isCursorHidden) {
89 m_isCursorHidden =
false;
106QWidget *KCursorPrivateAutoHideEventFilter::mouseWidget()
const
119bool KCursorPrivateAutoHideEventFilter::eventFilter(
QObject *o,
QEvent *e)
145 if (m_widget->hasFocus()) {
146 m_autoHideTimer.setSingleShot(
true);
147 m_autoHideTimer.start(KCursorPrivate::self()->hideCursorDelay);
157KCursorPrivate *KCursorPrivate::s_self =
nullptr;
159KCursorPrivate *KCursorPrivate::self()
162 s_self =
new KCursorPrivate;
172KCursorPrivate::KCursorPrivate()
174 hideCursorDelay = 5000;
178KCursorPrivate::~KCursorPrivate()
182void KCursorPrivate::setAutoHideCursor(
QWidget *w,
bool enable,
bool customEventFilter)
184 if (!w || !enabled) {
195 if (m_eventFilters.contains(w)) {
198 KCursorPrivateAutoHideEventFilter *
filter =
new KCursorPrivateAutoHideEventFilter(w);
199 m_eventFilters.insert(w, filter);
201 m_eventFilters.insert(viewport, filter);
204 if (!customEventFilter) {
212 KCursorPrivateAutoHideEventFilter *
filter = m_eventFilters.take(w);
213 if (filter ==
nullptr) {
218 m_eventFilters.remove(viewport);
219 disconnect(viewport, &
QObject::destroyed,
this, &KCursorPrivate::slotViewportDestroyed);
233 KCursorPrivateAutoHideEventFilter *
filter = m_eventFilters.value(o);
235 Q_ASSERT(filter !=
nullptr);
236 if (filter ==
nullptr) {
240 return filter->eventFilter(o, e);
243void KCursorPrivate::slotViewportDestroyed(
QObject *o)
245 m_eventFilters.remove(o);
248void KCursorPrivate::slotWidgetDestroyed(
QObject *o)
250 KCursorPrivateAutoHideEventFilter *
filter = m_eventFilters.take(o);
252 Q_ASSERT(filter !=
nullptr);
258#include "moc_kcursor_p.cpp"
static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter=false)
Sets auto-hiding the cursor for widget w.
static int hideCursorDelay()
static void setHideCursorDelay(int ms)
Sets the delay time in milliseconds for auto-hiding.
static void autoHideEventFilter(QObject *, QEvent *)
KCursor has to install an eventFilter over the widget you want to auto-hide.
void destroyed(QObject *obj)
void installEventFilter(QObject *filterObj)
void removeEventFilter(QObject *obj)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)