Share the love

This commit is contained in:
dmdmdm 2020-07-26 14:41:46 -04:00 committed by John Maguire
parent 75264f314d
commit acb75a5099
3 changed files with 290 additions and 0 deletions

79
src/ui/lovedialog.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "ui/lovedialog.h"
#include "ui_lovedialog.h"
#include <QLabel>
#include <QPushButton>
#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 = "<b>" + song.PrettyTitleWithArtist().toHtmlEscaped() + "</b>";
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();
}

59
src/ui/lovedialog.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef LOVE_DIALOG_H
#define LOVE_DIALOG_H
#include <QDialog>
#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

152
src/ui/lovedialog.ui Normal file
View File

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LoveDialog</class>
<widget class="QDialog" name="LoveDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>400</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>300</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="windowTitle">
<string>Quickly rate the playing track</string>
</property>
<property name="windowIcon">
<iconset resource="../../data/data.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextEdit" name="summary">
<property name="styleSheet">
<string notr="true">QTextEdit {
background: transparent;
}</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0">
<property name="horizontalSpacing">
<number>18</number>
</property>
<item row="2" column="0">
<widget class="RatingWidget" name="rating" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>RatingWidget</class>
<extends>QWidget</extends>
<header>widgets/ratingwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../data/data.qrc"/>
</resources>
<connections>
<connection>
<sender>button_box</sender>
<signal>accepted()</signal>
<receiver>LoveDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>65</x>
<y>552</y>
</hint>
<hint type="destinationlabel">
<x>84</x>
<y>533</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_box</sender>
<signal>rejected()</signal>
<receiver>LoveDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>236</x>
<y>542</y>
</hint>
<hint type="destinationlabel">
<x>242</x>
<y>532</y>
</hint>
</hints>
</connection>
</connections>
</ui>