diff options
| author | Krzysztof Starecki <krzysztof.starecki@gmail.com> | 2018-12-30 22:13:15 +0100 |
|---|---|---|
| committer | Krzysztof Starecki <krzysztof.starecki@gmail.com> | 2018-12-30 22:13:15 +0100 |
| commit | c11ff7e2db09514304cef35a650aa3fbef27dd16 (patch) | |
| tree | 52a514445448ca847016e795da66ef7d099d313b /src | |
| parent | cfb941082e27925279535cade18d2b3c912c8930 (diff) | |
Add icon for incomplete download info, add download progress delegate
Diffstat (limited to 'src')
| -rw-r--r-- | src/downloadlist.cpp | 5 | ||||
| -rw-r--r-- | src/downloadlist.h | 1 | ||||
| -rw-r--r-- | src/downloadlistwidget.cpp | 26 | ||||
| -rw-r--r-- | src/downloadlistwidget.h | 18 | ||||
| -rw-r--r-- | src/downloadmanager.cpp | 6 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 7 | ||||
| -rw-r--r-- | src/mainwindow.h | 2 |
7 files changed, 57 insertions, 8 deletions
diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index d78e97f9..09f6968c 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "downloadmanager.h"
#include <QEvent>
#include <QColor>
+#include <QIcon>
#include <QSortFilterProxyModel>
@@ -147,6 +148,10 @@ QVariant DownloadList::data(const QModelIndex &index, int role) const }
return text;
}
+ } else if (role == Qt::DecorationRole && index.column() == COL_NAME) {
+ if (!pendingDownload && m_Manager->getState(index.row()) >= DownloadManager::STATE_READY
+ && m_Manager->isInfoIncomplete(index.row()))
+ return QIcon(":/MO/gui/warning_16");
} else if (role == Qt::TextAlignmentRole) {
if (index.column() == COL_SIZE)
return Qt::AlignVCenter | Qt::AlignRight;
diff --git a/src/downloadlist.h b/src/downloadlist.h index d7764763..3b33fc40 100644 --- a/src/downloadlist.h +++ b/src/downloadlist.h @@ -23,7 +23,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QAbstractTableModel>
#include <QFontMetrics>
-
class DownloadManager;
diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index 9cf8e097..6a85c317 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -17,13 +17,39 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "downloadlist.h"
#include "downloadlistwidget.h"
#include <QPainter>
#include <QMouseEvent>
#include <QMenu>
#include <QMessageBox>
#include <QSortFilterProxyModel>
+#include <QApplication>
+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()
+ && m_Manager->getState(sourceIndex.row()) == DownloadManager::STATE_DOWNLOADING) {
+ bool pendingDownload = sourceIndex.row() >= m_Manager->numTotalDownloads();
+ QStyleOptionProgressBar progressBarOption;
+ progressBarOption.state = QStyle::State_Enabled;
+ progressBarOption.direction = QApplication::layoutDirection();
+ progressBarOption.rect = option.rect;
+ progressBarOption.fontMetrics = QApplication::fontMetrics();
+ progressBarOption.minimum = 0;
+ progressBarOption.maximum = 100;
+ progressBarOption.textAlignment = Qt::AlignCenter;
+ progressBarOption.textVisible = true;
+ progressBarOption.progress = m_Manager->getProgress(sourceIndex.row()).first;
+ progressBarOption.text = m_Manager->getProgress(sourceIndex.row()).second;
+
+ QApplication::style()->drawControl(QStyle::CE_ProgressBar,
+ &progressBarOption, painter);
+ } else {
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+}
DownloadListWidget::DownloadListWidget(QWidget *parent)
: QTreeView(parent)
diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h index 0c17de87..c19e4473 100644 --- a/src/downloadlistwidget.h +++ b/src/downloadlistwidget.h @@ -21,11 +21,14 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #define DOWNLOADLISTWIDGET_H
#include "downloadmanager.h"
+#include "downloadlistsortproxy.h"
#include <QWidget>
#include <QItemDelegate>
#include <QLabel>
#include <QProgressBar>
#include <QTreeView>
+#include <QStyledItemDelegate>
+
namespace Ui {
class DownloadListWidget;
@@ -33,6 +36,21 @@ namespace Ui { class DownloadManager;
+class DownloadProgressDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+
+public:
+ DownloadProgressDelegate(DownloadManager *manager, DownloadListSortProxy *sortProxy, QWidget *parent = 0) : QStyledItemDelegate(parent), m_Manager(manager), m_SortProxy(sortProxy) {}
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+
+private:
+ DownloadManager *m_Manager;
+ DownloadListSortProxy *m_SortProxy;
+};
+
class DownloadListWidget : public QTreeView
{
Q_OBJECT
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 9f07b030..b94b5864 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -64,7 +64,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const Mo info->m_DownloadID = s_NextDownloadID++;
info->m_StartTime.start();
info->m_PreResumeSize = 0LL;
- info->m_Progress = std::make_pair<int, QString>(0, " 0.0 Bytes/s ");
+ info->m_Progress = std::make_pair<int, QString>(0, "0.0 B/s ");
info->m_ResumePos = 0;
info->m_FileInfo = new ModRepositoryFileInfo(*fileInfo);
info->m_Urls = URLs;
@@ -1338,7 +1338,7 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) QString unit;
if (speed < 1000) {
- unit = "Bytes/s";
+ unit = "B/s";
}
else if (speed < 1000*1024) {
speed /= 1024;
@@ -1349,7 +1349,7 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) unit = "MB/s";
}
- info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(speed, 8, 'f', 1,' ').arg(unit, -8, ' ');
+ info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(QString::number(speed, 'f', 1)).arg(unit);
TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal);
emit update(index);
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b2876e33..4f60ae16 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -319,6 +319,7 @@ MainWindow::MainWindow(QSettings &initSettings //ui->bsaList->setLocalMoveOnly(true);
+ initDownloadView();
bool pluginListAdjusted = registerWidgetState(ui->espList->objectName(), ui->espList->header(), "plugin_list_state");
registerWidgetState(ui->dataTree->objectName(), ui->dataTree->header());
registerWidgetState(ui->downloadView->objectName(),
@@ -340,8 +341,6 @@ MainWindow::MainWindow(QSettings &initSettings ui->openFolderMenu->setMenu(openFolderMenu());
- initDownloadList();
-
ui->savegameList->installEventFilter(this);
ui->savegameList->setMouseTracking(true);
@@ -5145,15 +5144,17 @@ void MainWindow::on_actionEndorseMO_triggered() }
-void MainWindow::initDownloadList()
+void MainWindow::initDownloadView()
{
DownloadListSortProxy *sortProxy = new DownloadListSortProxy(m_OrganizerCore.downloadManager(), ui->downloadView);
sortProxy->setSourceModel(new DownloadList(m_OrganizerCore.downloadManager(), ui->downloadView));
connect(ui->downloadFilterEdit, SIGNAL(textChanged(QString)), sortProxy, SLOT(updateFilter(QString)));
connect(ui->downloadFilterEdit, SIGNAL(textChanged(QString)), this, SLOT(downloadFilterChanged(QString)));
+ ui->downloadView->setObjectName("downloadView");
ui->downloadView->setModel(sortProxy);
ui->downloadView->setManager(m_OrganizerCore.downloadManager());
+ ui->downloadView->setItemDelegate(new DownloadProgressDelegate(m_OrganizerCore.downloadManager(), sortProxy, ui->downloadView));
ui->downloadView->setUniformRowHeights(true);
ui->downloadView->header()->setStretchLastSection(false);
ui->downloadView->header()->setSectionResizeMode(QHeaderView::Interactive);
diff --git a/src/mainwindow.h b/src/mainwindow.h index 93f2ed5f..13a66a8e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -246,7 +246,7 @@ private: bool populateMenuCategories(QMenu *menu, int targetID);
- void initDownloadList();
+ void initDownloadView();
// remove invalid category-references from mods
void fixCategories();
|
