mirror of https://github.com/cutefishos/launcher
Refactored ListView
parent
868545255b
commit
d8c07c7edb
@ -1,8 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>qml/main.qml</file>
|
||||
<file>qml/LauncherGridDelegate.qml</file>
|
||||
<file>qml/PageView.qml</file>
|
||||
<file>qml/LauncherGridView.qml</file>
|
||||
<file>qml/GridItemDelegate.qml</file>
|
||||
<file>qml/AllAppsView.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS.
|
||||
*
|
||||
* Author: Reoin Wong <reionwong@gmail.com>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import FishUI 1.0 as FishUI
|
||||
|
||||
import Cutefish.Launcher 1.0
|
||||
|
||||
ListView {
|
||||
id: control
|
||||
|
||||
property bool searchMode: false
|
||||
|
||||
property var sourceModel: launcherModel
|
||||
property var modelCount: sourceModel.count
|
||||
|
||||
property int iconSize: 128 + FishUI.Units.largeSpacing * 2
|
||||
property int cellWidth: iconSize + calcExtraSpacing(iconSize, control.width)
|
||||
property int cellHeight: iconSize + calcExtraSpacing(iconSize, control.height)
|
||||
|
||||
property int rows: control.width / control.cellWidth
|
||||
property int columns: control.height / control.cellHeight
|
||||
property int pageCount: control.rows * control.columns
|
||||
|
||||
orientation: ListView.Horizontal
|
||||
snapMode: ListView.SnapOneItem
|
||||
model: Math.ceil(control.modelCount / control.pageCount)
|
||||
|
||||
maximumFlickVelocity: 10000
|
||||
highlightMoveDuration: 100
|
||||
|
||||
preferredHighlightBegin: 0
|
||||
preferredHighlightEnd: 0
|
||||
highlightRangeMode: ListView.StrictlyEnforceRange
|
||||
highlightFollowsCurrentItem: true
|
||||
|
||||
cacheBuffer: control.width * control.count
|
||||
boundsBehavior: Flickable.DragOverBounds
|
||||
currentIndex: 0
|
||||
clip: true
|
||||
|
||||
NumberAnimation on contentX {
|
||||
id: scrollAnim
|
||||
|
||||
duration: 300
|
||||
easing.type: Easing.InOutQuad
|
||||
|
||||
onStopped: {
|
||||
var index = control.indexAt(control.contentX + control.width / 2,
|
||||
control.contentY + control.height / 2)
|
||||
if (index === -1)
|
||||
control.currentIndex = 0
|
||||
else
|
||||
control.currentIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
z: -1
|
||||
|
||||
onClicked: {
|
||||
launcher.hideWindow()
|
||||
}
|
||||
|
||||
onWheel: {
|
||||
if (wheel.angleDelta.y > 0)
|
||||
scrollPreviousPage()
|
||||
else
|
||||
scrollNextPage()
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Flow {
|
||||
id: _page
|
||||
width: control.width
|
||||
height: control.height
|
||||
|
||||
readonly property int pageIndex: index
|
||||
|
||||
move: Transition {
|
||||
NumberAnimation {
|
||||
properties: "x, y"
|
||||
duration: 300
|
||||
easing.type: Easing.InOutQuad
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: PageModel {
|
||||
id: _pageModel
|
||||
sourceModel: launcherModel
|
||||
startIndex: control.pageCount * _page.pageIndex
|
||||
limitCount: control.pageCount
|
||||
}
|
||||
|
||||
delegate: GridItemDelegate {
|
||||
searchMode: control.searchMode
|
||||
pageIndex: _page.pageIndex
|
||||
pageCount: control.pageCount
|
||||
width: control.cellWidth
|
||||
height: control.cellHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calcExtraSpacing(cellSize, containerSize) {
|
||||
var availableColumns = Math.floor(containerSize / cellSize)
|
||||
var extraSpacing = 0
|
||||
if (availableColumns > 0) {
|
||||
var allColumnSize = availableColumns * cellSize
|
||||
var extraSpace = Math.max(containerSize - allColumnSize, 0)
|
||||
extraSpacing = extraSpace / availableColumns
|
||||
}
|
||||
return Math.floor(extraSpacing)
|
||||
}
|
||||
|
||||
function scrollNextPage() {
|
||||
if (scrollAnim.running)
|
||||
return
|
||||
|
||||
if (currentIndex < count - 1) {
|
||||
scrollAnim.to = control.currentItem.x + control.width
|
||||
scrollAnim.restart()
|
||||
}
|
||||
}
|
||||
|
||||
function scrollPreviousPage() {
|
||||
if (scrollAnim.running)
|
||||
return
|
||||
|
||||
if (currentIndex > 0) {
|
||||
scrollAnim.to = control.currentItem.x - control.width
|
||||
scrollAnim.restart()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS.
|
||||
*
|
||||
* Author: revenmartin <revenmartin@gmail.com>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Window 2.12
|
||||
import FishUI 1.0 as FishUI
|
||||
import Cutefish.Launcher 1.0
|
||||
|
||||
PageView {
|
||||
id: control
|
||||
|
||||
property int iconSize: 128 + FishUI.Units.largeSpacing * 2
|
||||
|
||||
property int cellWidth: {
|
||||
var extraWidth = calcExtraSpacing(iconSize, control.width)
|
||||
return iconSize + extraWidth
|
||||
}
|
||||
|
||||
property int cellHeight: {
|
||||
var extraHeight = calcExtraSpacing(iconSize, control.height)
|
||||
return iconSize + extraHeight
|
||||
}
|
||||
|
||||
columns: control.width / cellWidth
|
||||
rows: control.height / cellHeight
|
||||
|
||||
model: launcherModel
|
||||
|
||||
delegate: Item {
|
||||
width: cellWidth
|
||||
height: cellHeight
|
||||
|
||||
LauncherGridDelegate {
|
||||
id: delegate
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
|
||||
function calcExtraSpacing(cellSize, containerSize) {
|
||||
var availableColumns = Math.floor(containerSize / cellSize);
|
||||
var extraSpacing = 0;
|
||||
if (availableColumns > 0) {
|
||||
var allColumnSize = availableColumns * cellSize;
|
||||
var extraSpace = Math.max(containerSize - allColumnSize, 0);
|
||||
extraSpacing = extraSpace / availableColumns;
|
||||
}
|
||||
return Math.floor(extraSpacing);
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS.
|
||||
*
|
||||
* Author: revenmartin <revenmartin@gmail.com>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick 2.12
|
||||
import Cutefish.Launcher 1.0
|
||||
|
||||
Item {
|
||||
id: pagedGrid
|
||||
|
||||
property var model
|
||||
|
||||
property int rows
|
||||
property int columns
|
||||
|
||||
property Component delegate
|
||||
|
||||
readonly property var count: model.count
|
||||
|
||||
readonly property int pageCount: rows * columns
|
||||
readonly property alias pages: pageView.count
|
||||
property alias currentPage: pageView.currentIndex
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
propagateComposedEvents: true
|
||||
|
||||
onWheel: {
|
||||
if (wheel.angleDelta.y > 0)
|
||||
pageView.decrementCurrentIndex();
|
||||
else
|
||||
pageView.incrementCurrentIndex();
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: pageView
|
||||
anchors.fill: parent
|
||||
|
||||
orientation: Qt.Horizontal
|
||||
snapMode: ListView.SnapOneItem
|
||||
highlightFollowsCurrentItem: true
|
||||
highlightRangeMode: ListView.StrictlyEnforceRange
|
||||
highlightMoveDuration: 500
|
||||
currentIndex: 0
|
||||
|
||||
maximumFlickVelocity: 9000
|
||||
|
||||
preferredHighlightBegin: 0
|
||||
preferredHighlightEnd: 0
|
||||
|
||||
cacheBuffer: pageView.width * pageView.count
|
||||
boundsBehavior: Flickable.DragOverBounds
|
||||
clip: true
|
||||
|
||||
// // Blank area
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
z: -1
|
||||
onClicked: launcher.hideWindow()
|
||||
}
|
||||
|
||||
model: Math.ceil(pagedGrid.count / pageCount)
|
||||
delegate: pageDelegate
|
||||
}
|
||||
|
||||
Component {
|
||||
id: pageDelegate
|
||||
|
||||
Flow {
|
||||
id: _page
|
||||
width: pagedGrid.width
|
||||
height: pagedGrid.height
|
||||
// columns: pagedGrid.columns
|
||||
|
||||
readonly property int pageIndex: index
|
||||
|
||||
// move: Transition {
|
||||
// NumberAnimation {
|
||||
// duration: 300
|
||||
// easing.type: Easing.InOutQuad
|
||||
// properties: "x,y"
|
||||
// }
|
||||
// }
|
||||
|
||||
Repeater {
|
||||
model: PageModel {
|
||||
id: _pageModel
|
||||
sourceModel: pagedGrid.model
|
||||
startIndex: pageCount * pageIndex
|
||||
limitCount: pageCount
|
||||
}
|
||||
|
||||
delegate: pagedGrid.delegate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue