Switch to QTreeWidget

This commit is contained in:
AnyOldName3
2026-02-03 23:46:40 +00:00
parent 7f1673f14f
commit c7253fb418
9 changed files with 75 additions and 135 deletions
+62 -37
View File
@@ -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("<b>%1</b> contains an <b>openmw.cfg</b> and <b>settings.cfg</b>");
}
else if (hasOpenmwCfg && !hasSettingsCfg)
{
hasConfigs = tr("<b>%1</b> contains an <b>openmw.cfg</b>");
}
else if (!hasOpenmwCfg && hasSettingsCfg)
{
hasConfigs = tr("<b>%1</b> contains a <b>settings.cfg</b>");
}
else
{
hasConfigs = tr("<b>%1</b> doesn't have an <b>openmw.cfg</b> or <b>settings.cfg</b>");
}
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);
}
+1 -1
View File
@@ -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;
+12 -1
View File
@@ -1545,7 +1545,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QListWidget" name="configsList">
<widget class="QTreeWidget" name="configsList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -1555,6 +1555,17 @@
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
-16
View File
@@ -598,22 +598,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>Open settings.cfg</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt; and &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains a &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; doesn&apos;t have an &lt;b&gt;openmw.cfg&lt;/b&gt; or &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
-16
View File
@@ -598,22 +598,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>Open settings.cfg</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt; and &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains a &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; doesn&apos;t have an &lt;b&gt;openmw.cfg&lt;/b&gt; or &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
-16
View File
@@ -598,22 +598,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>Open settings.cfg</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt; and &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains a &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; doesn&apos;t have an &lt;b&gt;openmw.cfg&lt;/b&gt; or &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
-16
View File
@@ -602,22 +602,6 @@ do domyślnych czcionek Morrowind. Zaznacz to pole, jeśli nadal wolisz oryginal
<source>Open settings.cfg</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt; and &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains a &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; doesn&apos;t have an &lt;b&gt;openmw.cfg&lt;/b&gt; or &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
-16
View File
@@ -628,22 +628,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
<source>Open settings.cfg</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt; and &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains a &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; doesn&apos;t have an &lt;b&gt;openmw.cfg&lt;/b&gt; or &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>
-16
View File
@@ -601,22 +601,6 @@ de ordinarie fonterna i Morrowind. Bocka denna ruta om du ändå föredrar ordin
<source>Open settings.cfg</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt; and &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains an &lt;b&gt;openmw.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; contains a &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&lt;b&gt;%1&lt;/b&gt; doesn&apos;t have an &lt;b&gt;openmw.cfg&lt;/b&gt; or &lt;b&gt;settings.cfg&lt;/b&gt;</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MainWindow</name>