diff --git a/kcmcontrols/GridView.qml b/kcmcontrols/GridView.qml new file mode 100644 index 000000000..c425478ad --- /dev/null +++ b/kcmcontrols/GridView.qml @@ -0,0 +1,66 @@ +/* + Copyright (c) 2017 Marco Martin + + 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.1 +import QtQuick.Controls 2.2 as QtControls +import org.kde.kirigami 2.3 as Kirigami +import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate + +QtControls.ScrollView { + id: scroll + property alias view: view + property int cellWidth: Math.min(Math.floor((parent.width - scrollBarSpace - 4) / 2), Kirigami.Units.gridUnit * 10) + property int cellHeight: cellWidth / 1.6 + Kirigami.Units.gridUnit + + readonly property int scrollBarSpace: Kirigami.Units.gridUnit + + implicitWidth: Math.max( Math.min(parent.width, cellWidth * 2 + scroll.scrollBarSpace) + , Math.floor(view.availableWidth / cellWidth) * cellWidth + scroll.scrollBarSpace + 4) + activeFocusOnTab: false + Kirigami.Theme.colorSet: Kirigami.Theme.View + Kirigami.Theme.inherit: false + + GridView { + id: view + property int availableWidth: scroll.parent.width - scroll.scrollBarSpace - 4 + anchors { + fill: parent + margins: 2 + leftMargin: contentHeight <= height ? scroll.scrollBarSpace/2 : 2 + rightMargin: contentHeight <= height ? scroll.scrollBarSpace/2 : scroll.scrollBarSpace + 2 + } + clip: true + activeFocusOnTab: true + cellWidth: scroll.cellWidth + cellHeight: scroll.cellHeight + keyNavigationEnabled: true + keyNavigationWraps: true + highlightMoveDuration: 0 + } + + background: StylePrivate.StyleItem { + id: style + control: scroll + elementType: "frame" + + sunken: true + hasFocus: scroll.activeFocus + hover: scroll.hovered + } +} diff --git a/kcmcontrols/GridViewPage.qml b/kcmcontrols/GridViewPage.qml index 37665da64..5a76f65d6 100644 --- a/kcmcontrols/GridViewPage.qml +++ b/kcmcontrols/GridViewPage.qml @@ -1,73 +1,48 @@ /* Copyright (c) 2017 Marco Martin 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.1 import QtQuick.Controls 2.2 as QtControls import org.kde.kirigami 2.2 as Kirigami +import org.kde.kcmcontrols 1.0 as KCMControls import org.kde.kcm 1.0 Kirigami.Page { id: root title: kcm.name implicitWidth: Kirigami.Units.gridUnit * 20 implicitHeight: Kirigami.Units.gridUnit * 20 - property alias view: view + property alias view: scroll.view topPadding: 0 leftPadding: 0 rightPadding: 0 bottomPadding: footer ? Kirigami.Units.smallSpacing : 0 - QtControls.ScrollView { + KCMControls.GridView { id: scroll - property int cellWidth: Kirigami.Units.gridUnit * 10 - property int scrollBarSpace: Kirigami.Units.gridUnit*2 anchors { top: parent.top bottom: parent.bottom horizontalCenter: parent.horizontalCenter } - width: Math.max( Math.min(root.width, cellWidth * 2 + scroll.scrollBarSpace) - , Math.floor((root.width - scroll.scrollBarSpace) / cellWidth) * cellWidth + scroll.scrollBarSpace) - activeFocusOnTab: false - - GridView { - id: view - anchors { - fill: parent - margins: scroll.background ? 2 : 0 - rightMargin: contentHeight > height ? Kirigami.Units.gridUnit : 2 - } - contentItem.x: Math.round((width - Math.floor(width / cellWidth) * cellWidth) / 2) - clip: true - activeFocusOnTab: true - cellWidth: Math.min(Math.floor(width / 2), scroll.cellWidth) - cellHeight: cellWidth / 1.6 + scroll.scrollBarSpace - keyNavigationEnabled: true - keyNavigationWraps: true - highlightMoveDuration: 0 - } - //not all styles have background defined - Component.onCompleted: { - background.visible = true; - } } } diff --git a/kcmcontrols/qmldir b/kcmcontrols/qmldir index 8b7a8cb12..a2ffae6c1 100644 --- a/kcmcontrols/qmldir +++ b/kcmcontrols/qmldir @@ -1,4 +1,5 @@ module org.kde.kcmcontrols GridDelegate 1.0 GridDelegate.qml GridViewPage 1.0 GridViewPage.qml +GridView 1.0 GridView.qml