Merge pull request #7454 from Chocobo1/buttonbox

Replace dialog ok-cancel buttons with QDialogButtonBox
This commit is contained in:
Mike Tzou 2017-09-21 22:45:45 +08:00 committed by GitHub
commit 83c6b22d30
8 changed files with 75 additions and 208 deletions

View file

@ -31,23 +31,31 @@
#ifndef DOWNLOADFROMURL_H
#define DOWNLOADFROMURL_H
#include <QClipboard>
#include <QDialog>
#include <QMessageBox>
#include <QString>
#include <QPushButton>
#include <QRegExp>
#include <QString>
#include <QStringList>
#include <QClipboard>
#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();
}
};

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<width>501</width>
<height>220</height>
</rect>
</property>
@ -50,48 +50,14 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<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>
<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>
</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>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>

View file

@ -134,85 +134,19 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<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>
<item>
<widget class="QPushButton" name="loginButton">
<property name="text">
<string>Log in</string>
</property>
</widget>
</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>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<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>
<sender>lineUsername</sender>
<signal>returnPressed()</signal>

View file

@ -32,68 +32,17 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<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>
<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>
</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>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<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>
<connections/>
</ui>

View file

@ -31,6 +31,7 @@
#include <QFile>
#include <QHeaderView>
#include <QMessageBox>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
@ -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();
}

View file

@ -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;

View file

@ -30,6 +30,7 @@
#include "trackerlogin.h"
#include <QPushButton>
#include <libtorrent/version.hpp>
#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<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();
}
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();
}

View file

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