• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kcursor.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 1998 Kurt Granroth (granroth@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#ifdef KDE_USE_FINAL
20#ifdef KeyRelease
21#undef KeyRelease
22#endif
23#endif
24
25#include <kcursor.h>
26
27#include <tqbitmap.h>
28#include <tqcursor.h>
29#include <tqevent.h>
30#include <tqtimer.h>
31#include <tqwidget.h>
32
33#include <tdeglobal.h>
34#include <tdeconfig.h>
35#include <tqscrollview.h>
36
37#include "kcursor_private.h"
38
39KCursor::KCursor()
40{
41}
42
43TQCursor KCursor::handCursor()
44{
45 static TQCursor *hand_cursor = 0;
46
47 if (!hand_cursor)
48 {
49 TDEConfig *config = TDEGlobal::config();
50 TDEConfigGroupSaver saver( config, "General" );
51
52#ifndef TQ_WS_WIN // this mask doesn't work too well on win32
53 if ( config->readEntry("handCursorStyle", "Windows") == "Windows" )
54 {
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);
72 // Hack to force TQCursor to call XCreatePixmapCursor() immediately
73 // so the bitmaps don't get pushed out of the Xcursor LRU cache.
74 hand_cursor->handle();
75 }
76 else
77#endif
78 hand_cursor = new TQCursor(PointingHandCursor);
79 }
80
81 TQ_CHECK_PTR(hand_cursor);
82 return *hand_cursor;
83}
84
85/* XPM */
86static const char * const working_cursor_xpm[]={
87"32 32 3 1",
88"# c None",
89"a c #000000",
90". c #ffffff",
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"################################"};
123
124
125TQCursor KCursor::workingCursor()
126{
127 static TQCursor *working_cursor = 0;
128
129 if (!working_cursor)
130 {
131 TQPixmap pm( const_cast< const char** >( working_cursor_xpm ));
132 working_cursor = new TQCursor( pm, 1, 1 );
133 // Hack to force TQCursor to call XCreatePixmapCursor() immediately
134 // so the bitmaps don't get pushed out of the Xcursor LRU cache.
135 working_cursor->handle();
136 }
137
138 TQ_CHECK_PTR(working_cursor);
139 return *working_cursor;
140}
141
146TQCursor KCursor::arrowCursor()
147{
148 return TQt::arrowCursor;
149}
150
151
152TQCursor KCursor::upArrowCursor()
153{
154 return TQt::upArrowCursor;
155}
156
157
158TQCursor KCursor::crossCursor()
159{
160 return TQt::crossCursor;
161}
162
163
164TQCursor KCursor::waitCursor()
165{
166 return TQt::waitCursor;
167}
168
169
170TQCursor KCursor::ibeamCursor()
171{
172 return TQt::ibeamCursor;
173}
174
175
176TQCursor KCursor::sizeVerCursor()
177{
178 return TQt::sizeVerCursor;
179}
180
181
182TQCursor KCursor::sizeHorCursor()
183{
184 return TQt::sizeHorCursor;
185}
186
187
188TQCursor KCursor::sizeBDiagCursor()
189{
190 return TQt::sizeBDiagCursor;
191}
192
193
194TQCursor KCursor::sizeFDiagCursor()
195{
196 return TQt::sizeFDiagCursor;
197}
198
199
200TQCursor KCursor::sizeAllCursor()
201{
202 return TQt::sizeAllCursor;
203}
204
205
206TQCursor KCursor::blankCursor()
207{
208 return TQt::blankCursor;
209}
210
211TQCursor KCursor::whatsThisCursor()
212{
213 return TQt::whatsThisCursor;
214}
215
216// auto-hide cursor stuff
217
218void KCursor::setAutoHideCursor( TQWidget *w, bool enable )
219{
220 setAutoHideCursor( w, enable, false );
221}
222
223void KCursor::setAutoHideCursor( TQWidget *w, bool enable,
224 bool customEventFilter )
225{
226 KCursorPrivate::self()->setAutoHideCursor( w, enable, customEventFilter );
227}
228
229void KCursor::autoHideEventFilter( TQObject *o, TQEvent *e )
230{
231 KCursorPrivate::self()->eventFilter( o, e );
232}
233
234void KCursor::setHideCursorDelay( int ms )
235{
236 KCursorPrivate::self()->hideCursorDelay = ms;
237}
238
239int KCursor::hideCursorDelay()
240{
241 return KCursorPrivate::self()->hideCursorDelay;
242}
243
244// **************************************************************************
245
246KCursorPrivateAutoHideEventFilter::KCursorPrivateAutoHideEventFilter( TQWidget* widget )
247 : m_widget( widget )
248 , m_wasMouseTracking( m_widget->hasMouseTracking() )
249 , m_isCursorHidden( false )
250 , m_isOwnCursor( false )
251{
252 m_widget->setMouseTracking( true );
253 connect( &m_autoHideTimer, TQ_SIGNAL( timeout() ),
254 this, TQ_SLOT( hideCursor() ) );
255}
256
257KCursorPrivateAutoHideEventFilter::~KCursorPrivateAutoHideEventFilter()
258{
259 if( m_widget != NULL )
260 m_widget->setMouseTracking( m_wasMouseTracking );
261}
262
263void KCursorPrivateAutoHideEventFilter::resetWidget()
264{
265 m_widget = NULL;
266}
267
268void KCursorPrivateAutoHideEventFilter::hideCursor()
269{
270 m_autoHideTimer.stop();
271
272 if ( m_isCursorHidden )
273 return;
274
275 m_isCursorHidden = true;
276
277 TQWidget* w = actualWidget();
278
279 m_isOwnCursor = w->ownCursor();
280 if ( m_isOwnCursor )
281 m_oldCursor = w->cursor();
282
283 w->setCursor( KCursor::blankCursor() );
284}
285
286void KCursorPrivateAutoHideEventFilter::unhideCursor()
287{
288 m_autoHideTimer.stop();
289
290 if ( !m_isCursorHidden )
291 return;
292
293 m_isCursorHidden = false;
294
295 TQWidget* w = actualWidget();
296
297 if ( w->cursor().shape() != TQt::BlankCursor ) // someone messed with the cursor already
298 return;
299
300 if ( m_isOwnCursor )
301 w->setCursor( m_oldCursor );
302 else
303 w->unsetCursor();
304}
305
306TQWidget* KCursorPrivateAutoHideEventFilter::actualWidget() const
307{
308 TQWidget* w = m_widget;
309
310 // Is w a scrollview ? Call setCursor on the viewport in that case.
311 TQScrollView * sv = dynamic_cast<TQScrollView *>( w );
312 if ( sv )
313 w = sv->viewport();
314
315 return w;
316}
317
318bool KCursorPrivateAutoHideEventFilter::eventFilter( TQObject *o, TQEvent *e )
319{
320 Q_ASSERT( o == m_widget );
321
322 switch ( e->type() )
323 {
324 case TQEvent::Create:
325 // Qt steals mouseTracking on create()
326 m_widget->setMouseTracking( true );
327 break;
328 case TQEvent::Leave:
329 case TQEvent::FocusOut:
330 case TQEvent::WindowDeactivate:
331 unhideCursor();
332 break;
333 case TQEvent::KeyPress:
334 case TQEvent::AccelOverride:
335 hideCursor();
336 break;
337 case TQEvent::Enter:
338 case TQEvent::FocusIn:
339 case TQEvent::MouseButtonPress:
340 case TQEvent::MouseButtonRelease:
341 case TQEvent::MouseButtonDblClick:
342 case TQEvent::MouseMove:
343 case TQEvent::Show:
344 case TQEvent::Hide:
345 case TQEvent::Wheel:
346 unhideCursor();
347 if ( m_widget->hasFocus() )
348 m_autoHideTimer.start( KCursorPrivate::self()->hideCursorDelay, true );
349 break;
350 default:
351 break;
352 }
353
354 return false;
355}
356
357KCursorPrivate * KCursorPrivate::s_self = 0L;
358
359KCursorPrivate * KCursorPrivate::self()
360{
361 if ( !s_self )
362 s_self = new KCursorPrivate;
363 // WABA: We never delete KCursorPrivate. Don't change.
364
365 return s_self;
366}
367
368KCursorPrivate::KCursorPrivate()
369{
370 hideCursorDelay = 5000; // 5s default value
371
372 TDEConfig *kc = TDEGlobal::config();
373 TDEConfigGroupSaver ks( kc, TQString::fromLatin1("KDE") );
374 enabled = kc->readBoolEntry(
375 TQString::fromLatin1("Autohiding cursor enabled"), true );
376}
377
378KCursorPrivate::~KCursorPrivate()
379{
380}
381
382void KCursorPrivate::setAutoHideCursor( TQWidget *w, bool enable, bool customEventFilter )
383{
384 if ( !w || !enabled )
385 return;
386
387 if ( enable )
388 {
389 if ( m_eventFilters.find( w ) != NULL )
390 return;
391 KCursorPrivateAutoHideEventFilter* filter = new KCursorPrivateAutoHideEventFilter( w );
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*) ) );
397 }
398 else
399 {
400 KCursorPrivateAutoHideEventFilter* filter = m_eventFilters.take( w );
401 if ( filter == NULL )
402 return;
403 w->removeEventFilter( filter );
404 delete filter;
405 disconnect( w, TQ_SIGNAL( destroyed(TQObject*) ),
406 this, TQ_SLOT( slotWidgetDestroyed(TQObject*) ) );
407 }
408}
409
410bool KCursorPrivate::eventFilter( TQObject *o, TQEvent *e )
411{
412 if ( !enabled )
413 return false;
414
415 KCursorPrivateAutoHideEventFilter* filter = m_eventFilters.find( o );
416
417 Q_ASSERT( filter != NULL );
418 if ( filter == NULL )
419 return false;
420
421 return filter->eventFilter( o, e );
422}
423
424void KCursorPrivate::slotWidgetDestroyed( TQObject* o )
425{
426 KCursorPrivateAutoHideEventFilter* filter = m_eventFilters.take( o );
427
428 Q_ASSERT( filter != NULL );
429
430 filter->resetWidget(); // so that dtor doesn't access it
431 delete filter;
432}
433
434#include "kcursor_private.moc"
KCursorPrivateAutoHideEventFilter
I don't want the eventFilter to be in KCursor, so we have another class for that stuff.
Definition: kcursor_private.h:40
KCursorPrivate
Definition: kcursor_private.h:72
KCursor::setAutoHideCursor
static void setAutoHideCursor(TQWidget *w, bool enable)
Sets auto-hiding the cursor for widget w.
Definition: kcursor.cpp:218
KCursor::arrowCursor
static TQCursor arrowCursor()
Returns the proper arrow cursor according to the current GUI style (static function).
Definition: kcursor.cpp:146
KCursor::sizeHorCursor
static TQCursor sizeHorCursor()
Returns the proper horizontal resize cursor according to the current GUI style (static function).
Definition: kcursor.cpp:182
KCursor::KCursor
KCursor()
Constructor.
Definition: kcursor.cpp:39
KCursor::sizeAllCursor
static TQCursor sizeAllCursor()
Returns the proper all-directions resize cursor according to the current GUI style (static function).
Definition: kcursor.cpp:200
KCursor::crossCursor
static TQCursor crossCursor()
Returns the proper cross-hair cursor according to the current GUI style (static function).
Definition: kcursor.cpp:158
KCursor::blankCursor
static TQCursor blankCursor()
Returns a blank or invisible cursor (static function).
Definition: kcursor.cpp:206
KCursor::sizeFDiagCursor
static TQCursor sizeFDiagCursor()
Returns the proper diagonal resize () cursor according to the current GUI style (static function).
Definition: kcursor.cpp:194
KCursor::upArrowCursor
static TQCursor upArrowCursor()
Returns the proper up arrow cursor according to the current GUI style (static function).
Definition: kcursor.cpp:152
KCursor::hideCursorDelay
static int hideCursorDelay()
Definition: kcursor.cpp:239
KCursor::waitCursor
static TQCursor waitCursor()
Returns the proper hourglass cursor according to the current GUI style (static function).
Definition: kcursor.cpp:164
KCursor::handCursor
static TQCursor handCursor()
Returns the proper hand cursor according to the current GUI style (static function).
Definition: kcursor.cpp:43
KCursor::whatsThisCursor
static TQCursor whatsThisCursor()
Returns a WhatsThis cursor (static function).
Definition: kcursor.cpp:211
KCursor::workingCursor
static TQCursor workingCursor()
Returns the proper arrow+hourglass cursor according to the current GUI style (static function).
Definition: kcursor.cpp:125
KCursor::ibeamCursor
static TQCursor ibeamCursor()
Returns the proper text cursor according to the current GUI style (static function).
Definition: kcursor.cpp:170
KCursor::sizeVerCursor
static TQCursor sizeVerCursor()
Returns the proper vertical resize cursor according to the current GUI style (static function).
Definition: kcursor.cpp:176
KCursor::autoHideEventFilter
static void autoHideEventFilter(TQObject *, TQEvent *)
KCursor has to install an eventFilter over the widget you want to auto-hide.
Definition: kcursor.cpp:229
KCursor::setHideCursorDelay
static void setHideCursorDelay(int ms)
Sets the delay time in milliseconds for auto-hiding.
Definition: kcursor.cpp:234
KCursor::sizeBDiagCursor
static TQCursor sizeBDiagCursor()
Returns the proper diagonal resize (/) cursor according to the current GUI style (static function).
Definition: kcursor.cpp:188
TDEConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
TDEConfigGroupSaver
TDEConfig
TDEGlobal::config
static TDEConfig * config()

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.