Mercurial > octave
comparison libgui/graphics/EditControl.cc @ 31648:29d734430e5f stable
maint: Re-indent code after switch to using namespace macros.
* BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h,
ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h,
CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h,
ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h,
Figure.cc, Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc,
GLCanvas.h, GenericEventNotify.h, KeyMap.cc, KeyMap.h,
ListBoxControl.cc, ListBoxControl.h, Logger.cc, Logger.h, Menu.cc,
Menu.h, MenuContainer.h, Object.cc, Object.h, ObjectProxy.cc,
ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc,
PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h,
PushTool.cc, PushTool.h, QtHandlesUtils.cc, QtHandlesUtils.h,
RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc,
SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h,
TextEdit.cc, TextEdit.h, ToggleButtonControl.cc,
ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc,
ToolBar.h, ToolBarButton.cc, ToolBarButton.h, annotation-dialog.cc,
annotation-dialog.h, gl-select.cc, gl-select.h, qopengl-functions.h,
qt-graphics-toolkit.cc, qt-graphics-toolkit.h, module.mk, QTerminal.h,
color-picker.cc, color-picker.h, command-widget.cc, command-widget.h,
community-news.cc, community-news.h, dialog.cc, dialog.h,
documentation-bookmarks.cc, documentation-bookmarks.h,
documentation-dock-widget.cc, documentation-dock-widget.h,
documentation.cc, documentation.h, dw-main-window.cc,
dw-main-window.h, external-editor-interface.cc,
external-editor-interface.h, files-dock-widget.cc,
files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h,
find-files-model.cc, find-files-model.h, graphics-init.cc,
graphics-init.h, gui-settings.cc, gui-settings.h, gui-utils.cc,
gui-utils.h, history-dock-widget.cc, history-dock-widget.h,
interpreter-qobject.cc, interpreter-qobject.h, led-indicator.cc,
led-indicator.h, file-editor-interface.h, file-editor-tab.cc,
file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc,
find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc,
octave-qscintilla.h, octave-txt-lexer.cc, octave-txt-lexer.h,
main-window.cc, main-window.h, news-reader.cc, news-reader.h,
octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc,
octave-qobject.h, qt-application.cc, qt-application.h,
qt-interpreter-events.cc, qt-interpreter-events.h, qt-utils.h,
release-notes.cc, release-notes.h, resource-manager.cc,
resource-manager.h, set-path-dialog.cc, set-path-dialog.h,
set-path-model.cc, set-path-model.h, settings-dialog.cc,
settings-dialog.h, shortcut-manager.cc, shortcut-manager.h,
tab-bar.cc, tab-bar.h, terminal-dock-widget.cc,
terminal-dock-widget.h, variable-editor-model.cc,
variable-editor-model.h, variable-editor.cc, variable-editor.h,
welcome-wizard.cc, welcome-wizard.h, workspace-model.cc,
workspace-model.h, workspace-view.cc, workspace-view.h:
Re-indent code after switch to using namespace macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 14:53:00 -0500 |
parents | c6d54dd31a7e |
children | deb553ac2c54 597f3ee61a48 |
comparison
equal
deleted
inserted
replaced
31646:c6d54dd31a7e | 31648:29d734430e5f |
---|---|
36 | 36 |
37 #include "octave-qobject.h" | 37 #include "octave-qobject.h" |
38 | 38 |
39 OCTAVE_BEGIN_NAMESPACE(octave) | 39 OCTAVE_BEGIN_NAMESPACE(octave) |
40 | 40 |
41 EditControl * | 41 EditControl * |
42 EditControl::create (octave::base_qobject& oct_qobj, | 42 EditControl::create (octave::base_qobject& oct_qobj, |
43 octave::interpreter& interp, const graphics_object& go) | 43 octave::interpreter& interp, const graphics_object& go) |
44 { | 44 { |
45 Object *parent = parentObject (interp, go); | 45 Object *parent = parentObject (interp, go); |
46 | 46 |
47 if (parent) | 47 if (parent) |
48 { | 48 { |
49 Container *container = parent->innerContainer (); | 49 Container *container = parent->innerContainer (); |
50 | 50 |
51 if (container) | 51 if (container) |
52 { | 52 { |
53 uicontrol::properties& up = Utils::properties<uicontrol> (go); | 53 uicontrol::properties& up = Utils::properties<uicontrol> (go); |
54 | 54 |
55 if ((up.get_max () - up.get_min ()) > 1) | 55 if ((up.get_max () - up.get_min ()) > 1) |
56 return new EditControl (oct_qobj, interp, go, | 56 return new EditControl (oct_qobj, interp, go, |
57 new TextEdit (container)); | 57 new TextEdit (container)); |
58 else | 58 else |
59 return new EditControl (oct_qobj, interp, go, | 59 return new EditControl (oct_qobj, interp, go, |
60 new QLineEdit (container)); | 60 new QLineEdit (container)); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 return nullptr; | 64 return nullptr; |
65 } | 65 } |
66 | 66 |
67 EditControl::EditControl (octave::base_qobject& oct_qobj, | 67 EditControl::EditControl (octave::base_qobject& oct_qobj, |
68 octave::interpreter& interp, | 68 octave::interpreter& interp, |
69 const graphics_object& go, QLineEdit *edit) | 69 const graphics_object& go, QLineEdit *edit) |
70 : BaseControl (oct_qobj, interp, go, edit), m_multiLine (false), | 70 : BaseControl (oct_qobj, interp, go, edit), m_multiLine (false), |
71 m_textChanged (false) | 71 m_textChanged (false) |
72 { | 72 { |
73 init (edit); | 73 init (edit); |
74 } | 74 } |
75 | 75 |
76 void | 76 void |
77 EditControl::init (QLineEdit *edit, bool callBase) | 77 EditControl::init (QLineEdit *edit, bool callBase) |
78 { | 78 { |
79 if (callBase) | 79 if (callBase) |
80 BaseControl::init (edit, callBase); | 80 BaseControl::init (edit, callBase); |
81 | 81 |
82 m_multiLine = false; | 82 m_multiLine = false; |
83 initCommon (edit); | 83 initCommon (edit); |
84 | 84 |
85 uicontrol::properties& up = properties<uicontrol> (); | 85 uicontrol::properties& up = properties<uicontrol> (); |
86 | 86 |
87 if (up.enable_is ("inactive")) | 87 if (up.enable_is ("inactive")) |
88 edit->setReadOnly (true); | 88 edit->setReadOnly (true); |
89 else | 89 else |
90 edit->setEnabled (up.enable_is ("on")); | 90 edit->setEnabled (up.enable_is ("on")); |
91 edit->setText (Utils::fromStdString (up.get_string_string ())); | 91 edit->setText (Utils::fromStdString (up.get_string_string ())); |
92 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), | 92 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), |
93 up.get_verticalalignment ())); | 93 up.get_verticalalignment ())); |
94 | 94 |
95 connect (edit, &QLineEdit::textEdited, | 95 connect (edit, &QLineEdit::textEdited, |
96 this, &EditControl::textChanged); | 96 this, &EditControl::textChanged); |
97 connect (edit, &QLineEdit::editingFinished, | 97 connect (edit, &QLineEdit::editingFinished, |
98 this, &EditControl::editingFinished); | 98 this, &EditControl::editingFinished); |
99 connect (edit, &QLineEdit::returnPressed, | 99 connect (edit, &QLineEdit::returnPressed, |
100 this, &EditControl::returnPressed); | 100 this, &EditControl::returnPressed); |
101 } | 101 } |
102 | 102 |
103 EditControl::EditControl (octave::base_qobject& oct_qobj, | 103 EditControl::EditControl (octave::base_qobject& oct_qobj, |
104 octave::interpreter& interp, | 104 octave::interpreter& interp, |
105 const graphics_object& go, TextEdit *edit) | 105 const graphics_object& go, TextEdit *edit) |
106 : BaseControl (oct_qobj, interp, go, edit), m_multiLine (true), | 106 : BaseControl (oct_qobj, interp, go, edit), m_multiLine (true), |
107 m_textChanged (false) | 107 m_textChanged (false) |
108 { | 108 { |
109 init (edit); | 109 init (edit); |
110 } | 110 } |
111 | 111 |
112 void | 112 void |
113 EditControl::init (TextEdit *edit, bool callBase) | 113 EditControl::init (TextEdit *edit, bool callBase) |
114 { | 114 { |
115 if (callBase) | 115 if (callBase) |
116 BaseControl::init (edit, callBase); | 116 BaseControl::init (edit, callBase); |
117 | 117 |
118 m_multiLine = true; | 118 m_multiLine = true; |
119 initCommon (edit); | 119 initCommon (edit); |
120 | 120 |
121 uicontrol::properties& up = properties<uicontrol> (); | 121 uicontrol::properties& up = properties<uicontrol> (); |
122 | 122 |
123 if (up.enable_is ("inactive")) | 123 if (up.enable_is ("inactive")) |
124 edit->setReadOnly (true); | 124 edit->setReadOnly (true); |
125 else | 125 else |
126 edit->setEnabled (up.enable_is ("on")); | 126 edit->setEnabled (up.enable_is ("on")); |
127 edit->setAcceptRichText (false); | 127 edit->setAcceptRichText (false); |
128 edit->setPlainText (Utils::fromStringVector | 128 edit->setPlainText (Utils::fromStringVector |
129 (up.get_string_vector ()).join ("\n")); | 129 (up.get_string_vector ()).join ("\n")); |
130 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), | 130 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), |
131 up.get_verticalalignment ())); | 131 up.get_verticalalignment ())); |
132 | 132 |
133 connect (edit, &TextEdit::textChanged, | 133 connect (edit, &TextEdit::textChanged, |
134 this, &EditControl::textChanged); | 134 this, &EditControl::textChanged); |
135 connect (edit, &TextEdit::editingFinished, | 135 connect (edit, &TextEdit::editingFinished, |
136 this, &EditControl::editingFinished); | 136 this, &EditControl::editingFinished); |
137 connect (edit, &TextEdit::returnPressed, | 137 connect (edit, &TextEdit::returnPressed, |
138 this, &EditControl::returnPressed); | 138 this, &EditControl::returnPressed); |
139 } | 139 } |
140 | 140 |
141 EditControl::~EditControl (void) | 141 EditControl::~EditControl (void) |
142 { } | 142 { } |
143 | 143 |
144 void | 144 void |
145 EditControl::initCommon (QWidget *) | 145 EditControl::initCommon (QWidget *) |
146 { | 146 { |
147 m_textChanged = false; | 147 m_textChanged = false; |
148 } | 148 } |
149 | 149 |
150 void | 150 void |
151 EditControl::update (int pId) | 151 EditControl::update (int pId) |
152 { | 152 { |
153 bool handled = false; | 153 bool handled = false; |
154 | 154 |
155 if (m_multiLine) | 155 if (m_multiLine) |
156 handled = updateMultiLine (pId); | 156 handled = updateMultiLine (pId); |
157 else | 157 else |
158 handled = updateSingleLine (pId); | 158 handled = updateSingleLine (pId); |
159 | 159 |
160 if (! handled) | 160 if (! handled) |
161 { | 161 { |
162 switch (pId) | 162 switch (pId) |
163 { | 163 { |
164 default: | 164 default: |
165 BaseControl::update (pId); | 165 BaseControl::update (pId); |
166 break; | 166 break; |
167 } | 167 } |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 bool | 171 bool |
172 EditControl::updateSingleLine (int pId) | 172 EditControl::updateSingleLine (int pId) |
173 { | 173 { |
174 uicontrol::properties& up = properties<uicontrol> (); | 174 uicontrol::properties& up = properties<uicontrol> (); |
175 QLineEdit *edit = qWidget<QLineEdit> (); | 175 QLineEdit *edit = qWidget<QLineEdit> (); |
176 | 176 |
177 switch (pId) | 177 switch (pId) |
178 { | 178 { |
179 case uicontrol::properties::ID_STRING: | 179 case uicontrol::properties::ID_STRING: |
180 edit->setText (Utils::fromStdString (up.get_string_string ())); | 180 edit->setText (Utils::fromStdString (up.get_string_string ())); |
181 return true; | 181 return true; |
182 | 182 |
183 case uicontrol::properties::ID_HORIZONTALALIGNMENT: | 183 case uicontrol::properties::ID_HORIZONTALALIGNMENT: |
184 case uicontrol::properties::ID_VERTICALALIGNMENT: | 184 case uicontrol::properties::ID_VERTICALALIGNMENT: |
185 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), | 185 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), |
186 up.get_verticalalignment ())); | 186 up.get_verticalalignment ())); |
187 return true; | 187 return true; |
188 | 188 |
189 case uicontrol::properties::ID_ENABLE: | 189 case uicontrol::properties::ID_ENABLE: |
190 if (up.enable_is ("inactive")) | 190 if (up.enable_is ("inactive")) |
191 edit->setReadOnly (true); | 191 edit->setReadOnly (true); |
192 else | 192 else |
193 { | 193 { |
194 edit->setReadOnly (false); | 194 edit->setReadOnly (false); |
195 edit->setEnabled (up.enable_is ("on")); | 195 edit->setEnabled (up.enable_is ("on")); |
196 } | 196 } |
197 return true; | 197 return true; |
198 | 198 |
199 case uicontrol::properties::ID_MIN: | 199 case uicontrol::properties::ID_MIN: |
200 case uicontrol::properties::ID_MAX: | 200 case uicontrol::properties::ID_MAX: |
201 if ((up.get_max () - up.get_min ()) > 1) | 201 if ((up.get_max () - up.get_min ()) > 1) |
202 { | 202 { |
203 QWidget *container = edit->parentWidget (); | 203 QWidget *container = edit->parentWidget (); |
204 | 204 |
205 delete edit; | 205 delete edit; |
206 init (new TextEdit (container), true); | 206 init (new TextEdit (container), true); |
207 } | 207 } |
208 return true; | 208 return true; |
209 | 209 |
210 default: | 210 default: |
211 break; | 211 break; |
212 } | 212 } |
213 | 213 |
214 return false; | 214 return false; |
215 } | 215 } |
216 | 216 |
217 bool | 217 bool |
218 EditControl::updateMultiLine (int pId) | 218 EditControl::updateMultiLine (int pId) |
219 { | 219 { |
220 uicontrol::properties& up = properties<uicontrol> (); | 220 uicontrol::properties& up = properties<uicontrol> (); |
221 TextEdit *edit = qWidget<TextEdit> (); | 221 TextEdit *edit = qWidget<TextEdit> (); |
222 | 222 |
223 switch (pId) | 223 switch (pId) |
224 { | 224 { |
225 case uicontrol::properties::ID_STRING: | 225 case uicontrol::properties::ID_STRING: |
226 edit->setPlainText (Utils::fromStringVector | 226 edit->setPlainText (Utils::fromStringVector |
227 (up.get_string_vector ()).join ("\n")); | 227 (up.get_string_vector ()).join ("\n")); |
228 return true; | 228 return true; |
229 | 229 |
230 case uicontrol::properties::ID_HORIZONTALALIGNMENT: | 230 case uicontrol::properties::ID_HORIZONTALALIGNMENT: |
231 case uicontrol::properties::ID_VERTICALALIGNMENT: | 231 case uicontrol::properties::ID_VERTICALALIGNMENT: |
232 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), | 232 edit->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), |
233 up.get_verticalalignment ())); | 233 up.get_verticalalignment ())); |
234 return true; | 234 return true; |
235 | 235 |
236 case uicontrol::properties::ID_ENABLE: | 236 case uicontrol::properties::ID_ENABLE: |
237 if (up.enable_is ("inactive")) | 237 if (up.enable_is ("inactive")) |
238 edit->setReadOnly (true); | 238 edit->setReadOnly (true); |
239 else | 239 else |
240 { | 240 { |
241 edit->setReadOnly (false); | 241 edit->setReadOnly (false); |
242 edit->setEnabled (up.enable_is ("on")); | 242 edit->setEnabled (up.enable_is ("on")); |
243 } | 243 } |
244 return true; | 244 return true; |
245 | 245 |
246 case uicontrol::properties::ID_MIN: | 246 case uicontrol::properties::ID_MIN: |
247 case uicontrol::properties::ID_MAX: | 247 case uicontrol::properties::ID_MAX: |
248 if ((up.get_max () - up.get_min ()) <= 1) | 248 if ((up.get_max () - up.get_min ()) <= 1) |
249 { | 249 { |
250 QWidget *container = edit->parentWidget (); | 250 QWidget *container = edit->parentWidget (); |
251 | 251 |
252 delete edit; | 252 delete edit; |
253 init (new QLineEdit (container), true); | 253 init (new QLineEdit (container), true); |
254 } | 254 } |
255 return true; | 255 return true; |
256 | 256 |
257 default: | 257 default: |
258 break; | 258 break; |
259 } | 259 } |
260 | 260 |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 void | 264 void |
265 EditControl::textChanged (void) | 265 EditControl::textChanged (void) |
266 { | 266 { |
267 m_textChanged = true; | 267 m_textChanged = true; |
268 } | 268 } |
269 | 269 |
270 void | 270 void |
271 EditControl::returnPressed (void) | 271 EditControl::returnPressed (void) |
272 { | 272 { |
273 QString txt = (m_multiLine | 273 QString txt = (m_multiLine |
274 ? qWidget<TextEdit> ()->toPlainText () | 274 ? qWidget<TextEdit> ()->toPlainText () |
275 : qWidget<QLineEdit> ()->text ()); | 275 : qWidget<QLineEdit> ()->text ()); |
276 | 276 |
277 if (m_textChanged) | 277 if (m_textChanged) |
278 { | 278 { |
279 if (m_multiLine) | 279 if (m_multiLine) |
280 emit gh_set_event (m_handle, "string", | 280 emit gh_set_event (m_handle, "string", |
281 Utils::toCellString (txt.split ("\n")), false); | 281 Utils::toCellString (txt.split ("\n")), false); |
282 else | 282 else |
283 emit gh_set_event (m_handle, "string", | 283 emit gh_set_event (m_handle, "string", |
284 Utils::toStdString (txt), false); | 284 Utils::toStdString (txt), false); |
285 | 285 |
286 m_textChanged = false; | 286 m_textChanged = false; |
287 } | 287 } |
288 | 288 |
289 if (txt.length () > 0) | 289 if (txt.length () > 0) |
290 emit gh_callback_event (m_handle, "callback"); | |
291 } | |
292 | |
293 void | |
294 EditControl::editingFinished (void) | |
295 { | |
296 if (m_textChanged) | |
297 { | |
298 QString txt = (m_multiLine | |
299 ? qWidget<TextEdit> ()->toPlainText () | |
300 : qWidget<QLineEdit> ()->text ()); | |
301 if (m_multiLine) | |
302 emit gh_set_event (m_handle, "string", | |
303 Utils::toCellString (txt.split ("\n")), false); | |
304 else | |
305 emit gh_set_event (m_handle, "string", Utils::toStdString (txt), | |
306 false); | |
290 emit gh_callback_event (m_handle, "callback"); | 307 emit gh_callback_event (m_handle, "callback"); |
291 } | 308 |
292 | 309 m_textChanged = false; |
293 void | 310 } |
294 EditControl::editingFinished (void) | 311 } |
295 { | |
296 if (m_textChanged) | |
297 { | |
298 QString txt = (m_multiLine | |
299 ? qWidget<TextEdit> ()->toPlainText () | |
300 : qWidget<QLineEdit> ()->text ()); | |
301 if (m_multiLine) | |
302 emit gh_set_event (m_handle, "string", | |
303 Utils::toCellString (txt.split ("\n")), false); | |
304 else | |
305 emit gh_set_event (m_handle, "string", Utils::toStdString (txt), | |
306 false); | |
307 emit gh_callback_event (m_handle, "callback"); | |
308 | |
309 m_textChanged = false; | |
310 } | |
311 } | |
312 | 312 |
313 OCTAVE_END_NAMESPACE(octave) | 313 OCTAVE_END_NAMESPACE(octave) |