1 /*! 2 @file 3 @author Georgiy Evmenov 4 @date 09/2008 5 */ 6 7 #include "Precompiled.h" 8 #include "PanelProperties.h" 9 #include "Localise.h" 10 #include "EditorWidgets.h" 11 #include "PropertyFieldManager.h" 12 #include "UndoManager.h" 13 14 namespace tools 15 { 16 PanelProperties()17 PanelProperties::PanelProperties() : 18 BasePanelViewItem("PanelProperties.layout"), 19 mDepth(0), 20 mCurrentWidget(nullptr) 21 { 22 } 23 initialise()24 void PanelProperties::initialise() 25 { 26 mPanelCell->setCaption(replaceTags("Widget_type_propertes")); 27 } 28 shutdown()29 void PanelProperties::shutdown() 30 { 31 destroyPropertyFields(); 32 } 33 setDepth(size_t _value)34 void PanelProperties::setDepth(size_t _value) 35 { 36 mDepth = _value; 37 } 38 getDepth() const39 size_t PanelProperties::getDepth() const 40 { 41 return mDepth; 42 } 43 addParametrs(WidgetStyle * widgetType,WidgetContainer * widgetContainer,MyGUI::Widget * _currentWidget)44 size_t PanelProperties::addParametrs(WidgetStyle* widgetType, WidgetContainer* widgetContainer, MyGUI::Widget* _currentWidget) 45 { 46 size_t result = 0; 47 48 for (MyGUI::VectorStringPairs::iterator iter = widgetType->parameter.begin(); iter != widgetType->parameter.end(); ++iter) 49 { 50 std::string value = widgetContainer->getProperty(iter->first); 51 52 // TODO: add extra property to WidgetStyle.parameter 53 if (iter->first == "Depth" && mCurrentWidget->isRootWidget()) 54 continue; 55 56 IPropertyField* field = getPropertyField(mWidgetClient, iter->first, iter->second); 57 field->setTarget(_currentWidget); 58 field->setValue(value); 59 60 result ++; 61 } 62 63 return result; 64 } 65 update(MyGUI::Widget * _currentWidget,WidgetStyle * _widgetType)66 void PanelProperties::update(MyGUI::Widget* _currentWidget, WidgetStyle* _widgetType) 67 { 68 hidePropertyFields(); 69 70 mCurrentWidget = _currentWidget; 71 if (mCurrentWidget == nullptr) 72 return; 73 74 WidgetContainer* widgetContainer = EditorWidgets::getInstance().find(_currentWidget); 75 76 MyGUI::LanguageManager::getInstance().addUserTag("widget_type", _widgetType->name); 77 78 mPanelCell->setCaption(replaceTags("Widget_type_propertes")); 79 80 size_t count = addParametrs(_widgetType, widgetContainer, mCurrentWidget); 81 82 setVisible(count > 0); 83 84 updateSize(); 85 } 86 updateSize()87 void PanelProperties::updateSize() 88 { 89 int height = 0; 90 91 for (MapPropertyField::iterator item = mFields.begin(); item != mFields.end(); ++ item) 92 { 93 if ((*item).second->getVisible()) 94 { 95 MyGUI::IntSize size = (*item).second->getContentSize(); 96 (*item).second->setCoord(MyGUI::IntCoord(0, height, mMainWidget->getWidth(), size.height)); 97 height += size.height; 98 } 99 } 100 101 mPanelCell->setClientHeight(height); 102 } 103 destroyPropertyFields()104 void PanelProperties::destroyPropertyFields() 105 { 106 for (MapPropertyField::iterator item = mFields.begin(); item != mFields.end(); ++ item) 107 delete (*item).second; 108 mFields.clear(); 109 } 110 notifyAction(const std::string & _name,const std::string & _value,bool _final)111 void PanelProperties::notifyAction(const std::string& _name, const std::string& _value, bool _final) 112 { 113 WidgetContainer* widgetContainer = EditorWidgets::getInstance().find(mCurrentWidget); 114 115 EditorWidgets::getInstance().tryToApplyProperty(widgetContainer->getWidget(), _name, _value); 116 117 if (_final) 118 { 119 if (_value.empty()) 120 widgetContainer->clearProperty(_name); 121 else 122 widgetContainer->setProperty(_name, _value); 123 124 UndoManager::getInstance().addValue(PR_PROPERTIES); 125 } 126 } 127 hidePropertyFields()128 void PanelProperties::hidePropertyFields() 129 { 130 for (MapPropertyField::iterator item = mFields.begin(); item != mFields.end(); ++ item) 131 (*item).second->setVisible(false); 132 } 133 getPropertyField(MyGUI::Widget * _client,const std::string & _name,const std::string & _type)134 IPropertyField* PanelProperties::getPropertyField(MyGUI::Widget* _client, const std::string& _name, const std::string& _type) 135 { 136 MapPropertyField::iterator item = mFields.find(_name); 137 if (item != mFields.end()) 138 { 139 (*item).second->setVisible(true); 140 return (*item).second; 141 } 142 143 IPropertyField* result = PropertyFieldManager::getInstance().createPropertyField(_client, _type); 144 result->setName(_name); 145 result->eventAction = MyGUI::newDelegate(this, &PanelProperties::notifyAction); 146 147 mFields[_name] = result; 148 149 return result; 150 } 151 152 } 153