From 2282127d869b6056b99816e2470fa119ad3b6c32 Mon Sep 17 00:00:00 2001 From: emeric Date: Fri, 20 May 2022 00:08:37 +0200 Subject: [PATCH] Still converting to bootstrap 5. Some cover refacto --- approot/release.xml | 2 +- docroot/css/lms.css | 23 ++++--- src/lms/CMakeLists.txt | 2 +- src/lms/ui/PlayQueue.cpp | 17 ++--- src/lms/ui/TrackStringUtils.cpp | 37 ----------- src/lms/ui/Utils.cpp | 63 +++++++++++++++++++ .../ui/{TrackStringUtils.hpp => Utils.hpp} | 17 ++++- src/lms/ui/explore/ReleaseListHelpers.cpp | 16 ++--- src/lms/ui/explore/ReleaseView.cpp | 13 ++-- src/lms/ui/explore/TrackListHelpers.cpp | 25 +++----- 10 files changed, 124 insertions(+), 91 deletions(-) delete mode 100644 src/lms/ui/TrackStringUtils.cpp create mode 100644 src/lms/ui/Utils.cpp rename src/lms/ui/{TrackStringUtils.hpp => Utils.hpp} (62%) diff --git a/approot/release.xml b/approot/release.xml index 78f56dae..632b79f9 100644 --- a/approot/release.xml +++ b/approot/release.xml @@ -9,7 +9,7 @@
- ${cover class="Lms-explore-release-cover"} + ${cover}

${name}

diff --git a/docroot/css/lms.css b/docroot/css/lms.css index 5a158556..168af16c 100644 --- a/docroot/css/lms.css +++ b/docroot/css/lms.css @@ -8,11 +8,6 @@ body { padding-bottom: 78px; } -.Lms-cover-small { - width: 64px; - min-width: 64px; -} - .Lms-notification-container { position: fixed; bottom: 78px; @@ -32,6 +27,19 @@ body { } .Lms-cover { + opacity: 0; + transition: opacity 1s; +} + +.Lms-cover-container { + position: relative; +} + +.Lms-cover-loaded { + opacity: 1; +} + +.Lms-cover-release { max-height: 100%; max-width: 100%; width: auto; @@ -44,8 +52,9 @@ body { margin: auto; } -.Lms-cover-container { - position: relative; +.Lms-cover-track { + width: 64px; + min-width: 64px; } .Lms-responsive-square { diff --git a/src/lms/CMakeLists.txt b/src/lms/CMakeLists.txt index 8e922082..2ec36e21 100644 --- a/src/lms/CMakeLists.txt +++ b/src/lms/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(lms ui/NotificationContainer.cpp ui/PlayQueue.cpp ui/SettingsView.cpp - ui/TrackStringUtils.cpp + ui/Utils.cpp ui/admin/DatabaseSettingsView.cpp ui/admin/ScannerController.cpp ui/admin/InitWizardView.cpp diff --git a/src/lms/ui/PlayQueue.cpp b/src/lms/ui/PlayQueue.cpp index 191a6942..05a2247f 100644 --- a/src/lms/ui/PlayQueue.cpp +++ b/src/lms/ui/PlayQueue.cpp @@ -36,11 +36,10 @@ #include "utils/String.hpp" #include "common/InfiniteScrollingContainer.hpp" -#include "resource/CoverResource.hpp" #include "resource/DownloadResource.hpp" #include "LmsApplication.hpp" #include "MediaPlayer.hpp" -#include "TrackStringUtils.hpp" +#include "Utils.hpp" namespace UserInterface { @@ -408,22 +407,18 @@ PlayQueue::addEntry(const Database::TrackListEntry::pointer& tracklistEntry) entry->bindWidget("release", LmsApplication::createReleaseAnchor(release)); { Wt::WAnchor* anchor {entry->bindWidget("cover", LmsApplication::createReleaseAnchor(release, false))}; - auto cover {std::make_unique()}; - cover->setImageLink(LmsApp->getCoverResource()->getReleaseUrl(release->getId(), CoverResource::Size::Large)); - cover->setStyleClass("img-fluid"); // HACK - cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); + auto cover {Utils::createCover(release->getId(), CoverResource::Size::Small)}; + cover->addStyleClass("Lms-cover-track"); // HACK anchor->setImage(std::move(cover)); } } else { - auto cover = entry->bindNew("cover"); - cover->setImageLink(LmsApp->getCoverResource()->getTrackUrl(track->getId(), CoverResource::Size::Large)); - cover->setStyleClass("img-fluid"); // HACK - cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); + auto cover {entry->bindWidget("cover", Utils::createCover(track->getId(), CoverResource::Size::Small))}; + cover->addStyleClass("Lms-cover-track"); } - entry->bindString("duration", durationToString(track->getDuration()), Wt::TextFormat::Plain); + entry->bindString("duration", Utils::durationToString(track->getDuration()), Wt::TextFormat::Plain); Wt::WText* playBtn {entry->bindNew("play-btn", Wt::WString::tr("Lms.PlayQueue.template.play-btn"), Wt::TextFormat::XHTML)}; playBtn->clicked().connect([=] diff --git a/src/lms/ui/TrackStringUtils.cpp b/src/lms/ui/TrackStringUtils.cpp deleted file mode 100644 index 79abede5..00000000 --- a/src/lms/ui/TrackStringUtils.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2020 Emeric Poupon - * - * This file is part of LMS. - * - * LMS 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. - * - * LMS 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 LMS. If not, see . - */ - -#include "TrackStringUtils.hpp" - -#include -#include - -std::string -durationToString(std::chrono::milliseconds msDuration) -{ - const std::chrono::seconds duration {std::chrono::duration_cast(msDuration)}; - - std::ostringstream oss; - oss << (duration.count() / 60) - << ":" - << std::setfill('0') << std::setw(2) << duration.count() % 60; - - return oss.str(); -} - diff --git a/src/lms/ui/Utils.cpp b/src/lms/ui/Utils.cpp new file mode 100644 index 00000000..4fae3c62 --- /dev/null +++ b/src/lms/ui/Utils.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2020 Emeric Poupon + * + * This file is part of LMS. + * + * LMS 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. + * + * LMS 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 LMS. If not, see . + */ + +#include "Utils.hpp" + +#include +#include + +#include "LmsApplication.hpp" + +namespace UserInterface::Utils +{ + + std::string + durationToString(std::chrono::milliseconds msDuration) + { + const std::chrono::seconds duration {std::chrono::duration_cast(msDuration)}; + + std::ostringstream oss; + oss << (duration.count() / 60) + << ":" + << std::setfill('0') << std::setw(2) << duration.count() % 60; + + return oss.str(); + } + + + std::unique_ptr + createCover(Database::ReleaseId releaseId, CoverResource::Size size) + { + auto cover {std::make_unique()}; + cover->setImageLink(LmsApp->getCoverResource()->getReleaseUrl(releaseId, size)); + cover->setStyleClass("Lms-cover img-fluid"); // HACK + cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); // HACK + return cover; + } + + std::unique_ptr + createCover(Database::TrackId trackId, CoverResource::Size size) + { + auto cover {std::make_unique()}; + cover->setImageLink(LmsApp->getCoverResource()->getTrackUrl(trackId, size)); + cover->setStyleClass("Lms-cover img-fluid"); // HACK + cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); // HACK + return cover; + } +} diff --git a/src/lms/ui/TrackStringUtils.hpp b/src/lms/ui/Utils.hpp similarity index 62% rename from src/lms/ui/TrackStringUtils.hpp rename to src/lms/ui/Utils.hpp index 2af0b2fc..19ca01dd 100644 --- a/src/lms/ui/TrackStringUtils.hpp +++ b/src/lms/ui/Utils.hpp @@ -22,6 +22,19 @@ #include #include -std::string -durationToString(std::chrono::milliseconds msDuration); +#include + +#include "services/database/ReleaseId.hpp" +#include "services/database/TrackId.hpp" + +#include "resource/CoverResource.hpp" + +namespace UserInterface::Utils +{ + std::string + durationToString(std::chrono::milliseconds msDuration); + + std::unique_ptr createCover(Database::ReleaseId releaseId, CoverResource::Size size); + std::unique_ptr createCover(Database::TrackId trackId, CoverResource::Size size); +} diff --git a/src/lms/ui/explore/ReleaseListHelpers.cpp b/src/lms/ui/explore/ReleaseListHelpers.cpp index 5daeaec9..f3e2ac7b 100644 --- a/src/lms/ui/explore/ReleaseListHelpers.cpp +++ b/src/lms/ui/explore/ReleaseListHelpers.cpp @@ -25,9 +25,9 @@ #include "services/database/Artist.hpp" #include "services/database/Release.hpp" -#include "resource/CoverResource.hpp" #include "LmsApplication.hpp" +#include "Utils.hpp" using namespace Database; @@ -42,18 +42,18 @@ namespace UserInterface::ReleaseListHelpers entry->bindWidget("release-name", LmsApplication::createReleaseAnchor(release)); entry->addFunction("tr", &Wt::WTemplate::Functions::tr); - Wt::WAnchor* anchor {entry->bindWidget("cover", LmsApplication::createReleaseAnchor(release, false))}; - auto cover {std::make_unique()}; - cover->setImageLink(LmsApp->getCoverResource()->getReleaseUrl(release->getId(), CoverResource::Size::Large)); - cover->setStyleClass("Lms-cover rounded"); - cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); - anchor->setImage(std::move(cover)); + { + Wt::WAnchor* anchor {entry->bindWidget("cover", LmsApplication::createReleaseAnchor(release, false))}; + auto cover {Utils::createCover(release->getId(), CoverResource::Size::Large)}; + cover->addStyleClass("Lms-cover-release"); + anchor->setImage(std::move(cover)); + } auto artists {release->getReleaseArtists()}; if (artists.empty()) artists = release->getArtists(); - bool isSameArtist {(std::find(std::cbegin(artists), std::cend(artists), artist) != artists.end())}; + const bool isSameArtist {(std::find(std::cbegin(artists), std::cend(artists), artist) != artists.end())}; if (artists.size() > 1) { diff --git a/src/lms/ui/explore/ReleaseView.cpp b/src/lms/ui/explore/ReleaseView.cpp index 509be1b9..0cbafedb 100644 --- a/src/lms/ui/explore/ReleaseView.cpp +++ b/src/lms/ui/explore/ReleaseView.cpp @@ -34,13 +34,12 @@ #include "common/Template.hpp" #include "resource/DownloadResource.hpp" -#include "resource/CoverResource.hpp" #include "Filters.hpp" #include "LmsApplication.hpp" #include "LmsApplicationException.hpp" #include "MediaPlayer.hpp" #include "ReleaseListHelpers.hpp" -#include "TrackStringUtils.hpp" +#include "Utils.hpp" using namespace Database; @@ -127,15 +126,11 @@ Release::refreshView() } } - bindString("duration", durationToString(release->getDuration()), Wt::TextFormat::Plain); + bindString("duration", Utils::durationToString(release->getDuration()), Wt::TextFormat::Plain); refreshReleaseArtists(release); - { - Wt::WImage* cover {bindNew("cover", Wt::WLink(LmsApp->getCoverResource()->getReleaseUrl(release->getId(), CoverResource::Size::Large)))}; - cover->setStyleClass("img-fluid"); - cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); - } + bindWidget("cover", Utils::createCover(release->getId(), CoverResource::Size::Large)); Wt::WContainerWidget* clusterContainers {bindNew("clusters")}; { @@ -319,7 +314,7 @@ Release::refreshView() ->setLink(Wt::WLink {std::make_unique(trackId)}); } - entry->bindString("duration", durationToString(track->getDuration()), Wt::TextFormat::Plain); + entry->bindString("duration", Utils::durationToString(track->getDuration()), Wt::TextFormat::Plain); LmsApp->getMediaPlayer().trackLoaded.connect(entry, [=] (TrackId loadedTrackId) { diff --git a/src/lms/ui/explore/TrackListHelpers.cpp b/src/lms/ui/explore/TrackListHelpers.cpp index fdb681d3..e006d5f0 100644 --- a/src/lms/ui/explore/TrackListHelpers.cpp +++ b/src/lms/ui/explore/TrackListHelpers.cpp @@ -38,7 +38,7 @@ #include "resource/CoverResource.hpp" #include "LmsApplication.hpp" #include "MediaPlayer.hpp" -#include "TrackStringUtils.hpp" +#include "Utils.hpp" using namespace Database; @@ -60,26 +60,21 @@ namespace UserInterface::TrackListHelpers { entry->setCondition("if-has-release", true); entry->bindWidget("release", LmsApplication::createReleaseAnchor(track->getRelease())); - { - Wt::WAnchor* anchor {entry->bindWidget("cover", LmsApplication::createReleaseAnchor(release, false))}; - auto cover {std::make_unique()}; - cover->setImageLink(LmsApp->getCoverResource()->getReleaseUrl(release->getId(), CoverResource::Size::Large)); - cover->setStyleClass("img-fluid"); - cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); - anchor->setImage(std::move(cover)); - } + Wt::WAnchor* anchor {entry->bindWidget("cover", LmsApplication::createReleaseAnchor(release, false))}; + auto cover {Utils::createCover(release->getId(), CoverResource::Size::Small)}; + cover->addStyleClass("Lms-cover-track"); // HACK + anchor->setImage(std::move((cover))); } else { - auto* cover {entry->bindNew("cover")}; - cover->setImageLink(LmsApp->getCoverResource()->getTrackUrl(trackId, CoverResource::Size::Large)); - cover->setStyleClass("img-fluid"); - cover->setAttributeValue("onload", LmsApp->javaScriptClass() + ".onLoadCover(this)"); + auto cover {Utils::createCover(trackId, CoverResource::Size::Small)}; + cover->addStyleClass("Lms-cover-track"); // HACK + entry->bindWidget("cover", std::move(cover)); } - entry->bindString("duration", durationToString(track->getDuration()), Wt::TextFormat::Plain); + entry->bindString("duration", Utils::durationToString(track->getDuration()), Wt::TextFormat::Plain); - Wt::WText* playBtn = entry->bindNew("play-btn", Wt::WString::tr("Lms.Explore.template.play-btn"), Wt::TextFormat::XHTML); + Wt::WText* playBtn {entry->bindNew("play-btn", Wt::WString::tr("Lms.Explore.template.play-btn"), Wt::TextFormat::XHTML)}; playBtn->clicked().connect([trackId, &tracksAction] { tracksAction.emit(PlayQueueAction::Play, {trackId});