diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index a7b3a5b91..2ed0a7d3c 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -140,6 +140,7 @@ add_library(qbt_gui STATIC uithememanager.h uithemesource.h utils.h + utils/keysequence.h watchedfolderoptionsdialog.h watchedfoldersmodel.h windowstate.h @@ -239,6 +240,7 @@ add_library(qbt_gui STATIC uithememanager.cpp uithemesource.cpp utils.cpp + utils/keysequence.cpp watchedfolderoptionsdialog.cpp watchedfoldersmodel.cpp diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index b98663b5c..fc78ccbc8 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -101,6 +101,7 @@ #include "ui_mainwindow.h" #include "uithememanager.h" #include "utils.h" +#include "utils/keysequence.h" #ifdef Q_OS_MACOS #include "macosdockbadge/badger.h" @@ -883,7 +884,7 @@ void MainWindow::createKeyboardShortcuts() { m_ui->actionCreateTorrent->setShortcut(QKeySequence::New); m_ui->actionOpen->setShortcut(QKeySequence::Open); - m_ui->actionDelete->setShortcut(QKeySequence::Delete); + m_ui->actionDelete->setShortcut(Utils::KeySequence::deleteItem()); m_ui->actionDelete->setShortcutContext(Qt::WidgetShortcut); // nullify its effect: delete key event is handled by respective widgets, not here m_ui->actionDownloadFromURL->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_O); m_ui->actionExit->setShortcut(Qt::CTRL | Qt::Key_Q); diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index d10bb9c03..8546d7143 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -58,6 +58,7 @@ #include "base/utils/misc.h" #include "base/utils/string.h" #include "gui/uithememanager.h" +#include "gui/utils/keysequence.h" #include "peerlistsortmodel.h" #include "peersadditiondialog.h" #include "propertieswidget.h" @@ -187,7 +188,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) handleSortColumnChanged(header()->sortIndicatorSection()); const auto *copyHotkey = new QShortcut(QKeySequence::Copy, this, nullptr, nullptr, Qt::WidgetShortcut); connect(copyHotkey, &QShortcut::activated, this, &PeerListWidget::copySelectedPeers); - const auto *deleteHotkey = new QShortcut(QKeySequence::Delete, this, nullptr, nullptr, Qt::WidgetShortcut); + const auto *deleteHotkey = new QShortcut(Utils::KeySequence::deleteItem(), this, nullptr, nullptr, Qt::WidgetShortcut); connect(deleteHotkey, &QShortcut::activated, this, &PeerListWidget::banSelectedPeers); } diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index d5c2b03a4..ad9673272 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -56,6 +56,7 @@ #include "gui/trackerlist/trackerlistwidget.h" #include "gui/uithememanager.h" #include "gui/utils.h" +#include "gui/utils/keysequence.h" #include "downloadedpiecesbar.h" #include "peerlistwidget.h" #include "pieceavailabilitybar.h" @@ -136,7 +137,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) const auto *editWebSeedsHotkey = new QShortcut(Qt::Key_F2, m_ui->listWebSeeds, nullptr, nullptr, Qt::WidgetShortcut); connect(editWebSeedsHotkey, &QShortcut::activated, this, &PropertiesWidget::editWebSeed); - const auto *deleteWebSeedsHotkey = new QShortcut(QKeySequence::Delete, m_ui->listWebSeeds, nullptr, nullptr, Qt::WidgetShortcut); + const auto *deleteWebSeedsHotkey = new QShortcut(Utils::KeySequence::deleteItem(), m_ui->listWebSeeds, nullptr, nullptr, Qt::WidgetShortcut); connect(deleteWebSeedsHotkey, &QShortcut::activated, this, &PropertiesWidget::deleteSelectedUrlSeeds); connect(m_ui->listWebSeeds, &QListWidget::doubleClicked, this, &PropertiesWidget::editWebSeed); diff --git a/src/gui/rss/automatedrssdownloader.cpp b/src/gui/rss/automatedrssdownloader.cpp index 5492a6732..f305cefb9 100644 --- a/src/gui/rss/automatedrssdownloader.cpp +++ b/src/gui/rss/automatedrssdownloader.cpp @@ -55,6 +55,7 @@ #include "gui/torrentcategorydialog.h" #include "gui/uithememanager.h" #include "gui/utils.h" +#include "gui/utils/keysequence.h" #include "ui_automatedrssdownloader.h" const QString EXT_JSON = u".json"_s; @@ -151,7 +152,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) const auto *editHotkey = new QShortcut(Qt::Key_F2, m_ui->ruleList, nullptr, nullptr, Qt::WidgetShortcut); connect(editHotkey, &QShortcut::activated, this, &AutomatedRssDownloader::renameSelectedRule); - const auto *deleteHotkey = new QShortcut(QKeySequence::Delete, m_ui->ruleList, nullptr, nullptr, Qt::WidgetShortcut); + const auto *deleteHotkey = new QShortcut(Utils::KeySequence::deleteItem(), m_ui->ruleList, nullptr, nullptr, Qt::WidgetShortcut); connect(deleteHotkey, &QShortcut::activated, this, &AutomatedRssDownloader::onRemoveRuleBtnClicked); connect(m_ui->ruleList, &QAbstractItemView::doubleClicked, this, &AutomatedRssDownloader::renameSelectedRule); diff --git a/src/gui/rss/rsswidget.cpp b/src/gui/rss/rsswidget.cpp index 75c5d171b..98c272014 100644 --- a/src/gui/rss/rsswidget.cpp +++ b/src/gui/rss/rsswidget.cpp @@ -49,6 +49,7 @@ #include "gui/autoexpandabledialog.h" #include "gui/interfaces/iguiapplication.h" #include "gui/uithememanager.h" +#include "gui/utils/keysequence.h" #include "articlelistwidget.h" #include "automatedrssdownloader.h" #include "feedlistwidget.h" @@ -140,7 +141,7 @@ RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent) const auto *editHotkey = new QShortcut(Qt::Key_F2, m_ui->feedListWidget, nullptr, nullptr, Qt::WidgetShortcut); connect(editHotkey, &QShortcut::activated, this, &RSSWidget::renameSelectedRSSItem); - const auto *deleteHotkey = new QShortcut(QKeySequence::Delete, m_ui->feedListWidget, nullptr, nullptr, Qt::WidgetShortcut); + const auto *deleteHotkey = new QShortcut(Utils::KeySequence::deleteItem(), m_ui->feedListWidget, nullptr, nullptr, Qt::WidgetShortcut); connect(deleteHotkey, &QShortcut::activated, this, &RSSWidget::deleteSelectedItems); // Feeds list actions diff --git a/src/gui/trackerlist/trackerlistwidget.cpp b/src/gui/trackerlist/trackerlistwidget.cpp index 51ef35c9c..36ae595d8 100644 --- a/src/gui/trackerlist/trackerlistwidget.cpp +++ b/src/gui/trackerlist/trackerlistwidget.cpp @@ -53,6 +53,7 @@ #include "gui/autoexpandabledialog.h" #include "gui/trackersadditiondialog.h" #include "gui/uithememanager.h" +#include "gui/utils/keysequence.h" #include "trackerlistitemdelegate.h" #include "trackerlistmodel.h" #include "trackerlistsortmodel.h" @@ -106,7 +107,7 @@ TrackerListWidget::TrackerListWidget(QWidget *parent) // Set hotkeys const auto *editHotkey = new QShortcut(Qt::Key_F2, this, nullptr, nullptr, Qt::WidgetShortcut); connect(editHotkey, &QShortcut::activated, this, &TrackerListWidget::editSelectedTracker); - const auto *deleteHotkey = new QShortcut(QKeySequence::Delete, this, nullptr, nullptr, Qt::WidgetShortcut); + const auto *deleteHotkey = new QShortcut(Utils::KeySequence::deleteItem(), this, nullptr, nullptr, Qt::WidgetShortcut); connect(deleteHotkey, &QShortcut::activated, this, &TrackerListWidget::deleteSelectedTrackers); const auto *copyHotkey = new QShortcut(QKeySequence::Copy, this, nullptr, nullptr, Qt::WidgetShortcut); connect(copyHotkey, &QShortcut::activated, this, &TrackerListWidget::copyTrackerUrl); diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index cd6b44653..95814c0e6 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -72,6 +72,7 @@ #include "tristateaction.h" #include "uithememanager.h" #include "utils.h" +#include "utils/keysequence.h" #ifdef Q_OS_MACOS #include "macosshiftclickhandler.h" @@ -228,7 +229,7 @@ TransferListWidget::TransferListWidget(IGUIApplication *app, QWidget *parent) const auto *editHotkey = new QShortcut(Qt::Key_F2, this, nullptr, nullptr, Qt::WidgetShortcut); connect(editHotkey, &QShortcut::activated, this, &TransferListWidget::renameSelectedTorrent); - const auto *deleteHotkey = new QShortcut(QKeySequence::Delete, this, nullptr, nullptr, Qt::WidgetShortcut); + const auto *deleteHotkey = new QShortcut(Utils::KeySequence::deleteItem(), this, nullptr, nullptr, Qt::WidgetShortcut); connect(deleteHotkey, &QShortcut::activated, this, &TransferListWidget::softDeleteSelectedTorrents); const auto *permDeleteHotkey = new QShortcut((Qt::SHIFT | Qt::Key_Delete), this, nullptr, nullptr, Qt::WidgetShortcut); connect(permDeleteHotkey, &QShortcut::activated, this, &TransferListWidget::permDeleteSelectedTorrents); diff --git a/src/gui/utils/keysequence.cpp b/src/gui/utils/keysequence.cpp new file mode 100644 index 000000000..53fa5041f --- /dev/null +++ b/src/gui/utils/keysequence.cpp @@ -0,0 +1,41 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2025 Mike Tzou (Chocobo1) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "keysequence.h" + +#include +#include + +QKeySequence Utils::KeySequence::deleteItem() +{ +#ifdef Q_OS_MACOS + return Qt::CTRL | Qt::Key_Backspace; +#else + return QKeySequence::Delete; +#endif +} diff --git a/src/gui/utils/keysequence.h b/src/gui/utils/keysequence.h new file mode 100644 index 000000000..b89dd2d7f --- /dev/null +++ b/src/gui/utils/keysequence.h @@ -0,0 +1,38 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2025 Mike Tzou (Chocobo1) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#pragma once + +class QKeySequence; + +namespace Utils::KeySequence +{ + // QKeySequence variable cannot be initialized at compile time. It will crash at startup. + + QKeySequence deleteItem(); +}