17 #include <YPropertyEditor.h>
20 #include <YWidgetFactory.h>
22 #include <YLayoutBox.h>
23 #include <YAlignment.h>
24 #include <YButtonBox.h>
25 #include <YPushButton.h>
27 #include <YPopupInternal.h>
28 #include <YComboBox.h>
29 #include <YInputField.h>
30 #include <YIntField.h>
34 #define YUILogComponent "ui-property-editor"
45 popup(
nullptr), combo(
nullptr), intfield(
nullptr),
46 input(
nullptr), okButton(
nullptr), cancelButton(
nullptr)
49 bool edit(
const string &property );
57 void show(
const string &property );
64 bool run(
const string &property );
83 bool isReadOnly(
const string &property );
104 bool editable(
const string &property);
112 void YPropertyEditorPriv::refreshDialog()
119 bool YPropertyEditorPriv::edit(
const string &property)
121 if (!_widget || !editable(property))
return false;
123 yuiMilestone() <<
"editing property \"" <<
property <<
"\" (type: " <<
127 bool changed = run(property);
134 bool YPropertyEditorPriv::isReadOnly(
const string &property)
144 if (prop.
name() == property)
151 YUI_THROW(
YUIException(
"Unknown property: " + property) );
158 void YPropertyEditorPriv::show(
const string &property)
161 YPropertyType type = prop_value.
type();
165 popup = f->createPopupDialog();
166 auto vbox = f->createVBox(popup);
168 if (type == YBoolProperty)
170 combo = f->createComboBox(vbox, property);
174 items.push_back(
new YItem(
"true"));
175 items.push_back(
new YItem(
"false"));
177 combo->
setValue(prop_value.boolVal() ?
"true" :
"false");
179 else if (type == YIntegerProperty)
181 intfield = f->createIntField(vbox, property,
184 std::numeric_limits<int>::min(),
185 std::numeric_limits<int>::max(),
186 prop_value.integerVal());
189 else if (type == YStringProperty)
191 input = f->createInputField(vbox, property);
196 auto bbox = f->createButtonBox(vbox);
197 okButton = f->createPushButton(bbox,
"OK");
200 cancelButton = f->createPushButton(bbox,
"Cancel");
201 cancelButton->
setRole(YCancelButton);
205 void YPropertyEditorPriv::close()
219 bool YPropertyEditorPriv::run(
const string &property)
230 if (event->widget() == cancelButton || event->eventType() == YEvent::CancelEvent)
242 else if (event->widget() == okButton)
246 else if (event->widget() == combo)
248 string value = combo->
value();
249 yuiMilestone() <<
"Value changed to " << value;
253 else if (event->widget() == input)
255 string value = input->
value();
256 yuiMilestone() <<
"Value changed to " << value;
261 else if (event->widget() == intfield)
263 int value = intfield->
value();
264 yuiMilestone() <<
"Value changed to " << value;
273 bool YPropertyEditorPriv::editable(
const string &property)
278 if (isReadOnly(property))
284 YPropertyType type = prop_value.
type();
286 if (type != YBoolProperty && type != YStringProperty && type != YIntegerProperty)
297 return priv->edit(property);
307 YPropertyEditor::~YPropertyEditor()
void setValue(const std::string &newText)
Set the value of this ComboBox by string: Try to find a list item with that label and select it.
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
YEvent * waitForEvent(int timeout_millisec=0)
Wait for a user event.
std::string typeAsStr() const
Returns the type of this property value as string.
A set of properties to check names and types against.
std::string stringVal() const
Methods to get the value of this property.
void recalcLayout()
Recalculate the layout of the dialog and of all its children after children have been added or remove...
YPropertyType type() const
Returns the type of this property value.
const_iterator propertiesEnd() const
Returns an iterator that points after the last property in this set.
Class for widget properties.
bool edit(const std::string &property)
Display a popup for editing a widget property.
Abstract base class for events to be returned upon UI::UserInput() and related functions.
bool destroy(bool doThrow=true)
Close and delete this dialog (and all its children) if it is the topmost dialog.
YPropertyEditor(YWidget *widget)
Constructor.
ComboBox (or "drop down box", "drop down selection"); may be editable.
std::string name() const
Returns the name of this property.
const_iterator propertiesBegin() const
Returns an iterator that points to the first property in this set.
IntField: Input field for integer values.
Transport class for the value of simple properties.
std::string value()
Return the value of this ComboBox:
bool isReadOnly() const
Returns 'true' if this property cannot be changed, only retrieved.
virtual int value()=0
Get the current value (the number entered by the user or set from the outside) of this IntField.
static YWidgetFactory * widgetFactory()
Return the widget factory that provides all the createXY() methods for standard (mandatory,...
Base class for UI Exceptions.
A window in the desktop environment.
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.