1 /*
2 	Actiona
3 	Copyright (C) 2005 Jonathan Mercier-Ganady
4 
5 	Actiona is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 3 of the License, or
8 	(at your option) any later version.
9 
10 	Actiona is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 	Contact : jmgr@jmgr.info
19 */
20 
21 #pragma once
22 
23 #include "actiontools_global.h"
24 #include "code/codeclass.h"
25 
26 #include <QObject>
27 #include <QScriptValue>
28 #include <QScriptEngine>
29 #include <QRect>
30 #include <QPoint>
31 #include <QSize>
32 
33 namespace Code
34 {
35 	class ACTIONTOOLSSHARED_EXPORT Rect : public CodeClass
36 	{
37 		Q_OBJECT
38 		Q_PROPERTY(int top READ top WRITE setTop)
39 		Q_PROPERTY(int bottom READ bottom WRITE setBottom)
40 		Q_PROPERTY(int left READ left WRITE setLeft)
41 		Q_PROPERTY(int right READ right WRITE setRight)
42 		Q_PROPERTY(int x READ x WRITE setX)
43 		Q_PROPERTY(int y READ y WRITE setY)
44 		Q_PROPERTY(int width READ width WRITE setWidth)
45 		Q_PROPERTY(int height READ height WRITE setHeight)
46 
47 	public:
48 		static QScriptValue constructor(QScriptContext *context, QScriptEngine *engine);
49 		static QScriptValue constructor(const QRect &rect, QScriptEngine *engine);
50 		static QRect parameter(QScriptContext *context, QScriptEngine *engine);
51 
52 		static void registerClass(QScriptEngine *scriptEngine);
53 
54 		Rect();
55 		Rect(const Rect &other);
56 		Rect(const QRect &rect);
57 
58 		Rect &operator=(Rect other);
59 		Rect &operator=(QRect rect);
60 
61 		void swap(Rect &other);
62 		void swap(QRect &rect);
63 
64 		const QRect &rect() const;
65 
66 		int width() const;
67 		int height() const;
68 		int x() const;
69 		int y() const;
70 		int left() const;
71 		int right() const;
72 		int top() const;
73 		int bottom() const;
74 
75 	public slots:
76 		QScriptValue clone() const;
77 		bool equals(const QScriptValue &other) const override;
78 		QString toString() const override;
79 		QScriptValue normalize();
80 		QScriptValue setTop(int top);
81 		QScriptValue setBottom(int bottom);
82 		QScriptValue setLeft(int left);
83 		QScriptValue setRight(int right);
84 		QScriptValue setX(int x);
85 		QScriptValue setY(int y);
86 		QScriptValue setWidth(int width);
87 		QScriptValue setHeight(int height);
88 		QScriptValue setSize();
89 		QScriptValue setCoords(int x1, int y1, int x2, int y2);
90 		QScriptValue setRect();
91 		QScriptValue translate();
92 		bool contains(const QScriptValue &point) const;
93 		QScriptValue united() const;
94 		QScriptValue intersected() const;
95 		bool intersects() const;
96 		bool isEmpty() const;
97 		QScriptValue center() const;
98 		QScriptValue size() const;
99 
100 	private:
101 		QRect mRect;
102 	};
103 }
104 
105