33 #include <tdeglobal.h>
34 #include <tdeconfig.h>
35 #include <tqscrollview.h>
37 #include "kcursor_private.h"
45 static TQCursor *hand_cursor = 0;
53 if ( config->
readEntry(
"handCursorStyle",
"Windows") ==
"Windows" )
55 static const unsigned char HAND_BITS[] = {
56 0x80, 0x01, 0x00, 0x40, 0x02, 0x00, 0x40, 0x02, 0x00, 0x40, 0x02,
57 0x00, 0x40, 0x02, 0x00, 0x40, 0x02, 0x00, 0x40, 0x1e, 0x00, 0x40,
58 0xf2, 0x00, 0x40, 0x92, 0x01, 0x70, 0x92, 0x02, 0x50, 0x92, 0x04,
59 0x48, 0x80, 0x04, 0x48, 0x00, 0x04, 0x48, 0x00, 0x04, 0x08, 0x00,
60 0x04, 0x08, 0x00, 0x04, 0x10, 0x00, 0x04, 0x10, 0x00, 0x04, 0x20,
61 0x00, 0x02, 0x40, 0x00, 0x02, 0x40, 0x00, 0x01, 0xc0, 0xff, 0x01};
62 static const unsigned char HAND_MASK_BITS[] = {
63 0x80, 0x01, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03,
64 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x1f, 0x00, 0xc0,
65 0xff, 0x00, 0xc0, 0xff, 0x01, 0xf0, 0xff, 0x03, 0xf0, 0xff, 0x07,
66 0xf8, 0xff, 0x07, 0xf8, 0xff, 0x07, 0xf8, 0xff, 0x07, 0xf8, 0xff,
67 0x07, 0xf8, 0xff, 0x07, 0xf0, 0xff, 0x07, 0xf0, 0xff, 0x07, 0xe0,
68 0xff, 0x03, 0xc0, 0xff, 0x03, 0xc0, 0xff, 0x01, 0xc0, 0xff, 0x01};
69 TQBitmap hand_bitmap(22, 22, HAND_BITS,
true);
70 TQBitmap hand_mask(22, 22, HAND_MASK_BITS,
true);
71 hand_cursor =
new TQCursor(hand_bitmap, hand_mask, 7, 0);
74 hand_cursor->handle();
78 hand_cursor =
new TQCursor(PointingHandCursor);
81 TQ_CHECK_PTR(hand_cursor);
86 static const char *
const working_cursor_xpm[]={
91 "..##############################",
92 ".a.##########.aaaa.#############",
93 ".aa.#########.aaaa.#############",
94 ".aaa.#######.aaaaaa.############",
95 ".aaaa.#####.a...a..a..##########",
96 ".aaaaa.####a....a...aa##########",
97 ".aaaaaa.###a...aa...aa##########",
98 ".aaaaaaa.##a..a.....aa##########",
99 ".aaaaaaaa.#.aa.....a..##########",
100 ".aaaaa....##.aaaaaa.############",
101 ".aa.aa.######.aaaa.#############",
102 ".a.#.aa.#####.aaaa.#############",
103 "..##.aa.########################",
104 "#####.aa.#######################",
105 "#####.aa.#######################",
106 "######..########################",
107 "################################",
108 "################################",
109 "################################",
110 "################################",
111 "################################",
112 "################################",
113 "################################",
114 "################################",
115 "################################",
116 "################################",
117 "################################",
118 "################################",
119 "################################",
120 "################################",
121 "################################",
122 "################################"};
127 static TQCursor *working_cursor = 0;
131 TQPixmap pm(
const_cast< const char**
>( working_cursor_xpm ));
132 working_cursor =
new TQCursor( pm, 1, 1 );
135 working_cursor->handle();
138 TQ_CHECK_PTR(working_cursor);
139 return *working_cursor;
148 return TQt::arrowCursor;
154 return TQt::upArrowCursor;
160 return TQt::crossCursor;
166 return TQt::waitCursor;
172 return TQt::ibeamCursor;
178 return TQt::sizeVerCursor;
184 return TQt::sizeHorCursor;
190 return TQt::sizeBDiagCursor;
196 return TQt::sizeFDiagCursor;
202 return TQt::sizeAllCursor;
208 return TQt::blankCursor;
213 return TQt::whatsThisCursor;
224 bool customEventFilter )
226 KCursorPrivate::self()->setAutoHideCursor( w, enable, customEventFilter );
231 KCursorPrivate::self()->eventFilter( o, e );
236 KCursorPrivate::self()->hideCursorDelay = ms;
241 return KCursorPrivate::self()->hideCursorDelay;
246 KCursorPrivateAutoHideEventFilter::KCursorPrivateAutoHideEventFilter( TQWidget* widget )
248 , m_wasMouseTracking( m_widget->hasMouseTracking() )
249 , m_isCursorHidden( false )
250 , m_isOwnCursor( false )
252 m_widget->setMouseTracking(
true );
253 connect( &m_autoHideTimer, TQ_SIGNAL( timeout() ),
254 this, TQ_SLOT( hideCursor() ) );
257 KCursorPrivateAutoHideEventFilter::~KCursorPrivateAutoHideEventFilter()
259 if( m_widget != NULL )
260 m_widget->setMouseTracking( m_wasMouseTracking );
263 void KCursorPrivateAutoHideEventFilter::resetWidget()
268 void KCursorPrivateAutoHideEventFilter::hideCursor()
270 m_autoHideTimer.stop();
272 if ( m_isCursorHidden )
275 m_isCursorHidden =
true;
277 TQWidget* w = actualWidget();
279 m_isOwnCursor = w->ownCursor();
281 m_oldCursor = w->cursor();
286 void KCursorPrivateAutoHideEventFilter::unhideCursor()
288 m_autoHideTimer.stop();
290 if ( !m_isCursorHidden )
293 m_isCursorHidden =
false;
295 TQWidget* w = actualWidget();
297 if ( w->cursor().shape() != TQt::BlankCursor )
301 w->setCursor( m_oldCursor );
306 TQWidget* KCursorPrivateAutoHideEventFilter::actualWidget()
const
308 TQWidget* w = m_widget;
311 TQScrollView * sv =
dynamic_cast<TQScrollView *
>( w );
318 bool KCursorPrivateAutoHideEventFilter::eventFilter( TQObject *o, TQEvent *e )
320 Q_ASSERT( o == m_widget );
324 case TQEvent::Create:
326 m_widget->setMouseTracking(
true );
329 case TQEvent::FocusOut:
330 case TQEvent::WindowDeactivate:
333 case TQEvent::KeyPress:
334 case TQEvent::AccelOverride:
338 case TQEvent::FocusIn:
339 case TQEvent::MouseButtonPress:
340 case TQEvent::MouseButtonRelease:
341 case TQEvent::MouseButtonDblClick:
342 case TQEvent::MouseMove:
347 if ( m_widget->hasFocus() )
348 m_autoHideTimer.start( KCursorPrivate::self()->hideCursorDelay,
true );
368 KCursorPrivate::KCursorPrivate()
370 hideCursorDelay = 5000;
375 TQString::fromLatin1(
"Autohiding cursor enabled"),
true );
378 KCursorPrivate::~KCursorPrivate()
382 void KCursorPrivate::setAutoHideCursor( TQWidget *w,
bool enable,
bool customEventFilter )
384 if ( !w || !enabled )
389 if ( m_eventFilters.find( w ) != NULL )
392 m_eventFilters.insert( w, filter );
393 if ( !customEventFilter )
394 w->installEventFilter( filter );
395 connect( w, TQ_SIGNAL( destroyed(TQObject*) ),
396 this, TQ_SLOT( slotWidgetDestroyed(TQObject*) ) );
401 if ( filter == NULL )
403 w->removeEventFilter( filter );
405 disconnect( w, TQ_SIGNAL( destroyed(TQObject*) ),
406 this, TQ_SLOT( slotWidgetDestroyed(TQObject*) ) );
410 bool KCursorPrivate::eventFilter( TQObject *o, TQEvent *e )
417 Q_ASSERT( filter != NULL );
418 if ( filter == NULL )
421 return filter->eventFilter( o, e );
424 void KCursorPrivate::slotWidgetDestroyed( TQObject* o )
428 Q_ASSERT( filter != NULL );
430 filter->resetWidget();
434 #include "kcursor_private.moc"
I don't want the eventFilter to be in KCursor, so we have another class for that stuff.
static void setAutoHideCursor(TQWidget *w, bool enable)
Sets auto-hiding the cursor for widget w.
static TQCursor arrowCursor()
Returns the proper arrow cursor according to the current GUI style (static function).
static TQCursor sizeHorCursor()
Returns the proper horizontal resize cursor according to the current GUI style (static function).
static TQCursor sizeAllCursor()
Returns the proper all-directions resize cursor according to the current GUI style (static function).
static TQCursor crossCursor()
Returns the proper cross-hair cursor according to the current GUI style (static function).
static TQCursor blankCursor()
Returns a blank or invisible cursor (static function).
static TQCursor sizeFDiagCursor()
Returns the proper diagonal resize () cursor according to the current GUI style (static function).
static TQCursor upArrowCursor()
Returns the proper up arrow cursor according to the current GUI style (static function).
static int hideCursorDelay()
static TQCursor waitCursor()
Returns the proper hourglass cursor according to the current GUI style (static function).
static TQCursor handCursor()
Returns the proper hand cursor according to the current GUI style (static function).
static TQCursor whatsThisCursor()
Returns a WhatsThis cursor (static function).
static TQCursor workingCursor()
Returns the proper arrow+hourglass cursor according to the current GUI style (static function).
static TQCursor ibeamCursor()
Returns the proper text cursor according to the current GUI style (static function).
static TQCursor sizeVerCursor()
Returns the proper vertical resize cursor according to the current GUI style (static function).
static void autoHideEventFilter(TQObject *, TQEvent *)
KCursor has to install an eventFilter over the widget you want to auto-hide.
static void setHideCursorDelay(int ms)
Sets the delay time in milliseconds for auto-hiding.
static TQCursor sizeBDiagCursor()
Returns the proper diagonal resize (/) cursor according to the current GUI style (static function).
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
static TDEConfig * config()