diff --git a/src/qmlcontrols/kcmcontrols/qml/Tab.qml b/src/qmlcontrols/kcmcontrols/qml/Tab.qml new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/qml/Tab.qml @@ -0,0 +1,29 @@ +/* + Copyright (c) 2019 Nicolas Fella + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.7 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.2 as QtControls +import org.kde.kirigami 2.2 as Kirigami +import org.kde.kcm 1.1 as KCM +import "." as Priv + +Item { + property string title + property var delegate +} diff --git a/src/qmlcontrols/kcmcontrols/qml/TabKCM.qml b/src/qmlcontrols/kcmcontrols/qml/TabKCM.qml new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/qml/TabKCM.qml @@ -0,0 +1,163 @@ +/* + Copyright (c) 2017 Marco Martin + Copyright (c) 2019 Nicolas Fella + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.7 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.2 as QtControls +import org.kde.kirigami 2.2 as Kirigami +import "." as Priv + +/** + * This component is intended to be used for tabbed settings pages. + * @code + * import org.kde.kcm 1.3 as KCM + * KCM.TabKCM { + * tabs: [tab1, tab2] + * + * KCM.KCMTab { + * id: tab1 + * title: "Tab 1" + * delegate: Component { + * SomeItem { + * Layout.fillWidth: true + * Layout.fillHeight: true + * } + * } + * } + * + * KCM.KCMTab { + * id: tab2 + * title: "Tab 2" + * delegate: Component { + * SomeOtherItem { + * Layout.fillWidth: true + * Layout.fillHeight: true + * } + * } + * } + * } + * @endcode + * @inherits org.kde.kirigami.Page + */ +Kirigami.Page { + id: root + + property alias view: scroll.view + + property var tabs: [] + + title: kcm.name + implicitWidth: Kirigami.Units.gridUnit * 20 + implicitHeight: view && view.contentHeight > 0 ? Math.min(view.contentHeight, Kirigami.Units.gridUnit * 20) : Kirigami.Units.gridUnit * 20 + + //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 : (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: root.contentItem && root.contentItem.visible + height: visible ? implicitHeight : 0 + leftPadding: 4 + topPadding: 4 + rightPadding: 4 + bottomPadding: 4 + } + + ColumnLayout { + + anchors.fill: parent + spacing: 0 + + QtControls.TabBar { + id: tabView + Layout.leftMargin: 1 + Layout.bottomMargin: -2 + z: 1 + + Repeater { + id: tabsRepeater + + delegate: QtControls.TabButton { + text: modelData + } + } + } + + Item { + Layout.fillWidth: true + Layout.fillHeight: true + + + Priv.ScrollView { + id: scroll + anchors.fill: parent + + } + + StackLayout { + id: sl + anchors.fill: parent + + currentIndex: tabView.currentIndex + } + } + } + + footer: QtControls.Control { + id: footerParent + visible: root.contentItem && root.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 + } + + var theTabs = [] + var i = 0 + + for( i=0; i < tabs.length; i++) { + tabs[i].delegate.createObject(sl, {}) + theTabs.push(tabs[i].title) + } + tabsRepeater.model = theTabs + } +} diff --git a/src/qmlcontrols/kcmcontrols/qml/qmldir b/src/qmlcontrols/kcmcontrols/qml/qmldir --- a/src/qmlcontrols/kcmcontrols/qml/qmldir +++ b/src/qmlcontrols/kcmcontrols/qml/qmldir @@ -7,3 +7,5 @@ ScrollView 1.2 ScrollView.qml ScrollViewKCM 1.2 ScrollViewKCM.qml SimpleKCM 1.1 SimpleKCM.qml +TabKCM 1.3 TabKCM.qml +Tab 1.3 Tab.qml