1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24** * Redistributions of source code must retain the above copyright
25** notice, this list of conditions and the following disclaimer.
26** * Redistributions in binary form must reproduce the above copyright
27** notice, this list of conditions and the following disclaimer in
28** the documentation and/or other materials provided with the
29** distribution.
30** * Neither the name of The Qt Company Ltd nor the names of its
31** contributors may be used to endorse or promote products derived
32** from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
50
51#include <QApplication>
52#include <QPainter>
53#include <QTime>
54#include "block.h"
55#include "window.h"
56
57QImage createImage(int width, int height)
58{
59 QImage image(width, height, QImage::Format_RGB16);
60 QPainter painter;
61 QPen pen;
62 pen.setStyle(Qt::NoPen);
63 QBrush brush(Qt::blue);
64
65 painter.begin(&image);
66 painter.fillRect(image.rect(), brush);
67 brush.setColor(Qt::white);
68 painter.setPen(pen);
69 painter.setBrush(brush);
70
71 static const QPointF points1[3] = {
72 QPointF(4, 4),
73 QPointF(7, 4),
74 QPointF(5.5, 1)
75 };
76
77 static const QPointF points2[3] = {
78 QPointF(1, 4),
79 QPointF(7, 4),
80 QPointF(10, 10)
81 };
82
83 static const QPointF points3[3] = {
84 QPointF(4, 4),
85 QPointF(10, 4),
86 QPointF(1, 10)
87 };
88
89 painter.setWindow(x: 0, y: 0, w: 10, h: 10);
90
91 int x = 0;
92 int y = 0;
93 int starWidth = image.width()/3;
94 int starHeight = image.height()/3;
95
96 QRect rect(x, y, starWidth, starHeight);
97
98 for (int i = 0; i < 9; ++i) {
99
100 painter.setViewport(rect);
101 painter.drawPolygon(points: points1, pointCount: 3);
102 painter.drawPolygon(points: points2, pointCount: 3);
103 painter.drawPolygon(points: points3, pointCount: 3);
104
105 if (i % 3 == 2) {
106 y = y + starHeight;
107 rect.moveTop(pos: y);
108
109 x = 0;
110 rect.moveLeft(pos: x);
111
112 } else {
113 x = x + starWidth;
114 rect.moveLeft(pos: x);
115 }
116 }
117
118 painter.end();
119 return image;
120}
121
122//! [main function] //! [main start]
123int main(int argc, char *argv[])
124{
125 QApplication app(argc, argv);
126//! [main start] //! [register meta-type for queued communications]
127 qRegisterMetaType<Block>();
128//! [register meta-type for queued communications]
129
130 Window window;
131 window.show();
132
133 window.loadImage(image: createImage(width: 256, height: 256));
134//! [main finish]
135 return app.exec();
136}
137//! [main finish] //! [main function]
138

source code of qtbase/examples/corelib/threads/queuedcustomtype/main.cpp