Move implementation to its own file

This commit is contained in:
Chocobo1 2019-07-17 21:57:52 +08:00
parent 1e70c52e7a
commit 07263d2d70
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
18 changed files with 535 additions and 290 deletions

View File

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

View File

@ -25,6 +25,7 @@ stacktrace {
HEADERS += $$PWD/stacktrace_win.h
!nogui {
HEADERS += $$PWD/stacktracedialog.h
SOURCES += $$PWD/stacktracedialog.cpp
FORMS += $$PWD/stacktracedialog.ui
}
}

View File

@ -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 <QString>
#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(
"<p align=center><b><font size=7 color=red>"
"qBittorrent has crashed"
"</font></b></p>"
"<font size=4><p>"
"Please file a bug report at "
"<a href=\"http://bugs.qbittorrent.org\">http://bugs.qbittorrent.org</a> "
"and provide the following information:"
"</p></font>"
"<br/><hr><br/>"
"<p align=center><font size=4>"
"qBittorrent version: " QBT_VERSION " (%1-bit)<br/>"
"Libtorrent version: %2<br/>"
"Qt version: " QT_VERSION_STR "<br/>"
"Boost version: %3<br/>"
"OpenSSL version: %4<br/>"
"zlib version: %5<br/>"
"OS version: %6<br/><br/>"
"Caught signal: %7"
"</font></p>"
"<pre><code>%8</code></pre>"
"<br/><hr><br/><br/>")
.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);
}

View File

@ -31,64 +31,22 @@
#define STACKTRACEDIALOG_H
#include <QDialog>
#include <QString>
#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);
}
explicit StacktraceDialog(QWidget *parent = nullptr);
~StacktraceDialog() override;
~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(
"<p align=center><b><font size=7 color=red>"
"qBittorrent has crashed"
"</font></b></p>"
"<font size=4><p>"
"Please file a bug report at "
"<a href=\"http://bugs.qbittorrent.org\">http://bugs.qbittorrent.org</a> "
"and provide the following information:"
"</p></font>"
"<br/><hr><br/>"
"<p align=center><font size=4>"
"qBittorrent version: " QBT_VERSION " (%1-bit)<br/>"
"Libtorrent version: %2<br/>"
"Qt version: " QT_VERSION_STR "<br/>"
"Boost version: %3<br/>"
"OpenSSL version: %4<br/>"
"zlib version: %5<br/>"
"OS version: %6<br/><br/>"
"Caught signal: %7"
"</font></p>"
"<pre><code>%8</code></pre>"
"<br/><hr><br/><br/>")
.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);
}
void setStacktraceString(const QString &sigName, const QString &trace);
private:
Ui::StacktraceDialog *m_ui;

View File

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

105
src/gui/aboutdialog.cpp Normal file
View File

@ -0,0 +1,105 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* 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 <QFile>
#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("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));
m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32));
// About
QString aboutText = QString(
"<p style=\"white-space: pre-wrap;\">"
"%1\n\n"
"%2\n\n"
"<table>"
"<tr><td>%3</td><td><a href=\"https://www.qbittorrent.org\">https://www.qbittorrent.org</a></td></tr>"
"<tr><td>%4</td><td><a href=\"http://forum.qbittorrent.org\">http://forum.qbittorrent.org</a></td></tr>"
"<tr><td>%5</td><td><a href=\"http://bugs.qbittorrent.org\">http://bugs.qbittorrent.org</a></td></tr>"
"</table>"
"</p>")
.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;
}

View File

@ -29,86 +29,21 @@
#ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H
#include <QFile>
#include <QDialog>
#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("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));
m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32));
// About
QString aboutText = QString(
"<p style=\"white-space: pre-wrap;\">"
"%1\n\n"
"%2\n\n"
"<table>"
"<tr><td>%3</td><td><a href=\"https://www.qbittorrent.org\">https://www.qbittorrent.org</a></td></tr>"
"<tr><td>%4</td><td><a href=\"http://forum.qbittorrent.org\">http://forum.qbittorrent.org</a></td></tr>"
"<tr><td>%5</td><td><a href=\"http://bugs.qbittorrent.org\">http://bugs.qbittorrent.org</a></td></tr>"
"</table>"
"</p>")
.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;

View File

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

View File

@ -0,0 +1,63 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* 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 <QTabBar>
#ifdef Q_OS_MAC
#include <QPaintEvent>
#include <QStyle>
#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

View File

@ -29,43 +29,24 @@
#ifndef HIDABLETABWIDGET_H
#define HIDABLETABWIDGET_H
#include <QTabBar>
#include <QTabWidget>
#ifdef Q_OS_MAC
#include <QStyle>
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

View File

@ -0,0 +1,90 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* 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 <QApplication>
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
#include <QProxyStyle>
#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<int>(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;
}

View File

@ -29,74 +29,19 @@
#ifndef PREVIEWLISTDELEGATE_H
#define PREVIEWLISTDELEGATE_H
#include <QApplication>
#include <QItemDelegate>
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
#include <QProxyStyle>
#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)
{
}
explicit PreviewListDelegate(QObject *parent = nullptr);
~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<int>(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();
}
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

View File

@ -17,6 +17,8 @@ trackersadditiondialog.h
# sources
downloadedpiecesbar.cpp
peerlistdelegate.cpp
peerlistsortmodel.cpp
peerlistwidget.cpp
peersadditiondialog.cpp
pieceavailabilitybar.cpp

View File

@ -0,0 +1,91 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* 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 <QPainter>
#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;
}

View File

@ -30,15 +30,11 @@
#define PEERLISTDELEGATE_H
#include <QItemDelegate>
#include <QPainter>
#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) {}
explicit PeerListDelegate(QObject *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);
}
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

View File

@ -0,0 +1,53 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 Nick Tiskov <daymansmail@gmail.com>
*
* 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);
};
}

View File

@ -31,34 +31,16 @@
#include <QSortFilterProxyModel>
#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

View File

@ -23,6 +23,8 @@ HEADERS += \
SOURCES += \
$$PWD/downloadedpiecesbar.cpp \
$$PWD/peerlistdelegate.cpp \
$$PWD/peerlistsortmodel.cpp \
$$PWD/peerlistwidget.cpp \
$$PWD/peersadditiondialog.cpp \
$$PWD/pieceavailabilitybar.cpp \