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