source: trunk/demos/pathstroke/pathstroke.h@ 5

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

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

File size: 5.1 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#ifndef PATHSTROKE_H
43#define PATHSTROKE_H
44
45#include "arthurwidgets.h"
46#include <QtGui>
47
48class PathStrokeRenderer : public ArthurFrame
49{
50 Q_OBJECT
51 Q_PROPERTY(bool animation READ animation WRITE setAnimation)
52 Q_PROPERTY(qreal penWidth READ realPenWidth WRITE setRealPenWidth)
53public:
54 enum PathMode { CurveMode, LineMode };
55
56 PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
57
58 void paint(QPainter *);
59 void mousePressEvent(QMouseEvent *e);
60 void mouseMoveEvent(QMouseEvent *e);
61 void mouseReleaseEvent(QMouseEvent *e);
62 void timerEvent(QTimerEvent *e);
63
64 QSize sizeHint() const { return QSize(500, 500); }
65
66 bool animation() const { return m_timer.isActive(); }
67
68 qreal realPenWidth() const { return m_penWidth; }
69 void setRealPenWidth(qreal penWidth) { m_penWidth = penWidth; update(); }
70
71signals:
72 void clicked();
73
74public slots:
75 void setPenWidth(int penWidth) { m_penWidth = penWidth / 10.0; update(); }
76 void setAnimation(bool animation);
77
78 void setFlatCap() { m_capStyle = Qt::FlatCap; update(); }
79 void setSquareCap() { m_capStyle = Qt::SquareCap; update(); }
80 void setRoundCap() { m_capStyle = Qt::RoundCap; update(); }
81
82 void setBevelJoin() { m_joinStyle = Qt::BevelJoin; update(); }
83 void setMiterJoin() { m_joinStyle = Qt::MiterJoin; update(); }
84 void setRoundJoin() { m_joinStyle = Qt::RoundJoin; update(); }
85
86 void setCurveMode() { m_pathMode = CurveMode; update(); }
87 void setLineMode() { m_pathMode = LineMode; update(); }
88
89 void setSolidLine() { m_penStyle = Qt::SolidLine; update(); }
90 void setDashLine() { m_penStyle = Qt::DashLine; update(); }
91 void setDotLine() { m_penStyle = Qt::DotLine; update(); }
92 void setDashDotLine() { m_penStyle = Qt::DashDotLine; update(); }
93 void setDashDotDotLine() { m_penStyle = Qt::DashDotDotLine; update(); }
94 void setCustomDashLine() { m_penStyle = Qt::NoPen; update(); }
95
96private:
97 void initializePoints();
98 void updatePoints();
99
100 QBasicTimer m_timer;
101
102 PathMode m_pathMode;
103
104 bool m_wasAnimated;
105
106 qreal m_penWidth;
107 int m_pointCount;
108 int m_pointSize;
109 int m_activePoint;
110 QVector<QPointF> m_points;
111 QVector<QPointF> m_vectors;
112
113 Qt::PenJoinStyle m_joinStyle;
114 Qt::PenCapStyle m_capStyle;
115
116 Qt::PenStyle m_penStyle;
117
118 bool m_smallScreen;
119 QPoint m_mousePress;
120 bool m_mouseDrag;
121};
122
123class PathStrokeControls : public QWidget
124{
125 Q_OBJECT
126public:
127 PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen);
128
129signals:
130 void okPressed();
131 void quitPressed();
132
133private:
134 PathStrokeRenderer* m_renderer;
135
136 QGroupBox *m_capGroup;
137 QGroupBox *m_joinGroup;
138 QGroupBox *m_styleGroup;
139 QGroupBox *m_pathModeGroup;
140
141 void createCommonControls(QWidget* parent);
142 void layoutForDesktop();
143 void layoutForSmallScreens();
144
145private slots:
146 void emitQuitSignal();
147 void emitOkSignal();
148
149};
150
151class PathStrokeWidget : public QWidget
152{
153 Q_OBJECT
154public:
155 PathStrokeWidget(bool smallScreen);
156 void setStyle ( QStyle * style );
157
158private:
159 PathStrokeRenderer *m_renderer;
160 PathStrokeControls *m_controls;
161
162private slots:
163 void showControls();
164 void hideControls();
165
166};
167
168#endif // PATHSTROKE_H
Note: See TracBrowser for help on using the repository browser.