1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 11:47:46 +00:00
astra/launcher/ui/Pages/NewsPage.qml

202 lines
5.4 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
2023-12-17 12:47:13 -05:00
pragma ComponentBehavior: Bound
2023-09-16 18:15:11 -04:00
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import QtQuick.Effects
2023-09-16 18:15:11 -04:00
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import zone.xiv.astra
QQC2.Control {
id: page
property int currentBannerIndex: 0
property int numBannerImages: 0
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
Component.onCompleted: LauncherCore.refreshNews()
Connections {
target: LauncherCore
function onNewsChanged(): void {
page.currentBannerIndex = 0
page.numBannerImages = LauncherCore.headline.banners.length
}
}
Timer {
interval: 10000
running: true
repeat: true
onTriggered: {
if (page.numBannerImages === 0) {
return;
}
if (page.currentBannerIndex + 1 === page.numBannerImages) {
page.currentBannerIndex = 0;
} else {
page.currentBannerIndex++;
}
}
}
background: Rectangle {
anchors.fill: parent
color: Kirigami.Theme.backgroundColor
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
}
contentItem: ColumnLayout {
id: layout
readonly property real maximumWidth: Kirigami.Units.gridUnit * 50
spacing: Kirigami.Units.largeSpacing
Image {
id: bannerImage
readonly property real aspectRatio: sourceSize.height / sourceSize.width
Layout.maximumWidth: layout.maximumWidth
Layout.fillWidth: true
Layout.preferredHeight: aspectRatio * width
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
Layout.topMargin: Kirigami.Units.largeSpacing
source: {
if (LauncherCore.headline === null) {
return "";
}
if (page.numBannerImages === 0) {
return "";
}
return LauncherCore.headline.banners[page.currentBannerIndex].bannerImage;
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
2023-08-18 22:13:41 -04:00
hoverEnabled: true
onClicked: applicationWindow().openUrl(LauncherCore.headline.banners[page.currentBannerIndex].link)
}
layer.enabled: !(bannerImage.width < layout.maximumWidth)
layer.effect: MultiEffect {
id: root
maskEnabled: true
maskSpreadAtMax: 1
maskSpreadAtMin: 1
maskThresholdMin: 0.5
maskSource: ShaderEffectSource {
sourceItem: Rectangle {
width: root.width
height: root.height
radius: Kirigami.Units.mediumSpacing
}
}
}
}
FormCard.FormHeader {
title: i18n("News")
Layout.fillWidth: true
maximumWidth: layout.maximumWidth
}
FormCard.FormCard {
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
maximumWidth: layout.maximumWidth
visible: LauncherCore.headline !== null
Repeater {
model: LauncherCore.headline !== null ? LauncherCore.headline.news : undefined
FormCard.FormButtonDelegate {
2023-12-17 12:47:13 -05:00
required property var modelData
text: modelData.title
description: Qt.formatDate(modelData.date)
onClicked: applicationWindow().openUrl(modelData.url)
}
}
FormCard.FormTextDelegate {
description: i18n("No news.")
visible: LauncherCore.headline !== null ? LauncherCore.headline.failedToLoad : false
}
Kirigami.Theme.colorSet: Kirigami.Theme.Window
}
FormCard.FormHeader {
title: i18n("Topics")
Layout.fillWidth: true
maximumWidth: layout.maximumWidth
}
FormCard.FormCard {
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
maximumWidth: layout.maximumWidth
visible: LauncherCore.headline !== null
Repeater {
model: LauncherCore.headline !== null ? LauncherCore.headline.topics : undefined
FormCard.FormButtonDelegate {
2023-12-17 12:47:13 -05:00
required property var modelData
text: modelData.title
description: Qt.formatDate(modelData.date)
hoverEnabled: true
onClicked: applicationWindow().openUrl(modelData.url)
}
}
FormCard.FormTextDelegate {
description: i18n("No topics.")
visible: LauncherCore.headline !== null ? LauncherCore.headline.failedToLoad : false
}
Kirigami.Theme.colorSet: Kirigami.Theme.Window
}
Item {
Layout.fillHeight: true
}
}
Kirigami.LoadingPlaceholder {
anchors.centerIn: parent
visible: LauncherCore.headline === null
}
}