diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-06-25 13:02:11 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-07-02 10:10:19 -0400 |
| commit | fb93d9ff2d1c158fb546471f6e18e4dc9b965c2f (patch) | |
| tree | 3e26533b31dfdd420c422f508f62d1edd71d6f09 | |
| parent | 2b57172eb8ab23f2fab580be73c570f44500ed8d (diff) | |
nexus tab: fixed to only make one request, changed css to match nexus more closely
bbcode now supports [img width=x,height=x]
images tab: don't reload the original image
| -rw-r--r-- | src/bbcode.cpp | 2 | ||||
| -rw-r--r-- | src/modinfodialogimages.cpp | 12 | ||||
| -rw-r--r-- | src/modinfodialognexus.cpp | 52 | ||||
| -rw-r--r-- | src/modinfodialognexus.h | 1 |
4 files changed, 46 insertions, 21 deletions
diff --git a/src/bbcode.cpp b/src/bbcode.cpp index 3475f1b2..9f064106 100644 --- a/src/bbcode.cpp +++ b/src/bbcode.cpp @@ -174,7 +174,7 @@ private: "<a href=\"\\1\">\\1</a>");
m_TagMap["url="] = std::make_pair(QRegExp("\\[url=([^\\]]*)\\](.*)\\[/url\\]"),
"<a href=\"\\1\">\\2</a>");
- m_TagMap["img"] = std::make_pair(QRegExp("\\[img\\](.*)\\[/img\\]"),
+ m_TagMap["img"] = std::make_pair(QRegExp("\\[img(?:\\s*width=\\d+\\s*,?\\s*height=\\d+)?\\](.*)\\[/img\\]"),
"<img src=\"\\1\">");
m_TagMap["img="] = std::make_pair(QRegExp("\\[img=([^\\]]*)\\](.*)\\[/img\\]"),
"<img src=\"\\2\" alt=\"\\1\">");
diff --git a/src/modinfodialogimages.cpp b/src/modinfodialogimages.cpp index 22c004e6..9b0e98c5 100644 --- a/src/modinfodialogimages.cpp +++ b/src/modinfodialogimages.cpp @@ -282,14 +282,14 @@ bool ImagesTab::needsReload(const File& file, const QSize& imageSize) const void ImagesTab::reload(File& file, const QSize& scaledSize) { - file.original = {}; - file.thumbnail = {}; file.failed = false; - if (!file.original.load(file.path)) { - qCritical() << "failed to load image from " << file.path; - file.failed = true; - return; + if (file.original.isNull()) { + if (!file.original.load(file.path)) { + qCritical() << "failed to load image from " << file.path; + file.failed = true; + return; + } } file.thumbnail = file.original.scaled( diff --git a/src/modinfodialognexus.cpp b/src/modinfodialognexus.cpp index d296e000..797f7923 100644 --- a/src/modinfodialognexus.cpp +++ b/src/modinfodialognexus.cpp @@ -7,10 +7,16 @@ #include <versioninfo.h> #include <utility.h> +bool isValidModID(int id) +{ + return (id > 0); +} + NexusTab::NexusTab( OrganizerCore& oc, PluginContainer& plugin, - QWidget* parent, Ui::ModInfoDialog* ui, int id) - : ModInfoDialogTab(oc, plugin, parent, ui, id), m_requestStarted(false) + QWidget* parent, Ui::ModInfoDialog* ui, int id) : + ModInfoDialogTab(oc, plugin, parent, ui, id), m_requestStarted(false), + m_loading(false) { ui->modID->setValidator(new QIntValidator(ui->modID)); ui->endorse->setVisible(core().settings().endorsementIntegration()); @@ -53,6 +59,8 @@ void NexusTab::clear() void NexusTab::update() { + QScopedValueRollback loading(m_loading, true); + clear(); ui->modID->setText(QString("%1").arg(mod()->getNexusID())); @@ -123,7 +131,7 @@ void NexusTab::updateWebpage() { const int modID = mod()->getNexusID(); - if (modID > 0) { + if (isValidModID(modID)) { const QString nexusLink = NexusInterface::instance(&plugin()) ->getModURL(modID, mod()->getGameName()); @@ -147,16 +155,19 @@ void NexusTab::onModChanged() QString descriptionAsHTML = R"( <html> <head> - <style class=\"nexus-description\"> + <style class="nexus-description"> body { - font-style: sans-serif; - background: #707070; + font-family: sans-serif; + font-size: 14px; + background: #404040; + color: #f1f1f1; } a { - color: #5EA2E5; + color: #8197ec; + text-decoration: none; } </style> </head> @@ -181,6 +192,10 @@ void NexusTab::onModChanged() void NexusTab::onModIDChanged() { + if (m_loading) { + return; + } + const int oldID = mod()->getNexusID(); const int newID = ui->modID->text().toInt(); @@ -190,7 +205,7 @@ void NexusTab::onModIDChanged() ui->browser->page()->setHtml(""); - if (newID != 0) { + if (isValidModID(newID)) { refreshData(newID); } } @@ -198,6 +213,10 @@ void NexusTab::onModIDChanged() void NexusTab::onSourceGameChanged() { + if (m_loading) { + return; + } + for (auto game : plugin().plugins<MOBase::IPluginGame>()) { if (game->gameName() == ui->sourceGame->currentText()) { mod()->setGameName(game->gameShortName()); @@ -210,6 +229,10 @@ void NexusTab::onSourceGameChanged() void NexusTab::onVersionChanged() { + if (m_loading) { + return; + } + MOBase::VersionInfo version(ui->version->text()); mod()->setVersion(version); updateVersionColor(); @@ -217,6 +240,10 @@ void NexusTab::onVersionChanged() void NexusTab::onUrlChanged() { + if (m_loading) { + return; + } + mod()->setURL(ui->url->text()); mod()->setLastNexusQuery(QDateTime::fromSecsSinceEpoch(0)); } @@ -225,7 +252,7 @@ void NexusTab::onOpenLink() { const int modID = mod()->getNexusID(); - if (modID > 0) { + if (isValidModID(modID)) { const QString nexusLink = NexusInterface::instance(&plugin()) ->getModURL(modID, mod()->getGameName()); @@ -237,7 +264,7 @@ void NexusTab::onRefreshBrowser() { const auto modID = mod()->getNexusID(); - if (modID > 0) { + if (isValidModID(modID)) { refreshData(modID); } else qInfo("Mod has no valid Nexus ID, info can't be updated."); @@ -259,18 +286,15 @@ void NexusTab::refreshData(int modID) bool NexusTab::tryRefreshData(int modID) { - if (modID <= 0) { - qDebug() << "NexusTab: can't refresh, no mod id"; + if (!isValidModID(modID)) { return false; } if (m_requestStarted) { - qDebug() << "NexusTab: a refresh request is already running"; return false; } if (!mod()->updateNXMInfo()) { - qDebug() << "NexusTab: nexus description does not need an update"; return false; } diff --git a/src/modinfodialognexus.h b/src/modinfodialognexus.h index a09f4316..86d87c30 100644 --- a/src/modinfodialognexus.h +++ b/src/modinfodialognexus.h @@ -47,6 +47,7 @@ public: private: QMetaObject::Connection m_modConnection; bool m_requestStarted; + bool m_loading; void cleanup(); void updateVersionColor(); |
