From 3afafef65bff7fc6ecb02c88bc20657e1bdc2fe4 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 1 Oct 2022 18:49:43 -0400 Subject: Restore item shortcuts. --- qdeduper/mingui.cpp | 75 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'qdeduper') diff --git a/qdeduper/mingui.cpp b/qdeduper/mingui.cpp index 5c320b8..caf0249 100644 --- a/qdeduper/mingui.cpp +++ b/qdeduper/mingui.cpp @@ -150,6 +150,29 @@ DeduperMainWindow::DeduperMainWindow() QObject::connect(rampupd, &QTimer::timeout, this, &DeduperMainWindow::update_memusg); this->setup_menu(); this->update_actions(); + for (size_t i = 0; i < iadefkeys.size(); ++i) + { + QAction *ma = new QAction(); + QObject::connect(ma, &QAction::triggered, std::bind(&DeduperMainWindow::mark_toggle, this, i)); + selhk.push_back(ma); + + QAction *sa = new QAction(); + QObject::connect(sa, &QAction::triggered, std::bind(&DeduperMainWindow::mark_all_but, this, i)); + selhk.push_back(sa); + + QAction *ca = new QAction(); + QObject::connect(ca, &QAction::triggered, std::bind(&DeduperMainWindow::show_only, this, i)); + selhk.push_back(ca); + + QAction *oa = new QAction(); + QObject::connect(oa, &QAction::triggered, std::bind(&DeduperMainWindow::open_image, this, i)); + selhk.push_back(oa); + + QAction *la = new QAction(); + QObject::connect(la, &QAction::triggered, std::bind(&DeduperMainWindow::locate_image, this, i)); + selhk.push_back(la); + } + this->addActions(selhk); sr = new SettingsRegistry(QStandardPaths::writableLocation(QStandardPaths::StandardLocation::ConfigLocation) + QString("/qdeduperrc")); int generalt = sr->register_tab("General"); @@ -165,10 +188,15 @@ DeduperMainWindow::DeduperMainWindow() std::string hkn = hkp.first.substr(3); sr->register_keyseq_option(hkt, "hotkey/" + hkn, QString(), hkp.second); } - for (int i = 0; i < ItemActionType::ACTION_MAX; ++i) + for (size_t i = 0; i < iadefmo.size(); ++i) + { + std::string iamt = "hotkey/item_action_mod_" + std::to_string(i); + sr->register_int_option(hkt, iamt, QString(), INT_MIN, INT_MAX, iadefmo[i]); + } + for (size_t i = 0; i < iadefkeys.size(); ++i) { - std::string iakt = "hotkey/item_action_mod_" + std::to_string(i); - sr->register_int_option(hkt, iakt, QString(), INT_MIN, INT_MAX, 0); + std::string iakt = "hotkey/item_" + std::to_string(i) + "_action_key"; + sr->register_int_option(hkt, iakt, QString(), INT_MIN, INT_MAX, iadefkeys[i]); } prefdlg = new PreferenceDialog(sr, this); prefdlg->setModal(true); @@ -178,30 +206,6 @@ DeduperMainWindow::DeduperMainWindow() QObject::connect(prefdlg, &PreferenceDialog::accepted, this, &DeduperMainWindow::apply_prefs); apply_prefs(); - for (size_t i = 0; i < iadefkeys.size(); ++i) - { - QAction *ma = new QAction(); - QObject::connect(ma, &QAction::triggered, std::bind(&DeduperMainWindow::mark_toggle, this, i)); - selhk.push_back(ma); - - QAction *sa = new QAction(); - QObject::connect(sa, &QAction::triggered, std::bind(&DeduperMainWindow::mark_all_but, this, i)); - selhk.push_back(sa); - - QAction *ca = new QAction(); - QObject::connect(ca, &QAction::triggered, std::bind(&DeduperMainWindow::show_only, this, i)); - selhk.push_back(ca); - - QAction *oa = new QAction(); - QObject::connect(oa, &QAction::triggered, std::bind(&DeduperMainWindow::open_image, this, i)); - selhk.push_back(oa); - - QAction *la = new QAction(); - QObject::connect(la, &QAction::triggered, std::bind(&DeduperMainWindow::locate_image, this, i)); - selhk.push_back(la); - } - this->addActions(selhk); - QObject::connect(lv, &QListView::clicked, [this](const QModelIndex &i) { auto cs = i.data(Qt::ItemDataRole::CheckStateRole).value(); if (cs == Qt::CheckState::Checked) @@ -497,23 +501,18 @@ void DeduperMainWindow::setup_menu() QMenu *cm = new QMenu(this); QAction *ma = cm->addAction(cks == Qt::CheckState::Checked ? "Unmark" : "Mark"); QObject::connect(ma, &QAction::triggered, std::bind(&DeduperMainWindow::mark_toggle, this, idx.row())); - selhk.push_back(ma); QAction *sa = cm->addAction("Mark All Except"); QObject::connect(sa, &QAction::triggered, std::bind(&DeduperMainWindow::mark_all_but, this, idx.row())); - selhk.push_back(sa); QAction *ca = cm->addAction(id->is_single_item_mode() ? "Restore" : "Maximize"); QObject::connect(ca, &QAction::triggered, std::bind(&DeduperMainWindow::show_only, this, idx.row())); - selhk.push_back(ca); QAction *oa = cm->addAction("Open Image"); QObject::connect(oa, &QAction::triggered, std::bind(&DeduperMainWindow::open_image, this, idx.row())); - selhk.push_back(oa); QAction *la = cm->addAction("Open Containing Folder"); QObject::connect(la, &QAction::triggered, std::bind(&DeduperMainWindow::locate_image, this, idx.row())); - selhk.push_back(la); QObject::connect(cm, &QMenu::aboutToHide, [cm] {cm->deleteLater();}); cm->popup(this->lv->mapToGlobal(pos)); @@ -823,6 +822,18 @@ void DeduperMainWindow::apply_prefs() QKeySequence ks = sr->get_option_keyseq("hotkey/" + hkn); menuact[hkn]->setShortcut(ks); } + for (size_t i = 0; i < selhk.size(); ++i) + { + QAction *act = selhk[i]; + size_t actn = i / ItemActionType::ACTION_MAX; + size_t actt = i % ItemActionType::ACTION_MAX; + std::string iamt = "hotkey/item_action_mod_" + std::to_string(actt); + std::string iakt = "hotkey/item_" + std::to_string(actn) + "_action_key"; + int ik = sr->get_option_int(iakt); + int im = sr->get_option_int(iamt); + QKeySequence ks = QKeySequence(static_cast(ik | im)); + act->setShortcut(ks); + } } void DeduperMainWindow::update_memusg() -- cgit v1.2.3