src/gui/image/qpixmap_qws.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
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 <qpixmap.h>
       
    43 #include <qapplication.h>
       
    44 #include <qwidget.h>
       
    45 #include <qdesktopwidget.h>
       
    46 #include <qscreen_qws.h>
       
    47 #include <qwsdisplay_qws.h>
       
    48 #include <private/qdrawhelper_p.h>
       
    49 #include <private/qpixmap_raster_p.h>
       
    50 
       
    51 
       
    52 QT_BEGIN_NAMESPACE
       
    53 
       
    54 QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
       
    55 {
       
    56     QWidget *widget = QWidget::find(window);
       
    57     if (!widget)
       
    58         return QPixmap();
       
    59 
       
    60     QRect grabRect = widget->frameGeometry();
       
    61     if (!widget->isWindow())
       
    62         grabRect.translate(widget->parentWidget()->mapToGlobal(QPoint()));
       
    63     if (w < 0)
       
    64         w = widget->width() - x;
       
    65     if (h < 0)
       
    66         h = widget->height() - y;
       
    67     grabRect &= QRect(x, y, w, h).translated(widget->mapToGlobal(QPoint()));
       
    68 
       
    69     QScreen *screen = qt_screen;
       
    70     QDesktopWidget *desktop = QApplication::desktop();
       
    71     if (!desktop)
       
    72         return QPixmap();
       
    73     if (desktop->numScreens() > 1) {
       
    74         const int screenNo = desktop->screenNumber(widget);
       
    75         if (screenNo != -1)
       
    76             screen = qt_screen->subScreens().at(screenNo);
       
    77         grabRect = grabRect.translated(-screen->region().boundingRect().topLeft());
       
    78     }
       
    79 
       
    80     if (screen->pixelFormat() == QImage::Format_Invalid) {
       
    81         qWarning("QPixmap::grabWindow(): Unable to copy pixels from framebuffer");
       
    82         return QPixmap();
       
    83     }
       
    84 
       
    85     if (screen->isTransformed()) {
       
    86         const QSize screenSize(screen->width(), screen->height());
       
    87         grabRect = screen->mapToDevice(grabRect, screenSize);
       
    88     }
       
    89 
       
    90     QWSDisplay::grab(false);
       
    91     QPixmap pixmap;
       
    92     QImage img(screen->base(),
       
    93                screen->deviceWidth(), screen->deviceHeight(),
       
    94                screen->linestep(), screen->pixelFormat());
       
    95     img = img.copy(grabRect);
       
    96     QWSDisplay::ungrab();
       
    97 
       
    98     if (screen->isTransformed()) {
       
    99         QMatrix matrix;
       
   100         switch (screen->transformOrientation()) {
       
   101         case 1: matrix.rotate(90); break;
       
   102         case 2: matrix.rotate(180); break;
       
   103         case 3: matrix.rotate(270); break;
       
   104         default: break;
       
   105         }
       
   106         img = img.transformed(matrix);
       
   107     }
       
   108 
       
   109     if (screen->pixelType() == QScreen::BGRPixel)
       
   110         img = img.rgbSwapped();
       
   111 
       
   112     return QPixmap::fromImage(img);
       
   113 }
       
   114 
       
   115 QRgb* QPixmap::clut() const
       
   116 {
       
   117     if (data->classId() == QPixmapData::RasterClass) {
       
   118         const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
       
   119         return d->image.colorTable().data();
       
   120     }
       
   121 
       
   122     return 0;
       
   123 }
       
   124 
       
   125 int QPixmap::numCols() const
       
   126 {
       
   127     if (data->classId() == QPixmapData::RasterClass) {
       
   128         const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
       
   129         return d->image.numColors();
       
   130     }
       
   131 
       
   132     return 0;
       
   133 }
       
   134 
       
   135 const uchar* QPixmap::qwsBits() const
       
   136 {
       
   137     if (data->classId() == QPixmapData::RasterClass) {
       
   138         const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
       
   139         return d->image.bits();
       
   140     }
       
   141 
       
   142     return 0;
       
   143 }
       
   144 
       
   145 int QPixmap::qwsBytesPerLine() const
       
   146 {
       
   147     if (data->classId() == QPixmapData::RasterClass) {
       
   148         const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
       
   149         return d->image.bytesPerLine();
       
   150     }
       
   151 
       
   152     return 0;
       
   153 }
       
   154 
       
   155 QT_END_NAMESPACE