From bdd1e97d4f3a8b294a0691a7631c60cf24fffa90 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Wed, 29 Apr 2020 22:13:09 +0200 Subject: Add modinfodialog Notes Tab color selector. --- src/modinfodialog.ui | 40 ++++++++++++++++++++++++++---------- src/modinfodialogtab.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++- src/modinfodialogtab.h | 9 +++++--- 3 files changed, 87 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/modinfodialog.ui b/src/modinfodialog.ui index 869ae04e..f035d93b 100644 --- a/src/modinfodialog.ui +++ b/src/modinfodialog.ui @@ -1204,17 +1204,35 @@ p, li { white-space: pre-wrap; } - - - Enter comments about the mod here. These are displayed in the notes column of the mod list. - - - Enter comments about the mod here. These are displayed in the notes column of the mod list. - - - Enter comments about the mod here. These are displayed in the notes column of the mod list. - - + + + + + Enter comments about the mod here. These are displayed in the notes column of the mod list. + + + Enter comments about the mod here. These are displayed in the notes column of the mod list. + + + Enter comments about the mod here. These are displayed in the notes column of the mod list. + + + + + + + Set Color + + + + + + + Reset Color + + + + diff --git a/src/modinfodialogtab.cpp b/src/modinfodialogtab.cpp index d662e2b2..f795cdf9 100644 --- a/src/modinfodialogtab.cpp +++ b/src/modinfodialogtab.cpp @@ -154,12 +154,29 @@ NotesTab::NotesTab(ModInfoDialogTabContext cx) { connect(ui->comments, &QLineEdit::editingFinished, [&]{ onComments(); }); connect(ui->notes, &HTMLEditor::editingFinished, [&]{ onNotes(); }); + connect(ui->setColorButton, &QPushButton::clicked, [&] { onSetColor(); }); + connect(ui->resetColorButton, &QPushButton::clicked, [&] { onResetColor(); }); +} + +void NotesTab::updateCommentsColor(bool clear) +{ + QPalette commentPalette = QPalette(); + + if (!clear) { + auto modColor = mod().getColor(); + if (modColor.isValid()) { + commentPalette.setColor(QPalette::Base, modColor); + commentPalette.setColor(QPalette::Text, ColorSettings::idealTextColor(modColor)); + } + } + ui->comments->setPalette(commentPalette); } void NotesTab::clear() { ui->comments->clear(); ui->notes->clear(); + updateCommentsColor(true); setHasData(false); } @@ -170,6 +187,7 @@ void NotesTab::update() ui->comments->setText(comments); ui->notes->setText(notes); + updateCommentsColor(); checkHasData(); } @@ -196,6 +214,38 @@ void NotesTab::onNotes() checkHasData(); } +void NotesTab::onSetColor() +{ + QColorDialog dialog(m_parent); + dialog.setOption(QColorDialog::ShowAlphaChannel); + + QColor currentColor = mod().getColor(); + + if (currentColor.isValid()) { + dialog.setCurrentColor(currentColor); + } + + if (!dialog.exec()) + return; + + currentColor = dialog.currentColor(); + if (!currentColor.isValid()) + return; + + mod().setColor(currentColor); + updateCommentsColor(); + checkHasData(); +} + +void NotesTab::onResetColor() +{ + QColor color = QColor(); + + mod().setColor(color); + updateCommentsColor(); + checkHasData(); +} + bool NotesTab::usesOriginFiles() const { return false; @@ -205,5 +255,6 @@ void NotesTab::checkHasData() { setHasData( !ui->comments->text().isEmpty() || - !ui->notes->toPlainText().isEmpty()); + !ui->notes->toPlainText().isEmpty() || + mod().getColor().isValid()); } diff --git a/src/modinfodialogtab.h b/src/modinfodialogtab.h index d0a58574..7a42bf7e 100644 --- a/src/modinfodialogtab.h +++ b/src/modinfodialogtab.h @@ -253,6 +253,9 @@ protected: // void setFocus(); + // parent widget, used to display modal dialogs + QWidget* m_parent; + private: // core OrganizerCore& m_core; @@ -260,9 +263,6 @@ private: // plugin PluginContainer& m_plugin; - // parent widget, used to display modal dialogs - QWidget* m_parent; - // current mod, never null ModInfoPtr m_mod; @@ -299,8 +299,11 @@ public: bool usesOriginFiles() const override; private: + void updateCommentsColor(bool clear = false); void onComments(); void onNotes(); + void onSetColor(); + void onResetColor(); void checkHasData(); }; -- cgit v1.3.1