diff --git a/src/qmlcontrols/kcmcontrols/qml/ScrollViewKCM.qml b/src/qmlcontrols/kcmcontrols/qml/ScrollViewKCM.qml --- a/src/qmlcontrols/kcmcontrols/qml/ScrollViewKCM.qml +++ b/src/qmlcontrols/kcmcontrols/qml/ScrollViewKCM.qml @@ -56,18 +56,28 @@ //NOTE: this should be smallspacing buit we need a pixel size in order to align with systemsettings widgets leftPadding: Kirigami.Settings.isMobile ? 0 : 4 - topPadding: headerParent.contentItem ? 0 : leftPadding - rightPadding: leftPadding - bottomPadding: footerParent.contentItem ? 0 : leftPadding + topPadding: headerParent.contentItem ? 0 : (Kirigami.Settings.isMobile ? 0 : 4) + rightPadding: (Kirigami.Settings.isMobile ? 0 : 4) + bottomPadding: footerParent.contentItem ? 0 : (Kirigami.Settings.isMobile ? 0 : 4) header: QtControls.Control { id: headerParent - padding: 4 + visible: contentItem && contentItem.visible + height: visible ? implicitHeight : 0 + leftPadding: 4 + topPadding: 4 + rightPadding: 4 + bottomPadding: 4 } footer: QtControls.Control { id: footerParent - padding: 4 + visible: contentItem && contentItem.visible + height: visible ? implicitHeight : 0 + leftPadding: 4 + topPadding: 4 + rightPadding: 4 + bottomPadding: 4 } Component.onCompleted: { if (footer && footer != footerParent) { @@ -80,12 +90,12 @@ } if (header && header != headerParent) { - var f = header + var h = header - headerParent.contentItem = f + headerParent.contentItem = h header = headerParent - f.visible = true - f.parent = headerParent + h.visible = true + h.parent = headerParent } } Priv.ScrollView { diff --git a/src/qmlcontrols/kcmcontrols/qml/SimpleKCM.qml b/src/qmlcontrols/kcmcontrols/qml/SimpleKCM.qml --- a/src/qmlcontrols/kcmcontrols/qml/SimpleKCM.qml +++ b/src/qmlcontrols/kcmcontrols/qml/SimpleKCM.qml @@ -17,6 +17,7 @@ */ import QtQuick 2.7 +import QtQuick.Controls 2.2 as QtControls import org.kde.kirigami 2.2 as Kirigami import org.kde.kcm 1.1 as KCM @@ -49,6 +50,51 @@ implicitWidth: Kirigami.Units.gridUnit * 20 implicitHeight: Math.min(flickable.contentHeight, Kirigami.Units.gridUnit * 20) + leftPadding: Kirigami.Settings.isMobile ? 0 : 4 + topPadding: headerParent.contentItem ? 0 : (Kirigami.Settings.isMobile ? 0 : 4) + rightPadding: (Kirigami.Settings.isMobile ? 0 : 4) + bottomPadding: footerParent.contentItem ? 0 : (Kirigami.Settings.isMobile ? 0 : 4) + + header: QtControls.Control { + id: headerParent + visible: contentItem && contentItem.visible + height: visible ? implicitHeight : 0 + leftPadding: 4 + topPadding: 4 + rightPadding: 4 + bottomPadding: 4 + } + + footer: QtControls.Control { + id: footerParent + visible: contentItem && contentItem.visible + height: visible ? implicitHeight : 0 + leftPadding: 4 + topPadding: 4 + rightPadding: 4 + bottomPadding: 4 + } + + Component.onCompleted: { + if (footer && footer != footerParent) { + var f = footer + + footerParent.contentItem = f + footer = footerParent + f.visible = true + f.parent = footerParent + } + + if (header && header != headerParent) { + var h = header + + headerParent.contentItem = h + header = headerParent + h.visible = true + h.parent = headerParent + } + } + children: [ Kirigami.Separator { z: 999 diff --git a/src/quickaddons/configmodule.h b/src/quickaddons/configmodule.h --- a/src/quickaddons/configmodule.h +++ b/src/quickaddons/configmodule.h @@ -148,6 +148,8 @@ Q_PROPERTY(bool useRootOnlyMessage READ useRootOnlyMessage WRITE setUseRootOnlyMessage NOTIFY useRootOnlyMessageChanged) Q_PROPERTY(bool needsAuthorization READ needsAuthorization WRITE setNeedsAuthorization NOTIFY needsAuthorizationChanged) Q_PROPERTY(int columnWidth READ columnWidth WRITE setColumnWidth NOTIFY columnWidthChanged) + Q_PROPERTY(int depth READ depth NOTIFY depthChanged) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) public: @@ -402,6 +404,24 @@ */ void setColumnWidth(int width); + /** + * @returns how many pages this kcm has. + * It is guaranteed to be at least 1 9the main ui) plus how many times a new page has been pushed without pop + */ + int depth() const; + + /** + * Sets the current page index this kcm should display + * @since 5.53 + */ + void setCurrentIndex(int index); + + /** + * @returns the index of the page this kcm should display + * @since 5.53 + */ + int currentIndex() const; + static ConfigModule *qmlAttachedProperties(QObject *object); public Q_SLOTS: @@ -450,6 +470,11 @@ */ void push(const QString &fileName, const QVariantMap &propertyMap = QVariantMap()); + /** + * + */ + void push(QQuickItem *item); + /** * pop the last page of the KCM hyerarchy * @since 5.50 @@ -525,6 +550,18 @@ */ void columnWidthChanged(int width); + /** + * Emitted when the current page changed + * @since 5.53 + */ + void currentIndexChanged(int index); + + /** + * Emitted when the number of pages changed + * @since 5.53 + */ + void depthChanged(int index); + private: ConfigModulePrivate *const d; }; diff --git a/src/quickaddons/configmodule.cpp b/src/quickaddons/configmodule.cpp --- a/src/quickaddons/configmodule.cpp +++ b/src/quickaddons/configmodule.cpp @@ -68,6 +68,7 @@ QString _quickHelp; QList subPages; int _columnWidth = -1; + int currentIndex = 0; bool _useRootOnlyMessage : 1; bool _needsAuthorization : 1; @@ -190,7 +191,7 @@ package.setDefaultPackageRoot(QStringLiteral("kpackage/kcms")); package.setPath(aboutData()->componentName()); - QObject *object = d->_qmlObject->createObjectFromSource(QUrl::fromLocalFile(package.filePath("ui", fileName)), d->_qmlObject->rootContext());//TODO:propertyMap + QObject *object = d->_qmlObject->createObjectFromSource(QUrl::fromLocalFile(package.filePath("ui", fileName)), QQmlEngine::contextForObject(d->_qmlObject->rootObject())/*d->_qmlObject->rootContext()*/);//TODO:propertyMap QQuickItem *item = qobject_cast(object); if (!item) { @@ -200,6 +201,21 @@ d->subPages << item; emit pagePushed(item); + emit depthChanged(depth()); + setCurrentIndex(d->currentIndex + 1); +} + +void ConfigModule::push(QQuickItem *item) +{ + //ensure main ui is created + if (!mainUi()) { + return; + } + + d->subPages << item; + emit pagePushed(item); + emit depthChanged(depth()); + setCurrentIndex(d->currentIndex + 1); } void ConfigModule::pop() @@ -209,7 +225,10 @@ } QQuickItem *page = d->subPages.takeLast(); emit pageRemoved(); + emit depthChanged(depth()); page->deleteLater(); + + setCurrentIndex(qMin(d->currentIndex, depth() - 1)); } ConfigModule::Buttons ConfigModule::buttons() const @@ -276,6 +295,27 @@ emit columnWidthChanged(width); } +int ConfigModule::depth() const +{ + return d->subPages.count() + 1; +} + +void ConfigModule::setCurrentIndex(int index) +{ + if (index < 0 || index > d->subPages.count() || index == d->currentIndex) { + return; + } + + d->currentIndex = index; + + emit currentIndexChanged(index); +} + +int ConfigModule::currentIndex() const +{ + return d->currentIndex; +} + void ConfigModule::setAuthActionName(const QString &name) { if (d->_authActionName == name) {