add noctalia and fuzzel
This commit is contained in:
@@ -0,0 +1,276 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.Media
|
||||
import qs.Widgets
|
||||
|
||||
// Audio controls card: output and input volume controls
|
||||
NBox {
|
||||
id: root
|
||||
|
||||
property real localOutputVolume: 0
|
||||
property bool localOutputVolumeChanging: false
|
||||
property int lastSinkId: -1
|
||||
|
||||
property real localInputVolume: 0
|
||||
property bool localInputVolumeChanging: false
|
||||
property int lastSourceId: -1
|
||||
|
||||
readonly property bool outputVolumeGuard: outputVolumeSlider.sliderActive || localOutputVolumeChanging
|
||||
readonly property bool inputVolumeGuard: inputVolumeSlider.sliderActive || localInputVolumeChanging
|
||||
|
||||
Component.onCompleted: {
|
||||
var vol = AudioService.volume;
|
||||
localOutputVolume = (vol !== undefined && !isNaN(vol)) ? vol : 0;
|
||||
var inputVol = AudioService.inputVolume;
|
||||
localInputVolume = (inputVol !== undefined && !isNaN(inputVol)) ? inputVol : 0;
|
||||
if (AudioService.sink) {
|
||||
lastSinkId = AudioService.sink.id;
|
||||
}
|
||||
if (AudioService.source) {
|
||||
lastSourceId = AudioService.source.id;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset local volume when device changes - use current device's volume
|
||||
Connections {
|
||||
target: AudioService
|
||||
function onSinkChanged() {
|
||||
if (AudioService.sink) {
|
||||
const newSinkId = AudioService.sink.id;
|
||||
if (newSinkId !== lastSinkId) {
|
||||
lastSinkId = newSinkId;
|
||||
// Immediately set local volume to current device's volume
|
||||
var vol = AudioService.volume;
|
||||
localOutputVolume = (vol !== undefined && !isNaN(vol)) ? vol : 0;
|
||||
}
|
||||
} else {
|
||||
lastSinkId = -1;
|
||||
localOutputVolume = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: AudioService
|
||||
function onSourceChanged() {
|
||||
if (AudioService.source) {
|
||||
const newSourceId = AudioService.source.id;
|
||||
if (newSourceId !== lastSourceId) {
|
||||
lastSourceId = newSourceId;
|
||||
// Immediately set local volume to current device's volume
|
||||
var vol = AudioService.inputVolume;
|
||||
localInputVolume = (vol !== undefined && !isNaN(vol)) ? vol : 0;
|
||||
}
|
||||
} else {
|
||||
lastSourceId = -1;
|
||||
localInputVolume = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Timer to debounce volume changes
|
||||
// Only sync if the device hasn't changed (check by comparing IDs)
|
||||
Timer {
|
||||
interval: 100
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
// Only sync if sink hasn't changed
|
||||
if (AudioService.sink && AudioService.sink.id === lastSinkId) {
|
||||
if (Math.abs(localOutputVolume - AudioService.volume) >= 0.01) {
|
||||
AudioService.setVolume(localOutputVolume);
|
||||
}
|
||||
}
|
||||
// Only sync if source hasn't changed
|
||||
if (AudioService.source && AudioService.source.id === lastSourceId) {
|
||||
if (Math.abs(localInputVolume - AudioService.inputVolume) >= 0.01) {
|
||||
AudioService.setInputVolume(localInputVolume);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: AudioService
|
||||
function onVolumeChanged() {
|
||||
if (!outputVolumeGuard && !AudioService.isSettingOutputVolume && AudioService.sink && AudioService.sink.id === lastSinkId) {
|
||||
var vol = AudioService.volume;
|
||||
localOutputVolume = (vol !== undefined && !isNaN(vol)) ? vol : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: AudioService
|
||||
function onInputVolumeChanged() {
|
||||
if (!inputVolumeGuard && !AudioService.isSettingInputVolume && AudioService.source && AudioService.source.id === lastSourceId) {
|
||||
var vol = AudioService.inputVolume;
|
||||
localInputVolume = (vol !== undefined && !isNaN(vol)) ? vol : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: outputVolumeSlider
|
||||
function onSliderActiveChanged() {
|
||||
if (!outputVolumeSlider.sliderActive && AudioService.sink && AudioService.sink.id === lastSinkId) {
|
||||
var vol = AudioService.volume;
|
||||
localOutputVolume = (vol !== undefined && !isNaN(vol)) ? vol : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: inputVolumeSlider
|
||||
function onSliderActiveChanged() {
|
||||
if (!inputVolumeSlider.sliderActive && AudioService.source && AudioService.source.id === lastSourceId) {
|
||||
var vol = AudioService.inputVolume;
|
||||
localInputVolume = (vol !== undefined && !isNaN(vol)) ? vol : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Style.marginM
|
||||
spacing: Style.marginM
|
||||
|
||||
// Output Volume Section
|
||||
ColumnLayout {
|
||||
spacing: Style.marginXXS
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: 0
|
||||
opacity: AudioService.sink ? 1.0 : 0.5
|
||||
enabled: AudioService.sink
|
||||
|
||||
// Output Volume Header
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginXS
|
||||
|
||||
NIconButton {
|
||||
icon: AudioService.muted ? "volume-off" : "volume-high"
|
||||
baseSize: Style.baseWidgetSize * 0.5
|
||||
colorFg: AudioService.muted ? Color.mError : Color.mOnSurface
|
||||
colorBg: "transparent"
|
||||
colorBgHover: Color.mHover
|
||||
colorFgHover: Color.mOnHover
|
||||
onClicked: AudioService.setOutputMuted(!AudioService.muted)
|
||||
}
|
||||
|
||||
NText {
|
||||
text: AudioService.sink ? AudioService.sink.description : "No output device"
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Color.mOnSurfaceVariant
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: 0
|
||||
}
|
||||
}
|
||||
|
||||
// Output Volume Slider
|
||||
NSlider {
|
||||
id: outputVolumeSlider
|
||||
Layout.fillWidth: true
|
||||
from: 0
|
||||
to: Settings.data.audio.volumeOverdrive ? 1.5 : 1.0
|
||||
value: localOutputVolume
|
||||
stepSize: 0.01
|
||||
heightRatio: 0.5
|
||||
onMoved: localOutputVolume = value
|
||||
onPressedChanged: localOutputVolumeChanging = pressed
|
||||
tooltipText: `${Math.round((outputVolumeGuard ? localOutputVolume : AudioService.volume) * 100)}%`
|
||||
tooltipDirection: "bottom"
|
||||
|
||||
// MouseArea to handle wheel events when hovering over the slider
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
acceptedButtons: Qt.NoButton
|
||||
propagateComposedEvents: true
|
||||
|
||||
onWheel: wheel => {
|
||||
if (outputVolumeSlider.enabled && AudioService.sink) {
|
||||
const delta = wheel.angleDelta.y || wheel.angleDelta.x;
|
||||
const step = Settings.data.audio.volumeStep / 100.0; // Convert percentage to 0-1 range
|
||||
const increment = delta > 0 ? step : -step;
|
||||
const maxVolume = Settings.data.audio.volumeOverdrive ? 1.5 : 1.0;
|
||||
const newValue = Math.max(0, Math.min(maxVolume, localOutputVolume + increment));
|
||||
localOutputVolume = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Input Volume Section
|
||||
ColumnLayout {
|
||||
spacing: Style.marginXXS
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: 0
|
||||
opacity: AudioService.source ? 1.0 : 0.5
|
||||
enabled: AudioService.source
|
||||
|
||||
// Input Volume Header
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginXS
|
||||
|
||||
NIconButton {
|
||||
icon: AudioService.inputMuted ? "microphone-off" : "microphone"
|
||||
baseSize: Style.baseWidgetSize * 0.5
|
||||
colorFg: AudioService.inputMuted ? Color.mError : Color.mOnSurface
|
||||
colorBg: "transparent"
|
||||
colorBgHover: Color.mHover
|
||||
colorFgHover: Color.mOnHover
|
||||
onClicked: AudioService.setInputMuted(!AudioService.inputMuted)
|
||||
}
|
||||
|
||||
NText {
|
||||
text: AudioService.source ? AudioService.source.description : "No input device"
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Color.mOnSurfaceVariant
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: 0
|
||||
}
|
||||
}
|
||||
|
||||
// Input Volume Slider
|
||||
NSlider {
|
||||
id: inputVolumeSlider
|
||||
Layout.fillWidth: true
|
||||
from: 0
|
||||
to: Settings.data.audio.volumeOverdrive ? 1.5 : 1.0
|
||||
value: localInputVolume
|
||||
stepSize: 0.01
|
||||
heightRatio: 0.5
|
||||
onMoved: localInputVolume = value
|
||||
onPressedChanged: localInputVolumeChanging = pressed
|
||||
tooltipText: `${Math.round((inputVolumeGuard ? localInputVolume : AudioService.inputVolume) * 100)}%`
|
||||
tooltipDirection: "bottom"
|
||||
|
||||
// MouseArea to handle wheel events when hovering over the slider
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
acceptedButtons: Qt.NoButton
|
||||
propagateComposedEvents: true
|
||||
|
||||
onWheel: wheel => {
|
||||
if (inputVolumeSlider.enabled && AudioService.source) {
|
||||
const delta = wheel.angleDelta.y || wheel.angleDelta.x;
|
||||
const step = Settings.data.audio.volumeStep / 100.0; // Convert percentage to 0-1 range
|
||||
const increment = delta > 0 ? step : -step;
|
||||
const maxVolume = Settings.data.audio.volumeOverdrive ? 1.5 : 1.0;
|
||||
const newValue = Math.max(0, Math.min(maxVolume, localInputVolume + increment));
|
||||
localInputVolume = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.Hardware
|
||||
import qs.Widgets
|
||||
|
||||
// Brightness control card for the ControlCenter
|
||||
NBox {
|
||||
id: root
|
||||
|
||||
Layout.fillWidth: true
|
||||
clip: true
|
||||
|
||||
// Get the primary monitor (first screen)
|
||||
readonly property var brightnessMonitor: {
|
||||
if (Quickshell.screens.length > 0) {
|
||||
return BrightnessService.getMonitorForScreen(Quickshell.screens[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
property real localBrightness: 0
|
||||
property bool localBrightnessChanging: false
|
||||
|
||||
Component.onCompleted: {
|
||||
if (brightnessMonitor) {
|
||||
localBrightness = brightnessMonitor.brightness || 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Update local brightness when monitor changes
|
||||
Connections {
|
||||
target: BrightnessService
|
||||
function onMonitorBrightnessChanged(monitor, newBrightness) {
|
||||
if (monitor === brightnessMonitor && !localBrightnessChanging) {
|
||||
localBrightness = newBrightness;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update local brightness when monitor's brightness property changes
|
||||
Connections {
|
||||
target: brightnessMonitor
|
||||
ignoreUnknownSignals: true
|
||||
function onBrightnessUpdated() {
|
||||
if (brightnessMonitor && !localBrightnessChanging) {
|
||||
localBrightness = brightnessMonitor.brightness || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Timer to debounce brightness changes - only runs when user is changing slider
|
||||
Timer {
|
||||
id: debounceTimer
|
||||
interval: 100
|
||||
running: false
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
if (brightnessMonitor && Math.abs(localBrightness - brightnessMonitor.brightness) >= 0.01) {
|
||||
brightnessMonitor.setBrightness(localBrightness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Style.marginM
|
||||
spacing: Style.marginM
|
||||
|
||||
// Brightness Section
|
||||
ColumnLayout {
|
||||
spacing: Style.marginXXS
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: 0
|
||||
opacity: brightnessMonitor && brightnessMonitor.brightnessControlAvailable ? 1.0 : 0.5
|
||||
enabled: brightnessMonitor && brightnessMonitor.brightnessControlAvailable
|
||||
|
||||
// Brightness Header
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginXS
|
||||
|
||||
NIconButton {
|
||||
icon: {
|
||||
if (!brightnessMonitor)
|
||||
return "brightness-low";
|
||||
const brightness = brightnessMonitor.brightness || 0;
|
||||
if (brightness <= 0.001)
|
||||
return "sun-off";
|
||||
return brightness <= 0.5 ? "brightness-low" : "brightness-high";
|
||||
}
|
||||
baseSize: Style.baseWidgetSize * 0.5
|
||||
colorFg: Color.mOnSurface
|
||||
colorBg: "transparent"
|
||||
colorBgHover: Color.mHover
|
||||
colorFgHover: Color.mOnHover
|
||||
}
|
||||
|
||||
NText {
|
||||
text: brightnessMonitor ? I18n.tr("common.brightness") : "No display"
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Color.mOnSurfaceVariant
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: 0
|
||||
}
|
||||
|
||||
NText {
|
||||
text: brightnessMonitor ? Math.round(localBrightness * 100) + "%" : "N/A"
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Color.mOnSurfaceVariant
|
||||
opacity: brightnessMonitor && brightnessMonitor.brightnessControlAvailable ? 1.0 : 0.5
|
||||
}
|
||||
}
|
||||
|
||||
// Brightness Slider
|
||||
NSlider {
|
||||
id: brightnessSlider
|
||||
Layout.fillWidth: true
|
||||
from: 0
|
||||
to: 1
|
||||
value: localBrightness
|
||||
stepSize: 0.01
|
||||
heightRatio: 0.5
|
||||
onMoved: {
|
||||
localBrightness = value;
|
||||
debounceTimer.restart();
|
||||
}
|
||||
onPressedChanged: localBrightnessChanging = pressed
|
||||
tooltipText: `${Math.round(localBrightness * 100)}%`
|
||||
tooltipDirection: "bottom"
|
||||
|
||||
// MouseArea to handle wheel events when hovering over the slider
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
acceptedButtons: Qt.NoButton
|
||||
propagateComposedEvents: true
|
||||
|
||||
onWheel: wheel => {
|
||||
if (brightnessSlider.enabled && brightnessMonitor && brightnessMonitor.brightnessControlAvailable) {
|
||||
const delta = wheel.angleDelta.y || wheel.angleDelta.x;
|
||||
const step = Settings.data.brightness.brightnessStep / 100.0; // Convert percentage to 0-1 range
|
||||
const increment = delta > 0 ? step : -step;
|
||||
const newValue = Math.max(0, Math.min(1, localBrightness + increment));
|
||||
localBrightness = newValue;
|
||||
debounceTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.Location
|
||||
import qs.Widgets
|
||||
|
||||
// Calendar header with date, month/year, location, and clock
|
||||
Rectangle {
|
||||
id: root
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: (60 * Style.uiScaleRatio) + Style.margin2M
|
||||
Layout.preferredHeight: (60 * Style.uiScaleRatio) + Style.margin2M
|
||||
implicitHeight: (60 * Style.uiScaleRatio) + Style.margin2M
|
||||
radius: Style.radiusL
|
||||
color: Color.mPrimary
|
||||
|
||||
// Internal state
|
||||
readonly property var now: Time.now
|
||||
readonly property bool weatherReady: Settings.data.location.weatherEnabled && (LocationService.data.weather !== null)
|
||||
|
||||
// Expose current month/year for potential synchronization with CalendarMonthCard
|
||||
readonly property int currentMonth: now.getMonth()
|
||||
readonly property int currentYear: now.getFullYear()
|
||||
|
||||
ColumnLayout {
|
||||
id: capsuleColumn
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.topMargin: Style.marginM
|
||||
anchors.bottomMargin: Style.marginM
|
||||
anchors.rightMargin: clockLoader.width + Style.margin2XL
|
||||
anchors.leftMargin: Style.marginXL
|
||||
spacing: 0
|
||||
|
||||
// Combined layout for date, month year, location and time-zone
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
height: 60 * Style.uiScaleRatio
|
||||
clip: true
|
||||
spacing: Style.marginS
|
||||
|
||||
// Today day number
|
||||
NText {
|
||||
Layout.preferredWidth: implicitWidth
|
||||
elide: Text.ElideNone
|
||||
clip: true
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||
text: root.now.getDate()
|
||||
pointSize: Style.fontSizeXXXL * 1.5
|
||||
font.weight: Style.fontWeightBold
|
||||
color: Color.mOnPrimary
|
||||
}
|
||||
|
||||
// Month, year, location
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||
Layout.bottomMargin: Style.marginXXS
|
||||
Layout.topMargin: -Style.marginXXS
|
||||
spacing: -Style.marginXS
|
||||
|
||||
RowLayout {
|
||||
spacing: Style.marginS
|
||||
|
||||
NText {
|
||||
text: I18n.locale.monthName(root.currentMonth, Locale.LongFormat).toUpperCase()
|
||||
pointSize: Style.fontSizeXL * 1.1
|
||||
font.weight: Style.fontWeightBold
|
||||
color: Color.mOnPrimary
|
||||
Layout.alignment: Qt.AlignBaseline
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
NText {
|
||||
text: `${root.currentYear}`
|
||||
pointSize: Style.fontSizeM
|
||||
font.weight: Style.fontWeightBold
|
||||
color: Qt.alpha(Color.mOnPrimary, 0.7)
|
||||
Layout.alignment: Qt.AlignBaseline
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: 0
|
||||
|
||||
NText {
|
||||
text: {
|
||||
if (!Settings.data.location.weatherEnabled)
|
||||
return "";
|
||||
if (!LocationService.locationConfigured)
|
||||
return I18n.tr("common.weather-no-location");
|
||||
if (!root.weatherReady)
|
||||
return I18n.tr("common.weather-loading");
|
||||
if (Settings.data.location.hideWeatherCityName)
|
||||
return "";
|
||||
const chunks = Settings.data.location.name.split(",");
|
||||
return chunks[0];
|
||||
}
|
||||
pointSize: Style.fontSizeM
|
||||
color: Color.mOnPrimary
|
||||
Layout.maximumWidth: 150
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
NText {
|
||||
text: root.weatherReady && !Settings.data.location.hideWeatherTimezone ? `${Settings.data.location.hideWeatherCityName ? "" : " "}(${LocationService.data.weather.timezone_abbreviation})` : ""
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Qt.alpha(Color.mOnPrimary, 0.7)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Spacer
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Analog/Digital clock
|
||||
NClock {
|
||||
id: clockLoader
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Style.marginXL
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
clockStyle: Settings.data.location.analogClockInCalendar ? "analog" : "digital"
|
||||
progressColor: Color.mOnPrimary
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
now: root.now
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.Location
|
||||
import qs.Services.System
|
||||
import qs.Services.UI
|
||||
import qs.Widgets
|
||||
|
||||
// Calendar month grid with navigation
|
||||
NBox {
|
||||
id: root
|
||||
Layout.fillWidth: true
|
||||
implicitHeight: calendarContent.implicitHeight + Style.margin2M
|
||||
|
||||
// Internal state - independent from header
|
||||
readonly property var now: Time.now
|
||||
property int calendarMonth: now.getMonth()
|
||||
property int calendarYear: now.getFullYear()
|
||||
readonly property int firstDayOfWeek: Settings.data.location.firstDayOfWeek === -1 ? I18n.locale.firstDayOfWeek : Settings.data.location.firstDayOfWeek
|
||||
|
||||
// Helper function to calculate ISO week number
|
||||
function getISOWeekNumber(date) {
|
||||
const target = new Date(date.valueOf());
|
||||
const dayNr = (date.getDay() + 6) % 7;
|
||||
target.setDate(target.getDate() - dayNr + 3);
|
||||
const firstThursday = new Date(target.getFullYear(), 0, 4);
|
||||
const diff = target - firstThursday;
|
||||
const oneWeek = 1000 * 60 * 60 * 24 * 7;
|
||||
const weekNumber = 1 + Math.round(diff / oneWeek);
|
||||
return weekNumber;
|
||||
}
|
||||
|
||||
// Helper function to check if an event is all-day
|
||||
function isAllDayEvent(event) {
|
||||
const duration = event.end - event.start;
|
||||
const startDate = new Date(event.start * 1000);
|
||||
const isAtMidnight = startDate.getHours() === 0 && startDate.getMinutes() === 0;
|
||||
return duration === 86400 && isAtMidnight;
|
||||
}
|
||||
|
||||
// Navigation functions
|
||||
function navigateToPreviousMonth() {
|
||||
let newDate = new Date(root.calendarYear, root.calendarMonth - 1, 1);
|
||||
root.calendarYear = newDate.getFullYear();
|
||||
root.calendarMonth = newDate.getMonth();
|
||||
const now = new Date();
|
||||
const monthStart = new Date(root.calendarYear, root.calendarMonth, 1);
|
||||
const monthEnd = new Date(root.calendarYear, root.calendarMonth + 1, 0);
|
||||
const daysBehind = Math.max(0, Math.ceil((now - monthStart) / (24 * 60 * 60 * 1000)));
|
||||
const daysAhead = Math.max(0, Math.ceil((monthEnd - now) / (24 * 60 * 60 * 1000)));
|
||||
CalendarService.loadEvents(daysAhead + 30, daysBehind + 30);
|
||||
}
|
||||
|
||||
function navigateToNextMonth() {
|
||||
let newDate = new Date(root.calendarYear, root.calendarMonth + 1, 1);
|
||||
root.calendarYear = newDate.getFullYear();
|
||||
root.calendarMonth = newDate.getMonth();
|
||||
const now = new Date();
|
||||
const monthStart = new Date(root.calendarYear, root.calendarMonth, 1);
|
||||
const monthEnd = new Date(root.calendarYear, root.calendarMonth + 1, 0);
|
||||
const daysBehind = Math.max(0, Math.ceil((now - monthStart) / (24 * 60 * 60 * 1000)));
|
||||
const daysAhead = Math.max(0, Math.ceil((monthEnd - now) / (24 * 60 * 60 * 1000)));
|
||||
CalendarService.loadEvents(daysAhead + 30, daysBehind + 30);
|
||||
}
|
||||
|
||||
// Wheel handler for month navigation
|
||||
WheelHandler {
|
||||
id: wheelHandler
|
||||
target: root
|
||||
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
|
||||
onWheel: function (event) {
|
||||
if (event.angleDelta.y > 0) {
|
||||
// Scroll up - go to previous month
|
||||
root.navigateToPreviousMonth();
|
||||
event.accepted = true;
|
||||
} else if (event.angleDelta.y < 0) {
|
||||
// Scroll down - go to next month
|
||||
root.navigateToNextMonth();
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: calendarContent
|
||||
anchors.fill: parent
|
||||
anchors.margins: Style.marginM
|
||||
spacing: Style.marginS
|
||||
|
||||
// Navigation row
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginS
|
||||
|
||||
Item {
|
||||
Layout.preferredWidth: Style.marginS
|
||||
}
|
||||
|
||||
NText {
|
||||
text: I18n.locale.monthName(root.calendarMonth, Locale.LongFormat).toUpperCase() + " " + root.calendarYear
|
||||
pointSize: Style.fontSizeM
|
||||
font.weight: Style.fontWeightBold
|
||||
color: Color.mOnSurface
|
||||
}
|
||||
|
||||
NDivider {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
NIconButton {
|
||||
icon: "chevron-left"
|
||||
onClicked: root.navigateToPreviousMonth()
|
||||
}
|
||||
|
||||
NIconButton {
|
||||
icon: "calendar"
|
||||
onClicked: {
|
||||
root.calendarMonth = root.now.getMonth();
|
||||
root.calendarYear = root.now.getFullYear();
|
||||
CalendarService.loadEvents();
|
||||
}
|
||||
}
|
||||
|
||||
NIconButton {
|
||||
icon: "chevron-right"
|
||||
onClicked: root.navigateToNextMonth()
|
||||
}
|
||||
}
|
||||
|
||||
// Day names header
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 0
|
||||
|
||||
Item {
|
||||
visible: Settings.data.location.showWeekNumberInCalendar
|
||||
Layout.preferredWidth: visible ? Style.baseWidgetSize * 0.7 : 0
|
||||
}
|
||||
|
||||
GridLayout {
|
||||
Layout.fillWidth: true
|
||||
columns: 7
|
||||
rows: 1
|
||||
columnSpacing: 0
|
||||
rowSpacing: 0
|
||||
|
||||
Repeater {
|
||||
model: 7
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: Style.fontSizeS * 2
|
||||
|
||||
NText {
|
||||
anchors.centerIn: parent
|
||||
text: {
|
||||
let dayIndex = (root.firstDayOfWeek + index) % 7;
|
||||
const dayName = I18n.locale.dayName(dayIndex, Locale.ShortFormat);
|
||||
return dayName.substring(0, 2).toUpperCase();
|
||||
}
|
||||
color: Color.mPrimary
|
||||
pointSize: Style.fontSizeS
|
||||
font.weight: Style.fontWeightBold
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calendar grid with week numbers
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 0
|
||||
|
||||
// Helper functions
|
||||
function hasEventsOnDate(year, month, day) {
|
||||
if (!CalendarService.available || CalendarService.events.length === 0)
|
||||
return false;
|
||||
const targetDate = new Date(year, month, day);
|
||||
const targetStart = new Date(targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate()).getTime() / 1000;
|
||||
const targetEnd = targetStart + 86400;
|
||||
return CalendarService.events.some(event => {
|
||||
return (event.start >= targetStart && event.start < targetEnd) || (event.end > targetStart && event.end <= targetEnd) || (event.start < targetStart && event.end > targetEnd);
|
||||
});
|
||||
}
|
||||
|
||||
function getEventsForDate(year, month, day) {
|
||||
if (!CalendarService.available || CalendarService.events.length === 0)
|
||||
return [];
|
||||
const targetDate = new Date(year, month, day);
|
||||
const targetStart = Math.floor(new Date(targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate()).getTime() / 1000);
|
||||
const targetEnd = targetStart + 86400;
|
||||
return CalendarService.events.filter(event => {
|
||||
return (event.start >= targetStart && event.start < targetEnd) || (event.end > targetStart && event.end <= targetEnd) || (event.start < targetStart && event.end > targetEnd);
|
||||
});
|
||||
}
|
||||
|
||||
function isMultiDayEvent(event) {
|
||||
if (root.isAllDayEvent(event)) {
|
||||
return false;
|
||||
}
|
||||
const startDate = new Date(event.start * 1000);
|
||||
const endDate = new Date(event.end * 1000);
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
return startDateOnly.getTime() !== endDateOnly.getTime();
|
||||
}
|
||||
|
||||
function getEventColor(event, isToday) {
|
||||
if (isMultiDayEvent(event)) {
|
||||
return isToday ? Color.mOnSecondary : Color.mTertiary;
|
||||
} else if (root.isAllDayEvent(event)) {
|
||||
return isToday ? Color.mOnSecondary : Color.mSecondary;
|
||||
} else {
|
||||
return isToday ? Color.mOnSecondary : Color.mPrimary;
|
||||
}
|
||||
}
|
||||
|
||||
// Week numbers column
|
||||
ColumnLayout {
|
||||
visible: Settings.data.location.showWeekNumberInCalendar
|
||||
Layout.preferredWidth: visible ? Style.baseWidgetSize * 0.7 : 0
|
||||
Layout.alignment: Qt.AlignTop
|
||||
spacing: Style.marginXXS
|
||||
|
||||
property var weekNumbers: {
|
||||
if (!grid.daysModel || grid.daysModel.length === 0)
|
||||
return [];
|
||||
const weeks = [];
|
||||
const numWeeks = Math.ceil(grid.daysModel.length / 7);
|
||||
for (var i = 0; i < numWeeks; i++) {
|
||||
const dayIndex = i * 7;
|
||||
if (dayIndex < grid.daysModel.length) {
|
||||
const weekDay = grid.daysModel[dayIndex];
|
||||
const date = new Date(weekDay.year, weekDay.month, weekDay.day);
|
||||
let thursday = new Date(date);
|
||||
if (root.firstDayOfWeek === 0) {
|
||||
thursday.setDate(date.getDate() + 4);
|
||||
} else if (root.firstDayOfWeek === 1) {
|
||||
thursday.setDate(date.getDate() + 3);
|
||||
} else {
|
||||
let daysToThursday = (4 - root.firstDayOfWeek + 7) % 7;
|
||||
thursday.setDate(date.getDate() + daysToThursday);
|
||||
}
|
||||
weeks.push(root.getISOWeekNumber(thursday));
|
||||
}
|
||||
}
|
||||
return weeks;
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: parent.weekNumbers
|
||||
Item {
|
||||
Layout.preferredWidth: Style.baseWidgetSize * 0.7
|
||||
Layout.preferredHeight: Style.baseWidgetSize * 0.9
|
||||
|
||||
NText {
|
||||
anchors.centerIn: parent
|
||||
color: Qt.alpha(Color.mPrimary, 0.7)
|
||||
pointSize: Style.fontSizeXXS
|
||||
text: modelData
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calendar grid
|
||||
GridLayout {
|
||||
id: grid
|
||||
Layout.fillWidth: true
|
||||
columns: 7
|
||||
columnSpacing: Style.marginXXS
|
||||
rowSpacing: Style.marginXXS
|
||||
|
||||
property int month: root.calendarMonth
|
||||
property int year: root.calendarYear
|
||||
|
||||
property var daysModel: {
|
||||
const firstOfMonth = new Date(year, month, 1);
|
||||
const lastOfMonth = new Date(year, month + 1, 0);
|
||||
const daysInMonth = lastOfMonth.getDate();
|
||||
const firstDayOfWeek = root.firstDayOfWeek;
|
||||
const firstOfMonthDayOfWeek = firstOfMonth.getDay();
|
||||
let daysBefore = (firstOfMonthDayOfWeek - firstDayOfWeek + 7) % 7;
|
||||
const lastOfMonthDayOfWeek = lastOfMonth.getDay();
|
||||
const daysAfter = (firstDayOfWeek - lastOfMonthDayOfWeek - 1 + 7) % 7;
|
||||
const days = [];
|
||||
const today = new Date();
|
||||
|
||||
// Previous month days
|
||||
const prevMonth = new Date(year, month, 0);
|
||||
const prevMonthDays = prevMonth.getDate();
|
||||
for (var i = daysBefore - 1; i >= 0; i--) {
|
||||
const day = prevMonthDays - i;
|
||||
days.push({
|
||||
"day": day,
|
||||
"month": month - 1,
|
||||
"year": month === 0 ? year - 1 : year,
|
||||
"today": false,
|
||||
"currentMonth": false
|
||||
});
|
||||
}
|
||||
|
||||
// Current month days
|
||||
for (var day = 1; day <= daysInMonth; day++) {
|
||||
const date = new Date(year, month, day);
|
||||
const isToday = date.getFullYear() === today.getFullYear() && date.getMonth() === today.getMonth() && date.getDate() === today.getDate();
|
||||
days.push({
|
||||
"day": day,
|
||||
"month": month,
|
||||
"year": year,
|
||||
"today": isToday,
|
||||
"currentMonth": true
|
||||
});
|
||||
}
|
||||
|
||||
// Next month days
|
||||
for (var i = 1; i <= daysAfter; i++) {
|
||||
days.push({
|
||||
"day": i,
|
||||
"month": month + 1,
|
||||
"year": month === 11 ? year + 1 : year,
|
||||
"today": false,
|
||||
"currentMonth": false
|
||||
});
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: grid.daysModel
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: Style.baseWidgetSize * 0.9
|
||||
|
||||
Rectangle {
|
||||
width: Style.baseWidgetSize * 0.9
|
||||
height: Style.baseWidgetSize * 0.9
|
||||
anchors.centerIn: parent
|
||||
radius: Style.radiusM
|
||||
color: modelData.today ? Color.mSecondary : "transparent"
|
||||
|
||||
NText {
|
||||
anchors.centerIn: parent
|
||||
text: modelData.day
|
||||
color: {
|
||||
if (modelData.today)
|
||||
return Color.mOnSecondary;
|
||||
if (modelData.currentMonth)
|
||||
return Color.mOnSurface;
|
||||
return Color.mOnSurfaceVariant;
|
||||
}
|
||||
opacity: modelData.currentMonth ? 1.0 : 0.4
|
||||
pointSize: Style.fontSizeM
|
||||
font.weight: modelData.today ? Style.fontWeightBold : Style.fontWeightMedium
|
||||
}
|
||||
|
||||
// Event indicator dots
|
||||
Row {
|
||||
visible: Settings.data.location.showCalendarEvents && parent.parent.parent.parent.hasEventsOnDate(modelData.year, modelData.month, modelData.day)
|
||||
spacing: 2
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: Style.marginXS
|
||||
|
||||
Repeater {
|
||||
model: parent.parent.parent.parent.parent.getEventsForDate(modelData.year, modelData.month, modelData.day)
|
||||
|
||||
Rectangle {
|
||||
width: 4
|
||||
height: width
|
||||
radius: Style.radiusXXS
|
||||
color: parent.parent.parent.parent.parent.getEventColor(modelData, modelData.today)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
enabled: Settings.data.location.showCalendarEvents
|
||||
|
||||
onEntered: {
|
||||
const events = parent.parent.parent.parent.getEventsForDate(modelData.year, modelData.month, modelData.day);
|
||||
if (events.length > 0) {
|
||||
const summaries = events.map(event => {
|
||||
if (root.isAllDayEvent(event)) {
|
||||
return event.summary;
|
||||
} else {
|
||||
const timeFormat = Settings.data.location.use12hourFormat ? "hh:mm AP" : "HH:mm";
|
||||
const start = new Date(event.start * 1000);
|
||||
const startFormatted = I18n.locale.toString(start, timeFormat);
|
||||
const end = new Date(event.end * 1000);
|
||||
const endFormatted = I18n.locale.toString(end, timeFormat);
|
||||
return `${startFormatted}-${endFormatted} ${event.summary}`;
|
||||
}
|
||||
}).join('\n');
|
||||
TooltipService.show(parent, summaries, "auto", Style.tooltipDelay, Settings.data.ui.fontFixed);
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
const dateWithSlashes = `${(modelData.month + 1).toString().padStart(2, '0')}/${modelData.day.toString().padStart(2, '0')}/${modelData.year.toString().substring(2)}`;
|
||||
if (ProgramCheckerService.gnomeCalendarAvailable) {
|
||||
Quickshell.execDetached(["gnome-calendar", "--date", dateWithSlashes]);
|
||||
}
|
||||
}
|
||||
|
||||
onExited: {
|
||||
TooltipService.hide();
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Style.animationFast
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Effects
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.Media
|
||||
import qs.Services.UI
|
||||
import qs.Widgets
|
||||
import qs.Widgets.AudioSpectrum
|
||||
|
||||
NBox {
|
||||
id: root
|
||||
|
||||
// Track whether we have an active media player
|
||||
readonly property bool hasActivePlayer: MediaService.currentPlayer && MediaService.canPlay
|
||||
|
||||
// SpectrumService registration for visualizer
|
||||
readonly property bool needsSpectrum: Settings.data.audio.visualizerType !== "" && Settings.data.audio.visualizerType !== "none"
|
||||
|
||||
onNeedsSpectrumChanged: {
|
||||
if (root.needsSpectrum) {
|
||||
SpectrumService.registerComponent("mediacard");
|
||||
} else {
|
||||
SpectrumService.unregisterComponent("mediacard");
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (root.needsSpectrum) {
|
||||
SpectrumService.registerComponent("mediacard");
|
||||
}
|
||||
updateCachedWallpaper();
|
||||
}
|
||||
|
||||
Component.onDestruction: {
|
||||
SpectrumService.unregisterComponent("mediacard");
|
||||
}
|
||||
|
||||
property string wallpaper: WallpaperService.getWallpaper(screen.name)
|
||||
property string cachedWallpaper: ""
|
||||
|
||||
// External state management
|
||||
Connections {
|
||||
target: WallpaperService
|
||||
function onWallpaperChanged(screenName, path) {
|
||||
if (screenName === screen.name) {
|
||||
wallpaper = path;
|
||||
updateCachedWallpaper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateCachedWallpaper() {
|
||||
// Handle solid color mode - no wallpaper to cache
|
||||
if (Settings.data.wallpaper.useSolidColor || WallpaperService.isSolidColorPath(wallpaper)) {
|
||||
cachedWallpaper = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wallpaper) {
|
||||
cachedWallpaper = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ImageCacheService.initialized) {
|
||||
cachedWallpaper = wallpaper;
|
||||
return;
|
||||
}
|
||||
|
||||
ImageCacheService.getThumbnail(wallpaper, function (cachedPath, success) {
|
||||
if (!root)
|
||||
return;
|
||||
cachedWallpaper = success ? cachedPath : wallpaper;
|
||||
});
|
||||
}
|
||||
|
||||
// Wrapper - rounded rect clipper
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
layer.enabled: true
|
||||
layer.smooth: true
|
||||
layer.effect: MultiEffect {
|
||||
maskEnabled: true
|
||||
maskThresholdMin: 0.95
|
||||
maskSpreadAtMin: 0.15
|
||||
maskSource: ShaderEffectSource {
|
||||
sourceItem: Rectangle {
|
||||
width: root.width
|
||||
height: root.height
|
||||
radius: Style.radiusM
|
||||
color: "white"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Solid color background (always present as base layer)
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Settings.data.wallpaper.useSolidColor ? Settings.data.wallpaper.solidColor : Color.mSurface
|
||||
}
|
||||
|
||||
// Background image that covers everything
|
||||
Image {
|
||||
id: bgImage
|
||||
readonly property int dim: Math.round(256 * Style.uiScaleRatio)
|
||||
anchors.fill: parent
|
||||
visible: source.toString() !== ""
|
||||
source: MediaService.trackArtUrl || (Settings.data.wallpaper.enabled && !Settings.data.wallpaper.useSolidColor ? root.cachedWallpaper : "")
|
||||
sourceSize: Qt.size(dim, dim)
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
layer.enabled: true
|
||||
layer.smooth: true
|
||||
layer.effect: MultiEffect {
|
||||
blurEnabled: true
|
||||
blurMax: 8
|
||||
blur: 0.33
|
||||
}
|
||||
}
|
||||
|
||||
// Dark overlay for readability
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Color.mSurface
|
||||
opacity: 0.65
|
||||
radius: Style.radiusM
|
||||
}
|
||||
|
||||
// Border
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "transparent"
|
||||
border.color: Style.boxBorderColor
|
||||
border.width: Style.borderS
|
||||
radius: Style.radiusM
|
||||
}
|
||||
|
||||
// Background visualizer on top of the artwork
|
||||
Loader {
|
||||
anchors.fill: parent
|
||||
active: Settings.data.audio.visualizerType !== "" && Settings.data.audio.visualizerType !== "none"
|
||||
|
||||
sourceComponent: {
|
||||
switch (Settings.data.audio.visualizerType) {
|
||||
case "linear":
|
||||
return linearComponent;
|
||||
case "mirrored":
|
||||
return mirroredComponent;
|
||||
case "wave":
|
||||
return waveComponent;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: linearComponent
|
||||
NLinearSpectrum {
|
||||
anchors.fill: parent
|
||||
values: SpectrumService.values
|
||||
fillColor: Color.mPrimary
|
||||
opacity: 0.8
|
||||
mirrored: Settings.data.audio.spectrumMirrored
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: mirroredComponent
|
||||
NMirroredSpectrum {
|
||||
anchors.fill: parent
|
||||
values: SpectrumService.values
|
||||
fillColor: Color.mPrimary
|
||||
opacity: 0.8
|
||||
mirrored: Settings.data.audio.spectrumMirrored
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: waveComponent
|
||||
NWaveSpectrum {
|
||||
anchors.fill: parent
|
||||
values: SpectrumService.values
|
||||
fillColor: Color.mPrimary
|
||||
opacity: 0.8
|
||||
mirrored: Settings.data.audio.spectrumMirrored
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Player selector
|
||||
Rectangle {
|
||||
id: playerSelectorButton
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.topMargin: Style.marginXS
|
||||
anchors.leftMargin: Style.marginM
|
||||
anchors.rightMargin: Style.marginM
|
||||
height: Style.baseWidgetSize
|
||||
visible: MediaService.getAvailablePlayers().length > 1
|
||||
radius: Style.radiusM
|
||||
color: "transparent"
|
||||
|
||||
property var currentPlayer: MediaService.getAvailablePlayers()[MediaService.selectedPlayerIndex]
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
spacing: Style.marginS
|
||||
|
||||
NIcon {
|
||||
icon: "caret-down"
|
||||
pointSize: Style.fontSizeXXL
|
||||
color: Color.mOnSurfaceVariant
|
||||
}
|
||||
|
||||
NText {
|
||||
text: playerSelectorButton.currentPlayer ? playerSelectorButton.currentPlayer.identity : ""
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Color.mOnSurfaceVariant
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: playerSelectorMouseArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
onClicked: {
|
||||
var menuItems = [];
|
||||
var players = MediaService.getAvailablePlayers();
|
||||
for (var i = 0; i < players.length; i++) {
|
||||
menuItems.push({
|
||||
"label": players[i].identity,
|
||||
"action": i.toString(),
|
||||
"icon": "disc",
|
||||
"enabled": true,
|
||||
"visible": true
|
||||
});
|
||||
}
|
||||
playerContextMenu.model = menuItems;
|
||||
playerContextMenu.openAtItem(playerSelectorButton, playerSelectorButton.width - playerContextMenu.width, playerSelectorButton.height);
|
||||
}
|
||||
}
|
||||
|
||||
NContextMenu {
|
||||
id: playerContextMenu
|
||||
parent: root
|
||||
width: 200
|
||||
verticalPolicy: ScrollBar.AlwaysOff
|
||||
|
||||
onTriggered: function (action) {
|
||||
var index = parseInt(action);
|
||||
if (!isNaN(index)) {
|
||||
MediaService.switchToPlayer(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Content container that adjusts for player selector
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: playerSelectorButton.visible ? (playerSelectorButton.height + Style.marginXS + Style.marginM) : Style.marginM
|
||||
anchors.leftMargin: Style.marginM
|
||||
anchors.rightMargin: Style.marginM
|
||||
anchors.bottomMargin: Style.marginM
|
||||
|
||||
// No media player detected - centered disc icon
|
||||
NIcon {
|
||||
anchors.centerIn: parent
|
||||
visible: !root.hasActivePlayer && SpectrumService.isIdle
|
||||
icon: "disc"
|
||||
pointSize: Style.fontSizeXXXL * 3
|
||||
color: Color.mOnSurfaceVariant
|
||||
opacity: 1.0
|
||||
}
|
||||
|
||||
// MediaPlayer Main Content - use Loader for performance
|
||||
Loader {
|
||||
id: mainLoader
|
||||
anchors.fill: parent
|
||||
active: root.hasActivePlayer
|
||||
|
||||
sourceComponent: Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
// Exceptionaly we put shadow on text and controls to ease readability
|
||||
NDropShadow {
|
||||
anchors.fill: main
|
||||
source: main
|
||||
autoPaddingEnabled: true
|
||||
shadowBlur: 1.0
|
||||
shadowOpacity: 0.9
|
||||
shadowHorizontalOffset: 0
|
||||
shadowVerticalOffset: 0
|
||||
shadowColor: Settings.data.colorSchemes.darkMode ? "black" : "white"
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: main
|
||||
anchors.fill: parent
|
||||
spacing: Style.marginS
|
||||
|
||||
// Spacer to push content down
|
||||
Item {
|
||||
Layout.preferredHeight: Style.marginM
|
||||
}
|
||||
|
||||
// Metadata
|
||||
ColumnLayout {
|
||||
id: metadata
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
spacing: Style.marginXS
|
||||
|
||||
NText {
|
||||
visible: MediaService.trackTitle !== ""
|
||||
text: MediaService.trackTitle
|
||||
pointSize: Style.fontSizeL
|
||||
font.weight: Style.fontWeightBold
|
||||
elide: Text.ElideRight
|
||||
wrapMode: Text.Wrap
|
||||
maximumLineCount: 2
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
NText {
|
||||
visible: MediaService.trackArtist !== ""
|
||||
text: MediaService.trackArtist
|
||||
color: Color.mSecondary
|
||||
pointSize: Style.fontSizeS
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
NText {
|
||||
visible: MediaService.trackAlbum !== ""
|
||||
text: MediaService.trackAlbum
|
||||
color: Color.mOnSurfaceVariant
|
||||
pointSize: Style.fontSizeM
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
// Progress slider
|
||||
Item {
|
||||
id: progressWrapper
|
||||
visible: (MediaService.currentPlayer && MediaService.trackLength > 0)
|
||||
Layout.fillWidth: true
|
||||
height: Style.baseWidgetSize * 0.5
|
||||
|
||||
property real localSeekRatio: -1
|
||||
property real lastSentSeekRatio: -1
|
||||
property real seekEpsilon: 0.01
|
||||
property real progressRatio: {
|
||||
if (!MediaService.currentPlayer || MediaService.trackLength <= 0)
|
||||
return 0;
|
||||
const r = MediaService.currentPosition / MediaService.trackLength;
|
||||
if (isNaN(r) || !isFinite(r))
|
||||
return 0;
|
||||
return Math.max(0, Math.min(1, r));
|
||||
}
|
||||
property real effectiveRatio: (MediaService.isSeeking && localSeekRatio >= 0) ? Math.max(0, Math.min(1, localSeekRatio)) : progressRatio
|
||||
|
||||
Timer {
|
||||
id: seekDebounce
|
||||
interval: 75
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
if (MediaService.isSeeking && progressWrapper.localSeekRatio >= 0) {
|
||||
const next = Math.max(0, Math.min(1, progressWrapper.localSeekRatio));
|
||||
if (progressWrapper.lastSentSeekRatio < 0 || Math.abs(next - progressWrapper.lastSentSeekRatio) >= progressWrapper.seekEpsilon) {
|
||||
MediaService.seekByRatio(next);
|
||||
progressWrapper.lastSentSeekRatio = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSlider {
|
||||
id: progressSlider
|
||||
anchors.fill: parent
|
||||
from: 0
|
||||
to: 1
|
||||
stepSize: 0
|
||||
snapAlways: false
|
||||
enabled: MediaService.trackLength > 0 && MediaService.canSeek
|
||||
heightRatio: 0.6
|
||||
|
||||
onMoved: {
|
||||
progressWrapper.localSeekRatio = value;
|
||||
seekDebounce.restart();
|
||||
}
|
||||
onPressedChanged: {
|
||||
if (pressed) {
|
||||
MediaService.isSeeking = true;
|
||||
progressWrapper.localSeekRatio = value;
|
||||
MediaService.seekByRatio(value);
|
||||
progressWrapper.lastSentSeekRatio = value;
|
||||
} else {
|
||||
seekDebounce.stop();
|
||||
MediaService.seekByRatio(value);
|
||||
MediaService.isSeeking = false;
|
||||
progressWrapper.localSeekRatio = -1;
|
||||
progressWrapper.lastSentSeekRatio = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binding {
|
||||
target: progressSlider
|
||||
property: "value"
|
||||
value: progressWrapper.progressRatio
|
||||
when: !MediaService.isSeeking
|
||||
}
|
||||
}
|
||||
|
||||
// Spacer to push media controls down
|
||||
Item {
|
||||
Layout.preferredHeight: Style.marginL
|
||||
}
|
||||
|
||||
// Media controls
|
||||
RowLayout {
|
||||
spacing: Style.marginS
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
||||
NIconButton {
|
||||
icon: "media-prev"
|
||||
visible: MediaService.canGoPrevious
|
||||
onClicked: MediaService.canGoPrevious ? MediaService.previous() : {}
|
||||
}
|
||||
|
||||
NIconButton {
|
||||
icon: MediaService.isPlaying ? "media-pause" : "media-play"
|
||||
visible: (MediaService.canPlay || MediaService.canPause)
|
||||
onClicked: (MediaService.canPlay || MediaService.canPause) ? MediaService.playPause() : {}
|
||||
}
|
||||
|
||||
NIconButton {
|
||||
icon: "media-next"
|
||||
visible: MediaService.canGoNext
|
||||
onClicked: MediaService.canGoNext ? MediaService.next() : {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import QtQuick
|
||||
import QtQuick.Effects
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Widgets
|
||||
import qs.Commons
|
||||
import qs.Modules.Panels.Settings
|
||||
import qs.Services.System
|
||||
import qs.Services.UI
|
||||
import qs.Widgets
|
||||
|
||||
// Header card with avatar, user and quick actions
|
||||
NBox {
|
||||
id: root
|
||||
|
||||
property string uptimeText: "--"
|
||||
|
||||
RowLayout {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.margins: Style.marginM
|
||||
spacing: Style.marginM
|
||||
|
||||
NImageRounded {
|
||||
Layout.preferredWidth: Math.round(Style.baseWidgetSize * 1.25 * Style.uiScaleRatio)
|
||||
Layout.preferredHeight: Math.round(Style.baseWidgetSize * 1.25 * Style.uiScaleRatio)
|
||||
radius: Layout.preferredWidth / 2
|
||||
imagePath: Settings.preprocessPath(Settings.data.general.avatarImage)
|
||||
fallbackIcon: "person"
|
||||
borderColor: Color.mPrimary
|
||||
borderWidth: Style.borderS * 1.5
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumWidth: 0
|
||||
spacing: Style.marginXXS
|
||||
NText {
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumWidth: 0
|
||||
text: HostService.displayName
|
||||
font.weight: Style.fontWeightBold
|
||||
}
|
||||
NText {
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumWidth: 0
|
||||
text: I18n.tr("system.uptime", {
|
||||
"uptime": uptimeText
|
||||
})
|
||||
pointSize: Style.fontSizeS
|
||||
color: Color.mOnSurfaceVariant
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: Style.marginS
|
||||
Layout.fillWidth: false
|
||||
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
NIconButton {
|
||||
icon: "settings"
|
||||
tooltipText: I18n.tr("tooltips.open-settings")
|
||||
onClicked: {
|
||||
// Better close the control center in case the settings open in a separate window
|
||||
PanelService.openedPanel?.close();
|
||||
|
||||
var panel = PanelService.getPanel("settingsPanel", screen);
|
||||
panel.requestedTab = SettingsPanel.Tab.General;
|
||||
panel.open();
|
||||
}
|
||||
}
|
||||
|
||||
NIconButton {
|
||||
icon: "power"
|
||||
tooltipText: I18n.tr("tooltips.session-menu")
|
||||
onClicked: {
|
||||
PanelService.getPanel("sessionMenuPanel", screen)?.open();
|
||||
PanelService.getPanel("controlCenterPanel", screen)?.close();
|
||||
}
|
||||
}
|
||||
|
||||
NIconButton {
|
||||
icon: "close"
|
||||
tooltipText: I18n.tr("common.close")
|
||||
onClicked: {
|
||||
PanelService.getPanel("controlCenterPanel", screen)?.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// Uptime
|
||||
Timer {
|
||||
interval: 60000
|
||||
repeat: true
|
||||
running: true
|
||||
onTriggered: uptimeProcess.running = true
|
||||
}
|
||||
|
||||
Process {
|
||||
id: uptimeProcess
|
||||
command: ["cat", "/proc/uptime"]
|
||||
running: true
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
var uptimeSeconds = parseFloat(this.text.trim().split(' ')[0]);
|
||||
uptimeText = Time.formatVagueHumanReadableDuration(uptimeSeconds);
|
||||
uptimeProcess.running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateSystemInfo() {
|
||||
uptimeProcess.running = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Modules.Panels.ControlCenter
|
||||
import qs.Widgets
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginL
|
||||
|
||||
NBox {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: root.shortcutsHeight
|
||||
visible: Settings.data.controlCenter.shortcuts.left.length > 0
|
||||
|
||||
RowLayout {
|
||||
id: leftContent
|
||||
anchors.fill: parent
|
||||
spacing: Style.marginS
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: Settings.data.controlCenter.shortcuts.left
|
||||
delegate: ControlCenterWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
Layout.fillWidth: false
|
||||
widgetId: (modelData.id !== undefined ? modelData.id : "")
|
||||
widgetScreen: root.screen
|
||||
widgetProps: {
|
||||
"widgetId": modelData.id,
|
||||
"section": "quickSettings",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": Settings.data.controlCenter.shortcuts.left.length,
|
||||
"widgetSettings": modelData
|
||||
}
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NBox {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: root.shortcutsHeight
|
||||
visible: Settings.data.controlCenter.shortcuts.right.length > 0
|
||||
|
||||
RowLayout {
|
||||
id: rightContent
|
||||
anchors.fill: parent
|
||||
spacing: Style.marginS
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: Settings.data.controlCenter.shortcuts.right
|
||||
delegate: ControlCenterWidgetLoader {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
Layout.fillWidth: false
|
||||
widgetId: (modelData.id !== undefined ? modelData.id : "")
|
||||
widgetScreen: root.screen
|
||||
widgetProps: {
|
||||
"widgetId": modelData.id,
|
||||
"section": "quickSettings",
|
||||
"sectionWidgetIndex": index,
|
||||
"sectionWidgetsCount": Settings.data.controlCenter.shortcuts.right.length,
|
||||
"widgetSettings": modelData
|
||||
}
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.System
|
||||
import qs.Services.UI
|
||||
import qs.Widgets
|
||||
|
||||
// Unified system card: monitors CPU, temp, memory, disk
|
||||
NBox {
|
||||
id: root
|
||||
|
||||
Component.onCompleted: SystemStatService.registerComponent("card-sysmonitor")
|
||||
Component.onDestruction: SystemStatService.unregisterComponent("card-sysmonitor")
|
||||
|
||||
readonly property string diskPath: Settings.data.controlCenter.diskPath || "/"
|
||||
readonly property real contentScale: 0.95 * Style.uiScaleRatio
|
||||
|
||||
Item {
|
||||
id: content
|
||||
anchors.fill: parent
|
||||
anchors.margins: Style.marginS
|
||||
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: parent.height / 4
|
||||
|
||||
NCircleStat {
|
||||
id: cpuUsageGauge
|
||||
anchors.centerIn: parent
|
||||
ratio: SystemStatService.cpuUsage / 100
|
||||
icon: "cpu-usage"
|
||||
contentScale: root.contentScale
|
||||
fillColor: SystemStatService.cpuColor
|
||||
tooltipText: I18n.tr("system-monitor.cpu-usage") + `: ${Math.round(SystemStatService.cpuUsage)}%`
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: SystemStatService
|
||||
function onCpuUsageChanged() {
|
||||
if (TooltipService.activeTooltip && TooltipService.activeTooltip.targetItem === cpuUsageGauge) {
|
||||
TooltipService.updateText(I18n.tr("system-monitor.cpu-usage") + `: ${Math.round(SystemStatService.cpuUsage)}%`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: parent.height / 4
|
||||
|
||||
NCircleStat {
|
||||
id: cpuTempGauge
|
||||
anchors.centerIn: parent
|
||||
ratio: SystemStatService.cpuTemp / 100
|
||||
suffix: "°C"
|
||||
icon: "cpu-temperature"
|
||||
contentScale: root.contentScale
|
||||
fillColor: SystemStatService.tempColor
|
||||
tooltipText: I18n.tr("system-monitor.cpu-temp") + `: ${Math.round(SystemStatService.cpuTemp)}°C`
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: SystemStatService
|
||||
function onCpuTempChanged() {
|
||||
if (TooltipService.activeTooltip && TooltipService.activeTooltip.targetItem === cpuTempGauge) {
|
||||
TooltipService.updateText(I18n.tr("system-monitor.cpu-temp") + `: ${Math.round(SystemStatService.cpuTemp)}°C`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: parent.height / 4
|
||||
|
||||
NCircleStat {
|
||||
id: memPercentGauge
|
||||
anchors.centerIn: parent
|
||||
ratio: SystemStatService.memPercent / 100
|
||||
icon: "memory"
|
||||
contentScale: root.contentScale
|
||||
fillColor: SystemStatService.memColor
|
||||
tooltipText: I18n.tr("common.memory") + `: ${Math.round(SystemStatService.memPercent)}%`
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: SystemStatService
|
||||
function onMemPercentChanged() {
|
||||
if (TooltipService.activeTooltip && TooltipService.activeTooltip.targetItem === memPercentGauge) {
|
||||
TooltipService.updateText(I18n.tr("common.memory") + `: ${Math.round(SystemStatService.memPercent)}%`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: parent.height / 4
|
||||
|
||||
NCircleStat {
|
||||
id: diskPercentsGauge
|
||||
anchors.centerIn: parent
|
||||
ratio: (SystemStatService.diskPercents[root.diskPath] ?? 0) / 100
|
||||
icon: "storage"
|
||||
contentScale: root.contentScale
|
||||
fillColor: SystemStatService.getDiskColor(root.diskPath)
|
||||
tooltipText: I18n.tr("system-monitor.disk") + `: ${SystemStatService.diskPercents[root.diskPath] || 0}%\n${root.diskPath}`
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: SystemStatService
|
||||
function onDiskPercentsChanged() {
|
||||
if (TooltipService.activeTooltip && TooltipService.activeTooltip.targetItem === diskPercentsGauge) {
|
||||
TooltipService.updateText(I18n.tr("system-monitor.disk") + `: ${SystemStatService.diskPercents[root.diskPath] || 0}%\n${root.diskPath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
import QtQuick
|
||||
import QtQuick.Effects
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.Location
|
||||
import qs.Widgets
|
||||
|
||||
// Weather overview card (placeholder data)
|
||||
NBox {
|
||||
id: root
|
||||
|
||||
property int forecastDays: 6
|
||||
property bool showLocation: true
|
||||
property bool showEffects: Settings.data.location.weatherShowEffects
|
||||
readonly property bool weatherReady: Settings.data.location.weatherEnabled && (LocationService.data.weather !== null)
|
||||
|
||||
// Test mode: set to "clear_day", "clear_night", "rain", "snow", "cloud" or "fog"
|
||||
property string testEffects: ""
|
||||
|
||||
// Weather condition detection
|
||||
readonly property int currentWeatherCode: weatherReady ? LocationService.data.weather.current_weather.weathercode : 0
|
||||
readonly property bool isDayTime: weatherReady ? LocationService.data.weather.current_weather.is_day : true
|
||||
readonly property bool isRaining: testEffects === "rain" || (testEffects === "" && ((currentWeatherCode >= 51 && currentWeatherCode <= 67) || (currentWeatherCode >= 80 && currentWeatherCode <= 82)))
|
||||
readonly property bool isSnowing: testEffects === "snow" || (testEffects === "" && ((currentWeatherCode >= 71 && currentWeatherCode <= 77) || (currentWeatherCode >= 85 && currentWeatherCode <= 86)))
|
||||
readonly property bool isCloudy: testEffects === "cloud" || (testEffects === "" && (currentWeatherCode === 3))
|
||||
readonly property bool isFoggy: testEffects === "fog" || (testEffects === "" && (currentWeatherCode >= 40 && currentWeatherCode <= 49))
|
||||
readonly property bool isClearDay: testEffects === "clear_day" || (testEffects === "" && (currentWeatherCode === 0 && isDayTime))
|
||||
readonly property bool isClearNight: testEffects === "clear_night" || (testEffects === "" && (currentWeatherCode === 0 && !isDayTime))
|
||||
|
||||
visible: Settings.data.location.weatherEnabled
|
||||
implicitHeight: Math.max(100 * Style.uiScaleRatio, content.implicitHeight + Style.margin2XL)
|
||||
|
||||
// Weather effect layer (rain/snow)
|
||||
Loader {
|
||||
id: weatherEffectLoader
|
||||
anchors.fill: parent
|
||||
active: root.showEffects && (root.isRaining || root.isSnowing || root.isCloudy || root.isFoggy || root.isClearDay || root.isClearNight)
|
||||
|
||||
sourceComponent: Item {
|
||||
anchors.fill: parent
|
||||
|
||||
// Animated time for shaders
|
||||
property real shaderTime: 0
|
||||
NumberAnimation on shaderTime {
|
||||
loops: Animation.Infinite
|
||||
from: 0
|
||||
to: root.isSnowing ? 900 : 3000
|
||||
duration: 300000
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: weatherEffect
|
||||
anchors.fill: parent
|
||||
// Rain matches content margins, everything else fills the box
|
||||
anchors.margins: root.isRaining ? Style.marginXL : root.border.width
|
||||
|
||||
property var source: ShaderEffectSource {
|
||||
sourceItem: content
|
||||
hideSource: root.isRaining // Only hide for rain (distortion), show for snow
|
||||
}
|
||||
|
||||
// Limit update rate to avoid using too much processing power
|
||||
property real time: parent.shaderTime - (parent.shaderTime % (1 / (root.isRaining ? 3 : root.isSnowing ? 6 : 2)))
|
||||
property real itemWidth: weatherEffect.width
|
||||
property real itemHeight: weatherEffect.height
|
||||
property color bgColor: root.color
|
||||
property real cornerRadius: root.isRaining ? 0 : (root.radius - root.border.width)
|
||||
property real alternative: root.isFoggy
|
||||
|
||||
fragmentShader: {
|
||||
let shaderName;
|
||||
if (root.isSnowing)
|
||||
shaderName = "weather_snow";
|
||||
else if (root.isRaining)
|
||||
shaderName = "weather_rain";
|
||||
else if (root.isCloudy || root.isFoggy)
|
||||
shaderName = "weather_cloud";
|
||||
else if (root.isClearDay)
|
||||
shaderName = "weather_sun";
|
||||
else if (root.isClearNight)
|
||||
shaderName = "weather_stars";
|
||||
else
|
||||
shaderName = "";
|
||||
|
||||
return Qt.resolvedUrl(Quickshell.shellDir + "/Shaders/qsb/" + shaderName + ".frag.qsb");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: content
|
||||
anchors.fill: parent
|
||||
anchors.margins: Style.marginXL
|
||||
spacing: Style.marginM
|
||||
clip: true
|
||||
|
||||
RowLayout {
|
||||
visible: weatherReady
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginS
|
||||
|
||||
Item {
|
||||
Layout.preferredWidth: Style.marginXXS
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: Style.marginL
|
||||
Layout.fillWidth: true
|
||||
|
||||
Item {
|
||||
Layout.preferredWidth: mainWeatherIconSide
|
||||
Layout.preferredHeight: mainWeatherIconSide
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
readonly property int mainWeatherIconSide: Math.round(Style.fontSizeXXXL * 1.75 * Style.uiScaleRatio * 1.6)
|
||||
|
||||
NIcon {
|
||||
visible: !LocationService.taliaWeatherMascotActive
|
||||
anchors.centerIn: parent
|
||||
icon: weatherReady ? LocationService.weatherSymbolFromCode(LocationService.data.weather.current_weather.weathercode) : ""
|
||||
pointSize: Style.fontSizeXXXL * 1.75
|
||||
color: Color.mPrimary
|
||||
}
|
||||
Loader {
|
||||
active: LocationService.taliaWeatherMascotActive
|
||||
anchors.fill: parent
|
||||
asynchronous: true
|
||||
sourceComponent: Component {
|
||||
Image {
|
||||
anchors.fill: parent
|
||||
fillMode: Image.PreserveAspectFit
|
||||
smooth: true
|
||||
mipmap: true
|
||||
asynchronous: true
|
||||
source: Qt.resolvedUrl(LocationService.taliaWeatherImageFromCode(currentWeatherCode))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
spacing: Style.marginXXS
|
||||
NText {
|
||||
text: {
|
||||
// Ensure the name is not too long if one had to specify the country
|
||||
const chunks = Settings.data.location.name.split(",");
|
||||
return chunks[0];
|
||||
}
|
||||
pointSize: Style.fontSizeL
|
||||
font.weight: Style.fontWeightBold
|
||||
visible: showLocation && !Settings.data.location.hideWeatherCityName
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
NText {
|
||||
text: {
|
||||
if (!weatherReady)
|
||||
return "";
|
||||
var temp = LocationService.data.weather.current_weather.temperature;
|
||||
var suffix = "C";
|
||||
if (Settings.data.location.useFahrenheit) {
|
||||
temp = LocationService.celsiusToFahrenheit(temp);
|
||||
var suffix = "F";
|
||||
}
|
||||
temp = Math.round(temp);
|
||||
return `${temp}°${suffix}`;
|
||||
}
|
||||
pointSize: showLocation ? Style.fontSizeXL : Style.fontSizeXL * 1.6
|
||||
font.weight: Style.fontWeightBold
|
||||
}
|
||||
|
||||
NText {
|
||||
text: weatherReady ? `(${LocationService.data.weather.timezone_abbreviation})` : ""
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Color.mOnSurfaceVariant
|
||||
visible: LocationService.data.weather && showLocation && !Settings.data.location.hideWeatherTimezone
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NDivider {
|
||||
visible: weatherReady
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
visible: weatherReady
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
spacing: Style.marginM
|
||||
|
||||
Repeater {
|
||||
model: weatherReady ? Math.min(root.forecastDays, LocationService.data.weather.daily.time.length) : 0
|
||||
delegate: ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginXS
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
NText {
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
|
||||
text: {
|
||||
var weatherDate = new Date(LocationService.data.weather.daily.time[index].replace(/-/g, "/"));
|
||||
return I18n.locale.toString(weatherDate, "ddd");
|
||||
}
|
||||
color: Color.mOnSurface
|
||||
}
|
||||
Item {
|
||||
Layout.preferredWidth: forecastWeatherIconSide
|
||||
Layout.preferredHeight: forecastWeatherIconSide
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
|
||||
readonly property int forecastWeatherIconSide: Math.round(Style.fontSizeXXL * 1.6 * Style.uiScaleRatio * 1.6)
|
||||
|
||||
NIcon {
|
||||
visible: !LocationService.taliaWeatherMascotActive
|
||||
anchors.centerIn: parent
|
||||
icon: LocationService.weatherSymbolFromCode(LocationService.data.weather.daily.weathercode[index])
|
||||
pointSize: Style.fontSizeXXL * 1.6
|
||||
color: Color.mPrimary
|
||||
}
|
||||
Loader {
|
||||
active: LocationService.taliaWeatherMascotActive
|
||||
anchors.fill: parent
|
||||
asynchronous: true
|
||||
sourceComponent: Component {
|
||||
Image {
|
||||
anchors.fill: parent
|
||||
fillMode: Image.PreserveAspectFit
|
||||
smooth: true
|
||||
mipmap: true
|
||||
asynchronous: true
|
||||
source: Qt.resolvedUrl(LocationService.taliaWeatherImageFromCode(LocationService.data.weather.daily.weathercode[index]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NText {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: {
|
||||
var max = LocationService.data.weather.daily.temperature_2m_max[index];
|
||||
var min = LocationService.data.weather.daily.temperature_2m_min[index];
|
||||
if (Settings.data.location.useFahrenheit) {
|
||||
max = LocationService.celsiusToFahrenheit(max);
|
||||
min = LocationService.celsiusToFahrenheit(min);
|
||||
}
|
||||
max = Math.round(max);
|
||||
min = Math.round(min);
|
||||
return `${max}°/${min}°`;
|
||||
}
|
||||
pointSize: Style.fontSizeXS
|
||||
color: Color.mOnSurfaceVariant
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
visible: !weatherReady
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
spacing: Style.marginS
|
||||
|
||||
NBusyIndicator {
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
visible: LocationService.locationConfigured
|
||||
}
|
||||
|
||||
NText {
|
||||
visible: !LocationService.locationConfigured
|
||||
Layout.alignment: Qt.AlignCenter
|
||||
text: I18n.tr("common.weather-no-location")
|
||||
pointSize: Style.fontSizeS
|
||||
color: Color.mOnSurfaceVariant
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user