mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Follow project coding style. Issue #2192.
This commit is contained in:
parent
8e64ffba01
commit
f9c2bd3502
@ -78,33 +78,28 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
|
||||
|
||||
// case when calculated range is (15.2 >= x < 15.7)
|
||||
if (x2 == toCMinusOne) {
|
||||
if (vecin[x2]) {
|
||||
if (vecin[x2])
|
||||
value += ratio;
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
// case when (15.2 >= x < 17.8)
|
||||
else {
|
||||
// subcase (15.2 >= x < 16)
|
||||
if (x2 != fromR) {
|
||||
if (vecin[x2]) {
|
||||
if (vecin[x2])
|
||||
value += 1.0 - (fromR - fromC);
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
|
||||
// subcase (16 >= x < 17)
|
||||
for (; x2 < toCMinusOne; ++x2) {
|
||||
if (vecin[x2]) {
|
||||
for (; x2 < toCMinusOne; ++x2)
|
||||
if (vecin[x2])
|
||||
value += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
// subcase (17 >= x < 17.8)
|
||||
if (x2 == toCMinusOne) {
|
||||
if (vecin[x2]) {
|
||||
if (vecin[x2])
|
||||
value += 1.0 - (toC - toR);
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
}
|
||||
@ -121,7 +116,6 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int DownloadedPiecesBar::mixTwoColors(int &rgb1, int &rgb2, float ratio)
|
||||
{
|
||||
int r1 = qRed(rgb1);
|
||||
@ -160,12 +154,10 @@ void DownloadedPiecesBar::updateImage()
|
||||
QVector<float> scaled_pieces_dl = bitfieldToFloatVector(m_downloadedPieces, image2.width());
|
||||
|
||||
// filling image
|
||||
for (int x = 0; x < scaled_pieces.size(); ++x)
|
||||
{
|
||||
for (int x = 0; x < scaled_pieces.size(); ++x) {
|
||||
float pieces2_val = scaled_pieces.at(x);
|
||||
float pieces2_val_dl = scaled_pieces_dl.at(x);
|
||||
if (pieces2_val_dl != 0)
|
||||
{
|
||||
if (pieces2_val_dl != 0) {
|
||||
float fill_ratio = pieces2_val + pieces2_val_dl;
|
||||
float ratio = pieces2_val_dl / fill_ratio;
|
||||
|
||||
@ -174,8 +166,7 @@ void DownloadedPiecesBar::updateImage()
|
||||
|
||||
image2.setPixel(x, 0, mixedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
image2.setPixel(x, 0, m_pieceColors[pieces2_val * 255]);
|
||||
}
|
||||
}
|
||||
@ -210,13 +201,11 @@ void DownloadedPiecesBar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
QRect imageRect(1, 1, width() - 2, height() - 2);
|
||||
if (m_image.isNull())
|
||||
{
|
||||
if (m_image.isNull()) {
|
||||
painter.setBrush(Qt::white);
|
||||
painter.drawRect(imageRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
if (m_image.width() != imageRect.width())
|
||||
updateImage();
|
||||
painter.drawImage(imageRect, m_image);
|
||||
@ -239,5 +228,3 @@ void DownloadedPiecesBar::setColors(int background, int border, int complete, in
|
||||
updateImage();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include <QDebug>
|
||||
#include "pieceavailabilitybar.h"
|
||||
|
||||
|
||||
PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
|
@ -28,6 +28,8 @@
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#include "propertieswidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QListWidgetItem>
|
||||
@ -61,10 +63,10 @@
|
||||
#include "lineedit.h"
|
||||
#include "transferlistwidget.h"
|
||||
#include "autoexpandabledialog.h"
|
||||
#include "propertieswidget.h"
|
||||
|
||||
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList):
|
||||
QWidget(parent), transferList(transferList), main_window(main_window), m_torrent(0) {
|
||||
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *main_window, TransferListWidget *transferList)
|
||||
: QWidget(parent), transferList(transferList), main_window(main_window), m_torrent(0)
|
||||
{
|
||||
setupUi(this);
|
||||
setAutoFillBackground(true);
|
||||
|
||||
@ -168,7 +170,8 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
|
||||
connect(openHotkeyFile, SIGNAL(activated()), SLOT(openSelectedFile()));
|
||||
}
|
||||
|
||||
PropertiesWidget::~PropertiesWidget() {
|
||||
PropertiesWidget::~PropertiesWidget()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "ENTER";
|
||||
delete refreshTimer;
|
||||
delete trackerList;
|
||||
@ -186,7 +189,8 @@ PropertiesWidget::~PropertiesWidget() {
|
||||
qDebug() << Q_FUNC_INFO << "EXIT";
|
||||
}
|
||||
|
||||
void PropertiesWidget::showPiecesAvailability(bool show) {
|
||||
void PropertiesWidget::showPiecesAvailability(bool show)
|
||||
{
|
||||
avail_pieces_lbl->setVisible(show);
|
||||
pieces_availability->setVisible(show);
|
||||
avail_average_lbl->setVisible(show);
|
||||
@ -194,7 +198,8 @@ void PropertiesWidget::showPiecesAvailability(bool show) {
|
||||
line_2->setVisible(show);
|
||||
}
|
||||
|
||||
void PropertiesWidget::showPiecesDownloaded(bool show) {
|
||||
void PropertiesWidget::showPiecesDownloaded(bool show)
|
||||
{
|
||||
downloaded_pieces_lbl->setVisible(show);
|
||||
downloaded_pieces->setVisible(show);
|
||||
progress_lbl->setVisible(show);
|
||||
@ -202,8 +207,9 @@ void PropertiesWidget::showPiecesDownloaded(bool show) {
|
||||
line_2->setVisible(show);
|
||||
}
|
||||
|
||||
void PropertiesWidget::setVisibility(bool visible) {
|
||||
if (!visible && state == VISIBLE) {
|
||||
void PropertiesWidget::setVisibility(bool visible)
|
||||
{
|
||||
if (!visible && ( state == VISIBLE) ) {
|
||||
QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget());
|
||||
stackedProperties->setVisible(false);
|
||||
slideSizes = hSplitter->sizes();
|
||||
@ -215,7 +221,7 @@ void PropertiesWidget::setVisibility(bool visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (visible && state == REDUCED) {
|
||||
if (visible && ( state == REDUCED) ) {
|
||||
stackedProperties->setVisible(true);
|
||||
QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget());
|
||||
hSplitter->handle(1)->setDisabled(false);
|
||||
@ -227,7 +233,8 @@ void PropertiesWidget::setVisibility(bool visible) {
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::clear() {
|
||||
void PropertiesWidget::clear()
|
||||
{
|
||||
qDebug("Clearing torrent properties");
|
||||
save_path->clear();
|
||||
lbl_creationDate->clear();
|
||||
@ -271,10 +278,9 @@ BitTorrent::TorrentHandle *PropertiesWidget::getCurrentTorrent() const
|
||||
|
||||
void PropertiesWidget::updateSavePath(BitTorrent::TorrentHandle *const torrent)
|
||||
{
|
||||
if (m_torrent == torrent) {
|
||||
if (m_torrent == torrent)
|
||||
save_path->setText(Utils::Fs::toNativePath(m_torrent->savePath()));
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::loadTrackers(BitTorrent::TorrentHandle *const torrent)
|
||||
{
|
||||
@ -324,7 +330,8 @@ void PropertiesWidget::loadTorrentInfos(BitTorrent::TorrentHandle *const torrent
|
||||
loadDynamicData();
|
||||
}
|
||||
|
||||
void PropertiesWidget::readSettings() {
|
||||
void PropertiesWidget::readSettings()
|
||||
{
|
||||
const Preferences *const pref = Preferences::instance();
|
||||
// Restore splitter sizes
|
||||
QStringList sizes_str = pref->getPropSplitterSizes().split(",");
|
||||
@ -337,16 +344,15 @@ void PropertiesWidget::readSettings() {
|
||||
const int current_tab = pref->getPropCurTab();
|
||||
const bool visible = pref->getPropVisible();
|
||||
// the following will call saveSettings but shouldn't change any state
|
||||
if (!filesList->header()->restoreState(pref->getPropFileListState())) {
|
||||
if (!filesList->header()->restoreState(pref->getPropFileListState()))
|
||||
filesList->header()->resizeSection(0, 400); // Default
|
||||
}
|
||||
m_tabBar->setCurrentIndex(current_tab);
|
||||
if (!visible) {
|
||||
if (!visible)
|
||||
setVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::saveSettings() {
|
||||
void PropertiesWidget::saveSettings()
|
||||
{
|
||||
Preferences *const pref = Preferences::instance();
|
||||
pref->setPropVisible(state==VISIBLE);
|
||||
// Splitter sizes
|
||||
@ -357,21 +363,22 @@ void PropertiesWidget::saveSettings() {
|
||||
else
|
||||
sizes = slideSizes;
|
||||
qDebug("Sizes: %d", sizes.size());
|
||||
if (sizes.size() == 2) {
|
||||
if (sizes.size() == 2)
|
||||
pref->setPropSplitterSizes(QString::number(sizes.first()) + ',' + QString::number(sizes.last()));
|
||||
}
|
||||
pref->setPropFileListState(filesList->header()->saveState());
|
||||
// Remember current tab
|
||||
pref->setPropCurTab(m_tabBar->currentIndex());
|
||||
}
|
||||
|
||||
void PropertiesWidget::reloadPreferences() {
|
||||
void PropertiesWidget::reloadPreferences()
|
||||
{
|
||||
// Take program preferences into consideration
|
||||
peersList->updatePeerHostNameResolutionState();
|
||||
peersList->updatePeerCountryResolutionState();
|
||||
}
|
||||
|
||||
void PropertiesWidget::loadDynamicData() {
|
||||
void PropertiesWidget::loadDynamicData()
|
||||
{
|
||||
// Refresh only if the torrent handle is valid and if visible
|
||||
if (!m_torrent || (main_window->currentTabWidget() != transferList) || (state != VISIBLE)) return;
|
||||
|
||||
@ -490,7 +497,8 @@ void PropertiesWidget::loadDynamicData() {
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::loadUrlSeeds() {
|
||||
void PropertiesWidget::loadUrlSeeds()
|
||||
{
|
||||
listWebSeeds->clear();
|
||||
qDebug("Loading URL seeds");
|
||||
const QList<QUrl> hc_seeds = m_torrent->urlSeeds();
|
||||
@ -501,7 +509,8 @@ void PropertiesWidget::loadUrlSeeds() {
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) {
|
||||
void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index)
|
||||
{
|
||||
if (!index.isValid()) return;
|
||||
if (!m_torrent || !m_torrent->hasMetadata()) return;
|
||||
if (PropListModel->itemType(index) == TorrentContentModelItem::FileType)
|
||||
@ -510,7 +519,8 @@ void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) {
|
||||
openFolder(index, false);
|
||||
}
|
||||
|
||||
void PropertiesWidget::openFile(const QModelIndex &index) {
|
||||
void PropertiesWidget::openFile(const QModelIndex &index)
|
||||
{
|
||||
int i = PropListModel->getFileIndex(index);
|
||||
const QDir saveDir(m_torrent->savePath(true));
|
||||
const QString filename = m_torrent->filePath(i);
|
||||
@ -521,7 +531,8 @@ void PropertiesWidget::openFile(const QModelIndex &index) {
|
||||
Utils::Misc::openPath(file_path);
|
||||
}
|
||||
|
||||
void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_folder) {
|
||||
void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_folder)
|
||||
{
|
||||
QString absolute_path;
|
||||
// FOLDER
|
||||
if (PropListModel->itemType(index) == TorrentContentModelItem::FolderType) {
|
||||
@ -554,7 +565,8 @@ void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_fold
|
||||
Utils::Misc::openPath(absolute_path);
|
||||
}
|
||||
|
||||
void PropertiesWidget::displayFilesListMenu(const QPoint&) {
|
||||
void PropertiesWidget::displayFilesListMenu(const QPoint &)
|
||||
{
|
||||
if (!m_torrent) return;
|
||||
|
||||
QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0);
|
||||
@ -587,12 +599,15 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
|
||||
if (!index.isValid())
|
||||
return;
|
||||
if (act) {
|
||||
if (act == actOpen)
|
||||
if (act == actOpen) {
|
||||
openDoubleClickedFile(index);
|
||||
else if (act == actOpenContainingFolder)
|
||||
}
|
||||
else if (act == actOpenContainingFolder) {
|
||||
openFolder(index, true);
|
||||
else if (act == actRename)
|
||||
}
|
||||
else if (act == actRename) {
|
||||
renameSelectedFile();
|
||||
}
|
||||
else {
|
||||
int prio = prio::NORMAL;
|
||||
if (act == actionHigh)
|
||||
@ -613,7 +628,8 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::displayWebSeedListMenu(const QPoint&) {
|
||||
void PropertiesWidget::displayWebSeedListMenu(const QPoint &)
|
||||
{
|
||||
if (!m_torrent) return;
|
||||
|
||||
QMenu seedMenu;
|
||||
@ -643,7 +659,8 @@ void PropertiesWidget::displayWebSeedListMenu(const QPoint&) {
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::renameSelectedFile() {
|
||||
void PropertiesWidget::renameSelectedFile()
|
||||
{
|
||||
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
|
||||
if (selectedIndexes.size() != 1)
|
||||
return;
|
||||
@ -667,9 +684,8 @@ void PropertiesWidget::renameSelectedFile() {
|
||||
const int file_index = PropListModel->getFileIndex(index);
|
||||
if (!m_torrent || !m_torrent->hasMetadata()) return;
|
||||
QString old_name = m_torrent->filePath(file_index);
|
||||
if (old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
|
||||
if (old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB"))
|
||||
new_name_last += ".!qB";
|
||||
}
|
||||
QStringList path_items = old_name.split("/");
|
||||
path_items.removeLast();
|
||||
path_items << new_name_last;
|
||||
@ -763,14 +779,16 @@ void PropertiesWidget::renameSelectedFile() {
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::openSelectedFile() {
|
||||
void PropertiesWidget::openSelectedFile()
|
||||
{
|
||||
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
|
||||
if (selectedIndexes.size() != 1)
|
||||
return;
|
||||
openDoubleClickedFile(selectedIndexes.first());
|
||||
}
|
||||
|
||||
void PropertiesWidget::askWebSeed() {
|
||||
void PropertiesWidget::askWebSeed()
|
||||
{
|
||||
bool ok;
|
||||
// Ask user for a new url seed
|
||||
const QString url_seed = AutoExpandableDialog::getText(this, tr("New URL seed", "New HTTP source"),
|
||||
@ -790,7 +808,8 @@ void PropertiesWidget::askWebSeed() {
|
||||
loadUrlSeeds();
|
||||
}
|
||||
|
||||
void PropertiesWidget::deleteSelectedUrlSeeds() {
|
||||
void PropertiesWidget::deleteSelectedUrlSeeds()
|
||||
{
|
||||
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
||||
if (selectedItems.isEmpty()) return;
|
||||
|
||||
@ -803,7 +822,8 @@ void PropertiesWidget::deleteSelectedUrlSeeds() {
|
||||
loadUrlSeeds();
|
||||
}
|
||||
|
||||
void PropertiesWidget::copySelectedWebSeedsToClipboard() const {
|
||||
void PropertiesWidget::copySelectedWebSeedsToClipboard() const
|
||||
{
|
||||
const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems();
|
||||
if (selected_items.isEmpty())
|
||||
return;
|
||||
@ -815,7 +835,8 @@ void PropertiesWidget::copySelectedWebSeedsToClipboard() const {
|
||||
QApplication::clipboard()->setText(urls_to_copy.join("\n"));
|
||||
}
|
||||
|
||||
void PropertiesWidget::editWebSeed() {
|
||||
void PropertiesWidget::editWebSeed()
|
||||
{
|
||||
const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems();
|
||||
if (selected_items.size() != 1)
|
||||
return;
|
||||
@ -841,7 +862,8 @@ void PropertiesWidget::editWebSeed() {
|
||||
loadUrlSeeds();
|
||||
}
|
||||
|
||||
bool PropertiesWidget::applyPriorities() {
|
||||
bool PropertiesWidget::applyPriorities()
|
||||
{
|
||||
qDebug("Saving files priorities");
|
||||
const QVector<int> priorities = PropListModel->model()->getFilePriorities();
|
||||
// Prioritize the files
|
||||
@ -850,17 +872,20 @@ bool PropertiesWidget::applyPriorities() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void PropertiesWidget::filteredFilesChanged() {
|
||||
void PropertiesWidget::filteredFilesChanged()
|
||||
{
|
||||
if (m_torrent)
|
||||
applyPriorities();
|
||||
}
|
||||
|
||||
void PropertiesWidget::filterText(const QString& filter) {
|
||||
void PropertiesWidget::filterText(const QString &filter)
|
||||
{
|
||||
PropListModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive, QRegExp::WildcardUnix));
|
||||
if (filter.isEmpty()) {
|
||||
filesList->collapseAll();
|
||||
filesList->expand(PropListModel->index(0, 0));
|
||||
}
|
||||
else
|
||||
else {
|
||||
filesList->expandAll();
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ class QAction;
|
||||
class QTimer;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class PropertiesWidget : public QWidget, private Ui::PropertiesWidget {
|
||||
class PropertiesWidget: public QWidget, private Ui::PropertiesWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PropertiesWidget)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user