Qt 4.8
qcursor_qpa.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qcursor.h>
43 #include <private/qcursor_p.h>
44 #include <qplatformcursor_qpa.h>
45 #include <qbitmap.h>
46 
48 
50 
51 #ifndef QT_NO_CURSOR
52 
54 
55 /*****************************************************************************
56  Internal QCursorData class
57  *****************************************************************************/
58 
60  : cshape(s), bm(0), bmm(0), hx(0), hy(0), id(s)
61 {
62  ref = 1;
63 }
64 
66 {
67  delete bm;
68  delete bmm;
69 }
70 
71 
72 /*****************************************************************************
73  Global cursors
74  *****************************************************************************/
75 
76 extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
77 
78 int QCursor::handle() const
79 {
80  return d->id;
81 }
82 
83 
84 QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
85 {
88  if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
89  qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
90  QCursorData *c = qt_cursorTable[0];
91  c->ref.ref();
92  return c;
93  }
94  QCursorData *d = new QCursorData;
95  d->bm = new QBitmap(bitmap);
96  d->bmm = new QBitmap(mask);
98  d->id = ++nextCursorId;
99  d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
100  d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
101 
102  return d;
103 }
104 
105 void QCursorData::update()
106 {
107 }
108 
109 #endif //QT_NO_CURSOR
110 
111 extern int qt_last_x,qt_last_y;
112 
114 {
116  int cursorCount = cursors.count();
117  for (int i = 0; i < cursorCount; ++i) {
118  const QWeakPointer<QPlatformCursor> &cursor(cursors.at(i));
119  if (cursor)
120  return cursor.data()->pos();
121  }
122  return QPoint(qt_last_x, qt_last_y);
123 }
124 
125 void QCursor::setPos(int x, int y)
126 {
127  QPoint target(x, y);
128 
129  // Need to check, since some X servers generate null mouse move
130  // events, causing looping in applications which call setPos() on
131  // every mouse move event.
132  //
133  if (pos() == target)
134  return;
135 
137  int cursorCount = cursors.count();
138  for (int i = 0; i < cursorCount; ++i) {
139  const QWeakPointer<QPlatformCursor> &cursor(cursors.at(i));
140  if (cursor)
141  cursor.data()->setPos(target);
142  }
143 }
144 
HCURSOR_or_HANDLE handle() const
Returns a platform-specific cursor handle.
Definition: qcursor_mac.mm:301
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
int qt_last_x
short hy
Definition: qcursor_p.h:91
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool ref()
Atomically increments the value of this QAtomicInt.
static bool initialized
Definition: qcursor_p.h:125
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
T * data() const
int qt_last_y
static QCursorData * setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
Definition: qcursor_mac.mm:278
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
static int nextCursorId
Definition: qcursor_qpa.cpp:53
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QCursorData(Qt::CursorShape s=Qt::ArrowCursor)
Definition: qcursor_mac.mm:253
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
void update()
Creates the cursor.
Definition: qcursor_mac.mm:387
Qt::CursorShape cshape
Definition: qcursor_p.h:88
CursorShape
Definition: qnamespace.h:1262
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
short hx
Definition: qcursor_p.h:91
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
QBitmap * bmm
Definition: qcursor_p.h:89
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
QCursorData * qt_cursorTable[Qt::LastCursor+1]
Definition: qcursor.cpp:398
static void initialize()
Definition: qcursor.cpp:417
QAtomicInt ref
Definition: qcursor_p.h:87
QBitmap * bm
Definition: qcursor_p.h:89
static QList< QWeakPointer< QPlatformCursor > > getInstances()
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
The QWeakPointer class holds a weak reference to a shared pointer.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62