diff --git a/clients/qt4/qt4client.cpp b/clients/qt4/qt4client.cpp index 2a967089..3d71e6b3 100644 --- a/clients/qt4/qt4client.cpp +++ b/clients/qt4/qt4client.cpp @@ -2280,7 +2280,10 @@ void QtWindow::doInit() if (sect && *sect && *sect != "general") addDynamicProps(qFindChild(this,sect->c_str()),*sect); } - + + // Process "_yate_setaction" property for our children + QtClient::setAction(this); + // Connect actions' signal QList actions = qFindChildren(this); for (int i = 0; i < actions.size(); i++) { @@ -2302,10 +2305,8 @@ void QtWindow::doInit() // Connect abstract buttons (check boxes and radio/push/tool buttons) signals QList buttons = qFindChildren(this); for(int i = 0; i < buttons.size(); i++) - if (buttons[i]->isCheckable()) - QtClient::connectObjects(buttons[i],SIGNAL(toggled(bool)),this,SLOT(toggled(bool))); - else - QtClient::connectObjects(buttons[i],SIGNAL(clicked()),this,SLOT(action())); + if (QtClient::autoConnect(buttons[i])) + connectButton(buttons[i]); // Connect group boxes signals QList grp = qFindChildren(this); @@ -2751,6 +2752,22 @@ bool QtClient::getProperty(QObject* obj, const char* name, String& value) return false; } +// Associate actions to buttons with '_yate_setaction' property set +void QtClient::setAction(QWidget* parent) +{ + if (!parent) + return; + QList tb = qFindChildren(parent); + for (int i = 0; i < tb.size(); i++) { + QVariant var = tb[i]->property("_yate_setaction"); + if (var.toString().isEmpty()) + continue; + QAction* a = qFindChild(parent,var.toString()); + if (a) + tb[i]->setDefaultAction(a); + } +} + // Build a menu object from a list of parameters QMenu* QtClient::buildMenu(NamedList& params, const char* text, QObject* receiver, const char* triggerSlot, const char* toggleSlot, QWidget* parent, diff --git a/clients/qt4/qt4client.h b/clients/qt4/qt4client.h index 294df015..1e4a5a33 100644 --- a/clients/qt4/qt4client.h +++ b/clients/qt4/qt4client.h @@ -232,6 +232,36 @@ public: */ static bool getProperty(QObject* obj, const char* name, String& value); + /** + * Get an object's property and return its boolean conversion + * @param obj The object + * @param name Property name + * @param defVal Default value to return if the property is not found or has + * invalid boolean value + * @return The boolean conversion of the property or given default value + */ + static inline bool getBoolProperty(QObject* obj, const char* name, + bool defVal = false) { + String tmp; + if (!getProperty(obj,name,tmp)) + return defVal; + return tmp.toBoolean(defVal); + } + + /** + * Associate actions to buttons with '_yate_setaction' property set + * @param parent Parent widget + */ + static void setAction(QWidget* parent); + + /** + * Check if an object has '_yate_noautoconnect' boolean property set to true + * @param obj The object + * @return True if the object don't have the property or its value is not a boolean 'true' + */ + static inline bool autoConnect(QObject* obj) + { return !getBoolProperty(obj,"_yate_noautoconnect"); } + /** * Retrieve an object's identity from '_yate_identity' property or object name * @param obj The object @@ -420,6 +450,19 @@ public: virtual bool related(const Window* wnd) const; virtual void menu(int x, int y) ; + /** + * Connect an abstract button to window slots + * @param b The button to connect + * @return True on success + */ + inline bool connectButton(QAbstractButton* b) { + if (!b) + return false; + if (!b->isCheckable()) + return QtClient::connectObjects(b,SIGNAL(clicked()),this,SLOT(action())); + return QtClient::connectObjects(b,SIGNAL(toggled(bool)),this,SLOT(toggled(bool))); + } + /** * Load a widget from file * @param fileName UI filename to load