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#include "abstractformwindowcursor.h"
30
31QT_BEGIN_NAMESPACE
32
33/*!
34 \class QDesignerFormWindowCursorInterface
35
36 \brief The QDesignerFormWindowCursorInterface class allows you to
37 query and modify a form window's widget selection, and in addition
38 modify the properties of all the form's widgets.
39
40 \inmodule QtDesigner
41
42 QDesignerFormWindowCursorInterface is a convenience class that
43 provides an interface to the associated form window's text cursor;
44 it provides a collection of functions that enables you to query a
45 given form window's selection and change the selection's focus
46 according to defined modes (MoveMode) and movements
47 (MoveOperation). You can also use the interface to query the
48 form's widgets and change their properties.
49
50 The interface is not intended to be instantiated directly, but to
51 provide access to the selections and widgets of \QD's current form
52 windows. QDesignerFormWindowInterface always provides an
53 associated cursor interface. The form window for a given widget
54 can be retrieved using the static
55 QDesignerFormWindowInterface::findFormWindow() functions. For
56 example:
57
58 \snippet lib/tools_designer_src_lib_sdk_abstractformwindowcursor.cpp 0
59
60 You can retrieve any of \QD's current form windows through
61 \QD's \l {QDesignerFormWindowManagerInterface}{form window
62 manager}.
63
64 Once you have a form window's cursor interface, you can check if
65 the form window has a selection at all using the hasSelection()
66 function. You can query the form window for its total
67 widgetCount() and selectedWidgetCount(). You can retrieve the
68 currently selected widget (or widgets) using the current() or
69 selectedWidget() functions.
70
71 You can retrieve any of the form window's widgets using the
72 widget() function, and check if a widget is selected using the
73 isWidgetSelected() function. You can use the setProperty()
74 function to set the selected widget's properties, and the
75 setWidgetProperty() or resetWidgetProperty() functions to modify
76 the properties of any given widget.
77
78 Finally, you can change the selection by changing the text
79 cursor's position() using the setPosition() and movePosition()
80 functions.
81
82 \sa QDesignerFormWindowInterface, QDesignerFormWindowManagerInterface
83*/
84
85/*!
86 \enum QDesignerFormWindowCursorInterface::MoveOperation
87
88 This enum describes the types of text cursor operation that can occur in a form window.
89
90 \value NoMove The cursor does not move.
91 \value Start Moves the cursor to the start of the focus chain.
92 \value End Moves the cursor to the end of the focus chain.
93 \value Next Moves the cursor to the next widget in the focus chain.
94 \value Prev Moves the cursor to the previous widget in the focus chain.
95 \value Left The cursor moves to the left.
96 \value Right The cursor moves to the right.
97 \value Up The cursor moves upwards.
98 \value Down The cursor moves downwards.
99*/
100
101/*!
102 \enum QDesignerFormWindowCursorInterface::MoveMode
103
104 This enum describes the different modes that are used when the text cursor moves.
105
106 \value MoveAnchor The anchor moves with the cursor to its new location.
107 \value KeepAnchor The anchor remains at the cursor's old location.
108*/
109
110/*!
111 Returns true if the specified \a widget is selected; otherwise
112 returns false.
113*/
114bool QDesignerFormWindowCursorInterface::isWidgetSelected(QWidget *widget) const
115{
116 for (int index=0; index<selectedWidgetCount(); ++index) {
117 if (selectedWidget(index) == widget)
118 return true;
119 }
120
121 return false;
122}
123
124/*!
125 \fn virtual QDesignerFormWindowCursorInterface::~QDesignerFormWindowCursorInterface()
126
127 Destroys the cursor interface.
128*/
129
130/*!
131 \fn virtual QDesignerFormWindowInterface *QDesignerFormWindowCursorInterface::formWindow() const
132
133 Returns the form window interface associated with this cursor interface.
134*/
135
136/*!
137 \fn virtual bool QDesignerFormWindowCursorInterface::movePosition(MoveOperation operation, MoveMode mode)
138
139 Performs the given \a operation on the cursor using the specified
140 \a mode, and returns true if it completed successfully; otherwise
141 returns false.
142
143 \sa position(), setPosition()
144*/
145
146/*!
147 \fn virtual int QDesignerFormWindowCursorInterface::position() const
148
149 Returns the cursor position.
150
151 \sa setPosition(), movePosition()
152*/
153
154/*!
155 \fn virtual void QDesignerFormWindowCursorInterface::setPosition(int position, MoveMode mode = MoveAnchor)
156
157 Sets the position of the cursor to the given \a position using the
158 \a mode to specify how it is moved there.
159
160 \sa position(), movePosition()
161*/
162
163/*!
164 \fn virtual QWidget *QDesignerFormWindowCursorInterface::current() const
165
166 Returns the currently selected widget in the form window.
167
168 \sa selectedWidget()
169*/
170
171/*!
172 \fn virtual int QDesignerFormWindowCursorInterface::widgetCount() const
173
174 Returns the number of widgets in the form window.
175
176 \sa selectedWidgetCount()
177*/
178
179/*!
180 \fn virtual QWidget *QDesignerFormWindowCursorInterface::widget(int index) const
181
182 Returns the widget with the given \a index in the list of widgets
183 in the form window.
184
185 \sa selectedWidget()
186*/
187
188/*!
189 \fn virtual bool QDesignerFormWindowCursorInterface::hasSelection() const
190
191 Returns true if the form window contains a selection; otherwise
192 returns false.
193*/
194
195/*!
196 \fn virtual int QDesignerFormWindowCursorInterface::selectedWidgetCount() const
197
198 Returns the number of selected widgets in the form window.
199
200 \sa widgetCount()
201*/
202
203/*!
204 \fn virtual QWidget *QDesignerFormWindowCursorInterface::selectedWidget(int index) const
205
206 Returns the widget with the given \a index in the list of selected
207 widgets.
208
209 \sa current(), widget()
210*/
211
212/*!
213 \fn virtual void QDesignerFormWindowCursorInterface::setProperty(const QString &name, const QVariant &value)
214
215 Sets the property with the given \a name for the currently
216 selected widget to the specified \a value.
217
218 \sa setWidgetProperty(), resetWidgetProperty()
219*/
220
221/*!
222 \fn virtual void QDesignerFormWindowCursorInterface::setWidgetProperty(QWidget *widget, const QString &name, const QVariant &value)
223
224 Sets the property with the given \a name for the given \a widget
225 to the specified \a value.
226
227 \sa resetWidgetProperty(), setProperty()
228*/
229
230/*!
231 \fn virtual void QDesignerFormWindowCursorInterface::resetWidgetProperty(QWidget *widget, const QString &name)
232
233 Resets the property with the given \a name for the specified \a
234 widget to its default value.
235
236 \sa setProperty(), setWidgetProperty()
237*/
238
239QT_END_NAMESPACE
240

source code of qttools/src/designer/src/lib/sdk/abstractformwindowcursor.cpp