summaryrefslogtreecommitdiffstats
path: root/examples/qws
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /examples/qws
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'examples/qws')
-rw-r--r--examples/qws/README38
-rw-r--r--examples/qws/dbscreen/dbscreen.cpp95
-rw-r--r--examples/qws/dbscreen/dbscreen.h66
-rw-r--r--examples/qws/dbscreen/dbscreen.pro11
-rw-r--r--examples/qws/dbscreen/dbscreendriverplugin.cpp76
-rw-r--r--examples/qws/framebuffer/framebuffer.pro11
-rw-r--r--examples/qws/framebuffer/main.c585
-rw-r--r--examples/qws/mousecalibration/calibration.cpp144
-rw-r--r--examples/qws/mousecalibration/calibration.h67
-rw-r--r--examples/qws/mousecalibration/main.cpp92
-rw-r--r--examples/qws/mousecalibration/mousecalibration.pro11
-rw-r--r--examples/qws/mousecalibration/scribblewidget.cpp92
-rw-r--r--examples/qws/mousecalibration/scribblewidget.h70
-rw-r--r--examples/qws/qws.pro9
-rw-r--r--examples/qws/simpledecoration/analogclock.cpp110
-rw-r--r--examples/qws/simpledecoration/analogclock.h57
-rw-r--r--examples/qws/simpledecoration/main.cpp59
-rw-r--r--examples/qws/simpledecoration/mydecoration.cpp374
-rw-r--r--examples/qws/simpledecoration/mydecoration.h72
-rw-r--r--examples/qws/simpledecoration/simpledecoration.pro12
-rw-r--r--examples/qws/svgalib/README9
-rw-r--r--examples/qws/svgalib/svgalib.pro19
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.cpp66
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.h65
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.cpp190
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.h78
-rw-r--r--examples/qws/svgalib/svgalibplugin.cpp74
-rw-r--r--examples/qws/svgalib/svgalibscreen.cpp353
-rw-r--r--examples/qws/svgalib/svgalibscreen.h83
-rw-r--r--examples/qws/svgalib/svgalibsurface.cpp86
-rw-r--r--examples/qws/svgalib/svgalibsurface.h75
31 files changed, 3149 insertions, 0 deletions
diff --git a/examples/qws/README b/examples/qws/README
new file mode 100644
index 0000000000..d7cf21a5c5
--- /dev/null
+++ b/examples/qws/README
@@ -0,0 +1,38 @@
+These examples show how to take advantage of features specifically designed
+for use on systems with limited resources, specialized hardware, and small
+screens.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/qws/dbscreen/dbscreen.cpp b/examples/qws/dbscreen/dbscreen.cpp
new file mode 100644
index 0000000000..61953d98c2
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "dbscreen.h"
+#include <QApplication>
+
+//! [0]
+bool DBScreen::initDevice()
+{
+ if (!QLinuxFbScreen::initDevice())
+ return false;
+
+ QScreenCursor::initSoftwareCursor();
+ image = new QImage(deviceWidth(), deviceHeight(), pixelFormat());
+ painter = new QPainter(image);
+
+ return true;
+}
+//! [0]
+
+//! [1]
+void DBScreen::shutdownDevice()
+{
+ QLinuxFbScreen::shutdownDevice();
+ delete painter;
+ delete image;
+}
+//! [1]
+
+//! [2]
+void DBScreen::solidFill(const QColor &color, const QRegion &region)
+{
+ QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); i++)
+ painter->fillRect(rects.at(i), color);
+}
+//! [2]
+
+//! [3]
+void DBScreen::blit(const QImage &image, const QPoint &topLeft, const QRegion &region)
+{
+ QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); i++) {
+ QRect destRect = rects.at(i);
+ QRect srcRect(destRect.x()-topLeft.x(), destRect.y()-topLeft.y(), destRect.width(), destRect.height());
+ painter->drawImage(destRect.topLeft(), image, srcRect);
+ }
+}
+//! [3]
+
+//! [4]
+void DBScreen::exposeRegion(QRegion region, int changing)
+{
+ QLinuxFbScreen::exposeRegion(region, changing);
+ QLinuxFbScreen::blit(*image, QPoint(0, 0), region);
+}
+//! [4]
+
diff --git a/examples/qws/dbscreen/dbscreen.h b/examples/qws/dbscreen/dbscreen.h
new file mode 100644
index 0000000000..a708f07f1f
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DBSCREEN_H
+#define DBSCREEN_H
+
+#include <QLinuxFbScreen>
+#include <QPainter>
+
+//! [0]
+class DBScreen : public QLinuxFbScreen
+{
+public:
+ DBScreen(int displayId) : QLinuxFbScreen(displayId) {};
+ ~DBScreen() {}
+ bool initDevice();
+ void shutdownDevice();
+ void blit(const QImage &image, const QPoint &topLeft, const QRegion &region);
+ void solidFill(const QColor &color, const QRegion &region);
+ void exposeRegion(QRegion region, int changing);
+
+private:
+ QPainter *painter;
+ QImage *image;
+};
+//! [0]
+
+#endif // DBSCREEN_H
+
diff --git a/examples/qws/dbscreen/dbscreen.pro b/examples/qws/dbscreen/dbscreen.pro
new file mode 100644
index 0000000000..172a02a5e7
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.pro
@@ -0,0 +1,11 @@
+TEMPLATE = lib
+CONFIG += plugin
+
+TARGET = dbscreen
+target.path += $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+HEADERS = dbscreen.h
+SOURCES = dbscreendriverplugin.cpp \
+ dbscreen.cpp
+
diff --git a/examples/qws/dbscreen/dbscreendriverplugin.cpp b/examples/qws/dbscreen/dbscreendriverplugin.cpp
new file mode 100644
index 0000000000..7d70431900
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreendriverplugin.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QScreenDriverPlugin>
+#include "dbscreen.h"
+
+//! [0]
+class DBScreenDriverPlugin : public QScreenDriverPlugin
+{
+public:
+ DBScreenDriverPlugin();
+ QScreen* create(const QString& key, int displayId);
+ QStringList keys () const;
+};
+//! [0]
+
+DBScreenDriverPlugin::DBScreenDriverPlugin() : QScreenDriverPlugin()
+{
+}
+
+//! [1]
+QScreen* DBScreenDriverPlugin::create(const QString& key, int displayId)
+{
+ if (key.toLower() != "dbscreen")
+ return 0;
+
+ return new DBScreen(displayId);
+}
+//! [1]
+
+//! [2]
+QStringList DBScreenDriverPlugin::keys() const
+{
+ return QStringList() << "dbscreen";
+}
+//! [2] //! [3]
+
+Q_EXPORT_PLUGIN2(dbscreen, DBScreenDriverPlugin)
+//! [3]
diff --git a/examples/qws/framebuffer/framebuffer.pro b/examples/qws/framebuffer/framebuffer.pro
new file mode 100644
index 0000000000..098a97ed14
--- /dev/null
+++ b/examples/qws/framebuffer/framebuffer.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = framebuffer
+CONFIG -= qt
+
+SOURCES += main.c
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/framebuffer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS framebuffer.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/framebuffer
+INSTALLS += target sources
diff --git a/examples/qws/framebuffer/main.c b/examples/qws/framebuffer/main.c
new file mode 100644
index 0000000000..ab1a0fd373
--- /dev/null
+++ b/examples/qws/framebuffer/main.c
@@ -0,0 +1,585 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <linux/fb.h>
+#include <linux/kd.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <string.h>
+#include <errno.h>
+
+struct fb_var_screeninfo vinfo;
+struct fb_fix_screeninfo finfo;
+char *frameBuffer = 0;
+int fbFd = 0;
+int ttyFd = 0;
+
+void printFixedInfo()
+{
+ printf("Fixed screen info:\n"
+ "\tid: %s\n"
+ "\tsmem_start: 0x%lx\n"
+ "\tsmem_len: %d\n"
+ "\ttype: %d\n"
+ "\ttype_aux: %d\n"
+ "\tvisual: %d\n"
+ "\txpanstep: %d\n"
+ "\typanstep: %d\n"
+ "\tywrapstep: %d\n"
+ "\tline_length: %d\n"
+ "\tmmio_start: 0x%lx\n"
+ "\tmmio_len: %d\n"
+ "\taccel: %d\n"
+ "\n",
+ finfo.id, finfo.smem_start, finfo.smem_len, finfo.type,
+ finfo.type_aux, finfo.visual, finfo.xpanstep, finfo.ypanstep,
+ finfo.ywrapstep, finfo.line_length, finfo.mmio_start,
+ finfo.mmio_len, finfo.accel);
+}
+
+void printVariableInfo()
+{
+ printf("Variable screen info:\n"
+ "\txres: %d\n"
+ "\tyres: %d\n"
+ "\txres_virtual: %d\n"
+ "\tyres_virtual: %d\n"
+ "\tyoffset: %d\n"
+ "\txoffset: %d\n"
+ "\tbits_per_pixel: %d\n"
+ "\tgrayscale: %d\n"
+ "\tred: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\tgreen: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\tblue: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\ttransp: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\tnonstd: %d\n"
+ "\tactivate: %d\n"
+ "\theight: %d\n"
+ "\twidth: %d\n"
+ "\taccel_flags: 0x%x\n"
+ "\tpixclock: %d\n"
+ "\tleft_margin: %d\n"
+ "\tright_margin: %d\n"
+ "\tupper_margin: %d\n"
+ "\tlower_margin: %d\n"
+ "\thsync_len: %d\n"
+ "\tvsync_len: %d\n"
+ "\tsync: %d\n"
+ "\tvmode: %d\n"
+ "\n",
+ vinfo.xres, vinfo.yres, vinfo.xres_virtual, vinfo.yres_virtual,
+ vinfo.xoffset, vinfo.yoffset, vinfo.bits_per_pixel, vinfo.grayscale,
+ vinfo.red.offset, vinfo.red.length, vinfo.red.msb_right,
+ vinfo.green.offset, vinfo.green.length, vinfo.green.msb_right,
+ vinfo.blue.offset, vinfo.blue.length, vinfo.blue.msb_right,
+ vinfo.transp.offset, vinfo.transp.length, vinfo.transp.msb_right,
+ vinfo.nonstd, vinfo.activate, vinfo.height, vinfo.width,
+ vinfo.accel_flags, vinfo.pixclock, vinfo.left_margin,
+ vinfo.right_margin, vinfo.upper_margin, vinfo.lower_margin,
+ vinfo.hsync_len, vinfo.vsync_len, vinfo.sync, vinfo.vmode);
+}
+
+long switchToGraphicsMode()
+{
+ const char *const devs[] = {"/dev/tty0", "/dev/tty", "/dev/console", 0};
+ const char * const *dev;
+ long oldMode = KD_TEXT;
+
+ for (dev = devs; *dev; ++dev) {
+ ttyFd = open(*dev, O_RDWR);
+ if (ttyFd != -1)
+ break;
+ printf("Opening tty device %s failed: %s\n", *dev, strerror(errno));
+ }
+
+ ioctl(ttyFd, KDGETMODE, &oldMode);
+ if (oldMode == KD_GRAPHICS) {
+ printf("Was in graphics mode already. Skipping\n");
+ return oldMode;
+ }
+ int ret = ioctl(ttyFd, KDSETMODE, KD_GRAPHICS);
+ if (ret == -1) {
+ printf("Switch to graphics mode failed: %s\n", strerror(errno));
+ return oldMode;
+ }
+
+ printf("Successfully switched to graphics mode.\n\n");
+
+ return oldMode;
+}
+
+void restoreTextMode(long oldMode)
+{
+ if (ttyFd == -1)
+ return;
+
+ ioctl(ttyFd, KDSETMODE, oldMode);
+ close(ttyFd);
+}
+
+struct fb_cmap oldPalette;
+struct fb_cmap palette;
+int paletteSize = 0;
+
+void initPalette_16()
+{
+ if (finfo.type == FB_TYPE_PACKED_PIXELS) {
+ // We'll setup a grayscale map for 4bpp linear
+ int val = 0;
+ int i;
+ for (i = 0; i < 16; ++i) {
+ palette.red[i] = (val << 8) | val;
+ palette.green[i] = (val << 8) | val;
+ palette.blue[i] = (val << 8) | val;
+ val += 17;
+ }
+ return;
+ }
+
+ // Default 16 colour palette
+ unsigned char reds[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0xFF, 0xA2,
+ 0x00, 0xFF, 0xFF, 0x00, 0x7F, 0x7F,
+ 0x00, 0x00, 0x00, 0x82 };
+ unsigned char greens[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0xC5,
+ 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00,
+ 0x00, 0x7F, 0x7F, 0x7F };
+ unsigned char blues[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0x11,
+ 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x7F,
+ 0x7F, 0x7F, 0x00, 0x00 };
+
+ int i;
+ for (i = 0; i < 16; ++i) {
+ palette.red[i] = ((reds[i]) << 8) | reds[i];
+ palette.green[i] = ((greens[i]) << 8) | greens[i];
+ palette.blue[i] = ((blues[i]) << 8) | blues[i];
+ palette.transp[i] = 0;
+ }
+}
+
+void initPalette_256()
+{
+ if (vinfo.grayscale) {
+ int i;
+ for (i = 0; i < 256; ++i) {
+ unsigned short c = (i << 8) | i;
+ palette.red[i] = c;
+ palette.green[i] = c;
+ palette.blue[i] = c;
+ palette.transp[i] = 0;
+ }
+ return;
+ }
+
+ // 6x6x6 216 color cube
+ int i = 0;
+ int ir, ig, ib;
+ for (ir = 0x0; ir <= 0xff; ir += 0x33) {
+ for (ig = 0x0; ig <= 0xff; ig += 0x33) {
+ for (ib = 0x0; ib <= 0xff; ib += 0x33) {
+ palette.red[i] = (ir << 8)|ir;
+ palette.green[i] = (ig << 8)|ig;
+ palette.blue[i] = (ib << 8)|ib;
+ palette.transp[i] = 0;
+ ++i;
+ }
+ }
+ }
+}
+
+void initPalette()
+{
+ switch (vinfo.bits_per_pixel) {
+ case 8: paletteSize = 256; break;
+ case 4: paletteSize = 16; break;
+ default: break;
+ }
+
+ if (!paletteSize)
+ return; /* not using a palette */
+
+ /* read old palette */
+ oldPalette.start = 0;
+ oldPalette.len = paletteSize;
+ oldPalette.red = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ oldPalette.green = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ oldPalette.blue=(unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ oldPalette.transp=(unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ if (ioctl(ttyFd, FBIOGETCMAP, &oldPalette) == -1)
+ perror("initPalette: error reading palette");
+
+ /* create new palette */
+ palette.start = 0;
+ palette.len = paletteSize;
+ palette.red = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ palette.green = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ palette.blue = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ palette.transp = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ switch (paletteSize) {
+ case 16: initPalette_16(); break;
+ case 256: initPalette_256(); break;
+ default: break;
+ }
+
+ /* set new palette */
+ if (ioctl(ttyFd, FBIOPUTCMAP, &palette) == -1)
+ perror("initPalette: error setting palette");
+}
+
+void resetPalette()
+{
+ if (paletteSize == 0)
+ return;
+
+ if (ioctl(ttyFd, FBIOPUTCMAP, &oldPalette) == -1)
+ perror("resetPalette");
+
+ free(oldPalette.red);
+ free(oldPalette.green);
+ free(oldPalette.blue);
+ free(oldPalette.transp);
+
+ free(palette.red);
+ free(palette.green);
+ free(palette.blue);
+ free(palette.transp);
+}
+
+void drawRect_rgb32(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 4;
+ const int stride = finfo.line_length / bytesPerPixel;
+
+ int *dest = (int*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_rgb18(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 3;
+ const int stride = finfo.line_length - width * bytesPerPixel;
+ const int red = (color & 0xff0000) >> 16;
+ const int green = (color & 0xff00) >> 8;
+ const int blue = (color & 0xff);
+ const unsigned int packed = (blue >> 2) |
+ ((green >> 2) << 6) |
+ ((red >> 2) << 12);
+ const char color18[3] = { packed & 0xff,
+ (packed & 0xff00) >> 8,
+ (packed & 0xff0000) >> 16 };
+
+ char *dest = (char*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ *dest++ = color18[0];
+ *dest++ = color18[1];
+ *dest++ = color18[2];
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_rgb16(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 2;
+ const int stride = finfo.line_length / bytesPerPixel;
+ const int red = (color & 0xff0000) >> (16 + 3);
+ const int green = (color & 0xff00) >> (8 + 2);
+ const int blue = (color & 0xff) >> 3;
+ const short color16 = blue | (green << 5) | (red << (5 + 6));
+
+ short *dest = (short*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color16;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_rgb15(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 2;
+ const int stride = finfo.line_length / bytesPerPixel;
+ const int red = (color & 0xff0000) >> (16 + 3);
+ const int green = (color & 0xff00) >> (8 + 3);
+ const int blue = (color & 0xff) >> 3;
+ const short color15 = blue | (green << 5) | (red << (5 + 5));
+
+ short *dest = (short*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color15;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_palette(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 1;
+ const int stride = finfo.line_length / bytesPerPixel;
+ const unsigned char color8 = color;
+
+ unsigned char *dest = (unsigned char*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color8;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect(int x0, int y0, int width, int height, int color)
+{
+ switch (vinfo.bits_per_pixel) {
+ case 32:
+ drawRect_rgb32(x0, y0, width, height, color);
+ break;
+ case 18:
+ drawRect_rgb18(x0, y0, width, height, color);
+ break;
+ case 16:
+ drawRect_rgb16(x0, y0, width, height, color);
+ break;
+ case 15:
+ drawRect_rgb15(x0, y0, width, height, color);
+ break;
+ case 8:
+ drawRect_palette(x0, y0, width, height, color);
+ break;
+ case 4:
+ drawRect_palette(x0, y0, width, height, color);
+ break;
+ default:
+ printf("Warning: drawRect() not implemented for color depth %i\n",
+ vinfo.bits_per_pixel);
+ break;
+ }
+}
+
+#define PERFORMANCE_RUN_COUNT 5
+void performSpeedTest(void* fb, int fbSize)
+{
+ int i, j, run;
+
+ struct timeval startTime, endTime;
+ unsigned long long results[PERFORMANCE_RUN_COUNT];
+ unsigned long long average;
+
+ unsigned int* testImage;
+
+ unsigned int randData[17] = {
+ 0x3A428472, 0x724B84D3, 0x26B898AB, 0x7D980E3C, 0x5345A084,
+ 0x6779B66B, 0x791EE4B4, 0x6E8EE3CC, 0x63AF504A, 0x18A21B33,
+ 0x0E26EB73, 0x022F708E, 0x1740F3B0, 0x7E2C699D, 0x0E8A570B,
+ 0x5F2C22FB, 0x6A742130
+ };
+
+ printf("Frame Buffer Performance test...\n");
+
+ for (run=0; run<PERFORMANCE_RUN_COUNT; ++run) {
+
+ /* Generate test image with random(ish) data: */
+ testImage = (unsigned int*) malloc(fbSize);
+ j = run;
+ for (i=0; i < (int)(fbSize / sizeof(int)); ++i) {
+ testImage[i] = randData[j];
+ j++;
+ if (j >= 17)
+ j = 0;
+ }
+
+ gettimeofday(&startTime, NULL);
+ memcpy(fb, testImage, fbSize);
+ gettimeofday(&endTime, NULL);
+
+ long secsDiff = endTime.tv_sec - startTime.tv_sec;
+ results[run] = secsDiff * 1000000 + (endTime.tv_usec - startTime.tv_usec);
+
+ free(testImage);
+ }
+
+
+ average = 0;
+ for (i=0; i<PERFORMANCE_RUN_COUNT; ++i)
+ average += results[i];
+ average = average / PERFORMANCE_RUN_COUNT;
+
+ printf(" Average: %llu usecs\n", average);
+ printf(" Bandwidth: %.03f MByte/Sec\n", (fbSize / 1048576.0) / ((double)average / 1000000.0));
+ printf(" Max. FPS: %.03f fps\n\n", 1000000.0 / (double)average);
+
+ /* Clear the framebuffer back to black again: */
+ memset(fb, 0, fbSize);
+}
+
+int main(int argc, char **argv)
+{
+ long int screensize = 0;
+ int doGraphicsMode = 1;
+ long oldKdMode = KD_TEXT;
+ const char *devfile = "/dev/fb0";
+ int nextArg = 1;
+
+ if (nextArg < argc) {
+ if (strncmp("nographicsmodeswitch", argv[nextArg],
+ strlen("nographicsmodeswitch")) == 0)
+ {
+ ++nextArg;
+ doGraphicsMode = 0;
+ }
+ }
+ if (nextArg < argc)
+ devfile = argv[nextArg++];
+
+ /* Open the file for reading and writing */
+ fbFd = open(devfile, O_RDWR);
+ if (fbFd == -1) {
+ perror("Error: cannot open framebuffer device");
+ exit(1);
+ }
+ printf("The framebuffer device was opened successfully.\n\n");
+
+ /* Get fixed screen information */
+ if (ioctl(fbFd, FBIOGET_FSCREENINFO, &finfo) == -1) {
+ perror("Error reading fixed information");
+ exit(2);
+ }
+
+ printFixedInfo();
+
+ /* Figure out the size of the screen in bytes */
+ screensize = finfo.smem_len;
+
+ /* Map the device to memory */
+ frameBuffer = (char *)mmap(0, screensize,
+ PROT_READ | PROT_WRITE, MAP_SHARED,
+ fbFd, 0);
+ if (frameBuffer == MAP_FAILED) {
+ perror("Error: Failed to map framebuffer device to memory");
+ exit(4);
+ }
+ printf("The framebuffer device was mapped to memory successfully.\n"
+ "\n");
+
+ if (doGraphicsMode)
+ oldKdMode = switchToGraphicsMode();
+
+ /* Get variable screen information */
+ if (ioctl(fbFd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
+ perror("Error reading variable information");
+ exit(3);
+ }
+
+ printVariableInfo();
+
+ performSpeedTest(frameBuffer, screensize);
+
+ initPalette();
+
+ if (paletteSize == 0) {
+ printf("Will draw 3 rectangles on the screen,\n"
+ "they should be colored red, green and blue (in that order).\n");
+ drawRect(vinfo.xres / 8, vinfo.yres / 8,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 0xffff0000);
+ drawRect(vinfo.xres * 3 / 8, vinfo.yres * 3 / 8,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 0xff00ff00);
+ drawRect(vinfo.xres * 5 / 8, vinfo.yres * 5 / 8,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 0xff0000ff);
+ } else {
+ printf("Will rectangles from the 16 first entries in the color palette"
+ " on the screen\n");
+ int y;
+ int x;
+ for (y = 0; y < 4; ++y) {
+ for (x = 0; x < 4; ++x) {
+ drawRect(vinfo.xres / 4 * x, vinfo.yres / 4 * y,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 4 * y + x);
+ }
+ }
+ }
+
+ sleep(5);
+
+ resetPalette();
+
+ printf(" Done.\n");
+
+ if (doGraphicsMode)
+ restoreTextMode(oldKdMode);
+
+ munmap(frameBuffer, screensize);
+ close(fbFd);
+ return 0;
+}
diff --git a/examples/qws/mousecalibration/calibration.cpp b/examples/qws/mousecalibration/calibration.cpp
new file mode 100644
index 0000000000..c0746c9aeb
--- /dev/null
+++ b/examples/qws/mousecalibration/calibration.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "calibration.h"
+
+#include <QWSPointerCalibrationData>
+#include <QPainter>
+#include <QFile>
+#include <QTimer>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QMouseEvent>
+#include <QScreen>
+#include <QWSServer>
+
+//! [0]
+Calibration::Calibration()
+{
+ QRect desktop = QApplication::desktop()->geometry();
+ desktop.moveTo(QPoint(0, 0));
+ setGeometry(desktop);
+
+ setFocusPolicy(Qt::StrongFocus);
+ setFocus();
+ setModal(true);
+//! [0]
+
+//! [1]
+ int width = qt_screen->deviceWidth();
+ int height = qt_screen->deviceHeight();
+
+ int dx = width / 10;
+ int dy = height / 10;
+
+ QPoint *points = data.screenPoints;
+ points[QWSPointerCalibrationData::TopLeft] = QPoint(dx, dy);
+ points[QWSPointerCalibrationData::BottomLeft] = QPoint(dx, height - dy);
+ points[QWSPointerCalibrationData::BottomRight] = QPoint(width - dx, height - dy);
+ points[QWSPointerCalibrationData::TopRight] = QPoint(width - dx, dy);
+ points[QWSPointerCalibrationData::Center] = QPoint(width / 2, height / 2);
+//! [1]
+
+//! [2]
+ pressCount = 0;
+}
+//! [2]
+
+//! [3]
+Calibration::~Calibration()
+{
+}
+//! [3]
+
+//! [4]
+int Calibration::exec()
+{
+ QWSServer::mouseHandler()->clearCalibration();
+ grabMouse();
+ activateWindow();
+ int ret = QDialog::exec();
+ releaseMouse();
+ return ret;
+}
+//! [4]
+
+//! [5]
+void Calibration::paintEvent(QPaintEvent*)
+{
+ QPainter p(this);
+ p.fillRect(rect(), Qt::white);
+
+ QPoint point = data.screenPoints[pressCount];
+
+ // Map to logical coordinates in case the screen is transformed
+ QSize screenSize(qt_screen->deviceWidth(), qt_screen->deviceHeight());
+ point = qt_screen->mapFromDevice(point, screenSize);
+
+ p.fillRect(point.x() - 6, point.y() - 1, 13, 3, Qt::black);
+ p.fillRect(point.x() - 1, point.y() - 6, 3, 13, Qt::black);
+}
+//! [5]
+
+//! [6]
+void Calibration::mouseReleaseEvent(QMouseEvent *event)
+{
+ // Map from device coordinates in case the screen is transformed
+ QSize screenSize(qt_screen->width(), qt_screen->height());
+ QPoint p = qt_screen->mapToDevice(event->pos(), screenSize);
+
+ data.devPoints[pressCount] = p;
+
+ if (++pressCount < 5)
+ repaint();
+ else
+ accept();
+}
+//! [6]
+
+//! [7]
+void Calibration::accept()
+{
+ Q_ASSERT(pressCount == 5);
+ QWSServer::mouseHandler()->calibrate(&data);
+ QDialog::accept();
+}
+//! [7]
+
diff --git a/examples/qws/mousecalibration/calibration.h b/examples/qws/mousecalibration/calibration.h
new file mode 100644
index 0000000000..4988b6e755
--- /dev/null
+++ b/examples/qws/mousecalibration/calibration.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CALIBRATION_H
+#define CALIBRATION_H
+
+#include <QDialog>
+#include <QWSPointerCalibrationData>
+
+//! [0]
+class Calibration : public QDialog
+{
+public:
+ Calibration();
+ ~Calibration();
+ int exec();
+
+protected:
+ void paintEvent(QPaintEvent*);
+ void mouseReleaseEvent(QMouseEvent*);
+ void accept();
+
+private:
+ QWSPointerCalibrationData data;
+ int pressCount;
+};
+//! [0]
+
+
+#endif
diff --git a/examples/qws/mousecalibration/main.cpp b/examples/qws/mousecalibration/main.cpp
new file mode 100644
index 0000000000..3db11cd109
--- /dev/null
+++ b/examples/qws/mousecalibration/main.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMessageBox>
+#include <QTimer>
+#include <QWSServer>
+
+#include "calibration.h"
+#include "scribblewidget.h"
+
+//! [0]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv, QApplication::GuiServer);
+
+ if (!QWSServer::mouseHandler())
+ qFatal("No mouse handler installed");
+
+ {
+ QMessageBox message;
+ message.setText("<p>Please press once at each of the marks "
+ "shown in the next screen.</p>"
+ "<p>This messagebox will timout after 10 seconds "
+ "if you are unable to close it.</p>");
+ QTimer::singleShot(10 * 1000, &message, SLOT(accept()));
+ message.exec();
+ }
+
+//! [0] //! [1]
+ Calibration cal;
+ cal.exec();
+//! [1]
+
+//! [2]
+ {
+ QMessageBox message;
+ message.setText("<p>The next screen will let you test the calibration "
+ "by drawing into a widget.</p><p>This program will "
+ "automatically close after 20 seconds.<p>");
+ QTimer::singleShot(10 * 1000, &message, SLOT(accept()));
+ message.exec();
+ }
+
+ ScribbleWidget scribble;
+ scribble.showMaximized();
+ scribble.show();
+
+ app.setActiveWindow(&scribble);
+ QTimer::singleShot(20 * 1000, &app, SLOT(quit()));
+
+ return app.exec();
+}
+//! [2]
+
diff --git a/examples/qws/mousecalibration/mousecalibration.pro b/examples/qws/mousecalibration/mousecalibration.pro
new file mode 100644
index 0000000000..878aff23bc
--- /dev/null
+++ b/examples/qws/mousecalibration/mousecalibration.pro
@@ -0,0 +1,11 @@
+HEADERS += calibration.h \
+ scribblewidget.h
+SOURCES += calibration.cpp \
+ scribblewidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/mousecalibration
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/mousecalibration
+INSTALLS += target sources
diff --git a/examples/qws/mousecalibration/scribblewidget.cpp b/examples/qws/mousecalibration/scribblewidget.cpp
new file mode 100644
index 0000000000..cc24aeb3bf
--- /dev/null
+++ b/examples/qws/mousecalibration/scribblewidget.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "scribblewidget.h"
+
+ScribbleWidget::ScribbleWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ scribbling = false;
+}
+
+void ScribbleWidget::resizeEvent(QResizeEvent *e)
+{
+ image = QImage(e->size(), QImage::Format_RGB32);
+ image.fill(QColor(Qt::white).rgb());
+}
+
+void ScribbleWidget::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() != Qt::LeftButton)
+ return;
+
+ lastPoint = event->pos();
+ scribbling = true;
+}
+
+void ScribbleWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ if ((event->buttons() & Qt::LeftButton) && scribbling)
+ drawLineTo(event->pos());
+}
+
+void ScribbleWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && scribbling) {
+ drawLineTo(event->pos());
+ scribbling = false;
+ }
+}
+
+void ScribbleWidget::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.drawImage(QPoint(0, 0), image);
+}
+
+void ScribbleWidget::drawLineTo(const QPoint &endPoint)
+{
+ QPainter painter(&image);
+ painter.setPen(QPen(Qt::blue, 1, Qt::SolidLine,
+ Qt::RoundCap, Qt::RoundJoin));
+ painter.drawLine(lastPoint, endPoint);
+ update();
+ lastPoint = endPoint;
+}
diff --git a/examples/qws/mousecalibration/scribblewidget.h b/examples/qws/mousecalibration/scribblewidget.h
new file mode 100644
index 0000000000..a8957b4664
--- /dev/null
+++ b/examples/qws/mousecalibration/scribblewidget.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCRIBBLEWIDGET_H
+#define SCRIBBLEWIDGET_H
+
+#include <QLabel>
+#include <QMouseEvent>
+#include <QResizeEvent>
+#include <QImage>
+#include <QPainter>
+
+class ScribbleWidget : public QWidget
+{
+public:
+ ScribbleWidget(QWidget *parent = 0);
+
+ void resizeEvent(QResizeEvent *e);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *);
+
+private:
+ void drawLineTo(const QPoint &endPoint);
+
+private:
+ bool scribbling;
+ QPoint lastPoint;
+ QImage image;
+};
+
+#endif // SCRIBBLEWIDGET_H
diff --git a/examples/qws/qws.pro b/examples/qws/qws.pro
new file mode 100644
index 0000000000..7736625cbe
--- /dev/null
+++ b/examples/qws/qws.pro
@@ -0,0 +1,9 @@
+TEMPLATE = subdirs
+# no /dev/fbX
+!qnx:!vxworks:SUBDIRS = framebuffer
+SUBDIRS += mousecalibration simpledecoration
+
+# install
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws
+INSTALLS += sources
diff --git a/examples/qws/simpledecoration/analogclock.cpp b/examples/qws/simpledecoration/analogclock.cpp
new file mode 100644
index 0000000000..4a91e0dc0a
--- /dev/null
+++ b/examples/qws/simpledecoration/analogclock.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "analogclock.h"
+
+AnalogClock::AnalogClock(QWidget *parent)
+ : QWidget(parent)
+{
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(update()));
+ timer->start(1000);
+
+ setWindowTitle(tr("Analog Clock"));
+ resize(200, 200);
+}
+
+void AnalogClock::paintEvent(QPaintEvent *)
+{
+ static const QPoint hourHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -40)
+ };
+ static const QPoint minuteHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -70)
+ };
+
+ QColor hourColor(127, 0, 127);
+ QColor minuteColor(0, 127, 127, 191);
+
+ int side = qMin(width(), height());
+ QTime time = QTime::currentTime();
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.translate(width() / 2, height() / 2);
+ painter.scale(side / 200.0, side / 200.0);
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(hourColor);
+
+ painter.save();
+ painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
+ painter.drawConvexPolygon(hourHand, 3);
+ painter.restore();
+
+ painter.setPen(hourColor);
+
+ for (int i = 0; i < 12; ++i) {
+ painter.drawLine(88, 0, 96, 0);
+ painter.rotate(30.0);
+ }
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(minuteColor);
+
+ painter.save();
+ painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
+ painter.drawConvexPolygon(minuteHand, 3);
+ painter.restore();
+
+ painter.setPen(minuteColor);
+
+ for (int j = 0; j < 60; ++j) {
+ if ((j % 5) != 0)
+ painter.drawLine(92, 0, 96, 0);
+ painter.rotate(6.0);
+ }
+}
diff --git a/examples/qws/simpledecoration/analogclock.h b/examples/qws/simpledecoration/analogclock.h
new file mode 100644
index 0000000000..6fef764ee1
--- /dev/null
+++ b/examples/qws/simpledecoration/analogclock.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANALOGCLOCK_H
+#define ANALOGCLOCK_H
+
+#include <QWidget>
+
+class AnalogClock : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AnalogClock(QWidget *parent = 0);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+};
+
+#endif
diff --git a/examples/qws/simpledecoration/main.cpp b/examples/qws/simpledecoration/main.cpp
new file mode 100644
index 0000000000..9a8f913ee5
--- /dev/null
+++ b/examples/qws/simpledecoration/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "analogclock.h"
+#include "mydecoration.h"
+
+//! [create application]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MyDecoration *decoration = new MyDecoration();
+ app.qwsSetDecoration(decoration);
+//! [create application]
+
+//! [start application]
+ AnalogClock clock;
+ clock.show();
+
+ return app.exec();
+}
+//! [start application]
diff --git a/examples/qws/simpledecoration/mydecoration.cpp b/examples/qws/simpledecoration/mydecoration.cpp
new file mode 100644
index 0000000000..32db90596e
--- /dev/null
+++ b/examples/qws/simpledecoration/mydecoration.cpp
@@ -0,0 +1,374 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "mydecoration.h"
+
+/* XPM */
+static const char * const _close_button[] = {
+"16 16 3 1",
+" c none",
+". c #ffafaf",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" x............x ",
+" x.x........x.x ",
+" x..x......x..x ",
+" x...x....x...x ",
+" x....x..x....x ",
+" x.....xx.....x ",
+" x.....xx.....x ",
+" x....x..x....x ",
+" x...x....x...x ",
+" x..x......x..x ",
+" x.x........x.x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+static const char * const _normalize_button[] = {
+"16 16 4 1",
+" c none",
+". c #dfdfff",
+"o c #7f7f7f",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" xx...........x ",
+" x.x..........x ",
+" x..x..x......x ",
+" x...xxx......x ",
+" x...xxx......x ",
+" x..xxxx......x ",
+" x............x ",
+" x.......xxxx.x ",
+" x.......x..x.x ",
+" x.......x..x.x ",
+" x.......xxxx.x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+static const char * const _maximize_button[] = {
+"16 16 4 1",
+" c none",
+". c #dfdfff",
+"o c #7f7f7f",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" x............x ",
+" x.......xxxx.x ",
+" x........xxx.x ",
+" x........xxx.x ",
+" x.......x..x.x ",
+" x......x.....x ",
+" x.....x......x ",
+" x.oooo.......x ",
+" x.o..o.......x ",
+" x.o..o.......x ",
+" x.oooo.......x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+static const char * const _help_button[] = {
+"16 16 3 1",
+" c none",
+". c #afffdf",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" x............x ",
+" x....xxxx....x ",
+" x..xx....xx..x ",
+" x.xx......xx.x ",
+" x.xx......xx.x ",
+" x........xx..x ",
+" x......xx....x ",
+" x.....xx.....x ",
+" x.....xx.....x ",
+" x............x ",
+" x.....xx.....x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+//! [constructor start]
+MyDecoration::MyDecoration()
+ : QDecorationDefault()
+{
+ border = 4;
+ titleHeight = 24;
+ buttonWidth = 20;
+ buttonHeight = 20;
+ buttonMargin = 2;
+ buttonHints << Qt::Window
+ << Qt::WindowMaximizeButtonHint
+ << Qt::WindowContextHelpButtonHint;
+ //! [constructor start]
+
+ //! [map window flags to decoration regions]
+ buttonHintMap[Qt::Window] = Close;
+ buttonHintMap[Qt::WindowMaximizeButtonHint] = Maximize;
+ buttonHintMap[Qt::WindowContextHelpButtonHint] = Help;
+ //! [map window flags to decoration regions]
+
+ //! [map decoration regions to pixmaps]
+ normalButtonPixmaps[Close] = QPixmap(_close_button);
+ normalButtonPixmaps[Maximize] = QPixmap(_maximize_button);
+ normalButtonPixmaps[Normalize] = QPixmap(_normalize_button);
+ normalButtonPixmaps[Help] = QPixmap(_help_button);
+
+ maximizedButtonPixmaps[Close] = QPixmap(_close_button);
+ maximizedButtonPixmaps[Maximize] = QPixmap(_normalize_button);
+ maximizedButtonPixmaps[Normalize] = QPixmap(_normalize_button);
+ maximizedButtonPixmaps[Help] = QPixmap(_help_button);
+ //! [map decoration regions to pixmaps]
+
+ //! [constructor end]
+ stateRegions << Close << Maximize << Help;
+}
+//! [constructor end]
+
+//! [region start]
+QRegion MyDecoration::region(const QWidget *widget, const QRect &insideRect,
+ int decorationRegion)
+{
+ //! [region start]
+ //! [calculate the positions of buttons based on the window flags used]
+ QHash<DecorationRegion, int> buttons;
+ Qt::WindowFlags flags = widget->windowFlags();
+ int dx = -buttonMargin - buttonWidth;
+
+ foreach (Qt::WindowType button, buttonHints) {
+ if (flags & button) {
+ int x = (buttons.size() + 1) * dx;
+ buttons[buttonHintMap[button]] = x;
+ }
+ }
+ //! [calculate the positions of buttons based on the window flags used]
+
+ //! [calculate the extent of the title]
+ int titleRightMargin = buttons.size() * dx;
+
+ QRect outsideRect(insideRect.left() - border,
+ insideRect.top() - titleHeight - border,
+ insideRect.width() + 2 * border,
+ insideRect.height() + titleHeight + 2 * border);
+ //! [calculate the extent of the title]
+
+ //! [check for all regions]
+ QRegion region;
+
+ if (decorationRegion == All) {
+ region += QRegion(outsideRect) - QRegion(insideRect);
+ return region;
+ }
+ //! [check for all regions]
+
+ //! [compose a region based on the decorations specified]
+ if (decorationRegion & Title) {
+ QRect rect = outsideRect.adjusted(border, border, -border, 0);
+ rect.setHeight(titleHeight);
+
+ // Adjust the width to accommodate buttons.
+ rect.setWidth(qMax(0, rect.width() + titleRightMargin));
+ region += rect;
+ }
+ if (decorationRegion & Top) {
+ QRect rect = outsideRect.adjusted(border, 0, -border, 0);
+ rect.setHeight(border);
+ region += rect;
+ }
+ if (decorationRegion & Left) {
+ QRect rect = outsideRect.adjusted(0, border, 0, -border);
+ rect.setWidth(border);
+ region += rect;
+ }
+ if (decorationRegion & Right) {
+ QRect rect = outsideRect.adjusted(0, border, 0, -border);
+ rect.setLeft(rect.right() + 1 - border);
+ region += rect;
+ }
+ if (decorationRegion & Bottom) {
+ QRect rect = outsideRect.adjusted(border, 0, -border, 0);
+ rect.setTop(rect.bottom() + 1 - border);
+ region += rect;
+ }
+ if (decorationRegion & TopLeft) {
+ QRect rect = outsideRect;
+ rect.setWidth(border);
+ rect.setHeight(border);
+ region += rect;
+ }
+ if (decorationRegion & TopRight) {
+ QRect rect = outsideRect;
+ rect.setLeft(rect.right() + 1 - border);
+ rect.setHeight(border);
+ region += rect;
+ }
+ if (decorationRegion & BottomLeft) {
+ QRect rect = outsideRect;
+ rect.setWidth(border);
+ rect.setTop(rect.bottom() + 1 - border);
+ region += rect;
+ }
+ if (decorationRegion & BottomRight) {
+ QRect rect = outsideRect;
+ rect.setLeft(rect.right() + 1 - border);
+ rect.setTop(rect.bottom() + 1 - border);
+ region += rect;
+ }
+ //! [compose a region based on the decorations specified]
+
+ //! [add a region for each button only if it is present]
+ foreach (QDecoration::DecorationRegion testRegion, stateRegions) {
+ if (decorationRegion & testRegion and buttons.contains(testRegion)) {
+ // Inside the title rectangle
+ QRect rect = outsideRect.adjusted(border, border, -border, 0);
+ rect.setHeight(titleHeight);
+
+ dx = buttons[testRegion];
+ rect.setLeft(rect.right() + 1 + dx);
+ rect.setWidth(buttonWidth + buttonMargin);
+ region += rect;
+ }
+ }
+ //! [add a region for each button only if it is present]
+
+ //! [region end]
+ return region;
+}
+//! [region end]
+
+//! [paint start]
+bool MyDecoration::paint(QPainter *painter, const QWidget *widget,
+ int decorationRegion, DecorationState state)
+{
+ if (decorationRegion == None)
+ return false;
+ //! [paint start]
+
+ //! [paint different regions]
+ bool handled = false;
+
+ QPalette palette = QApplication::palette();
+ QHash<DecorationRegion, QPixmap> buttonPixmaps;
+
+ if (widget->windowState() == Qt::WindowMaximized)
+ buttonPixmaps = maximizedButtonPixmaps;
+ else
+ buttonPixmaps = normalButtonPixmaps;
+
+ if (decorationRegion & Title) {
+ QRect rect = QDecoration::region(widget, Title).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Base));
+ painter->save();
+ painter->setPen(QPen(palette.color(QPalette::Text)));
+ painter->drawText(rect, Qt::AlignCenter, widget->windowTitle());
+ painter->restore();
+ handled = true;
+ }
+ if (decorationRegion & Top) {
+ QRect rect = QDecoration::region(widget, Top).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & Left) {
+ QRect rect = QDecoration::region(widget, Left).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & Right) {
+ QRect rect = QDecoration::region(widget, Right).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & Bottom) {
+ QRect rect = QDecoration::region(widget, Bottom).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & TopLeft) {
+ QRect rect = QDecoration::region(widget, TopLeft).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & TopRight) {
+ QRect rect = QDecoration::region(widget, TopRight).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & BottomLeft) {
+ QRect rect = QDecoration::region(widget, BottomLeft).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & BottomRight) {
+ QRect rect = QDecoration::region(widget, BottomRight).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ //! [paint different regions]
+
+ //! [paint buttons]
+ int margin = (titleHeight - 16) / 2;
+ Qt::WindowFlags flags = widget->windowFlags();
+
+ foreach (DecorationRegion testRegion, stateRegions) {
+ if (decorationRegion & testRegion && flags & buttonHintMap.key(testRegion)) {
+ QRect rect = QDecoration::region(
+ widget, testRegion).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Base));
+
+ QRect buttonRect = rect.adjusted(0, margin, -buttonMargin - margin,
+ -buttonMargin);
+ painter->drawPixmap(buttonRect.topLeft(), buttonPixmaps[testRegion]);
+ handled = true;
+ }
+ }
+ //! [paint buttons]
+
+ //! [paint end]
+ return handled;
+}
+//! [paint end]
diff --git a/examples/qws/simpledecoration/mydecoration.h b/examples/qws/simpledecoration/mydecoration.h
new file mode 100644
index 0000000000..6d8aebf6b2
--- /dev/null
+++ b/examples/qws/simpledecoration/mydecoration.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYDECORATION_H
+#define MYDECORATION_H
+
+#include <QDecorationDefault>
+#include <QHash>
+#include <QPixmap>
+#include <QRegion>
+#include <Qt>
+
+//! [decoration class definition]
+class MyDecoration : public QDecorationDefault
+{
+public:
+ MyDecoration();
+ QRegion region(const QWidget *widget, const QRect &insideRect, int decorationRegion);
+ bool paint(QPainter *painter, const QWidget *widget, int decorationRegion, DecorationState state);
+
+private:
+ int border;
+ int buttonHeight;
+ int buttonMargin;
+ int buttonWidth;
+ int titleHeight;
+ QHash<Qt::WindowType, DecorationRegion> buttonHintMap;
+ QHash<DecorationRegion, QPixmap> normalButtonPixmaps;
+ QHash<DecorationRegion, QPixmap> maximizedButtonPixmaps;
+ QVector<Qt::WindowType> buttonHints;
+ QVector<DecorationRegion> stateRegions;
+};
+//! [decoration class definition]
+
+#endif
diff --git a/examples/qws/simpledecoration/simpledecoration.pro b/examples/qws/simpledecoration/simpledecoration.pro
new file mode 100644
index 0000000000..2a4e0be51c
--- /dev/null
+++ b/examples/qws/simpledecoration/simpledecoration.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+HEADERS = analogclock.h \
+ mydecoration.h
+SOURCES = analogclock.cpp \
+ main.cpp \
+ mydecoration.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/simpledecoration
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/simpledecoration
+INSTALLS += target sources
diff --git a/examples/qws/svgalib/README b/examples/qws/svgalib/README
new file mode 100644
index 0000000000..227c066f01
--- /dev/null
+++ b/examples/qws/svgalib/README
@@ -0,0 +1,9 @@
+This is the SVGA screen driver plugin example for QWS.
+
+You may need to set the SVGALIB_DEFAULT_MODE environment
+variable. These values have been confirmed to work on one specific
+machine using svgalib 1.4.3: 18, 24, 34, 35, 36
+
+There is a bug in the example causing missing updates in 8-bit mode
+(e.g. modes 10 and 12). Fixing this bug is left as an exercise for the
+reader.
diff --git a/examples/qws/svgalib/svgalib.pro b/examples/qws/svgalib/svgalib.pro
new file mode 100644
index 0000000000..8a47c1d1d0
--- /dev/null
+++ b/examples/qws/svgalib/svgalib.pro
@@ -0,0 +1,19 @@
+TEMPLATE = lib
+CONFIG += plugin
+
+LIBS += -lvgagl -lvga
+
+TARGET = svgalibscreen
+target.path = $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+HEADERS = svgalibscreen.h \
+ svgalibpaintengine.h \
+ svgalibsurface.h \
+ svgalibpaintdevice.h
+SOURCES = svgalibscreen.cpp \
+ svgalibpaintengine.cpp \
+ svgalibsurface.cpp \
+ svgalibpaintdevice.cpp \
+ svgalibplugin.cpp
+
diff --git a/examples/qws/svgalib/svgalibpaintdevice.cpp b/examples/qws/svgalib/svgalibpaintdevice.cpp
new file mode 100644
index 0000000000..5b1ecb0717
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintdevice.h"
+#include "svgalibpaintengine.h"
+
+#include <QApplication>
+#include <QDesktopWidget>
+
+SvgalibPaintDevice::SvgalibPaintDevice(QWidget *w)
+ : QCustomRasterPaintDevice(w)
+{
+ pengine = new SvgalibPaintEngine(this);
+}
+
+SvgalibPaintDevice::~SvgalibPaintDevice()
+{
+ delete pengine;
+}
+
+int SvgalibPaintDevice::metric(PaintDeviceMetric m) const
+{
+ if (m == PdmWidth)
+ return QApplication::desktop()->screenGeometry().width();
+ else if (m == PdmHeight)
+ return QApplication::desktop()->screenGeometry().height();
+ return QCustomRasterPaintDevice::metric(m);
+}
+
diff --git a/examples/qws/svgalib/svgalibpaintdevice.h b/examples/qws/svgalib/svgalibpaintdevice.h
new file mode 100644
index 0000000000..0b70b86df9
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBPAINTDEVICE_H
+#define SVGALIBPAINTDEVICE_H
+
+#include "svgalibpaintengine.h"
+#include <private/qpaintengine_raster_p.h>
+#include <qscreen_qws.h>
+
+//! [0]
+class SvgalibPaintDevice : public QCustomRasterPaintDevice
+{
+public:
+ SvgalibPaintDevice(QWidget *w);
+ ~SvgalibPaintDevice();
+
+ void* memory() const { return QScreen::instance()->base(); }
+
+ QPaintEngine *paintEngine() const { return pengine; }
+ int metric(PaintDeviceMetric m) const;
+
+private:
+ SvgalibPaintEngine *pengine;
+};
+//! [0]
+
+#endif // SVGALIBPAINTDEVICE_H
diff --git a/examples/qws/svgalib/svgalibpaintengine.cpp b/examples/qws/svgalib/svgalibpaintengine.cpp
new file mode 100644
index 0000000000..f6774d0683
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintengine.h"
+
+#include <QColor>
+#include <vga.h>
+#include <vgagl.h>
+
+SvgalibPaintEngine::SvgalibPaintEngine(QPaintDevice *device)
+ : QRasterPaintEngine(device)
+{
+}
+
+SvgalibPaintEngine::~SvgalibPaintEngine()
+{
+}
+
+//! [0]
+bool SvgalibPaintEngine::begin(QPaintDevice *dev)
+{
+ device = dev;
+ pen = Qt::NoPen;
+ simplePen = true;
+ brush = Qt::NoBrush;
+ simpleBrush = true;
+ matrix = QTransform();
+ simpleMatrix = true;
+ setClip(QRect(0, 0, device->width(), device->height()));
+ opaque = true;
+ aliased = true;
+ sourceOver = true;
+
+ return QRasterPaintEngine::begin(dev);
+}
+//! [0]
+
+//! [1]
+bool SvgalibPaintEngine::end()
+{
+ gl_setclippingwindow(0, 0, device->width() - 1, device->height() - 1);
+ return QRasterPaintEngine::end();
+}
+//! [1]
+
+//! [2]
+void SvgalibPaintEngine::updateState()
+{
+ QRasterPaintEngineState *s = state();
+
+ if (s->dirty & DirtyTransform) {
+ matrix = s->matrix;
+ simpleMatrix = (matrix.m12() == 0 && matrix.m21() == 0);
+ }
+
+ if (s->dirty & DirtyPen) {
+ pen = s->pen;
+ simplePen = (pen.width() == 0 || pen.widthF() <= 1)
+ && (pen.style() == Qt::NoPen || pen.style() == Qt::SolidLine)
+ && (pen.color().alpha() == 255);
+ }
+
+ if (s->dirty & DirtyBrush) {
+ brush = s->brush;
+ simpleBrush = (brush.style() == Qt::SolidPattern
+ || brush.style() == Qt::NoBrush)
+ && (brush.color().alpha() == 255);
+ }
+
+ if (s->dirty & DirtyClipRegion)
+ setClip(s->clipRegion);
+
+ if (s->dirty & DirtyClipEnabled) {
+ clipEnabled = s->isClipEnabled();
+ updateClip();
+ }
+
+ if (s->dirty & DirtyClipPath) {
+ setClip(QRegion());
+ simpleClip = false;
+ }
+
+ if (s->dirty & DirtyCompositionMode) {
+ const QPainter::CompositionMode m = s->composition_mode;
+ sourceOver = (m == QPainter::CompositionMode_SourceOver);
+ }
+
+ if (s->dirty & DirtyOpacity)
+ opaque = (s->opacity == 256);
+
+ if (s->dirty & DirtyHints)
+ aliased = !(s->flags.antialiased);
+}
+//! [2]
+
+//! [3]
+void SvgalibPaintEngine::setClip(const QRegion &region)
+{
+ if (region.isEmpty())
+ clip = QRect(0, 0, device->width(), device->height());
+ else
+ clip = matrix.map(region) & QRect(0, 0, device->width(), device->height());
+ clipEnabled = true;
+ updateClip();
+}
+//! [3]
+
+//! [4]
+void SvgalibPaintEngine::updateClip()
+{
+ QRegion clipRegion = QRect(0, 0, device->width(), device->height());
+
+ if (!systemClip().isEmpty())
+ clipRegion &= systemClip();
+ if (clipEnabled)
+ clipRegion &= clip;
+
+ simpleClip = (clipRegion.rects().size() <= 1);
+
+ const QRect r = clipRegion.boundingRect();
+ gl_setclippingwindow(r.left(), r.top(),
+ r.x() + r.width(),
+ r.y() + r.height());
+}
+//! [4]
+
+//! [5]
+void SvgalibPaintEngine::drawRects(const QRect *rects, int rectCount)
+{
+ const bool canAccelerate = simplePen && simpleBrush && simpleMatrix
+ && simpleClip && opaque && aliased
+ && sourceOver;
+ if (!canAccelerate) {
+ QRasterPaintEngine::drawRects(rects, rectCount);
+ return;
+ }
+
+ for (int i = 0; i < rectCount; ++i) {
+ const QRect r = matrix.mapRect(rects[i]);
+ if (brush != Qt::NoBrush) {
+ gl_fillbox(r.left(), r.top(), r.width(), r.height(),
+ brush.color().rgba());
+ }
+ if (pen != Qt::NoPen) {
+ const int c = pen.color().rgba();
+ gl_hline(r.left(), r.top(), r.right(), c);
+ gl_hline(r.left(), r.bottom(), r.right(), c);
+ gl_line(r.left(), r.top(), r.left(), r.bottom(), c);
+ gl_line(r.right(), r.top(), r.right(), r.bottom(), c);
+ }
+ }
+}
+//! [5]
diff --git a/examples/qws/svgalib/svgalibpaintengine.h b/examples/qws/svgalib/svgalibpaintengine.h
new file mode 100644
index 0000000000..d3d85ba7a8
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBPAINTENGINE_H
+#define SVGALIBPAINTENGINE_H
+
+//! [0]
+#include <private/qpaintengine_raster_p.h>
+
+class SvgalibPaintEngine : public QRasterPaintEngine
+{
+public:
+ SvgalibPaintEngine(QPaintDevice *device);
+ ~SvgalibPaintEngine();
+
+ bool begin(QPaintDevice *device);
+ bool end();
+ void updateState();
+ void drawRects(const QRect *rects, int rectCount);
+
+private:
+ void setClip(const QRegion &region);
+ void updateClip();
+
+ QPen pen;
+ bool simplePen;
+ QBrush brush;
+ bool simpleBrush;
+ QTransform matrix;
+ bool simpleMatrix;
+ QRegion clip;
+ bool clipEnabled;
+ bool simpleClip;
+ bool opaque;
+ bool aliased;
+ bool sourceOver;
+ QPaintDevice *device;
+};
+//! [0]
+
+#endif // SVGALIBPAINTENGINE_H
diff --git a/examples/qws/svgalib/svgalibplugin.cpp b/examples/qws/svgalib/svgalibplugin.cpp
new file mode 100644
index 0000000000..9be629e63b
--- /dev/null
+++ b/examples/qws/svgalib/svgalibplugin.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibscreen.h"
+
+#include <QScreenDriverPlugin>
+#include <QStringList>
+
+class SvgalibPlugin : public QScreenDriverPlugin
+{
+public:
+ SvgalibPlugin();
+
+ QStringList keys() const;
+ QScreen *create(const QString&, int displayId);
+};
+
+SvgalibPlugin::SvgalibPlugin()
+ : QScreenDriverPlugin()
+{
+}
+
+QStringList SvgalibPlugin::keys() const
+{
+ return (QStringList() << "svgalib");
+}
+
+QScreen* SvgalibPlugin::create(const QString& driver, int displayId)
+{
+ if (driver.toLower() != "svgalib")
+ return 0;
+
+ return new SvgalibScreen(displayId);
+}
+
+Q_EXPORT_STATIC_PLUGIN(Svgalib)
+Q_EXPORT_PLUGIN2(svgalibscreendriver, SvgalibPlugin)
diff --git a/examples/qws/svgalib/svgalibscreen.cpp b/examples/qws/svgalib/svgalibscreen.cpp
new file mode 100644
index 0000000000..163259178c
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.cpp
@@ -0,0 +1,353 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibscreen.h"
+#include "svgalibsurface.h"
+
+#include <QVector>
+#include <QApplication>
+#include <QColor>
+#include <QWidget>
+
+#include <math.h>
+
+static int getModeDepth(vga_modeinfo *mode)
+{
+ const int bits = int(log2(mode->colors));
+ if (bits == 24 && mode->bytesperpixel == 4)
+ return 32;
+ return bits;
+}
+
+//! [0]
+bool SvgalibScreen::connect(const QString &displaySpec)
+{
+ int mode = vga_getdefaultmode();
+ if (mode <= 0) {
+ qCritical("SvgalibScreen::connect(): invalid vga mode");
+ return false;
+ }
+
+ vga_modeinfo *modeinfo = vga_getmodeinfo(mode);
+
+ QScreen::lstep = modeinfo->linewidth;
+ QScreen::dw = QScreen::w = modeinfo->width;
+ QScreen::dh = QScreen::h = modeinfo->height;
+ QScreen::d = getModeDepth(modeinfo);
+ QScreen::size = QScreen::lstep * dh;
+ QScreen::data = 0;
+
+ switch (depth()) {
+ case 32:
+ setPixelFormat(QImage::Format_ARGB32_Premultiplied);
+ break;
+ case 24:
+ setPixelFormat(QImage::Format_RGB888);
+ break;
+ case 16:
+ setPixelFormat(QImage::Format_RGB16);
+ break;
+ case 15:
+ setPixelFormat(QImage::Format_RGB555);
+ break;
+ default:
+ break;
+ }
+
+ const int dpi = 72;
+ QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
+ QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);
+
+ const QStringList args = displaySpec.split(QLatin1Char(':'),
+ QString::SkipEmptyParts);
+ grayscale = args.contains(QLatin1String("grayscale"), Qt::CaseInsensitive);
+
+ return true;
+}
+//! [0]
+
+void SvgalibScreen::initColorMap()
+{
+ const int numColors = vga_getcolors();
+ if (numColors == 2 || numColors > 256) {
+ screencols = 0;
+ return; // not a palette based mode
+ }
+
+ if (numColors == 16) {
+ if (grayscale) {
+ for (int i = 0; i < 256; ++i) {
+ const int c = i * 16 / 256;
+ vga_setpalette(i, c, c, c);
+ }
+ screencols = 256; // XXX: takes advantage of optimization in alloc()
+ } else { // read in EGA palette
+ int r, g, b;
+ for (int i = 0; i < 16; ++i) {
+ vga_getpalette(i, &r, &g, &b);
+ screenclut[i] = qRgb(r, g, b);
+ }
+ screencols = 16;
+ }
+
+ return;
+ }
+
+ Q_ASSERT(numColors == 256);
+
+ if (grayscale) {
+ for (int i = 0; i < 256; ++i) {
+ const int c = i * 64 / 256;
+ vga_setpalette(i, c, c, c);
+ }
+ } else {
+ int i = 0;
+
+#if 0
+ // read in EGA palette
+ while (i < 16) {
+ int r, g, b;
+ vga_getpalette(i, &r, &g, &b);
+ screenclut[i] = qRgb(r, g, b);
+ ++i;
+ }
+ screencols = 16;
+#endif
+
+ // 6 * 6 * 6 color cube
+ for (int r = 0; r < 6; ++r) {
+ for (int g = 0; g < 6; ++g) {
+ for (int b = 0; b < 6; ++b) {
+ vga_setpalette(i, r * 64/6, g * 64/6, b * 64/6);
+ screenclut[i] = qRgb(r * 256/6, g * 256/6, b * 256/6);
+ ++i;
+ }
+ }
+ }
+ screencols = i;
+
+ while (i < 256) {
+ screenclut[i] = qRgb(0, 0, 0);
+ ++i;
+ }
+ }
+}
+
+//! [1]
+bool SvgalibScreen::initDevice()
+{
+ if (vga_init() != 0) {
+ qCritical("SvgalibScreen::initDevice(): unable to initialize svgalib");
+ return false;
+ }
+
+ int mode = vga_getdefaultmode();
+ if (vga_setmode(mode) == -1) {
+ qCritical("SvgalibScreen::initialize(): unable to set graphics mode");
+ return false;
+ }
+
+ if (gl_setcontextvga(mode) != 0) {
+ qCritical("SvgalibScreen::initDevice(): unable to set vga context");
+ return false;
+ }
+ context = gl_allocatecontext();
+ gl_getcontext(context);
+
+ vga_modeinfo *modeinfo = vga_getmodeinfo(mode);
+ if (modeinfo->flags & IS_LINEAR)
+ QScreen::data = vga_getgraphmem();
+
+ initColorMap();
+
+ QScreenCursor::initSoftwareCursor();
+ return true;
+}
+//! [1]
+
+//! [2]
+void SvgalibScreen::shutdownDevice()
+{
+ gl_freecontext(context);
+ vga_setmode(TEXT);
+}
+//! [2]
+
+//! [3]
+void SvgalibScreen::disconnect()
+{
+}
+//! [3]
+
+//! [4]
+void SvgalibScreen::solidFill(const QColor &color, const QRegion &reg)
+{
+ int c;
+ if (depth() == 4 || depth() == 8)
+ c = alloc(color.red(), color.green(), color.blue());
+ else
+ c = gl_rgbcolor(color.red(), color.green(), color.blue());
+
+ const QVector<QRect> rects = (reg & region()).rects();
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_fillbox(r.left(), r.top(), r.width(), r.height(), c);
+ }
+}
+//! [4]
+
+void SvgalibScreen::blit16To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region)
+{
+ const int imageStride = image.bytesPerLine() / 2;
+ const QVector<QRect> rects = region.rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i).translated(-topLeft);
+ int y = r.y();
+ const quint16 *s = reinterpret_cast<const quint16*>(image.scanLine(y));
+
+ while (y <= r.bottom()) {
+ int x1 = r.x();
+ while (x1 <= r.right()) {
+ const quint16 c = s[x1];
+ int x2 = x1;
+ // find span length
+ while ((x2+1 < r.right()) && (s[x2+1] == c))
+ ++x2;
+ gl_hline(x1 + topLeft.x(), y + topLeft.y(), x2 + topLeft.x(),
+ qt_colorConvert<quint8, quint16>(c, 0));
+ x1 = x2 + 1;
+ }
+ s += imageStride;
+ ++y;
+ }
+ }
+}
+
+void SvgalibScreen::blit32To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region)
+{
+ const int imageStride = image.bytesPerLine() / 4;
+ const QVector<QRect> rects = region.rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i).translated(-topLeft);
+ int y = r.y();
+ const quint32 *s = reinterpret_cast<const quint32*>(image.scanLine(y));
+
+ while (y <= r.bottom()) {
+ int x1 = r.x();
+ while (x1 <= r.right()) {
+ const quint32 c = s[x1];
+ int x2 = x1;
+ // find span length
+ while ((x2+1 < r.right()) && (s[x2+1] == c))
+ ++x2;
+ gl_hline(x1 + topLeft.x(), y + topLeft.y(), x2 + topLeft.x(),
+ qt_colorConvert<quint8, quint32>(c, 0));
+ x1 = x2 + 1;
+ }
+ s += imageStride;
+ ++y;
+ }
+ }
+}
+
+//! [5]
+void SvgalibScreen::blit(const QImage &img, const QPoint &topLeft,
+ const QRegion &reg)
+{
+ if (depth() == 8) {
+ switch (img.format()) {
+ case QImage::Format_RGB16:
+ blit16To8(img, topLeft, reg);
+ return;
+ case QImage::Format_RGB32:
+ case QImage::Format_ARGB32:
+ case QImage::Format_ARGB32_Premultiplied:
+ blit32To8(img, topLeft, reg);
+ return;
+ default:
+ break;
+ }
+ }
+
+ if (img.format() != pixelFormat()) {
+ if (base())
+ QScreen::blit(img, topLeft, reg);
+ return;
+ }
+
+ const QVector<QRect> rects = (reg & region()).rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_putboxpart(r.x(), r.y(), r.width(), r.height(),
+ img.width(), img.height(),
+ static_cast<void*>(const_cast<uchar*>(img.bits())),
+ r.x() - topLeft.x(), r.y() - topLeft.y());
+ }
+}
+//! [5]
+
+//! [7]
+QWSWindowSurface* SvgalibScreen::createSurface(QWidget *widget) const
+{
+ if (base()) {
+ static int onScreenPaint = -1;
+ if (onScreenPaint == -1)
+ onScreenPaint = qgetenv("QT_ONSCREEN_PAINT").toInt();
+
+ if (onScreenPaint > 0 || widget->testAttribute(Qt::WA_PaintOnScreen))
+ return new SvgalibSurface(widget);
+ }
+ return QScreen::createSurface(widget);
+}
+//! [7]
+
+//! [8]
+QWSWindowSurface* SvgalibScreen::createSurface(const QString &key) const
+{
+ if (key == QLatin1String("svgalib"))
+ return new SvgalibSurface;
+ return QScreen::createSurface(key);
+}
+//! [8]
diff --git a/examples/qws/svgalib/svgalibscreen.h b/examples/qws/svgalib/svgalibscreen.h
new file mode 100644
index 0000000000..da3b05e103
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBSCREEN_H
+#define SVGALIBSCREEN_H
+
+#include <QScreen>
+
+#include <vga.h>
+#include <vgagl.h>
+
+//! [0]
+class SvgalibScreen : public QScreen
+{
+public:
+ SvgalibScreen(int displayId) : QScreen(displayId) {}
+ ~SvgalibScreen() {}
+
+ bool connect(const QString &displaySpec);
+ bool initDevice();
+ void shutdownDevice();
+ void disconnect();
+
+ void setMode(int, int, int) {}
+ void blank(bool) {}
+
+ void blit(const QImage &img, const QPoint &topLeft, const QRegion &region);
+ void solidFill(const QColor &color, const QRegion &region);
+//! [0]
+
+ QWSWindowSurface* createSurface(QWidget *widget) const;
+ QWSWindowSurface* createSurface(const QString &key) const;
+
+//! [1]
+private:
+ void initColorMap();
+ void blit16To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region);
+ void blit32To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region);
+
+ GraphicsContext *context;
+};
+//! [1]
+
+#endif // SVGALIBSCREEN_H
diff --git a/examples/qws/svgalib/svgalibsurface.cpp b/examples/qws/svgalib/svgalibsurface.cpp
new file mode 100644
index 0000000000..ad270a1783
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibsurface.h"
+#include "svgalibpaintdevice.h"
+
+#include <vgagl.h>
+
+SvgalibSurface::SvgalibSurface() : QWSWindowSurface(), pdevice(0)
+{
+ setSurfaceFlags(Opaque);
+}
+
+SvgalibSurface::SvgalibSurface(QWidget *w)
+ : QWSWindowSurface(w)
+{
+ setSurfaceFlags(Opaque);
+ pdevice = new SvgalibPaintDevice(w);
+}
+
+SvgalibSurface::~SvgalibSurface()
+{
+ delete pdevice;
+}
+
+void SvgalibSurface::setGeometry(const QRect &rect)
+{
+ QWSWindowSurface::setGeometry(rect);
+}
+
+QPoint SvgalibSurface::painterOffset() const
+{
+ return geometry().topLeft() + QWSWindowSurface::painterOffset();
+}
+
+//! [0]
+bool SvgalibSurface::scroll(const QRegion &region, int dx, int dy)
+{
+ const QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_copybox(r.left(), r.top(), r.width(), r.height(),
+ r.left() + dx, r.top() + dy);
+ }
+
+ return true;
+}
+//! [0]
+
diff --git a/examples/qws/svgalib/svgalibsurface.h b/examples/qws/svgalib/svgalibsurface.h
new file mode 100644
index 0000000000..5c25e72521
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBSURFACE_H
+#define SVGALIBSURFACE_H
+
+#include "svgalibpaintengine.h"
+#include "svgalibpaintdevice.h"
+#include <private/qwindowsurface_qws_p.h>
+
+class SvgalibPaintDevice;
+
+//! [0]
+class SvgalibSurface : public QWSWindowSurface
+{
+public:
+ SvgalibSurface();
+ SvgalibSurface(QWidget *w);
+ ~SvgalibSurface();
+
+ void setGeometry(const QRect &rect);
+ bool isValid() const { return true; }
+ bool scroll(const QRegion &region, int dx, int dy);
+ QString key() const { return QLatin1String("svgalib"); }
+
+ bool attach(const QByteArray &) { return true; }
+ void detach() {}
+
+ QImage image() const { return QImage(); }
+ QPaintDevice *paintDevice() { return pdevice; }
+ QPoint painterOffset() const;
+
+private:
+ SvgalibPaintDevice *pdevice;
+};
+//! [0]
+
+#endif // SVGALIBSURFACE_H