source: trunk/demos/pathstroke/pathstroke.cpp@ 493

Last change on this file since 493 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 19.9 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 "pathstroke.h"
43#include "arthurstyle.h"
44#include "arthurwidgets.h"
45
46#include <stdio.h>
47
48extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius);
49
50
51PathStrokeControls::PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen)
52 : QWidget(parent)
53{
54 m_renderer = renderer;
55
56 if (smallScreen)
57 layoutForSmallScreens();
58 else
59 layoutForDesktop();
60}
61
62void PathStrokeControls::createCommonControls(QWidget* parent)
63{
64 m_capGroup = new QGroupBox(parent);
65 m_capGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
66 QRadioButton *flatCap = new QRadioButton(m_capGroup);
67 QRadioButton *squareCap = new QRadioButton(m_capGroup);
68 QRadioButton *roundCap = new QRadioButton(m_capGroup);
69 m_capGroup->setTitle(tr("Cap Style"));
70 flatCap->setText(tr("Flat"));
71 squareCap->setText(tr("Square"));
72 roundCap->setText(tr("Round"));
73 flatCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
74 squareCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
75 roundCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
76
77 m_joinGroup = new QGroupBox(parent);
78 m_joinGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
79 QRadioButton *bevelJoin = new QRadioButton(m_joinGroup);
80 QRadioButton *miterJoin = new QRadioButton(m_joinGroup);
81 QRadioButton *roundJoin = new QRadioButton(m_joinGroup);
82 m_joinGroup->setTitle(tr("Join Style"));
83 bevelJoin->setText(tr("Bevel"));
84 miterJoin->setText(tr("Miter"));
85 roundJoin->setText(tr("Round"));
86
87 m_styleGroup = new QGroupBox(parent);
88 m_styleGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
89 QRadioButton *solidLine = new QRadioButton(m_styleGroup);
90 QRadioButton *dashLine = new QRadioButton(m_styleGroup);
91 QRadioButton *dotLine = new QRadioButton(m_styleGroup);
92 QRadioButton *dashDotLine = new QRadioButton(m_styleGroup);
93 QRadioButton *dashDotDotLine = new QRadioButton(m_styleGroup);
94 QRadioButton *customDashLine = new QRadioButton(m_styleGroup);
95 m_styleGroup->setTitle(tr("Pen Style"));
96
97 QPixmap line_solid(":res/images/line_solid.png");
98 solidLine->setIcon(line_solid);
99 solidLine->setIconSize(line_solid.size());
100 QPixmap line_dashed(":res/images/line_dashed.png");
101 dashLine->setIcon(line_dashed);
102 dashLine->setIconSize(line_dashed.size());
103 QPixmap line_dotted(":res/images/line_dotted.png");
104 dotLine->setIcon(line_dotted);
105 dotLine->setIconSize(line_dotted.size());
106 QPixmap line_dash_dot(":res/images/line_dash_dot.png");
107 dashDotLine->setIcon(line_dash_dot);
108 dashDotLine->setIconSize(line_dash_dot.size());
109 QPixmap line_dash_dot_dot(":res/images/line_dash_dot_dot.png");
110 dashDotDotLine->setIcon(line_dash_dot_dot);
111 dashDotDotLine->setIconSize(line_dash_dot_dot.size());
112 customDashLine->setText(tr("Custom"));
113
114 int fixedHeight = bevelJoin->sizeHint().height();
115 solidLine->setFixedHeight(fixedHeight);
116 dashLine->setFixedHeight(fixedHeight);
117 dotLine->setFixedHeight(fixedHeight);
118 dashDotLine->setFixedHeight(fixedHeight);
119 dashDotDotLine->setFixedHeight(fixedHeight);
120
121 m_pathModeGroup = new QGroupBox(parent);
122 m_pathModeGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
123 QRadioButton *curveMode = new QRadioButton(m_pathModeGroup);
124 QRadioButton *lineMode = new QRadioButton(m_pathModeGroup);
125 m_pathModeGroup->setTitle(tr("Line Style"));
126 curveMode->setText(tr("Curves"));
127 lineMode->setText(tr("Lines"));
128
129
130 // Layouts
131 QVBoxLayout *capGroupLayout = new QVBoxLayout(m_capGroup);
132 capGroupLayout->addWidget(flatCap);
133 capGroupLayout->addWidget(squareCap);
134 capGroupLayout->addWidget(roundCap);
135
136 QVBoxLayout *joinGroupLayout = new QVBoxLayout(m_joinGroup);
137 joinGroupLayout->addWidget(bevelJoin);
138 joinGroupLayout->addWidget(miterJoin);
139 joinGroupLayout->addWidget(roundJoin);
140
141 QVBoxLayout *styleGroupLayout = new QVBoxLayout(m_styleGroup);
142 styleGroupLayout->addWidget(solidLine);
143 styleGroupLayout->addWidget(dashLine);
144 styleGroupLayout->addWidget(dotLine);
145 styleGroupLayout->addWidget(dashDotLine);
146 styleGroupLayout->addWidget(dashDotDotLine);
147 styleGroupLayout->addWidget(customDashLine);
148
149 QVBoxLayout *pathModeGroupLayout = new QVBoxLayout(m_pathModeGroup);
150 pathModeGroupLayout->addWidget(curveMode);
151 pathModeGroupLayout->addWidget(lineMode);
152
153
154 // Connections
155 connect(flatCap, SIGNAL(clicked()), m_renderer, SLOT(setFlatCap()));
156 connect(squareCap, SIGNAL(clicked()), m_renderer, SLOT(setSquareCap()));
157 connect(roundCap, SIGNAL(clicked()), m_renderer, SLOT(setRoundCap()));
158
159 connect(bevelJoin, SIGNAL(clicked()), m_renderer, SLOT(setBevelJoin()));
160 connect(miterJoin, SIGNAL(clicked()), m_renderer, SLOT(setMiterJoin()));
161 connect(roundJoin, SIGNAL(clicked()), m_renderer, SLOT(setRoundJoin()));
162
163 connect(curveMode, SIGNAL(clicked()), m_renderer, SLOT(setCurveMode()));
164 connect(lineMode, SIGNAL(clicked()), m_renderer, SLOT(setLineMode()));
165
166 connect(solidLine, SIGNAL(clicked()), m_renderer, SLOT(setSolidLine()));
167 connect(dashLine, SIGNAL(clicked()), m_renderer, SLOT(setDashLine()));
168 connect(dotLine, SIGNAL(clicked()), m_renderer, SLOT(setDotLine()));
169 connect(dashDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotLine()));
170 connect(dashDotDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotDotLine()));
171 connect(customDashLine, SIGNAL(clicked()), m_renderer, SLOT(setCustomDashLine()));
172
173 // Set the defaults:
174 flatCap->setChecked(true);
175 bevelJoin->setChecked(true);
176 curveMode->setChecked(true);
177 solidLine->setChecked(true);
178}
179
180
181void PathStrokeControls::layoutForDesktop()
182{
183 QGroupBox *mainGroup = new QGroupBox(this);
184 mainGroup->setFixedWidth(180);
185 mainGroup->setTitle(tr("Path Stroking"));
186
187 createCommonControls(mainGroup);
188
189 QGroupBox* penWidthGroup = new QGroupBox(mainGroup);
190 QSlider *penWidth = new QSlider(Qt::Horizontal, penWidthGroup);
191 penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
192 penWidthGroup->setTitle(tr("Pen Width"));
193 penWidth->setRange(0, 500);
194
195 QPushButton *animated = new QPushButton(mainGroup);
196 animated->setText(tr("Animate"));
197 animated->setCheckable(true);
198
199 QPushButton *showSourceButton = new QPushButton(mainGroup);
200 showSourceButton->setText(tr("Show Source"));
201#ifdef QT_OPENGL_SUPPORT