diff --git a/Mainpage.dox b/Mainpage.dox --- a/Mainpage.dox +++ b/Mainpage.dox @@ -44,6 +44,7 @@ - \link org::kde::kirigami::AbstractListItem AbstractListItem \endlink - \link org::kde::kirigami::ApplicationHeader ApplicationHeader \endlink - \link org::kde::kirigami::BasicListItem BasicListItem \endlink +- \link org::kde::kirigami::ListSectionHeader ListSectionHeader \endlink - \link org::kde::kirigami::SwipeListItem SwipeListItem \endlink - \link org::kde::kirigami::Heading Heading \endlink - \link org::kde::kirigami::Label Label \endlink diff --git a/kirigami.qrc.in b/kirigami.qrc.in --- a/kirigami.qrc.in +++ b/kirigami.qrc.in @@ -73,6 +73,7 @@ @kirigami_QML_DIR@/src/controls/LinkButton.qml @kirigami_QML_DIR@/src/controls/Label.qml @kirigami_QML_DIR@/src/controls/BasicListItem.qml + @kirigami_QML_DIR@/src/controls/ListSectionHeader.qml @kirigami_QML_DIR@/src/controls/AbstractApplicationHeader.qml @kirigami_QML_DIR@/src/controls/FormLayout.qml @kirigami_QML_DIR@/src/controls/ListItemDragHandle.qml diff --git a/src/controls/ListSectionHeader.qml b/src/controls/ListSectionHeader.qml new file mode 100644 --- /dev/null +++ b/src/controls/ListSectionHeader.qml @@ -0,0 +1,80 @@ +/* + * Copyright 2019 Björn Feber + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. + */ + +import QtQuick 2.5 +import QtQuick.Layouts 1.2 +import QtQuick.Controls 2.5 as QQC2 +import org.kde.kirigami 2.10 + +/** + * A section delegate for the primitive ListView component. + * + * It's intended to make all listviews look coherent. + * + * Example usage: + * @code + * import QtQuick 2.5 + * import QtQuick.Controls 2.5 as QQC2 + * + * import org.kde.kirigami 2.10 as Kirigami + * + * ListView { + * [...] + * section.delegate: Kirigami.ListSectionHeader { + * label: section + * + * QQC2.Button { + * text: "Button 1" + * } + * QQC2.Button { + * text: "Button 2" + * } + * } + * [...] + * } + * @endcode + * + */ +AbstractListItem { + id: listSection + + /** + * string: bool + * A single text label the list section header will contain + */ + property alias label: listSection.text + + default property alias _contents: rowLayout.data + + backgroundColor: Theme.alternateBackgroundColor + separatorVisible: false + sectionDelegate: true + hoverEnabled: false + supportsMouseEvents: false + + contentItem: RowLayout { + id: rowLayout + + Heading { + level: 3 + text: listSection.text + Layout.fillWidth: true + } + } +} diff --git a/src/controls/plugins.qmltypes b/src/controls/plugins.qmltypes --- a/src/controls/plugins.qmltypes +++ b/src/controls/plugins.qmltypes @@ -524,6 +524,25 @@ Property { name: "containsMouse"; type: "bool"; isReadonly: true } Property { name: "_default"; type: "QQuickItem"; isPointer: true } } + Component { + prototype: "QQuickItemDelegate" + name: "org.kde.kirigami/ListSectionHeader 2.10" + exports: ["org.kde.kirigami/ListSectionHeader 2.10"] + exportMetaObjectRevisions: [0] + isComposite: true + defaultProperty: "_contents" + Property { name: "label"; type: "string" } + Property { name: "_contents"; type: "QQuickItem"; isList: true; isReadonly: true } + Property { name: "supportsMouseEvents"; type: "bool" } + Property { name: "sectionDelegate"; type: "bool" } + Property { name: "separatorVisible"; type: "bool" } + Property { name: "textColor"; type: "QColor" } + Property { name: "backgroundColor"; type: "QColor" } + Property { name: "activeTextColor"; type: "QColor" } + Property { name: "activeBackgroundColor"; type: "QColor" } + Property { name: "containsMouse"; type: "bool"; isReadonly: true } + Property { name: "_default"; type: "QQuickItem"; isPointer: true } + } Component { prototype: "QQuickItem" name: "QtQuick.Controls.Material.impl/BoxShadow 2.0" diff --git a/src/kirigamiplugin.cpp b/src/kirigamiplugin.cpp --- a/src/kirigamiplugin.cpp +++ b/src/kirigamiplugin.cpp @@ -193,6 +193,9 @@ qmlRegisterType(uri, 2, 9, "WheelHandler"); qmlRegisterUncreatableType(uri, 2, 9, "WheelEvent", QStringLiteral("Cannot create objects of type WheelEvent.")); + //2.10 + qmlRegisterType(componentUrl(QStringLiteral("ListSectionHeader.qml")), uri, 2, 10, "ListSectionHeader"); + qmlProtectModule(uri, 2); } diff --git a/src/qmldir b/src/qmldir --- a/src/qmldir +++ b/src/qmldir @@ -50,3 +50,4 @@ ActionTextField 2.7 ActionTextField.qml SearchField 2.8 SearchField.qml PasswordField 2.8 PasswordField.qml +ListSectionHeader 2.10 ListSectionHeader.qml