1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qcursor.h"
|
---|
43 |
|
---|
44 | #ifndef QT_NO_CURSOR
|
---|
45 |
|
---|
46 | #include <qapplication.h>
|
---|
47 | #include <qbitmap.h>
|
---|
48 | #include <qimage.h>
|
---|
49 | #include <qdatastream.h>
|
---|
50 | #include <qvariant.h>
|
---|
51 | #include <private/qcursor_p.h>
|
---|
52 |
|
---|
53 | QT_BEGIN_NAMESPACE
|
---|
54 |
|
---|
55 | /*!
|
---|
56 | \class QCursor
|
---|
57 |
|
---|
58 | \brief The QCursor class provides a mouse cursor with an arbitrary
|
---|
59 | shape.
|
---|
60 |
|
---|
61 | \ingroup appearance
|
---|
62 | \ingroup shared
|
---|
63 | \mainclass
|
---|
64 |
|
---|
65 | This class is mainly used to create mouse cursors that are
|
---|
66 | associated with particular widgets and to get and set the position
|
---|
67 | of the mouse cursor.
|
---|
68 |
|
---|
69 | Qt has a number of standard cursor shapes, but you can also make
|
---|
70 | custom cursor shapes based on a QBitmap, a mask and a hotspot.
|
---|
71 |
|
---|
72 | To associate a cursor with a widget, use QWidget::setCursor(). To
|
---|
73 | associate a cursor with all widgets (normally for a short period
|
---|
74 | of time), use QApplication::setOverrideCursor().
|
---|
75 |
|
---|
76 | To set a cursor shape use QCursor::setShape() or use the QCursor
|
---|
77 | constructor which takes the shape as argument, or you can use one
|
---|
78 | of the predefined cursors defined in the \l Qt::CursorShape enum.
|
---|
79 |
|
---|
80 | If you want to create a cursor with your own bitmap, either use
|
---|
81 | the QCursor constructor which takes a bitmap and a mask or the
|
---|
82 | constructor which takes a pixmap as arguments.
|
---|
83 |
|
---|
84 | To set or get the position of the mouse cursor use the static
|
---|
85 | methods QCursor::pos() and QCursor::setPos().
|
---|
86 |
|
---|
87 | \bold{Note:} It is possible to create a QCursor before
|
---|
88 | QApplication, but it is not useful except as a place-holder for a
|
---|
89 | real QCursor created after QApplication. Attempting to use a
|
---|
90 | QCursor that was created before QApplication will result in a
|
---|
91 | crash.
|
---|
92 |
|
---|
93 | \section1 A Note for X11 Users
|
---|
94 |
|
---|
95 | On X11, Qt supports the \link
|
---|
96 | http://www.xfree86.org/4.3.0/Xcursor.3.html Xcursor\endlink
|
---|
97 | library, which allows for full color icon themes. The table below
|
---|
98 | shows the cursor name used for each Qt::CursorShape value. If a
|
---|
99 | cursor cannot be found using the name shown below, a standard X11
|
---|
100 | cursor will be used instead. Note: X11 does not provide
|
---|
101 | appropriate cursors for all possible Qt::CursorShape values. It
|
---|
102 | is possible that some cursors will be taken from the Xcursor
|
---|
103 | theme, while others will use an internal bitmap cursor.
|
---|
104 |
|
---|
105 | \table
|
---|
106 | \header \o Shape \o Qt::CursorShape Value \o Cursor Name
|
---|
107 | \o Shape \o Qt::CursorShape Value \o Cursor Name
|
---|
108 | \row \o \inlineimage cursor-arrow.png
|
---|
109 | \o Qt::ArrowCursor \o \c left_ptr
|
---|
110 | \o \inlineimage cursor-sizev.png
|
---|
111 | \o Qt::SizeVerCursor \o \c size_ver
|
---|
112 | \row \o \inlineimage cursor-uparrow.png
|
---|
113 | \o Qt::UpArrowCursor \o \c up_arrow
|
---|
114 | \o \inlineimage cursor-sizeh.png
|
---|
115 | \o Qt::SizeHorCursor \o \c size_hor
|
---|
116 | \row \o \inlineimage cursor-cross.png
|
---|
117 | \o Qt::CrossCursor \o \c cross
|
---|
118 | \o \inlineimage cursor-sizeb.png
|
---|
119 | \o Qt::SizeBDiagCursor \o \c size_bdiag
|
---|
120 | \row \o \inlineimage cursor-ibeam.png
|
---|
121 | \o Qt::IBeamCursor \o \c ibeam
|
---|
122 | \o \inlineimage cursor-sizef.png
|
---|
123 | \o Qt::SizeFDiagCursor \o \c size_fdiag
|
---|
124 | \row \o \inlineimage cursor-wait.png
|
---|
125 | \o Qt::WaitCursor \o \c wait
|
---|
126 | \o \inlineimage cursor-sizeall.png
|
---|
127 | \o Qt::SizeAllCursor \o \c size_all
|
---|
128 | \row \o \inlineimage cursor-busy.png
|
---|
129 | \o Qt::BusyCursor \o \c left_ptr_watch
|
---|
130 | \o \inlineimage cursor-hsplit.png
|
---|
131 | \o Qt::SplitVCursor \o \c split_v
|
---|
132 | \row \o \inlineimage cursor-forbidden.png
|
---|
133 | \o Qt::ForbiddenCursor \o \c forbidden
|
---|
134 | \o \inlineimage cursor-vsplit.png
|
---|
135 | \o Qt::SplitHCursor \o \c split_h
|
---|
136 | \row \o \inlineimage cursor-hand.png
|
---|
137 | \o Qt::PointingHandCursor \o \c pointing_hand
|
---|
138 | \o \inlineimage cursor-openhand.png
|
---|
139 | \o Qt::OpenHandCursor \o \c openhand
|
---|
140 | \row \o \inlineimage cursor-whatsthis.png
|
---|
141 | \o Qt::WhatsThisCursor \o \c whats_this
|
---|
142 | \o \inlineimage cursor-closedhand.png
|
---|
143 | \o Qt::ClosedHandCursor \o \c closedhand
|
---|
144 | \endtable
|
---|
145 |
|
---|
146 | \sa QWidget, {fowler}{GUI Design Handbook: Cursors}
|
---|
147 | */
|
---|
148 |
|
---|
149 | /*!
|
---|
150 | \fn HCURSOR_or_HANDLE QCursor::handle() const
|
---|
151 |
|
---|
152 | Returns a platform-specific cursor handle. The \c
|
---|
153 | HCURSOR_or_HANDLE type is \c HCURSOR on Windows and Qt::HANDLE on X11
|
---|
154 | and Mac OS X. On \l{Qt for Embedded Linux} it is an integer.
|
---|
155 |
|
---|
156 | \warning Using the value returned by this function is not
|
---|
157 | portable.
|
---|
158 | */
|
---|
159 |
|
---|
160 | /*!
|
---|
161 | \fn QCursor::QCursor(HCURSOR cursor)
|
---|
162 |
|
---|
163 | Constructs a Qt cursor from the given Windows \a cursor.
|
---|
164 |
|
---|
165 | \warning This function is only available on Windows.
|
---|
166 |
|
---|
167 | \sa handle()
|
---|
168 | */
|
---|
169 |
|
---|
170 | /*!
|
---|
171 | \fn QCursor::QCursor(Qt::HANDLE handle)
|
---|
172 |
|
---|
173 | Constructs a Qt cursor from the given \a handle.
|
---|
174 |
|
---|
175 | \warning This function is only available on X11.
|
---|
176 |
|
---|
177 | \sa handle()
|
---|
178 | */
|
---|
179 |
|
---|
180 | /*!
|
---|
181 | \fn QPoint QCursor::pos()
|
---|
182 |
|
---|
183 | Returns the position of the cursor (hot spot) in global screen
|
---|
184 | coordinates.
|
---|
185 |
|
---|
186 | You can call QWidget::mapFromGlobal() to translate it to widget
|
---|
187 | coordinates.
|
---|
188 |
|
---|
189 | \sa setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()
|
---|
190 | */
|
---|
191 |
|
---|
192 | /*!
|
---|
193 | \fn void QCursor::setPos(int x, int y)
|
---|
194 |
|
---|
195 | Moves the cursor (hot spot) to the global screen position (\a x,
|
---|
196 | \a y).
|
---|
197 |
|
---|
198 | You can call QWidget::mapToGlobal() to translate widget
|
---|
199 | coordinates to global screen coordinates.
|
---|
200 |
|
---|
201 | \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()
|
---|
202 | */
|
---|
203 |
|
---|
204 | /*!
|
---|
205 | \fn void QCursor::setPos (const QPoint &p)
|
---|
206 |
|
---|
207 | \overload
|
---|
208 |
|
---|
209 | Moves the cursor (hot spot) to the global screen position at point
|
---|
210 | \a p.
|
---|
211 | */
|
---|
212 |
|
---|
213 | /*****************************************************************************
|
---|
214 | QCursor stream functions
|
---|
215 | *****************************************************************************/
|
---|
216 |
|
---|
217 | #ifndef QT_NO_DATASTREAM
|
---|
218 |
|
---|
219 |
|
---|
220 | /*!
|
---|
221 | \fn QDataStream &operator<<(QDataStream &stream, const QCursor &cursor)
|
---|
222 | \relates QCursor
|
---|
223 |
|
---|
224 | Writes the \a cursor to the \a stream.
|
---|
225 |
|
---|
226 | \sa {Format of the QDataStream operators}
|
---|
227 | */
|
---|
228 |
|
---|
229 | QDataStream &operator<<(QDataStream &s, const QCursor &c)
|
---|
230 | {
|
---|
231 | s << (qint16)c.shape(); // write shape id to stream
|
---|
232 | if (c.shape() == Qt::BitmapCursor) { // bitmap cursor
|
---|
233 | bool isPixmap = false;
|
---|
234 | if (s.version() >= 7) {
|
---|
235 | isPixmap = !c.pixmap().isNull();
|
---|
236 | s << isPixmap;
|
---|
237 | }
|
---|
238 | if (isPixmap)
|
---|
239 | s << c.pixmap();
|
---|
240 | else
|
---|
241 | s << *c.bitmap() << *c.mask();
|
---|
242 | s << c.hotSpot();
|
---|
243 | }
|
---|
244 | return s;
|
---|
245 | }
|
---|
246 |
|
---|
247 | /*!
|
---|
248 | \fn QDataStream &operator>>(QDataStream &stream, QCursor &cursor)
|
---|
|
---|