1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qscreenproxy_qws.h>
43
44 #ifndef QT_NO_QWS_PROXYSCREEN
45
46 #include <qregexp.h>
47
48 QT_BEGIN_NAMESPACE
49 #ifndef QT_NO_QWS_CURSOR
50
51 /*!
52 \class QProxyScreenCursor
53 \since 4.5
54 \ingroup qws
55 \brief The QProxyScreenCursor class provides a generic interface to
56 QScreenCursor implementations.
57 */
58
59 /*!
60 Constructs a proxy screen cursor.
61 */
QProxyScreenCursor()62 QProxyScreenCursor::QProxyScreenCursor()
63 : QScreenCursor(), realCursor(0), d_ptr(0)
64 {
65 }
66
67 /*!
68 Destroys the proxy screen cursor.
69 */
~QProxyScreenCursor()70 QProxyScreenCursor::~QProxyScreenCursor()
71 {
72 }
73
74 /*!
75 Sets the real screen cursor to be used for the proxy screen cursor to
76 the \a cursor specified.
77
78 \sa screenCursor()
79 */
setScreenCursor(QScreenCursor * cursor)80 void QProxyScreenCursor::setScreenCursor(QScreenCursor *cursor)
81 {
82 realCursor = cursor;
83 configure();
84 }
85
86 /*!
87 Returns the real screen cursor used by the proxy screen cursor.
88
89 \sa setScreenCursor()
90 */
screenCursor() const91 QScreenCursor* QProxyScreenCursor::screenCursor() const
92 {
93 return realCursor;
94 }
95
96 /*!
97 \reimp
98 */
set(const QImage & image,int hotx,int hoty)99 void QProxyScreenCursor::set(const QImage &image, int hotx, int hoty)
100 {
101 if (realCursor) {
102 hotspot = QPoint(hotx, hoty);
103 cursor = image;
104 size = image.size();
105 realCursor->set(image, hotx, hoty);
106 } else {
107 QScreenCursor::set(image, hotx, hoty);
108 }
109 }
110
111 /*!
112 \reimp
113 */
move(int x,int y)114 void QProxyScreenCursor::move(int x, int y)
115 {
116 if (realCursor) {
117 pos = QPoint(x, y);
118 realCursor->move(x, y);
119 } else {
120 QScreenCursor::move(x, y);
121 }
122 }
123
124 /*!
125 \reimp
126 */
show()127 void QProxyScreenCursor::show()
128 {
129 if (realCursor) {
130 realCursor->show();
131 enable = true;
132 } else {
133 QScreenCursor::show();
134 }
135 }
136
137 /*!
138 \reimp
139 */
hide()140 void QProxyScreenCursor::hide()
141 {
142 if (realCursor) {
143 realCursor->hide();
144 enable = false;
145 } else {
146 QScreenCursor::hide();
147 }
148 }
149
150 /*!
151 \internal
152 */
configure()153 void QProxyScreenCursor::configure()
154 {
155 if (!realCursor)
156 return;
157
158 cursor = realCursor->cursor;
159 size = realCursor->size;
160 pos = realCursor->pos;
161 hotspot = realCursor->hotspot;
162 enable = realCursor->enable;
163 hwaccel = realCursor->hwaccel;
164 supportsAlpha = realCursor->supportsAlpha;
165 }
166
167 #endif // QT_NO_QWS_CURSOR
168
169 /*!
170 \class QProxyScreen
171 \ingroup qws
172 \brief The QProxyScreen class provides a generic interface to QScreen implementations.
173 */
174
175 /*!
176 \fn QProxyScreen::QProxyScreen(int displayId, ClassId classId)
177
178 Constructs a proxy screen with the given \a displayId and \a classId.
179 */
QProxyScreen(int displayId,QScreen::ClassId classId)180 QProxyScreen::QProxyScreen(int displayId, QScreen::ClassId classId)
181 : QScreen(displayId, classId), realScreen(0), d_ptr(0)
182 {
183 }
184
185 /*!
186 Destroys the proxy screen.
187 */
~QProxyScreen()188 QProxyScreen::~QProxyScreen()
189 {
190 }
191
192 /*!
193 Sets the real \a screen to be used by the proxy screen.
194
195 \sa screen()
196 */
setScreen(QScreen * screen)197 void QProxyScreen::setScreen(QScreen *screen)
198 {
199 realScreen = screen;
200 configure();
201 }
202
203 /*!
204 Returns the real screen used by the proxy screen.
205
206 \sa setScreen()
207 */
screen() const208 QScreen* QProxyScreen::screen() const
209 {
210 return realScreen;
211 }
212
213
214 /*!
215 \internal
216 */
configure()217 void QProxyScreen::configure()
218 {
219 if (!realScreen)
220 return;
221
222 d = realScreen->depth();
223 w = realScreen->width();
224 h = realScreen->height();
225 dw = realScreen->deviceWidth();
226 dh = realScreen->deviceHeight();
227 lstep = realScreen->linestep();
228 data = realScreen->base();
229 lstep = realScreen->linestep();
230 size = realScreen->screenSize();
231 physWidth = realScreen->physicalWidth();
232 physHeight = realScreen->physicalHeight();
233 pixeltype = realScreen->pixelType();
234 #if Q_BYTE_ORDER == Q_BIG_ENDIAN
235 setFrameBufferLittleEndian(realScreen->frameBufferLittleEndian());
236 #endif
237
238 setOffset(realScreen->offset());
239 setPixelFormat(realScreen->pixelFormat());
240
241 #ifdef QT_QWS_CLIENTBLIT
242 setSupportsBlitInClients(realScreen->supportsBlitInClients());
243 #endif
244 }
245
246 /*!
247 \internal
248 Returns the display ID that corresponds to the given \a spec.
249 */
getDisplayId(const QString & spec)250 static int getDisplayId(const QString &spec)
251 {
252 QRegExp regexp(QLatin1String(":(\\d+)\\b"));
253 if (regexp.lastIndexIn(spec) != -1) {
254 const QString capture = regexp.cap(1);
255 return capture.toInt();
256 }
257 return 0;
258 }
259
260 /*!
261 \reimp
262 */
connect(const QString & displaySpec)263 bool QProxyScreen::connect(const QString &displaySpec)
264 {
265 const int id = getDisplayId(displaySpec);
266 realScreen = qt_get_screen(id, displaySpec.toLatin1().constData());
267 configure();
268
269 return true;
270 }
271
272 /*!
273 \reimp
274 */
exposeRegion(QRegion r,int changing)275 void QProxyScreen::exposeRegion(QRegion r, int changing)
276 {
277 if (!realScreen) {
278 QScreen::exposeRegion(r, changing);
279 return;
280 }
281
282 realScreen->exposeRegion(r, changing);
283 r &= realScreen->region();
284
285 const QVector<QRect> rects = r.rects();
286 for (int i = 0; i < rects.size(); ++i)
287 setDirty(rects.at(i));
288 }
289
290 /*!
291 \reimp
292 */
blit(const QImage & image,const QPoint & topLeft,const QRegion & region)293 void QProxyScreen::blit(const QImage &image, const QPoint &topLeft,
294 const QRegion ®ion)
295 {
296 if (!realScreen) {
297 QScreen::blit(image, topLeft, region);
298 return;
299 }
300
301 realScreen->blit(image, topLeft, region);
302 }
303
304 /*!
305 \reimp
306 */
solidFill(const QColor & color,const QRegion & region)307 void QProxyScreen::solidFill(const QColor &color, const QRegion ®ion)
308 {
309 if (!realScreen) {
310 QScreen::solidFill(color, region);
311 return;
312 }
313 realScreen->solidFill(color, region);
314 }
315
316 /*!
317 \reimp
318 */
mapToDevice(const QSize & s) const319 QSize QProxyScreen::mapToDevice(const QSize &s) const
320 {
321 if (!realScreen)
322 return QScreen::mapToDevice(s);
323
324 return realScreen->mapToDevice(s);
325 }
326
327 /*!
328 \reimp
329 */
mapFromDevice(const QSize & s) const330 QSize QProxyScreen::mapFromDevice(const QSize &s) const
331 {
332 if (!realScreen)
333 return QScreen::mapFromDevice(s);
334
335 return realScreen->mapFromDevice(s);
336 }
337
338 /*!
339 \reimp
340 */
mapToDevice(const QPoint & p,const QSize & s) const341 QPoint QProxyScreen::mapToDevice(const QPoint &p, const QSize &s) const
342 {
343 if (!realScreen)
344 return QScreen::mapToDevice(p, s);
345
346 return realScreen->mapToDevice(p, s);
347 }
348
349 /*!
350 \reimp
351 */
mapFromDevice(const QPoint & p,const QSize & s) const352 QPoint QProxyScreen::mapFromDevice(const QPoint &p, const QSize &s) const
353 {
354 if (!realScreen)
355 return QScreen::mapFromDevice(p, s);
356
357 return realScreen->mapFromDevice(p, s);
358 }
359
360 /*!
361 \reimp
362 */
mapToDevice(const QRect & r,const QSize & s) const363 QRect QProxyScreen::mapToDevice(const QRect &r, const QSize &s) const
364 {
365 if (!realScreen)
366 return QScreen::mapToDevice(r, s);
367
368 return realScreen->mapToDevice(r, s);
369 }
370
371 /*!
372 \reimp
373 */
mapFromDevice(const QRect & r,const QSize & s) const374 QRect QProxyScreen::mapFromDevice(const QRect &r, const QSize &s) const
375 {
376 if (!realScreen)
377 return QScreen::mapFromDevice(r, s);
378
379 return realScreen->mapFromDevice(r, s);
380 }
381
382 /*!
383 \reimp
384 */
mapToDevice(const QRegion & r,const QSize & s) const385 QRegion QProxyScreen::mapToDevice(const QRegion &r, const QSize &s) const
386 {
387 if (!realScreen)
388 return QScreen::mapToDevice(r, s);
389
390 return realScreen->mapToDevice(r, s);
391 }
392
393 /*!
394 \reimp
395 */
mapFromDevice(const QRegion & r,const QSize & s) const396 QRegion QProxyScreen::mapFromDevice(const QRegion &r, const QSize &s) const
397 {
398 if (!realScreen)
399 return QScreen::mapFromDevice(r, s);
400
401 return realScreen->mapFromDevice(r, s);
402 }
403
404 /*!
405 \reimp
406 */
disconnect()407 void QProxyScreen::disconnect()
408 {
409 if (realScreen) {
410 realScreen->disconnect();
411 delete realScreen;
412 realScreen = 0;
413 }
414 }
415
416 /*!
417 */
initDevice()418 bool QProxyScreen::initDevice()
419 {
420 if (realScreen)
421 return realScreen->initDevice();
422
423 return false;
424 }
425
426 /*!
427 \reimp
428 */
shutdownDevice()429 void QProxyScreen::shutdownDevice()
430 {
431 if (realScreen)
432 realScreen->shutdownDevice();
433 }
434
435 /*!
436 \reimp
437 */
setMode(int w,int h,int d)438 void QProxyScreen::setMode(int w,int h, int d)
439 {
440 if (realScreen) {
441 realScreen->setMode(w, h, d);
442 } else {
443 QScreen::dw = QScreen::w = w;
444 QScreen::dh = QScreen::h = h;
445 QScreen::d = d;
446 }
447 configure();
448 exposeRegion(region(), 0);
449 }
450
451 /*!
452 \reimp
453 */
supportsDepth(int depth) const454 bool QProxyScreen::supportsDepth(int depth) const
455 {
456 if (realScreen)
457 return realScreen->supportsDepth(depth);
458 return false;
459 }
460
461 /*!
462 \reimp
463 */
save()464 void QProxyScreen::save()
465 {
466 if (realScreen)
467 realScreen->save();
468 QScreen::save();
469 }
470
471 /*!
472 \reimp
473 */
restore()474 void QProxyScreen::restore()
475 {
476 if (realScreen)
477 realScreen->restore();
478 QScreen::restore();
479 }
480
481 /*!
482 \reimp
483 */
blank(bool on)484 void QProxyScreen::blank(bool on)
485 {
486 if (realScreen)
487 realScreen->blank(on);
488 }
489
490 /*!
491 \reimp
492 */
onCard(const unsigned char * ptr) const493 bool QProxyScreen::onCard(const unsigned char *ptr) const
494 {
495 if (realScreen)
496 return realScreen->onCard(ptr);
497 return false;
498 }
499
500 /*!
501 \reimp
502 */
onCard(const unsigned char * ptr,ulong & offset) const503 bool QProxyScreen::onCard(const unsigned char *ptr, ulong &offset) const
504 {
505 if (realScreen)
506 return realScreen->onCard(ptr, offset);
507 return false;
508 }
509
510 /*!
511 \reimp
512 */
isInterlaced() const513 bool QProxyScreen::isInterlaced() const
514 {
515 if (realScreen)
516 return realScreen->isInterlaced();
517 return false;
518 }
519
520 /*!
521 \reimp
522 */
isTransformed() const523 bool QProxyScreen::isTransformed() const
524 {
525 if (realScreen)
526 return realScreen->isTransformed();
527 return QScreen::isTransformed();
528 }
529
530 /*!
531 \reimp
532 */
transformOrientation() const533 int QProxyScreen::transformOrientation() const
534 {
535 if (realScreen)
536 return realScreen->transformOrientation();
537 return QScreen::transformOrientation();
538 }
539
540 /*!
541 \internal
542 */
memoryNeeded(const QString & str)543 int QProxyScreen::memoryNeeded(const QString &str)
544 {
545 if (realScreen)
546 return realScreen->memoryNeeded(str);
547 else
548 return QScreen::memoryNeeded(str);
549 }
550
551 /*!
552 \internal
553 */
sharedRamSize(void * ptr)554 int QProxyScreen::sharedRamSize(void *ptr)
555 {
556 if (realScreen)
557 return realScreen->sharedRamSize(ptr);
558 else
559 return QScreen::sharedRamSize(ptr);
560 }
561
562 /*!
563 \internal
564 */
haltUpdates()565 void QProxyScreen::haltUpdates()
566 {
567 if (realScreen)
568 realScreen->haltUpdates();
569 }
570
571 /*!
572 \internal
573 */
resumeUpdates()574 void QProxyScreen::resumeUpdates()
575 {
576 if (realScreen)
577 realScreen->resumeUpdates();
578 }
579
580 /*!
581 \reimp
582 */
setDirty(const QRect & rect)583 void QProxyScreen::setDirty(const QRect &rect)
584 {
585 if (realScreen)
586 realScreen->setDirty(rect);
587 }
588
589 /*!
590 \reimp
591 */
createSurface(QWidget * widget) const592 QWSWindowSurface* QProxyScreen::createSurface(QWidget *widget) const
593 {
594 if (realScreen)
595 return realScreen->createSurface(widget);
596
597 return QScreen::createSurface(widget);
598 }
599
600 /*!
601 \reimp
602 */
createSurface(const QString & key) const603 QWSWindowSurface* QProxyScreen::createSurface(const QString &key) const
604 {
605 if (realScreen)
606 return realScreen->createSurface(key);
607
608 return QScreen::createSurface(key);
609 }
610
611 /*!
612 \reimp
613 */
subScreens() const614 QList<QScreen*> QProxyScreen::subScreens() const
615 {
616 if (realScreen)
617 return realScreen->subScreens();
618
619 return QScreen::subScreens();
620 }
621
622 /*!
623 \reimp
624 */
region() const625 QRegion QProxyScreen::region() const
626 {
627 if (realScreen)
628 return realScreen->region();
629 else
630 return QScreen::region();
631 }
632
633 QT_END_NAMESPACE
634
635 #endif // QT_NO_QWS_PROXYSCREEN
636