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 demonstration applications 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#ifndef XFORM_H
52#define XFORM_H
53
54#include "arthurwidgets.h"
55
56#include <QBasicTimer>
57#include <QPolygonF>
58
59class HoverPoints;
60
61QT_BEGIN_NAMESPACE
62class QLineEdit;
63QT_END_NAMESPACE
64
65class XFormView : public ArthurFrame
66{
67public:
68 Q_OBJECT
69
70 Q_PROPERTY(XFormType type READ type WRITE setType)
71 Q_PROPERTY(bool animation READ animation WRITE setAnimation)
72 Q_PROPERTY(qreal shear READ shear WRITE setShear)
73 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)
74 Q_PROPERTY(qreal scale READ scale WRITE setScale)
75 Q_PROPERTY(QString text READ text WRITE setText)
76 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
77 Q_ENUMS(XFormType)
78
79public:
80 enum XFormType { VectorType, PixmapType, TextType };
81
82 XFormView(QWidget *parent);
83 void paint(QPainter *) override;
84 void drawVectorType(QPainter *painter);
85 void drawPixmapType(QPainter *painter);
86 void drawTextType(QPainter *painter);
87 QSize sizeHint() const override { return QSize(500, 500); }
88
89 void mousePressEvent(QMouseEvent *e) override;
90 void resizeEvent(QResizeEvent *e) override;
91 HoverPoints *hoverPoints() { return pts; }
92
93 bool animation() const { return timer.isActive(); }
94 qreal shear() const { return m_shear; }
95 qreal scale() const { return m_scale; }
96 qreal rotation() const { return m_rotation; }
97 void setShear(qreal s);
98 void setScale(qreal s);
99 void setRotation(qreal r);
100
101 XFormType type() const;
102 QPixmap pixmap() const;
103 QString text() const;
104
105public slots:
106 void setAnimation(bool animate);
107 void updateCtrlPoints(const QPolygonF &);
108 void changeRotation(int rotation);
109 void changeScale(int scale);
110 void changeShear(int shear);
111
112 void setText(const QString &);
113 void setPixmap(const QPixmap &);
114 void setType(XFormType t);
115
116 void setVectorType();
117 void setPixmapType();
118 void setTextType();
119 void reset();
120
121signals:
122 void rotationChanged(int rotation);
123 void scaleChanged(int scale);
124 void shearChanged(int shear);
125
126protected:
127 void timerEvent(QTimerEvent *e) override;
128#if QT_CONFIG(wheelevent)
129 void wheelEvent(QWheelEvent *) override;
130#endif
131
132private:
133 QPolygonF ctrlPoints;
134 HoverPoints *pts;
135 qreal m_rotation;
136 qreal m_scale;
137 qreal m_shear;
138 XFormType m_type;
139 QPixmap m_pixmap;
140 QString m_text;
141 QBasicTimer timer;
142};
143
144class XFormWidget : public QWidget
145{
146 Q_OBJECT
147public:
148 XFormWidget(QWidget *parent);
149
150private:
151 XFormView *view;
152 QLineEdit *textEditor;
153};
154
155#endif // XFORM_H
156