mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
Fix side panel resizing of elements.
This commit is contained in:
parent
f0d5ce4b98
commit
a85b6df314
@ -51,28 +51,52 @@
|
|||||||
#include "downloadthread.h"
|
#include "downloadthread.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
LabelFiltersList::LabelFiltersList(QWidget *parent): QListWidget(parent)
|
FiltersBase::FiltersBase(QWidget *parent)
|
||||||
|
: QListWidget(parent)
|
||||||
{
|
{
|
||||||
itemHover = 0;
|
|
||||||
// Accept drop
|
|
||||||
setAcceptDrops(true);
|
|
||||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
|
||||||
setStyleSheet("QListWidget { background: transparent; border: 0 }");
|
setStyleSheet("QListWidget { background: transparent; border: 0 }");
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSize FiltersBase::sizeHint() const
|
||||||
|
{
|
||||||
|
QSize size = QListWidget::sizeHint();
|
||||||
|
// Height should be exactly the height of the content
|
||||||
|
size.setHeight((sizeHintForRow(0) * count()) + (2 * frameWidth()) + 6);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize FiltersBase::minimumSizeHint() const
|
||||||
|
{
|
||||||
|
QSize size = QListWidget::minimumSizeHint();
|
||||||
|
// Minimum height should be exactly the sticky labels height
|
||||||
|
size.setHeight((sizeHintForRow(0) * 2) + (2 * frameWidth()) + 6);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
LabelFiltersList::LabelFiltersList(QWidget *parent)
|
||||||
|
: FiltersBase(parent)
|
||||||
|
{
|
||||||
|
itemHover = 0;
|
||||||
|
// Accept drop
|
||||||
|
setAcceptDrops(true);
|
||||||
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
|
}
|
||||||
|
|
||||||
void LabelFiltersList::addItem(QListWidgetItem *it)
|
void LabelFiltersList::addItem(QListWidgetItem *it)
|
||||||
{
|
{
|
||||||
Q_ASSERT(count() >= 2);
|
Q_ASSERT(count() >= 2);
|
||||||
for (int i = 2; i<count(); ++i) {
|
for (int i = 2; i<count(); ++i) {
|
||||||
if (item(i)->text().localeAwareCompare(it->text()) >= 0) {
|
if (item(i)->text().localeAwareCompare(it->text()) >= 0) {
|
||||||
insertItem(i, it);
|
insertItem(i, it);
|
||||||
|
updateGeometry();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QListWidget::addItem(it);
|
QListWidget::addItem(it);
|
||||||
|
updateGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LabelFiltersList::labelFromRow(int row) const
|
QString LabelFiltersList::labelFromRow(int row) const
|
||||||
@ -150,33 +174,21 @@ void LabelFiltersList::setItemHover(bool hover)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusFiltersWidget::StatusFiltersWidget(QWidget *parent): QListWidget(parent), m_shown(false)
|
StatusFiltersWidget::StatusFiltersWidget(QWidget *parent)
|
||||||
|
: FiltersBase(parent)
|
||||||
|
, m_shown(false)
|
||||||
{
|
{
|
||||||
setUniformItemSizes(true);
|
setUniformItemSizes(true);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
// Height is fixed (sizeHint().height() is used)
|
// Height is fixed (sizeHint().height() is used)
|
||||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||||
setStyleSheet("QListWidget { background: transparent; border: 0 }");
|
|
||||||
#if defined(Q_OS_MAC)
|
|
||||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize StatusFiltersWidget::sizeHint() const
|
TrackerFiltersList::TrackerFiltersList(QWidget *parent)
|
||||||
{
|
: FiltersBase(parent)
|
||||||
QSize size = QListWidget::sizeHint();
|
, m_downloader(new DownloadThread(this))
|
||||||
// Height should be exactly the height of the content
|
|
||||||
size.setHeight(contentsSize().height() + 2 * frameWidth() + 6);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
TrackerFiltersList::TrackerFiltersList(QWidget *parent): QListWidget(parent), m_downloader(new DownloadThread(this))
|
|
||||||
{
|
{
|
||||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||||
setStyleSheet("QListWidget { background: transparent; border: 0 }");
|
|
||||||
#if defined(Q_OS_MAC)
|
|
||||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
||||||
#endif
|
|
||||||
QListWidgetItem *allTrackers = new QListWidgetItem(this);
|
QListWidgetItem *allTrackers = new QListWidgetItem(this);
|
||||||
allTrackers->setData(Qt::DisplayRole, QVariant(tr("All trackers (0)")));
|
allTrackers->setData(Qt::DisplayRole, QVariant(tr("All trackers (0)")));
|
||||||
allTrackers->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server"));
|
allTrackers->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server"));
|
||||||
@ -387,7 +399,7 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
|
|||||||
QFont font;
|
QFont font;
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
font.setCapitalization(QFont::SmallCaps);
|
font.setCapitalization(QFont::SmallCaps);
|
||||||
QLabel *torrentsLabel = new QLabel(tr("Torrents"));
|
torrentsLabel = new QLabel(tr("Torrents"));
|
||||||
torrentsLabel->setIndent(2);
|
torrentsLabel->setIndent(2);
|
||||||
torrentsLabel->setFont(font);
|
torrentsLabel->setFont(font);
|
||||||
vLayout->addWidget(torrentsLabel);
|
vLayout->addWidget(torrentsLabel);
|
||||||
@ -478,6 +490,13 @@ TransferListFiltersWidget::~TransferListFiltersWidget()
|
|||||||
delete vLayout;
|
delete vLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransferListFiltersWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
int height = event->size().height();
|
||||||
|
int minHeight = statusFilters->height() + (3 * torrentsLabel->height());
|
||||||
|
trackerFilters->setMinimumHeight((height - minHeight) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
StatusFiltersWidget* TransferListFiltersWidget::getStatusFilters() const
|
StatusFiltersWidget* TransferListFiltersWidget::getStatusFilters() const
|
||||||
{
|
{
|
||||||
return statusFilters;
|
return statusFilters;
|
||||||
@ -639,6 +658,7 @@ void TransferListFiltersWidget::removeSelectedLabel()
|
|||||||
applyLabelFilter(0);
|
applyLabelFilter(0);
|
||||||
// Un display filter
|
// Un display filter
|
||||||
delete labelFilters->takeItem(row);
|
delete labelFilters->takeItem(row);
|
||||||
|
labelFilters->updateGeometry();
|
||||||
// Save custom labels to remember it was deleted
|
// Save custom labels to remember it was deleted
|
||||||
Preferences::instance()->removeTorrentLabel(label);
|
Preferences::instance()->removeTorrentLabel(label);
|
||||||
}
|
}
|
||||||
@ -655,6 +675,8 @@ void TransferListFiltersWidget::removeUnusedLabels()
|
|||||||
delete labelFilters->takeItem(labelFilters->rowFromLabel(label));
|
delete labelFilters->takeItem(labelFilters->rowFromLabel(label));
|
||||||
Preferences::instance()->removeTorrentLabel(label);
|
Preferences::instance()->removeTorrentLabel(label);
|
||||||
}
|
}
|
||||||
|
if (!unusedLabels.empty())
|
||||||
|
labelFilters->updateGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListFiltersWidget::applyLabelFilter(int row)
|
void TransferListFiltersWidget::applyLabelFilter(int row)
|
||||||
|
@ -38,6 +38,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QListWidgetItem;
|
class QListWidgetItem;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class QDragMoveEvent;
|
class QDragMoveEvent;
|
||||||
|
class QLabel;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class TransferListWidget;
|
class TransferListWidget;
|
||||||
@ -45,7 +46,18 @@ class TorrentModelItem;
|
|||||||
class QTorrentHandle;
|
class QTorrentHandle;
|
||||||
class DownloadThread;
|
class DownloadThread;
|
||||||
|
|
||||||
class LabelFiltersList: public QListWidget
|
class FiltersBase: public QListWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FiltersBase(QWidget *parent);
|
||||||
|
|
||||||
|
QSize sizeHint() const;
|
||||||
|
QSize minimumSizeHint() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class LabelFiltersList: public FiltersBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -71,21 +83,18 @@ protected:
|
|||||||
void setItemHover(bool hover);
|
void setItemHover(bool hover);
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatusFiltersWidget: public QListWidget
|
class StatusFiltersWidget: public FiltersBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StatusFiltersWidget(QWidget *parent);
|
StatusFiltersWidget(QWidget *parent);
|
||||||
|
|
||||||
protected:
|
|
||||||
QSize sizeHint() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_shown;
|
bool m_shown;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TrackerFiltersList: public QListWidget
|
class TrackerFiltersList: public FiltersBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -127,6 +136,8 @@ private:
|
|||||||
TransferListWidget *transferList;
|
TransferListWidget *transferList;
|
||||||
int nb_labeled;
|
int nb_labeled;
|
||||||
int nb_torrents;
|
int nb_torrents;
|
||||||
|
//for use in resizeEvent()
|
||||||
|
QLabel *torrentsLabel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList);
|
TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList);
|
||||||
@ -141,6 +152,9 @@ public slots:
|
|||||||
void addTracker(const QString &tracker, const QString &hash);
|
void addTracker(const QString &tracker, const QString &hash);
|
||||||
void removeTracker(const QString &tracker, const QString &hash);
|
void removeTracker(const QString &tracker, const QString &hash);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void updateTorrentNumbers();
|
void updateTorrentNumbers();
|
||||||
void torrentDropped(int row);
|
void torrentDropped(int row);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user