src/gui/embedded/qscreenproxy_qws.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    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 */
       
    62 QProxyScreenCursor::QProxyScreenCursor()
       
    63     : QScreenCursor(), realCursor(0), d_ptr(0)
       
    64 {
       
    65 }
       
    66 
       
    67 /*!
       
    68     Destroys the proxy screen cursor.
       
    69 */
       
    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 */
       
    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 */
       
    91 QScreenCursor* QProxyScreenCursor::screenCursor() const
       
    92 {
       
    93     return realCursor;
       
    94 }
       
    95 
       
    96 /*!
       
    97     \reimp
       
    98 */
       
    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 */
       
   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 */
       
   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 */
       
   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 */
       
   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 */
       
   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 */
       
   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 */
       
   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 */
       
   208 QScreen* QProxyScreen::screen() const
       
   209 {
       
   210     return realScreen;
       
   211 }
       
   212 
       
   213 
       
   214 /*!
       
   215     \internal
       
   216 */
       
   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 */
       
   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 */
       
   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 */
       
   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 */
       
   293 void QProxyScreen::blit(const QImage &image, const QPoint &topLeft,
       
   294                         const QRegion &region)
       
   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 */
       
   307 void QProxyScreen::solidFill(const QColor &color, const QRegion &region)
       
   308 {
       
   309     if (!realScreen) {
       
   310         QScreen::solidFill(color, region);
       
   311         return;
       
   312     }
       
   313     realScreen->solidFill(color, region);
       
   314 }
       
   315 
       
   316 /*!
       
   317     \reimp
       
   318 */
       
   319 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 */
       
   330 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 */
       
   341 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 */
       
   352 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 */
       
   363 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 */
       
   374 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 */
       
   385 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 */
       
   396 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 */
       
   407 void QProxyScreen::disconnect()
       
   408 {
       
   409     if (realScreen) {
       
   410         realScreen->disconnect();
       
   411         delete realScreen;
       
   412         realScreen = 0;
       
   413     }
       
   414 }
       
   415 
       
   416 /*!
       
   417 */
       
   418 bool QProxyScreen::initDevice()
       
   419 {
       
   420     if (realScreen)
       
   421         return realScreen->initDevice();
       
   422 
       
   423     return false;
       
   424 }
       
   425 
       
   426 /*!
       
   427     \reimp
       
   428 */
       
   429 void QProxyScreen::shutdownDevice()
       
   430 {
       
   431     if (realScreen)
       
   432         realScreen->shutdownDevice();
       
   433 }
       
   434 
       
   435 /*!
       
   436     \reimp
       
   437 */
       
   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 */
       
   454 bool QProxyScreen::supportsDepth(int depth) const
       
   455 {
       
   456     if (realScreen)
       
   457         return realScreen->supportsDepth(depth);
       
   458     return false;
       
   459 }
       
   460 
       
   461 /*!
       
   462     \reimp
       
   463 */
       
   464 void QProxyScreen::save()
       
   465 {
       
   466     if (realScreen)
       
   467         realScreen->save();
       
   468     QScreen::save();
       
   469 }
       
   470 
       
   471 /*!
       
   472     \reimp
       
   473 */
       
   474 void QProxyScreen::restore()
       
   475 {
       
   476     if (realScreen)
       
   477         realScreen->restore();
       
   478     QScreen::restore();
       
   479 }
       
   480 
       
   481 /*!
       
   482     \reimp
       
   483 */
       
   484 void QProxyScreen::blank(bool on)
       
   485 {
       
   486     if (realScreen)
       
   487         realScreen->blank(on);
       
   488 }
       
   489 
       
   490 /*!
       
   491     \reimp
       
   492 */
       
   493 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 */
       
   503 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 */
       
   513 bool QProxyScreen::isInterlaced() const
       
   514 {
       
   515     if (realScreen)
       
   516         return realScreen->isInterlaced();
       
   517     return false;
       
   518 }
       
   519 
       
   520 /*!
       
   521     \reimp
       
   522 */
       
   523 bool QProxyScreen::isTransformed() const
       
   524 {
       
   525     if (realScreen)
       
   526         return realScreen->isTransformed();
       
   527     return QScreen::isTransformed();
       
   528 }
       
   529 
       
   530 /*!
       
   531     \reimp
       
   532 */
       
   533 int QProxyScreen::transformOrientation() const
       
   534 {
       
   535     if (realScreen)
       
   536         return realScreen->transformOrientation();
       
   537     return QScreen::transformOrientation();
       
   538 }
       
   539 
       
   540 /*!
       
   541 \internal
       
   542 */
       
   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 */
       
   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 */
       
   565 void QProxyScreen::haltUpdates()
       
   566 {
       
   567     if (realScreen)
       
   568         realScreen->haltUpdates();
       
   569 }
       
   570 
       
   571 /*!
       
   572 \internal
       
   573 */
       
   574 void QProxyScreen::resumeUpdates()
       
   575 {
       
   576     if (realScreen)
       
   577         realScreen->resumeUpdates();
       
   578 }
       
   579 
       
   580 /*!
       
   581     \reimp
       
   582 */
       
   583 void QProxyScreen::setDirty(const QRect &rect)
       
   584 {
       
   585     if (realScreen)
       
   586         realScreen->setDirty(rect);
       
   587 }
       
   588 
       
   589 /*!
       
   590     \reimp
       
   591 */
       
   592 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 */
       
   603 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 */
       
   614 QList<QScreen*> QProxyScreen::subScreens() const
       
   615 {
       
   616     if (realScreen)
       
   617         return realScreen->subScreens();
       
   618 
       
   619     return QScreen::subScreens();
       
   620 }
       
   621 
       
   622 /*!
       
   623     \reimp
       
   624 */
       
   625 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