From c57d7567c4f8e89f9fa562c0e3361670391974ee Mon Sep 17 00:00:00 2001 From: Krzysztof Starecki Date: Wed, 2 Jan 2019 18:47:50 +0100 Subject: Tweak download tab column resizing --- src/downloadlistwidget.cpp | 75 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 16 deletions(-) (limited to 'src/downloadlistwidget.cpp') diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 24695032..37202421 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -32,9 +32,9 @@ along with Mod Organizer. If not, see . void DownloadProgressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QModelIndex sourceIndex = m_SortProxy->mapToSource(index); - if (sourceIndex.column() == DownloadList::COL_STATUS && sourceIndex.row() < m_Manager->numTotalDownloads() + bool pendingDownload = (sourceIndex.row() >= m_Manager->numTotalDownloads()); + if (sourceIndex.column() == DownloadList::COL_STATUS && !pendingDownload && m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_DOWNLOADING) { - bool pendingDownload = sourceIndex.row() >= m_Manager->numTotalDownloads(); QProgressBar progressBar; progressBar.setProperty("downloadView", option.widget->property("downloadView")); progressBar.setProperty("downloadProgress", true); @@ -47,38 +47,73 @@ void DownloadProgressDelegate::paint(QPainter *painter, const QStyleOptionViewIt progressBar.setFormat(m_Manager->getProgress(sourceIndex.row()).second); progressBar.setStyle(QApplication::style()); - /* - QLabel progressText; - progressText.setProperty("downloadView", option.widget->property("downloadView")); - progressText.setProperty("downloadProgress", true); - progressText.resize(option.rect.width(), option.rect.height()); - progressText.setAttribute(Qt::WA_TranslucentBackground); - progressText.setAlignment(Qt::AlignCenter); - progressText.setText(m_Manager->getProgress(sourceIndex.row()).second); - progressText.setStyle(QApplication::style()); - */ - // paint the background with default delegate first to preserve table cell styling QStyledItemDelegate::paint(painter, option, index); painter->save(); painter->translate(option.rect.topLeft()); progressBar.render(painter); - //progressText.render(painter); painter->restore(); } else { QStyledItemDelegate::paint(painter, option, index); } } +void DownloadListHeader::customResizeSections() +{ + // find the rightmost column that is not hidden + int rightVisible = count() - 1; + while (isSectionHidden(rightVisible) && rightVisible > 0) + rightVisible--; + + // if that column is already squashed, squash others to the right side -- + // otherwise to the left + if (sectionSize(rightVisible) == minimumSectionSize()) { + for (int idx = rightVisible; idx >= 0; idx--) { + if (!isSectionHidden(idx)) { + if (length() != width()) + resizeSection(idx, std::max(sectionSize(idx) + width() - length(), minimumSectionSize())); + else + break; + } + } + } else { + for (int idx = 0; idx <= rightVisible; idx++) { + if (!isSectionHidden(idx)) { + if (length() != width()) + resizeSection(idx, std::max(sectionSize(idx) + width() - length(), minimumSectionSize())); + else + break; + } + } + } +} + +void DownloadListHeader::mouseReleaseEvent(QMouseEvent *event) +{ + QHeaderView::mouseReleaseEvent(event); + customResizeSections(); +} + DownloadListWidget::DownloadListWidget(QWidget *parent) : QTreeView(parent) { - connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClick(QModelIndex))); - connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenu(QPoint))); + setHeader(new DownloadListHeader(Qt::Horizontal, this)); + header()->setSectionsMovable(true); header()->setContextMenuPolicy(Qt::CustomContextMenu); + header()->setCascadingSectionResizes(true); + header()->setStretchLastSection(false); + header()->setSectionResizeMode(QHeaderView::Interactive); + header()->setDefaultSectionSize(100); + + setUniformRowHeights(false); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + sortByColumn(1, Qt::DescendingOrder); + connect(header(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onHeaderCustomContextMenu(QPoint))); + connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClick(QModelIndex))); + connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenu(QPoint))); } DownloadListWidget::~DownloadListWidget() @@ -141,6 +176,14 @@ void DownloadListWidget::onHeaderCustomContextMenu(const QPoint &point) } ++i; } + + qobject_cast(header())->customResizeSections(); +} + +void DownloadListWidget::resizeEvent(QResizeEvent *event) +{ + QTreeView::resizeEvent(event); + qobject_cast(header())->customResizeSections(); } void DownloadListWidget::onCustomContextMenu(const QPoint &point) -- cgit v1.3.1 From 08477d652421baae7d97678c19e6543e4aec496e Mon Sep 17 00:00:00 2001 From: Al Date: Sat, 5 Jan 2019 23:43:10 +0100 Subject: Fix compact/normal download sizes on all themes. Fix hover/select padding changes. Fix non uniform height due to warning icon. --- src/downloadlistwidget.cpp | 2 +- src/mainwindow.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/downloadlistwidget.cpp') diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 37202421..f885a5a8 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -107,7 +107,7 @@ DownloadListWidget::DownloadListWidget(QWidget *parent) header()->setSectionResizeMode(QHeaderView::Interactive); header()->setDefaultSectionSize(100); - setUniformRowHeights(false); + setUniformRowHeights(true); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); sortByColumn(1, Qt::DescendingOrder); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 52cb894f..d0cb0416 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5191,16 +5191,16 @@ void MainWindow::updateDownloadView() // set the view attribute and default row sizes if (m_OrganizerCore.settings().compactDownloads()) { ui->downloadView->setProperty("downloadView", "compact"); - setStyleSheet("DownloadListWidget::item { padding: 4px; }"); + setStyleSheet("DownloadListWidget::item { padding: 4px 0; }"); } else { ui->downloadView->setProperty("downloadView", "standard"); - setStyleSheet("DownloadListWidget::item { padding: 16px; }"); + setStyleSheet("DownloadListWidget::item { padding: 16px 0; }"); } - setStyleSheet("DownloadListWidget::item:hover { padding: 0px; }"); - setStyleSheet("DownloadListWidget::item:selected { padding: 0px; }"); + //setStyleSheet("DownloadListWidget::item:hover { padding: 0px; }"); + //setStyleSheet("DownloadListWidget::item:selected { padding: 0px; }"); // reapply global stylesheet on the widget level (!) to override the defaults - ui->downloadView->setStyleSheet(styleSheet()); + //ui->downloadView->setStyleSheet(styleSheet()); ui->downloadView->setMetaDisplay(m_OrganizerCore.settings().metaDownloads()); ui->downloadView->style()->unpolish(ui->downloadView); -- cgit v1.3.1