Debian Codegraph @

examples/widgets/painting/affine/xform.h

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 #ifndef XFORM_H
5 #define XFORM_H
6
7 #include "arthurwidgets.h"
8
9 #include <QBasicTimer>
10 #include <QPolygonF>
11
12 class HoverPoints;
13
14 QT_BEGIN_NAMESPACE
15 class QLineEdit;
16 QT_END_NAMESPACE
17
18 class XFormView : public ArthurFrame
19 {
20 public:
21 Q_OBJECT
22
23 Q_PROPERTY(XFormType type READ type WRITE setType)
24 Q_PROPERTY(bool animation READ animation WRITE setAnimation)
25 Q_PROPERTY(qreal shear READ shear WRITE setShear)
26 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)
27 Q_PROPERTY(qreal scale READ scale WRITE setScale)
28 Q_PROPERTY(QString text READ text WRITE setText)
29 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
30 Q_ENUMS(XFormType)
31
32 public:
33 enum XFormType { VectorType, PixmapType, TextType };
34
35 XFormView(QWidget *parent);
36 void paint(QPainter *) override;
37 void drawVectorType(QPainter *painter);
38 void drawPixmapType(QPainter *painter);
39 void drawTextType(QPainter *painter);
40 QSize sizeHint() const override { return QSize(500, 500); }
41
42 void mousePressEvent(QMouseEvent *e) override;
43 void resizeEvent(QResizeEvent *e) override;
44 HoverPoints *hoverPoints() { return m_hoverPoints; }
45
46 bool animation() const { return timer.isActive(); }
47 qreal shear() const { return m_shear; }
48 qreal scale() const { return m_scale; }
49 qreal rotation() const { return m_rotation; }
50 void setShear(qreal s);
51 void setScale(qreal s);
52 void setRotation(qreal r);
53
54 XFormType type() const;
55 QPixmap pixmap() const;
56 QString text() const;
57
58 public slots:
59 void setAnimation(bool animate);
60 void updateControlPoints(const QPolygonF &);
61 void changeRotation(int rotation);
62 void changeScale(int scale);
63 void changeShear(int shear);
64
65 void setText(const QString &);
66 void setPixmap(const QPixmap &);
67 void setType(XFormType t);
68
69 void setVectorType();
70 void setPixmapType();
71 void setTextType();
72 void reset();
73
74 signals:
75 void rotationChanged(int rotation);
76 void scaleChanged(int scale);
77 void shearChanged(int shear);
78
79 protected:
80 void timerEvent(QTimerEvent *e) override;
81 #if QT_CONFIG(wheelevent)
82 void wheelEvent(QWheelEvent *) override;
83 #endif
84
85 private:
86 QPolygonF m_controlPoints{{250, 250}, {350, 250}};
87 HoverPoints *m_hoverPoints;
88 qreal m_rotation = 0;
89 qreal m_scale = 1;
90 qreal m_shear = 0;
91 XFormType m_type = VectorType;
92 QPixmap m_pixmap;
93 QString m_text;
94 QBasicTimer timer;
95 };
96
97 class XFormWidget : public QWidget
98 {
99 Q_OBJECT
100 public:
101 XFormWidget(QWidget *parent);
102
103 private:
104 XFormView *view;
105 QLineEdit *textEditor;
106 };
107
108 #endif // XFORM_H