CUSTOM_METAOBJECT(DeclarativeSeparator, QAction)
//// Layouts ////
+class DeclarativeBoxLayoutAttached::Private
+{
+ public:
+ Private() : stretch(0), alignment(0) {}
+
+ int stretch;
+ Qt::Alignment alignment;
+};
+
+DeclarativeBoxLayoutAttached::DeclarativeBoxLayoutAttached(QObject *parent)
+ : QObject(parent), d(new Private)
+{
+}
+
+DeclarativeBoxLayoutAttached::~DeclarativeBoxLayoutAttached()
+{
+ delete d;
+}
+
+void DeclarativeBoxLayoutAttached::setStretch(int stretch)
+{
+ if (stretch == d->stretch)
+ return;
+
+ d->stretch = stretch;
+ emit stretchChanged(stretch);
+}
+
+int DeclarativeBoxLayoutAttached::stretch() const
+{
+ return d->stretch;
+}
+
+void DeclarativeBoxLayoutAttached::setAlignment(Qt::Alignment alignment)
+{
+ if (alignment == d->alignment)
+ return;
+
+ d->alignment = alignment;
+ emit alignmentChanged(alignment);
+}
+
+Qt::Alignment DeclarativeBoxLayoutAttached::alignment() const
+{
+ return d->alignment;
+}
// DeclarativeHBoxLayout
DeclarativeHBoxLayout::DeclarativeHBoxLayout(QObject *parent) : DeclarativeBoxLayout<QHBoxLayout>(parent)
connectAllSignals(m_proxiedObject, this);
}
+DeclarativeBoxLayoutAttached *DeclarativeHBoxLayout::qmlAttachedProperties(QObject *parent)
+{
+ return new DeclarativeBoxLayoutAttached(parent);
+}
+
+void DeclarativeHBoxLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject)
+{
+ int stretch = 0;
+ Qt::Alignment alignment = 0;
+
+ QObject *attachedProperties = qmlAttachedPropertiesObject<DeclarativeHBoxLayout>(declarativeObject, false);
+ DeclarativeBoxLayoutAttached *properties = qobject_cast<DeclarativeBoxLayoutAttached*>(attachedProperties);
+ if (properties) {
+ stretch = properties->stretch();
+ alignment = properties->alignment();
+ }
+
+ m_proxiedObject->addWidget(widget, stretch, alignment);
+ m_children.append(declarativeObject);
+}
+
CUSTOM_METAOBJECT(DeclarativeHBoxLayout, QHBoxLayout)
// DeclarativeVBoxLayout
connectAllSignals(m_proxiedObject, this);
}
+DeclarativeBoxLayoutAttached *DeclarativeVBoxLayout::qmlAttachedProperties(QObject *parent)
+{
+ return new DeclarativeBoxLayoutAttached(parent);
+}
+
+void DeclarativeVBoxLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject)
+{
+ int stretch = 0;
+ Qt::Alignment alignment = 0;
+
+ QObject *attachedProperties = qmlAttachedPropertiesObject<DeclarativeVBoxLayout>(declarativeObject, false);
+ DeclarativeBoxLayoutAttached *properties = qobject_cast<DeclarativeBoxLayoutAttached*>(attachedProperties);
+ if (properties) {
+ stretch = properties->stretch();
+ alignment = properties->alignment();
+ }
+
+ m_proxiedObject->addWidget(widget, stretch, alignment);
+ m_children.append(declarativeObject);
+}
+
CUSTOM_METAOBJECT(DeclarativeVBoxLayout, QVBoxLayout)
//// Widgets ////
};
//// Layouts ////
+class DeclarativeBoxLayoutAttached : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged)
+ Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
+
+ public:
+ DeclarativeBoxLayoutAttached(QObject *parent);
+ ~DeclarativeBoxLayoutAttached();
+
+ void setStretch(int stretch);
+ int stretch() const;
+
+ void setAlignment(Qt::Alignment alignment);
+ Qt::Alignment alignment() const;
+
+ Q_SIGNALS:
+ void stretchChanged(int stretch);
+ void alignmentChanged(Qt::Alignment alignment);
+
+ private:
+ class Private;
+ Private *const d;
+};
+
template <class T>
class DeclarativeBoxLayout : public DeclarativeObjectProxy<T>
{
if (declarativeObject) {
QWidget *widget = qobject_cast<QWidget*>(declarativeObject->object());
if (widget) {
- DeclarativeObjectProxy<T>::m_children.append(object);
- DeclarativeObjectProxy<T>::m_proxiedObject->addWidget(widget);
+ addWidget(widget, declarativeObject);
return;
}
DeclarativeObjectProxy<T>::dataAppend(object);
}
+
+ virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) = 0;
};
class DeclarativeHBoxLayout : public DeclarativeBoxLayout<QHBoxLayout>
public:
DeclarativeHBoxLayout(QObject *parent = 0);
+
+ static DeclarativeBoxLayoutAttached *qmlAttachedProperties(QObject *parent);
+
+ protected:
+ void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject);
};
+
+QML_DECLARE_TYPEINFO(DeclarativeHBoxLayout, QML_HAS_ATTACHED_PROPERTIES)
+
class DeclarativeVBoxLayout : public DeclarativeBoxLayout<QVBoxLayout>
{
DECLARATIVE_OBJECT
public:
DeclarativeVBoxLayout(QObject *parent = 0);
+
+ static DeclarativeBoxLayoutAttached *qmlAttachedProperties(QObject *parent);
+
+ protected:
+ void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject);
};
+QML_DECLARE_TYPEINFO(DeclarativeVBoxLayout, QML_HAS_ATTACHED_PROPERTIES)
+
//// Widgets ////
class DeclarativeCalendarWidget : public DeclarativeWidgetProxy<QCalendarWidget>
{