From d3e1061dbf5d1378d17f2a7dc48a051336383981 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Fri, 2 Nov 2012 12:13:35 +0100 Subject: [PATCH] Split declarativeobjects_p.h/cpp into separated files Moved files around to have a cleaner separation between library and application. Use GPL+KDAB copyright statement in all files. --- README | 1 + animation.qml | 31 - browser.qml | 38 - declarativeobjects.cpp | 1907 ------------------------- declarativeobjects_p.h | 1135 --------------- declarativewidgetdocument.cpp | 149 -- declarativewidgetdocument.h | 39 - declarativewidgets.pro | 153 ++- dialogs.qml | 143 -- editor.qml | 164 --- examples/animation.qml | 31 + examples/browser.qml | 38 + examples/dialogs.qml | 143 ++ examples/editor.qml | 164 +++ examples/filedialog.qml | 44 + examples/gallery.qml | 164 +++ examples/layouts.qml | 183 +++ examples/messagebox.qml | 62 + examples/test.qml | 91 ++ filedialog.qml | 44 - gallery.qml | 164 --- layouts.qml | 183 --- lib/abstractdeclarativeobject.cpp | 116 ++ lib/abstractdeclarativeobject_p.h | 59 + lib/declarativeaction.cpp | 29 + lib/declarativeaction_p.h | 37 + lib/declarativeactionitem.cpp | 29 + lib/declarativeactionitem_p.h | 36 + lib/declarativeboxlayout.cpp | 94 ++ lib/declarativeboxlayout_p.h | 55 + lib/declarativebuttongroup.cpp | 29 + lib/declarativebuttongroup_p.h | 36 + lib/declarativecalendarwidget.cpp | 29 + lib/declarativecalendarwidget_p.h | 36 + lib/declarativecheckbox.cpp | 29 + lib/declarativecheckbox_p.h | 36 + lib/declarativecolordialog.cpp | 112 ++ lib/declarativecolordialog_p.h | 70 + lib/declarativecolumnview.cpp | 29 + lib/declarativecolumnview_p.h | 36 + lib/declarativecommandlinkbutton.cpp | 29 + lib/declarativecommandlinkbutton_p.h | 36 + lib/declarativedateedit.cpp | 29 + lib/declarativedateedit_p.h | 36 + lib/declarativedatetimeedit.cpp | 29 + lib/declarativedatetimeedit_p.h | 36 + lib/declarativedial.cpp | 29 + lib/declarativedial_p.h | 36 + lib/declarativedialog.cpp | 29 + lib/declarativedialog_p.h | 36 + lib/declarativedialogbuttonbox.cpp | 29 + lib/declarativedialogbuttonbox_p.h | 36 + lib/declarativedoublespinbox.cpp | 29 + lib/declarativedoublespinbox_p.h | 36 + lib/declarativefiledialog.cpp | 178 +++ lib/declarativefiledialog_p.h | 91 ++ lib/declarativefontdialog.cpp | 29 + lib/declarativefontdialog_p.h | 36 + lib/declarativeformlayout.cpp | 95 ++ lib/declarativeformlayout_p.h | 65 + lib/declarativeframe.cpp | 29 + lib/declarativeframe_p.h | 36 + lib/declarativegridlayout.cpp | 212 +++ lib/declarativegridlayout_p.h | 88 ++ lib/declarativegroupbox.cpp | 29 + lib/declarativegroupbox_p.h | 36 + lib/declarativehboxlayout.cpp | 83 ++ lib/declarativehboxlayout_p.h | 45 + lib/declarativeinputdialog.cpp | 324 +++++ lib/declarativeinputdialog_p.h | 136 ++ lib/declarativelabel.cpp | 29 + lib/declarativelabel_p.h | 36 + lib/declarativelayoutproxy_p.h | 65 + lib/declarativelcdnumber.cpp | 29 + lib/declarativelcdnumber_p.h | 36 + lib/declarativelineedit.cpp | 29 + lib/declarativelineedit_p.h | 36 + lib/declarativelistview.cpp | 29 + lib/declarativelistview_p.h | 36 + lib/declarativemainwindow.cpp | 68 + lib/declarativemainwindow_p.h | 40 + lib/declarativemenu.cpp | 64 + lib/declarativemenu_p.h | 41 + lib/declarativemenubar.cpp | 64 + lib/declarativemenubar_p.h | 41 + lib/declarativemessagebox.cpp | 89 ++ lib/declarativemessagebox_p.h | 62 + lib/declarativeobjectproxy_p.h | 156 ++ lib/declarativeplaintextedit.cpp | 29 + lib/declarativeplaintextedit_p.h | 36 + lib/declarativeprogressbar.cpp | 29 + lib/declarativeprogressbar_p.h | 36 + lib/declarativepushbutton.cpp | 29 + lib/declarativepushbutton_p.h | 36 + lib/declarativeradiobutton.cpp | 29 + lib/declarativeradiobutton_p.h | 36 + lib/declarativescrollarea.cpp | 47 + lib/declarativescrollarea_p.h | 40 + lib/declarativescrollbar.cpp | 29 + lib/declarativescrollbar_p.h | 36 + lib/declarativeseparator.cpp | 29 + lib/declarativeseparator_p.h | 36 + lib/declarativeslider.cpp | 29 + lib/declarativeslider_p.h | 36 + lib/declarativespinbox.cpp | 29 + lib/declarativespinbox_p.h | 36 + lib/declarativestackedlayout.cpp | 40 + lib/declarativestackedlayout_p.h | 40 + lib/declarativestackedwidget.cpp | 40 + lib/declarativestackedwidget_p.h | 40 + lib/declarativestatusbar.cpp | 89 ++ lib/declarativestatusbar_p.h | 65 + lib/declarativetableview.cpp | 29 + lib/declarativetableview_p.h | 36 + lib/declarativetabwidget.cpp | 120 ++ lib/declarativetabwidget_p.h | 72 + lib/declarativetextbrowser.cpp | 29 + lib/declarativetextbrowser_p.h | 36 + lib/declarativetextedit.cpp | 29 + lib/declarativetextedit_p.h | 36 + lib/declarativetimeedit.cpp | 29 + lib/declarativetimeedit_p.h | 36 + lib/declarativetoolbar.cpp | 58 + lib/declarativetoolbar_p.h | 41 + lib/declarativetoolbutton.cpp | 29 + lib/declarativetoolbutton_p.h | 36 + lib/declarativetreeview.cpp | 29 + lib/declarativetreeview_p.h | 36 + lib/declarativevboxlayout.cpp | 83 ++ lib/declarativevboxlayout_p.h | 45 + lib/declarativewebview.cpp | 29 + lib/declarativewebview_p.h | 36 + lib/declarativewidget.cpp | 29 + lib/declarativewidget_p.h | 36 + lib/declarativewidgetproxy_p.h | 106 ++ lib/declarativewidgetsdocument.cpp | 222 +++ lib/declarativewidgetsdocument.h | 59 + lib/objectadaptors.cpp | 261 ++++ lib/objectadaptors_p.h | 216 +++ lib/qmetaobjectbuilder.cpp | 2601 ++++++++++++++++++++++++++++++++++ lib/qmetaobjectbuilder_p.h | 325 +++++ main.cpp | 24 +- messagebox.qml | 62 - objectadaptors.cpp | 240 ---- objectadaptors_p.h | 196 --- qmetaobjectbuilder.cpp | 2601 ---------------------------------- qmetaobjectbuilder_p.h | 325 ----- test.qml | 91 -- 148 files changed, 10542 insertions(+), 7532 deletions(-) create mode 100644 README delete mode 100644 animation.qml delete mode 100644 browser.qml delete mode 100644 declarativeobjects.cpp delete mode 100644 declarativeobjects_p.h delete mode 100644 declarativewidgetdocument.cpp delete mode 100644 declarativewidgetdocument.h delete mode 100644 dialogs.qml delete mode 100644 editor.qml create mode 100644 examples/animation.qml create mode 100644 examples/browser.qml create mode 100644 examples/dialogs.qml create mode 100644 examples/editor.qml create mode 100644 examples/filedialog.qml create mode 100644 examples/gallery.qml create mode 100644 examples/layouts.qml create mode 100644 examples/messagebox.qml create mode 100644 examples/test.qml delete mode 100644 filedialog.qml delete mode 100644 gallery.qml delete mode 100644 layouts.qml create mode 100644 lib/abstractdeclarativeobject.cpp create mode 100644 lib/abstractdeclarativeobject_p.h create mode 100644 lib/declarativeaction.cpp create mode 100644 lib/declarativeaction_p.h create mode 100644 lib/declarativeactionitem.cpp create mode 100644 lib/declarativeactionitem_p.h create mode 100644 lib/declarativeboxlayout.cpp create mode 100644 lib/declarativeboxlayout_p.h create mode 100644 lib/declarativebuttongroup.cpp create mode 100644 lib/declarativebuttongroup_p.h create mode 100644 lib/declarativecalendarwidget.cpp create mode 100644 lib/declarativecalendarwidget_p.h create mode 100644 lib/declarativecheckbox.cpp create mode 100644 lib/declarativecheckbox_p.h create mode 100644 lib/declarativecolordialog.cpp create mode 100644 lib/declarativecolordialog_p.h create mode 100644 lib/declarativecolumnview.cpp create mode 100644 lib/declarativecolumnview_p.h create mode 100644 lib/declarativecommandlinkbutton.cpp create mode 100644 lib/declarativecommandlinkbutton_p.h create mode 100644 lib/declarativedateedit.cpp create mode 100644 lib/declarativedateedit_p.h create mode 100644 lib/declarativedatetimeedit.cpp create mode 100644 lib/declarativedatetimeedit_p.h create mode 100644 lib/declarativedial.cpp create mode 100644 lib/declarativedial_p.h create mode 100644 lib/declarativedialog.cpp create mode 100644 lib/declarativedialog_p.h create mode 100644 lib/declarativedialogbuttonbox.cpp create mode 100644 lib/declarativedialogbuttonbox_p.h create mode 100644 lib/declarativedoublespinbox.cpp create mode 100644 lib/declarativedoublespinbox_p.h create mode 100644 lib/declarativefiledialog.cpp create mode 100644 lib/declarativefiledialog_p.h create mode 100644 lib/declarativefontdialog.cpp create mode 100644 lib/declarativefontdialog_p.h create mode 100644 lib/declarativeformlayout.cpp create mode 100644 lib/declarativeformlayout_p.h create mode 100644 lib/declarativeframe.cpp create mode 100644 lib/declarativeframe_p.h create mode 100644 lib/declarativegridlayout.cpp create mode 100644 lib/declarativegridlayout_p.h create mode 100644 lib/declarativegroupbox.cpp create mode 100644 lib/declarativegroupbox_p.h create mode 100644 lib/declarativehboxlayout.cpp create mode 100644 lib/declarativehboxlayout_p.h create mode 100644 lib/declarativeinputdialog.cpp create mode 100644 lib/declarativeinputdialog_p.h create mode 100644 lib/declarativelabel.cpp create mode 100644 lib/declarativelabel_p.h create mode 100644 lib/declarativelayoutproxy_p.h create mode 100644 lib/declarativelcdnumber.cpp create mode 100644 lib/declarativelcdnumber_p.h create mode 100644 lib/declarativelineedit.cpp create mode 100644 lib/declarativelineedit_p.h create mode 100644 lib/declarativelistview.cpp create mode 100644 lib/declarativelistview_p.h create mode 100644 lib/declarativemainwindow.cpp create mode 100644 lib/declarativemainwindow_p.h create mode 100644 lib/declarativemenu.cpp create mode 100644 lib/declarativemenu_p.h create mode 100644 lib/declarativemenubar.cpp create mode 100644 lib/declarativemenubar_p.h create mode 100644 lib/declarativemessagebox.cpp create mode 100644 lib/declarativemessagebox_p.h create mode 100644 lib/declarativeobjectproxy_p.h create mode 100644 lib/declarativeplaintextedit.cpp create mode 100644 lib/declarativeplaintextedit_p.h create mode 100644 lib/declarativeprogressbar.cpp create mode 100644 lib/declarativeprogressbar_p.h create mode 100644 lib/declarativepushbutton.cpp create mode 100644 lib/declarativepushbutton_p.h create mode 100644 lib/declarativeradiobutton.cpp create mode 100644 lib/declarativeradiobutton_p.h create mode 100644 lib/declarativescrollarea.cpp create mode 100644 lib/declarativescrollarea_p.h create mode 100644 lib/declarativescrollbar.cpp create mode 100644 lib/declarativescrollbar_p.h create mode 100644 lib/declarativeseparator.cpp create mode 100644 lib/declarativeseparator_p.h create mode 100644 lib/declarativeslider.cpp create mode 100644 lib/declarativeslider_p.h create mode 100644 lib/declarativespinbox.cpp create mode 100644 lib/declarativespinbox_p.h create mode 100644 lib/declarativestackedlayout.cpp create mode 100644 lib/declarativestackedlayout_p.h create mode 100644 lib/declarativestackedwidget.cpp create mode 100644 lib/declarativestackedwidget_p.h create mode 100644 lib/declarativestatusbar.cpp create mode 100644 lib/declarativestatusbar_p.h create mode 100644 lib/declarativetableview.cpp create mode 100644 lib/declarativetableview_p.h create mode 100644 lib/declarativetabwidget.cpp create mode 100644 lib/declarativetabwidget_p.h create mode 100644 lib/declarativetextbrowser.cpp create mode 100644 lib/declarativetextbrowser_p.h create mode 100644 lib/declarativetextedit.cpp create mode 100644 lib/declarativetextedit_p.h create mode 100644 lib/declarativetimeedit.cpp create mode 100644 lib/declarativetimeedit_p.h create mode 100644 lib/declarativetoolbar.cpp create mode 100644 lib/declarativetoolbar_p.h create mode 100644 lib/declarativetoolbutton.cpp create mode 100644 lib/declarativetoolbutton_p.h create mode 100644 lib/declarativetreeview.cpp create mode 100644 lib/declarativetreeview_p.h create mode 100644 lib/declarativevboxlayout.cpp create mode 100644 lib/declarativevboxlayout_p.h create mode 100644 lib/declarativewebview.cpp create mode 100644 lib/declarativewebview_p.h create mode 100644 lib/declarativewidget.cpp create mode 100644 lib/declarativewidget_p.h create mode 100644 lib/declarativewidgetproxy_p.h create mode 100644 lib/declarativewidgetsdocument.cpp create mode 100644 lib/declarativewidgetsdocument.h create mode 100644 lib/objectadaptors.cpp create mode 100644 lib/objectadaptors_p.h create mode 100644 lib/qmetaobjectbuilder.cpp create mode 100644 lib/qmetaobjectbuilder_p.h delete mode 100644 messagebox.qml delete mode 100644 objectadaptors.cpp delete mode 100644 objectadaptors_p.h delete mode 100644 qmetaobjectbuilder.cpp delete mode 100644 qmetaobjectbuilder_p.h delete mode 100644 test.qml diff --git a/README b/README new file mode 100644 index 0000000..460d822 --- /dev/null +++ b/README @@ -0,0 +1 @@ +If you wish to use this software in ways incompatible with the GPL, please contact sales@kdab.com, and we'll work something out. diff --git a/animation.qml b/animation.qml deleted file mode 100644 index 3d75237..0000000 --- a/animation.qml +++ /dev/null @@ -1,31 +0,0 @@ -import QtQuick 1.0 -import QtGui 1.0 - -Widget { - VBoxLayout { - PushButton { - id: button - text: anim.running ? qsTr("Stop animation") : qsTr("Start animation") - checkable: true - } - - Slider { - id: slider - - minimum: 0 - maximum: 100 - PropertyAnimation { - id: anim - - running: button.checked - target: slider - property: "value" - from: 0 - to: 100 - duration: 3000 - easing.type: Easing.InOutBounce - loops: Animation.Infinite - } - } - } -} diff --git a/browser.qml b/browser.qml deleted file mode 100644 index 18b3cc7..0000000 --- a/browser.qml +++ /dev/null @@ -1,38 +0,0 @@ -import QtGui 1.0 - -Widget { - id: mainWidget - - VBoxLayout { - - HBoxLayout { - PushButton { - text: qsTr("<") - onClicked: webView.back() - } - - PushButton { - text: qsTr(">") - onClicked: webView.forward() - } - - LineEdit { - id: urlInput - - onEditingFinished: webView.url = urlInput.text - } - - PushButton { - text: qsTr("Go") - onClicked: webView.url = urlInput.text - } - } - - WebView { - id: webView - - onTitleChanged: mainWidget.windowTitle = title - onUrlChanged: urlInput.text = url - } - } -} diff --git a/declarativeobjects.cpp b/declarativeobjects.cpp deleted file mode 100644 index 73dff26..0000000 --- a/declarativeobjects.cpp +++ /dev/null @@ -1,1907 +0,0 @@ -#include "declarativeobjects_p.h" - -#include "qmetaobjectbuilder_p.h" - -#include - -#define CUSTOM_METAOBJECT(ClassName, ProxyObjectType) \ -QMetaObject ClassName::staticMetaObject;\ -bool ClassName::metaObjectInitialized = ClassName::initializeMetaObject(); \ -bool ClassName::initializeMetaObject() \ -{ \ - QMetaObjectBuilder builder; \ - const QMetaObject *mo = &ProxyObjectType::staticMetaObject; \ - builder.addMetaObject(mo); \ - builder.addMetaObject(&AbstractDeclarativeObject::staticMetaObject); \ - builder.setSuperClass(ProxyObjectType::staticMetaObject.superClass()); \ - builder.setClassName(""#ClassName); \ - ClassName::staticMetaObject = *builder.toMetaObject(); \ - return true; \ -} \ -const QMetaObject &ClassName::getStaticMetaObject() \ -{ \ - return ClassName::staticMetaObject; \ -} \ -const QMetaObject* ClassName::metaObject() const \ -{ \ - return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; \ -} \ -void* ClassName::qt_metacast(const char*) \ -{ \ - return 0; \ -} \ -int ClassName::qt_metacall(QMetaObject::Call call, int id, void **argv) \ -{ \ - if (call == QMetaObject::ReadProperty || call == QMetaObject::WriteProperty) { \ - if (id >= ProxyObjectType::staticMetaObject.propertyCount()) { \ - id = AbstractDeclarativeObject::qt_metacall(call, id - ProxyObjectType::staticMetaObject.propertyCount() + 1, argv); \ - id += ProxyObjectType::staticMetaObject.propertyCount() - 1; \ - } else { \ - id = m_proxiedObject->qt_metacall(call, id, argv); \ - } \ - if (id < 0) \ - return 0; \ - } else if (call == QMetaObject::InvokeMetaMethod) {\ - if (ClassName::staticMetaObject.method(id).methodType() == QMetaMethod::Signal) \ - QMetaObject::activate(this, id, argv); \ - else \ - id = m_proxiedObject->qt_metacall(call, id, argv); \ - id -= 1; \ - } \ - return id; \ -} - -// AbstractDeclarativeObject -AbstractDeclarativeObject::AbstractDeclarativeObject(QObject *parent) - : QObject(parent) -{ -} - -AbstractDeclarativeObject::~AbstractDeclarativeObject() -{ -} - -QDeclarativeListProperty AbstractDeclarativeObject::data() -{ - return QDeclarativeListProperty(this, 0, AbstractDeclarativeObject::data_append, - AbstractDeclarativeObject::data_count, - AbstractDeclarativeObject::data_at, - AbstractDeclarativeObject::data_clear); -} - -void AbstractDeclarativeObject::dataAppend(QObject *) -{ -} - -int AbstractDeclarativeObject::dataCount() const -{ - return 0; -} - -QObject* AbstractDeclarativeObject::dataAt(int) const -{ - return 0; -} - -void AbstractDeclarativeObject::dataClear() -{ -} - -static void connectAllSignals(QObject *sender, QObject *receiver, const QSet &blacklist = QSet()) -{ - for (int i = 0; i < sender->metaObject()->methodCount(); ++i) { - const QMetaMethod method = sender->metaObject()->method(i); - if (method.methodType() == QMetaMethod::Signal) { - if (blacklist.contains(method.signature())) - continue; - - const QByteArray signature = "2" + QByteArray(method.signature()); - QObject::connect(sender, signature.data(), receiver, signature.data()); - } - } -} - -void AbstractDeclarativeObject::data_append(QDeclarativeListProperty *property, QObject *object) -{ - if (!object) - return; - - AbstractDeclarativeObject *that = dynamic_cast(property->object); - if (that) - that->dataAppend(object); - else - qWarning("cast went wrong in data_append"); -} - -int AbstractDeclarativeObject::data_count(QDeclarativeListProperty *property) -{ - AbstractDeclarativeObject *that = dynamic_cast(property->object); - if (that) - return that->dataCount(); - else { - qWarning("cast went wrong in data_count"); - return 0; - } -} - -QObject* AbstractDeclarativeObject::data_at(QDeclarativeListProperty *property, int index) -{ - AbstractDeclarativeObject *that = dynamic_cast(property->object); - if (that) - return that->dataAt(index); - else { - qWarning("cast went wrong in data_at"); - return 0; - } -} - -void AbstractDeclarativeObject::data_clear(QDeclarativeListProperty *property) -{ - AbstractDeclarativeObject *that = dynamic_cast(property->object); - if (that) - that->dataClear(); - else - qWarning("cast went wrong in data_clear"); -} - -//// Objects //// - -// DeclarativeAction -DeclarativeAction::DeclarativeAction(QObject *parent) : DeclarativeObjectProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeAction, QAction) - -// DeclarativeActionItem -DeclarativeActionItem::DeclarativeActionItem(QObject *parent) : DeclarativeObjectProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeActionItem, ActionItem) - -// DeclarativeButtonGroup -DeclarativeButtonGroup::DeclarativeButtonGroup(QObject *parent) : DeclarativeObjectProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeButtonGroup, ButtonGroup) - -// DeclarativeSeparator -DeclarativeSeparator::DeclarativeSeparator(QObject *parent) : DeclarativeObjectProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeSeparator, QAction) - -//// Layouts //// -class DeclarativeBoxLayoutAttached::Private -{ - public: - Private(QWidget *w, QLayout *l) : stretch(0), alignment(0), widget(w), layout(l) {} - - int stretch; - Qt::Alignment alignment; - - QPointer widget; - QPointer layout; - QPointer parentLayout; -}; - -DeclarativeBoxLayoutAttached::DeclarativeBoxLayoutAttached(QWidget *widget, QObject *parent) - : QObject(parent), d(new Private(widget, 0)) -{ -} - -DeclarativeBoxLayoutAttached::DeclarativeBoxLayoutAttached(QLayout *layout, QObject *parent) - : QObject(parent), d(new Private(0, layout)) -{ -} - -DeclarativeBoxLayoutAttached::~DeclarativeBoxLayoutAttached() -{ - delete d; -} - -void DeclarativeBoxLayoutAttached::setParentLayout(QBoxLayout *parentLayout) -{ - d->parentLayout = parentLayout; -} - -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); - - if (d->parentLayout) { - if (d->widget) - d->parentLayout->setAlignment(d->widget, d->alignment); - - if (d->layout) - d->parentLayout->setAlignment(d->layout, d->alignment); - } -} - -Qt::Alignment DeclarativeBoxLayoutAttached::alignment() const -{ - return d->alignment; -} - -class DeclarativeFormLayoutAttached::Private -{ - public: - QString label; -}; - -DeclarativeFormLayoutAttached::DeclarativeFormLayoutAttached(QObject *parent) - : QObject(parent), d(new Private) -{ -} - -DeclarativeFormLayoutAttached::~DeclarativeFormLayoutAttached() -{ - delete d; -} - -void DeclarativeFormLayoutAttached::setLabel(const QString &label) -{ - if (label == d->label) - return; - - d->label = label; - emit labelChanged(label); -} - -class DeclarativeGridLayoutAttached::Private -{ - public: - Private(QWidget *w, QLayout *l) - : row(0), column(0), rowSpan(1), columnSpan(1), alignment(0), - widget(w), layout(l) - {} - - int row; - int column; - int rowSpan; - int columnSpan; - Qt::Alignment alignment; - - QPointer widget; - QPointer layout; - QPointer parentLayout; -}; - -DeclarativeGridLayoutAttached::DeclarativeGridLayoutAttached(QWidget *widget, QObject *parent) - : QObject(parent), d(new Private(widget, 0)) -{ -} - -DeclarativeGridLayoutAttached::DeclarativeGridLayoutAttached(QLayout *layout, QObject *parent) - : QObject(parent), d(new Private(0, layout)) -{ -} - -DeclarativeGridLayoutAttached::~DeclarativeGridLayoutAttached() -{ - delete d; -} - -void DeclarativeGridLayoutAttached::setParentLayout(QGridLayout *parentLayout) -{ - d->parentLayout = parentLayout; -} - -void DeclarativeGridLayoutAttached::setRow(int row) -{ - if (row == d->row) - return; - - d->row = row; - emit rowChanged(row); -} - -int DeclarativeGridLayoutAttached::row() const -{ - return d->row; -} - -void DeclarativeGridLayoutAttached::setColumn(int column) -{ - if (column == d->column) - return; - - d->column = column; - emit columnChanged(column); -} - -int DeclarativeGridLayoutAttached::column() const -{ - return d->column; -} - -void DeclarativeGridLayoutAttached::setRowSpan(int rowSpan) -{ - if (rowSpan == d->rowSpan) - return; - - d->rowSpan = rowSpan; - emit rowSpanChanged(rowSpan); -} - -int DeclarativeGridLayoutAttached::rowSpan() const -{ - return d->rowSpan; -} - -void DeclarativeGridLayoutAttached::setColumnSpan(int columnSpan) -{ - if (columnSpan == d->columnSpan) - return; - - d->columnSpan = columnSpan; - emit columnSpanChanged(columnSpan); -} - -int DeclarativeGridLayoutAttached::columnSpan() const -{ - return d->columnSpan; -} - -void DeclarativeGridLayoutAttached::setAlignment(Qt::Alignment alignment) -{ - if (alignment == d->alignment) - return; - - d->alignment = alignment; - emit alignmentChanged(alignment); - - if (d->parentLayout) { - if (d->widget) - d->parentLayout->setAlignment(d->widget, d->alignment); - - if (d->layout) - d->parentLayout->setAlignment(d->layout, d->alignment); - } -} - -Qt::Alignment DeclarativeGridLayoutAttached::alignment() const -{ - return d->alignment; -} - -QString DeclarativeFormLayoutAttached::label() const -{ - return d->label; -} - -// DeclarativeFormLayout -DeclarativeFormLayout::DeclarativeFormLayout(QObject *parent) : DeclarativeLayoutProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeFormLayoutAttached *DeclarativeFormLayout::qmlAttachedProperties(QObject *parent) -{ - return new DeclarativeFormLayoutAttached(parent); -} - -void DeclarativeFormLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeFormLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - if (!properties->label().isEmpty()) { - m_proxiedObject->addRow(properties->label(), widget); - m_children.append(declarativeObject); - return; - } - } - - m_proxiedObject->addRow(widget); - m_children.append(declarativeObject); -} - -void DeclarativeFormLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeFormLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - if (!properties->label().isEmpty()) { - m_proxiedObject->addRow(properties->label(), layout); - m_children.append(declarativeObject); - return; - } - } - m_proxiedObject->addRow(layout); - m_children.append(declarativeObject); -} - -CUSTOM_METAOBJECT(DeclarativeFormLayout, QFormLayout) - -// DeclarativeGridLayout -DeclarativeGridLayout::DeclarativeGridLayout(QObject *parent) : DeclarativeLayoutProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeGridLayoutAttached *DeclarativeGridLayout::qmlAttachedProperties(QObject *parent) -{ - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) { - QWidget *widget = qobject_cast(declarativeObject->object()); - if (widget) - return new DeclarativeGridLayoutAttached(widget, parent); - - QLayout *layout = qobject_cast(declarativeObject->object()); - if (layout) - return new DeclarativeGridLayoutAttached(layout, parent); - } - - qmlInfo(parent) << "Can only attach GridLayout to widgets and layouts"; - return 0; -} - -void DeclarativeGridLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - int row = 0; - int column = 0; - int rowSpan = 1; - int columnSpan = 1; - Qt::Alignment alignment = 0; - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeGridLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - row = properties->row(); - column = properties->column(); - rowSpan = properties->rowSpan(); - columnSpan = properties->columnSpan(); - alignment = properties->alignment(); - - properties->setParentLayout(m_proxiedObject); - } - - m_proxiedObject->addWidget(widget, row, column, rowSpan, columnSpan, alignment); - m_children.append(declarativeObject); -} - -void DeclarativeGridLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - int row = 0; - int column = 0; - int rowSpan = 1; - int columnSpan = 1; - Qt::Alignment alignment = 0; - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeGridLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - row = properties->row(); - column = properties->column(); - rowSpan = properties->rowSpan(); - columnSpan = properties->columnSpan(); - alignment = properties->alignment(); - - properties->setParentLayout(m_proxiedObject); - } - - m_proxiedObject->addLayout(layout, row, column, rowSpan, columnSpan, alignment); - m_children.append(declarativeObject); -} - -CUSTOM_METAOBJECT(DeclarativeGridLayout, QGridLayout) - -// DeclarativeHBoxLayout -DeclarativeHBoxLayout::DeclarativeHBoxLayout(QObject *parent) : DeclarativeLayoutProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeBoxLayoutAttached *DeclarativeHBoxLayout::qmlAttachedProperties(QObject *parent) -{ - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) { - QWidget *widget = qobject_cast(declarativeObject->object()); - if (widget) - return new DeclarativeBoxLayoutAttached(widget, parent); - - QLayout *layout = qobject_cast(declarativeObject->object()); - if (layout) - return new DeclarativeBoxLayoutAttached(layout, parent); - } - - qmlInfo(parent) << "Can only attach HBoxLayout to widgets and layouts"; - return 0; -} - -void DeclarativeHBoxLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - int stretch = 0; - Qt::Alignment alignment = 0; - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - stretch = properties->stretch(); - alignment = properties->alignment(); - - properties->setParentLayout(m_proxiedObject); - } - - m_proxiedObject->addWidget(widget, stretch, alignment); - m_children.append(declarativeObject); -} - -void DeclarativeHBoxLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - int stretch = 0; - Qt::Alignment alignment = 0; - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - stretch = properties->stretch(); - alignment = properties->alignment(); - - properties->setParentLayout(m_proxiedObject); - } - - m_proxiedObject->addLayout(layout, stretch); - m_proxiedObject->setAlignment(layout, alignment); - m_children.append(declarativeObject); -} - -CUSTOM_METAOBJECT(DeclarativeHBoxLayout, QHBoxLayout) - -// DeclarativeStackedLayout -DeclarativeStackedLayout::DeclarativeStackedLayout(QObject *parent) : DeclarativeLayoutProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeStackedLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - m_proxiedObject->addWidget(widget); - m_children.append(declarativeObject); -} - -void DeclarativeStackedLayout::addLayout(QLayout*, AbstractDeclarativeObject *declarativeObject) -{ - qmlInfo(declarativeObject) << "StackedLayout does not support child layouts"; -} - -CUSTOM_METAOBJECT(DeclarativeStackedLayout, StackedLayout) - -// DeclarativeVBoxLayout -DeclarativeVBoxLayout::DeclarativeVBoxLayout(QObject *parent) : DeclarativeLayoutProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeBoxLayoutAttached *DeclarativeVBoxLayout::qmlAttachedProperties(QObject *parent) -{ - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) { - QWidget *widget = qobject_cast(declarativeObject->object()); - if (widget) - return new DeclarativeBoxLayoutAttached(widget, parent); - - QLayout *layout = qobject_cast(declarativeObject->object()); - if (layout) - return new DeclarativeBoxLayoutAttached(layout, parent); - } - - qmlInfo(parent) << "Can only attach VBoxLayout to widgets and layouts"; - return 0; -} - -void DeclarativeVBoxLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - int stretch = 0; - Qt::Alignment alignment = 0; - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - stretch = properties->stretch(); - alignment = properties->alignment(); - - properties->setParentLayout(m_proxiedObject); - } - - m_proxiedObject->addWidget(widget, stretch, alignment); - m_children.append(declarativeObject); -} - -void DeclarativeVBoxLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - int stretch = 0; - Qt::Alignment alignment = 0; - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); - if (properties) { - stretch = properties->stretch(); - alignment = properties->alignment(); - - properties->setParentLayout(m_proxiedObject); - } - - m_proxiedObject->addLayout(layout, stretch); - m_proxiedObject->setAlignment(layout, alignment); - m_children.append(declarativeObject); -} - -CUSTOM_METAOBJECT(DeclarativeVBoxLayout, QVBoxLayout) - -//// Widgets //// - -// DeclarativeCalendarWidget -DeclarativeCalendarWidget::DeclarativeCalendarWidget(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeCalendarWidget, QCalendarWidget) - -// DeclarativeCheckBox -DeclarativeCheckBox::DeclarativeCheckBox(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeCheckBox, QCheckBox) - -// DeclarativeColorDialog -class DeclarativeColorDialogAttached::Private -{ - public: - Private() : options(0) {} - - public: - QPointer dialogParent; - QString title; - QColorDialog::ColorDialogOptions options; -}; - -DeclarativeColorDialogAttached::DeclarativeColorDialogAttached(QObject *parent) - : QObject(parent), d(new Private) -{ -} - -DeclarativeColorDialogAttached::~DeclarativeColorDialogAttached() -{ - delete d; -} - -void DeclarativeColorDialogAttached::setDialogParent(QObject *parent) -{ - if (parent == d->dialogParent) - return; - - d->dialogParent = parent; - emit dialogParentChanged(parent); -} - -QObject *DeclarativeColorDialogAttached::dialogParent() const -{ - return d->dialogParent; -} - -void DeclarativeColorDialogAttached::setTitle(const QString &title) -{ - if (title == d->title) - return; - - d->title = title; - emit titleChanged(title); -} - -QString DeclarativeColorDialogAttached::title() const -{ - return d->title; -} - -QColor DeclarativeColorDialogAttached::getColor(const QColor &initialColor) -{ - QWidget *parent = bestParentWindow(d->dialogParent); - if (!d->title.isEmpty() || d->options != 0) - return QColorDialog::getColor(initialColor, parent, d->title, d->options); - else - return QColorDialog::getColor(initialColor, parent); -} - -QWidget *DeclarativeColorDialogAttached::bestParentWindow(QObject *parent) const -{ - if (!parent) - parent = this->parent(); - - // if parent is a Declarative Object, search the proxied hierarchy - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) - parent = declarativeObject->object(); - - while (parent) { - QWidget *widget = qobject_cast(parent); - if (widget) - return widget->topLevelWidget(); - - parent = parent->parent(); - } - - return 0; -} - -DeclarativeColorDialog::DeclarativeColorDialog(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeColorDialogAttached *DeclarativeColorDialog::qmlAttachedProperties(QObject *parent) -{ - return new DeclarativeColorDialogAttached(parent); -} - -CUSTOM_METAOBJECT(DeclarativeColorDialog, QColorDialog) - -// DeclarativeColumnView -DeclarativeColumnView::DeclarativeColumnView(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeColumnView, ColumnView) - -// DeclarativeCommandLinkButton -DeclarativeCommandLinkButton::DeclarativeCommandLinkButton(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeCommandLinkButton, QCommandLinkButton) - -// DeclarativeDateEdit -DeclarativeDateEdit::DeclarativeDateEdit(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeDateEdit, QDateEdit) - -// DeclarativeDateTimeEdit -DeclarativeDateTimeEdit::DeclarativeDateTimeEdit(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeDateTimeEdit, QDateTimeEdit) - -// DeclarativeDial -DeclarativeDial::DeclarativeDial(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeDial, QDial) - -// DeclarativeDialog -DeclarativeDialog::DeclarativeDialog(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeDialog, QDialog) - -// DeclarativeDialogButtonBox -DeclarativeDialogButtonBox::DeclarativeDialogButtonBox(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeDialogButtonBox, QDialogButtonBox) - -// DeclarativeDoubleSpinBox -DeclarativeDoubleSpinBox::DeclarativeDoubleSpinBox(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeDoubleSpinBox, QDoubleSpinBox) - -// DeclarativeFileDialog -class DeclarativeFileDialogAttached::Private -{ - public: - QPointer dialogParent; - QString caption; - QString dir; - QStringList nameFilters; - QString selectedFilter; -}; - -DeclarativeFileDialogAttached::DeclarativeFileDialogAttached(QObject *parent) - : QObject(parent), d(new Private) -{ -} - -DeclarativeFileDialogAttached::~DeclarativeFileDialogAttached() -{ - delete d; -} - -void DeclarativeFileDialogAttached::setDialogParent(QObject *parent) -{ - if (parent == d->dialogParent) - return; - - d->dialogParent = parent; - emit dialogParentChanged(parent); -} - -QObject *DeclarativeFileDialogAttached::dialogParent() const -{ - return d->dialogParent; -} - -void DeclarativeFileDialogAttached::setCaption(const QString &caption) -{ - if (caption == d->caption) - return; - - d->caption = caption; - emit captionChanged(caption); -} - -QString DeclarativeFileDialogAttached::caption() const -{ - return d->caption; -} - -void DeclarativeFileDialogAttached::setDir(const QString &dir) -{ - if (dir == d->dir) - return; - - d->dir = dir; - emit dirChanged(dir); -} - -QString DeclarativeFileDialogAttached::dir() const -{ - return d->dir; -} - -void DeclarativeFileDialogAttached::setNameFilters(const QStringList &nameFilters) -{ - if (nameFilters == d->nameFilters) - return; - - d->nameFilters = nameFilters; - emit nameFiltersChanged(nameFilters); -} - -QStringList DeclarativeFileDialogAttached::nameFilters() const -{ - return d->nameFilters; -} - -QString DeclarativeFileDialogAttached::selectedFilter() const -{ - return d->selectedFilter; -} - -QString DeclarativeFileDialogAttached::getExistingDirectory() -{ - return QFileDialog::getExistingDirectory(bestParentWindow(d->dialogParent), d->caption, d->dir, QFileDialog::ShowDirsOnly); -} - -QString DeclarativeFileDialogAttached::getOpenFileName() -{ - QString selectedFilter; - const QString retVal = QFileDialog::getOpenFileName(bestParentWindow(d->dialogParent), d->caption, d->dir, - d->nameFilters.join(";;"), &selectedFilter, 0); - setSelectedFilter(selectedFilter); - return retVal; -} - -QStringList DeclarativeFileDialogAttached::getOpenFileNames() -{ - QString selectedFilter; - const QStringList retVal = QFileDialog::getOpenFileNames(bestParentWindow(d->dialogParent), d->caption, d->dir, - d->nameFilters.join(";;"), &selectedFilter, 0); - setSelectedFilter(selectedFilter); - return retVal; -} - -QString DeclarativeFileDialogAttached::getSaveFileName() -{ - QString selectedFilter; - const QString retVal = QFileDialog::getSaveFileName(bestParentWindow(d->dialogParent), d->caption, d->dir, - d->nameFilters.join(";;"), &selectedFilter, 0); - setSelectedFilter(selectedFilter); - return retVal; -} - -QWidget *DeclarativeFileDialogAttached::bestParentWindow(QObject *parent) const -{ - if (!parent) - parent = this->parent(); - - // if parent is a Declarative Object, search the proxied hierarchy - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) - parent = declarativeObject->object(); - - while (parent) { - QWidget *widget = qobject_cast(parent); - if (widget) - return widget->topLevelWidget(); - - parent = parent->parent(); - } - - return 0; -} - -void DeclarativeFileDialogAttached::setSelectedFilter(const QString &filter) -{ - if (filter == d->selectedFilter) - return; - - d->selectedFilter = filter; - emit selectedFilterChanged(filter); -} - -DeclarativeFileDialog::DeclarativeFileDialog(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeFileDialogAttached *DeclarativeFileDialog::qmlAttachedProperties(QObject *parent) -{ - return new DeclarativeFileDialogAttached(parent); -} - -CUSTOM_METAOBJECT(DeclarativeFileDialog, FileDialog) - -// DeclarativeFontDialog -DeclarativeFontDialog::DeclarativeFontDialog(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeFontDialog, QFontDialog) - -// DeclarativeFrame -DeclarativeFrame::DeclarativeFrame(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeFrame, QFrame) - -// DeclarativeGroupBox -DeclarativeGroupBox::DeclarativeGroupBox(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeGroupBox, QGroupBox) - -// DeclarativeInputDialog -class DeclarativeInputDialogAttached::Private -{ - public: - Private() : dialogAccepted(false), - value(0), min(-2147483647), max(2147483647), decimals(1), step(1), - currentItem(0), itemsEditable(true), - echoMode(QLineEdit::Normal) - {} - - public: - QPointer dialogParent; - QString title; - QString label; - bool dialogAccepted; - - QVariant value; - QVariant min; - QVariant max; - int decimals; - int step; - - int currentItem; - bool itemsEditable; - - QLineEdit::EchoMode echoMode; - QString text; -}; - -DeclarativeInputDialogAttached::DeclarativeInputDialogAttached(QObject *parent) - : QObject(parent), d(new Private) -{ -} - -DeclarativeInputDialogAttached::~DeclarativeInputDialogAttached() -{ - delete d; -} - -void DeclarativeInputDialogAttached::setDialogParent(QObject *parent) -{ - if (parent == d->dialogParent) - return; - - d->dialogParent = parent; - emit dialogParentChanged(parent); -} - -QObject *DeclarativeInputDialogAttached::dialogParent() const -{ - return d->dialogParent; -} - -void DeclarativeInputDialogAttached::setTitle(const QString &title) -{ - if (title == d->title) - return; - - d->title = title; - emit titleChanged(title); -} - -QString DeclarativeInputDialogAttached::title() const -{ - return d->title; -} - -void DeclarativeInputDialogAttached::setLabel(const QString &label) -{ - if (label == d->label) - return; - - d->label = label; - emit labelChanged(label); -} - -QString DeclarativeInputDialogAttached::label() const -{ - return d->label; -} - -bool DeclarativeInputDialogAttached::dialogAccepted() const -{ - return d->dialogAccepted; -} - -void DeclarativeInputDialogAttached::setValue(const QVariant &value) -{ - if (value == d->value) - return; - - d->value = value; - emit valueChanged(value); -} - -QVariant DeclarativeInputDialogAttached::value() const -{ - return d->value; -} - -void DeclarativeInputDialogAttached::setMin(const QVariant &min) -{ - if (min == d->min) - return; - - d->min = min; - emit minChanged(min); -} - -QVariant DeclarativeInputDialogAttached::min() const -{ - return d->min; -} - -void DeclarativeInputDialogAttached::setMax(const QVariant &max) -{ - if (max == d->max) - return; - - d->max = max; - emit maxChanged(max); -} - -QVariant DeclarativeInputDialogAttached::max() const -{ - return d->max; -} - -void DeclarativeInputDialogAttached::setDecimals(int decimals) -{ - if (decimals == d->decimals) - return; - - d->decimals = decimals; - emit decimalsChanged(decimals); -} - -int DeclarativeInputDialogAttached::decimals() const -{ - return d->decimals; -} - -void DeclarativeInputDialogAttached::setStep(int step) -{ - if (step == d->step) - return; - - d->step = step; - emit stepChanged(step); -} - -int DeclarativeInputDialogAttached::step() const -{ - return d->step; -} - -void DeclarativeInputDialogAttached::setCurrentItem(int current) -{ - if (current == d->currentItem) - return; - - d->currentItem = current; - emit currentItemChanged(current); -} - -int DeclarativeInputDialogAttached::currentItem() const -{ - return d->currentItem; -} - -void DeclarativeInputDialogAttached::setItemsEditable(bool editable) -{ - if (editable == d->itemsEditable) - return; - - d->itemsEditable = editable; - emit itemsEditableChanged(editable); -} - -bool DeclarativeInputDialogAttached::itemsEditable() const -{ - return d->itemsEditable; -} - -void DeclarativeInputDialogAttached::setEchoMode(QLineEdit::EchoMode echoMode) -{ - if (echoMode == d->echoMode) - return; - - d->echoMode = echoMode; - emit echoModeChanged(echoMode); -} - -QLineEdit::EchoMode DeclarativeInputDialogAttached::echoMode() const -{ - return d->echoMode; -} - -void DeclarativeInputDialogAttached::setText(const QString &text) -{ - if (text == d->text) - return; - - d->text = text; - emit textChanged(text); -} - -QString DeclarativeInputDialogAttached::text() const -{ - return d->text; -} - -double DeclarativeInputDialogAttached::getDouble() -{ - QWidget *parent = bestParentWindow(d->dialogParent); - bool ok = false; - const double value = d->value.canConvert() ? d->value.value() : 0.0; - const double min = d->min.canConvert() ? d->min.value() : -2147483647; - const double max = d->max.canConvert() ? d->max.value() : 2147483647; - - const double retVal = QInputDialog::getDouble(parent, d->title, d->label, value, min, max, d->decimals, &ok); - - setDialogAccepted(ok); - return retVal; -} - -int DeclarativeInputDialogAttached::getInt() -{ - QWidget *parent = bestParentWindow(d->dialogParent); - bool ok = false; - const int value = d->value.canConvert() ? d->value.value() : 0; - const int min = d->min.canConvert() ? d->min.value() : -2147483647; - const int max = d->max.canConvert() ? d->max.value() : 2147483647; - - const int retVal = QInputDialog::getInt(parent, d->title, d->label, value, min, max, d->step, &ok); - - setDialogAccepted(ok); - return retVal; -} - -QString DeclarativeInputDialogAttached::getItem(const QStringList &items) -{ - QWidget *parent = bestParentWindow(d->dialogParent); - bool ok = false; - - const QString retVal = QInputDialog::getItem(parent, d->title, d->label, items, d->currentItem, d->itemsEditable, &ok); - - setDialogAccepted(ok); - return retVal; -} - -QString DeclarativeInputDialogAttached::getText() -{ - QWidget *parent = bestParentWindow(d->dialogParent); - bool ok = false; - - const QString retVal = QInputDialog::getText(parent, d->title, d->label, d->echoMode, d->text, &ok); - - setDialogAccepted(ok); - return retVal; -} - -void DeclarativeInputDialogAttached::setDialogAccepted(bool accepted) -{ - if (accepted == d->dialogAccepted) - return; - - d->dialogAccepted = accepted; - emit dialogAcceptedChanged(accepted); -} - -QWidget *DeclarativeInputDialogAttached::bestParentWindow(QObject *parent) const -{ - if (!parent) - parent = this->parent(); - - // if parent is a Declarative Object, search the proxied hierarchy - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) - parent = declarativeObject->object(); - - while (parent) { - QWidget *widget = qobject_cast(parent); - if (widget) - return widget->topLevelWidget(); - - parent = parent->parent(); - } - - return 0; -} - -DeclarativeInputDialog::DeclarativeInputDialog(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeInputDialogAttached *DeclarativeInputDialog::qmlAttachedProperties(QObject *parent) -{ - return new DeclarativeInputDialogAttached(parent); -} - -CUSTOM_METAOBJECT(DeclarativeInputDialog, InputDialog) - -// DeclarativeLabel -DeclarativeLabel::DeclarativeLabel(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeLabel, QLabel) - -// DeclarativeLCDNumber -DeclarativeLCDNumber::DeclarativeLCDNumber(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeLCDNumber, QLCDNumber) - -// DeclarativeLineEdit -DeclarativeLineEdit::DeclarativeLineEdit(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeLineEdit, QLineEdit) - -// DeclarativeListView -DeclarativeListView::DeclarativeListView(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeListView, ListView) - -// DeclarativeMainWindow -DeclarativeMainWindow::DeclarativeMainWindow(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - QMenuBar *menuBar = qobject_cast(widget); - QToolBar *toolBar = qobject_cast(widget); - QStatusBar *statusBar = qobject_cast(widget); - QDialog *dialog = qobject_cast(widget); - - if (menuBar) { - m_proxiedObject->setMenuBar(menuBar); - } else if (toolBar) { - m_proxiedObject->addToolBar(toolBar); - } else if (statusBar) { - m_proxiedObject->setStatusBar(statusBar); - } else if (dialog) { - // We allow to place dialogs on the mainwindow - dialog->setParent(m_proxiedObject, dialog->windowFlags()); - } else if (widget) { - if (m_proxiedObject->centralWidget()) { - qmlInfo(declarativeObject) << "The QMainWindow contains a central widget already"; - return; - } - - m_proxiedObject->setCentralWidget(widget); - } - - m_children.append(declarativeObject); -} - -void DeclarativeMainWindow::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not set a QLayout to a QMainWindow"; -} - -CUSTOM_METAOBJECT(DeclarativeMainWindow, QMainWindow) - -// DeclarativeMenu -DeclarativeMenu::DeclarativeMenu(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeMenu::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - QMenu *menu = qobject_cast(widget); - if (!menu) { - qmlInfo(declarativeObject) << "The QMenu can only contain QMenu, QAction or Separator"; - return; - } - - m_proxiedObject->addMenu(menu); - - m_children.append(declarativeObject); -} - -void DeclarativeMenu::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not set a QLayout to a QMenu"; -} - -void DeclarativeMenu::addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) -{ - DeclarativeSeparator *separator = dynamic_cast(declarativeObject); - - if (separator) { - m_proxiedObject->addSeparator(); - } else { - m_proxiedObject->addAction(action); - } - - m_children.append(declarativeObject); -} - -CUSTOM_METAOBJECT(DeclarativeMenu, QMenu) - -// DeclarativeMenuBar -DeclarativeMenuBar::DeclarativeMenuBar(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeMenuBar::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - QMenu *menu = qobject_cast(widget); - if (!menu) { - qmlInfo(declarativeObject) << "The QMenuBar can only contain QMenus"; - return; - } - - m_proxiedObject->addMenu(menu); - - m_children.append(declarativeObject); -} - -void DeclarativeMenuBar::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not set a QLayout to a QMenuBar"; -} - -void DeclarativeMenuBar::addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(action) - - DeclarativeSeparator *separator = dynamic_cast(declarativeObject); - - if (separator) { - m_proxiedObject->addSeparator(); - } - - m_children.append(declarativeObject); -} - -CUSTOM_METAOBJECT(DeclarativeMenuBar, QMenuBar) - -// DeclarativeMessageBox -DeclarativeMessageBoxAttached::DeclarativeMessageBoxAttached(QObject *parent) : QObject(parent) -{ -} - -void DeclarativeMessageBoxAttached::about(QObject *parent, const QString &title, const QString &text) -{ - QMessageBox::about(bestParentWindow(parent), title, text); -} - -void DeclarativeMessageBoxAttached::aboutQt(QObject *parent, const QString &title) -{ - QMessageBox::aboutQt(bestParentWindow(parent), title); -} - -int DeclarativeMessageBoxAttached::critical(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) -{ - return QMessageBox::critical(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); -} - -int DeclarativeMessageBoxAttached::information(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) -{ - return QMessageBox::information(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); -} - -int DeclarativeMessageBoxAttached::question(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) -{ - return QMessageBox::question(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); -} - -int DeclarativeMessageBoxAttached::warning(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) -{ - return QMessageBox::warning(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); -} - -QWidget *DeclarativeMessageBoxAttached::bestParentWindow(QObject *parent) const -{ - if (!parent) - parent = this->parent(); - - // if parent is a Declarative Object, search the proxied hierarchy - AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); - if (declarativeObject) - parent = declarativeObject->object(); - - while (parent) { - QWidget *widget = qobject_cast(parent); - if (widget) - return widget->topLevelWidget(); - - parent = parent->parent(); - } - - return 0; -} - -DeclarativeMessageBox::DeclarativeMessageBox(QObject *parent) : DeclarativeObjectProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -DeclarativeMessageBoxAttached *DeclarativeMessageBox::qmlAttachedProperties(QObject *parent) -{ - return new DeclarativeMessageBoxAttached(parent); -} - -CUSTOM_METAOBJECT(DeclarativeMessageBox, QMessageBox) - -// DeclarativePlainTextEdit -DeclarativePlainTextEdit::DeclarativePlainTextEdit(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativePlainTextEdit, QPlainTextEdit) - -// DeclarativeProgressBar -DeclarativeProgressBar::DeclarativeProgressBar(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeProgressBar, QProgressBar) - -// DeclarativePushButton -DeclarativePushButton::DeclarativePushButton(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this, QSet() << "clicked()"); -} - -CUSTOM_METAOBJECT(DeclarativePushButton, QPushButton) - -// DeclarativeRadioButton -DeclarativeRadioButton::DeclarativeRadioButton(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeRadioButton, QRadioButton) - -// DeclarativeScrollArea -DeclarativeScrollArea::DeclarativeScrollArea(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeScrollArea::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - if (m_proxiedObject->widget()) { - qmlInfo(declarativeObject) << "Can not add multiple Widgets to ScrollArea"; - } else { - m_proxiedObject->setWidget(widget); - } - - m_children.append(declarativeObject); -} - -void DeclarativeScrollArea::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not add Layout to ScrollArea"; -} - -CUSTOM_METAOBJECT(DeclarativeScrollArea, QScrollArea) - -// DeclarativeScrollBar -DeclarativeScrollBar::DeclarativeScrollBar(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeScrollBar, QScrollBar) - -// DeclarativeSlider -DeclarativeSlider::DeclarativeSlider(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeSlider, QSlider) - -// DeclarativeSpinBox -DeclarativeSpinBox::DeclarativeSpinBox(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeSpinBox, QSpinBox) - -// DeclarativeStackedWidget -DeclarativeStackedWidget::DeclarativeStackedWidget(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeStackedWidget::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - m_proxiedObject->addWidget(widget); - m_children.append(declarativeObject); -} - -void DeclarativeStackedWidget::setLayout(QLayout*, AbstractDeclarativeObject *declarativeObject) -{ - qmlInfo(declarativeObject) << "StackedWidget does not support child layouts"; -} - -CUSTOM_METAOBJECT(DeclarativeStackedWidget, QStackedWidget) - -// DeclarativeStatusBar -class DeclarativeStatusBarAttached::Private -{ - public: - int stretch; -}; - -DeclarativeStatusBarAttached::DeclarativeStatusBarAttached(QObject *parent) - : QObject(parent), d(new DeclarativeStatusBarAttached::Private) -{ - d->stretch = 0; -} - -DeclarativeStatusBarAttached::~DeclarativeStatusBarAttached() -{ - delete d; -} - -void DeclarativeStatusBarAttached::setStretch(int stretch) -{ - if (d->stretch == stretch) - return; - - d->stretch = stretch; - emit stretchChanged(); -} - -int DeclarativeStatusBarAttached::stretch() const -{ - return d->stretch; -} - -DeclarativeStatusBar::DeclarativeStatusBar(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeStatusBar::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - // TODO: error when layout is set - - m_children.append(declarativeObject); - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeStatusBarAttached *attached = qobject_cast(attachedProperties); - - int stretch = 0; - if (attached) { - stretch = attached->stretch(); - } - - m_proxiedObject->addPermanentWidget(widget, stretch); -} - -void DeclarativeStatusBar::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not add QLayout to QStatusBar"; -} - -DeclarativeStatusBarAttached *DeclarativeStatusBar::qmlAttachedProperties(QObject *object) -{ - return new DeclarativeStatusBarAttached(object); -} - -CUSTOM_METAOBJECT(DeclarativeStatusBar, QStatusBar) - -// DeclarativeTableView -DeclarativeTableView::DeclarativeTableView(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeTableView, TableView) - -// DeclarativeTabWidget -class DeclarativeTabWidgetAttached::Private -{ - public: - QString label; - QIcon icon; - QPointer tabWidget; - int index; -}; - -DeclarativeTabWidgetAttached::DeclarativeTabWidgetAttached(QObject *parent) - : QObject(parent), d(new DeclarativeTabWidgetAttached::Private) -{ -} - -DeclarativeTabWidgetAttached::~DeclarativeTabWidgetAttached() -{ - delete d; -} - -void DeclarativeTabWidgetAttached::setLabel(const QString &label) -{ - if (label == d->label) - return; - - d->label = label; - - if (d->tabWidget) - d->tabWidget->setTabText(d->index, d->label); - - emit labelChanged(label); -} - -QString DeclarativeTabWidgetAttached::label() const -{ - return d->label; -} - -void DeclarativeTabWidgetAttached::setIcon(const QIcon &icon) -{ - d->icon = icon; - - if (d->tabWidget) - d->tabWidget->setTabIcon(d->index, d->icon); - - emit iconChanged(icon); -} - -QIcon DeclarativeTabWidgetAttached::icon() const -{ - return d->icon; -} - -void DeclarativeTabWidgetAttached::setAssociation(QTabWidget *widget, int index) -{ - d->tabWidget = widget; - d->index = index; -} - -DeclarativeTabWidget::DeclarativeTabWidget(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeTabWidget::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - // TODO: error when layout is set - - m_children.append(declarativeObject); - - QString label; - QIcon icon; - - QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); - DeclarativeTabWidgetAttached *tabHeader = qobject_cast(attachedProperties); - if (tabHeader) { - label = tabHeader->label(); - icon = tabHeader->icon(); - } - - const int index = m_proxiedObject->addTab(widget, icon, label); - if (tabHeader) - tabHeader->setAssociation(m_proxiedObject, index); -} - -void DeclarativeTabWidget::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not add QLayout to QTabWidget"; -} - -DeclarativeTabWidgetAttached *DeclarativeTabWidget::qmlAttachedProperties(QObject *object) -{ - return new DeclarativeTabWidgetAttached(object); -} - -CUSTOM_METAOBJECT(DeclarativeTabWidget, QTabWidget) - -// DeclarativeTextBrowser -DeclarativeTextBrowser::DeclarativeTextBrowser(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeTextBrowser, QTextBrowser) - -// DeclarativeTextEdit -DeclarativeTextEdit::DeclarativeTextEdit(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeTextEdit, TextEdit) - -// DeclarativeTimeEdit -DeclarativeTimeEdit::DeclarativeTimeEdit(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeTimeEdit, QTimeEdit) - -// DeclarativeToolBar -DeclarativeToolBar::DeclarativeToolBar(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -void DeclarativeToolBar::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) -{ - m_proxiedObject->addWidget(widget); - - m_children.append(declarativeObject); -} - -void DeclarativeToolBar::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) -{ - Q_UNUSED(layout); - Q_UNUSED(declarativeObject); - qmlInfo(this) << "Can not set a QLayout to a QToolBar"; -} - -void DeclarativeToolBar::addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) -{ - DeclarativeSeparator *separator = dynamic_cast(declarativeObject); - - if (separator) { - m_proxiedObject->addSeparator(); - } else { - m_proxiedObject->addAction(action); - } - - m_children.append(declarativeObject); -} - -CUSTOM_METAOBJECT(DeclarativeToolBar, QToolBar) - -// DeclarativeToolButton -DeclarativeToolButton::DeclarativeToolButton(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeToolButton, QToolButton) - -// DeclarativeTreeView -DeclarativeTreeView::DeclarativeTreeView(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeTreeView, TreeView) - -// DeclarativeWebView -DeclarativeWebView::DeclarativeWebView(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeWebView, QWebView) - -// DeclarativeWidget -DeclarativeWidget::DeclarativeWidget(QObject *parent) : DeclarativeWidgetProxy(parent) -{ - connectAllSignals(m_proxiedObject, this); -} - -CUSTOM_METAOBJECT(DeclarativeWidget, QWidget) - diff --git a/declarativeobjects_p.h b/declarativeobjects_p.h deleted file mode 100644 index 0db7851..0000000 --- a/declarativeobjects_p.h +++ /dev/null @@ -1,1135 +0,0 @@ -#ifndef DECLARATIVEOBJECTS_H -#define DECLARATIVEOBJECTS_H - -#include "objectadaptors_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "objectadaptors_p.h" - -Q_DECLARE_METATYPE(QAction*) - -#define DECLARATIVE_OBJECT \ - public: \ - Q_OBJECT_CHECK \ - static QMetaObject staticMetaObject; \ - static bool metaObjectInitialized; \ - static bool initializeMetaObject(); \ - static const QMetaObject &getStaticMetaObject(); \ - virtual const QMetaObject *metaObject() const; \ - virtual void *qt_metacast(const char *); \ - virtual int qt_metacall(QMetaObject::Call, int, void **); \ - private: \ - -class AbstractDeclarativeObject : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty data READ data DESIGNABLE false) - - Q_CLASSINFO("DefaultProperty", "data") - - public: - AbstractDeclarativeObject(QObject *parent = 0); - virtual ~AbstractDeclarativeObject(); - - virtual QObject* object() const = 0; - - protected: - virtual void dataAppend(QObject *); - virtual int dataCount() const; - virtual QObject *dataAt(int) const; - virtual void dataClear(); - - private: - QDeclarativeListProperty data(); - - static void data_append(QDeclarativeListProperty *, QObject *); - static int data_count(QDeclarativeListProperty *); - static QObject *data_at(QDeclarativeListProperty *, int); - static void data_clear(QDeclarativeListProperty *); -}; - -template -class DeclarativeObjectProxy : public AbstractDeclarativeObject -{ -}; - -template -class DeclarativeObjectProxy : public AbstractDeclarativeObject -{ - public: - DeclarativeObjectProxy(QObject *parent = 0) : AbstractDeclarativeObject(parent), m_proxiedObject(new T) {} - ~DeclarativeObjectProxy() { delete m_proxiedObject; } - - virtual QObject *object() const { return m_proxiedObject.data(); } - - protected: - virtual void dataAppend(QObject *object) - { - m_children.append(object); - } - - virtual int dataCount() const { return m_children.count(); } - virtual QObject *dataAt(int index) const { return m_children.at(index); } - virtual void dataClear() - { - qDeleteAll(m_children); - m_children.clear(); - } - - protected: - QPointer m_proxiedObject; - QVector m_children; -}; - -template -class DeclarativeObjectProxy : public AbstractDeclarativeObject -{ - public: - DeclarativeObjectProxy(QObject *parent = 0) : AbstractDeclarativeObject(parent), m_proxiedObject(new T(0)) {} - ~DeclarativeObjectProxy() { delete m_proxiedObject; } - - virtual QObject *object() const { return m_proxiedObject.data(); } - - protected: - virtual void dataAppend(QObject *object) - { - m_children.append(object); - } - - virtual int dataCount() const { return m_children.count(); } - virtual QObject *dataAt(int index) const { return m_children.at(index); } - virtual void dataClear() - { - qDeleteAll(m_children); - m_children.clear(); - } - - protected: - QPointer m_proxiedObject; - QVector m_children; -}; - -class DeclarativeActionItem : public DeclarativeObjectProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeActionItem(QObject *parent = 0); -}; - -template -class DeclarativeWidgetProxy : public DeclarativeObjectProxy -{ - public: - DeclarativeWidgetProxy(QObject *parent = 0) : DeclarativeObjectProxy(parent) {} - - protected: - virtual void dataAppend(QObject *object) - { - AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); - if (declarativeObject) { - QWidget *widget = qobject_cast(declarativeObject->object()); - if (widget) { - addWidget(widget, declarativeObject); - return; - } - - QLayout *layout = qobject_cast(declarativeObject->object()); - if (layout) { - // TODO: error when widget is set - - if (DeclarativeObjectProxy::m_proxiedObject->layout()) { - qmlInfo(this) << "Can not add a second Layout"; - return; - } - - setLayout(layout, declarativeObject); - return; - } - - DeclarativeActionItem *declarativeActionItem = dynamic_cast(object); - if (declarativeActionItem) { - addAction(qobject_cast(declarativeActionItem->object())->action(), declarativeObject); - return; - } - - QAction *action = qobject_cast(declarativeObject->object()); - if (action) { - addAction(action, declarativeObject); - return; - } - - addQObject(declarativeObject->object(), declarativeObject); - return; - } - - DeclarativeObjectProxy::dataAppend(object); - } - - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) - { - Q_UNUSED(declarativeObject); - DeclarativeObjectProxy::m_children.append(declarativeObject); - widget->setParent(DeclarativeObjectProxy::m_proxiedObject, widget->windowFlags()); - } - - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) - { - DeclarativeObjectProxy::m_children.append(declarativeObject); - DeclarativeObjectProxy::m_proxiedObject->setLayout(layout); - } - - virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) - { - DeclarativeObjectProxy::m_children.append(declarativeObject); - DeclarativeObjectProxy::m_proxiedObject->addAction(action); - } - - virtual void addQObject(QObject *object, AbstractDeclarativeObject *declarativeObject) - { - object->setParent(DeclarativeObjectProxy::m_proxiedObject); - DeclarativeObjectProxy::m_children.append(declarativeObject); - } -}; - -template -class DeclarativeLayoutProxy : public DeclarativeObjectProxy -{ - public: - DeclarativeLayoutProxy(QObject *parent = 0) : DeclarativeObjectProxy(parent) {} - - protected: - virtual void dataAppend(QObject *object) - { - AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); - if (declarativeObject) { - QWidget *widget = qobject_cast(declarativeObject->object()); - if (widget) { - addWidget(widget, declarativeObject); - return; - } - - QLayout *layout = qobject_cast(declarativeObject->object()); - if (layout) { - addLayout(layout, declarativeObject); - return; - } - } - - DeclarativeObjectProxy::dataAppend(object); - } - - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) - { - DeclarativeObjectProxy::m_children.append(declarativeObject); - DeclarativeObjectProxy::m_proxiedObject->addWidget(widget); - } - - virtual void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) = 0; -}; - -//// Objects /// -class DeclarativeAction : public DeclarativeObjectProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeAction(QObject *parent = 0); -}; -Q_DECLARE_METATYPE(DeclarativeAction*) - -class DeclarativeButtonGroup : public DeclarativeObjectProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeButtonGroup(QObject *parent = 0); -}; - -class DeclarativeSeparator : public DeclarativeObjectProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeSeparator(QObject *parent = 0); -}; - -//// 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(QWidget *widget, QObject *parent); - DeclarativeBoxLayoutAttached(QLayout *layout, QObject *parent); - ~DeclarativeBoxLayoutAttached(); - - void setParentLayout(QBoxLayout *parentLayout); - - void setStretch(int stretch); - int stretch() const; - - void setAlignment(Qt::Alignment alignment); - Qt::Alignment alignment() const; - - Q_INVOKABLE QString foo() const { qDebug() << Q_FUNC_INFO; return "foo"; } - - Q_SIGNALS: - void stretchChanged(int stretch); - void alignmentChanged(Qt::Alignment alignment); - - private: - class Private; - Private *const d; -}; - -class DeclarativeFormLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) - - public: - DeclarativeFormLayoutAttached(QObject *parent); - ~DeclarativeFormLayoutAttached(); - - void setLabel(const QString &label); - QString label() const; - - Q_SIGNALS: - void labelChanged(const QString &label); - - private: - class Private; - Private *const d; -}; - -class DeclarativeGridLayoutAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged) - Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged) - Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan NOTIFY rowSpanChanged) - Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan NOTIFY columnSpanChanged) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) - - public: - DeclarativeGridLayoutAttached(QWidget *widget, QObject *parent); - DeclarativeGridLayoutAttached(QLayout *layout, QObject *parent); - ~DeclarativeGridLayoutAttached(); - - void setParentLayout(QGridLayout *parentLayout); - - void setRow(int row); - int row() const; - - void setColumn(int column); - int column() const; - - void setRowSpan(int rowSpan); - int rowSpan() const; - - void setColumnSpan(int columnSpan); - int columnSpan() const; - - void setAlignment(Qt::Alignment alignment); - Qt::Alignment alignment() const; - - Q_SIGNALS: - void rowChanged(int row); - void columnChanged(int column); - void rowSpanChanged(int rowSpan); - void columnSpanChanged(int columnSpan); - void alignmentChanged(Qt::Alignment alignment); - - private: - class Private; - Private *const d; -}; - -class DeclarativeFormLayout : public DeclarativeLayoutProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeFormLayout(QObject *parent = 0); - - static DeclarativeFormLayoutAttached *qmlAttachedProperties(QObject *parent); - - protected: - void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -QML_DECLARE_TYPEINFO(DeclarativeFormLayout, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeGridLayout : public DeclarativeLayoutProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeGridLayout(QObject *parent = 0); - - static DeclarativeGridLayoutAttached *qmlAttachedProperties(QObject *parent); - - protected: - void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -QML_DECLARE_TYPEINFO(DeclarativeGridLayout, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeHBoxLayout : public DeclarativeLayoutProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeHBoxLayout(QObject *parent = 0); - - static DeclarativeBoxLayoutAttached *qmlAttachedProperties(QObject *parent); - - protected: - void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - - -QML_DECLARE_TYPEINFO(DeclarativeHBoxLayout, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeStackedLayout : public DeclarativeLayoutProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeStackedLayout(QObject *parent = 0); - - protected: - void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -class DeclarativeVBoxLayout : public DeclarativeLayoutProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeVBoxLayout(QObject *parent = 0); - - static DeclarativeBoxLayoutAttached *qmlAttachedProperties(QObject *parent); - - protected: - void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -QML_DECLARE_TYPEINFO(DeclarativeVBoxLayout, QML_HAS_ATTACHED_PROPERTIES) - -//// Widgets //// -class DeclarativeCalendarWidget : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeCalendarWidget(QObject *parent = 0); -}; - -class DeclarativeCheckBox : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeCheckBox(QObject *parent = 0); -}; - -class DeclarativeColorDialogAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - // TODO option - - public: - DeclarativeColorDialogAttached(QObject *parent = 0); - ~DeclarativeColorDialogAttached(); - - void setDialogParent(QObject *parent); - QObject *dialogParent() const; - - void setTitle(const QString &title); - QString title() const; - - Q_INVOKABLE QColor getColor(const QColor &initialColor); - - Q_SIGNALS: - void dialogParentChanged(QObject *parent); - void titleChanged(const QString &title); - - private: - QWidget *bestParentWindow(QObject *parent) const; - - class Private; - Private *const d; -}; - -class DeclarativeColorDialog : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeColorDialog(QObject *parent = 0); - - static DeclarativeColorDialogAttached *qmlAttachedProperties(QObject *parent); -}; - -QML_DECLARE_TYPEINFO(DeclarativeColorDialog, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeColumnView : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeColumnView(QObject *parent = 0); -}; - -class DeclarativeCommandLinkButton : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeCommandLinkButton(QObject *parent = 0); -}; - -class DeclarativeDateEdit : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeDateEdit(QObject *parent = 0); -}; - -class DeclarativeDateTimeEdit : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeDateTimeEdit(QObject *parent = 0); -}; - -class DeclarativeDial : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeDial(QObject *parent = 0); -}; - -class DeclarativeDialog : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeDialog(QObject *parent = 0); -}; - -class DeclarativeDialogButtonBox : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeDialogButtonBox(QObject *parent = 0); -}; - -class DeclarativeDoubleSpinBox : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeDoubleSpinBox(QObject *parent = 0); -}; - -class DeclarativeFileDialogAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) - Q_PROPERTY(QString caption READ caption WRITE setCaption NOTIFY captionChanged) - Q_PROPERTY(QString dir READ dir WRITE setDir NOTIFY dirChanged) - Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged) - // TODO dialog option - Q_PROPERTY(QString selectedFilter READ selectedFilter NOTIFY selectedFilterChanged) - - public: - DeclarativeFileDialogAttached(QObject *parent = 0); - ~DeclarativeFileDialogAttached(); - - void setDialogParent(QObject *parent); - QObject *dialogParent() const; - - void setCaption(const QString &caption); - QString caption() const; - - void setDir(const QString &dir); - QString dir() const; - - void setNameFilters(const QStringList &nameFilters); - QStringList nameFilters() const; - - QString selectedFilter() const; - - Q_INVOKABLE QString getExistingDirectory(); - - Q_INVOKABLE QString getOpenFileName(); - - Q_INVOKABLE QStringList getOpenFileNames(); - - Q_INVOKABLE QString getSaveFileName(); - - Q_SIGNALS: - void dialogParentChanged(QObject *parent); - void captionChanged(const QString &caption); - void dirChanged(const QString &dir); - void nameFiltersChanged(const QStringList &filters); - void selectedFilterChanged(const QString &filter); - - private: - QWidget *bestParentWindow(QObject *parent) const; - void setSelectedFilter(const QString &filter); - - class Private; - Private *const d; -}; - -class DeclarativeFileDialog : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeFileDialog(QObject *parent = 0); - - static DeclarativeFileDialogAttached *qmlAttachedProperties(QObject *parent); -}; - -QML_DECLARE_TYPEINFO(DeclarativeFileDialog, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeFontDialog : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeFontDialog(QObject *parent = 0); -}; - -class DeclarativeFrame : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeFrame(QObject *parent = 0); -}; - -class DeclarativeGroupBox : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeGroupBox(QObject *parent = 0); -}; - -class DeclarativeInputDialogAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) - Q_PROPERTY(bool ok READ dialogAccepted NOTIFY dialogAcceptedChanged) - - Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) - Q_PROPERTY(QVariant min READ min WRITE setMin NOTIFY minChanged) - Q_PROPERTY(QVariant max READ max WRITE setMax NOTIFY maxChanged) - Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged) - Q_PROPERTY(int step READ step WRITE setStep NOTIFY stepChanged) - - Q_PROPERTY(int current READ currentItem WRITE setCurrentItem NOTIFY currentItemChanged) - Q_PROPERTY(bool editable READ itemsEditable WRITE setItemsEditable NOTIFY itemsEditableChanged) - - Q_PROPERTY(QLineEdit::EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged) - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - - public: - DeclarativeInputDialogAttached(QObject *parent = 0); - ~DeclarativeInputDialogAttached(); - - void setDialogParent(QObject *parent); - QObject *dialogParent() const; - - void setTitle(const QString &title); - QString title() const; - - void setLabel(const QString &label); - QString label() const; - - bool dialogAccepted() const; - - void setValue(const QVariant &value); - QVariant value() const; - - void setMin(const QVariant &min); - QVariant min() const; - - void setMax(const QVariant &max); - QVariant max() const; - - void setDecimals(int decimals); - int decimals() const; - - void setStep(int step); - int step() const; - - void setCurrentItem(int current); - int currentItem() const; - - void setItemsEditable(bool editable); - bool itemsEditable() const; - - void setEchoMode(QLineEdit::EchoMode echoMode); - QLineEdit::EchoMode echoMode() const; - - void setText(const QString &text); - QString text() const; - - Q_INVOKABLE double getDouble(); - - Q_INVOKABLE int getInt(); - - Q_INVOKABLE QString getItem(const QStringList &items); - - Q_INVOKABLE QString getText(); - - Q_SIGNALS: - void dialogParentChanged(QObject *parent); - void titleChanged(const QString &title); - void labelChanged(const QString &label); - void dialogAcceptedChanged(bool accepted); - - void valueChanged(const QVariant &value); - void minChanged(const QVariant &min); - void maxChanged(const QVariant &max); - void decimalsChanged(int decimals); - void stepChanged(int step); - - void currentItemChanged(int current); - void itemsEditableChanged(bool editable); - - void echoModeChanged(QLineEdit::EchoMode echoMode); - void textChanged(const QString &text); - - private: - void setDialogAccepted(bool accepted); - QWidget *bestParentWindow(QObject *parent) const; - - class Private; - Private *const d; -}; - -class DeclarativeInputDialog : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeInputDialog(QObject *parent = 0); - - static DeclarativeInputDialogAttached *qmlAttachedProperties(QObject *parent); -}; - -QML_DECLARE_TYPEINFO(DeclarativeInputDialog, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeLabel : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeLabel(QObject *parent = 0); -}; - -class DeclarativeLCDNumber : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeLCDNumber(QObject *parent = 0); -}; - -class DeclarativeLineEdit : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeLineEdit(QObject *parent = 0); -}; - -class DeclarativeListView : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeListView(QObject *parent = 0); -}; - -class DeclarativeMainWindow : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeMainWindow(QObject *parent = 0); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -class DeclarativeMenu : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeMenu(QObject *parent = 0); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); - virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject); -}; - -class DeclarativeMenuBar : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeMenuBar(QObject *parent = 0); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); - virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject); -}; - -class DeclarativeMessageBoxAttached : public QObject -{ - Q_OBJECT - - public: - DeclarativeMessageBoxAttached(QObject *parent = 0); - - Q_INVOKABLE void about(QObject *parent, const QString &title, const QString &text); - Q_INVOKABLE void aboutQt(QObject *parent, const QString &title); - Q_INVOKABLE int critical(QObject *parent, const QString &title, const QString &text, - int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); - Q_INVOKABLE int information(QObject *parent, const QString &title, const QString &text, - int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); - Q_INVOKABLE int question(QObject *parent, const QString &title, const QString &text, - int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); - Q_INVOKABLE int warning(QObject *parent, const QString &title, const QString &text, - int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); - - private: - QWidget *bestParentWindow(QObject *parent) const; -}; - -class DeclarativeMessageBox : public DeclarativeObjectProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeMessageBox(QObject *parent = 0); - - static DeclarativeMessageBoxAttached *qmlAttachedProperties(QObject *parent); -}; - -QML_DECLARE_TYPEINFO(DeclarativeMessageBox, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativePlainTextEdit : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativePlainTextEdit(QObject *parent = 0); -}; - -class DeclarativeProgressBar : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeProgressBar(QObject *parent = 0); -}; - -class DeclarativePushButton : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativePushButton(QObject *parent = 0); -}; - -class DeclarativeRadioButton : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeRadioButton(QObject *parent = 0); -}; - -class DeclarativeScrollArea : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeScrollArea(QObject *parent = 0); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -class DeclarativeScrollBar : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeScrollBar(QObject *parent = 0); -}; - -class DeclarativeSlider : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeSlider(QObject *parent = 0); -}; - -class DeclarativeSpinBox : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeSpinBox(QObject *parent = 0); -}; - -class DeclarativeStackedWidget : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeStackedWidget(QObject *parent = 0); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -// attached property for DeclarativeStatusBar -class DeclarativeStatusBarAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged) - - public: - DeclarativeStatusBarAttached(QObject *parent = 0); - ~DeclarativeStatusBarAttached(); - - void setStretch(int stretch); - int stretch() const; - - Q_SIGNALS: - void stretchChanged(); - - private: - class Private; - Private *const d; -}; - -class DeclarativeStatusBar : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeStatusBar(QObject *parent = 0); - - static DeclarativeStatusBarAttached *qmlAttachedProperties(QObject *object); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -QML_DECLARE_TYPEINFO(DeclarativeStatusBar, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeTableView : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeTableView(QObject *parent = 0); -}; - -// attached property for DeclarativeTabWidget -class DeclarativeTabWidgetAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) - Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY iconChanged) - - public: - DeclarativeTabWidgetAttached(QObject *parent = 0); - ~DeclarativeTabWidgetAttached(); - - void setLabel(const QString &label); - QString label() const; - - void setIcon(const QIcon &icon); - QIcon icon() const; - - void setAssociation(QTabWidget *widget, int index); - - Q_SIGNALS: - void labelChanged(const QString &label); - void iconChanged(const QIcon &icon); - - private: - class Private; - Private *const d; -}; - -class DeclarativeTabWidget : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeTabWidget(QObject *parent = 0); - - static DeclarativeTabWidgetAttached *qmlAttachedProperties(QObject *object); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); -}; - -QML_DECLARE_TYPEINFO(DeclarativeTabWidget, QML_HAS_ATTACHED_PROPERTIES) - -class DeclarativeTextBrowser : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeTextBrowser(QObject *parent = 0); -}; - -class DeclarativeTextEdit : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeTextEdit(QObject *parent = 0); -}; - -class DeclarativeTimeEdit : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeTimeEdit(QObject *parent = 0); -}; - -class DeclarativeToolBar : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeToolBar(QObject *parent = 0); - - protected: - virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); - virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); - virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject); -}; - -class DeclarativeToolButton : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeToolButton(QObject *parent = 0); -}; - -class DeclarativeTreeView : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeTreeView(QObject *parent = 0); -}; - -class DeclarativeWebView : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeWebView(QObject *parent = 0); -}; - -class DeclarativeWidget : public DeclarativeWidgetProxy -{ - DECLARATIVE_OBJECT - - public: - DeclarativeWidget(QObject *parent = 0); -}; - -#endif diff --git a/declarativewidgetdocument.cpp b/declarativewidgetdocument.cpp deleted file mode 100644 index ca51bcc..0000000 --- a/declarativewidgetdocument.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "declarativewidgetdocument.h" - -#include "declarativeobjects_p.h" - -#include -#include -#include -#include -#include - -class DeclarativeWidgetDocument::Private -{ - public: - Private(DeclarativeWidgetDocument *qq, const QUrl &url) - : q(qq) - , m_url(url) - , m_engine(new QDeclarativeEngine(q)) - , m_component(new QDeclarativeComponent(m_engine, q)) - { - } - - DeclarativeWidgetDocument* q; - QUrl m_url; - QDeclarativeEngine* m_engine; - QDeclarativeComponent* m_component; -}; - -DeclarativeWidgetDocument::DeclarativeWidgetDocument(const QUrl &url, QObject *parent) - : QObject(parent) - , d(new Private(this, url)) -{ - qmlRegisterType(); - qmlRegisterType(); - - // objects - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "Action"); - qmlRegisterType("QtGui", 1, 0, "ActionItem"); - qmlRegisterType("QtGui", 1, 0, "ButtonGroup"); - qmlRegisterType("QtGui", 1, 0, "Separator"); - - // layouts - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "FormLayout"); - qmlRegisterType("QtGui", 1, 0, "GridLayout"); - qmlRegisterType("QtGui", 1, 0, "HBoxLayout"); - qmlRegisterType("QtGui", 1, 0, "StackedLayout"); - qmlRegisterType("QtGui", 1, 0, "VBoxLayout"); - - // widgets - qmlRegisterType("QtGui", 1, 0, "CalendarWidget"); - qmlRegisterType("QtGui", 1, 0, "CheckBox"); - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "ColorDialog"); - qmlRegisterType("QtGui", 1, 0, "ColumnView"); - qmlRegisterType("QtGui", 1, 0, "CommandLinkButton"); - qmlRegisterType("QtGui", 1, 0, "DateEdit"); - qmlRegisterType("QtGui", 1, 0, "DateTimeEdit"); - qmlRegisterType("QtGui", 1, 0, "Dial"); - qmlRegisterType("QtGui", 1, 0, "Dialog"); - qmlRegisterType("QtGui", 1, 0, "DialogButtonBox"); - qmlRegisterType("QtGui", 1, 0, "DoubleSpinBox"); - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "FileDialog"); - qmlRegisterType("QtGui", 1, 0, "FontDialog"); - qmlRegisterType("QtGui", 1, 0, "Frame"); - qmlRegisterType("QtGui", 1, 0, "GroupBox"); - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "InputDialog"); - qmlRegisterType("QtGui", 1, 0, "Label"); - qmlRegisterType("QtGui", 1, 0, "LCDNumber"); - qmlRegisterType("QtGui", 1, 0, "LineEdit"); - qmlRegisterType("QtGui", 1, 0, "ListView"); - qmlRegisterType("QtGui", 1, 0, "MainWindow"); - qmlRegisterType("QtGui", 1, 0, "Menu"); - qmlRegisterType("QtGui", 1, 0, "MenuBar"); - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "MessageBox"); - qmlRegisterType("QtGui", 1, 0, "PlainTextEdit"); - qmlRegisterType("QtGui", 1, 0, "ProgressBar"); - qmlRegisterType("QtGui", 1, 0, "PushButton"); - qmlRegisterType("QtGui", 1, 0, "RadioButton"); - qmlRegisterType("QtGui", 1, 0, "ScrollArea"); - qmlRegisterType("QtGui", 1, 0, "ScrollBar"); - qmlRegisterType("QtGui", 1, 0, "Slider"); - qmlRegisterType("QtGui", 1, 0, "SpinBox"); - qmlRegisterType("QtGui", 1, 0, "StackedWidget"); - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "StatusBar"); - qmlRegisterType("QtGui", 1, 0, "TableView"); - qmlRegisterType(); - qmlRegisterType("QtGui", 1, 0, "TabWidget"); - qmlRegisterType("QtGui", 1, 0, "TextBrowser"); - qmlRegisterType("QtGui", 1, 0, "TextEdit"); - qmlRegisterType("QtGui", 1, 0, "TimeEdit"); - qmlRegisterType("QtGui", 1, 0, "ToolBar"); - qmlRegisterType("QtGui", 1, 0, "ToolButton"); - qmlRegisterType("QtGui", 1, 0, "TreeView"); - qmlRegisterType("QtGui", 1, 0, "WebView"); - qmlRegisterType("QtGui", 1, 0, "Widget"); - - d->m_component->loadUrl(d->m_url); - if (d->m_component->isError()) { - foreach (const QDeclarativeError &error, d->m_component->errors()) - qDebug() << error.toString(); - } -} - -DeclarativeWidgetDocument::~DeclarativeWidgetDocument() -{ - delete d; -} - -void DeclarativeWidgetDocument::setContextProperty(const QString &name, const QVariant &value) -{ - d->m_engine->rootContext()->setContextProperty(name, value); -} - -void DeclarativeWidgetDocument::setContextProperty(const QString &name, QObject *object) -{ - d->m_engine->rootContext()->setContextProperty(name, object); -} - -QDeclarativeEngine* DeclarativeWidgetDocument::engine() const -{ - return d->m_engine; -} - -QWidget* DeclarativeWidgetDocument::createWidget() -{ - QObject *object = d->m_component->create(); - if (!object) { - qWarning("Unable to create component"); - return 0; - } - - AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); - - if (!declarativeObject) { - qWarning("Root element is no AbstractDeclarativeObject subclass"); - return 0; - } - - declarativeObject->setParent(this); - - return qobject_cast(declarativeObject->object()); -} diff --git a/declarativewidgetdocument.h b/declarativewidgetdocument.h deleted file mode 100644 index e156df6..0000000 --- a/declarativewidgetdocument.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DECLARATIVEWIDGETDOCUMENT_H -#define DECLARATIVEWIDGETDOCUMENT_H - -#include -#include - -class QDeclarativeEngine; - -class DeclarativeWidgetDocument : public QObject -{ - Q_OBJECT - - public: - DeclarativeWidgetDocument(const QUrl &url, QObject *parent = 0); - ~DeclarativeWidgetDocument(); - - void setContextProperty(const QString &name, const QVariant &value); - void setContextProperty(const QString &name, QObject *object); - - QDeclarativeEngine* engine() const; - - template - T* create() - { - QWidget *widget = createWidget(); - if (!widget) - return 0; - - return qobject_cast(widget); - } - - private: - QWidget* createWidget(); - - class Private; - Private* const d; -}; - -#endif diff --git a/declarativewidgets.pro b/declarativewidgets.pro index bc9ed0d..6d67f2f 100644 --- a/declarativewidgets.pro +++ b/declarativewidgets.pro @@ -5,30 +5,147 @@ TEMPLATE = app TARGET = DEPENDPATH += . -INCLUDEPATH += . +INCLUDEPATH += . lib/ # Input +LIB_HEADERS = \ + lib/abstractdeclarativeobject_p.h \ + lib/declarativeactionitem_p.h \ + lib/declarativeaction_p.h \ + lib/declarativeboxlayout_p.h \ + lib/declarativebuttongroup_p.h \ + lib/declarativecalendarwidget_p.h \ + lib/declarativecheckbox_p.h \ + lib/declarativecolordialog_p.h \ + lib/declarativecolumnview_p.h \ + lib/declarativecommandlinkbutton_p.h \ + lib/declarativedateedit_p.h \ + lib/declarativedatetimeedit_p.h \ + lib/declarativedialogbuttonbox_p.h \ + lib/declarativedialog_p.h \ + lib/declarativedial_p.h \ + lib/declarativedoublespinbox_p.h \ + lib/declarativefiledialog_p.h \ + lib/declarativefontdialog_p.h \ + lib/declarativeformlayout_p.h \ + lib/declarativeframe_p.h \ + lib/declarativegridlayout_p.h \ + lib/declarativegroupbox_p.h \ + lib/declarativehboxlayout_p.h \ + lib/declarativeinputdialog_p.h \ + lib/declarativelabel_p.h \ + lib/declarativelayoutproxy_p.h \ + lib/declarativelcdnumber_p.h \ + lib/declarativelineedit_p.h \ + lib/declarativelistview_p.h \ + lib/declarativemainwindow_p.h \ + lib/declarativemenubar_p.h \ + lib/declarativemenu_p.h \ + lib/declarativemessagebox_p.h \ + lib/declarativeobjectproxy_p.h \ + lib/declarativeplaintextedit_p.h \ + lib/declarativeprogressbar_p.h \ + lib/declarativepushbutton_p.h \ + lib/declarativeradiobutton_p.h \ + lib/declarativescrollarea_p.h \ + lib/declarativescrollbar_p.h \ + lib/declarativeseparator_p.h \ + lib/declarativeslider_p.h \ + lib/declarativespinbox_p.h \ + lib/declarativestackedlayout_p.h \ + lib/declarativestackedwidget_p.h \ + lib/declarativestatusbar_p.h \ + lib/declarativetableview_p.h \ + lib/declarativetabwidget_p.h \ + lib/declarativetextbrowser_p.h \ + lib/declarativetextedit_p.h \ + lib/declarativetimeedit_p.h \ + lib/declarativetoolbar_p.h \ + lib/declarativetoolbutton_p.h \ + lib/declarativetreeview_p.h \ + lib/declarativevboxlayout_p.h \ + lib/declarativewebview_p.h \ + lib/declarativewidget_p.h \ + lib/declarativewidgetproxy_p.h \ + lib/declarativewidgetsdocument.h \ + lib/objectadaptors_p.h \ + lib/qmetaobjectbuilder_p.h + +LIB_SOURCES = \ + lib/abstractdeclarativeobject.cpp \ + lib/declarativeaction.cpp \ + lib/declarativeactionitem.cpp \ + lib/declarativeboxlayout.cpp \ + lib/declarativebuttongroup.cpp \ + lib/declarativecalendarwidget.cpp \ + lib/declarativecheckbox.cpp \ + lib/declarativecolordialog.cpp \ + lib/declarativecolumnview.cpp \ + lib/declarativecommandlinkbutton.cpp \ + lib/declarativedateedit.cpp \ + lib/declarativedatetimeedit.cpp \ + lib/declarativedial.cpp \ + lib/declarativedialogbuttonbox.cpp \ + lib/declarativedialog.cpp \ + lib/declarativedoublespinbox.cpp \ + lib/declarativefiledialog.cpp \ + lib/declarativefontdialog.cpp \ + lib/declarativeformlayout.cpp \ + lib/declarativeframe.cpp \ + lib/declarativegridlayout.cpp \ + lib/declarativegroupbox.cpp \ + lib/declarativehboxlayout.cpp \ + lib/declarativeinputdialog.cpp \ + lib/declarativelabel.cpp \ + lib/declarativelcdnumber.cpp \ + lib/declarativelineedit.cpp \ + lib/declarativelistview.cpp \ + lib/declarativemainwindow.cpp \ + lib/declarativemenubar.cpp \ + lib/declarativemenu.cpp \ + lib/declarativemessagebox.cpp \ + lib/declarativeplaintextedit.cpp \ + lib/declarativeprogressbar.cpp \ + lib/declarativepushbutton.cpp \ + lib/declarativeradiobutton.cpp \ + lib/declarativescrollarea.cpp \ + lib/declarativescrollbar.cpp \ + lib/declarativeseparator.cpp \ + lib/declarativeslider.cpp \ + lib/declarativespinbox.cpp \ + lib/declarativestackedlayout.cpp \ + lib/declarativestackedwidget.cpp \ + lib/declarativestatusbar.cpp \ + lib/declarativetableview.cpp \ + lib/declarativetabwidget.cpp \ + lib/declarativetextbrowser.cpp \ + lib/declarativetextedit.cpp \ + lib/declarativetimeedit.cpp \ + lib/declarativetoolbar.cpp \ + lib/declarativetoolbutton.cpp \ + lib/declarativetreeview.cpp \ + lib/declarativevboxlayout.cpp \ + lib/declarativewebview.cpp \ + lib/declarativewidget.cpp \ + lib/declarativewidgetsdocument.cpp \ + lib/objectadaptors.cpp \ + lib/qmetaobjectbuilder.cpp + HEADERS += \ - declarativeobjects_p.h \ - declarativewidgetdocument.h \ - objectadaptors_p.h \ - qmetaobjectbuilder_p.h + $$LIB_HEADERS SOURCES += \ - declarativeobjects.cpp \ - declarativewidgetdocument.cpp \ - main.cpp \ - objectadaptors.cpp \ - qmetaobjectbuilder.cpp + $$LIB_SOURCES \ + main.cpp QT += declarative webkit OTHER_FILES += \ - animation.qml \ - browser.qml \ - dialogs.qml \ - editor.qml \ - gallery.qml \ - layouts.qml \ - test.qml \ - messagebox.qml + examples/animation.qml \ + examples/browser.qml \ + examples/dialogs.qml \ + examples/editor.qml \ + examples/gallery.qml \ + examples/layouts.qml \ + examples/test.qml \ + examples/messagebox.qml diff --git a/dialogs.qml b/dialogs.qml deleted file mode 100644 index 85c372f..0000000 --- a/dialogs.qml +++ /dev/null @@ -1,143 +0,0 @@ -import QtGui 1.0 - -Widget { - ColorDialog { - id: colorDialog - } - - FileDialog { - id: fileDialog - - fileMode: FileDialog.ExistingFile - viewMode: FileDialog.List - } - - FontDialog { - id: fontDialog - } - - VBoxLayout { - PushButton { - text: qsTr("InputDialog::getInt()") - onClicked: { - var value = InputDialog.getInt() - console.log("InputDialog.getInt returned " + value) - } - } - - PushButton { - text: qsTr("InputDialog::getInt() with options") - onClicked: { - InputDialog.title = qsTr("Integer Input") - InputDialog.label = qsTr("Percentage...") - InputDialog.value = 25 - InputDialog.min = 0 - InputDialog.max = 100 - InputDialog.step = 10 - var value = InputDialog.getInt() - console.log("InputDialog.getInt " + (InputDialog.ok ? "returned " + value : "was cancelled")) - } - } - - PushButton { - text: qsTr("InputDialog::getDouble()") - onClicked: { - var value = InputDialog.getDouble() - console.log("InputDialog.getDouble returned " + value) - } - } - - PushButton { - text: qsTr("InputDialog::getDouble() with options") - onClicked: { - InputDialog.title = qsTr("Double Input") - InputDialog.label = qsTr("Amount:") - InputDialog.value = 37.56 - InputDialog.decimals = 2 - var value = InputDialog.getDouble() - console.log("InputDialog.getDouble " + (InputDialog.ok ? "returned " + value : "was cancelled")) - } - } - - PushButton { - text: qsTr("InputDialog::getItem()") - onClicked: { - var items = [ qsTr("Spring"), qsTr("Summer"), qsTr("Autumn"), qsTr("Winter") ] - var item = InputDialog.getItem(items) - console.log("InputDialog.getItem returned " + item) - } - } - - PushButton { - text: qsTr("InputDialog::getItem() with options") - onClicked: { - InputDialog.title = qsTr("Item Selection") - InputDialog.label = qsTr("Season:") - InputDialog.current = 2 - var items = [ qsTr("Spring"), qsTr("Summer"), qsTr("Autumn"), qsTr("Winter") ] - var item = InputDialog.getItem(items) - console.log("InputDialog.getItem " + (InputDialog.ok ? "returned " + item : "was cancelled")) - } - } - - PushButton { - text: qsTr("InputDialog::getText()") - onClicked: { - var text = InputDialog.getText() - console.log("InputDialog.getText returned " + text) - } - } - - PushButton { - text: qsTr("InputDialog::getText() with options") - onClicked: { - InputDialog.title = qsTr("Text Input") - InputDialog.label = qsTr("Password:") - InputDialog.echoMode = LineEdit.Password - InputDialog.text = "secret" - var text = InputDialog.getText() - console.log("InputDialog.getText " + (InputDialog.ok ? "returned " + text : "was cancelled")) - } - } - - PushButton { - text: qsTr("Color Dialog...") - onClicked: { - if (colorDialog.exec()) - console.log("Selected color: " + colorDialog.currentColor) - } - } - - PushButton { - text: qsTr("Color Dialog::getColor") - onClicked: { - console.log("Selected color: " + ColorDialog.getColor("#ff0000")) - } - } - - PushButton { - text: qsTr("Color Dialog::getColor with title") - onClicked: { - ColorDialog.title = "Pick a color" - console.log("Selected color: " + ColorDialog.getColor("#ff0000")) - } - } - - PushButton { - text: qsTr("File Dialog...") - onClicked: { - if (fileDialog.exec()) - console.log("Selected files: " + fileDialog.selectedFiles) - } - } - - PushButton { - text: qsTr("Font Dialog...") - onClicked: { - if (fontDialog.exec()) - console.log("Selected font: " + fontDialog.currentFont) - } - } - - } -} diff --git a/editor.qml b/editor.qml deleted file mode 100644 index 43f29ad..0000000 --- a/editor.qml +++ /dev/null @@ -1,164 +0,0 @@ -import QtGui 1.0 - -MainWindow { - windowTitle: textEdit.modified ? qsTr("Declarative Widget Editor *modified*") : qsTr("Declarative Widget Editor") - - size: Qt.size(500, 300) - - Dialog { - id: myDialog - - size: Qt.size(300, 200) - visible: false - - VBoxLayout { - Label { - text: "Hello World" - } - DialogButtonBox { - standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel - - onAccepted: myDialog.accept() - onRejected: myDialog.reject() - } - } - } - - MenuBar { - Menu { - title: qsTr("File") - - Action { - text: qsTr("New") - onTriggered: { - var result = myDialog.exec() - console.log("result="+result) - } - } - - Action { - text: qsTr("Save") - } - - Separator {} - - Action { - text: qsTr("Print") - } - - Separator {} - - Action { - text: qsTr("Close") - onTriggered: Qt.quit() - } - } - - Menu { - title: qsTr("Edit") - - Action { - text: qsTr("Undo") - onTriggered: textEdit.undo() - } - - Action { - text: qsTr("Redo") - onTriggered: textEdit.redo() - } - - Separator {} - - Action { - id: cutAction - text: qsTr("Cut") - onTriggered: textEdit.cut() - } - - Action { - id: copyAction - text: qsTr("Copy") - onTriggered: textEdit.copy() - } - - Action { - id: pasteAction - text: qsTr("Paste") - onTriggered: textEdit.paste() - } - - Separator {} - - Action { - text: qsTr("Select All") - onTriggered: textEdit.selectAll() - } - } - - Menu { - title: qsTr("View") - - Action { - text: qsTr("Enlarge Font") - onTriggered: textEdit.zoomIn() - } - - Action { - text: qsTr("Shrink Font") - onTriggered: textEdit.zoomOut() - } - } - - Menu { - title: qsTr("Help") - - Action { - text: qsTr("About") - onTriggered: MessageBox.about(0, qsTr("About Declarative Widgets Editor Example"), - qsTr("This is an example of a simple text editor written in QML using DeclarativeWidgets")) - } - - Action { - text: qsTr("About Qt") - onTriggered: MessageBox.aboutQt(0, qsTr("About Qt")) - } - } - } - - ToolBar { - Action { - text: qsTr("New") - } - - Separator {} - - Label { - text: "Zoom" - } - } - - TextEdit { - id: textEdit - - contextMenuPolicy: Qt.ActionsContextMenu - - ActionItem { - action: cutAction - } - - ActionItem { - action: copyAction - } - - ActionItem { - action: pasteAction - } - } - - StatusBar { - Label { - StatusBar.stretch: 2 - text: "Pos:" - } - } -} diff --git a/examples/animation.qml b/examples/animation.qml new file mode 100644 index 0000000..3d75237 --- /dev/null +++ b/examples/animation.qml @@ -0,0 +1,31 @@ +import QtQuick 1.0 +import QtGui 1.0 + +Widget { + VBoxLayout { + PushButton { + id: button + text: anim.running ? qsTr("Stop animation") : qsTr("Start animation") + checkable: true + } + + Slider { + id: slider + + minimum: 0 + maximum: 100 + PropertyAnimation { + id: anim + + running: button.checked + target: slider + property: "value" + from: 0 + to: 100 + duration: 3000 + easing.type: Easing.InOutBounce + loops: Animation.Infinite + } + } + } +} diff --git a/examples/browser.qml b/examples/browser.qml new file mode 100644 index 0000000..18b3cc7 --- /dev/null +++ b/examples/browser.qml @@ -0,0 +1,38 @@ +import QtGui 1.0 + +Widget { + id: mainWidget + + VBoxLayout { + + HBoxLayout { + PushButton { + text: qsTr("<") + onClicked: webView.back() + } + + PushButton { + text: qsTr(">") + onClicked: webView.forward() + } + + LineEdit { + id: urlInput + + onEditingFinished: webView.url = urlInput.text + } + + PushButton { + text: qsTr("Go") + onClicked: webView.url = urlInput.text + } + } + + WebView { + id: webView + + onTitleChanged: mainWidget.windowTitle = title + onUrlChanged: urlInput.text = url + } + } +} diff --git a/examples/dialogs.qml b/examples/dialogs.qml new file mode 100644 index 0000000..85c372f --- /dev/null +++ b/examples/dialogs.qml @@ -0,0 +1,143 @@ +import QtGui 1.0 + +Widget { + ColorDialog { + id: colorDialog + } + + FileDialog { + id: fileDialog + + fileMode: FileDialog.ExistingFile + viewMode: FileDialog.List + } + + FontDialog { + id: fontDialog + } + + VBoxLayout { + PushButton { + text: qsTr("InputDialog::getInt()") + onClicked: { + var value = InputDialog.getInt() + console.log("InputDialog.getInt returned " + value) + } + } + + PushButton { + text: qsTr("InputDialog::getInt() with options") + onClicked: { + InputDialog.title = qsTr("Integer Input") + InputDialog.label = qsTr("Percentage...") + InputDialog.value = 25 + InputDialog.min = 0 + InputDialog.max = 100 + InputDialog.step = 10 + var value = InputDialog.getInt() + console.log("InputDialog.getInt " + (InputDialog.ok ? "returned " + value : "was cancelled")) + } + } + + PushButton { + text: qsTr("InputDialog::getDouble()") + onClicked: { + var value = InputDialog.getDouble() + console.log("InputDialog.getDouble returned " + value) + } + } + + PushButton { + text: qsTr("InputDialog::getDouble() with options") + onClicked: { + InputDialog.title = qsTr("Double Input") + InputDialog.label = qsTr("Amount:") + InputDialog.value = 37.56 + InputDialog.decimals = 2 + var value = InputDialog.getDouble() + console.log("InputDialog.getDouble " + (InputDialog.ok ? "returned " + value : "was cancelled")) + } + } + + PushButton { + text: qsTr("InputDialog::getItem()") + onClicked: { + var items = [ qsTr("Spring"), qsTr("Summer"), qsTr("Autumn"), qsTr("Winter") ] + var item = InputDialog.getItem(items) + console.log("InputDialog.getItem returned " + item) + } + } + + PushButton { + text: qsTr("InputDialog::getItem() with options") + onClicked: { + InputDialog.title = qsTr("Item Selection") + InputDialog.label = qsTr("Season:") + InputDialog.current = 2 + var items = [ qsTr("Spring"), qsTr("Summer"), qsTr("Autumn"), qsTr("Winter") ] + var item = InputDialog.getItem(items) + console.log("InputDialog.getItem " + (InputDialog.ok ? "returned " + item : "was cancelled")) + } + } + + PushButton { + text: qsTr("InputDialog::getText()") + onClicked: { + var text = InputDialog.getText() + console.log("InputDialog.getText returned " + text) + } + } + + PushButton { + text: qsTr("InputDialog::getText() with options") + onClicked: { + InputDialog.title = qsTr("Text Input") + InputDialog.label = qsTr("Password:") + InputDialog.echoMode = LineEdit.Password + InputDialog.text = "secret" + var text = InputDialog.getText() + console.log("InputDialog.getText " + (InputDialog.ok ? "returned " + text : "was cancelled")) + } + } + + PushButton { + text: qsTr("Color Dialog...") + onClicked: { + if (colorDialog.exec()) + console.log("Selected color: " + colorDialog.currentColor) + } + } + + PushButton { + text: qsTr("Color Dialog::getColor") + onClicked: { + console.log("Selected color: " + ColorDialog.getColor("#ff0000")) + } + } + + PushButton { + text: qsTr("Color Dialog::getColor with title") + onClicked: { + ColorDialog.title = "Pick a color" + console.log("Selected color: " + ColorDialog.getColor("#ff0000")) + } + } + + PushButton { + text: qsTr("File Dialog...") + onClicked: { + if (fileDialog.exec()) + console.log("Selected files: " + fileDialog.selectedFiles) + } + } + + PushButton { + text: qsTr("Font Dialog...") + onClicked: { + if (fontDialog.exec()) + console.log("Selected font: " + fontDialog.currentFont) + } + } + + } +} diff --git a/examples/editor.qml b/examples/editor.qml new file mode 100644 index 0000000..43f29ad --- /dev/null +++ b/examples/editor.qml @@ -0,0 +1,164 @@ +import QtGui 1.0 + +MainWindow { + windowTitle: textEdit.modified ? qsTr("Declarative Widget Editor *modified*") : qsTr("Declarative Widget Editor") + + size: Qt.size(500, 300) + + Dialog { + id: myDialog + + size: Qt.size(300, 200) + visible: false + + VBoxLayout { + Label { + text: "Hello World" + } + DialogButtonBox { + standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel + + onAccepted: myDialog.accept() + onRejected: myDialog.reject() + } + } + } + + MenuBar { + Menu { + title: qsTr("File") + + Action { + text: qsTr("New") + onTriggered: { + var result = myDialog.exec() + console.log("result="+result) + } + } + + Action { + text: qsTr("Save") + } + + Separator {} + + Action { + text: qsTr("Print") + } + + Separator {} + + Action { + text: qsTr("Close") + onTriggered: Qt.quit() + } + } + + Menu { + title: qsTr("Edit") + + Action { + text: qsTr("Undo") + onTriggered: textEdit.undo() + } + + Action { + text: qsTr("Redo") + onTriggered: textEdit.redo() + } + + Separator {} + + Action { + id: cutAction + text: qsTr("Cut") + onTriggered: textEdit.cut() + } + + Action { + id: copyAction + text: qsTr("Copy") + onTriggered: textEdit.copy() + } + + Action { + id: pasteAction + text: qsTr("Paste") + onTriggered: textEdit.paste() + } + + Separator {} + + Action { + text: qsTr("Select All") + onTriggered: textEdit.selectAll() + } + } + + Menu { + title: qsTr("View") + + Action { + text: qsTr("Enlarge Font") + onTriggered: textEdit.zoomIn() + } + + Action { + text: qsTr("Shrink Font") + onTriggered: textEdit.zoomOut() + } + } + + Menu { + title: qsTr("Help") + + Action { + text: qsTr("About") + onTriggered: MessageBox.about(0, qsTr("About Declarative Widgets Editor Example"), + qsTr("This is an example of a simple text editor written in QML using DeclarativeWidgets")) + } + + Action { + text: qsTr("About Qt") + onTriggered: MessageBox.aboutQt(0, qsTr("About Qt")) + } + } + } + + ToolBar { + Action { + text: qsTr("New") + } + + Separator {} + + Label { + text: "Zoom" + } + } + + TextEdit { + id: textEdit + + contextMenuPolicy: Qt.ActionsContextMenu + + ActionItem { + action: cutAction + } + + ActionItem { + action: copyAction + } + + ActionItem { + action: pasteAction + } + } + + StatusBar { + Label { + StatusBar.stretch: 2 + text: "Pos:" + } + } +} diff --git a/examples/filedialog.qml b/examples/filedialog.qml new file mode 100644 index 0000000..4d04cc5 --- /dev/null +++ b/examples/filedialog.qml @@ -0,0 +1,44 @@ +import QtGui 1.0 + +Widget { + VBoxLayout { + PushButton { + text: "FileDialog::getExistingDirectory" + onClicked: { + var file = FileDialog.getExistingDirectory() + console.log("FileDialog.getExistingDirectory returned " + file) + } + } + PushButton { + text: "FileDialog::getOpenFileName" + onClicked: { + var file = FileDialog.getOpenFileName() + console.log("FileDialog.getOpenFileName returned " + file) + } + } + PushButton { + text: "FileDialog::getOpenFileName, with options" + onClicked: { + FileDialog.caption = "Select a file to open"; + FileDialog.nameFilters = [ "Headers (*.h)", "Sources (*.cpp)", "All Files (*.*)" ] + var file = FileDialog.getOpenFileName() + console.log("FileDialog.getOpenFileName returned " + file) + console.log("Selected filter " + FileDialog.selectedFilter) + } + } + PushButton { + text: "FileDialog::getOpenFileNames" + onClicked: { + var files = FileDialog.getOpenFileNames() + console.log("FileDialog.getOpenFileNames returned " + files) + } + } + PushButton { + text: "FileDialog::getSaveFileName" + onClicked: { + var file = FileDialog.getSaveFileName() + console.log("FileDialog.getSaveFileName returned " + file) + } + } + } +} diff --git a/examples/gallery.qml b/examples/gallery.qml new file mode 100644 index 0000000..5f54a92 --- /dev/null +++ b/examples/gallery.qml @@ -0,0 +1,164 @@ +import QtGui 1.0 + +TabWidget { + windowTitle: qsTr("Widget Gallery") + size: Qt.size(700, 500) + + Widget { + TabWidget.label: "Buttons" + + VBoxLayout { + PushButton { + text: qsTr("PushButton") + } + + ToolButton { + text: qsTr("ToolButton") + } + + RadioButton { + text: qsTr("RadioButton") + } + + CheckBox { + text: qsTr("CheckBox") + } + + CommandLinkButton { + text: qsTr("CommandLinkButton") + description: qsTr("A short description") + } + + DialogButtonBox { + standardButtons: DialogButtonBox.Save | DialogButtonBox.Cancel + } + } + } + + Widget { + TabWidget.label: "ItemViews" + + VBoxLayout { + ListView { + model: _fileSystemModel + } + TreeView { + model: _fileSystemModel + } + TableView { + model: _fileSystemModel + } + ColumnView { + model: _fileSystemModel + } + } + } + + Widget { + TabWidget.label: "Containers" + + VBoxLayout { + GroupBox { + title: "GroupBox" + minimumWidth: 100 + minimumHeight: 100 + } + ScrollArea { + Widget { + size: Qt.size(800, 800) + } + } + Frame { + frameShape: Frame.Panel + frameShadow: Frame.Sunken + minimumWidth: 100 + minimumHeight: 100 + } + StackedWidget { + Label { + text: "Page 1" + } + Label { + text: "Page 2" + } + } + } + } + + Widget { + TabWidget.label: "Input Widgets" + + VBoxLayout { + LineEdit { + text: qsTr("LineEdit") + onTextChanged: console.log("Types: " + text) + } + + TextEdit { + plainText: qsTr("TextEdit") + } + + PlainTextEdit { + plainText: qsTr("PlainTextEdit") + } + + SpinBox {} + + DoubleSpinBox {} + + TimeEdit {} + + DateEdit {} + + DateTimeEdit {} + + Dial {} + + ScrollBar { + minimum: 0 + maximum: 100 + value: 50 + orientation: Qt.Horizontal + } + + Slider { + minimum: 0 + maximum: 100 + value: 50 + orientation: Qt.Horizontal + } + } + } + + Widget { + TabWidget.label: "Display Widgets" + + VBoxLayout { + Label { + text: qsTr("Label") + } + + TextBrowser { + openExternalLinks: true + html: "TextBrowser Coolest project ever" + } + + CalendarWidget {} + + LCDNumber { + value: 42 + } + + ProgressBar { + minimum: 0 + maximum: 100 + value: 42 + textVisible: true + } + + WebView { + url: "http://www.kdab.com" + } + } + } +} diff --git a/examples/layouts.qml b/examples/layouts.qml new file mode 100644 index 0000000..c02389f --- /dev/null +++ b/examples/layouts.qml @@ -0,0 +1,183 @@ +import QtGui 1.0 + +TabWidget { + Widget { + TabWidget.label: "Box Layouts" + + VBoxLayout { + Widget { + HBoxLayout { + PushButton { + HBoxLayout.stretch: 1 + text: "1" + } + PushButton { + HBoxLayout.stretch: 1 + text: "1" + } + PushButton { + HBoxLayout.stretch: 2 + text: "2" + } + } + } + Widget { + HBoxLayout { + Label { + HBoxLayout.alignment: Qt.AlignTop + text: "Top" + } + Label { + HBoxLayout.alignment: Qt.AlignVCenter + text: "VCenter" + } + Label { + HBoxLayout.alignment: Qt.AlignBottom + text: "Bottom" + } + Label { // just for increasing the parent's height + text: "\n\n\n" + } + } + } + + HBoxLayout { + VBoxLayout { + Label { + VBoxLayout.alignment: Qt.AlignLeft + text: "Left" + } + Label { + VBoxLayout.alignment: Qt.AlignHCenter + text: "HCenter" + } + Label { + VBoxLayout.alignment: Qt.AlignRight + text: "Right" + } + } + VBoxLayout { + TextEdit { + VBoxLayout.stretch: 1 + } + TextEdit { + VBoxLayout.stretch: 2 + } + } + } + } + } + + Widget { + TabWidget.label: "Form Layout" + + VBoxLayout { + FormLayout { + PushButton { + FormLayout.label: "Label 1" + text: "Row 1" + } + CheckBox { + text: "Row 2" + } + } + FormLayout { + HBoxLayout { + FormLayout.label: "Label 1" + + Label { + text: "row" + } + Label { + text: "1" + } + } + HBoxLayout { + Label { + text: "row" + } + Label { + text: "2" + } + } + } + } + } + Widget { + TabWidget.label: "Grid Layout" + + GridLayout { + PushButton { + GridLayout.row: 0 + GridLayout.column: 0 + + text: "0/0" + } + PushButton { + GridLayout.row: 0 + GridLayout.column: 2 + + text: "0/2" + } + PushButton { + GridLayout.row: 1 + GridLayout.column: 0 + + text: "1/0" + } + PushButton { + GridLayout.row: 1 + GridLayout.column: 1 + GridLayout.columnSpan: 2 + + text: "1/1, 1/2" + } + TextEdit { + GridLayout.row: 2 + GridLayout.column: 0 + GridLayout.columnSpan: 2 + GridLayout.rowSpan: 2 + + plainText: "2/0, 2/2" + } + PushButton { + GridLayout.row: 2 + GridLayout.column: 2 + GridLayout.alignment: Qt.AlignBottom + + text: "2/2" + } + PushButton { + GridLayout.row: 3 + GridLayout.column: 2 + GridLayout.alignment: Qt.AlignTop + + text: "3/2" + } + } + } + + Widget { + TabWidget.label: "Stacked Layout" + VBoxLayout { + PushButton { + text: "Next Page" + onClicked: { + stackedLayout.currentIndex = ((stackedLayout.currentIndex + 1) % stackedLayout.count) + } + } + StackedLayout { + id: stackedLayout + Label { + text: "Page 1" + } + Label { + text: "Page 2" + } + Label { + text: "Page 3" + } + } + } + } +} diff --git a/examples/messagebox.qml b/examples/messagebox.qml new file mode 100644 index 0000000..f2a6f7f --- /dev/null +++ b/examples/messagebox.qml @@ -0,0 +1,62 @@ +import QtGui 1.0 + +Widget { + VBoxLayout { + PushButton { + text: qsTr("MessageBox instance") + + onClicked: messageBox.show() + } + + PushButton { + id: aboutButton + text: qsTr("MessageBox::about") + onClicked: MessageBox.about(aboutButton, qsTr("About DeclarativeWidgets"), qsTr("This is a text about declarative widgets.")) + } + + PushButton { + text: qsTr("MessageBox::aboutQt") + onClicked: MessageBox.aboutQt(0, qsTr("About Qt")) + } + + PushButton { + text: qsTr("MessageBox::critical") + onClicked: { + var button = MessageBox.critical(0, qsTr("Error"), qsTr("An error occurred!")) + console.log("MessageBox.critical returned " + button) + } + } + + PushButton { + text: qsTr("MessageBox::information") + onClicked: { + var button = MessageBox.information(0, qsTr("Information"), qsTr("The taxi is here")) + console.log("MessageBox.information returned " + button) + } + } + + PushButton { + text: qsTr("MessageBox::question") + onClicked: { + var button = MessageBox.question(0, qsTr("Network error"), qsTr("Can not connect to host"), MessageBox.Retry | MessageBox.Abort | MessageBox.Ignore, MessageBox.Abort) + console.log("MessageBox.question returned " + button) + } + } + + PushButton { + text: qsTr("MessageBox::warning") + onClicked: { + var button = MessageBox.warning(0, qsTr("Warning"), qsTr("Do you really want to quit?"), MessageBox.Ok | MessageBox.Cancel, MessageBox.Ok) + console.log("MessageBox.warning returned " + button) + } + } + } + + MessageBox { + id: messageBox + + windowTitle: qsTr("MessageBox instance") + text: qsTr("text") + detailedText: qsTr("detailedText") + } +} diff --git a/examples/test.qml b/examples/test.qml new file mode 100644 index 0000000..06aa886 --- /dev/null +++ b/examples/test.qml @@ -0,0 +1,91 @@ +import QtQuick 1.0 +import QtGui 1.0 + +Widget { + windowTitle: qsTr("Cool Test App") + size: Qt.size(300, 500) + + property int counter: 0 + + function myFunc() + { + counter++; + } + + Component.onCompleted: _timer.timeout.connect(myFunc) + + VBoxLayout { + Label { + text: "Hallo ASCII-safe Kevin!!! " + counter + } + Label { + id: secondLabel + text: "Wie geht es" + } + Label { + id: lastLabel + text: secondLabel.text + } + Label { + id: urlLabel + text: "Hallo Welt" + + onLinkActivated: console.log("link=" + link) + } + PushButton { + text: "Click me" + onClicked: { + secondLabel.text = "Changed" + counter++ + } + } + HBoxLayout { + CheckBox { + id: checkBox + } + Label { + text: checkBox.checked ? "Is checked" : "Is not checked" + } + } + TabWidget { + Label { + TabWidget.label: qsTr("Title 1") + + text: "Page 1" + } + Widget { + TabWidget.label: "Title 2" + + ButtonGroup { + buttons: [ button1, button2, button3, button4 ] + } + + VBoxLayout { + RadioButton { + id: button1 + text: qsTr("Apple") + } + RadioButton { + id: button2 + text: qsTr("Banana") + } + RadioButton { + id: button3 + text: qsTr("Peach") + } + + PushButton { + id: button4 + checkable: true + text: qsTr("Peas") + } + } + } + Label { + TabWidget.label: "Title 3" + + text: "Page 3" + } + } + } +} diff --git a/filedialog.qml b/filedialog.qml deleted file mode 100644 index 4d04cc5..0000000 --- a/filedialog.qml +++ /dev/null @@ -1,44 +0,0 @@ -import QtGui 1.0 - -Widget { - VBoxLayout { - PushButton { - text: "FileDialog::getExistingDirectory" - onClicked: { - var file = FileDialog.getExistingDirectory() - console.log("FileDialog.getExistingDirectory returned " + file) - } - } - PushButton { - text: "FileDialog::getOpenFileName" - onClicked: { - var file = FileDialog.getOpenFileName() - console.log("FileDialog.getOpenFileName returned " + file) - } - } - PushButton { - text: "FileDialog::getOpenFileName, with options" - onClicked: { - FileDialog.caption = "Select a file to open"; - FileDialog.nameFilters = [ "Headers (*.h)", "Sources (*.cpp)", "All Files (*.*)" ] - var file = FileDialog.getOpenFileName() - console.log("FileDialog.getOpenFileName returned " + file) - console.log("Selected filter " + FileDialog.selectedFilter) - } - } - PushButton { - text: "FileDialog::getOpenFileNames" - onClicked: { - var files = FileDialog.getOpenFileNames() - console.log("FileDialog.getOpenFileNames returned " + files) - } - } - PushButton { - text: "FileDialog::getSaveFileName" - onClicked: { - var file = FileDialog.getSaveFileName() - console.log("FileDialog.getSaveFileName returned " + file) - } - } - } -} diff --git a/gallery.qml b/gallery.qml deleted file mode 100644 index 5f54a92..0000000 --- a/gallery.qml +++ /dev/null @@ -1,164 +0,0 @@ -import QtGui 1.0 - -TabWidget { - windowTitle: qsTr("Widget Gallery") - size: Qt.size(700, 500) - - Widget { - TabWidget.label: "Buttons" - - VBoxLayout { - PushButton { - text: qsTr("PushButton") - } - - ToolButton { - text: qsTr("ToolButton") - } - - RadioButton { - text: qsTr("RadioButton") - } - - CheckBox { - text: qsTr("CheckBox") - } - - CommandLinkButton { - text: qsTr("CommandLinkButton") - description: qsTr("A short description") - } - - DialogButtonBox { - standardButtons: DialogButtonBox.Save | DialogButtonBox.Cancel - } - } - } - - Widget { - TabWidget.label: "ItemViews" - - VBoxLayout { - ListView { - model: _fileSystemModel - } - TreeView { - model: _fileSystemModel - } - TableView { - model: _fileSystemModel - } - ColumnView { - model: _fileSystemModel - } - } - } - - Widget { - TabWidget.label: "Containers" - - VBoxLayout { - GroupBox { - title: "GroupBox" - minimumWidth: 100 - minimumHeight: 100 - } - ScrollArea { - Widget { - size: Qt.size(800, 800) - } - } - Frame { - frameShape: Frame.Panel - frameShadow: Frame.Sunken - minimumWidth: 100 - minimumHeight: 100 - } - StackedWidget { - Label { - text: "Page 1" - } - Label { - text: "Page 2" - } - } - } - } - - Widget { - TabWidget.label: "Input Widgets" - - VBoxLayout { - LineEdit { - text: qsTr("LineEdit") - onTextChanged: console.log("Types: " + text) - } - - TextEdit { - plainText: qsTr("TextEdit") - } - - PlainTextEdit { - plainText: qsTr("PlainTextEdit") - } - - SpinBox {} - - DoubleSpinBox {} - - TimeEdit {} - - DateEdit {} - - DateTimeEdit {} - - Dial {} - - ScrollBar { - minimum: 0 - maximum: 100 - value: 50 - orientation: Qt.Horizontal - } - - Slider { - minimum: 0 - maximum: 100 - value: 50 - orientation: Qt.Horizontal - } - } - } - - Widget { - TabWidget.label: "Display Widgets" - - VBoxLayout { - Label { - text: qsTr("Label") - } - - TextBrowser { - openExternalLinks: true - html: "TextBrowser Coolest project ever" - } - - CalendarWidget {} - - LCDNumber { - value: 42 - } - - ProgressBar { - minimum: 0 - maximum: 100 - value: 42 - textVisible: true - } - - WebView { - url: "http://www.kdab.com" - } - } - } -} diff --git a/layouts.qml b/layouts.qml deleted file mode 100644 index c02389f..0000000 --- a/layouts.qml +++ /dev/null @@ -1,183 +0,0 @@ -import QtGui 1.0 - -TabWidget { - Widget { - TabWidget.label: "Box Layouts" - - VBoxLayout { - Widget { - HBoxLayout { - PushButton { - HBoxLayout.stretch: 1 - text: "1" - } - PushButton { - HBoxLayout.stretch: 1 - text: "1" - } - PushButton { - HBoxLayout.stretch: 2 - text: "2" - } - } - } - Widget { - HBoxLayout { - Label { - HBoxLayout.alignment: Qt.AlignTop - text: "Top" - } - Label { - HBoxLayout.alignment: Qt.AlignVCenter - text: "VCenter" - } - Label { - HBoxLayout.alignment: Qt.AlignBottom - text: "Bottom" - } - Label { // just for increasing the parent's height - text: "\n\n\n" - } - } - } - - HBoxLayout { - VBoxLayout { - Label { - VBoxLayout.alignment: Qt.AlignLeft - text: "Left" - } - Label { - VBoxLayout.alignment: Qt.AlignHCenter - text: "HCenter" - } - Label { - VBoxLayout.alignment: Qt.AlignRight - text: "Right" - } - } - VBoxLayout { - TextEdit { - VBoxLayout.stretch: 1 - } - TextEdit { - VBoxLayout.stretch: 2 - } - } - } - } - } - - Widget { - TabWidget.label: "Form Layout" - - VBoxLayout { - FormLayout { - PushButton { - FormLayout.label: "Label 1" - text: "Row 1" - } - CheckBox { - text: "Row 2" - } - } - FormLayout { - HBoxLayout { - FormLayout.label: "Label 1" - - Label { - text: "row" - } - Label { - text: "1" - } - } - HBoxLayout { - Label { - text: "row" - } - Label { - text: "2" - } - } - } - } - } - Widget { - TabWidget.label: "Grid Layout" - - GridLayout { - PushButton { - GridLayout.row: 0 - GridLayout.column: 0 - - text: "0/0" - } - PushButton { - GridLayout.row: 0 - GridLayout.column: 2 - - text: "0/2" - } - PushButton { - GridLayout.row: 1 - GridLayout.column: 0 - - text: "1/0" - } - PushButton { - GridLayout.row: 1 - GridLayout.column: 1 - GridLayout.columnSpan: 2 - - text: "1/1, 1/2" - } - TextEdit { - GridLayout.row: 2 - GridLayout.column: 0 - GridLayout.columnSpan: 2 - GridLayout.rowSpan: 2 - - plainText: "2/0, 2/2" - } - PushButton { - GridLayout.row: 2 - GridLayout.column: 2 - GridLayout.alignment: Qt.AlignBottom - - text: "2/2" - } - PushButton { - GridLayout.row: 3 - GridLayout.column: 2 - GridLayout.alignment: Qt.AlignTop - - text: "3/2" - } - } - } - - Widget { - TabWidget.label: "Stacked Layout" - VBoxLayout { - PushButton { - text: "Next Page" - onClicked: { - stackedLayout.currentIndex = ((stackedLayout.currentIndex + 1) % stackedLayout.count) - } - } - StackedLayout { - id: stackedLayout - Label { - text: "Page 1" - } - Label { - text: "Page 2" - } - Label { - text: "Page 3" - } - } - } - } -} diff --git a/lib/abstractdeclarativeobject.cpp b/lib/abstractdeclarativeobject.cpp new file mode 100644 index 0000000..abae271 --- /dev/null +++ b/lib/abstractdeclarativeobject.cpp @@ -0,0 +1,116 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "abstractdeclarativeobject_p.h" + +#include + +AbstractDeclarativeObject::AbstractDeclarativeObject(QObject *parent) + : QObject(parent) +{ +} + +AbstractDeclarativeObject::~AbstractDeclarativeObject() +{ +} + +QDeclarativeListProperty AbstractDeclarativeObject::data() +{ + return QDeclarativeListProperty(this, 0, AbstractDeclarativeObject::data_append, + AbstractDeclarativeObject::data_count, + AbstractDeclarativeObject::data_at, + AbstractDeclarativeObject::data_clear); +} + +void AbstractDeclarativeObject::dataAppend(QObject *) +{ +} + +int AbstractDeclarativeObject::dataCount() const +{ + return 0; +} + +QObject* AbstractDeclarativeObject::dataAt(int) const +{ + return 0; +} + +void AbstractDeclarativeObject::dataClear() +{ +} + +void AbstractDeclarativeObject::connectAllSignals(QObject *sender, QObject *receiver, const QSet &blacklist) const +{ + for (int i = 0; i < sender->metaObject()->methodCount(); ++i) { + const QMetaMethod method = sender->metaObject()->method(i); + if (method.methodType() == QMetaMethod::Signal) { + if (blacklist.contains(method.signature())) + continue; + + const QByteArray signature = "2" + QByteArray(method.signature()); + QObject::connect(sender, signature.data(), receiver, signature.data()); + } + } +} + +void AbstractDeclarativeObject::data_append(QDeclarativeListProperty *property, QObject *object) +{ + if (!object) + return; + + AbstractDeclarativeObject *that = dynamic_cast(property->object); + if (that) + that->dataAppend(object); + else + qWarning("cast went wrong in data_append"); +} + +int AbstractDeclarativeObject::data_count(QDeclarativeListProperty *property) +{ + AbstractDeclarativeObject *that = dynamic_cast(property->object); + if (that) + return that->dataCount(); + else { + qWarning("cast went wrong in data_count"); + return 0; + } +} + +QObject* AbstractDeclarativeObject::data_at(QDeclarativeListProperty *property, int index) +{ + AbstractDeclarativeObject *that = dynamic_cast(property->object); + if (that) + return that->dataAt(index); + else { + qWarning("cast went wrong in data_at"); + return 0; + } +} + +void AbstractDeclarativeObject::data_clear(QDeclarativeListProperty *property) +{ + AbstractDeclarativeObject *that = dynamic_cast(property->object); + if (that) + that->dataClear(); + else + qWarning("cast went wrong in data_clear"); +} + diff --git a/lib/abstractdeclarativeobject_p.h b/lib/abstractdeclarativeobject_p.h new file mode 100644 index 0000000..c2672a6 --- /dev/null +++ b/lib/abstractdeclarativeobject_p.h @@ -0,0 +1,59 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef ABSTRACTDECLARATIVEOBJECT_P_H +#define ABSTRACTDECLARATIVEOBJECT_P_H + +#include +#include +#include + +class AbstractDeclarativeObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty data READ data DESIGNABLE false) + + Q_CLASSINFO("DefaultProperty", "data") + + public: + AbstractDeclarativeObject(QObject *parent = 0); + virtual ~AbstractDeclarativeObject(); + + virtual QObject* object() const = 0; + + protected: + virtual void dataAppend(QObject *); + virtual int dataCount() const; + virtual QObject *dataAt(int) const; + virtual void dataClear(); + + void connectAllSignals(QObject *sender, QObject *receiver, const QSet &blacklist = QSet()) const; + + private: + QDeclarativeListProperty data(); + + static void data_append(QDeclarativeListProperty *, QObject *); + static int data_count(QDeclarativeListProperty *); + static QObject *data_at(QDeclarativeListProperty *, int); + static void data_clear(QDeclarativeListProperty *); +}; + +#endif diff --git a/lib/declarativeaction.cpp b/lib/declarativeaction.cpp new file mode 100644 index 0000000..cc117ca --- /dev/null +++ b/lib/declarativeaction.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeaction_p.h" + +DeclarativeAction::DeclarativeAction(QObject *parent) + : DeclarativeObjectProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeAction, QAction) diff --git a/lib/declarativeaction_p.h b/lib/declarativeaction_p.h new file mode 100644 index 0000000..d77c577 --- /dev/null +++ b/lib/declarativeaction_p.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEACTION_P_H +#define DECLARATIVEACTION_P_H + +#include "declarativeobjectproxy_p.h" + +#include + +class DeclarativeAction : public DeclarativeObjectProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeAction(QObject *parent = 0); +}; +Q_DECLARE_METATYPE(DeclarativeAction*) + +#endif diff --git a/lib/declarativeactionitem.cpp b/lib/declarativeactionitem.cpp new file mode 100644 index 0000000..70a8817 --- /dev/null +++ b/lib/declarativeactionitem.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeactionitem_p.h" + +DeclarativeActionItem::DeclarativeActionItem(QObject *parent) + : DeclarativeObjectProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeActionItem, ActionItem) diff --git a/lib/declarativeactionitem_p.h b/lib/declarativeactionitem_p.h new file mode 100644 index 0000000..6bbee17 --- /dev/null +++ b/lib/declarativeactionitem_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEACTIONITEM_P_H +#define DECLARATIVEACTIONITEM_P_H + +#include "declarativeobjectproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeActionItem : public DeclarativeObjectProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeActionItem(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativeboxlayout.cpp b/lib/declarativeboxlayout.cpp new file mode 100644 index 0000000..7300c44 --- /dev/null +++ b/lib/declarativeboxlayout.cpp @@ -0,0 +1,94 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeboxlayout_p.h" + +#include +#include + +class DeclarativeBoxLayoutAttached::Private +{ + public: + Private(QWidget *w, QLayout *l) : stretch(0), alignment(0), widget(w), layout(l) {} + + int stretch; + Qt::Alignment alignment; + + QPointer widget; + QPointer layout; + QPointer parentLayout; +}; + +DeclarativeBoxLayoutAttached::DeclarativeBoxLayoutAttached(QWidget *widget, QObject *parent) + : QObject(parent), d(new Private(widget, 0)) +{ +} + +DeclarativeBoxLayoutAttached::DeclarativeBoxLayoutAttached(QLayout *layout, QObject *parent) + : QObject(parent), d(new Private(0, layout)) +{ +} + +DeclarativeBoxLayoutAttached::~DeclarativeBoxLayoutAttached() +{ + delete d; +} + +void DeclarativeBoxLayoutAttached::setParentLayout(QBoxLayout *parentLayout) +{ + d->parentLayout = parentLayout; +} + +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); + + if (d->parentLayout) { + if (d->widget) + d->parentLayout->setAlignment(d->widget, d->alignment); + + if (d->layout) + d->parentLayout->setAlignment(d->layout, d->alignment); + } +} + +Qt::Alignment DeclarativeBoxLayoutAttached::alignment() const +{ + return d->alignment; +} + diff --git a/lib/declarativeboxlayout_p.h b/lib/declarativeboxlayout_p.h new file mode 100644 index 0000000..9f14059 --- /dev/null +++ b/lib/declarativeboxlayout_p.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEBOXLAYOUT_P_H +#define DECLARATIVEBOXLAYOUT_P_H + +#include + +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(QWidget *widget, QObject *parent); + DeclarativeBoxLayoutAttached(QLayout *layout, QObject *parent); + ~DeclarativeBoxLayoutAttached(); + + void setParentLayout(QBoxLayout *parentLayout); + + 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; +}; + +#endif diff --git a/lib/declarativebuttongroup.cpp b/lib/declarativebuttongroup.cpp new file mode 100644 index 0000000..981f1db --- /dev/null +++ b/lib/declarativebuttongroup.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativebuttongroup_p.h" + +DeclarativeButtonGroup::DeclarativeButtonGroup(QObject *parent) + : DeclarativeObjectProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeButtonGroup, ButtonGroup) diff --git a/lib/declarativebuttongroup_p.h b/lib/declarativebuttongroup_p.h new file mode 100644 index 0000000..964c31d --- /dev/null +++ b/lib/declarativebuttongroup_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEBUTTONGROUP_P_H +#define DECLARATIVEBUTTONGROUP_P_H + +#include "declarativeobjectproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeButtonGroup : public DeclarativeObjectProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeButtonGroup(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativecalendarwidget.cpp b/lib/declarativecalendarwidget.cpp new file mode 100644 index 0000000..cad4d66 --- /dev/null +++ b/lib/declarativecalendarwidget.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativecalendarwidget_p.h" + +DeclarativeCalendarWidget::DeclarativeCalendarWidget(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeCalendarWidget, QCalendarWidget) diff --git a/lib/declarativecalendarwidget_p.h b/lib/declarativecalendarwidget_p.h new file mode 100644 index 0000000..4a40931 --- /dev/null +++ b/lib/declarativecalendarwidget_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVECALENDARWIDGET_P_H +#define DECLARATIVECALENDARWIDGET_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeCalendarWidget : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeCalendarWidget(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativecheckbox.cpp b/lib/declarativecheckbox.cpp new file mode 100644 index 0000000..663385b --- /dev/null +++ b/lib/declarativecheckbox.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativecheckbox_p.h" + +DeclarativeCheckBox::DeclarativeCheckBox(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeCheckBox, QCheckBox) diff --git a/lib/declarativecheckbox_p.h b/lib/declarativecheckbox_p.h new file mode 100644 index 0000000..3880354 --- /dev/null +++ b/lib/declarativecheckbox_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVECHECKBOX_P_H +#define DECLARATIVECHECKBOX_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeCheckBox : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeCheckBox(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativecolordialog.cpp b/lib/declarativecolordialog.cpp new file mode 100644 index 0000000..84a3bd4 --- /dev/null +++ b/lib/declarativecolordialog.cpp @@ -0,0 +1,112 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativecolordialog_p.h" + +class DeclarativeColorDialogAttached::Private +{ + public: + Private() : options(0) {} + + public: + QPointer dialogParent; + QString title; + QColorDialog::ColorDialogOptions options; +}; + +DeclarativeColorDialogAttached::DeclarativeColorDialogAttached(QObject *parent) + : QObject(parent), d(new Private) +{ +} + +DeclarativeColorDialogAttached::~DeclarativeColorDialogAttached() +{ + delete d; +} + +void DeclarativeColorDialogAttached::setDialogParent(QObject *parent) +{ + if (parent == d->dialogParent) + return; + + d->dialogParent = parent; + emit dialogParentChanged(parent); +} + +QObject *DeclarativeColorDialogAttached::dialogParent() const +{ + return d->dialogParent; +} + +void DeclarativeColorDialogAttached::setTitle(const QString &title) +{ + if (title == d->title) + return; + + d->title = title; + emit titleChanged(title); +} + +QString DeclarativeColorDialogAttached::title() const +{ + return d->title; +} + +QColor DeclarativeColorDialogAttached::getColor(const QColor &initialColor) +{ + QWidget *parent = bestParentWindow(d->dialogParent); + if (!d->title.isEmpty() || d->options != 0) + return QColorDialog::getColor(initialColor, parent, d->title, d->options); + else + return QColorDialog::getColor(initialColor, parent); +} + +QWidget *DeclarativeColorDialogAttached::bestParentWindow(QObject *parent) const +{ + if (!parent) + parent = this->parent(); + + // if parent is a Declarative Object, search the proxied hierarchy + AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); + if (declarativeObject) + parent = declarativeObject->object(); + + while (parent) { + QWidget *widget = qobject_cast(parent); + if (widget) + return widget->topLevelWidget(); + + parent = parent->parent(); + } + + return 0; +} + +DeclarativeColorDialog::DeclarativeColorDialog(QObject *parent) : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeColorDialogAttached *DeclarativeColorDialog::qmlAttachedProperties(QObject *parent) +{ + return new DeclarativeColorDialogAttached(parent); +} + +CUSTOM_METAOBJECT(DeclarativeColorDialog, QColorDialog) diff --git a/lib/declarativecolordialog_p.h b/lib/declarativecolordialog_p.h new file mode 100644 index 0000000..abdd429 --- /dev/null +++ b/lib/declarativecolordialog_p.h @@ -0,0 +1,70 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVECOLORDIALOG_P_H +#define DECLARATIVECOLORDIALOG_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeColorDialogAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) + // TODO option + + public: + DeclarativeColorDialogAttached(QObject *parent = 0); + ~DeclarativeColorDialogAttached(); + + void setDialogParent(QObject *parent); + QObject *dialogParent() const; + + void setTitle(const QString &title); + QString title() const; + + Q_INVOKABLE QColor getColor(const QColor &initialColor); + + Q_SIGNALS: + void dialogParentChanged(QObject *parent); + void titleChanged(const QString &title); + + private: + QWidget *bestParentWindow(QObject *parent) const; + + class Private; + Private *const d; +}; + +class DeclarativeColorDialog : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeColorDialog(QObject *parent = 0); + + static DeclarativeColorDialogAttached *qmlAttachedProperties(QObject *parent); +}; + +QML_DECLARE_TYPEINFO(DeclarativeColorDialog, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativecolumnview.cpp b/lib/declarativecolumnview.cpp new file mode 100644 index 0000000..6d3e098 --- /dev/null +++ b/lib/declarativecolumnview.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativecolumnview_p.h" + +DeclarativeColumnView::DeclarativeColumnView(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeColumnView, ColumnView) diff --git a/lib/declarativecolumnview_p.h b/lib/declarativecolumnview_p.h new file mode 100644 index 0000000..4ecf16a --- /dev/null +++ b/lib/declarativecolumnview_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVECOLUMNVIEW_P_H +#define DECLARATIVECOLUMNVIEW_P_H + +#include "declarativewidgetproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeColumnView : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeColumnView(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativecommandlinkbutton.cpp b/lib/declarativecommandlinkbutton.cpp new file mode 100644 index 0000000..fb89b70 --- /dev/null +++ b/lib/declarativecommandlinkbutton.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativecommandlinkbutton_p.h" + +DeclarativeCommandLinkButton::DeclarativeCommandLinkButton(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeCommandLinkButton, QCommandLinkButton) diff --git a/lib/declarativecommandlinkbutton_p.h b/lib/declarativecommandlinkbutton_p.h new file mode 100644 index 0000000..817dda7 --- /dev/null +++ b/lib/declarativecommandlinkbutton_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVECOMMANDLINKBUTTON_P_H +#define DECLARATIVECOMMANDLINKBUTTON_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeCommandLinkButton : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeCommandLinkButton(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativedateedit.cpp b/lib/declarativedateedit.cpp new file mode 100644 index 0000000..5c05b07 --- /dev/null +++ b/lib/declarativedateedit.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativedateedit_p.h" + +DeclarativeDateEdit::DeclarativeDateEdit(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDateEdit, QDateEdit) diff --git a/lib/declarativedateedit_p.h b/lib/declarativedateedit_p.h new file mode 100644 index 0000000..2e4ab62 --- /dev/null +++ b/lib/declarativedateedit_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEDATEEDIT_P_H +#define DECLARATIVEDATEEDIT_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeDateEdit : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDateEdit(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativedatetimeedit.cpp b/lib/declarativedatetimeedit.cpp new file mode 100644 index 0000000..3df82a0 --- /dev/null +++ b/lib/declarativedatetimeedit.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativedatetimeedit_p.h" + +DeclarativeDateTimeEdit::DeclarativeDateTimeEdit(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDateTimeEdit, QDateTimeEdit) diff --git a/lib/declarativedatetimeedit_p.h b/lib/declarativedatetimeedit_p.h new file mode 100644 index 0000000..0cf1b31 --- /dev/null +++ b/lib/declarativedatetimeedit_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEDATETIMEEDIT_P_H +#define DECLARATIVEDATETIMEEDIT_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeDateTimeEdit : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDateTimeEdit(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativedial.cpp b/lib/declarativedial.cpp new file mode 100644 index 0000000..8b800cf --- /dev/null +++ b/lib/declarativedial.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativedial_p.h" + +DeclarativeDial::DeclarativeDial(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDial, QDial) diff --git a/lib/declarativedial_p.h b/lib/declarativedial_p.h new file mode 100644 index 0000000..288f768 --- /dev/null +++ b/lib/declarativedial_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEDIAL_P_H +#define DECLARATIVEDIAL_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeDial : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDial(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativedialog.cpp b/lib/declarativedialog.cpp new file mode 100644 index 0000000..baf8b71 --- /dev/null +++ b/lib/declarativedialog.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativedialog_p.h" + +DeclarativeDialog::DeclarativeDialog(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDialog, QDialog) diff --git a/lib/declarativedialog_p.h b/lib/declarativedialog_p.h new file mode 100644 index 0000000..bd84e8c --- /dev/null +++ b/lib/declarativedialog_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEDIALOG_P_H +#define DECLARATIVEDIALOG_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeDialog : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDialog(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativedialogbuttonbox.cpp b/lib/declarativedialogbuttonbox.cpp new file mode 100644 index 0000000..db6f033 --- /dev/null +++ b/lib/declarativedialogbuttonbox.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativedialogbuttonbox_p.h" + +DeclarativeDialogButtonBox::DeclarativeDialogButtonBox(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDialogButtonBox, QDialogButtonBox) diff --git a/lib/declarativedialogbuttonbox_p.h b/lib/declarativedialogbuttonbox_p.h new file mode 100644 index 0000000..f110a07 --- /dev/null +++ b/lib/declarativedialogbuttonbox_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEDIALOGBUTTONBOX_P_H +#define DECLARATIVEDIALOGBUTTONBOX_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeDialogButtonBox : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDialogButtonBox(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativedoublespinbox.cpp b/lib/declarativedoublespinbox.cpp new file mode 100644 index 0000000..be39057 --- /dev/null +++ b/lib/declarativedoublespinbox.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativedoublespinbox_p.h" + +DeclarativeDoubleSpinBox::DeclarativeDoubleSpinBox(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeDoubleSpinBox, QDoubleSpinBox) diff --git a/lib/declarativedoublespinbox_p.h b/lib/declarativedoublespinbox_p.h new file mode 100644 index 0000000..4aaae39 --- /dev/null +++ b/lib/declarativedoublespinbox_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEDOUBLESPINBOX_P_H +#define DECLARATIVEDOUBLESPINBOX_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeDoubleSpinBox : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeDoubleSpinBox(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativefiledialog.cpp b/lib/declarativefiledialog.cpp new file mode 100644 index 0000000..93c9a62 --- /dev/null +++ b/lib/declarativefiledialog.cpp @@ -0,0 +1,178 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativefiledialog_p.h" + +class DeclarativeFileDialogAttached::Private +{ + public: + QPointer dialogParent; + QString caption; + QString dir; + QStringList nameFilters; + QString selectedFilter; +}; + +DeclarativeFileDialogAttached::DeclarativeFileDialogAttached(QObject *parent) + : QObject(parent), d(new Private) +{ +} + +DeclarativeFileDialogAttached::~DeclarativeFileDialogAttached() +{ + delete d; +} + +void DeclarativeFileDialogAttached::setDialogParent(QObject *parent) +{ + if (parent == d->dialogParent) + return; + + d->dialogParent = parent; + emit dialogParentChanged(parent); +} + +QObject *DeclarativeFileDialogAttached::dialogParent() const +{ + return d->dialogParent; +} + +void DeclarativeFileDialogAttached::setCaption(const QString &caption) +{ + if (caption == d->caption) + return; + + d->caption = caption; + emit captionChanged(caption); +} + +QString DeclarativeFileDialogAttached::caption() const +{ + return d->caption; +} + +void DeclarativeFileDialogAttached::setDir(const QString &dir) +{ + if (dir == d->dir) + return; + + d->dir = dir; + emit dirChanged(dir); +} + +QString DeclarativeFileDialogAttached::dir() const +{ + return d->dir; +} + +void DeclarativeFileDialogAttached::setNameFilters(const QStringList &nameFilters) +{ + if (nameFilters == d->nameFilters) + return; + + d->nameFilters = nameFilters; + emit nameFiltersChanged(nameFilters); +} + +QStringList DeclarativeFileDialogAttached::nameFilters() const +{ + return d->nameFilters; +} + +QString DeclarativeFileDialogAttached::selectedFilter() const +{ + return d->selectedFilter; +} + +QString DeclarativeFileDialogAttached::getExistingDirectory() +{ + return QFileDialog::getExistingDirectory(bestParentWindow(d->dialogParent), d->caption, d->dir, QFileDialog::ShowDirsOnly); +} + +QString DeclarativeFileDialogAttached::getOpenFileName() +{ + QString selectedFilter; + const QString retVal = QFileDialog::getOpenFileName(bestParentWindow(d->dialogParent), d->caption, d->dir, + d->nameFilters.join(";;"), &selectedFilter, 0); + setSelectedFilter(selectedFilter); + return retVal; +} + +QStringList DeclarativeFileDialogAttached::getOpenFileNames() +{ + QString selectedFilter; + const QStringList retVal = QFileDialog::getOpenFileNames(bestParentWindow(d->dialogParent), d->caption, d->dir, + d->nameFilters.join(";;"), &selectedFilter, 0); + setSelectedFilter(selectedFilter); + return retVal; +} + +QString DeclarativeFileDialogAttached::getSaveFileName() +{ + QString selectedFilter; + const QString retVal = QFileDialog::getSaveFileName(bestParentWindow(d->dialogParent), d->caption, d->dir, + d->nameFilters.join(";;"), &selectedFilter, 0); + setSelectedFilter(selectedFilter); + return retVal; +} + +QWidget *DeclarativeFileDialogAttached::bestParentWindow(QObject *parent) const +{ + if (!parent) + parent = this->parent(); + + // if parent is a Declarative Object, search the proxied hierarchy + AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); + if (declarativeObject) + parent = declarativeObject->object(); + + while (parent) { + QWidget *widget = qobject_cast(parent); + if (widget) + return widget->topLevelWidget(); + + parent = parent->parent(); + } + + return 0; +} + +void DeclarativeFileDialogAttached::setSelectedFilter(const QString &filter) +{ + if (filter == d->selectedFilter) + return; + + d->selectedFilter = filter; + emit selectedFilterChanged(filter); +} + + +DeclarativeFileDialog::DeclarativeFileDialog(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeFileDialogAttached *DeclarativeFileDialog::qmlAttachedProperties(QObject *parent) +{ + return new DeclarativeFileDialogAttached(parent); +} + +CUSTOM_METAOBJECT(DeclarativeFileDialog, FileDialog) diff --git a/lib/declarativefiledialog_p.h b/lib/declarativefiledialog_p.h new file mode 100644 index 0000000..69fa604 --- /dev/null +++ b/lib/declarativefiledialog_p.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEFILEDIALOG_P_H +#define DECLARATIVEFILEDIALOG_P_H + +#include "declarativewidgetproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeFileDialogAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) + Q_PROPERTY(QString caption READ caption WRITE setCaption NOTIFY captionChanged) + Q_PROPERTY(QString dir READ dir WRITE setDir NOTIFY dirChanged) + Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged) + // TODO dialog option + Q_PROPERTY(QString selectedFilter READ selectedFilter NOTIFY selectedFilterChanged) + + public: + DeclarativeFileDialogAttached(QObject *parent = 0); + ~DeclarativeFileDialogAttached(); + + void setDialogParent(QObject *parent); + QObject *dialogParent() const; + + void setCaption(const QString &caption); + QString caption() const; + + void setDir(const QString &dir); + QString dir() const; + + void setNameFilters(const QStringList &nameFilters); + QStringList nameFilters() const; + + QString selectedFilter() const; + + Q_INVOKABLE QString getExistingDirectory(); + + Q_INVOKABLE QString getOpenFileName(); + + Q_INVOKABLE QStringList getOpenFileNames(); + + Q_INVOKABLE QString getSaveFileName(); + + Q_SIGNALS: + void dialogParentChanged(QObject *parent); + void captionChanged(const QString &caption); + void dirChanged(const QString &dir); + void nameFiltersChanged(const QStringList &filters); + void selectedFilterChanged(const QString &filter); + + private: + QWidget *bestParentWindow(QObject *parent) const; + void setSelectedFilter(const QString &filter); + + class Private; + Private *const d; +}; + +class DeclarativeFileDialog : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeFileDialog(QObject *parent = 0); + + static DeclarativeFileDialogAttached *qmlAttachedProperties(QObject *parent); +}; + +QML_DECLARE_TYPEINFO(DeclarativeFileDialog, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativefontdialog.cpp b/lib/declarativefontdialog.cpp new file mode 100644 index 0000000..c7e433d --- /dev/null +++ b/lib/declarativefontdialog.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativefontdialog_p.h" + +DeclarativeFontDialog::DeclarativeFontDialog(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeFontDialog, QFontDialog) diff --git a/lib/declarativefontdialog_p.h b/lib/declarativefontdialog_p.h new file mode 100644 index 0000000..354e6e1 --- /dev/null +++ b/lib/declarativefontdialog_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEFONTDIALOG_P_H +#define DECLARATIVEFONTDIALOG_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeFontDialog : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeFontDialog(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativeformlayout.cpp b/lib/declarativeformlayout.cpp new file mode 100644 index 0000000..02c31d7 --- /dev/null +++ b/lib/declarativeformlayout.cpp @@ -0,0 +1,95 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeformlayout_p.h" + +class DeclarativeFormLayoutAttached::Private +{ + public: + QString label; +}; + +DeclarativeFormLayoutAttached::DeclarativeFormLayoutAttached(QObject *parent) + : QObject(parent), d(new Private) +{ +} + +DeclarativeFormLayoutAttached::~DeclarativeFormLayoutAttached() +{ + delete d; +} + +void DeclarativeFormLayoutAttached::setLabel(const QString &label) +{ + if (label == d->label) + return; + + d->label = label; + emit labelChanged(label); +} + +QString DeclarativeFormLayoutAttached::label() const +{ + return d->label; +} + +// DeclarativeFormLayout +DeclarativeFormLayout::DeclarativeFormLayout(QObject *parent) : DeclarativeLayoutProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeFormLayoutAttached *DeclarativeFormLayout::qmlAttachedProperties(QObject *parent) +{ + return new DeclarativeFormLayoutAttached(parent); +} + +void DeclarativeFormLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeFormLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + if (!properties->label().isEmpty()) { + m_proxiedObject->addRow(properties->label(), widget); + m_children.append(declarativeObject); + return; + } + } + + m_proxiedObject->addRow(widget); + m_children.append(declarativeObject); +} + +void DeclarativeFormLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeFormLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + if (!properties->label().isEmpty()) { + m_proxiedObject->addRow(properties->label(), layout); + m_children.append(declarativeObject); + return; + } + } + m_proxiedObject->addRow(layout); + m_children.append(declarativeObject); +} + +CUSTOM_METAOBJECT(DeclarativeFormLayout, QFormLayout) diff --git a/lib/declarativeformlayout_p.h b/lib/declarativeformlayout_p.h new file mode 100644 index 0000000..1cbe86f --- /dev/null +++ b/lib/declarativeformlayout_p.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEFORMLAYOUT_P_H +#define DECLARATIVEFORMLAYOUT_P_H + +#include "declarativelayoutproxy_p.h" + +#include + +class DeclarativeFormLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) + + public: + DeclarativeFormLayoutAttached(QObject *parent); + ~DeclarativeFormLayoutAttached(); + + void setLabel(const QString &label); + QString label() const; + + Q_SIGNALS: + void labelChanged(const QString &label); + + private: + class Private; + Private *const d; +}; + +class DeclarativeFormLayout : public DeclarativeLayoutProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeFormLayout(QObject *parent = 0); + + static DeclarativeFormLayoutAttached *qmlAttachedProperties(QObject *parent); + + protected: + void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +QML_DECLARE_TYPEINFO(DeclarativeFormLayout, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativeframe.cpp b/lib/declarativeframe.cpp new file mode 100644 index 0000000..8b8418e --- /dev/null +++ b/lib/declarativeframe.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeframe_p.h" + +DeclarativeFrame::DeclarativeFrame(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeFrame, QFrame) diff --git a/lib/declarativeframe_p.h b/lib/declarativeframe_p.h new file mode 100644 index 0000000..c96252c --- /dev/null +++ b/lib/declarativeframe_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEFRAME_P_H +#define DECLARATIVEFRAME_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeFrame : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeFrame(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativegridlayout.cpp b/lib/declarativegridlayout.cpp new file mode 100644 index 0000000..dab5a44 --- /dev/null +++ b/lib/declarativegridlayout.cpp @@ -0,0 +1,212 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativegridlayout_p.h" + +class DeclarativeGridLayoutAttached::Private +{ + public: + Private(QWidget *w, QLayout *l) + : row(0), column(0), rowSpan(1), columnSpan(1), alignment(0), + widget(w), layout(l) + {} + + int row; + int column; + int rowSpan; + int columnSpan; + Qt::Alignment alignment; + + QPointer widget; + QPointer layout; + QPointer parentLayout; +}; + +DeclarativeGridLayoutAttached::DeclarativeGridLayoutAttached(QWidget *widget, QObject *parent) + : QObject(parent), d(new Private(widget, 0)) +{ +} + +DeclarativeGridLayoutAttached::DeclarativeGridLayoutAttached(QLayout *layout, QObject *parent) + : QObject(parent), d(new Private(0, layout)) +{ +} + +DeclarativeGridLayoutAttached::~DeclarativeGridLayoutAttached() +{ + delete d; +} + +void DeclarativeGridLayoutAttached::setParentLayout(QGridLayout *parentLayout) +{ + d->parentLayout = parentLayout; +} + +void DeclarativeGridLayoutAttached::setRow(int row) +{ + if (row == d->row) + return; + + d->row = row; + emit rowChanged(row); +} + +int DeclarativeGridLayoutAttached::row() const +{ + return d->row; +} + +void DeclarativeGridLayoutAttached::setColumn(int column) +{ + if (column == d->column) + return; + + d->column = column; + emit columnChanged(column); +} + +int DeclarativeGridLayoutAttached::column() const +{ + return d->column; +} + +void DeclarativeGridLayoutAttached::setRowSpan(int rowSpan) +{ + if (rowSpan == d->rowSpan) + return; + + d->rowSpan = rowSpan; + emit rowSpanChanged(rowSpan); +} + +int DeclarativeGridLayoutAttached::rowSpan() const +{ + return d->rowSpan; +} + +void DeclarativeGridLayoutAttached::setColumnSpan(int columnSpan) +{ + if (columnSpan == d->columnSpan) + return; + + d->columnSpan = columnSpan; + emit columnSpanChanged(columnSpan); +} + +int DeclarativeGridLayoutAttached::columnSpan() const +{ + return d->columnSpan; +} + +void DeclarativeGridLayoutAttached::setAlignment(Qt::Alignment alignment) +{ + if (alignment == d->alignment) + return; + + d->alignment = alignment; + emit alignmentChanged(alignment); + + if (d->parentLayout) { + if (d->widget) + d->parentLayout->setAlignment(d->widget, d->alignment); + + if (d->layout) + d->parentLayout->setAlignment(d->layout, d->alignment); + } +} + +Qt::Alignment DeclarativeGridLayoutAttached::alignment() const +{ + return d->alignment; +} + +// DeclarativeGridLayout +DeclarativeGridLayout::DeclarativeGridLayout(QObject *parent) : DeclarativeLayoutProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeGridLayoutAttached *DeclarativeGridLayout::qmlAttachedProperties(QObject *parent) +{ + AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); + if (declarativeObject) { + QWidget *widget = qobject_cast(declarativeObject->object()); + if (widget) + return new DeclarativeGridLayoutAttached(widget, parent); + + QLayout *layout = qobject_cast(declarativeObject->object()); + if (layout) + return new DeclarativeGridLayoutAttached(layout, parent); + } + + qmlInfo(parent) << "Can only attach GridLayout to widgets and layouts"; + return 0; +} + +void DeclarativeGridLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + int row = 0; + int column = 0; + int rowSpan = 1; + int columnSpan = 1; + Qt::Alignment alignment = 0; + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeGridLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + row = properties->row(); + column = properties->column(); + rowSpan = properties->rowSpan(); + columnSpan = properties->columnSpan(); + alignment = properties->alignment(); + + properties->setParentLayout(m_proxiedObject); + } + + m_proxiedObject->addWidget(widget, row, column, rowSpan, columnSpan, alignment); + m_children.append(declarativeObject); +} + +void DeclarativeGridLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + int row = 0; + int column = 0; + int rowSpan = 1; + int columnSpan = 1; + Qt::Alignment alignment = 0; + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeGridLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + row = properties->row(); + column = properties->column(); + rowSpan = properties->rowSpan(); + columnSpan = properties->columnSpan(); + alignment = properties->alignment(); + + properties->setParentLayout(m_proxiedObject); + } + + m_proxiedObject->addLayout(layout, row, column, rowSpan, columnSpan, alignment); + m_children.append(declarativeObject); +} + +CUSTOM_METAOBJECT(DeclarativeGridLayout, QGridLayout) + diff --git a/lib/declarativegridlayout_p.h b/lib/declarativegridlayout_p.h new file mode 100644 index 0000000..89e3fec --- /dev/null +++ b/lib/declarativegridlayout_p.h @@ -0,0 +1,88 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEGRIDLAYOUT_P_H +#define DECLARATIVEGRIDLAYOUT_P_H + +#include "declarativelayoutproxy_p.h" + +#include + +class DeclarativeGridLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged) + Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged) + Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan NOTIFY rowSpanChanged) + Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan NOTIFY columnSpanChanged) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) + + public: + DeclarativeGridLayoutAttached(QWidget *widget, QObject *parent); + DeclarativeGridLayoutAttached(QLayout *layout, QObject *parent); + ~DeclarativeGridLayoutAttached(); + + void setParentLayout(QGridLayout *parentLayout); + + void setRow(int row); + int row() const; + + void setColumn(int column); + int column() const; + + void setRowSpan(int rowSpan); + int rowSpan() const; + + void setColumnSpan(int columnSpan); + int columnSpan() const; + + void setAlignment(Qt::Alignment alignment); + Qt::Alignment alignment() const; + + Q_SIGNALS: + void rowChanged(int row); + void columnChanged(int column); + void rowSpanChanged(int rowSpan); + void columnSpanChanged(int columnSpan); + void alignmentChanged(Qt::Alignment alignment); + + private: + class Private; + Private *const d; +}; + +class DeclarativeGridLayout : public DeclarativeLayoutProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeGridLayout(QObject *parent = 0); + + static DeclarativeGridLayoutAttached *qmlAttachedProperties(QObject *parent); + + protected: + void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +QML_DECLARE_TYPEINFO(DeclarativeGridLayout, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativegroupbox.cpp b/lib/declarativegroupbox.cpp new file mode 100644 index 0000000..959da9c --- /dev/null +++ b/lib/declarativegroupbox.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativegroupbox_p.h" + +DeclarativeGroupBox::DeclarativeGroupBox(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeGroupBox, QGroupBox) diff --git a/lib/declarativegroupbox_p.h b/lib/declarativegroupbox_p.h new file mode 100644 index 0000000..e0316d0 --- /dev/null +++ b/lib/declarativegroupbox_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEGROUPBOX_P_H +#define DECLARATIVEGROUPBOX_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeGroupBox : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeGroupBox(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativehboxlayout.cpp b/lib/declarativehboxlayout.cpp new file mode 100644 index 0000000..d177152 --- /dev/null +++ b/lib/declarativehboxlayout.cpp @@ -0,0 +1,83 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativehboxlayout_p.h" + +DeclarativeHBoxLayout::DeclarativeHBoxLayout(QObject *parent) + : DeclarativeLayoutProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeBoxLayoutAttached *DeclarativeHBoxLayout::qmlAttachedProperties(QObject *parent) +{ + AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); + if (declarativeObject) { + QWidget *widget = qobject_cast(declarativeObject->object()); + if (widget) + return new DeclarativeBoxLayoutAttached(widget, parent); + + QLayout *layout = qobject_cast(declarativeObject->object()); + if (layout) + return new DeclarativeBoxLayoutAttached(layout, parent); + } + + qmlInfo(parent) << "Can only attach HBoxLayout to widgets and layouts"; + return 0; +} + +void DeclarativeHBoxLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + int stretch = 0; + Qt::Alignment alignment = 0; + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + stretch = properties->stretch(); + alignment = properties->alignment(); + + properties->setParentLayout(m_proxiedObject); + } + + m_proxiedObject->addWidget(widget, stretch, alignment); + m_children.append(declarativeObject); +} + +void DeclarativeHBoxLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + int stretch = 0; + Qt::Alignment alignment = 0; + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + stretch = properties->stretch(); + alignment = properties->alignment(); + + properties->setParentLayout(m_proxiedObject); + } + + m_proxiedObject->addLayout(layout, stretch); + m_proxiedObject->setAlignment(layout, alignment); + m_children.append(declarativeObject); +} + +CUSTOM_METAOBJECT(DeclarativeHBoxLayout, QHBoxLayout) diff --git a/lib/declarativehboxlayout_p.h b/lib/declarativehboxlayout_p.h new file mode 100644 index 0000000..f0bb378 --- /dev/null +++ b/lib/declarativehboxlayout_p.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEHBOXLAYOUT_P_H +#define DECLARATIVEHBOXLAYOUT_P_H + +#include "declarativeboxlayout_p.h" +#include "declarativelayoutproxy_p.h" + +#include + +class DeclarativeHBoxLayout : public DeclarativeLayoutProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeHBoxLayout(QObject *parent = 0); + + static DeclarativeBoxLayoutAttached *qmlAttachedProperties(QObject *parent); + + protected: + void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +QML_DECLARE_TYPEINFO(DeclarativeHBoxLayout, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativeinputdialog.cpp b/lib/declarativeinputdialog.cpp new file mode 100644 index 0000000..d23aacd --- /dev/null +++ b/lib/declarativeinputdialog.cpp @@ -0,0 +1,324 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeinputdialog_p.h" + +class DeclarativeInputDialogAttached::Private +{ + public: + Private() : dialogAccepted(false), + value(0), min(-2147483647), max(2147483647), decimals(1), step(1), + currentItem(0), itemsEditable(true), + echoMode(QLineEdit::Normal) + {} + + public: + QPointer dialogParent; + QString title; + QString label; + bool dialogAccepted; + + QVariant value; + QVariant min; + QVariant max; + int decimals; + int step; + + int currentItem; + bool itemsEditable; + + QLineEdit::EchoMode echoMode; + QString text; +}; + +DeclarativeInputDialogAttached::DeclarativeInputDialogAttached(QObject *parent) + : QObject(parent), d(new Private) +{ +} + +DeclarativeInputDialogAttached::~DeclarativeInputDialogAttached() +{ + delete d; +} + +void DeclarativeInputDialogAttached::setDialogParent(QObject *parent) +{ + if (parent == d->dialogParent) + return; + + d->dialogParent = parent; + emit dialogParentChanged(parent); +} + +QObject *DeclarativeInputDialogAttached::dialogParent() const +{ + return d->dialogParent; +} + +void DeclarativeInputDialogAttached::setTitle(const QString &title) +{ + if (title == d->title) + return; + + d->title = title; + emit titleChanged(title); +} + +QString DeclarativeInputDialogAttached::title() const +{ + return d->title; +} + +void DeclarativeInputDialogAttached::setLabel(const QString &label) +{ + if (label == d->label) + return; + + d->label = label; + emit labelChanged(label); +} + +QString DeclarativeInputDialogAttached::label() const +{ + return d->label; +} + +bool DeclarativeInputDialogAttached::dialogAccepted() const +{ + return d->dialogAccepted; +} + +void DeclarativeInputDialogAttached::setValue(const QVariant &value) +{ + if (value == d->value) + return; + + d->value = value; + emit valueChanged(value); +} + +QVariant DeclarativeInputDialogAttached::value() const +{ + return d->value; +} + +void DeclarativeInputDialogAttached::setMin(const QVariant &min) +{ + if (min == d->min) + return; + + d->min = min; + emit minChanged(min); +} + +QVariant DeclarativeInputDialogAttached::min() const +{ + return d->min; +} + +void DeclarativeInputDialogAttached::setMax(const QVariant &max) +{ + if (max == d->max) + return; + + d->max = max; + emit maxChanged(max); +} + +QVariant DeclarativeInputDialogAttached::max() const +{ + return d->max; +} + +void DeclarativeInputDialogAttached::setDecimals(int decimals) +{ + if (decimals == d->decimals) + return; + + d->decimals = decimals; + emit decimalsChanged(decimals); +} + +int DeclarativeInputDialogAttached::decimals() const +{ + return d->decimals; +} + +void DeclarativeInputDialogAttached::setStep(int step) +{ + if (step == d->step) + return; + + d->step = step; + emit stepChanged(step); +} + +int DeclarativeInputDialogAttached::step() const +{ + return d->step; +} + +void DeclarativeInputDialogAttached::setCurrentItem(int current) +{ + if (current == d->currentItem) + return; + + d->currentItem = current; + emit currentItemChanged(current); +} + +int DeclarativeInputDialogAttached::currentItem() const +{ + return d->currentItem; +} + +void DeclarativeInputDialogAttached::setItemsEditable(bool editable) +{ + if (editable == d->itemsEditable) + return; + + d->itemsEditable = editable; + emit itemsEditableChanged(editable); +} + +bool DeclarativeInputDialogAttached::itemsEditable() const +{ + return d->itemsEditable; +} + +void DeclarativeInputDialogAttached::setEchoMode(QLineEdit::EchoMode echoMode) +{ + if (echoMode == d->echoMode) + return; + + d->echoMode = echoMode; + emit echoModeChanged(echoMode); +} + +QLineEdit::EchoMode DeclarativeInputDialogAttached::echoMode() const +{ + return d->echoMode; +} + +void DeclarativeInputDialogAttached::setText(const QString &text) +{ + if (text == d->text) + return; + + d->text = text; + emit textChanged(text); +} + +QString DeclarativeInputDialogAttached::text() const +{ + return d->text; +} + +double DeclarativeInputDialogAttached::getDouble() +{ + QWidget *parent = bestParentWindow(d->dialogParent); + bool ok = false; + const double value = d->value.canConvert() ? d->value.value() : 0.0; + const double min = d->min.canConvert() ? d->min.value() : -2147483647; + const double max = d->max.canConvert() ? d->max.value() : 2147483647; + + const double retVal = QInputDialog::getDouble(parent, d->title, d->label, value, min, max, d->decimals, &ok); + + setDialogAccepted(ok); + return retVal; +} + +int DeclarativeInputDialogAttached::getInt() +{ + QWidget *parent = bestParentWindow(d->dialogParent); + bool ok = false; + const int value = d->value.canConvert() ? d->value.value() : 0; + const int min = d->min.canConvert() ? d->min.value() : -2147483647; + const int max = d->max.canConvert() ? d->max.value() : 2147483647; + + const int retVal = QInputDialog::getInt(parent, d->title, d->label, value, min, max, d->step, &ok); + + setDialogAccepted(ok); + return retVal; +} + +QString DeclarativeInputDialogAttached::getItem(const QStringList &items) +{ + QWidget *parent = bestParentWindow(d->dialogParent); + bool ok = false; + + const QString retVal = QInputDialog::getItem(parent, d->title, d->label, items, d->currentItem, d->itemsEditable, &ok); + + setDialogAccepted(ok); + return retVal; +} + +QString DeclarativeInputDialogAttached::getText() +{ + QWidget *parent = bestParentWindow(d->dialogParent); + bool ok = false; + + const QString retVal = QInputDialog::getText(parent, d->title, d->label, d->echoMode, d->text, &ok); + + setDialogAccepted(ok); + return retVal; +} + +void DeclarativeInputDialogAttached::setDialogAccepted(bool accepted) +{ + if (accepted == d->dialogAccepted) + return; + + d->dialogAccepted = accepted; + emit dialogAcceptedChanged(accepted); +} + +QWidget *DeclarativeInputDialogAttached::bestParentWindow(QObject *parent) const +{ + if (!parent) + parent = this->parent(); + + // if parent is a Declarative Object, search the proxied hierarchy + AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); + if (declarativeObject) + parent = declarativeObject->object(); + + while (parent) { + QWidget *widget = qobject_cast(parent); + if (widget) + return widget->topLevelWidget(); + + parent = parent->parent(); + } + + return 0; +} + +DeclarativeInputDialog::DeclarativeInputDialog(QObject *parent) : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeInputDialogAttached *DeclarativeInputDialog::qmlAttachedProperties(QObject *parent) +{ + return new DeclarativeInputDialogAttached(parent); +} + +CUSTOM_METAOBJECT(DeclarativeInputDialog, InputDialog) diff --git a/lib/declarativeinputdialog_p.h b/lib/declarativeinputdialog_p.h new file mode 100644 index 0000000..d2705d4 --- /dev/null +++ b/lib/declarativeinputdialog_p.h @@ -0,0 +1,136 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEINPUTDIALOG_P_H +#define DECLARATIVEINPUTDIALOG_P_H + +#include "declarativewidgetproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeInputDialogAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject* parent READ dialogParent WRITE setDialogParent NOTIFY dialogParentChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) + Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) + Q_PROPERTY(bool ok READ dialogAccepted NOTIFY dialogAcceptedChanged) + + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(QVariant min READ min WRITE setMin NOTIFY minChanged) + Q_PROPERTY(QVariant max READ max WRITE setMax NOTIFY maxChanged) + Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged) + Q_PROPERTY(int step READ step WRITE setStep NOTIFY stepChanged) + + Q_PROPERTY(int current READ currentItem WRITE setCurrentItem NOTIFY currentItemChanged) + Q_PROPERTY(bool editable READ itemsEditable WRITE setItemsEditable NOTIFY itemsEditableChanged) + + Q_PROPERTY(QLineEdit::EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged) + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + + public: + DeclarativeInputDialogAttached(QObject *parent = 0); + ~DeclarativeInputDialogAttached(); + + void setDialogParent(QObject *parent); + QObject *dialogParent() const; + + void setTitle(const QString &title); + QString title() const; + + void setLabel(const QString &label); + QString label() const; + + bool dialogAccepted() const; + + void setValue(const QVariant &value); + QVariant value() const; + + void setMin(const QVariant &min); + QVariant min() const; + + void setMax(const QVariant &max); + QVariant max() const; + + void setDecimals(int decimals); + int decimals() const; + + void setStep(int step); + int step() const; + + void setCurrentItem(int current); + int currentItem() const; + + void setItemsEditable(bool editable); + bool itemsEditable() const; + + void setEchoMode(QLineEdit::EchoMode echoMode); + QLineEdit::EchoMode echoMode() const; + + void setText(const QString &text); + QString text() const; + + Q_INVOKABLE double getDouble(); + + Q_INVOKABLE int getInt(); + + Q_INVOKABLE QString getItem(const QStringList &items); + + Q_INVOKABLE QString getText(); + + Q_SIGNALS: + void dialogParentChanged(QObject *parent); + void titleChanged(const QString &title); + void labelChanged(const QString &label); + void dialogAcceptedChanged(bool accepted); + + void valueChanged(const QVariant &value); + void minChanged(const QVariant &min); + void maxChanged(const QVariant &max); + void decimalsChanged(int decimals); + void stepChanged(int step); + + void currentItemChanged(int current); + void itemsEditableChanged(bool editable); + + void echoModeChanged(QLineEdit::EchoMode echoMode); + void textChanged(const QString &text); + + private: + void setDialogAccepted(bool accepted); + QWidget *bestParentWindow(QObject *parent) const; + + class Private; + Private *const d; +}; + +class DeclarativeInputDialog : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeInputDialog(QObject *parent = 0); + + static DeclarativeInputDialogAttached *qmlAttachedProperties(QObject *parent); +}; + +QML_DECLARE_TYPEINFO(DeclarativeInputDialog, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativelabel.cpp b/lib/declarativelabel.cpp new file mode 100644 index 0000000..fc94f36 --- /dev/null +++ b/lib/declarativelabel.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativelabel_p.h" + +DeclarativeLabel::DeclarativeLabel(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeLabel, QLabel) diff --git a/lib/declarativelabel_p.h b/lib/declarativelabel_p.h new file mode 100644 index 0000000..7630b5d --- /dev/null +++ b/lib/declarativelabel_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVELABEL_P_H +#define DECLARATIVELABEL_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeLabel : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeLabel(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativelayoutproxy_p.h b/lib/declarativelayoutproxy_p.h new file mode 100644 index 0000000..a3fcbd4 --- /dev/null +++ b/lib/declarativelayoutproxy_p.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVELAYOUTPROXY_P_H +#define DECLARATIVELAYOUTPROXY_P_H + +#include "declarativeobjectproxy_p.h" + +#include +#include + +template +class DeclarativeLayoutProxy : public DeclarativeObjectProxy +{ + public: + DeclarativeLayoutProxy(QObject *parent = 0) : DeclarativeObjectProxy(parent) {} + + protected: + virtual void dataAppend(QObject *object) + { + AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); + if (declarativeObject) { + QWidget *widget = qobject_cast(declarativeObject->object()); + if (widget) { + addWidget(widget, declarativeObject); + return; + } + + QLayout *layout = qobject_cast(declarativeObject->object()); + if (layout) { + addLayout(layout, declarativeObject); + return; + } + } + + DeclarativeObjectProxy::dataAppend(object); + } + + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) + { + DeclarativeObjectProxy::m_children.append(declarativeObject); + DeclarativeObjectProxy::m_proxiedObject->addWidget(widget); + } + + virtual void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) = 0; +}; + +#endif diff --git a/lib/declarativelcdnumber.cpp b/lib/declarativelcdnumber.cpp new file mode 100644 index 0000000..4c8d30b --- /dev/null +++ b/lib/declarativelcdnumber.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativelcdnumber_p.h" + +DeclarativeLCDNumber::DeclarativeLCDNumber(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeLCDNumber, QLCDNumber) diff --git a/lib/declarativelcdnumber_p.h b/lib/declarativelcdnumber_p.h new file mode 100644 index 0000000..f8518a7 --- /dev/null +++ b/lib/declarativelcdnumber_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVELCDNUMBER_P_H +#define DECLARATIVELCDNUMBER_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeLCDNumber : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeLCDNumber(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativelineedit.cpp b/lib/declarativelineedit.cpp new file mode 100644 index 0000000..cd0b2d9 --- /dev/null +++ b/lib/declarativelineedit.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativelineedit_p.h" + +DeclarativeLineEdit::DeclarativeLineEdit(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeLineEdit, QLineEdit) diff --git a/lib/declarativelineedit_p.h b/lib/declarativelineedit_p.h new file mode 100644 index 0000000..d308452 --- /dev/null +++ b/lib/declarativelineedit_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVELINEEDIT_P_H +#define DECLARATIVELINEEDIT_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeLineEdit : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeLineEdit(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativelistview.cpp b/lib/declarativelistview.cpp new file mode 100644 index 0000000..4362b4e --- /dev/null +++ b/lib/declarativelistview.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativelistview_p.h" + +DeclarativeListView::DeclarativeListView(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeListView, ListView) diff --git a/lib/declarativelistview_p.h b/lib/declarativelistview_p.h new file mode 100644 index 0000000..9c236c8 --- /dev/null +++ b/lib/declarativelistview_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVELISTVIEW_P_H +#define DECLARATIVELISTVIEW_P_H + +#include "declarativewidgetproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeListView : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeListView(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativemainwindow.cpp b/lib/declarativemainwindow.cpp new file mode 100644 index 0000000..b3b0fa5 --- /dev/null +++ b/lib/declarativemainwindow.cpp @@ -0,0 +1,68 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativemainwindow_p.h" + +#include +#include +#include + +DeclarativeMainWindow::DeclarativeMainWindow(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeMainWindow::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + QMenuBar *menuBar = qobject_cast(widget); + QToolBar *toolBar = qobject_cast(widget); + QStatusBar *statusBar = qobject_cast(widget); + QDialog *dialog = qobject_cast(widget); + + if (menuBar) { + m_proxiedObject->setMenuBar(menuBar); + } else if (toolBar) { + m_proxiedObject->addToolBar(toolBar); + } else if (statusBar) { + m_proxiedObject->setStatusBar(statusBar); + } else if (dialog) { + // We allow to place dialogs on the mainwindow + dialog->setParent(m_proxiedObject, dialog->windowFlags()); + } else if (widget) { + if (m_proxiedObject->centralWidget()) { + qmlInfo(declarativeObject) << "The QMainWindow contains a central widget already"; + return; + } + + m_proxiedObject->setCentralWidget(widget); + } + + m_children.append(declarativeObject); +} + +void DeclarativeMainWindow::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(layout); + Q_UNUSED(declarativeObject); + qmlInfo(this) << "Can not set a QLayout to a QMainWindow"; +} + +CUSTOM_METAOBJECT(DeclarativeMainWindow, QMainWindow) diff --git a/lib/declarativemainwindow_p.h b/lib/declarativemainwindow_p.h new file mode 100644 index 0000000..c51af70 --- /dev/null +++ b/lib/declarativemainwindow_p.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEMAINWINDOW_P_H +#define DECLARATIVEMAINWINDOW_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeMainWindow : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeMainWindow(QObject *parent = 0); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +#endif diff --git a/lib/declarativemenu.cpp b/lib/declarativemenu.cpp new file mode 100644 index 0000000..965bef0 --- /dev/null +++ b/lib/declarativemenu.cpp @@ -0,0 +1,64 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativemenu_p.h" + +#include "declarativeseparator_p.h" + +DeclarativeMenu::DeclarativeMenu(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeMenu::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + QMenu *menu = qobject_cast(widget); + if (!menu) { + qmlInfo(declarativeObject) << "The QMenu can only contain QMenu, QAction or Separator"; + return; + } + + m_proxiedObject->addMenu(menu); + + m_children.append(declarativeObject); +} + +void DeclarativeMenu::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(layout); + Q_UNUSED(declarativeObject); + qmlInfo(this) << "Can not set a QLayout to a QMenu"; +} + +void DeclarativeMenu::addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) +{ + DeclarativeSeparator *separator = dynamic_cast(declarativeObject); + + if (separator) { + m_proxiedObject->addSeparator(); + } else { + m_proxiedObject->addAction(action); + } + + m_children.append(declarativeObject); +} + +CUSTOM_METAOBJECT(DeclarativeMenu, QMenu) diff --git a/lib/declarativemenu_p.h b/lib/declarativemenu_p.h new file mode 100644 index 0000000..6e8d8dd --- /dev/null +++ b/lib/declarativemenu_p.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEMENU_P_H +#define DECLARATIVEMENU_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeMenu : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeMenu(QObject *parent = 0); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); + virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject); +}; + +#endif diff --git a/lib/declarativemenubar.cpp b/lib/declarativemenubar.cpp new file mode 100644 index 0000000..acb58dc --- /dev/null +++ b/lib/declarativemenubar.cpp @@ -0,0 +1,64 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativemenubar_p.h" + +#include "declarativeseparator_p.h" + +DeclarativeMenuBar::DeclarativeMenuBar(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeMenuBar::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + QMenu *menu = qobject_cast(widget); + if (!menu) { + qmlInfo(declarativeObject) << "The QMenuBar can only contain QMenus"; + return; + } + + m_proxiedObject->addMenu(menu); + + m_children.append(declarativeObject); +} + +void DeclarativeMenuBar::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(layout); + Q_UNUSED(declarativeObject); + qmlInfo(this) << "Can not set a QLayout to a QMenuBar"; +} + +void DeclarativeMenuBar::addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(action) + + DeclarativeSeparator *separator = dynamic_cast(declarativeObject); + + if (separator) { + m_proxiedObject->addSeparator(); + } + + m_children.append(declarativeObject); +} + +CUSTOM_METAOBJECT(DeclarativeMenuBar, QMenuBar) diff --git a/lib/declarativemenubar_p.h b/lib/declarativemenubar_p.h new file mode 100644 index 0000000..5257cf0 --- /dev/null +++ b/lib/declarativemenubar_p.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEMENUBAR_P_H +#define DECLARATIVEMENUBAR_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeMenuBar : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeMenuBar(QObject *parent = 0); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); + virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject); +}; + +#endif diff --git a/lib/declarativemessagebox.cpp b/lib/declarativemessagebox.cpp new file mode 100644 index 0000000..4eca6b2 --- /dev/null +++ b/lib/declarativemessagebox.cpp @@ -0,0 +1,89 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativemessagebox_p.h" + +DeclarativeMessageBoxAttached::DeclarativeMessageBoxAttached(QObject *parent) + : QObject(parent) +{ +} + +void DeclarativeMessageBoxAttached::about(QObject *parent, const QString &title, const QString &text) +{ + QMessageBox::about(bestParentWindow(parent), title, text); +} + +void DeclarativeMessageBoxAttached::aboutQt(QObject *parent, const QString &title) +{ + QMessageBox::aboutQt(bestParentWindow(parent), title); +} + +int DeclarativeMessageBoxAttached::critical(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) +{ + return QMessageBox::critical(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); +} + +int DeclarativeMessageBoxAttached::information(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) +{ + return QMessageBox::information(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); +} + +int DeclarativeMessageBoxAttached::question(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) +{ + return QMessageBox::question(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); +} + +int DeclarativeMessageBoxAttached::warning(QObject *parent, const QString &title, const QString &text, int buttons, int defaultButton) +{ + return QMessageBox::warning(bestParentWindow(parent), title, text, static_cast(buttons), static_cast(defaultButton)); +} + +QWidget *DeclarativeMessageBoxAttached::bestParentWindow(QObject *parent) const +{ + if (!parent) + parent = this->parent(); + + // if parent is a Declarative Object, search the proxied hierarchy + AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); + if (declarativeObject) + parent = declarativeObject->object(); + + while (parent) { + QWidget *widget = qobject_cast(parent); + if (widget) + return widget->topLevelWidget(); + + parent = parent->parent(); + } + + return 0; +} + +DeclarativeMessageBox::DeclarativeMessageBox(QObject *parent) : DeclarativeObjectProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeMessageBoxAttached *DeclarativeMessageBox::qmlAttachedProperties(QObject *parent) +{ + return new DeclarativeMessageBoxAttached(parent); +} + +CUSTOM_METAOBJECT(DeclarativeMessageBox, QMessageBox) diff --git a/lib/declarativemessagebox_p.h b/lib/declarativemessagebox_p.h new file mode 100644 index 0000000..b04bb20 --- /dev/null +++ b/lib/declarativemessagebox_p.h @@ -0,0 +1,62 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEMESSAGEBOX_P_H +#define DECLARATIVEMESSAGEBOX_P_H + +#include "declarativeobjectproxy_p.h" + +#include + +class DeclarativeMessageBoxAttached : public QObject +{ + Q_OBJECT + + public: + DeclarativeMessageBoxAttached(QObject *parent = 0); + + Q_INVOKABLE void about(QObject *parent, const QString &title, const QString &text); + Q_INVOKABLE void aboutQt(QObject *parent, const QString &title); + Q_INVOKABLE int critical(QObject *parent, const QString &title, const QString &text, + int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); + Q_INVOKABLE int information(QObject *parent, const QString &title, const QString &text, + int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); + Q_INVOKABLE int question(QObject *parent, const QString &title, const QString &text, + int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); + Q_INVOKABLE int warning(QObject *parent, const QString &title, const QString &text, + int buttons = QMessageBox::Ok, int defaultButton = QMessageBox::NoButton); + + private: + QWidget *bestParentWindow(QObject *parent) const; +}; + +class DeclarativeMessageBox : public DeclarativeObjectProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeMessageBox(QObject *parent = 0); + + static DeclarativeMessageBoxAttached *qmlAttachedProperties(QObject *parent); +}; + +QML_DECLARE_TYPEINFO(DeclarativeMessageBox, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativeobjectproxy_p.h b/lib/declarativeobjectproxy_p.h new file mode 100644 index 0000000..1b52b8b --- /dev/null +++ b/lib/declarativeobjectproxy_p.h @@ -0,0 +1,156 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEOBJECTPROXY_P_H +#define DECLARATIVEOBJECTPROXY_P_H + +#include "abstractdeclarativeobject_p.h" + +#include +#include +#include +#include + +#define DECLARATIVE_OBJECT \ + public: \ + Q_OBJECT_CHECK \ + static QMetaObject staticMetaObject; \ + static bool metaObjectInitialized; \ + static bool initializeMetaObject(); \ + static const QMetaObject &getStaticMetaObject(); \ + virtual const QMetaObject *metaObject() const; \ + virtual void *qt_metacast(const char *); \ + virtual int qt_metacall(QMetaObject::Call, int, void **); \ + private: \ + + +template +class DeclarativeObjectProxy : public AbstractDeclarativeObject +{ +}; + +template +class DeclarativeObjectProxy : public AbstractDeclarativeObject +{ + public: + DeclarativeObjectProxy(QObject *parent = 0) : AbstractDeclarativeObject(parent), m_proxiedObject(new T) {} + ~DeclarativeObjectProxy() { delete m_proxiedObject; } + + virtual QObject *object() const { return m_proxiedObject.data(); } + + protected: + virtual void dataAppend(QObject *object) + { + m_children.append(object); + } + + virtual int dataCount() const { return m_children.count(); } + virtual QObject *dataAt(int index) const { return m_children.at(index); } + virtual void dataClear() + { + qDeleteAll(m_children); + m_children.clear(); + } + + protected: + QPointer m_proxiedObject; + QVector m_children; +}; + +template +class DeclarativeObjectProxy : public AbstractDeclarativeObject +{ + public: + DeclarativeObjectProxy(QObject *parent = 0) : AbstractDeclarativeObject(parent), m_proxiedObject(new T(0)) {} + ~DeclarativeObjectProxy() { delete m_proxiedObject; } + + virtual QObject *object() const { return m_proxiedObject.data(); } + + protected: + virtual void dataAppend(QObject *object) + { + m_children.append(object); + } + + virtual int dataCount() const { return m_children.count(); } + virtual QObject *dataAt(int index) const { return m_children.at(index); } + virtual void dataClear() + { + qDeleteAll(m_children); + m_children.clear(); + } + + protected: + QPointer m_proxiedObject; + QVector m_children; +}; + +//TODO: Find a solution to make the macro public but the usage of QMetaObjectBuilder private + +#include "qmetaobjectbuilder_p.h" + +#define CUSTOM_METAOBJECT(ClassName, ProxyObjectType) \ +QMetaObject ClassName::staticMetaObject;\ +bool ClassName::metaObjectInitialized = ClassName::initializeMetaObject(); \ +bool ClassName::initializeMetaObject() \ +{ \ + QMetaObjectBuilder builder; \ + const QMetaObject *mo = &ProxyObjectType::staticMetaObject; \ + builder.addMetaObject(mo); \ + builder.addMetaObject(&AbstractDeclarativeObject::staticMetaObject); \ + builder.setSuperClass(ProxyObjectType::staticMetaObject.superClass()); \ + builder.setClassName(""#ClassName); \ + ClassName::staticMetaObject = *builder.toMetaObject(); \ + return true; \ +} \ +const QMetaObject &ClassName::getStaticMetaObject() \ +{ \ + return ClassName::staticMetaObject; \ +} \ +const QMetaObject* ClassName::metaObject() const \ +{ \ + return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; \ +} \ +void* ClassName::qt_metacast(const char*) \ +{ \ + return 0; \ +} \ +int ClassName::qt_metacall(QMetaObject::Call call, int id, void **argv) \ +{ \ + if (call == QMetaObject::ReadProperty || call == QMetaObject::WriteProperty) { \ + if (id >= ProxyObjectType::staticMetaObject.propertyCount()) { \ + id = AbstractDeclarativeObject::qt_metacall(call, id - ProxyObjectType::staticMetaObject.propertyCount() + 1, argv); \ + id += ProxyObjectType::staticMetaObject.propertyCount() - 1; \ + } else { \ + id = m_proxiedObject->qt_metacall(call, id, argv); \ + } \ + if (id < 0) \ + return 0; \ + } else if (call == QMetaObject::InvokeMetaMethod) {\ + if (ClassName::staticMetaObject.method(id).methodType() == QMetaMethod::Signal) \ + QMetaObject::activate(this, id, argv); \ + else \ + id = m_proxiedObject->qt_metacall(call, id, argv); \ + id -= 1; \ + } \ + return id; \ +} + +#endif diff --git a/lib/declarativeplaintextedit.cpp b/lib/declarativeplaintextedit.cpp new file mode 100644 index 0000000..f6cc06a --- /dev/null +++ b/lib/declarativeplaintextedit.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeplaintextedit_p.h" + +DeclarativePlainTextEdit::DeclarativePlainTextEdit(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativePlainTextEdit, QPlainTextEdit) diff --git a/lib/declarativeplaintextedit_p.h b/lib/declarativeplaintextedit_p.h new file mode 100644 index 0000000..c9184e1 --- /dev/null +++ b/lib/declarativeplaintextedit_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEPLAINTEXTEDIT_P_H +#define DECLARATIVEPLAINTEXTEDIT_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativePlainTextEdit : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativePlainTextEdit(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativeprogressbar.cpp b/lib/declarativeprogressbar.cpp new file mode 100644 index 0000000..85afad6 --- /dev/null +++ b/lib/declarativeprogressbar.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeprogressbar_p.h" + +DeclarativeProgressBar::DeclarativeProgressBar(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeProgressBar, QProgressBar) diff --git a/lib/declarativeprogressbar_p.h b/lib/declarativeprogressbar_p.h new file mode 100644 index 0000000..05ccb7c --- /dev/null +++ b/lib/declarativeprogressbar_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEPROGRESSBAR_P_H +#define DECLARATIVEPROGRESSBAR_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeProgressBar : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeProgressBar(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativepushbutton.cpp b/lib/declarativepushbutton.cpp new file mode 100644 index 0000000..6c68abd --- /dev/null +++ b/lib/declarativepushbutton.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativepushbutton_p.h" + +DeclarativePushButton::DeclarativePushButton(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this, QSet() << "clicked()"); +} + +CUSTOM_METAOBJECT(DeclarativePushButton, QPushButton) diff --git a/lib/declarativepushbutton_p.h b/lib/declarativepushbutton_p.h new file mode 100644 index 0000000..90fd48b --- /dev/null +++ b/lib/declarativepushbutton_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEPUSHBUTTON_P_H +#define DECLARATIVEPUSHBUTTON_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativePushButton : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativePushButton(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativeradiobutton.cpp b/lib/declarativeradiobutton.cpp new file mode 100644 index 0000000..49dd3e2 --- /dev/null +++ b/lib/declarativeradiobutton.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeradiobutton_p.h" + +DeclarativeRadioButton::DeclarativeRadioButton(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeRadioButton, QRadioButton) diff --git a/lib/declarativeradiobutton_p.h b/lib/declarativeradiobutton_p.h new file mode 100644 index 0000000..277fd53 --- /dev/null +++ b/lib/declarativeradiobutton_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVERADIOBUTTON_P_H +#define DECLARATIVERADIOBUTTON_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeRadioButton : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeRadioButton(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativescrollarea.cpp b/lib/declarativescrollarea.cpp new file mode 100644 index 0000000..e59ad36 --- /dev/null +++ b/lib/declarativescrollarea.cpp @@ -0,0 +1,47 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativescrollarea_p.h" + +DeclarativeScrollArea::DeclarativeScrollArea(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeScrollArea::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + if (m_proxiedObject->widget()) { + qmlInfo(declarativeObject) << "Can not add multiple Widgets to ScrollArea"; + } else { + m_proxiedObject->setWidget(widget); + } + + m_children.append(declarativeObject); +} + +void DeclarativeScrollArea::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(layout); + Q_UNUSED(declarativeObject); + qmlInfo(this) << "Can not add Layout to ScrollArea"; +} + +CUSTOM_METAOBJECT(DeclarativeScrollArea, QScrollArea) diff --git a/lib/declarativescrollarea_p.h b/lib/declarativescrollarea_p.h new file mode 100644 index 0000000..55a2ca6 --- /dev/null +++ b/lib/declarativescrollarea_p.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESCROLLAREA_P_H +#define DECLARATIVESCROLLAREA_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeScrollArea : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeScrollArea(QObject *parent = 0); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +#endif diff --git a/lib/declarativescrollbar.cpp b/lib/declarativescrollbar.cpp new file mode 100644 index 0000000..0c242b4 --- /dev/null +++ b/lib/declarativescrollbar.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativescrollbar_p.h" + +DeclarativeScrollBar::DeclarativeScrollBar(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeScrollBar, QScrollBar) diff --git a/lib/declarativescrollbar_p.h b/lib/declarativescrollbar_p.h new file mode 100644 index 0000000..058712f --- /dev/null +++ b/lib/declarativescrollbar_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESCROLLBAR_P_H +#define DECLARATIVESCROLLBAR_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeScrollBar : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeScrollBar(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativeseparator.cpp b/lib/declarativeseparator.cpp new file mode 100644 index 0000000..0f2ce7d --- /dev/null +++ b/lib/declarativeseparator.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeseparator_p.h" + +DeclarativeSeparator::DeclarativeSeparator(QObject *parent) + : DeclarativeObjectProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeSeparator, QAction) diff --git a/lib/declarativeseparator_p.h b/lib/declarativeseparator_p.h new file mode 100644 index 0000000..00fc703 --- /dev/null +++ b/lib/declarativeseparator_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESEPARATOR_P_H +#define DECLARATIVESEPARATOR_P_H + +#include "declarativeobjectproxy_p.h" + +#include + +class DeclarativeSeparator : public DeclarativeObjectProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeSeparator(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativeslider.cpp b/lib/declarativeslider.cpp new file mode 100644 index 0000000..d22e39e --- /dev/null +++ b/lib/declarativeslider.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativeslider_p.h" + +DeclarativeSlider::DeclarativeSlider(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeSlider, QSlider) diff --git a/lib/declarativeslider_p.h b/lib/declarativeslider_p.h new file mode 100644 index 0000000..6a767d6 --- /dev/null +++ b/lib/declarativeslider_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESLIDER_P_H +#define DECLARATIVESLIDER_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeSlider : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeSlider(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativespinbox.cpp b/lib/declarativespinbox.cpp new file mode 100644 index 0000000..b139d72 --- /dev/null +++ b/lib/declarativespinbox.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativespinbox_p.h" + +DeclarativeSpinBox::DeclarativeSpinBox(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeSpinBox, QSpinBox) diff --git a/lib/declarativespinbox_p.h b/lib/declarativespinbox_p.h new file mode 100644 index 0000000..259260a --- /dev/null +++ b/lib/declarativespinbox_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESPINBOX_P_H +#define DECLARATIVESPINBOX_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeSpinBox : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeSpinBox(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativestackedlayout.cpp b/lib/declarativestackedlayout.cpp new file mode 100644 index 0000000..459a395 --- /dev/null +++ b/lib/declarativestackedlayout.cpp @@ -0,0 +1,40 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativestackedlayout_p.h" + +DeclarativeStackedLayout::DeclarativeStackedLayout(QObject *parent) + : DeclarativeLayoutProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeStackedLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + m_proxiedObject->addWidget(widget); + m_children.append(declarativeObject); +} + +void DeclarativeStackedLayout::addLayout(QLayout*, AbstractDeclarativeObject *declarativeObject) +{ + qmlInfo(declarativeObject) << "StackedLayout does not support child layouts"; +} + +CUSTOM_METAOBJECT(DeclarativeStackedLayout, StackedLayout) diff --git a/lib/declarativestackedlayout_p.h b/lib/declarativestackedlayout_p.h new file mode 100644 index 0000000..65a4889 --- /dev/null +++ b/lib/declarativestackedlayout_p.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESTACKEDLAYOUT_P_H +#define DECLARATIVESTACKEDLAYOUT_P_H + +#include "declarativelayoutproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeStackedLayout : public DeclarativeLayoutProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeStackedLayout(QObject *parent = 0); + + protected: + void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +#endif diff --git a/lib/declarativestackedwidget.cpp b/lib/declarativestackedwidget.cpp new file mode 100644 index 0000000..698148b --- /dev/null +++ b/lib/declarativestackedwidget.cpp @@ -0,0 +1,40 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativestackedwidget_p.h" + +DeclarativeStackedWidget::DeclarativeStackedWidget(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeStackedWidget::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + m_proxiedObject->addWidget(widget); + m_children.append(declarativeObject); +} + +void DeclarativeStackedWidget::setLayout(QLayout*, AbstractDeclarativeObject *declarativeObject) +{ + qmlInfo(declarativeObject) << "StackedWidget does not support child layouts"; +} + +CUSTOM_METAOBJECT(DeclarativeStackedWidget, QStackedWidget) diff --git a/lib/declarativestackedwidget_p.h b/lib/declarativestackedwidget_p.h new file mode 100644 index 0000000..28a827f --- /dev/null +++ b/lib/declarativestackedwidget_p.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESTACKEDWIDGET_P_H +#define DECLARATIVESTACKEDWIDGET_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeStackedWidget : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeStackedWidget(QObject *parent = 0); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +#endif diff --git a/lib/declarativestatusbar.cpp b/lib/declarativestatusbar.cpp new file mode 100644 index 0000000..48df452 --- /dev/null +++ b/lib/declarativestatusbar.cpp @@ -0,0 +1,89 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativestatusbar_p.h" + +class DeclarativeStatusBarAttached::Private +{ + public: + int stretch; +}; + +DeclarativeStatusBarAttached::DeclarativeStatusBarAttached(QObject *parent) + : QObject(parent), d(new DeclarativeStatusBarAttached::Private) +{ + d->stretch = 0; +} + +DeclarativeStatusBarAttached::~DeclarativeStatusBarAttached() +{ + delete d; +} + +void DeclarativeStatusBarAttached::setStretch(int stretch) +{ + if (d->stretch == stretch) + return; + + d->stretch = stretch; + emit stretchChanged(); +} + +int DeclarativeStatusBarAttached::stretch() const +{ + return d->stretch; +} + +DeclarativeStatusBar::DeclarativeStatusBar(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeStatusBar::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + // TODO: error when layout is set + + m_children.append(declarativeObject); + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeStatusBarAttached *attached = qobject_cast(attachedProperties); + + int stretch = 0; + if (attached) { + stretch = attached->stretch(); + } + + m_proxiedObject->addPermanentWidget(widget, stretch); +} + +void DeclarativeStatusBar::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(layout); + Q_UNUSED(declarativeObject); + qmlInfo(this) << "Can not add QLayout to QStatusBar"; +} + +DeclarativeStatusBarAttached *DeclarativeStatusBar::qmlAttachedProperties(QObject *object) +{ + return new DeclarativeStatusBarAttached(object); +} + +CUSTOM_METAOBJECT(DeclarativeStatusBar, QStatusBar) diff --git a/lib/declarativestatusbar_p.h b/lib/declarativestatusbar_p.h new file mode 100644 index 0000000..3a1a977 --- /dev/null +++ b/lib/declarativestatusbar_p.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVESTATUSBAR_P_H +#define DECLARATIVESTATUSBAR_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeStatusBarAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged) + + public: + DeclarativeStatusBarAttached(QObject *parent = 0); + ~DeclarativeStatusBarAttached(); + + void setStretch(int stretch); + int stretch() const; + + Q_SIGNALS: + void stretchChanged(); + + private: + class Private; + Private *const d; +}; + +class DeclarativeStatusBar : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeStatusBar(QObject *parent = 0); + + static DeclarativeStatusBarAttached *qmlAttachedProperties(QObject *object); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +QML_DECLARE_TYPEINFO(DeclarativeStatusBar, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativetableview.cpp b/lib/declarativetableview.cpp new file mode 100644 index 0000000..ee41509 --- /dev/null +++ b/lib/declarativetableview.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetableview_p.h" + +DeclarativeTableView::DeclarativeTableView(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeTableView, TableView) diff --git a/lib/declarativetableview_p.h b/lib/declarativetableview_p.h new file mode 100644 index 0000000..973a62b --- /dev/null +++ b/lib/declarativetableview_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETABLEVIEW_P_H +#define DECLARATIVETABLEVIEW_P_H + +#include "declarativewidgetproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeTableView : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeTableView(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativetabwidget.cpp b/lib/declarativetabwidget.cpp new file mode 100644 index 0000000..c668f9f --- /dev/null +++ b/lib/declarativetabwidget.cpp @@ -0,0 +1,120 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetabwidget_p.h" + +class DeclarativeTabWidgetAttached::Private +{ + public: + QString label; + QIcon icon; + QPointer tabWidget; + int index; +}; + +DeclarativeTabWidgetAttached::DeclarativeTabWidgetAttached(QObject *parent) + : QObject(parent), d(new DeclarativeTabWidgetAttached::Private) +{ +} + +DeclarativeTabWidgetAttached::~DeclarativeTabWidgetAttached() +{ + delete d; +} + +void DeclarativeTabWidgetAttached::setLabel(const QString &label) +{ + if (label == d->label) + return; + + d->label = label; + + if (d->tabWidget) + d->tabWidget->setTabText(d->index, d->label); + + emit labelChanged(label); +} + +QString DeclarativeTabWidgetAttached::label() const +{ + return d->label; +} + +void DeclarativeTabWidgetAttached::setIcon(const QIcon &icon) +{ + d->icon = icon; + + if (d->tabWidget) + d->tabWidget->setTabIcon(d->index, d->icon); + + emit iconChanged(icon); +} + +QIcon DeclarativeTabWidgetAttached::icon() const +{ + return d->icon; +} + +void DeclarativeTabWidgetAttached::setAssociation(QTabWidget *widget, int index) +{ + d->tabWidget = widget; + d->index = index; +} + +DeclarativeTabWidget::DeclarativeTabWidget(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeTabWidget::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + // TODO: error when layout is set + + m_children.append(declarativeObject); + + QString label; + QIcon icon; + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeTabWidgetAttached *tabHeader = qobject_cast(attachedProperties); + if (tabHeader) { + label = tabHeader->label(); + icon = tabHeader->icon(); + } + + const int index = m_proxiedObject->addTab(widget, icon, label); + if (tabHeader) + tabHeader->setAssociation(m_proxiedObject, index); +} + +void DeclarativeTabWidget::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(layout); + Q_UNUSED(declarativeObject); + qmlInfo(this) << "Can not add QLayout to QTabWidget"; +} + +DeclarativeTabWidgetAttached *DeclarativeTabWidget::qmlAttachedProperties(QObject *object) +{ + return new DeclarativeTabWidgetAttached(object); +} + +CUSTOM_METAOBJECT(DeclarativeTabWidget, QTabWidget) diff --git a/lib/declarativetabwidget_p.h b/lib/declarativetabwidget_p.h new file mode 100644 index 0000000..05d138a --- /dev/null +++ b/lib/declarativetabwidget_p.h @@ -0,0 +1,72 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETABWIDGET_P_H +#define DECLARATIVETABWIDGET_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeTabWidgetAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) + Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY iconChanged) + + public: + DeclarativeTabWidgetAttached(QObject *parent = 0); + ~DeclarativeTabWidgetAttached(); + + void setLabel(const QString &label); + QString label() const; + + void setIcon(const QIcon &icon); + QIcon icon() const; + + void setAssociation(QTabWidget *widget, int index); + + Q_SIGNALS: + void labelChanged(const QString &label); + void iconChanged(const QIcon &icon); + + private: + class Private; + Private *const d; +}; + +class DeclarativeTabWidget : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeTabWidget(QObject *parent = 0); + + static DeclarativeTabWidgetAttached *qmlAttachedProperties(QObject *object); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +QML_DECLARE_TYPEINFO(DeclarativeTabWidget, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativetextbrowser.cpp b/lib/declarativetextbrowser.cpp new file mode 100644 index 0000000..973d903 --- /dev/null +++ b/lib/declarativetextbrowser.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetextbrowser_p.h" + +DeclarativeTextBrowser::DeclarativeTextBrowser(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeTextBrowser, QTextBrowser) diff --git a/lib/declarativetextbrowser_p.h b/lib/declarativetextbrowser_p.h new file mode 100644 index 0000000..49bcdfa --- /dev/null +++ b/lib/declarativetextbrowser_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETEXTBROWSER_P_H +#define DECLARATIVETEXTBROWSER_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeTextBrowser : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeTextBrowser(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativetextedit.cpp b/lib/declarativetextedit.cpp new file mode 100644 index 0000000..7a1584f --- /dev/null +++ b/lib/declarativetextedit.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetextedit_p.h" + +DeclarativeTextEdit::DeclarativeTextEdit(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeTextEdit, TextEdit) diff --git a/lib/declarativetextedit_p.h b/lib/declarativetextedit_p.h new file mode 100644 index 0000000..2502bfd --- /dev/null +++ b/lib/declarativetextedit_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETEXTEDIT_P_H +#define DECLARATIVETEXTEDIT_P_H + +#include "declarativewidgetproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeTextEdit : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeTextEdit(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativetimeedit.cpp b/lib/declarativetimeedit.cpp new file mode 100644 index 0000000..2be3b8a --- /dev/null +++ b/lib/declarativetimeedit.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetimeedit_p.h" + +DeclarativeTimeEdit::DeclarativeTimeEdit(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeTimeEdit, QTimeEdit) diff --git a/lib/declarativetimeedit_p.h b/lib/declarativetimeedit_p.h new file mode 100644 index 0000000..3342a43 --- /dev/null +++ b/lib/declarativetimeedit_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETIMEEDIT_P_H +#define DECLARATIVETIMEEDIT_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeTimeEdit : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeTimeEdit(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativetoolbar.cpp b/lib/declarativetoolbar.cpp new file mode 100644 index 0000000..3e02500 --- /dev/null +++ b/lib/declarativetoolbar.cpp @@ -0,0 +1,58 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetoolbar_p.h" + +#include "declarativeseparator_p.h" + +DeclarativeToolBar::DeclarativeToolBar(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +void DeclarativeToolBar::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + m_proxiedObject->addWidget(widget); + + m_children.append(declarativeObject); +} + +void DeclarativeToolBar::setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + Q_UNUSED(layout); + Q_UNUSED(declarativeObject); + qmlInfo(this) << "Can not set a QLayout to a QToolBar"; +} + +void DeclarativeToolBar::addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) +{ + DeclarativeSeparator *separator = dynamic_cast(declarativeObject); + + if (separator) { + m_proxiedObject->addSeparator(); + } else { + m_proxiedObject->addAction(action); + } + + m_children.append(declarativeObject); +} + +CUSTOM_METAOBJECT(DeclarativeToolBar, QToolBar) diff --git a/lib/declarativetoolbar_p.h b/lib/declarativetoolbar_p.h new file mode 100644 index 0000000..b605f1c --- /dev/null +++ b/lib/declarativetoolbar_p.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETOOLBAR_P_H +#define DECLARATIVETOOLBAR_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeToolBar : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeToolBar(QObject *parent = 0); + + protected: + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); + virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject); +}; + +#endif diff --git a/lib/declarativetoolbutton.cpp b/lib/declarativetoolbutton.cpp new file mode 100644 index 0000000..86d71c0 --- /dev/null +++ b/lib/declarativetoolbutton.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetoolbutton_p.h" + +DeclarativeToolButton::DeclarativeToolButton(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeToolButton, QToolButton) diff --git a/lib/declarativetoolbutton_p.h b/lib/declarativetoolbutton_p.h new file mode 100644 index 0000000..0f588d8 --- /dev/null +++ b/lib/declarativetoolbutton_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETOOLBUTTON_P_H +#define DECLARATIVETOOLBUTTON_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeToolButton : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeToolButton(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativetreeview.cpp b/lib/declarativetreeview.cpp new file mode 100644 index 0000000..f651b4b --- /dev/null +++ b/lib/declarativetreeview.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativetreeview_p.h" + +DeclarativeTreeView::DeclarativeTreeView(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeTreeView, TreeView) diff --git a/lib/declarativetreeview_p.h b/lib/declarativetreeview_p.h new file mode 100644 index 0000000..dffdcef --- /dev/null +++ b/lib/declarativetreeview_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVETREEVIEW_P_H +#define DECLARATIVETREEVIEW_P_H + +#include "declarativewidgetproxy_p.h" + +#include "objectadaptors_p.h" + +class DeclarativeTreeView : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeTreeView(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativevboxlayout.cpp b/lib/declarativevboxlayout.cpp new file mode 100644 index 0000000..e66dc39 --- /dev/null +++ b/lib/declarativevboxlayout.cpp @@ -0,0 +1,83 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativevboxlayout_p.h" + +DeclarativeVBoxLayout::DeclarativeVBoxLayout(QObject *parent) + : DeclarativeLayoutProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +DeclarativeBoxLayoutAttached *DeclarativeVBoxLayout::qmlAttachedProperties(QObject *parent) +{ + AbstractDeclarativeObject *declarativeObject = dynamic_cast(parent); + if (declarativeObject) { + QWidget *widget = qobject_cast(declarativeObject->object()); + if (widget) + return new DeclarativeBoxLayoutAttached(widget, parent); + + QLayout *layout = qobject_cast(declarativeObject->object()); + if (layout) + return new DeclarativeBoxLayoutAttached(layout, parent); + } + + qmlInfo(parent) << "Can only attach VBoxLayout to widgets and layouts"; + return 0; +} + +void DeclarativeVBoxLayout::addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) +{ + int stretch = 0; + Qt::Alignment alignment = 0; + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + stretch = properties->stretch(); + alignment = properties->alignment(); + + properties->setParentLayout(m_proxiedObject); + } + + m_proxiedObject->addWidget(widget, stretch, alignment); + m_children.append(declarativeObject); +} + +void DeclarativeVBoxLayout::addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) +{ + int stretch = 0; + Qt::Alignment alignment = 0; + + QObject *attachedProperties = qmlAttachedPropertiesObject(declarativeObject, false); + DeclarativeBoxLayoutAttached *properties = qobject_cast(attachedProperties); + if (properties) { + stretch = properties->stretch(); + alignment = properties->alignment(); + + properties->setParentLayout(m_proxiedObject); + } + + m_proxiedObject->addLayout(layout, stretch); + m_proxiedObject->setAlignment(layout, alignment); + m_children.append(declarativeObject); +} + +CUSTOM_METAOBJECT(DeclarativeVBoxLayout, QVBoxLayout) diff --git a/lib/declarativevboxlayout_p.h b/lib/declarativevboxlayout_p.h new file mode 100644 index 0000000..037814c --- /dev/null +++ b/lib/declarativevboxlayout_p.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEVBOXLAYOUT_P_H +#define DECLARATIVEVBOXLAYOUT_P_H + +#include "declarativeboxlayout_p.h" +#include "declarativelayoutproxy_p.h" + +#include + +class DeclarativeVBoxLayout : public DeclarativeLayoutProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeVBoxLayout(QObject *parent = 0); + + static DeclarativeBoxLayoutAttached *qmlAttachedProperties(QObject *parent); + + protected: + void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject); + void addLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject); +}; + +QML_DECLARE_TYPEINFO(DeclarativeVBoxLayout, QML_HAS_ATTACHED_PROPERTIES) + +#endif diff --git a/lib/declarativewebview.cpp b/lib/declarativewebview.cpp new file mode 100644 index 0000000..47efca1 --- /dev/null +++ b/lib/declarativewebview.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativewebview_p.h" + +DeclarativeWebView::DeclarativeWebView(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeWebView, QWebView) diff --git a/lib/declarativewebview_p.h b/lib/declarativewebview_p.h new file mode 100644 index 0000000..d15eb4e --- /dev/null +++ b/lib/declarativewebview_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEWEBVIEW_P_H +#define DECLARATIVEWEBVIEW_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeWebView : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeWebView(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativewidget.cpp b/lib/declarativewidget.cpp new file mode 100644 index 0000000..d76463c --- /dev/null +++ b/lib/declarativewidget.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativewidget_p.h" + +DeclarativeWidget::DeclarativeWidget(QObject *parent) + : DeclarativeWidgetProxy(parent) +{ + connectAllSignals(m_proxiedObject, this); +} + +CUSTOM_METAOBJECT(DeclarativeWidget, QWidget) diff --git a/lib/declarativewidget_p.h b/lib/declarativewidget_p.h new file mode 100644 index 0000000..90f4c06 --- /dev/null +++ b/lib/declarativewidget_p.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEWIDGET_P_H +#define DECLARATIVEWIDGET_P_H + +#include "declarativewidgetproxy_p.h" + +#include + +class DeclarativeWidget : public DeclarativeWidgetProxy +{ + DECLARATIVE_OBJECT + + public: + DeclarativeWidget(QObject *parent = 0); +}; + +#endif diff --git a/lib/declarativewidgetproxy_p.h b/lib/declarativewidgetproxy_p.h new file mode 100644 index 0000000..d1c45d9 --- /dev/null +++ b/lib/declarativewidgetproxy_p.h @@ -0,0 +1,106 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEWIDGETPROXY_P_H +#define DECLARATIVEWIDGETPROXY_P_H + +#include "declarativeobjectproxy_p.h" + +#include "declarativeactionitem_p.h" + +#include +#include + +template +class DeclarativeWidgetProxy : public DeclarativeObjectProxy +{ + public: + DeclarativeWidgetProxy(QObject *parent = 0) : DeclarativeObjectProxy(parent) {} + + protected: + virtual void dataAppend(QObject *object) + { + AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); + if (declarativeObject) { + QWidget *widget = qobject_cast(declarativeObject->object()); + if (widget) { + addWidget(widget, declarativeObject); + return; + } + + QLayout *layout = qobject_cast(declarativeObject->object()); + if (layout) { + // TODO: error when widget is set + + if (DeclarativeObjectProxy::m_proxiedObject->layout()) { + qmlInfo(this) << "Can not add a second Layout"; + return; + } + + setLayout(layout, declarativeObject); + return; + } + + DeclarativeActionItem *declarativeActionItem = dynamic_cast(object); + if (declarativeActionItem) { + addAction(qobject_cast(declarativeActionItem->object())->action(), declarativeObject); + return; + } + + QAction *action = qobject_cast(declarativeObject->object()); + if (action) { + addAction(action, declarativeObject); + return; + } + + addQObject(declarativeObject->object(), declarativeObject); + return; + } + + DeclarativeObjectProxy::dataAppend(object); + } + + virtual void addWidget(QWidget *widget, AbstractDeclarativeObject *declarativeObject) + { + Q_UNUSED(declarativeObject); + DeclarativeObjectProxy::m_children.append(declarativeObject); + widget->setParent(DeclarativeObjectProxy::m_proxiedObject, widget->windowFlags()); + } + + virtual void setLayout(QLayout *layout, AbstractDeclarativeObject *declarativeObject) + { + DeclarativeObjectProxy::m_children.append(declarativeObject); + DeclarativeObjectProxy::m_proxiedObject->setLayout(layout); + } + + virtual void addAction(QAction *action, AbstractDeclarativeObject *declarativeObject) + { + DeclarativeObjectProxy::m_children.append(declarativeObject); + DeclarativeObjectProxy::m_proxiedObject->addAction(action); + } + + virtual void addQObject(QObject *object, AbstractDeclarativeObject *declarativeObject) + { + object->setParent(DeclarativeObjectProxy::m_proxiedObject); + DeclarativeObjectProxy::m_children.append(declarativeObject); + } +}; + +#endif diff --git a/lib/declarativewidgetsdocument.cpp b/lib/declarativewidgetsdocument.cpp new file mode 100644 index 0000000..b1a067b --- /dev/null +++ b/lib/declarativewidgetsdocument.cpp @@ -0,0 +1,222 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativewidgetsdocument.h" + +// The declarative widget wrappers +#include "declarativeactionitem_p.h" +#include "declarativeaction_p.h" +#include "declarativebuttongroup_p.h" +#include "declarativecalendarwidget_p.h" +#include "declarativecheckbox_p.h" +#include "declarativecolordialog_p.h" +#include "declarativecolumnview_p.h" +#include "declarativecommandlinkbutton_p.h" +#include "declarativedateedit_p.h" +#include "declarativedatetimeedit_p.h" +#include "declarativedialogbuttonbox_p.h" +#include "declarativedialog_p.h" +#include "declarativedial_p.h" +#include "declarativedoublespinbox_p.h" +#include "declarativefiledialog_p.h" +#include "declarativefontdialog_p.h" +#include "declarativeformlayout_p.h" +#include "declarativeframe_p.h" +#include "declarativegridlayout_p.h" +#include "declarativegroupbox_p.h" +#include "declarativehboxlayout_p.h" +#include "declarativeinputdialog_p.h" +#include "declarativelabel_p.h" +#include "declarativelcdnumber_p.h" +#include "declarativelineedit_p.h" +#include "declarativelistview_p.h" +#include "declarativemainwindow_p.h" +#include "declarativemenubar_p.h" +#include "declarativemenu_p.h" +#include "declarativemessagebox_p.h" +#include "declarativeplaintextedit_p.h" +#include "declarativeprogressbar_p.h" +#include "declarativepushbutton_p.h" +#include "declarativeradiobutton_p.h" +#include "declarativescrollarea_p.h" +#include "declarativescrollbar_p.h" +#include "declarativeseparator_p.h" +#include "declarativeslider_p.h" +#include "declarativespinbox_p.h" +#include "declarativestackedlayout_p.h" +#include "declarativestackedwidget_p.h" +#include "declarativestatusbar_p.h" +#include "declarativetableview_p.h" +#include "declarativetabwidget_p.h" +#include "declarativetextbrowser_p.h" +#include "declarativetextedit_p.h" +#include "declarativetimeedit_p.h" +#include "declarativetoolbar_p.h" +#include "declarativetoolbutton_p.h" +#include "declarativetreeview_p.h" +#include "declarativevboxlayout_p.h" +#include "declarativewebview_p.h" +#include "declarativewidget_p.h" + +#include +#include +#include +#include +#include + +class DeclarativeWidgetsDocument::Private +{ + public: + Private(DeclarativeWidgetsDocument *qq, const QUrl &url) + : q(qq) + , m_url(url) + , m_engine(new QDeclarativeEngine(q)) + , m_component(new QDeclarativeComponent(m_engine, q)) + { + } + + DeclarativeWidgetsDocument* q; + QUrl m_url; + QDeclarativeEngine* m_engine; + QDeclarativeComponent* m_component; +}; + +DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject *parent) + : QObject(parent) + , d(new Private(this, url)) +{ + qmlRegisterType(); + qmlRegisterType(); + + // objects + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "Action"); + qmlRegisterType("QtGui", 1, 0, "ActionItem"); + qmlRegisterType("QtGui", 1, 0, "ButtonGroup"); + qmlRegisterType("QtGui", 1, 0, "Separator"); + + // layouts + qmlRegisterType(); + qmlRegisterType(); + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "FormLayout"); + qmlRegisterType("QtGui", 1, 0, "GridLayout"); + qmlRegisterType("QtGui", 1, 0, "HBoxLayout"); + qmlRegisterType("QtGui", 1, 0, "StackedLayout"); + qmlRegisterType("QtGui", 1, 0, "VBoxLayout"); + + // widgets + qmlRegisterType("QtGui", 1, 0, "CalendarWidget"); + qmlRegisterType("QtGui", 1, 0, "CheckBox"); + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "ColorDialog"); + qmlRegisterType("QtGui", 1, 0, "ColumnView"); + qmlRegisterType("QtGui", 1, 0, "CommandLinkButton"); + qmlRegisterType("QtGui", 1, 0, "DateEdit"); + qmlRegisterType("QtGui", 1, 0, "DateTimeEdit"); + qmlRegisterType("QtGui", 1, 0, "Dial"); + qmlRegisterType("QtGui", 1, 0, "Dialog"); + qmlRegisterType("QtGui", 1, 0, "DialogButtonBox"); + qmlRegisterType("QtGui", 1, 0, "DoubleSpinBox"); + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "FileDialog"); + qmlRegisterType("QtGui", 1, 0, "FontDialog"); + qmlRegisterType("QtGui", 1, 0, "Frame"); + qmlRegisterType("QtGui", 1, 0, "GroupBox"); + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "InputDialog"); + qmlRegisterType("QtGui", 1, 0, "Label"); + qmlRegisterType("QtGui", 1, 0, "LCDNumber"); + qmlRegisterType("QtGui", 1, 0, "LineEdit"); + qmlRegisterType("QtGui", 1, 0, "ListView"); + qmlRegisterType("QtGui", 1, 0, "MainWindow"); + qmlRegisterType("QtGui", 1, 0, "Menu"); + qmlRegisterType("QtGui", 1, 0, "MenuBar"); + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "MessageBox"); + qmlRegisterType("QtGui", 1, 0, "PlainTextEdit"); + qmlRegisterType("QtGui", 1, 0, "ProgressBar"); + qmlRegisterType("QtGui", 1, 0, "PushButton"); + qmlRegisterType("QtGui", 1, 0, "RadioButton"); + qmlRegisterType("QtGui", 1, 0, "ScrollArea"); + qmlRegisterType("QtGui", 1, 0, "ScrollBar"); + qmlRegisterType("QtGui", 1, 0, "Slider"); + qmlRegisterType("QtGui", 1, 0, "SpinBox"); + qmlRegisterType("QtGui", 1, 0, "StackedWidget"); + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "StatusBar"); + qmlRegisterType("QtGui", 1, 0, "TableView"); + qmlRegisterType(); + qmlRegisterType("QtGui", 1, 0, "TabWidget"); + qmlRegisterType("QtGui", 1, 0, "TextBrowser"); + qmlRegisterType("QtGui", 1, 0, "TextEdit"); + qmlRegisterType("QtGui", 1, 0, "TimeEdit"); + qmlRegisterType("QtGui", 1, 0, "ToolBar"); + qmlRegisterType("QtGui", 1, 0, "ToolButton"); + qmlRegisterType("QtGui", 1, 0, "TreeView"); + qmlRegisterType("QtGui", 1, 0, "WebView"); + qmlRegisterType("QtGui", 1, 0, "Widget"); + + d->m_component->loadUrl(d->m_url); + if (d->m_component->isError()) { + foreach (const QDeclarativeError &error, d->m_component->errors()) + qDebug() << error.toString(); + } +} + +DeclarativeWidgetsDocument::~DeclarativeWidgetsDocument() +{ + delete d; +} + +void DeclarativeWidgetsDocument::setContextProperty(const QString &name, const QVariant &value) +{ + d->m_engine->rootContext()->setContextProperty(name, value); +} + +void DeclarativeWidgetsDocument::setContextProperty(const QString &name, QObject *object) +{ + d->m_engine->rootContext()->setContextProperty(name, object); +} + +QDeclarativeEngine* DeclarativeWidgetsDocument::engine() const +{ + return d->m_engine; +} + +QWidget* DeclarativeWidgetsDocument::createWidget() +{ + QObject *object = d->m_component->create(); + if (!object) { + qWarning("Unable to create component"); + return 0; + } + + AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); + + if (!declarativeObject) { + qWarning("Root element is no AbstractDeclarativeObject subclass"); + return 0; + } + + declarativeObject->setParent(this); + + return qobject_cast(declarativeObject->object()); +} diff --git a/lib/declarativewidgetsdocument.h b/lib/declarativewidgetsdocument.h new file mode 100644 index 0000000..8e7f3ea --- /dev/null +++ b/lib/declarativewidgetsdocument.h @@ -0,0 +1,59 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef DECLARATIVEWIDGETSDOCUMENT_H +#define DECLARATIVEWIDGETSDOCUMENT_H + +#include +#include + +class QDeclarativeEngine; + +class DeclarativeWidgetsDocument : public QObject +{ + Q_OBJECT + + public: + DeclarativeWidgetsDocument(const QUrl &url, QObject *parent = 0); + ~DeclarativeWidgetsDocument(); + + void setContextProperty(const QString &name, const QVariant &value); + void setContextProperty(const QString &name, QObject *object); + + QDeclarativeEngine* engine() const; + + template + T* create() + { + QWidget *widget = createWidget(); + if (!widget) + return 0; + + return qobject_cast(widget); + } + + private: + QWidget* createWidget(); + + class Private; + Private* const d; +}; + +#endif diff --git a/lib/objectadaptors.cpp b/lib/objectadaptors.cpp new file mode 100644 index 0000000..b654864 --- /dev/null +++ b/lib/objectadaptors.cpp @@ -0,0 +1,261 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "objectadaptors_p.h" + +#include "declarativeaction_p.h" + +#include +#include + +// ActionItem +ActionItem::ActionItem(QObject *parent) + : QObject(parent) + , m_placeholderAction(new QAction(this)) + , m_qAction(m_placeholderAction) +{ +} + +QAction* ActionItem::action() +{ + return m_qAction; +} + +void ActionItem::setAction(const QVariant &action) +{ + if (m_action == action) + return; + + m_action = action; + + QObject *object = m_action.value(); + + // Is the passed action a QAction ... + QAction *newAction = qobject_cast(object); + + // ... or a DeclarativeAction + DeclarativeAction *declarativeAction = dynamic_cast(object); + if (declarativeAction) { + newAction = qobject_cast(declarativeAction->object()); + } + + // Check if the placeholder must be replaced with the actual action + if (m_qAction == m_placeholderAction) { + const QList widgets = m_placeholderAction->associatedWidgets(); + if (!widgets.isEmpty()) { + Q_ASSERT(widgets.count() == 1); // The placeholder action can only be plugged into one widget + + // Replace the placeholder action with the new one + widgets.first()->insertAction(m_placeholderAction, newAction); + widgets.first()->removeAction(m_placeholderAction); + + m_qAction = newAction; + } + } + + emit actionChanged(); +} + +QVariant ActionItem::qmlAction() const +{ + return m_action; +} + +// ButtonGroup +ButtonGroup::ButtonGroup(QObject *parent) + : QButtonGroup(parent) +{ +} + +void ButtonGroup::setButtons(const QVariantList &buttons) +{ + if (m_buttons == buttons) + return; + + // First remove the old buttons ... + foreach (const QVariant &variant, m_buttons) { + QObject *object = variant.value(); + if (object) { + AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); + if (declarativeObject) { + QAbstractButton *button = qobject_cast(declarativeObject->object()); + if (button) + QButtonGroup::removeButton(button); + } + } + } + + m_buttons = buttons; + + // ... then add the new ones + foreach (const QVariant &variant, m_buttons) { + QObject *object = variant.value(); + if (object) { + AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); + if (declarativeObject) { + QAbstractButton *button = qobject_cast(declarativeObject->object()); + if (button) + QButtonGroup::addButton(button); + } + } + } + + emit buttonsChanged(); +} + +QVariantList ButtonGroup::buttons() const +{ + return m_buttons; +} + +// ColumnView +ColumnView::ColumnView(QWidget *parent) + : QColumnView(parent) +{ +} + +void ColumnView::setModel(QAbstractItemModel *model) +{ + if (this->model() == model) + return; + + QColumnView::setModel(model); + + emit modelChanged(model); + emit selectionModelChanged(selectionModel()); +} + +void ColumnView::setSelectionModel(QItemSelectionModel *selectionModel) +{ + if (this->selectionModel() == selectionModel) + return; + + QColumnView::setSelectionModel(selectionModel); + + emit selectionModelChanged(selectionModel); +} + +// FileDialog +FileDialog::FileDialog(QWidget *parent) + : QFileDialog(parent) +{ +} + +// InputDialog +InputDialog::InputDialog(QWidget *parent) + : QInputDialog(parent) +{ + connect(this, SIGNAL(textValueChanged(QString)), this, SIGNAL(customTextValueChanged())); + connect(this, SIGNAL(intValueChanged(int)), this, SIGNAL(customIntValueChanged())); + connect(this, SIGNAL(doubleValueChanged(double)), this, SIGNAL(customDoubleValueChanged())); +} + +// ListView +ListView::ListView(QWidget *parent) + : QListView(parent) +{ +} + +void ListView::setModel(QAbstractItemModel *model) +{ + if (this->model() == model) + return; + + QListView::setModel(model); + + emit modelChanged(model); + emit selectionModelChanged(selectionModel()); +} + +void ListView::setSelectionModel(QItemSelectionModel *selectionModel) +{ + if (this->selectionModel() == selectionModel) + return; + + QListView::setSelectionModel(selectionModel); + + emit selectionModelChanged(selectionModel); +} + +// TableView +TableView::TableView(QWidget *parent) + : QTableView(parent) +{ +} + +void TableView::setModel(QAbstractItemModel *model) +{ + if (this->model() == model) + return; + + QTableView::setModel(model); + + emit modelChanged(model); + emit selectionModelChanged(selectionModel()); +} + +void TableView::setSelectionModel(QItemSelectionModel *selectionModel) +{ + if (this->selectionModel() == selectionModel) + return; + + QTableView::setSelectionModel(selectionModel); + + emit selectionModelChanged(selectionModel); +} + +// TextEdit +TextEdit::TextEdit(QWidget *parent) + : QTextEdit(parent) +{ + connect(document(), SIGNAL(modificationChanged(bool)), this, SIGNAL(modifiedChanged())); +} + +bool TextEdit::modified() const +{ + return document()->isModified(); +} + +// TreeView +TreeView::TreeView(QWidget *parent) + : QTreeView(parent) +{ +} + +void TreeView::setModel(QAbstractItemModel *model) +{ + if (this->model() == model) + return; + + QTreeView::setModel(model); + + emit modelChanged(model); + emit selectionModelChanged(selectionModel()); +} + +void TreeView::setSelectionModel(QItemSelectionModel *selectionModel) +{ + if (this->selectionModel() == selectionModel) + return; + + QTreeView::setSelectionModel(selectionModel); + + emit selectionModelChanged(selectionModel); +} diff --git a/lib/objectadaptors_p.h b/lib/objectadaptors_p.h new file mode 100644 index 0000000..e830ae9 --- /dev/null +++ b/lib/objectadaptors_p.h @@ -0,0 +1,216 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef OBJECTADAPTORS_P_H +#define OBJECTADAPTORS_P_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class ActionItem : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QVariant action READ qmlAction WRITE setAction NOTIFY actionChanged) + + public: + ActionItem(QObject *parent = 0); + + QAction* action(); + + Q_SIGNALS: + void actionChanged(); + + private: + void setAction(const QVariant &action); + QVariant qmlAction() const; + + QVariant m_action; + QAction* m_placeholderAction; + QAction* m_qAction; +}; + +class ButtonGroup : public QButtonGroup +{ + Q_OBJECT + + Q_PROPERTY(QVariantList buttons READ buttons WRITE setButtons NOTIFY buttonsChanged) + + public: + ButtonGroup(QObject *parent = 0); + + Q_SIGNALS: + void buttonsChanged(); + + private: + void setButtons(const QVariantList &buttons); + QVariantList buttons() const; + + QVariantList m_buttons; +}; + +class ColumnView : public QColumnView +{ + Q_OBJECT + + Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) + + public: + ColumnView(QWidget *parent = 0); + + void setModel(QAbstractItemModel *model); + void setSelectionModel(QItemSelectionModel *selectionModel); + + Q_SIGNALS: + void modelChanged(QAbstractItemModel*); + void selectionModelChanged(QItemSelectionModel*); +}; + +class FileDialog : public QFileDialog +{ + Q_OBJECT + + Q_PROPERTY(QStringList selectedFiles READ selectedFiles) + + public: + FileDialog(QWidget *parent = 0); +}; + +class InputDialog : public QInputDialog +{ + Q_OBJECT + + Q_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode) + Q_PROPERTY(QString labelText READ labelText WRITE setLabelText) + Q_PROPERTY(InputDialogOptions options READ options WRITE setOptions) + Q_PROPERTY(QString textValue READ textValue WRITE setTextValue NOTIFY customTextValueChanged) + Q_PROPERTY(int intValue READ intValue WRITE setIntValue NOTIFY customIntValueChanged) + Q_PROPERTY(int doubleValue READ doubleValue WRITE setDoubleValue NOTIFY customDoubleValueChanged) + Q_PROPERTY(QLineEdit::EchoMode textEchoMode READ textEchoMode WRITE setTextEchoMode) + Q_PROPERTY(bool comboBoxEditable READ isComboBoxEditable WRITE setComboBoxEditable) + Q_PROPERTY(QStringList comboBoxItems READ comboBoxItems WRITE setComboBoxItems) + Q_PROPERTY(int intMinimum READ intMinimum WRITE setIntMinimum) + Q_PROPERTY(int intMaximum READ intMaximum WRITE setIntMaximum) + Q_PROPERTY(int intStep READ intStep WRITE setIntStep) + Q_PROPERTY(double doubleMinimum READ doubleMinimum WRITE setDoubleMinimum) + Q_PROPERTY(double doubleMaximum READ doubleMaximum WRITE setDoubleMaximum) + Q_PROPERTY(int doubleDecimals READ doubleDecimals WRITE setDoubleDecimals) + Q_PROPERTY(QString okButtonText READ okButtonText WRITE setOkButtonText) + Q_PROPERTY(QString cancelButtonText READ cancelButtonText WRITE setCancelButtonText) + + Q_ENUMS(InputMode) + Q_ENUMS(InputDialogOption) + + public: + InputDialog(QWidget *parent = 0); + + Q_SIGNALS: + void customTextValueChanged(); + void customIntValueChanged(); + void customDoubleValueChanged(); +}; + +class ListView : public QListView +{ + Q_OBJECT + + Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) + + public: + ListView(QWidget *parent = 0); + + void setModel(QAbstractItemModel *model); + void setSelectionModel(QItemSelectionModel *selectionModel); + + Q_SIGNALS: + void modelChanged(QAbstractItemModel*); + void selectionModelChanged(QItemSelectionModel*); +}; + +class StackedLayout : public QStackedLayout +{ + Q_OBJECT + + Q_PROPERTY(int count READ count) +}; + +class TableView : public QTableView +{ + Q_OBJECT + + Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) + + public: + TableView(QWidget *parent = 0); + + void setModel(QAbstractItemModel *model); + void setSelectionModel(QItemSelectionModel *selectionModel); + + Q_SIGNALS: + void modelChanged(QAbstractItemModel*); + void selectionModelChanged(QItemSelectionModel*); +}; + +class TextEdit : public QTextEdit +{ + Q_OBJECT + + Q_PROPERTY(bool modified READ modified NOTIFY modifiedChanged) + + public: + TextEdit(QWidget *parent = 0); + + Q_SIGNALS: + void modifiedChanged(); + + private: + bool modified() const; +}; + +class TreeView : public QTreeView +{ + Q_OBJECT + + Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) + + public: + TreeView(QWidget *parent = 0); + + void setModel(QAbstractItemModel *model); + void setSelectionModel(QItemSelectionModel *selectionModel); + + Q_SIGNALS: + void modelChanged(QAbstractItemModel*); + void selectionModelChanged(QItemSelectionModel*); +}; + +#endif diff --git a/lib/qmetaobjectbuilder.cpp b/lib/qmetaobjectbuilder.cpp new file mode 100644 index 0000000..ff4c97c --- /dev/null +++ b/lib/qmetaobjectbuilder.cpp @@ -0,0 +1,2601 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmetaobjectbuilder_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QMetaObjectBuilder + \internal + \brief The QMetaObjectBuilder class supports building QMetaObject objects at runtime. + +*/ + +/*! + \enum QMetaObjectBuilder::AddMember + This enum defines which members of QMetaObject should be copied by QMetaObjectBuilder::addMetaObject() + + \value ClassName Add the class name. + \value SuperClass Add the super class. + \value Methods Add methods that aren't signals or slots. + \value Signals Add signals. + \value Slots Add slots. + \value Constructors Add constructors. + \value Properties Add properties. + \value Enumerators Add enumerators. + \value ClassInfos Add items of class information. + \value RelatedMetaObjects Add related meta objects. + \value StaticMetacall Add the static metacall function. + \value PublicMethods Add public methods (ignored for signals). + \value ProtectedMethods Add protected methods (ignored for signals). + \value PrivateMethods All private methods (ignored for signals). + \value AllMembers Add all members. + \value AllPrimaryMembers Add everything except the class name, super class, and static metacall function. +*/ + +// copied from moc's generator.cpp +uint qvariant_nameToType(const char* name) +{ + if (!name) + return 0; + + if (strcmp(name, "QVariant") == 0) + return 0xffffffff; + if (strcmp(name, "QCString") == 0) + return QMetaType::QByteArray; + if (strcmp(name, "Q_LLONG") == 0) + return QMetaType::LongLong; + if (strcmp(name, "Q_ULLONG") == 0) + return QMetaType::ULongLong; + if (strcmp(name, "QIconSet") == 0) + return QMetaType::QIcon; + + uint tp = QMetaType::type(name); + return tp < QMetaType::User ? tp : 0; +} + +/* + Returns true if the type is a QVariant types. +*/ +bool isVariantType(const char* type) +{ + return qvariant_nameToType(type) != 0; +} + +// copied from qmetaobject_p.h +// do not touch without touching the moc as well +enum PropertyFlags { + Invalid = 0x00000000, + Readable = 0x00000001, + Writable = 0x00000002, + Resettable = 0x00000004, + EnumOrFlag = 0x00000008, + StdCppSet = 0x00000100, +// Override = 0x00000200, + Constant = 0x00000400, + Final = 0x00000800, + Designable = 0x00001000, + ResolveDesignable = 0x00002000, + Scriptable = 0x00004000, + ResolveScriptable = 0x00008000, + Stored = 0x00010000, + ResolveStored = 0x00020000, + Editable = 0x00040000, + ResolveEditable = 0x00080000, + User = 0x00100000, + ResolveUser = 0x00200000, + Notify = 0x00400000, + Revisioned = 0x00800000 +}; + +enum MethodFlags { + AccessPrivate = 0x00, + AccessProtected = 0x01, + AccessPublic = 0x02, + AccessMask = 0x03, //mask + + MethodMethod = 0x00, + MethodSignal = 0x04, + MethodSlot = 0x08, + MethodConstructor = 0x0c, + MethodTypeMask = 0x0c, + + MethodCompatibility = 0x10, + MethodCloned = 0x20, + MethodScriptable = 0x40, + MethodRevisioned = 0x80 +}; + +struct QMetaObjectPrivate +{ + int revision; + int className; + int classInfoCount, classInfoData; + int methodCount, methodData; + int propertyCount, propertyData; + int enumeratorCount, enumeratorData; + int constructorCount, constructorData; + int flags; +}; + +static inline const QMetaObjectPrivate *priv(const uint* data) +{ return reinterpret_cast(data); } +// end of copied lines from qmetaobject.cpp + +class QMetaMethodBuilderPrivate +{ +public: + QMetaMethodBuilderPrivate + (QMetaMethod::MethodType _methodType, + const QByteArray& _signature, + const QByteArray& _returnType = QByteArray(), + QMetaMethod::Access _access = QMetaMethod::Public) + : signature(QMetaObject::normalizedSignature(_signature.constData())), + returnType(QMetaObject::normalizedType(_returnType)), + attributes(((int)_access) | (((int)_methodType) << 2)) + { + } + + QByteArray signature; + QByteArray returnType; + QList parameterNames; + QByteArray tag; + int attributes; + + QMetaMethod::MethodType methodType() const + { + return (QMetaMethod::MethodType)((attributes & MethodTypeMask) >> 2); + } + + QMetaMethod::Access access() const + { + return (QMetaMethod::Access)(attributes & AccessMask); + } + + void setAccess(QMetaMethod::Access value) + { + attributes = ((attributes & ~AccessMask) | (int)value); + } +}; + +class QMetaPropertyBuilderPrivate +{ +public: + QMetaPropertyBuilderPrivate + (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1) + : name(_name), + type(QMetaObject::normalizedType(_type.constData())), + flags(Readable | Writable | Scriptable), notifySignal(-1) + { + if (notifierIdx >= 0) { + flags |= Notify; + notifySignal = notifierIdx; + } + } + + QByteArray name; + QByteArray type; + int flags; + int notifySignal; + + bool flag(int f) const + { + return ((flags & f) != 0); + } + + void setFlag(int f, bool value) + { + if (value) + flags |= f; + else + flags &= ~f; + } +}; + +class QMetaEnumBuilderPrivate +{ +public: + QMetaEnumBuilderPrivate(const QByteArray& _name) + : name(_name), isFlag(false) + { + } + + QByteArray name; + bool isFlag; + QList keys; + QList values; +}; + +class QMetaObjectBuilderPrivate +{ +public: + QMetaObjectBuilderPrivate() + : flags(0) + { + superClass = &QObject::staticMetaObject; + staticMetacallFunction = 0; + } + + QByteArray className; + const QMetaObject *superClass; + QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction; + QList methods; + QList constructors; + QList properties; + QList classInfoNames; + QList classInfoValues; + QList enumerators; +#ifdef Q_NO_DATA_RELOCATION + QList relatedMetaObjects; +#else + QList relatedMetaObjects; +#endif + int flags; +}; + +/*! + Constructs a new QMetaObjectBuilder. +*/ +QMetaObjectBuilder::QMetaObjectBuilder() +{ + d = new QMetaObjectBuilderPrivate(); +} + +/*! + Constructs a new QMetaObjectBuilder which is a copy of the + meta object information in \a prototype. Note: the super class + contents for \a prototype are not copied, only the immediate + class that is defined by \a prototype. + + The \a members parameter indicates which members of \a prototype + should be added. The default is AllMembers. + + \sa addMetaObject() +*/ +QMetaObjectBuilder::QMetaObjectBuilder + (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members) +{ + d = new QMetaObjectBuilderPrivate(); + addMetaObject(prototype, members); +} + +/*! + Destroys this meta object builder. +*/ +QMetaObjectBuilder::~QMetaObjectBuilder() +{ + delete d; +} + +/*! + Returns the name of the class being constructed by this + meta object builder. The default value is an empty QByteArray. + + \sa setClassName(), superClass() +*/ +QByteArray QMetaObjectBuilder::className() const +{ + return d->className; +} + +/*! + Sets the \a name of the class being constructed by this + meta object builder. + + \sa className(), setSuperClass() +*/ +void QMetaObjectBuilder::setClassName(const QByteArray& name) +{ + d->className = name; +} + +/*! + Returns the superclass meta object of the class being constructed + by this meta object builder. The default value is the meta object + for QObject. + + \sa setSuperClass(), className() +*/ +const QMetaObject *QMetaObjectBuilder::superClass() const +{ + return d->superClass; +} + +/*! + Sets the superclass meta object of the class being constructed + by this meta object builder to \a meta. The \a meta parameter + must not be null. + + \sa superClass(), setClassName() +*/ +void QMetaObjectBuilder::setSuperClass(const QMetaObject *meta) +{ + Q_ASSERT(meta); + d->superClass = meta; +} + +/*! + Returns the flags of the class being constructed by this meta object + builder. + + \sa setFlags() +*/ +QMetaObjectBuilder::MetaObjectFlags QMetaObjectBuilder::flags() const +{ + return (QMetaObjectBuilder::MetaObjectFlags)d->flags; +} + +/*! + Sets the \a flags of the class being constructed by this meta object + builder. + + \sa flags() +*/ +void QMetaObjectBuilder::setFlags(MetaObjectFlags flags) +{ + d->flags = flags; +} + +/*! + Returns the number of methods in this class, excluding the number + of methods in the base class. These include signals and slots + as well as normal member functions. + + \sa addMethod(), method(), removeMethod(), indexOfMethod() +*/ +int QMetaObjectBuilder::methodCount() const +{ + return d->methods.size(); +} + +/*! + Returns the number of constructors in this class. + + \sa addConstructor(), constructor(), removeConstructor(), indexOfConstructor() +*/ +int QMetaObjectBuilder::constructorCount() const +{ + return d->constructors.size(); +} + +/*! + Returns the number of properties in this class, excluding the number + of properties in the base class. + + \sa addProperty(), property(), removeProperty(), indexOfProperty() +*/ +int QMetaObjectBuilder::propertyCount() const +{ + return d->properties.size(); +} + +/*! + Returns the number of enumerators in this class, excluding the + number of enumerators in the base class. + + \sa addEnumerator(), enumerator(), removeEnumerator() + \sa indexOfEnumerator() +*/ +int QMetaObjectBuilder::enumeratorCount() const +{ + return d->enumerators.size(); +} + +/*! + Returns the number of items of class information in this class, + exclusing the number of items of class information in the base class. + + \sa addClassInfo(), classInfoName(), classInfoValue(), removeClassInfo() + \sa indexOfClassInfo() +*/ +int QMetaObjectBuilder::classInfoCount() const +{ + return d->classInfoNames.size(); +} + +/*! + Returns the number of related meta objects that are associated + with this class. + + Related meta objects are used when resolving the enumerated type + associated with a property, where the enumerated type is in a + different class from the property. + + \sa addRelatedMetaObject(), relatedMetaObject() + \sa removeRelatedMetaObject() +*/ +int QMetaObjectBuilder::relatedMetaObjectCount() const +{ + return d->relatedMetaObjects.size(); +} + +/*! + Adds a new public method to this class with the specified \a signature. + Returns an object that can be used to adjust the other attributes + of the method. The \a signature will be normalized before it is + added to the class. + + \sa method(), methodCount(), removeMethod(), indexOfMethod() +*/ +QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature) +{ + int index = d->methods.size(); + d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature)); + return QMetaMethodBuilder(this, index); +} + +/*! + Adds a new public method to this class with the specified + \a signature and \a returnType. Returns an object that can be + used to adjust the other attributes of the method. The \a signature + and \a returnType will be normalized before they are added to + the class. If \a returnType is empty, then it indicates that + the method has \c{void} as its return type. + + \sa method(), methodCount(), removeMethod(), indexOfMethod() +*/ +QMetaMethodBuilder QMetaObjectBuilder::addMethod + (const QByteArray& signature, const QByteArray& returnType) +{ + int index = d->methods.size(); + d->methods.append(QMetaMethodBuilderPrivate + (QMetaMethod::Method, signature, returnType)); + return QMetaMethodBuilder(this, index); +} + +/*! + Adds a new public method to this class that has the same information as + \a prototype. This is used to clone the methods of an existing + QMetaObject. Returns an object that can be used to adjust the + attributes of the method. + + This function will detect if \a prototype is an ordinary method, + signal, slot, or constructor and act accordingly. + + \sa method(), methodCount(), removeMethod(), indexOfMethod() +*/ +QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype) +{ + QMetaMethodBuilder method; + if (prototype.methodType() == QMetaMethod::Method) + method = addMethod(prototype.signature()); + else if (prototype.methodType() == QMetaMethod::Signal) + method = addSignal(prototype.signature()); + else if (prototype.methodType() == QMetaMethod::Slot) + method = addSlot(prototype.signature()); + else if (prototype.methodType() == QMetaMethod::Constructor) + method = addConstructor(prototype.signature()); + method.setReturnType(prototype.typeName()); + method.setParameterNames(prototype.parameterNames()); + method.setTag(prototype.tag()); + method.setAccess(prototype.access()); + method.setAttributes(prototype.attributes()); + return method; +} + +/*! + Adds a new public slot to this class with the specified \a signature. + Returns an object that can be used to adjust the other attributes + of the slot. The \a signature will be normalized before it is + added to the class. + + \sa addMethod(), addSignal(), indexOfSlot() +*/ +QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature) +{ + int index = d->methods.size(); + d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature)); + return QMetaMethodBuilder(this, index); +} + +/*! + Adds a new signal to this class with the specified \a signature. + Returns an object that can be used to adjust the other attributes + of the signal. The \a signature will be normalized before it is + added to the class. + + \sa addMethod(), addSlot(), indexOfSignal() +*/ +QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature) +{ + int index = d->methods.size(); + d->methods.append(QMetaMethodBuilderPrivate + (QMetaMethod::Signal, signature, QByteArray(), QMetaMethod::Protected)); + return QMetaMethodBuilder(this, index); +} + +/*! + Adds a new constructor to this class with the specified \a signature. + Returns an object that can be used to adjust the other attributes + of the constructor. The \a signature will be normalized before it is + added to the class. + + \sa constructor(), constructorCount(), removeConstructor() + \sa indexOfConstructor() +*/ +QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature) +{ + int index = d->constructors.size(); + d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature)); + return QMetaMethodBuilder(this, -(index + 1)); +} + +/*! + Adds a new constructor to this class that has the same information as + \a prototype. This is used to clone the constructors of an existing + QMetaObject. Returns an object that can be used to adjust the + attributes of the constructor. + + This function requires that \a prototype be a constructor. + + \sa constructor(), constructorCount(), removeConstructor() + \sa indexOfConstructor() +*/ +QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototype) +{ + Q_ASSERT(prototype.methodType() == QMetaMethod::Constructor); + QMetaMethodBuilder ctor = addConstructor(prototype.signature()); + ctor.setReturnType(prototype.typeName()); + ctor.setParameterNames(prototype.parameterNames()); + ctor.setTag(prototype.tag()); + ctor.setAccess(prototype.access()); + ctor.setAttributes(prototype.attributes()); + return ctor; +} + +/*! + Adds a new readable/writable property to this class with the + specified \a name and \a type. Returns an object that can be used + to adjust the other attributes of the property. The \a type will + be normalized before it is added to the class. \a notifierId will + be registered as the property's \e notify signal. + + \sa property(), propertyCount(), removeProperty(), indexOfProperty() +*/ +QMetaPropertyBuilder QMetaObjectBuilder::addProperty + (const QByteArray& name, const QByteArray& type, int notifierId) +{ + int index = d->properties.size(); + d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId)); + return QMetaPropertyBuilder(this, index); +} + +/*! + Adds a new property to this class that has the same information as + \a prototype. This is used to clone the properties of an existing + QMetaObject. Returns an object that can be used to adjust the + attributes of the property. + + \sa property(), propertyCount(), removeProperty(), indexOfProperty() +*/ +QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& prototype) +{ + QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName()); + property.setReadable(prototype.isReadable()); + property.setWritable(prototype.isWritable()); + property.setResettable(prototype.isResettable()); + property.setDesignable(prototype.isDesignable()); + property.setScriptable(prototype.isScriptable()); + property.setStored(prototype.isStored()); + property.setEditable(prototype.isEditable()); + property.setUser(prototype.isUser()); + property.setStdCppSet(prototype.hasStdCppSet()); + property.setEnumOrFlag(prototype.isEnumType()); + property.setConstant(prototype.isConstant()); + property.setFinal(prototype.isFinal()); + if (prototype.hasNotifySignal()) { + // Find an existing method for the notify signal, or add a new one. + QMetaMethod method = prototype.notifySignal(); + int index = indexOfMethod(method.signature()); + if (index == -1) + index = addMethod(method).index(); + d->properties[property._index].notifySignal = index; + d->properties[property._index].setFlag(Notify, true); + } + return property; +} + +/*! + Adds a new enumerator to this class with the specified + \a name. Returns an object that can be used to adjust + the other attributes of the enumerator. + + \sa enumerator(), enumeratorCount(), removeEnumerator(), + \sa indexOfEnumerator() +*/ +QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name) +{ + int index = d->enumerators.size(); + d->enumerators.append(QMetaEnumBuilderPrivate(name)); + return QMetaEnumBuilder(this, index); +} + +/*! + Adds a new enumerator to this class that has the same information as + \a prototype. This is used to clone the enumerators of an existing + QMetaObject. Returns an object that can be used to adjust the + attributes of the enumerator. + + \sa enumerator(), enumeratorCount(), removeEnumerator(), + \sa indexOfEnumerator() +*/ +QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype) +{ + QMetaEnumBuilder en = addEnumerator(prototype.name()); + en.setIsFlag(prototype.isFlag()); + int count = prototype.keyCount(); + for (int index = 0; index < count; ++index) + en.addKey(prototype.key(index), prototype.value(index)); + return en; +} + +/*! + Adds \a name and \a value as an item of class information to this class. + Returns the index of the new item of class information. + + \sa classInfoCount(), classInfoName(), classInfoValue(), removeClassInfo() + \sa indexOfClassInfo() +*/ +int QMetaObjectBuilder::addClassInfo(const QByteArray& name, const QByteArray& value) +{ + int index = d->classInfoNames.size(); + d->classInfoNames += name; + d->classInfoValues += value; + return index; +} + +/*! + Adds \a meta to this class as a related meta object. Returns + the index of the new related meta object entry. + + Related meta objects are used when resolving the enumerated type + associated with a property, where the enumerated type is in a + different class from the property. + + \sa relatedMetaObjectCount(), relatedMetaObject() + \sa removeRelatedMetaObject() +*/ +#ifdef Q_NO_DATA_RELOCATION +int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObjectAccessor &meta) +#else +int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObject *meta) +#endif +{ + Q_ASSERT(meta); + int index = d->relatedMetaObjects.size(); + d->relatedMetaObjects.append(meta); + return index; +} + +/*! + Adds the contents of \a prototype to this meta object builder. + This function is useful for cloning the contents of an existing QMetaObject. + + The \a members parameter indicates which members of \a prototype + should be added. The default is AllMembers. +*/ +void QMetaObjectBuilder::addMetaObject + (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members) +{ + Q_ASSERT(prototype); + int index; + + if ((members & ClassName) != 0) + d->className = prototype->className(); + + if ((members & SuperClass) != 0) + d->superClass = prototype->superClass(); + + if ((members & (Methods | Signals | Slots)) != 0) { + for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) { + QMetaMethod method = prototype->method(index); + if (method.methodType() != QMetaMethod::Signal) { + if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0) + continue; + if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0) + continue; + if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0) + continue; + } + if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) { + addMethod(method); + } else if (method.methodType() == QMetaMethod::Signal && + (members & Signals) != 0) { + addMethod(method); + } else if (method.methodType() == QMetaMethod::Slot && + (members & Slots) != 0) { + addMethod(method); + } + } + } + + if ((members & Constructors) != 0) { + for (index = 0; index < prototype->constructorCount(); ++index) + addConstructor(prototype->constructor(index)); + } + + if ((members & Properties) != 0) { + for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index) + addProperty(prototype->property(index)); + } + + if ((members & Enumerators) != 0) { + for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index) + addEnumerator(prototype->enumerator(index)); + } + + if ((members & ClassInfos) != 0) { + for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) { + QMetaClassInfo ci = prototype->classInfo(index); + addClassInfo(ci.name(), ci.value()); + } + } + + if ((members & RelatedMetaObjects) != 0) { +#ifdef Q_NO_DATA_RELOCATION + const QMetaObjectAccessor *objects = 0; +#else + const QMetaObject **objects; + if (priv(prototype->d.data)->revision < 2) { + objects = (const QMetaObject **)(prototype->d.extradata); + } else +#endif + { + const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata); + if (extra) + objects = extra->objects; + else + objects = 0; + } + if (objects) { + while (*objects != 0) { + addRelatedMetaObject(*objects); + ++objects; + } + } + } + + if ((members & StaticMetacall) != 0) { + if (priv(prototype->d.data)->revision >= 6) { + const QMetaObjectExtraData *extra = + (const QMetaObjectExtraData *)(prototype->d.extradata); + if (extra && extra->static_metacall) + setStaticMetacallFunction(extra->static_metacall); + } + } +} + +/*! + Returns the method at \a index in this class. + + \sa methodCount(), addMethod(), removeMethod(), indexOfMethod() +*/ +QMetaMethodBuilder QMetaObjectBuilder::method(int index) const +{ + if (index >= 0 && index < d->methods.size()) + return QMetaMethodBuilder(this, index); + else + return QMetaMethodBuilder(); +} + +/*! + Returns the constructor at \a index in this class. + + \sa methodCount(), addMethod(), removeMethod(), indexOfConstructor() +*/ +QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const +{ + if (index >= 0 && index < d->constructors.size()) + return QMetaMethodBuilder(this, -(index + 1)); + else + return QMetaMethodBuilder(); +} + +/*! + Returns the property at \a index in this class. + + \sa methodCount(), addMethod(), removeMethod(), indexOfProperty() +*/ +QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const +{ + if (index >= 0 && index < d->properties.size()) + return QMetaPropertyBuilder(this, index); + else + return QMetaPropertyBuilder(); +} + +/*! + Returns the enumerator at \a index in this class. + + \sa enumeratorCount(), addEnumerator(), removeEnumerator() + \sa indexOfEnumerator() +*/ +QMetaEnumBuilder QMetaObjectBuilder::enumerator(int index) const +{ + if (index >= 0 && index < d->enumerators.size()) + return QMetaEnumBuilder(this, index); + else + return QMetaEnumBuilder(); +} + +/*! + Returns the related meta object at \a index in this class. + + Related meta objects are used when resolving the enumerated type + associated with a property, where the enumerated type is in a + different class from the property. + + \sa relatedMetaObjectCount(), addRelatedMetaObject() + \sa removeRelatedMetaObject() +*/ +const QMetaObject *QMetaObjectBuilder::relatedMetaObject(int index) const +{ + if (index >= 0 && index < d->relatedMetaObjects.size()) +#ifdef Q_NO_DATA_RELOCATION + return &((*(d->relatedMetaObjects[index]))()); +#else + return d->relatedMetaObjects[index]; +#endif + else + return 0; +} + +/*! + Returns the name of the item of class information at \a index + in this class. + + \sa classInfoCount(), addClassInfo(), classInfoValue(), removeClassInfo() + \sa indexOfClassInfo() +*/ +QByteArray QMetaObjectBuilder::classInfoName(int index) const +{ + if (index >= 0 && index < d->classInfoNames.size()) + return d->classInfoNames[index]; + else + return QByteArray(); +} + +/*! + Returns the value of the item of class information at \a index + in this class. + + \sa classInfoCount(), addClassInfo(), classInfoName(), removeClassInfo() + \sa indexOfClassInfo() +*/ +QByteArray QMetaObjectBuilder::classInfoValue(int index) const +{ + if (index >= 0 && index < d->classInfoValues.size()) + return d->classInfoValues[index]; + else + return QByteArray(); +} + +/*! + Removes the method at \a index from this class. The indices of + all following methods will be adjusted downwards by 1. If the + method is registered as a notify signal on a property, then the + notify signal will be removed from the property. + + \sa methodCount(), addMethod(), method(), indexOfMethod() +*/ +void QMetaObjectBuilder::removeMethod(int index) +{ + if (index >= 0 && index < d->methods.size()) { + d->methods.removeAt(index); + for (int prop = 0; prop < d->properties.size(); ++prop) { + // Adjust the indices of property notify signal references. + if (d->properties[prop].notifySignal == index) { + d->properties[prop].notifySignal = -1; + d->properties[prop].setFlag(Notify, false); + } else if (d->properties[prop].notifySignal > index) + (d->properties[prop].notifySignal)--; + } + } +} + +/*! + Removes the constructor at \a index from this class. The indices of + all following constructors will be adjusted downwards by 1. + + \sa constructorCount(), addConstructor(), constructor() + \sa indexOfConstructor() +*/ +void QMetaObjectBuilder::removeConstructor(int index) +{ + if (index >= 0 && index < d->constructors.size()) + d->constructors.removeAt(index); +} + +/*! + Removes the property at \a index from this class. The indices of + all following properties will be adjusted downwards by 1. + + \sa propertyCount(), addProperty(), property(), indexOfProperty() +*/ +void QMetaObjectBuilder::removeProperty(int index) +{ + if (index >= 0 && index < d->properties.size()) + d->properties.removeAt(index); +} + +/*! + Removes the enumerator at \a index from this class. The indices of + all following enumerators will be adjusted downwards by 1. + + \sa enumertorCount(), addEnumerator(), enumerator() + \sa indexOfEnumerator() +*/ +void QMetaObjectBuilder::removeEnumerator(int index) +{ + if (index >= 0 && index < d->enumerators.size()) + d->enumerators.removeAt(index); +} + +/*! + Removes the item of class information at \a index from this class. + The indices of all following items will be adjusted downwards by 1. + + \sa classInfoCount(), addClassInfo(), classInfoName(), classInfoValue() + \sa indexOfClassInfo() +*/ +void QMetaObjectBuilder::removeClassInfo(int index) +{ + if (index >= 0 && index < d->classInfoNames.size()) { + d->classInfoNames.removeAt(index); + d->classInfoValues.removeAt(index); + } +} + +/*! + Removes the related meta object at \a index from this class. + The indices of all following related meta objects will be adjusted + downwards by 1. + + Related meta objects are used when resolving the enumerated type + associated with a property, where the enumerated type is in a + different class from the property. + + \sa relatedMetaObjectCount(), addRelatedMetaObject() + \sa relatedMetaObject() +*/ +void QMetaObjectBuilder::removeRelatedMetaObject(int index) +{ + if (index >= 0 && index < d->relatedMetaObjects.size()) + d->relatedMetaObjects.removeAt(index); +} + +/*! + Finds a method with the specified \a signature and returns its index; + otherwise returns -1. The \a signature will be normalized by this method. + + \sa method(), methodCount(), addMethod(), removeMethod() +*/ +int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature) +{ + QByteArray sig = QMetaObject::normalizedSignature(signature); + for (int index = 0; index < d->methods.size(); ++index) { + if (sig == d->methods[index].signature) + return index; + } + return -1; +} + +/*! + Finds a signal with the specified \a signature and returns its index; + otherwise returns -1. The \a signature will be normalized by this method. + + \sa indexOfMethod(), indexOfSlot() +*/ +int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature) +{ + QByteArray sig = QMetaObject::normalizedSignature(signature); + for (int index = 0; index < d->methods.size(); ++index) { + if (sig == d->methods[index].signature && + d->methods[index].methodType() == QMetaMethod::Signal) + return index; + } + return -1; +} + +/*! + Finds a slot with the specified \a signature and returns its index; + otherwise returns -1. The \a signature will be normalized by this method. + + \sa indexOfMethod(), indexOfSignal() +*/ +int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature) +{ + QByteArray sig = QMetaObject::normalizedSignature(signature); + for (int index = 0; index < d->methods.size(); ++index) { + if (sig == d->methods[index].signature && + d->methods[index].methodType() == QMetaMethod::Slot) + return index; + } + return -1; +} + +/*! + Finds a constructor with the specified \a signature and returns its index; + otherwise returns -1. The \a signature will be normalized by this method. + + \sa constructor(), constructorCount(), addConstructor(), removeConstructor() +*/ +int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature) +{ + QByteArray sig = QMetaObject::normalizedSignature(signature); + for (int index = 0; index < d->constructors.size(); ++index) { + if (sig == d->constructors[index].signature) + return index; + } + return -1; +} + +/*! + Finds a property with the specified \a name and returns its index; + otherwise returns -1. + + \sa property(), propertyCount(), addProperty(), removeProperty() +*/ +int QMetaObjectBuilder::indexOfProperty(const QByteArray& name) +{ + for (int index = 0; index < d->properties.size(); ++index) { + if (name == d->properties[index].name) + return index; + } + return -1; +} + +/*! + Finds an enumerator with the specified \a name and returns its index; + otherwise returns -1. + + \sa enumertor(), enumeratorCount(), addEnumerator(), removeEnumerator() +*/ +int QMetaObjectBuilder::indexOfEnumerator(const QByteArray& name) +{ + for (int index = 0; index < d->enumerators.size(); ++index) { + if (name == d->enumerators[index].name) + return index; + } + return -1; +} + +/*! + Finds an item of class information with the specified \a name and + returns its index; otherwise returns -1. + + \sa classInfoName(), classInfoValue(), classInfoCount(), addClassInfo() + \sa removeClassInfo() +*/ +int QMetaObjectBuilder::indexOfClassInfo(const QByteArray& name) +{ + for (int index = 0; index < d->classInfoNames.size(); ++index) { + if (name == d->classInfoNames[index]) + return index; + } + return -1; +} + +// Align on a specific type boundary. +#define ALIGN(size,type) \ + (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1) + +// Build a string into a QMetaObject representation. Returns the +// position in the string table where the string was placed. +static int buildString + (char *buf, char *str, int *offset, const QByteArray& value, int empty) +{ + if (value.size() == 0 && empty >= 0) + return empty; + if (buf) { + memcpy(str + *offset, value.constData(), value.size()); + str[*offset + value.size()] = '\0'; + } + int posn = *offset; + *offset += value.size() + 1; + return posn; +} + +// Build the parameter array string for a method. +static QByteArray buildParameterNames + (const QByteArray& signature, const QList& parameterNames) +{ + // If the parameter name list is specified, then concatenate them. + if (!parameterNames.isEmpty()) { + QByteArray names; + bool first = true; + foreach (const QByteArray &name, parameterNames) { + if (first) + first = false; + else + names += (char)','; + names += name; + } + return names; + } + + // Count commas in the signature, excluding those inside template arguments. + int index = signature.indexOf('('); + if (index < 0) + return QByteArray(); + ++index; + if (index >= signature.size()) + return QByteArray(); + if (signature[index] == ')') + return QByteArray(); + int count = 1; + int brackets = 0; + while (index < signature.size() && signature[index] != ',') { + char ch = signature[index++]; + if (ch == '<') + ++brackets; + else if (ch == '>') + --brackets; + else if (ch == ',' && brackets <= 0) + ++count; + } + return QByteArray(count - 1, ','); +} + +// Build a QMetaObject in "buf" based on the information in "d". +// If "buf" is null, then return the number of bytes needed to +// build the QMetaObject. Returns -1 if the metaobject if +// relocatable is set, but the metaobject contains extradata. +static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, + bool relocatable) +{ + int size = 0; + int dataIndex; + int enumIndex; + int index; + bool hasNotifySignals = false; + + if (relocatable && + (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction)) + return -1; + + // Create the main QMetaObject structure at the start of the buffer. + QMetaObject *meta = reinterpret_cast(buf); + size += sizeof(QMetaObject); + ALIGN(size, int); + if (buf) { + if (!relocatable) meta->d.superdata = d->superClass; + meta->d.extradata = 0; + } + + // Populate the QMetaObjectPrivate structure. + QMetaObjectPrivate *pmeta + = reinterpret_cast(buf + size); + int pmetaSize = size; + dataIndex = 13; // Number of fields in the QMetaObjectPrivate. + for (index = 0; index < d->properties.size(); ++index) { + if (d->properties[index].notifySignal != -1) { + hasNotifySignals = true; + break; + } + } + if (buf) { + pmeta->revision = 3; + pmeta->flags = d->flags; + pmeta->className = 0; // Class name is always the first string. + + pmeta->classInfoCount = d->classInfoNames.size(); + pmeta->classInfoData = dataIndex; + dataIndex += 2 * d->classInfoNames.size(); + + pmeta->methodCount = d->methods.size(); + pmeta->methodData = dataIndex; + dataIndex += 5 * d->methods.size(); + + pmeta->propertyCount = d->properties.size(); + pmeta->propertyData = dataIndex; + dataIndex += 3 * d->properties.size(); + if (hasNotifySignals) + dataIndex += d->properties.size(); + + pmeta->enumeratorCount = d->enumerators.size(); + pmeta->enumeratorData = dataIndex; + dataIndex += 4 * d->enumerators.size(); + + pmeta->constructorCount = d->constructors.size(); + pmeta->constructorData = dataIndex; + dataIndex += 5 * d->constructors.size(); + } else { + dataIndex += 2 * d->classInfoNames.size(); + dataIndex += 5 * d->methods.size(); + dataIndex += 3 * d->properties.size(); + if (hasNotifySignals) + dataIndex += d->properties.size(); + dataIndex += 4 * d->enumerators.size(); + dataIndex += 5 * d->constructors.size(); + } + + // Allocate space for the enumerator key names and values. + enumIndex = dataIndex; + for (index = 0; index < d->enumerators.size(); ++index) { + QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); + dataIndex += 2 * enumerator->keys.size(); + } + + // Zero terminator at the end of the data offset table. + ++dataIndex; + + // Find the start of the data and string tables. + int *data = reinterpret_cast(pmeta); + size += dataIndex * sizeof(int); + char *str = reinterpret_cast(buf + size); + if (buf) { + if (relocatable) { + meta->d.stringdata = reinterpret_cast((quintptr)size); + meta->d.data = reinterpret_cast((quintptr)pmetaSize); + } else { + meta->d.stringdata = str; + meta->d.data = reinterpret_cast(data); + } + } + + // Reset the current data position to just past the QMetaObjectPrivate. + dataIndex = 13; + + // Add the class name to the string table. + int offset = 0; + buildString(buf, str, &offset, d->className, -1); + + // Add a common empty string, which is used to indicate "void" + // method returns, empty tag strings, etc. + int empty = buildString(buf, str, &offset, QByteArray(), -1); + + // Output the class infos, + for (index = 0; index < d->classInfoNames.size(); ++index) { + int name = buildString(buf, str, &offset, d->classInfoNames[index], empty); + int value = buildString(buf, str, &offset, d->classInfoValues[index], empty); + if (buf) { + data[dataIndex] = name; + data[dataIndex + 1] = value; + } + dataIndex += 2; + } + + // Output the methods in the class. + for (index = 0; index < d->methods.size(); ++index) { + QMetaMethodBuilderPrivate *method = &(d->methods[index]); + int sig = buildString(buf, str, &offset, method->signature, empty); + int params; + QByteArray names = buildParameterNames + (method->signature, method->parameterNames); + params = buildString(buf, str, &offset, names, empty); + int ret = buildString(buf, str, &offset, method->returnType, empty); + int tag = buildString(buf, str, &offset, method->tag, empty); + int attrs = method->attributes; + if (buf) { + data[dataIndex] = sig; + data[dataIndex + 1] = params; + data[dataIndex + 2] = ret; + data[dataIndex + 3] = tag; + data[dataIndex + 4] = attrs; + } + dataIndex += 5; + } + + // Output the properties in the class. + for (index = 0; index < d->properties.size(); ++index) { + QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); + int name = buildString(buf, str, &offset, prop->name, empty); + int type = buildString(buf, str, &offset, prop->type, empty); + int flags = prop->flags; + + if (!isVariantType(prop->type)) { + flags |= EnumOrFlag; + } else { + flags |= qvariant_nameToType(prop->type) << 24; + } + + if (buf) { + data[dataIndex] = name; + data[dataIndex + 1] = type; + data[dataIndex + 2] = flags; + } + dataIndex += 3; + } + if (hasNotifySignals) { + for (index = 0; index < d->properties.size(); ++index) { + QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); + if (buf) { + if (prop->notifySignal != -1) + data[dataIndex] = prop->notifySignal; + else + data[dataIndex] = 0; + } + ++dataIndex; + } + } + + // Output the enumerators in the class. + for (index = 0; index < d->enumerators.size(); ++index) { + QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); + int name = buildString(buf, str, &offset, enumerator->name, empty); + int isFlag = (int)(enumerator->isFlag); + int count = enumerator->keys.size(); + int enumOffset = enumIndex; + if (buf) { + data[dataIndex] = name; + data[dataIndex + 1] = isFlag; + data[dataIndex + 2] = count; + data[dataIndex + 3] = enumOffset; + } + for (int key = 0; key < count; ++key) { + int keyIndex = buildString(buf, str, &offset, enumerator->keys[key], empty); + if (buf) { + data[enumOffset++] = keyIndex; + data[enumOffset++] = enumerator->values[key]; + } + } + dataIndex += 4; + enumIndex += 2 * count; + } + + // Output the constructors in the class. + for (index = 0; index < d->constructors.size(); ++index) { + QMetaMethodBuilderPrivate *method = &(d->constructors[index]); + int sig = buildString(buf, str, &offset, method->signature, empty); + int params; + QByteArray names = buildParameterNames + (method->signature, method->parameterNames); + params = buildString(buf, str, &offset, names, empty); + int ret = buildString(buf, str, &offset, method->returnType, empty); + int tag = buildString(buf, str, &offset, method->tag, empty); + int attrs = method->attributes; + if (buf) { + data[dataIndex] = sig; + data[dataIndex + 1] = params; + data[dataIndex + 2] = ret; + data[dataIndex + 3] = tag; + data[dataIndex + 4] = attrs; + } + dataIndex += 5; + } + + // One more empty string to act as a terminator. + buildString(buf, str, &offset, QByteArray(), -1); + size += offset; + + // Output the zero terminator in the data array. + if (buf) + data[enumIndex] = 0; + + // Create the extradata block if we need one. + if (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction) { + ALIGN(size, QMetaObject **); + ALIGN(size, QMetaObjectBuilder::StaticMetacallFunction); + QMetaObjectExtraData *extra = + reinterpret_cast(buf + size); + size += sizeof(QMetaObjectExtraData); + ALIGN(size, QMetaObject *); +#ifdef Q_NO_DATA_RELOCATION + QMetaObjectAccessor *objects = + reinterpret_cast(buf + size); +#else + const QMetaObject **objects = + reinterpret_cast(buf + size); +#endif + if (buf) { + if (d->relatedMetaObjects.size() > 0) { + extra->objects = objects; + for (index = 0; index < d->relatedMetaObjects.size(); ++index) + objects[index] = d->relatedMetaObjects[index]; + objects[index] = 0; + } else { + extra->objects = 0; + } + extra->static_metacall = d->staticMetacallFunction; + meta->d.extradata = reinterpret_cast(extra); + } + if (d->relatedMetaObjects.size() > 0) + size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1); + } + + // Align the final size and return it. + ALIGN(size, void *); + return size; +} + +/*! + Converts this meta object builder into a concrete QMetaObject. + The return value should be deallocated using qFree() once it + is no longer needed. + + The returned meta object is a snapshot of the state of the + QMetaObjectBuilder. Any further modifications to the QMetaObjectBuilder + will not be reflected in previous meta objects returned by + this method. +*/ +QMetaObject *QMetaObjectBuilder::toMetaObject() const +{ + int size = buildMetaObject(d, 0, false); + char *buf = reinterpret_cast(qMalloc(size)); + memset(buf, 0, size); + buildMetaObject(d, buf, false); + return reinterpret_cast(buf); +} + +/* + \internal + + Converts this meta object builder into relocatable data. This data can + be stored, copied and later passed to fromRelocatableData() to create a + concrete QMetaObject. + + The data is specific to the architecture on which it was created, but is not + specific to the process that created it. Not all meta object builder's can + be converted to data in this way. If \a ok is provided, it will be set to + true if the conversion succeeds, and false otherwise. If a + staticMetacallFunction() or any relatedMetaObject()'s are specified the + conversion to relocatable data will fail. +*/ +QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const +{ + int size = buildMetaObject(d, 0, true); + if (size == -1) { + if (ok) *ok = false; + return QByteArray(); + } + + QByteArray data; + data.resize(size); + char *buf = data.data(); + memset(buf, 0, size); + buildMetaObject(d, buf, true); + if (ok) *ok = true; + return data; +} + +/* + \internal + + Sets the \a data returned from toRelocatableData() onto a concrete + QMetaObject instance, \a output. As the meta object's super class is not + saved in the relocatable data, it must be passed as \a superClass. +*/ +void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, + const QMetaObject *superclass, + const QByteArray &data) +{ + if (!output) + return; + + const char *buf = data.constData(); + const QMetaObject *dataMo = reinterpret_cast(buf); + + quintptr stringdataOffset = (quintptr)dataMo->d.stringdata; + quintptr dataOffset = (quintptr)dataMo->d.data; + + output->d.superdata = superclass; + output->d.stringdata = buf + stringdataOffset; + output->d.data = reinterpret_cast(buf + dataOffset); +} + +/*! + \typedef QMetaObjectBuilder::StaticMetacallFunction + + Typedef for static metacall functions. The three parameters are + the call type value, the constructor index, and the + array of parameters. +*/ + +/*! + Returns the static metacall function to use to construct objects + of this class. The default value is null. + + \sa setStaticMetacallFunction() +*/ +QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const +{ + return d->staticMetacallFunction; +} + +/*! + Sets the static metacall function to use to construct objects + of this class to \a value. The default value is null. + + \sa staticMetacallFunction() +*/ +void QMetaObjectBuilder::setStaticMetacallFunction + (QMetaObjectBuilder::StaticMetacallFunction value) +{ + d->staticMetacallFunction = value; +} + +#ifndef QT_NO_DATASTREAM + +/*! + Serializes the contents of the meta object builder onto \a stream. + + \sa deserialize() +*/ +void QMetaObjectBuilder::serialize(QDataStream& stream) const +{ + int index; + + // Write the class and super class names. + stream << d->className; + if (d->superClass) + stream << QByteArray(d->superClass->className()); + else + stream << QByteArray(); + + // Write the counts for each type of class member. + stream << d->classInfoNames.size(); + stream << d->methods.size(); + stream << d->properties.size(); + stream << d->enumerators.size(); + stream << d->constructors.size(); + stream << d->relatedMetaObjects.size(); + + // Write the items of class information. + for (index = 0; index < d->classInfoNames.size(); ++index) { + stream << d->classInfoNames[index]; + stream << d->classInfoValues[index]; + } + + // Write the methods. + for (index = 0; index < d->methods.size(); ++index) { + const QMetaMethodBuilderPrivate *method = &(d->methods[index]); + stream << method->signature; + stream << method->returnType; + stream << method->parameterNames; + stream << method->tag; + stream << method->attributes; + } + + // Write the properties. + for (index = 0; index < d->properties.size(); ++index) { + const QMetaPropertyBuilderPrivate *property = &(d->properties[index]); + stream << property->name; + stream << property->type; + stream << property->flags; + stream << property->notifySignal; + } + + // Write the enumerators. + for (index = 0; index < d->enumerators.size(); ++index) { + const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); + stream << enumerator->name; + stream << enumerator->isFlag; + stream << enumerator->keys; + stream << enumerator->values; + } + + // Write the constructors. + for (index = 0; index < d->constructors.size(); ++index) { + const QMetaMethodBuilderPrivate *method = &(d->constructors[index]); + stream << method->signature; + stream << method->returnType; + stream << method->parameterNames; + stream << method->tag; + stream << method->attributes; + } + + // Write the related meta objects. +#ifdef Q_NO_DATA_RELOCATION + //### What do we do here? +#else + for (index = 0; index < d->relatedMetaObjects.size(); ++index) { + const QMetaObject *meta = d->relatedMetaObjects[index]; + stream << QByteArray(meta->className()); + } +#endif + + // Add an extra empty QByteArray for additional data in future versions. + // This should help maintain backwards compatibility, allowing older + // versions to read newer data. + stream << QByteArray(); +} + +// Resolve a class name using the name reference map. +static const QMetaObject *resolveClassName + (const QMap& references, + const QByteArray& name) +{ + if (name == QByteArray("QObject")) + return &QObject::staticMetaObject; + else + return references.value(name, 0); +} + +/*! + Deserializes a meta object builder from \a stream into + this meta object builder. + + The \a references parameter specifies a mapping from class names + to QMetaObject instances for resolving the super class name and + related meta objects in the object that is deserialized. + The meta object for QObject is implicitly added to \a references + and does not need to be supplied. + + The QDataStream::status() value on \a stream will be set to + QDataStream::ReadCorruptData if the input data is corrupt. + The status will be set to QDataStream::ReadPastEnd if the + input was exhausted before the full meta object was read. + + \sa serialize() +*/ +void QMetaObjectBuilder::deserialize + (QDataStream& stream, + const QMap& references) +{ + QByteArray name; + const QMetaObject *cl; + int index; + + // Clear all members in the builder to their default states. + d->className.clear(); + d->superClass = &QObject::staticMetaObject; + d->classInfoNames.clear(); + d->classInfoValues.clear(); + d->methods.clear(); + d->properties.clear(); + d->enumerators.clear(); + d->constructors.clear(); + d->relatedMetaObjects.clear(); + d->staticMetacallFunction = 0; + + // Read the class and super class names. + stream >> d->className; + stream >> name; + if (name.isEmpty()) { + d->superClass = 0; + } else if ((cl = resolveClassName(references, name)) != 0) { + d->superClass = cl; + } else { + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + + // Read the counts for each type of class member. + int classInfoCount, methodCount, propertyCount; + int enumeratorCount, constructorCount, relatedMetaObjectCount; + stream >> classInfoCount; + stream >> methodCount; + stream >> propertyCount; + stream >> enumeratorCount; + stream >> constructorCount; + stream >> relatedMetaObjectCount; + if (classInfoCount < 0 || methodCount < 0 || + propertyCount < 0 || enumeratorCount < 0 || + constructorCount < 0 || relatedMetaObjectCount < 0) { + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + + // Read the items of class information. + for (index = 0; index < classInfoCount; ++index) { + if (stream.status() != QDataStream::Ok) + return; + QByteArray value; + stream >> name; + stream >> value; + addClassInfo(name, value); + } + + // Read the member methods. + for (index = 0; index < methodCount; ++index) { + if (stream.status() != QDataStream::Ok) + return; + stream >> name; + addMethod(name); + QMetaMethodBuilderPrivate *method = &(d->methods[index]); + stream >> method->returnType; + stream >> method->parameterNames; + stream >> method->tag; + stream >> method->attributes; + if (method->methodType() == QMetaMethod::Constructor) { + // Cannot add a constructor in this set of methods. + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + } + + // Read the properties. + for (index = 0; index < propertyCount; ++index) { + if (stream.status() != QDataStream::Ok) + return; + QByteArray type; + stream >> name; + stream >> type; + addProperty(name, type); + QMetaPropertyBuilderPrivate *property = &(d->properties[index]); + stream >> property->flags; + stream >> property->notifySignal; + if (property->notifySignal < -1 || + property->notifySignal >= d->methods.size()) { + // Notify signal method index is out of range. + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + if (property->notifySignal >= 0 && + d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) { + // Notify signal method index does not refer to a signal. + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + } + + // Read the enumerators. + for (index = 0; index < enumeratorCount; ++index) { + if (stream.status() != QDataStream::Ok) + return; + stream >> name; + addEnumerator(name); + QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); + stream >> enumerator->isFlag; + stream >> enumerator->keys; + stream >> enumerator->values; + if (enumerator->keys.size() != enumerator->values.size()) { + // Mismatch between number of keys and number of values. + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + } + + // Read the constructor methods. + for (index = 0; index < constructorCount; ++index) { + if (stream.status() != QDataStream::Ok) + return; + stream >> name; + addConstructor(name); + QMetaMethodBuilderPrivate *method = &(d->constructors[index]); + stream >> method->returnType; + stream >> method->parameterNames; + stream >> method->tag; + stream >> method->attributes; + if (method->methodType() != QMetaMethod::Constructor) { + // The type must be Constructor. + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + } + + // Read the related meta objects. +#ifdef Q_NO_DATA_RELOCATION + //### What do we do here +#else + for (index = 0; index < relatedMetaObjectCount; ++index) { + if (stream.status() != QDataStream::Ok) + return; + stream >> name; + cl = resolveClassName(references, name); + if (!cl) { + stream.setStatus(QDataStream::ReadCorruptData); + return; + } + addRelatedMetaObject(cl); + } +#endif + + // Read the extra data block, which is reserved for future use. + stream >> name; +} + +#endif // !QT_NO_DATASTREAM + +/*! + \class QMetaMethodBuilder + \internal + \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder. +*/ + +QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const +{ + // Positive indices indicate methods, negative indices indicate constructors. + if (_mobj && _index >= 0 && _index < _mobj->d->methods.size()) + return &(_mobj->d->methods[_index]); + else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size()) + return &(_mobj->d->constructors[(-_index) - 1]); + else + return 0; +} + +/*! + \fn QMetaMethodBuilder::QMetaMethodBuilder() + \internal +*/ + +/*! + Returns the index of this method within its QMetaObjectBuilder. +*/ +int QMetaMethodBuilder::index() const +{ + if (_index >= 0) + return _index; // Method, signal, or slot + else + return (-_index) - 1; // Constructor +} + +/*! + Returns the type of this method (signal, slot, method, or constructor). +*/ +QMetaMethod::MethodType QMetaMethodBuilder::methodType() const +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + return d->methodType(); + else + return QMetaMethod::Method; +} + +/*! + Returns the signature of this method. + + \sa parameterNames(), returnType() +*/ +QByteArray QMetaMethodBuilder::signature() const +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + return d->signature; + else + return QByteArray(); +} + +/*! + Returns the return type for this method; empty if the method's + return type is \c{void}. + + \sa setReturnType(), signature() +*/ +QByteArray QMetaMethodBuilder::returnType() const +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + return d->returnType; + else + return QByteArray(); +} + +/*! + Sets the return type for this method to \a value. If \a value + is empty, then the method's return type is \c{void}. The \a value + will be normalized before it is added to the method. + + \sa returnType(), signature() +*/ +void QMetaMethodBuilder::setReturnType(const QByteArray& value) +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + d->returnType = QMetaObject::normalizedType(value); +} + +/*! + Returns the list of parameter names for this method. + + \sa setParameterNames() +*/ +QList QMetaMethodBuilder::parameterNames() const +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + return d->parameterNames; + else + return QList(); +} + +/*! + Sets the list of parameter names for this method to \a value. + + \sa parameterNames() +*/ +void QMetaMethodBuilder::setParameterNames(const QList& value) +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + d->parameterNames = value; +} + +/*! + Returns the tag associated with this method. + + \sa setTag() +*/ +QByteArray QMetaMethodBuilder::tag() const +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + return d->tag; + else + return QByteArray(); +} + +/*! + Sets the tag associated with this method to \a value. + + \sa setTag() +*/ +void QMetaMethodBuilder::setTag(const QByteArray& value) +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + d->tag = value; +} + +/*! + Returns the access specification of this method (private, protected, + or public). The default value is QMetaMethod::Public for methods, + slots, and constructors. The default value is QMetaMethod::Protected + for signals. + + \sa setAccess() +*/ +QMetaMethod::Access QMetaMethodBuilder::access() const +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + return d->access(); + else + return QMetaMethod::Public; +} + +/*! + Sets the access specification of this method (private, protected, + or public) to \a value. If the method is a signal, this function + will be ignored. + + \sa access() +*/ +void QMetaMethodBuilder::setAccess(QMetaMethod::Access value) +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d && d->methodType() != QMetaMethod::Signal) + d->setAccess(value); +} + +/*! + Returns the additional attributes for this method. + + \sa setAttributes() +*/ +int QMetaMethodBuilder::attributes() const +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + return (d->attributes >> 4); + else + return 0; +} + +/*! + Sets the additional attributes for this method to \a value. + + \sa attributes() +*/ +void QMetaMethodBuilder::setAttributes(int value) +{ + QMetaMethodBuilderPrivate *d = d_func(); + if (d) + d->attributes = ((d->attributes & 0x0f) | (value << 4)); +} + +/*! + \class QMetaPropertyBuilder + \internal + \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder. +*/ + +QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const +{ + if (_mobj && _index >= 0 && _index < _mobj->d->properties.size()) + return &(_mobj->d->properties[_index]); + else + return 0; +} + +/*! + \fn QMetaPropertyBuilder::QMetaPropertyBuilder() + \internal +*/ + +/*! + \fn int QMetaPropertyBuilder::index() const + + Returns the index of this property within its QMetaObjectBuilder. +*/ + +/*! + Returns the name associated with this property. + + \sa type() +*/ +QByteArray QMetaPropertyBuilder::name() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->name; + else + return QByteArray(); +} + +/*! + Returns the type associated with this property. + + \sa name() +*/ +QByteArray QMetaPropertyBuilder::type() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->type; + else + return QByteArray(); +} + +/*! + Returns true if this property has a notify signal; false otherwise. + + \sa notifySignal(), setNotifySignal(), removeNotifySignal() +*/ +bool QMetaPropertyBuilder::hasNotifySignal() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Notify); + else + return false; +} + +/*! + Returns the notify signal associated with this property. + + \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal() +*/ +QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d && d->notifySignal >= 0) + return QMetaMethodBuilder(_mobj, d->notifySignal); + else + return QMetaMethodBuilder(); +} + +/*! + Sets the notify signal associated with this property to \a value. + + \sa hasNotifySignal(), notifySignal(), removeNotifySignal() +*/ +void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) { + if (value._mobj) { + d->notifySignal = value._index; + d->setFlag(Notify, true); + } else { + d->notifySignal = -1; + d->setFlag(Notify, false); + } + } +} + +/*! + Removes the notify signal from this property. + + \sa hasNotifySignal(), notifySignal(), setNotifySignal() +*/ +void QMetaPropertyBuilder::removeNotifySignal() +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) { + d->notifySignal = -1; + d->setFlag(Notify, false); + } +} + +/*! + Returns true if this property is readable; otherwise returns false. + The default value is true. + + \sa setReadable(), isWritable() +*/ +bool QMetaPropertyBuilder::isReadable() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Readable); + else + return false; +} + +/*! + Returns true if this property is writable; otherwise returns false. + The default value is true. + + \sa setWritable(), isReadable() +*/ +bool QMetaPropertyBuilder::isWritable() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Writable); + else + return false; +} + +/*! + Returns true if this property can be reset to a default value; otherwise + returns false. The default value is false. + + \sa setResettable() +*/ +bool QMetaPropertyBuilder::isResettable() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Resettable); + else + return false; +} + +/*! + Returns true if this property is designable; otherwise returns false. + This default value is false. + + \sa setDesignable(), isScriptable(), isStored() +*/ +bool QMetaPropertyBuilder::isDesignable() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Designable); + else + return false; +} + +/*! + Returns true if the property is scriptable; otherwise returns false. + This default value is true. + + \sa setScriptable(), isDesignable(), isStored() +*/ +bool QMetaPropertyBuilder::isScriptable() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Scriptable); + else + return false; +} + +/*! + Returns true if the property is stored; otherwise returns false. + This default value is false. + + \sa setStored(), isDesignable(), isScriptable() +*/ +bool QMetaPropertyBuilder::isStored() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Stored); + else + return false; +} + +/*! + Returns true if the property is editable; otherwise returns false. + This default value is false. + + \sa setEditable(), isDesignable(), isScriptable(), isStored() +*/ +bool QMetaPropertyBuilder::isEditable() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Editable); + else + return false; +} + +/*! + Returns true if this property is designated as the \c USER + property, i.e., the one that the user can edit or that is + significant in some other way. Otherwise it returns + false. This default value is false. + + \sa setUser(), isDesignable(), isScriptable() +*/ +bool QMetaPropertyBuilder::isUser() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(User); + else + return false; +} + +/*! + Returns true if the property has a C++ setter function that + follows Qt's standard "name" / "setName" pattern. Designer and uic + query hasStdCppSet() in order to avoid expensive + QObject::setProperty() calls. All properties in Qt [should] follow + this pattern. The default value is false. + + \sa setStdCppSet() +*/ +bool QMetaPropertyBuilder::hasStdCppSet() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(StdCppSet); + else + return false; +} + +/*! + Returns true if the property is an enumerator or flag type; + otherwise returns false. This default value is false. + + \sa setEnumOrFlag() +*/ +bool QMetaPropertyBuilder::isEnumOrFlag() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(EnumOrFlag); + else + return false; +} + +/*! + Returns true if the property is constant; otherwise returns false. + The default value is false. +*/ +bool QMetaPropertyBuilder::isConstant() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Constant); + else + return false; +} + +/*! + Returns true if the property is final; otherwise returns false. + The default value is false. +*/ +bool QMetaPropertyBuilder::isFinal() const +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + return d->flag(Final); + else + return false; +} + +/*! + Sets this property to readable if \a value is true. + + \sa isReadable(), setWritable() +*/ +void QMetaPropertyBuilder::setReadable(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Readable, value); +} + +/*! + Sets this property to writable if \a value is true. + + \sa isWritable(), setReadable() +*/ +void QMetaPropertyBuilder::setWritable(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Writable, value); +} + +/*! + Sets this property to resettable if \a value is true. + + \sa isResettable() +*/ +void QMetaPropertyBuilder::setResettable(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Resettable, value); +} + +/*! + Sets this property to designable if \a value is true. + + \sa isDesignable(), setScriptable(), setStored() +*/ +void QMetaPropertyBuilder::setDesignable(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Designable, value); +} + +/*! + Sets this property to scriptable if \a value is true. + + \sa isScriptable(), setDesignable(), setStored() +*/ +void QMetaPropertyBuilder::setScriptable(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Scriptable, value); +} + +/*! + Sets this property to storable if \a value is true. + + \sa isStored(), setDesignable(), setScriptable() +*/ +void QMetaPropertyBuilder::setStored(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Stored, value); +} + +/*! + Sets this property to editable if \a value is true. + + \sa isEditable(), setDesignable(), setScriptable(), setStored() +*/ +void QMetaPropertyBuilder::setEditable(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Editable, value); +} + +/*! + Sets the \c USER flag on this property to \a value. + + \sa isUser(), setDesignable(), setScriptable() +*/ +void QMetaPropertyBuilder::setUser(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(User, value); +} + +/*! + Sets the C++ setter flag on this property to \a value, which is + true if the property has a C++ setter function that follows Qt's + standard "name" / "setName" pattern. + + \sa hasStdCppSet() +*/ +void QMetaPropertyBuilder::setStdCppSet(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(StdCppSet, value); +} + +/*! + Sets this property to be of an enumerator or flag type if + \a value is true. + + \sa isEnumOrFlag() +*/ +void QMetaPropertyBuilder::setEnumOrFlag(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(EnumOrFlag, value); +} + +/*! + Sets the \c CONSTANT flag on this property to \a value. + + \sa isConstant() +*/ +void QMetaPropertyBuilder::setConstant(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Constant, value); +} + +/*! + Sets the \c FINAL flag on this property to \a value. + + \sa isFinal() +*/ +void QMetaPropertyBuilder::setFinal(bool value) +{ + QMetaPropertyBuilderPrivate *d = d_func(); + if (d) + d->setFlag(Final, value); +} + + +/*! + \class QMetaEnumBuilder + \internal + \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder. +*/ + +QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const +{ + if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size()) + return &(_mobj->d->enumerators[_index]); + else + return 0; +} + +/*! + \fn QMetaEnumBuilder::QMetaEnumBuilder() + \internal +*/ + +/*! + \fn int QMetaEnumBuilder::index() const + + Returns the index of this enumerator within its QMetaObjectBuilder. +*/ + +/*! + Returns the name of the enumerator (without the scope). +*/ +QByteArray QMetaEnumBuilder::name() const +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d) + return d->name; + else + return QByteArray(); +} + +/*! + Returns true if this enumerator is used as a flag; otherwise returns + false. + + \sa setIsFlag() +*/ +bool QMetaEnumBuilder::isFlag() const +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d) + return d->isFlag; + else + return false; +} + +/*! + Sets this enumerator to be used as a flag if \a value is true. + + \sa isFlag() +*/ +void QMetaEnumBuilder::setIsFlag(bool value) +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d) + d->isFlag = value; +} + +/*! + Returns the number of keys. + + \sa key(), addKey() +*/ +int QMetaEnumBuilder::keyCount() const +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d) + return d->keys.size(); + else + return 0; +} + +/*! + Returns the key with the given \a index, or an empty QByteArray + if no such key exists. + + \sa keyCount(), addKey(), value() +*/ +QByteArray QMetaEnumBuilder::key(int index) const +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d && index >= 0 && index < d->keys.size()) + return d->keys[index]; + else + return QByteArray(); +} + +/*! + Returns the value with the given \a index; or returns -1 if there + is no such value. + + \sa keyCount(), addKey(), key() +*/ +int QMetaEnumBuilder::value(int index) const +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d && index >= 0 && index < d->keys.size()) + return d->values[index]; + else + return -1; +} + +/*! + Adds a new key called \a name to this enumerator, associated + with \a value. Returns the index of the new key. + + \sa keyCount(), key(), value(), removeKey() +*/ +int QMetaEnumBuilder::addKey(const QByteArray& name, int value) +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d) { + int index = d->keys.size(); + d->keys += name; + d->values += value; + return index; + } else { + return -1; + } +} + +/*! + Removes the key at \a index from this enumerator. + + \sa addKey() +*/ +void QMetaEnumBuilder::removeKey(int index) +{ + QMetaEnumBuilderPrivate *d = d_func(); + if (d && index >= 0 && index < d->keys.size()) { + d->keys.removeAt(index); + d->values.removeAt(index); + } +} + +QT_END_NAMESPACE diff --git a/lib/qmetaobjectbuilder_p.h b/lib/qmetaobjectbuilder_p.h new file mode 100644 index 0000000..1e85353 --- /dev/null +++ b/lib/qmetaobjectbuilder_p.h @@ -0,0 +1,325 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMETAOBJECTBUILDER_H +#define QMETAOBJECTBUILDER_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of moc. This header file may change from version to version without notice, +// or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include + +//#include + +QT_BEGIN_NAMESPACE + +class QMetaObjectBuilderPrivate; +class QMetaMethodBuilder; +class QMetaMethodBuilderPrivate; +class QMetaPropertyBuilder; +class QMetaPropertyBuilderPrivate; +class QMetaEnumBuilder; +class QMetaEnumBuilderPrivate; + +class QMetaObjectBuilder +{ +public: + enum AddMember + { + ClassName = 0x00000001, + SuperClass = 0x00000002, + Methods = 0x00000004, + Signals = 0x00000008, + Slots = 0x00000010, + Constructors = 0x00000020, + Properties = 0x00000040, + Enumerators = 0x00000080, + ClassInfos = 0x00000100, + RelatedMetaObjects = 0x00000200, + StaticMetacall = 0x00000400, + PublicMethods = 0x00000800, + ProtectedMethods = 0x00001000, + PrivateMethods = 0x00002000, + AllMembers = 0x7FFFFFFF, + AllPrimaryMembers = 0x7FFFFBFC + }; + Q_DECLARE_FLAGS(AddMembers, AddMember) + + enum MetaObjectFlag { + DynamicMetaObject = 0x01 + }; + Q_DECLARE_FLAGS(MetaObjectFlags, MetaObjectFlag) + + QMetaObjectBuilder(); + explicit QMetaObjectBuilder(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); + virtual ~QMetaObjectBuilder(); + + QByteArray className() const; + void setClassName(const QByteArray& name); + + const QMetaObject *superClass() const; + void setSuperClass(const QMetaObject *meta); + + MetaObjectFlags flags() const; + void setFlags(MetaObjectFlags); + + int methodCount() const; + int constructorCount() const; + int propertyCount() const; + int enumeratorCount() const; + int classInfoCount() const; + int relatedMetaObjectCount() const; + + QMetaMethodBuilder addMethod(const QByteArray& signature); + QMetaMethodBuilder addMethod(const QByteArray& signature, const QByteArray& returnType); + QMetaMethodBuilder addMethod(const QMetaMethod& prototype); + + QMetaMethodBuilder addSlot(const QByteArray& signature); + QMetaMethodBuilder addSignal(const QByteArray& signature); + + QMetaMethodBuilder addConstructor(const QByteArray& signature); + QMetaMethodBuilder addConstructor(const QMetaMethod& prototype); + + QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, int notifierId=-1); + QMetaPropertyBuilder addProperty(const QMetaProperty& prototype); + + QMetaEnumBuilder addEnumerator(const QByteArray& name); + QMetaEnumBuilder addEnumerator(const QMetaEnum& prototype); + + int addClassInfo(const QByteArray& name, const QByteArray& value); + +#ifdef Q_NO_DATA_RELOCATION + int addRelatedMetaObject(const QMetaObjectAccessor &meta); +#else + int addRelatedMetaObject(const QMetaObject *meta); +#endif + + void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); + + QMetaMethodBuilder method(int index) const; + QMetaMethodBuilder constructor(int index) const; + QMetaPropertyBuilder property(int index) const; + QMetaEnumBuilder enumerator(int index) const; + const QMetaObject *relatedMetaObject(int index) const; + + QByteArray classInfoName(int index) const; + QByteArray classInfoValue(int index) const; + + void removeMethod(int index); + void removeConstructor(int index); + void removeProperty(int index); + void removeEnumerator(int index); + void removeClassInfo(int index); + void removeRelatedMetaObject(int index); + + int indexOfMethod(const QByteArray& signature); + int indexOfSignal(const QByteArray& signature); + int indexOfSlot(const QByteArray& signature); + int indexOfConstructor(const QByteArray& signature); + int indexOfProperty(const QByteArray& name); + int indexOfEnumerator(const QByteArray& name); + int indexOfClassInfo(const QByteArray& name); + + typedef QMetaObjectExtraData::StaticMetacallFunction StaticMetacallFunction; + + QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const; + void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value); + + QMetaObject *toMetaObject() const; + QByteArray toRelocatableData(bool * = 0) const; + static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &); + +#ifndef QT_NO_DATASTREAM + void serialize(QDataStream& stream) const; + void deserialize + (QDataStream& stream, + const QMap& references); +#endif + +private: + Q_DISABLE_COPY(QMetaObjectBuilder) + + QMetaObjectBuilderPrivate *d; + + friend class QMetaMethodBuilder; + friend class QMetaPropertyBuilder; + friend class QMetaEnumBuilder; +}; + +class QMetaMethodBuilder +{ +public: + QMetaMethodBuilder() : _mobj(0), _index(0) {} + + int index() const; + + QMetaMethod::MethodType methodType() const; + QByteArray signature() const; + + QByteArray returnType() const; + void setReturnType(const QByteArray& value); + + QList parameterNames() const; + void setParameterNames(const QList& value); + + QByteArray tag() const; + void setTag(const QByteArray& value); + + QMetaMethod::Access access() const; + void setAccess(QMetaMethod::Access value); + + int attributes() const; + void setAttributes(int value); + +private: + const QMetaObjectBuilder *_mobj; + int _index; + + friend class QMetaObjectBuilder; + friend class QMetaPropertyBuilder; + + QMetaMethodBuilder(const QMetaObjectBuilder *mobj, int index) + : _mobj(mobj), _index(index) {} + + QMetaMethodBuilderPrivate *d_func() const; +}; + +class QMetaPropertyBuilder +{ +public: + QMetaPropertyBuilder() : _mobj(0), _index(0) {} + + int index() const { return _index; } + + QByteArray name() const; + QByteArray type() const; + + bool hasNotifySignal() const; + QMetaMethodBuilder notifySignal() const; + void setNotifySignal(const QMetaMethodBuilder& value); + void removeNotifySignal(); + + bool isReadable() const; + bool isWritable() const; + bool isResettable() const; + bool isDesignable() const; + bool isScriptable() const; + bool isStored() const; + bool isEditable() const; + bool isUser() const; + bool hasStdCppSet() const; + bool isEnumOrFlag() const; + bool isConstant() const; + bool isFinal() const; + + void setReadable(bool value); + void setWritable(bool value); + void setResettable(bool value); + void setDesignable(bool value); + void setScriptable(bool value); + void setStored(bool value); + void setEditable(bool value); + void setUser(bool value); + void setStdCppSet(bool value); + void setEnumOrFlag(bool value); + void setConstant(bool value); + void setFinal(bool value); + +private: + const QMetaObjectBuilder *_mobj; + int _index; + + friend class QMetaObjectBuilder; + + QMetaPropertyBuilder(const QMetaObjectBuilder *mobj, int index) + : _mobj(mobj), _index(index) {} + + QMetaPropertyBuilderPrivate *d_func() const; +}; + +class QMetaEnumBuilder +{ +public: + QMetaEnumBuilder() : _mobj(0), _index(0) {} + + int index() const { return _index; } + + QByteArray name() const; + + bool isFlag() const; + void setIsFlag(bool value); + + int keyCount() const; + QByteArray key(int index) const; + int value(int index) const; + + int addKey(const QByteArray& name, int value); + void removeKey(int index); + +private: + const QMetaObjectBuilder *_mobj; + int _index; + + friend class QMetaObjectBuilder; + + QMetaEnumBuilder(const QMetaObjectBuilder *mobj, int index) + : _mobj(mobj), _index(index) {} + + QMetaEnumBuilderPrivate *d_func() const; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers) +Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::MetaObjectFlags) + +QT_END_NAMESPACE + +#endif diff --git a/main.cpp b/main.cpp index 201c796..f8efb19 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,24 @@ -#include "declarativewidgetdocument.h" +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativewidgetsdocument.h" #include #include @@ -29,7 +49,7 @@ int main(int argc, char **argv) QFileSystemModel model; model.setRootPath("/"); - DeclarativeWidgetDocument document(documentUrl); + DeclarativeWidgetsDocument document(documentUrl); QObject::connect(document.engine(), SIGNAL(quit()), &app, SLOT(quit())); document.setContextProperty("_timer", &timer); diff --git a/messagebox.qml b/messagebox.qml deleted file mode 100644 index f2a6f7f..0000000 --- a/messagebox.qml +++ /dev/null @@ -1,62 +0,0 @@ -import QtGui 1.0 - -Widget { - VBoxLayout { - PushButton { - text: qsTr("MessageBox instance") - - onClicked: messageBox.show() - } - - PushButton { - id: aboutButton - text: qsTr("MessageBox::about") - onClicked: MessageBox.about(aboutButton, qsTr("About DeclarativeWidgets"), qsTr("This is a text about declarative widgets.")) - } - - PushButton { - text: qsTr("MessageBox::aboutQt") - onClicked: MessageBox.aboutQt(0, qsTr("About Qt")) - } - - PushButton { - text: qsTr("MessageBox::critical") - onClicked: { - var button = MessageBox.critical(0, qsTr("Error"), qsTr("An error occurred!")) - console.log("MessageBox.critical returned " + button) - } - } - - PushButton { - text: qsTr("MessageBox::information") - onClicked: { - var button = MessageBox.information(0, qsTr("Information"), qsTr("The taxi is here")) - console.log("MessageBox.information returned " + button) - } - } - - PushButton { - text: qsTr("MessageBox::question") - onClicked: { - var button = MessageBox.question(0, qsTr("Network error"), qsTr("Can not connect to host"), MessageBox.Retry | MessageBox.Abort | MessageBox.Ignore, MessageBox.Abort) - console.log("MessageBox.question returned " + button) - } - } - - PushButton { - text: qsTr("MessageBox::warning") - onClicked: { - var button = MessageBox.warning(0, qsTr("Warning"), qsTr("Do you really want to quit?"), MessageBox.Ok | MessageBox.Cancel, MessageBox.Ok) - console.log("MessageBox.warning returned " + button) - } - } - } - - MessageBox { - id: messageBox - - windowTitle: qsTr("MessageBox instance") - text: qsTr("text") - detailedText: qsTr("detailedText") - } -} diff --git a/objectadaptors.cpp b/objectadaptors.cpp deleted file mode 100644 index 7bd564b..0000000 --- a/objectadaptors.cpp +++ /dev/null @@ -1,240 +0,0 @@ -#include "objectadaptors_p.h" - -#include "declarativeobjects_p.h" - -#include - -// ActionItem -ActionItem::ActionItem(QObject *parent) - : QObject(parent) - , m_placeholderAction(new QAction(this)) - , m_qAction(m_placeholderAction) -{ -} - -QAction* ActionItem::action() -{ - return m_qAction; -} - -void ActionItem::setAction(const QVariant &action) -{ - if (m_action == action) - return; - - m_action = action; - - QObject *object = m_action.value(); - - // Is the passed action a QAction ... - QAction *newAction = qobject_cast(object); - - // ... or a DeclarativeAction - DeclarativeAction *declarativeAction = dynamic_cast(object); - if (declarativeAction) { - newAction = qobject_cast(declarativeAction->object()); - } - - // Check if the placeholder must be replaced with the actual action - if (m_qAction == m_placeholderAction) { - const QList widgets = m_placeholderAction->associatedWidgets(); - if (!widgets.isEmpty()) { - Q_ASSERT(widgets.count() == 1); // The placeholder action can only be plugged into one widget - - // Replace the placeholder action with the new one - widgets.first()->insertAction(m_placeholderAction, newAction); - widgets.first()->removeAction(m_placeholderAction); - - m_qAction = newAction; - } - } - - emit actionChanged(); -} - -QVariant ActionItem::qmlAction() const -{ - return m_action; -} - -// ButtonGroup -ButtonGroup::ButtonGroup(QObject *parent) - : QButtonGroup(parent) -{ -} - -void ButtonGroup::setButtons(const QVariantList &buttons) -{ - if (m_buttons == buttons) - return; - - // First remove the old buttons ... - foreach (const QVariant &variant, m_buttons) { - QObject *object = variant.value(); - if (object) { - AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); - if (declarativeObject) { - QAbstractButton *button = qobject_cast(declarativeObject->object()); - if (button) - QButtonGroup::removeButton(button); - } - } - } - - m_buttons = buttons; - - // ... then add the new ones - foreach (const QVariant &variant, m_buttons) { - QObject *object = variant.value(); - if (object) { - AbstractDeclarativeObject *declarativeObject = dynamic_cast(object); - if (declarativeObject) { - QAbstractButton *button = qobject_cast(declarativeObject->object()); - if (button) - QButtonGroup::addButton(button); - } - } - } - - emit buttonsChanged(); -} - -QVariantList ButtonGroup::buttons() const -{ - return m_buttons; -} - -// ColumnView -ColumnView::ColumnView(QWidget *parent) - : QColumnView(parent) -{ -} - -void ColumnView::setModel(QAbstractItemModel *model) -{ - if (this->model() == model) - return; - - QColumnView::setModel(model); - - emit modelChanged(model); - emit selectionModelChanged(selectionModel()); -} - -void ColumnView::setSelectionModel(QItemSelectionModel *selectionModel) -{ - if (this->selectionModel() == selectionModel) - return; - - QColumnView::setSelectionModel(selectionModel); - - emit selectionModelChanged(selectionModel); -} - -// FileDialog -FileDialog::FileDialog(QWidget *parent) - : QFileDialog(parent) -{ -} - -// InputDialog -InputDialog::InputDialog(QWidget *parent) - : QInputDialog(parent) -{ - connect(this, SIGNAL(textValueChanged(QString)), this, SIGNAL(customTextValueChanged())); - connect(this, SIGNAL(intValueChanged(int)), this, SIGNAL(customIntValueChanged())); - connect(this, SIGNAL(doubleValueChanged(double)), this, SIGNAL(customDoubleValueChanged())); -} - -// ListView -ListView::ListView(QWidget *parent) - : QListView(parent) -{ -} - -void ListView::setModel(QAbstractItemModel *model) -{ - if (this->model() == model) - return; - - QListView::setModel(model); - - emit modelChanged(model); - emit selectionModelChanged(selectionModel()); -} - -void ListView::setSelectionModel(QItemSelectionModel *selectionModel) -{ - if (this->selectionModel() == selectionModel) - return; - - QListView::setSelectionModel(selectionModel); - - emit selectionModelChanged(selectionModel); -} - -// TableView -TableView::TableView(QWidget *parent) - : QTableView(parent) -{ -} - -void TableView::setModel(QAbstractItemModel *model) -{ - if (this->model() == model) - return; - - QTableView::setModel(model); - - emit modelChanged(model); - emit selectionModelChanged(selectionModel()); -} - -void TableView::setSelectionModel(QItemSelectionModel *selectionModel) -{ - if (this->selectionModel() == selectionModel) - return; - - QTableView::setSelectionModel(selectionModel); - - emit selectionModelChanged(selectionModel); -} - -// TextEdit -TextEdit::TextEdit(QWidget *parent) - : QTextEdit(parent) -{ - connect(document(), SIGNAL(modificationChanged(bool)), this, SIGNAL(modifiedChanged())); -} - -bool TextEdit::modified() const -{ - return document()->isModified(); -} - -// TreeView -TreeView::TreeView(QWidget *parent) - : QTreeView(parent) -{ -} - -void TreeView::setModel(QAbstractItemModel *model) -{ - if (this->model() == model) - return; - - QTreeView::setModel(model); - - emit modelChanged(model); - emit selectionModelChanged(selectionModel()); -} - -void TreeView::setSelectionModel(QItemSelectionModel *selectionModel) -{ - if (this->selectionModel() == selectionModel) - return; - - QTreeView::setSelectionModel(selectionModel); - - emit selectionModelChanged(selectionModel); -} diff --git a/objectadaptors_p.h b/objectadaptors_p.h deleted file mode 100644 index cc0850a..0000000 --- a/objectadaptors_p.h +++ /dev/null @@ -1,196 +0,0 @@ -#ifndef OBJECTADAPTORS_P_H -#define OBJECTADAPTORS_P_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class ActionItem : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QVariant action READ qmlAction WRITE setAction NOTIFY actionChanged) - - public: - ActionItem(QObject *parent = 0); - - QAction* action(); - - Q_SIGNALS: - void actionChanged(); - - private: - void setAction(const QVariant &action); - QVariant qmlAction() const; - - QVariant m_action; - QAction* m_placeholderAction; - QAction* m_qAction; -}; - -class ButtonGroup : public QButtonGroup -{ - Q_OBJECT - - Q_PROPERTY(QVariantList buttons READ buttons WRITE setButtons NOTIFY buttonsChanged) - - public: - ButtonGroup(QObject *parent = 0); - - Q_SIGNALS: - void buttonsChanged(); - - private: - void setButtons(const QVariantList &buttons); - QVariantList buttons() const; - - QVariantList m_buttons; -}; - -class ColumnView : public QColumnView -{ - Q_OBJECT - - Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) - - public: - ColumnView(QWidget *parent = 0); - - void setModel(QAbstractItemModel *model); - void setSelectionModel(QItemSelectionModel *selectionModel); - - Q_SIGNALS: - void modelChanged(QAbstractItemModel*); - void selectionModelChanged(QItemSelectionModel*); -}; - -class FileDialog : public QFileDialog -{ - Q_OBJECT - - Q_PROPERTY(QStringList selectedFiles READ selectedFiles) - - public: - FileDialog(QWidget *parent = 0); -}; - -class InputDialog : public QInputDialog -{ - Q_OBJECT - - Q_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode) - Q_PROPERTY(QString labelText READ labelText WRITE setLabelText) - Q_PROPERTY(InputDialogOptions options READ options WRITE setOptions) - Q_PROPERTY(QString textValue READ textValue WRITE setTextValue NOTIFY customTextValueChanged) - Q_PROPERTY(int intValue READ intValue WRITE setIntValue NOTIFY customIntValueChanged) - Q_PROPERTY(int doubleValue READ doubleValue WRITE setDoubleValue NOTIFY customDoubleValueChanged) - Q_PROPERTY(QLineEdit::EchoMode textEchoMode READ textEchoMode WRITE setTextEchoMode) - Q_PROPERTY(bool comboBoxEditable READ isComboBoxEditable WRITE setComboBoxEditable) - Q_PROPERTY(QStringList comboBoxItems READ comboBoxItems WRITE setComboBoxItems) - Q_PROPERTY(int intMinimum READ intMinimum WRITE setIntMinimum) - Q_PROPERTY(int intMaximum READ intMaximum WRITE setIntMaximum) - Q_PROPERTY(int intStep READ intStep WRITE setIntStep) - Q_PROPERTY(double doubleMinimum READ doubleMinimum WRITE setDoubleMinimum) - Q_PROPERTY(double doubleMaximum READ doubleMaximum WRITE setDoubleMaximum) - Q_PROPERTY(int doubleDecimals READ doubleDecimals WRITE setDoubleDecimals) - Q_PROPERTY(QString okButtonText READ okButtonText WRITE setOkButtonText) - Q_PROPERTY(QString cancelButtonText READ cancelButtonText WRITE setCancelButtonText) - - Q_ENUMS(InputMode) - Q_ENUMS(InputDialogOption) - - public: - InputDialog(QWidget *parent = 0); - - Q_SIGNALS: - void customTextValueChanged(); - void customIntValueChanged(); - void customDoubleValueChanged(); -}; - -class ListView : public QListView -{ - Q_OBJECT - - Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) - - public: - ListView(QWidget *parent = 0); - - void setModel(QAbstractItemModel *model); - void setSelectionModel(QItemSelectionModel *selectionModel); - - Q_SIGNALS: - void modelChanged(QAbstractItemModel*); - void selectionModelChanged(QItemSelectionModel*); -}; - -class StackedLayout : public QStackedLayout -{ - Q_OBJECT - - Q_PROPERTY(int count READ count) -}; - -class TableView : public QTableView -{ - Q_OBJECT - - Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) - - public: - TableView(QWidget *parent = 0); - - void setModel(QAbstractItemModel *model); - void setSelectionModel(QItemSelectionModel *selectionModel); - - Q_SIGNALS: - void modelChanged(QAbstractItemModel*); - void selectionModelChanged(QItemSelectionModel*); -}; - -class TextEdit : public QTextEdit -{ - Q_OBJECT - - Q_PROPERTY(bool modified READ modified NOTIFY modifiedChanged) - - public: - TextEdit(QWidget *parent = 0); - - Q_SIGNALS: - void modifiedChanged(); - - private: - bool modified() const; -}; - -class TreeView : public QTreeView -{ - Q_OBJECT - - Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged) - - public: - TreeView(QWidget *parent = 0); - - void setModel(QAbstractItemModel *model); - void setSelectionModel(QItemSelectionModel *selectionModel); - - Q_SIGNALS: - void modelChanged(QAbstractItemModel*); - void selectionModelChanged(QItemSelectionModel*); -}; - -#endif diff --git a/qmetaobjectbuilder.cpp b/qmetaobjectbuilder.cpp deleted file mode 100644 index ff4c97c..0000000 --- a/qmetaobjectbuilder.cpp +++ /dev/null @@ -1,2601 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmetaobjectbuilder_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QMetaObjectBuilder - \internal - \brief The QMetaObjectBuilder class supports building QMetaObject objects at runtime. - -*/ - -/*! - \enum QMetaObjectBuilder::AddMember - This enum defines which members of QMetaObject should be copied by QMetaObjectBuilder::addMetaObject() - - \value ClassName Add the class name. - \value SuperClass Add the super class. - \value Methods Add methods that aren't signals or slots. - \value Signals Add signals. - \value Slots Add slots. - \value Constructors Add constructors. - \value Properties Add properties. - \value Enumerators Add enumerators. - \value ClassInfos Add items of class information. - \value RelatedMetaObjects Add related meta objects. - \value StaticMetacall Add the static metacall function. - \value PublicMethods Add public methods (ignored for signals). - \value ProtectedMethods Add protected methods (ignored for signals). - \value PrivateMethods All private methods (ignored for signals). - \value AllMembers Add all members. - \value AllPrimaryMembers Add everything except the class name, super class, and static metacall function. -*/ - -// copied from moc's generator.cpp -uint qvariant_nameToType(const char* name) -{ - if (!name) - return 0; - - if (strcmp(name, "QVariant") == 0) - return 0xffffffff; - if (strcmp(name, "QCString") == 0) - return QMetaType::QByteArray; - if (strcmp(name, "Q_LLONG") == 0) - return QMetaType::LongLong; - if (strcmp(name, "Q_ULLONG") == 0) - return QMetaType::ULongLong; - if (strcmp(name, "QIconSet") == 0) - return QMetaType::QIcon; - - uint tp = QMetaType::type(name); - return tp < QMetaType::User ? tp : 0; -} - -/* - Returns true if the type is a QVariant types. -*/ -bool isVariantType(const char* type) -{ - return qvariant_nameToType(type) != 0; -} - -// copied from qmetaobject_p.h -// do not touch without touching the moc as well -enum PropertyFlags { - Invalid = 0x00000000, - Readable = 0x00000001, - Writable = 0x00000002, - Resettable = 0x00000004, - EnumOrFlag = 0x00000008, - StdCppSet = 0x00000100, -// Override = 0x00000200, - Constant = 0x00000400, - Final = 0x00000800, - Designable = 0x00001000, - ResolveDesignable = 0x00002000, - Scriptable = 0x00004000, - ResolveScriptable = 0x00008000, - Stored = 0x00010000, - ResolveStored = 0x00020000, - Editable = 0x00040000, - ResolveEditable = 0x00080000, - User = 0x00100000, - ResolveUser = 0x00200000, - Notify = 0x00400000, - Revisioned = 0x00800000 -}; - -enum MethodFlags { - AccessPrivate = 0x00, - AccessProtected = 0x01, - AccessPublic = 0x02, - AccessMask = 0x03, //mask - - MethodMethod = 0x00, - MethodSignal = 0x04, - MethodSlot = 0x08, - MethodConstructor = 0x0c, - MethodTypeMask = 0x0c, - - MethodCompatibility = 0x10, - MethodCloned = 0x20, - MethodScriptable = 0x40, - MethodRevisioned = 0x80 -}; - -struct QMetaObjectPrivate -{ - int revision; - int className; - int classInfoCount, classInfoData; - int methodCount, methodData; - int propertyCount, propertyData; - int enumeratorCount, enumeratorData; - int constructorCount, constructorData; - int flags; -}; - -static inline const QMetaObjectPrivate *priv(const uint* data) -{ return reinterpret_cast(data); } -// end of copied lines from qmetaobject.cpp - -class QMetaMethodBuilderPrivate -{ -public: - QMetaMethodBuilderPrivate - (QMetaMethod::MethodType _methodType, - const QByteArray& _signature, - const QByteArray& _returnType = QByteArray(), - QMetaMethod::Access _access = QMetaMethod::Public) - : signature(QMetaObject::normalizedSignature(_signature.constData())), - returnType(QMetaObject::normalizedType(_returnType)), - attributes(((int)_access) | (((int)_methodType) << 2)) - { - } - - QByteArray signature; - QByteArray returnType; - QList parameterNames; - QByteArray tag; - int attributes; - - QMetaMethod::MethodType methodType() const - { - return (QMetaMethod::MethodType)((attributes & MethodTypeMask) >> 2); - } - - QMetaMethod::Access access() const - { - return (QMetaMethod::Access)(attributes & AccessMask); - } - - void setAccess(QMetaMethod::Access value) - { - attributes = ((attributes & ~AccessMask) | (int)value); - } -}; - -class QMetaPropertyBuilderPrivate -{ -public: - QMetaPropertyBuilderPrivate - (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1) - : name(_name), - type(QMetaObject::normalizedType(_type.constData())), - flags(Readable | Writable | Scriptable), notifySignal(-1) - { - if (notifierIdx >= 0) { - flags |= Notify; - notifySignal = notifierIdx; - } - } - - QByteArray name; - QByteArray type; - int flags; - int notifySignal; - - bool flag(int f) const - { - return ((flags & f) != 0); - } - - void setFlag(int f, bool value) - { - if (value) - flags |= f; - else - flags &= ~f; - } -}; - -class QMetaEnumBuilderPrivate -{ -public: - QMetaEnumBuilderPrivate(const QByteArray& _name) - : name(_name), isFlag(false) - { - } - - QByteArray name; - bool isFlag; - QList keys; - QList values; -}; - -class QMetaObjectBuilderPrivate -{ -public: - QMetaObjectBuilderPrivate() - : flags(0) - { - superClass = &QObject::staticMetaObject; - staticMetacallFunction = 0; - } - - QByteArray className; - const QMetaObject *superClass; - QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction; - QList methods; - QList constructors; - QList properties; - QList classInfoNames; - QList classInfoValues; - QList enumerators; -#ifdef Q_NO_DATA_RELOCATION - QList relatedMetaObjects; -#else - QList relatedMetaObjects; -#endif - int flags; -}; - -/*! - Constructs a new QMetaObjectBuilder. -*/ -QMetaObjectBuilder::QMetaObjectBuilder() -{ - d = new QMetaObjectBuilderPrivate(); -} - -/*! - Constructs a new QMetaObjectBuilder which is a copy of the - meta object information in \a prototype. Note: the super class - contents for \a prototype are not copied, only the immediate - class that is defined by \a prototype. - - The \a members parameter indicates which members of \a prototype - should be added. The default is AllMembers. - - \sa addMetaObject() -*/ -QMetaObjectBuilder::QMetaObjectBuilder - (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members) -{ - d = new QMetaObjectBuilderPrivate(); - addMetaObject(prototype, members); -} - -/*! - Destroys this meta object builder. -*/ -QMetaObjectBuilder::~QMetaObjectBuilder() -{ - delete d; -} - -/*! - Returns the name of the class being constructed by this - meta object builder. The default value is an empty QByteArray. - - \sa setClassName(), superClass() -*/ -QByteArray QMetaObjectBuilder::className() const -{ - return d->className; -} - -/*! - Sets the \a name of the class being constructed by this - meta object builder. - - \sa className(), setSuperClass() -*/ -void QMetaObjectBuilder::setClassName(const QByteArray& name) -{ - d->className = name; -} - -/*! - Returns the superclass meta object of the class being constructed - by this meta object builder. The default value is the meta object - for QObject. - - \sa setSuperClass(), className() -*/ -const QMetaObject *QMetaObjectBuilder::superClass() const -{ - return d->superClass; -} - -/*! - Sets the superclass meta object of the class being constructed - by this meta object builder to \a meta. The \a meta parameter - must not be null. - - \sa superClass(), setClassName() -*/ -void QMetaObjectBuilder::setSuperClass(const QMetaObject *meta) -{ - Q_ASSERT(meta); - d->superClass = meta; -} - -/*! - Returns the flags of the class being constructed by this meta object - builder. - - \sa setFlags() -*/ -QMetaObjectBuilder::MetaObjectFlags QMetaObjectBuilder::flags() const -{ - return (QMetaObjectBuilder::MetaObjectFlags)d->flags; -} - -/*! - Sets the \a flags of the class being constructed by this meta object - builder. - - \sa flags() -*/ -void QMetaObjectBuilder::setFlags(MetaObjectFlags flags) -{ - d->flags = flags; -} - -/*! - Returns the number of methods in this class, excluding the number - of methods in the base class. These include signals and slots - as well as normal member functions. - - \sa addMethod(), method(), removeMethod(), indexOfMethod() -*/ -int QMetaObjectBuilder::methodCount() const -{ - return d->methods.size(); -} - -/*! - Returns the number of constructors in this class. - - \sa addConstructor(), constructor(), removeConstructor(), indexOfConstructor() -*/ -int QMetaObjectBuilder::constructorCount() const -{ - return d->constructors.size(); -} - -/*! - Returns the number of properties in this class, excluding the number - of properties in the base class. - - \sa addProperty(), property(), removeProperty(), indexOfProperty() -*/ -int QMetaObjectBuilder::propertyCount() const -{ - return d->properties.size(); -} - -/*! - Returns the number of enumerators in this class, excluding the - number of enumerators in the base class. - - \sa addEnumerator(), enumerator(), removeEnumerator() - \sa indexOfEnumerator() -*/ -int QMetaObjectBuilder::enumeratorCount() const -{ - return d->enumerators.size(); -} - -/*! - Returns the number of items of class information in this class, - exclusing the number of items of class information in the base class. - - \sa addClassInfo(), classInfoName(), classInfoValue(), removeClassInfo() - \sa indexOfClassInfo() -*/ -int QMetaObjectBuilder::classInfoCount() const -{ - return d->classInfoNames.size(); -} - -/*! - Returns the number of related meta objects that are associated - with this class. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa addRelatedMetaObject(), relatedMetaObject() - \sa removeRelatedMetaObject() -*/ -int QMetaObjectBuilder::relatedMetaObjectCount() const -{ - return d->relatedMetaObjects.size(); -} - -/*! - Adds a new public method to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the method. The \a signature will be normalized before it is - added to the class. - - \sa method(), methodCount(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QByteArray& signature) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Method, signature)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new public method to this class with the specified - \a signature and \a returnType. Returns an object that can be - used to adjust the other attributes of the method. The \a signature - and \a returnType will be normalized before they are added to - the class. If \a returnType is empty, then it indicates that - the method has \c{void} as its return type. - - \sa method(), methodCount(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addMethod - (const QByteArray& signature, const QByteArray& returnType) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate - (QMetaMethod::Method, signature, returnType)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new public method to this class that has the same information as - \a prototype. This is used to clone the methods of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the method. - - This function will detect if \a prototype is an ordinary method, - signal, slot, or constructor and act accordingly. - - \sa method(), methodCount(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addMethod(const QMetaMethod& prototype) -{ - QMetaMethodBuilder method; - if (prototype.methodType() == QMetaMethod::Method) - method = addMethod(prototype.signature()); - else if (prototype.methodType() == QMetaMethod::Signal) - method = addSignal(prototype.signature()); - else if (prototype.methodType() == QMetaMethod::Slot) - method = addSlot(prototype.signature()); - else if (prototype.methodType() == QMetaMethod::Constructor) - method = addConstructor(prototype.signature()); - method.setReturnType(prototype.typeName()); - method.setParameterNames(prototype.parameterNames()); - method.setTag(prototype.tag()); - method.setAccess(prototype.access()); - method.setAttributes(prototype.attributes()); - return method; -} - -/*! - Adds a new public slot to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the slot. The \a signature will be normalized before it is - added to the class. - - \sa addMethod(), addSignal(), indexOfSlot() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addSlot(const QByteArray& signature) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate(QMetaMethod::Slot, signature)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new signal to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the signal. The \a signature will be normalized before it is - added to the class. - - \sa addMethod(), addSlot(), indexOfSignal() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addSignal(const QByteArray& signature) -{ - int index = d->methods.size(); - d->methods.append(QMetaMethodBuilderPrivate - (QMetaMethod::Signal, signature, QByteArray(), QMetaMethod::Protected)); - return QMetaMethodBuilder(this, index); -} - -/*! - Adds a new constructor to this class with the specified \a signature. - Returns an object that can be used to adjust the other attributes - of the constructor. The \a signature will be normalized before it is - added to the class. - - \sa constructor(), constructorCount(), removeConstructor() - \sa indexOfConstructor() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QByteArray& signature) -{ - int index = d->constructors.size(); - d->constructors.append(QMetaMethodBuilderPrivate(QMetaMethod::Constructor, signature)); - return QMetaMethodBuilder(this, -(index + 1)); -} - -/*! - Adds a new constructor to this class that has the same information as - \a prototype. This is used to clone the constructors of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the constructor. - - This function requires that \a prototype be a constructor. - - \sa constructor(), constructorCount(), removeConstructor() - \sa indexOfConstructor() -*/ -QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod& prototype) -{ - Q_ASSERT(prototype.methodType() == QMetaMethod::Constructor); - QMetaMethodBuilder ctor = addConstructor(prototype.signature()); - ctor.setReturnType(prototype.typeName()); - ctor.setParameterNames(prototype.parameterNames()); - ctor.setTag(prototype.tag()); - ctor.setAccess(prototype.access()); - ctor.setAttributes(prototype.attributes()); - return ctor; -} - -/*! - Adds a new readable/writable property to this class with the - specified \a name and \a type. Returns an object that can be used - to adjust the other attributes of the property. The \a type will - be normalized before it is added to the class. \a notifierId will - be registered as the property's \e notify signal. - - \sa property(), propertyCount(), removeProperty(), indexOfProperty() -*/ -QMetaPropertyBuilder QMetaObjectBuilder::addProperty - (const QByteArray& name, const QByteArray& type, int notifierId) -{ - int index = d->properties.size(); - d->properties.append(QMetaPropertyBuilderPrivate(name, type, notifierId)); - return QMetaPropertyBuilder(this, index); -} - -/*! - Adds a new property to this class that has the same information as - \a prototype. This is used to clone the properties of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the property. - - \sa property(), propertyCount(), removeProperty(), indexOfProperty() -*/ -QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& prototype) -{ - QMetaPropertyBuilder property = addProperty(prototype.name(), prototype.typeName()); - property.setReadable(prototype.isReadable()); - property.setWritable(prototype.isWritable()); - property.setResettable(prototype.isResettable()); - property.setDesignable(prototype.isDesignable()); - property.setScriptable(prototype.isScriptable()); - property.setStored(prototype.isStored()); - property.setEditable(prototype.isEditable()); - property.setUser(prototype.isUser()); - property.setStdCppSet(prototype.hasStdCppSet()); - property.setEnumOrFlag(prototype.isEnumType()); - property.setConstant(prototype.isConstant()); - property.setFinal(prototype.isFinal()); - if (prototype.hasNotifySignal()) { - // Find an existing method for the notify signal, or add a new one. - QMetaMethod method = prototype.notifySignal(); - int index = indexOfMethod(method.signature()); - if (index == -1) - index = addMethod(method).index(); - d->properties[property._index].notifySignal = index; - d->properties[property._index].setFlag(Notify, true); - } - return property; -} - -/*! - Adds a new enumerator to this class with the specified - \a name. Returns an object that can be used to adjust - the other attributes of the enumerator. - - \sa enumerator(), enumeratorCount(), removeEnumerator(), - \sa indexOfEnumerator() -*/ -QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QByteArray& name) -{ - int index = d->enumerators.size(); - d->enumerators.append(QMetaEnumBuilderPrivate(name)); - return QMetaEnumBuilder(this, index); -} - -/*! - Adds a new enumerator to this class that has the same information as - \a prototype. This is used to clone the enumerators of an existing - QMetaObject. Returns an object that can be used to adjust the - attributes of the enumerator. - - \sa enumerator(), enumeratorCount(), removeEnumerator(), - \sa indexOfEnumerator() -*/ -QMetaEnumBuilder QMetaObjectBuilder::addEnumerator(const QMetaEnum& prototype) -{ - QMetaEnumBuilder en = addEnumerator(prototype.name()); - en.setIsFlag(prototype.isFlag()); - int count = prototype.keyCount(); - for (int index = 0; index < count; ++index) - en.addKey(prototype.key(index), prototype.value(index)); - return en; -} - -/*! - Adds \a name and \a value as an item of class information to this class. - Returns the index of the new item of class information. - - \sa classInfoCount(), classInfoName(), classInfoValue(), removeClassInfo() - \sa indexOfClassInfo() -*/ -int QMetaObjectBuilder::addClassInfo(const QByteArray& name, const QByteArray& value) -{ - int index = d->classInfoNames.size(); - d->classInfoNames += name; - d->classInfoValues += value; - return index; -} - -/*! - Adds \a meta to this class as a related meta object. Returns - the index of the new related meta object entry. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa relatedMetaObjectCount(), relatedMetaObject() - \sa removeRelatedMetaObject() -*/ -#ifdef Q_NO_DATA_RELOCATION -int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObjectAccessor &meta) -#else -int QMetaObjectBuilder::addRelatedMetaObject(const QMetaObject *meta) -#endif -{ - Q_ASSERT(meta); - int index = d->relatedMetaObjects.size(); - d->relatedMetaObjects.append(meta); - return index; -} - -/*! - Adds the contents of \a prototype to this meta object builder. - This function is useful for cloning the contents of an existing QMetaObject. - - The \a members parameter indicates which members of \a prototype - should be added. The default is AllMembers. -*/ -void QMetaObjectBuilder::addMetaObject - (const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members) -{ - Q_ASSERT(prototype); - int index; - - if ((members & ClassName) != 0) - d->className = prototype->className(); - - if ((members & SuperClass) != 0) - d->superClass = prototype->superClass(); - - if ((members & (Methods | Signals | Slots)) != 0) { - for (index = prototype->methodOffset(); index < prototype->methodCount(); ++index) { - QMetaMethod method = prototype->method(index); - if (method.methodType() != QMetaMethod::Signal) { - if (method.access() == QMetaMethod::Public && (members & PublicMethods) == 0) - continue; - if (method.access() == QMetaMethod::Private && (members & PrivateMethods) == 0) - continue; - if (method.access() == QMetaMethod::Protected && (members & ProtectedMethods) == 0) - continue; - } - if (method.methodType() == QMetaMethod::Method && (members & Methods) != 0) { - addMethod(method); - } else if (method.methodType() == QMetaMethod::Signal && - (members & Signals) != 0) { - addMethod(method); - } else if (method.methodType() == QMetaMethod::Slot && - (members & Slots) != 0) { - addMethod(method); - } - } - } - - if ((members & Constructors) != 0) { - for (index = 0; index < prototype->constructorCount(); ++index) - addConstructor(prototype->constructor(index)); - } - - if ((members & Properties) != 0) { - for (index = prototype->propertyOffset(); index < prototype->propertyCount(); ++index) - addProperty(prototype->property(index)); - } - - if ((members & Enumerators) != 0) { - for (index = prototype->enumeratorOffset(); index < prototype->enumeratorCount(); ++index) - addEnumerator(prototype->enumerator(index)); - } - - if ((members & ClassInfos) != 0) { - for (index = prototype->classInfoOffset(); index < prototype->classInfoCount(); ++index) { - QMetaClassInfo ci = prototype->classInfo(index); - addClassInfo(ci.name(), ci.value()); - } - } - - if ((members & RelatedMetaObjects) != 0) { -#ifdef Q_NO_DATA_RELOCATION - const QMetaObjectAccessor *objects = 0; -#else - const QMetaObject **objects; - if (priv(prototype->d.data)->revision < 2) { - objects = (const QMetaObject **)(prototype->d.extradata); - } else -#endif - { - const QMetaObjectExtraData *extra = (const QMetaObjectExtraData *)(prototype->d.extradata); - if (extra) - objects = extra->objects; - else - objects = 0; - } - if (objects) { - while (*objects != 0) { - addRelatedMetaObject(*objects); - ++objects; - } - } - } - - if ((members & StaticMetacall) != 0) { - if (priv(prototype->d.data)->revision >= 6) { - const QMetaObjectExtraData *extra = - (const QMetaObjectExtraData *)(prototype->d.extradata); - if (extra && extra->static_metacall) - setStaticMetacallFunction(extra->static_metacall); - } - } -} - -/*! - Returns the method at \a index in this class. - - \sa methodCount(), addMethod(), removeMethod(), indexOfMethod() -*/ -QMetaMethodBuilder QMetaObjectBuilder::method(int index) const -{ - if (index >= 0 && index < d->methods.size()) - return QMetaMethodBuilder(this, index); - else - return QMetaMethodBuilder(); -} - -/*! - Returns the constructor at \a index in this class. - - \sa methodCount(), addMethod(), removeMethod(), indexOfConstructor() -*/ -QMetaMethodBuilder QMetaObjectBuilder::constructor(int index) const -{ - if (index >= 0 && index < d->constructors.size()) - return QMetaMethodBuilder(this, -(index + 1)); - else - return QMetaMethodBuilder(); -} - -/*! - Returns the property at \a index in this class. - - \sa methodCount(), addMethod(), removeMethod(), indexOfProperty() -*/ -QMetaPropertyBuilder QMetaObjectBuilder::property(int index) const -{ - if (index >= 0 && index < d->properties.size()) - return QMetaPropertyBuilder(this, index); - else - return QMetaPropertyBuilder(); -} - -/*! - Returns the enumerator at \a index in this class. - - \sa enumeratorCount(), addEnumerator(), removeEnumerator() - \sa indexOfEnumerator() -*/ -QMetaEnumBuilder QMetaObjectBuilder::enumerator(int index) const -{ - if (index >= 0 && index < d->enumerators.size()) - return QMetaEnumBuilder(this, index); - else - return QMetaEnumBuilder(); -} - -/*! - Returns the related meta object at \a index in this class. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa relatedMetaObjectCount(), addRelatedMetaObject() - \sa removeRelatedMetaObject() -*/ -const QMetaObject *QMetaObjectBuilder::relatedMetaObject(int index) const -{ - if (index >= 0 && index < d->relatedMetaObjects.size()) -#ifdef Q_NO_DATA_RELOCATION - return &((*(d->relatedMetaObjects[index]))()); -#else - return d->relatedMetaObjects[index]; -#endif - else - return 0; -} - -/*! - Returns the name of the item of class information at \a index - in this class. - - \sa classInfoCount(), addClassInfo(), classInfoValue(), removeClassInfo() - \sa indexOfClassInfo() -*/ -QByteArray QMetaObjectBuilder::classInfoName(int index) const -{ - if (index >= 0 && index < d->classInfoNames.size()) - return d->classInfoNames[index]; - else - return QByteArray(); -} - -/*! - Returns the value of the item of class information at \a index - in this class. - - \sa classInfoCount(), addClassInfo(), classInfoName(), removeClassInfo() - \sa indexOfClassInfo() -*/ -QByteArray QMetaObjectBuilder::classInfoValue(int index) const -{ - if (index >= 0 && index < d->classInfoValues.size()) - return d->classInfoValues[index]; - else - return QByteArray(); -} - -/*! - Removes the method at \a index from this class. The indices of - all following methods will be adjusted downwards by 1. If the - method is registered as a notify signal on a property, then the - notify signal will be removed from the property. - - \sa methodCount(), addMethod(), method(), indexOfMethod() -*/ -void QMetaObjectBuilder::removeMethod(int index) -{ - if (index >= 0 && index < d->methods.size()) { - d->methods.removeAt(index); - for (int prop = 0; prop < d->properties.size(); ++prop) { - // Adjust the indices of property notify signal references. - if (d->properties[prop].notifySignal == index) { - d->properties[prop].notifySignal = -1; - d->properties[prop].setFlag(Notify, false); - } else if (d->properties[prop].notifySignal > index) - (d->properties[prop].notifySignal)--; - } - } -} - -/*! - Removes the constructor at \a index from this class. The indices of - all following constructors will be adjusted downwards by 1. - - \sa constructorCount(), addConstructor(), constructor() - \sa indexOfConstructor() -*/ -void QMetaObjectBuilder::removeConstructor(int index) -{ - if (index >= 0 && index < d->constructors.size()) - d->constructors.removeAt(index); -} - -/*! - Removes the property at \a index from this class. The indices of - all following properties will be adjusted downwards by 1. - - \sa propertyCount(), addProperty(), property(), indexOfProperty() -*/ -void QMetaObjectBuilder::removeProperty(int index) -{ - if (index >= 0 && index < d->properties.size()) - d->properties.removeAt(index); -} - -/*! - Removes the enumerator at \a index from this class. The indices of - all following enumerators will be adjusted downwards by 1. - - \sa enumertorCount(), addEnumerator(), enumerator() - \sa indexOfEnumerator() -*/ -void QMetaObjectBuilder::removeEnumerator(int index) -{ - if (index >= 0 && index < d->enumerators.size()) - d->enumerators.removeAt(index); -} - -/*! - Removes the item of class information at \a index from this class. - The indices of all following items will be adjusted downwards by 1. - - \sa classInfoCount(), addClassInfo(), classInfoName(), classInfoValue() - \sa indexOfClassInfo() -*/ -void QMetaObjectBuilder::removeClassInfo(int index) -{ - if (index >= 0 && index < d->classInfoNames.size()) { - d->classInfoNames.removeAt(index); - d->classInfoValues.removeAt(index); - } -} - -/*! - Removes the related meta object at \a index from this class. - The indices of all following related meta objects will be adjusted - downwards by 1. - - Related meta objects are used when resolving the enumerated type - associated with a property, where the enumerated type is in a - different class from the property. - - \sa relatedMetaObjectCount(), addRelatedMetaObject() - \sa relatedMetaObject() -*/ -void QMetaObjectBuilder::removeRelatedMetaObject(int index) -{ - if (index >= 0 && index < d->relatedMetaObjects.size()) - d->relatedMetaObjects.removeAt(index); -} - -/*! - Finds a method with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa method(), methodCount(), addMethod(), removeMethod() -*/ -int QMetaObjectBuilder::indexOfMethod(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { - if (sig == d->methods[index].signature) - return index; - } - return -1; -} - -/*! - Finds a signal with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa indexOfMethod(), indexOfSlot() -*/ -int QMetaObjectBuilder::indexOfSignal(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { - if (sig == d->methods[index].signature && - d->methods[index].methodType() == QMetaMethod::Signal) - return index; - } - return -1; -} - -/*! - Finds a slot with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa indexOfMethod(), indexOfSignal() -*/ -int QMetaObjectBuilder::indexOfSlot(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->methods.size(); ++index) { - if (sig == d->methods[index].signature && - d->methods[index].methodType() == QMetaMethod::Slot) - return index; - } - return -1; -} - -/*! - Finds a constructor with the specified \a signature and returns its index; - otherwise returns -1. The \a signature will be normalized by this method. - - \sa constructor(), constructorCount(), addConstructor(), removeConstructor() -*/ -int QMetaObjectBuilder::indexOfConstructor(const QByteArray& signature) -{ - QByteArray sig = QMetaObject::normalizedSignature(signature); - for (int index = 0; index < d->constructors.size(); ++index) { - if (sig == d->constructors[index].signature) - return index; - } - return -1; -} - -/*! - Finds a property with the specified \a name and returns its index; - otherwise returns -1. - - \sa property(), propertyCount(), addProperty(), removeProperty() -*/ -int QMetaObjectBuilder::indexOfProperty(const QByteArray& name) -{ - for (int index = 0; index < d->properties.size(); ++index) { - if (name == d->properties[index].name) - return index; - } - return -1; -} - -/*! - Finds an enumerator with the specified \a name and returns its index; - otherwise returns -1. - - \sa enumertor(), enumeratorCount(), addEnumerator(), removeEnumerator() -*/ -int QMetaObjectBuilder::indexOfEnumerator(const QByteArray& name) -{ - for (int index = 0; index < d->enumerators.size(); ++index) { - if (name == d->enumerators[index].name) - return index; - } - return -1; -} - -/*! - Finds an item of class information with the specified \a name and - returns its index; otherwise returns -1. - - \sa classInfoName(), classInfoValue(), classInfoCount(), addClassInfo() - \sa removeClassInfo() -*/ -int QMetaObjectBuilder::indexOfClassInfo(const QByteArray& name) -{ - for (int index = 0; index < d->classInfoNames.size(); ++index) { - if (name == d->classInfoNames[index]) - return index; - } - return -1; -} - -// Align on a specific type boundary. -#define ALIGN(size,type) \ - (size) = ((size) + sizeof(type) - 1) & ~(sizeof(type) - 1) - -// Build a string into a QMetaObject representation. Returns the -// position in the string table where the string was placed. -static int buildString - (char *buf, char *str, int *offset, const QByteArray& value, int empty) -{ - if (value.size() == 0 && empty >= 0) - return empty; - if (buf) { - memcpy(str + *offset, value.constData(), value.size()); - str[*offset + value.size()] = '\0'; - } - int posn = *offset; - *offset += value.size() + 1; - return posn; -} - -// Build the parameter array string for a method. -static QByteArray buildParameterNames - (const QByteArray& signature, const QList& parameterNames) -{ - // If the parameter name list is specified, then concatenate them. - if (!parameterNames.isEmpty()) { - QByteArray names; - bool first = true; - foreach (const QByteArray &name, parameterNames) { - if (first) - first = false; - else - names += (char)','; - names += name; - } - return names; - } - - // Count commas in the signature, excluding those inside template arguments. - int index = signature.indexOf('('); - if (index < 0) - return QByteArray(); - ++index; - if (index >= signature.size()) - return QByteArray(); - if (signature[index] == ')') - return QByteArray(); - int count = 1; - int brackets = 0; - while (index < signature.size() && signature[index] != ',') { - char ch = signature[index++]; - if (ch == '<') - ++brackets; - else if (ch == '>') - --brackets; - else if (ch == ',' && brackets <= 0) - ++count; - } - return QByteArray(count - 1, ','); -} - -// Build a QMetaObject in "buf" based on the information in "d". -// If "buf" is null, then return the number of bytes needed to -// build the QMetaObject. Returns -1 if the metaobject if -// relocatable is set, but the metaobject contains extradata. -static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, - bool relocatable) -{ - int size = 0; - int dataIndex; - int enumIndex; - int index; - bool hasNotifySignals = false; - - if (relocatable && - (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction)) - return -1; - - // Create the main QMetaObject structure at the start of the buffer. - QMetaObject *meta = reinterpret_cast(buf); - size += sizeof(QMetaObject); - ALIGN(size, int); - if (buf) { - if (!relocatable) meta->d.superdata = d->superClass; - meta->d.extradata = 0; - } - - // Populate the QMetaObjectPrivate structure. - QMetaObjectPrivate *pmeta - = reinterpret_cast(buf + size); - int pmetaSize = size; - dataIndex = 13; // Number of fields in the QMetaObjectPrivate. - for (index = 0; index < d->properties.size(); ++index) { - if (d->properties[index].notifySignal != -1) { - hasNotifySignals = true; - break; - } - } - if (buf) { - pmeta->revision = 3; - pmeta->flags = d->flags; - pmeta->className = 0; // Class name is always the first string. - - pmeta->classInfoCount = d->classInfoNames.size(); - pmeta->classInfoData = dataIndex; - dataIndex += 2 * d->classInfoNames.size(); - - pmeta->methodCount = d->methods.size(); - pmeta->methodData = dataIndex; - dataIndex += 5 * d->methods.size(); - - pmeta->propertyCount = d->properties.size(); - pmeta->propertyData = dataIndex; - dataIndex += 3 * d->properties.size(); - if (hasNotifySignals) - dataIndex += d->properties.size(); - - pmeta->enumeratorCount = d->enumerators.size(); - pmeta->enumeratorData = dataIndex; - dataIndex += 4 * d->enumerators.size(); - - pmeta->constructorCount = d->constructors.size(); - pmeta->constructorData = dataIndex; - dataIndex += 5 * d->constructors.size(); - } else { - dataIndex += 2 * d->classInfoNames.size(); - dataIndex += 5 * d->methods.size(); - dataIndex += 3 * d->properties.size(); - if (hasNotifySignals) - dataIndex += d->properties.size(); - dataIndex += 4 * d->enumerators.size(); - dataIndex += 5 * d->constructors.size(); - } - - // Allocate space for the enumerator key names and values. - enumIndex = dataIndex; - for (index = 0; index < d->enumerators.size(); ++index) { - QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - dataIndex += 2 * enumerator->keys.size(); - } - - // Zero terminator at the end of the data offset table. - ++dataIndex; - - // Find the start of the data and string tables. - int *data = reinterpret_cast(pmeta); - size += dataIndex * sizeof(int); - char *str = reinterpret_cast(buf + size); - if (buf) { - if (relocatable) { - meta->d.stringdata = reinterpret_cast((quintptr)size); - meta->d.data = reinterpret_cast((quintptr)pmetaSize); - } else { - meta->d.stringdata = str; - meta->d.data = reinterpret_cast(data); - } - } - - // Reset the current data position to just past the QMetaObjectPrivate. - dataIndex = 13; - - // Add the class name to the string table. - int offset = 0; - buildString(buf, str, &offset, d->className, -1); - - // Add a common empty string, which is used to indicate "void" - // method returns, empty tag strings, etc. - int empty = buildString(buf, str, &offset, QByteArray(), -1); - - // Output the class infos, - for (index = 0; index < d->classInfoNames.size(); ++index) { - int name = buildString(buf, str, &offset, d->classInfoNames[index], empty); - int value = buildString(buf, str, &offset, d->classInfoValues[index], empty); - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = value; - } - dataIndex += 2; - } - - // Output the methods in the class. - for (index = 0; index < d->methods.size(); ++index) { - QMetaMethodBuilderPrivate *method = &(d->methods[index]); - int sig = buildString(buf, str, &offset, method->signature, empty); - int params; - QByteArray names = buildParameterNames - (method->signature, method->parameterNames); - params = buildString(buf, str, &offset, names, empty); - int ret = buildString(buf, str, &offset, method->returnType, empty); - int tag = buildString(buf, str, &offset, method->tag, empty); - int attrs = method->attributes; - if (buf) { - data[dataIndex] = sig; - data[dataIndex + 1] = params; - data[dataIndex + 2] = ret; - data[dataIndex + 3] = tag; - data[dataIndex + 4] = attrs; - } - dataIndex += 5; - } - - // Output the properties in the class. - for (index = 0; index < d->properties.size(); ++index) { - QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); - int name = buildString(buf, str, &offset, prop->name, empty); - int type = buildString(buf, str, &offset, prop->type, empty); - int flags = prop->flags; - - if (!isVariantType(prop->type)) { - flags |= EnumOrFlag; - } else { - flags |= qvariant_nameToType(prop->type) << 24; - } - - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = type; - data[dataIndex + 2] = flags; - } - dataIndex += 3; - } - if (hasNotifySignals) { - for (index = 0; index < d->properties.size(); ++index) { - QMetaPropertyBuilderPrivate *prop = &(d->properties[index]); - if (buf) { - if (prop->notifySignal != -1) - data[dataIndex] = prop->notifySignal; - else - data[dataIndex] = 0; - } - ++dataIndex; - } - } - - // Output the enumerators in the class. - for (index = 0; index < d->enumerators.size(); ++index) { - QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - int name = buildString(buf, str, &offset, enumerator->name, empty); - int isFlag = (int)(enumerator->isFlag); - int count = enumerator->keys.size(); - int enumOffset = enumIndex; - if (buf) { - data[dataIndex] = name; - data[dataIndex + 1] = isFlag; - data[dataIndex + 2] = count; - data[dataIndex + 3] = enumOffset; - } - for (int key = 0; key < count; ++key) { - int keyIndex = buildString(buf, str, &offset, enumerator->keys[key], empty); - if (buf) { - data[enumOffset++] = keyIndex; - data[enumOffset++] = enumerator->values[key]; - } - } - dataIndex += 4; - enumIndex += 2 * count; - } - - // Output the constructors in the class. - for (index = 0; index < d->constructors.size(); ++index) { - QMetaMethodBuilderPrivate *method = &(d->constructors[index]); - int sig = buildString(buf, str, &offset, method->signature, empty); - int params; - QByteArray names = buildParameterNames - (method->signature, method->parameterNames); - params = buildString(buf, str, &offset, names, empty); - int ret = buildString(buf, str, &offset, method->returnType, empty); - int tag = buildString(buf, str, &offset, method->tag, empty); - int attrs = method->attributes; - if (buf) { - data[dataIndex] = sig; - data[dataIndex + 1] = params; - data[dataIndex + 2] = ret; - data[dataIndex + 3] = tag; - data[dataIndex + 4] = attrs; - } - dataIndex += 5; - } - - // One more empty string to act as a terminator. - buildString(buf, str, &offset, QByteArray(), -1); - size += offset; - - // Output the zero terminator in the data array. - if (buf) - data[enumIndex] = 0; - - // Create the extradata block if we need one. - if (d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction) { - ALIGN(size, QMetaObject **); - ALIGN(size, QMetaObjectBuilder::StaticMetacallFunction); - QMetaObjectExtraData *extra = - reinterpret_cast(buf + size); - size += sizeof(QMetaObjectExtraData); - ALIGN(size, QMetaObject *); -#ifdef Q_NO_DATA_RELOCATION - QMetaObjectAccessor *objects = - reinterpret_cast(buf + size); -#else - const QMetaObject **objects = - reinterpret_cast(buf + size); -#endif - if (buf) { - if (d->relatedMetaObjects.size() > 0) { - extra->objects = objects; - for (index = 0; index < d->relatedMetaObjects.size(); ++index) - objects[index] = d->relatedMetaObjects[index]; - objects[index] = 0; - } else { - extra->objects = 0; - } - extra->static_metacall = d->staticMetacallFunction; - meta->d.extradata = reinterpret_cast(extra); - } - if (d->relatedMetaObjects.size() > 0) - size += sizeof(QMetaObject *) * (d->relatedMetaObjects.size() + 1); - } - - // Align the final size and return it. - ALIGN(size, void *); - return size; -} - -/*! - Converts this meta object builder into a concrete QMetaObject. - The return value should be deallocated using qFree() once it - is no longer needed. - - The returned meta object is a snapshot of the state of the - QMetaObjectBuilder. Any further modifications to the QMetaObjectBuilder - will not be reflected in previous meta objects returned by - this method. -*/ -QMetaObject *QMetaObjectBuilder::toMetaObject() const -{ - int size = buildMetaObject(d, 0, false); - char *buf = reinterpret_cast(qMalloc(size)); - memset(buf, 0, size); - buildMetaObject(d, buf, false); - return reinterpret_cast(buf); -} - -/* - \internal - - Converts this meta object builder into relocatable data. This data can - be stored, copied and later passed to fromRelocatableData() to create a - concrete QMetaObject. - - The data is specific to the architecture on which it was created, but is not - specific to the process that created it. Not all meta object builder's can - be converted to data in this way. If \a ok is provided, it will be set to - true if the conversion succeeds, and false otherwise. If a - staticMetacallFunction() or any relatedMetaObject()'s are specified the - conversion to relocatable data will fail. -*/ -QByteArray QMetaObjectBuilder::toRelocatableData(bool *ok) const -{ - int size = buildMetaObject(d, 0, true); - if (size == -1) { - if (ok) *ok = false; - return QByteArray(); - } - - QByteArray data; - data.resize(size); - char *buf = data.data(); - memset(buf, 0, size); - buildMetaObject(d, buf, true); - if (ok) *ok = true; - return data; -} - -/* - \internal - - Sets the \a data returned from toRelocatableData() onto a concrete - QMetaObject instance, \a output. As the meta object's super class is not - saved in the relocatable data, it must be passed as \a superClass. -*/ -void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, - const QMetaObject *superclass, - const QByteArray &data) -{ - if (!output) - return; - - const char *buf = data.constData(); - const QMetaObject *dataMo = reinterpret_cast(buf); - - quintptr stringdataOffset = (quintptr)dataMo->d.stringdata; - quintptr dataOffset = (quintptr)dataMo->d.data; - - output->d.superdata = superclass; - output->d.stringdata = buf + stringdataOffset; - output->d.data = reinterpret_cast(buf + dataOffset); -} - -/*! - \typedef QMetaObjectBuilder::StaticMetacallFunction - - Typedef for static metacall functions. The three parameters are - the call type value, the constructor index, and the - array of parameters. -*/ - -/*! - Returns the static metacall function to use to construct objects - of this class. The default value is null. - - \sa setStaticMetacallFunction() -*/ -QMetaObjectBuilder::StaticMetacallFunction QMetaObjectBuilder::staticMetacallFunction() const -{ - return d->staticMetacallFunction; -} - -/*! - Sets the static metacall function to use to construct objects - of this class to \a value. The default value is null. - - \sa staticMetacallFunction() -*/ -void QMetaObjectBuilder::setStaticMetacallFunction - (QMetaObjectBuilder::StaticMetacallFunction value) -{ - d->staticMetacallFunction = value; -} - -#ifndef QT_NO_DATASTREAM - -/*! - Serializes the contents of the meta object builder onto \a stream. - - \sa deserialize() -*/ -void QMetaObjectBuilder::serialize(QDataStream& stream) const -{ - int index; - - // Write the class and super class names. - stream << d->className; - if (d->superClass) - stream << QByteArray(d->superClass->className()); - else - stream << QByteArray(); - - // Write the counts for each type of class member. - stream << d->classInfoNames.size(); - stream << d->methods.size(); - stream << d->properties.size(); - stream << d->enumerators.size(); - stream << d->constructors.size(); - stream << d->relatedMetaObjects.size(); - - // Write the items of class information. - for (index = 0; index < d->classInfoNames.size(); ++index) { - stream << d->classInfoNames[index]; - stream << d->classInfoValues[index]; - } - - // Write the methods. - for (index = 0; index < d->methods.size(); ++index) { - const QMetaMethodBuilderPrivate *method = &(d->methods[index]); - stream << method->signature; - stream << method->returnType; - stream << method->parameterNames; - stream << method->tag; - stream << method->attributes; - } - - // Write the properties. - for (index = 0; index < d->properties.size(); ++index) { - const QMetaPropertyBuilderPrivate *property = &(d->properties[index]); - stream << property->name; - stream << property->type; - stream << property->flags; - stream << property->notifySignal; - } - - // Write the enumerators. - for (index = 0; index < d->enumerators.size(); ++index) { - const QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - stream << enumerator->name; - stream << enumerator->isFlag; - stream << enumerator->keys; - stream << enumerator->values; - } - - // Write the constructors. - for (index = 0; index < d->constructors.size(); ++index) { - const QMetaMethodBuilderPrivate *method = &(d->constructors[index]); - stream << method->signature; - stream << method->returnType; - stream << method->parameterNames; - stream << method->tag; - stream << method->attributes; - } - - // Write the related meta objects. -#ifdef Q_NO_DATA_RELOCATION - //### What do we do here? -#else - for (index = 0; index < d->relatedMetaObjects.size(); ++index) { - const QMetaObject *meta = d->relatedMetaObjects[index]; - stream << QByteArray(meta->className()); - } -#endif - - // Add an extra empty QByteArray for additional data in future versions. - // This should help maintain backwards compatibility, allowing older - // versions to read newer data. - stream << QByteArray(); -} - -// Resolve a class name using the name reference map. -static const QMetaObject *resolveClassName - (const QMap& references, - const QByteArray& name) -{ - if (name == QByteArray("QObject")) - return &QObject::staticMetaObject; - else - return references.value(name, 0); -} - -/*! - Deserializes a meta object builder from \a stream into - this meta object builder. - - The \a references parameter specifies a mapping from class names - to QMetaObject instances for resolving the super class name and - related meta objects in the object that is deserialized. - The meta object for QObject is implicitly added to \a references - and does not need to be supplied. - - The QDataStream::status() value on \a stream will be set to - QDataStream::ReadCorruptData if the input data is corrupt. - The status will be set to QDataStream::ReadPastEnd if the - input was exhausted before the full meta object was read. - - \sa serialize() -*/ -void QMetaObjectBuilder::deserialize - (QDataStream& stream, - const QMap& references) -{ - QByteArray name; - const QMetaObject *cl; - int index; - - // Clear all members in the builder to their default states. - d->className.clear(); - d->superClass = &QObject::staticMetaObject; - d->classInfoNames.clear(); - d->classInfoValues.clear(); - d->methods.clear(); - d->properties.clear(); - d->enumerators.clear(); - d->constructors.clear(); - d->relatedMetaObjects.clear(); - d->staticMetacallFunction = 0; - - // Read the class and super class names. - stream >> d->className; - stream >> name; - if (name.isEmpty()) { - d->superClass = 0; - } else if ((cl = resolveClassName(references, name)) != 0) { - d->superClass = cl; - } else { - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - - // Read the counts for each type of class member. - int classInfoCount, methodCount, propertyCount; - int enumeratorCount, constructorCount, relatedMetaObjectCount; - stream >> classInfoCount; - stream >> methodCount; - stream >> propertyCount; - stream >> enumeratorCount; - stream >> constructorCount; - stream >> relatedMetaObjectCount; - if (classInfoCount < 0 || methodCount < 0 || - propertyCount < 0 || enumeratorCount < 0 || - constructorCount < 0 || relatedMetaObjectCount < 0) { - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - - // Read the items of class information. - for (index = 0; index < classInfoCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - QByteArray value; - stream >> name; - stream >> value; - addClassInfo(name, value); - } - - // Read the member methods. - for (index = 0; index < methodCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - addMethod(name); - QMetaMethodBuilderPrivate *method = &(d->methods[index]); - stream >> method->returnType; - stream >> method->parameterNames; - stream >> method->tag; - stream >> method->attributes; - if (method->methodType() == QMetaMethod::Constructor) { - // Cannot add a constructor in this set of methods. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - } - - // Read the properties. - for (index = 0; index < propertyCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - QByteArray type; - stream >> name; - stream >> type; - addProperty(name, type); - QMetaPropertyBuilderPrivate *property = &(d->properties[index]); - stream >> property->flags; - stream >> property->notifySignal; - if (property->notifySignal < -1 || - property->notifySignal >= d->methods.size()) { - // Notify signal method index is out of range. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - if (property->notifySignal >= 0 && - d->methods[property->notifySignal].methodType() != QMetaMethod::Signal) { - // Notify signal method index does not refer to a signal. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - } - - // Read the enumerators. - for (index = 0; index < enumeratorCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - addEnumerator(name); - QMetaEnumBuilderPrivate *enumerator = &(d->enumerators[index]); - stream >> enumerator->isFlag; - stream >> enumerator->keys; - stream >> enumerator->values; - if (enumerator->keys.size() != enumerator->values.size()) { - // Mismatch between number of keys and number of values. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - } - - // Read the constructor methods. - for (index = 0; index < constructorCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - addConstructor(name); - QMetaMethodBuilderPrivate *method = &(d->constructors[index]); - stream >> method->returnType; - stream >> method->parameterNames; - stream >> method->tag; - stream >> method->attributes; - if (method->methodType() != QMetaMethod::Constructor) { - // The type must be Constructor. - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - } - - // Read the related meta objects. -#ifdef Q_NO_DATA_RELOCATION - //### What do we do here -#else - for (index = 0; index < relatedMetaObjectCount; ++index) { - if (stream.status() != QDataStream::Ok) - return; - stream >> name; - cl = resolveClassName(references, name); - if (!cl) { - stream.setStatus(QDataStream::ReadCorruptData); - return; - } - addRelatedMetaObject(cl); - } -#endif - - // Read the extra data block, which is reserved for future use. - stream >> name; -} - -#endif // !QT_NO_DATASTREAM - -/*! - \class QMetaMethodBuilder - \internal - \brief The QMetaMethodBuilder class enables modifications to a method definition on a meta object builder. -*/ - -QMetaMethodBuilderPrivate *QMetaMethodBuilder::d_func() const -{ - // Positive indices indicate methods, negative indices indicate constructors. - if (_mobj && _index >= 0 && _index < _mobj->d->methods.size()) - return &(_mobj->d->methods[_index]); - else if (_mobj && -_index >= 1 && -_index <= _mobj->d->constructors.size()) - return &(_mobj->d->constructors[(-_index) - 1]); - else - return 0; -} - -/*! - \fn QMetaMethodBuilder::QMetaMethodBuilder() - \internal -*/ - -/*! - Returns the index of this method within its QMetaObjectBuilder. -*/ -int QMetaMethodBuilder::index() const -{ - if (_index >= 0) - return _index; // Method, signal, or slot - else - return (-_index) - 1; // Constructor -} - -/*! - Returns the type of this method (signal, slot, method, or constructor). -*/ -QMetaMethod::MethodType QMetaMethodBuilder::methodType() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->methodType(); - else - return QMetaMethod::Method; -} - -/*! - Returns the signature of this method. - - \sa parameterNames(), returnType() -*/ -QByteArray QMetaMethodBuilder::signature() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->signature; - else - return QByteArray(); -} - -/*! - Returns the return type for this method; empty if the method's - return type is \c{void}. - - \sa setReturnType(), signature() -*/ -QByteArray QMetaMethodBuilder::returnType() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->returnType; - else - return QByteArray(); -} - -/*! - Sets the return type for this method to \a value. If \a value - is empty, then the method's return type is \c{void}. The \a value - will be normalized before it is added to the method. - - \sa returnType(), signature() -*/ -void QMetaMethodBuilder::setReturnType(const QByteArray& value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->returnType = QMetaObject::normalizedType(value); -} - -/*! - Returns the list of parameter names for this method. - - \sa setParameterNames() -*/ -QList QMetaMethodBuilder::parameterNames() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->parameterNames; - else - return QList(); -} - -/*! - Sets the list of parameter names for this method to \a value. - - \sa parameterNames() -*/ -void QMetaMethodBuilder::setParameterNames(const QList& value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->parameterNames = value; -} - -/*! - Returns the tag associated with this method. - - \sa setTag() -*/ -QByteArray QMetaMethodBuilder::tag() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->tag; - else - return QByteArray(); -} - -/*! - Sets the tag associated with this method to \a value. - - \sa setTag() -*/ -void QMetaMethodBuilder::setTag(const QByteArray& value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->tag = value; -} - -/*! - Returns the access specification of this method (private, protected, - or public). The default value is QMetaMethod::Public for methods, - slots, and constructors. The default value is QMetaMethod::Protected - for signals. - - \sa setAccess() -*/ -QMetaMethod::Access QMetaMethodBuilder::access() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return d->access(); - else - return QMetaMethod::Public; -} - -/*! - Sets the access specification of this method (private, protected, - or public) to \a value. If the method is a signal, this function - will be ignored. - - \sa access() -*/ -void QMetaMethodBuilder::setAccess(QMetaMethod::Access value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d && d->methodType() != QMetaMethod::Signal) - d->setAccess(value); -} - -/*! - Returns the additional attributes for this method. - - \sa setAttributes() -*/ -int QMetaMethodBuilder::attributes() const -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - return (d->attributes >> 4); - else - return 0; -} - -/*! - Sets the additional attributes for this method to \a value. - - \sa attributes() -*/ -void QMetaMethodBuilder::setAttributes(int value) -{ - QMetaMethodBuilderPrivate *d = d_func(); - if (d) - d->attributes = ((d->attributes & 0x0f) | (value << 4)); -} - -/*! - \class QMetaPropertyBuilder - \internal - \brief The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builder. -*/ - -QMetaPropertyBuilderPrivate *QMetaPropertyBuilder::d_func() const -{ - if (_mobj && _index >= 0 && _index < _mobj->d->properties.size()) - return &(_mobj->d->properties[_index]); - else - return 0; -} - -/*! - \fn QMetaPropertyBuilder::QMetaPropertyBuilder() - \internal -*/ - -/*! - \fn int QMetaPropertyBuilder::index() const - - Returns the index of this property within its QMetaObjectBuilder. -*/ - -/*! - Returns the name associated with this property. - - \sa type() -*/ -QByteArray QMetaPropertyBuilder::name() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->name; - else - return QByteArray(); -} - -/*! - Returns the type associated with this property. - - \sa name() -*/ -QByteArray QMetaPropertyBuilder::type() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->type; - else - return QByteArray(); -} - -/*! - Returns true if this property has a notify signal; false otherwise. - - \sa notifySignal(), setNotifySignal(), removeNotifySignal() -*/ -bool QMetaPropertyBuilder::hasNotifySignal() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Notify); - else - return false; -} - -/*! - Returns the notify signal associated with this property. - - \sa hasNotifySignal(), setNotifySignal(), removeNotifySignal() -*/ -QMetaMethodBuilder QMetaPropertyBuilder::notifySignal() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d && d->notifySignal >= 0) - return QMetaMethodBuilder(_mobj, d->notifySignal); - else - return QMetaMethodBuilder(); -} - -/*! - Sets the notify signal associated with this property to \a value. - - \sa hasNotifySignal(), notifySignal(), removeNotifySignal() -*/ -void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) { - if (value._mobj) { - d->notifySignal = value._index; - d->setFlag(Notify, true); - } else { - d->notifySignal = -1; - d->setFlag(Notify, false); - } - } -} - -/*! - Removes the notify signal from this property. - - \sa hasNotifySignal(), notifySignal(), setNotifySignal() -*/ -void QMetaPropertyBuilder::removeNotifySignal() -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) { - d->notifySignal = -1; - d->setFlag(Notify, false); - } -} - -/*! - Returns true if this property is readable; otherwise returns false. - The default value is true. - - \sa setReadable(), isWritable() -*/ -bool QMetaPropertyBuilder::isReadable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Readable); - else - return false; -} - -/*! - Returns true if this property is writable; otherwise returns false. - The default value is true. - - \sa setWritable(), isReadable() -*/ -bool QMetaPropertyBuilder::isWritable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Writable); - else - return false; -} - -/*! - Returns true if this property can be reset to a default value; otherwise - returns false. The default value is false. - - \sa setResettable() -*/ -bool QMetaPropertyBuilder::isResettable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Resettable); - else - return false; -} - -/*! - Returns true if this property is designable; otherwise returns false. - This default value is false. - - \sa setDesignable(), isScriptable(), isStored() -*/ -bool QMetaPropertyBuilder::isDesignable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Designable); - else - return false; -} - -/*! - Returns true if the property is scriptable; otherwise returns false. - This default value is true. - - \sa setScriptable(), isDesignable(), isStored() -*/ -bool QMetaPropertyBuilder::isScriptable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Scriptable); - else - return false; -} - -/*! - Returns true if the property is stored; otherwise returns false. - This default value is false. - - \sa setStored(), isDesignable(), isScriptable() -*/ -bool QMetaPropertyBuilder::isStored() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Stored); - else - return false; -} - -/*! - Returns true if the property is editable; otherwise returns false. - This default value is false. - - \sa setEditable(), isDesignable(), isScriptable(), isStored() -*/ -bool QMetaPropertyBuilder::isEditable() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Editable); - else - return false; -} - -/*! - Returns true if this property is designated as the \c USER - property, i.e., the one that the user can edit or that is - significant in some other way. Otherwise it returns - false. This default value is false. - - \sa setUser(), isDesignable(), isScriptable() -*/ -bool QMetaPropertyBuilder::isUser() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(User); - else - return false; -} - -/*! - Returns true if the property has a C++ setter function that - follows Qt's standard "name" / "setName" pattern. Designer and uic - query hasStdCppSet() in order to avoid expensive - QObject::setProperty() calls. All properties in Qt [should] follow - this pattern. The default value is false. - - \sa setStdCppSet() -*/ -bool QMetaPropertyBuilder::hasStdCppSet() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(StdCppSet); - else - return false; -} - -/*! - Returns true if the property is an enumerator or flag type; - otherwise returns false. This default value is false. - - \sa setEnumOrFlag() -*/ -bool QMetaPropertyBuilder::isEnumOrFlag() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(EnumOrFlag); - else - return false; -} - -/*! - Returns true if the property is constant; otherwise returns false. - The default value is false. -*/ -bool QMetaPropertyBuilder::isConstant() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Constant); - else - return false; -} - -/*! - Returns true if the property is final; otherwise returns false. - The default value is false. -*/ -bool QMetaPropertyBuilder::isFinal() const -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - return d->flag(Final); - else - return false; -} - -/*! - Sets this property to readable if \a value is true. - - \sa isReadable(), setWritable() -*/ -void QMetaPropertyBuilder::setReadable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Readable, value); -} - -/*! - Sets this property to writable if \a value is true. - - \sa isWritable(), setReadable() -*/ -void QMetaPropertyBuilder::setWritable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Writable, value); -} - -/*! - Sets this property to resettable if \a value is true. - - \sa isResettable() -*/ -void QMetaPropertyBuilder::setResettable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Resettable, value); -} - -/*! - Sets this property to designable if \a value is true. - - \sa isDesignable(), setScriptable(), setStored() -*/ -void QMetaPropertyBuilder::setDesignable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Designable, value); -} - -/*! - Sets this property to scriptable if \a value is true. - - \sa isScriptable(), setDesignable(), setStored() -*/ -void QMetaPropertyBuilder::setScriptable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Scriptable, value); -} - -/*! - Sets this property to storable if \a value is true. - - \sa isStored(), setDesignable(), setScriptable() -*/ -void QMetaPropertyBuilder::setStored(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Stored, value); -} - -/*! - Sets this property to editable if \a value is true. - - \sa isEditable(), setDesignable(), setScriptable(), setStored() -*/ -void QMetaPropertyBuilder::setEditable(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Editable, value); -} - -/*! - Sets the \c USER flag on this property to \a value. - - \sa isUser(), setDesignable(), setScriptable() -*/ -void QMetaPropertyBuilder::setUser(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(User, value); -} - -/*! - Sets the C++ setter flag on this property to \a value, which is - true if the property has a C++ setter function that follows Qt's - standard "name" / "setName" pattern. - - \sa hasStdCppSet() -*/ -void QMetaPropertyBuilder::setStdCppSet(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(StdCppSet, value); -} - -/*! - Sets this property to be of an enumerator or flag type if - \a value is true. - - \sa isEnumOrFlag() -*/ -void QMetaPropertyBuilder::setEnumOrFlag(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(EnumOrFlag, value); -} - -/*! - Sets the \c CONSTANT flag on this property to \a value. - - \sa isConstant() -*/ -void QMetaPropertyBuilder::setConstant(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Constant, value); -} - -/*! - Sets the \c FINAL flag on this property to \a value. - - \sa isFinal() -*/ -void QMetaPropertyBuilder::setFinal(bool value) -{ - QMetaPropertyBuilderPrivate *d = d_func(); - if (d) - d->setFlag(Final, value); -} - - -/*! - \class QMetaEnumBuilder - \internal - \brief The QMetaEnumBuilder class enables modifications to an enumerator definition on a meta object builder. -*/ - -QMetaEnumBuilderPrivate *QMetaEnumBuilder::d_func() const -{ - if (_mobj && _index >= 0 && _index < _mobj->d->enumerators.size()) - return &(_mobj->d->enumerators[_index]); - else - return 0; -} - -/*! - \fn QMetaEnumBuilder::QMetaEnumBuilder() - \internal -*/ - -/*! - \fn int QMetaEnumBuilder::index() const - - Returns the index of this enumerator within its QMetaObjectBuilder. -*/ - -/*! - Returns the name of the enumerator (without the scope). -*/ -QByteArray QMetaEnumBuilder::name() const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - return d->name; - else - return QByteArray(); -} - -/*! - Returns true if this enumerator is used as a flag; otherwise returns - false. - - \sa setIsFlag() -*/ -bool QMetaEnumBuilder::isFlag() const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - return d->isFlag; - else - return false; -} - -/*! - Sets this enumerator to be used as a flag if \a value is true. - - \sa isFlag() -*/ -void QMetaEnumBuilder::setIsFlag(bool value) -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - d->isFlag = value; -} - -/*! - Returns the number of keys. - - \sa key(), addKey() -*/ -int QMetaEnumBuilder::keyCount() const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) - return d->keys.size(); - else - return 0; -} - -/*! - Returns the key with the given \a index, or an empty QByteArray - if no such key exists. - - \sa keyCount(), addKey(), value() -*/ -QByteArray QMetaEnumBuilder::key(int index) const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d && index >= 0 && index < d->keys.size()) - return d->keys[index]; - else - return QByteArray(); -} - -/*! - Returns the value with the given \a index; or returns -1 if there - is no such value. - - \sa keyCount(), addKey(), key() -*/ -int QMetaEnumBuilder::value(int index) const -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d && index >= 0 && index < d->keys.size()) - return d->values[index]; - else - return -1; -} - -/*! - Adds a new key called \a name to this enumerator, associated - with \a value. Returns the index of the new key. - - \sa keyCount(), key(), value(), removeKey() -*/ -int QMetaEnumBuilder::addKey(const QByteArray& name, int value) -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d) { - int index = d->keys.size(); - d->keys += name; - d->values += value; - return index; - } else { - return -1; - } -} - -/*! - Removes the key at \a index from this enumerator. - - \sa addKey() -*/ -void QMetaEnumBuilder::removeKey(int index) -{ - QMetaEnumBuilderPrivate *d = d_func(); - if (d && index >= 0 && index < d->keys.size()) { - d->keys.removeAt(index); - d->values.removeAt(index); - } -} - -QT_END_NAMESPACE diff --git a/qmetaobjectbuilder_p.h b/qmetaobjectbuilder_p.h deleted file mode 100644 index 1e85353..0000000 --- a/qmetaobjectbuilder_p.h +++ /dev/null @@ -1,325 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMETAOBJECTBUILDER_H -#define QMETAOBJECTBUILDER_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of moc. This header file may change from version to version without notice, -// or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include - -//#include - -QT_BEGIN_NAMESPACE - -class QMetaObjectBuilderPrivate; -class QMetaMethodBuilder; -class QMetaMethodBuilderPrivate; -class QMetaPropertyBuilder; -class QMetaPropertyBuilderPrivate; -class QMetaEnumBuilder; -class QMetaEnumBuilderPrivate; - -class QMetaObjectBuilder -{ -public: - enum AddMember - { - ClassName = 0x00000001, - SuperClass = 0x00000002, - Methods = 0x00000004, - Signals = 0x00000008, - Slots = 0x00000010, - Constructors = 0x00000020, - Properties = 0x00000040, - Enumerators = 0x00000080, - ClassInfos = 0x00000100, - RelatedMetaObjects = 0x00000200, - StaticMetacall = 0x00000400, - PublicMethods = 0x00000800, - ProtectedMethods = 0x00001000, - PrivateMethods = 0x00002000, - AllMembers = 0x7FFFFFFF, - AllPrimaryMembers = 0x7FFFFBFC - }; - Q_DECLARE_FLAGS(AddMembers, AddMember) - - enum MetaObjectFlag { - DynamicMetaObject = 0x01 - }; - Q_DECLARE_FLAGS(MetaObjectFlags, MetaObjectFlag) - - QMetaObjectBuilder(); - explicit QMetaObjectBuilder(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); - virtual ~QMetaObjectBuilder(); - - QByteArray className() const; - void setClassName(const QByteArray& name); - - const QMetaObject *superClass() const; - void setSuperClass(const QMetaObject *meta); - - MetaObjectFlags flags() const; - void setFlags(MetaObjectFlags); - - int methodCount() const; - int constructorCount() const; - int propertyCount() const; - int enumeratorCount() const; - int classInfoCount() const; - int relatedMetaObjectCount() const; - - QMetaMethodBuilder addMethod(const QByteArray& signature); - QMetaMethodBuilder addMethod(const QByteArray& signature, const QByteArray& returnType); - QMetaMethodBuilder addMethod(const QMetaMethod& prototype); - - QMetaMethodBuilder addSlot(const QByteArray& signature); - QMetaMethodBuilder addSignal(const QByteArray& signature); - - QMetaMethodBuilder addConstructor(const QByteArray& signature); - QMetaMethodBuilder addConstructor(const QMetaMethod& prototype); - - QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, int notifierId=-1); - QMetaPropertyBuilder addProperty(const QMetaProperty& prototype); - - QMetaEnumBuilder addEnumerator(const QByteArray& name); - QMetaEnumBuilder addEnumerator(const QMetaEnum& prototype); - - int addClassInfo(const QByteArray& name, const QByteArray& value); - -#ifdef Q_NO_DATA_RELOCATION - int addRelatedMetaObject(const QMetaObjectAccessor &meta); -#else - int addRelatedMetaObject(const QMetaObject *meta); -#endif - - void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); - - QMetaMethodBuilder method(int index) const; - QMetaMethodBuilder constructor(int index) const; - QMetaPropertyBuilder property(int index) const; - QMetaEnumBuilder enumerator(int index) const; - const QMetaObject *relatedMetaObject(int index) const; - - QByteArray classInfoName(int index) const; - QByteArray classInfoValue(int index) const; - - void removeMethod(int index); - void removeConstructor(int index); - void removeProperty(int index); - void removeEnumerator(int index); - void removeClassInfo(int index); - void removeRelatedMetaObject(int index); - - int indexOfMethod(const QByteArray& signature); - int indexOfSignal(const QByteArray& signature); - int indexOfSlot(const QByteArray& signature); - int indexOfConstructor(const QByteArray& signature); - int indexOfProperty(const QByteArray& name); - int indexOfEnumerator(const QByteArray& name); - int indexOfClassInfo(const QByteArray& name); - - typedef QMetaObjectExtraData::StaticMetacallFunction StaticMetacallFunction; - - QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const; - void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value); - - QMetaObject *toMetaObject() const; - QByteArray toRelocatableData(bool * = 0) const; - static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &); - -#ifndef QT_NO_DATASTREAM - void serialize(QDataStream& stream) const; - void deserialize - (QDataStream& stream, - const QMap& references); -#endif - -private: - Q_DISABLE_COPY(QMetaObjectBuilder) - - QMetaObjectBuilderPrivate *d; - - friend class QMetaMethodBuilder; - friend class QMetaPropertyBuilder; - friend class QMetaEnumBuilder; -}; - -class QMetaMethodBuilder -{ -public: - QMetaMethodBuilder() : _mobj(0), _index(0) {} - - int index() const; - - QMetaMethod::MethodType methodType() const; - QByteArray signature() const; - - QByteArray returnType() const; - void setReturnType(const QByteArray& value); - - QList parameterNames() const; - void setParameterNames(const QList& value); - - QByteArray tag() const; - void setTag(const QByteArray& value); - - QMetaMethod::Access access() const; - void setAccess(QMetaMethod::Access value); - - int attributes() const; - void setAttributes(int value); - -private: - const QMetaObjectBuilder *_mobj; - int _index; - - friend class QMetaObjectBuilder; - friend class QMetaPropertyBuilder; - - QMetaMethodBuilder(const QMetaObjectBuilder *mobj, int index) - : _mobj(mobj), _index(index) {} - - QMetaMethodBuilderPrivate *d_func() const; -}; - -class QMetaPropertyBuilder -{ -public: - QMetaPropertyBuilder() : _mobj(0), _index(0) {} - - int index() const { return _index; } - - QByteArray name() const; - QByteArray type() const; - - bool hasNotifySignal() const; - QMetaMethodBuilder notifySignal() const; - void setNotifySignal(const QMetaMethodBuilder& value); - void removeNotifySignal(); - - bool isReadable() const; - bool isWritable() const; - bool isResettable() const; - bool isDesignable() const; - bool isScriptable() const; - bool isStored() const; - bool isEditable() const; - bool isUser() const; - bool hasStdCppSet() const; - bool isEnumOrFlag() const; - bool isConstant() const; - bool isFinal() const; - - void setReadable(bool value); - void setWritable(bool value); - void setResettable(bool value); - void setDesignable(bool value); - void setScriptable(bool value); - void setStored(bool value); - void setEditable(bool value); - void setUser(bool value); - void setStdCppSet(bool value); - void setEnumOrFlag(bool value); - void setConstant(bool value); - void setFinal(bool value); - -private: - const QMetaObjectBuilder *_mobj; - int _index; - - friend class QMetaObjectBuilder; - - QMetaPropertyBuilder(const QMetaObjectBuilder *mobj, int index) - : _mobj(mobj), _index(index) {} - - QMetaPropertyBuilderPrivate *d_func() const; -}; - -class QMetaEnumBuilder -{ -public: - QMetaEnumBuilder() : _mobj(0), _index(0) {} - - int index() const { return _index; } - - QByteArray name() const; - - bool isFlag() const; - void setIsFlag(bool value); - - int keyCount() const; - QByteArray key(int index) const; - int value(int index) const; - - int addKey(const QByteArray& name, int value); - void removeKey(int index); - -private: - const QMetaObjectBuilder *_mobj; - int _index; - - friend class QMetaObjectBuilder; - - QMetaEnumBuilder(const QMetaObjectBuilder *mobj, int index) - : _mobj(mobj), _index(index) {} - - QMetaEnumBuilderPrivate *d_func() const; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers) -Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::MetaObjectFlags) - -QT_END_NAMESPACE - -#endif diff --git a/test.qml b/test.qml deleted file mode 100644 index 06aa886..0000000 --- a/test.qml +++ /dev/null @@ -1,91 +0,0 @@ -import QtQuick 1.0 -import QtGui 1.0 - -Widget { - windowTitle: qsTr("Cool Test App") - size: Qt.size(300, 500) - - property int counter: 0 - - function myFunc() - { - counter++; - } - - Component.onCompleted: _timer.timeout.connect(myFunc) - - VBoxLayout { - Label { - text: "Hallo ASCII-safe Kevin!!! " + counter - } - Label { - id: secondLabel - text: "Wie geht es" - } - Label { - id: lastLabel - text: secondLabel.text - } - Label { - id: urlLabel - text: "Hallo Welt" - - onLinkActivated: console.log("link=" + link) - } - PushButton { - text: "Click me" - onClicked: { - secondLabel.text = "Changed" - counter++ - } - } - HBoxLayout { - CheckBox { - id: checkBox - } - Label { - text: checkBox.checked ? "Is checked" : "Is not checked" - } - } - TabWidget { - Label { - TabWidget.label: qsTr("Title 1") - - text: "Page 1" - } - Widget { - TabWidget.label: "Title 2" - - ButtonGroup { - buttons: [ button1, button2, button3, button4 ] - } - - VBoxLayout { - RadioButton { - id: button1 - text: qsTr("Apple") - } - RadioButton { - id: button2 - text: qsTr("Banana") - } - RadioButton { - id: button3 - text: qsTr("Peach") - } - - PushButton { - id: button4 - checkable: true - text: qsTr("Peas") - } - } - } - Label { - TabWidget.label: "Title 3" - - text: "Page 3" - } - } - } -} -- 1.7.2.5