Debian Codegraph @

examples/widgets/painting/pathstroke/pathstroke.h

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 #ifndef PATHSTROKE_H
5 #define PATHSTROKE_H
6
7 #include "arthurwidgets.h"
8
9 #include <QtWidgets>
10
11 class PathStrokeRenderer : public ArthurFrame
12 {
13 Q_OBJECT
14 Q_PROPERTY(bool animation READ animation WRITE setAnimation)
15 Q_PROPERTY(qreal penWidth READ realPenWidth WRITE setRealPenWidth)
16 public:
17 enum PathMode { CurveMode, LineMode };
18
19 explicit PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
20
21 void paint(QPainter *) override;
22 void mousePressEvent(QMouseEvent *e) override;
23 void mouseMoveEvent(QMouseEvent *e) override;
24 void mouseReleaseEvent(QMouseEvent *e) override;
25 void timerEvent(QTimerEvent *e) override;
26 bool event(QEvent *e) override;
27
28 QSize sizeHint() const override { return QSize(500, 500); }
29
30 bool animation() const { return m_timer.isActive(); }
31
32 qreal realPenWidth() const { return m_penWidth; }
33 void setRealPenWidth(qreal penWidth) { m_penWidth = penWidth; update(); }
34
35 signals:
36 void clicked();
37
38 public slots:
39 void setPenWidth(int penWidth) { m_penWidth = penWidth / 10.0; update(); }
40 void setAnimation(bool animation);
41
42 void setFlatCap() { m_capStyle = Qt::FlatCap; update(); }
43 void setSquareCap() { m_capStyle = Qt::SquareCap; update(); }
44 void setRoundCap() { m_capStyle = Qt::RoundCap; update(); }
45
46 void setBevelJoin() { m_joinStyle = Qt::BevelJoin; update(); }
47 void setMiterJoin() { m_joinStyle = Qt::MiterJoin; update(); }
48 void setSvgMiterJoin() { m_joinStyle = Qt::SvgMiterJoin; update(); }
49 void setRoundJoin() { m_joinStyle = Qt::RoundJoin; update(); }
50
51 void setCurveMode() { m_pathMode = CurveMode; update(); }
52 void setLineMode() { m_pathMode = LineMode; update(); }
53
54 void setSolidLine() { m_penStyle = Qt::SolidLine; update(); }
55 void setDashLine() { m_penStyle = Qt::DashLine; update(); }
56 void setDotLine() { m_penStyle = Qt::DotLine; update(); }
57 void setDashDotLine() { m_penStyle = Qt::DashDotLine; update(); }
58 void setDashDotDotLine() { m_penStyle = Qt::DashDotDotLine; update(); }
59 void setCustomDashLine() { m_penStyle = Qt::NoPen; update(); }
60
61 private:
62 void initializePoints();
63 void updatePoints();
64
65 QBasicTimer m_timer;
66
67 PathMode m_pathMode;
68
69 bool m_wasAnimated;
70
71 qreal m_penWidth;
72 int m_pointCount;
73 int m_pointSize;
74 int m_activePoint;
75 QList<QPointF> m_points;
76 QList<QPointF> m_vectors;
77
78 Qt::PenJoinStyle m_joinStyle;
79 Qt::PenCapStyle m_capStyle;
80
81 Qt::PenStyle m_penStyle;
82
83 bool m_smallScreen;
84 QPoint m_mousePress;
85 bool m_mouseDrag;
86
87 QHash<int, int> m_fingerPointMapping;
88 };
89
90 class PathStrokeControls : public QWidget
91 {
92 Q_OBJECT
93
94 public:
95 PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen);
96
97 signals:
98 void okPressed();
99 void quitPressed();
100
101 private:
102 PathStrokeRenderer* m_renderer;
103
104 QGroupBox *m_capGroup;
105 QGroupBox *m_joinGroup;
106 QGroupBox *m_styleGroup;
107 QGroupBox *m_pathModeGroup;
108
109 void createCommonControls(QWidget* parent);
110 void layoutForDesktop();
111 void layoutForSmallScreens();
112
113 private slots:
114 void emitQuitSignal();
115 void emitOkSignal();
116
117 };
118
119 class PathStrokeWidget : public QWidget
120 {
121 Q_OBJECT
122
123 public:
124 PathStrokeWidget(bool smallScreen);
125 void setStyle(QStyle *style);
126
127 private:
128 PathStrokeRenderer *m_renderer;
129 PathStrokeControls *m_controls;
130
131 private slots:
132 void showControls();
133 void hideControls();
134 };
135
136 #endif // PATHSTROKE_H