qWarning("cast went wrong in data_clear");
}
+// DeclarativeHBoxLayout
+DeclarativeHBoxLayout::DeclarativeHBoxLayout(QObject *parent)
+ : DeclarativeObject(parent)
+ , m_layout(new QHBoxLayout)
+{
+ connectAllSignals(m_layout, this);
+}
+
+DeclarativeHBoxLayout::~DeclarativeHBoxLayout()
+{
+ delete m_layout;
+}
+
+QObject* DeclarativeHBoxLayout::object()
+{
+ return m_layout;
+}
+
+void DeclarativeHBoxLayout::dataAppend(QObject *object)
+{
+ DeclarativeWidget *widget = dynamic_cast<DeclarativeWidget*>(object);
+ DeclarativeHBoxLayout *hboxLayout = dynamic_cast<DeclarativeHBoxLayout*>(object);
+ DeclarativeVBoxLayout *vboxLayout = dynamic_cast<DeclarativeVBoxLayout*>(object);
+
+ if (widget) {
+ m_children.append(object);
+ m_layout->addWidget(qobject_cast<QWidget*>(widget->object()));
+ } else if (hboxLayout) {
+ m_children.append(object);
+ m_layout->addLayout(qobject_cast<QLayout*>(hboxLayout->object()));
+ } else if (vboxLayout) {
+ m_children.append(object);
+ m_layout->addLayout(qobject_cast<QLayout*>(vboxLayout->object()));
+ } else {
+ // TODO: error unknown type
+ }
+}
+
+int DeclarativeHBoxLayout::dataCount()
+{
+ return m_children.count();
+}
+
+QObject* DeclarativeHBoxLayout::dataAt(int index)
+{
+ return m_children.at(index);
+}
+
+void DeclarativeHBoxLayout::dataClear()
+{
+ qDeleteAll(m_children);
+ m_children.clear();
+}
+
+CUSTOM_METAOBJECT(DeclarativeHBoxLayout, DeclarativeObject, QHBoxLayout, m_layout)
+
// DeclarativeVBoxLayout
DeclarativeVBoxLayout::DeclarativeVBoxLayout(QObject *parent)
: DeclarativeObject(parent)
void DeclarativeVBoxLayout::dataAppend(QObject *object)
{
DeclarativeWidget *widget = dynamic_cast<DeclarativeWidget*>(object);
- DeclarativeVBoxLayout *layout = dynamic_cast<DeclarativeVBoxLayout*>(object);
+ DeclarativeHBoxLayout *hboxLayout = dynamic_cast<DeclarativeHBoxLayout*>(object);
+ DeclarativeVBoxLayout *vboxLayout = dynamic_cast<DeclarativeVBoxLayout*>(object);
if (widget) {
m_children.append(object);
m_layout->addWidget(qobject_cast<QWidget*>(widget->object()));
- } else if (layout) {
+ } else if (hboxLayout) {
m_children.append(object);
- m_layout->addLayout(qobject_cast<QLayout*>(layout->object()));
+ m_layout->addLayout(qobject_cast<QLayout*>(hboxLayout->object()));
+ } else if (vboxLayout) {
+ m_children.append(object);
+ m_layout->addLayout(qobject_cast<QLayout*>(vboxLayout->object()));
} else {
// TODO: error unknown type
}
void DeclarativeWidget::dataAppend(QObject *object)
{
DeclarativeWidget *widget = dynamic_cast<DeclarativeWidget*>(object);
- DeclarativeVBoxLayout *layout = dynamic_cast<DeclarativeVBoxLayout*>(object);
+ DeclarativeHBoxLayout *hboxLayout = dynamic_cast<DeclarativeHBoxLayout*>(object);
+ DeclarativeVBoxLayout *vboxLayout = dynamic_cast<DeclarativeVBoxLayout*>(object);
if (widget) {
// TODO: error when layout is set
m_children.append(object);
qobject_cast<QWidget*>(widget->object())->setParent(m_widget);
- } else if (layout) {
+ } else if (hboxLayout) {
// TODO: error when widget is set
- m_children.append(layout);
- m_widget->setLayout(qobject_cast<QVBoxLayout*>(layout->object()));
+ m_children.append(object);
+ m_widget->setLayout(qobject_cast<QLayout*>(hboxLayout->object()));
+ } else if (vboxLayout) {
+ // TODO: error when widget is set
+
+ m_children.append(object);
+ m_widget->setLayout(qobject_cast<QLayout*>(vboxLayout->object()));
} else {
// TODO: error unknown type
}
#include <QtCore/QObject>
#include <QtCore/QPointer>
#include <QtGui/QCheckBox>
+#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
static void data_clear(QDeclarativeListProperty<QObject> *);
};
+class DeclarativeHBoxLayout : public DeclarativeObject
+{
+ DECLARATIVE_OBJECT
+
+ public:
+ DeclarativeHBoxLayout(QObject *parent = 0);
+ ~DeclarativeHBoxLayout();
+
+ virtual QObject* object();
+
+ virtual void dataAppend(QObject *);
+ virtual int dataCount();
+ virtual QObject *dataAt(int);
+ virtual void dataClear();
+
+ private:
+ QPointer<QHBoxLayout> m_layout;
+ QVector<QObject*> m_children;
+};
+
class DeclarativeVBoxLayout : public DeclarativeObject
{
DECLARATIVE_OBJECT
: QObject(parent)
, d(new Private(this, url))
{
- qmlRegisterType<DeclarativeWidget>("qtgui.widgets", 1, 0, "Widget");
- qmlRegisterType<DeclarativeLabel>("qtgui.widgets", 1, 0, "Label");
- qmlRegisterType<DeclarativeVBoxLayout>("qtgui.widgets", 1, 0, "VBoxLayout");
- qmlRegisterType<DeclarativeTabWidget>("qtgui.widgets", 1, 0, "TabWidget");
- qmlRegisterType<DeclarativePushButton>("qtgui.widgets", 1, 0, "PushButton");
+ qmlRegisterType<DeclarativeWidget>("QtGui", 1, 0, "Widget");
+ qmlRegisterType<DeclarativeLabel>("QtGui", 1, 0, "Label");
+ qmlRegisterType<DeclarativeHBoxLayout>("QtGui", 1, 0, "HBoxLayout");
+ qmlRegisterType<DeclarativeVBoxLayout>("QtGui", 1, 0, "VBoxLayout");
+ qmlRegisterType<DeclarativeTabWidget>("QtGui", 1, 0, "TabWidget");
+ qmlRegisterType<DeclarativePushButton>("QtGui", 1, 0, "PushButton");
+ qmlRegisterType<DeclarativeCheckBox>("QtGui", 1, 0, "CheckBox");
d->m_component->loadUrl(d->m_url);
if (d->m_component->isError()) {