Browse Source

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.
adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
7059b947e8
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 27
      src/gui/downloadfromurldlg.h
  2. 46
      src/gui/downloadfromurldlg.ui
  3. 76
      src/gui/login.ui
  4. 63
      src/gui/preview.ui
  5. 17
      src/gui/previewselect.cpp
  6. 7
      src/gui/previewselect.h
  7. 23
      src/gui/trackerlogin.cpp
  8. 6
      src/gui/trackerlogin.h

27
src/gui/downloadfromurldlg.h

@ -31,23 +31,31 @@
#ifndef DOWNLOADFROMURL_H #ifndef DOWNLOADFROMURL_H
#define DOWNLOADFROMURL_H #define DOWNLOADFROMURL_H
#include <QClipboard>
#include <QDialog> #include <QDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QString> #include <QPushButton>
#include <QRegExp> #include <QRegExp>
#include <QString>
#include <QStringList> #include <QStringList>
#include <QClipboard>
#include "ui_downloadfromurldlg.h" #include "ui_downloadfromurldlg.h"
class downloadFromURL : public QDialog, private Ui::downloadFromURL{ class downloadFromURL : public QDialog, private Ui::downloadFromURL
{
Q_OBJECT Q_OBJECT
public: public:
downloadFromURL(QWidget *parent): QDialog(parent) { downloadFromURL(QWidget *parent): QDialog(parent)
{
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setModal(true); 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 // Paste clipboard if there is an URL in it
QString clip_txt = qApp->clipboard()->text(); QString clip_txt = qApp->clipboard()->text();
QStringList clip_txt_list = clip_txt.split(QString::fromUtf8("\n")); QStringList clip_txt_list = clip_txt.split(QString::fromUtf8("\n"));
@ -80,8 +88,9 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{
signals: signals:
void urlsReadyToBeDownloaded(const QStringList& torrent_urls); void urlsReadyToBeDownloaded(const QStringList& torrent_urls);
public slots: private slots:
void on_downloadButton_clicked() { void downloadButtonClicked()
{
QString urls = textUrls->toPlainText(); QString urls = textUrls->toPlainText();
QStringList url_list = urls.split(QString::fromUtf8("\n")); QStringList url_list = urls.split(QString::fromUtf8("\n"));
QString url; QString url;
@ -100,11 +109,7 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{
} }
emit urlsReadyToBeDownloaded(url_list_cleaned); emit urlsReadyToBeDownloaded(url_list_cleaned);
qDebug("Emitted urlsReadytobedownloaded signal"); qDebug("Emitted urlsReadytobedownloaded signal");
close(); accept();
}
void on_cancelButton_clicked() {
close();
} }
}; };

46
src/gui/downloadfromurldlg.ui

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>482</width> <width>501</width>
<height>220</height> <height>220</height>
</rect> </rect>
</property> </property>
@ -50,49 +50,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <widget class="QDialogButtonBox" name="buttonBox">
<item> <property name="standardButtons">
<spacer> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> <property name="centerButtons">
</item> <bool>true</bool>
<item>
<widget class="QPushButton" name="downloadButton">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

76
src/gui/login.ui

@ -134,85 +134,19 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <widget class="QDialogButtonBox" name="buttonBox">
<item> <property name="standardButtons">
<spacer> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> <property name="centerButtons">
</item> <bool>true</bool>
<item>
<widget class="QPushButton" name="loginButton">
<property name="text">
<string>Log in</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>authentication</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>245</x>
<y>195</y>
</hint>
<hint type="destinationlabel">
<x>179</x>
<y>230</y>
</hint>
</hints>
</connection>
<connection>
<sender>linePasswd</sender>
<signal>returnPressed()</signal>
<receiver>loginButton</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>139</x>
<y>158</y>
</hint>
<hint type="destinationlabel">
<x>122</x>
<y>199</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>lineUsername</sender> <sender>lineUsername</sender>
<signal>returnPressed()</signal> <signal>returnPressed()</signal>

63
src/gui/preview.ui

@ -32,68 +32,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <widget class="QDialogButtonBox" name="buttonBox">
<item> <property name="standardButtons">
<spacer> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> <property name="centerButtons">
</item> <bool>true</bool>
<item>
<widget class="QPushButton" name="previewButton">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections> <connections/>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>preview</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>296</x>
<y>245</y>
</hint>
<hint type="destinationlabel">
<x>179</x>
<y>282</y>
</hint>
</hints>
</connection>
</connections>
</ui> </ui>

17
src/gui/previewselect.cpp

@ -31,6 +31,7 @@
#include <QFile> #include <QFile>
#include <QHeaderView> #include <QHeaderView>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QTableView> #include <QTableView>
@ -45,6 +46,11 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t
{ {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); 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(); Preferences *const pref = Preferences::instance();
// Preview list // Preview list
m_previewListModel = new QStandardItemModel(0, NB_COLUMNS); m_previewListModel = new QStandardItemModel(0, NB_COLUMNS);
@ -95,7 +101,7 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t
if (m_previewListModel->rowCount() == 1) { if (m_previewListModel->rowCount() == 1) {
qDebug("Torrent file only contains one file, no need to display selection dialog before preview"); qDebug("Torrent file only contains one file, no need to display selection dialog before preview");
// Only one file : no choice // Only one file : no choice
on_previewButton_clicked(); previewButtonClicked();
} }
else { else {
qDebug("Displaying media file selection dialog for preview"); 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); QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX);
if (selectedIndexes.size() == 0) return; if (selectedIndexes.size() == 0) return;
@ -127,10 +133,5 @@ void PreviewSelect::on_previewButton_clicked()
else else
QMessageBox::critical(this->parentWidget(), tr("Preview impossible"), tr("Sorry, we can't preview this file")); QMessageBox::critical(this->parentWidget(), tr("Preview impossible"), tr("Sorry, we can't preview this file"));
close(); accept();
}
void PreviewSelect::on_cancelButton_clicked()
{
close();
} }

7
src/gui/previewselect.h

@ -39,7 +39,7 @@ class QStandardItemModel;
class PreviewListDelegate; class PreviewListDelegate;
class PreviewSelect: public QDialog, private Ui::preview class PreviewSelect : public QDialog, private Ui::preview
{ {
Q_OBJECT Q_OBJECT
@ -60,9 +60,8 @@ public:
signals: signals:
void readyToPreviewFile(QString) const; void readyToPreviewFile(QString) const;
protected slots: private slots:
void on_previewButton_clicked(); void previewButtonClicked();
void on_cancelButton_clicked();
private: private:
QStandardItemModel *m_previewListModel; QStandardItemModel *m_previewListModel;

23
src/gui/trackerlogin.cpp

@ -30,6 +30,7 @@
#include "trackerlogin.h" #include "trackerlogin.h"
#include <QPushButton>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
@ -39,24 +40,36 @@ trackerLogin::trackerLogin(QWidget *parent, BitTorrent::TorrentHandle *const tor
{ {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Log in"));
login_logo->setPixmap(QPixmap(QString::fromUtf8(":/icons/qbt-theme/encrypted.png"))); login_logo->setPixmap(QPixmap(QString::fromUtf8(":/icons/qbt-theme/encrypted.png")));
tracker_url->setText(torrent->currentTracker()); tracker_url->setText(torrent->currentTracker());
connect(this, SIGNAL(trackerLoginCancelled(QPair<BitTorrent::TorrentHandle*, QString>)), parent, SLOT(addUnauthenticatedTracker(QPair<BitTorrent::TorrentHandle*, QString>)));
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<BitTorrent::TorrentHandle*, QString>)), // TODO: use Qt5 connect syntax
parent, SLOT(addUnauthenticatedTracker(QPair<BitTorrent::TorrentHandle*, QString>)));
show(); show();
} }
trackerLogin::~trackerLogin() {} trackerLogin::~trackerLogin() {}
void trackerLogin::on_loginButton_clicked() { void trackerLogin::loginButtonClicked()
{
// login // login
#if LIBTORRENT_VERSION_NUM < 10100 #if LIBTORRENT_VERSION_NUM < 10100
m_torrent->setTrackerLogin(lineUsername->text(), linePasswd->text()); m_torrent->setTrackerLogin(lineUsername->text(), linePasswd->text());
#endif #endif
close(); accept();
} }
void trackerLogin::on_cancelButton_clicked() { void trackerLogin::cancelButtonClicked()
{
// Emit a signal to GUI to stop asking for authentication // Emit a signal to GUI to stop asking for authentication
emit trackerLoginCancelled(qMakePair(m_torrent, m_torrent->currentTracker())); emit trackerLoginCancelled(qMakePair(m_torrent, m_torrent->currentTracker()));
close(); reject();
} }

6
src/gui/trackerlogin.h

@ -53,9 +53,9 @@ class trackerLogin : public QDialog, private Ui::authentication{
signals: signals:
void trackerLoginCancelled(QPair<BitTorrent::TorrentHandle*, QString> tracker); void trackerLoginCancelled(QPair<BitTorrent::TorrentHandle*, QString> tracker);
public slots: private slots:
void on_loginButton_clicked(); void loginButtonClicked();
void on_cancelButton_clicked(); void cancelButtonClicked();
}; };
#endif #endif

Loading…
Cancel
Save