Compare commits
1 Commits
visualisat
...
artistbio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f1bda0546 |
9
.github/workflows/build.yml
vendored
9
.github/workflows/build.yml
vendored
@@ -62,7 +62,6 @@ jobs:
|
||||
libchromaprint-devel
|
||||
fftw3-devel
|
||||
libebur128-devel
|
||||
projectM-devel
|
||||
desktop-file-utils
|
||||
update-desktop-files
|
||||
appstream-glib
|
||||
@@ -79,7 +78,6 @@ jobs:
|
||||
qt6-base-common-devel
|
||||
qt6-sql-sqlite
|
||||
qt6-linguist-devel
|
||||
qt6-openglwidgets-devel
|
||||
gtest
|
||||
gmock
|
||||
sparsehash-devel
|
||||
@@ -202,7 +200,6 @@ jobs:
|
||||
libchromaprint-devel
|
||||
libebur128-devel
|
||||
fftw-devel
|
||||
libprojectM-devel
|
||||
desktop-file-utils
|
||||
libappstream-glib
|
||||
hicolor-icon-theme
|
||||
@@ -293,7 +290,6 @@ jobs:
|
||||
lib64Qt6DBus-devel
|
||||
lib64Qt6Gui-devel
|
||||
lib64Qt6Widgets-devel
|
||||
lib64Qt6OpenGLWidgets-devel
|
||||
lib64Qt6Test-devel
|
||||
lib64kdsingleapplication-devel
|
||||
lib64xkbcommon-devel
|
||||
@@ -388,7 +384,6 @@ jobs:
|
||||
lib64fftw-devel
|
||||
lib64dbus-devel
|
||||
lib64appstream-devel
|
||||
lib64projectm-devel
|
||||
lib64qt6core-devel
|
||||
lib64qt6gui-devel
|
||||
lib64qt6widgets-devel
|
||||
@@ -398,7 +393,6 @@ jobs:
|
||||
lib64qt6dbus-devel
|
||||
lib64qt6help-devel
|
||||
lib64qt6test-devel
|
||||
lib64qt6openglwidgets-devel
|
||||
lib64sparsehash-devel
|
||||
lib64kdsingleapplication-devel
|
||||
desktop-file-utils
|
||||
@@ -505,7 +499,6 @@ jobs:
|
||||
qt6-tools-dev-tools
|
||||
qt6-l10n-tools
|
||||
rapidjson-dev
|
||||
libprojectm-dev
|
||||
- name: Install KDSingleApplication
|
||||
if: matrix.debian_version != 'bookworm'
|
||||
run: apt install -y libkdsingleapplication-qt6-dev
|
||||
@@ -602,7 +595,6 @@ jobs:
|
||||
qt6-tools-dev-tools
|
||||
qt6-l10n-tools
|
||||
rapidjson-dev
|
||||
libprojectm-dev
|
||||
- name: Install KDSingleApplication
|
||||
if: matrix.ubuntu_version != 'noble' && matrix.ubuntu_version != 'plucky'
|
||||
run: apt install -y libkdsingleapplication-qt6-dev
|
||||
@@ -701,7 +693,6 @@ jobs:
|
||||
gstreamer1.0-pulseaudio
|
||||
libkdsingleapplication-qt6-dev
|
||||
rapidjson-dev
|
||||
libprojectm-dev
|
||||
- name: Install keyboxd
|
||||
if: matrix.ubuntu_version == 'noble'
|
||||
env:
|
||||
|
||||
@@ -208,15 +208,6 @@ else()
|
||||
pkg_check_modules(TAGLIB REQUIRED IMPORTED_TARGET taglib>=1.12)
|
||||
endif()
|
||||
|
||||
find_package(projectM4 COMPONENTS Playlist)
|
||||
if(projectM4_FOUND)
|
||||
set(LIBPROJECTM_FOUND ON)
|
||||
set(HAVE_PROJECTM4 ON)
|
||||
set(LIBPROJECTM_LIBRARIES libprojectM::projectM libprojectM::playlist)
|
||||
else()
|
||||
pkg_check_modules(LIBPROJECTM libprojectM)
|
||||
endif()
|
||||
|
||||
find_package(GTest)
|
||||
|
||||
pkg_check_modules(LIBSPARSEHASH IMPORTED_TARGET libsparsehash)
|
||||
@@ -227,7 +218,7 @@ set(QT_VERSION_MAJOR 6)
|
||||
set(QT_MIN_VERSION 6.4.0)
|
||||
set(QT_DEFAULT_MAJOR_VERSION ${QT_VERSION_MAJOR})
|
||||
set(QT_COMPONENTS Core Concurrent Gui Widgets Network Sql)
|
||||
set(QT_OPTIONAL_COMPONENTS GuiPrivate OpenGLWidgets LinguistTools Test)
|
||||
set(QT_OPTIONAL_COMPONENTS GuiPrivate LinguistTools Test)
|
||||
if(UNIX AND NOT APPLE)
|
||||
list(APPEND QT_OPTIONAL_COMPONENTS DBus)
|
||||
endif()
|
||||
@@ -398,11 +389,6 @@ if(HAVE_X11_GLOBALSHORTCUTS OR HAVE_KGLOBALACCEL_GLOBALSHORTCUTS OR APPLE OR WIN
|
||||
set(HAVE_GLOBALSHORTCUTS ON)
|
||||
endif()
|
||||
|
||||
optional_component(VISUALIZATIONS ON "Visualizations"
|
||||
DEPENDS "libprojectm" LIBPROJECTM_FOUND
|
||||
DEPENDS "QtOpenGLWidgets" Qt${QT_VERSION_MAJOR}OpenGLWidgets_FOUND
|
||||
)
|
||||
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
# Check that we have Qt with sqlite driver
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++17")
|
||||
@@ -848,6 +834,12 @@ set(SOURCES
|
||||
src/device/devicestatefiltermodel.cpp
|
||||
src/device/deviceviewcontainer.cpp
|
||||
src/device/deviceview.cpp
|
||||
|
||||
src/artistbio/artistbioview.cpp
|
||||
src/artistbio/artistbiofetcher.cpp
|
||||
src/artistbio/artistbioprovider.cpp
|
||||
src/artistbio/lastfmartistbio.cpp
|
||||
src/artistbio/wikipediaartistbio.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
@@ -1136,6 +1128,12 @@ set(HEADERS
|
||||
src/device/devicestatefiltermodel.h
|
||||
src/device/deviceviewcontainer.h
|
||||
src/device/deviceview.h
|
||||
|
||||
src/artistbio/artistbiofetcher.h
|
||||
src/artistbio/artistbioprovider.h
|
||||
src/artistbio/artistbioview.h
|
||||
src/artistbio/lastfmartistbio.h
|
||||
src/artistbio/wikipediaartistbio.h
|
||||
)
|
||||
|
||||
set(UI
|
||||
@@ -1494,26 +1492,6 @@ optional_source(HAVE_QOBUZ
|
||||
src/settings/qobuzsettingspage.ui
|
||||
)
|
||||
|
||||
optional_source(HAVE_VISUALIZATIONS
|
||||
SOURCES
|
||||
src/visualizations/projectmpresetmodel.cpp
|
||||
src/visualizations/projectmvisualization.cpp
|
||||
src/visualizations/visualizationcontainer.cpp
|
||||
src/visualizations/visualizationoverlay.cpp
|
||||
src/visualizations/visualizationselector.cpp
|
||||
src/visualizations/visualizationopenglwidget.cpp
|
||||
HEADERS
|
||||
src/visualizations/projectmpresetmodel.h
|
||||
src/visualizations/projectmvisualization.h
|
||||
src/visualizations/visualizationcontainer.h
|
||||
src/visualizations/visualizationoverlay.h
|
||||
src/visualizations/visualizationselector.h
|
||||
src/visualizations/visualizationopenglwidget.h
|
||||
UI
|
||||
src/visualizations/visualizationoverlay.ui
|
||||
src/visualizations/visualizationselector.ui
|
||||
)
|
||||
|
||||
qt_wrap_cpp(SOURCES ${HEADERS})
|
||||
qt_wrap_ui(SOURCES ${UI})
|
||||
qt_add_resources(SOURCES data/data.qrc data/icons.qrc)
|
||||
@@ -1584,7 +1562,6 @@ target_link_libraries(strawberry_lib PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Sql
|
||||
$<$<BOOL:${HAVE_DBUS}>:Qt${QT_VERSION_MAJOR}::DBus>
|
||||
$<$<BOOL:${HAVE_QPA_QPLATFORMNATIVEINTERFACE}>:Qt${QT_VERSION_MAJOR}::GuiPrivate>
|
||||
$<$<BOOL:${HAVE_VISUALIZATIONS}>:Qt${QT_VERSION_MAJOR}::OpenGLWidgets>
|
||||
ICU::uc
|
||||
ICU::i18n
|
||||
$<$<BOOL:${HAVE_STREAMTAGREADER}>:PkgConfig::LIBSPARSEHASH>
|
||||
@@ -1600,7 +1577,6 @@ target_link_libraries(strawberry_lib PUBLIC
|
||||
$<$<BOOL:${HAVE_MTP}>:PkgConfig::LIBMTP>
|
||||
$<$<BOOL:${HAVE_GPOD}>:PkgConfig::LIBGPOD PkgConfig::GDK_PIXBUF>
|
||||
$<$<BOOL:${HAVE_QTSPARKLE}>:qtsparkle-qt${QT_VERSION_MAJOR}::qtsparkle>
|
||||
$<$<BOOL:${HAVE_VISUALIZATIONS}>:${LIBPROJECTM_LIBRARIES}>
|
||||
$<$<BOOL:${WIN32}>:dsound dwmapi ${GETOPT_LIBRARIES}>
|
||||
$<$<BOOL:${MSVC}>:WindowsApp>
|
||||
KDAB::kdsingleapplication
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<file>schema/schema-21.sql</file>
|
||||
<file>schema/device-schema.sql</file>
|
||||
<file>style/strawberry.css</file>
|
||||
<file>style/artistbio.css</file>
|
||||
<file>style/smartplaylistsearchterm.css</file>
|
||||
<file>html/oauthsuccess.html</file>
|
||||
<file>pictures/strawberry.png</file>
|
||||
|
||||
@@ -98,6 +98,7 @@
|
||||
<file>icons/128x128/somafm.png</file>
|
||||
<file>icons/128x128/radioparadise.png</file>
|
||||
<file>icons/128x128/musicbrainz.png</file>
|
||||
<file>icons/128x128/guitar.png</file>
|
||||
<file>icons/64x64/albums.png</file>
|
||||
<file>icons/64x64/alsa.png</file>
|
||||
<file>icons/64x64/application-exit.png</file>
|
||||
@@ -197,6 +198,7 @@
|
||||
<file>icons/64x64/somafm.png</file>
|
||||
<file>icons/64x64/radioparadise.png</file>
|
||||
<file>icons/64x64/musicbrainz.png</file>
|
||||
<file>icons/64x64/guitar.png</file>
|
||||
<file>icons/48x48/albums.png</file>
|
||||
<file>icons/48x48/alsa.png</file>
|
||||
<file>icons/48x48/application-exit.png</file>
|
||||
@@ -300,6 +302,7 @@
|
||||
<file>icons/48x48/somafm.png</file>
|
||||
<file>icons/48x48/radioparadise.png</file>
|
||||
<file>icons/48x48/musicbrainz.png</file>
|
||||
<file>icons/48x48/guitar.png</file>
|
||||
<file>icons/32x32/albums.png</file>
|
||||
<file>icons/32x32/alsa.png</file>
|
||||
<file>icons/32x32/application-exit.png</file>
|
||||
@@ -403,6 +406,7 @@
|
||||
<file>icons/32x32/somafm.png</file>
|
||||
<file>icons/32x32/radioparadise.png</file>
|
||||
<file>icons/32x32/musicbrainz.png</file>
|
||||
<file>icons/32x32/guitar.png</file>
|
||||
<file>icons/22x22/albums.png</file>
|
||||
<file>icons/22x22/alsa.png</file>
|
||||
<file>icons/22x22/application-exit.png</file>
|
||||
@@ -506,5 +510,6 @@
|
||||
<file>icons/22x22/somafm.png</file>
|
||||
<file>icons/22x22/radioparadise.png</file>
|
||||
<file>icons/22x22/musicbrainz.png</file>
|
||||
<file>icons/22x22/guitar.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
data/icons/128x128/guitar.png
Normal file
BIN
data/icons/128x128/guitar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
data/icons/22x22/guitar.png
Normal file
BIN
data/icons/22x22/guitar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
data/icons/32x32/guitar.png
Normal file
BIN
data/icons/32x32/guitar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
data/icons/48x48/guitar.png
Normal file
BIN
data/icons/48x48/guitar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
BIN
data/icons/64x64/guitar.png
Normal file
BIN
data/icons/64x64/guitar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
BIN
data/icons/full/guitar.png
Normal file
BIN
data/icons/full/guitar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 125 KiB |
7
data/style/artistbio.css
Normal file
7
data/style/artistbio.css
Normal file
@@ -0,0 +1,7 @@
|
||||
QScrollArea {
|
||||
background: qpalette(base);
|
||||
}
|
||||
|
||||
QTextEdit {
|
||||
border: 0px;
|
||||
}
|
||||
3
debian/control
vendored
3
debian/control
vendored
@@ -32,8 +32,7 @@ Build-Depends: debhelper-compat (= 12),
|
||||
libfftw3-dev,
|
||||
libebur128-dev,
|
||||
libsparsehash-dev,
|
||||
rapidjson-dev,
|
||||
libprojectm-dev
|
||||
rapidjson-dev
|
||||
Standards-Version: 4.7.0
|
||||
|
||||
Package: strawberry
|
||||
|
||||
1
dist/unix/strawberry.spec.in
vendored
1
dist/unix/strawberry.spec.in
vendored
@@ -43,7 +43,6 @@ BuildRequires: pkgconfig(taglib)
|
||||
BuildRequires: pkgconfig(fftw3)
|
||||
BuildRequires: pkgconfig(icu-uc)
|
||||
BuildRequires: pkgconfig(icu-i18n)
|
||||
BuildRequires: pkgconfig(libprojectM)
|
||||
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Core)
|
||||
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Concurrent)
|
||||
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Network)
|
||||
|
||||
@@ -73,8 +73,7 @@ AnalyzerContainer::AnalyzerContainer(QWidget *parent)
|
||||
double_click_timer_(new QTimer(this)),
|
||||
ignore_next_click_(false),
|
||||
current_analyzer_(nullptr),
|
||||
engine_(nullptr),
|
||||
action_visualization_(nullptr) {
|
||||
engine_(nullptr) {
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
setLayout(layout);
|
||||
@@ -119,17 +118,6 @@ void AnalyzerContainer::mouseReleaseEvent(QMouseEvent *e) {
|
||||
|
||||
}
|
||||
|
||||
void AnalyzerContainer::mouseDoubleClickEvent(QMouseEvent *e) {
|
||||
|
||||
Q_UNUSED(e);
|
||||
|
||||
double_click_timer_->stop();
|
||||
ignore_next_click_ = true;
|
||||
|
||||
if (action_visualization_) action_visualization_->trigger();
|
||||
|
||||
}
|
||||
|
||||
void AnalyzerContainer::ShowPopupMenu() {
|
||||
context_menu_->popup(last_click_pos_);
|
||||
}
|
||||
@@ -261,10 +249,3 @@ void AnalyzerContainer::AddFramerate(const QString &name, const int framerate) {
|
||||
QObject::connect(action, &QAction::triggered, this, [this, framerate]() { ChangeFramerate(framerate); } );
|
||||
|
||||
}
|
||||
|
||||
void AnalyzerContainer::SetVisualizationsAction(QAction *visualization) {
|
||||
|
||||
action_visualization_ = visualization;
|
||||
context_menu_->addAction(action_visualization_);
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ class AnalyzerContainer : public QWidget {
|
||||
explicit AnalyzerContainer(QWidget *parent);
|
||||
|
||||
void SetEngine(SharedPtr<EngineBase> engine);
|
||||
void SetVisualizationsAction(QAction *visualization);
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
static const char *kSettingsFramerate;
|
||||
@@ -56,7 +55,6 @@ class AnalyzerContainer : public QWidget {
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
@@ -91,8 +89,6 @@ class AnalyzerContainer : public QWidget {
|
||||
|
||||
AnalyzerBase *current_analyzer_;
|
||||
SharedPtr<EngineBase> engine_;
|
||||
|
||||
QAction *action_visualization_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
126
src/artistbio/artistbiofetcher.cpp
Normal file
126
src/artistbio/artistbiofetcher.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
|
||||
#include "artistbiofetcher.h"
|
||||
#include "artistbioprovider.h"
|
||||
#include "core/logging.h"
|
||||
|
||||
ArtistBioFetcher::ArtistBioFetcher(QObject *parent)
|
||||
: QObject(parent),
|
||||
timeout_duration_(kDefaultTimeoutDuration),
|
||||
next_id_(1) {}
|
||||
|
||||
void ArtistBioFetcher::AddProvider(ArtistBioProvider *provider) {
|
||||
|
||||
providers_ << provider;
|
||||
connect(provider, SIGNAL(ImageReady(int, QUrl)), SLOT(ImageReady(int, QUrl)), Qt::QueuedConnection);
|
||||
connect(provider, SIGNAL(InfoReady(int, CollapsibleInfoPane::Data)), SLOT(InfoReady(int, CollapsibleInfoPane::Data)), Qt::QueuedConnection);
|
||||
connect(provider, SIGNAL(Finished(int)), SLOT(ProviderFinished(int)), Qt::QueuedConnection);
|
||||
|
||||
}
|
||||
|
||||
ArtistBioFetcher::~ArtistBioFetcher() {
|
||||
|
||||
while (!providers_.isEmpty()) {
|
||||
ArtistBioProvider *provider = providers_.takeFirst();
|
||||
provider->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int ArtistBioFetcher::FetchInfo(const Song &metadata) {
|
||||
|
||||
const int id = next_id_++;
|
||||
results_[id] = Result();
|
||||
timeout_timers_[id] = new QTimer(this);
|
||||
timeout_timers_[id]->setSingleShot(true);
|
||||
timeout_timers_[id]->setInterval(timeout_duration_);
|
||||
timeout_timers_[id]->start();
|
||||
|
||||
connect(timeout_timers_[id], &QTimer::timeout, [this, id]() { Timeout(id); });
|
||||
|
||||
for (ArtistBioProvider *provider : providers_) {
|
||||
if (provider->is_enabled()) {
|
||||
waiting_for_[id].append(provider);
|
||||
provider->Start(id, metadata);
|
||||
}
|
||||
}
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioFetcher::ImageReady(const int id, const QUrl &url) {
|
||||
|
||||
if (!results_.contains(id)) return;
|
||||
results_[id].images_ << url;
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioFetcher::InfoReady(const int id, const CollapsibleInfoPane::Data &data) {
|
||||
|
||||
if (!results_.contains(id)) return;
|
||||
results_[id].info_ << data;
|
||||
|
||||
if (!waiting_for_.contains(id)) return;
|
||||
Q_EMIT InfoResultReady(id, data);
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioFetcher::ProviderFinished(const int id) {
|
||||
|
||||
if (!results_.contains(id)) return;
|
||||
if (!waiting_for_.contains(id)) return;
|
||||
|
||||
ArtistBioProvider *provider = qobject_cast<ArtistBioProvider*>(sender());
|
||||
if (!waiting_for_[id].contains(provider)) return;
|
||||
|
||||
waiting_for_[id].removeAll(provider);
|
||||
if (waiting_for_[id].isEmpty()) {
|
||||
Result result = results_.take(id);
|
||||
Q_EMIT ResultReady(id, result);
|
||||
waiting_for_.remove(id);
|
||||
delete timeout_timers_.take(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioFetcher::Timeout(const int id) {
|
||||
|
||||
if (!results_.contains(id)) return;
|
||||
if (!waiting_for_.contains(id)) return;
|
||||
|
||||
// Emit the results that we have already
|
||||
Q_EMIT ResultReady(id, results_.take(id));
|
||||
|
||||
// Cancel any providers that we're still waiting for
|
||||
for (ArtistBioProvider *provider : waiting_for_[id]) {
|
||||
qLog(Info) << "Request timed out from info provider" << provider->name();
|
||||
provider->Cancel(id);
|
||||
}
|
||||
waiting_for_.remove(id);
|
||||
|
||||
// Remove the timer
|
||||
delete timeout_timers_.take(id);
|
||||
|
||||
}
|
||||
75
src/artistbio/artistbiofetcher.h
Normal file
75
src/artistbio/artistbiofetcher.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ARTISTBIOFETCHER_H
|
||||
#define ARTISTBIOFETCHER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QUrl>
|
||||
|
||||
#include "widgets/collapsibleinfopane.h"
|
||||
#include "core/song.h"
|
||||
|
||||
class QTimer;
|
||||
class ArtistBioProvider;
|
||||
|
||||
class ArtistBioFetcher : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ArtistBioFetcher(QObject *parent = nullptr);
|
||||
~ArtistBioFetcher() override;
|
||||
|
||||
struct Result {
|
||||
QList<QUrl> images_;
|
||||
QList<CollapsibleInfoPane::Data> info_;
|
||||
};
|
||||
|
||||
static const int kDefaultTimeoutDuration = 25000;
|
||||
|
||||
void AddProvider(ArtistBioProvider *provider);
|
||||
int FetchInfo(const Song &metadata);
|
||||
|
||||
QList<ArtistBioProvider*> providers() const { return providers_; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void InfoResultReady(int, CollapsibleInfoPane::Data);
|
||||
void ResultReady(int, ArtistBioFetcher::Result);
|
||||
|
||||
private Q_SLOTS:
|
||||
void ImageReady(const int id, const QUrl &url);
|
||||
void InfoReady(const int id, const CollapsibleInfoPane::Data &data);
|
||||
void ProviderFinished(const int id);
|
||||
void Timeout(const int id);
|
||||
|
||||
private:
|
||||
QList<ArtistBioProvider*> providers_;
|
||||
|
||||
QMap<int, Result> results_;
|
||||
QMap<int, QList<ArtistBioProvider*>> waiting_for_;
|
||||
QMap<int, QTimer*> timeout_timers_;
|
||||
|
||||
int timeout_duration_;
|
||||
int next_id_;
|
||||
};
|
||||
|
||||
#endif // ARTISTBIOFETCHER_H
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,23 +18,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "artistbioprovider.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
ArtistBioProvider::ArtistBioProvider() : enabled_(true) {}
|
||||
|
||||
#include "visualizationopenglwidget.h"
|
||||
#include "projectmvisualization.h"
|
||||
|
||||
VisualizationOpenGLWidget::VisualizationOpenGLWidget(ProjectMVisualization *projectm_visualization, QWidget *parent, Qt::WindowFlags f)
|
||||
: QOpenGLWidget(parent, f),
|
||||
projectm_visualization_(projectm_visualization) {}
|
||||
|
||||
void VisualizationOpenGLWidget::initializeGL() {
|
||||
|
||||
projectm_visualization_->Init();
|
||||
|
||||
QOpenGLWidget::initializeGL();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
}
|
||||
QString ArtistBioProvider::name() const { return QString::fromLatin1(metaObject()->className()); }
|
||||
53
src/artistbio/artistbioprovider.h
Normal file
53
src/artistbio/artistbioprovider.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ARTISTBIOPROVIDER_H
|
||||
#define ARTISTBIOPROVIDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
#include "widgets/collapsibleinfopane.h"
|
||||
#include "core/song.h"
|
||||
|
||||
class ArtistBioProvider : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ArtistBioProvider();
|
||||
|
||||
virtual void Start(const int id, const Song &song) = 0;
|
||||
virtual void Cancel(const int) {}
|
||||
|
||||
virtual QString name() const;
|
||||
|
||||
bool is_enabled() const { return enabled_; }
|
||||
void set_enabled(bool enabled) { enabled_ = enabled; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void ImageReady(int, QUrl);
|
||||
void InfoReady(int, CollapsibleInfoPane::Data);
|
||||
void Finished(int);
|
||||
|
||||
private:
|
||||
bool enabled_;
|
||||
};
|
||||
|
||||
#endif // ARTISTBIOPROVIDER_H
|
||||
287
src/artistbio/artistbioview.cpp
Normal file
287
src/artistbio/artistbioview.cpp
Normal file
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QWidget>
|
||||
#include <QFile>
|
||||
#include <QScrollArea>
|
||||
#include <QSettings>
|
||||
#include <QSpacerItem>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QShowEvent>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "widgets/prettyimageview.h"
|
||||
#include "widgets/widgetfadehelper.h"
|
||||
#include "artistbiofetcher.h"
|
||||
#include "lastfmartistbio.h"
|
||||
#include "wikipediaartistbio.h"
|
||||
|
||||
#include "artistbioview.h"
|
||||
|
||||
const char *ArtistBioView::kSettingsGroup = "ArtistBio";
|
||||
|
||||
ArtistBioView::ArtistBioView(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
fetcher_(new ArtistBioFetcher(this)),
|
||||
current_request_id_(-1),
|
||||
container_(new QVBoxLayout),
|
||||
section_container_(nullptr),
|
||||
fader_(new WidgetFadeHelper(this, 1000)),
|
||||
dirty_(false) {
|
||||
|
||||
// Add the top-level scroll area
|
||||
QScrollArea *scrollarea = new QScrollArea(this);
|
||||
setLayout(new QVBoxLayout);
|
||||
layout()->setContentsMargins(0, 0, 0, 0);
|
||||
layout()->addWidget(scrollarea);
|
||||
|
||||
// Add a container widget to the scroll area
|
||||
QWidget *container_widget = new QWidget;
|
||||
container_widget->setLayout(container_);
|
||||
container_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
container_widget->setBackgroundRole(QPalette::Base);
|
||||
container_->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
container_->setContentsMargins(0, 0, 0, 0);
|
||||
container_->setSpacing(6);
|
||||
scrollarea->setWidget(container_widget);
|
||||
scrollarea->setWidgetResizable(true);
|
||||
|
||||
// Add a spacer to the bottom of the container
|
||||
container_->addStretch();
|
||||
|
||||
// Set stylesheet
|
||||
QFile stylesheet(QStringLiteral(":/style/artistbio.css"));
|
||||
if (stylesheet.open(QIODevice::ReadOnly)) {
|
||||
setStyleSheet(QString::fromLatin1(stylesheet.readAll()));
|
||||
stylesheet.close();
|
||||
}
|
||||
|
||||
fetcher_->AddProvider(new LastFMArtistBio);
|
||||
fetcher_->AddProvider(new WikipediaArtistBio);
|
||||
|
||||
connect(fetcher_, SIGNAL(ResultReady(int, ArtistBioFetcher::Result)), SLOT(ResultReady(int, ArtistBioFetcher::Result)));
|
||||
connect(fetcher_, SIGNAL(InfoResultReady(int, CollapsibleInfoPane::Data)), SLOT(InfoResultReady(int, CollapsibleInfoPane::Data)));
|
||||
|
||||
}
|
||||
|
||||
ArtistBioView::~ArtistBioView() {}
|
||||
|
||||
void ArtistBioView::showEvent(QShowEvent *e) {
|
||||
|
||||
if (dirty_) {
|
||||
MaybeUpdate(queued_metadata_);
|
||||
dirty_ = false;
|
||||
}
|
||||
|
||||
QWidget::showEvent(e);
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::ReloadSettings() {
|
||||
|
||||
for (CollapsibleInfoPane *pane : sections_) {
|
||||
QWidget *contents = pane->data().contents_;
|
||||
if (!contents) continue;
|
||||
|
||||
QMetaObject::invokeMethod(contents, "ReloadSettings");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ArtistBioView::NeedsUpdate(const Song &old_metadata, const Song &new_metadata) const {
|
||||
|
||||
if (new_metadata.artist().isEmpty()) return false;
|
||||
|
||||
return old_metadata.artist() != new_metadata.artist();
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::InfoResultReady(const int id, const CollapsibleInfoPane::Data &_data) {
|
||||
|
||||
if (id != current_request_id_) return;
|
||||
|
||||
AddSection(new CollapsibleInfoPane(_data, this));
|
||||
CollapseSections();
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::ResultReady(const int id, const ArtistBioFetcher::Result &result) {
|
||||
|
||||
if (id != current_request_id_) return;
|
||||
|
||||
if (!result.images_.isEmpty()) {
|
||||
// Image view goes at the top
|
||||
PrettyImageView *image_view = new PrettyImageView(network_, this);
|
||||
AddWidget(image_view);
|
||||
|
||||
for (const QUrl& url : result.images_) {
|
||||
image_view->AddImage(url);
|
||||
}
|
||||
}
|
||||
|
||||
CollapseSections();
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::Clear() {
|
||||
|
||||
fader_->StartFade();
|
||||
|
||||
qDeleteAll(widgets_);
|
||||
widgets_.clear();
|
||||
if (section_container_) {
|
||||
container_->removeWidget(section_container_);
|
||||
delete section_container_;
|
||||
}
|
||||
sections_.clear();
|
||||
|
||||
// Container for collapsible sections goes below
|
||||
section_container_ = new QWidget;
|
||||
section_container_->setLayout(new QVBoxLayout);
|
||||
section_container_->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
section_container_->layout()->setSpacing(1);
|
||||
section_container_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
container_->insertWidget(0, section_container_);
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::AddSection(CollapsibleInfoPane *section) {
|
||||
|
||||
int i = 0;
|
||||
for (; i < sections_.count(); ++i) {
|
||||
if (section->data() < sections_[i]->data()) break;
|
||||
}
|
||||
|
||||
ConnectWidget(section->data().contents_);
|
||||
|
||||
sections_.insert(i, section);
|
||||
qobject_cast<QVBoxLayout*>(section_container_->layout())->insertWidget(i, section);
|
||||
section->show();
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::AddWidget(QWidget *widget) {
|
||||
|
||||
ConnectWidget(widget);
|
||||
|
||||
container_->insertWidget(container_->count() - 2, widget);
|
||||
widgets_ << widget;
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::SongChanged(const Song &metadata) {
|
||||
|
||||
if (isVisible()) {
|
||||
MaybeUpdate(metadata);
|
||||
dirty_ = false;
|
||||
}
|
||||
else {
|
||||
queued_metadata_ = metadata;
|
||||
dirty_ = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::SongFinished() { dirty_ = false; }
|
||||
|
||||
void ArtistBioView::MaybeUpdate(const Song &metadata) {
|
||||
|
||||
if (old_metadata_.is_valid()) {
|
||||
if (!NeedsUpdate(old_metadata_, metadata)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Update(metadata);
|
||||
old_metadata_ = metadata;
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::Update(const Song &metadata) {
|
||||
|
||||
current_request_id_ = fetcher_->FetchInfo(metadata);
|
||||
|
||||
// Do this after the new pane has been shown otherwise it'll just grab a black rectangle.
|
||||
Clear();
|
||||
QTimer::singleShot(0, fader_, SLOT(StartBlur()));
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::CollapseSections() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
// Sections are already sorted by type and relevance, so the algorithm we use to determine which ones to show by default is:
|
||||
// * In the absence of any user preference, show the first (highest relevance section of each type and hide the rest)
|
||||
// * If one or more sections in a type have been explicitly hidden/shown by the user before then hide all sections in that type and show only the ones that are explicitly shown.
|
||||
|
||||
QMultiMap<CollapsibleInfoPane::Data::Type, CollapsibleInfoPane*> types_;
|
||||
QSet<CollapsibleInfoPane::Data::Type> has_user_preference_;
|
||||
for (CollapsibleInfoPane *pane : sections_) {
|
||||
const CollapsibleInfoPane::Data::Type type = pane->data().type_;
|
||||
types_.insert(type, pane);
|
||||
|
||||
QVariant preference = s.value(pane->data().id_);
|
||||
if (preference.isValid()) {
|
||||
has_user_preference_.insert(type);
|
||||
if (preference.toBool()) {
|
||||
pane->Expand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (CollapsibleInfoPane::Data::Type type : types_.keys()) {
|
||||
if (!has_user_preference_.contains(type)) {
|
||||
// Expand the first one
|
||||
types_.values(type).last()->Expand();
|
||||
}
|
||||
}
|
||||
|
||||
for (CollapsibleInfoPane *pane : sections_) {
|
||||
connect(pane, SIGNAL(Toggled(bool)), SLOT(SectionToggled(bool)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::SectionToggled(const bool value) {
|
||||
|
||||
CollapsibleInfoPane *pane = qobject_cast<CollapsibleInfoPane*>(sender());
|
||||
if (!pane || !sections_.contains(pane)) return;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue(pane->data().id_, value);
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void ArtistBioView::ConnectWidget(QWidget *widget) {
|
||||
|
||||
const QMetaObject *m = widget->metaObject();
|
||||
|
||||
if (m->indexOfSignal("ShowSettingsDialog()") != -1) {
|
||||
connect(widget, SIGNAL(ShowSettingsDialog()), SIGNAL(ShowSettingsDialog()));
|
||||
}
|
||||
|
||||
}
|
||||
104
src/artistbio/artistbioview.h
Normal file
104
src/artistbio/artistbioview.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ARTISTBIOVIEW_H
|
||||
#define ARTISTBIOVIEW_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QList>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "widgets/collapsibleinfopane.h"
|
||||
#include "widgets/widgetfadehelper.h"
|
||||
#include "widgets/collapsibleinfopane.h"
|
||||
#include "playlist/playlistitem.h"
|
||||
#include "smartplaylists/playlistgenerator_fwd.h"
|
||||
#include "artistbiofetcher.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QTimeLine;
|
||||
class QVBoxLayout;
|
||||
class QScrollArea;
|
||||
class QShowEvent;
|
||||
|
||||
class PrettyImageView;
|
||||
class CollapsibleInfoPane;
|
||||
class WidgetFadeHelper;
|
||||
|
||||
class ArtistBioView : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ArtistBioView(QWidget *parent = nullptr);
|
||||
~ArtistBioView() override;
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
public Q_SLOTS:
|
||||
void SongChanged(const Song& metadata);
|
||||
void SongFinished();
|
||||
virtual void ReloadSettings();
|
||||
|
||||
Q_SIGNALS:
|
||||
void ShowSettingsDialog();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
|
||||
void Update(const Song &metadata);
|
||||
void AddWidget(QWidget *widget);
|
||||
void AddSection(CollapsibleInfoPane *section);
|
||||
void Clear();
|
||||
void CollapseSections();
|
||||
|
||||
bool NeedsUpdate(const Song& old_metadata, const Song &new_metadata) const;
|
||||
|
||||
protected Q_SLOTS:
|
||||
void ResultReady(const int id, const ArtistBioFetcher::Result &result);
|
||||
void InfoResultReady(const int id, const CollapsibleInfoPane::Data &data);
|
||||
|
||||
protected:
|
||||
QNetworkAccessManager *network_;
|
||||
ArtistBioFetcher *fetcher_;
|
||||
int current_request_id_;
|
||||
|
||||
private:
|
||||
void MaybeUpdate(const Song &metadata);
|
||||
void ConnectWidget(QWidget *widget);
|
||||
|
||||
private Q_SLOTS:
|
||||
void SectionToggled(const bool value);
|
||||
|
||||
private:
|
||||
QVBoxLayout *container_;
|
||||
QList<QWidget*> widgets_;
|
||||
|
||||
QWidget *section_container_;
|
||||
QList<CollapsibleInfoPane*> sections_;
|
||||
|
||||
WidgetFadeHelper *fader_;
|
||||
|
||||
Song queued_metadata_;
|
||||
Song old_metadata_;
|
||||
bool dirty_;
|
||||
};
|
||||
|
||||
#endif // ARTISTBIOVIEW_H
|
||||
209
src/artistbio/lastfmartistbio.cpp
Normal file
209
src/artistbio/lastfmartistbio.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QLocale>
|
||||
#include <QVariant>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QDateTime>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "core/song.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/iconloader.h"
|
||||
|
||||
#include "lastfmartistbio.h"
|
||||
#include "widgets/infotextview.h"
|
||||
#include "scrobbler/scrobblingapi20.h"
|
||||
#include "scrobbler/lastfmscrobbler.h"
|
||||
|
||||
LastFMArtistBio::LastFMArtistBio() : ArtistBioProvider(), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
LastFMArtistBio::~LastFMArtistBio() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LastFMArtistBio::Start(const int id, const Song &song) {
|
||||
|
||||
ParamList params = ParamList()
|
||||
<< Param(QStringLiteral("api_key"), QString::fromLatin1(ScrobblingAPI20::kApiKey))
|
||||
<< Param(QStringLiteral("lang"), QLocale().name().left(2).toLower())
|
||||
<< Param(QStringLiteral("format"), QStringLiteral("json"))
|
||||
<< Param(QStringLiteral("method"), QStringLiteral("artist.getinfo"))
|
||||
<< Param(QStringLiteral("artist"), song.artist());
|
||||
|
||||
std::sort(params.begin(), params.end());
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
url_query.addQueryItem(QString::fromLatin1(QUrl::toPercentEncoding(param.first)), QString::fromLatin1(QUrl::toPercentEncoding(param.second)));
|
||||
}
|
||||
|
||||
QUrl url(QString::fromLatin1(LastFMScrobbler::kApiUrl));
|
||||
url.setQuery(url_query);
|
||||
QNetworkRequest req(url);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
|
||||
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
#else
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#endif
|
||||
req.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded"));
|
||||
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
replies_ << reply;
|
||||
connect(reply, &QNetworkReply::finished, [=] { RequestFinished(reply, id); });
|
||||
|
||||
qLog(Debug) << "Sending request" << url_query.toString(QUrl::FullyDecoded);
|
||||
|
||||
}
|
||||
|
||||
QByteArray LastFMArtistBio::GetReplyData(QNetworkReply *reply) {
|
||||
|
||||
QByteArray data;
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
|
||||
data = reply->readAll();
|
||||
}
|
||||
else {
|
||||
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
|
||||
// This is a network error, there is nothing more to do.
|
||||
Error(QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
}
|
||||
else {
|
||||
QString error;
|
||||
// See if there is Json data containing "error" and "message" - then use that instead.
|
||||
data = reply->readAll();
|
||||
QJsonParseError json_error;
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
|
||||
int error_code = -1;
|
||||
if (json_error.error == QJsonParseError::NoError && !json_doc.isEmpty() && json_doc.isObject()) {
|
||||
QJsonObject json_obj = json_doc.object();
|
||||
if (json_obj.contains(QLatin1String("error")) && json_obj.contains(QLatin1String("message"))) {
|
||||
error_code = json_obj[QLatin1String("error")].toInt();
|
||||
QString error_message = json_obj[QLatin1String("message")].toString();
|
||||
error = QStringLiteral("%1 (%2)").arg(error_message).arg(error_code);
|
||||
}
|
||||
}
|
||||
if (error.isEmpty()) {
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
error = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
}
|
||||
else {
|
||||
error = QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
}
|
||||
}
|
||||
Error(error);
|
||||
}
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
QJsonObject LastFMArtistBio::ExtractJsonObj(const QByteArray &data) {
|
||||
|
||||
if (data.isEmpty()) return QJsonObject();
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
Error(QStringLiteral("Reply from server missing Json data."), data);
|
||||
return QJsonObject();
|
||||
}
|
||||
if (json_doc.isEmpty()) {
|
||||
Error(QStringLiteral("Received empty Json document."), json_doc);
|
||||
return QJsonObject();
|
||||
}
|
||||
if (!json_doc.isObject()) {
|
||||
Error(QStringLiteral("Json document is not an object."), json_doc);
|
||||
return QJsonObject();
|
||||
}
|
||||
QJsonObject json_obj = json_doc.object();
|
||||
if (json_obj.isEmpty()) {
|
||||
Error(QStringLiteral("Received empty Json object."), json_doc);
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
return json_obj;
|
||||
|
||||
}
|
||||
|
||||
void LastFMArtistBio::RequestFinished(QNetworkReply *reply, const int id) {
|
||||
|
||||
if (!replies_.contains(reply)) return;
|
||||
replies_.removeAll(reply);
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonObject json_obj = ExtractJsonObj(GetReplyData(reply));
|
||||
|
||||
QString title;
|
||||
QString text;
|
||||
if (!json_obj.isEmpty() && json_obj.contains(QLatin1String("artist")) && json_obj[QLatin1String("artist")].isObject()) {
|
||||
json_obj = json_obj[QLatin1String("artist")].toObject();
|
||||
if (json_obj.contains(QLatin1String("bio")) && json_obj[QLatin1String("bio")].isObject()) {
|
||||
title = json_obj[QLatin1String("name")].toString();
|
||||
QJsonObject obj_bio = json_obj[QLatin1String("bio")].toObject();
|
||||
if (obj_bio.contains(QLatin1String("content"))) {
|
||||
text = obj_bio[QLatin1String("content")].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CollapsibleInfoPane::Data info_data;
|
||||
info_data.id_ = title;
|
||||
info_data.title_ = tr("Biography");
|
||||
info_data.type_ = CollapsibleInfoPane::Data::Type_Biography;
|
||||
info_data.icon_ = IconLoader::Load(QStringLiteral("scrobble"));
|
||||
InfoTextView *editor = new InfoTextView;
|
||||
editor->SetHtml(text);
|
||||
info_data.contents_ = editor;
|
||||
Q_EMIT InfoReady(id, info_data);
|
||||
Q_EMIT Finished(id);
|
||||
|
||||
}
|
||||
|
||||
void LastFMArtistBio::Error(const QString &error, const QVariant &debug) {
|
||||
|
||||
qLog(Error) << error;
|
||||
if (debug.isValid()) qLog(Debug) << debug;
|
||||
|
||||
}
|
||||
66
src/artistbio/lastfmartistbio.h
Normal file
66
src/artistbio/lastfmartistbio.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LASTFMARTISTBIO_H
|
||||
#define LASTFMARTISTBIO_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
#include "artistbioprovider.h"
|
||||
|
||||
class NetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class LastFMArtistBio : public ArtistBioProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LastFMArtistBio();
|
||||
~LastFMArtistBio();
|
||||
|
||||
void Start(const int id, const Song &song) override;
|
||||
|
||||
private:
|
||||
using Param = QPair<QString, QString>;
|
||||
using ParamList = QList<Param>;
|
||||
|
||||
QNetworkReply *CreateRequest(const ParamList &request_params);
|
||||
QByteArray GetReplyData(QNetworkReply *reply);
|
||||
QJsonObject ExtractJsonObj(const QByteArray &data);
|
||||
void Error(const QString &error, const QVariant &debug = QVariant());
|
||||
|
||||
private Q_SLOTS:
|
||||
void RequestFinished(QNetworkReply *reply, const int id);
|
||||
|
||||
private:
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
#endif // LASTFMARTISTBIO_H
|
||||
319
src/artistbio/wikipediaartistbio.cpp
Normal file
319
src/artistbio/wikipediaartistbio.cpp
Normal file
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/latch.h"
|
||||
|
||||
#include "widgets/infotextview.h"
|
||||
#include "wikipediaartistbio.h"
|
||||
|
||||
namespace {
|
||||
constexpr char kApiUrl[] = "https://en.wikipedia.org/w/api.php";
|
||||
constexpr int kMinimumImageSize = 400;
|
||||
}
|
||||
|
||||
WikipediaArtistBio::WikipediaArtistBio() : ArtistBioProvider(), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
WikipediaArtistBio::~WikipediaArtistBio() {
|
||||
|
||||
while (!replies_.isEmpty()) {
|
||||
QNetworkReply *reply = replies_.takeFirst();
|
||||
disconnect(reply, nullptr, this, nullptr);
|
||||
if (reply->isRunning()) reply->abort();
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QNetworkReply *WikipediaArtistBio::CreateRequest(QList<Param> ¶ms) {
|
||||
|
||||
params << Param(QLatin1String("format"), QLatin1String("json"));
|
||||
params << Param(QLatin1String("action"), QLatin1String("query"));
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
url_query.addQueryItem(QString::fromLatin1(QUrl::toPercentEncoding(param.first)), QString::fromLatin1(QUrl::toPercentEncoding(param.second)));
|
||||
}
|
||||
|
||||
QUrl url(QString::fromLatin1(kApiUrl));
|
||||
url.setQuery(url_query);
|
||||
QNetworkRequest req(url);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
|
||||
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
#else
|
||||
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
#endif
|
||||
req.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded"));
|
||||
|
||||
QNetworkReply *reply = network_->get(req);
|
||||
connect(reply, &QNetworkReply::sslErrors, this, &WikipediaArtistBio::HandleSSLErrors);
|
||||
replies_ << reply;
|
||||
|
||||
return reply;
|
||||
|
||||
}
|
||||
|
||||
QByteArray WikipediaArtistBio::GetReplyData(QNetworkReply *reply) {
|
||||
|
||||
QByteArray data;
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
|
||||
data = reply->readAll();
|
||||
}
|
||||
else {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
qLog(Error) << "Wikipedia artist biography error: Received HTTP code" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
}
|
||||
else {
|
||||
qLog(Error) << "Wikipedia artist biography error:" << reply->error() << reply->errorString();
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
QJsonObject WikipediaArtistBio::ExtractJsonObj(const QByteArray &data) {
|
||||
|
||||
if (data.isEmpty()) return QJsonObject();
|
||||
|
||||
QJsonParseError json_error;
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
|
||||
|
||||
if (json_error.error != QJsonParseError::NoError) {
|
||||
qLog(Error) << "Wikipedia artist biography error: Failed to parse json data:" << json_error.errorString();
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
if (json_doc.isEmpty()) {
|
||||
qLog(Error) << "Wikipedia artist biography error: Received empty Json document.";
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
if (!json_doc.isObject()) {
|
||||
qLog(Error) << "Wikipedia artist biography error: Json document is not an object.";
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
QJsonObject json_obj = json_doc.object();
|
||||
if (json_obj.isEmpty()) {
|
||||
qLog(Error) << "Wikipedia artist biography error: Received empty Json object.";
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
return json_obj;
|
||||
|
||||
}
|
||||
|
||||
void WikipediaArtistBio::HandleSSLErrors(QList<QSslError>) {}
|
||||
|
||||
void WikipediaArtistBio::Start(const int id, const Song &metadata) {
|
||||
|
||||
if (metadata.artist().isEmpty()) {
|
||||
Q_EMIT Finished(id);
|
||||
return;
|
||||
}
|
||||
|
||||
CountdownLatch *latch = new CountdownLatch;
|
||||
connect(latch, &CountdownLatch::Done, [this, id, latch](){
|
||||
latch->deleteLater();
|
||||
Q_EMIT Finished(id);
|
||||
});
|
||||
|
||||
GetImageTitles(id, metadata.artist(), latch);
|
||||
//GetArticle(id, metadata.artist(), latch);
|
||||
|
||||
}
|
||||
|
||||
void WikipediaArtistBio::GetArticle(const int id, const QString &artist, CountdownLatch *latch) {
|
||||
|
||||
latch->Wait();
|
||||
|
||||
ParamList params = ParamList() << Param(QStringLiteral("titles"), artist)
|
||||
<< Param(QStringLiteral("prop"), QStringLiteral("extracts"));
|
||||
|
||||
QNetworkReply *reply = CreateRequest(params);
|
||||
connect(reply, &QNetworkReply::finished, [this, reply, id, latch]() { GetArticleReply(reply, id, latch); });
|
||||
|
||||
}
|
||||
|
||||
void WikipediaArtistBio::GetArticleReply(QNetworkReply *reply, const int id, CountdownLatch *latch) {
|
||||
|
||||
reply->deleteLater();
|
||||
replies_.removeAll(reply);
|
||||
|
||||
QJsonObject json_obj = ExtractJsonObj(GetReplyData(reply));
|
||||
|
||||
QString title;
|
||||
QString text;
|
||||
if (!json_obj.isEmpty() && json_obj.contains(QLatin1String("query")) && json_obj[QLatin1String("query")].isObject()) {
|
||||
json_obj = json_obj[QLatin1String("query")].toObject();
|
||||
if (json_obj.contains(QLatin1String("pages")) && json_obj[QLatin1String("pages")].isObject()) {
|
||||
QJsonObject value_pages = json_obj[QLatin1String("pages")].toObject();
|
||||
for (const QJsonValue value_page : value_pages) {
|
||||
if (!value_page.isObject()) continue;
|
||||
QJsonObject obj_page = value_page.toObject();
|
||||
if (!obj_page.contains(QLatin1String("title")) || !obj_page.contains(QLatin1String("extract"))) continue;
|
||||
title = obj_page[QLatin1String("title")].toString();
|
||||
text = obj_page[QLatin1String("extract")].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CollapsibleInfoPane::Data info_data;
|
||||
info_data.id_ = title;
|
||||
info_data.title_ = tr("Biography");
|
||||
info_data.type_ = CollapsibleInfoPane::Data::Type_Biography;
|
||||
info_data.icon_ = IconLoader::Load(QStringLiteral("wikipedia"));
|
||||
InfoTextView *editor = new InfoTextView;
|
||||
editor->SetHtml(text);
|
||||
info_data.contents_ = editor;
|
||||
Q_EMIT InfoReady(id, info_data);
|
||||
|
||||
latch->CountDown();
|
||||
|
||||
}
|
||||
|
||||
void WikipediaArtistBio::GetImageTitles(const int id, const QString &artist, CountdownLatch *latch) {
|
||||
|
||||
latch->Wait();
|
||||
|
||||
ParamList params = ParamList() << Param(QStringLiteral("titles"), artist)
|
||||
<< Param(QStringLiteral("prop"), QStringLiteral("images"))
|
||||
<< Param(QStringLiteral("imlimit"), QString::number(25));
|
||||
|
||||
QNetworkReply *reply = CreateRequest(params);
|
||||
connect(reply, &QNetworkReply::finished, [this, reply, id, latch]() { GetImageTitlesFinished(reply, id, latch); });
|
||||
|
||||
}
|
||||
|
||||
void WikipediaArtistBio::GetImageTitlesFinished(QNetworkReply *reply, const int id, CountdownLatch *latch) {
|
||||
|
||||
reply->deleteLater();
|
||||
replies_.removeAll(reply);
|
||||
|
||||
QJsonObject json_obj = ExtractJsonObj(GetReplyData(reply));
|
||||
|
||||
QString title;
|
||||
QStringList titles;
|
||||
if (!json_obj.isEmpty() && json_obj.contains(QLatin1String("query")) && json_obj[QLatin1String("query")].isObject()) {
|
||||
json_obj = json_obj[QLatin1String("query")].toObject();
|
||||
if (json_obj.contains(QLatin1String("pages")) && json_obj[QLatin1String("pages")].isObject()) {
|
||||
QJsonObject value_pages = json_obj[QLatin1String("pages")].toObject();
|
||||
for (const QJsonValue value_page : value_pages) {
|
||||
if (!value_page.isObject()) continue;
|
||||
QJsonObject obj_page = value_page.toObject();
|
||||
if (!obj_page.contains(QLatin1String("title")) || !obj_page.contains(QLatin1String("images")) || !obj_page[QLatin1String("images")].isArray()) continue;
|
||||
title = obj_page[QLatin1String("title")].toString();
|
||||
QJsonArray array_images = obj_page[QLatin1String("images")].toArray();
|
||||
for (const QJsonValue value_image : array_images) {
|
||||
if (!value_image.isObject()) continue;
|
||||
QJsonObject obj_image = value_image.toObject();
|
||||
if (!obj_image.contains(QLatin1String("title"))) continue;
|
||||
QString filename = obj_image[QLatin1String("title")].toString();
|
||||
if (filename.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive) || filename.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)) {
|
||||
titles << filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const QString &image_title : titles) {
|
||||
GetImage(id, image_title, latch);
|
||||
}
|
||||
|
||||
latch->CountDown();
|
||||
|
||||
}
|
||||
|
||||
void WikipediaArtistBio::GetImage(const int id, const QString &title, CountdownLatch *latch) {
|
||||
|
||||
latch->Wait();
|
||||
|
||||
ParamList params2 = ParamList() << Param(QStringLiteral("titles"), title)
|
||||
<< Param(QStringLiteral("prop"), QStringLiteral("imageinfo"))
|
||||
<< Param(QStringLiteral("iiprop"), QStringLiteral("url|size"));
|
||||
|
||||
QNetworkReply *reply = CreateRequest(params2);
|
||||
connect(reply, &QNetworkReply::finished, [this, reply, id, latch]() { GetImageFinished(reply, id, latch); });
|
||||
|
||||
}
|
||||
|
||||
void WikipediaArtistBio::GetImageFinished(QNetworkReply *reply, const int id, CountdownLatch *latch) {
|
||||
|
||||
reply->deleteLater();
|
||||
replies_.removeAll(reply);
|
||||
|
||||
QJsonObject json_obj = ExtractJsonObj(GetReplyData(reply));
|
||||
|
||||
if (!json_obj.isEmpty()) {
|
||||
QList<QUrl> urls = ExtractImageUrls(json_obj);
|
||||
for (const QUrl &url : urls) {
|
||||
Q_EMIT ImageReady(id, url);
|
||||
}
|
||||
}
|
||||
|
||||
latch->CountDown();
|
||||
|
||||
}
|
||||
|
||||
QList<QUrl> WikipediaArtistBio::ExtractImageUrls(QJsonObject json_obj) {
|
||||
|
||||
QList<QUrl> urls;
|
||||
if (json_obj.contains(QLatin1String("query")) && json_obj[QLatin1String("query")].isObject()) {
|
||||
json_obj = json_obj[QLatin1String("query")].toObject();
|
||||
if (json_obj.contains(QLatin1String("pages")) && json_obj[QLatin1String("pages")].isObject()) {
|
||||
QJsonObject value_pages = json_obj[QLatin1String("pages")].toObject();
|
||||
for (const QJsonValue value_page : value_pages) {
|
||||
if (!value_page.isObject()) continue;
|
||||
QJsonObject obj_page = value_page.toObject();
|
||||
if (!obj_page.contains(QLatin1String("title")) || !obj_page.contains(QLatin1String("imageinfo")) || !obj_page[QLatin1String("imageinfo")].isArray()) continue;
|
||||
QJsonArray array_images = obj_page[QLatin1String("imageinfo")].toArray();
|
||||
for (const QJsonValue value_image : array_images) {
|
||||
if (!value_image.isObject()) continue;
|
||||
QJsonObject obj_image = value_image.toObject();
|
||||
if (!obj_image.contains(QLatin1String("url")) || !obj_image.contains(QLatin1String("width")) || !obj_image.contains(QLatin1String("height"))) continue;
|
||||
QUrl url(obj_image[QLatin1String("url")].toString());
|
||||
const int width = obj_image[QLatin1String("width")].toInt();
|
||||
const int height = obj_image[QLatin1String("height")].toInt();
|
||||
if (!url.isValid() || width < kMinimumImageSize || height < kMinimumImageSize) continue;
|
||||
urls << url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return urls;
|
||||
|
||||
}
|
||||
69
src/artistbio/wikipediaartistbio.h
Normal file
69
src/artistbio/wikipediaartistbio.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WIKIPEDIAARTISTBIO_H
|
||||
#define WIKIPEDIAARTISTBIO_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QSslError>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "artistbioprovider.h"
|
||||
|
||||
class QNetworkReply;
|
||||
class CountdownLatch;
|
||||
class NetworkAccessManager;
|
||||
|
||||
class WikipediaArtistBio : public ArtistBioProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WikipediaArtistBio();
|
||||
~WikipediaArtistBio();
|
||||
|
||||
void Start(const int id, const Song &song) override;
|
||||
|
||||
private:
|
||||
typedef QPair<QString, QString> Param;
|
||||
typedef QList<Param> ParamList;
|
||||
|
||||
QNetworkReply *CreateRequest(QList<Param> ¶ms);
|
||||
QByteArray GetReplyData(QNetworkReply *reply);
|
||||
QJsonObject ExtractJsonObj(const QByteArray &data);
|
||||
void GetArticle(const int id, const QString &artist, CountdownLatch* latch);
|
||||
void GetImageTitles(const int id, const QString &artist, CountdownLatch* latch);
|
||||
void GetImage(const int id, const QString &title, CountdownLatch *latch);
|
||||
QList<QUrl> ExtractImageUrls(QJsonObject json_obj);
|
||||
|
||||
private Q_SLOTS:
|
||||
void HandleSSLErrors(QList<QSslError> ssl_errors);
|
||||
void GetArticleReply(QNetworkReply *reply, const int id, CountdownLatch *latch);
|
||||
void GetImageTitlesFinished(QNetworkReply *reply, const int id, CountdownLatch *latch);
|
||||
void GetImageFinished(QNetworkReply *reply, const int id, CountdownLatch *latch);
|
||||
|
||||
private:
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
#endif // WIKIPEDIAARTISTBIO_H
|
||||
@@ -48,7 +48,4 @@
|
||||
|
||||
#cmakedefine ENABLE_WIN32_CONSOLE
|
||||
|
||||
#cmakedefine HAVE_VISUALIZATIONS
|
||||
#cmakedefine HAVE_PROJECTM4
|
||||
|
||||
#endif // CONFIG_H_IN
|
||||
|
||||
39
src/core/latch.cpp
Normal file
39
src/core/latch.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2016, John Maguire <john.maguire@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include "latch.h"
|
||||
|
||||
CountdownLatch::CountdownLatch() : count_(0) {}
|
||||
|
||||
void CountdownLatch::Wait() {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
++count_;
|
||||
|
||||
}
|
||||
|
||||
void CountdownLatch::CountDown() {
|
||||
|
||||
QMutexLocker l(&mutex_);
|
||||
Q_ASSERT(count_ > 0);
|
||||
--count_;
|
||||
if (count_ == 0) {
|
||||
emit Done();
|
||||
}
|
||||
|
||||
}
|
||||
39
src/core/latch.h
Normal file
39
src/core/latch.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2016, John Maguire <john.maguire@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LATCH_H
|
||||
#define LATCH_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
class CountdownLatch : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CountdownLatch();
|
||||
void Wait();
|
||||
void CountDown();
|
||||
|
||||
Q_SIGNALS:
|
||||
void Done();
|
||||
|
||||
private:
|
||||
QMutex mutex_;
|
||||
int count_;
|
||||
};
|
||||
|
||||
#endif // LATCH_H
|
||||
@@ -205,11 +205,7 @@
|
||||
#include "smartplaylists/smartplaylistsviewcontainer.h"
|
||||
|
||||
#include "organize/organizeerrordialog.h"
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
# include "visualizations/visualizationcontainer.h"
|
||||
# include "engine/gstengine.h"
|
||||
#endif
|
||||
#include "artistbio/artistbioview.h"
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
# include "core/windows7thumbbar.h"
|
||||
@@ -237,6 +233,7 @@
|
||||
|
||||
using std::make_unique;
|
||||
using std::make_shared;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
@@ -362,6 +359,7 @@ MainWindow::MainWindow(Application *app,
|
||||
qobuz_view_(new StreamingTabsView(app->streaming_services()->ServiceBySource(Song::Source::Qobuz), app->albumcover_loader(), QLatin1String(QobuzSettings::kSettingsGroup), this)),
|
||||
#endif
|
||||
radio_view_(new RadioViewContainer(this)),
|
||||
artistbio_view_(new ArtistBioView(this)),
|
||||
lastfm_import_dialog_(new LastFMImportDialog(app_->lastfm_import(), this)),
|
||||
collection_show_all_(nullptr),
|
||||
collection_show_duplicates_(nullptr),
|
||||
@@ -446,6 +444,7 @@ MainWindow::MainWindow(Application *app,
|
||||
#ifdef HAVE_QOBUZ
|
||||
ui_->tabs->AddTab(qobuz_view_, u"qobuz"_s, IconLoader::Load(u"qobuz"_s, true, 0, 32), tr("Qobuz"));
|
||||
#endif
|
||||
ui_->tabs->AddTab(artistbio_view_, QStringLiteral("artistbio"), IconLoader::Load(QStringLiteral("guitar")), tr("Artist biography"));
|
||||
|
||||
// Add the playing widget to the fancy tab widget
|
||||
ui_->tabs->AddBottomWidget(ui_->widget_playing);
|
||||
@@ -628,12 +627,6 @@ MainWindow::MainWindow(Application *app,
|
||||
stop_menu->addAction(ui_->action_stop_after_this_track);
|
||||
ui_->stop_button->setMenu(stop_menu);
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
QObject::connect(ui_->action_visualizations, &QAction::triggered, this, &MainWindow::ShowVisualizations);
|
||||
#else
|
||||
ui_->action_visualizations->setEnabled(false);
|
||||
#endif
|
||||
|
||||
// Player connections
|
||||
QObject::connect(ui_->volume, &VolumeSlider::valueChanged, &*app_->player(), &Player::SetVolumeFromSlider);
|
||||
|
||||
@@ -918,7 +911,6 @@ MainWindow::MainWindow(Application *app,
|
||||
|
||||
// Analyzer
|
||||
QObject::connect(ui_->analyzer, &AnalyzerContainer::WheelEvent, this, &MainWindow::VolumeWheelEvent);
|
||||
ui_->analyzer->SetVisualizationsAction(ui_->action_visualizations);
|
||||
|
||||
// Statusbar widgets
|
||||
ui_->playlist_summary->setMinimumWidth(QFontMetrics(font()).horizontalAdvance(u"WW selected of WW tracks - [ WW:WW ]"_s));
|
||||
@@ -989,6 +981,10 @@ MainWindow::MainWindow(Application *app,
|
||||
ui_->action_open_cd->setVisible(false);
|
||||
#endif
|
||||
|
||||
connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, artistbio_view_, &ArtistBioView::SongChanged);
|
||||
connect(&*app_->player(), &Player::PlaylistFinished, artistbio_view_, &ArtistBioView::SongFinished);
|
||||
connect(&*app_->player(), &Player::Stopped, artistbio_view_, &ArtistBioView::SongFinished);
|
||||
|
||||
// Load settings
|
||||
qLog(Debug) << "Loading settings";
|
||||
Settings settings;
|
||||
@@ -1244,6 +1240,16 @@ void MainWindow::ReloadSettings() {
|
||||
album_cover_choice_controller_->search_cover_auto_action()->setChecked(s.value(MainWindowSettings::kSearchForCoverAuto, true).toBool());
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(BehaviourSettings::kSettingsGroup);
|
||||
bool artistbio = s.value("artistbio", false).toBool();
|
||||
s.endGroup();
|
||||
if (artistbio) {
|
||||
ui_->tabs->EnableTab(artistbio_view_);
|
||||
}
|
||||
else {
|
||||
ui_->tabs->DisableTab(artistbio_view_);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SUBSONIC
|
||||
s.beginGroup(SubsonicSettings::kSettingsGroup);
|
||||
bool enable_subsonic = s.value(SubsonicSettings::kEnabled, false).toBool();
|
||||
@@ -3416,24 +3422,3 @@ void MainWindow::FocusSearchField() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::ShowVisualizations() {
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
|
||||
if (!visualization_) {
|
||||
visualization_.reset(new VisualizationContainer);
|
||||
|
||||
visualization_->SetActions(ui_->action_previous_track, ui_->action_play_pause, ui_->action_stop, ui_->action_next_track);
|
||||
connect(&*app_->player(), &Player::Stopped, &*visualization_, &VisualizationContainer::Stopped);
|
||||
connect(&*app_->player(), &Player::ForceShowOSD, &*visualization_, &VisualizationContainer::SongMetadataChanged);
|
||||
connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, &*visualization_, &VisualizationContainer::SongMetadataChanged);
|
||||
|
||||
visualization_->SetEngine(qobject_cast<GstEngine*>(&*app_->player()->engine()));
|
||||
}
|
||||
|
||||
visualization_->show();
|
||||
|
||||
#endif // HAVE_VISUALIZATIONS
|
||||
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class Windows7ThumbBar;
|
||||
class AddStreamDialog;
|
||||
class LastFMImportDialog;
|
||||
class RadioViewContainer;
|
||||
class VisualizationContainer;
|
||||
class ArtistBioView;
|
||||
|
||||
#ifdef HAVE_DISCORD_RPC
|
||||
namespace discord {
|
||||
@@ -282,7 +282,6 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
public Q_SLOTS:
|
||||
void CommandlineOptionsReceived(const QByteArray &string_options);
|
||||
void Raise();
|
||||
void ShowVisualizations();
|
||||
|
||||
private:
|
||||
void SaveSettings();
|
||||
@@ -360,11 +359,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
|
||||
RadioViewContainer *radio_view_;
|
||||
|
||||
LastFMImportDialog *lastfm_import_dialog_;
|
||||
ArtistBioView *artistbio_view_;
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
ScopedPtr<VisualizationContainer> visualization_;
|
||||
#endif
|
||||
LastFMImportDialog *lastfm_import_dialog_;
|
||||
|
||||
QAction *collection_show_all_;
|
||||
QAction *collection_show_duplicates_;
|
||||
|
||||
@@ -517,7 +517,6 @@
|
||||
<addaction name="action_cover_manager"/>
|
||||
<addaction name="action_equalizer"/>
|
||||
<addaction name="action_transcoder"/>
|
||||
<addaction name="action_visualizations"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="action_update_collection"/>
|
||||
<addaction name="action_full_collection_scan"/>
|
||||
@@ -864,11 +863,6 @@
|
||||
<string>Import data from last.fm...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_visualizations">
|
||||
<property name="text">
|
||||
<string>Visualizations</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
#include "smartplaylists/playlistgenerator_fwd.h"
|
||||
|
||||
#include "radios/radiochannel.h"
|
||||
#include "widgets/collapsibleinfopane.h"
|
||||
|
||||
#ifdef HAVE_MTP
|
||||
# include "device/mtpconnection.h"
|
||||
@@ -147,6 +148,8 @@ void RegisterMetaTypes() {
|
||||
qRegisterMetaType<RadioChannel>("RadioChannel");
|
||||
qRegisterMetaType<RadioChannelList>("RadioChannelList");
|
||||
|
||||
qRegisterMetaType<CollapsibleInfoPane::Data>("CollapsibleInfoPane::Data");
|
||||
|
||||
#ifdef HAVE_MTP
|
||||
qRegisterMetaType<MtpConnection*>("MtpConnection*");
|
||||
#endif
|
||||
|
||||
@@ -36,7 +36,7 @@ class GstBufferConsumer {
|
||||
|
||||
// This is called in some unspecified GStreamer thread.
|
||||
// Ownership of the buffer is transferred to the BufferConsumer, and it should gst_buffer_unref it.
|
||||
virtual void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) = 0;
|
||||
virtual void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) = 0;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(GstBufferConsumer)
|
||||
|
||||
@@ -543,9 +543,7 @@ void GstEngine::ReloadSettings() {
|
||||
|
||||
}
|
||||
|
||||
void GstEngine::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) {
|
||||
|
||||
Q_UNUSED(channels);
|
||||
void GstEngine::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) {
|
||||
|
||||
// Schedule this to run in the GUI thread. The buffer gets added to the queue and unreffed by UpdateScope.
|
||||
if (!QMetaObject::invokeMethod(this, "AddBufferToScope", Q_ARG(GstBuffer*, buffer), Q_ARG(int, pipeline_id), Q_ARG(QString, format))) {
|
||||
|
||||
@@ -84,7 +84,7 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
bool ALSADeviceSupport(const QString &output) const override;
|
||||
bool ExclusiveModeSupport(const QString &output) const override;
|
||||
|
||||
void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) override;
|
||||
void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void ReloadSettings() override;
|
||||
|
||||
@@ -1385,7 +1385,7 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb
|
||||
|
||||
for (GstBufferConsumer *consumer : std::as_const(consumers)) {
|
||||
gst_buffer_ref(buf);
|
||||
consumer->ConsumeBuffer(buf, instance->id(), format, channels);
|
||||
consumer->ConsumeBuffer(buf, instance->id(), format);
|
||||
}
|
||||
|
||||
if (buf16) {
|
||||
|
||||
@@ -165,6 +165,7 @@ void BehaviourSettingsPage::Load() {
|
||||
|
||||
ui_->checkbox_resumeplayback->setChecked(s.value(kResumePlayback, false).toBool());
|
||||
ui_->checkbox_playingwidget->setChecked(s.value(kPlayingWidget, true).toBool());
|
||||
ui_->checkbox_artistbio->setChecked(s.value("artistbio", false).toBool());
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
const StartupBehaviour startup_behaviour = static_cast<StartupBehaviour>(s.value(kStartupBehaviour, static_cast<int>(StartupBehaviour::Remember)).toInt());
|
||||
@@ -232,9 +233,12 @@ void BehaviourSettingsPage::Save() {
|
||||
#if defined(HAVE_DBUS) && !defined(Q_OS_MACOS)
|
||||
s.setValue(kTaskbarProgress, ui_->checkbox_taskbar_progress->isChecked());
|
||||
#endif
|
||||
|
||||
s.setValue(kResumePlayback, ui_->checkbox_resumeplayback->isChecked());
|
||||
s.setValue(kPlayingWidget, ui_->checkbox_playingwidget->isChecked());
|
||||
|
||||
s.setValue("artistbio", ui_->checkbox_artistbio->isChecked());
|
||||
|
||||
StartupBehaviour startup_behaviour = StartupBehaviour::Remember;
|
||||
if (ui_->radiobutton_remember->isChecked()) startup_behaviour = StartupBehaviour::Remember;
|
||||
if (ui_->radiobutton_show->isChecked()) startup_behaviour = StartupBehaviour::Show;
|
||||
|
||||
@@ -65,6 +65,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkbox_artistbio">
|
||||
<property name="text">
|
||||
<string>Artist biography</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupbox_startup">
|
||||
<property name="title">
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
|
||||
#include "core/logging.h"
|
||||
|
||||
#include "projectmpresetmodel.h"
|
||||
#include "projectmvisualization.h"
|
||||
|
||||
ProjectMPresetModel::ProjectMPresetModel(ProjectMVisualization *projectm_visualization, QObject *parent)
|
||||
: QAbstractItemModel(parent),
|
||||
projectm_visualization_(projectm_visualization) {
|
||||
|
||||
// Find presets
|
||||
if (QFileInfo::exists(projectm_visualization_->preset_path())) {
|
||||
QDirIterator it(projectm_visualization_->preset_path(), QStringList() << QStringLiteral("*.milk") << QStringLiteral("*.prjm"), QDir::Files | QDir::NoDotAndDotDot | QDir::Readable, QDirIterator::Subdirectories);
|
||||
QStringList files;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
files << it.filePath();
|
||||
}
|
||||
std::stable_sort(files.begin(), files.end());
|
||||
for (const QString &filepath : std::as_const(files)) {
|
||||
const QFileInfo fileinfo(filepath);
|
||||
all_presets_ << Preset(fileinfo.filePath(), fileinfo.fileName(), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
qLog(Error) << "ProjectM preset path" << projectm_visualization_->preset_path() << "does not exist";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int ProjectMPresetModel::rowCount(const QModelIndex &idx) const {
|
||||
|
||||
Q_UNUSED(idx);
|
||||
|
||||
if (!projectm_visualization_) return 0;
|
||||
|
||||
return static_cast<int>(all_presets_.count());
|
||||
|
||||
}
|
||||
|
||||
int ProjectMPresetModel::columnCount(const QModelIndex &idx) const {
|
||||
Q_UNUSED(idx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
QModelIndex ProjectMPresetModel::index(const int row, const int column, const QModelIndex &idx) const {
|
||||
Q_UNUSED(idx);
|
||||
return createIndex(row, column);
|
||||
}
|
||||
|
||||
QModelIndex ProjectMPresetModel::parent(const QModelIndex &child) const {
|
||||
Q_UNUSED(child);
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QVariant ProjectMPresetModel::data(const QModelIndex &index, const int role) const {
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return all_presets_[index.row()].name_;
|
||||
case Qt::CheckStateRole:{
|
||||
bool selected = all_presets_[index.row()].selected_;
|
||||
return selected ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
case Role::Role_Path:
|
||||
return all_presets_[index.row()].path_;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Qt::ItemFlags ProjectMPresetModel::flags(const QModelIndex &idx) const {
|
||||
|
||||
if (!idx.isValid()) return QAbstractItemModel::flags(idx);
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
|
||||
|
||||
}
|
||||
|
||||
bool ProjectMPresetModel::setData(const QModelIndex &idx, const QVariant &value, int role) {
|
||||
|
||||
if (role == Qt::CheckStateRole) {
|
||||
all_presets_[idx.row()].selected_ = value.toBool();
|
||||
projectm_visualization_->SetSelected(QStringList() << all_presets_[idx.row()].path_, value.toBool());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::SetImmediatePreset(const QModelIndex &idx) {
|
||||
projectm_visualization_->SetImmediatePreset(all_presets_[idx.row()].path_);
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::SelectAll() {
|
||||
|
||||
QStringList paths;
|
||||
paths.reserve(all_presets_.count());
|
||||
for (int i = 0; i < all_presets_.count(); ++i) {
|
||||
paths << all_presets_[i].path_;
|
||||
all_presets_[i].selected_ = true;
|
||||
}
|
||||
projectm_visualization_->SetSelected(paths, true);
|
||||
|
||||
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
||||
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::SelectNone() {
|
||||
|
||||
projectm_visualization_->ClearSelected();
|
||||
for (int i = 0; i < all_presets_.count(); ++i) {
|
||||
all_presets_[i].selected_ = false;
|
||||
}
|
||||
|
||||
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
||||
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::MarkSelected(const QString &path, const bool selected) {
|
||||
|
||||
for (int i = 0; i < all_presets_.count(); ++i) {
|
||||
if (path == all_presets_[i].path_) {
|
||||
all_presets_[i].selected_ = selected;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROJECTMPRESETMODEL_H
|
||||
#define PROJECTMPRESETMODEL_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class ProjectMVisualization;
|
||||
|
||||
class ProjectMPresetModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
friend class ProjectMVisualization;
|
||||
|
||||
public:
|
||||
explicit ProjectMPresetModel(ProjectMVisualization *projectm_visualization, QObject *parent = nullptr);
|
||||
|
||||
enum Role {
|
||||
Role_Path = Qt::UserRole,
|
||||
};
|
||||
|
||||
void MarkSelected(const QString &path, bool selected);
|
||||
|
||||
// QAbstractItemModel
|
||||
QModelIndex index(const int row, const int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, const int role = Qt::DisplayRole) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, const int role = Qt::EditRole) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetImmediatePreset(const QModelIndex &index);
|
||||
void SelectAll();
|
||||
void SelectNone();
|
||||
|
||||
private:
|
||||
struct Preset {
|
||||
explicit Preset(const QString &path, const QString &name, const bool selected)
|
||||
: path_(path),
|
||||
name_(name),
|
||||
selected_(selected) {}
|
||||
|
||||
QString path_;
|
||||
QString name_;
|
||||
bool selected_;
|
||||
};
|
||||
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
QList<Preset> all_presets_;
|
||||
};
|
||||
|
||||
#endif // PROJECTMPRESETMODEL_H
|
||||
@@ -1,469 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
# include <projectM-4/types.h>
|
||||
# include <projectM-4/core.h>
|
||||
# include <projectM-4/parameters.h>
|
||||
# include <projectM-4/memory.h>
|
||||
# include <projectM-4/audio.h>
|
||||
# include <projectM-4/render_opengl.h>
|
||||
# include <projectM-4/playlist_types.h>
|
||||
# include <projectM-4/playlist_core.h>
|
||||
# include <projectM-4/playlist_memory.h>
|
||||
# include <projectM-4/playlist_items.h>
|
||||
# include <projectM-4/playlist_playback.h>
|
||||
#else
|
||||
# include <libprojectM/projectM.hpp>
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QGraphicsScene>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QScopeGuard>
|
||||
#include <QPainter>
|
||||
#include <QRandomGenerator>
|
||||
#include <QMessageBox>
|
||||
#include <QTimerEvent>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "projectmvisualization.h"
|
||||
#include "projectmpresetmodel.h"
|
||||
#include "visualizationcontainer.h"
|
||||
|
||||
ProjectMVisualization::ProjectMVisualization(VisualizationContainer *container)
|
||||
: QGraphicsScene(container),
|
||||
container_(container),
|
||||
preset_model_(nullptr),
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_instance_(nullptr),
|
||||
projectm_playlist_instance_(nullptr),
|
||||
#endif
|
||||
mode_(Mode::Random),
|
||||
duration_(15),
|
||||
texture_size_(512) {
|
||||
|
||||
QObject::connect(this, &QGraphicsScene::sceneRectChanged, this, &ProjectMVisualization::SceneRectChanged);
|
||||
|
||||
#ifndef HAVE_PROJECTM4
|
||||
for (int i = 0; i < TOTAL_RATING_TYPES; ++i) {
|
||||
default_rating_list_.push_back(3);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
ProjectMVisualization::~ProjectMVisualization() {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_playlist_instance_) {
|
||||
projectm_playlist_destroy(projectm_playlist_instance_);
|
||||
}
|
||||
if (projectm_instance_) {
|
||||
projectm_destroy(projectm_instance_);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Init() {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
return;
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
// Find the projectM presets
|
||||
|
||||
QStringList data_paths = QStringList() << QStringLiteral("/usr/share")
|
||||
<< QStringLiteral("/usr/local/share")
|
||||
<< QLatin1String(CMAKE_INSTALL_PREFIX) + QLatin1String("/share");
|
||||
|
||||
const QStringList xdg_data_dirs = QString::fromUtf8(qgetenv("XDG_DATA_DIRS")).split(QLatin1Char(':'));
|
||||
for (const QString &xdg_data_dir : xdg_data_dirs) {
|
||||
if (!data_paths.contains(xdg_data_dir)) {
|
||||
data_paths.append(xdg_data_dir);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
data_paths.prepend(QCoreApplication::applicationDirPath());
|
||||
#endif
|
||||
|
||||
const QStringList projectm_paths = QStringList() << QStringLiteral("projectM/presets")
|
||||
<< QStringLiteral("projectm-presets");
|
||||
|
||||
QStringList preset_paths;
|
||||
for (const QString &data_path : std::as_const(data_paths)) {
|
||||
for (const QString &projectm_path : projectm_paths) {
|
||||
const QString path = data_path + QLatin1Char('/') + projectm_path;
|
||||
if (!QFileInfo::exists(path) || QDir(path).entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot).isEmpty()) {
|
||||
preset_paths << path;
|
||||
continue;
|
||||
}
|
||||
preset_path_ = path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Create projectM settings
|
||||
#ifdef HAVE_PROJECTM4
|
||||
Q_ASSERT(projectm_instance_ == nullptr);
|
||||
Q_ASSERT(projectm_playlist_instance_ == nullptr);
|
||||
projectm_instance_ = projectm_create();
|
||||
projectm_set_preset_duration(projectm_instance_, duration_);
|
||||
projectm_set_mesh_size(projectm_instance_, 32, 24);
|
||||
projectm_set_fps(projectm_instance_, 35);
|
||||
projectm_set_window_size(projectm_instance_, 512, 512);
|
||||
projectm_playlist_instance_ = projectm_playlist_create(projectm_instance_);
|
||||
#else
|
||||
projectM::Settings s;
|
||||
s.presetURL = preset_path_.toStdString();
|
||||
s.meshX = 32;
|
||||
s.meshY = 24;
|
||||
s.textureSize = texture_size_;
|
||||
s.fps = 35;
|
||||
s.windowWidth = 512;
|
||||
s.windowHeight = 512;
|
||||
s.smoothPresetDuration = 5;
|
||||
s.presetDuration = duration_;
|
||||
s.shuffleEnabled = true;
|
||||
s.softCutRatingsEnabled = false;
|
||||
s.easterEgg = 0;
|
||||
projectm_ = std::make_unique<projectM>(s);
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
Q_ASSERT(preset_model_ == nullptr);
|
||||
preset_model_ = new ProjectMPresetModel(this, this);
|
||||
|
||||
Load();
|
||||
|
||||
// Start at a random preset.
|
||||
#ifdef HAVE_PROJECTM4
|
||||
const uint count = projectm_playlist_size(projectm_playlist_instance_);
|
||||
if (count > 0) {
|
||||
const uint position = QRandomGenerator::global()->bounded(count);
|
||||
projectm_playlist_set_position(projectm_playlist_instance_, position, true);
|
||||
}
|
||||
#else
|
||||
const uint count = projectm_->getPlaylistSize();
|
||||
if (count > 0) {
|
||||
const uint selection = QRandomGenerator::global()->bounded(count);
|
||||
projectm_->selectPreset(selection, true);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
if (preset_path_.isEmpty()) {
|
||||
qWarning("ProjectM presets could not be found, search path was:\n %s", preset_paths.join(QLatin1String("\n ")).toLocal8Bit().constData());
|
||||
QMessageBox::warning(nullptr, tr("Missing projectM presets"), tr("Strawberry could not load any projectM visualizations. Check that you have installed Strawberry properly."));
|
||||
}
|
||||
|
||||
Resize(sceneRect().width(), sceneRect().height(), container_->devicePixelRatio());
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::drawBackground(QPainter *p, const QRectF &rect) {
|
||||
|
||||
Q_UNUSED(rect);
|
||||
|
||||
p->beginNativePainting();
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_opengl_render_frame(projectm_instance_);
|
||||
#else
|
||||
projectm_->renderFrame();
|
||||
#endif
|
||||
|
||||
p->endNativePainting();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SceneRectChanged(const QRectF &rect) {
|
||||
|
||||
Resize(rect.width(), rect.height(), container_->devicePixelRatio());
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Resize(const qreal width, const qreal height, const qreal pixel_ratio) {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
projectm_set_window_size(projectm_instance_, static_cast<size_t>(width * pixel_ratio), static_cast<size_t>(height * pixel_ratio));
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->projectM_resetGL(static_cast<int>(width * pixel_ratio), static_cast<int>(height * pixel_ratio));
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetTextureSize(const int size) {
|
||||
|
||||
texture_size_ = size;
|
||||
|
||||
#ifndef HAVE_PROJECTM4
|
||||
if (projectm_) {
|
||||
projectm_->changeTextureSize(texture_size_);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetDuration(const int seconds) {
|
||||
|
||||
duration_ = seconds;
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
projectm_set_preset_duration(projectm_instance_, duration_);
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->changePresetDuration(duration_);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) {
|
||||
|
||||
Q_UNUSED(pipeline_id);
|
||||
Q_UNUSED(format);
|
||||
|
||||
GstMapInfo map;
|
||||
gst_buffer_map(buffer, &map, GST_MAP_READ);
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
const unsigned int samples_per_channel = (map.size / sizeof(int16_t)) / channels;
|
||||
const int16_t *data = reinterpret_cast<int16_t*>(map.data);
|
||||
projectm_pcm_add_int16(projectm_instance_, data, samples_per_channel, static_cast<projectm_channels>(channels));
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
const int16_t samples_per_channel = static_cast<int16_t>((map.size / sizeof(int16_t)) / channels);
|
||||
const int16_t *data = reinterpret_cast<int16_t*>(map.data);
|
||||
projectm_->pcm()->addPCM16Data(data, samples_per_channel);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
gst_buffer_unmap(buffer, &map);
|
||||
gst_buffer_unref(buffer);
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetSelected(const QStringList &paths, const bool selected) {
|
||||
|
||||
for (const QString &path : paths) {
|
||||
const int index = IndexOfPreset(path);
|
||||
if (selected && index == -1) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_add_preset(projectm_playlist_instance_, path.toUtf8().constData(), true);
|
||||
#else
|
||||
projectm_->addPresetURL(path.toStdString(), std::string(), default_rating_list_);
|
||||
#endif
|
||||
}
|
||||
else if (!selected && index != -1) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_remove_preset(projectm_playlist_instance_, index);
|
||||
#else
|
||||
projectm_->removePreset(index);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::ClearSelected() {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_clear(projectm_playlist_instance_);
|
||||
#else
|
||||
projectm_->clearPlaylist();
|
||||
#endif
|
||||
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
int ProjectMVisualization::IndexOfPreset(const QString &preset_path) const {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
const uint count = projectm_playlist_size(projectm_playlist_instance_);
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
char *projectm_preset_path = projectm_playlist_item(projectm_playlist_instance_, i);
|
||||
if (projectm_preset_path) {
|
||||
const QScopeGuard projectm_preset_path_deleter = qScopeGuard([projectm_preset_path](){ projectm_playlist_free_string(projectm_preset_path); });
|
||||
if (QLatin1String(projectm_preset_path) == preset_path) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
const uint count = projectm_->getPlaylistSize();
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
if (QString::fromStdString(projectm_->getPresetURL(i)) == preset_path) return static_cast<int>(i);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Load() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(QLatin1String(VisualizationContainer::kSettingsGroup));
|
||||
mode_ = Mode(s.value("mode", 0).toInt());
|
||||
duration_ = s.value("duration", duration_).toInt();
|
||||
s.endGroup();
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_set_preset_duration(projectm_instance_, duration_);
|
||||
projectm_playlist_clear(projectm_playlist_instance_);
|
||||
#else
|
||||
projectm_->changePresetDuration(duration_);
|
||||
projectm_->clearPlaylist();
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
switch (mode_) {
|
||||
case Mode::Random:{
|
||||
for (int i = 0; i < preset_model_->all_presets_.count(); ++i) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_add_preset(projectm_playlist_instance_, preset_model_->all_presets_[i].path_.toUtf8().constData(), false);
|
||||
#else
|
||||
projectm_->addPresetURL(preset_model_->all_presets_[i].path_.toStdString(), std::string(), default_rating_list_);
|
||||
#endif
|
||||
preset_model_->all_presets_[i].selected_ = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mode::FromList:{
|
||||
s.beginGroup(QLatin1String(VisualizationContainer::kSettingsGroup));
|
||||
const QStringList paths = s.value("preset_paths").toStringList();
|
||||
s.endGroup();
|
||||
for (const QString &path : paths) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_add_preset(projectm_playlist_instance_, path.toUtf8().constData(), true);
|
||||
#else
|
||||
projectm_->addPresetURL(path.toStdString(), std::string(), default_rating_list_);
|
||||
#endif
|
||||
preset_model_->MarkSelected(path, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Save() {
|
||||
|
||||
QStringList paths;
|
||||
|
||||
for (const ProjectMPresetModel::Preset &preset : std::as_const(preset_model_->all_presets_)) {
|
||||
if (preset.selected_) paths << preset.path_;
|
||||
}
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(VisualizationContainer::kSettingsGroup);
|
||||
s.setValue("preset_paths", paths);
|
||||
s.setValue("mode", static_cast<int>(mode_));
|
||||
s.setValue("duration", duration_);
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetMode(const Mode mode) {
|
||||
|
||||
mode_ = mode;
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
QString ProjectMVisualization::preset_path() const {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
return preset_path_;
|
||||
#else
|
||||
if (projectm_) {
|
||||
return QString::fromStdString(projectm_->settings().presetURL);
|
||||
}
|
||||
return QString();
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetImmediatePreset(const int index) {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_playlist_instance_) {
|
||||
projectm_playlist_set_position(projectm_playlist_instance_, index, true);
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->selectPreset(index, true);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetImmediatePreset(const QString &path) {
|
||||
|
||||
const int index = IndexOfPreset(path);
|
||||
if (index != -1) {
|
||||
SetImmediatePreset(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Lock(const bool lock) {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
projectm_set_preset_locked(projectm_instance_, lock);
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->setPresetLock(lock);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
if (!lock) Load();
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROJECTMVISUALIZATION_H
|
||||
#define PROJECTMVISUALIZATION_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
# include <projectM-4/types.h>
|
||||
# include <projectM-4/playlist_types.h>
|
||||
#else
|
||||
# include <libprojectM/projectM.hpp>
|
||||
#endif
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include "engine/gstbufferconsumer.h"
|
||||
|
||||
class projectM;
|
||||
class QPainter;
|
||||
class ProjectMPresetModel;
|
||||
class VisualizationContainer;
|
||||
|
||||
class ProjectMVisualization : public QGraphicsScene, public GstBufferConsumer {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProjectMVisualization(VisualizationContainer *container);
|
||||
~ProjectMVisualization();
|
||||
|
||||
enum class Mode {
|
||||
Random = 0,
|
||||
FromList = 1,
|
||||
};
|
||||
|
||||
QString preset_path() const;
|
||||
ProjectMPresetModel *preset_model() const { return preset_model_; }
|
||||
|
||||
Mode mode() const { return mode_; }
|
||||
int duration() const { return duration_; }
|
||||
|
||||
void Init();
|
||||
|
||||
// BufferConsumer
|
||||
void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetTextureSize(const int size);
|
||||
void SetDuration(const int seconds);
|
||||
|
||||
void SetSelected(const QStringList &paths, const bool selected);
|
||||
void ClearSelected();
|
||||
void SetImmediatePreset(const int index);
|
||||
void SetImmediatePreset(const QString &path);
|
||||
void SetMode(const Mode mode);
|
||||
|
||||
void Lock(const bool lock);
|
||||
|
||||
protected:
|
||||
// QGraphicsScene
|
||||
void drawBackground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void SceneRectChanged(const QRectF &rect);
|
||||
|
||||
private:
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
int IndexOfPreset(const QString &preset_path) const;
|
||||
|
||||
void Resize(const qreal width, const qreal height, const qreal pixel_ratio);
|
||||
|
||||
private:
|
||||
VisualizationContainer *container_;
|
||||
ProjectMPresetModel *preset_model_;
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_handle projectm_instance_;
|
||||
projectm_playlist_handle projectm_playlist_instance_;
|
||||
#else
|
||||
std::unique_ptr<projectM> projectm_;
|
||||
#endif
|
||||
Mode mode_;
|
||||
int duration_;
|
||||
std::vector<int> default_rating_list_;
|
||||
int texture_size_;
|
||||
QString preset_path_;
|
||||
};
|
||||
|
||||
#endif // PROJECTMVISUALIZATION_H
|
||||
@@ -1,328 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <QOpenGLWidget>
|
||||
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
#include <QActionGroup>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/settings.h"
|
||||
#include "engine/gstengine.h"
|
||||
#include "visualizationcontainer.h"
|
||||
#include "visualizationopenglwidget.h"
|
||||
#include "visualizationoverlay.h"
|
||||
#include "visualizationselector.h"
|
||||
#include "projectmvisualization.h"
|
||||
|
||||
const char *VisualizationContainer::kSettingsGroup = "Visualizations";
|
||||
|
||||
namespace {
|
||||
constexpr int kLowFramerate = 15;
|
||||
constexpr int kMediumFramerate = 25;
|
||||
constexpr int kHighFramerate = 35;
|
||||
constexpr int kSuperHighFramerate = 60;
|
||||
|
||||
constexpr int kDefaultWidth = 828;
|
||||
constexpr int kDefaultHeight = 512;
|
||||
constexpr int kDefaultFps = kHighFramerate;
|
||||
constexpr int kDefaultTextureSize = 512;
|
||||
} // namespace
|
||||
|
||||
VisualizationContainer::VisualizationContainer(QWidget *parent)
|
||||
: QGraphicsView(parent),
|
||||
projectm_visualization_(new ProjectMVisualization(this)),
|
||||
overlay_(new VisualizationOverlay),
|
||||
selector_(new VisualizationSelector(this)),
|
||||
overlay_proxy_(nullptr),
|
||||
engine_(nullptr),
|
||||
menu_(new QMenu(this)),
|
||||
fps_(kDefaultFps),
|
||||
size_(kDefaultTextureSize) {
|
||||
|
||||
setWindowTitle(tr("Visualizations"));
|
||||
setWindowIcon(IconLoader::Load(QStringLiteral("strawberry")));
|
||||
setMinimumSize(64, 64);
|
||||
|
||||
{
|
||||
Settings s;
|
||||
s.beginGroup(QLatin1String(kSettingsGroup));
|
||||
if (!restoreGeometry(s.value("geometry").toByteArray())) {
|
||||
resize(kDefaultWidth, kDefaultHeight);
|
||||
}
|
||||
fps_ = s.value("fps", kDefaultFps).toInt();
|
||||
size_ = s.value("size", kDefaultTextureSize).toInt();
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
QShortcut *close = new QShortcut(QKeySequence::Close, this);
|
||||
QObject::connect(close, &QShortcut::activated, this, &VisualizationContainer::close);
|
||||
|
||||
// Set up the graphics view
|
||||
setScene(projectm_visualization_);
|
||||
setViewport(new VisualizationOpenGLWidget(projectm_visualization_));
|
||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
// Add the overlay
|
||||
overlay_proxy_ = scene()->addWidget(overlay_);
|
||||
QObject::connect(overlay_, &VisualizationOverlay::OpacityChanged, this, &VisualizationContainer::ChangeOverlayOpacity);
|
||||
QObject::connect(overlay_, &VisualizationOverlay::ShowPopupMenu, this, &VisualizationContainer::ShowPopupMenu);
|
||||
ChangeOverlayOpacity(0.0);
|
||||
|
||||
projectm_visualization_->SetTextureSize(size_);
|
||||
SizeChanged();
|
||||
|
||||
// Selector
|
||||
selector_->SetVisualization(projectm_visualization_);
|
||||
|
||||
// Settings menu
|
||||
menu_->addAction(IconLoader::Load(QStringLiteral("view-fullscreen")), tr("Toggle fullscreen"), this, &VisualizationContainer::ToggleFullscreen);
|
||||
|
||||
QMenu *fps_menu = menu_->addMenu(tr("Framerate"));
|
||||
QActionGroup *fps_group = new QActionGroup(this);
|
||||
AddFramerateMenuItem(tr("Low (%1 fps)").arg(kLowFramerate), kLowFramerate, fps_, fps_group);
|
||||
AddFramerateMenuItem(tr("Medium (%1 fps)").arg(kMediumFramerate), kMediumFramerate, fps_, fps_group);
|
||||
AddFramerateMenuItem(tr("High (%1 fps)").arg(kHighFramerate), kHighFramerate, fps_, fps_group);
|
||||
AddFramerateMenuItem(tr("Super high (%1 fps)").arg(kSuperHighFramerate), kSuperHighFramerate, fps_, fps_group);
|
||||
fps_menu->addActions(fps_group->actions());
|
||||
|
||||
QMenu *quality_menu = menu_->addMenu(tr("Quality", "Visualization quality"));
|
||||
QActionGroup *quality_group = new QActionGroup(this);
|
||||
AddQualityMenuItem(tr("Low (256x256)"), 256, size_, quality_group);
|
||||
AddQualityMenuItem(tr("Medium (512x512)"), 512, size_, quality_group);
|
||||
AddQualityMenuItem(tr("High (1024x1024)"), 1024, size_, quality_group);
|
||||
AddQualityMenuItem(tr("Super high (2048x2048)"), 2048, size_, quality_group);
|
||||
quality_menu->addActions(quality_group->actions());
|
||||
|
||||
menu_->addAction(tr("Select visualizations..."), selector_, &VisualizationContainer::show);
|
||||
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(IconLoader::Load(QStringLiteral("application-exit")), tr("Close visualization"), this, &VisualizationContainer::hide);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::AddFramerateMenuItem(const QString &name, const int value, const int def, QActionGroup *group) {
|
||||
|
||||
QAction *action = group->addAction(name);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(value == def);
|
||||
QObject::connect(action, &QAction::triggered, this, [this, value]() { SetFps(value); });
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::AddQualityMenuItem(const QString &name, const int value, const int def, QActionGroup *group) {
|
||||
|
||||
QAction *action = group->addAction(name);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(value == def);
|
||||
QObject::connect(action, &QAction::triggered, this, [this, value]() { SetQuality(value); });
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetEngine(GstEngine *engine) {
|
||||
|
||||
engine_ = engine;
|
||||
|
||||
if (isVisible()) engine_->AddBufferConsumer(projectm_visualization_);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::showEvent(QShowEvent *e) {
|
||||
|
||||
qLog(Debug) << "Showing visualization";
|
||||
|
||||
QGraphicsView::showEvent(e);
|
||||
|
||||
update_timer_.start(1000 / fps_, this);
|
||||
|
||||
if (engine_) engine_->AddBufferConsumer(projectm_visualization_);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::hideEvent(QHideEvent *e) {
|
||||
|
||||
qLog(Debug) << "Hiding visualization";
|
||||
|
||||
QGraphicsView::hideEvent(e);
|
||||
|
||||
update_timer_.stop();
|
||||
|
||||
if (engine_) engine_->RemoveBufferConsumer(projectm_visualization_);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::closeEvent(QCloseEvent *e) {
|
||||
|
||||
Q_UNUSED(e);
|
||||
|
||||
// Don't close the window. Just hide it.
|
||||
e->ignore();
|
||||
hide();
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::resizeEvent(QResizeEvent *e) {
|
||||
QGraphicsView::resizeEvent(e);
|
||||
SizeChanged();
|
||||
}
|
||||
|
||||
void VisualizationContainer::SizeChanged() {
|
||||
|
||||
// Save the geometry
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("geometry", saveGeometry());
|
||||
|
||||
// Resize the scene
|
||||
if (scene()) scene()->setSceneRect(QRect(QPoint(0, 0), size()));
|
||||
|
||||
// Resize the overlay
|
||||
if (overlay_) overlay_->resize(size());
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::timerEvent(QTimerEvent *e) {
|
||||
|
||||
QGraphicsView::timerEvent(e);
|
||||
if (e->timerId() == update_timer_.timerId()) scene()->update();
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next) {
|
||||
overlay_->SetActions(previous, play_pause, stop, next);
|
||||
}
|
||||
|
||||
void VisualizationContainer::SongMetadataChanged(const Song &metadata) {
|
||||
overlay_->SetSongTitle(QStringLiteral("%1 - %2").arg(metadata.artist(), metadata.title()));
|
||||
}
|
||||
|
||||
void VisualizationContainer::Stopped() {
|
||||
overlay_->SetSongTitle(tr("strawberry"));
|
||||
}
|
||||
|
||||
void VisualizationContainer::ChangeOverlayOpacity(const qreal value) {
|
||||
|
||||
overlay_proxy_->setOpacity(value);
|
||||
|
||||
// Hide the cursor if the overlay is hidden
|
||||
if (value < 0.5) {
|
||||
viewport()->setCursor(Qt::BlankCursor);
|
||||
}
|
||||
else {
|
||||
viewport()->unsetCursor();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::enterEvent(QEnterEvent *e) {
|
||||
|
||||
QGraphicsView::enterEvent(e);
|
||||
|
||||
overlay_->SetVisible(true);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::leaveEvent(QEvent *e) {
|
||||
QGraphicsView::leaveEvent(e);
|
||||
overlay_->SetVisible(false);
|
||||
}
|
||||
|
||||
void VisualizationContainer::mouseMoveEvent(QMouseEvent *e) {
|
||||
QGraphicsView::mouseMoveEvent(e);
|
||||
overlay_->SetVisible(true);
|
||||
}
|
||||
|
||||
void VisualizationContainer::mouseDoubleClickEvent(QMouseEvent *e) {
|
||||
QGraphicsView::mouseDoubleClickEvent(e);
|
||||
ToggleFullscreen();
|
||||
}
|
||||
|
||||
void VisualizationContainer::contextMenuEvent(QContextMenuEvent *event) {
|
||||
QGraphicsView::contextMenuEvent(event);
|
||||
ShowPopupMenu(event->pos());
|
||||
}
|
||||
|
||||
void VisualizationContainer::keyReleaseEvent(QKeyEvent *event) {
|
||||
|
||||
if (event->matches(QKeySequence::Close) || event->key() == Qt::Key_Escape) {
|
||||
if (isFullScreen()) {
|
||||
ToggleFullscreen();
|
||||
}
|
||||
else {
|
||||
hide();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView::keyReleaseEvent(event);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::ToggleFullscreen() {
|
||||
|
||||
setWindowState(windowState() ^ Qt::WindowFullScreen);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetFps(const int fps) {
|
||||
|
||||
fps_ = fps;
|
||||
|
||||
// Save settings
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("fps", fps_);
|
||||
|
||||
update_timer_.stop();
|
||||
update_timer_.start(1000 / fps_, this);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::ShowPopupMenu(const QPoint &pos) {
|
||||
menu_->popup(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetQuality(const int size) {
|
||||
|
||||
size_ = size;
|
||||
|
||||
// Save settings
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("size", size_);
|
||||
|
||||
projectm_visualization_->SetTextureSize(size_);
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONCONTAINER_H
|
||||
#define VISUALIZATIONCONTAINER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QBasicTimer>
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
class GstEngine;
|
||||
class ProjectMVisualization;
|
||||
class VisualizationOverlay;
|
||||
class VisualizationSelector;
|
||||
|
||||
class QMenu;
|
||||
class QActionGroup;
|
||||
class QEvent;
|
||||
class QShowEvent;
|
||||
class QHideEvent;
|
||||
class QCloseEvent;
|
||||
class QResizeEvent;
|
||||
class QTimerEvent;
|
||||
class QMouseEvent;
|
||||
class QContextMenuEvent;
|
||||
class QKeyEvent;
|
||||
class QEnterEvent;
|
||||
|
||||
class VisualizationContainer : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationContainer(QWidget *parent = nullptr);
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
void SetEngine(GstEngine *engine);
|
||||
void SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next);
|
||||
|
||||
public Q_SLOTS:
|
||||
void SongMetadataChanged(const Song &metadata);
|
||||
void Stopped();
|
||||
|
||||
protected:
|
||||
// QWidget
|
||||
void showEvent(QShowEvent *e) override;
|
||||
void hideEvent(QHideEvent *e) override;
|
||||
void closeEvent(QCloseEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void timerEvent(QTimerEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void enterEvent(QEnterEvent *e) override;
|
||||
void leaveEvent(QEvent *e) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
void keyReleaseEvent(QKeyEvent *event) override;
|
||||
|
||||
private:
|
||||
void SizeChanged();
|
||||
void AddFramerateMenuItem(const QString &name, int value, int def, QActionGroup *group);
|
||||
void AddQualityMenuItem(const QString &name, int value, int def, QActionGroup *group);
|
||||
|
||||
private Q_SLOTS:
|
||||
void ChangeOverlayOpacity(qreal value);
|
||||
void ShowPopupMenu(const QPoint &pos);
|
||||
void ToggleFullscreen();
|
||||
void SetFps(const int fps);
|
||||
void SetQuality(const int size);
|
||||
|
||||
private:
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
VisualizationOverlay *overlay_;
|
||||
VisualizationSelector *selector_;
|
||||
QGraphicsProxyWidget *overlay_proxy_;
|
||||
GstEngine *engine_;
|
||||
QMenu *menu_;
|
||||
QBasicTimer update_timer_;
|
||||
int fps_;
|
||||
int size_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONCONTAINER_H
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QBasicTimer>
|
||||
#include <QTimeLine>
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QTimerEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "core/iconloader.h"
|
||||
#include "visualizationoverlay.h"
|
||||
#include "ui_visualizationoverlay.h"
|
||||
|
||||
namespace {
|
||||
constexpr int kFadeDuration = 500;
|
||||
constexpr int kFadeTimeout = 5000;
|
||||
}
|
||||
|
||||
VisualizationOverlay::VisualizationOverlay(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
ui_(new Ui_VisualizationOverlay),
|
||||
fade_timeline_(new QTimeLine(kFadeDuration, this)),
|
||||
visible_(false) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setMouseTracking(true);
|
||||
|
||||
ui_->settings->setIcon(IconLoader::Load(QStringLiteral("configure")));
|
||||
|
||||
QObject::connect(ui_->settings, &QToolButton::clicked, this, &VisualizationOverlay::ShowSettingsMenu);
|
||||
QObject::connect(fade_timeline_, &QTimeLine::valueChanged, this, &VisualizationOverlay::OpacityChanged);
|
||||
|
||||
}
|
||||
|
||||
VisualizationOverlay::~VisualizationOverlay() { delete ui_; }
|
||||
|
||||
QGraphicsProxyWidget *VisualizationOverlay::title(QGraphicsProxyWidget *proxy) const {
|
||||
return proxy->createProxyForChildWidget(ui_->song_title);
|
||||
}
|
||||
|
||||
void VisualizationOverlay::SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next) {
|
||||
|
||||
ui_->previous->setDefaultAction(previous);
|
||||
ui_->play_pause->setDefaultAction(play_pause);
|
||||
ui_->stop->setDefaultAction(stop);
|
||||
ui_->next->setDefaultAction(next);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::ShowSettingsMenu() {
|
||||
|
||||
Q_EMIT ShowPopupMenu(ui_->settings->mapToGlobal(ui_->settings->rect().bottomLeft()));
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::timerEvent(QTimerEvent *e) {
|
||||
|
||||
QWidget::timerEvent(e);
|
||||
|
||||
if (e->timerId() == fade_out_timeout_.timerId()) {
|
||||
SetVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::SetVisible(const bool visible) {
|
||||
|
||||
// If we're showing the overlay, then fade out again in a little while
|
||||
fade_out_timeout_.stop();
|
||||
if (visible) fade_out_timeout_.start(kFadeTimeout, this);
|
||||
|
||||
// Don't change to the state we're in already
|
||||
if (visible == visible_) return;
|
||||
visible_ = visible;
|
||||
|
||||
// If there's already another fader running then start from the same time that one was already at.
|
||||
int start_time = visible ? 0 : fade_timeline_->duration();
|
||||
if (fade_timeline_->state() == QTimeLine::Running)
|
||||
start_time = fade_timeline_->currentTime();
|
||||
|
||||
fade_timeline_->stop();
|
||||
fade_timeline_->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward);
|
||||
fade_timeline_->setCurrentTime(start_time);
|
||||
fade_timeline_->resume();
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::SetSongTitle(const QString &title) {
|
||||
|
||||
ui_->song_title->setText(title);
|
||||
SetVisible(true);
|
||||
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VisualizationOverlay</class>
|
||||
<widget class="QWidget" name="VisualizationOverlay">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>523</width>
|
||||
<height>302</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">VisualizationOverlay {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#frame {
|
||||
background-color: rgba(96, 59, 25, 70%);
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
border-color: rgba(145, 89, 38, 100%);
|
||||
border-width: 4px 4px 0px 4px;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
#song_title {
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
color: #feae65;
|
||||
}
|
||||
|
||||
QToolButton {
|
||||
background: transparent;
|
||||
border: none;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>210</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="song_title">
|
||||
<property name="text">
|
||||
<string>Strawberry</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="previous">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="play_pause">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="stop">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="next">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>13</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="settings">
|
||||
<property name="toolTip">
|
||||
<string>Visualizations Settings</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "visualizationselector.h"
|
||||
#include "projectmpresetmodel.h"
|
||||
#include "projectmvisualization.h"
|
||||
#include "ui_visualizationselector.h"
|
||||
|
||||
VisualizationSelector::VisualizationSelector(QWidget *parent)
|
||||
: QDialog(parent),
|
||||
ui_(new Ui_VisualizationSelector),
|
||||
projectm_visualization_(nullptr),
|
||||
select_all_(nullptr),
|
||||
select_none_(nullptr) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
select_all_ = ui_->buttonBox->addButton(tr("Select All"), QDialogButtonBox::ActionRole);
|
||||
select_none_ = ui_->buttonBox->addButton(tr("Select None"), QDialogButtonBox::ActionRole);
|
||||
QObject::connect(select_all_, &QPushButton::clicked, this, &VisualizationSelector::SelectAll);
|
||||
QObject::connect(select_none_, &QPushButton::clicked, this, &VisualizationSelector::SelectNone);
|
||||
select_all_->setEnabled(false);
|
||||
select_none_->setEnabled(false);
|
||||
|
||||
QObject::connect(ui_->mode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &VisualizationSelector::ModeChanged);
|
||||
|
||||
}
|
||||
|
||||
VisualizationSelector::~VisualizationSelector() { delete ui_; }
|
||||
|
||||
void VisualizationSelector::showEvent(QShowEvent *e) {
|
||||
|
||||
Q_UNUSED(e);
|
||||
|
||||
if (!ui_->list->model()) {
|
||||
ui_->delay->setValue(projectm_visualization_->duration());
|
||||
ui_->list->setModel(projectm_visualization_->preset_model());
|
||||
QObject::connect(ui_->list->selectionModel(), &QItemSelectionModel::currentChanged, projectm_visualization_->preset_model(), &ProjectMPresetModel::SetImmediatePreset);
|
||||
QObject::connect(ui_->delay, QOverload<int>::of(&QSpinBox::valueChanged), projectm_visualization_, &ProjectMVisualization::SetDuration);
|
||||
|
||||
ui_->mode->setCurrentIndex(static_cast<int>(projectm_visualization_->mode()));
|
||||
}
|
||||
|
||||
projectm_visualization_->Lock(true);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationSelector::hideEvent(QHideEvent *e) {
|
||||
Q_UNUSED(e);
|
||||
projectm_visualization_->Lock(false);
|
||||
}
|
||||
|
||||
void VisualizationSelector::ModeChanged(const int mode) {
|
||||
|
||||
const bool enabled = mode == 1;
|
||||
ui_->list->setEnabled(enabled);
|
||||
select_all_->setEnabled(enabled);
|
||||
select_none_->setEnabled(enabled);
|
||||
|
||||
projectm_visualization_->SetMode(static_cast<ProjectMVisualization::Mode>(mode));
|
||||
|
||||
}
|
||||
|
||||
void VisualizationSelector::SelectAll() { projectm_visualization_->preset_model()->SelectAll(); }
|
||||
|
||||
void VisualizationSelector::SelectNone() { projectm_visualization_->preset_model()->SelectNone(); }
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONSELECTOR_H
|
||||
#define VISUALIZATIONSELECTOR_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QPushButton;
|
||||
class QShowEvent;
|
||||
class QHideEvent;
|
||||
|
||||
class ProjectMVisualization;
|
||||
class Ui_VisualizationSelector;
|
||||
|
||||
class VisualizationSelector : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationSelector(QWidget *parent = nullptr);
|
||||
~VisualizationSelector();
|
||||
|
||||
void SetVisualization(ProjectMVisualization *projectm_visualization) { projectm_visualization_ = projectm_visualization; }
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
void hideEvent(QHideEvent *e) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void ModeChanged(const int mode);
|
||||
void SelectAll();
|
||||
void SelectNone();
|
||||
|
||||
private:
|
||||
Ui_VisualizationSelector *ui_;
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
QPushButton *select_all_;
|
||||
QPushButton *select_none_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONSELECTOR_H
|
||||
@@ -1,140 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VisualizationSelector</class>
|
||||
<widget class="QDialog" name="VisualizationSelector">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>595</width>
|
||||
<height>475</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Select visualizations</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../data/data.qrc">
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Visualization mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="mode">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Random visualization</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Choose from the list</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Delay between visualizations</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="delay">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>120</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>15</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="list">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>mode</tabstop>
|
||||
<tabstop>delay</tabstop>
|
||||
<tabstop>list</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../data/data.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>VisualizationSelector</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>VisualizationSelector</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
174
src/widgets/collapsibleinfoheader.cpp
Normal file
174
src/widgets/collapsibleinfoheader.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QWidget>
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
#include <QColor>
|
||||
#include <QStyle>
|
||||
#include <QFont>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QStyleOption>
|
||||
#include <QEnterEvent>
|
||||
#include <QPaintEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QEvent>
|
||||
|
||||
#include "collapsibleinfoheader.h"
|
||||
|
||||
const int CollapsibleInfoHeader::kHeight = 20;
|
||||
const int CollapsibleInfoHeader::kIconSize = 16;
|
||||
|
||||
CollapsibleInfoHeader::CollapsibleInfoHeader(QWidget* parent)
|
||||
: QWidget(parent),
|
||||
expanded_(false),
|
||||
hovering_(false),
|
||||
animation_(new QPropertyAnimation(this, "opacity", this)),
|
||||
opacity_(0.0) {
|
||||
|
||||
setMinimumHeight(kHeight);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
setCursor(QCursor(Qt::PointingHandCursor));
|
||||
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::SetTitle(const QString &title) {
|
||||
title_ = title;
|
||||
update();
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::SetIcon(const QIcon &icon) {
|
||||
icon_ = icon;
|
||||
update();
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::SetExpanded(const bool expanded) {
|
||||
|
||||
expanded_ = expanded;
|
||||
|
||||
emit ExpandedToggled(expanded);
|
||||
if (expanded)
|
||||
emit Expanded();
|
||||
else
|
||||
emit Collapsed();
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void CollapsibleInfoHeader::enterEvent(QEnterEvent*) {
|
||||
#else
|
||||
void CollapsibleInfoHeader::enterEvent(QEvent*) {
|
||||
#endif
|
||||
|
||||
hovering_ = true;
|
||||
if (!expanded_) {
|
||||
animation_->stop();
|
||||
animation_->setEndValue(1.0);
|
||||
animation_->setDuration(80);
|
||||
animation_->start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::leaveEvent(QEvent*) {
|
||||
|
||||
hovering_ = false;
|
||||
if (!expanded_) {
|
||||
animation_->stop();
|
||||
animation_->setEndValue(0.0);
|
||||
animation_->setDuration(160);
|
||||
animation_->start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::set_opacity(const float opacity) {
|
||||
opacity_ = opacity;
|
||||
update();
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::paintEvent(QPaintEvent*) {
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
QColor active_text_color(palette().color(QPalette::Active, QPalette::HighlightedText));
|
||||
QColor inactive_text_color(palette().color(QPalette::Active, QPalette::Text));
|
||||
QColor text_color;
|
||||
if (expanded_) {
|
||||
text_color = active_text_color;
|
||||
}
|
||||
else {
|
||||
p.setOpacity(0.4 + opacity_ * 0.6);
|
||||
text_color = QColor(active_text_color.red() * opacity_ + inactive_text_color.red() * (1.0 - opacity_), active_text_color.green() * opacity_ + inactive_text_color.green() * (1.0 - opacity_), active_text_color.blue() * opacity_ + inactive_text_color.blue() * (1.0 - opacity_));
|
||||
}
|
||||
|
||||
QRect indicator_rect(0, 0, height(), height());
|
||||
QRect icon_rect(height() + 2, (kHeight - kIconSize) / 2, kIconSize, kIconSize);
|
||||
QRect text_rect(rect());
|
||||
text_rect.setLeft(icon_rect.right() + 4);
|
||||
|
||||
// Draw the background
|
||||
QColor highlight(palette().color(QPalette::Active, QPalette::Highlight));
|
||||
const QColor bg_color_1(highlight.lighter(120));
|
||||
const QColor bg_color_2(highlight.darker(120));
|
||||
const QColor bg_border(palette().color(QPalette::Dark));
|
||||
QLinearGradient bg_brush(rect().topLeft(), rect().bottomLeft());
|
||||
bg_brush.setColorAt(0.0, bg_color_1);
|
||||
bg_brush.setColorAt(0.5, bg_color_1);
|
||||
bg_brush.setColorAt(0.5, bg_color_2);
|
||||
bg_brush.setColorAt(1.0, bg_color_2);
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
p.fillRect(rect(), bg_brush);
|
||||
|
||||
p.setPen(bg_border);
|
||||
p.drawLine(rect().topLeft(), rect().topRight());
|
||||
p.drawLine(rect().bottomLeft(), rect().bottomRight());
|
||||
|
||||
// Draw the expand/collapse indicator
|
||||
QStyleOption opt;
|
||||
opt.initFrom(this);
|
||||
opt.rect = indicator_rect;
|
||||
opt.state |= QStyle::State_Children;
|
||||
if (expanded_) opt.state |= QStyle::State_Open;
|
||||
if (hovering_) opt.state |= QStyle::State_Active;
|
||||
|
||||
// Have to use the application's style here because using the widget's style
|
||||
// will trigger QStyleSheetStyle's recursion guard (I don't know why).
|
||||
QApplication::style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, &p, this);
|
||||
|
||||
// Draw the icon
|
||||
p.drawPixmap(icon_rect, icon_.pixmap(kIconSize));
|
||||
|
||||
// Draw the title text
|
||||
QFont bold_font(font());
|
||||
bold_font.setBold(true);
|
||||
p.setFont(bold_font);
|
||||
|
||||
p.setPen(text_color);
|
||||
p.drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, title_);
|
||||
|
||||
}
|
||||
|
||||
void CollapsibleInfoHeader::mouseReleaseEvent(QMouseEvent*) {
|
||||
SetExpanded(!expanded_);
|
||||
}
|
||||
82
src/widgets/collapsibleinfoheader.h
Normal file
82
src/widgets/collapsibleinfoheader.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COLLAPSIBLEINFOHEADER_H
|
||||
#define COLLAPSIBLEINFOHEADER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
|
||||
class QPropertyAnimation;
|
||||
class QEnterEvent;
|
||||
class QEvent;
|
||||
class QPaintEvent;
|
||||
class QMouseEvent;
|
||||
|
||||
class CollapsibleInfoHeader : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float opacity READ opacity WRITE set_opacity)
|
||||
|
||||
public:
|
||||
CollapsibleInfoHeader(QWidget *parent = nullptr);
|
||||
|
||||
static const int kHeight;
|
||||
static const int kIconSize;
|
||||
|
||||
bool expanded() const { return expanded_; }
|
||||
bool hovering() const { return hovering_; }
|
||||
const QString &title() const { return title_; }
|
||||
const QIcon &icon() const { return icon_; }
|
||||
|
||||
float opacity() const { return opacity_; }
|
||||
void set_opacity(const float opacity);
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetExpanded(const bool expanded);
|
||||
void SetTitle(const QString &title);
|
||||
void SetIcon(const QIcon &icon);
|
||||
|
||||
Q_SIGNALS:
|
||||
void Expanded();
|
||||
void Collapsed();
|
||||
void ExpandedToggled(const bool expanded);
|
||||
|
||||
protected:
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void enterEvent(QEnterEvent*) override;
|
||||
#else
|
||||
void enterEvent(QEvent*) override;
|
||||
#endif
|
||||
void leaveEvent(QEvent*) override;
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
|
||||
private:
|
||||
bool expanded_;
|
||||
bool hovering_;
|
||||
QString title_;
|
||||
QIcon icon_;
|
||||
|
||||
QPropertyAnimation *animation_;
|
||||
float opacity_;
|
||||
};
|
||||
|
||||
#endif // COLLAPSIBLEINFOHEADER_H
|
||||
64
src/widgets/collapsibleinfopane.cpp
Normal file
64
src/widgets/collapsibleinfopane.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "collapsibleinfoheader.h"
|
||||
#include "collapsibleinfopane.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
CollapsibleInfoPane::CollapsibleInfoPane(const Data &data, QWidget *parent)
|
||||
: QWidget(parent), data_(data), header_(new CollapsibleInfoHeader(this)) {
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(3);
|
||||
layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
setLayout(layout);
|
||||
|
||||
layout->addWidget(header_);
|
||||
layout->addWidget(data.contents_);
|
||||
data.contents_->hide();
|
||||
|
||||
header_->SetTitle(data.title_);
|
||||
header_->SetIcon(data.icon_);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
|
||||
connect(header_, SIGNAL(ExpandedToggled(bool)), SLOT(ExpandedToggled(bool)));
|
||||
connect(header_, SIGNAL(ExpandedToggled(bool)), SIGNAL(Toggled(bool)));
|
||||
|
||||
}
|
||||
|
||||
void CollapsibleInfoPane::Collapse() { header_->SetExpanded(false); }
|
||||
|
||||
void CollapsibleInfoPane::Expand() { header_->SetExpanded(true); }
|
||||
|
||||
void CollapsibleInfoPane::ExpandedToggled(bool expanded) {
|
||||
data_.contents_->setVisible(expanded);
|
||||
}
|
||||
|
||||
bool CollapsibleInfoPane::Data::operator<(const CollapsibleInfoPane::Data &other) const {
|
||||
|
||||
const int my_score = (TypeCount - type_) * 1000 + relevance_;
|
||||
const int other_score = (TypeCount - other.type_) * 1000 + other.relevance_;
|
||||
|
||||
return my_score > other_score;
|
||||
|
||||
}
|
||||
72
src/widgets/collapsibleinfopane.h
Normal file
72
src/widgets/collapsibleinfopane.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COLLAPSIBLEINFOPANE_H
|
||||
#define COLLAPSIBLEINFOPANE_H
|
||||
|
||||
#include <QIcon>
|
||||
#include <QWidget>
|
||||
|
||||
class CollapsibleInfoHeader;
|
||||
|
||||
class CollapsibleInfoPane : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct Data {
|
||||
explicit Data() : type_(Type_Biography), relevance_(0) {}
|
||||
|
||||
bool operator<(const Data& other) const;
|
||||
|
||||
enum Type {
|
||||
Type_Biography,
|
||||
TypeCount
|
||||
};
|
||||
|
||||
QString id_;
|
||||
QString title_;
|
||||
QIcon icon_;
|
||||
Type type_;
|
||||
int relevance_;
|
||||
|
||||
QWidget *contents_;
|
||||
QObject *content_object_;
|
||||
};
|
||||
|
||||
CollapsibleInfoPane(const Data &data, QWidget* parent = nullptr);
|
||||
|
||||
const Data &data() const { return data_; }
|
||||
|
||||
public Q_SLOTS:
|
||||
void Expand();
|
||||
void Collapse();
|
||||
|
||||
Q_SIGNALS:
|
||||
void Toggled(const bool expanded);
|
||||
|
||||
private Q_SLOTS:
|
||||
void ExpandedToggled(const bool expanded);
|
||||
|
||||
private:
|
||||
Data data_;
|
||||
CollapsibleInfoHeader *header_;
|
||||
};
|
||||
|
||||
#endif // COLLAPSIBLEINFOPANE_H
|
||||
89
src/widgets/infotextview.cpp
Normal file
89
src/widgets/infotextview.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QWidget>
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QWheelEvent>
|
||||
#include <QRegularExpression>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "infotextview.h"
|
||||
|
||||
InfoTextView::InfoTextView(QWidget *parent) : QTextBrowser(parent), last_width_(-1), recursion_filter_(false) {
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setOpenExternalLinks(true);
|
||||
|
||||
}
|
||||
|
||||
void InfoTextView::resizeEvent(QResizeEvent *e) {
|
||||
|
||||
const int w = qMax(100, width());
|
||||
if (w == last_width_) return;
|
||||
last_width_ = w;
|
||||
|
||||
document()->setTextWidth(w);
|
||||
setMinimumHeight(document()->size().height());
|
||||
|
||||
QTextBrowser::resizeEvent(e);
|
||||
|
||||
}
|
||||
|
||||
QSize InfoTextView::sizeHint() const { return minimumSize(); }
|
||||
|
||||
void InfoTextView::wheelEvent(QWheelEvent *e) { e->ignore(); }
|
||||
|
||||
void InfoTextView::SetHtml(const QString &html) {
|
||||
|
||||
QString copy(html.trimmed());
|
||||
|
||||
// Simplify newlines
|
||||
copy.replace(QRegularExpression(QStringLiteral("\\r\\n?")), QStringLiteral("\n"));
|
||||
|
||||
// Convert two or more newlines to <p>, convert single newlines to <br>
|
||||
copy.replace(QRegularExpression(QStringLiteral("([^>])([\\t ]*\\n){2,}")), QStringLiteral("\\1<p>"));
|
||||
copy.replace(QRegularExpression(QStringLiteral("([^>])[\\t ]*\\n")), QStringLiteral("\\1<br>"));
|
||||
|
||||
// Strip any newlines from the end
|
||||
copy.replace(QRegularExpression(QStringLiteral("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$")), QLatin1String(""));
|
||||
|
||||
setHtml(copy);
|
||||
|
||||
}
|
||||
|
||||
// Prevents QTextDocument from trying to load remote images before they are ready.
|
||||
QVariant InfoTextView::loadResource(int type, const QUrl &name) {
|
||||
|
||||
if (recursion_filter_) {
|
||||
recursion_filter_ = false;
|
||||
return QVariant();
|
||||
}
|
||||
recursion_filter_ = true;
|
||||
if (type == QTextDocument::ImageResource && name.scheme() == QLatin1String("http")) {
|
||||
if (document()->resource(type, name).isNull()) {
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return QTextBrowser::loadResource(type, name);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -17,26 +18,35 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONOPENGLWIDGET_H
|
||||
#define VISUALIZATIONOPENGLWIDGET_H
|
||||
#ifndef INFOTEXTVIEW_H
|
||||
#define INFOTEXTVIEW_H
|
||||
|
||||
#include "config.h"
|
||||
#include <QTextBrowser>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include <QOpenGLWidget>
|
||||
class QResizeEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
class ProjectMVisualization;
|
||||
|
||||
class VisualizationOpenGLWidget : public QOpenGLWidget {
|
||||
class InfoTextView : public QTextBrowser {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationOpenGLWidget(ProjectMVisualization *projectm_visualization, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
explicit InfoTextView(QWidget *parent = nullptr);
|
||||
|
||||
QSize sizeHint() const override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetHtml(const QString &html);
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
QVariant loadResource(int type, const QUrl &name) override;
|
||||
|
||||
private:
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
int last_width_;
|
||||
bool recursion_filter_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONOPENGLWIDGET_H
|
||||
#endif // INFOTEXTVIEW_H
|
||||
257
src/widgets/prettyimage.cpp
Normal file
257
src/widgets/prettyimage.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWindow>
|
||||
#include <QScreen>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QFuture>
|
||||
#include <QString>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QSettings>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QScrollArea>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "core/iconloader.h"
|
||||
|
||||
#include "prettyimage.h"
|
||||
|
||||
const int PrettyImage::kTotalHeight = 200;
|
||||
const int PrettyImage::kReflectionHeight = 40;
|
||||
const int PrettyImage::kImageHeight = PrettyImage::kTotalHeight - PrettyImage::kReflectionHeight;
|
||||
|
||||
const int PrettyImage::kMaxImageWidth = 300;
|
||||
|
||||
const char *PrettyImage::kSettingsGroup = "PrettyImageView";
|
||||
|
||||
PrettyImage::PrettyImage(const QUrl &url, QNetworkAccessManager *network, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
network_(network),
|
||||
state_(State_WaitingForLazyLoad),
|
||||
url_(url),
|
||||
menu_(nullptr) {
|
||||
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
|
||||
LazyLoad();
|
||||
|
||||
}
|
||||
|
||||
void PrettyImage::LazyLoad() {
|
||||
|
||||
if (state_ != State_WaitingForLazyLoad) return;
|
||||
|
||||
// Start fetching the image
|
||||
QNetworkReply *reply = network_->get(QNetworkRequest(url_));
|
||||
state_ = State_Fetching;
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply]() { ImageFetched(reply); });
|
||||
|
||||
}
|
||||
|
||||
QSize PrettyImage::image_size() const {
|
||||
|
||||
if (state_ != State_Finished) return QSize(kImageHeight * 1.6, kImageHeight);
|
||||
|
||||
QSize ret = image_.size();
|
||||
ret.scale(kMaxImageWidth, kImageHeight, Qt::KeepAspectRatio);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
QSize PrettyImage::sizeHint() const {
|
||||
return QSize(image_size().width(), kTotalHeight);
|
||||
}
|
||||
|
||||
void PrettyImage::ImageFetched(QNetworkReply *reply) {
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
QImage image = QImage::fromData(reply->readAll());
|
||||
if (image.isNull()) {
|
||||
qLog(Debug) << "Image failed to load" << reply->request().url() << reply->error();
|
||||
deleteLater();
|
||||
}
|
||||
else {
|
||||
state_ = State_CreatingThumbnail;
|
||||
image_ = image;
|
||||
(void)QtConcurrent::run([=]{ ImageScaled(image_.scaled(image_size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrettyImage::ImageScaled(QImage image) {
|
||||
|
||||
thumbnail_ = QPixmap::fromImage(image);
|
||||
state_ = State_Finished;
|
||||
|
||||
updateGeometry();
|
||||
update();
|
||||
emit Loaded();
|
||||
|
||||
}
|
||||
|
||||
void PrettyImage::paintEvent(QPaintEvent*) {
|
||||
|
||||
// Draw at the bottom of our area
|
||||
QRect image_rect(QPoint(0, 0), image_size());
|
||||
image_rect.moveBottom(kImageHeight);
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
// Draw the main image
|
||||
DrawThumbnail(&p, image_rect);
|
||||
|
||||
// Draw the reflection
|
||||
// Figure out where to draw it
|
||||
QRect reflection_rect(image_rect);
|
||||
reflection_rect.moveTop(image_rect.bottom());
|
||||
|
||||
// Create the reflected pixmap
|
||||
QImage reflection(reflection_rect.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
reflection.fill(palette().color(QPalette::Base).rgba());
|
||||
QPainter reflection_painter(&reflection);
|
||||
|
||||
// Set up the transformation
|
||||
QTransform transform;
|
||||
transform.scale(1.0, -1.0);
|
||||
transform.translate(0.0, -reflection_rect.height());
|
||||
reflection_painter.setTransform(transform);
|
||||
|
||||
QRect fade_rect(reflection.rect().bottomLeft() - QPoint(0, kReflectionHeight), reflection.rect().bottomRight());
|
||||
|
||||
// Draw the reflection into the buffer
|
||||
DrawThumbnail(&reflection_painter, reflection.rect());
|
||||
|
||||
// Make it fade out towards the bottom
|
||||
QLinearGradient fade_gradient(fade_rect.topLeft(), fade_rect.bottomLeft());
|
||||
fade_gradient.setColorAt(0.0, QColor(0, 0, 0, 0));
|
||||
fade_gradient.setColorAt(1.0, QColor(0, 0, 0, 128));
|
||||
|
||||
reflection_painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
reflection_painter.fillRect(fade_rect, fade_gradient);
|
||||
|
||||
reflection_painter.end();
|
||||
|
||||
// Draw the reflection on the image
|
||||
p.drawImage(reflection_rect, reflection);
|
||||
|
||||
}
|
||||
|
||||
void PrettyImage::DrawThumbnail(QPainter *p, const QRect &rect) {
|
||||
|
||||
switch (state_) {
|
||||
case State_WaitingForLazyLoad:
|
||||
case State_Fetching:
|
||||
case State_CreatingThumbnail:
|
||||
p->setPen(palette().color(QPalette::Disabled, QPalette::Text));
|
||||
p->drawText(rect, Qt::AlignHCenter | Qt::AlignBottom, tr("Loading..."));
|
||||
break;
|
||||
|
||||
case State_Finished:
|
||||
p->drawPixmap(rect, thumbnail_);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrettyImage::contextMenuEvent(QContextMenuEvent *e) {
|
||||
|
||||
if (e->pos().y() >= kImageHeight) return;
|
||||
|
||||
if (!menu_) {
|
||||
menu_ = new QMenu(this);
|
||||
menu_->addAction(IconLoader::Load(QStringLiteral("zoom-in")), tr("Show fullsize..."), this, &PrettyImage::ShowFullsize);
|
||||
menu_->addAction(IconLoader::Load(QStringLiteral("document-save")), tr("Save image") + QLatin1String("..."), this, &PrettyImage::SaveAs);
|
||||
}
|
||||
|
||||
menu_->popup(e->globalPos());
|
||||
|
||||
}
|
||||
|
||||
void PrettyImage::ShowFullsize() {
|
||||
|
||||
// Create the window
|
||||
QScrollArea *pwindow = new QScrollArea;
|
||||
pwindow->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
pwindow->setWindowTitle(tr("%1 image viewer").arg(QLatin1String("Strawberry")));
|
||||
|
||||
// Work out how large to make the window, based on the size of the screen
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QScreen *screen = QWidget::screen();
|
||||
#else
|
||||
QScreen *screen = (window() && window()->windowHandle() ? window()->windowHandle()->screen() : QGuiApplication::primaryScreen());
|
||||
#endif
|
||||
if (screen) {
|
||||
QRect desktop_rect(screen->availableGeometry());
|
||||
QSize window_size(qMin(desktop_rect.width() - 20, image_.width()), qMin(desktop_rect.height() - 20, image_.height()));
|
||||
pwindow->resize(window_size);
|
||||
}
|
||||
|
||||
// Create the label that displays the image
|
||||
QLabel *label = new QLabel(pwindow);
|
||||
label->setPixmap(QPixmap::fromImage(image_));
|
||||
|
||||
// Show the label in the window
|
||||
pwindow->setWidget(label);
|
||||
pwindow->setFrameShape(QFrame::NoFrame);
|
||||
pwindow->show();
|
||||
|
||||
}
|
||||
|
||||
void PrettyImage::SaveAs() {
|
||||
|
||||
QString filename = QFileInfo(url_.path()).fileName();
|
||||
|
||||
if (filename.isEmpty()) filename = QLatin1String("artwork.jpg");
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
QString last_save_dir = s.value("last_save_dir", QDir::homePath()).toString();
|
||||
|
||||
QString path = last_save_dir.isEmpty() ? QDir::homePath() : last_save_dir;
|
||||
QFileInfo path_info(path);
|
||||
if (path_info.isDir()) {
|
||||
path += QLatin1Char('/') + filename;
|
||||
}
|
||||
else {
|
||||
path = path_info.path() + QLatin1Char('/') + filename;
|
||||
}
|
||||
|
||||
filename = QFileDialog::getSaveFileName(this, tr("Save image"), path);
|
||||
if (filename.isEmpty()) return;
|
||||
|
||||
image_.save(filename);
|
||||
|
||||
s.setValue("last_save_dir", last_save_dir);
|
||||
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
92
src/widgets/prettyimage.h
Normal file
92
src/widgets/prettyimage.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRETTYIMAGE_H
|
||||
#define PRETTYIMAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
|
||||
class QMenu;
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class QContextMenuEvent;
|
||||
class QPaintEvent;
|
||||
|
||||
class PrettyImage : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PrettyImage(const QUrl &url, QNetworkAccessManager *network, QWidget *parent = nullptr);
|
||||
|
||||
static const int kTotalHeight;
|
||||
static const int kReflectionHeight;
|
||||
static const int kImageHeight;
|
||||
|
||||
static const int kMaxImageWidth;
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
QSize sizeHint() const override;
|
||||
QSize image_size() const;
|
||||
|
||||
signals:
|
||||
void Loaded();
|
||||
|
||||
public slots:
|
||||
void LazyLoad();
|
||||
void SaveAs();
|
||||
void ShowFullsize();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent*) override;
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
|
||||
private slots:
|
||||
void ImageFetched(QNetworkReply *reply);
|
||||
void ImageScaled(QImage image);
|
||||
|
||||
private:
|
||||
enum State {
|
||||
State_WaitingForLazyLoad,
|
||||
State_Fetching,
|
||||
State_CreatingThumbnail,
|
||||
State_Finished,
|
||||
};
|
||||
|
||||
void DrawThumbnail(QPainter *p, const QRect &rect);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *network_;
|
||||
State state_;
|
||||
QUrl url_;
|
||||
|
||||
QImage image_;
|
||||
QPixmap thumbnail_;
|
||||
|
||||
QMenu *menu_;
|
||||
QString last_save_dir_;
|
||||
};
|
||||
|
||||
#endif // PRETTYIMAGE_H
|
||||
189
src/widgets/prettyimageview.cpp
Normal file
189
src/widgets/prettyimageview.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QAbstractSlider>
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollArea>
|
||||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
#include <QMouseEvent>
|
||||
#include <QResizeEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include "core/networkaccessmanager.h"
|
||||
|
||||
#include "prettyimage.h"
|
||||
#include "prettyimageview.h"
|
||||
|
||||
PrettyImageView::PrettyImageView(QNetworkAccessManager *network, QWidget* parent)
|
||||
: QScrollArea(parent),
|
||||
network_(network),
|
||||
container_(new QWidget(this)),
|
||||
layout_(new QHBoxLayout(container_)),
|
||||
current_index_(-1),
|
||||
scroll_animation_(new QPropertyAnimation(horizontalScrollBar(), "value", this)),
|
||||
recursion_filter_(false) {
|
||||
|
||||
setWidget(container_);
|
||||
setWidgetResizable(true);
|
||||
setMinimumHeight(PrettyImage::kTotalHeight + 10);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
scroll_animation_->setDuration(250);
|
||||
scroll_animation_->setEasingCurve(QEasingCurve::InOutCubic);
|
||||
connect(horizontalScrollBar(), SIGNAL(sliderReleased()), SLOT(ScrollBarReleased()));
|
||||
connect(horizontalScrollBar(), SIGNAL(actionTriggered(int)), SLOT(ScrollBarAction(int)));
|
||||
|
||||
layout_->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
layout_->setContentsMargins(6, 6, 6, 6);
|
||||
layout_->setSpacing(6);
|
||||
layout_->addSpacing(200);
|
||||
layout_->addSpacing(200);
|
||||
|
||||
container_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
|
||||
}
|
||||
|
||||
bool PrettyImageView::eventFilter(QObject *obj, QEvent *event) {
|
||||
|
||||
// Work around infinite recursion in QScrollArea resizes.
|
||||
if (recursion_filter_) {
|
||||
return false;
|
||||
}
|
||||
recursion_filter_ = true;
|
||||
bool ret = QScrollArea::eventFilter(obj, event);
|
||||
recursion_filter_ = false;
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void PrettyImageView::AddImage(const QUrl &url) {
|
||||
|
||||
PrettyImage *image = new PrettyImage(url, network_, container_);
|
||||
connect(image, SIGNAL(destroyed()), SLOT(ScrollToCurrent()));
|
||||
connect(image, SIGNAL(Loaded()), SLOT(ScrollToCurrent()));
|
||||
|
||||
layout_->insertWidget(layout_->count() - 1, image);
|
||||
if (current_index_ == -1) ScrollTo(0);
|
||||
|
||||
}
|
||||
|
||||
void PrettyImageView::mouseReleaseEvent(QMouseEvent *e) {
|
||||
|
||||
// Find the image that was clicked on
|
||||
QWidget *widget = container_->childAt(container_->mapFrom(this, e->pos()));
|
||||
if (!widget) return;
|
||||
|
||||
// Get the index of that image
|
||||
const int index = layout_->indexOf(widget) - 1;
|
||||
if (index == -1) return;
|
||||
|
||||
if (index == current_index_) {
|
||||
// Show the image fullsize
|
||||
PrettyImage* pretty_image = qobject_cast<PrettyImage*>(widget);
|
||||
if (pretty_image) {
|
||||
pretty_image->ShowFullsize();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Scroll to the image
|
||||
ScrollTo(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrettyImageView::ScrollTo(const int index, const bool smooth) {
|
||||
|
||||
current_index_ = qBound(0, index, layout_->count() - 3);
|
||||
const int layout_index = current_index_ + 1;
|
||||
|
||||
const QWidget *target_widget = layout_->itemAt(layout_index)->widget();
|
||||
if (!target_widget) return;
|
||||
|
||||
const int current_x = horizontalScrollBar()->value();
|
||||
const int target_x = target_widget->geometry().center().x() - width() / 2;
|
||||
|
||||
if (current_x == target_x) return;
|
||||
|
||||
if (smooth) {
|
||||
scroll_animation_->setStartValue(current_x);
|
||||
scroll_animation_->setEndValue(target_x);
|
||||
scroll_animation_->start();
|
||||
}
|
||||
else {
|
||||
scroll_animation_->stop();
|
||||
horizontalScrollBar()->setValue(target_x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrettyImageView::ScrollToCurrent() { ScrollTo(current_index_); }
|
||||
|
||||
void PrettyImageView::ScrollBarReleased() {
|
||||
|
||||
// Find the nearest widget to where the scroll bar was released
|
||||
const int current_x = horizontalScrollBar()->value() + width() / 2;
|
||||
int layout_index = 1;
|
||||
for (; layout_index < layout_->count() - 1; ++layout_index) {
|
||||
const QWidget *widget = layout_->itemAt(layout_index)->widget();
|
||||
if (widget && widget->geometry().right() > current_x) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollTo(layout_index - 1);
|
||||
|
||||
}
|
||||
|
||||
void PrettyImageView::ScrollBarAction(const int action) {
|
||||
|
||||
switch (action) {
|
||||
case QAbstractSlider::SliderSingleStepAdd:
|
||||
case QAbstractSlider::SliderPageStepAdd:
|
||||
ScrollTo(current_index_ + 1);
|
||||
break;
|
||||
|
||||
case QAbstractSlider::SliderSingleStepSub:
|
||||
case QAbstractSlider::SliderPageStepSub:
|
||||
ScrollTo(current_index_ - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrettyImageView::resizeEvent(QResizeEvent *e) {
|
||||
|
||||
QScrollArea::resizeEvent(e);
|
||||
ScrollTo(current_index_, false);
|
||||
|
||||
}
|
||||
|
||||
void PrettyImageView::wheelEvent(QWheelEvent *e) {
|
||||
|
||||
const int d = e->angleDelta().x() > 0 ? -1 : 1;
|
||||
ScrollTo(current_index_ + d, true);
|
||||
|
||||
}
|
||||
74
src/widgets/prettyimageview.h
Normal file
74
src/widgets/prettyimageview.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PRETTYIMAGEVIEW_H
|
||||
#define PRETTYIMAGEVIEW_H
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QMap>
|
||||
#include <QUrl>
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class QMenu;
|
||||
class QHBoxLayout;
|
||||
class QPropertyAnimation;
|
||||
class QTimeLine;
|
||||
class QMouseEvent;
|
||||
class QResizeEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
class PrettyImageView : public QScrollArea {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PrettyImageView(QNetworkAccessManager *network, QWidget *parent = nullptr);
|
||||
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
public Q_SLOTS:
|
||||
void AddImage(const QUrl& url);
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void ScrollBarReleased();
|
||||
void ScrollBarAction(const int action);
|
||||
void ScrollTo(const int index, const bool smooth = true);
|
||||
void ScrollToCurrent();
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject*, QEvent*) override;
|
||||
|
||||
QNetworkAccessManager *network_;
|
||||
|
||||
QWidget *container_;
|
||||
QHBoxLayout *layout_;
|
||||
|
||||
int current_index_;
|
||||
QPropertyAnimation *scroll_animation_;
|
||||
|
||||
bool recursion_filter_;
|
||||
};
|
||||
|
||||
#endif // PRETTYIMAGEVIEW_H
|
||||
187
src/widgets/widgetfadehelper.cpp
Normal file
187
src/widgets/widgetfadehelper.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
#include <QTimeLine>
|
||||
#include <QResizeEvent>
|
||||
#include <QEvent>
|
||||
|
||||
#include "widgetfadehelper.h"
|
||||
#include "core/qt_blurimage.h"
|
||||
|
||||
const int WidgetFadeHelper::kLoadingPadding = 9;
|
||||
const int WidgetFadeHelper::kLoadingBorderRadius = 10;
|
||||
|
||||
WidgetFadeHelper::WidgetFadeHelper(QWidget *parent, const int msec)
|
||||
: QWidget(parent),
|
||||
parent_(parent),
|
||||
blur_timeline_(new QTimeLine(msec, this)),
|
||||
fade_timeline_(new QTimeLine(msec, this)) {
|
||||
|
||||
parent->installEventFilter(this);
|
||||
|
||||
connect(blur_timeline_, SIGNAL(valueChanged(qreal)), SLOT(update()));
|
||||
connect(fade_timeline_, SIGNAL(valueChanged(qreal)), SLOT(update()));
|
||||
connect(fade_timeline_, SIGNAL(finished()), SLOT(FadeFinished()));
|
||||
|
||||
hide();
|
||||
|
||||
}
|
||||
|
||||
bool WidgetFadeHelper::eventFilter(QObject *obj, QEvent *event) {
|
||||
|
||||
// We're only interested in our parent's resize events
|
||||
if (obj != parent_ || event->type() != QEvent::Resize) return false;
|
||||
|
||||
// Don't care if we're hidden
|
||||
if (!isVisible()) return false;
|
||||
|
||||
QResizeEvent *re = static_cast<QResizeEvent*>(event);
|
||||
if (re->oldSize() == re->size()) {
|
||||
// Ignore phoney resize events
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get a new capture of the parent
|
||||
hide();
|
||||
CaptureParent();
|
||||
show();
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void WidgetFadeHelper::StartBlur() {
|
||||
|
||||
CaptureParent();
|
||||
|
||||
// Cover the parent
|
||||
raise();
|
||||
show();
|
||||
|
||||
// Start the timeline
|
||||
blur_timeline_->stop();
|
||||
blur_timeline_->start();
|
||||
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents, false);
|
||||
|
||||
}
|
||||
|
||||
void WidgetFadeHelper::CaptureParent() {
|
||||
|
||||
// Take a "screenshot" of the window
|
||||
original_pixmap_ = parent_->grab();
|
||||
QImage original_image = original_pixmap_.toImage();
|
||||
|
||||
// Blur it
|
||||
QImage blurred(original_image.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
blurred.fill(Qt::transparent);
|
||||
|
||||
QPainter blur_painter(&blurred);
|
||||
blur_painter.save();
|
||||
qt_blurImage(&blur_painter, original_image, 10.0, true, false);
|
||||
blur_painter.restore();
|
||||
|
||||
// Draw some loading text over the top
|
||||
QFont loading_font(font());
|
||||
loading_font.setBold(true);
|
||||
QFontMetrics loading_font_metrics(loading_font);
|
||||
|
||||
const QString loading_text = tr("Loading...");
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
const QSize loading_size(kLoadingPadding * 2 + loading_font_metrics.horizontalAdvance(loading_text), kLoadingPadding * 2 + loading_font_metrics.height());
|
||||
#else
|
||||
const QSize loading_size(kLoadingPadding * 2 + loading_font_metrics.width(loading_text), kLoadingPadding * 2 + loading_font_metrics.height());
|
||||
#endif
|
||||
const QRect loading_rect((blurred.width() - loading_size.width()) / 2, 100, loading_size.width(), loading_size.height());
|
||||
|
||||
blur_painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
blur_painter.translate(0.5, 0.5);
|
||||
blur_painter.setPen(QColor(200, 200, 200, 255));
|
||||
blur_painter.setBrush(QColor(200, 200, 200, 192));
|
||||
blur_painter.drawRoundedRect(loading_rect, kLoadingBorderRadius, kLoadingBorderRadius);
|
||||
|
||||
blur_painter.setPen(palette().brush(QPalette::Text).color());
|
||||
blur_painter.setFont(loading_font);
|
||||
blur_painter.drawText(loading_rect.translated(-1, -1), Qt::AlignCenter, loading_text);
|
||||
blur_painter.translate(-0.5, -0.5);
|
||||
|
||||
blur_painter.end();
|
||||
|
||||
blurred_pixmap_ = QPixmap::fromImage(blurred);
|
||||
|
||||
resize(parent_->size());
|
||||
|
||||
}
|
||||
|
||||
void WidgetFadeHelper::StartFade() {
|
||||
|
||||
if (blur_timeline_->state() == QTimeLine::Running) {
|
||||
// Blur timeline is still running, so we need render the current state
|
||||
// into a new pixmap.
|
||||
QPixmap pixmap(original_pixmap_);
|
||||
QPainter painter(&pixmap);
|
||||
painter.setOpacity(blur_timeline_->currentValue());
|
||||
painter.drawPixmap(0, 0, blurred_pixmap_);
|
||||
painter.end();
|
||||
blurred_pixmap_ = pixmap;
|
||||
}
|
||||
blur_timeline_->stop();
|
||||
original_pixmap_ = QPixmap();
|
||||
|
||||
// Start the timeline
|
||||
fade_timeline_->stop();
|
||||
fade_timeline_->start();
|
||||
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
||||
|
||||
}
|
||||
|
||||
void WidgetFadeHelper::paintEvent(QPaintEvent *event) {
|
||||
|
||||
Q_UNUSED(event)
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
if (fade_timeline_->state() != QTimeLine::Running) {
|
||||
// We're fading in the blur
|
||||
p.drawPixmap(0, 0, original_pixmap_);
|
||||
p.setOpacity(blur_timeline_->currentValue());
|
||||
}
|
||||
else {
|
||||
// Fading out the blur into the new image
|
||||
p.setOpacity(1.0 - fade_timeline_->currentValue());
|
||||
}
|
||||
|
||||
p.drawPixmap(0, 0, blurred_pixmap_);
|
||||
|
||||
}
|
||||
|
||||
void WidgetFadeHelper::FadeFinished() {
|
||||
|
||||
hide();
|
||||
original_pixmap_ = QPixmap();
|
||||
blurred_pixmap_ = QPixmap();
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,53 +18,46 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONOVERLAY_H
|
||||
#define VISUALIZATIONOVERLAY_H
|
||||
|
||||
#include "config.h"
|
||||
#ifndef WIDGETFADEHELPER_H
|
||||
#define WIDGETFADEHELPER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include <QBasicTimer>
|
||||
#include <QPixmap>
|
||||
|
||||
class Ui_VisualizationOverlay;
|
||||
|
||||
class QGraphicsProxyWidget;
|
||||
class QTimeLine;
|
||||
class QAction;
|
||||
class QPaintEvent;
|
||||
class QEvent;
|
||||
|
||||
class VisualizationOverlay : public QWidget {
|
||||
class WidgetFadeHelper : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationOverlay(QWidget *parent = nullptr);
|
||||
~VisualizationOverlay();
|
||||
|
||||
QGraphicsProxyWidget *title(QGraphicsProxyWidget *proxy) const;
|
||||
|
||||
void SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next);
|
||||
void SetSongTitle(const QString &title);
|
||||
WidgetFadeHelper(QWidget *parent, const int msec = 500);
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetVisible(const bool visible);
|
||||
|
||||
Q_SIGNALS:
|
||||
void OpacityChanged(const qreal value);
|
||||
void ShowPopupMenu(const QPoint &pos);
|
||||
void StartBlur();
|
||||
void StartFade();
|
||||
|
||||
protected:
|
||||
// QWidget
|
||||
void timerEvent(QTimerEvent *e);
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void ShowSettingsMenu();
|
||||
void FadeFinished();
|
||||
|
||||
private:
|
||||
Ui_VisualizationOverlay *ui_;
|
||||
void CaptureParent();
|
||||
|
||||
private:
|
||||
static const int kLoadingPadding;
|
||||
static const int kLoadingBorderRadius;
|
||||
|
||||
QWidget *parent_;
|
||||
QTimeLine *blur_timeline_;
|
||||
QTimeLine *fade_timeline_;
|
||||
QBasicTimer fade_out_timeout_;
|
||||
bool visible_;
|
||||
|
||||
QPixmap original_pixmap_;
|
||||
QPixmap blurred_pixmap_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONOVERLAY_H
|
||||
#endif // WIDGETFADEHELPER_H
|
||||
Reference in New Issue
Block a user