From acb75a50992f84e152b493b537b0be8511a61d1a Mon Sep 17 00:00:00 2001 From: dmdmdm Date: Sun, 26 Jul 2020 14:41:46 -0400 Subject: [PATCH] Share the love --- src/ui/lovedialog.cpp | 79 ++++++++++++++++++++++ src/ui/lovedialog.h | 59 ++++++++++++++++ src/ui/lovedialog.ui | 152 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 290 insertions(+) create mode 100644 src/ui/lovedialog.cpp create mode 100644 src/ui/lovedialog.h create mode 100644 src/ui/lovedialog.ui diff --git a/src/ui/lovedialog.cpp b/src/ui/lovedialog.cpp new file mode 100644 index 000000000..d4e04b128 --- /dev/null +++ b/src/ui/lovedialog.cpp @@ -0,0 +1,79 @@ +/* This file is part of Clementine. + Copyright 2020, Dave McKellar + + Clementine 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. + + Clementine 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 Clementine. If not, see . +*/ + +#include "ui/lovedialog.h" +#include "ui_lovedialog.h" + +#include +#include + +#include "core/application.h" +#include "core/logging.h" +#include "core/utilities.h" +#include "library/librarybackend.h" + +const char* LoveDialog::kSettingsGroup = "LoveDialog"; + +LoveDialog::LoveDialog(Application* app, QWidget* parent) + : QDialog(parent), + ui_(new Ui_LoveDialog), + app_(app) +{ + ui_->setupUi(this); + + connect(ui_->button_box, SIGNAL(clicked(QAbstractButton*)), + SLOT(ButtonClicked(QAbstractButton*))); + connect(ui_->rating, SIGNAL(RatingChanged(float)), SLOT(SongRated(float))); +} + +LoveDialog::~LoveDialog() { delete ui_; } + +void LoveDialog::SetSong(const Song& song) { + song_ = song; + QString summary = "" + song.PrettyTitleWithArtist().toHtmlEscaped() + ""; + ui_->summary->setText(summary); + ui_->rating->set_rating(song.rating()); +} + +void LoveDialog::ButtonClicked(QAbstractButton* button) { + if (button == ui_->button_box->button(QDialogButtonBox::Cancel)) { + reject(); + } +} + +void LoveDialog::showEvent(QShowEvent* e) { + // Set the dialog's height to the smallest possible + resize(width(), sizeHint().height()); + + // Restore the tab that was current last time. + QSettings s; + s.beginGroup(kSettingsGroup); + + QDialog::showEvent(e); +} + +void LoveDialog::SongRated(float rating) { + qLog(Debug) << "LoveDialog::SongRated: rating=" << rating; + Song* song = &song_; + qLog(Debug) << "LoveDialog::SongRated: isValid=" << song->is_valid() << " id=" << song->id(); + if (!song->is_valid() || song->id() == -1) return; + + qLog(Debug) << "LoveDialog::SongRated: song is valid and id is good"; + song->set_rating(rating); + app_->library_backend()->UpdateSongRatingAsync(song->id(), rating); + QDialog::accept(); +} diff --git a/src/ui/lovedialog.h b/src/ui/lovedialog.h new file mode 100644 index 000000000..0e180f695 --- /dev/null +++ b/src/ui/lovedialog.h @@ -0,0 +1,59 @@ +/* This file is part of Clementine. + Copyright 2020, Dave McKellar + + Clementine 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. + + Clementine 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 Clementine. If not, see . +*/ + +#ifndef LOVE_DIALOG_H +#define LOVE_DIALOG_H + +#include + +#include "core/song.h" +//#include "widgets/lineedit.h" + +class Application; +class Ui_LoveDialog; + +class QAbstractButton; +class QLabel; + +class LoveDialog : public QDialog { + Q_OBJECT + + public: + LoveDialog(Application* app, QWidget* parent = nullptr); + ~LoveDialog(); + + static const char* kSettingsGroup; + + void SetSong(const Song&); + +signals: + void Error(const QString& message); + + protected: + void showEvent(QShowEvent*); + + private slots: + void ButtonClicked(QAbstractButton* button); + void SongRated(float rating); + + private: + Ui_LoveDialog* ui_; + Application* app_; + Song song_; +}; + +#endif diff --git a/src/ui/lovedialog.ui b/src/ui/lovedialog.ui new file mode 100644 index 000000000..ef120148c --- /dev/null +++ b/src/ui/lovedialog.ui @@ -0,0 +1,152 @@ + + + LoveDialog + + + + 0 + 0 + 400 + 400 + + + + + 0 + 0 + + + + + 200 + 300 + + + + + 400 + 400 + + + + Quickly rate the playing track + + + + :/icon.png:/icon.png + + + + + + + + QTextEdit { + background: transparent; +} + + + QFrame::NoFrame + + + + + + + Qt::Horizontal + + + + + + + 18 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + QDialogButtonBox::Cancel + + + + + + + + RatingWidget + QWidget +
widgets/ratingwidget.h
+ 1 +
+
+ + + + + + button_box + accepted() + LoveDialog + accept() + + + 65 + 552 + + + 84 + 533 + + + + + button_box + rejected() + LoveDialog + reject() + + + 236 + 542 + + + 242 + 532 + + + + +