feat: dashboard show on hover, media and weather tabs added

This commit is contained in:
2026-09-30 14:22:22 +02:00
parent d259c6ffbe
commit 2c90339c77
97 changed files with 4480 additions and 990 deletions
+2
View File
@@ -1,5 +1,6 @@
qml_module(ZShell-config
URI ZShell.Config
INCLUDE_PREFIX config
SOURCES
confignode.hpp confignode.cpp
configobject.hpp configobject.cpp
@@ -14,6 +15,7 @@ qml_module(ZShell-config
colors.hpp
dashboard.hpp
dock.hpp
enums.hpp
general.hpp
launcher.hpp
lock.hpp
+2
View File
@@ -48,6 +48,8 @@ class Dashboard : public ConfigObject {
QML_ANONYMOUS
CFG_PROPERTY(bool, enabled, true)
CFG_PROPERTY(bool, showOnHover, true)
CFG_PROPERTY(int, dragThreshold, 50)
CFG_PROPERTY(int, mediaUpdateInterval, 2000)
CONFIG_SUBOBJECT(Performance, performance)
CFG_PROPERTY(int, resourceUpdateInterval, 1000)
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include <qobject.h>
#include <qqmlintegration.h>
namespace ZShell::config {
#define ENUM(Name, ...) \
namespace Name { \
\
Q_NAMESPACE \
QML_ELEMENT \
\
enum Enum : quint8 { __VA_ARGS__ }; \
Q_ENUM_NS(Enum) \
};
ENUM(BarWorkspaceDisplay, Shapes, Text, Icons)
ENUM(BarWorkspaceCapitalisation, Preserve, Upper, Lower)
ENUM(LyricsBackend, Auto, Local, LRCLIB, NetEase)
ENUM(GpuType, Auto, Nvidia, Generic, None)
ENUM(NotifsFullscreen, On, Off)
ENUM(TemperatureUnit, Auto, Celsius, Fahrenheit, Kelvin)
ENUM(DataUnit, Binary, Decimal)
ENUM(ClockFormat, Auto, TwelveHour, TwentyFourHour)
#undef ENUM
} // namespace ZShell::config
+5
View File
@@ -1,6 +1,7 @@
#pragma once
#include "configlist.hpp"
#include "configobject.hpp"
#include <QStandardPaths>
#include <QStringList>
namespace ZShell::config {
@@ -141,6 +142,10 @@ class General : public ConfigObject {
CFG_PROPERTY(QString, dateFormat, QStringLiteral("ddd d MMM - hh:mm:ss"))
CFG_PROPERTY(bool, desktopIcons, true)
CONFIG_SUBOBJECT(Idle, idle)
CFG_PROPERTY(
QString,
lyricsDir,
QStandardPaths::writableLocation(QStandardPaths::MusicLocation) + QStringLiteral("/Lyrics/"))
CFG_PROPERTY(QString, logo, QString())
CFG_PROPERTY(bool, showOverFullscreen, true)
CFG_PROPERTY(
+2
View File
@@ -1,6 +1,7 @@
#pragma once
#include "configlist.hpp"
#include "configobject.hpp"
#include "enums.hpp"
namespace ZShell::config {
@@ -31,6 +32,7 @@ class Services : public ConfigObject {
CFG_PROPERTY(bool, ddcutilService, true)
CFG_PROPERTY(QString, defaultPlayer, QStringLiteral("Spotify"))
CFG_PROPERTY(QString, gpuType, QStringLiteral("NVIDIA"))
CFG_PROPERTY(LyricsBackend::Enum, lyricsBackend, LyricsBackend::Auto)
CFG_PROPERTY(qreal, maxVolume, 1)
CFG_PROPERTY(qreal, minBrightness, 0.01)
CONFIG_LIST(
+106 -11
View File
@@ -1,9 +1,11 @@
#include "sparklineitem.hpp"
#include <qmath.h>
#include <qnumeric.h>
#include <qpainter.h>
#include <qpainterpath.h>
#include <qpen.h>
#include <qtypes.h>
namespace ZShell::internal {
@@ -35,9 +37,19 @@ void SparklineItem::drawLine(
const int len = buffer->count();
if (len < 2 || m_maxValue <= 0.0) return;
const qreal stepX = w / static_cast<qreal>(m_historyLength - 1);
const qreal startX =
w - (len - 1) * stepX - stepX * m_slideProgress + stepX;
qreal stepX = 0.0;
if (m_sliding)
stepX = w / static_cast<qreal>(m_historyLength - 1);
else
stepX = w / static_cast<qreal>(len - 1);
qreal startX = 0.0;
if (m_sliding)
startX = w - (len - 1) * stepX - stepX * m_slideProgress + stepX;
else
startX = 0;
const qreal strokePad = qCeil(m_lineWidth / 2);
const qreal curvePad = 3.0;
@@ -52,24 +64,75 @@ void SparklineItem::drawLine(
points.reserve(len);
for (int i = 0; i < len; ++i) {
qreal value = 0.0;
if (m_smoothing > 0.0) {
const int radius = qRound(m_smoothing);
qreal sum = 0.0;
int count = 0;
for (int j = -radius; j <= radius; ++j) {
const int index = i + j;
if (index < 0 || index >= len) continue;
sum += buffer->at(index);
count++;
}
value = sum / static_cast<qreal>(count);
} else {
value = buffer->at(i);
}
value = qBound<qreal>(0.0, value, m_maxValue);
const qreal x = startX + i * stepX;
const qreal value = qBound<qreal>(0.0, buffer->at(i), m_maxValue);
const qreal y = plotTop + (1.0 - (value / m_maxValue)) * plotH;
points.append(QPointF(x, y));
}
QPainterPath linePath;
linePath.moveTo(points[0]);
for (int i = 0; i < points.size() - 1; ++i) {
const QPointF& p0 = points[i];
const QPointF& p1 = points[i + 1];
if (m_curveSmoothing && points.size() > 2) {
// 1.0 = standard uniform Catmull-Rom. Lower (e.g. 0.5) = tighter, less overshoot.
const qreal tension = 1.0;
const qreal k =
tension / 6.0; // Catmull-Rom -> Bezier factor (1/6 for uniform)
const qreal ctrlX = (p0.x() + p1.x()) * 0.5;
const QPointF c1(ctrlX, p0.y());
const QPointF c2(ctrlX, p1.y());
const int n = points.size();
linePath.cubicTo(c1, c2, p1);
for (int i = 0; i < n - 1; ++i) {
// Duplicate endpoints so the first/last segments are well-defined
const QPointF& p0 = points[qMax(i - 1, 0)];
const QPointF& p1 = points[i];
const QPointF& p2 = points[i + 1];
const QPointF& p3 = points[qMin(i + 2, n - 1)];
QPointF c1 = p1 + (p2 - p0) * k;
QPointF c2 = p2 - (p3 - p1) * k;
// Keep control points inside the vertical range of the segment's
// endpoints so we never overshoot (no dips below zero, no
// bulges above a peak). Remember: smaller y = higher value.
const qreal segMinY = qMin(p1.y(), p2.y());
const qreal segMaxY = qMax(p1.y(), p2.y());
c1.setY(qBound(segMinY, c1.y(), segMaxY));
c2.setY(qBound(segMinY, c2.y(), segMaxY));
linePath.cubicTo(c1, c2, p2);
}
} else {
// Existing horizontal-tangent (smoothstep-style) curve
for (int i = 0; i < points.size() - 1; ++i) {
const QPointF& p0 = points[i];
const QPointF& p1 = points[i + 1];
const qreal ctrlX = (p0.x() + p1.x()) * 0.5;
linePath.cubicTo(QPointF(ctrlX, p0.y()), QPointF(ctrlX, p1.y()), p1);
}
}
QPen pen(color, m_lineWidth);
@@ -224,4 +287,36 @@ void SparklineItem::setLineWidth(qreal width) {
update();
}
void SparklineItem::setSliding(bool sliding) {
if (m_sliding == sliding) return;
m_sliding = sliding;
emit slidingChanged();
}
bool SparklineItem::sliding() const {
return m_sliding;
};
void SparklineItem::setSmoothing(qreal smoothing) {
smoothing = qMax<qreal>(0.0, smoothing);
if (qFuzzyCompare(m_smoothing, smoothing)) return;
m_smoothing = smoothing;
emit smoothingChanged();
}
qreal SparklineItem::smoothing() const {
return m_smoothing;
};
void SparklineItem::setCurveSmoothing(bool sliding) {
if (m_curveSmoothing == sliding) return;
m_curveSmoothing = sliding;
emit curveSmoothingChanged();
}
bool SparklineItem::curveSmoothing() const {
return m_curveSmoothing;
};
} // namespace ZShell::internal
+23
View File
@@ -4,6 +4,7 @@
#include <qobject.h>
#include <qqmlintegration.h>
#include <qquickpainteditem.h>
#include <qtmetamacros.h>
#include "circularbuffer.hpp"
@@ -40,6 +41,13 @@ class SparklineItem : public QQuickPaintedItem {
Q_PROPERTY(
qreal lineWidth READ lineWidth WRITE setLineWidth NOTIFY
lineWidthChanged)
Q_PROPERTY(bool sliding READ sliding WRITE setSliding NOTIFY slidingChanged)
Q_PROPERTY(
qreal smoothing READ smoothing WRITE setSmoothing NOTIFY
smoothingChanged)
Q_PROPERTY(
bool curveSmoothing READ curveSmoothing WRITE setCurveSmoothing NOTIFY
curveSmoothingChanged)
public:
explicit SparklineItem(QQuickItem* parent = nullptr);
@@ -76,6 +84,15 @@ class SparklineItem : public QQuickPaintedItem {
[[nodiscard]] qreal lineWidth() const;
void setLineWidth(qreal width);
[[nodiscard]] bool sliding() const;
void setSliding(bool sliding);
[[nodiscard]] qreal smoothing() const;
void setSmoothing(qreal smoothing);
[[nodiscard]] bool curveSmoothing() const;
void setCurveSmoothing(bool curveSmoothing);
signals:
void line1Changed();
void line2Changed();
@@ -87,6 +104,9 @@ class SparklineItem : public QQuickPaintedItem {
void slideProgressChanged();
void historyLengthChanged();
void lineWidthChanged();
void slidingChanged();
void smoothingChanged();
void curveSmoothingChanged();
private:
void drawLine(
@@ -106,6 +126,9 @@ class SparklineItem : public QQuickPaintedItem {
qreal m_slideProgress = 0.0;
int m_historyLength = 30;
qreal m_lineWidth = 2.0;
bool m_sliding = true;
qreal m_smoothing = 0.0;
bool m_curveSmoothing = false;
};
} // namespace ZShell::internal
+6 -1
View File
@@ -18,6 +18,8 @@ qml_module(ZShell-services
memory.hpp memory.cpp
diskinfo.hpp diskinfo.cpp
storage.hpp storage.cpp
lyriccandidate.hpp lyriccandidate.cpp
lyrics.hpp lyrics.cpp
LIBRARIES
Qt6::Core
Qt6::Qml
@@ -25,4 +27,7 @@ qml_module(ZShell-services
PkgConfig::Aubio
PkgConfig::Cava
Sensors::Sensors
)
ZShell-config
DEPENDENCIES
ZShell.Config
)
@@ -0,0 +1,55 @@
#include "lyriccandidate.hpp"
namespace ZShell::services {
LyricCandidate::LyricCandidate(
LyricsBackend backend,
QString id,
QString title,
QString artist,
QString album,
qreal duration)
: m_backend(backend)
, m_id(std::move(id))
, m_title(std::move(title))
, m_artist(std::move(artist))
, m_album(std::move(album))
, m_duration(duration) {}
LyricsBackend LyricCandidate::backend() const {
return m_backend;
}
QString LyricCandidate::id() const {
return m_id;
}
QString LyricCandidate::title() const {
return m_title;
}
QString LyricCandidate::artist() const {
return m_artist;
}
QString LyricCandidate::album() const {
return m_album;
}
qreal LyricCandidate::duration() const {
return m_duration;
}
bool LyricCandidate::isValid() const {
return !m_id.isEmpty();
}
bool LyricCandidate::operator==(const LyricCandidate& o) const noexcept {
return m_backend == o.m_backend && m_id == o.m_id;
}
bool LyricCandidate::operator!=(const LyricCandidate& o) const noexcept {
return !(*this == o);
}
} // namespace ZShell::services
@@ -0,0 +1,53 @@
#pragma once
#include <qobject.h>
#include <qqmlintegration.h>
#include "config/enums.hpp"
namespace ZShell::services {
using LyricsBackend = config::LyricsBackend::Enum;
class LyricCandidate {
Q_GADGET
QML_VALUE_TYPE(lyricCandidate)
Q_PROPERTY(ZShell::config::LyricsBackend::Enum backend READ backend)
Q_PROPERTY(QString id READ id)
Q_PROPERTY(QString title READ title)
Q_PROPERTY(QString artist READ artist)
Q_PROPERTY(QString album READ album)
Q_PROPERTY(qreal duration READ duration)
public:
LyricCandidate() = default;
LyricCandidate(
LyricsBackend backend,
QString id,
QString title,
QString artist,
QString album = {},
qreal duration = 0.0);
[[nodiscard]] LyricsBackend backend() const;
[[nodiscard]] QString id() const;
[[nodiscard]] QString title() const;
[[nodiscard]] QString artist() const;
[[nodiscard]] QString album() const;
[[nodiscard]] qreal duration() const;
[[nodiscard]] bool isValid() const;
bool operator==(const LyricCandidate& o) const noexcept;
bool operator!=(const LyricCandidate& o) const noexcept;
private:
LyricsBackend m_backend = LyricsBackend::Auto;
QString m_id;
QString m_title;
QString m_artist;
QString m_album;
qreal m_duration = 0.0;
};
} // namespace ZShell::services
File diff suppressed because it is too large Load Diff
+162
View File
@@ -0,0 +1,162 @@
#pragma once
#include <qhash.h>
#include <qjsonobject.h>
#include <qnetworkaccessmanager.h>
#include <qnetworkreply.h>
#include <qtimer.h>
#include "lyriccandidate.hpp"
namespace ZShell::services {
struct LyricLine {
qreal time = 0.0;
QString text;
};
class Lyrics : public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(QStringList lyrics READ lyrics NOTIFY lyricsChanged)
Q_PROPERTY(
ZShell::config::LyricsBackend::Enum backend READ backend NOTIFY
backendChanged)
Q_PROPERTY(
ZShell::config::LyricsBackend::Enum preferredBackend READ
preferredBackend WRITE setPreferredBackend NOTIFY
preferredBackendChanged)
Q_PROPERTY(
QList<ZShell::services::LyricCandidate> lyricCandidates READ
lyricCandidates NOTIFY lyricCandidatesChanged)
Q_PROPERTY(
ZShell::services::LyricCandidate selectedCandidate READ selectedCandidate
WRITE setSelectedCandidate NOTIFY selectedCandidateChanged)
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
Q_PROPERTY(bool hasLyrics READ hasLyrics NOTIFY hasLyricsChanged)
Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged)
Q_PROPERTY(QString trackArtist READ trackArtist NOTIFY trackChanged)
Q_PROPERTY(QString trackTitle READ trackTitle NOTIFY trackChanged)
public:
explicit Lyrics(QObject* parent = nullptr);
[[nodiscard]] QStringList lyrics() const;
[[nodiscard]] LyricsBackend backend() const;
[[nodiscard]] LyricsBackend preferredBackend() const;
void setPreferredBackend(LyricsBackend value);
[[nodiscard]] QList<LyricCandidate> lyricCandidates() const;
[[nodiscard]] LyricCandidate selectedCandidate() const;
void setSelectedCandidate(const LyricCandidate& value);
[[nodiscard]] bool loading() const;
[[nodiscard]] bool hasLyrics() const;
[[nodiscard]] qreal offset() const;
void setOffset(qreal value);
[[nodiscard]] QString trackArtist() const;
[[nodiscard]] QString trackTitle() const;
[[nodiscard]] Q_INVOKABLE int indexForTime(qreal time) const;
[[nodiscard]] Q_INVOKABLE qreal timeForIndex(int index) const;
Q_INVOKABLE void setTrack(
const QString& artist,
const QString& title,
const QString& album = {},
qreal duration = 0.0);
Q_INVOKABLE void clearTrack();
Q_INVOKABLE void refresh();
signals:
void lyricsChanged();
void backendChanged();
void preferredBackendChanged();
void lyricCandidatesChanged();
void selectedCandidateChanged();
void loadingChanged();
void hasLyricsChanged();
void offsetChanged();
void trackChanged();
private:
void setBackend(LyricsBackend value);
void setLoading(bool value);
void setLines(QVector<LyricLine> lines, LyricsBackend source);
void clearLines();
void appendCandidates(const QList<LyricCandidate>& add);
void clearCandidates();
void scheduleLoad();
void doLoad();
void cancelInFlight();
int newRequestId();
void tryLocal(int reqId);
void tryLrclib(int reqId);
void tryNetEase(int reqId);
void chainNext(LyricsBackend justFailed, int reqId);
void searchLrclibCandidates(int reqId);
void searchNetEaseCandidates(int reqId);
void fetchLrclibById(const QString& id, int reqId);
void fetchNetEaseLyricsById(const QString& id, int reqId);
QNetworkReply* getJson(
const QUrl& url, const QHash<QByteArray, QByteArray>& headers = {});
void trackReply(int reqId, QNetworkReply* reply);
void onPreferredBackendConfigChanged();
void onLyricsDirChanged();
void loadLyricsMap();
void persistTrackPrefs();
[[nodiscard]] static QString lyricsDir();
[[nodiscard]] static QString lyricsMapPath();
[[nodiscard]] QString trackKey() const;
[[nodiscard]] static QString backendKey(LyricsBackend value);
[[nodiscard]] static LyricsBackend backendFromKey(const QString& key);
[[nodiscard]] static const QString& stateDir();
[[nodiscard]] static const QString& cacheDir();
[[nodiscard]] static QString cachePathFor(
LyricsBackend backend, const QString& id);
[[nodiscard]] static QString readCachedLrc(
LyricsBackend backend, const QString& id);
static void writeCachedLrc(
LyricsBackend backend, const QString& id, const QString& text);
[[nodiscard]] static QVector<LyricLine> parseLrc(const QString& text);
[[nodiscard]] static QString tryReadLocalLrc(
const QString& dir, const QString& artist, const QString& title);
[[nodiscard]] static QString findLocalLrcRecursive(
const QString& dir, const QString& artist, const QString& title);
QNetworkAccessManager* m_nam;
QTimer* m_loadDebounce;
QVector<LyricLine> m_lines;
QStringList m_lyrics;
LyricsBackend m_backend = LyricsBackend::Auto;
LyricsBackend m_preferredBackend = LyricsBackend::Auto;
QList<LyricCandidate> m_candidates;
LyricCandidate m_selected;
bool m_loading = false;
bool m_hasLyrics = false;
qreal m_offset = 0.0;
QString m_artist;
QString m_title;
QString m_album;
qreal m_duration = 0.0;
int m_currentRequestId = 0;
QHash<int, QList<QPointer<QNetworkReply>>> m_pendingReplies;
QJsonObject m_lyricsMap;
bool m_lyricsMapLoaded = false;
bool m_settingFromPrefs = false;
};
} // namespace ZShell::services