commit 8cb93c2f
Add option to add more "roots"
Changed files
| M | src/mainwindow.cpp before |
| M | src/mainwindow.h before |
| M | src/preferencesdialog.cpp before |
| M | src/preferencesdialog.h before |
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index ef3ff04..3fadf22 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -116,15 +116,6 @@ void MainWindow::setupUi()
m_rootList = new QListWidget;
m_rootList->setSelectionMode(QAbstractItemView::SingleSelection);
- auto addRootItem = [this](const QString &label, const QString &path) {
- QListWidgetItem *item = new QListWidgetItem(label, m_rootList);
- item->setData(Qt::UserRole, path);
- };
- addRootItem(tr("Home"), QDir::homePath());
- addRootItem(tr("Pictures"), QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
- addRootItem(tr("File System"), QDir::rootPath());
- m_rootList->setCurrentRow(0);
-
m_treeView = new QTreeView;
m_treeView->setModel(m_dirModel);
m_treeView->setRootIndex(m_dirModel->rootIndex());
@@ -979,6 +970,14 @@ void MainWindow::loadPreferences()
m_imageModel->setCacheMaxSize(m_folderCacheSizePreference);
m_thumbnailCacheSizePreference = settings.value("thumbnailCacheSize", "normal").toString();
m_imageModel->setThumbnailSize(thumbnailSizeFromString(m_thumbnailCacheSizePreference));
+ m_rootLabelsPreference = settings.value("rootLabels").toStringList();
+ m_rootPathsPreference = settings.value("rootPaths").toStringList();
+ if (m_rootLabelsPreference.isEmpty() || m_rootPathsPreference.isEmpty()) {
+ m_rootLabelsPreference = {tr("Home"), tr("Pictures"), tr("File System")};
+ m_rootPathsPreference = {QDir::homePath(), QStandardPaths::writableLocation(QStandardPaths::PicturesLocation), QDir::rootPath()};
+ }
+ updateRootList();
+
ShortcutManager::instance().load(settings);
if (settings.contains("windowGeometry"))
restoreGeometry(settings.value("windowGeometry").toByteArray());
@@ -993,6 +992,8 @@ void MainWindow::savePreferences()
settings.setValue("lockDocking", m_lockDockingPreference);
settings.setValue("folderCacheSize", m_folderCacheSizePreference);
settings.setValue("thumbnailCacheSize", m_thumbnailCacheSizePreference);
+ settings.setValue("rootLabels", m_rootLabelsPreference);
+ settings.setValue("rootPaths", m_rootPathsPreference);
ShortcutManager::instance().save(settings);
settings.setValue("windowGeometry", saveGeometry());
settings.setValue("windowState", saveState());
@@ -1005,6 +1006,8 @@ void MainWindow::onPreferencesTriggered()
dialog.setLockDocking(m_lockDockingPreference);
dialog.setCacheSize(m_folderCacheSizePreference);
dialog.setThumbnailCacheSize(m_thumbnailCacheSizePreference);
+ dialog.setRootLabels(m_rootLabelsPreference);
+ dialog.setRootPaths(m_rootPathsPreference);
// Populate shortcuts tab from current bindings
{
@@ -1036,6 +1039,10 @@ void MainWindow::onPreferencesTriggered()
loadVisibleThumbnails();
}
+ m_rootLabelsPreference = dialog.getRootLabels();
+ m_rootPathsPreference = dialog.getRootPaths();
+ updateRootList();
+
// Apply shortcut changes
QMap<int, QKeySequence> scMap = dialog.getShortcuts();
for (auto it = scMap.cbegin(); it != scMap.cend(); ++it)
@@ -1081,3 +1088,14 @@ void MainWindow::resetLayoutToDefault()
m_folderDock->show();
m_previewDock->show();
}
+
+void MainWindow::updateRootList()
+{
+ m_rootList->clear();
+ for (int i = 0; i < m_rootLabelsPreference.size() && i < m_rootPathsPreference.size(); ++i) {
+ QListWidgetItem *item = new QListWidgetItem(m_rootLabelsPreference[i], m_rootList);
+ item->setData(Qt::UserRole, m_rootPathsPreference[i]);
+ }
+ if (m_rootList->count() > 0)
+ m_rootList->setCurrentRow(0);
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 9899878..6b784f6 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -84,6 +84,7 @@ private:
QByteArray siblingFolder(int delta) const;
void navigateToPrevFolder();
void navigateToNextFolder();
+ void updateRootList();
void keyPressEvent(QKeyEvent *event) override;
bool eventFilter(QObject *obj, QEvent *event) override;
@@ -107,6 +108,8 @@ private:
QString m_backgroundColorPreference = "black";
int m_folderCacheSizePreference = 4;
QString m_thumbnailCacheSizePreference = "normal";
+ QStringList m_rootLabelsPreference;
+ QStringList m_rootPathsPreference;
QWidget *m_browserPage;
ImageViewWidget *m_imageView;
bool m_wasMaximized = false;
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index 80fc3f8..7e21b35 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -37,6 +37,7 @@ SOFTWARE.
#include <QTableWidget>
#include <QKeySequenceEdit>
#include <QHeaderView>
+#include <QFileDialog>
PreferencesDialog::PreferencesDialog(QWidget *parent)
: QDialog(parent)
@@ -50,6 +51,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent)
QTabWidget *tabs = new QTabWidget(this);
setupGeneralTab(tabs);
setupShortcutsTab(tabs);
+ setupRootsTab(tabs);
mainLayout->addWidget(tabs);
QHBoxLayout *buttonLayout = new QHBoxLayout;
@@ -227,6 +229,48 @@ void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs)
tabs->addTab(page, tr("Shortcuts"));
}
+void PreferencesDialog::setupRootsTab(QTabWidget *tabs)
+{
+ QWidget *page = new QWidget;
+ QVBoxLayout *pageLayout = new QVBoxLayout(page);
+
+ m_rootsTable = new QTableWidget(0, 2, page);
+ m_rootsTable->setHorizontalHeaderLabels({tr("Label"), tr("Path")});
+ m_rootsTable->horizontalHeader()->setStretchLastSection(true);
+ m_rootsTable->verticalHeader()->hide();
+ m_rootsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+ m_rootsTable->setSelectionMode(QAbstractItemView::SingleSelection);
+
+ pageLayout->addWidget(m_rootsTable);
+
+ QHBoxLayout *btnLayout = new QHBoxLayout;
+ QPushButton *addBtn = new QPushButton(tr("Add"));
+ QPushButton *removeBtn = new QPushButton(tr("Remove"));
+ btnLayout->addStretch();
+ btnLayout->addWidget(addBtn);
+ btnLayout->addWidget(removeBtn);
+ pageLayout->addLayout(btnLayout);
+
+ connect(addBtn, &QPushButton::clicked, this, [this]() {
+ QString dir = QFileDialog::getExistingDirectory(this, tr("Select Root Directory"));
+ if (!dir.isEmpty()) {
+ int row = m_rootsTable->rowCount();
+ m_rootsTable->insertRow(row);
+ m_rootsTable->setItem(row, 0, new QTableWidgetItem(QFileInfo(dir).fileName()));
+ m_rootsTable->setItem(row, 1, new QTableWidgetItem(dir));
+ }
+ });
+
+ connect(removeBtn, &QPushButton::clicked, this, [this]() {
+ int row = m_rootsTable->currentRow();
+ if (row >= 0) {
+ m_rootsTable->removeRow(row);
+ }
+ });
+
+ tabs->addTab(page, tr("Roots"));
+}
+
void PreferencesDialog::highlightConflicts()
{
// Group sequences by category, then detect conflicts within each category.
@@ -354,3 +398,43 @@ void PreferencesDialog::setResetLayout(bool reset)
{
m_resetLayoutCheck->setChecked(reset);
}
+
+QStringList PreferencesDialog::getRootLabels() const
+{
+ QStringList labels;
+ for (int i = 0; i < m_rootsTable->rowCount(); ++i) {
+ labels << m_rootsTable->item(i, 0)->text();
+ }
+ return labels;
+}
+
+void PreferencesDialog::setRootLabels(const QStringList &labels)
+{
+ if (m_rootsTable->rowCount() < labels.size())
+ m_rootsTable->setRowCount(labels.size());
+ for (int i = 0; i < labels.size(); ++i) {
+ if (!m_rootsTable->item(i, 0))
+ m_rootsTable->setItem(i, 0, new QTableWidgetItem);
+ m_rootsTable->item(i, 0)->setText(labels[i]);
+ }
+}
+
+QStringList PreferencesDialog::getRootPaths() const
+{
+ QStringList paths;
+ for (int i = 0; i < m_rootsTable->rowCount(); ++i) {
+ paths << m_rootsTable->item(i, 1)->text();
+ }
+ return paths;
+}
+
+void PreferencesDialog::setRootPaths(const QStringList &paths)
+{
+ if (m_rootsTable->rowCount() < paths.size())
+ m_rootsTable->setRowCount(paths.size());
+ for (int i = 0; i < paths.size(); ++i) {
+ if (!m_rootsTable->item(i, 1))
+ m_rootsTable->setItem(i, 1, new QTableWidgetItem);
+ m_rootsTable->item(i, 1)->setText(paths[i]);
+ }
+}
diff --git a/src/preferencesdialog.h b/src/preferencesdialog.h
index d1e6dfc..b4d3c29 100644
--- a/src/preferencesdialog.h
+++ b/src/preferencesdialog.h
@@ -60,12 +60,19 @@ public:
QMap<int, QKeySequence> getShortcuts() const;
void setShortcuts(const QMap<int, QKeySequence> &map);
+ QStringList getRootLabels() const;
+ void setRootLabels(const QStringList &labels);
+
+ QStringList getRootPaths() const;
+ void setRootPaths(const QStringList &paths);
+
signals:
void resetLayoutRequested();
private:
void setupGeneralTab(QTabWidget *tabs);
void setupShortcutsTab(QTabWidget *tabs);
+ void setupRootsTab(QTabWidget *tabs);
void highlightConflicts();
QComboBox *m_backgroundColorCombo;
@@ -74,5 +81,6 @@ private:
QCheckBox *m_lockDockingCheck;
QCheckBox *m_resetLayoutCheck;
QTableWidget *m_shortcutsTable = nullptr;
+ QTableWidget *m_rootsTable = nullptr;
QList<int> m_rowToAction; // maps table row → ShortcutManager::Action
};