git repos / SagoImageBrowser

blame: src/preferencesdialog.cpp

normal view · raw

14cf904f Poul Sander 2026-06-22 18:18 1
/*
14cf904f Poul Sander 2026-06-22 18:18 2
MIT License
14cf904f Poul Sander 2026-06-22 18:18 3
14cf904f Poul Sander 2026-06-22 18:18 4
Copyright (c) 2026 Poul Sander
14cf904f Poul Sander 2026-06-22 18:18 5
14cf904f Poul Sander 2026-06-22 18:18 6
Permission is hereby granted, free of charge, to any person obtaining a copy
14cf904f Poul Sander 2026-06-22 18:18 7
of this software and associated documentation files (the "Software"), to deal
14cf904f Poul Sander 2026-06-22 18:18 8
in the Software without restriction, including without limitation the rights
14cf904f Poul Sander 2026-06-22 18:18 9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14cf904f Poul Sander 2026-06-22 18:18 10
copies of the Software, and to permit persons to whom the Software is
14cf904f Poul Sander 2026-06-22 18:18 11
furnished to do so, subject to the following conditions:
14cf904f Poul Sander 2026-06-22 18:18 12
14cf904f Poul Sander 2026-06-22 18:18 13
The above copyright notice and this permission notice shall be included in all
14cf904f Poul Sander 2026-06-22 18:18 14
copies or substantial portions of the Software.
14cf904f Poul Sander 2026-06-22 18:18 15
14cf904f Poul Sander 2026-06-22 18:18 16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14cf904f Poul Sander 2026-06-22 18:18 17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14cf904f Poul Sander 2026-06-22 18:18 18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14cf904f Poul Sander 2026-06-22 18:18 19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14cf904f Poul Sander 2026-06-22 18:18 20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14cf904f Poul Sander 2026-06-22 18:18 21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
14cf904f Poul Sander 2026-06-22 18:18 22
SOFTWARE.
14cf904f Poul Sander 2026-06-22 18:18 23
14cf904f Poul Sander 2026-06-22 18:18 24
*/
14cf904f Poul Sander 2026-06-22 18:18 25
10d6e6f8 Poul Sander 2026-02-24 18:40 26
#include "preferencesdialog.h"
83f0e0bc Poul Sander 2026-05-30 17:59 27
#include "shortcutmanager.h"
10d6e6f8 Poul Sander 2026-02-24 18:40 28
10d6e6f8 Poul Sander 2026-02-24 18:40 29
#include <QHBoxLayout>
10d6e6f8 Poul Sander 2026-02-24 18:40 30
#include <QLabel>
10d6e6f8 Poul Sander 2026-02-24 18:40 31
#include <QComboBox>
459bad0f Poul Sander 2026-05-17 14:11 32
#include <QSpinBox>
4ae57f60 Poul Sander 2026-02-25 21:35 33
#include <QCheckBox>
10d6e6f8 Poul Sander 2026-02-24 18:40 34
#include <QPushButton>
10d6e6f8 Poul Sander 2026-02-24 18:40 35
#include <QGroupBox>
83f0e0bc Poul Sander 2026-05-30 17:59 36
#include <QTabWidget>
83f0e0bc Poul Sander 2026-05-30 17:59 37
#include <QTableWidget>
83f0e0bc Poul Sander 2026-05-30 17:59 38
#include <QKeySequenceEdit>
83f0e0bc Poul Sander 2026-05-30 17:59 39
#include <QHeaderView>
8cb93c2f Poul Sander 2026-06-28 19:31 40
#include <QFileDialog>
10d6e6f8 Poul Sander 2026-02-24 18:40 41
10d6e6f8 Poul Sander 2026-02-24 18:40 42
PreferencesDialog::PreferencesDialog(QWidget *parent)
10d6e6f8 Poul Sander 2026-02-24 18:40 43
    : QDialog(parent)
10d6e6f8 Poul Sander 2026-02-24 18:40 44
{
4c41f5ff Poul Sander 2026-05-31 00:01 45
    setWindowTitle(tr("Preferences"));
10d6e6f8 Poul Sander 2026-02-24 18:40 46
    setModal(true);
83f0e0bc Poul Sander 2026-05-30 17:59 47
    setMinimumWidth(500);
10d6e6f8 Poul Sander 2026-02-24 18:40 48
10d6e6f8 Poul Sander 2026-02-24 18:40 49
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
10d6e6f8 Poul Sander 2026-02-24 18:40 50
83f0e0bc Poul Sander 2026-05-30 17:59 51
    QTabWidget *tabs = new QTabWidget(this);
83f0e0bc Poul Sander 2026-05-30 17:59 52
    setupGeneralTab(tabs);
83f0e0bc Poul Sander 2026-05-30 17:59 53
    setupShortcutsTab(tabs);
8cb93c2f Poul Sander 2026-06-28 19:31 54
    setupRootsTab(tabs);
83f0e0bc Poul Sander 2026-05-30 17:59 55
    mainLayout->addWidget(tabs);
83f0e0bc Poul Sander 2026-05-30 17:59 56
83f0e0bc Poul Sander 2026-05-30 17:59 57
    QHBoxLayout *buttonLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 58
    QPushButton *okButton = new QPushButton(tr("OK"));
4c41f5ff Poul Sander 2026-05-31 00:01 59
    QPushButton *cancelButton = new QPushButton(tr("Cancel"));
83f0e0bc Poul Sander 2026-05-30 17:59 60
83f0e0bc Poul Sander 2026-05-30 17:59 61
    buttonLayout->addStretch();
83f0e0bc Poul Sander 2026-05-30 17:59 62
    buttonLayout->addWidget(okButton);
83f0e0bc Poul Sander 2026-05-30 17:59 63
    buttonLayout->addWidget(cancelButton);
83f0e0bc Poul Sander 2026-05-30 17:59 64
83f0e0bc Poul Sander 2026-05-30 17:59 65
    mainLayout->addLayout(buttonLayout);
83f0e0bc Poul Sander 2026-05-30 17:59 66
83f0e0bc Poul Sander 2026-05-30 17:59 67
    connect(okButton, &QPushButton::clicked, this, [this]() {
83f0e0bc Poul Sander 2026-05-30 17:59 68
        if (m_resetLayoutCheck->isChecked())
83f0e0bc Poul Sander 2026-05-30 17:59 69
            emit resetLayoutRequested();
83f0e0bc Poul Sander 2026-05-30 17:59 70
        accept();
83f0e0bc Poul Sander 2026-05-30 17:59 71
    });
83f0e0bc Poul Sander 2026-05-30 17:59 72
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
83f0e0bc Poul Sander 2026-05-30 17:59 73
}
83f0e0bc Poul Sander 2026-05-30 17:59 74
83f0e0bc Poul Sander 2026-05-30 17:59 75
void PreferencesDialog::setupGeneralTab(QTabWidget *tabs)
83f0e0bc Poul Sander 2026-05-30 17:59 76
{
83f0e0bc Poul Sander 2026-05-30 17:59 77
    QWidget *page = new QWidget;
83f0e0bc Poul Sander 2026-05-30 17:59 78
    QVBoxLayout *pageLayout = new QVBoxLayout(page);
83f0e0bc Poul Sander 2026-05-30 17:59 79
4c41f5ff Poul Sander 2026-05-31 00:01 80
    QGroupBox *imageGroup = new QGroupBox(tr("Image Viewer"), page);
10d6e6f8 Poul Sander 2026-02-24 18:40 81
    QVBoxLayout *groupLayout = new QVBoxLayout(imageGroup);
10d6e6f8 Poul Sander 2026-02-24 18:40 82
10d6e6f8 Poul Sander 2026-02-24 18:40 83
    QHBoxLayout *bgColorLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 84
    QLabel *bgColorLabel = new QLabel(tr("Background Color:"));
10d6e6f8 Poul Sander 2026-02-24 18:40 85
    m_backgroundColorCombo = new QComboBox;
4c41f5ff Poul Sander 2026-05-31 00:01 86
    m_backgroundColorCombo->addItem(tr("Black"), "black");
4c41f5ff Poul Sander 2026-05-31 00:01 87
    m_backgroundColorCombo->addItem(tr("White"), "white");
4c41f5ff Poul Sander 2026-05-31 00:01 88
    m_backgroundColorCombo->addItem(tr("Dark Gray"), "darkgray");
10d6e6f8 Poul Sander 2026-02-24 18:40 89
10d6e6f8 Poul Sander 2026-02-24 18:40 90
    bgColorLayout->addWidget(bgColorLabel);
10d6e6f8 Poul Sander 2026-02-24 18:40 91
    bgColorLayout->addWidget(m_backgroundColorCombo);
10d6e6f8 Poul Sander 2026-02-24 18:40 92
    bgColorLayout->addStretch();
10d6e6f8 Poul Sander 2026-02-24 18:40 93
10d6e6f8 Poul Sander 2026-02-24 18:40 94
    groupLayout->addLayout(bgColorLayout);
459bad0f Poul Sander 2026-05-17 14:11 95
459bad0f Poul Sander 2026-05-17 14:11 96
    QHBoxLayout *cacheSizeLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 97
    QLabel *cacheSizeLabel = new QLabel(tr("Folder thumbnail cache (folders):"));
459bad0f Poul Sander 2026-05-17 14:11 98
    m_cacheSizeSpinBox = new QSpinBox;
459bad0f Poul Sander 2026-05-17 14:11 99
    m_cacheSizeSpinBox->setRange(1, 20);
459bad0f Poul Sander 2026-05-17 14:11 100
    m_cacheSizeSpinBox->setValue(4);
459bad0f Poul Sander 2026-05-17 14:11 101
    cacheSizeLayout->addWidget(cacheSizeLabel);
459bad0f Poul Sander 2026-05-17 14:11 102
    cacheSizeLayout->addWidget(m_cacheSizeSpinBox);
459bad0f Poul Sander 2026-05-17 14:11 103
    cacheSizeLayout->addStretch();
459bad0f Poul Sander 2026-05-17 14:11 104
    groupLayout->addLayout(cacheSizeLayout);
459bad0f Poul Sander 2026-05-17 14:11 105
ac476ca8 Poul Sander 2026-05-18 16:47 106
    QHBoxLayout *thumbSizeLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 107
    QLabel *thumbSizeLabel = new QLabel(tr("Thumbnail cache size:"));
ac476ca8 Poul Sander 2026-05-18 16:47 108
    m_thumbnailSizeCombo = new QComboBox;
4c41f5ff Poul Sander 2026-05-31 00:01 109
    m_thumbnailSizeCombo->addItem(tr("Normal (128 px)"), "normal");
4c41f5ff Poul Sander 2026-05-31 00:01 110
    m_thumbnailSizeCombo->addItem(tr("Large (256 px)"), "large");
ac476ca8 Poul Sander 2026-05-18 16:47 111
    thumbSizeLayout->addWidget(thumbSizeLabel);
ac476ca8 Poul Sander 2026-05-18 16:47 112
    thumbSizeLayout->addWidget(m_thumbnailSizeCombo);
ac476ca8 Poul Sander 2026-05-18 16:47 113
    thumbSizeLayout->addStretch();
ac476ca8 Poul Sander 2026-05-18 16:47 114
    groupLayout->addLayout(thumbSizeLayout);
ac476ca8 Poul Sander 2026-05-18 16:47 115
83f0e0bc Poul Sander 2026-05-30 17:59 116
    pageLayout->addWidget(imageGroup);
10d6e6f8 Poul Sander 2026-02-24 18:40 117
4c41f5ff Poul Sander 2026-05-31 00:01 118
    QGroupBox *layoutGroup = new QGroupBox(tr("Layout"), page);
4ae57f60 Poul Sander 2026-02-25 21:35 119
    QVBoxLayout *layoutGroupLayout = new QVBoxLayout(layoutGroup);
4c41f5ff Poul Sander 2026-05-31 00:01 120
    m_lockDockingCheck = new QCheckBox(tr("Lock docking (prevent accidental moves)"));
4ae57f60 Poul Sander 2026-02-25 21:35 121
    layoutGroupLayout->addWidget(m_lockDockingCheck);
83f0e0bc Poul Sander 2026-05-30 17:59 122
4c41f5ff Poul Sander 2026-05-31 00:01 123
    m_resetLayoutCheck = new QCheckBox(tr("Reset layout to default when closing the menu"));
d1aa6cbe Poul Sander 2026-03-02 16:57 124
    layoutGroupLayout->addWidget(m_resetLayoutCheck);
4ae57f60 Poul Sander 2026-02-25 21:35 125
83f0e0bc Poul Sander 2026-05-30 17:59 126
    pageLayout->addWidget(layoutGroup);
83f0e0bc Poul Sander 2026-05-30 17:59 127
    pageLayout->addStretch();
10d6e6f8 Poul Sander 2026-02-24 18:40 128
4c41f5ff Poul Sander 2026-05-31 00:01 129
    tabs->addTab(page, tr("General"));
83f0e0bc Poul Sander 2026-05-30 17:59 130
}
10d6e6f8 Poul Sander 2026-02-24 18:40 131
83f0e0bc Poul Sander 2026-05-30 17:59 132
void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs)
83f0e0bc Poul Sander 2026-05-30 17:59 133
{
83f0e0bc Poul Sander 2026-05-30 17:59 134
    QWidget *page = new QWidget;
83f0e0bc Poul Sander 2026-05-30 17:59 135
    QVBoxLayout *pageLayout = new QVBoxLayout(page);
10d6e6f8 Poul Sander 2026-02-24 18:40 136
83f0e0bc Poul Sander 2026-05-30 17:59 137
    // Count configurable actions to size the table (plus 2 section header rows)
83f0e0bc Poul Sander 2026-05-30 17:59 138
    int configurableCount = 0;
83f0e0bc Poul Sander 2026-05-30 17:59 139
    for (int i = 0; i < ShortcutManager::ActionCount; ++i) {
83f0e0bc Poul Sander 2026-05-30 17:59 140
        if (ShortcutManager::actionCategory(static_cast<ShortcutManager::Action>(i))
83f0e0bc Poul Sander 2026-05-30 17:59 141
            != ShortcutManager::CatNotConfigurable)
83f0e0bc Poul Sander 2026-05-30 17:59 142
            ++configurableCount;
83f0e0bc Poul Sander 2026-05-30 17:59 143
    }
83f0e0bc Poul Sander 2026-05-30 17:59 144
    // +2 for section headers (Image Viewer, Browser)
83f0e0bc Poul Sander 2026-05-30 17:59 145
    const int totalRows = configurableCount + 2;
10d6e6f8 Poul Sander 2026-02-24 18:40 146
83f0e0bc Poul Sander 2026-05-30 17:59 147
    m_shortcutsTable = new QTableWidget(totalRows, 2, page);
4c41f5ff Poul Sander 2026-05-31 00:01 148
    m_shortcutsTable->setHorizontalHeaderLabels({tr("Action"), tr("Key")});
83f0e0bc Poul Sander 2026-05-30 17:59 149
    m_shortcutsTable->horizontalHeader()->setStretchLastSection(true);
83f0e0bc Poul Sander 2026-05-30 17:59 150
    m_shortcutsTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
83f0e0bc Poul Sander 2026-05-30 17:59 151
    m_shortcutsTable->verticalHeader()->hide();
83f0e0bc Poul Sander 2026-05-30 17:59 152
    m_shortcutsTable->setSelectionMode(QAbstractItemView::SingleSelection);
83f0e0bc Poul Sander 2026-05-30 17:59 153
83f0e0bc Poul Sander 2026-05-30 17:59 154
    m_rowToAction.clear();
83f0e0bc Poul Sander 2026-05-30 17:59 155
    const ShortcutManager &mgr = ShortcutManager::instance();
83f0e0bc Poul Sander 2026-05-30 17:59 156
    int row = 0;
83f0e0bc Poul Sander 2026-05-30 17:59 157
83f0e0bc Poul Sander 2026-05-30 17:59 158
    auto addSectionHeader = [&](const QString &title) {
83f0e0bc Poul Sander 2026-05-30 17:59 159
        auto *item = new QTableWidgetItem(title);
83f0e0bc Poul Sander 2026-05-30 17:59 160
        item->setFlags(Qt::NoItemFlags);
83f0e0bc Poul Sander 2026-05-30 17:59 161
        QFont f = item->font();
83f0e0bc Poul Sander 2026-05-30 17:59 162
        f.setBold(true);
83f0e0bc Poul Sander 2026-05-30 17:59 163
        item->setFont(f);
83f0e0bc Poul Sander 2026-05-30 17:59 164
        item->setBackground(palette().alternateBase());
83f0e0bc Poul Sander 2026-05-30 17:59 165
        m_shortcutsTable->setItem(row, 0, item);
83f0e0bc Poul Sander 2026-05-30 17:59 166
        auto *emptyItem = new QTableWidgetItem();
83f0e0bc Poul Sander 2026-05-30 17:59 167
        emptyItem->setFlags(Qt::NoItemFlags);
83f0e0bc Poul Sander 2026-05-30 17:59 168
        emptyItem->setBackground(palette().alternateBase());
83f0e0bc Poul Sander 2026-05-30 17:59 169
        m_shortcutsTable->setItem(row, 1, emptyItem);
83f0e0bc Poul Sander 2026-05-30 17:59 170
        m_rowToAction.append(-1); // -1 = section header
83f0e0bc Poul Sander 2026-05-30 17:59 171
        ++row;
83f0e0bc Poul Sander 2026-05-30 17:59 172
    };
83f0e0bc Poul Sander 2026-05-30 17:59 173
83f0e0bc Poul Sander 2026-05-30 17:59 174
    auto addAction = [&](ShortcutManager::Action action) {
83f0e0bc Poul Sander 2026-05-30 17:59 175
        auto *descItem = new QTableWidgetItem(mgr.description(action));
83f0e0bc Poul Sander 2026-05-30 17:59 176
        descItem->setFlags(descItem->flags() & ~Qt::ItemIsEditable);
83f0e0bc Poul Sander 2026-05-30 17:59 177
        m_shortcutsTable->setItem(row, 0, descItem);
83f0e0bc Poul Sander 2026-05-30 17:59 178
83f0e0bc Poul Sander 2026-05-30 17:59 179
        auto *edit = new QKeySequenceEdit(mgr.shortcut(action));
4c41f5ff Poul Sander 2026-05-31 00:01 180
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
83f0e0bc Poul Sander 2026-05-30 17:59 181
        edit->setMaximumSequenceLength(1);
4c41f5ff Poul Sander 2026-05-31 00:01 182
#endif
83f0e0bc Poul Sander 2026-05-30 17:59 183
        connect(edit, &QKeySequenceEdit::keySequenceChanged, this, [this]() {
83f0e0bc Poul Sander 2026-05-30 17:59 184
            highlightConflicts();
83f0e0bc Poul Sander 2026-05-30 17:59 185
        });
83f0e0bc Poul Sander 2026-05-30 17:59 186
        m_shortcutsTable->setCellWidget(row, 1, edit);
83f0e0bc Poul Sander 2026-05-30 17:59 187
        m_rowToAction.append(static_cast<int>(action));
83f0e0bc Poul Sander 2026-05-30 17:59 188
        ++row;
83f0e0bc Poul Sander 2026-05-30 17:59 189
    };
83f0e0bc Poul Sander 2026-05-30 17:59 190
83f0e0bc Poul Sander 2026-05-30 17:59 191
    // Image Viewer section
4c41f5ff Poul Sander 2026-05-31 00:01 192
    addSectionHeader(tr("Image Viewer"));
83f0e0bc Poul Sander 2026-05-30 17:59 193
    for (int i = 0; i < ShortcutManager::ActionCount; ++i) {
83f0e0bc Poul Sander 2026-05-30 17:59 194
        auto action = static_cast<ShortcutManager::Action>(i);
83f0e0bc Poul Sander 2026-05-30 17:59 195
        if (ShortcutManager::actionCategory(action) == ShortcutManager::CatImageViewer)
83f0e0bc Poul Sander 2026-05-30 17:59 196
            addAction(action);
83f0e0bc Poul Sander 2026-05-30 17:59 197
    }
83f0e0bc Poul Sander 2026-05-30 17:59 198
83f0e0bc Poul Sander 2026-05-30 17:59 199
    // Browser section
4c41f5ff Poul Sander 2026-05-31 00:01 200
    addSectionHeader(tr("Browser"));
83f0e0bc Poul Sander 2026-05-30 17:59 201
    for (int i = 0; i < ShortcutManager::ActionCount; ++i) {
83f0e0bc Poul Sander 2026-05-30 17:59 202
        auto action = static_cast<ShortcutManager::Action>(i);
83f0e0bc Poul Sander 2026-05-30 17:59 203
        if (ShortcutManager::actionCategory(action) == ShortcutManager::CatBrowser)
83f0e0bc Poul Sander 2026-05-30 17:59 204
            addAction(action);
83f0e0bc Poul Sander 2026-05-30 17:59 205
    }
83f0e0bc Poul Sander 2026-05-30 17:59 206
83f0e0bc Poul Sander 2026-05-30 17:59 207
    pageLayout->addWidget(m_shortcutsTable);
83f0e0bc Poul Sander 2026-05-30 17:59 208
83f0e0bc Poul Sander 2026-05-30 17:59 209
    QHBoxLayout *btnLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 210
    QPushButton *resetBtn = new QPushButton(tr("Reset to Defaults"));
83f0e0bc Poul Sander 2026-05-30 17:59 211
    btnLayout->addStretch();
83f0e0bc Poul Sander 2026-05-30 17:59 212
    btnLayout->addWidget(resetBtn);
83f0e0bc Poul Sander 2026-05-30 17:59 213
    pageLayout->addLayout(btnLayout);
83f0e0bc Poul Sander 2026-05-30 17:59 214
83f0e0bc Poul Sander 2026-05-30 17:59 215
    connect(resetBtn, &QPushButton::clicked, this, [this]() {
83f0e0bc Poul Sander 2026-05-30 17:59 216
        for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 217
            int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 218
            if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 219
                continue;
83f0e0bc Poul Sander 2026-05-30 17:59 220
            auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 221
                m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 222
            if (edit)
83f0e0bc Poul Sander 2026-05-30 17:59 223
                edit->setKeySequence(ShortcutManager::defaultShortcut(
83f0e0bc Poul Sander 2026-05-30 17:59 224
                    static_cast<ShortcutManager::Action>(actionIdx)));
83f0e0bc Poul Sander 2026-05-30 17:59 225
        }
83f0e0bc Poul Sander 2026-05-30 17:59 226
        highlightConflicts();
d1aa6cbe Poul Sander 2026-03-02 16:57 227
    });
83f0e0bc Poul Sander 2026-05-30 17:59 228
4c41f5ff Poul Sander 2026-05-31 00:01 229
    tabs->addTab(page, tr("Shortcuts"));
83f0e0bc Poul Sander 2026-05-30 17:59 230
}
83f0e0bc Poul Sander 2026-05-30 17:59 231
8cb93c2f Poul Sander 2026-06-28 19:31 232
void PreferencesDialog::setupRootsTab(QTabWidget *tabs)
8cb93c2f Poul Sander 2026-06-28 19:31 233
{
8cb93c2f Poul Sander 2026-06-28 19:31 234
    QWidget *page = new QWidget;
8cb93c2f Poul Sander 2026-06-28 19:31 235
    QVBoxLayout *pageLayout = new QVBoxLayout(page);
8cb93c2f Poul Sander 2026-06-28 19:31 236
8cb93c2f Poul Sander 2026-06-28 19:31 237
    m_rootsTable = new QTableWidget(0, 2, page);
8cb93c2f Poul Sander 2026-06-28 19:31 238
    m_rootsTable->setHorizontalHeaderLabels({tr("Label"), tr("Path")});
8cb93c2f Poul Sander 2026-06-28 19:31 239
    m_rootsTable->horizontalHeader()->setStretchLastSection(true);
8cb93c2f Poul Sander 2026-06-28 19:31 240
    m_rootsTable->verticalHeader()->hide();
8cb93c2f Poul Sander 2026-06-28 19:31 241
    m_rootsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
8cb93c2f Poul Sander 2026-06-28 19:31 242
    m_rootsTable->setSelectionMode(QAbstractItemView::SingleSelection);
8cb93c2f Poul Sander 2026-06-28 19:31 243
8cb93c2f Poul Sander 2026-06-28 19:31 244
    pageLayout->addWidget(m_rootsTable);
8cb93c2f Poul Sander 2026-06-28 19:31 245
8cb93c2f Poul Sander 2026-06-28 19:31 246
    QHBoxLayout *btnLayout = new QHBoxLayout;
8cb93c2f Poul Sander 2026-06-28 19:31 247
    QPushButton *addBtn = new QPushButton(tr("Add"));
8cb93c2f Poul Sander 2026-06-28 19:31 248
    QPushButton *removeBtn = new QPushButton(tr("Remove"));
8cb93c2f Poul Sander 2026-06-28 19:31 249
    btnLayout->addStretch();
8cb93c2f Poul Sander 2026-06-28 19:31 250
    btnLayout->addWidget(addBtn);
8cb93c2f Poul Sander 2026-06-28 19:31 251
    btnLayout->addWidget(removeBtn);
8cb93c2f Poul Sander 2026-06-28 19:31 252
    pageLayout->addLayout(btnLayout);
8cb93c2f Poul Sander 2026-06-28 19:31 253
8cb93c2f Poul Sander 2026-06-28 19:31 254
    connect(addBtn, &QPushButton::clicked, this, [this]() {
8cb93c2f Poul Sander 2026-06-28 19:31 255
        QString dir = QFileDialog::getExistingDirectory(this, tr("Select Root Directory"));
8cb93c2f Poul Sander 2026-06-28 19:31 256
        if (!dir.isEmpty()) {
8cb93c2f Poul Sander 2026-06-28 19:31 257
            int row = m_rootsTable->rowCount();
8cb93c2f Poul Sander 2026-06-28 19:31 258
            m_rootsTable->insertRow(row);
8cb93c2f Poul Sander 2026-06-28 19:31 259
            m_rootsTable->setItem(row, 0, new QTableWidgetItem(QFileInfo(dir).fileName()));
8cb93c2f Poul Sander 2026-06-28 19:31 260
            m_rootsTable->setItem(row, 1, new QTableWidgetItem(dir));
8cb93c2f Poul Sander 2026-06-28 19:31 261
        }
8cb93c2f Poul Sander 2026-06-28 19:31 262
    });
8cb93c2f Poul Sander 2026-06-28 19:31 263
8cb93c2f Poul Sander 2026-06-28 19:31 264
    connect(removeBtn, &QPushButton::clicked, this, [this]() {
8cb93c2f Poul Sander 2026-06-28 19:31 265
        int row = m_rootsTable->currentRow();
8cb93c2f Poul Sander 2026-06-28 19:31 266
        if (row >= 0) {
8cb93c2f Poul Sander 2026-06-28 19:31 267
            m_rootsTable->removeRow(row);
8cb93c2f Poul Sander 2026-06-28 19:31 268
        }
8cb93c2f Poul Sander 2026-06-28 19:31 269
    });
8cb93c2f Poul Sander 2026-06-28 19:31 270
8cb93c2f Poul Sander 2026-06-28 19:31 271
    tabs->addTab(page, tr("Roots"));
8cb93c2f Poul Sander 2026-06-28 19:31 272
}
8cb93c2f Poul Sander 2026-06-28 19:31 273
83f0e0bc Poul Sander 2026-05-30 17:59 274
void PreferencesDialog::highlightConflicts()
83f0e0bc Poul Sander 2026-05-30 17:59 275
{
83f0e0bc Poul Sander 2026-05-30 17:59 276
    // Group sequences by category, then detect conflicts within each category.
83f0e0bc Poul Sander 2026-05-30 17:59 277
    // key: (category, sequenceString) → list of rows
83f0e0bc Poul Sander 2026-05-30 17:59 278
    QMap<QPair<int,QString>, QList<int>> catSeqToRows;
83f0e0bc Poul Sander 2026-05-30 17:59 279
83f0e0bc Poul Sander 2026-05-30 17:59 280
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 281
        int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 282
        if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 283
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 284
        auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 285
            m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 286
        if (!edit)
83f0e0bc Poul Sander 2026-05-30 17:59 287
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 288
        QString s = edit->keySequence().toString();
83f0e0bc Poul Sander 2026-05-30 17:59 289
        if (!s.isEmpty()) {
83f0e0bc Poul Sander 2026-05-30 17:59 290
            int cat = ShortcutManager::actionCategory(
83f0e0bc Poul Sander 2026-05-30 17:59 291
                static_cast<ShortcutManager::Action>(actionIdx));
83f0e0bc Poul Sander 2026-05-30 17:59 292
            catSeqToRows[{cat, s}].append(r);
83f0e0bc Poul Sander 2026-05-30 17:59 293
        }
83f0e0bc Poul Sander 2026-05-30 17:59 294
    }
83f0e0bc Poul Sander 2026-05-30 17:59 295
83f0e0bc Poul Sander 2026-05-30 17:59 296
    // Reset all backgrounds
83f0e0bc Poul Sander 2026-05-30 17:59 297
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 298
        if (m_rowToAction[r] < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 299
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 300
        QTableWidgetItem *item = m_shortcutsTable->item(r, 0);
83f0e0bc Poul Sander 2026-05-30 17:59 301
        if (item)
83f0e0bc Poul Sander 2026-05-30 17:59 302
            item->setBackground(QBrush());
83f0e0bc Poul Sander 2026-05-30 17:59 303
    }
83f0e0bc Poul Sander 2026-05-30 17:59 304
83f0e0bc Poul Sander 2026-05-30 17:59 305
    // Highlight conflicts (only within same category)
83f0e0bc Poul Sander 2026-05-30 17:59 306
    for (auto it = catSeqToRows.cbegin(); it != catSeqToRows.cend(); ++it) {
83f0e0bc Poul Sander 2026-05-30 17:59 307
        if (it.value().size() > 1) {
83f0e0bc Poul Sander 2026-05-30 17:59 308
            for (int r : it.value()) {
83f0e0bc Poul Sander 2026-05-30 17:59 309
                QTableWidgetItem *item = m_shortcutsTable->item(r, 0);
83f0e0bc Poul Sander 2026-05-30 17:59 310
                if (item)
83f0e0bc Poul Sander 2026-05-30 17:59 311
                    item->setBackground(QColor(255, 100, 100, 80));
83f0e0bc Poul Sander 2026-05-30 17:59 312
            }
83f0e0bc Poul Sander 2026-05-30 17:59 313
        }
83f0e0bc Poul Sander 2026-05-30 17:59 314
    }
83f0e0bc Poul Sander 2026-05-30 17:59 315
}
83f0e0bc Poul Sander 2026-05-30 17:59 316
83f0e0bc Poul Sander 2026-05-30 17:59 317
QMap<int, QKeySequence> PreferencesDialog::getShortcuts() const
83f0e0bc Poul Sander 2026-05-30 17:59 318
{
83f0e0bc Poul Sander 2026-05-30 17:59 319
    QMap<int, QKeySequence> map;
83f0e0bc Poul Sander 2026-05-30 17:59 320
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 321
        int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 322
        if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 323
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 324
        auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 325
            m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 326
        if (edit)
83f0e0bc Poul Sander 2026-05-30 17:59 327
            map[actionIdx] = edit->keySequence();
83f0e0bc Poul Sander 2026-05-30 17:59 328
    }
83f0e0bc Poul Sander 2026-05-30 17:59 329
    return map;
83f0e0bc Poul Sander 2026-05-30 17:59 330
}
83f0e0bc Poul Sander 2026-05-30 17:59 331
83f0e0bc Poul Sander 2026-05-30 17:59 332
void PreferencesDialog::setShortcuts(const QMap<int, QKeySequence> &map)
83f0e0bc Poul Sander 2026-05-30 17:59 333
{
83f0e0bc Poul Sander 2026-05-30 17:59 334
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 335
        int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 336
        if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 337
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 338
        if (!map.contains(actionIdx))
83f0e0bc Poul Sander 2026-05-30 17:59 339
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 340
        auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 341
            m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 342
        if (edit)
83f0e0bc Poul Sander 2026-05-30 17:59 343
            edit->setKeySequence(map[actionIdx]);
83f0e0bc Poul Sander 2026-05-30 17:59 344
    }
83f0e0bc Poul Sander 2026-05-30 17:59 345
    highlightConflicts();
10d6e6f8 Poul Sander 2026-02-24 18:40 346
}
10d6e6f8 Poul Sander 2026-02-24 18:40 347
10d6e6f8 Poul Sander 2026-02-24 18:40 348
QString PreferencesDialog::getBackgroundColor() const
10d6e6f8 Poul Sander 2026-02-24 18:40 349
{
10d6e6f8 Poul Sander 2026-02-24 18:40 350
    return m_backgroundColorCombo->currentData().toString();
10d6e6f8 Poul Sander 2026-02-24 18:40 351
}
10d6e6f8 Poul Sander 2026-02-24 18:40 352
10d6e6f8 Poul Sander 2026-02-24 18:40 353
void PreferencesDialog::setBackgroundColor(const QString &color)
10d6e6f8 Poul Sander 2026-02-24 18:40 354
{
10d6e6f8 Poul Sander 2026-02-24 18:40 355
    int index = m_backgroundColorCombo->findData(color);
10d6e6f8 Poul Sander 2026-02-24 18:40 356
    if (index >= 0)
10d6e6f8 Poul Sander 2026-02-24 18:40 357
        m_backgroundColorCombo->setCurrentIndex(index);
10d6e6f8 Poul Sander 2026-02-24 18:40 358
}
4ae57f60 Poul Sander 2026-02-25 21:35 359
459bad0f Poul Sander 2026-05-17 14:11 360
int PreferencesDialog::getCacheSize() const
459bad0f Poul Sander 2026-05-17 14:11 361
{
459bad0f Poul Sander 2026-05-17 14:11 362
    return m_cacheSizeSpinBox->value();
459bad0f Poul Sander 2026-05-17 14:11 363
}
459bad0f Poul Sander 2026-05-17 14:11 364
459bad0f Poul Sander 2026-05-17 14:11 365
void PreferencesDialog::setCacheSize(int n)
459bad0f Poul Sander 2026-05-17 14:11 366
{
459bad0f Poul Sander 2026-05-17 14:11 367
    m_cacheSizeSpinBox->setValue(n);
459bad0f Poul Sander 2026-05-17 14:11 368
}
459bad0f Poul Sander 2026-05-17 14:11 369
ac476ca8 Poul Sander 2026-05-18 16:47 370
QString PreferencesDialog::getThumbnailCacheSize() const
ac476ca8 Poul Sander 2026-05-18 16:47 371
{
ac476ca8 Poul Sander 2026-05-18 16:47 372
    return m_thumbnailSizeCombo->currentData().toString();
ac476ca8 Poul Sander 2026-05-18 16:47 373
}
ac476ca8 Poul Sander 2026-05-18 16:47 374
ac476ca8 Poul Sander 2026-05-18 16:47 375
void PreferencesDialog::setThumbnailCacheSize(const QString &size)
ac476ca8 Poul Sander 2026-05-18 16:47 376
{
ac476ca8 Poul Sander 2026-05-18 16:47 377
    int index = m_thumbnailSizeCombo->findData(size);
ac476ca8 Poul Sander 2026-05-18 16:47 378
    if (index >= 0)
ac476ca8 Poul Sander 2026-05-18 16:47 379
        m_thumbnailSizeCombo->setCurrentIndex(index);
ac476ca8 Poul Sander 2026-05-18 16:47 380
}
ac476ca8 Poul Sander 2026-05-18 16:47 381
4ae57f60 Poul Sander 2026-02-25 21:35 382
bool PreferencesDialog::getLockDocking() const
4ae57f60 Poul Sander 2026-02-25 21:35 383
{
4ae57f60 Poul Sander 2026-02-25 21:35 384
    return m_lockDockingCheck->isChecked();
4ae57f60 Poul Sander 2026-02-25 21:35 385
}
4ae57f60 Poul Sander 2026-02-25 21:35 386
4ae57f60 Poul Sander 2026-02-25 21:35 387
void PreferencesDialog::setLockDocking(bool lock)
4ae57f60 Poul Sander 2026-02-25 21:35 388
{
4ae57f60 Poul Sander 2026-02-25 21:35 389
    m_lockDockingCheck->setChecked(lock);
4ae57f60 Poul Sander 2026-02-25 21:35 390
}
d1aa6cbe Poul Sander 2026-03-02 16:57 391
d1aa6cbe Poul Sander 2026-03-02 16:57 392
bool PreferencesDialog::getResetLayout() const
d1aa6cbe Poul Sander 2026-03-02 16:57 393
{
d1aa6cbe Poul Sander 2026-03-02 16:57 394
    return m_resetLayoutCheck->isChecked();
d1aa6cbe Poul Sander 2026-03-02 16:57 395
}
d1aa6cbe Poul Sander 2026-03-02 16:57 396
d1aa6cbe Poul Sander 2026-03-02 16:57 397
void PreferencesDialog::setResetLayout(bool reset)
d1aa6cbe Poul Sander 2026-03-02 16:57 398
{
d1aa6cbe Poul Sander 2026-03-02 16:57 399
    m_resetLayoutCheck->setChecked(reset);
d1aa6cbe Poul Sander 2026-03-02 16:57 400
}
8cb93c2f Poul Sander 2026-06-28 19:31 401
8cb93c2f Poul Sander 2026-06-28 19:31 402
QStringList PreferencesDialog::getRootLabels() const
8cb93c2f Poul Sander 2026-06-28 19:31 403
{
8cb93c2f Poul Sander 2026-06-28 19:31 404
    QStringList labels;
8cb93c2f Poul Sander 2026-06-28 19:31 405
    for (int i = 0; i < m_rootsTable->rowCount(); ++i) {
8cb93c2f Poul Sander 2026-06-28 19:31 406
        labels << m_rootsTable->item(i, 0)->text();
8cb93c2f Poul Sander 2026-06-28 19:31 407
    }
8cb93c2f Poul Sander 2026-06-28 19:31 408
    return labels;
8cb93c2f Poul Sander 2026-06-28 19:31 409
}
8cb93c2f Poul Sander 2026-06-28 19:31 410
8cb93c2f Poul Sander 2026-06-28 19:31 411
void PreferencesDialog::setRootLabels(const QStringList &labels)
8cb93c2f Poul Sander 2026-06-28 19:31 412
{
8cb93c2f Poul Sander 2026-06-28 19:31 413
    if (m_rootsTable->rowCount() < labels.size())
8cb93c2f Poul Sander 2026-06-28 19:31 414
        m_rootsTable->setRowCount(labels.size());
8cb93c2f Poul Sander 2026-06-28 19:31 415
    for (int i = 0; i < labels.size(); ++i) {
8cb93c2f Poul Sander 2026-06-28 19:31 416
        if (!m_rootsTable->item(i, 0))
8cb93c2f Poul Sander 2026-06-28 19:31 417
            m_rootsTable->setItem(i, 0, new QTableWidgetItem);
8cb93c2f Poul Sander 2026-06-28 19:31 418
        m_rootsTable->item(i, 0)->setText(labels[i]);
8cb93c2f Poul Sander 2026-06-28 19:31 419
    }
8cb93c2f Poul Sander 2026-06-28 19:31 420
}
8cb93c2f Poul Sander 2026-06-28 19:31 421
8cb93c2f Poul Sander 2026-06-28 19:31 422
QStringList PreferencesDialog::getRootPaths() const
8cb93c2f Poul Sander 2026-06-28 19:31 423
{
8cb93c2f Poul Sander 2026-06-28 19:31 424
    QStringList paths;
8cb93c2f Poul Sander 2026-06-28 19:31 425
    for (int i = 0; i < m_rootsTable->rowCount(); ++i) {
8cb93c2f Poul Sander 2026-06-28 19:31 426
        paths << m_rootsTable->item(i, 1)->text();
8cb93c2f Poul Sander 2026-06-28 19:31 427
    }
8cb93c2f Poul Sander 2026-06-28 19:31 428
    return paths;
8cb93c2f Poul Sander 2026-06-28 19:31 429
}
8cb93c2f Poul Sander 2026-06-28 19:31 430
8cb93c2f Poul Sander 2026-06-28 19:31 431
void PreferencesDialog::setRootPaths(const QStringList &paths)
8cb93c2f Poul Sander 2026-06-28 19:31 432
{
8cb93c2f Poul Sander 2026-06-28 19:31 433
    if (m_rootsTable->rowCount() < paths.size())
8cb93c2f Poul Sander 2026-06-28 19:31 434
        m_rootsTable->setRowCount(paths.size());
8cb93c2f Poul Sander 2026-06-28 19:31 435
    for (int i = 0; i < paths.size(); ++i) {
8cb93c2f Poul Sander 2026-06-28 19:31 436
        if (!m_rootsTable->item(i, 1))
8cb93c2f Poul Sander 2026-06-28 19:31 437
            m_rootsTable->setItem(i, 1, new QTableWidgetItem);
8cb93c2f Poul Sander 2026-06-28 19:31 438
        m_rootsTable->item(i, 1)->setText(paths[i]);
8cb93c2f Poul Sander 2026-06-28 19:31 439
    }
8cb93c2f Poul Sander 2026-06-28 19:31 440
}
1970-01-01 00:00 441