source: trunk/demos/shared/arthurwidgets.cpp@ 551

Last change on this file since 551 was 514, checked in by Dmitry A. Kuminov, 15 years ago

demos/shared: Don't depend on the private header on platforms that do not need it [vendor bug].

File size: 11.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the demonstration applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "arthurwidgets.h"
43#include <QApplication>
44#include <QPainter>
45#include <QPainterPath>
46#include <QPixmapCache>
47#include <QtEvents>
48#include <QTextDocument>
49#include <QAbstractTextDocumentLayout>
50#include <QFile>
51#include <QTextBrowser>
52#include <QBoxLayout>
53
54#ifdef Q_WS_X11
55#include <private/qpixmapdata_p.h>
56#endif
57
58extern QPixmap cached(const QString &img);
59
60ArthurFrame::ArthurFrame(QWidget *parent)
61 : QWidget(parent)
62 , m_prefer_image(false)
63{
64#ifdef QT_OPENGL_SUPPORT
65 glw = 0;
66 m_use_opengl = false;
67 QGLFormat f = QGLFormat::defaultFormat();
68 f.setSampleBuffers(true);
69 f.setStencil(true);
70 f.setAlpha(true);
71 f.setAlphaBufferSize(8);
72 QGLFormat::setDefaultFormat(f);
73#endif
74 m_document = 0;
75 m_show_doc = false;
76
77 m_tile = QPixmap(128, 128);
78 m_tile.fill(Qt::white);
79 QPainter pt(&m_tile);
80 QColor color(230, 230, 230);
81 pt.fillRect(0, 0, 64, 64, color);
82 pt.fillRect(64, 64, 64, 64, color);
83 pt.end();
84
85// QPalette pal = palette();
86// pal.setBrush(backgroundRole(), m_tile);
87// setPalette(pal);
88
89#ifdef Q_WS_X11
90 QPixmap xRenderPixmap(1, 1);
91 m_prefer_image = xRenderPixmap.pixmapData()->classId() == QPixmapData::X11Class && !xRenderPixmap.x11PictureHandle();
92#endif
93}
94
95
96#ifdef QT_OPENGL_SUPPORT
97void ArthurFrame::enableOpenGL(bool use_opengl)
98{
99 m_use_opengl = use_opengl;
100
101 if (!glw) {
102 glw = new GLWidget(this);
103 glw->setAutoFillBackground(false);
104 glw->disableAutoBufferSwap();
105 QApplication::postEvent(this, new QResizeEvent(size(), size()));
106 }
107
108 if (use_opengl) {
109 glw->show();
110 } else {
111 glw->hide();
112 }
113
114 update();
115}
116#endif
117
118void ArthurFrame::paintEvent(QPaintEvent *e)
119{
120#ifdef Q_WS_QWS
121 static QPixmap *static_image = 0;
122#else
123 static QImage *static_image = 0;
124#endif
125 QPainter painter;
126 if (preferImage()
127#ifdef QT_OPENGL_SUPPORT
128 && !m_use_opengl
129#endif
130 ) {