git repos / SagoImageBrowser

blame: src/preferencesdialog.cpp

normal view · raw

10d6e6f8 Poul Sander 2026-02-24 18:40 1
#include "preferencesdialog.h"
83f0e0bc Poul Sander 2026-05-30 17:59 2
#include "shortcutmanager.h"
10d6e6f8 Poul Sander 2026-02-24 18:40 3
10d6e6f8 Poul Sander 2026-02-24 18:40 4
#include <QVBoxLayout>
10d6e6f8 Poul Sander 2026-02-24 18:40 5
#include <QHBoxLayout>
10d6e6f8 Poul Sander 2026-02-24 18:40 6
#include <QLabel>
10d6e6f8 Poul Sander 2026-02-24 18:40 7
#include <QComboBox>
459bad0f Poul Sander 2026-05-17 14:11 8
#include <QSpinBox>
4ae57f60 Poul Sander 2026-02-25 21:35 9
#include <QCheckBox>
10d6e6f8 Poul Sander 2026-02-24 18:40 10
#include <QPushButton>
10d6e6f8 Poul Sander 2026-02-24 18:40 11
#include <QGroupBox>
83f0e0bc Poul Sander 2026-05-30 17:59 12
#include <QTabWidget>
83f0e0bc Poul Sander 2026-05-30 17:59 13
#include <QTableWidget>
83f0e0bc Poul Sander 2026-05-30 17:59 14
#include <QKeySequenceEdit>
83f0e0bc Poul Sander 2026-05-30 17:59 15
#include <QHeaderView>
10d6e6f8 Poul Sander 2026-02-24 18:40 16
10d6e6f8 Poul Sander 2026-02-24 18:40 17
PreferencesDialog::PreferencesDialog(QWidget *parent)
10d6e6f8 Poul Sander 2026-02-24 18:40 18
    : QDialog(parent)
10d6e6f8 Poul Sander 2026-02-24 18:40 19
{
4c41f5ff Poul Sander 2026-05-31 00:01 20
    setWindowTitle(tr("Preferences"));
10d6e6f8 Poul Sander 2026-02-24 18:40 21
    setModal(true);
83f0e0bc Poul Sander 2026-05-30 17:59 22
    setMinimumWidth(500);
10d6e6f8 Poul Sander 2026-02-24 18:40 23
10d6e6f8 Poul Sander 2026-02-24 18:40 24
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
10d6e6f8 Poul Sander 2026-02-24 18:40 25
83f0e0bc Poul Sander 2026-05-30 17:59 26
    QTabWidget *tabs = new QTabWidget(this);
83f0e0bc Poul Sander 2026-05-30 17:59 27
    setupGeneralTab(tabs);
83f0e0bc Poul Sander 2026-05-30 17:59 28
    setupShortcutsTab(tabs);
83f0e0bc Poul Sander 2026-05-30 17:59 29
    mainLayout->addWidget(tabs);
83f0e0bc Poul Sander 2026-05-30 17:59 30
83f0e0bc Poul Sander 2026-05-30 17:59 31
    QHBoxLayout *buttonLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 32
    QPushButton *okButton = new QPushButton(tr("OK"));
4c41f5ff Poul Sander 2026-05-31 00:01 33
    QPushButton *cancelButton = new QPushButton(tr("Cancel"));
83f0e0bc Poul Sander 2026-05-30 17:59 34
83f0e0bc Poul Sander 2026-05-30 17:59 35
    buttonLayout->addStretch();
83f0e0bc Poul Sander 2026-05-30 17:59 36
    buttonLayout->addWidget(okButton);
83f0e0bc Poul Sander 2026-05-30 17:59 37
    buttonLayout->addWidget(cancelButton);
83f0e0bc Poul Sander 2026-05-30 17:59 38
83f0e0bc Poul Sander 2026-05-30 17:59 39
    mainLayout->addLayout(buttonLayout);
83f0e0bc Poul Sander 2026-05-30 17:59 40
83f0e0bc Poul Sander 2026-05-30 17:59 41
    connect(okButton, &QPushButton::clicked, this, [this]() {
83f0e0bc Poul Sander 2026-05-30 17:59 42
        if (m_resetLayoutCheck->isChecked())
83f0e0bc Poul Sander 2026-05-30 17:59 43
            emit resetLayoutRequested();
83f0e0bc Poul Sander 2026-05-30 17:59 44
        accept();
83f0e0bc Poul Sander 2026-05-30 17:59 45
    });
83f0e0bc Poul Sander 2026-05-30 17:59 46
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
83f0e0bc Poul Sander 2026-05-30 17:59 47
}
83f0e0bc Poul Sander 2026-05-30 17:59 48
83f0e0bc Poul Sander 2026-05-30 17:59 49
void PreferencesDialog::setupGeneralTab(QTabWidget *tabs)
83f0e0bc Poul Sander 2026-05-30 17:59 50
{
83f0e0bc Poul Sander 2026-05-30 17:59 51
    QWidget *page = new QWidget;
83f0e0bc Poul Sander 2026-05-30 17:59 52
    QVBoxLayout *pageLayout = new QVBoxLayout(page);
83f0e0bc Poul Sander 2026-05-30 17:59 53
4c41f5ff Poul Sander 2026-05-31 00:01 54
    QGroupBox *imageGroup = new QGroupBox(tr("Image Viewer"), page);
10d6e6f8 Poul Sander 2026-02-24 18:40 55
    QVBoxLayout *groupLayout = new QVBoxLayout(imageGroup);
10d6e6f8 Poul Sander 2026-02-24 18:40 56
10d6e6f8 Poul Sander 2026-02-24 18:40 57
    QHBoxLayout *bgColorLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 58
    QLabel *bgColorLabel = new QLabel(tr("Background Color:"));
10d6e6f8 Poul Sander 2026-02-24 18:40 59
    m_backgroundColorCombo = new QComboBox;
4c41f5ff Poul Sander 2026-05-31 00:01 60
    m_backgroundColorCombo->addItem(tr("Black"), "black");
4c41f5ff Poul Sander 2026-05-31 00:01 61
    m_backgroundColorCombo->addItem(tr("White"), "white");
4c41f5ff Poul Sander 2026-05-31 00:01 62
    m_backgroundColorCombo->addItem(tr("Dark Gray"), "darkgray");
10d6e6f8 Poul Sander 2026-02-24 18:40 63
10d6e6f8 Poul Sander 2026-02-24 18:40 64
    bgColorLayout->addWidget(bgColorLabel);
10d6e6f8 Poul Sander 2026-02-24 18:40 65
    bgColorLayout->addWidget(m_backgroundColorCombo);
10d6e6f8 Poul Sander 2026-02-24 18:40 66
    bgColorLayout->addStretch();
10d6e6f8 Poul Sander 2026-02-24 18:40 67
10d6e6f8 Poul Sander 2026-02-24 18:40 68
    groupLayout->addLayout(bgColorLayout);
459bad0f Poul Sander 2026-05-17 14:11 69
459bad0f Poul Sander 2026-05-17 14:11 70
    QHBoxLayout *cacheSizeLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 71
    QLabel *cacheSizeLabel = new QLabel(tr("Folder thumbnail cache (folders):"));
459bad0f Poul Sander 2026-05-17 14:11 72
    m_cacheSizeSpinBox = new QSpinBox;
459bad0f Poul Sander 2026-05-17 14:11 73
    m_cacheSizeSpinBox->setRange(1, 20);
459bad0f Poul Sander 2026-05-17 14:11 74
    m_cacheSizeSpinBox->setValue(4);
459bad0f Poul Sander 2026-05-17 14:11 75
    cacheSizeLayout->addWidget(cacheSizeLabel);
459bad0f Poul Sander 2026-05-17 14:11 76
    cacheSizeLayout->addWidget(m_cacheSizeSpinBox);
459bad0f Poul Sander 2026-05-17 14:11 77
    cacheSizeLayout->addStretch();
459bad0f Poul Sander 2026-05-17 14:11 78
    groupLayout->addLayout(cacheSizeLayout);
459bad0f Poul Sander 2026-05-17 14:11 79
ac476ca8 Poul Sander 2026-05-18 16:47 80
    QHBoxLayout *thumbSizeLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 81
    QLabel *thumbSizeLabel = new QLabel(tr("Thumbnail cache size:"));
ac476ca8 Poul Sander 2026-05-18 16:47 82
    m_thumbnailSizeCombo = new QComboBox;
4c41f5ff Poul Sander 2026-05-31 00:01 83
    m_thumbnailSizeCombo->addItem(tr("Normal (128 px)"), "normal");
4c41f5ff Poul Sander 2026-05-31 00:01 84
    m_thumbnailSizeCombo->addItem(tr("Large (256 px)"), "large");
ac476ca8 Poul Sander 2026-05-18 16:47 85
    thumbSizeLayout->addWidget(thumbSizeLabel);
ac476ca8 Poul Sander 2026-05-18 16:47 86
    thumbSizeLayout->addWidget(m_thumbnailSizeCombo);
ac476ca8 Poul Sander 2026-05-18 16:47 87
    thumbSizeLayout->addStretch();
ac476ca8 Poul Sander 2026-05-18 16:47 88
    groupLayout->addLayout(thumbSizeLayout);
ac476ca8 Poul Sander 2026-05-18 16:47 89
83f0e0bc Poul Sander 2026-05-30 17:59 90
    pageLayout->addWidget(imageGroup);
10d6e6f8 Poul Sander 2026-02-24 18:40 91
4c41f5ff Poul Sander 2026-05-31 00:01 92
    QGroupBox *layoutGroup = new QGroupBox(tr("Layout"), page);
4ae57f60 Poul Sander 2026-02-25 21:35 93
    QVBoxLayout *layoutGroupLayout = new QVBoxLayout(layoutGroup);
4c41f5ff Poul Sander 2026-05-31 00:01 94
    m_lockDockingCheck = new QCheckBox(tr("Lock docking (prevent accidental moves)"));
4ae57f60 Poul Sander 2026-02-25 21:35 95
    layoutGroupLayout->addWidget(m_lockDockingCheck);
83f0e0bc Poul Sander 2026-05-30 17:59 96
4c41f5ff Poul Sander 2026-05-31 00:01 97
    m_resetLayoutCheck = new QCheckBox(tr("Reset layout to default when closing the menu"));
d1aa6cbe Poul Sander 2026-03-02 16:57 98
    layoutGroupLayout->addWidget(m_resetLayoutCheck);
4ae57f60 Poul Sander 2026-02-25 21:35 99
83f0e0bc Poul Sander 2026-05-30 17:59 100
    pageLayout->addWidget(layoutGroup);
83f0e0bc Poul Sander 2026-05-30 17:59 101
    pageLayout->addStretch();
10d6e6f8 Poul Sander 2026-02-24 18:40 102
4c41f5ff Poul Sander 2026-05-31 00:01 103
    tabs->addTab(page, tr("General"));
83f0e0bc Poul Sander 2026-05-30 17:59 104
}
10d6e6f8 Poul Sander 2026-02-24 18:40 105
83f0e0bc Poul Sander 2026-05-30 17:59 106
void PreferencesDialog::setupShortcutsTab(QTabWidget *tabs)
83f0e0bc Poul Sander 2026-05-30 17:59 107
{
83f0e0bc Poul Sander 2026-05-30 17:59 108
    QWidget *page = new QWidget;
83f0e0bc Poul Sander 2026-05-30 17:59 109
    QVBoxLayout *pageLayout = new QVBoxLayout(page);
10d6e6f8 Poul Sander 2026-02-24 18:40 110
83f0e0bc Poul Sander 2026-05-30 17:59 111
    // Count configurable actions to size the table (plus 2 section header rows)
83f0e0bc Poul Sander 2026-05-30 17:59 112
    int configurableCount = 0;
83f0e0bc Poul Sander 2026-05-30 17:59 113
    for (int i = 0; i < ShortcutManager::ActionCount; ++i) {
83f0e0bc Poul Sander 2026-05-30 17:59 114
        if (ShortcutManager::actionCategory(static_cast<ShortcutManager::Action>(i))
83f0e0bc Poul Sander 2026-05-30 17:59 115
            != ShortcutManager::CatNotConfigurable)
83f0e0bc Poul Sander 2026-05-30 17:59 116
            ++configurableCount;
83f0e0bc Poul Sander 2026-05-30 17:59 117
    }
83f0e0bc Poul Sander 2026-05-30 17:59 118
    // +2 for section headers (Image Viewer, Browser)
83f0e0bc Poul Sander 2026-05-30 17:59 119
    const int totalRows = configurableCount + 2;
10d6e6f8 Poul Sander 2026-02-24 18:40 120
83f0e0bc Poul Sander 2026-05-30 17:59 121
    m_shortcutsTable = new QTableWidget(totalRows, 2, page);
4c41f5ff Poul Sander 2026-05-31 00:01 122
    m_shortcutsTable->setHorizontalHeaderLabels({tr("Action"), tr("Key")});
83f0e0bc Poul Sander 2026-05-30 17:59 123
    m_shortcutsTable->horizontalHeader()->setStretchLastSection(true);
83f0e0bc Poul Sander 2026-05-30 17:59 124
    m_shortcutsTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
83f0e0bc Poul Sander 2026-05-30 17:59 125
    m_shortcutsTable->verticalHeader()->hide();
83f0e0bc Poul Sander 2026-05-30 17:59 126
    m_shortcutsTable->setSelectionMode(QAbstractItemView::SingleSelection);
83f0e0bc Poul Sander 2026-05-30 17:59 127
83f0e0bc Poul Sander 2026-05-30 17:59 128
    m_rowToAction.clear();
83f0e0bc Poul Sander 2026-05-30 17:59 129
    const ShortcutManager &mgr = ShortcutManager::instance();
83f0e0bc Poul Sander 2026-05-30 17:59 130
    int row = 0;
83f0e0bc Poul Sander 2026-05-30 17:59 131
83f0e0bc Poul Sander 2026-05-30 17:59 132
    auto addSectionHeader = [&](const QString &title) {
83f0e0bc Poul Sander 2026-05-30 17:59 133
        auto *item = new QTableWidgetItem(title);
83f0e0bc Poul Sander 2026-05-30 17:59 134
        item->setFlags(Qt::NoItemFlags);
83f0e0bc Poul Sander 2026-05-30 17:59 135
        QFont f = item->font();
83f0e0bc Poul Sander 2026-05-30 17:59 136
        f.setBold(true);
83f0e0bc Poul Sander 2026-05-30 17:59 137
        item->setFont(f);
83f0e0bc Poul Sander 2026-05-30 17:59 138
        item->setBackground(palette().alternateBase());
83f0e0bc Poul Sander 2026-05-30 17:59 139
        m_shortcutsTable->setItem(row, 0, item);
83f0e0bc Poul Sander 2026-05-30 17:59 140
        auto *emptyItem = new QTableWidgetItem();
83f0e0bc Poul Sander 2026-05-30 17:59 141
        emptyItem->setFlags(Qt::NoItemFlags);
83f0e0bc Poul Sander 2026-05-30 17:59 142
        emptyItem->setBackground(palette().alternateBase());
83f0e0bc Poul Sander 2026-05-30 17:59 143
        m_shortcutsTable->setItem(row, 1, emptyItem);
83f0e0bc Poul Sander 2026-05-30 17:59 144
        m_rowToAction.append(-1); // -1 = section header
83f0e0bc Poul Sander 2026-05-30 17:59 145
        ++row;
83f0e0bc Poul Sander 2026-05-30 17:59 146
    };
83f0e0bc Poul Sander 2026-05-30 17:59 147
83f0e0bc Poul Sander 2026-05-30 17:59 148
    auto addAction = [&](ShortcutManager::Action action) {
83f0e0bc Poul Sander 2026-05-30 17:59 149
        auto *descItem = new QTableWidgetItem(mgr.description(action));
83f0e0bc Poul Sander 2026-05-30 17:59 150
        descItem->setFlags(descItem->flags() & ~Qt::ItemIsEditable);
83f0e0bc Poul Sander 2026-05-30 17:59 151
        m_shortcutsTable->setItem(row, 0, descItem);
83f0e0bc Poul Sander 2026-05-30 17:59 152
83f0e0bc Poul Sander 2026-05-30 17:59 153
        auto *edit = new QKeySequenceEdit(mgr.shortcut(action));
4c41f5ff Poul Sander 2026-05-31 00:01 154
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
83f0e0bc Poul Sander 2026-05-30 17:59 155
        edit->setMaximumSequenceLength(1);
4c41f5ff Poul Sander 2026-05-31 00:01 156
#endif
83f0e0bc Poul Sander 2026-05-30 17:59 157
        connect(edit, &QKeySequenceEdit::keySequenceChanged, this, [this]() {
83f0e0bc Poul Sander 2026-05-30 17:59 158
            highlightConflicts();
83f0e0bc Poul Sander 2026-05-30 17:59 159
        });
83f0e0bc Poul Sander 2026-05-30 17:59 160
        m_shortcutsTable->setCellWidget(row, 1, edit);
83f0e0bc Poul Sander 2026-05-30 17:59 161
        m_rowToAction.append(static_cast<int>(action));
83f0e0bc Poul Sander 2026-05-30 17:59 162
        ++row;
83f0e0bc Poul Sander 2026-05-30 17:59 163
    };
83f0e0bc Poul Sander 2026-05-30 17:59 164
83f0e0bc Poul Sander 2026-05-30 17:59 165
    // Image Viewer section
4c41f5ff Poul Sander 2026-05-31 00:01 166
    addSectionHeader(tr("Image Viewer"));
83f0e0bc Poul Sander 2026-05-30 17:59 167
    for (int i = 0; i < ShortcutManager::ActionCount; ++i) {
83f0e0bc Poul Sander 2026-05-30 17:59 168
        auto action = static_cast<ShortcutManager::Action>(i);
83f0e0bc Poul Sander 2026-05-30 17:59 169
        if (ShortcutManager::actionCategory(action) == ShortcutManager::CatImageViewer)
83f0e0bc Poul Sander 2026-05-30 17:59 170
            addAction(action);
83f0e0bc Poul Sander 2026-05-30 17:59 171
    }
83f0e0bc Poul Sander 2026-05-30 17:59 172
83f0e0bc Poul Sander 2026-05-30 17:59 173
    // Browser section
4c41f5ff Poul Sander 2026-05-31 00:01 174
    addSectionHeader(tr("Browser"));
83f0e0bc Poul Sander 2026-05-30 17:59 175
    for (int i = 0; i < ShortcutManager::ActionCount; ++i) {
83f0e0bc Poul Sander 2026-05-30 17:59 176
        auto action = static_cast<ShortcutManager::Action>(i);
83f0e0bc Poul Sander 2026-05-30 17:59 177
        if (ShortcutManager::actionCategory(action) == ShortcutManager::CatBrowser)
83f0e0bc Poul Sander 2026-05-30 17:59 178
            addAction(action);
83f0e0bc Poul Sander 2026-05-30 17:59 179
    }
83f0e0bc Poul Sander 2026-05-30 17:59 180
83f0e0bc Poul Sander 2026-05-30 17:59 181
    pageLayout->addWidget(m_shortcutsTable);
83f0e0bc Poul Sander 2026-05-30 17:59 182
83f0e0bc Poul Sander 2026-05-30 17:59 183
    QHBoxLayout *btnLayout = new QHBoxLayout;
4c41f5ff Poul Sander 2026-05-31 00:01 184
    QPushButton *resetBtn = new QPushButton(tr("Reset to Defaults"));
83f0e0bc Poul Sander 2026-05-30 17:59 185
    btnLayout->addStretch();
83f0e0bc Poul Sander 2026-05-30 17:59 186
    btnLayout->addWidget(resetBtn);
83f0e0bc Poul Sander 2026-05-30 17:59 187
    pageLayout->addLayout(btnLayout);
83f0e0bc Poul Sander 2026-05-30 17:59 188
83f0e0bc Poul Sander 2026-05-30 17:59 189
    connect(resetBtn, &QPushButton::clicked, this, [this]() {
83f0e0bc Poul Sander 2026-05-30 17:59 190
        for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 191
            int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 192
            if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 193
                continue;
83f0e0bc Poul Sander 2026-05-30 17:59 194
            auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 195
                m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 196
            if (edit)
83f0e0bc Poul Sander 2026-05-30 17:59 197
                edit->setKeySequence(ShortcutManager::defaultShortcut(
83f0e0bc Poul Sander 2026-05-30 17:59 198
                    static_cast<ShortcutManager::Action>(actionIdx)));
83f0e0bc Poul Sander 2026-05-30 17:59 199
        }
83f0e0bc Poul Sander 2026-05-30 17:59 200
        highlightConflicts();
d1aa6cbe Poul Sander 2026-03-02 16:57 201
    });
83f0e0bc Poul Sander 2026-05-30 17:59 202
4c41f5ff Poul Sander 2026-05-31 00:01 203
    tabs->addTab(page, tr("Shortcuts"));
83f0e0bc Poul Sander 2026-05-30 17:59 204
}
83f0e0bc Poul Sander 2026-05-30 17:59 205
83f0e0bc Poul Sander 2026-05-30 17:59 206
void PreferencesDialog::highlightConflicts()
83f0e0bc Poul Sander 2026-05-30 17:59 207
{
83f0e0bc Poul Sander 2026-05-30 17:59 208
    // Group sequences by category, then detect conflicts within each category.
83f0e0bc Poul Sander 2026-05-30 17:59 209
    // key: (category, sequenceString) → list of rows
83f0e0bc Poul Sander 2026-05-30 17:59 210
    QMap<QPair<int,QString>, QList<int>> catSeqToRows;
83f0e0bc Poul Sander 2026-05-30 17:59 211
83f0e0bc Poul Sander 2026-05-30 17:59 212
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 213
        int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 214
        if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 215
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 216
        auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 217
            m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 218
        if (!edit)
83f0e0bc Poul Sander 2026-05-30 17:59 219
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 220
        QString s = edit->keySequence().toString();
83f0e0bc Poul Sander 2026-05-30 17:59 221
        if (!s.isEmpty()) {
83f0e0bc Poul Sander 2026-05-30 17:59 222
            int cat = ShortcutManager::actionCategory(
83f0e0bc Poul Sander 2026-05-30 17:59 223
                static_cast<ShortcutManager::Action>(actionIdx));
83f0e0bc Poul Sander 2026-05-30 17:59 224
            catSeqToRows[{cat, s}].append(r);
83f0e0bc Poul Sander 2026-05-30 17:59 225
        }
83f0e0bc Poul Sander 2026-05-30 17:59 226
    }
83f0e0bc Poul Sander 2026-05-30 17:59 227
83f0e0bc Poul Sander 2026-05-30 17:59 228
    // Reset all backgrounds
83f0e0bc Poul Sander 2026-05-30 17:59 229
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 230
        if (m_rowToAction[r] < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 231
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 232
        QTableWidgetItem *item = m_shortcutsTable->item(r, 0);
83f0e0bc Poul Sander 2026-05-30 17:59 233
        if (item)
83f0e0bc Poul Sander 2026-05-30 17:59 234
            item->setBackground(QBrush());
83f0e0bc Poul Sander 2026-05-30 17:59 235
    }
83f0e0bc Poul Sander 2026-05-30 17:59 236
83f0e0bc Poul Sander 2026-05-30 17:59 237
    // Highlight conflicts (only within same category)
83f0e0bc Poul Sander 2026-05-30 17:59 238
    for (auto it = catSeqToRows.cbegin(); it != catSeqToRows.cend(); ++it) {
83f0e0bc Poul Sander 2026-05-30 17:59 239
        if (it.value().size() > 1) {
83f0e0bc Poul Sander 2026-05-30 17:59 240
            for (int r : it.value()) {
83f0e0bc Poul Sander 2026-05-30 17:59 241
                QTableWidgetItem *item = m_shortcutsTable->item(r, 0);
83f0e0bc Poul Sander 2026-05-30 17:59 242
                if (item)
83f0e0bc Poul Sander 2026-05-30 17:59 243
                    item->setBackground(QColor(255, 100, 100, 80));
83f0e0bc Poul Sander 2026-05-30 17:59 244
            }
83f0e0bc Poul Sander 2026-05-30 17:59 245
        }
83f0e0bc Poul Sander 2026-05-30 17:59 246
    }
83f0e0bc Poul Sander 2026-05-30 17:59 247
}
83f0e0bc Poul Sander 2026-05-30 17:59 248
83f0e0bc Poul Sander 2026-05-30 17:59 249
QMap<int, QKeySequence> PreferencesDialog::getShortcuts() const
83f0e0bc Poul Sander 2026-05-30 17:59 250
{
83f0e0bc Poul Sander 2026-05-30 17:59 251
    QMap<int, QKeySequence> map;
83f0e0bc Poul Sander 2026-05-30 17:59 252
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 253
        int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 254
        if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 255
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 256
        auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 257
            m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 258
        if (edit)
83f0e0bc Poul Sander 2026-05-30 17:59 259
            map[actionIdx] = edit->keySequence();
83f0e0bc Poul Sander 2026-05-30 17:59 260
    }
83f0e0bc Poul Sander 2026-05-30 17:59 261
    return map;
83f0e0bc Poul Sander 2026-05-30 17:59 262
}
83f0e0bc Poul Sander 2026-05-30 17:59 263
83f0e0bc Poul Sander 2026-05-30 17:59 264
void PreferencesDialog::setShortcuts(const QMap<int, QKeySequence> &map)
83f0e0bc Poul Sander 2026-05-30 17:59 265
{
83f0e0bc Poul Sander 2026-05-30 17:59 266
    for (int r = 0; r < m_rowToAction.size(); ++r) {
83f0e0bc Poul Sander 2026-05-30 17:59 267
        int actionIdx = m_rowToAction[r];
83f0e0bc Poul Sander 2026-05-30 17:59 268
        if (actionIdx < 0)
83f0e0bc Poul Sander 2026-05-30 17:59 269
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 270
        if (!map.contains(actionIdx))
83f0e0bc Poul Sander 2026-05-30 17:59 271
            continue;
83f0e0bc Poul Sander 2026-05-30 17:59 272
        auto *edit = qobject_cast<QKeySequenceEdit *>(
83f0e0bc Poul Sander 2026-05-30 17:59 273
            m_shortcutsTable->cellWidget(r, 1));
83f0e0bc Poul Sander 2026-05-30 17:59 274
        if (edit)
83f0e0bc Poul Sander 2026-05-30 17:59 275
            edit->setKeySequence(map[actionIdx]);
83f0e0bc Poul Sander 2026-05-30 17:59 276
    }
83f0e0bc Poul Sander 2026-05-30 17:59 277
    highlightConflicts();
10d6e6f8 Poul Sander 2026-02-24 18:40 278
}
10d6e6f8 Poul Sander 2026-02-24 18:40 279
10d6e6f8 Poul Sander 2026-02-24 18:40 280
QString PreferencesDialog::getBackgroundColor() const
10d6e6f8 Poul Sander 2026-02-24 18:40 281
{
10d6e6f8 Poul Sander 2026-02-24 18:40 282
    return m_backgroundColorCombo->currentData().toString();
10d6e6f8 Poul Sander 2026-02-24 18:40 283
}
10d6e6f8 Poul Sander 2026-02-24 18:40 284
10d6e6f8 Poul Sander 2026-02-24 18:40 285
void PreferencesDialog::setBackgroundColor(const QString &color)
10d6e6f8 Poul Sander 2026-02-24 18:40 286
{
10d6e6f8 Poul Sander 2026-02-24 18:40 287
    int index = m_backgroundColorCombo->findData(color);
10d6e6f8 Poul Sander 2026-02-24 18:40 288
    if (index >= 0)
10d6e6f8 Poul Sander 2026-02-24 18:40 289
        m_backgroundColorCombo->setCurrentIndex(index);
10d6e6f8 Poul Sander 2026-02-24 18:40 290
}
4ae57f60 Poul Sander 2026-02-25 21:35 291
459bad0f Poul Sander 2026-05-17 14:11 292
int PreferencesDialog::getCacheSize() const
459bad0f Poul Sander 2026-05-17 14:11 293
{
459bad0f Poul Sander 2026-05-17 14:11 294
    return m_cacheSizeSpinBox->value();
459bad0f Poul Sander 2026-05-17 14:11 295
}
459bad0f Poul Sander 2026-05-17 14:11 296
459bad0f Poul Sander 2026-05-17 14:11 297
void PreferencesDialog::setCacheSize(int n)
459bad0f Poul Sander 2026-05-17 14:11 298
{
459bad0f Poul Sander 2026-05-17 14:11 299
    m_cacheSizeSpinBox->setValue(n);
459bad0f Poul Sander 2026-05-17 14:11 300
}
459bad0f Poul Sander 2026-05-17 14:11 301
ac476ca8 Poul Sander 2026-05-18 16:47 302
QString PreferencesDialog::getThumbnailCacheSize() const
ac476ca8 Poul Sander 2026-05-18 16:47 303
{
ac476ca8 Poul Sander 2026-05-18 16:47 304
    return m_thumbnailSizeCombo->currentData().toString();
ac476ca8 Poul Sander 2026-05-18 16:47 305
}
ac476ca8 Poul Sander 2026-05-18 16:47 306
ac476ca8 Poul Sander 2026-05-18 16:47 307
void PreferencesDialog::setThumbnailCacheSize(const QString &size)
ac476ca8 Poul Sander 2026-05-18 16:47 308
{
ac476ca8 Poul Sander 2026-05-18 16:47 309
    int index = m_thumbnailSizeCombo->findData(size);
ac476ca8 Poul Sander 2026-05-18 16:47 310
    if (index >= 0)
ac476ca8 Poul Sander 2026-05-18 16:47 311
        m_thumbnailSizeCombo->setCurrentIndex(index);
ac476ca8 Poul Sander 2026-05-18 16:47 312
}
ac476ca8 Poul Sander 2026-05-18 16:47 313
4ae57f60 Poul Sander 2026-02-25 21:35 314
bool PreferencesDialog::getLockDocking() const
4ae57f60 Poul Sander 2026-02-25 21:35 315
{
4ae57f60 Poul Sander 2026-02-25 21:35 316
    return m_lockDockingCheck->isChecked();
4ae57f60 Poul Sander 2026-02-25 21:35 317
}
4ae57f60 Poul Sander 2026-02-25 21:35 318
4ae57f60 Poul Sander 2026-02-25 21:35 319
void PreferencesDialog::setLockDocking(bool lock)
4ae57f60 Poul Sander 2026-02-25 21:35 320
{
4ae57f60 Poul Sander 2026-02-25 21:35 321
    m_lockDockingCheck->setChecked(lock);
4ae57f60 Poul Sander 2026-02-25 21:35 322
}
d1aa6cbe Poul Sander 2026-03-02 16:57 323
d1aa6cbe Poul Sander 2026-03-02 16:57 324
bool PreferencesDialog::getResetLayout() const
d1aa6cbe Poul Sander 2026-03-02 16:57 325
{
d1aa6cbe Poul Sander 2026-03-02 16:57 326
    return m_resetLayoutCheck->isChecked();
d1aa6cbe Poul Sander 2026-03-02 16:57 327
}
d1aa6cbe Poul Sander 2026-03-02 16:57 328
d1aa6cbe Poul Sander 2026-03-02 16:57 329
void PreferencesDialog::setResetLayout(bool reset)
d1aa6cbe Poul Sander 2026-03-02 16:57 330
{
d1aa6cbe Poul Sander 2026-03-02 16:57 331
    m_resetLayoutCheck->setChecked(reset);
d1aa6cbe Poul Sander 2026-03-02 16:57 332
}
1970-01-01 00:00 333