diff --git a/src/dialogs/edittagdialog.cpp b/src/dialogs/edittagdialog.cpp index 7b4e0695b..adabcb5d6 100644 --- a/src/dialogs/edittagdialog.cpp +++ b/src/dialogs/edittagdialog.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -156,6 +157,9 @@ EditTagDialog::EditTagDialog(Application *app, QWidget *parent) else if (qobject_cast(widget)) { connect(widget, SIGNAL(valueChanged(int)), SLOT(FieldValueEdited())); } + else if (qobject_cast(widget)) { + connect(widget, SIGNAL(stateChanged(int)), SLOT(FieldValueEdited())); + } } } @@ -275,6 +279,7 @@ QList EditTagDialog::LoadData(const SongList &songs) const } return ret; + } void EditTagDialog::SetSongs(const SongList &s, const PlaylistItemList &items) { @@ -325,9 +330,11 @@ void EditTagDialog::SetSongsFinished(QFuture> future) { } void EditTagDialog::SetSongListVisibility(bool visible) { + ui_->song_list->setVisible(visible); previous_button_->setEnabled(visible); next_button_->setEnabled(visible); + } QVariant EditTagDialog::Data::value(const Song &song, const QString &id) { @@ -345,6 +352,7 @@ QVariant EditTagDialog::Data::value(const Song &song, const QString &id) { if (id == "track") return song.track(); if (id == "disc") return song.disc(); if (id == "year") return song.year(); + if (id == "compilation") return song.compilation(); qLog(Warning) << "Unknown ID" << id; return QVariant(); @@ -365,16 +373,19 @@ void EditTagDialog::Data::set_value(const QString &id, const QVariant &value) { else if (id == "track") current_.set_track(value.toInt()); else if (id == "disc") current_.set_disc(value.toInt()); else if (id == "year") current_.set_year(value.toInt()); + else if (id == "compilation") current_.set_compilation(value.toBool()); else qLog(Warning) << "Unknown ID" << id; } bool EditTagDialog::DoesValueVary(const QModelIndexList &sel, const QString &id) const { + QVariant value = data_[sel.first().row()].current_value(id); for (int i = 1; i < sel.count(); ++i) { if (value != data_[sel[i].row()].current_value(id)) return true; } return false; + } bool EditTagDialog::IsValueModified(const QModelIndexList &sel, const QString &id) const { @@ -396,11 +407,15 @@ void EditTagDialog::InitFieldValue(const FieldData &field, const QModelIndexList editor->clear_hint(); if (varies) { editor->set_hint(tr(EditTagDialog::kHintText)); + editor->set_partially(); } else { - editor->set_text(data_[sel[0].row()].current_value(field.id_).toString()); + editor->set_value(data_[sel[0].row()].current_value(field.id_)); } } + else { + qLog(Error) << "Missing editor for" << field.editor_->objectName(); + } UpdateModifiedField(field, sel); @@ -410,8 +425,12 @@ void EditTagDialog::UpdateFieldValue(const FieldData &field, const QModelIndexLi // Get the value from the field QVariant value; + if (ExtendedEditor *editor = dynamic_cast(field.editor_)) { - value = editor->text(); + value = editor->value(); + } + else { + qLog(Error) << "Missing editor for" << field.editor_->objectName(); } // Did we get it? @@ -654,6 +673,7 @@ void EditTagDialog::LoadCoverFromURL() { QUrl cover_url = album_cover_choice_controller_->LoadCoverFromURL(song); if (!cover_url.isEmpty()) UpdateCoverOf(*song, sel, cover_url); + } void EditTagDialog::SearchForCover() { @@ -666,6 +686,7 @@ void EditTagDialog::SearchForCover() { QUrl cover_url = album_cover_choice_controller_->SearchForCover(song); if (!cover_url.isEmpty()) UpdateCoverOf(*song, sel, cover_url); + } void EditTagDialog::UnsetCover() { @@ -677,6 +698,7 @@ void EditTagDialog::UnsetCover() { QUrl cover_url = album_cover_choice_controller_->UnsetCover(song); UpdateCoverOf(*song, sel, cover_url); + } void EditTagDialog::ShowCover() { @@ -687,6 +709,7 @@ void EditTagDialog::ShowCover() { } album_cover_choice_controller_->ShowCover(*song); + } void EditTagDialog::UpdateCoverOf(const Song &selected, const QModelIndexList &sel, const QUrl &cover_url) { @@ -716,6 +739,7 @@ void EditTagDialog::NextSong() { int row = (ui_->song_list->currentRow() + 1) % ui_->song_list->count(); ui_->song_list->setCurrentRow(row); + } void EditTagDialog::PreviousSong() { @@ -726,12 +750,15 @@ void EditTagDialog::PreviousSong() { int row = (ui_->song_list->currentRow() - 1 + ui_->song_list->count()) % ui_->song_list->count(); ui_->song_list->setCurrentRow(row); + } void EditTagDialog::ButtonClicked(QAbstractButton *button) { + if (button == ui_->button_box->button(QDialogButtonBox::Discard)) { reject(); } + } void EditTagDialog::SaveData(const QList &tag_data) { @@ -802,6 +829,7 @@ bool EditTagDialog::eventFilter(QObject *o, QEvent *e) { } } return false; + } void EditTagDialog::showEvent(QShowEvent *e) { @@ -815,6 +843,7 @@ void EditTagDialog::showEvent(QShowEvent *e) { ui_->tab_widget->setCurrentIndex(s.value("current_tab").toInt()); QDialog::showEvent(e); + } void EditTagDialog::hideEvent(QHideEvent *e) { @@ -825,6 +854,7 @@ void EditTagDialog::hideEvent(QHideEvent *e) { s.setValue("current_tab", ui_->tab_widget->currentIndex()); QDialog::hideEvent(e); + } void EditTagDialog::ResetPlayCounts() { diff --git a/src/dialogs/edittagdialog.ui b/src/dialogs/edittagdialog.ui index 4427bad0f..a28359365 100644 --- a/src/dialogs/edittagdialog.ui +++ b/src/dialogs/edittagdialog.ui @@ -7,7 +7,7 @@ 0 0 863 - 645 + 671 @@ -30,7 +30,7 @@ - 0 + 1 @@ -150,7 +150,7 @@ 18 - + 0 @@ -194,7 +194,7 @@ - + 0 @@ -226,7 +226,7 @@ - + 0 @@ -252,7 +252,7 @@ - + 0 @@ -290,7 +290,7 @@ - + 0 @@ -316,7 +316,7 @@ - + 0 @@ -348,7 +348,7 @@ - + 0 @@ -380,7 +380,7 @@ - + 0 @@ -412,7 +412,7 @@ - + 0 @@ -447,7 +447,7 @@ - + 0 @@ -473,7 +473,7 @@ - + 0 @@ -499,7 +499,7 @@ - + File name @@ -580,6 +580,12 @@ + + + 80 + 0 + + Genre @@ -609,7 +615,13 @@ - + + + + 80 + 0 + + Title @@ -619,7 +631,13 @@ - + + + + 80 + 0 + + Grouping @@ -629,7 +647,13 @@ - + + + + 80 + 0 + + Album @@ -669,7 +693,13 @@ - + + + + 80 + 0 + + Album artist @@ -689,7 +719,13 @@ - + + + + 80 + 0 + + Composer @@ -699,7 +735,13 @@ - + + + + 80 + 0 + + Comment @@ -719,7 +761,7 @@ - + Track @@ -755,7 +797,13 @@ - + + + + 80 + 0 + + Artist @@ -791,7 +839,7 @@ - + Year @@ -811,7 +859,13 @@ - + + + + 80 + 0 + + Performer @@ -822,6 +876,12 @@ + + + 80 + 0 + + Lyrics @@ -840,6 +900,32 @@ + + + + false + + + false + + + + + + + + 80 + 0 + + + + Compilation + + + compilation + + + @@ -878,6 +964,11 @@ QSpinBox
widgets/lineedit.h
+ + CheckBox + QCheckBox +
widgets/lineedit.h
+
song_list diff --git a/src/widgets/lineedit.cpp b/src/widgets/lineedit.cpp index 6eff359c3..7aaa1061f 100644 --- a/src/widgets/lineedit.cpp +++ b/src/widgets/lineedit.cpp @@ -71,19 +71,21 @@ ExtendedEditor::ExtendedEditor(QWidget *widget, int extra_right_padding, bool dr reset_button_->setFocusPolicy(Qt::NoFocus); reset_button_->hide(); - widget->connect(clear_button_, SIGNAL(clicked()), widget, SLOT(clear())); widget->connect(clear_button_, SIGNAL(clicked()), widget, SLOT(setFocus())); + if (qobject_cast(widget) || qobject_cast(widget) || qobject_cast(widget)) { + widget->connect(clear_button_, SIGNAL(clicked()), widget, SLOT(clear())); + } UpdateButtonGeometry(); } -void ExtendedEditor::set_hint(const QString& hint) { +void ExtendedEditor::set_hint(const QString &hint) { hint_ = hint; widget_->update(); } -void ExtendedEditor::set_clear_button(bool visible) { +void ExtendedEditor::set_clear_button(const bool visible) { has_clear_button_ = visible; clear_button_->setVisible(visible); UpdateButtonGeometry(); @@ -93,7 +95,7 @@ bool ExtendedEditor::has_reset_button() const { return reset_button_->isVisible(); } -void ExtendedEditor::set_reset_button(bool visible) { +void ExtendedEditor::set_reset_button(const bool visible) { reset_button_->setVisible(visible); UpdateButtonGeometry(); } @@ -161,7 +163,7 @@ LineEdit::LineEdit(QWidget *parent) : QLineEdit(parent), ExtendedEditor(this) { connect(this, SIGNAL(textChanged(QString)), SLOT(text_changed(QString))); } -void LineEdit::text_changed(const QString& text) { +void LineEdit::text_changed(const QString &text) { if (text.isEmpty()) { // Consider empty string as LTR @@ -222,8 +224,26 @@ void SpinBox::resizeEvent(QResizeEvent *e) { Resize(); } +CheckBox::CheckBox(QWidget *parent) + : QCheckBox(parent), ExtendedEditor(this, 14, false) +{ + connect(reset_button_, SIGNAL(clicked()), SIGNAL(Reset())); +} + +void CheckBox::paintEvent(QPaintEvent *e) { + QCheckBox::paintEvent(e); + Paint(this); +} + +void CheckBox::resizeEvent(QResizeEvent *e) { + QCheckBox::resizeEvent(e); + Resize(); +} + QString SpinBox::textFromValue(int val) const { + if (val <= 0 && !hint_.isEmpty()) return "-"; return QSpinBox::textFromValue(val); + } diff --git a/src/widgets/lineedit.h b/src/widgets/lineedit.h index 83470c3df..f999bf7eb 100644 --- a/src/widgets/lineedit.h +++ b/src/widgets/lineedit.h @@ -30,6 +30,7 @@ #include #include #include +#include class QToolButton; class QPaintDevice; @@ -37,6 +38,7 @@ class QPaintEvent; class QResizeEvent; class LineEditInterface { + public: explicit LineEditInterface(QWidget *widget) : widget_(widget) {} @@ -44,40 +46,43 @@ class LineEditInterface { virtual ~LineEditInterface() {} - virtual void clear() { set_text(QString()); } + virtual void set_enabled(const bool enabled) = 0; virtual void set_focus() = 0; - virtual QString text() const = 0; - virtual void set_text(const QString& text) = 0; + + virtual void clear() = 0; + virtual QVariant value() const = 0; + virtual void set_value(const QVariant &value) = 0; virtual QString hint() const = 0; - virtual void set_hint(const QString& hint) = 0; + virtual void set_hint(const QString &hint) = 0; virtual void clear_hint() = 0; - virtual void set_enabled(bool enabled) = 0; + virtual void set_partially() {} protected: QWidget *widget_; }; class ExtendedEditor : public LineEditInterface { + public: explicit ExtendedEditor(QWidget *widget, int extra_right_padding = 0, bool draw_hint = true); ~ExtendedEditor() override {} - virtual bool is_empty() const { return text().isEmpty(); } + virtual bool is_empty() const { return value().toString().isEmpty(); } QString hint() const override { return hint_; } - void set_hint(const QString& hint) override; + void set_hint(const QString &hint) override; void clear_hint() override { set_hint(QString()); } bool has_clear_button() const { return has_clear_button_; } - void set_clear_button(bool visible); + void set_clear_button(const bool visible); bool has_reset_button() const; - void set_reset_button(bool visible); + void set_reset_button(const bool visible); qreal font_point_size() const { return font_point_size_; } - void set_font_point_size(qreal size) { font_point_size_ = size; } + void set_font_point_size(const qreal size) { font_point_size_ = size; } protected: void Paint(QPaintDevice *device); @@ -111,10 +116,14 @@ class LineEdit : public QLineEdit, public ExtendedEditor { explicit LineEdit(QWidget *parent = nullptr); // ExtendedEditor - void set_focus() override { QLineEdit::setFocus(); } - QString text() const override { return QLineEdit::text(); } - void set_text(const QString& text) override { QLineEdit::setText(text); } void set_enabled(bool enabled) override { QLineEdit::setEnabled(enabled); } + void set_focus() override { QLineEdit::setFocus(); } + + QVariant value() const override { return QLineEdit::text(); } + void set_value(const QVariant &value) override { QLineEdit::setText(value.toString()); } + + public slots: + void clear() override { QLineEdit::clear(); } protected: void paintEvent(QPaintEvent*) override; @@ -125,7 +134,7 @@ class LineEdit : public QLineEdit, public ExtendedEditor { void set_rtl(bool rtl) { is_rtl_ = rtl; } private slots: - void text_changed(const QString& text); + void text_changed(const QString &text); signals: void Reset(); @@ -141,10 +150,14 @@ class TextEdit : public QPlainTextEdit, public ExtendedEditor { explicit TextEdit(QWidget *parent = nullptr); // ExtendedEditor - void set_focus() override { QPlainTextEdit::setFocus(); } - QString text() const override { return QPlainTextEdit::toPlainText(); } - void set_text(const QString& text) override { QPlainTextEdit::setPlainText(text); } void set_enabled(bool enabled) override { QPlainTextEdit::setEnabled(enabled); } + void set_focus() override { QPlainTextEdit::setFocus(); } + + QVariant value() const override { return QPlainTextEdit::toPlainText(); } + void set_value(const QVariant &value) override { QPlainTextEdit::setPlainText(value.toString()); } + + public slots: + void clear() override { QPlainTextEdit::clear(); } protected: void paintEvent(QPaintEvent*) override; @@ -167,11 +180,44 @@ class SpinBox : public QSpinBox, public ExtendedEditor { QString textFromValue(int val) const override; // ExtendedEditor - bool is_empty() const override { return text().isEmpty() || text() == "0"; } - void set_focus() override { QSpinBox::setFocus(); } - QString text() const override { return QSpinBox::text(); } - void set_text(const QString& text) override { QSpinBox::setValue(text.toInt()); } void set_enabled(bool enabled) override { QSpinBox::setEnabled(enabled); } + void set_focus() override { QSpinBox::setFocus(); } + + QVariant value() const override { return QSpinBox::value(); } + void set_value(const QVariant &value) override { QSpinBox::setValue(value.toInt()); } + bool is_empty() const override { return text().isEmpty() || text() == "0"; } + + public slots: + void clear() override { QSpinBox::clear(); } + + protected: + void paintEvent(QPaintEvent*) override; + void resizeEvent(QResizeEvent*) override; + + signals: + void Reset(); +}; + +class CheckBox : public QCheckBox, public ExtendedEditor { + Q_OBJECT + Q_PROPERTY(QString hint READ hint WRITE set_hint) + Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button) + Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button) + + public: + explicit CheckBox(QWidget *parent = nullptr); + + // ExtendedEditor + void set_enabled(bool enabled) override { QCheckBox::setEnabled(enabled); } + void set_focus() override { QCheckBox::setFocus(); } + + bool is_empty() const override { return text().isEmpty() || text() == "0"; } + QVariant value() const override { return QCheckBox::isChecked(); } + void set_value(const QVariant &value) override { QCheckBox::setCheckState(value.toBool() ? Qt::Checked : Qt::Unchecked); } + void set_partially() override { QCheckBox::setCheckState(Qt::PartiallyChecked); } + + public slots: + void clear() override { QCheckBox::setChecked(false); } protected: void paintEvent(QPaintEvent*) override;