Qt 4.8
qvnccursor.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 plugins 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 <QPainter>
43 #include <QTcpSocket>
44 #include <arpa/inet.h>
45 #include <QBitmap>
46 #include <QApplication>
47 
48 #include <QDebug>
49 
50 #include "qvnccursor.h"
51 #include "qvncserver.h"
52 #include "qvncintegration.h"
53 
55 
57  :QPlatformSoftwareCursor(scr), useVncCursor(false), server(srvr)
58 {
59 }
60 
62 {
63  QPlatformSoftwareCursor::changeCursor(widgetCursor, widget);
64  if (useVncCursor) {
66  } else {
67  setDirty();
68  }
69 }
70 
72 {
73  if (vnc) {
74  setDirty();
76  } else {
78  }
79  useVncCursor = vnc;
80 }
81 
83 {
84  if (useVncCursor)
85  return QRect();
86 
88 }
89 
91 {
92  QTcpSocket *socket = server->clientSocket();
93  if (!socket) {
94  return;
95  }
96  // FramebufferUpdate header
97  {
98  const quint16 tmp[6] = { htons(0),
99  htons(1),
100  htons(0), htons(0),
101  htons(0),
102  htons(0) };
103  socket->write((char*)tmp, sizeof(tmp));
104 
105  const quint32 encoding = htonl(-239);
106  socket->write((char*)(&encoding), sizeof(encoding));
107  }
108 }
109 
111 {
112  if (useVncCursor == false) {
114  return;
115  }
116  QImage *image = graphic->image();
117  if (image->isNull())
118  return;
119  QTcpSocket *socket = server->clientSocket();
120  if (!socket) {
121  return;
122  }
123  // FramebufferUpdate header
124  {
125  const quint16 tmp[6] = { htons(0),
126  htons(1),
127  htons(graphic->hotspot().x()), htons(graphic->hotspot().y()),
128  htons(image->width()),
129  htons(image->height()) };
130  socket->write((char*)tmp, sizeof(tmp));
131 
132  const quint32 encoding = htonl(-239);
133  socket->write((char*)(&encoding), sizeof(encoding));
134  }
135 
136  // write pixels
137  //Q_ASSERT(cursor->hasAlphaChannel());
138  const QImage img = image->convertToFormat(QImage::Format_RGB32);
139  const int n = server->clientBytesPerPixel() * img.width();
140  char *buffer = new char[n];
141  for (int i = 0; i < img.height(); ++i) {
142  server->convertPixels(buffer, (const char*)img.scanLine(i), img.width());
143  socket->write(buffer, n);
144  }
145  delete[] buffer;
146 
147  // write mask
149  Q_ASSERT(bitmap.depth() == 1);
150  Q_ASSERT(bitmap.size() == img.size());
151  const int width = (bitmap.width() + 7) / 8;
152  for (int i = 0; i < bitmap.height(); ++i)
153  socket->write((const char*)bitmap.scanLine(i), width);
154 }
155 
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void changeCursor(QCursor *widgetCursor, QWidget *widget)
This method is called by Qt whenever the cursor graphic should be changed.
Definition: qvnccursor.cpp:61
void convertPixels(char *dst, const char *src, int count) const
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void clearClientCursor()
Definition: qvnccursor.cpp:90
bool useVncCursor
Definition: qvnccursor.h:69
virtual QRect drawCursor(QPainter &painter)
Definition: fb_base.cpp:78
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QRect drawCursor(QPainter &)
Definition: qvnccursor.cpp:82
QImage image() const
Returns the cursor&#39;s image.
Definition: qscreen_qws.h:151
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QVNCScreen class implements a screen driver for VNC servers.
virtual void changeCursor(QCursor *widgetCursor, QWidget *widget)
This method is called by Qt whenever the cursor graphic should be changed.
Definition: fb_base.cpp:120
QVNCCursor(QVNCScreen *s)
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage createAlphaMask(Qt::ImageConversionFlags flags=Qt::AutoColor) const
Builds and returns a 1-bpp mask from the alpha buffer in this image.
Definition: qimage.cpp:4720
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
QImage * image()
Return the cursor graphic as a pointer to a QImage.
void setDirtyCursor()
Definition: qscreenvnc_p.h:440
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
static QAuServer & server()
Definition: qsound.cpp:79
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
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
QTcpSocket * clientSocket() const
Definition: qscreenvnc_p.h:463
QPoint hotspot()
Return the cursor&#39;s hotspot.
QVNCServer * server
Definition: qvnccursor.h:71
unsigned int quint32
Definition: qglobal.h:938
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setCursorMode(bool vnc)
Definition: qvnccursor.cpp:71
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
QPlatformCursorImage * graphic
Definition: fb_base.h:79
void sendClientCursor()
Definition: qvnccursor.cpp:110
virtual void setDirty()
Definition: fb_base.h:73
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
int clientBytesPerPixel() const
Definition: qscreenvnc_p.h:457