From 9e98221cebf773c28d62140ff756c22c5fced2c2 Mon Sep 17 00:00:00 2001 From: marian Date: Fri, 27 Mar 2009 12:17:49 +0000 Subject: [PATCH] Added custom QObject descendant class. Handle it when building custom widgets and setting window parameters. git-svn-id: http://yate.null.ro/svn/yate/trunk@2546 acf43c95-373e-0410-b603-e72c3f656dc1 --- clients/qt4/qt4client.cpp | 32 +++++++++++++++++++++++++++----- clients/qt4/qt4client.h | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/clients/qt4/qt4client.cpp b/clients/qt4/qt4client.cpp index 878ec7a3..80814d91 100644 --- a/clients/qt4/qt4client.cpp +++ b/clients/qt4/qt4client.cpp @@ -75,11 +75,12 @@ public: Action, // QAction descendant CustomTable, // QtTable descendant CustomWidget, // QtCustomWidget descendant + CustomObject, // QtCustomObject descendant Missing // Invalid pointer }; // Set widget from object inline QtWidget(QObject* w) - : m_widget(0), m_action(0), m_type(Missing) { + : m_widget(0), m_action(0), m_object(0), m_type(Missing) { if (!w) return; if (w->inherits("QWidget")) @@ -90,17 +91,20 @@ public: } // Set widget from object and type inline QtWidget(QWidget* w, int t) - : m_widget(w), m_action(0), m_type(t) { + : m_widget(w), m_action(0), m_object(0), m_type(t) { if (!m_widget) m_type = Missing; } // Set widget/action from object and name inline QtWidget(QtWindow* wnd, const String& name) - : m_widget(0), m_action(0), m_type(Missing) { + : m_widget(0), m_action(0), m_object(0), m_type(Missing) { QString what = QtClient::setUtf8(name); m_widget = qFindChild(wnd,what); - if (!m_widget) + if (!m_widget) { m_action = qFindChild(wnd,what); + if (!m_action) + m_object = qFindChild(wnd,what); + } m_type = getType(); } inline bool valid() const @@ -154,6 +158,8 @@ public: { return qobject_cast(m_widget); } inline QtCustomWidget* customWidget() { return qobject_cast(m_widget); } + inline QtCustomObject* customObject() + { return qobject_cast(m_object); } inline QAction* action() { return m_action; } @@ -171,12 +177,15 @@ public: } if (m_action && m_action->inherits("QAction")) return Action; + if (customObject()) + return CustomObject; return Missing; } static String s_types[Unknown]; protected: QWidget* m_widget; QAction* m_action; + QObject* m_object; int m_type; private: QtWidget() {} @@ -825,6 +834,8 @@ bool QtWindow::setParams(const NamedList& params) ok = w.customTable()->setParams(*nl) && ok; else if (w.type() == QtWidget::CustomWidget) ok = w.customWidget()->setParams(*nl) && ok; + else if (w.type() == QtWidget::CustomObject) + ok = w.customObject()->setParams(*nl) && ok; else ok = false; } @@ -2094,7 +2105,18 @@ void QtWindow::doInit() } } TelEngine::destruct(list); - setWidget(frm[i],(QWidget*)UIFactory::build(type,name,¶ms)); + QObject* obj = (QObject*)UIFactory::build(type,name,¶ms); + if (!obj) + continue; + QWidget* wid = qobject_cast(obj); + if (wid) + setWidget(frm[i],wid); + else { + obj->setParent(frm[i]); + QtCustomObject* customObj = qobject_cast(obj); + if (customObj) + customObj->parentChanged(); + } } // Create window's children dynamic properties from config diff --git a/clients/qt4/qt4client.h b/clients/qt4/qt4client.h index 9ea5156a..0afa42bc 100644 --- a/clients/qt4/qt4client.h +++ b/clients/qt4/qt4client.h @@ -64,6 +64,8 @@ class QtEventProxy; // Proxy to global QT events class QtClient; // The QT based client class QtDriver; // The QT based telephony driver class QtWindow; // A QT window +class QtCustomObject; // A custom QT object +class QtCustomWidget; // A custom QT widget class QtTable; // A custom QT table widget class QtSound; // A QT client sound @@ -479,8 +481,37 @@ protected: }; /** - * This class encapsulates a custom QT table - * @short A custom QT table widget + * This class encapsulates a custom QT object + * @short A custom QT object + */ +class YQT4_API QtCustomObject : public QObject, public UIWidget +{ + YCLASS(QtCustomObject,UIWidget) + Q_CLASSINFO("QtCustomObject","Yate") + Q_OBJECT +public: + /** + * Constructor + * @param name Object's name + * @param parent Optional parent object + */ + inline QtCustomObject(const char* name, QObject* parent = 0) + : QObject(parent), UIWidget(name) + { setObjectName(name); } + + /** + * Parent changed notification + */ + virtual void parentChanged() + {} + +private: + QtCustomObject() {} // No default constructor +}; + +/** + * This class encapsulates a custom QT widget + * @short A custom QT widget */ class YQT4_API QtCustomWidget : public QWidget, public UIWidget {