From f9e10616d09a9360a793a425de4a3a148d3daba3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 7 Mar 2019 15:31:50 +0800 Subject: [PATCH] Improve AdvancedSettings::addRow() 1. Add context to connect(). 2. Use QLabel in the left table cell, this allows using rich text formatting, such as HTML links. --- src/gui/advancedsettings.cpp | 23 +++++++++++------------ src/gui/advancedsettings.h | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 64fb4cfae..5cbcbe1c8 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -303,18 +303,14 @@ void AdvancedSettings::loadAdvancedSettings() const BitTorrent::Session *const session = BitTorrent::Session::instance(); // add section headers - QFont boldFont; - boldFont.setBold(true); - addRow(QBITTORRENT_HEADER, tr("qBittorrent Section"), &labelQbtLink); - item(QBITTORRENT_HEADER, PROPERTY)->setFont(boldFont); labelQbtLink.setText(QString("%2") .arg("https://github.com/qbittorrent/qBittorrent/wiki/Explanation-of-Options-in-qBittorrent#Advanced", tr("Open documentation"))); labelQbtLink.setOpenExternalLinks(true); + addRow(QBITTORRENT_HEADER, QString("%1").arg(tr("qBittorrent Section")), &labelQbtLink); - addRow(LIBTORRENT_HEADER, tr("libtorrent Section"), &labelLibtorrentLink); - item(LIBTORRENT_HEADER, PROPERTY)->setFont(boldFont); labelLibtorrentLink.setText(QString("%2").arg("https://www.libtorrent.org/reference.html", tr("Open documentation"))); labelLibtorrentLink.setOpenExternalLinks(true); + addRow(LIBTORRENT_HEADER, QString("%1").arg(tr("libtorrent Section")), &labelLibtorrentLink); // Async IO threads spinBoxAsyncIOThreads.setMinimum(1); @@ -523,17 +519,20 @@ void AdvancedSettings::loadAdvancedSettings() } template -void AdvancedSettings::addRow(int row, const QString &rowText, T *widget) +void AdvancedSettings::addRow(const int row, const QString &text, T *widget) { - setItem(row, PROPERTY, new QTableWidgetItem(rowText)); + auto label = new QLabel(text); + label->setOpenExternalLinks(true); + + setCellWidget(row, PROPERTY, label); setCellWidget(row, VALUE, widget); if (std::is_same::value) - connect(widget, SIGNAL(stateChanged(int)), SIGNAL(settingsChanged())); + connect(widget, SIGNAL(stateChanged(int)), this, SIGNAL(settingsChanged())); else if (std::is_same::value) - connect(widget, SIGNAL(valueChanged(int)), SIGNAL(settingsChanged())); + connect(widget, SIGNAL(valueChanged(int)), this, SIGNAL(settingsChanged())); else if (std::is_same::value) - connect(widget, SIGNAL(currentIndexChanged(int)), SIGNAL(settingsChanged())); + connect(widget, SIGNAL(currentIndexChanged(int)), this, SIGNAL(settingsChanged())); else if (std::is_same::value) - connect(widget, SIGNAL(textChanged(QString)), SIGNAL(settingsChanged())); + connect(widget, SIGNAL(textChanged(QString)), this, SIGNAL(settingsChanged())); } diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 15133ae42..4272e08c3 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -56,7 +56,7 @@ private slots: private: void loadAdvancedSettings(); - template void addRow(int row, const QString &rowText, T *widget); + template void addRow(int row, const QString &text, T *widget); QLabel labelQbtLink, labelLibtorrentLink; QSpinBox spinBoxAsyncIOThreads, spinBoxCheckingMemUsage, spinBoxCache, spinBoxSaveResumeDataInterval, spinBoxOutgoingPortsMin, spinBoxOutgoingPortsMax, spinBoxListRefresh, spinBoxMaxHalfOpen,