Handle _yate_setaction property: associate a QToolButton with an existing QAction. Handle _yate_noautoconnect property: don't connect buttons to window slots.
git-svn-id: http://yate.null.ro/svn/yate/trunk@3173 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
8145b0fe96
commit
bd58381dbb
|
@ -2280,7 +2280,10 @@ void QtWindow::doInit()
|
|||
if (sect && *sect && *sect != "general")
|
||||
addDynamicProps(qFindChild<QObject*>(this,sect->c_str()),*sect);
|
||||
}
|
||||
|
||||
|
||||
// Process "_yate_setaction" property for our children
|
||||
QtClient::setAction(this);
|
||||
|
||||
// Connect actions' signal
|
||||
QList<QAction*> actions = qFindChildren<QAction*>(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<QAbstractButton*> buttons = qFindChildren<QAbstractButton*>(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<QGroupBox*> grp = qFindChildren<QGroupBox*>(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<QToolButton*> tb = qFindChildren<QToolButton*>(parent);
|
||||
for (int i = 0; i < tb.size(); i++) {
|
||||
QVariant var = tb[i]->property("_yate_setaction");
|
||||
if (var.toString().isEmpty())
|
||||
continue;
|
||||
QAction* a = qFindChild<QAction*>(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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue