| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.cpp`/ |
| 2 | |
| 3 | #include "dynamic-shortcuts/dynamicshortcutswidget.h"cxx . . $ `<file>/src/librssguard/dynamic-shortcuts/dynamicshortcutswidget.h`/ |
| 4 | |
| 5 | #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/ |
| 6 | #include "dynamic-shortcuts/shortcutcatcher.h"cxx . . $ `<file>/src/librssguard/dynamic-shortcuts/shortcutcatcher.h`/ |
| 7 | #include "gui/messagebox.h"cxx . . $ `<file>/src/librssguard/gui/messagebox.h`/ |
| 8 | |
| 9 | #include <QAction> |
| 10 | #include <QGridLayout> |
| 11 | #include <QLabel> |
| 12 | |
| 13 | DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#::DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#DynamicShortcutsWidget(108f35f7aa7f3cf9).(QWidgetcxx . . $ QWidget#* parent) : QWidgetcxx . . $ QWidget#QWidget(872e7b0c281abd8d).(parent) { |
| 14 | // Create layout for this control and set is as active. |
| 15 | m_layoutcxx . . $ DynamicShortcutsWidget#m_layout. = new QGridLayoutcxx . . $ QGridLayout#QGridLayout(108f35f7aa7f3cf9).(this); |
| 16 | m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.->setContentsMarginscxx . . $ QLayout#setContentsMargins(79c4c8645766fc71).({cxx . . $ QMargins#QMargins(ced63f7c635d850d).}); |
| 17 | |
| 18 | setLayoutcxx . . $ QWidget#setLayout(23396b1058755fec).(m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.); |
| 19 | } |
| 20 | |
| 21 | DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#::~cxx . . $ DynamicShortcutsWidget#`~DynamicShortcutsWidget`(ced63f7c635d850d).DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#() { |
| 22 | delete m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.; |
| 23 | } |
| 24 | |
| 25 | bool DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#::areShortcutsUniquecxx . . $ DynamicShortcutsWidget#areShortcutsUnique(50ce9a9e25b4a850).() const { |
| 26 | QListcxx . . $ QList#<QKeySequencecxx . . $ QKeySequence#> all_shortcutscxx . . $ QList#QList(ced63f7c635d850d).; |
| 27 | |
| 28 | // Obtain all shortcuts. |
| 29 | for (ShortcutCatchercxx . . $ ShortcutCatcher#* catcher : m_actionBindingscxx . . $ DynamicShortcutsWidget#m_actionBindings.) { |
| 30 | const QKeySequencecxx . . $ QKeySequence# new_shortcut = catcher->shortcutcxx . . $ ShortcutCatcher#shortcut(61730174ff4ccd18).(); |
| 31 | |
| 32 | if (!new_shortcut.isEmptycxx . . $ QKeySequence#isEmpty(50ce9a9e25b4a850).() && all_shortcuts.containscxx . . $ QListSpecialMethodsBase#contains(7349e39e0b02d05c).(new_shortcut)) { |
| 33 | // Problem, two identical non-empty shortcuts found. |
| 34 | return false; |
| 35 | } |
| 36 | else { |
| 37 | all_shortcuts.appendcxx . . $ QList#append(1262c8661f7a27a7).(catcher->shortcutcxx . . $ ShortcutCatcher#shortcut(61730174ff4ccd18).()); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | void DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#::updateShortcutscxx . . $ DynamicShortcutsWidget#updateShortcuts(49f6e7a06ebc5aa8).() { |
| 45 | for (ShortcutCatchercxx . . $ ShortcutCatcher#* catcher : stdcxx . . $ std/::as_constcxx . . $ std/as_const(1dc117cbefefc300).(m_actionBindingscxx . . $ DynamicShortcutsWidget#m_actionBindings.)) { |
| 46 | catcher->actioncxx . . $ ShortcutCatcher#action(50f6a0536a8019cb).()->setShortcutcxx . . $ QAction#setShortcut(462600f892e8a1ee).(catcher->shortcutcxx . . $ ShortcutCatcher#shortcut(61730174ff4ccd18).()); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#::populatecxx . . $ DynamicShortcutsWidget#populate(b5518ac558724ab9).(QListcxx . . $ QList#<QActioncxx . . $ QAction#*> actions) { |
| 51 | m_actionBindingscxx . . $ DynamicShortcutsWidget#m_actionBindings..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).(); |
| 52 | stdcxx . . $ std/::sortcxx . . $ std/sort(4d3091562df4e52e).(actions.begincxx . . $ QList#begin(ca2520f641887418).(), actions.endcxx . . $ QList#end(ca2520f641887418).(), [](QActioncxx . . $ QAction#* lhs, QActioncxx . . $ QAction#* rhs) { |
| 53 | return QStringcxx . . $ QString#::localeAwareComparecxx . . $ QString#localeAwareCompare(c6f4e55073dadb56).(lhs->textcxx . . $ QAction#text(6ef7b6c27b00b43d).().replacecxx . . $ QString#replace(8efa7599e214252).(QL1Scxx . . $ `src/librssguard/definitions/definitions.h:449:9`!("&"), QStringcxx . . $ QString#QString(ced63f7c635d850d).()), |
| 54 | rhs->textcxx . . $ QAction#text(6ef7b6c27b00b43d).().replacecxx . . $ QString#replace(8efa7599e214252).(QL1Scxx . . $ `src/librssguard/definitions/definitions.h:449:9`!("&"), QStringcxx . . $ QString#QString(ced63f7c635d850d).())) < 0; |
| 55 | }); |
| 56 | int row_id = 0; |
| 57 | |
| 58 | for (QActioncxx . . $ QAction#* action : actions) { |
| 59 | // Create shortcut catcher for this action and set default shortcut. |
| 60 | auto* catcher = new ShortcutCatchercxx . . $ ShortcutCatcher#ShortcutCatcher(108f35f7aa7f3cf9).(this); |
| 61 | |
| 62 | catcher->setActioncxx . . $ ShortcutCatcher#setAction(92b1e80c0a7f1406).(action); |
| 63 | catcher->setDefaultShortcutcxx . . $ ShortcutCatcher#setDefaultShortcut(462600f892e8a1ee).(action->shortcutcxx . . $ QAction#shortcut(61730174ff4ccd18).()); |
| 64 | |
| 65 | if (!action->shortcutcxx . . $ QAction#shortcut(61730174ff4ccd18).().isEmptycxx . . $ QKeySequence#isEmpty(50ce9a9e25b4a850).()) { |
| 66 | m_assignedShortcutscxx . . $ DynamicShortcutsWidget#m_assignedShortcuts..insertcxx . . $ QHash#insert(d77b19c31d2eb147).(action->shortcutcxx . . $ QAction#shortcut(61730174ff4ccd18).(), catcher); |
| 67 | } |
| 68 | |
| 69 | m_actionBindingscxx . . $ DynamicShortcutsWidget#m_actionBindings..appendcxx . . $ QList#append(200d2dc08238a4ed).(catcher); |
| 70 | |
| 71 | // Add new catcher to our control. |
| 72 | auto* action_label = new QLabelcxx . . $ QLabel#QLabel(872e7b0c281abd8d).(this); |
| 73 | auto act_text = actioncxx . . $ QString#QString(132dd6869045752b).->textcxx . . $ QAction#text(6ef7b6c27b00b43d).().removecxx . . $ QString#remove(d7c3fdecc68f03c6).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("&")); |
| 74 | auto act_toolt = action->toolTipcxx . . $ QAction#toolTip(6ef7b6c27b00b43d).(); |
| 75 | |
| 76 | if (act_toolt.isEmptycxx . . $ QString#isEmpty(3482b152b9333168).() || act_text ==cxx . . $ `operator==`(5bc2975d2d751687). act_toolt) { |
| 77 | action_label->setTextcxx . . $ QLabel#setText(3520e46b33348bf6).(act_text); |
| 78 | } |
| 79 | else { |
| 80 | action_label->setTextcxx . . $ QLabel#setText(3520e46b33348bf6).(act_toolt); |
| 81 | // action_label->setText(QSL("%1 (%2)").arg(act_text, act_toolt)); |
| 82 | } |
| 83 | |
| 84 | action_label->setToolTipcxx . . $ QWidget#setToolTip(3520e46b33348bf6).(action->toolTipcxx . . $ QAction#toolTip(6ef7b6c27b00b43d).()); |
| 85 | action_label->setWordWrapcxx . . $ QLabel#setWordWrap(b45ddcbc8423892c).(true); |
| 86 | |
| 87 | // action_label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); |
| 88 | |
| 89 | auto* action_icon = new QLabelcxx . . $ QLabel#QLabel(872e7b0c281abd8d).(this); |
| 90 | |
| 91 | action_icon->setPixmapcxx . . $ QLabel#setPixmap(8887f7d25b86c3f4).(action->iconcxx . . $ QAction#icon(952ef71f8967d9eb).().pixmapcxx . . $ QIcon#pixmap(6ca65e964a77a341).(ICON_SIZE_SETTINGScxx . . $ `src/librssguard/definitions/definitions.h:71:9`!, ICON_SIZE_SETTINGScxx . . $ `src/librssguard/definitions/definitions.h:71:9`!)); |
| 92 | action_icon->setToolTipcxx . . $ QWidget#setToolTip(3520e46b33348bf6).(action->toolTipcxx . . $ QAction#toolTip(6ef7b6c27b00b43d).()); |
| 93 | |
| 94 | m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.->addWidgetcxx . . $ QGridLayout#addWidget(17d1465fab362e2d).(action_icon, row_id, 0); |
| 95 | m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.->addWidgetcxx . . $ QGridLayout#addWidget(17d1465fab362e2d).(action_label, row_id, 1); |
| 96 | m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.->addWidgetcxx . . $ QGridLayout#addWidget(17d1465fab362e2d).(catcher, row_id, 2); |
| 97 | |
| 98 | row_id++; |
| 99 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(catcher, &ShortcutCatchercxx . . $ ShortcutCatcher#::shortcutChangedcxx . . $ ShortcutCatcher#shortcutChanged(462600f892e8a1ee)., this, &DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#::onShortcutChangedcxx . . $ DynamicShortcutsWidget#onShortcutChanged(462600f892e8a1ee).); |
| 100 | } |
| 101 | |
| 102 | // Make sure that "spacer" is added. |
| 103 | m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.->setRowStretchcxx . . $ QGridLayout#setRowStretch(3e454b8ccf442868).(row_id, 1); |
| 104 | m_layoutcxx . . $ DynamicShortcutsWidget#m_layout.->setColumnStretchcxx . . $ QGridLayout#setColumnStretch(3e454b8ccf442868).(1, 1); |
| 105 | } |
| 106 | |
| 107 | void DynamicShortcutsWidgetcxx . . $ DynamicShortcutsWidget#::onShortcutChangedcxx . . $ DynamicShortcutsWidget#onShortcutChanged(462600f892e8a1ee).(const QKeySequencecxx . . $ QKeySequence#& sequence) { |
| 108 | ShortcutCatchercxx . . $ ShortcutCatcher#* catcher = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<ShortcutCatchercxx . . $ ShortcutCatcher#*>(sendercxx . . $ QObject#sender(2dbb680a34285c44).()); |
| 109 | QKeySequencecxx . . $ QKeySequence# assigned_sequence = m_assignedShortcutscxx . . $ DynamicShortcutsWidget#m_assignedShortcuts..keycxx . . $ QHash#key(9ad62395b044fdf8).(catcher); |
| 110 | |
| 111 | qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). catcher->actioncxx . . $ ShortcutCatcher#action(50f6a0536a8019cb).()->textcxx . . $ QAction#text(6ef7b6c27b00b43d).(); |
| 112 | |
| 113 | // We remove currently assigned sequence to this catcher. |
| 114 | m_assignedShortcutscxx . . $ DynamicShortcutsWidget#m_assignedShortcuts..removecxx . . $ QHash#remove(fe1ba53999e710f3).(assigned_sequence); |
| 115 | |
| 116 | if (!sequence.isEmptycxx . . $ QKeySequence#isEmpty(50ce9a9e25b4a850).()) { |
| 117 | // Now we check if any other catcher has assigned the same sequence. |
| 118 | ShortcutCatchercxx . . $ ShortcutCatcher#* conflicting_catcher = m_assignedShortcutscxx . . $ DynamicShortcutsWidget#m_assignedShortcuts..valuecxx . . $ QHash#value(5f65a9ee2c9899ff).(sequence); |
| 119 | |
| 120 | if (conflicting_catcher != nullptr) { |
| 121 | // We found conflicting catcher. |
| 122 | catcher->blockSignalscxx . . $ QObject#blockSignals(4264aff4942d46ac).(true); |
| 123 | |
| 124 | QMessageBoxcxx . . $ QMessageBox#::StandardButtoncxx . . $ QMessageBox#StandardButton# decision = |
| 125 | MsgBoxcxx . . $ MsgBox#::showcxx . . $ MsgBox#show(699e792c6fa2d501).(this, |
| 126 | QMessageBoxcxx . . $ QMessageBox#::Iconcxx . . $ QMessageBox#Icon#::Criticalcxx . . $ QMessageBox#Critical., |
| 127 | trcxx . . $ DynamicShortcutsWidget#tr(75d9f1c324b4579d).("Duplicate shortcut"), |
| 128 | trcxx . . $ DynamicShortcutsWidget#tr(75d9f1c324b4579d).("There is another action which has the same shortcut assigned."), |
| 129 | trcxx . . $ DynamicShortcutsWidget#tr(75d9f1c324b4579d).("Do you want to keep the new shortcut assignment and clear the previous shortcut?"), |
| 130 | conflicting_catcher->actioncxx . . $ ShortcutCatcher#action(50f6a0536a8019cb).()->textcxx . . $ QAction#text(6ef7b6c27b00b43d).().removecxx . . $ QString#remove(d7c3fdecc68f03c6).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("&")), |
| 131 | QMessageBoxcxx . . $ QMessageBox#::StandardButtoncxx . . $ QMessageBox#StandardButton#::Yescxx . . $ QMessageBox#Yes. |cxx . . $ `operator|`(67530149e923fc12). QMessageBoxcxx . . $ QMessageBox#::StandardButtoncxx . . $ QMessageBox#StandardButton#::Nocxx . . $ QMessageBox#No., |
| 132 | QMessageBoxcxx . . $ QMessageBox#::StandardButtoncxx . . $ QMessageBox#StandardButton#::Yescxx . . $ QMessageBox#Yes.); |
| 133 | |
| 134 | catcher->blockSignalscxx . . $ QObject#blockSignals(4264aff4942d46ac).(false); |
| 135 | |
| 136 | if (decision == QMessageBoxcxx . . $ QMessageBox#::StandardButtoncxx . . $ QMessageBox#StandardButton#::Yescxx . . $ QMessageBox#Yes.) { |
| 137 | // We keep the new shortcut and reset old conflicting action. |
| 138 | m_assignedShortcutscxx . . $ DynamicShortcutsWidget#m_assignedShortcuts..insertcxx . . $ QHash#insert(d77b19c31d2eb147).(sequence, catcher); |
| 139 | conflicting_catcher->clearShortcutcxx . . $ ShortcutCatcher#clearShortcut(49f6e7a06ebc5aa8).(); |
| 140 | } |
| 141 | else { |
| 142 | // We discard new shortcut. |
| 143 | catcher->clearShortcutcxx . . $ ShortcutCatcher#clearShortcut(49f6e7a06ebc5aa8).(); |
| 144 | } |
| 145 | } |
| 146 | else { |
| 147 | m_assignedShortcutscxx . . $ DynamicShortcutsWidget#m_assignedShortcuts..insertcxx . . $ QHash#insert(d77b19c31d2eb147).(sequence, catcher); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! setupChangedcxx . . $ DynamicShortcutsWidget#setupChanged(49f6e7a06ebc5aa8).(); |
| 152 | } |