From ef4f68e6614bd0d92debe907794802e1fef74401 Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 26 Feb 2018 19:50:40 +0100 Subject: [PATCH 01/13] Add ListItem control --- extensionplugin/extensionplugin_plugin.cpp | 2 + lib/declarativelistitem.cpp | 69 ++++++++++++++++++++++ lib/declarativelistitem_p.h | 50 ++++++++++++++++ lib/lib.pro | 22 +++---- 4 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 lib/declarativelistitem.cpp create mode 100644 lib/declarativelistitem_p.h diff --git a/extensionplugin/extensionplugin_plugin.cpp b/extensionplugin/extensionplugin_plugin.cpp index 2dd532c..807aaad 100644 --- a/extensionplugin/extensionplugin_plugin.cpp +++ b/extensionplugin/extensionplugin_plugin.cpp @@ -63,6 +63,7 @@ #include "scrollareawidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" +#include "declarativelistitem_p.h" #include #include @@ -188,4 +189,5 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "WebEngineView"); #endif qmlRegisterExtendedType(uri, 1, 0, "Widget"); + qmlRegisterExtendedType(uri, 1, 0, "ListItem"); } diff --git a/lib/declarativelistitem.cpp b/lib/declarativelistitem.cpp new file mode 100644 index 0000000..91835a4 --- /dev/null +++ b/lib/declarativelistitem.cpp @@ -0,0 +1,69 @@ +/* + declarativelistitem.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2012-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#include "declarativelistitem_p.h" + +#include +#include + +DeclarativeListItem::DeclarativeListItem() +{ + setMouseTracking(true); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); +} + +void DeclarativeListItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QStyleOptionViewItem option; + option.initFrom(this); + + QStylePainter stylePainter(this); + stylePainter.drawControl(QStyle::CE_ItemViewItem, option); +} + +void DeclarativeListItem::enterEvent(QEvent *event) +{ + Q_UNUSED(event); + + update(); +} + +void DeclarativeListItem::leaveEvent(QEvent *event) +{ + Q_UNUSED(event); + + update(); +} + +void DeclarativeListItem::mousePressEvent(QMouseEvent *event) +{ + Q_UNUSED(event); + + emit clicked(); +} diff --git a/lib/declarativelistitem_p.h b/lib/declarativelistitem_p.h new file mode 100644 index 0000000..0063e6f --- /dev/null +++ b/lib/declarativelistitem_p.h @@ -0,0 +1,50 @@ +/* + declarativelistitem_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2012-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#ifndef DECLARATIVELISTITEM_P_H +#define DECLARATIVELISTITEM_P_H + +#include + +class DeclarativeListItem : public QWidget +{ + Q_OBJECT + + public: + DeclarativeListItem(); + + private: + void paintEvent(QPaintEvent *event) override; + void enterEvent(QEvent *event) override; + void leaveEvent(QEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + + Q_SIGNALS: + void clicked(); +}; + +#endif // DECLARATIVELISTITEM_P_H diff --git a/lib/lib.pro b/lib/lib.pro index 0482a66..da3738f 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -66,11 +66,12 @@ HEADERS = \ staticdialogmethodattached_p.h \ toolbarwidgetcontainer_p.h \ widgetcontainerinterface_p.h \ - declarativeloaderwidget_p.h \ - declarativespaceritem_p.h \ - declarativeline_p.h \ - declarativelabelextension_p.h \ - declarativetabstops_p.h + declarativeloaderwidget_p.h \ + declarativespaceritem_p.h \ + declarativeline_p.h \ + declarativelabelextension_p.h \ + declarativetabstops_p.h \ + declarativelistitem_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -116,8 +117,9 @@ SOURCES = \ stackedwidgetwidgetcontainer.cpp \ staticdialogmethodattached.cpp \ toolbarwidgetcontainer.cpp \ - declarativeloaderwidget.cpp \ - declarativespaceritem.cpp \ - declarativeline.cpp \ - declarativelabelextension.cpp \ - declarativetabstops.cpp + declarativeloaderwidget.cpp \ + declarativespaceritem.cpp \ + declarativeline.cpp \ + declarativelabelextension.cpp \ + declarativetabstops.cpp \ + declarativelistitem.cpp From a6a883837a830bd3e840276bbc1a5b2a76aef41e Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 26 Feb 2018 19:56:41 +0100 Subject: [PATCH 02/13] Add support for Repeater --- extensionplugin/extensionplugin_plugin.cpp | 2 + lib/declarativerepeater.cpp | 250 +++++++++++++++++++++ lib/declarativerepeater_p.h | 89 ++++++++ lib/lib.pro | 22 +- 4 files changed, 353 insertions(+), 10 deletions(-) create mode 100644 lib/declarativerepeater.cpp create mode 100644 lib/declarativerepeater_p.h diff --git a/extensionplugin/extensionplugin_plugin.cpp b/extensionplugin/extensionplugin_plugin.cpp index 2dd532c..d9c73b7 100644 --- a/extensionplugin/extensionplugin_plugin.cpp +++ b/extensionplugin/extensionplugin_plugin.cpp @@ -63,6 +63,7 @@ #include "scrollareawidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" +#include "declarativerepeater_p.h" #include #include @@ -188,4 +189,5 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "WebEngineView"); #endif qmlRegisterExtendedType(uri, 1, 0, "Widget"); + qmlRegisterType(uri, 1, 0, "Repeater"); } diff --git a/lib/declarativerepeater.cpp b/lib/declarativerepeater.cpp new file mode 100644 index 0000000..0a58272 --- /dev/null +++ b/lib/declarativerepeater.cpp @@ -0,0 +1,250 @@ +/* + declarativerepeater.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2012-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#include "declarativerepeater_p.h" + +#include + +#include +#include +#include +#include + +class QQmlContext; +class QQmlInstanceModel; + +class DeclarativeRepeater::Private +{ + public: + Private() + : model(nullptr) + , itemCount(0) + { + } + + ~Private() + { + delete model; + } + + void requestItems() + { + for (int i = 0; i < itemCount; i++) { + QObject *object = model->object(i, QQmlIncubator::AsynchronousIfNested); + if (object) + model->release(object); + } + } + + QPointer model; + QVector> deletables; + QVariant dataSource; + + int itemCount; +}; + +DeclarativeRepeater::DeclarativeRepeater(QObject *parent) + : QObject(parent) + , d(new Private) +{ +} + +QVariant DeclarativeRepeater::model() const +{ + return d->dataSource; +} + +void DeclarativeRepeater::setModel(const QVariant &model) +{ + clear(); + + if (d->model) { + qmlobject_disconnect(d->model, QQmlInstanceModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), + this, DeclarativeRepeater, SLOT(modelUpdated(QQmlChangeSet,bool))); + qmlobject_disconnect(d->model, QQmlInstanceModel, SIGNAL(createdItem(int,QObject*)), + this, DeclarativeRepeater, SLOT(createdItem(int,QObject*))); + qmlobject_disconnect(d->model, QQmlInstanceModel, SIGNAL(initItem(int,QObject*)), + this, DeclarativeRepeater, SLOT(initItem(int,QObject*))); + } else { + d->model = new QQmlDelegateModel(qmlContext(this)); + d->model->componentComplete(); + } + + d->model->setModel(model); + d->dataSource = model; + + qmlobject_connect(d->model, QQmlInstanceModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), + this, DeclarativeRepeater, SLOT(modelUpdated(QQmlChangeSet,bool))); + qmlobject_connect(d->model, QQmlInstanceModel, SIGNAL(createdItem(int,QObject*)), + this, DeclarativeRepeater, SLOT(createdItem(int,QObject*))); + qmlobject_connect(d->model, QQmlInstanceModel, SIGNAL(initItem(int,QObject*)), + this, DeclarativeRepeater, SLOT(initItem(int,QObject*))); + + regenerate(); + + emit modelChanged(); + emit countChanged(); +} + +QQmlComponent *DeclarativeRepeater::delegate() const +{ + if (d->model) + return d->model->delegate(); + + return Q_NULLPTR; +} + +void DeclarativeRepeater::setDelegate(QQmlComponent *delegate) +{ + if (d->model) { + if (delegate == d->model->delegate()) + return; + } else { + d->model = new QQmlDelegateModel(qmlContext(this)); + } + + d->model->setDelegate(delegate); + + regenerate(); + + emit delegateChanged(); +} + +int DeclarativeRepeater::count() const +{ + if (d->model) + return d->model->count(); + + return 0; +} + +QWidget *DeclarativeRepeater::itemAt(int index) const +{ + if (index >= 0 && index < d->deletables.count()) + return d->deletables[index]; + + return Q_NULLPTR; +} + +void DeclarativeRepeater::componentComplete() +{ + if (d->model) + d->model->componentComplete(); + + regenerate(); + + if (d->model && d->model->count()) + emit countChanged(); +} + +void DeclarativeRepeater::clear() +{ + if (d->model) { + // We remove in reverse order deliberately; so that signals are emitted + // with sensible indices. + for (int i = d->deletables.count() - 1; i >= 0; --i) { + if (QWidget *widget = d->deletables.at(i)) { + emit itemRemoved(i, widget); + d->model->release(widget); + } + } + } + + QLayout *layout = qobject_cast(parent()); + + if (!layout) { + qmlInfo(this) << "Parent must be of BoxLayout type"; + return; + } + + for (QWidget *widget : d->deletables) { + layout->removeWidget(widget); + } + + d->deletables.clear(); + d->itemCount = 0; +} + +void DeclarativeRepeater::regenerate() +{ + clear(); + + if (!d->model || !d->model->count() || !d->model->isValid() || !parent()) + return; + + d->itemCount = count(); + d->deletables.resize(d->itemCount); + d->requestItems(); +} + +void DeclarativeRepeater::classBegin() +{ +} + +void DeclarativeRepeater::createdItem(int index, QObject *) +{ + QObject *object = d->model->object(index, QQmlIncubator::AsynchronousIfNested); + QWidget *item = qmlobject_cast(object); + + emit itemAdded(index, item); +} + +void DeclarativeRepeater::initItem(int index, QObject *object) +{ + QWidget *widget = qobject_cast(object); + + if (!d->deletables.at(index)) { + if (!widget) { + if (object) { + d->model->release(object); + qmlInfo(this) << "Delegate must be of Widget type"; + } + return; + } + + QLayout *layout = qobject_cast(parent()); + + if (!layout) { + qmlInfo(this) << "Parent must be of BoxLayout type"; + return; + } + + layout->addWidget(widget); + + d->deletables[index] = widget; + } +} + +void DeclarativeRepeater::modelUpdated(const QQmlChangeSet &changeSet, bool reset) +{ + Q_UNUSED(reset); + + regenerate(); + + if (changeSet.difference() != 0) + emit countChanged(); +} diff --git a/lib/declarativerepeater_p.h b/lib/declarativerepeater_p.h new file mode 100644 index 0000000..e5197a2 --- /dev/null +++ b/lib/declarativerepeater_p.h @@ -0,0 +1,89 @@ +/* + declarativerepeater_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2012-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#ifndef DECLARATIVEREPEATER_P_H +#define DECLARATIVEREPEATER_P_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QQmlChangeSet; +class QQmlComponent; +QT_END_NAMESPACE + +class DeclarativeRepeater : public QObject, public QQmlParserStatus +{ + Q_OBJECT + + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) + + Q_CLASSINFO("DefaultProperty", "delegate") + + Q_INTERFACES(QQmlParserStatus) + +public: + DeclarativeRepeater(QObject *parent = Q_NULLPTR); + + QVariant model() const; + void setModel(const QVariant &model); + + QQmlComponent *delegate() const; + void setDelegate(QQmlComponent *); + + int count() const; + + Q_INVOKABLE QWidget *itemAt(int index) const; + + Q_SIGNALS: + void modelChanged(); + void delegateChanged(); + void countChanged(); + + void itemAdded(int index, QWidget *item); + void itemRemoved(int index, QWidget *item); + + private: + class Private; + Private *const d; + + void clear(); + void regenerate(); + + protected: + void classBegin() override; + void componentComplete() override; + + private Q_SLOTS: + void createdItem(int index, QObject *item); + void initItem(int, QObject *item); + void modelUpdated(const QQmlChangeSet &changeSet, bool reset); +}; + +#endif // DECLARATIVEREPEATER_P_H diff --git a/lib/lib.pro b/lib/lib.pro index 0482a66..482b3e5 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -66,11 +66,12 @@ HEADERS = \ staticdialogmethodattached_p.h \ toolbarwidgetcontainer_p.h \ widgetcontainerinterface_p.h \ - declarativeloaderwidget_p.h \ - declarativespaceritem_p.h \ - declarativeline_p.h \ - declarativelabelextension_p.h \ - declarativetabstops_p.h + declarativeloaderwidget_p.h \ + declarativespaceritem_p.h \ + declarativeline_p.h \ + declarativelabelextension_p.h \ + declarativetabstops_p.h \ + declarativerepeater_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -116,8 +117,9 @@ SOURCES = \ stackedwidgetwidgetcontainer.cpp \ staticdialogmethodattached.cpp \ toolbarwidgetcontainer.cpp \ - declarativeloaderwidget.cpp \ - declarativespaceritem.cpp \ - declarativeline.cpp \ - declarativelabelextension.cpp \ - declarativetabstops.cpp + declarativeloaderwidget.cpp \ + declarativespaceritem.cpp \ + declarativeline.cpp \ + declarativelabelextension.cpp \ + declarativetabstops.cpp \ + declarativerepeater.cpp From 0f1eba8883120c04161e9beb3206d8cc5a3bf972 Mon Sep 17 00:00:00 2001 From: Znurre Date: Tue, 20 Feb 2018 19:22:32 +0100 Subject: [PATCH 03/13] Add support for accessing Widget backgroundRole/foregroundRole --- src/declarativepalette_p.h | 41 ++++++++++++++++++++++++++++++ src/declarativewidgetextension.cpp | 34 +++++++++++++++++++++++++ src/declarativewidgetextension.h | 15 +++++++++-- src/declarativewidgets_plugin.cpp | 4 ++- src/src.pro | 3 ++- 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/declarativepalette_p.h diff --git a/src/declarativepalette_p.h b/src/declarativepalette_p.h new file mode 100644 index 0000000..2bc263c --- /dev/null +++ b/src/declarativepalette_p.h @@ -0,0 +1,41 @@ +#ifndef DECLARATIVEPALETTE_P_H +#define DECLARATIVEPALETTE_P_H + +#include +#include + +class DeclarativePalette : public QObject +{ + Q_OBJECT + + Q_ENUMS(ColorRole) + + public: + enum ColorRole { + WindowText = QPalette::WindowText, + Button = QPalette::Button, + Light = QPalette::Light, + Midlight = QPalette::Midlight, + Dark = QPalette::Dark, + Mid = QPalette::Mid, + Text = QPalette::Text, + BrightText = QPalette::BrightText, + ButtonText = QPalette::ButtonText, + Base = QPalette::Base, + Window = QPalette::Window, + Shadow = QPalette::Shadow, + Highlight = QPalette::Highlight, + HighlightedText = QPalette::HighlightedText, + Link = QPalette::Link, + LinkVisited = QPalette::LinkVisited, + AlternateBase = QPalette::AlternateBase, + NoRole = QPalette::NoRole, + ToolTipBase = QPalette::ToolTipBase, + ToolTipText = QPalette::ToolTipText, + NColorRoles = QPalette::NColorRoles, + Foreground = QPalette::Foreground, + Background = QPalette::Background + }; +}; + +#endif // DECLARATIVEPALETTE_P_H diff --git a/src/declarativewidgetextension.cpp b/src/declarativewidgetextension.cpp index e5d46c3..f15664d 100644 --- a/src/declarativewidgetextension.cpp +++ b/src/declarativewidgetextension.cpp @@ -200,6 +200,40 @@ void DeclarativeWidgetExtension::setVisible(bool visible) extendedWidget()->setVisible(visible); } +int DeclarativeWidgetExtension::backgroundRole() const +{ + return static_cast(extendedWidget()->backgroundRole()); +} + +void DeclarativeWidgetExtension::setBackgroundRole(int backgroundRole) +{ + const QPalette::ColorRole role = static_cast(backgroundRole); + + if (extendedWidget()->backgroundRole() == role) + return; + + extendedWidget()->setBackgroundRole(role); + + emit backgroundRoleChanged(backgroundRole); +} + +int DeclarativeWidgetExtension::foregroundRole() const +{ + return static_cast(extendedWidget()->foregroundRole()); +} + +void DeclarativeWidgetExtension::setForegroundRole(int foregroundRole) +{ + const QPalette::ColorRole role = static_cast(foregroundRole); + + if (extendedWidget()->foregroundRole() == role) + return; + + extendedWidget()->setForegroundRole(role); + + emit foregroundRoleChanged(foregroundRole); +} + bool DeclarativeWidgetExtension::eventFilter(QObject *watched, QEvent *event) { Q_ASSERT(watched == parent()); diff --git a/src/declarativewidgetextension.h b/src/declarativewidgetextension.h index 58f4daf..b141f0b 100644 --- a/src/declarativewidgetextension.h +++ b/src/declarativewidgetextension.h @@ -30,6 +30,7 @@ #include #include "declarativeobjectextension.h" +#include "declarativepalette_p.h" #include @@ -54,11 +55,13 @@ class DeclarativeWidgetExtension : public DeclarativeObjectExtension Q_PROPERTY(int height READ height WRITE setHeight NOTIFY sizeChanged) Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(int backgroundRole READ backgroundRole WRITE setBackgroundRole NOTIFY backgroundRoleChanged) + Q_PROPERTY(int foregroundRole READ foregroundRole WRITE setForegroundRole NOTIFY foregroundRoleChanged) Q_CLASSINFO("DefaultProperty", "data") public: - explicit DeclarativeWidgetExtension(QObject *parent = 0); + explicit DeclarativeWidgetExtension(QObject *parent = Q_NULLPTR); QWidget *extendedWidget() const; @@ -80,16 +83,24 @@ class DeclarativeWidgetExtension : public DeclarativeObjectExtension bool isVisible() const; void setVisible(bool visible); + int backgroundRole() const; + void setBackgroundRole(int backgroundRole); + + int foregroundRole() const; + void setForegroundRole(int foregroundRole); + bool eventFilter(QObject *watched, QEvent *event); protected: - explicit DeclarativeWidgetExtension(WidgetContainerInterface *widgetContainer, QObject *parent = 0); + explicit DeclarativeWidgetExtension(WidgetContainerInterface *widgetContainer, QObject *parent = Q_NULLPTR); Q_SIGNALS: void posChanged(); void sizeChanged(); void geometryChanged(); void visibleChanged(bool visible); + void backgroundRoleChanged(int backgroundRole); + void foregroundRoleChanged(int foregroundRole); }; #endif // DECLARATIVEWIDGETEXTENSION_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 02a7be2..8dea26d 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -68,6 +68,7 @@ #include "scrollareawidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" +#include "declarativepalette_p.h" #include #include @@ -138,7 +139,8 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "FileSystemModel"); qmlRegisterType(uri, 1, 0, "Icon"); qmlRegisterExtendedType(uri, 1, 0, "Separator"); - qmlRegisterType("QtWidgets", 1, 0, "TabStops"); + qmlRegisterType(uri, 1, 0, "TabStops"); + qmlRegisterType(uri, 1, 0, "Palette"); // layouts qmlRegisterExtendedType(uri, 1, 0, "FormLayout"); diff --git a/src/src.pro b/src/src.pro index d8c0224..5a8f494 100644 --- a/src/src.pro +++ b/src/src.pro @@ -85,7 +85,8 @@ HEADERS = \ stackedwidgetwidgetcontainer_p.h \ staticdialogmethodattached_p.h \ toolbarwidgetcontainer_p.h \ - widgetcontainerinterface_p.h + widgetcontainerinterface_p.h \ + declarativepalette_p.h SOURCES = \ abstractdeclarativeobject.cpp \ From 2d7551ba490ab4b9d449c4f090fadd29fa39faac Mon Sep 17 00:00:00 2001 From: Znurre Date: Sun, 18 Feb 2018 20:29:22 +0100 Subject: [PATCH 04/13] Alias QPushButton::default to QPushButton::isDefault --- src/declarativepushbutton.cpp | 32 +++++++++++++++++++++++ src/declarativepushbutton_p.h | 42 +++++++++++++++++++++++++++++++ src/declarativewidgets_plugin.cpp | 3 ++- src/src.pro | 6 +++-- 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/declarativepushbutton.cpp create mode 100644 src/declarativepushbutton_p.h diff --git a/src/declarativepushbutton.cpp b/src/declarativepushbutton.cpp new file mode 100644 index 0000000..74e5cea --- /dev/null +++ b/src/declarativepushbutton.cpp @@ -0,0 +1,32 @@ +/* + declarativeloaderwidget_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#include "declarativepushbutton_p.h" + +DeclarativePushButton::DeclarativePushButton(QWidget *parent) : QPushButton(parent) +{ +} diff --git a/src/declarativepushbutton_p.h b/src/declarativepushbutton_p.h new file mode 100644 index 0000000..0714ed6 --- /dev/null +++ b/src/declarativepushbutton_p.h @@ -0,0 +1,42 @@ +/* + declarativeloaderwidget_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#ifndef DECLARATIVEPUSHBUTTON_P_H +#define DECLARATIVEPUSHBUTTON_P_H + +#include + +class DeclarativePushButton : public QPushButton +{ + Q_OBJECT + Q_PROPERTY(bool isDefault READ isDefault WRITE setDefault) + + public: + explicit DeclarativePushButton(QWidget *parent = 0); +}; + +#endif // DECLARATIVEPUSHBUTTON_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 02a7be2..9a05a08 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -68,6 +68,7 @@ #include "scrollareawidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" +#include "declarativepushbutton_p.h" #include #include @@ -178,7 +179,7 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "MessageBox"); qmlRegisterExtendedType(uri, 1, 0, "PlainTextEdit"); qmlRegisterExtendedType(uri, 1, 0, "ProgressBar"); - qmlRegisterExtendedType(uri, 1, 0, "PushButton"); + qmlRegisterExtendedType(uri, 1, 0, "PushButton"); qmlRegisterExtendedType(uri, 1, 0, "RadioButton"); qmlRegisterExtendedType >(uri, 1, 0, "ScrollArea"); qmlRegisterExtendedType(uri, 1, 0, "ScrollBar"); diff --git a/src/src.pro b/src/src.pro index d8c0224..0e93feb 100644 --- a/src/src.pro +++ b/src/src.pro @@ -85,7 +85,8 @@ HEADERS = \ stackedwidgetwidgetcontainer_p.h \ staticdialogmethodattached_p.h \ toolbarwidgetcontainer_p.h \ - widgetcontainerinterface_p.h + widgetcontainerinterface_p.h \ + declarativepushbutton_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -135,4 +136,5 @@ SOURCES = \ scrollareawidgetcontainer.cpp \ stackedwidgetwidgetcontainer.cpp \ staticdialogmethodattached.cpp \ - toolbarwidgetcontainer.cpp + toolbarwidgetcontainer.cpp \ + declarativepushbutton.cpp From 4f4b99dada3370319a10afc3de3ef8b33aa0249a Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 19 Feb 2018 21:21:29 +0100 Subject: [PATCH 05/13] Fix copyright header --- src/declarativepushbutton.cpp | 2 +- src/declarativepushbutton_p.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarativepushbutton.cpp b/src/declarativepushbutton.cpp index 74e5cea..7ab95fa 100644 --- a/src/declarativepushbutton.cpp +++ b/src/declarativepushbutton.cpp @@ -1,5 +1,5 @@ /* - declarativeloaderwidget_p.h + declarativepushbutton.cpp This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. diff --git a/src/declarativepushbutton_p.h b/src/declarativepushbutton_p.h index 0714ed6..84be315 100644 --- a/src/declarativepushbutton_p.h +++ b/src/declarativepushbutton_p.h @@ -1,5 +1,5 @@ /* - declarativeloaderwidget_p.h + declarativepushbutton_p.h This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. From ae1d0ee7d6b4a5516288bc040d777fde481b4c39 Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 26 Mar 2018 12:08:28 +0200 Subject: [PATCH 06/13] Changed year in copyright header --- src/declarativepushbutton.cpp | 2 +- src/declarativepushbutton_p.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarativepushbutton.cpp b/src/declarativepushbutton.cpp index 7ab95fa..e99cf5e 100644 --- a/src/declarativepushbutton.cpp +++ b/src/declarativepushbutton.cpp @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/src/declarativepushbutton_p.h b/src/declarativepushbutton_p.h index 84be315..a33a66f 100644 --- a/src/declarativepushbutton_p.h +++ b/src/declarativepushbutton_p.h @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in From ef313e402aa2895f2d4d33a0d0d9ec269c84905f Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 19 Feb 2018 21:12:19 +0100 Subject: [PATCH 07/13] Add support for Splitter --- src/declarativesplitter.cpp | 88 +++++++++++++++++++ src/declarativesplitter_p.h | 67 ++++++++++++++ src/declarativewidgets_plugin.cpp | 3 + src/splitterwidgetcontainer.cpp | 65 ++++++++++++++ src/splitterwidgetcontainer_p.h | 52 +++++++++++ src/src.pro | 8 +- tests/auto/instantiatetypes/qml.qrc | 1 + .../qml/creatable/widgets/Splitter.qml | 32 +++++++ 8 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 src/declarativesplitter.cpp create mode 100644 src/declarativesplitter_p.h create mode 100644 src/splitterwidgetcontainer.cpp create mode 100644 src/splitterwidgetcontainer_p.h create mode 100644 tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp new file mode 100644 index 0000000..86905e4 --- /dev/null +++ b/src/declarativesplitter.cpp @@ -0,0 +1,88 @@ +/* + declarativesplitter.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#include "declarativesplitter_p.h" + +#include +#include +#include + +class DeclarativeSplitterAttached::Private +{ + public: + Private(QWidget *w) + : stretch(0) + , widget(w) + { + } + + int stretch; + + QPointer widget; +}; + +DeclarativeSplitterAttached::DeclarativeSplitterAttached(QWidget *widget, QObject *parent) + : QObject(parent) + , d(new Private(widget)) +{ +} + +DeclarativeSplitterAttached::~DeclarativeSplitterAttached() +{ + delete d; +} + +void DeclarativeSplitterAttached::setStretch(int stretch) +{ + if (stretch == d->stretch) + return; + + d->stretch = stretch; + + emit stretchChanged(stretch); +} + +int DeclarativeSplitterAttached::stretch() const +{ + return d->stretch; +} + +DeclarativeSplitter::DeclarativeSplitter(QWidget *parent) + : QSplitter(parent) +{ +} + +DeclarativeSplitterAttached *DeclarativeSplitter::qmlAttachedProperties(QObject *parent) +{ + QWidget *widget = qobject_cast(parent); + if (widget) + return new DeclarativeSplitterAttached(widget, parent); + + qmlInfo(parent) << "Can only attach Splitter to widgets"; + + return Q_NULLPTR; +} diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h new file mode 100644 index 0000000..f5ed2aa --- /dev/null +++ b/src/declarativesplitter_p.h @@ -0,0 +1,67 @@ +/* + declarativesplitter_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#ifndef DECLARATIVESPLITTER_P_H +#define DECLARATIVESPLITTER_P_H + +#include +#include +#include +#include + +class DeclarativeSplitterAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged) + + public: + DeclarativeSplitterAttached(QWidget *widget, QObject *parent); + ~DeclarativeSplitterAttached(); + + void setStretch(int stretch); + int stretch() const; + + Q_SIGNALS: + void stretchChanged(int stretch); + + private: + class Private; + Private *const d; +}; + +class DeclarativeSplitter : public QSplitter +{ + public: + DeclarativeSplitter(QWidget *parent = Q_NULLPTR); + + static DeclarativeSplitterAttached *qmlAttachedProperties(QObject *parent); +}; + +QML_DECLARE_TYPEINFO(DeclarativeSplitter, QML_HAS_ATTACHED_PROPERTIES) + +#endif // DECLARATIVESPLITTER_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 5c0267c..a57a806 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -70,6 +70,8 @@ #include "scrollareawidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" +#include "splitterwidgetcontainer_p.h" +#include "declarativesplitter_p.h" #include #include @@ -206,4 +208,5 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "WebEngineView"); #endif qmlRegisterExtendedType(uri, 1, 0, "Widget"); + qmlRegisterExtendedType>(uri, 1, 0, "Splitter"); } diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp new file mode 100644 index 0000000..fc2bbac --- /dev/null +++ b/src/splitterwidgetcontainer.cpp @@ -0,0 +1,65 @@ +/* + splitterwidgetcontainer.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#include "splitterwidgetcontainer_p.h" + +#include "declarativesplitter_p.h" + +#include +#include +#include + +SplitterWidgetContainer::SplitterWidgetContainer(QObject *parent) + : DefaultWidgetContainer(qobject_cast(parent)) +{ + Q_ASSERT(m_widget); +} + +void SplitterWidgetContainer::setLayout(QLayout *layout) +{ + Q_UNUSED(layout); + qmlInfo(m_widget) << "Can not set a Layout to a Splitter"; +} + +void SplitterWidgetContainer::addWidget(QWidget *widget) +{ + QObject *attachedProperties = qmlAttachedPropertiesObject(widget, false); + DeclarativeSplitterAttached *properties = qobject_cast(attachedProperties); + if (properties) { + QSizePolicy policy = widget->sizePolicy(); + policy.setHorizontalStretch(properties->stretch()); + policy.setVerticalStretch(properties->stretch()); + widget->setSizePolicy(policy); + } + + extendedSplitter()->addWidget(widget); +} + +QSplitter *SplitterWidgetContainer::extendedSplitter() const +{ + return static_cast(m_widget); +} diff --git a/src/splitterwidgetcontainer_p.h b/src/splitterwidgetcontainer_p.h new file mode 100644 index 0000000..3c4ff3e --- /dev/null +++ b/src/splitterwidgetcontainer_p.h @@ -0,0 +1,52 @@ +/* + splitterwidgetcontainer_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#ifndef SPLITTERWIDGETCONTAINER_P_H +#define SPLITTERWIDGETCONTAINER_P_H + +#include + +#include "defaultwidgetcontainer.h" + +QT_BEGIN_NAMESPACE +class QSplitter; +class QObject; +QT_END_NAMESPACE + +class SplitterWidgetContainer : public DefaultWidgetContainer +{ + public: + explicit SplitterWidgetContainer(QObject *parent = Q_NULLPTR); + + void setLayout(QLayout *layout) Q_DECL_OVERRIDE; + void addWidget(QWidget *widget) Q_DECL_OVERRIDE; + + private: + QSplitter *extendedSplitter() const; +}; + +#endif // SPLITTERWIDGETCONTAINER_P_H diff --git a/src/src.pro b/src/src.pro index 6d5919b..d535780 100644 --- a/src/src.pro +++ b/src/src.pro @@ -86,7 +86,9 @@ HEADERS = \ staticdialogmethodattached_p.h \ toolbarwidgetcontainer_p.h \ widgetcontainerinterface_p.h \ - declarativesizepolicy_p.h + declarativesizepolicy_p.h \ + splitterwidgetcontainer_p.h \ + declarativesplitter_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -137,4 +139,6 @@ SOURCES = \ stackedwidgetwidgetcontainer.cpp \ staticdialogmethodattached.cpp \ toolbarwidgetcontainer.cpp \ - declarativesizepolicy.cpp + declarativesizepolicy.cpp \ + splitterwidgetcontainer.cpp \ + declarativesplitter.cpp diff --git a/tests/auto/instantiatetypes/qml.qrc b/tests/auto/instantiatetypes/qml.qrc index 1a8ebb9..192dec0 100644 --- a/tests/auto/instantiatetypes/qml.qrc +++ b/tests/auto/instantiatetypes/qml.qrc @@ -66,5 +66,6 @@ qml/uncreatable/ItemSelectionModel.qml qml/uncreatable/TextDocument.qml qml/creatable/webenginewidgets/WebEngineView.qml + qml/creatable/widgets/Splitter.qml diff --git a/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml new file mode 100644 index 0000000..2dfca9b --- /dev/null +++ b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml @@ -0,0 +1,32 @@ +/* + Splitter.qml + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +import QtWidgets 1.0 + +Splitter { + +} From 39f80315ed3410aaf3fe3c213d44f5e9c0f63241 Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 26 Mar 2018 12:21:21 +0200 Subject: [PATCH 08/13] Changed year in copyright header --- src/declarativesplitter.cpp | 2 +- src/declarativesplitter_p.h | 2 +- src/splitterwidgetcontainer.cpp | 2 +- src/splitterwidgetcontainer_p.h | 2 +- tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp index 86905e4..abf0a7b 100644 --- a/src/declarativesplitter.cpp +++ b/src/declarativesplitter.cpp @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h index f5ed2aa..f0e7730 100644 --- a/src/declarativesplitter_p.h +++ b/src/declarativesplitter_p.h @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp index fc2bbac..b6e6af4 100644 --- a/src/splitterwidgetcontainer.cpp +++ b/src/splitterwidgetcontainer.cpp @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/src/splitterwidgetcontainer_p.h b/src/splitterwidgetcontainer_p.h index 3c4ff3e..9de7b87 100644 --- a/src/splitterwidgetcontainer_p.h +++ b/src/splitterwidgetcontainer_p.h @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml index 2dfca9b..f0b2483 100644 --- a/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml +++ b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in From 86bf0212e46f7348f608fbfe41356f3b62b2f97f Mon Sep 17 00:00:00 2001 From: Znurre Date: Wed, 28 Mar 2018 17:14:10 +0200 Subject: [PATCH 09/13] Added Splitter layout tests --- tests/auto/layouts/layouts.pro | 9 +++-- tests/auto/layouts/qml.qrc | 1 + tests/auto/layouts/qml/SplitterTest.qml | 37 ++++++++++++++++++ tests/auto/layouts/splitter.cpp | 42 ++++++++++++++++++++ tests/auto/layouts/splitter.h | 52 +++++++++++++++++++++++++ tests/auto/layouts/splitter.ui | 18 +++++++++ tests/auto/layouts/tst_layouts.cpp | 23 +++++++++++ 7 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 tests/auto/layouts/qml/SplitterTest.qml create mode 100644 tests/auto/layouts/splitter.cpp create mode 100644 tests/auto/layouts/splitter.h create mode 100644 tests/auto/layouts/splitter.ui diff --git a/tests/auto/layouts/layouts.pro b/tests/auto/layouts/layouts.pro index 82ad540..77eb65e 100644 --- a/tests/auto/layouts/layouts.pro +++ b/tests/auto/layouts/layouts.pro @@ -6,7 +6,8 @@ SOURCES += tst_layouts.cpp \ formlayoutwidget.cpp \ gridlayoutwidget.cpp \ stackedlayoutwidget.cpp \ - stackedwidget.cpp + stackedwidget.cpp \ + splitter.cpp RESOURCES += \ qml.qrc @@ -16,7 +17,8 @@ FORMS += \ vboxlayout.ui \ formlayout.ui \ gridlayout.ui \ - stackedwidget.ui + stackedwidget.ui \ + splitter.ui HEADERS += \ hboxlayoutwidget.h \ @@ -24,4 +26,5 @@ HEADERS += \ formlayoutwidget.h \ gridlayoutwidget.h \ stackedlayoutwidget.h \ - stackedwidget.h + stackedwidget.h \ + splitter.h diff --git a/tests/auto/layouts/qml.qrc b/tests/auto/layouts/qml.qrc index a71de82..c150531 100644 --- a/tests/auto/layouts/qml.qrc +++ b/tests/auto/layouts/qml.qrc @@ -6,5 +6,6 @@ qml/GridLayoutTest.qml qml/StackedLayoutTest.qml qml/StackedWidgetTest.qml + qml/SplitterTest.qml diff --git a/tests/auto/layouts/qml/SplitterTest.qml b/tests/auto/layouts/qml/SplitterTest.qml new file mode 100644 index 0000000..d3b5bbf --- /dev/null +++ b/tests/auto/layouts/qml/SplitterTest.qml @@ -0,0 +1,37 @@ +/* + SplitterTest.qml + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +import QtWidgets 1.0 + +Splitter { + Label { + text: "Label 1" + } + Label { + text: "Label 2" + } +} diff --git a/tests/auto/layouts/splitter.cpp b/tests/auto/layouts/splitter.cpp new file mode 100644 index 0000000..ff1b881 --- /dev/null +++ b/tests/auto/layouts/splitter.cpp @@ -0,0 +1,42 @@ +/* + splitter.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#include "splitter.h" + +#include "ui_splitter.h" + +Splitter::Splitter(QWidget *parent) + : QSplitter(parent) + , ui(new Ui::Splitter) +{ + ui->setupUi(this); +} + +Splitter::~Splitter() +{ + delete ui; +} diff --git a/tests/auto/layouts/splitter.h b/tests/auto/layouts/splitter.h new file mode 100644 index 0000000..894229a --- /dev/null +++ b/tests/auto/layouts/splitter.h @@ -0,0 +1,52 @@ +/* + splitter.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#ifndef SPLITTER_H +#define SPLITTER_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui +{ + class Splitter; +} +QT_END_NAMESPACE + +class Splitter : public QSplitter +{ + Q_OBJECT + + public: + explicit Splitter(QWidget *parent = Q_NULLPTR); + ~Splitter(); + + private: + Ui::Splitter *ui; +}; + +#endif // SPLITTER_H diff --git a/tests/auto/layouts/splitter.ui b/tests/auto/layouts/splitter.ui new file mode 100644 index 0000000..434d5ed --- /dev/null +++ b/tests/auto/layouts/splitter.ui @@ -0,0 +1,18 @@ + + + Splitter + + + + Label 1 + + + + + Label 2 + + + + + + diff --git a/tests/auto/layouts/tst_layouts.cpp b/tests/auto/layouts/tst_layouts.cpp index 8eefa78..b81f1a3 100644 --- a/tests/auto/layouts/tst_layouts.cpp +++ b/tests/auto/layouts/tst_layouts.cpp @@ -31,6 +31,7 @@ #include "vboxlayoutwidget.h" #include "formlayoutwidget.h" #include "gridlayoutwidget.h" +#include "splitter.h" #include "stackedlayoutwidget.h" #include "stackedwidget.h" @@ -65,6 +66,8 @@ private slots: void stackedWidget(); void sizePolicy_data(); void sizePolicy(); + void splitter_data(); + void splitter(); private: QQmlEngine* m_qmlEngine; @@ -214,6 +217,26 @@ void tst_Layouts::stackedWidget() testLayouts(uiWidget, declarativeWidget); } +void tst_Layouts::splitter_data() +{ + QQmlComponent component(m_qmlEngine, QUrl(QStringLiteral("qrc:/qml/SplitterTest.qml"))); + QWidgetPtr declarativeWidget(qobject_cast(component.create())); + QVERIFY(declarativeWidget != nullptr); + + QTest::addColumn("uiWidget"); + QTest::addColumn("declarativeWidget"); + + QTest::newRow("splitterWidget") << QWidgetPtr(new Splitter()) << declarativeWidget; +} + +void tst_Layouts::splitter() +{ + QFETCH(QWidgetPtr, uiWidget); + QFETCH(QWidgetPtr, declarativeWidget); + + testLayouts(uiWidget, declarativeWidget); +} + void tst_Layouts::sizePolicy_data() { // QSizePolicy::ControlType is not registered with the meta-type system. From 85c8f528226fae71785c3bb65ffa53982c2c1c87 Mon Sep 17 00:00:00 2001 From: Znurre Date: Wed, 28 Mar 2018 18:13:21 +0200 Subject: [PATCH 10/13] Dropped the Splitter attached properties --- src/declarativesplitter.cpp | 55 ------------------------------- src/declarativesplitter_p.h | 28 ---------------- src/declarativewidgets_plugin.cpp | 4 +-- src/splitterwidgetcontainer.cpp | 12 +------ 4 files changed, 3 insertions(+), 96 deletions(-) diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp index abf0a7b..25fccd4 100644 --- a/src/declarativesplitter.cpp +++ b/src/declarativesplitter.cpp @@ -27,62 +27,7 @@ #include "declarativesplitter_p.h" -#include -#include -#include - -class DeclarativeSplitterAttached::Private -{ - public: - Private(QWidget *w) - : stretch(0) - , widget(w) - { - } - - int stretch; - - QPointer widget; -}; - -DeclarativeSplitterAttached::DeclarativeSplitterAttached(QWidget *widget, QObject *parent) - : QObject(parent) - , d(new Private(widget)) -{ -} - -DeclarativeSplitterAttached::~DeclarativeSplitterAttached() -{ - delete d; -} - -void DeclarativeSplitterAttached::setStretch(int stretch) -{ - if (stretch == d->stretch) - return; - - d->stretch = stretch; - - emit stretchChanged(stretch); -} - -int DeclarativeSplitterAttached::stretch() const -{ - return d->stretch; -} - DeclarativeSplitter::DeclarativeSplitter(QWidget *parent) : QSplitter(parent) { } - -DeclarativeSplitterAttached *DeclarativeSplitter::qmlAttachedProperties(QObject *parent) -{ - QWidget *widget = qobject_cast(parent); - if (widget) - return new DeclarativeSplitterAttached(widget, parent); - - qmlInfo(parent) << "Can only attach Splitter to widgets"; - - return Q_NULLPTR; -} diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h index f0e7730..c5cc58b 100644 --- a/src/declarativesplitter_p.h +++ b/src/declarativesplitter_p.h @@ -28,40 +28,12 @@ #ifndef DECLARATIVESPLITTER_P_H #define DECLARATIVESPLITTER_P_H -#include -#include #include -#include - -class DeclarativeSplitterAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged) - - public: - DeclarativeSplitterAttached(QWidget *widget, QObject *parent); - ~DeclarativeSplitterAttached(); - - void setStretch(int stretch); - int stretch() const; - - Q_SIGNALS: - void stretchChanged(int stretch); - - private: - class Private; - Private *const d; -}; class DeclarativeSplitter : public QSplitter { public: DeclarativeSplitter(QWidget *parent = Q_NULLPTR); - - static DeclarativeSplitterAttached *qmlAttachedProperties(QObject *parent); }; -QML_DECLARE_TYPEINFO(DeclarativeSplitter, QML_HAS_ATTACHED_PROPERTIES) - #endif // DECLARATIVESPLITTER_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index a57a806..4e474e8 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -54,6 +54,7 @@ #include "declarativeseparator_p.h" #include "declarativesizepolicy_p.h" #include "declarativespaceritem_p.h" +#include "declarativesplitter_p.h" #include "declarativestackedlayout_p.h" #include "declarativestatusbar_p.h" #include "declarativestringlistmodelextension_p.h" @@ -68,10 +69,9 @@ #include "menubarwidgetcontainer_p.h" #include "menuwidgetcontainer_p.h" #include "scrollareawidgetcontainer_p.h" +#include "splitterwidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" -#include "splitterwidgetcontainer_p.h" -#include "declarativesplitter_p.h" #include #include diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp index b6e6af4..8bc1f24 100644 --- a/src/splitterwidgetcontainer.cpp +++ b/src/splitterwidgetcontainer.cpp @@ -29,9 +29,8 @@ #include "declarativesplitter_p.h" -#include #include -#include +#include SplitterWidgetContainer::SplitterWidgetContainer(QObject *parent) : DefaultWidgetContainer(qobject_cast(parent)) @@ -47,15 +46,6 @@ void SplitterWidgetContainer::setLayout(QLayout *layout) void SplitterWidgetContainer::addWidget(QWidget *widget) { - QObject *attachedProperties = qmlAttachedPropertiesObject(widget, false); - DeclarativeSplitterAttached *properties = qobject_cast(attachedProperties); - if (properties) { - QSizePolicy policy = widget->sizePolicy(); - policy.setHorizontalStretch(properties->stretch()); - policy.setVerticalStretch(properties->stretch()); - widget->setSizePolicy(policy); - } - extendedSplitter()->addWidget(widget); } From e6ec70d7aed7a2f4087080e1e7d633251ebe4b04 Mon Sep 17 00:00:00 2001 From: Znurre Date: Thu, 29 Mar 2018 16:59:11 +0200 Subject: [PATCH 11/13] Remove unused class DeclarativeSplitter --- src/declarativesplitter.cpp | 33 -------------------------- src/declarativesplitter_p.h | 39 ------------------------------- src/declarativewidgets_plugin.cpp | 4 ++-- src/splitterwidgetcontainer.cpp | 2 -- src/src.pro | 6 ++--- 5 files changed, 4 insertions(+), 80 deletions(-) delete mode 100644 src/declarativesplitter.cpp delete mode 100644 src/declarativesplitter_p.h diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp deleted file mode 100644 index 25fccd4..0000000 --- a/src/declarativesplitter.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - declarativesplitter.cpp - - This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - - Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Lova Widmark - - Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in - accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. - - Contact info@kdab.com if any conditions of this licensing are not clear to you. - - 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, see . -*/ - -#include "declarativesplitter_p.h" - -DeclarativeSplitter::DeclarativeSplitter(QWidget *parent) - : QSplitter(parent) -{ -} diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h deleted file mode 100644 index c5cc58b..0000000 --- a/src/declarativesplitter_p.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - declarativesplitter_p.h - - This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - - Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Lova Widmark - - Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in - accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. - - Contact info@kdab.com if any conditions of this licensing are not clear to you. - - 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, see . -*/ - -#ifndef DECLARATIVESPLITTER_P_H -#define DECLARATIVESPLITTER_P_H - -#include - -class DeclarativeSplitter : public QSplitter -{ - public: - DeclarativeSplitter(QWidget *parent = Q_NULLPTR); -}; - -#endif // DECLARATIVESPLITTER_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 4e474e8..47b836b 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -54,7 +54,6 @@ #include "declarativeseparator_p.h" #include "declarativesizepolicy_p.h" #include "declarativespaceritem_p.h" -#include "declarativesplitter_p.h" #include "declarativestackedlayout_p.h" #include "declarativestatusbar_p.h" #include "declarativestringlistmodelextension_p.h" @@ -100,6 +99,7 @@ #include #include #include +#include #include #include #include @@ -208,5 +208,5 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "WebEngineView"); #endif qmlRegisterExtendedType(uri, 1, 0, "Widget"); - qmlRegisterExtendedType>(uri, 1, 0, "Splitter"); + qmlRegisterExtendedType>(uri, 1, 0, "Splitter"); } diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp index 8bc1f24..fecc4e7 100644 --- a/src/splitterwidgetcontainer.cpp +++ b/src/splitterwidgetcontainer.cpp @@ -27,8 +27,6 @@ #include "splitterwidgetcontainer_p.h" -#include "declarativesplitter_p.h" - #include #include diff --git a/src/src.pro b/src/src.pro index d535780..81ad2b4 100644 --- a/src/src.pro +++ b/src/src.pro @@ -87,8 +87,7 @@ HEADERS = \ toolbarwidgetcontainer_p.h \ widgetcontainerinterface_p.h \ declarativesizepolicy_p.h \ - splitterwidgetcontainer_p.h \ - declarativesplitter_p.h + splitterwidgetcontainer_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -140,5 +139,4 @@ SOURCES = \ staticdialogmethodattached.cpp \ toolbarwidgetcontainer.cpp \ declarativesizepolicy.cpp \ - splitterwidgetcontainer.cpp \ - declarativesplitter.cpp + splitterwidgetcontainer.cpp From 5739971c1a29c5b2e602d6c42ffa2e7cc10c03c3 Mon Sep 17 00:00:00 2001 From: Znurre Date: Thu, 29 Mar 2018 17:29:39 +0200 Subject: [PATCH 12/13] Rework DeclarativePushButton into an extension class --- ...=> declarativeabstractbuttonextension.cpp} | 9 +-- ...=> declarativeabstractbuttonextension_p.h} | 21 +++---- src/declarativepushbuttonextension.cpp | 61 +++++++++++++++++++ src/declarativepushbuttonextension_p.h | 56 +++++++++++++++++ src/declarativewidgets_plugin.cpp | 4 +- src/src.pro | 6 +- 6 files changed, 138 insertions(+), 19 deletions(-) rename src/{declarativepushbutton.cpp => declarativeabstractbuttonextension.cpp} (77%) rename src/{declarativepushbutton_p.h => declarativeabstractbuttonextension_p.h} (68%) create mode 100644 src/declarativepushbuttonextension.cpp create mode 100644 src/declarativepushbuttonextension_p.h diff --git a/src/declarativepushbutton.cpp b/src/declarativeabstractbuttonextension.cpp similarity index 77% rename from src/declarativepushbutton.cpp rename to src/declarativeabstractbuttonextension.cpp index e99cf5e..195cbb2 100644 --- a/src/declarativepushbutton.cpp +++ b/src/declarativeabstractbuttonextension.cpp @@ -1,9 +1,9 @@ /* - declarativepushbutton.cpp + declarativeabstractbuttonextension.cpp This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in @@ -25,8 +25,9 @@ along with this program. If not, see . */ -#include "declarativepushbutton_p.h" +#include "declarativeabstractbuttonextension_p.h" -DeclarativePushButton::DeclarativePushButton(QWidget *parent) : QPushButton(parent) +DeclarativeAbstractButtonExtension::DeclarativeAbstractButtonExtension(QObject *parent) + : DeclarativeWidgetExtension(parent) { } diff --git a/src/declarativepushbutton_p.h b/src/declarativeabstractbuttonextension_p.h similarity index 68% rename from src/declarativepushbutton_p.h rename to src/declarativeabstractbuttonextension_p.h index a33a66f..5177d33 100644 --- a/src/declarativepushbutton_p.h +++ b/src/declarativeabstractbuttonextension_p.h @@ -1,9 +1,9 @@ /* - declarativepushbutton_p.h + declarativeabstractbuttonextension_p.h This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in @@ -25,18 +25,17 @@ along with this program. If not, see . */ -#ifndef DECLARATIVEPUSHBUTTON_P_H -#define DECLARATIVEPUSHBUTTON_P_H +#ifndef DECLARATIVEABSTRACTBUTTONEXTENSION_P_H +#define DECLARATIVEABSTRACTBUTTONEXTENSION_P_H -#include +#include "declarativewidgetextension.h" -class DeclarativePushButton : public QPushButton +class DeclarativeAbstractButtonExtension : public DeclarativeWidgetExtension { - Q_OBJECT - Q_PROPERTY(bool isDefault READ isDefault WRITE setDefault) + Q_OBJECT - public: - explicit DeclarativePushButton(QWidget *parent = 0); +public: + explicit DeclarativeAbstractButtonExtension(QObject *parent = Q_NULLPTR); }; -#endif // DECLARATIVEPUSHBUTTON_P_H +#endif // DECLARATIVEABSTRACTBUTTONEXTENSION_P_H diff --git a/src/declarativepushbuttonextension.cpp b/src/declarativepushbuttonextension.cpp new file mode 100644 index 0000000..25a6132 --- /dev/null +++ b/src/declarativepushbuttonextension.cpp @@ -0,0 +1,61 @@ +/* + declarativepushbuttonextension.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#include "declarativepushbuttonextension_p.h" + +#include + +DeclarativePushButtonExtension::DeclarativePushButtonExtension(QObject *parent) + : DeclarativeAbstractButtonExtension(parent) +{ +} + +bool DeclarativePushButtonExtension::isDefault() const +{ + return pushButton()->isDefault(); +} + +void DeclarativePushButtonExtension::setIsDefault(bool isDefault) +{ + QPushButton *button = pushButton(); + + if (button->isDefault() == isDefault) + return; + + button->setDefault(isDefault); + + emit isDefaultChanged(); +} + +QPushButton *DeclarativePushButtonExtension::pushButton() const +{ + QPushButton *pushButton = qobject_cast(extendedObject()); + + Q_ASSERT(pushButton); + + return pushButton; +} diff --git a/src/declarativepushbuttonextension_p.h b/src/declarativepushbuttonextension_p.h new file mode 100644 index 0000000..d2f566e --- /dev/null +++ b/src/declarativepushbuttonextension_p.h @@ -0,0 +1,56 @@ +/* + declarativepushbuttonextension_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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, see . +*/ + +#ifndef DECLARATIVEPUSHBUTTONEXTENSION_P_H +#define DECLARATIVEPUSHBUTTONEXTENSION_P_H + +#include "declarativeabstractbuttonextension_p.h" + +QT_BEGIN_NAMESPACE +class QPushButton; +QT_END_NAMESPACE + +class DeclarativePushButtonExtension : public DeclarativeAbstractButtonExtension +{ + Q_OBJECT + + Q_PROPERTY(bool isDefault READ isDefault WRITE setIsDefault NOTIFY isDefaultChanged) + +public: + explicit DeclarativePushButtonExtension(QObject *parent = Q_NULLPTR); + + bool isDefault() const; + void setIsDefault(bool isDefault); + +Q_SIGNALS: + void isDefaultChanged(); + +private: + QPushButton *pushButton() const; +}; + +#endif // DECLARATIVEPUSHBUTTONEXTENSION_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 1202222..f8bc35d 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -48,6 +48,7 @@ #include "declarativeline_p.h" #include "declarativeloaderwidget_p.h" #include "declarativemessagebox_p.h" +#include "declarativepushbuttonextension_p.h" #include "declarativeqmlcontext_p.h" #include "declarativequickwidgetextension_p.h" #include "declarativeseparator_p.h" @@ -69,7 +70,6 @@ #include "scrollareawidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" -#include "declarativepushbutton_p.h" #include #include @@ -182,7 +182,7 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "MessageBox"); qmlRegisterExtendedType(uri, 1, 0, "PlainTextEdit"); qmlRegisterExtendedType(uri, 1, 0, "ProgressBar"); - qmlRegisterExtendedType(uri, 1, 0, "PushButton"); + qmlRegisterExtendedType(uri, 1, 0, "PushButton"); qmlRegisterExtendedType(uri, 1, 0, "RadioButton"); qmlRegisterExtendedType >(uri, 1, 0, "ScrollArea"); qmlRegisterExtendedType(uri, 1, 0, "ScrollBar"); diff --git a/src/src.pro b/src/src.pro index 015f00a..dc8b562 100644 --- a/src/src.pro +++ b/src/src.pro @@ -87,7 +87,8 @@ HEADERS = \ toolbarwidgetcontainer_p.h \ widgetcontainerinterface_p.h \ declarativesizepolicy_p.h \ - declarativepushbutton_p.h + declarativeabstractbuttonextension_p.h \ + declarativepushbuttonextension_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -139,4 +140,5 @@ SOURCES = \ staticdialogmethodattached.cpp \ toolbarwidgetcontainer.cpp \ declarativesizepolicy.cpp \ - declarativepushbutton.cpp + declarativeabstractbuttonextension.cpp \ + declarativepushbuttonextension.cpp From 8ee2dfd39f34c29f1b5351e4ea79abc947530592 Mon Sep 17 00:00:00 2001 From: Znurre Date: Sun, 18 Feb 2018 19:31:47 +0100 Subject: [PATCH 13/13] Have created loader items inherit the parent context --- src/declarativeloaderwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarativeloaderwidget.cpp b/src/declarativeloaderwidget.cpp index 55c7f7b..cd25348 100644 --- a/src/declarativeloaderwidget.cpp +++ b/src/declarativeloaderwidget.cpp @@ -114,7 +114,7 @@ void DeclarativeLoaderWidget::onStatusChanged() return; } - QObject *object = d->component->create(); + QObject *object = d->component->create(qmlContext(this)); if (!object) { qWarning() << "Unable to create component from" << d->source; return;