From f8a037a409d1b6bbb2f34b237b8b66d454179f56 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Tue, 18 Jun 2019 09:29:06 -0400
Subject: changed layout of esps tab, moved to modinfodialogesps.cpp/h slightly
offset next/previous images so they look better when shown next to each other
vertically
---
src/CMakeLists.txt | 3 +
src/modinfodialog.cpp | 98 +------------
src/modinfodialog.h | 2 -
src/modinfodialog.ui | 268 ++++++++++++++++++++++--------------
src/modinfodialogesps.cpp | 287 +++++++++++++++++++++++++++++++++++++++
src/modinfodialogesps.h | 26 ++++
src/modinfodialogimages.cpp | 2 -
src/resources/go-next_16.png | Bin 676 -> 719 bytes
src/resources/go-previous_16.png | Bin 655 -> 718 bytes
9 files changed, 483 insertions(+), 203 deletions(-)
create mode 100644 src/modinfodialogesps.cpp
create mode 100644 src/modinfodialogesps.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c5018baf..aba922f9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -54,6 +54,7 @@ SET(organizer_SRCS
modlist.cpp
modidlineedit.cpp
modinfodialog.cpp
+ modinfodialogesps.cpp
modinfodialogimages.cpp
modinfodialogtextfiles.cpp
modinfo.cpp
@@ -156,6 +157,7 @@ SET(organizer_HDRS
modlist.h
modidlineedit.h
modinfodialog.h
+ modinfodialogesps.h
modinfodialogimages.h
modinfodialogtextfiles.h
modinfo.h
@@ -356,6 +358,7 @@ set(modinfo
modinfo
modinfobackup
modinfodialog
+ modinfodialogesps
modinfodialogimages
modinfodialogtextfiles
modinfoforeign
diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp
index cc3140b6..a52f2031 100644
--- a/src/modinfodialog.cpp
+++ b/src/modinfodialog.cpp
@@ -40,6 +40,7 @@ along with Mod Organizer. If not, see .
#include "modinfodialogtextfiles.h"
#include "modinfodialogimages.h"
+#include "modinfodialogesps.h"
#include
#include
@@ -70,6 +71,7 @@ std::vector> ModInfoDialogTab::createTabs(
v.push_back(std::make_unique(ui));
v.push_back(std::make_unique(ui));
v.push_back(std::make_unique(ui));
+ v.push_back(std::make_unique(ui));
return v;
}
@@ -353,15 +355,16 @@ ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, const DirectoryEntry *directo
ui->tabWidget->setTabEnabled(TAB_TEXTFILES, false);
ui->tabWidget->setTabEnabled(TAB_INIFILES, false);
ui->tabWidget->setTabEnabled(TAB_IMAGES, false);
+ ui->tabWidget->setTabEnabled(TAB_ESPS, false);
ui->tabWidget->setTabEnabled(TAB_CATEGORIES, false);
ui->tabWidget->setTabEnabled(TAB_NEXUS, false);
ui->tabWidget->setTabEnabled(TAB_FILETREE, false);
ui->tabWidget->setTabEnabled(TAB_NOTES, false);
- ui->tabWidget->setTabEnabled(TAB_ESPS, false);
} else {
ui->tabWidget->setTabEnabled(TAB_TEXTFILES, true);
ui->tabWidget->setTabEnabled(TAB_INIFILES, true);
ui->tabWidget->setTabEnabled(TAB_IMAGES, true);
+ ui->tabWidget->setTabEnabled(TAB_ESPS, true);
initFiletree(modInfo);
addCategories(CategoryFactory::instance(), modInfo->getCategories(), ui->categoriesTree->invisibleRootItem(), 0);
@@ -848,10 +851,6 @@ void ModInfoDialog::refreshFiles()
tab->clear();
}
- ui->inactiveESPList->clear();
- ui->activeESPList->clear();
-
-
if (m_RootPath.length() > 0) {
QDirIterator dirIterator(m_RootPath, QDir::Files, QDirIterator::Subdirectories);
while (dirIterator.hasNext()) {
@@ -862,24 +861,8 @@ void ModInfoDialog::refreshFiles()
break;
}
}
-
- if (fileName.endsWith(".esp", Qt::CaseInsensitive) ||
- fileName.endsWith(".esm", Qt::CaseInsensitive) ||
- fileName.endsWith(".esl", Qt::CaseInsensitive)) {
- QString relativePath = fileName.mid(m_RootPath.length() + 1);
- if (relativePath.contains('/')) {
- QFileInfo fileInfo(fileName);
- QListWidgetItem *newItem = new QListWidgetItem(fileInfo.fileName());
- newItem->setData(Qt::UserRole, relativePath);
- ui->inactiveESPList->addItem(newItem);
- } else {
- ui->activeESPList->addItem(relativePath);
- }
- }
}
}
-
- ui->tabWidget->setTabEnabled(TAB_ESPS, (ui->inactiveESPList->count() != 0) || (ui->activeESPList->count() != 0));
}
void ModInfoDialog::addCategories(const CategoryFactory &factory, const std::set &enabledCategories, QTreeWidgetItem *root, int rootLevel)
@@ -947,79 +930,6 @@ void ModInfoDialog::openTab(int tab)
}
}
-void ModInfoDialog::on_activateESP_clicked()
-{
- QListWidget *activeESPList = findChild("activeESPList");
- QListWidget *inactiveESPList = findChild("inactiveESPList");
-
- int selectedRow = inactiveESPList->currentRow();
- if (selectedRow < 0) {
- return;
- }
-
- QListWidgetItem *selectedItem = inactiveESPList->takeItem(selectedRow);
-
- QDir root(m_RootPath);
- bool renamed = false;
-
- while (root.exists(selectedItem->text())) {
- bool okClicked = false;
- QString newName = QInputDialog::getText(this, tr("File Exists"), tr("A file with that name exists, please enter a new one"), QLineEdit::Normal, selectedItem->text(), &okClicked);
- if (!okClicked) {
- inactiveESPList->insertItem(selectedRow, selectedItem);
- return;
- } else if (newName.size() > 0) {
- selectedItem->setText(newName);
- renamed = true;
- }
- }
-
- if (root.rename(selectedItem->data(Qt::UserRole).toString(), selectedItem->text())) {
- activeESPList->addItem(selectedItem);
- if (renamed) {
- selectedItem->setData(Qt::UserRole, QVariant());
- }
- } else {
- inactiveESPList->insertItem(selectedRow, selectedItem);
- reportError(tr("failed to move file"));
- }
-}
-
-
-void ModInfoDialog::on_deactivateESP_clicked()
-{
- QListWidget *activeESPList = findChild("activeESPList");
- QListWidget *inactiveESPList = findChild("inactiveESPList");
-
- int selectedRow = activeESPList->currentRow();
- if (selectedRow < 0) {
- return;
- }
-
- QDir root(m_RootPath);
-
- QListWidgetItem *selectedItem = activeESPList->takeItem(selectedRow);
-
- // if we moved the file from optional to active in this session, we move the file back to
- // where it came from. Otherwise, it is moved to the new folder "optional"
- if (selectedItem->data(Qt::UserRole).isNull()) {
- selectedItem->setData(Qt::UserRole, QString("optional/") + selectedItem->text());
- if (!root.exists("optional")) {
- if (!root.mkdir("optional")) {
- reportError(tr("failed to create directory \"optional\""));
- activeESPList->insertItem(selectedRow, selectedItem);
- return;
- }
- }
- }
-
- if (root.rename(selectedItem->text(), selectedItem->data(Qt::UserRole).toString())) {
- inactiveESPList->addItem(selectedItem);
- } else {
- activeESPList->insertItem(selectedRow, selectedItem);
- }
-}
-
void ModInfoDialog::on_visitNexusLabel_linkActivated(const QString &link)
{
emit linkActivated(link);
diff --git a/src/modinfodialog.h b/src/modinfodialog.h
index f3ef6e76..6ecf16bf 100644
--- a/src/modinfodialog.h
+++ b/src/modinfodialog.h
@@ -186,8 +186,6 @@ private slots:
void on_openInExplorerButton_clicked();
void on_closeButton_clicked();
- void on_activateESP_clicked();
- void on_deactivateESP_clicked();
void on_visitNexusLabel_linkActivated(const QString &link);
void on_modIDEdit_editingFinished();
void on_sourceGameEdit_currentIndexChanged(int);
diff --git a/src/modinfodialog.ui b/src/modinfodialog.ui
index c1dba1c7..f1212634 100644
--- a/src/modinfodialog.ui
+++ b/src/modinfodialog.ui
@@ -104,7 +104,7 @@
Qt::Horizontal
-
+
6
@@ -128,7 +128,7 @@
-
+
-
@@ -180,7 +180,7 @@
0
0
- 604
+ 741
436
@@ -213,117 +213,175 @@
Optional ESPs
-
-
-
-
-
- List of esps, esms, and esls that can not be loaded by the game.
-
-
- List of esps, esms, and esls contained in this plugin that currently can not be loaded by the game. They will not even appear in the esp-list in the main MO-window.
-They usually contain optional functionality, see the readme.
-
-Most mods do not have optional esps, so chances are good you are looking at an empty list.
-
-
-
- -
-
-
- Optional ESPs
+
+
-
+
+
+ Qt::Horizontal
-
-
- -
-
-
-
-
-
-
- 96
- 0
-
-
-
- Make the selected mod in the lower list unavailable.
-
-
- The selected esp (in the lower list) will be pushed into a subdirectory of the mod and will thus become "invisible" to the game. It can then no longer be activated.
-
-
-
-
-
-
- :/MO/gui/resources/go-up.png:/MO/gui/resources/go-up.png
+
+
+
+ 0
-
-
- 22
- 22
-
+
+ 0
-
-
- -
-
-
-
- 96
- 0
-
+
+ 0
-
- Move a file to the data directory.
+
+ 0
-
- This moves a esp to the esp directory so it can be enabled in the main window. Please note that the ESP merely becomes "available", it will not necessarily be loaded! That is configured in the main window of omo.
+
-
+
+
+ Optional ESPs
+
+
+
+ -
+
+
+ List of esps, esms, and esls that can not be loaded by the game.
+
+
+ List of esps, esms, and esls contained in this plugin that currently can not be loaded by the game. They will not even appear in the esp-list in the main MO-window.
+They usually contain optional functionality, see the readme.
+
+Most mods do not have optional esps, so chances are good you are looking at an empty list.
+
+
+
+
+
+
+
+
+ 0
-
-
+
+ 0
-
-
- :/MO/gui/resources/go-down.png:/MO/gui/resources/go-down.png
+
+ 0
-
-
- 22
- 22
-
+
+ 0
-
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
- ESPs in the data directory and thus visible to the game.
-
-
- These are the mod files that are in the (virtual) data directory of your game and will thus be selectable in the esp list in the main window.
-
-
-
- -
-
-
- Available ESPs
-
+
-
+
+
-
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Move a file to the data directory.
+
+
+ This moves a esp to the esp directory so it can be enabled in the main window. Please note that the ESP merely becomes "available", it will not necessarily be loaded! That is configured in the main window of omo.
+
+
+
+
+
+
+ :/MO/gui/next:/MO/gui/next
+
+
+
+ 22
+ 22
+
+
+
+
+ -
+
+
+ Make the selected mod in the lower list unavailable.
+
+
+ The selected esp (in the lower list) will be pushed into a subdirectory of the mod and will thus become "invisible" to the game. It can then no longer be activated.
+
+
+
+
+
+
+ :/MO/gui/previous:/MO/gui/previous
+
+
+
+ 22
+ 22
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ Available ESPs
+
+
+
+ -
+
+
+ ESPs in the data directory and thus visible to the game.
+
+
+ These are the mod files that are in the (virtual) data directory of your game and will thus be selectable in the esp list in the main window.
+
+
+
+
+
+
+
+
diff --git a/src/modinfodialogesps.cpp b/src/modinfodialogesps.cpp
new file mode 100644
index 00000000..32dcdb35
--- /dev/null
+++ b/src/modinfodialogesps.cpp
@@ -0,0 +1,287 @@
+#include "modinfodialogesps.h"
+#include "ui_modinfodialog.h"
+#include
+
+using MOBase::reportError;
+
+
+class ESP
+{
+public:
+ ESP(QString rootPath, QString relativePath)
+ : m_rootPath(std::move(rootPath)), m_active(false)
+ {
+ if (relativePath.contains('/')) {
+ m_inactivePath = relativePath;
+ } else {
+ m_activePath = relativePath;
+ m_active = true;
+ }
+ }
+
+ const QString& rootPath() const
+ {
+ return m_rootPath;
+ }
+
+ const QString& relativePath() const
+ {
+ if (m_active) {
+ return m_activePath;
+ } else {
+ return m_inactivePath;
+ }
+ }
+
+ const QString& activePath() const
+ {
+ return m_activePath;
+ }
+
+ const QString& inactivePath() const
+ {
+ return m_inactivePath;
+ }
+
+ QFileInfo fileInfo() const
+ {
+ return m_rootPath + QDir::separator() + relativePath();
+ }
+
+ bool isActive() const
+ {
+ return m_active;
+ }
+
+ bool activate(const QString& newName)
+ {
+ QDir root(m_rootPath);
+
+ if (root.rename(m_inactivePath, newName)) {
+ m_active = true;
+ m_activePath = newName;
+
+ if (QFileInfo(m_inactivePath).fileName() != newName) {
+ // file was renamed
+ m_inactivePath = QFileInfo(m_inactivePath).path() + QDir::separator() + newName;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ bool deactivate(const QString& newName)
+ {
+ QDir root(m_rootPath);
+
+ if (root.rename(m_activePath, newName)) {
+ m_active = false;
+ m_inactivePath = newName;
+ return true;
+ }
+
+ return false;
+ }
+
+private:
+ QString m_rootPath;
+ QString m_activePath;
+ QString m_inactivePath;
+ bool m_active;
+};
+
+
+class ESPItem : public QListWidgetItem
+{
+public:
+ ESPItem(ESP esp)
+ : m_esp(std::move(esp))
+ {
+ updateText();
+ }
+
+ const ESP& esp() const
+ {
+ return m_esp;
+ }
+
+ void setESP(ESP esp)
+ {
+ m_esp = esp;
+ updateText();
+ }
+
+private:
+ ESP m_esp;
+
+ void updateText()
+ {
+ setText(m_esp.fileInfo().fileName());
+ }
+};
+
+
+ESPsTab::ESPsTab(Ui::ModInfoDialog* ui)
+ : ui(ui)
+{
+ QObject::connect(
+ ui->activateESP1, &QToolButton::clicked, [&]{ onActivate(); });
+
+ QObject::connect(
+ ui->deactivateESP1, &QToolButton::clicked, [&]{ onDeactivate(); });
+}
+
+void ESPsTab::clear()
+{
+ ui->inactiveESPList1->clear();
+ ui->activeESPList1->clear();
+}
+
+bool ESPsTab::feedFile(const QString& rootPath, const QString& fullPath)
+{
+ static constexpr const char* extensions[] = {
+ ".esp", ".esm", ".esl"
+ };
+
+ for (const auto* e : extensions) {
+ if (fullPath.endsWith(e, Qt::CaseInsensitive)) {
+ QString relativePath = fullPath.mid(rootPath.length() + 1);
+
+ auto* item = new ESPItem({rootPath, relativePath});
+
+ if (item->esp().isActive()) {
+ ui->activeESPList1->addItem(item);
+ } else {
+ ui->inactiveESPList1->addItem(item);
+ }
+
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void ESPsTab::onActivate()
+{
+ auto* item = selectedInactive();
+ if (!item) {
+ qWarning("ESPsTab::onActivate(): no selection");
+ return;
+ }
+
+ ESP esp = item->esp();
+
+ if (esp.isActive()) {
+ qWarning("ESPsTab::onActive(): item is already active");
+ return;
+ }
+
+ QDir root(esp.rootPath());
+ const QFileInfo file(esp.fileInfo());
+
+ QString newName = file.fileName();
+
+ while (root.exists(newName)) {
+ bool okClicked = false;
+
+ newName = QInputDialog::getText(
+ ui->tabESPs,
+ QObject::tr("File Exists"),
+ QObject::tr("A file with that name exists, please enter a new one"),
+ QLineEdit::Normal, file.fileName(), &okClicked);
+
+ if (!okClicked) {
+ return;
+ }
+
+ if (newName.isEmpty()) {
+ newName = file.fileName();
+ }
+ }
+
+ if (esp.activate(newName)) {
+ ui->inactiveESPList1->takeItem(ui->inactiveESPList1->row(item));
+ ui->activeESPList1->addItem(item);
+ item->setESP(esp);
+ } else {
+ reportError(QObject::tr("Failed to move file"));
+ }
+}
+
+void ESPsTab::onDeactivate()
+{
+ auto* item = selectedActive();
+ if (!item) {
+ qWarning("ESPsTab::onDeactivate(): no selection");
+ return;
+ }
+
+ ESP esp = item->esp();
+
+ if (!esp.isActive()) {
+ qWarning("ESPsTab::onDeactivate(): item is already inactive");
+ return;
+ }
+
+ QDir root(esp.rootPath());
+
+ // if we moved the file from optional to active in this session, we move the
+ // file back to where it came from. Otherwise, it is moved to the new folder
+ // "optional"
+
+ QString newName = esp.inactivePath();
+
+ if (newName.isEmpty()) {
+ if (!root.exists("optional")) {
+ if (!root.mkdir("optional")) {
+ reportError(QObject::tr("Failed to create directory \"optional\""));
+ return;
+ }
+ }
+
+ newName = QString("optional") + QDir::separator() + esp.fileInfo().fileName();
+ }
+
+ if (esp.deactivate(newName)) {
+ ui->activeESPList1->takeItem(ui->activeESPList1->row(item));
+ ui->inactiveESPList1->addItem(item);
+ item->setESP(esp);
+ } else {
+ reportError(QObject::tr("Failed to move file"));
+ }
+}
+
+ESPItem* ESPsTab::selectedInactive()
+{
+ auto* item = ui->inactiveESPList1->currentItem();
+ if (!item) {
+ return nullptr;
+ }
+
+ auto* esp = dynamic_cast(item);
+ if (!esp) {
+ qCritical("ESPsTab: inactive item is not an ESPItem");
+ return nullptr;
+ }
+
+ return esp;
+}
+
+ESPItem* ESPsTab::selectedActive()
+{
+ auto* item = ui->activeESPList1->currentItem();
+ if (!item) {
+ return nullptr;
+ }
+
+ auto* esp = dynamic_cast(item);
+ if (!esp) {
+ qCritical("ESPsTab: active item is not an ESPItem");
+ return nullptr;
+ }
+
+ return esp;
+}
diff --git a/src/modinfodialogesps.h b/src/modinfodialogesps.h
new file mode 100644
index 00000000..a46677cb
--- /dev/null
+++ b/src/modinfodialogesps.h
@@ -0,0 +1,26 @@
+#ifndef MODINFODIALOGESPS_H
+#define MODINFODIALOGESPS_H
+
+#include "modinfodialog.h"
+
+class ESPItem;
+
+class ESPsTab : public ModInfoDialogTab
+{
+public:
+ ESPsTab(Ui::ModInfoDialog* ui);
+
+ void clear() override;
+ bool feedFile(const QString& rootPath, const QString& fullPath) override;
+
+private:
+ Ui::ModInfoDialog* ui;
+
+ void onActivate();
+ void onDeactivate();
+
+ ESPItem* selectedInactive();
+ ESPItem* selectedActive();
+};
+
+#endif // MODINFODIALOGESPS_H
diff --git a/src/modinfodialogimages.cpp b/src/modinfodialogimages.cpp
index fb2ad1fe..1659bed3 100644
--- a/src/modinfodialogimages.cpp
+++ b/src/modinfodialogimages.cpp
@@ -52,8 +52,6 @@ void ScalableImage::paintEvent(QPaintEvent* e)
static_cast(std::round(m_original.height() * ratio)));
if (m_scaled.isNull() || m_scaled.size() != scaledSize) {
- qDebug() << "scaled to " << scaledSize;
-
m_scaled = m_original.scaled(
scaledSize.width(), scaledSize.height(),
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
diff --git a/src/resources/go-next_16.png b/src/resources/go-next_16.png
index 6ef8de76..58742d39 100644
Binary files a/src/resources/go-next_16.png and b/src/resources/go-next_16.png differ
diff --git a/src/resources/go-previous_16.png b/src/resources/go-previous_16.png
index 659cd90d..b4b22d04 100644
Binary files a/src/resources/go-previous_16.png and b/src/resources/go-previous_16.png differ
--
cgit v1.3.1