diff options
| author | Al <26797547+Al12rs@users.noreply.github.com> | 2020-04-30 15:57:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-30 15:57:42 +0200 |
| commit | 4b265a5cd381168f73c156227c473a0ac55bb476 (patch) | |
| tree | c9845642b6f048fa80edbc38285d78ee3bf0c3fa /src | |
| parent | 9945beabf160c68852a8bdac07de255f04fd6886 (diff) | |
| parent | bdd1e97d4f3a8b294a0691a7631c60cf24fffa90 (diff) | |
Merge pull request #1063 from Al12rs/mod_colors
Mod colors
Diffstat (limited to 'src')
| -rw-r--r-- | src/mainwindow.cpp | 22 | ||||
| -rw-r--r-- | src/modinfodialog.ui | 40 | ||||
| -rw-r--r-- | src/modinfodialogtab.cpp | 53 | ||||
| -rw-r--r-- | src/modinfodialogtab.h | 9 | ||||
| -rw-r--r-- | src/modlist.cpp | 6 |
5 files changed, 103 insertions, 27 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 01d3e62c..b5beb229 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3649,11 +3649,7 @@ void MainWindow::setColor_clicked() if (selection->hasSelection() && selection->selectedRows().count() > 1) { for (QModelIndex idx : selection->selectedRows()) { ModInfo::Ptr info = ModInfo::getByIndex(idx.data(Qt::UserRole + 1).toInt()); - auto flags = info->getFlags(); - if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_SEPARATOR) != flags.end()) - { - info->setColor(currentColor); - } + info->setColor(currentColor); } } else { @@ -3669,11 +3665,7 @@ void MainWindow::resetColor_clicked() if (selection->hasSelection() && selection->selectedRows().count() > 1) { for (QModelIndex idx : selection->selectedRows()) { ModInfo::Ptr info = ModInfo::getByIndex(idx.data(Qt::UserRole + 1).toInt()); - auto flags = info->getFlags(); - if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_SEPARATOR) != flags.end()) - { - info->setColor(color); - } + info->setColor(color); } } else { @@ -4652,6 +4644,7 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) m_ContextIdx = mapToModel(m_OrganizerCore.modList(), modList->indexAt(pos)); m_ContextRow = m_ContextIdx.row(); + int contextColumn = m_ContextIdx.column(); if (m_ContextRow == -1) { // no selection @@ -4774,6 +4767,15 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) menu.addSeparator(); + if (contextColumn == ModList::COL_NOTES) { + menu.addAction(tr("Select Color..."), this, SLOT(setColor_clicked())); + + if (info->getColor().isValid()) + menu.addAction(tr("Reset Color"), this, SLOT(resetColor_clicked())); + + menu.addSeparator(); + } + if (info->getNexusID() > 0 && Settings::instance().nexus().endorsementIntegration()) { switch (info->endorsedState()) { case ModInfo::ENDORSED_TRUE: { 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; } </attribute>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
- <widget class="QLineEdit" name="comments">
- <property name="toolTip">
- <string>Enter comments about the mod here. These are displayed in the notes column of the mod list.</string>
- </property>
- <property name="whatsThis">
- <string>Enter comments about the mod here. These are displayed in the notes column of the mod list.</string>
- </property>
- <property name="placeholderText">
- <string>Enter comments about the mod here. These are displayed in the notes column of the mod list.</string>
- </property>
- </widget>
+ <layout class="QHBoxLayout" name="horizontalLayout_11">
+ <item>
+ <widget class="QLineEdit" name="comments">
+ <property name="toolTip">
+ <string>Enter comments about the mod here. These are displayed in the notes column of the mod list.</string>
+ </property>
+ <property name="whatsThis">
+ <string>Enter comments about the mod here. These are displayed in the notes column of the mod list.</string>
+ </property>
+ <property name="placeholderText">
+ <string>Enter comments about the mod here. These are displayed in the notes column of the mod list.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="setColorButton">
+ <property name="text">
+ <string>Set Color</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="resetColorButton">
+ <property name="text">
+ <string>Reset Color</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
<item>
<widget class="HTMLEditor" name="notes">
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(); }; diff --git a/src/modlist.cpp b/src/modlist.cpp index fb3dde13..4afd2a25 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -404,7 +404,7 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const } return QVariant(); } else if (role == Qt::ForegroundRole) { - if (modInfo->hasFlag(ModInfo::FLAG_SEPARATOR) && modInfo->getColor().isValid()) { + if (modInfo->hasFlag(ModInfo::FLAG_SEPARATOR) || (column == COL_NOTES) && modInfo->getColor().isValid()) { return ColorSettings::idealTextColor(modInfo->getColor()); } else if (column == COL_NAME) { int highlight = modInfo->getHighlight(); @@ -430,7 +430,9 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const bool overwritten = m_Overwritten.find(modIndex) != m_Overwritten.end(); bool archiveOverwritten = m_ArchiveOverwritten.find(modIndex) != m_ArchiveOverwritten.end(); bool archiveLooseOverwritten = m_ArchiveLooseOverwritten.find(modIndex) != m_ArchiveLooseOverwritten.end(); - if (modInfo->getHighlight() & ModInfo::HIGHLIGHT_PLUGIN) { + if (column == COL_NOTES && modInfo->getColor().isValid()) { + return modInfo->getColor(); + } else if (modInfo->getHighlight() & ModInfo::HIGHLIGHT_PLUGIN) { return Settings::instance().colors().modlistContainsPlugin(); } else if (overwritten || archiveLooseOverwritten) { return Settings::instance().colors().modlistOverwritingLoose(); |
