Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QXlibCursor Class Reference

#include <qxlibcursor.h>

Inheritance diagram for QXlibCursor:
QPlatformCursor

Public Functions

void changeCursor (QCursor *cursor, QWidget *widget)
 This method is called by Qt whenever the cursor graphic should be changed. More...
 
 QXlibCursor (QXlibScreen *screen)
 

Private Functions

Cursor createCursorBitmap (QCursor *cursor)
 
Cursor createCursorShape (int cshape)
 
QXlibScreentestLiteScreen () const
 
- Private Functions inherited from QPlatformCursor
virtual void pointerEvent (const QMouseEvent &event)
 This method is called by Qt whenever a QMouseEvent is generated by the underlying pointer input. More...
 
virtual QPoint pos () const
 
 QPlatformCursor (QPlatformScreen *)
 Constructs a QPlatformCursor for the given screen. More...
 
virtual void setPos (const QPoint &pos)
 
- Private Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Properties

QMap< int, Cursor > cursorMap
 
- Properties inherited from QPlatformCursor
QPlatformScreenscreen
 
- Properties inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Additional Inherited Members

- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Private Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Private Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Private Attributes inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 51 of file qxlibcursor.h.

Constructors and Destructors

◆ QXlibCursor()

QXlibCursor::QXlibCursor ( QXlibScreen screen)

Definition at line 55 of file qxlibcursor.cpp.

56  : QPlatformCursor(screen)
57 {
58 }
QPlatformCursor(QPlatformScreen *)
Constructs a QPlatformCursor for the given screen.

Functions

◆ changeCursor()

void QXlibCursor::changeCursor ( QCursor widgetCursor,
QWidget widget 
)
virtual

This method is called by Qt whenever the cursor graphic should be changed.

Implementation of this method is mandatory for a subclass of QPlatformCursor.

widgetCursor is a pointer to the QCursor that should be displayed.

widget is a pointer to the widget currently displayed at QCursor::pos(). Note that this may be 0 if the current position is not occupied by a displayed widget.

See also
QCursor::pos()

Implements QPlatformCursor.

Definition at line 60 of file qxlibcursor.cpp.

61 {
62  QXlibWindow *w = 0;
63  if (widget) {
64  QWidget *window = widget->window();
65  w = static_cast<QXlibWindow*>(window->platformWindow());
66  } else {
67  // No X11 cursor control when there is no widget under the cursor
68  return;
69  }
70 
71  if (!w)
72  return;
73 
74  int id = cursor->handle();
75 
76  Cursor c;
77  if (!cursorMap.contains(id)) {
78  if (cursor->shape() == Qt::BitmapCursor)
79  c = createCursorBitmap(cursor);
80  else
81  c = createCursorShape(cursor->shape());
82  if (!c) {
83  return;
84  }
85  cursorMap.insert(id, c);
86  } else {
87  c = cursorMap.value(id);
88  }
89 
90  w->setCursor(c);
91 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
NSWindow * window
QMap< int, Cursor > cursorMap
Definition: qxlibcursor.h:63
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
Cursor createCursorShape(int cshape)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
Cursor createCursorBitmap(QCursor *cursor)
Definition: qxlibcursor.cpp:93
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
void setCursor(const Cursor &cursor)

◆ createCursorBitmap()

Cursor QXlibCursor::createCursorBitmap ( QCursor cursor)
private

Definition at line 93 of file qxlibcursor.cpp.

Referenced by changeCursor().

94 {
95  XColor bg, fg;
96  bg.red = 255 << 8;
97  bg.green = 255 << 8;
98  bg.blue = 255 << 8;
99  fg.red = 0;
100  fg.green = 0;
101  fg.blue = 0;
102  QPoint spot = cursor->hotSpot();
103  Window rootwin = testLiteScreen()->rootWindow();
104 
106  QImage maskImage = cursor->mask()->toImage().convertToFormat(QImage::Format_MonoLSB);
107 
108  int width = cursor->bitmap()->width();
109  int height = cursor->bitmap()->height();
110  int bytesPerLine = mapImage.bytesPerLine();
111  int destLineSize = width / 8;
112  if (width % 8)
113  destLineSize++;
114 
115  const uchar * map = mapImage.bits();
116  const uchar * mask = maskImage.bits();
117 
118  char * mapBits = new char[height * destLineSize];
119  char * maskBits = new char[height * destLineSize];
120  for (int i = 0; i < height; i++) {
121  memcpy(mapBits + (destLineSize * i),map + (bytesPerLine * i), destLineSize);
122  memcpy(maskBits + (destLineSize * i),mask + (bytesPerLine * i), destLineSize);
123  }
124 
125  Pixmap cp = XCreateBitmapFromData(testLiteScreen()->display()->nativeDisplay(), rootwin, mapBits, width, height);
126  Pixmap mp = XCreateBitmapFromData(testLiteScreen()->display()->nativeDisplay(), rootwin, maskBits, width, height);
127  Cursor c = XCreatePixmapCursor(testLiteScreen()->display()->nativeDisplay(), cp, mp, &fg, &bg, spot.x(), spot.y());
128  XFreePixmap(testLiteScreen()->display()->nativeDisplay(), cp);
129  XFreePixmap(testLiteScreen()->display()->nativeDisplay(), mp);
130  delete[] mapBits;
131  delete[] maskBits;
132 
133  return c;
134 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
unsigned char c[8]
Definition: qnumeric_p.h:62
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
Window rootWindow()
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
unsigned char uchar
Definition: qglobal.h:994
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QPoint hotSpot() const
Returns the cursor hot spot, or (0, 0) if it is one of the standard cursors.
Definition: qcursor.cpp:540
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
const QBitmap * bitmap() const
Returns the cursor bitmap, or 0 if it is one of the standard cursors.
Definition: qcursor.cpp:504
QXlibScreen * testLiteScreen() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QBitmap * mask() const
Returns the cursor bitmap mask, or 0 if it is one of the standard cursors.
Definition: qcursor.cpp:516

◆ createCursorShape()

Cursor QXlibCursor::createCursorShape ( int  cshape)
private

Definition at line 136 of file qxlibcursor.cpp.

Referenced by changeCursor().

137 {
138  Cursor cursor = 0;
139 
140  if (cshape < 0 || cshape > Qt::LastCursor)
141  return 0;
142 
143  switch (cshape) {
144  case Qt::ArrowCursor:
145  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_left_ptr);
146  break;
147  case Qt::UpArrowCursor:
148  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_center_ptr);
149  break;
150  case Qt::CrossCursor:
151  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_crosshair);
152  break;
153  case Qt::WaitCursor:
154  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_watch);
155  break;
156  case Qt::IBeamCursor:
157  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_xterm);
158  break;
159  case Qt::SizeAllCursor:
160  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_fleur);
161  break;
163  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_hand2);
164  break;
165  case Qt::SizeBDiagCursor:
166  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_top_right_corner);
167  break;
168  case Qt::SizeFDiagCursor:
169  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_bottom_right_corner);
170  break;
171  case Qt::SizeVerCursor:
172  case Qt::SplitVCursor:
173  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_sb_v_double_arrow);
174  break;
175  case Qt::SizeHorCursor:
176  case Qt::SplitHCursor:
177  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_sb_h_double_arrow);
178  break;
179  case Qt::WhatsThisCursor:
180  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_question_arrow);
181  break;
182  case Qt::ForbiddenCursor:
183  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_circle);
184  break;
185  case Qt::BusyCursor:
186  cursor = XCreateFontCursor(testLiteScreen()->display()->nativeDisplay(), XC_watch);
187  break;
188 
189  default: //default cursor for all the rest
190  break;
191  }
192  return cursor;
193 }
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
Definition: qegl_qpa.cpp:55
QXlibScreen * testLiteScreen() const

◆ testLiteScreen()

QXlibScreen * QXlibCursor::testLiteScreen ( ) const
private

Definition at line 195 of file qxlibcursor.cpp.

Referenced by createCursorBitmap(), and createCursorShape().

196 {
197  return static_cast<QXlibScreen *>(screen);
198 }
QPlatformScreen * screen

Properties

◆ cursorMap

QMap<int, Cursor> QXlibCursor::cursorMap
private

Definition at line 63 of file qxlibcursor.h.

Referenced by changeCursor().


The documentation for this class was generated from the following files: