Compare commits
7 Commits
dc4b9fc047
...
master
Author | SHA1 | Date | |
---|---|---|---|
af38103c0d | |||
094a83512e | |||
5f6c89673c | |||
010e7162fd | |||
097b32c70d | |||
042988ffbb | |||
91c6672f5c |
@ -58,6 +58,7 @@ set (PMUSIC_HEADER_FILES
|
|||||||
lyricsmanager.h
|
lyricsmanager.h
|
||||||
fftspectrum.h
|
fftspectrum.h
|
||||||
playbackprogressindicator.h
|
playbackprogressindicator.h
|
||||||
|
taskbarmanager.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set (PMUSIC_UI_FILES
|
set (PMUSIC_UI_FILES
|
||||||
@ -84,6 +85,9 @@ TS_FILES
|
|||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_sources(${EXE_NAME} PRIVATE assets/pineapple-music.rc)
|
target_sources(${EXE_NAME} PRIVATE assets/pineapple-music.rc)
|
||||||
|
target_sources(${EXE_NAME} PRIVATE taskbarmanager.cpp)
|
||||||
|
else ()
|
||||||
|
target_sources(${EXE_NAME} PRIVATE taskbarmanager_dummy.cpp)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT TagLib_FOUND)
|
if (NOT TagLib_FOUND)
|
||||||
|
@ -23,7 +23,6 @@ These features are not available, some of them are TBD and others are not planne
|
|||||||
- Limited system integration:
|
- Limited system integration:
|
||||||
- No [SMTC](https://learn.microsoft.com/en-us/uwp/api/windows.media.systemmediatransportcontrols) support under Windows for now
|
- No [SMTC](https://learn.microsoft.com/en-us/uwp/api/windows.media.systemmediatransportcontrols) support under Windows for now
|
||||||
- No [MPRIS](https://www.freedesktop.org/wiki/Specifications/mpris-spec/) support under Linux desktop for now
|
- No [MPRIS](https://www.freedesktop.org/wiki/Specifications/mpris-spec/) support under Linux desktop for now
|
||||||
- No "playback progress on taskbar icon" and "taskbar thumbnail buttons" support whatever on Windows or Linux desktop for now
|
|
||||||
- Limited lyrics (`.lrc`) loading support:
|
- Limited lyrics (`.lrc`) loading support:
|
||||||
- Currently no `.tlrc` (for translated lyrics) or `.rlrc` (for romanized lyrics) support.
|
- Currently no `.tlrc` (for translated lyrics) or `.rlrc` (for romanized lyrics) support.
|
||||||
- Multi-line lyrics and duplicated timestamps are not supported
|
- Multi-line lyrics and duplicated timestamps are not supported
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include <kissfft.hh>
|
#include <kissfft.hh>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
FFTSpectrum::FFTSpectrum(QWidget* parent)
|
FFTSpectrum::FFTSpectrum(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@ -81,14 +86,35 @@ FFTSpectrum::FFTSpectrum(QWidget* parent)
|
|||||||
qWarning() << "Unsupported format or channel config:" << sampleFormat << channelConfig;
|
qWarning() << "Unsupported format or channel config:" << sampleFormat << channelConfig;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Apply Hanning window to reduce spectral leakage
|
||||||
|
for (int i = 0; i < frameCount; ++i) {
|
||||||
|
float window = 0.5f * (1.0f - cos(2.0f * M_PI * i / (frameCount - 1)));
|
||||||
|
samples[i].real(samples[i].real() * window);
|
||||||
|
}
|
||||||
fft.transform(samples.data(), mass.data());
|
fft.transform(samples.data(), mass.data());
|
||||||
m_freq.resize(frameCount);
|
// Use only the first half of FFT result (positive frequencies)
|
||||||
for (int i = 0; i < frameCount; i++) {
|
int spectrumSize = frameCount / 2;
|
||||||
|
m_freq.resize(spectrumSize);
|
||||||
|
for (int i = 0; i < spectrumSize; i++) {
|
||||||
m_freq[i] = sqrt(mass[i].real() * mass[i].real() + mass[i].imag() * mass[i].imag());
|
m_freq[i] = sqrt(mass[i].real() * mass[i].real() + mass[i].imag() * mass[i].imag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove DC component and very low frequencies (like most spectrum analyzers do)
|
||||||
|
// DC component (0 Hz) is usually not musically relevant
|
||||||
|
m_freq[0] = 0;
|
||||||
|
|
||||||
|
// Optionally remove the first few bins (very low frequencies below ~20Hz)
|
||||||
|
// Calculate how many bins correspond to frequencies below 20Hz
|
||||||
|
int sampleRate = fmt.sampleRate();
|
||||||
|
int lowFreqCutoff = std::min(3, (20 * frameCount) / (sampleRate * 2)); // Limit to first 3 bins max
|
||||||
|
for (int i = 1; i <= lowFreqCutoff && i < spectrumSize; i++) {
|
||||||
|
m_freq[i] *= (float(i) / float(lowFreqCutoff + 1)); // Gradual fade-in instead of hard cut
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& val : m_freq) {
|
for (auto& val : m_freq) {
|
||||||
val = log10(val + 1);
|
val = log10(val + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
});
|
});
|
||||||
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
||||||
@ -113,11 +139,19 @@ void FFTSpectrum::paintEvent(QPaintEvent* e)
|
|||||||
if (!m_freq.empty()) {
|
if (!m_freq.empty()) {
|
||||||
int width = this->width();
|
int width = this->width();
|
||||||
int height = this->height();
|
int height = this->height();
|
||||||
int barWidth = std::max(1, (int)(width / m_freq.size()));
|
int barWidth = std::max(1, width / static_cast<int>(m_freq.size()));
|
||||||
for (int i = 0; i < m_freq.size(); i++) {
|
|
||||||
int barHeight = static_cast<int>(sqrt(m_freq[i]) * height * 0.5);
|
for (size_t i = 0; i < m_freq.size(); i++) {
|
||||||
QColor color(70, 130, 180, std::min(255, (int)(140 * m_freq[i]) + 90));
|
// Use sqrt to compress the range similar to original, but safer
|
||||||
painter.fillRect(i * barWidth, height - barHeight, barWidth, barHeight, color);
|
int barHeight = static_cast<int>(sqrt(std::max(0.0f, m_freq[i])) * height * 0.5);
|
||||||
|
barHeight = std::max(0, std::min(barHeight, height));
|
||||||
|
|
||||||
|
// Calculate alpha based on frequency value, similar to original
|
||||||
|
int alpha = std::min(255, static_cast<int>(140 * m_freq[i]) + 90);
|
||||||
|
alpha = std::max(90, alpha);
|
||||||
|
|
||||||
|
QColor color(70, 130, 180, alpha);
|
||||||
|
painter.fillRect(static_cast<int>(i) * barWidth, height - barHeight, barWidth, barHeight, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,82 +12,113 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>MainWindow</name>
|
<name>MainWindow</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="93"/>
|
<location filename="../mainwindow.cpp" line="125"/>
|
||||||
<source>Mono</source>
|
<source>Mono</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="95"/>
|
<location filename="../mainwindow.cpp" line="127"/>
|
||||||
<source>Stereo</source>
|
<source>Stereo</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="97"/>
|
<location filename="../mainwindow.cpp" line="129"/>
|
||||||
<source>%1 Channels</source>
|
<source>%1 Channels</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="241"/>
|
<location filename="../mainwindow.cpp" line="298"/>
|
||||||
<source>Select songs to play</source>
|
<source>Select songs to play</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="243"/>
|
<location filename="../mainwindow.cpp" line="300"/>
|
||||||
<source>Audio Files</source>
|
<source>Audio Files</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="576"/>
|
<location filename="../mainwindow.cpp" line="685"/>
|
||||||
<source>Select image as background skin</source>
|
<source>Select image as background skin</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="578"/>
|
<location filename="../mainwindow.cpp" line="687"/>
|
||||||
<source>Image files (*.jpg *.jpeg *.png *.gif)</source>
|
<source>Image files (*.jpg *.jpeg *.png *.gif)</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../mainwindow.cpp" line="764"/>
|
||||||
|
<source>Based on the following free software libraries:</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="23"/>
|
<location filename="../mainwindow.ui" line="23"/>
|
||||||
|
<location filename="../mainwindow.cpp" line="762"/>
|
||||||
<location filename="../lrcbar.cpp" line="89"/>
|
<location filename="../lrcbar.cpp" line="89"/>
|
||||||
<source>Pineapple Music</source>
|
<source>Pineapple Music</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="313"/>
|
<location filename="../mainwindow.ui" line="327"/>
|
||||||
<source>No song loaded...</source>
|
<source>No song loaded...</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="325"/>
|
<location filename="../mainwindow.ui" line="339"/>
|
||||||
<source>Drag and drop file to load</source>
|
<source>Drag and drop file to load</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="338"/>
|
<location filename="../mainwindow.ui" line="352"/>
|
||||||
<source>Lrc</source>
|
<source>Lrc</source>
|
||||||
<comment>Lyrics</comment>
|
<comment>Lyrics</comment>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="103"/>
|
<location filename="../mainwindow.ui" line="711"/>
|
||||||
|
<location filename="../mainwindow.ui" line="714"/>
|
||||||
|
<location filename="../mainwindow.cpp" line="759"/>
|
||||||
|
<source>About</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../mainwindow.ui" line="728"/>
|
||||||
|
<source>Open</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../mainwindow.cpp" line="135"/>
|
||||||
<source>Sample Rate: %1 Hz</source>
|
<source>Sample Rate: %1 Hz</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="108"/>
|
<location filename="../mainwindow.cpp" line="140"/>
|
||||||
<source>Bitrate: %1 Kbps</source>
|
<source>Bitrate: %1 Kbps</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="113"/>
|
<location filename="../mainwindow.cpp" line="145"/>
|
||||||
<source>Channel Count: %1</source>
|
<source>Channel Count: %1</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>PlaybackProgressIndicator</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../playbackprogressindicator.cpp" line="85"/>
|
||||||
|
<source>Time</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../playbackprogressindicator.cpp" line="85"/>
|
||||||
|
<source>Chapter Name</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>main</name>
|
<name>main</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../main.cpp" line="28"/>
|
<location filename="../main.cpp" line="27"/>
|
||||||
<source>File list.</source>
|
<source>File list.</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
@ -12,82 +12,113 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>MainWindow</name>
|
<name>MainWindow</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="93"/>
|
<location filename="../mainwindow.cpp" line="125"/>
|
||||||
<source>Mono</source>
|
<source>Mono</source>
|
||||||
<translation>单声道</translation>
|
<translation>单声道</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="95"/>
|
<location filename="../mainwindow.cpp" line="127"/>
|
||||||
<source>Stereo</source>
|
<source>Stereo</source>
|
||||||
<translation>立体声</translation>
|
<translation>立体声</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="97"/>
|
<location filename="../mainwindow.cpp" line="129"/>
|
||||||
<source>%1 Channels</source>
|
<source>%1 Channels</source>
|
||||||
<translation>%1 声道</translation>
|
<translation>%1 声道</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="241"/>
|
<location filename="../mainwindow.cpp" line="298"/>
|
||||||
<source>Select songs to play</source>
|
<source>Select songs to play</source>
|
||||||
<translation>选择要播放的曲目</translation>
|
<translation>选择要播放的曲目</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="243"/>
|
<location filename="../mainwindow.cpp" line="300"/>
|
||||||
<source>Audio Files</source>
|
<source>Audio Files</source>
|
||||||
<translation>音频文件</translation>
|
<translation>音频文件</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="576"/>
|
<location filename="../mainwindow.cpp" line="685"/>
|
||||||
<source>Select image as background skin</source>
|
<source>Select image as background skin</source>
|
||||||
<translation>选择图片作为背景皮肤</translation>
|
<translation>选择图片作为背景皮肤</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="578"/>
|
<location filename="../mainwindow.cpp" line="687"/>
|
||||||
<source>Image files (*.jpg *.jpeg *.png *.gif)</source>
|
<source>Image files (*.jpg *.jpeg *.png *.gif)</source>
|
||||||
<translation>图片文件 (*.jpg *.jpeg *.png *.gif)</translation>
|
<translation>图片文件 (*.jpg *.jpeg *.png *.gif)</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../mainwindow.cpp" line="764"/>
|
||||||
|
<source>Based on the following free software libraries:</source>
|
||||||
|
<translation>基于下列自由软件库:</translation>
|
||||||
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="23"/>
|
<location filename="../mainwindow.ui" line="23"/>
|
||||||
|
<location filename="../mainwindow.cpp" line="762"/>
|
||||||
<location filename="../lrcbar.cpp" line="89"/>
|
<location filename="../lrcbar.cpp" line="89"/>
|
||||||
<source>Pineapple Music</source>
|
<source>Pineapple Music</source>
|
||||||
<translation>菠萝音乐</translation>
|
<translation>菠萝音乐</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="313"/>
|
<location filename="../mainwindow.ui" line="327"/>
|
||||||
<source>No song loaded...</source>
|
<source>No song loaded...</source>
|
||||||
<translation>未加载曲目...</translation>
|
<translation>未加载曲目...</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="325"/>
|
<location filename="../mainwindow.ui" line="339"/>
|
||||||
<source>Drag and drop file to load</source>
|
<source>Drag and drop file to load</source>
|
||||||
<translation>拖放文件来播放</translation>
|
<translation>拖放文件来播放</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.ui" line="338"/>
|
<location filename="../mainwindow.ui" line="352"/>
|
||||||
<source>Lrc</source>
|
<source>Lrc</source>
|
||||||
<comment>Lyrics</comment>
|
<comment>Lyrics</comment>
|
||||||
<translation>歌词</translation>
|
<translation>歌词</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="103"/>
|
<location filename="../mainwindow.ui" line="711"/>
|
||||||
|
<location filename="../mainwindow.ui" line="714"/>
|
||||||
|
<location filename="../mainwindow.cpp" line="759"/>
|
||||||
|
<source>About</source>
|
||||||
|
<translation>关于</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../mainwindow.ui" line="728"/>
|
||||||
|
<source>Open</source>
|
||||||
|
<translation>打开</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../mainwindow.cpp" line="135"/>
|
||||||
<source>Sample Rate: %1 Hz</source>
|
<source>Sample Rate: %1 Hz</source>
|
||||||
<translation>采样率: %1 Hz</translation>
|
<translation>采样率: %1 Hz</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="108"/>
|
<location filename="../mainwindow.cpp" line="140"/>
|
||||||
<source>Bitrate: %1 Kbps</source>
|
<source>Bitrate: %1 Kbps</source>
|
||||||
<translation>比特率: %1 Kbps</translation>
|
<translation>比特率: %1 Kbps</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../mainwindow.cpp" line="113"/>
|
<location filename="../mainwindow.cpp" line="145"/>
|
||||||
<source>Channel Count: %1</source>
|
<source>Channel Count: %1</source>
|
||||||
<translation>声道数: %1</translation>
|
<translation>声道数: %1</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>PlaybackProgressIndicator</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../playbackprogressindicator.cpp" line="85"/>
|
||||||
|
<source>Time</source>
|
||||||
|
<translation>时间</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../playbackprogressindicator.cpp" line="85"/>
|
||||||
|
<source>Chapter Name</source>
|
||||||
|
<translation>章节名称</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>main</name>
|
<name>main</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../main.cpp" line="28"/>
|
<location filename="../main.cpp" line="27"/>
|
||||||
<source>File list.</source>
|
<source>File list.</source>
|
||||||
<translation>文件列表。</translation>
|
<translation>文件列表。</translation>
|
||||||
</message>
|
</message>
|
||||||
|
131
mainwindow.cpp
131
mainwindow.cpp
@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
|
// SPDX-FileCopyrightText: 2025 Gary Wang <opensource@blumia.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
@ -8,6 +8,7 @@
|
|||||||
#include "playlistmanager.h"
|
#include "playlistmanager.h"
|
||||||
#include "fftspectrum.h"
|
#include "fftspectrum.h"
|
||||||
#include "lrcbar.h"
|
#include "lrcbar.h"
|
||||||
|
#include "taskbarmanager.h"
|
||||||
|
|
||||||
// taglib
|
// taglib
|
||||||
#ifndef NO_TAGLIB
|
#ifndef NO_TAGLIB
|
||||||
@ -26,6 +27,7 @@
|
|||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QCollator>
|
#include <QCollator>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QMenu>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QMediaDevices>
|
#include <QMediaDevices>
|
||||||
@ -34,6 +36,7 @@
|
|||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QGraphicsDropShadowEffect>
|
#include <QGraphicsDropShadowEffect>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
constexpr QSize miniSize(490, 160);
|
constexpr QSize miniSize(490, 160);
|
||||||
constexpr QSize fullSize(490, 420);
|
constexpr QSize fullSize(490, 420);
|
||||||
@ -47,6 +50,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, m_fftSpectrum(new FFTSpectrum(this))
|
, m_fftSpectrum(new FFTSpectrum(this))
|
||||||
, m_lrcbar(new LrcBar(nullptr))
|
, m_lrcbar(new LrcBar(nullptr))
|
||||||
, m_playlistManager(new PlaylistManager(this))
|
, m_playlistManager(new PlaylistManager(this))
|
||||||
|
, m_taskbarManager(new TaskBarManager(this))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
m_playlistManager->setAutoLoadFilterSuffixes({
|
m_playlistManager->setAutoLoadFilterSuffixes({
|
||||||
@ -57,6 +61,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
|
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
|
||||||
ui->playlistView->setModel(m_playlistManager->model());
|
ui->playlistView->setModel(m_playlistManager->model());
|
||||||
|
|
||||||
|
ui->chapterNameBtn->setVisible(false);
|
||||||
|
ui->chapterlistView->setModel(ui->playbackProgressIndicator->chapterModel());
|
||||||
|
ui->chapterlistView->setRootIsDecorated(false);
|
||||||
|
|
||||||
ui->actionHelp->setShortcut(QKeySequence::HelpContents);
|
ui->actionHelp->setShortcut(QKeySequence::HelpContents);
|
||||||
addAction(ui->actionHelp);
|
addAction(ui->actionHelp);
|
||||||
ui->actionOpen->setShortcut(QKeySequence::Open);
|
ui->actionOpen->setShortcut(QKeySequence::Open);
|
||||||
@ -70,12 +78,21 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
|
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
|
||||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
|
|
||||||
|
m_taskbarManager->setCanTogglePlayback(true);
|
||||||
|
m_taskbarManager->setCanSkipBackward(true);
|
||||||
|
m_taskbarManager->setCanSkipForward(true);
|
||||||
|
m_taskbarManager->setShowProgress(true);
|
||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
loadSkinData();
|
loadSkinData();
|
||||||
initConnections();
|
initConnections();
|
||||||
initUiAndAnimation();
|
initUiAndAnimation();
|
||||||
|
|
||||||
centerWindow();
|
centerWindow();
|
||||||
|
|
||||||
|
QTimer::singleShot(1000, [this](){
|
||||||
|
m_taskbarManager->setWinId(window()->winId());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -248,6 +265,15 @@ void MainWindow::dropEvent(QDropEvent *e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileName.endsWith(".m3u") || fileName.endsWith(".m3u8")) {
|
||||||
|
const QModelIndex & modelIndex = m_playlistManager->loadM3U8Playlist(urls.constFirst());
|
||||||
|
if (modelIndex.isValid()) {
|
||||||
|
loadByModelIndex(modelIndex);
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urls);
|
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urls);
|
||||||
if (modelIndex.isValid()) {
|
if (modelIndex.isValid()) {
|
||||||
loadByModelIndex(modelIndex);
|
loadByModelIndex(modelIndex);
|
||||||
@ -255,6 +281,16 @@ void MainWindow::dropEvent(QDropEvent *e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
QMenu * menu = new QMenu;
|
||||||
|
menu->addAction(ui->actionHelp);
|
||||||
|
menu->exec(mapToGlobal(event->pos()));
|
||||||
|
menu->deleteLater();
|
||||||
|
|
||||||
|
return QMainWindow::contextMenuEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::loadFile()
|
void MainWindow::loadFile()
|
||||||
{
|
{
|
||||||
QStringList musicFolders(QStandardPaths::standardLocations(QStandardPaths::MusicLocation));
|
QStringList musicFolders(QStandardPaths::standardLocations(QStandardPaths::MusicLocation));
|
||||||
@ -269,9 +305,8 @@ void MainWindow::loadFile()
|
|||||||
urlList.append(QUrl::fromLocalFile(fileName));
|
urlList.append(QUrl::fromLocalFile(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_playlistManager->loadPlaylist(urlList);
|
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urlList);
|
||||||
const QUrl & firstUrl = urlList.first();
|
loadByModelIndex(modelIndex);
|
||||||
loadFile(firstUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadFile(const QUrl &url)
|
void MainWindow::loadFile(const QUrl &url)
|
||||||
@ -337,16 +372,6 @@ void MainWindow::on_playBtn_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::ms2str(qint64 ms)
|
|
||||||
{
|
|
||||||
QTime duaTime(QTime::fromMSecsSinceStartOfDay(ms));
|
|
||||||
if (duaTime.hour() > 0) {
|
|
||||||
return duaTime.toString("h:mm:ss");
|
|
||||||
} else {
|
|
||||||
return duaTime.toString("m:ss");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QUrl> MainWindow::strlst2urllst(QStringList strlst)
|
QList<QUrl> MainWindow::strlst2urllst(QStringList strlst)
|
||||||
{
|
{
|
||||||
QList<QUrl> urlList;
|
QList<QUrl> urlList;
|
||||||
@ -489,11 +514,28 @@ void MainWindow::initConnections()
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) {
|
connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) {
|
||||||
ui->nowTimeLabel->setText(ms2str(pos));
|
ui->nowTimeLabel->setText(PlaybackProgressIndicator::formatTime(pos));
|
||||||
if (m_mediaPlayer->duration() != 0) {
|
if (m_mediaPlayer->duration() != 0) {
|
||||||
ui->playbackProgressIndicator->setPosition(pos);
|
ui->playbackProgressIndicator->setPosition(pos);
|
||||||
|
m_taskbarManager->setProgressValue(pos);
|
||||||
}
|
}
|
||||||
m_lrcbar->playbackPositionChanged(pos, m_mediaPlayer->duration());
|
m_lrcbar->playbackPositionChanged(pos, m_mediaPlayer->duration());
|
||||||
|
|
||||||
|
static QString lastChapterName;
|
||||||
|
if (ui->playbackProgressIndicator->chapterModel()->rowCount() > 0) {
|
||||||
|
QString currentChapterName = ui->playbackProgressIndicator->currentChapterName();
|
||||||
|
if (currentChapterName != lastChapterName) {
|
||||||
|
ui->chapterNameBtn->setText(currentChapterName);
|
||||||
|
lastChapterName = currentChapterName;
|
||||||
|
}
|
||||||
|
ui->chapterNameBtn->setVisible(true);
|
||||||
|
} else {
|
||||||
|
if (!lastChapterName.isEmpty()) {
|
||||||
|
ui->chapterNameBtn->setText("");
|
||||||
|
lastChapterName.clear();
|
||||||
|
}
|
||||||
|
ui->chapterNameBtn->setVisible(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_audioOutput, &QAudioOutput::mutedChanged, this, [=](bool muted) {
|
connect(m_audioOutput, &QAudioOutput::mutedChanged, this, [=](bool muted) {
|
||||||
@ -506,7 +548,8 @@ void MainWindow::initConnections()
|
|||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::durationChanged, this, [=](qint64 dua) {
|
connect(m_mediaPlayer, &QMediaPlayer::durationChanged, this, [=](qint64 dua) {
|
||||||
ui->playbackProgressIndicator->setDuration(dua);
|
ui->playbackProgressIndicator->setDuration(dua);
|
||||||
ui->totalTimeLabel->setText(ms2str(dua));
|
m_taskbarManager->setProgressMaximum(dua);
|
||||||
|
ui->totalTimeLabel->setText(PlaybackProgressIndicator::formatTime(dua));
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::playbackStateChanged, this, [=](QMediaPlayer::PlaybackState newState) {
|
connect(m_mediaPlayer, &QMediaPlayer::playbackStateChanged, this, [=](QMediaPlayer::PlaybackState newState) {
|
||||||
@ -519,6 +562,7 @@ void MainWindow::initConnections()
|
|||||||
ui->playBtn->setIcon(QIcon(":/icons/icons/media-playback-start.png"));
|
ui->playBtn->setIcon(QIcon(":/icons/icons/media-playback-start.png"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
m_taskbarManager->setPlaybackState(newState);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_audioOutput, &QAudioOutput::volumeChanged, this, [=](float vol) {
|
connect(m_audioOutput, &QAudioOutput::volumeChanged, this, [=](float vol) {
|
||||||
@ -559,9 +603,21 @@ void MainWindow::initConnections()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::errorOccurred, this, [=](QMediaPlayer::Error error, const QString &errorString) {
|
connect(m_taskbarManager, &TaskBarManager::togglePlayback, this, [this](){
|
||||||
|
on_playBtn_clicked();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_taskbarManager, &TaskBarManager::skipBackward, this, [this](){
|
||||||
|
on_prevBtn_clicked();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_taskbarManager, &TaskBarManager::skipForward, this, [this](){
|
||||||
|
on_nextBtn_clicked();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_mediaPlayer, &QMediaPlayer::errorOccurred, this, [=](QMediaPlayer::Error error, const QString &errorString) {
|
||||||
qDebug() << error << errorString;
|
qDebug() << error << errorString;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadConfig()
|
void MainWindow::loadConfig()
|
||||||
@ -641,7 +697,16 @@ void MainWindow::on_setSkinBtn_clicked()
|
|||||||
|
|
||||||
void MainWindow::on_playListBtn_clicked()
|
void MainWindow::on_playListBtn_clicked()
|
||||||
{
|
{
|
||||||
setFixedSize(size().height() < 200 ? fullSize : miniSize);
|
if (size().height() < 200) {
|
||||||
|
setFixedSize(fullSize);
|
||||||
|
ui->pluginStackedWidget->setCurrentWidget(ui->playlistViewPage);
|
||||||
|
} else {
|
||||||
|
if (ui->pluginStackedWidget->currentWidget() == ui->playlistViewPage) {
|
||||||
|
setFixedSize(miniSize);
|
||||||
|
} else {
|
||||||
|
ui->pluginStackedWidget->setCurrentWidget(ui->playlistViewPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_playlistView_activated(const QModelIndex &index)
|
void MainWindow::on_playlistView_activated(const QModelIndex &index)
|
||||||
@ -660,6 +725,33 @@ void MainWindow::on_lrcBtn_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_chapterlistView_activated(const QModelIndex &index)
|
||||||
|
{
|
||||||
|
if (!index.isValid()) return;
|
||||||
|
|
||||||
|
QModelIndex timeColumnIndex = index.sibling(index.row(), 0);
|
||||||
|
QStandardItem* timeItem = ui->playbackProgressIndicator->chapterModel()->itemFromIndex(timeColumnIndex);
|
||||||
|
if (!timeItem) return;
|
||||||
|
|
||||||
|
qint64 chapterStartTime = timeItem->data(PlaybackProgressIndicator::StartTimeMsRole).toLongLong();
|
||||||
|
m_mediaPlayer->setPosition(chapterStartTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_chapterNameBtn_clicked()
|
||||||
|
{
|
||||||
|
if (size().height() < 200) {
|
||||||
|
setFixedSize(fullSize);
|
||||||
|
}
|
||||||
|
ui->pluginStackedWidget->setCurrentWidget(ui->chaptersViewPage);
|
||||||
|
if (ui->playbackProgressIndicator->chapterModel()->rowCount() > 0) {
|
||||||
|
const QModelIndex & curChapterItem = ui->playbackProgressIndicator->currentChapterItem();
|
||||||
|
if (curChapterItem.isValid()) {
|
||||||
|
ui->chapterlistView->setCurrentIndex(curChapterItem);
|
||||||
|
ui->chapterlistView->scrollTo(curChapterItem, QAbstractItemView::EnsureVisible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionOpen_triggered()
|
void MainWindow::on_actionOpen_triggered()
|
||||||
{
|
{
|
||||||
loadFile();
|
loadFile();
|
||||||
@ -707,4 +799,3 @@ QGraphicsDropShadowEffect *MainWindow::createLabelShadowEffect()
|
|||||||
effect->setOffset(1, 1);
|
effect->setOffset(1, 1);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
|
// SPDX-FileCopyrightText: 2025 Gary Wang <opensource@blumia.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ QT_END_NAMESPACE
|
|||||||
class FFTSpectrum;
|
class FFTSpectrum;
|
||||||
class LrcBar;
|
class LrcBar;
|
||||||
class PlaylistManager;
|
class PlaylistManager;
|
||||||
|
class TaskBarManager;
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -54,6 +55,7 @@ protected:
|
|||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||||
void dropEvent(QDropEvent *e) override;
|
void dropEvent(QDropEvent *e) override;
|
||||||
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
|
||||||
void loadFile();
|
void loadFile();
|
||||||
void loadFile(const QUrl &url);
|
void loadFile(const QUrl &url);
|
||||||
@ -78,6 +80,8 @@ private slots:
|
|||||||
void on_playListBtn_clicked();
|
void on_playListBtn_clicked();
|
||||||
void on_playlistView_activated(const QModelIndex &index);
|
void on_playlistView_activated(const QModelIndex &index);
|
||||||
void on_lrcBtn_clicked();
|
void on_lrcBtn_clicked();
|
||||||
|
void on_chapterlistView_activated(const QModelIndex &index);
|
||||||
|
void on_chapterNameBtn_clicked();
|
||||||
void on_actionOpen_triggered();
|
void on_actionOpen_triggered();
|
||||||
void on_actionHelp_triggered();
|
void on_actionHelp_triggered();
|
||||||
|
|
||||||
@ -103,6 +107,7 @@ private:
|
|||||||
LrcBar *m_lrcbar;
|
LrcBar *m_lrcbar;
|
||||||
QPropertyAnimation *m_fadeOutAnimation;
|
QPropertyAnimation *m_fadeOutAnimation;
|
||||||
PlaylistManager *m_playlistManager;
|
PlaylistManager *m_playlistManager;
|
||||||
|
TaskBarManager *m_taskbarManager;
|
||||||
|
|
||||||
void initUiAndAnimation();
|
void initUiAndAnimation();
|
||||||
void initConnections();
|
void initConnections();
|
||||||
|
@ -109,6 +109,18 @@ QLabel#coverLabel {
|
|||||||
QListView {
|
QListView {
|
||||||
color: white;
|
color: white;
|
||||||
background: rgba(0, 0, 0, 50);
|
background: rgba(0, 0, 0, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****** TreeView ******/
|
||||||
|
|
||||||
|
QTreeView {
|
||||||
|
color: white;
|
||||||
|
background: rgba(0, 0, 0, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
QHeaderView {
|
||||||
|
color: white;
|
||||||
|
background-color: rgba(200, 200, 200, 50);
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="locale">
|
<property name="locale">
|
||||||
@ -217,7 +229,7 @@ QListView {
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@ -295,7 +307,7 @@ QListView {
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="playerPanelLayout">
|
<layout class="QVBoxLayout" name="playerPanelLayout">
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>10</number>
|
<number>10</number>
|
||||||
@ -358,13 +370,26 @@ QListView {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="chapterNameBtn">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="totalTimeLabel">
|
<widget class="QLabel" name="totalTimeLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">0:00</string>
|
<string notr="true">0:00</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -599,7 +624,7 @@ QListView {
|
|||||||
<number>100</number>
|
<number>100</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -626,7 +651,10 @@ QListView {
|
|||||||
<height>0</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="pluginStackedWidgetPage1">
|
<property name="currentIndex">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="playlistViewPage">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
@ -648,22 +676,48 @@ QListView {
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="chaptersViewPage">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="chapterlistView">
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionHelp">
|
<action name="actionHelp">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="system-help"/>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Help</string>
|
<string>About</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Help</string>
|
<string>About</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>F1</string>
|
<string notr="true">F1</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::AboutRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionOpen">
|
<action name="actionOpen">
|
||||||
@ -674,10 +728,10 @@ QListView {
|
|||||||
<string>Open</string>
|
<string>Open</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+O</string>
|
<string notr="true">Ctrl+O</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -25,6 +25,37 @@ PlaybackProgressIndicator::PlaybackProgressIndicator(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex PlaybackProgressIndicator::currentChapterItem() const
|
||||||
|
{
|
||||||
|
int currentChapterIndex = -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < m_chapterModel.rowCount(); i++) {
|
||||||
|
QStandardItem* timeItem = m_chapterModel.item(i, 0);
|
||||||
|
qint64 chapterStartTime = timeItem->data(PlaybackProgressIndicator::StartTimeMsRole).toLongLong();
|
||||||
|
|
||||||
|
if (m_position >= chapterStartTime) {
|
||||||
|
currentChapterIndex = i;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentChapterIndex >= 0) {
|
||||||
|
return m_chapterModel.index(currentChapterIndex, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PlaybackProgressIndicator::currentChapterName() const
|
||||||
|
{
|
||||||
|
const QModelIndex timeIndex(currentChapterItem());
|
||||||
|
if (timeIndex.isValid()) {
|
||||||
|
return m_chapterModel.item(timeIndex.row(), 1)->text();
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void PlaybackProgressIndicator::setPosition(qint64 pos)
|
void PlaybackProgressIndicator::setPosition(qint64 pos)
|
||||||
{
|
{
|
||||||
m_position = pos;
|
m_position = pos;
|
||||||
@ -37,14 +68,34 @@ void PlaybackProgressIndicator::setDuration(qint64 dur)
|
|||||||
emit durationChanged(m_duration);
|
emit durationChanged(m_duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PlaybackProgressIndicator::formatTime(qint64 milliseconds)
|
||||||
|
{
|
||||||
|
QTime duaTime(QTime::fromMSecsSinceStartOfDay(milliseconds));
|
||||||
|
if (duaTime.hour() > 0) {
|
||||||
|
return duaTime.toString("h:mm:ss");
|
||||||
|
} else {
|
||||||
|
return duaTime.toString("m:ss");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PlaybackProgressIndicator::setChapters(QList<std::pair<qint64, QString> > chapters)
|
void PlaybackProgressIndicator::setChapters(QList<std::pair<qint64, QString> > chapters)
|
||||||
{
|
{
|
||||||
qDebug() << chapters;
|
|
||||||
m_chapterModel.clear();
|
m_chapterModel.clear();
|
||||||
|
|
||||||
|
m_chapterModel.setHorizontalHeaderLabels(QStringList() << tr("Time") << tr("Chapter Name"));
|
||||||
|
|
||||||
for (const std::pair<qint64, QString> & chapter : chapters) {
|
for (const std::pair<qint64, QString> & chapter : chapters) {
|
||||||
|
QList<QStandardItem*> row;
|
||||||
|
|
||||||
|
QStandardItem * timeItem = new QStandardItem(formatTime(chapter.first));
|
||||||
|
timeItem->setData(chapter.first, StartTimeMsRole);
|
||||||
|
row.append(timeItem);
|
||||||
|
|
||||||
QStandardItem * chapterItem = new QStandardItem(chapter.second);
|
QStandardItem * chapterItem = new QStandardItem(chapter.second);
|
||||||
chapterItem->setData(chapter.first, StartTimeMsRole);
|
chapterItem->setData(chapter.first, StartTimeMsRole);
|
||||||
m_chapterModel.appendRow(chapterItem);
|
row.append(chapterItem);
|
||||||
|
|
||||||
|
m_chapterModel.appendRow(row);
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,15 @@ public:
|
|||||||
explicit PlaybackProgressIndicator(QWidget *parent = nullptr);
|
explicit PlaybackProgressIndicator(QWidget *parent = nullptr);
|
||||||
~PlaybackProgressIndicator() = default;
|
~PlaybackProgressIndicator() = default;
|
||||||
|
|
||||||
|
QStandardItemModel* chapterModel() { return &m_chapterModel; }
|
||||||
|
QModelIndex currentChapterItem() const;
|
||||||
|
QString currentChapterName() const;
|
||||||
|
|
||||||
void setPosition(qint64 pos);
|
void setPosition(qint64 pos);
|
||||||
void setDuration(qint64 dur);
|
void setDuration(qint64 dur);
|
||||||
void setChapters(QList<std::pair<qint64, QString>> chapters);
|
void setChapters(QList<std::pair<qint64, QString>> chapters);
|
||||||
|
|
||||||
|
static QString formatTime(qint64 milliseconds);
|
||||||
static QList<std::pair<qint64, QString>> tryLoadChapters(const QString & filePath);
|
static QList<std::pair<qint64, QString>> tryLoadChapters(const QString & filePath);
|
||||||
static QList<std::pair<qint64, QString>> tryLoadSidecarChapterFile(const QString & filePath);
|
static QList<std::pair<qint64, QString>> tryLoadSidecarChapterFile(const QString & filePath);
|
||||||
static QList<std::pair<qint64, QString>> tryLoadChaptersFromMetadata(const QString & filePath);
|
static QList<std::pair<qint64, QString>> tryLoadChaptersFromMetadata(const QString & filePath);
|
||||||
|
@ -186,6 +186,26 @@ QModelIndex PlaylistManager::loadPlaylist(const QUrl &url)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex PlaylistManager::loadM3U8Playlist(const QUrl &url)
|
||||||
|
{
|
||||||
|
QFile file(url.toLocalFile());
|
||||||
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QList<QUrl> urls;
|
||||||
|
while (!file.atEnd()) {
|
||||||
|
QString line = file.readLine();
|
||||||
|
if (line.startsWith('#')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QFileInfo fileInfo(file);
|
||||||
|
QUrl item = QUrl::fromUserInput(line, fileInfo.absolutePath());
|
||||||
|
urls.append(item);
|
||||||
|
}
|
||||||
|
return loadPlaylist(urls);
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int PlaylistManager::totalCount() const
|
int PlaylistManager::totalCount() const
|
||||||
{
|
{
|
||||||
return m_model.rowCount();
|
return m_model.rowCount();
|
||||||
@ -196,7 +216,7 @@ QModelIndex PlaylistManager::previousIndex() const
|
|||||||
int count = totalCount();
|
int count = totalCount();
|
||||||
if (count == 0) return {};
|
if (count == 0) return {};
|
||||||
|
|
||||||
return m_model.index(m_currentIndex - 1 < 0 ? count - 1 : m_currentIndex - 1);
|
return m_model.index(isFirstIndex() ? count - 1 : m_currentIndex - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex PlaylistManager::nextIndex() const
|
QModelIndex PlaylistManager::nextIndex() const
|
||||||
@ -204,7 +224,7 @@ QModelIndex PlaylistManager::nextIndex() const
|
|||||||
int count = totalCount();
|
int count = totalCount();
|
||||||
if (count == 0) return {};
|
if (count == 0) return {};
|
||||||
|
|
||||||
return m_model.index(m_currentIndex + 1 == count ? 0 : m_currentIndex + 1);
|
return m_model.index(isLastIndex() ? 0 : m_currentIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex PlaylistManager::curIndex() const
|
QModelIndex PlaylistManager::curIndex() const
|
||||||
@ -212,6 +232,16 @@ QModelIndex PlaylistManager::curIndex() const
|
|||||||
return m_model.index(m_currentIndex);
|
return m_model.index(m_currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlaylistManager::isFirstIndex() const
|
||||||
|
{
|
||||||
|
return m_currentIndex == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlaylistManager::isLastIndex() const
|
||||||
|
{
|
||||||
|
return m_currentIndex + 1 == totalCount();
|
||||||
|
}
|
||||||
|
|
||||||
void PlaylistManager::setCurrentIndex(const QModelIndex &index)
|
void PlaylistManager::setCurrentIndex(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {
|
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {
|
||||||
|
@ -61,11 +61,14 @@ public:
|
|||||||
void setPlaylist(const QList<QUrl> & url);
|
void setPlaylist(const QList<QUrl> & url);
|
||||||
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
||||||
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
|
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
|
||||||
|
Q_INVOKABLE QModelIndex loadM3U8Playlist(const QUrl & url);
|
||||||
|
|
||||||
int totalCount() const;
|
int totalCount() const;
|
||||||
QModelIndex previousIndex() const;
|
QModelIndex previousIndex() const;
|
||||||
QModelIndex nextIndex() const;
|
QModelIndex nextIndex() const;
|
||||||
QModelIndex curIndex() const;
|
QModelIndex curIndex() const;
|
||||||
|
bool isFirstIndex() const;
|
||||||
|
bool isLastIndex() const;
|
||||||
void setCurrentIndex(const QModelIndex & index);
|
void setCurrentIndex(const QModelIndex & index);
|
||||||
QUrl urlByIndex(const QModelIndex & index);
|
QUrl urlByIndex(const QModelIndex & index);
|
||||||
QString localFileByIndex(const QModelIndex & index);
|
QString localFileByIndex(const QModelIndex & index);
|
||||||
|
383
taskbarmanager.cpp
Normal file
383
taskbarmanager.cpp
Normal file
@ -0,0 +1,383 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 (c) Jack Hill <jackhill3103@gmail.com>
|
||||||
|
// SPDX-FileCopyrightText: 2025 (c) Gary Wang <opensource@blumia.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// This file is modified based on Elisa's taskmanager.cpp implementation,
|
||||||
|
// with its Qt Quick usage removed.
|
||||||
|
|
||||||
|
#include "taskbarmanager.h"
|
||||||
|
|
||||||
|
#include <QAbstractEventDispatcher>
|
||||||
|
#include <QAbstractNativeEventFilter>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <Shobjidl.h>
|
||||||
|
#include <WinDef.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
constexpr int numOfButtons = 3;
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
|
||||||
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
|
||||||
|
static HICON hiconFromTheme(const QString &iconName)
|
||||||
|
#else
|
||||||
|
static HICON hiconFromTheme(const QIcon::ThemeIcon iconName)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
const auto width = GetSystemMetrics(SM_CXSMICON);
|
||||||
|
const auto height = GetSystemMetrics(SM_CYSMICON);
|
||||||
|
return QIcon::fromTheme(iconName).pixmap(width, height).toImage().toHICON();
|
||||||
|
}
|
||||||
|
|
||||||
|
class TaskBarManagerPrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
ITaskbarList3 *taskBar = nullptr;
|
||||||
|
HWND hwnd = nullptr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the toolbar has been added to the taskbar
|
||||||
|
*/
|
||||||
|
bool addedThumbButtons = false;
|
||||||
|
|
||||||
|
QMediaPlayer::PlaybackState playbackState = QMediaPlayer::StoppedState;
|
||||||
|
|
||||||
|
bool showProgress = false;
|
||||||
|
qlonglong progressMaximum = 0;
|
||||||
|
qlonglong progressValue = 0;
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
|
||||||
|
HICON skipBackwardIcon = hiconFromTheme(u"media-skip-backward"_s);
|
||||||
|
HICON skipForwardIcon = hiconFromTheme(u"media-skip-forward"_s);
|
||||||
|
HICON playIcon = hiconFromTheme(u"media-playback-start"_s);
|
||||||
|
HICON pauseIcon = hiconFromTheme(u"media-playback-pause"_s);
|
||||||
|
#else
|
||||||
|
HICON skipBackwardIcon = hiconFromTheme(QIcon::ThemeIcon::MediaSkipBackward);
|
||||||
|
HICON skipForwardIcon = hiconFromTheme(QIcon::ThemeIcon::MediaSkipForward);
|
||||||
|
HICON playIcon = hiconFromTheme(QIcon::ThemeIcon::MediaPlaybackStart);
|
||||||
|
HICON pauseIcon = hiconFromTheme(QIcon::ThemeIcon::MediaPlaybackPause);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains the current state of each button
|
||||||
|
*/
|
||||||
|
struct ButtonData {
|
||||||
|
HICON icon = nullptr;
|
||||||
|
bool enabled = false;
|
||||||
|
};
|
||||||
|
std::array<ButtonData, numOfButtons> buttonData = {{
|
||||||
|
{skipBackwardIcon, false},
|
||||||
|
{playIcon, false},
|
||||||
|
{skipForwardIcon, false}
|
||||||
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For convenience when reading code
|
||||||
|
*/
|
||||||
|
enum ButtonID {
|
||||||
|
SkipBackward = 0,
|
||||||
|
TogglePlayback = 1,
|
||||||
|
SkipForward = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
TaskBarManagerPrivate()
|
||||||
|
{
|
||||||
|
HRESULT result = CoCreateInstance(CLSID_TaskbarList,
|
||||||
|
nullptr,
|
||||||
|
CLSCTX_INPROC_SERVER,
|
||||||
|
IID_PPV_ARGS(&taskBar));
|
||||||
|
if (FAILED(result)) {
|
||||||
|
taskBar = nullptr;
|
||||||
|
qWarning() << "Failed to create Windows taskbar instance";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~TaskBarManagerPrivate()
|
||||||
|
{
|
||||||
|
if (taskBar) {
|
||||||
|
taskBar->Release();
|
||||||
|
}
|
||||||
|
DestroyIcon(skipForwardIcon);
|
||||||
|
DestroyIcon(skipBackwardIcon);
|
||||||
|
DestroyIcon(pauseIcon);
|
||||||
|
DestroyIcon(playIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the native window handle for the taskbar instance
|
||||||
|
*/
|
||||||
|
void setHWND(HWND newHwnd)
|
||||||
|
{
|
||||||
|
if (hwnd == newHwnd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hwnd = newHwnd;
|
||||||
|
addedThumbButtons = false;
|
||||||
|
if (hwnd) {
|
||||||
|
updateProgressFlags();
|
||||||
|
updateProgressValue();
|
||||||
|
setupTaskBarManagerButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the taskbar progress flags
|
||||||
|
*/
|
||||||
|
void updateProgressFlags()
|
||||||
|
{
|
||||||
|
if (taskBar && hwnd) {
|
||||||
|
taskBar->SetProgressState(hwnd, progressFlags());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the taskbar progress value, only if the taskbar is showing progress
|
||||||
|
*/
|
||||||
|
void updateProgressValue()
|
||||||
|
{
|
||||||
|
if (taskBar && hwnd && showProgress && playbackState != QMediaPlayer::StoppedState) {
|
||||||
|
taskBar->SetProgressValue(hwnd, progressValue, progressMaximum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the state of a single toolbutton
|
||||||
|
*/
|
||||||
|
void updateButton(const ButtonID buttonId)
|
||||||
|
{
|
||||||
|
if (!taskBar || !hwnd || !addedThumbButtons) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
THUMBBUTTON thumbButtons[1];
|
||||||
|
initThumbButton(thumbButtons, buttonId);
|
||||||
|
taskBar->ThumbBarUpdateButtons(hwnd, 1, thumbButtons);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Convert playbackState into windows taskbar flags
|
||||||
|
*/
|
||||||
|
TBPFLAG progressFlags() const
|
||||||
|
{
|
||||||
|
if (!showProgress) {
|
||||||
|
return TBPF_NOPROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (playbackState) {
|
||||||
|
case QMediaPlayer::StoppedState:
|
||||||
|
return TBPF_NOPROGRESS;
|
||||||
|
case QMediaPlayer::PlayingState:
|
||||||
|
return TBPF_NORMAL;
|
||||||
|
case QMediaPlayer::PausedState:
|
||||||
|
return TBPF_PAUSED;
|
||||||
|
default:
|
||||||
|
return TBPF_NOPROGRESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a single toolbutton
|
||||||
|
*/
|
||||||
|
void initThumbButton(THUMBBUTTON *button, const ButtonID id)
|
||||||
|
{
|
||||||
|
button->dwMask = THB_ICON | THB_FLAGS;
|
||||||
|
button->iId = id;
|
||||||
|
button->hIcon = buttonData.at(id).icon;
|
||||||
|
button->dwFlags = buttonData.at(id).enabled ? THBF_ENABLED : THBF_DISABLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the toolbar
|
||||||
|
*/
|
||||||
|
void setupTaskBarManagerButtons()
|
||||||
|
{
|
||||||
|
if (!taskBar || !hwnd || addedThumbButtons) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
THUMBBUTTON thumbButtons[numOfButtons];
|
||||||
|
THUMBBUTTON *currButton = thumbButtons;
|
||||||
|
for (int i = 0; i < numOfButtons; ++i) {
|
||||||
|
initThumbButton(currButton++, static_cast<ButtonID>(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// win32 api reference says we should pass &thumbButtons but this doesn't compile
|
||||||
|
HRESULT result = taskBar->ThumbBarAddButtons(hwnd, numOfButtons, thumbButtons);
|
||||||
|
if (FAILED(result)) {
|
||||||
|
qWarning() << "Failed to create Windows taskbar buttons";
|
||||||
|
} else {
|
||||||
|
addedThumbButtons = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TaskBarManager::TaskBarManager(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, d(std::make_unique<TaskBarManagerPrivate>())
|
||||||
|
{
|
||||||
|
QAbstractEventDispatcher::instance()->installNativeEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskBarManager::~TaskBarManager() = default;
|
||||||
|
|
||||||
|
bool TaskBarManager::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *)
|
||||||
|
{
|
||||||
|
if (eventType == "windows_generic_MSG") {
|
||||||
|
MSG *msg = static_cast<MSG *>(message);
|
||||||
|
if (msg->hwnd != d->hwnd || msg->message != WM_COMMAND || HIWORD(msg->wParam) != THBN_CLICKED) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (LOWORD(msg->wParam)) {
|
||||||
|
case TaskBarManagerPrivate::SkipBackward:
|
||||||
|
Q_EMIT skipBackward();
|
||||||
|
return true;
|
||||||
|
case TaskBarManagerPrivate::TogglePlayback:
|
||||||
|
Q_EMIT togglePlayback();
|
||||||
|
return true;
|
||||||
|
case TaskBarManagerPrivate::SkipForward:
|
||||||
|
Q_EMIT skipForward();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMediaPlayer::PlaybackState TaskBarManager::playbackState() const
|
||||||
|
{
|
||||||
|
return d->playbackState;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::showProgress() const
|
||||||
|
{
|
||||||
|
return d->showProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
qulonglong TaskBarManager::progressMaximum() const
|
||||||
|
{
|
||||||
|
return d->progressMaximum;
|
||||||
|
}
|
||||||
|
|
||||||
|
qulonglong TaskBarManager::progressValue() const
|
||||||
|
{
|
||||||
|
return d->progressValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::canSkipBackward() const
|
||||||
|
{
|
||||||
|
return d->buttonData.at(TaskBarManagerPrivate::SkipBackward).enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::canSkipForward() const
|
||||||
|
{
|
||||||
|
return d->buttonData.at(TaskBarManagerPrivate::SkipForward).enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::canTogglePlayback() const
|
||||||
|
{
|
||||||
|
return d->buttonData.at(TaskBarManagerPrivate::TogglePlayback).enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setWinId(WId winId)
|
||||||
|
{
|
||||||
|
d->setHWND(reinterpret_cast<HWND>(winId));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setPlaybackState(const QMediaPlayer::PlaybackState newPlaybackState)
|
||||||
|
{
|
||||||
|
if (d->playbackState == newPlaybackState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->playbackState = newPlaybackState;
|
||||||
|
Q_EMIT playbackStateChanged();
|
||||||
|
|
||||||
|
d->buttonData.at(TaskBarManagerPrivate::TogglePlayback).icon =
|
||||||
|
d->playbackState == QMediaPlayer::PlayingState ? d->pauseIcon : d->playIcon;
|
||||||
|
d->updateButton(TaskBarManagerPrivate::TogglePlayback);
|
||||||
|
d->updateProgressFlags();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setShowProgress(const bool showProgress)
|
||||||
|
{
|
||||||
|
if (d->showProgress == showProgress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->showProgress = showProgress;
|
||||||
|
Q_EMIT showProgressChanged();
|
||||||
|
|
||||||
|
d->updateProgressFlags();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setProgressMaximum(const qlonglong newMaximum)
|
||||||
|
{
|
||||||
|
if (d->progressMaximum == newMaximum) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->progressMaximum = newMaximum;
|
||||||
|
Q_EMIT progressMaximumChanged();
|
||||||
|
|
||||||
|
if (d->progressValue > d->progressMaximum) {
|
||||||
|
d->progressValue = d->progressMaximum;
|
||||||
|
Q_EMIT progressValueChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
d->updateProgressValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setProgressValue(const qlonglong newValue)
|
||||||
|
{
|
||||||
|
if (d->progressValue == newValue) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->progressValue = newValue < d->progressMaximum ? newValue : d->progressMaximum;
|
||||||
|
Q_EMIT progressValueChanged();
|
||||||
|
|
||||||
|
d->updateProgressValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setCanSkipBackward(const bool canSkip)
|
||||||
|
{
|
||||||
|
if (d->buttonData[TaskBarManagerPrivate::SkipBackward].enabled == canSkip) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->buttonData[TaskBarManagerPrivate::SkipBackward].enabled = canSkip;
|
||||||
|
Q_EMIT canSkipBackwardChanged();
|
||||||
|
|
||||||
|
d->updateButton(TaskBarManagerPrivate::SkipBackward);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setCanSkipForward(const bool canSkip)
|
||||||
|
{
|
||||||
|
if (d->buttonData[TaskBarManagerPrivate::SkipForward].enabled == canSkip) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->buttonData[TaskBarManagerPrivate::SkipForward].enabled = canSkip;
|
||||||
|
Q_EMIT canSkipForwardChanged();
|
||||||
|
|
||||||
|
d->updateButton(TaskBarManagerPrivate::SkipForward);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setCanTogglePlayback(const bool canToggle)
|
||||||
|
{
|
||||||
|
if (d->buttonData[TaskBarManagerPrivate::TogglePlayback].enabled == canToggle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->buttonData[TaskBarManagerPrivate::TogglePlayback].enabled = canToggle;
|
||||||
|
Q_EMIT canTogglePlaybackChanged();
|
||||||
|
|
||||||
|
d->updateButton(TaskBarManagerPrivate::TogglePlayback);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_taskbarmanager.cpp"
|
151
taskbarmanager.h
Normal file
151
taskbarmanager.h
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2024 (c) Jack Hill <jackhill3103@gmail.com>
|
||||||
|
// SPDX-FileCopyrightText: 2025 (c) Gary Wang <opensource@blumia.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// This file is modified based on Elisa's taskmanager.cpp implementation,
|
||||||
|
// with its Qt Quick usage removed.
|
||||||
|
|
||||||
|
#ifndef TASKBAR_H
|
||||||
|
#define TASKBAR_H
|
||||||
|
|
||||||
|
#include <QAbstractNativeEventFilter>
|
||||||
|
#include <QMediaPlayer>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class TaskBarManagerPrivate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Windows taskbar
|
||||||
|
*/
|
||||||
|
class TaskBarManager : public QObject, public QAbstractNativeEventFilter
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the media is playing, paused, or stopped
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(QMediaPlayer::PlaybackState playbackState
|
||||||
|
READ playbackState
|
||||||
|
WRITE setPlaybackState
|
||||||
|
NOTIFY playbackStateChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to show track progress on the taskbar
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(bool showProgress
|
||||||
|
READ showProgress
|
||||||
|
WRITE setShowProgress
|
||||||
|
NOTIFY showProgressChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum possible progress
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(qulonglong progressMaximum
|
||||||
|
READ progressMaximum
|
||||||
|
WRITE setProgressMaximum
|
||||||
|
NOTIFY progressMaximumChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current progress; this is always clamped to be in the range [0, progressMaximum]
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(qulonglong progressValue
|
||||||
|
READ progressValue
|
||||||
|
WRITE setProgressValue
|
||||||
|
NOTIFY progressValueChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the "Skip Backward" button is enabled
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(bool canSkipBackward
|
||||||
|
READ canSkipBackward
|
||||||
|
WRITE setCanSkipBackward
|
||||||
|
NOTIFY canSkipBackwardChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the "Skip Forward" button is enabled
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(bool canSkipForward
|
||||||
|
READ canSkipForward
|
||||||
|
WRITE setCanSkipForward
|
||||||
|
NOTIFY canSkipForwardChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the "Toggle Playback" button is enabled
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(bool canTogglePlayback
|
||||||
|
READ canTogglePlayback
|
||||||
|
WRITE setCanTogglePlayback
|
||||||
|
NOTIFY canTogglePlaybackChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit TaskBarManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
~TaskBarManager() override;
|
||||||
|
|
||||||
|
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
|
||||||
|
|
||||||
|
[[nodiscard]] QMediaPlayer::PlaybackState playbackState() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool showProgress() const;
|
||||||
|
|
||||||
|
[[nodiscard]] qulonglong progressMaximum() const;
|
||||||
|
|
||||||
|
[[nodiscard]] qulonglong progressValue() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool canSkipBackward() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool canSkipForward() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool canTogglePlayback() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
|
||||||
|
void playbackStateChanged();
|
||||||
|
|
||||||
|
void showProgressChanged();
|
||||||
|
|
||||||
|
void progressMaximumChanged();
|
||||||
|
|
||||||
|
void progressValueChanged();
|
||||||
|
|
||||||
|
void canSkipBackwardChanged();
|
||||||
|
|
||||||
|
void canSkipForwardChanged();
|
||||||
|
|
||||||
|
void canTogglePlaybackChanged();
|
||||||
|
|
||||||
|
void skipBackward();
|
||||||
|
|
||||||
|
void skipForward();
|
||||||
|
|
||||||
|
void togglePlayback();
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
|
||||||
|
void setWinId(WId win);
|
||||||
|
|
||||||
|
void setPlaybackState(QMediaPlayer::PlaybackState newPlaybackState);
|
||||||
|
|
||||||
|
void setShowProgress(bool showProgress);
|
||||||
|
|
||||||
|
void setProgressMaximum(qlonglong newMaximum);
|
||||||
|
|
||||||
|
void setProgressValue(qlonglong newValue);
|
||||||
|
|
||||||
|
void setCanSkipBackward(bool canSkip);
|
||||||
|
|
||||||
|
void setCanSkipForward(bool canSkip);
|
||||||
|
|
||||||
|
void setCanTogglePlayback(bool canToggle);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::unique_ptr<TaskBarManagerPrivate> d;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TASKBAR_H
|
97
taskbarmanager_dummy.cpp
Normal file
97
taskbarmanager_dummy.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2025 Gary Wang <opensource@blumia.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
#include "taskbarmanager.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class TaskBarManagerPrivate {};
|
||||||
|
|
||||||
|
TaskBarManager::TaskBarManager(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskBarManager::~TaskBarManager() = default;
|
||||||
|
|
||||||
|
bool TaskBarManager::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMediaPlayer::PlaybackState TaskBarManager::playbackState() const
|
||||||
|
{
|
||||||
|
return QMediaPlayer::StoppedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::showProgress() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
qulonglong TaskBarManager::progressMaximum() const
|
||||||
|
{
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
qulonglong TaskBarManager::progressValue() const
|
||||||
|
{
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::canSkipBackward() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::canSkipForward() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskBarManager::canTogglePlayback() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setWinId(WId winId)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setPlaybackState(const QMediaPlayer::PlaybackState newPlaybackState)
|
||||||
|
{
|
||||||
|
Q_UNUSED(newPlaybackState);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setShowProgress(const bool showProgress)
|
||||||
|
{
|
||||||
|
Q_UNUSED(showProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setProgressMaximum(const qlonglong newMaximum)
|
||||||
|
{
|
||||||
|
Q_UNUSED(newMaximum);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setProgressValue(const qlonglong newValue)
|
||||||
|
{
|
||||||
|
Q_UNUSED(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setCanSkipBackward(const bool canSkip)
|
||||||
|
{
|
||||||
|
Q_UNUSED(canSkip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setCanSkipForward(const bool canSkip)
|
||||||
|
{
|
||||||
|
Q_UNUSED(canSkip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBarManager::setCanTogglePlayback(const bool canToggle)
|
||||||
|
{
|
||||||
|
Q_UNUSED(canToggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_taskbarmanager.cpp"
|
Reference in New Issue
Block a user