From 7059b947e8ffcbc34bbe0da883ca313c711d07bc Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 15 Sep 2017 13:57:55 +0800 Subject: [PATCH] Replace dialog ok-cancel buttons with QDialogButtonBox This PR will make button order follow the platform default. For example: windows use: OK, Cancel; linux use: Cancel, OK. --- src/gui/downloadfromurldlg.h | 27 +++++++----- src/gui/downloadfromurldlg.ui | 52 ++++------------------ src/gui/login.ui | 82 ++++------------------------------- src/gui/preview.ui | 69 ++++------------------------- src/gui/previewselect.cpp | 17 ++++---- src/gui/previewselect.h | 7 ++- src/gui/trackerlogin.cpp | 23 +++++++--- src/gui/trackerlogin.h | 6 +-- 8 files changed, 75 insertions(+), 208 deletions(-) diff --git a/src/gui/downloadfromurldlg.h b/src/gui/downloadfromurldlg.h index cd05aeb17..0a8cfbef1 100644 --- a/src/gui/downloadfromurldlg.h +++ b/src/gui/downloadfromurldlg.h @@ -31,23 +31,31 @@ #ifndef DOWNLOADFROMURL_H #define DOWNLOADFROMURL_H +#include #include #include -#include +#include #include +#include #include -#include + #include "ui_downloadfromurldlg.h" -class downloadFromURL : public QDialog, private Ui::downloadFromURL{ +class downloadFromURL : public QDialog, private Ui::downloadFromURL +{ Q_OBJECT public: - downloadFromURL(QWidget *parent): QDialog(parent) { + downloadFromURL(QWidget *parent): QDialog(parent) + { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); setModal(true); + buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Download")); + connect(buttonBox, &QDialogButtonBox::accepted, this, &downloadFromURL::downloadButtonClicked); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + // Paste clipboard if there is an URL in it QString clip_txt = qApp->clipboard()->text(); QStringList clip_txt_list = clip_txt.split(QString::fromUtf8("\n")); @@ -80,8 +88,9 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{ signals: void urlsReadyToBeDownloaded(const QStringList& torrent_urls); - public slots: - void on_downloadButton_clicked() { + private slots: + void downloadButtonClicked() + { QString urls = textUrls->toPlainText(); QStringList url_list = urls.split(QString::fromUtf8("\n")); QString url; @@ -100,11 +109,7 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{ } emit urlsReadyToBeDownloaded(url_list_cleaned); qDebug("Emitted urlsReadytobedownloaded signal"); - close(); - } - - void on_cancelButton_clicked() { - close(); + accept(); } }; diff --git a/src/gui/downloadfromurldlg.ui b/src/gui/downloadfromurldlg.ui index a701e7f99..c42528617 100644 --- a/src/gui/downloadfromurldlg.ui +++ b/src/gui/downloadfromurldlg.ui @@ -6,7 +6,7 @@ 0 0 - 482 + 501 220 @@ -50,48 +50,14 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Download - - - - - - - Cancel - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + diff --git a/src/gui/login.ui b/src/gui/login.ui index 63a9125d2..a4c8c2c0e 100644 --- a/src/gui/login.ui +++ b/src/gui/login.ui @@ -134,85 +134,19 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Log in - - - - - - - Cancel - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + - - cancelButton - clicked() - authentication - reject() - - - 245 - 195 - - - 179 - 230 - - - - - linePasswd - returnPressed() - loginButton - click() - - - 139 - 158 - - - 122 - 199 - - - lineUsername returnPressed() diff --git a/src/gui/preview.ui b/src/gui/preview.ui index 7405b3e0f..be7873d97 100644 --- a/src/gui/preview.ui +++ b/src/gui/preview.ui @@ -32,68 +32,17 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Preview - - - - - - - Cancel - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + - - - cancelButton - clicked() - preview - reject() - - - 296 - 245 - - - 179 - 282 - - - - + diff --git a/src/gui/previewselect.cpp b/src/gui/previewselect.cpp index e9cf03be4..763ebeacf 100644 --- a/src/gui/previewselect.cpp +++ b/src/gui/previewselect.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,11 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); + + buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview")); + connect(buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelect::previewButtonClicked); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + Preferences *const pref = Preferences::instance(); // Preview list m_previewListModel = new QStandardItemModel(0, NB_COLUMNS); @@ -95,7 +101,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t if (m_previewListModel->rowCount() == 1) { qDebug("Torrent file only contains one file, no need to display selection dialog before preview"); // Only one file : no choice - on_previewButton_clicked(); + previewButtonClicked(); } else { qDebug("Displaying media file selection dialog for preview"); @@ -110,7 +116,7 @@ PreviewSelect::~PreviewSelect() } -void PreviewSelect::on_previewButton_clicked() +void PreviewSelect::previewButtonClicked() { QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX); if (selectedIndexes.size() == 0) return; @@ -127,10 +133,5 @@ void PreviewSelect::on_previewButton_clicked() else QMessageBox::critical(this->parentWidget(), tr("Preview impossible"), tr("Sorry, we can't preview this file")); - close(); -} - -void PreviewSelect::on_cancelButton_clicked() -{ - close(); + accept(); } diff --git a/src/gui/previewselect.h b/src/gui/previewselect.h index 0f1db209c..1a32cd114 100644 --- a/src/gui/previewselect.h +++ b/src/gui/previewselect.h @@ -39,7 +39,7 @@ class QStandardItemModel; class PreviewListDelegate; -class PreviewSelect: public QDialog, private Ui::preview +class PreviewSelect : public QDialog, private Ui::preview { Q_OBJECT @@ -60,9 +60,8 @@ public: signals: void readyToPreviewFile(QString) const; -protected slots: - void on_previewButton_clicked(); - void on_cancelButton_clicked(); +private slots: + void previewButtonClicked(); private: QStandardItemModel *m_previewListModel; diff --git a/src/gui/trackerlogin.cpp b/src/gui/trackerlogin.cpp index 74abf1dae..e2d425221 100644 --- a/src/gui/trackerlogin.cpp +++ b/src/gui/trackerlogin.cpp @@ -30,6 +30,7 @@ #include "trackerlogin.h" +#include #include #include "base/bittorrent/torrenthandle.h" @@ -39,24 +40,36 @@ trackerLogin::trackerLogin(QWidget *parent, BitTorrent::TorrentHandle *const tor { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); + + buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Log in")); + login_logo->setPixmap(QPixmap(QString::fromUtf8(":/icons/qbt-theme/encrypted.png"))); + tracker_url->setText(torrent->currentTracker()); - connect(this, SIGNAL(trackerLoginCancelled(QPair)), parent, SLOT(addUnauthenticatedTracker(QPair))); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &trackerLogin::loginButtonClicked); + connect(buttonBox, &QDialogButtonBox::rejected, this, &trackerLogin::cancelButtonClicked); + connect(linePasswd, &QLineEdit::returnPressed, this, &trackerLogin::loginButtonClicked); + connect(this, SIGNAL(trackerLoginCancelled(QPair)), // TODO: use Qt5 connect syntax + parent, SLOT(addUnauthenticatedTracker(QPair))); + show(); } trackerLogin::~trackerLogin() {} -void trackerLogin::on_loginButton_clicked() { +void trackerLogin::loginButtonClicked() +{ // login #if LIBTORRENT_VERSION_NUM < 10100 m_torrent->setTrackerLogin(lineUsername->text(), linePasswd->text()); #endif - close(); + accept(); } -void trackerLogin::on_cancelButton_clicked() { +void trackerLogin::cancelButtonClicked() +{ // Emit a signal to GUI to stop asking for authentication emit trackerLoginCancelled(qMakePair(m_torrent, m_torrent->currentTracker())); - close(); + reject(); } diff --git a/src/gui/trackerlogin.h b/src/gui/trackerlogin.h index 780162dca..e43b9e8dc 100644 --- a/src/gui/trackerlogin.h +++ b/src/gui/trackerlogin.h @@ -53,9 +53,9 @@ class trackerLogin : public QDialog, private Ui::authentication{ signals: void trackerLoginCancelled(QPair tracker); - public slots: - void on_loginButton_clicked(); - void on_cancelButton_clicked(); + private slots: + void loginButtonClicked(); + void cancelButtonClicked(); }; #endif