diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-08-24 15:13:47 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-08-24 15:23:14 +0200 |
commit | eca5159e12288e1b4ee7d2d52f0475ca6433a0eb (patch) | |
tree | e4f695d9ece39de9f45965b1d64a8d2cd610353b /lib | |
parent | WebPage: add render process crash recovery page (diff) | |
download | smolbote-eca5159e12288e1b4ee7d2d52f0475ca6433a0eb.tar.xz |
Downloads: prevent download widget width from exceeding download list width
Downloads: add open button
Diffstat (limited to 'lib')
-rw-r--r-- | lib/downloads/downloadsform.ui | 15 | ||||
-rw-r--r-- | lib/downloads/downloadswidget.cpp | 15 | ||||
-rw-r--r-- | lib/downloads/downloadswidget.h | 2 | ||||
-rw-r--r-- | lib/downloads/widgets/downloaditemform.ui | 10 | ||||
-rw-r--r-- | lib/downloads/widgets/downloaditemwidget.cpp | 44 | ||||
-rw-r--r-- | lib/downloads/widgets/downloaditemwidget.h | 2 | ||||
-rw-r--r-- | lib/downloads/widgets/elidedlabel.cpp | 1 |
7 files changed, 55 insertions, 34 deletions
diff --git a/lib/downloads/downloadsform.ui b/lib/downloads/downloadsform.ui index 43a0d49..9ca3459 100644 --- a/lib/downloads/downloadsform.ui +++ b/lib/downloads/downloadsform.ui @@ -15,7 +15,20 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QListWidget" name="listWidget"/> + <widget class="QListWidget" name="listWidget"> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="showDropIndicator" stdset="0"> + <bool>false</bool> + </property> + <property name="spacing"> + <number>4</number> + </property> + </widget> </item> </layout> </widget> diff --git a/lib/downloads/downloadswidget.cpp b/lib/downloads/downloadswidget.cpp index 2a8fe56..340ef93 100644 --- a/lib/downloads/downloadswidget.cpp +++ b/lib/downloads/downloadswidget.cpp @@ -14,14 +14,13 @@ DownloadsWidget::DownloadsWidget(const QString &downloadPath, QWidget *parent) : QDialog(parent) , ui(new Ui::DownloadDialog) + , m_downloadPath(downloadPath) { // make sure this dialog does not get deleted on close setAttribute(Qt::WA_DeleteOnClose, false); setWindowTitle(tr("Downloads")); ui->setupUi(this); - - m_downloadPath = downloadPath; } DownloadsWidget::~DownloadsWidget() @@ -31,9 +30,7 @@ DownloadsWidget::~DownloadsWidget() void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) { - QString filepath = QFileDialog::getSaveFileName(this, - tr("Save"), - m_downloadPath + "/" + QFileInfo(item->path()).fileName()); + const QString filepath = QFileDialog::getSaveFileName(this, tr("Save File"), m_downloadPath + "/" + QFileInfo(item->path()).fileName()); if(filepath.isEmpty()) { // user cancelled the save dialog @@ -43,15 +40,13 @@ void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) item->setPath(filepath); - auto *listItem = new QListWidgetItem(); - int rowIndex = ui->listWidget->count(); - ui->listWidget->insertItem(rowIndex, listItem); + auto *listItem = new QListWidgetItem(ui->listWidget); auto *form = new DownloadItemWidget(item, this); ui->listWidget->setItemWidget(listItem, form); - listItem->setSizeHint(form->sizeHint()); + listItem->setSizeHint(QSize(listItem->sizeHint().width(), form->size().height())); item->accept(); - ui->listWidget->setCurrentRow(rowIndex); + ui->listWidget->setCurrentItem(listItem); } diff --git a/lib/downloads/downloadswidget.h b/lib/downloads/downloadswidget.h index dcf13d1..5dfde3e 100644 --- a/lib/downloads/downloadswidget.h +++ b/lib/downloads/downloadswidget.h @@ -30,7 +30,7 @@ public slots: private: Ui::DownloadDialog *ui; - QString m_downloadPath; + const QString m_downloadPath; }; #endif // SMOLBOTE_DOWNLOADDIALOG_H diff --git a/lib/downloads/widgets/downloaditemform.ui b/lib/downloads/widgets/downloaditemform.ui index 9b4ba12..7944084 100644 --- a/lib/downloads/widgets/downloaditemform.ui +++ b/lib/downloads/widgets/downloaditemform.ui @@ -66,6 +66,13 @@ </property> </widget> </item> + <item> + <widget class="QToolButton" name="open_toolButton"> + <property name="text"> + <string>Open</string> + </property> + </widget> + </item> </layout> </item> <item> @@ -73,9 +80,6 @@ <property name="text"> <string>path_label</string> </property> - <property name="wordWrap"> - <bool>true</bool> - </property> </widget> </item> </layout> diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp index 3fe2ebd..927c58b 100644 --- a/lib/downloads/widgets/downloaditemwidget.cpp +++ b/lib/downloads/widgets/downloaditemwidget.cpp @@ -10,6 +10,24 @@ #include "ui_downloaditemform.h" #include <QStyle> #include <QUrl> +#include <QDesktopServices> + +inline QString sizeString(int size) +{ + if(size < 1024) { + return QString("%1 bytes").arg(size); + } + // KiB + if(size < 1024 * 1024) { + return QString("%1 kB").arg(size / 1024); + } + // MiB + if(size < 1024 * 1024 * 1024) { + return QString("%1 MB").arg(size / (1024 * 1024)); + } + // GiB + return QString("%1 GB").arg(size / (1024 * 1024 * 1024)); +} DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent) : QWidget(parent) @@ -31,6 +49,7 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa ui->url_label->setText(item->url().toString()); ui->path_label->setText(item->path()); + this->updateState(item->state()); connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState); connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress); connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished); @@ -43,6 +62,9 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa item->resume(); } }); + connect(ui->open_toolButton, &QToolButton::clicked, item, [item]() { + QDesktopServices::openUrl(QUrl::fromLocalFile(item->path())); + }); } DownloadItemWidget::~DownloadItemWidget() @@ -50,23 +72,6 @@ DownloadItemWidget::~DownloadItemWidget() delete ui; } -QString DownloadItemWidget::sizeString(int size) const -{ - if(size < 1024) { - return QString("%1 bytes").arg(size); - } - // KiB - if(size < 1024 * 1024) { - return QString("%1 kB").arg(size / 1024); - } - // MiB - if(size < 1024 * 1024 * 1024) { - return QString("%1 MB").arg(size / (1024 * 1024)); - } - // GiB - return QString("%1 GB").arg(size / (1024 * 1024 * 1024)); -} - void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state) { switch(state) { @@ -74,26 +79,31 @@ void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state ui->status_label->setText(tr("Requested")); ui->pause_toolButton->setEnabled(true); ui->abort_toolButton->setEnabled(true); + ui->open_toolButton->setEnabled(false); break; case QWebEngineDownloadItem::DownloadInProgress: ui->status_label->setText(tr("In progress")); ui->pause_toolButton->setEnabled(true); ui->abort_toolButton->setEnabled(true); + ui->open_toolButton->setEnabled(false); break; case QWebEngineDownloadItem::DownloadCompleted: ui->status_label->setText(tr("Completed")); ui->pause_toolButton->setEnabled(false); ui->abort_toolButton->setEnabled(false); + ui->open_toolButton->setEnabled(true); break; case QWebEngineDownloadItem::DownloadCancelled: ui->status_label->setText(tr("Cancelled")); ui->pause_toolButton->setEnabled(false); ui->abort_toolButton->setEnabled(false); + ui->open_toolButton->setEnabled(false); break; case QWebEngineDownloadItem::DownloadInterrupted: ui->status_label->setText(tr("Interrupted")); ui->pause_toolButton->setEnabled(false); ui->abort_toolButton->setEnabled(false); + ui->open_toolButton->setEnabled(false); break; default: break; diff --git a/lib/downloads/widgets/downloaditemwidget.h b/lib/downloads/widgets/downloaditemwidget.h index 29a02d6..db4dc8e 100644 --- a/lib/downloads/widgets/downloaditemwidget.h +++ b/lib/downloads/widgets/downloaditemwidget.h @@ -25,8 +25,6 @@ public: explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); ~DownloadItemWidget() override; - QString sizeString(int size) const; - private slots: void updateState(QWebEngineDownloadItem::DownloadState state); void updateProgress(qint64 value, qint64 total); diff --git a/lib/downloads/widgets/elidedlabel.cpp b/lib/downloads/widgets/elidedlabel.cpp index da81407..b6761ab 100644 --- a/lib/downloads/widgets/elidedlabel.cpp +++ b/lib/downloads/widgets/elidedlabel.cpp @@ -14,6 +14,7 @@ ElidedLabel::ElidedLabel(QWidget *parent) : QLabel(parent) { + setWordWrap(true); } void ElidedLabel::setText(const QString &text) |