From 76fbe6effef7c2e787c1801741d4eb0a156128ce Mon Sep 17 00:00:00 2001 From: Tannin Date: Tue, 4 Feb 2014 19:55:27 +0100 Subject: - tabs in the mod info dialog can now be moved around by the user --- src/mainwindow.cpp | 3 +++ src/modinfodialog.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++---- src/modinfodialog.h | 8 +++++++ src/modinfodialog.ui | 11 +++++---- 4 files changed, 76 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 90eb6bce..b6a744aa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3160,7 +3160,10 @@ void MainWindow::displayModInformation(ModInfo::Ptr modInfo, unsigned int index, connect(&dialog, SIGNAL(endorseMod(ModInfo::Ptr)), this, SLOT(endorseMod(ModInfo::Ptr))); dialog.openTab(tab); + dialog.restoreTabState(m_Settings.directInterface().value("mod_info_tabs").toByteArray()); dialog.exec(); + m_Settings.directInterface().setValue("mod_info_tabs", dialog.saveTabState()); + modInfo->saveMeta(); emit modInfoDisplayed(); m_ModList.modInfoChanged(modInfo); diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp index 3657d48a..117b2726 100644 --- a/src/modinfodialog.cpp +++ b/src/modinfodialog.cpp @@ -69,7 +69,6 @@ ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, const DirectoryEntry *directo ui->setupUi(this); this->setWindowTitle(modInfo->name()); this->setWindowModality(Qt::WindowModal); - m_UTF8Codec = QTextCodec::codecForName("utf-8"); QListWidget *textFileList = findChild("textFileList"); @@ -143,7 +142,6 @@ ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, const DirectoryEntry *directo QTabWidget *tabWidget = findChild("tabWidget"); tabWidget->setTabEnabled(TAB_TEXTFILES, textFileList->count() != 0); - //tabWidget->setTabEnabled(TAB_INIFILES, (iniFileList->count() != 0) || (iniTweaksList->count() != 0)); tabWidget->setTabEnabled(TAB_IMAGES, thumbnailArea->count() != 0); tabWidget->setTabEnabled(TAB_ESPS, (inactiveESPList->count() != 0) || (activeESPList->count() != 0)); tabWidget->setTabEnabled(TAB_CONFLICTS, m_Origin != NULL); @@ -168,6 +166,63 @@ ModInfoDialog::~ModInfoDialog() } +int ModInfoDialog::tabIndex(const QString &tabId) +{ + for (int i = 0; i < ui->tabWidget->count(); ++i) { + if (ui->tabWidget->widget(i)->objectName() == tabId) { + return i; + } + } + return -1; +} + + +void ModInfoDialog::restoreTabState(const QByteArray &state) +{ + QDataStream stream(state); + int count = 0; + stream >> count; + + QStringList tabIds; + + // first, only determine the new mapping + for (int newPos = 0; newPos < count; ++newPos) { + QString tabId; + stream >> tabId; + tabIds.append(tabId); + int oldPos = tabIndex(tabId); + if (oldPos != -1) { + m_RealTabPos[newPos] = oldPos; + } else { + m_RealTabPos[newPos] = newPos; + } + } + // then actually move the tabs + QTabBar *tabBar = ui->tabWidget->findChild("qt_tabwidget_tabbar"); // magic name = bad + ui->tabWidget->blockSignals(true); + for (int newPos = 0; newPos < count; ++newPos) { + QString tabId = tabIds.at(newPos); + int oldPos = tabIndex(tabId); + tabBar->moveTab(oldPos, newPos); + } + ui->tabWidget->blockSignals(false); +} + + +QByteArray ModInfoDialog::saveTabState() const +{ + QByteArray result; + QDataStream stream(&result, QIODevice::WriteOnly); + stream << ui->tabWidget->count(); + for (int i = 0; i < ui->tabWidget->count(); ++i) { + stream << ui->tabWidget->widget(i)->objectName(); + + } + + return result; +} + + void ModInfoDialog::refreshLists() { int numNonConflicting = 0; @@ -331,7 +386,6 @@ void ModInfoDialog::openTab(int tab) } } - void ModInfoDialog::thumbnailClicked(const QString &fileName) { QLabel *imageLabel = findChild("imageLabel"); @@ -784,7 +838,7 @@ void ModInfoDialog::activateNexusTab() void ModInfoDialog::on_tabWidget_currentChanged(int index) { - if (index == TAB_NEXUS) { + if (m_RealTabPos[index] == TAB_NEXUS) { activateNexusTab(); } } diff --git a/src/modinfodialog.h b/src/modinfodialog.h index b33b743e..edfe59cf 100644 --- a/src/modinfodialog.h +++ b/src/modinfodialog.h @@ -100,6 +100,10 @@ public: **/ void openTab(int tab); + void restoreTabState(const QByteArray &state); + + QByteArray saveTabState() const; + signals: void thumbnailClickedSignal(const QString &filename); @@ -142,6 +146,8 @@ private: void addCheckedCategories(QTreeWidgetItem *tree); void refreshPrimaryCategoriesBox(); + int tabIndex(const QString &tabId); + private slots: void hideConflictFile(); @@ -221,6 +227,8 @@ private: MOShared::FilesOrigin *m_Origin; QTextCodec *m_UTF8Codec; + std::map m_RealTabPos; + }; #endif // MODINFODIALOG_H diff --git a/src/modinfodialog.ui b/src/modinfodialog.ui index 7b95e011..1d357f70 100644 --- a/src/modinfodialog.ui +++ b/src/modinfodialog.ui @@ -22,6 +22,9 @@ 0 + + true + Textfiles @@ -209,7 +212,7 @@ 0 0 - 668 + 676 126 @@ -546,7 +549,7 @@ Most mods do not have optional esps, so chances are good you are looking at an e - + :/MO/gui/resources/internet-web-browser.png:/MO/gui/resources/internet-web-browser.png @@ -666,8 +669,8 @@ p, li { white-space: pre-wrap; } <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"><br /></p></body></html> Qt::TextBrowserInteraction -- cgit v1.3.1