From 07263d2d7066af7ce1cb2689d1e71f41e4f484b7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 17 Jul 2019 21:57:52 +0800 Subject: [PATCH] Move implementation to its own file --- src/app/CMakeLists.txt | 2 +- src/app/app.pri | 1 + src/app/stacktracedialog.cpp | 84 ++++++++++++++++++ src/app/stacktracedialog.h | 58 ++----------- src/gui/CMakeLists.txt | 3 + src/gui/aboutdialog.cpp | 105 +++++++++++++++++++++++ src/gui/aboutdialog.h | 81 ++--------------- src/gui/gui.pri | 3 + src/gui/hidabletabwidget.cpp | 63 ++++++++++++++ src/gui/hidabletabwidget.h | 33 ++----- src/gui/previewlistdelegate.cpp | 90 +++++++++++++++++++ src/gui/previewlistdelegate.h | 65 ++------------ src/gui/properties/CMakeLists.txt | 2 + src/gui/properties/peerlistdelegate.cpp | 91 ++++++++++++++++++++ src/gui/properties/peerlistdelegate.h | 63 ++------------ src/gui/properties/peerlistsortmodel.cpp | 53 ++++++++++++ src/gui/properties/peerlistsortmodel.h | 26 +----- src/gui/properties/properties.pri | 2 + 18 files changed, 535 insertions(+), 290 deletions(-) create mode 100644 src/app/stacktracedialog.cpp create mode 100644 src/gui/aboutdialog.cpp create mode 100644 src/gui/hidabletabwidget.cpp create mode 100644 src/gui/previewlistdelegate.cpp create mode 100644 src/gui/properties/peerlistdelegate.cpp create mode 100644 src/gui/properties/peerlistsortmodel.cpp diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index db123eca4..8b548586e 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -65,7 +65,7 @@ if (STACKTRACE) else (UNIX) target_sources(qBittorrent PRIVATE stacktrace_win.h) if (Qt5Widgets_FOUND) - target_sources(qBittorrent PRIVATE stacktracedialog.h) + target_sources(qBittorrent PRIVATE stacktracedialog.cpp stacktracedialog.h) endif (Qt5Widgets_FOUND) endif (UNIX) endif (STACKTRACE) diff --git a/src/app/app.pri b/src/app/app.pri index 64287241c..14db0a17d 100644 --- a/src/app/app.pri +++ b/src/app/app.pri @@ -25,6 +25,7 @@ stacktrace { HEADERS += $$PWD/stacktrace_win.h !nogui { HEADERS += $$PWD/stacktracedialog.h + SOURCES += $$PWD/stacktracedialog.cpp FORMS += $$PWD/stacktracedialog.ui } } diff --git a/src/app/stacktracedialog.cpp b/src/app/stacktracedialog.cpp new file mode 100644 index 000000000..00be4a4db --- /dev/null +++ b/src/app/stacktracedialog.cpp @@ -0,0 +1,84 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2015 The qBittorrent project + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + * + */ + +#include "stacktracedialog.h" + +#include + +#include "base/utils/misc.h" +#include "ui_stacktracedialog.h" + +StacktraceDialog::StacktraceDialog(QWidget *parent) + : QDialog(parent) + , m_ui(new Ui::StacktraceDialog) +{ + m_ui->setupUi(this); +} + +StacktraceDialog::~StacktraceDialog() +{ + delete m_ui; +} + +void StacktraceDialog::setStacktraceString(const QString &sigName, const QString &trace) +{ + // try to call Qt function as less as possible + const QString htmlStr = QString( + "

" + "qBittorrent has crashed" + "

" + "

" + "Please file a bug report at " + "http://bugs.qbittorrent.org " + "and provide the following information:" + "

" + "


" + "

" + "qBittorrent version: " QBT_VERSION " (%1-bit)
" + "Libtorrent version: %2
" + "Qt version: " QT_VERSION_STR "
" + "Boost version: %3
" + "OpenSSL version: %4
" + "zlib version: %5
" + "OS version: %6

" + "Caught signal: %7" + "

" + "
%8
" + "



") + .arg(QString::number(QT_POINTER_SIZE * 8) + , Utils::Misc::libtorrentVersionString() + , Utils::Misc::boostVersionString() + , Utils::Misc::opensslVersionString() + , Utils::Misc::zlibVersionString() + , Utils::Misc::osName() + , sigName + , trace); + + m_ui->errorText->setHtml(htmlStr); +} diff --git a/src/app/stacktracedialog.h b/src/app/stacktracedialog.h index 96292093f..0a7f3db19 100644 --- a/src/app/stacktracedialog.h +++ b/src/app/stacktracedialog.h @@ -31,64 +31,22 @@ #define STACKTRACEDIALOG_H #include -#include -#include "base/utils/misc.h" -#include "ui_stacktracedialog.h" +namespace Ui +{ + class StacktraceDialog; +} class StacktraceDialog : public QDialog { Q_OBJECT + Q_DISABLE_COPY(StacktraceDialog) public: - StacktraceDialog(QWidget *parent = nullptr) - : QDialog(parent) - , m_ui(new Ui::StacktraceDialog) - { - m_ui->setupUi(this); - } - - ~StacktraceDialog() - { - delete m_ui; - } - - void setStacktraceString(const QString &sigName, const QString &trace) - { - // try to call Qt function as less as possible - const QString htmlStr = QString( - "

" - "qBittorrent has crashed" - "

" - "

" - "Please file a bug report at " - "http://bugs.qbittorrent.org " - "and provide the following information:" - "

" - "


" - "

" - "qBittorrent version: " QBT_VERSION " (%1-bit)
" - "Libtorrent version: %2
" - "Qt version: " QT_VERSION_STR "
" - "Boost version: %3
" - "OpenSSL version: %4
" - "zlib version: %5
" - "OS version: %6

" - "Caught signal: %7" - "

" - "
%8
" - "



") - .arg(QString::number(QT_POINTER_SIZE * 8) - , Utils::Misc::libtorrentVersionString() - , Utils::Misc::boostVersionString() - , Utils::Misc::opensslVersionString() - , Utils::Misc::zlibVersionString() - , Utils::Misc::osName() - , sigName - , trace); + explicit StacktraceDialog(QWidget *parent = nullptr); + ~StacktraceDialog() override; - m_ui->errorText->setHtml(htmlStr); - } + void setStacktraceString(const QString &sigName, const QString &trace); private: Ui::StacktraceDialog *m_ui; diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index e2b6d89d5..cea242ac6 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -64,6 +64,7 @@ updownratiodialog.h utils.h # sources +aboutdialog.cpp addnewtorrentdialog.cpp advancedsettings.cpp autoexpandabledialog.cpp @@ -77,11 +78,13 @@ downloadfromurldialog.cpp executionlogwidget.cpp fspathedit.cpp fspathedit_p.cpp +hidabletabwidget.cpp ipsubnetwhitelistoptionsdialog.cpp lineedit.cpp loglistwidget.cpp mainwindow.cpp optionsdialog.cpp +previewlistdelegate.cpp previewselectdialog.cpp private/tristatewidget.cpp raisedmessagebox.cpp diff --git a/src/gui/aboutdialog.cpp b/src/gui/aboutdialog.cpp new file mode 100644 index 000000000..5d1c3b7eb --- /dev/null +++ b/src/gui/aboutdialog.cpp @@ -0,0 +1,105 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "aboutdialog.h" + +#include + +#include "base/unicodestrings.h" +#include "base/utils/misc.h" +#include "ui_aboutdialog.h" +#include "utils.h" + +AboutDialog::AboutDialog(QWidget *parent) + : QDialog(parent) + , m_ui(new Ui::AboutDialog) +{ + m_ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + // Title + m_ui->labelName->setText(QString("

qBittorrent " QBT_VERSION " (%1-bit)

").arg(QT_POINTER_SIZE * 8)); + + m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32)); + + // About + QString aboutText = QString( + "

" + "%1\n\n" + "%2\n\n" + "" + "" + "" + "" + "
%3https://www.qbittorrent.org
%4http://forum.qbittorrent.org
%5http://bugs.qbittorrent.org
" + "

") + .arg(tr("An advanced BitTorrent client programmed in C++, based on Qt toolkit and libtorrent-rasterbar.") + , tr("Copyright %1 2006-2019 The qBittorrent project").arg(QString::fromUtf8(C_COPYRIGHT)) + , tr("Home Page:") + , tr("Forum:") + , tr("Bug Tracker:")); + m_ui->labelAbout->setText(aboutText); + + m_ui->labelMascot->setPixmap(Utils::Gui::scaledPixmap(":/icons/skin/mascot.png", this)); + + // Thanks + QFile thanksfile(":/thanks.html"); + if (thanksfile.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_ui->textBrowserThanks->setHtml(QString::fromUtf8(thanksfile.readAll().constData())); + thanksfile.close(); + } + + // Translation + QFile translatorsfile(":/translators.html"); + if (translatorsfile.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_ui->textBrowserTranslation->setHtml(QString::fromUtf8(translatorsfile.readAll().constData())); + translatorsfile.close(); + } + + // License + QFile licensefile(":/gpl.html"); + if (licensefile.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_ui->textBrowserLicense->setHtml(QString::fromUtf8(licensefile.readAll().constData())); + licensefile.close(); + } + + // Libraries + m_ui->labelQtVer->setText(QT_VERSION_STR); + m_ui->labelLibtVer->setText(Utils::Misc::libtorrentVersionString()); + m_ui->labelBoostVer->setText(Utils::Misc::boostVersionString()); + m_ui->labelOpensslVer->setText(Utils::Misc::opensslVersionString()); + m_ui->labelZlibVer->setText(Utils::Misc::zlibVersionString()); + + Utils::Gui::resize(this); + show(); +} + +AboutDialog::~AboutDialog() +{ + delete m_ui; +} diff --git a/src/gui/aboutdialog.h b/src/gui/aboutdialog.h index a41bc9a02..7aef6920e 100644 --- a/src/gui/aboutdialog.h +++ b/src/gui/aboutdialog.h @@ -29,86 +29,21 @@ #ifndef ABOUTDIALOG_H #define ABOUTDIALOG_H -#include +#include -#include "base/unicodestrings.h" -#include "base/utils/misc.h" -#include "ui_aboutdialog.h" -#include "utils.h" +namespace Ui +{ + class AboutDialog; +} class AboutDialog : public QDialog { Q_OBJECT + Q_DISABLE_COPY(AboutDialog) public: - AboutDialog(QWidget *parent) - : QDialog(parent) - , m_ui(new Ui::AboutDialog) - { - m_ui->setupUi(this); - setAttribute(Qt::WA_DeleteOnClose); - - // Title - m_ui->labelName->setText(QString("

qBittorrent " QBT_VERSION " (%1-bit)

").arg(QT_POINTER_SIZE * 8)); - - m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32)); - - // About - QString aboutText = QString( - "

" - "%1\n\n" - "%2\n\n" - "" - "" - "" - "" - "
%3https://www.qbittorrent.org
%4http://forum.qbittorrent.org
%5http://bugs.qbittorrent.org
" - "

") - .arg(tr("An advanced BitTorrent client programmed in C++, based on Qt toolkit and libtorrent-rasterbar.") - , tr("Copyright %1 2006-2019 The qBittorrent project").arg(QString::fromUtf8(C_COPYRIGHT)) - , tr("Home Page:") - , tr("Forum:") - , tr("Bug Tracker:")); - m_ui->labelAbout->setText(aboutText); - - m_ui->labelMascot->setPixmap(Utils::Gui::scaledPixmap(":/icons/skin/mascot.png", this)); - - // Thanks - QFile thanksfile(":/thanks.html"); - if (thanksfile.open(QIODevice::ReadOnly | QIODevice::Text)) { - m_ui->textBrowserThanks->setHtml(QString::fromUtf8(thanksfile.readAll().constData())); - thanksfile.close(); - } - - // Translation - QFile translatorsfile(":/translators.html"); - if (translatorsfile.open(QIODevice::ReadOnly | QIODevice::Text)) { - m_ui->textBrowserTranslation->setHtml(QString::fromUtf8(translatorsfile.readAll().constData())); - translatorsfile.close(); - } - - // License - QFile licensefile(":/gpl.html"); - if (licensefile.open(QIODevice::ReadOnly | QIODevice::Text)) { - m_ui->textBrowserLicense->setHtml(QString::fromUtf8(licensefile.readAll().constData())); - licensefile.close(); - } - - // Libraries - m_ui->labelQtVer->setText(QT_VERSION_STR); - m_ui->labelLibtVer->setText(Utils::Misc::libtorrentVersionString()); - m_ui->labelBoostVer->setText(Utils::Misc::boostVersionString()); - m_ui->labelOpensslVer->setText(Utils::Misc::opensslVersionString()); - m_ui->labelZlibVer->setText(Utils::Misc::zlibVersionString()); - - Utils::Gui::resize(this); - show(); - } - - ~AboutDialog() - { - delete m_ui; - } + explicit AboutDialog(QWidget *parent); + ~AboutDialog() override; private: Ui::AboutDialog *m_ui; diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 7ef160d42..ea1d09ea3 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -69,6 +69,7 @@ HEADERS += \ $$PWD/utils.h SOURCES += \ + $$PWD/aboutdialog.cpp \ $$PWD/addnewtorrentdialog.cpp \ $$PWD/advancedsettings.cpp \ $$PWD/autoexpandabledialog.cpp \ @@ -82,11 +83,13 @@ SOURCES += \ $$PWD/executionlogwidget.cpp \ $$PWD/fspathedit.cpp \ $$PWD/fspathedit_p.cpp \ + $$PWD/hidabletabwidget.cpp \ $$PWD/ipsubnetwhitelistoptionsdialog.cpp \ $$PWD/lineedit.cpp \ $$PWD/loglistwidget.cpp \ $$PWD/mainwindow.cpp \ $$PWD/optionsdialog.cpp \ + $$PWD/previewlistdelegate.cpp \ $$PWD/previewselectdialog.cpp \ $$PWD/private/tristatewidget.cpp \ $$PWD/raisedmessagebox.cpp \ diff --git a/src/gui/hidabletabwidget.cpp b/src/gui/hidabletabwidget.cpp new file mode 100644 index 000000000..f2bec36f8 --- /dev/null +++ b/src/gui/hidabletabwidget.cpp @@ -0,0 +1,63 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "hidabletabwidget.h" + +#include + +#ifdef Q_OS_MAC +#include +#include +#endif + +HidableTabWidget::HidableTabWidget(QWidget *parent) + : QTabWidget(parent) +{ +} + +void HidableTabWidget::tabInserted(const int index) +{ + QTabWidget::tabInserted(index); + tabBar()->setVisible(count() != 1); +} + +void HidableTabWidget::tabRemoved(const int index) +{ + //QTabWidget::tabInserted(index); + QTabWidget::tabRemoved(index); + tabBar()->setVisible(count() != 1); +} + +#ifdef Q_OS_MAC +void HidableTabWidget::paintEvent(QPaintEvent *event) +{ + // Hide the pane for macintosh style + if (!style()->inherits("QMacStyle")) + QTabWidget::paintEvent(event); +} +#endif diff --git a/src/gui/hidabletabwidget.h b/src/gui/hidabletabwidget.h index 2b2860a56..a614dbd2a 100644 --- a/src/gui/hidabletabwidget.h +++ b/src/gui/hidabletabwidget.h @@ -29,43 +29,24 @@ #ifndef HIDABLETABWIDGET_H #define HIDABLETABWIDGET_H -#include #include #ifdef Q_OS_MAC -#include +class QPaintEvent; #endif class HidableTabWidget : public QTabWidget { public: - explicit HidableTabWidget(QWidget *parent = nullptr) - : QTabWidget(parent) - { - } + explicit HidableTabWidget(QWidget *parent = nullptr); + +private: + void tabInserted(int index) override; + void tabRemoved(int index) override; -protected: #ifdef Q_OS_MAC - void paintEvent(QPaintEvent *event) override - { - // Hide the pane for macintosh style - if (!style()->inherits("QMacStyle")) - QTabWidget::paintEvent(event); - } + void paintEvent(QPaintEvent *event) override; #endif - - void tabInserted(int index) override - { - QTabWidget::tabInserted(index); - tabBar()->setVisible(count() != 1); - } - - void tabRemoved(int index) override - { - //QTabWidget::tabInserted(index); - QTabWidget::tabRemoved(index); - tabBar()->setVisible(count() != 1); - } }; #endif // HIDABLETABWIDGET_H diff --git a/src/gui/previewlistdelegate.cpp b/src/gui/previewlistdelegate.cpp new file mode 100644 index 000000000..9371da34d --- /dev/null +++ b/src/gui/previewlistdelegate.cpp @@ -0,0 +1,90 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "previewlistdelegate.h" + +#include +#include +#include +#include +#include + +#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) +#include +#endif + +#include "base/utils/misc.h" +#include "base/utils/string.h" +#include "previewselectdialog.h" + +PreviewListDelegate::PreviewListDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} + +void PreviewListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + painter->save(); + QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); + + switch (index.column()) { + case PreviewSelectDialog::SIZE: + QItemDelegate::drawBackground(painter, opt, index); + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); + break; + case PreviewSelectDialog::PROGRESS: { + QStyleOptionProgressBar newopt; + qreal progress = index.data().toDouble() * 100.; + newopt.rect = opt.rect; + newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%'); + newopt.progress = static_cast(progress); + newopt.maximum = 100; + newopt.minimum = 0; + newopt.state |= QStyle::State_Enabled; + newopt.textVisible = true; +#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) + // XXX: To avoid having the progress text on the right of the bar + QProxyStyle st("fusion"); + st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); +#else + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); +#endif + } + break; + default: + QItemDelegate::paint(painter, option, index); + } + + painter->restore(); +} + +QWidget *PreviewListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const +{ + // No editor here + return nullptr; +} diff --git a/src/gui/previewlistdelegate.h b/src/gui/previewlistdelegate.h index e15b857d3..f70c77d06 100644 --- a/src/gui/previewlistdelegate.h +++ b/src/gui/previewlistdelegate.h @@ -29,74 +29,19 @@ #ifndef PREVIEWLISTDELEGATE_H #define PREVIEWLISTDELEGATE_H -#include #include -#include -#include -#include -#include - -#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) -#include -#endif - -#include "base/utils/misc.h" -#include "base/utils/string.h" -#include "previewselectdialog.h" class PreviewListDelegate : public QItemDelegate { Q_OBJECT + Q_DISABLE_COPY(PreviewListDelegate) public: - PreviewListDelegate(QObject *parent = nullptr) - : QItemDelegate(parent) - { - } - - ~PreviewListDelegate() {} - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const - { - painter->save(); - QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); - - switch (index.column()) { - case PreviewSelectDialog::SIZE: - QItemDelegate::drawBackground(painter, opt, index); - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); - break; - case PreviewSelectDialog::PROGRESS: { - QStyleOptionProgressBar newopt; - qreal progress = index.data().toDouble() * 100.; - newopt.rect = opt.rect; - newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%'); - newopt.progress = static_cast(progress); - newopt.maximum = 100; - newopt.minimum = 0; - newopt.state |= QStyle::State_Enabled; - newopt.textVisible = true; -#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS) - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); -#else - // XXX: To avoid having the progress text on the right of the bar - QProxyStyle st("fusion"); - st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); -#endif - } - break; - default: - QItemDelegate::paint(painter, option, index); - } - - painter->restore(); - } + explicit PreviewListDelegate(QObject *parent = nullptr); - QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const - { - // No editor here - return nullptr; - } +private: + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override; }; #endif // PREVIEWLISTDELEGATE_H diff --git a/src/gui/properties/CMakeLists.txt b/src/gui/properties/CMakeLists.txt index b4c87dbfe..a778e3a3c 100644 --- a/src/gui/properties/CMakeLists.txt +++ b/src/gui/properties/CMakeLists.txt @@ -17,6 +17,8 @@ trackersadditiondialog.h # sources downloadedpiecesbar.cpp +peerlistdelegate.cpp +peerlistsortmodel.cpp peerlistwidget.cpp peersadditiondialog.cpp pieceavailabilitybar.cpp diff --git a/src/gui/properties/peerlistdelegate.cpp b/src/gui/properties/peerlistdelegate.cpp new file mode 100644 index 000000000..b1b3b9ef5 --- /dev/null +++ b/src/gui/properties/peerlistdelegate.cpp @@ -0,0 +1,91 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "peerlistdelegate.h" + +#include + +#include "base/preferences.h" +#include "base/utils/misc.h" +#include "base/utils/string.h" + +PeerListDelegate::PeerListDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} + +void PeerListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + painter->save(); + + const bool hideValues = Preferences::instance()->getHideZeroValues(); + QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); + QItemDelegate::drawBackground(painter, opt, index); + + switch (index.column()) { + case PORT: + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); + break; + case TOT_DOWN: + case TOT_UP: { + qlonglong size = index.data().toLongLong(); + if (hideValues && (size <= 0)) + break; + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); + } + break; + case DOWN_SPEED: + case UP_SPEED: { + qreal speed = index.data().toDouble(); + if (speed <= 0.0) + break; + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); + } + break; + case PROGRESS: + case RELEVANCE: { + qreal progress = index.data().toDouble(); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + '%'); + } + break; + default: + QItemDelegate::paint(painter, option, index); + } + + painter->restore(); +} + +QWidget *PeerListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const +{ + // No editor here + return nullptr; +} diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index e0baca12c..bf3bacd7a 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -30,15 +30,11 @@ #define PEERLISTDELEGATE_H #include -#include - -#include "base/preferences.h" -#include "base/utils/misc.h" -#include "base/utils/string.h" class PeerListDelegate : public QItemDelegate { Q_OBJECT + Q_DISABLE_COPY(PeerListDelegate) public: enum PeerListColumns @@ -61,60 +57,11 @@ public: COL_COUNT }; - PeerListDelegate(QObject *parent) : QItemDelegate(parent) {} - - ~PeerListDelegate() override {} - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override - { - painter->save(); - - const bool hideValues = Preferences::instance()->getHideZeroValues(); - QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); - QItemDelegate::drawBackground(painter, opt, index); - - switch (index.column()) { - case PORT: - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); - break; - case TOT_DOWN: - case TOT_UP: { - qlonglong size = index.data().toLongLong(); - if (hideValues && (size <= 0)) - break; - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); - } - break; - case DOWN_SPEED: - case UP_SPEED: { - qreal speed = index.data().toDouble(); - if (speed <= 0.0) - break; - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); - } - break; - case PROGRESS: - case RELEVANCE: { - qreal progress = index.data().toDouble(); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + '%'); - } - break; - default: - QItemDelegate::paint(painter, option, index); - } + explicit PeerListDelegate(QObject *parent); - painter->restore(); - } - - QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override - { - // No editor here - return nullptr; - } +private: + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override; }; #endif // PEERLISTDELEGATE_H diff --git a/src/gui/properties/peerlistsortmodel.cpp b/src/gui/properties/peerlistsortmodel.cpp new file mode 100644 index 000000000..78a2f9c31 --- /dev/null +++ b/src/gui/properties/peerlistsortmodel.cpp @@ -0,0 +1,53 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2013 Nick Tiskov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "peerlistsortmodel.h" + +#include "base/utils/string.h" +#include "peerlistdelegate.h" + +PeerListSortModel::PeerListSortModel(QObject *parent) + : QSortFilterProxyModel(parent) +{ +} + +bool PeerListSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +{ + switch (sortColumn()) { + case PeerListDelegate::IP: + case PeerListDelegate::CLIENT: { + const QString strL = left.data().toString(); + const QString strR = right.data().toString(); + const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive); + return (result < 0); + } + break; + default: + return QSortFilterProxyModel::lessThan(left, right); + }; +} diff --git a/src/gui/properties/peerlistsortmodel.h b/src/gui/properties/peerlistsortmodel.h index 8cd8b3f9f..d454572bc 100644 --- a/src/gui/properties/peerlistsortmodel.h +++ b/src/gui/properties/peerlistsortmodel.h @@ -31,34 +31,16 @@ #include -#include "peerlistdelegate.h" - class PeerListSortModel : public QSortFilterProxyModel { Q_OBJECT + Q_DISABLE_COPY(PeerListSortModel) public: - PeerListSortModel(QObject *parent = nullptr) - : QSortFilterProxyModel(parent) - { - } + explicit PeerListSortModel(QObject *parent = nullptr); -protected: - bool lessThan(const QModelIndex &left, const QModelIndex &right) const - { - switch (sortColumn()) { - case PeerListDelegate::IP: - case PeerListDelegate::CLIENT: { - const QString strL = left.data().toString(); - const QString strR = right.data().toString(); - const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive); - return (result < 0); - } - break; - default: - return QSortFilterProxyModel::lessThan(left, right); - }; - } +private: + bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; }; #endif // PEERLISTSORTMODEL_H diff --git a/src/gui/properties/properties.pri b/src/gui/properties/properties.pri index d2c7dbec9..ac565e6ed 100644 --- a/src/gui/properties/properties.pri +++ b/src/gui/properties/properties.pri @@ -23,6 +23,8 @@ HEADERS += \ SOURCES += \ $$PWD/downloadedpiecesbar.cpp \ + $$PWD/peerlistdelegate.cpp \ + $$PWD/peerlistsortmodel.cpp \ $$PWD/peerlistwidget.cpp \ $$PWD/peersadditiondialog.cpp \ $$PWD/pieceavailabilitybar.cpp \