35 #include <tqscrollview.h>
37 #include "kcursor_private.h"
45 static TQCursor *hand_cursor = 0;
52 #ifndef Q_WS_WIN // this mask doesn't work too well on win32
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 Q_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 Q_CHECK_PTR(working_cursor);
139 return *working_cursor;
148 return tqarrowCursor;
154 return tqupArrowCursor;
160 return tqcrossCursor;
172 return tqibeamCursor;
178 return tqsizeVerCursor;
184 return tqsizeHorCursor;
190 return tqsizeBDiagCursor;
196 return tqsizeFDiagCursor;
202 return tqsizeAllCursor;
208 return tqblankCursor;
213 return tqwhatsThisCursor;
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, TQT_SIGNAL( timeout() ),
254 this, TQT_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() != Qt::BlankCursor )
301 w->setCursor( m_oldCursor );
306 TQWidget* KCursorPrivateAutoHideEventFilter::actualWidget()
const
308 TQWidget* w = m_widget;
311 TQScrollView * sv = tqt_dynamic_cast<TQScrollView *>( w );
318 bool KCursorPrivateAutoHideEventFilter::eventFilter( TQObject *o, TQEvent *e )
320 Q_ASSERT( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(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, TQT_SIGNAL( destroyed(TQObject*) ),
396 this, TQT_SLOT( slotWidgetDestroyed(TQObject*) ) );
401 if ( filter == NULL )
403 w->removeEventFilter( filter );
405 disconnect( w, TQT_SIGNAL( destroyed(TQObject*) ),
406 this, TQT_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"