Commit 7d87b82c authored by Nicolas Fella's avatar Nicolas Fella Committed by Han Young
Browse files

Introduce WeatherStrip component

Removes some code duplication
parent b76593d1
......@@ -131,24 +131,10 @@ Kirigami.ScrollablePage {
shadow.color: Qt.rgba(0.0, 0.0, 0.0, 0.15)
shadow.yOffset: Kirigami.Units.devicePixelRatio * 2
}
// detect mouse hover
HoverHandler {
id: dayMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
contentItem: ListView {
orientation: ListView.Horizontal
contentItem: WeatherStrip {
id: dailyListView
Layout.fillWidth: true
implicitHeight: Kirigami.Units.gridUnit * 8
spacing: Kirigami.Units.largeSpacing
clip: true
snapMode: ListView.SnapToItem
highlightMoveDuration: 400
highlightMoveVelocity: -1
highlight: Rectangle {
......@@ -162,47 +148,13 @@ Kirigami.ScrollablePage {
focus: true
}
currentIndex: 0
spacing: Kirigami.Units.largeSpacing
model: weatherLocation.dayForecasts
delegate: WeatherDayDelegate {
weather: modelData
textColor: weatherLocation.cardTextColor
}
// left right mouse controls
Button {
icon.name: "arrow-left"
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
visible: (dayMouseArea.hovered || leftMouseArea.hovered) && dailyListView.currentIndex != 0
onClicked: {
if (dailyListView.currentIndex > 0) {
dailyListView.currentIndex--;
weatherLocation.hourListModel.updateHourView(dailyListView.currentIndex);
}
}
HoverHandler {
id: leftMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
}
Button {
icon.name: "arrow-right"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
visible: (dayMouseArea.hovered || rightMouseArea.hovered) && dailyListView.currentIndex != dailyListView.count - 1
onClicked: {
if (dailyListView.currentIndex < dailyListView.count-1) {
dailyListView.currentIndex++;
weatherLocation.hourListModel.updateHourView(dailyListView.currentIndex);
}
}
HoverHandler {
id: rightMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
}
}
}
......@@ -246,59 +198,13 @@ Kirigami.ScrollablePage {
shadow.yOffset: Kirigami.Units.devicePixelRatio * 2
}
// detect mouse hover
HoverHandler {
id: hourMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
contentItem: ListView {
id: weatherHourListView
orientation: ListView.Horizontal
implicitHeight: contentItem.childrenRect.height
spacing: Kirigami.Units.largeSpacing * 3
clip: true
snapMode: ListView.SnapToItem
contentItem: WeatherStrip {
model: weatherLocation.hourListModel
delegate: WeatherHourDelegate {
weather: hourItem
textColor: weatherLocation.cardTextColor
}
// left right mouse controls
Button {
id: control
icon.name: "arrow-left"
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
visible: hourMouseArea.hovered && weatherHourListView.contentX != 0
SmoothedAnimation {
target: weatherHourListView
property: "contentX"
running: control.pressed
to: 0
velocity: 500
maximumEasingTime: 0
}
}
Button {
id: control2
icon.name: "arrow-right"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
visible: hourMouseArea.hovered && weatherHourListView.contentX != weatherHourListView.contentWidth - weatherHourListView.width
SmoothedAnimation {
target: weatherHourListView
property: "contentX"
running: control2.pressed
to: weatherHourListView.contentWidth - weatherHourListView.width
velocity: 500
maximumEasingTime: 0
}
}
}
}
......
......@@ -98,17 +98,12 @@ Kirigami.ScrollablePage {
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.largeSpacing * 2
}
ListView {
orientation: ListView.Horizontal
id: dailyListView
WeatherStrip {
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.largeSpacing * 2
implicitHeight: Kirigami.Units.gridUnit * 8
spacing: Kirigami.Units.largeSpacing
clip: true
snapMode: ListView.SnapToItem
highlightMoveDuration: 400
highlightMoveVelocity: -1
......@@ -123,51 +118,11 @@ Kirigami.ScrollablePage {
focus: true
}
currentIndex: 0
model: weatherLocation.dayForecasts
delegate: WeatherDayDelegate {
weather: modelData
textColor: Kirigami.Theme.textColor
}
// left right mouse controls
HoverHandler {
id: dayMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
Button {
icon.name: "arrow-left"
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
visible: (dayMouseArea.hovered || leftMouseArea.hovered) && dailyListView.currentIndex != 0
onClicked: {
if (dailyListView.currentIndex > 0) {
dailyListView.currentIndex--;
weatherLocation.hourListModel.updateHourView(dailyListView.currentIndex);
}
}
HoverHandler {
id: leftMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
}
Button {
icon.name: "arrow-right"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
visible: (dayMouseArea.hovered || rightMouseArea.hovered) && dailyListView.currentIndex != dailyListView.count - 1
onClicked: {
if (dailyListView.currentIndex < dailyListView.count-1) {
dailyListView.currentIndex++;
weatherLocation.hourListModel.updateHourView(dailyListView.currentIndex);
}
}
HoverHandler {
id: rightMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
}
}
// hourly view
......@@ -180,60 +135,18 @@ Kirigami.ScrollablePage {
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.largeSpacing * 2
}
ListView {
id: weatherHourListView
orientation: ListView.Horizontal
Layout.topMargin: Kirigami.Units.largeSpacing * 2
WeatherStrip {
implicitHeight: Kirigami.Units.gridUnit * 10.5
implicitWidth: parent.width
spacing: Kirigami.Units.largeSpacing * 3
clip: true
snapMode: ListView.SnapToItem
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.largeSpacing * 2
model: weatherLocation.hourListModel
delegate: WeatherHourDelegate {
weather: hourItem
textColor: Kirigami.Theme.textColor
}
// left right mouse controls
HoverHandler {
id: hourMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
textColor: weatherLocation.cardTextColor
}
Button {
id: control
icon.name: "arrow-left"
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
visible: hourMouseArea.hovered && weatherHourListView.contentX != 0
SmoothedAnimation {
target: weatherHourListView
property: "contentX"
running: control.pressed
to: 0
velocity: 500
maximumEasingTime: 0
}
}
Button {
id: control2
icon.name: "arrow-right"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
visible: hourMouseArea.hovered && weatherHourListView.contentX != weatherHourListView.contentWidth - weatherHourListView.width
SmoothedAnimation {
target: weatherHourListView
property: "contentX"
running: control2.pressed
to: weatherHourListView.contentWidth - weatherHourListView.width
velocity: 500
maximumEasingTime: 0
}
}
}
InfoCard {
......
/*
* SPDX-FileCopyrightText: 2020 Han Young <hanyoung@protonmail.com>
* SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.2
import QtCharts 2.3
import org.kde.kirigami 2.13 as Kirigami
import kweather 1.0
import "backgrounds"
ListView {
id: root
orientation: ListView.Horizontal
implicitHeight: contentItem.childrenRect.height
spacing: Kirigami.Units.largeSpacing * 3
clip: true
snapMode: ListView.SnapToItem
// detect mouse hover
HoverHandler {
id: hourMouseArea
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
}
// left right mouse controls
Button {
id: control
icon.name: "arrow-left"
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
visible: hourMouseArea.hovered && root.contentX != 0
SmoothedAnimation {
target: root
property: "contentX"
running: control.pressed
to: 0
velocity: 500
maximumEasingTime: 0
}
}
Button {
id: control2
icon.name: "arrow-right"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
visible: hourMouseArea.hovered && root.contentX != root.contentWidth - root.width
SmoothedAnimation {
target: root
property: "contentX"
running: control2.pressed
to: root.contentWidth - root.width
velocity: 500
maximumEasingTime: 0
}
}
}
......@@ -23,6 +23,7 @@
<file>qml/TemperatureChartCard.qml</file>
<file>qml/SunriseCard.qml</file>
<file>qml/InfoCard.qml</file>
<file>qml/WeatherStrip.qml</file>
<file>qml/backgrounds/ClearDay.qml</file>
<file>qml/backgrounds/ClearNight.qml</file>
<file>qml/backgrounds/CloudyDay.qml</file>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment