From c7253fb418dc4e709687de21778693c4cbe13f76 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Tue, 3 Feb 2026 23:46:40 +0000 Subject: [PATCH] Switch to QTreeWidget --- apps/launcher/settingspage.cpp | 99 ++++++++++++++++++++------------ apps/launcher/settingspage.hpp | 2 +- apps/launcher/ui/settingspage.ui | 13 ++++- files/lang/launcher_de.ts | 16 ------ files/lang/launcher_en.ts | 16 ------ files/lang/launcher_fr.ts | 16 ------ files/lang/launcher_pl.ts | 16 ------ files/lang/launcher_ru.ts | 16 ------ files/lang/launcher_sv.ts | 16 ------ 9 files changed, 75 insertions(+), 135 deletions(-) diff --git a/apps/launcher/settingspage.cpp b/apps/launcher/settingspage.cpp index e6eaf45e3c..bd84b959d3 100644 --- a/apps/launcher/settingspage.cpp +++ b/apps/launcher/settingspage.cpp @@ -71,6 +71,14 @@ namespace } return 0; } + + enum FileTypeRoles + { + ThisFile = Qt::ItemDataRole::UserRole, + ConfigDirectory, + OpenMWCfg, + SettingsCfg + }; } Launcher::SettingsPage::SettingsPage( @@ -96,40 +104,51 @@ Launcher::SettingsPage::SettingsPage( mCellNameCompleter.setModel(&mCellNameCompleterModel); startDefaultCharacterAtField->setCompleter(&mCellNameCompleter); - connect(configsList, &QListWidget::itemActivated, this, &SettingsPage::slotOpenFile); + connect(configsList, &QTreeWidget::itemActivated, this, &SettingsPage::slotOpenFile); auto actionOpenDir = new QAction(tr("Open directory"), configsList); connect(actionOpenDir, &QAction::triggered, [=]() { - QUrl configFolderUrl = configsList->currentItem()->data(Qt::ItemDataRole::UserRole).toUrl(); + QUrl configFolderUrl = configsList->currentItem()->data(0, ConfigDirectory).toUrl(); QDesktopServices::openUrl(configFolderUrl); }); auto actionOpenOpenmwCfg = new QAction(tr("Open openmw.cfg"), configsList); connect(actionOpenOpenmwCfg, &QAction::triggered, [=]() { - QVariant configFileUrl = configsList->currentItem()->data(Qt::ItemDataRole::UserRole + 1); + QVariant configFileUrl = configsList->currentItem()->data(0, OpenMWCfg); if (configFileUrl.isValid()) QDesktopServices::openUrl(configFileUrl.toUrl()); }); auto actionOpenSettingsCfg = new QAction(tr("Open settings.cfg"), configsList); connect(actionOpenSettingsCfg, &QAction::triggered, [=]() { - QVariant configFileUrl = configsList->currentItem()->data(Qt::ItemDataRole::UserRole + 2); + QVariant configFileUrl = configsList->currentItem()->data(0, SettingsCfg); if (configFileUrl.isValid()) QDesktopServices::openUrl(configFileUrl.toUrl()); }); - connect(configsList, &QListWidget::customContextMenuRequested, [=](const QPoint& pos) { + connect(configsList, &QTreeWidget::customContextMenuRequested, [=](const QPoint& pos) { if (configsList->currentItem()) { QMenu* contextMenu = new QMenu(); - QVariant configFileUrl = configsList->currentItem()->data(Qt::ItemDataRole::UserRole + 1); + QVariant configFileUrl = configsList->currentItem()->data(0, OpenMWCfg); actionOpenOpenmwCfg->setEnabled(configFileUrl.isValid()); - configFileUrl = configsList->currentItem()->data(Qt::ItemDataRole::UserRole + 2); + configFileUrl = configsList->currentItem()->data(0, SettingsCfg); actionOpenSettingsCfg->setEnabled(configFileUrl.isValid()); contextMenu->addActions({ actionOpenDir, actionOpenOpenmwCfg, actionOpenSettingsCfg }); + for (QAction* action : contextMenu->actions()) + action->setVisible(true); + + if (configsList->currentItem()->parent()) + { + // we're a child and don't want sibling files in our context menu + // must temporarily make them visible first as isEnabled() is false for invisible things + for (QAction* action : contextMenu->actions()) + action->setVisible(action->isEnabled()); + } + contextMenu->exec(configsList->mapToGlobal(pos)); contextMenu->deleteLater(); } @@ -432,39 +451,45 @@ void Launcher::SettingsPage::populateLoadedConfigs() } } + QTreeWidgetItem* configItem = new QTreeWidgetItem(configsList); + configItem->setText(0, configPath); + configItem->setToolTip(0, toolTipText); + configItem->setExpanded(true); + + QUrl directoryUrl = QUrl::fromLocalFile(configPath); + configItem->setData(0, ThisFile, directoryUrl); + configItem->setData(0, ConfigDirectory, directoryUrl); + bool hasOpenmwCfg = std::filesystem::exists(path / "openmw.cfg"); bool hasSettingsCfg = std::filesystem::exists(path / "settings.cfg"); - QString hasConfigs; - if (hasOpenmwCfg && hasSettingsCfg) - { - hasConfigs = tr("%1 contains an openmw.cfg and settings.cfg"); - } - else if (hasOpenmwCfg && !hasSettingsCfg) - { - hasConfigs = tr("%1 contains an openmw.cfg"); - } - else if (!hasOpenmwCfg && hasSettingsCfg) - { - hasConfigs = tr("%1 contains a settings.cfg"); - } - else - { - hasConfigs = tr("%1 doesn't have an openmw.cfg or settings.cfg"); - } - - QListWidgetItem* configItem = new QListWidgetItem(configsList); - QLabel* alternativeLabel = new QLabel(hasConfigs.arg(configPath)); - configsList->setItemWidget(configItem, alternativeLabel); - - configItem->setToolTip(toolTipText); - configItem->setData(Qt::ItemDataRole::UserRole, QUrl::fromLocalFile(configPath)); if (hasOpenmwCfg) - configItem->setData( - Qt::ItemDataRole::UserRole + 1, QUrl::fromLocalFile(Files::pathToQString(path / "openmw.cfg"))); + { + QTreeWidgetItem* openmwCfgItem = new QTreeWidgetItem(configItem); + openmwCfgItem->setText(0, "openmw.cfg"); + + QUrl url = QUrl::fromLocalFile(Files::pathToQString(path / "openmw.cfg")); + + openmwCfgItem->setData(0, ThisFile, url); + openmwCfgItem->setData(0, OpenMWCfg, url); + openmwCfgItem->setData(0, ConfigDirectory, directoryUrl); + + configItem->setData(0, OpenMWCfg, url); + } + if (hasSettingsCfg) - configItem->setData( - Qt::ItemDataRole::UserRole + 2, QUrl::fromLocalFile(Files::pathToQString(path / "settings.cfg"))); + { + QTreeWidgetItem* settingsCfgItem = new QTreeWidgetItem(configItem); + settingsCfgItem->setText(0, "settings.cfg"); + + QUrl url = QUrl::fromLocalFile(Files::pathToQString(path / "settings.cfg")); + + settingsCfgItem->setData(0, ThisFile, url); + settingsCfgItem->setData(0, SettingsCfg, url); + settingsCfgItem->setData(0, ConfigDirectory, directoryUrl); + + configItem->setData(0, SettingsCfg, url); + } } } @@ -706,8 +731,8 @@ void Launcher::SettingsPage::slotDistantLandToggled(bool checked) objectPagingMinSizeComboBox->setEnabled(checked); } -void Launcher::SettingsPage::slotOpenFile(QListWidgetItem* item) +void Launcher::SettingsPage::slotOpenFile(QTreeWidgetItem* item) { - QUrl configFolderUrl = item->data(Qt::ItemDataRole::UserRole).toUrl(); + QUrl configFolderUrl = item->data(0, ThisFile).toUrl(); QDesktopServices::openUrl(configFolderUrl); } diff --git a/apps/launcher/settingspage.hpp b/apps/launcher/settingspage.hpp index 257dec522f..90f55cd93d 100644 --- a/apps/launcher/settingspage.hpp +++ b/apps/launcher/settingspage.hpp @@ -39,7 +39,7 @@ namespace Launcher void slotShadowDistLimitToggled(bool checked); void slotDistantLandToggled(bool checked); void slotControllerMenusToggled(bool checked); - void slotOpenFile(QListWidgetItem* item); + void slotOpenFile(QTreeWidgetItem* item); private: const Files::ConfigurationManager& mCfgMgr; diff --git a/apps/launcher/ui/settingspage.ui b/apps/launcher/ui/settingspage.ui index 05709a25e9..e5bbc346f4 100644 --- a/apps/launcher/ui/settingspage.ui +++ b/apps/launcher/ui/settingspage.ui @@ -1545,7 +1545,7 @@ - + 0 @@ -1555,6 +1555,17 @@ Qt::CustomContextMenu + + false + + + false + + + + 1 + + diff --git a/files/lang/launcher_de.ts b/files/lang/launcher_de.ts index d634a11fd0..c27678bc9e 100644 --- a/files/lang/launcher_de.ts +++ b/files/lang/launcher_de.ts @@ -598,22 +598,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov Open settings.cfg - - <b>%1</b> contains an <b>openmw.cfg</b> and <b>settings.cfg</b> - - - - <b>%1</b> contains an <b>openmw.cfg</b> - - - - <b>%1</b> contains a <b>settings.cfg</b> - - - - <b>%1</b> doesn't have an <b>openmw.cfg</b> or <b>settings.cfg</b> - - MainWindow diff --git a/files/lang/launcher_en.ts b/files/lang/launcher_en.ts index bcd9af0c01..4b10dc7523 100644 --- a/files/lang/launcher_en.ts +++ b/files/lang/launcher_en.ts @@ -598,22 +598,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov Open settings.cfg - - <b>%1</b> contains an <b>openmw.cfg</b> and <b>settings.cfg</b> - - - - <b>%1</b> contains an <b>openmw.cfg</b> - - - - <b>%1</b> contains a <b>settings.cfg</b> - - - - <b>%1</b> doesn't have an <b>openmw.cfg</b> or <b>settings.cfg</b> - - MainWindow diff --git a/files/lang/launcher_fr.ts b/files/lang/launcher_fr.ts index d709830d80..7966cbd3fc 100644 --- a/files/lang/launcher_fr.ts +++ b/files/lang/launcher_fr.ts @@ -598,22 +598,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov Open settings.cfg - - <b>%1</b> contains an <b>openmw.cfg</b> and <b>settings.cfg</b> - - - - <b>%1</b> contains an <b>openmw.cfg</b> - - - - <b>%1</b> contains a <b>settings.cfg</b> - - - - <b>%1</b> doesn't have an <b>openmw.cfg</b> or <b>settings.cfg</b> - - MainWindow diff --git a/files/lang/launcher_pl.ts b/files/lang/launcher_pl.ts index eaf7222efd..7cb1dc8363 100644 --- a/files/lang/launcher_pl.ts +++ b/files/lang/launcher_pl.ts @@ -602,22 +602,6 @@ do domyślnych czcionek Morrowind. Zaznacz to pole, jeśli nadal wolisz oryginal Open settings.cfg - - <b>%1</b> contains an <b>openmw.cfg</b> and <b>settings.cfg</b> - - - - <b>%1</b> contains an <b>openmw.cfg</b> - - - - <b>%1</b> contains a <b>settings.cfg</b> - - - - <b>%1</b> doesn't have an <b>openmw.cfg</b> or <b>settings.cfg</b> - - MainWindow diff --git a/files/lang/launcher_ru.ts b/files/lang/launcher_ru.ts index ee81b53497..4c6689b811 100644 --- a/files/lang/launcher_ru.ts +++ b/files/lang/launcher_ru.ts @@ -628,22 +628,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov Open settings.cfg - - <b>%1</b> contains an <b>openmw.cfg</b> and <b>settings.cfg</b> - - - - <b>%1</b> contains an <b>openmw.cfg</b> - - - - <b>%1</b> contains a <b>settings.cfg</b> - - - - <b>%1</b> doesn't have an <b>openmw.cfg</b> or <b>settings.cfg</b> - - MainWindow diff --git a/files/lang/launcher_sv.ts b/files/lang/launcher_sv.ts index 21e7a71c16..176ee0143a 100644 --- a/files/lang/launcher_sv.ts +++ b/files/lang/launcher_sv.ts @@ -601,22 +601,6 @@ de ordinarie fonterna i Morrowind. Bocka denna ruta om du ändå föredrar ordin Open settings.cfg - - <b>%1</b> contains an <b>openmw.cfg</b> and <b>settings.cfg</b> - - - - <b>%1</b> contains an <b>openmw.cfg</b> - - - - <b>%1</b> contains a <b>settings.cfg</b> - - - - <b>%1</b> doesn't have an <b>openmw.cfg</b> or <b>settings.cfg</b> - - MainWindow