Enable edit/rename via F2 or double click in various places

This commit is contained in:
Nick Tiskov 2013-07-22 18:39:48 +04:00 committed by sledgehammer999
parent afd7867151
commit a7bf28b78f
8 changed files with 30 additions and 2 deletions

View file

@ -81,6 +81,9 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
loadState(); loadState();
// Signal / slots // Signal / slots
connect(ui->adv_button, SIGNAL(clicked(bool)), SLOT(showAdvancedSettings(bool))); connect(ui->adv_button, SIGNAL(clicked(bool)), SLOT(showAdvancedSettings(bool)));
editHotkey = new QShortcut(QKeySequence("F2"), ui->content_tree, 0, 0, Qt::WidgetShortcut);
connect(editHotkey, SIGNAL(activated()), SLOT(renameSelectedFile()));
connect(ui->content_tree, SIGNAL(doubleClicked(QModelIndex)), SLOT(renameSelectedFile()));
} }
AddNewTorrentDialog::~AddNewTorrentDialog() AddNewTorrentDialog::~AddNewTorrentDialog()
@ -89,6 +92,7 @@ AddNewTorrentDialog::~AddNewTorrentDialog()
delete ui; delete ui;
if (m_contentModel) if (m_contentModel)
delete m_contentModel; delete m_contentModel;
delete editHotkey;
} }
void AddNewTorrentDialog::loadState() void AddNewTorrentDialog::loadState()
@ -390,7 +394,8 @@ void AddNewTorrentDialog::relayout()
void AddNewTorrentDialog::renameSelectedFile() void AddNewTorrentDialog::renameSelectedFile()
{ {
const QModelIndexList selectedIndexes = ui->content_tree->selectionModel()->selectedRows(0); const QModelIndexList selectedIndexes = ui->content_tree->selectionModel()->selectedRows(0);
Q_ASSERT(selectedIndexes.size() == 1); if (selectedIndexes.size() != 1)
return;
const QModelIndex &index = selectedIndexes.first(); const QModelIndex &index = selectedIndexes.first();
// Ask for new name // Ask for new name
bool ok; bool ok;

View file

@ -31,6 +31,7 @@
#ifndef ADDNEWTORRENTDIALOG_H #ifndef ADDNEWTORRENTDIALOG_H
#define ADDNEWTORRENTDIALOG_H #define ADDNEWTORRENTDIALOG_H
#include <QShortcut>
#include <QDialog> #include <QDialog>
#include <QUrl> #include <QUrl>
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
@ -86,6 +87,7 @@ private:
boost::intrusive_ptr<libtorrent::torrent_info> m_torrentInfo; boost::intrusive_ptr<libtorrent::torrent_info> m_torrentInfo;
QStringList m_filesPath; QStringList m_filesPath;
bool m_hasRenamedFile; bool m_hasRenamedFile;
QShortcut *editHotkey;
}; };
#endif // ADDNEWTORRENTDIALOG_H #endif // ADDNEWTORRENTDIALOG_H

View file

@ -122,6 +122,11 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
refreshTimer = new QTimer(this); refreshTimer = new QTimer(this);
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData())); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
refreshTimer->start(3000); // 3sec refreshTimer->start(3000); // 3sec
editHotkeyFile = new QShortcut(QKeySequence("F2"), filesList, 0, 0, Qt::WidgetShortcut);
connect(editHotkeyFile, SIGNAL(activated()), SLOT(renameSelectedFile()));
editHotkeyWeb = new QShortcut(QKeySequence("F2"), listWebSeeds, 0, 0, Qt::WidgetShortcut);
connect(editHotkeyWeb, SIGNAL(activated()), SLOT(editWebSeed()));
connect(listWebSeeds, SIGNAL(doubleClicked(QModelIndex)), SLOT(editWebSeed()));
} }
PropertiesWidget::~PropertiesWidget() { PropertiesWidget::~PropertiesWidget() {
@ -134,6 +139,8 @@ PropertiesWidget::~PropertiesWidget() {
delete PropListModel; delete PropListModel;
delete PropDelegate; delete PropDelegate;
delete m_tabBar; delete m_tabBar;
delete editHotkeyFile;
delete editHotkeyWeb;
qDebug() << Q_FUNC_INFO << "EXIT"; qDebug() << Q_FUNC_INFO << "EXIT";
} }
@ -505,7 +512,8 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
void PropertiesWidget::renameSelectedFile() { void PropertiesWidget::renameSelectedFile() {
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0); const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
Q_ASSERT(selectedIndexes.size() == 1); if (selectedIndexes.size() != 1)
return;
const QModelIndex index = selectedIndexes.first(); const QModelIndex index = selectedIndexes.first();
// Ask for new name // Ask for new name
bool ok; bool ok;

View file

@ -31,6 +31,7 @@
#ifndef PROPERTIESWIDGET_H #ifndef PROPERTIESWIDGET_H
#define PROPERTIESWIDGET_H #define PROPERTIESWIDGET_H
#include <QShortcut>
#include <QWidget> #include <QWidget>
#include "ui_propertieswidget.h" #include "ui_propertieswidget.h"
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
@ -109,6 +110,8 @@ private:
PieceAvailabilityBar *pieces_availability; PieceAvailabilityBar *pieces_availability;
PropTabBar *m_tabBar; PropTabBar *m_tabBar;
LineEdit *m_contentFilerLine; LineEdit *m_contentFilerLine;
QShortcut *editHotkeyFile;
QShortcut *editHotkeyWeb;
}; };
#endif // PROPERTIESWIDGET_H #endif // PROPERTIESWIDGET_H

View file

@ -72,11 +72,14 @@ TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), propertie
lsd_item = new QTreeWidgetItem(QStringList() << "" << "** [LSD] **"); lsd_item = new QTreeWidgetItem(QStringList() << "" << "** [LSD] **");
insertTopLevelItem(2, lsd_item); insertTopLevelItem(2, lsd_item);
setRowColor(2, QColor("grey")); setRowColor(2, QColor("grey"));
editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut);
connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker()));
loadSettings(); loadSettings();
} }
TrackerList::~TrackerList() { TrackerList::~TrackerList() {
delete editHotkey;
saveSettings(); saveSettings();
} }

View file

@ -31,6 +31,7 @@
#ifndef TRACKERLIST_H #ifndef TRACKERLIST_H
#define TRACKERLIST_H #define TRACKERLIST_H
#include <QShortcut>
#include <QTreeWidget> #include <QTreeWidget>
#include <QList> #include <QList>
@ -51,6 +52,7 @@ private:
QTreeWidgetItem* dht_item; QTreeWidgetItem* dht_item;
QTreeWidgetItem* pex_item; QTreeWidgetItem* pex_item;
QTreeWidgetItem* lsd_item; QTreeWidgetItem* lsd_item;
QShortcut *editHotkey;
public: public:
TrackerList(PropertiesWidget *properties); TrackerList(PropertiesWidget *properties);

View file

@ -132,6 +132,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window,
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&))); connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&)));
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&))); connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&)));
editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(renameSelectedTorrent()), 0, Qt::WidgetShortcut);
} }
TransferListWidget::~TransferListWidget() { TransferListWidget::~TransferListWidget() {
@ -144,6 +146,7 @@ TransferListWidget::~TransferListWidget() {
delete nameFilterModel; delete nameFilterModel;
delete listModel; delete listModel;
delete listDelegate; delete listDelegate;
delete editHotkey;
qDebug() << Q_FUNC_INFO << "EXIT"; qDebug() << Q_FUNC_INFO << "EXIT";
} }

View file

@ -31,6 +31,7 @@
#ifndef TRANSFERLISTWIDGET_H #ifndef TRANSFERLISTWIDGET_H
#define TRANSFERLISTWIDGET_H #define TRANSFERLISTWIDGET_H
#include <QShortcut>
#include <QTreeView> #include <QTreeView>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
@ -116,6 +117,7 @@ private:
QSortFilterProxyModel *labelFilterModel; QSortFilterProxyModel *labelFilterModel;
QBtSession* BTSession; QBtSession* BTSession;
MainWindow *main_window; MainWindow *main_window;
QShortcut *editHotkey;
}; };
#endif // TRANSFERLISTWIDGET_H #endif // TRANSFERLISTWIDGET_H