Mercurial > octave-nkf
comparison libgui/graphics/BaseControl.cc @ 20002:3cc0734283dc
style fixes in Qt graphics code
* Backend.cc, BaseControl.cc, ButtonControl.cc, Canvas.cc,
CheckBoxControl.cc, Container.cc, ContextMenu.cc, EditControl.cc,
Figure.cc, FigureWindow.cc, GLCanvas.cc, KeyMap.cc, ListBoxControl.cc,
Logger.cc, Menu.cc, MouseModeActionGroup.cc, Object.cc,
ObjectFactory.cc, ObjectProxy.cc, Panel.cc, PopupMenuControl.cc,
PushButtonControl.cc, PushTool.cc, QtHandlesUtils.cc,
RadioButtonControl.cc, SliderControl.cc, TextControl.cc, TextEdit.cc,
ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, ToolBarButton.cc,
__init_qt__.cc: Follow a few more Octave coding conventions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 Mar 2015 12:27:54 -0400 |
parents | 2f4406e9dad6 |
children | f0e61a67ad9f |
comparison
equal
deleted
inserted
replaced
20001:40b2c4323c16 | 20002:3cc0734283dc |
---|---|
34 #include "QtHandlesUtils.h" | 34 #include "QtHandlesUtils.h" |
35 | 35 |
36 namespace QtHandles | 36 namespace QtHandles |
37 { | 37 { |
38 | 38 |
39 static void updatePalette (const uicontrol::properties& props, QWidget* w) | 39 static void |
40 updatePalette (const uicontrol::properties& props, QWidget* w) | |
40 { | 41 { |
41 QPalette p = w->palette (); | 42 QPalette p = w->palette (); |
42 | 43 |
43 if (props.style_is ("edit") | 44 if (props.style_is ("edit") |
44 || props.style_is ("listbox") | 45 || props.style_is ("listbox") |
72 : Object (go, w), m_normalizedFont (false), m_keyPressHandlerDefined (false) | 73 : Object (go, w), m_normalizedFont (false), m_keyPressHandlerDefined (false) |
73 { | 74 { |
74 init (w); | 75 init (w); |
75 } | 76 } |
76 | 77 |
77 void BaseControl::init (QWidget* w, bool callBase) | 78 void |
79 BaseControl::init (QWidget* w, bool callBase) | |
78 { | 80 { |
79 if (callBase) | 81 if (callBase) |
80 Object::init (w, callBase); | 82 Object::init (w, callBase); |
81 | 83 |
82 uicontrol::properties& up = properties<uicontrol> (); | 84 uicontrol::properties& up = properties<uicontrol> (); |
98 | 100 |
99 BaseControl::~BaseControl (void) | 101 BaseControl::~BaseControl (void) |
100 { | 102 { |
101 } | 103 } |
102 | 104 |
103 void BaseControl::update (int pId) | 105 void |
106 BaseControl::update (int pId) | |
104 { | 107 { |
105 uicontrol::properties& up = properties<uicontrol> (); | 108 uicontrol::properties& up = properties<uicontrol> (); |
106 QWidget* w = qWidget<QWidget> (); | 109 QWidget* w = qWidget<QWidget> (); |
107 | 110 |
108 switch (pId) | 111 switch (pId) |
112 Matrix bb = up.get_boundingbox (false); | 115 Matrix bb = up.get_boundingbox (false); |
113 w->setGeometry (xround (bb(0)), xround (bb(1)), | 116 w->setGeometry (xround (bb(0)), xround (bb(1)), |
114 xround (bb(2)), xround (bb(3))); | 117 xround (bb(2)), xround (bb(3))); |
115 } | 118 } |
116 break; | 119 break; |
120 | |
117 case uicontrol::properties::ID_FONTNAME: | 121 case uicontrol::properties::ID_FONTNAME: |
118 case uicontrol::properties::ID_FONTSIZE: | 122 case uicontrol::properties::ID_FONTSIZE: |
119 case uicontrol::properties::ID_FONTWEIGHT: | 123 case uicontrol::properties::ID_FONTWEIGHT: |
120 case uicontrol::properties::ID_FONTANGLE: | 124 case uicontrol::properties::ID_FONTANGLE: |
121 w->setFont (Utils::computeFont<uicontrol> (up)); | 125 w->setFont (Utils::computeFont<uicontrol> (up)); |
122 break; | 126 break; |
127 | |
123 case uicontrol::properties::ID_FONTUNITS: | 128 case uicontrol::properties::ID_FONTUNITS: |
124 // FIXME: We shouldn't have to do anything, octave should update | 129 // FIXME: We shouldn't have to do anything, octave should update |
125 // the "fontsize" property automatically to the new units. | 130 // the "fontsize" property automatically to the new units. |
126 // Hence the actual font used shouldn't change. | 131 // Hence the actual font used shouldn't change. |
127 m_normalizedFont = up.fontunits_is ("normalized"); | 132 m_normalizedFont = up.fontunits_is ("normalized"); |
128 break; | 133 break; |
134 | |
129 case uicontrol::properties::ID_BACKGROUNDCOLOR: | 135 case uicontrol::properties::ID_BACKGROUNDCOLOR: |
130 case uicontrol::properties::ID_FOREGROUNDCOLOR: | 136 case uicontrol::properties::ID_FOREGROUNDCOLOR: |
131 updatePalette (up, w); | 137 updatePalette (up, w); |
132 break; | 138 break; |
139 | |
133 case uicontrol::properties::ID_ENABLE: | 140 case uicontrol::properties::ID_ENABLE: |
134 w->setEnabled (up.enable_is ("on")); | 141 w->setEnabled (up.enable_is ("on")); |
135 break; | 142 break; |
143 | |
136 case uicontrol::properties::ID_TOOLTIPSTRING: | 144 case uicontrol::properties::ID_TOOLTIPSTRING: |
137 w->setToolTip (Utils::fromStdString (up.get_tooltipstring ())); | 145 w->setToolTip (Utils::fromStdString (up.get_tooltipstring ())); |
138 break; | 146 break; |
147 | |
139 case base_properties::ID_VISIBLE: | 148 case base_properties::ID_VISIBLE: |
140 w->setVisible (up.is_visible ()); | 149 w->setVisible (up.is_visible ()); |
141 break; | 150 break; |
151 | |
142 case uicontrol::properties::ID_KEYPRESSFCN: | 152 case uicontrol::properties::ID_KEYPRESSFCN: |
143 m_keyPressHandlerDefined = ! up.get_keypressfcn ().is_empty (); | 153 m_keyPressHandlerDefined = ! up.get_keypressfcn ().is_empty (); |
144 break; | 154 break; |
155 | |
145 default: | 156 default: |
146 break; | 157 break; |
147 } | 158 } |
148 } | 159 } |
149 | 160 |
150 bool BaseControl::eventFilter (QObject* watched, QEvent* xevent) | 161 bool |
162 BaseControl::eventFilter (QObject* watched, QEvent* xevent) | |
151 { | 163 { |
152 switch (xevent->type ()) | 164 switch (xevent->type ()) |
153 { | 165 { |
154 case QEvent::Resize: | 166 case QEvent::Resize: |
155 if (m_normalizedFont) | 167 if (m_normalizedFont) |
158 | 170 |
159 qWidget<QWidget> ()->setFont (Utils::computeFont<uicontrol> | 171 qWidget<QWidget> ()->setFont (Utils::computeFont<uicontrol> |
160 (properties<uicontrol> ())); | 172 (properties<uicontrol> ())); |
161 } | 173 } |
162 break; | 174 break; |
175 | |
163 case QEvent::MouseButtonPress: | 176 case QEvent::MouseButtonPress: |
164 { | 177 { |
165 gh_manager::auto_lock lock; | 178 gh_manager::auto_lock lock; |
166 | 179 |
167 QMouseEvent* m = dynamic_cast<QMouseEvent*> (xevent); | 180 QMouseEvent* m = dynamic_cast<QMouseEvent*> (xevent); |
168 graphics_object go = object (); | 181 graphics_object go = object (); |
169 uicontrol::properties& up = Utils::properties<uicontrol> (go); | 182 uicontrol::properties& up = Utils::properties<uicontrol> (go); |
170 graphics_object fig = go.get_ancestor ("figure"); | 183 graphics_object fig = go.get_ancestor ("figure"); |
171 | 184 |
172 if (m->button () != Qt::LeftButton | 185 if (m->button () != Qt::LeftButton |
173 || ! up.enable_is ("on")) | 186 || ! up.enable_is ("on")) |
174 { | 187 { |
188 gh_manager::post_set (fig.get_handle (), "selectiontype", | |
189 Utils::figureSelectionType (m), false); | |
190 gh_manager::post_set (fig.get_handle (), "currentpoint", | |
191 Utils::figureCurrentPoint (fig, m), | |
192 false); | |
193 gh_manager::post_callback (fig.get_handle (), | |
194 "windowbuttondownfcn"); | |
195 gh_manager::post_callback (m_handle, "buttondownfcn"); | |
196 | |
197 if (m->button () == Qt::RightButton) | |
198 ContextMenu::executeAt (up, m->globalPos ()); | |
199 } | |
200 else | |
201 { | |
202 if (up.style_is ("listbox")) | |
175 gh_manager::post_set (fig.get_handle (), "selectiontype", | 203 gh_manager::post_set (fig.get_handle (), "selectiontype", |
176 Utils::figureSelectionType (m), false); | 204 Utils::figureSelectionType (m), false); |
177 gh_manager::post_set (fig.get_handle (), "currentpoint", | 205 else |
178 Utils::figureCurrentPoint (fig, m), | 206 gh_manager::post_set (fig.get_handle (), "selectiontype", |
179 false); | 207 octave_value ("normal"), false); |
180 gh_manager::post_callback (fig.get_handle (), | 208 } |
181 "windowbuttondownfcn"); | 209 } |
182 gh_manager::post_callback (m_handle, "buttondownfcn"); | 210 break; |
183 | 211 |
184 if (m->button () == Qt::RightButton) | |
185 ContextMenu::executeAt (up, m->globalPos ()); | |
186 } | |
187 else | |
188 { | |
189 if (up.style_is ("listbox")) | |
190 gh_manager::post_set (fig.get_handle (), "selectiontype", | |
191 Utils::figureSelectionType (m), false); | |
192 else | |
193 gh_manager::post_set (fig.get_handle (), "selectiontype", | |
194 octave_value ("normal"), false); | |
195 } | |
196 } | |
197 break; | |
198 case QEvent::MouseMove: | 212 case QEvent::MouseMove: |
199 if (qWidget<QWidget> ()->hasMouseTracking ()) | 213 if (qWidget<QWidget> ()->hasMouseTracking ()) |
200 { | 214 { |
201 gh_manager::auto_lock lock; | 215 gh_manager::auto_lock lock; |
202 | 216 |
207 gh_manager::post_set (fig.get_handle (), "currentpoint", | 221 gh_manager::post_set (fig.get_handle (), "currentpoint", |
208 Utils::figureCurrentPoint (fig, m), false); | 222 Utils::figureCurrentPoint (fig, m), false); |
209 gh_manager::post_callback (fig.get_handle (), "windowbuttonmotionfcn"); | 223 gh_manager::post_callback (fig.get_handle (), "windowbuttonmotionfcn"); |
210 } | 224 } |
211 break; | 225 break; |
226 | |
212 case QEvent::KeyPress: | 227 case QEvent::KeyPress: |
213 if (m_keyPressHandlerDefined) | 228 if (m_keyPressHandlerDefined) |
214 { | 229 { |
215 gh_manager::auto_lock lock; | 230 gh_manager::auto_lock lock; |
216 | 231 |
221 gh_manager::post_set (fig.get_handle (), "currentcharacter", | 236 gh_manager::post_set (fig.get_handle (), "currentcharacter", |
222 keyData.getfield ("Character"), false); | 237 keyData.getfield ("Character"), false); |
223 gh_manager::post_callback (m_handle, "keypressfcn", keyData); | 238 gh_manager::post_callback (m_handle, "keypressfcn", keyData); |
224 } | 239 } |
225 break; | 240 break; |
226 default: break; | 241 |
242 default: | |
243 break; | |
227 } | 244 } |
228 | 245 |
229 return Object::eventFilter (watched, xevent); | 246 return Object::eventFilter (watched, xevent); |
230 } | 247 } |
231 | 248 |