BibleTime
cacceleratorsettings.cpp
Go to the documentation of this file.
1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, https://bibletime.info/
6*
7* Copyright 1999-2025 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
14
15#include <QComboBox>
16#include <QHBoxLayout>
17#include <QKeySequence>
18#include <QLabel>
19#include <QList>
20#include <QMessageBox>
21#include <QNonConstOverload>
22#include <QStackedWidget>
23#include <Qt>
24#include <QVBoxLayout>
25#include <utility>
26#include "../../util/btconnect.h"
27#include "../../util/cresmgr.h"
28#include "../bibletime.h"
29#include "../displaywindow/btactioncollection.h"
30#include "../displaywindow/cbiblereadwindow.h"
31#include "../displaywindow/cbookreadwindow.h"
32#include "../displaywindow/ccommentaryreadwindow.h"
33#include "../displaywindow/cdisplaywindow.h"
34#include "../displaywindow/clexiconreadwindow.h"
35#include "../messagedialog.h"
36#include "btshortcutseditor.h"
38
39
41 : BtConfigDialog::Page(CResMgr::settings::keys::icon(), parent)
42{
43 QVBoxLayout *mainLayout = new QVBoxLayout(this);
44
45 QHBoxLayout* layoutForWindowTypeChooser = new QHBoxLayout();
46 mainLayout->addLayout(layoutForWindowTypeChooser);
47
48 m_actionGroupLabel = new QLabel(this);
49 layoutForWindowTypeChooser->addWidget(m_actionGroupLabel);
50
51 m_typeChooser = new QComboBox(this);
52 layoutForWindowTypeChooser->addWidget(m_typeChooser);
53
54 BT_CONNECT(m_typeChooser, qOverload<int>(&QComboBox::activated),
55 [this](int i) { m_keyChooserStack->setCurrentIndex(i); });
56
57 // m_*.title strings are empty here, they are filled and added to the stacked widget in the retranslateUi() function
58 m_keyChooserStack = new QStackedWidget(this);
60
61 // create shortcuteditors
62 auto const initShortcutEditor =
63 [this](WindowType & windowType,
64 BtActionCollection * const actionCollection,
65 char const * const groupName)
66 {
67 windowType.actionCollection = actionCollection;
68 actionCollection->readShortcuts(groupName);
69 windowType.keyChooser =
70 new BtShortcutsEditor(actionCollection,
72 m_keyChooserStack->addWidget(windowType.keyChooser);
74 windowType.keyChooser,
76 [this, &windowType](QString const & actionName,
77 QKeySequence const & keys)
78 {
79 /* Check the BtShortcutsEditor's for shortcut conflicts.
80 Either clear the conflicts and set the new shortcut or do
81 nothing. */
82
83 /* Get the list of shortcuts editors that can conflict with
84 a key change in the current shortcut editor: */
85 QList<WindowType *> list;
86 list.append(&m_application);
87 list.append(&m_general);
88 if ((&windowType == &m_application)
89 || (&windowType == &m_general))
90 {
91 list.append(&m_bible);
92 list.append(&m_commentary);
93 list.append(&m_lexicon);
94 list.append(&m_book);
95 } else {
96 list.append(&windowType);
97 }
98 QStringList conflicts;
99 auto const conflictTr = tr("\"%1\" in the \"%2\" group");
100 for (auto const * const windowType2 : list)
101 if (auto conflict =
102 windowType2->keyChooser->findConflictWithKeys(
103 keys);
104 !conflict.isEmpty())
105 conflicts.append(conflictTr
106 .arg(std::move(conflict))
107 .arg(windowType2->title));
108
109 if (!conflicts.isEmpty()) {
111 this,
112 tr("Shortcut conflict detected"),
113 QStringLiteral("%1<ul><li>%2</li></ul>%3")
114 .arg(
115 tr("The shortcut \"%1\" you want to "
116 "assign to \"%2\" in the \"%3\" "
117 "group conflicts with the following "
118 "%n shortcut(s):",
119 nullptr,
120 conflicts.size())
121 .arg(keys.toString())
122 .arg(actionName)
123 .arg(windowType.title),
124 conflicts.join(QStringLiteral("</li><li>")),
125 tr("Do you want to clear these conflicting "
126 "shortcuts and continue?")),
127 QMessageBox::Yes | QMessageBox::No,
128 QMessageBox::Yes) == QMessageBox::Yes)
129 {
130 // Clear conflicts with keys:
131 for (auto const * const windowType2 : list)
132 windowType2->keyChooser->clearConflictWithKeys(
133 keys);
134
135 windowType.keyChooser->changeShortcutInDialog(keys);
136 }
137 } else {
138 windowType.keyChooser->changeShortcutInDialog(keys);
139 }
140 });
141 };
142 initShortcutEditor(m_application,
144 new QAction(this), // dummy "Show bookshelf" action
145 new QAction(this), // dummy "Show bookmarks" action
146 new QAction(this), // dummy "Show mag" action
147 this),
148 "Application shortcuts");
149 initShortcutEditor(m_general,
151 "Displaywindow shortcuts");
152 initShortcutEditor(m_bible,
154 "Bible shortcuts");
155 initShortcutEditor(m_commentary,
157 "Commentary shortcuts");
158 initShortcutEditor(m_lexicon,
160 "Lexicon shortcuts");
161 initShortcutEditor(m_book,
163 "Book shortcuts");
164
165 mainLayout->addWidget(m_keyChooserStack);
166 m_keyChooserStack->setCurrentIndex(m_typeChooser->currentIndex());
167
168 m_typeChooser->setFocus(Qt::MouseFocusReason);
169
170 retranslateUi();
171}
172
174 setHeaderText(tr("Shortcuts"));
175
176 m_actionGroupLabel->setText(tr("Choose action group:"));
177
178 m_application.title = tr("Main Window");
179 m_general.title = tr("All text windows");
180 m_bible.title = tr("Bible windows");
181 m_commentary.title = tr("Commentary windows");
182 m_lexicon.title = tr("Lexicon windows");
183 m_book.title = tr("Book windows");
184
185 m_typeChooser->clear();
187 m_typeChooser->addItem(m_general.title);
188 m_typeChooser->addItem(m_bible.title);
190 m_typeChooser->addItem(m_lexicon.title);
191 m_typeChooser->addItem(m_book.title);
192}
193
196 m_application.keyChooser->commitChanges();
198 m_general.keyChooser->commitChanges();
200 m_bible.keyChooser->commitChanges();
202 m_commentary.keyChooser->commitChanges();
204 m_lexicon.keyChooser->commitChanges();
205 if (m_book.keyChooser)
206 m_book.keyChooser->commitChanges();
207
208 m_application.actionCollection->writeShortcuts("Application shortcuts"); //application
209 m_general.actionCollection->writeShortcuts("Displaywindow shortcuts"); //read display windows
210 m_bible.actionCollection->writeShortcuts("Bible shortcuts"); //bible
211 m_commentary.actionCollection->writeShortcuts("Commentary shortcuts"); //commentary
212 m_lexicon.actionCollection->writeShortcuts("Lexicon shortcuts"); //lexicon
213 m_book.actionCollection->writeShortcuts("Book shortcuts"); //book
214}
#define BT_CONNECT(...)
Definition btconnect.h:20
void readShortcuts(QString const &group)
Read shortcuts from config.
void writeShortcuts(QString const &group) const
Write shortcuts to config.
void setHeaderText(QString const &headerText)
void keyChangeRequest(QString const &actionName, QKeySequence const &keys)
void save() const final override
CAcceleratorSettingsPage(CConfigurationDialog *parent=nullptr)
QMessageBox::StandardButton showQuestion(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QPointer< BtShortcutsEditor > keyChooser