File indexing completed on 2025-02-16 13:11:39
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1998 Kurt Granroth <granroth@kde.org> 0004 SPDX-FileCopyrightText: 2000 Carsten Pfeiffer <pfeiffer@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-only 0007 */ 0008 0009 #ifndef KCURSOR_H 0010 #define KCURSOR_H 0011 0012 #include <kwidgetsaddons_export.h> 0013 0014 class QEvent; 0015 class QObject; 0016 class QWidget; 0017 0018 /** 0019 * @class KCursor kcursor.h KCursor 0020 * 0021 * The KCursor class provides a set of static 0022 * convenience methods for auto-hiding cursors on widgets. 0023 */ 0024 class KWIDGETSADDONS_EXPORT KCursor 0025 { 0026 public: 0027 /** 0028 * Sets auto-hiding the cursor for widget @p w. Enabling it will result in 0029 * the cursor being hidden when 0030 * @li a key-event happens 0031 * @li there are no key-events for a configured time-frame (see 0032 * setHideCursorDelay()) 0033 * 0034 * The cursor will be shown again when the focus is lost or a mouse-event 0035 * happens. 0036 * 0037 * Side effect: when enabling auto-hide, mouseTracking is enabled for the 0038 * specified widget, because it's needed to get mouse-move-events. So 0039 * don't disable mouseTracking for a widget while using auto-hide for it. 0040 * 0041 * When disabling auto-hide, mouseTracking will be disabled, so if you need 0042 * mouseTracking after disabling auto-hide, you have to re-enable 0043 * mouseTracking. 0044 * 0045 * If you want to use auto-hiding for widgets that don't take focus, e.g. 0046 * a QCanvasView, then you have to pass all key-events that should trigger 0047 * auto-hiding to autoHideEventFilter(). 0048 */ 0049 static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter = false); 0050 0051 /** 0052 * Sets the delay time in milliseconds for auto-hiding. When no keyboard 0053 * events arrive for that time-frame, the cursor will be hidden. 0054 * 0055 * Default is 5000, i.e. 5 seconds. 0056 */ 0057 static void setHideCursorDelay(int ms); 0058 0059 /** 0060 * @returns the current auto-hide delay time. 0061 * 0062 * Default is 5000, i.e. 5 seconds. 0063 */ 0064 static int hideCursorDelay(); 0065 0066 /** 0067 * KCursor has to install an eventFilter over the widget you want to 0068 * auto-hide. If you have an own eventFilter() on that widget and stop 0069 * some events by returning true, you might break auto-hiding, because 0070 * KCursor doesn't get those events. 0071 * 0072 * In this case, you need to call setAutoHideCursor( widget, true, true ); 0073 * to tell KCursor not to install an eventFilter. Then you call this method 0074 * from the beginning of your eventFilter, for example: 0075 * \code 0076 * edit = new KEdit( this, "some edit widget" ); 0077 * edit->installEventFilter( this ); 0078 * KCursor::setAutoHideCursor( edit, true, true ); 0079 * 0080 * [...] 0081 * 0082 * bool YourClass::eventFilter( QObject *o, QEvent *e ) 0083 * { 0084 * if ( o == edit ) // only that widget where you enabled auto-hide! 0085 * KCursor::autoHideEventFilter( o, e ); 0086 * 0087 * // now you can do your own event-processing 0088 * [...] 0089 * } 0090 * \endcode 0091 * 0092 * Note that you must not call KCursor::autoHideEventFilter() when you 0093 * didn't enable or after disabling auto-hiding. 0094 */ 0095 static void autoHideEventFilter(QObject *, QEvent *); 0096 0097 private: 0098 KCursor() = delete; 0099 }; 0100 0101 #endif // _KCURSOR_H