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 Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef WIDGETSELECTION_H |
30 | #define WIDGETSELECTION_H |
31 | |
32 | #include "formeditor_global.h" |
33 | #include <invisible_widget_p.h> |
34 | |
35 | #include <QtCore/qhash.h> |
36 | #include <QtCore/qpointer.h> |
37 | |
38 | QT_BEGIN_NAMESPACE |
39 | |
40 | class QDesignerFormEditorInterface; |
41 | class QMouseEvent; |
42 | class QPaintEvent; |
43 | |
44 | namespace qdesigner_internal { |
45 | |
46 | class FormWindow; |
47 | class WidgetSelection; |
48 | |
49 | class QT_FORMEDITOR_EXPORT WidgetHandle: public InvisibleWidget |
50 | { |
51 | Q_OBJECT |
52 | public: |
53 | enum Type |
54 | { |
55 | LeftTop, |
56 | Top, |
57 | RightTop, |
58 | Right, |
59 | RightBottom, |
60 | Bottom, |
61 | LeftBottom, |
62 | Left, |
63 | |
64 | TypeCount |
65 | }; |
66 | |
67 | WidgetHandle(FormWindow *parent, Type t, WidgetSelection *s); |
68 | void setWidget(QWidget *w); |
69 | void setActive(bool a); |
70 | void updateCursor(); |
71 | |
72 | void setEnabled(bool) {} |
73 | |
74 | QDesignerFormEditorInterface *core() const; |
75 | |
76 | protected: |
77 | void paintEvent(QPaintEvent *e) override; |
78 | void mousePressEvent(QMouseEvent *e) override; |
79 | void mouseMoveEvent(QMouseEvent *e) override; |
80 | void mouseReleaseEvent(QMouseEvent *e) override; |
81 | |
82 | private: |
83 | void changeGridLayoutItemSpan(); |
84 | void changeFormLayoutItemSpan(); |
85 | void trySetGeometry(QWidget *w, int x, int y, int width, int height); |
86 | void tryResize(QWidget *w, int width, int height); |
87 | |
88 | private: |
89 | QWidget *m_widget; |
90 | const Type m_type; |
91 | QPoint m_origPressPos; |
92 | FormWindow *m_formWindow; |
93 | WidgetSelection *m_sel; |
94 | QRect m_geom, m_origGeom; |
95 | bool m_active; |
96 | }; |
97 | |
98 | class QT_FORMEDITOR_EXPORT WidgetSelection: public QObject |
99 | { |
100 | Q_OBJECT |
101 | public: |
102 | WidgetSelection(FormWindow *parent); |
103 | |
104 | void setWidget(QWidget *w); |
105 | bool isUsed() const; |
106 | |
107 | void updateActive(); |
108 | void updateGeometry(); |
109 | void hide(); |
110 | void show(); |
111 | void update(); |
112 | |
113 | QWidget *widget() const; |
114 | |
115 | QDesignerFormEditorInterface *core() const; |
116 | |
117 | bool eventFilter(QObject *object, QEvent *event) override; |
118 | |
119 | enum WidgetState { UnlaidOut, LaidOut, ManagedGridLayout, ManagedFormLayout }; |
120 | static WidgetState widgetState(const QDesignerFormEditorInterface *core, QWidget *w); |
121 | |
122 | private: |
123 | WidgetHandle *m_handles[WidgetHandle::TypeCount]; |
124 | QPointer<QWidget> m_widget; |
125 | FormWindow *m_formWindow; |
126 | }; |
127 | |
128 | } // namespace qdesigner_internal |
129 | |
130 | QT_END_NAMESPACE |
131 | |
132 | #endif // WIDGETSELECTION_H |
133 | |