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 +++++++++++++++----- src/downloadlistwidget.h | 15 ++++ src/mainwindow.cpp | 6 +- src/organizer_en.ts | 166 ++++++++++++++++++++++----------------------- 4 files changed, 158 insertions(+), 104 deletions(-) (limited to 'src') 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) diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h index 0002e2b4..4776d259 100644 --- a/src/downloadlistwidget.h +++ b/src/downloadlistwidget.h @@ -28,6 +28,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #include @@ -50,6 +51,18 @@ private: DownloadListSortProxy *m_SortProxy; }; +class DownloadListHeader : public QHeaderView +{ + Q_OBJECT + +public: + explicit DownloadListHeader(Qt::Orientation orientation, QWidget *parent = nullptr) : QHeaderView(orientation, parent) {} + void customResizeSections(); + +private: + void mouseReleaseEvent(QMouseEvent *event) override; +}; + class DownloadListWidget : public QTreeView { Q_OBJECT @@ -101,6 +114,8 @@ private: DownloadManager *m_Manager; DownloadList *m_SourceModel = 0; int m_ContextRow; + + void resizeEvent(QResizeEvent *event); }; #endif // DOWNLOADLISTWIDGET_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2e1391c1..0cba0745 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5164,11 +5164,6 @@ void MainWindow::initDownloadView() ui->downloadView->setModel(sortProxy); ui->downloadView->setManager(m_OrganizerCore.downloadManager()); ui->downloadView->setItemDelegate(new DownloadProgressDelegate(m_OrganizerCore.downloadManager(), sortProxy, ui->downloadView)); - ui->downloadView->setUniformRowHeights(false); - ui->downloadView->header()->setStretchLastSection(false); - ui->downloadView->header()->setSectionResizeMode(QHeaderView::Interactive); - ui->downloadView->header()->setSectionResizeMode(0, QHeaderView::Stretch); - ui->downloadView->sortByColumn(1, Qt::DescendingOrder); updateDownloadView(); connect(ui->downloadView, SIGNAL(installDownload(int)), &m_OrganizerCore, SLOT(installDownload(int))); @@ -5202,6 +5197,7 @@ void MainWindow::updateDownloadView() ui->downloadView->setMetaDisplay(m_OrganizerCore.settings().metaDownloads()); ui->downloadView->style()->unpolish(ui->downloadView); ui->downloadView->style()->polish(ui->downloadView); + qobject_cast(ui->downloadView->header())->customResizeSections(); m_OrganizerCore.downloadManager()->refreshList(); } diff --git a/src/organizer_en.ts b/src/organizer_en.ts index 2b256839..fe54a05a 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -395,145 +395,145 @@ p, li { white-space: pre-wrap; } DownloadListWidget - + Install - + Query Info - + Visit on Nexus - + Open File - - - + + + Show in Folder - - + + Delete - + Un-Hide - + Hide - + Cancel - + Pause - + Resume - + Delete Installed... - + Delete Uninstalled... - + Delete All... - + Hide Installed... - + Hide Uninstalled... - + Hide All... - + Un-Hide All... - - - - + + + + Delete Files? - + This will permanently delete the selected download. - + This will remove all finished downloads from this list and from disk. - + This will remove all installed downloads from this list and from disk. - + This will remove all uninstalled downloads from this list and from disk. - - - + + + Are you sure? - + This will remove all finished downloads from this list (but NOT from disk). - + This will remove all installed downloads from this list (but NOT from disk). - + This will remove all uninstalled downloads from this list (but NOT from disk). @@ -2281,7 +2281,7 @@ Please enter a name: - + Are you sure? @@ -2608,13 +2608,13 @@ You can also use online editors and converters instead. - + Enable selected - + Disable selected @@ -2675,13 +2675,13 @@ You can also use online editors and converters instead. - + Exception: - + Unknown exception @@ -2819,7 +2819,7 @@ Click OK to restart MO now. - + Set Priority @@ -2884,196 +2884,196 @@ Click OK to restart MO now. - + Thank you! - + Thank you for your endorsement! - + Request to Nexus failed: %1 - - + + failed to read %1: %2 - - + + Error - + failed to extract %1 (errorcode %2) - + Extract BSA - + This archive contains invalid hashes. Some files may be broken. - + Extract... - + This will restart MO, continue? - + Edit Categories... - + Deselect filter - + Remove - + Enable all - + Disable all - + Unlock load order - + Lock load order - + Open Origin in Explorer - + Open Origin Info... - + depends on missing "%1" - + incompatible with "%1" - + Please wait while LOOT is running - + loot failed. Exit code was: %1 - + failed to start loot - + failed to run loot: %1 - + Errors occured - + Backup of load order created - + Choose backup to restore - + No Backups - + There are no backups to restore - - + + Restore failed - - + + Failed to restore the backup. Errorcode: %1 - + Backup of modlist created - + A file with the same name has already been downloaded. What would you like to do? - + Overwrite - + Rename new file - + Ignore file - + Set the priority of the selected mods -- cgit v1.3.1