From bd39e7cb0dd080b2a8f2785b1a444a2f5e71d4b4 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 25 Aug 2024 05:49:41 +0200 Subject: [PATCH] smartplaylists: Move classes to own files --- src/CMakeLists.txt | 10 ++ .../smartplaylistquerywizardplugin.cpp | 51 +------ .../smartplaylistquerywizardplugin.h | 11 +- ...artplaylistquerywizardpluginsearchpage.cpp | 45 ++++++ ...smartplaylistquerywizardpluginsearchpage.h | 55 +++++++ ...smartplaylistquerywizardpluginsortpage.cpp | 35 +++++ .../smartplaylistquerywizardpluginsortpage.h | 45 ++++++ .../smartplaylistsearchtermwidget.cpp | 137 ++---------------- .../smartplaylistsearchtermwidget.h | 6 +- .../smartplaylistsearchtermwidgetoverlay.cpp | 130 +++++++++++++++++ .../smartplaylistsearchtermwidgetoverlay.h | 61 ++++++++ src/smartplaylists/smartplaylistwizard.cpp | 30 +--- src/smartplaylists/smartplaylistwizard.h | 9 +- .../smartplaylistwizardfinishpage.cpp | 34 +++++ .../smartplaylistwizardfinishpage.h | 42 ++++++ .../smartplaylistwizardtypepage.cpp | 25 ++++ .../smartplaylistwizardtypepage.h | 37 +++++ 17 files changed, 551 insertions(+), 212 deletions(-) create mode 100644 src/smartplaylists/smartplaylistquerywizardpluginsearchpage.cpp create mode 100644 src/smartplaylists/smartplaylistquerywizardpluginsearchpage.h create mode 100644 src/smartplaylists/smartplaylistquerywizardpluginsortpage.cpp create mode 100644 src/smartplaylists/smartplaylistquerywizardpluginsortpage.h create mode 100644 src/smartplaylists/smartplaylistsearchtermwidgetoverlay.cpp create mode 100644 src/smartplaylists/smartplaylistsearchtermwidgetoverlay.h create mode 100644 src/smartplaylists/smartplaylistwizardfinishpage.cpp create mode 100644 src/smartplaylists/smartplaylistwizardfinishpage.h create mode 100644 src/smartplaylists/smartplaylistwizardtypepage.cpp create mode 100644 src/smartplaylists/smartplaylistwizardtypepage.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c4083fd61..4d2befb5e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,15 +148,20 @@ set(SOURCES smartplaylists/playlistgeneratormimedata.cpp smartplaylists/playlistquerygenerator.cpp smartplaylists/smartplaylistquerywizardplugin.cpp + smartplaylists/smartplaylistquerywizardpluginsortpage.cpp + smartplaylists/smartplaylistquerywizardpluginsearchpage.cpp smartplaylists/smartplaylistsearch.cpp smartplaylists/smartplaylistsearchpreview.cpp smartplaylists/smartplaylistsearchterm.cpp smartplaylists/smartplaylistsearchtermwidget.cpp + smartplaylists/smartplaylistsearchtermwidgetoverlay.cpp smartplaylists/smartplaylistsmodel.cpp smartplaylists/smartplaylistsviewcontainer.cpp smartplaylists/smartplaylistsview.cpp smartplaylists/smartplaylistwizard.cpp smartplaylists/smartplaylistwizardplugin.cpp + smartplaylists/smartplaylistwizardtypepage.cpp + smartplaylists/smartplaylistwizardfinishpage.cpp covermanager/albumcovermanager.cpp covermanager/albumcovermanagerlist.cpp @@ -409,13 +414,18 @@ set(HEADERS smartplaylists/playlistquerygenerator.h smartplaylists/playlistgeneratormimedata.h smartplaylists/smartplaylistquerywizardplugin.h + smartplaylists/smartplaylistquerywizardpluginsortpage.h + smartplaylists/smartplaylistquerywizardpluginsearchpage.h smartplaylists/smartplaylistsearchpreview.h smartplaylists/smartplaylistsearchtermwidget.h + smartplaylists/smartplaylistsearchtermwidgetoverlay.h smartplaylists/smartplaylistsmodel.h smartplaylists/smartplaylistsviewcontainer.h smartplaylists/smartplaylistsview.h smartplaylists/smartplaylistwizard.h smartplaylists/smartplaylistwizardplugin.h + smartplaylists/smartplaylistwizardtypepage.h + smartplaylists/smartplaylistwizardfinishpage.h covermanager/albumcovermanager.h covermanager/albumcovermanagerlist.h diff --git a/src/smartplaylists/smartplaylistquerywizardplugin.cpp b/src/smartplaylists/smartplaylistquerywizardplugin.cpp index db7c3181e..0f8d7ee8f 100644 --- a/src/smartplaylists/smartplaylistquerywizardplugin.cpp +++ b/src/smartplaylists/smartplaylistquerywizardplugin.cpp @@ -34,6 +34,8 @@ #include "core/shared_ptr.h" #include "playlistquerygenerator.h" #include "smartplaylistquerywizardplugin.h" +#include "smartplaylistquerywizardpluginsearchpage.h" +#include "smartplaylistquerywizardpluginsortpage.h" #include "smartplaylistsearchtermwidget.h" #include "ui_smartplaylistquerysearchpage.h" #include "ui_smartplaylistquerysortpage.h" @@ -41,51 +43,6 @@ using std::make_unique; using std::make_shared; -class SmartPlaylistQueryWizardPlugin::SearchPage : public QWizardPage { // clazy:exclude=missing-qobject-macro - - friend class SmartPlaylistQueryWizardPlugin; - - public: - explicit SearchPage(QWidget *parent = nullptr) - : QWizardPage(parent), - layout_(nullptr), - new_term_(nullptr), - preview_(nullptr), - ui_(new Ui_SmartPlaylistQuerySearchPage) { - - ui_->setupUi(this); - - } - - bool isComplete() const override { - if (ui_->type->currentIndex() == 2) { // All songs - return true; - } - return !std::any_of(terms_.begin(), terms_.end(), [](SmartPlaylistSearchTermWidget *widget) { return !widget->Term().is_valid(); }); - } - - QVBoxLayout *layout_; - QList terms_; - SmartPlaylistSearchTermWidget *new_term_; - - SmartPlaylistSearchPreview *preview_; - - ScopedPtr ui_; -}; - -class SmartPlaylistQueryWizardPlugin::SortPage : public QWizardPage { // clazy:exclude=missing-qobject-macro - public: - SortPage(SmartPlaylistQueryWizardPlugin *plugin, QWidget *parent, int next_id) - : QWizardPage(parent), next_id_(next_id), plugin_(plugin) {} - - void showEvent(QShowEvent*) override { plugin_->UpdateSortPreview(); } - - int nextId() const override { return next_id_; } - int next_id_; - - SmartPlaylistQueryWizardPlugin *plugin_; -}; - SmartPlaylistQueryWizardPlugin::SmartPlaylistQueryWizardPlugin(Application *app, SharedPtr collection_backend, QObject *parent) : SmartPlaylistWizardPlugin(app, collection_backend, parent), search_page_(nullptr), @@ -102,9 +59,9 @@ QString SmartPlaylistQueryWizardPlugin::description() const { int SmartPlaylistQueryWizardPlugin::CreatePages(QWizard *wizard, int finish_page_id) { // Create the UI - search_page_ = new SearchPage(wizard); + search_page_ = new SmartPlaylistQueryWizardPluginSearchPage(wizard); - QWizardPage *sort_page = new SortPage(this, wizard, finish_page_id); + QWizardPage *sort_page = new SmartPlaylistQueryWizardPluginSortPage(this, wizard, finish_page_id); sort_ui_ = make_unique(); sort_ui_->setupUi(sort_page); diff --git a/src/smartplaylists/smartplaylistquerywizardplugin.h b/src/smartplaylists/smartplaylistquerywizardplugin.h index b0c8a8e0c..91f028e32 100644 --- a/src/smartplaylists/smartplaylistquerywizardplugin.h +++ b/src/smartplaylists/smartplaylistquerywizardplugin.h @@ -23,7 +23,6 @@ #include "config.h" -#include #include #include "core/scoped_ptr.h" @@ -35,6 +34,7 @@ class QWizard; class CollectionBackend; class SmartPlaylistSearch; +class SmartPlaylistQueryWizardPluginSearchPage; class Ui_SmartPlaylistQuerySortPage; class SmartPlaylistQueryWizardPlugin : public SmartPlaylistWizardPlugin { @@ -53,6 +53,9 @@ class SmartPlaylistQueryWizardPlugin : public SmartPlaylistWizardPlugin { void SetGenerator(PlaylistGeneratorPtr) override; PlaylistGeneratorPtr CreateGenerator() const override; + public Q_SLOTS: + void UpdateSortPreview(); + private Q_SLOTS: void AddSearchTerm(); void RemoveSearchTerm(); @@ -60,19 +63,15 @@ class SmartPlaylistQueryWizardPlugin : public SmartPlaylistWizardPlugin { void SearchTypeChanged(); void UpdateTermPreview(); - void UpdateSortPreview(); void UpdateSortOrder(); void MoveTermListToBottom(const int min, const int max); private: - class SearchPage; - class SortPage; - SmartPlaylistSearch MakeSearch() const; ScopedPtr sort_ui_; - SearchPage *search_page_; + SmartPlaylistQueryWizardPluginSearchPage *search_page_; int previous_scrollarea_max_; }; diff --git a/src/smartplaylists/smartplaylistquerywizardpluginsearchpage.cpp b/src/smartplaylists/smartplaylistquerywizardpluginsearchpage.cpp new file mode 100644 index 000000000..71c612bfe --- /dev/null +++ b/src/smartplaylists/smartplaylistquerywizardpluginsearchpage.cpp @@ -0,0 +1,45 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#include + +#include "smartplaylistquerywizardpluginsearchpage.h" +#include "smartplaylistsearchtermwidget.h" +#include "ui_smartplaylistquerysearchpage.h" + +SmartPlaylistQueryWizardPluginSearchPage::SmartPlaylistQueryWizardPluginSearchPage(QWidget *parent) + : QWizardPage(parent), + layout_(nullptr), + new_term_(nullptr), + preview_(nullptr), + ui_(new Ui_SmartPlaylistQuerySearchPage) { + + ui_->setupUi(this); + +} + +bool SmartPlaylistQueryWizardPluginSearchPage::isComplete() const { + + if (ui_->type->currentIndex() == 2) { // All songs + return true; + } + return !std::any_of(terms_.begin(), terms_.end(), [](SmartPlaylistSearchTermWidget *widget) { return !widget->Term().is_valid(); }); + +} diff --git a/src/smartplaylists/smartplaylistquerywizardpluginsearchpage.h b/src/smartplaylists/smartplaylistquerywizardpluginsearchpage.h new file mode 100644 index 000000000..9b635cb15 --- /dev/null +++ b/src/smartplaylists/smartplaylistquerywizardpluginsearchpage.h @@ -0,0 +1,55 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#ifndef SMARTPLAYLISTQUERYWIZARDPLUGINSEARCHPAGE_H +#define SMARTPLAYLISTQUERYWIZARDPLUGINSEARCHPAGE_H + +#include + +#include "core/scoped_ptr.h" + +#include "ui_smartplaylistquerysearchpage.h" + +class QVBoxLayout; + +class SmartPlaylistSearchTermWidget; +class SmartPlaylistSearchPreview; + +class SmartPlaylistQueryWizardPluginSearchPage : public QWizardPage { + Q_OBJECT + + friend class SmartPlaylistQueryWizardPlugin; + + public: + explicit SmartPlaylistQueryWizardPluginSearchPage(QWidget *parent = nullptr); + + bool isComplete() const override; + + private: + QVBoxLayout *layout_; + QList terms_; + SmartPlaylistSearchTermWidget *new_term_; + + SmartPlaylistSearchPreview *preview_; + + ScopedPtr ui_; +}; + +#endif // SMARTPLAYLISTQUERYWIZARDPLUGINSEARCHPAGE_H diff --git a/src/smartplaylists/smartplaylistquerywizardpluginsortpage.cpp b/src/smartplaylists/smartplaylistquerywizardpluginsortpage.cpp new file mode 100644 index 000000000..6ae026c93 --- /dev/null +++ b/src/smartplaylists/smartplaylistquerywizardpluginsortpage.cpp @@ -0,0 +1,35 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#include "smartplaylistquerywizardplugin.h" +#include "smartplaylistquerywizardpluginsortpage.h" + +SmartPlaylistQueryWizardPluginSortPage::SmartPlaylistQueryWizardPluginSortPage(SmartPlaylistQueryWizardPlugin *plugin, QWidget *parent, const int next_id) + : QWizardPage(parent), next_id_(next_id), plugin_(plugin) {} + +void SmartPlaylistQueryWizardPluginSortPage::showEvent(QShowEvent *e) { + + Q_UNUSED(e) + + plugin_->UpdateSortPreview(); + +} + +int SmartPlaylistQueryWizardPluginSortPage::nextId() const { return next_id_; } diff --git a/src/smartplaylists/smartplaylistquerywizardpluginsortpage.h b/src/smartplaylists/smartplaylistquerywizardpluginsortpage.h new file mode 100644 index 000000000..8e999d04f --- /dev/null +++ b/src/smartplaylists/smartplaylistquerywizardpluginsortpage.h @@ -0,0 +1,45 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#ifndef SMARTPLAYLISTQUERYWIZARDPLUGINSORTPAGE_H +#define SMARTPLAYLISTQUERYWIZARDPLUGINSORTPAGE_H + +#include + +class QShowEvent; +class SmartPlaylistQueryWizardPlugin; + +class SmartPlaylistQueryWizardPluginSortPage : public QWizardPage { + Q_OBJECT + + public: + explicit SmartPlaylistQueryWizardPluginSortPage(SmartPlaylistQueryWizardPlugin *plugin, QWidget *parent, const int next_id); + + void showEvent(QShowEvent *e) override; + + int nextId() const override; + + private: + int next_id_; + + SmartPlaylistQueryWizardPlugin *plugin_; +}; + +#endif // SMARTPLAYLISTQUERYWIZARDPLUGINSORTPAGE_H diff --git a/src/smartplaylists/smartplaylistsearchtermwidget.cpp b/src/smartplaylists/smartplaylistsearchtermwidget.cpp index 5f7241024..8ee71d6a7 100644 --- a/src/smartplaylists/smartplaylistsearchtermwidget.cpp +++ b/src/smartplaylists/smartplaylistsearchtermwidget.cpp @@ -20,19 +20,16 @@ #include "config.h" -#include #include #include #include -#include -#include -#include -#include #include #include #include -#include +#include #include +#include +#include #include "core/shared_ptr.h" #include "core/iconloader.h" @@ -41,39 +38,9 @@ #include "playlist/playlistdelegates.h" #include "smartplaylistsearchterm.h" #include "smartplaylistsearchtermwidget.h" +#include "smartplaylistsearchtermwidgetoverlay.h" #include "ui_smartplaylistsearchtermwidget.h" -// Exported by QtGui -void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0); - -class SmartPlaylistSearchTermWidget::Overlay : public QWidget { // clazy:exclude=missing-qobject-macro - public: - explicit Overlay(SmartPlaylistSearchTermWidget *parent); - void Grab(); - void SetOpacity(const float opacity); - float opacity() const { return opacity_; } - - static const int kSpacing; - static const int kIconSize; - - protected: - void paintEvent(QPaintEvent*) override; - void mouseReleaseEvent(QMouseEvent*) override; - void keyReleaseEvent(QKeyEvent *e) override; - - private: - SmartPlaylistSearchTermWidget *parent_; - - float opacity_; - QString text_; - QPixmap pixmap_; - QPixmap icon_; - -}; - -const int SmartPlaylistSearchTermWidget::Overlay::kSpacing = 6; -const int SmartPlaylistSearchTermWidget::Overlay::kIconSize = 22; - SmartPlaylistSearchTermWidget::SmartPlaylistSearchTermWidget(SharedPtr collection_backend, QWidget *parent) : QWidget(parent), ui_(new Ui_SmartPlaylistSearchTermWidget), @@ -259,17 +226,19 @@ void SmartPlaylistSearchTermWidget::SetActive(bool active) { ui_->container->setEnabled(active); if (!active) { - overlay_ = new Overlay(this); + overlay_ = new SmartPlaylistSearchTermWidgetOverlay(this); } } #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -void SmartPlaylistSearchTermWidget::enterEvent(QEnterEvent*) { +void SmartPlaylistSearchTermWidget::enterEvent(QEnterEvent *e) { #else -void SmartPlaylistSearchTermWidget::enterEvent(QEvent*) { +void SmartPlaylistSearchTermWidget::enterEvent(QEvent *e) { #endif + Q_UNUSED(e) + if (!overlay_ || !isEnabled()) return; animation_->stop(); @@ -279,7 +248,9 @@ void SmartPlaylistSearchTermWidget::enterEvent(QEvent*) { } -void SmartPlaylistSearchTermWidget::leaveEvent(QEvent*) { +void SmartPlaylistSearchTermWidget::leaveEvent(QEvent *e) { + + Q_UNUSED(e); if (!overlay_) return; @@ -293,6 +264,7 @@ void SmartPlaylistSearchTermWidget::leaveEvent(QEvent*) { void SmartPlaylistSearchTermWidget::resizeEvent(QResizeEvent *e) { QWidget::resizeEvent(e); + if (overlay_ && overlay_->isVisible()) { QMetaObject::invokeMethod(this, &SmartPlaylistSearchTermWidget::Grab); } @@ -425,86 +397,3 @@ void SmartPlaylistSearchTermWidget::RelativeValueChanged() { Q_EMIT Changed(); } - -SmartPlaylistSearchTermWidget::Overlay::Overlay(SmartPlaylistSearchTermWidget *parent) - : QWidget(parent), - parent_(parent), - opacity_(0.0), - text_(tr("Add search term")), - icon_(IconLoader::Load(QStringLiteral("list-add")).pixmap(kIconSize)) { - - raise(); - setFocusPolicy(Qt::TabFocus); - -} - -void SmartPlaylistSearchTermWidget::Overlay::SetOpacity(const float opacity) { - - opacity_ = opacity; - update(); - -} - -void SmartPlaylistSearchTermWidget::Overlay::Grab() { - - hide(); - - // Take a "screenshot" of the window - QPixmap pixmap = parent_->grab(); - QImage image = pixmap.toImage(); - - // Blur it - QImage blurred(image.size(), QImage::Format_ARGB32_Premultiplied); - blurred.fill(Qt::transparent); - - QPainter blur_painter(&blurred); - qt_blurImage(&blur_painter, image, 10.0, true, false); - blur_painter.end(); - - pixmap_ = QPixmap::fromImage(blurred); - - resize(parent_->size()); - show(); - update(); - -} - -void SmartPlaylistSearchTermWidget::Overlay::paintEvent(QPaintEvent*) { - - QPainter p(this); - - // Background - p.fillRect(rect(), palette().window()); - - // Blurred parent widget - p.setOpacity(0.25 + opacity_ * 0.25); - p.drawPixmap(0, 0, pixmap_); - - // Draw a frame - p.setOpacity(1.0); - p.setPen(palette().color(QPalette::Mid)); - p.setRenderHint(QPainter::Antialiasing); - p.drawRoundedRect(rect(), 5, 5); - - // Geometry - - const QSize contents_size(kIconSize + kSpacing + fontMetrics().horizontalAdvance(text_), qMax(kIconSize, fontMetrics().height())); - - const QRect contents(QPoint((width() - contents_size.width()) / 2, (height() - contents_size.height()) / 2), contents_size); - const QRect icon(contents.topLeft(), QSize(kIconSize, kIconSize)); - const QRect text(icon.right() + kSpacing, icon.top(), contents.width() - kSpacing - kIconSize, contents.height()); - - // Icon and text - p.setPen(palette().color(QPalette::Text)); - p.drawPixmap(icon, icon_); - p.drawText(text, Qt::TextDontClip | Qt::AlignVCenter, text_); // NOLINT(bugprone-suspicious-enum-usage) - -} - -void SmartPlaylistSearchTermWidget::Overlay::mouseReleaseEvent(QMouseEvent*) { - Q_EMIT parent_->Clicked(); -} - -void SmartPlaylistSearchTermWidget::Overlay::keyReleaseEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Space) Q_EMIT parent_->Clicked(); -} diff --git a/src/smartplaylists/smartplaylistsearchtermwidget.h b/src/smartplaylists/smartplaylistsearchtermwidget.h index 8efd3c9a9..d1e185770 100644 --- a/src/smartplaylists/smartplaylistsearchtermwidget.h +++ b/src/smartplaylists/smartplaylistsearchtermwidget.h @@ -37,6 +37,7 @@ class QResizeEvent; class CollectionBackend; class Ui_SmartPlaylistSearchTermWidget; +class SmartPlaylistSearchTermWidgetOverlay; class SmartPlaylistSearchTermWidget : public QWidget { Q_OBJECT @@ -78,13 +79,10 @@ class SmartPlaylistSearchTermWidget : public QWidget { void Grab(); private: - class Overlay; - friend class Overlay; - Ui_SmartPlaylistSearchTermWidget *ui_; SharedPtr collection_backend_; - Overlay *overlay_; + SmartPlaylistSearchTermWidgetOverlay *overlay_; QPropertyAnimation *animation_; bool active_; bool initialized_; diff --git a/src/smartplaylists/smartplaylistsearchtermwidgetoverlay.cpp b/src/smartplaylists/smartplaylistsearchtermwidgetoverlay.cpp new file mode 100644 index 000000000..3303bb84c --- /dev/null +++ b/src/smartplaylists/smartplaylistsearchtermwidgetoverlay.cpp @@ -0,0 +1,130 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "core/iconloader.h" +#include "smartplaylistsearchterm.h" +#include "smartplaylistsearchtermwidget.h" +#include "smartplaylistsearchtermwidgetoverlay.h" + +const int SmartPlaylistSearchTermWidgetOverlay::kSpacing = 6; +const int SmartPlaylistSearchTermWidgetOverlay::kIconSize = 22; + +// Exported by QtGui +void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0); + +SmartPlaylistSearchTermWidgetOverlay::SmartPlaylistSearchTermWidgetOverlay(SmartPlaylistSearchTermWidget *parent) + : QWidget(parent), + parent_(parent), + opacity_(0.0), + text_(tr("Add search term")), + icon_(IconLoader::Load(QStringLiteral("list-add")).pixmap(kIconSize)) { + + raise(); + setFocusPolicy(Qt::TabFocus); + +} + +void SmartPlaylistSearchTermWidgetOverlay::Grab() { + + hide(); + + // Take a "screenshot" of the window + QPixmap pixmap = parent_->grab(); + QImage image = pixmap.toImage(); + + // Blur it + QImage blurred(image.size(), QImage::Format_ARGB32_Premultiplied); + blurred.fill(Qt::transparent); + + QPainter blur_painter(&blurred); + qt_blurImage(&blur_painter, image, 10.0, true, false); + blur_painter.end(); + + pixmap_ = QPixmap::fromImage(blurred); + + resize(parent_->size()); + show(); + update(); + +} + +void SmartPlaylistSearchTermWidgetOverlay::SetOpacity(const float opacity) { + + opacity_ = opacity; + update(); + +} + +void SmartPlaylistSearchTermWidgetOverlay::paintEvent(QPaintEvent*) { + + QPainter p(this); + + // Background + p.fillRect(rect(), palette().window()); + + // Blurred parent widget + p.setOpacity(0.25 + opacity_ * 0.25); + p.drawPixmap(0, 0, pixmap_); + + // Draw a frame + p.setOpacity(1.0); + p.setPen(palette().color(QPalette::Mid)); + p.setRenderHint(QPainter::Antialiasing); + p.drawRoundedRect(rect(), 5, 5); + + // Geometry + + const QSize contents_size(kIconSize + kSpacing + fontMetrics().horizontalAdvance(text_), qMax(kIconSize, fontMetrics().height())); + + const QRect contents(QPoint((width() - contents_size.width()) / 2, (height() - contents_size.height()) / 2), contents_size); + const QRect icon(contents.topLeft(), QSize(kIconSize, kIconSize)); + const QRect text(icon.right() + kSpacing, icon.top(), contents.width() - kSpacing - kIconSize, contents.height()); + + // Icon and text + p.setPen(palette().color(QPalette::Text)); + p.drawPixmap(icon, icon_); + p.drawText(text, Qt::TextDontClip | Qt::AlignVCenter, text_); // NOLINT(bugprone-suspicious-enum-usage) + +} + +void SmartPlaylistSearchTermWidgetOverlay::mouseReleaseEvent(QMouseEvent *e) { + + Q_UNUSED(e) + Q_EMIT parent_->Clicked(); + +} + +void SmartPlaylistSearchTermWidgetOverlay::keyReleaseEvent(QKeyEvent *e) { + + if (e->key() == Qt::Key_Space) { + Q_EMIT parent_->Clicked(); + } + +} + +float SmartPlaylistSearchTermWidgetOverlay::opacity() const { return opacity_; } diff --git a/src/smartplaylists/smartplaylistsearchtermwidgetoverlay.h b/src/smartplaylists/smartplaylistsearchtermwidgetoverlay.h new file mode 100644 index 000000000..45c64458f --- /dev/null +++ b/src/smartplaylists/smartplaylistsearchtermwidgetoverlay.h @@ -0,0 +1,61 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#ifndef SMARTPLAYLISTSEARCHTERMWIDGETOVERLAY_H +#define SMARTPLAYLISTSEARCHTERMWIDGETOVERLAY_H + +#include +#include +#include + +class QPaintEvent; +class QMouseEvent; +class QKeyEvent; + +class SmartPlaylistSearchTermWidget; + +class SmartPlaylistSearchTermWidgetOverlay : public QWidget { + Q_OBJECT + + public: + explicit SmartPlaylistSearchTermWidgetOverlay(SmartPlaylistSearchTermWidget *parent); + + static const int kSpacing; + static const int kIconSize; + + void Grab(); + void SetOpacity(const float opacity); + float opacity() const; + + protected: + void paintEvent(QPaintEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void keyReleaseEvent(QKeyEvent *e) override; + + private: + SmartPlaylistSearchTermWidget *parent_; + + float opacity_; + QString text_; + QPixmap pixmap_; + QPixmap icon_; +}; + +#endif // SMARTPLAYLISTSEARCHTERMWIDGETOVERLAY_H diff --git a/src/smartplaylists/smartplaylistwizard.cpp b/src/smartplaylists/smartplaylistwizard.cpp index 574aa2391..a5f0a2926 100644 --- a/src/smartplaylists/smartplaylistwizard.cpp +++ b/src/smartplaylists/smartplaylistwizard.cpp @@ -34,38 +34,16 @@ #include "smartplaylistquerywizardplugin.h" #include "smartplaylistwizard.h" #include "smartplaylistwizardplugin.h" +#include "smartplaylistwizardtypepage.h" +#include "smartplaylistwizardfinishpage.h" #include "ui_smartplaylistwizardfinishpage.h" -class SmartPlaylistWizard::TypePage : public QWizardPage { // clazy:exclude=missing-qobject-macro - public: - explicit TypePage(QWidget *parent) : QWizardPage(parent), next_id_(-1) {} - - int nextId() const override { return next_id_; } - int next_id_; -}; - -class SmartPlaylistWizard::FinishPage : public QWizardPage { // clazy:exclude=missing-qobject-macro - public: - explicit FinishPage(QWidget *parent) : QWizardPage(parent), ui_(new Ui_SmartPlaylistWizardFinishPage) { - ui_->setupUi(this); - QObject::connect(ui_->name, &QLineEdit::textChanged, this, &SmartPlaylistWizard::FinishPage::completeChanged); - } - - ~FinishPage() override { delete ui_; } - - int nextId() const override { return -1; } - bool isComplete() const override { return !ui_->name->text().isEmpty(); } - - Ui_SmartPlaylistWizardFinishPage *ui_; - -}; - SmartPlaylistWizard::SmartPlaylistWizard(Application *app, SharedPtr collection_backend, QWidget *parent) : QWizard(parent), app_(app), collection_backend_(collection_backend), - type_page_(new TypePage(this)), - finish_page_(new FinishPage(this)), + type_page_(new SmartPlaylistWizardTypePage(this)), + finish_page_(new SmartPlaylistWizardFinishPage(this)), type_index_(-1) { setWindowIcon(IconLoader::Load(QStringLiteral("strawberry"))); diff --git a/src/smartplaylists/smartplaylistwizard.h b/src/smartplaylists/smartplaylistwizard.h index c63475e38..4a330c130 100644 --- a/src/smartplaylists/smartplaylistwizard.h +++ b/src/smartplaylists/smartplaylistwizard.h @@ -32,6 +32,8 @@ class Application; class CollectionBackend; class SmartPlaylistWizardPlugin; +class SmartPlaylistWizardTypePage; +class SmartPlaylistWizardFinishPage; class SmartPlaylistWizard : public QWizard { Q_OBJECT @@ -47,9 +49,6 @@ class SmartPlaylistWizard : public QWizard { void initializePage(const int id) override; private: - class TypePage; - class FinishPage; - void AddPlugin(SmartPlaylistWizardPlugin *plugin); private Q_SLOTS: @@ -58,8 +57,8 @@ class SmartPlaylistWizard : public QWizard { private: Application *app_; SharedPtr collection_backend_; - TypePage *type_page_; - FinishPage *finish_page_; + SmartPlaylistWizardTypePage *type_page_; + SmartPlaylistWizardFinishPage *finish_page_; int finish_id_; int type_index_; diff --git a/src/smartplaylists/smartplaylistwizardfinishpage.cpp b/src/smartplaylists/smartplaylistwizardfinishpage.cpp new file mode 100644 index 000000000..70f379163 --- /dev/null +++ b/src/smartplaylists/smartplaylistwizardfinishpage.cpp @@ -0,0 +1,34 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#include "smartplaylistwizardfinishpage.h" +#include "ui_smartplaylistwizardfinishpage.h" + +SmartPlaylistWizardFinishPage::SmartPlaylistWizardFinishPage(QWidget *parent) : QWizardPage(parent), ui_(new Ui_SmartPlaylistWizardFinishPage) { + + ui_->setupUi(this); + QObject::connect(ui_->name, &QLineEdit::textChanged, this, &SmartPlaylistWizardFinishPage::completeChanged); + +} + +SmartPlaylistWizardFinishPage::~SmartPlaylistWizardFinishPage() { delete ui_; } + +int SmartPlaylistWizardFinishPage::nextId() const { return -1; } +bool SmartPlaylistWizardFinishPage::isComplete() const { return !ui_->name->text().isEmpty(); } diff --git a/src/smartplaylists/smartplaylistwizardfinishpage.h b/src/smartplaylists/smartplaylistwizardfinishpage.h new file mode 100644 index 000000000..52f340e1f --- /dev/null +++ b/src/smartplaylists/smartplaylistwizardfinishpage.h @@ -0,0 +1,42 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#ifndef SMARTPLAYLISTWIZARDFINISHPAGE_H +#define SMARTPLAYLISTWIZARDFINISHPAGE_H + +#include + +class Ui_SmartPlaylistWizardFinishPage; + +class SmartPlaylistWizardFinishPage : public QWizardPage { + Q_OBJECT + + public: + explicit SmartPlaylistWizardFinishPage(QWidget *parent); + ~SmartPlaylistWizardFinishPage() override; + + int nextId() const override; + bool isComplete() const override; + + Ui_SmartPlaylistWizardFinishPage *ui_; +}; + +#endif // SMARTPLAYLISTWIZARDFINISHPAGE_H + diff --git a/src/smartplaylists/smartplaylistwizardtypepage.cpp b/src/smartplaylists/smartplaylistwizardtypepage.cpp new file mode 100644 index 000000000..86d303a86 --- /dev/null +++ b/src/smartplaylists/smartplaylistwizardtypepage.cpp @@ -0,0 +1,25 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#include "smartplaylistwizardtypepage.h" + +SmartPlaylistWizardTypePage::SmartPlaylistWizardTypePage(QWidget *parent) : QWizardPage(parent), next_id_(-1) {} + +int SmartPlaylistWizardTypePage::nextId() const { return next_id_; } diff --git a/src/smartplaylists/smartplaylistwizardtypepage.h b/src/smartplaylists/smartplaylistwizardtypepage.h new file mode 100644 index 000000000..5fa1caa38 --- /dev/null +++ b/src/smartplaylists/smartplaylistwizardtypepage.h @@ -0,0 +1,37 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * + * 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 . + * + */ + +#ifndef SMARTPLAYLISTWIZARDTYPEPAGE_H +#define SMARTPLAYLISTWIZARDTYPEPAGE_H + +#include + +class SmartPlaylistWizardTypePage : public QWizardPage { + Q_OBJECT + + public: + explicit SmartPlaylistWizardTypePage(QWidget *parent); + + int nextId() const override; + int next_id_; +}; + +#endif // SMARTPLAYLISTWIZARDTYPEPAGE_H +