diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-12-27 17:06:33 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-12-27 17:06:33 +0100 |
commit | bdc239d1f827308c0fc1e4c202ed0e3f5c71da0b (patch) | |
tree | e743885fcdfc92a85eb46b075cf65e6b7c0c8a8e /src | |
parent | UrlRequestInterceptor fixes (diff) | |
download | smolbote-bdc239d1f827308c0fc1e4c202ed0e3f5c71da0b.tar.xz |
Download manager fixes
DownloadsWidget
- Download widget now in landscape
- Download widget no longer docks in the main window, but is a dialog
DownloadItemWidget
- Download item widget looks more compact
- Download details are now a part of the item widgets instead
- Download details: save path
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/downloads/downloadsform.ui | 61 | ||||
-rw-r--r-- | src/lib/downloads/downloadswidget.cpp | 28 | ||||
-rw-r--r-- | src/lib/downloads/downloadswidget.h | 7 | ||||
-rw-r--r-- | src/lib/downloads/widgets/downloaditemform.ui | 28 | ||||
-rw-r--r-- | src/lib/downloads/widgets/downloaditemwidget.cpp | 19 | ||||
-rw-r--r-- | src/lib/downloads/widgets/downloaditemwidget.h | 3 | ||||
-rw-r--r-- | src/mainwindow.cpp | 3 | ||||
-rw-r--r-- | src/mainwindow.h | 2 | ||||
-rw-r--r-- | src/widgets/mainwindowmenubar.cpp | 10 | ||||
-rw-r--r-- | src/widgets/mainwindowmenubar.h | 1 |
10 files changed, 71 insertions, 91 deletions
diff --git a/src/lib/downloads/downloadsform.ui b/src/lib/downloads/downloadsform.ui index 5ab770f..43a0d49 100644 --- a/src/lib/downloads/downloadsform.ui +++ b/src/lib/downloads/downloadsform.ui @@ -6,16 +6,10 @@ <rect> <x>0</x> <y>0</y> - <width>420</width> - <height>600</height> + <width>600</width> + <height>420</height> </rect> </property> - <property name="minimumSize"> - <size> - <width>420</width> - <height>600</height> - </size> - </property> <property name="windowTitle"> <string>Downloads</string> </property> @@ -23,57 +17,6 @@ <item> <widget class="QListWidget" name="listWidget"/> </item> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Details</string> - </property> - <layout class="QFormLayout" name="formLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="mimeType"> - <property name="text"> - <string>Type</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="mimeType_label"> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="filePath"> - <property name="text"> - <string>Path</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="fileSize"> - <property name="text"> - <string>Size</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLabel" name="fileSize_label"> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLabel" name="filePath_label"> - <property name="text"> - <string/> - </property> - </widget> - </item> - </layout> - </widget> - </item> </layout> </widget> <resources/> diff --git a/src/lib/downloads/downloadswidget.cpp b/src/lib/downloads/downloadswidget.cpp index af41397..dc7d5e2 100644 --- a/src/lib/downloads/downloadswidget.cpp +++ b/src/lib/downloads/downloadswidget.cpp @@ -17,7 +17,7 @@ #include "widgets/downloaditemwidget.h" DownloadsWidget::DownloadsWidget(const QString &downloadPath, QWidget *parent) : - QWidget(parent), + QDialog(parent), ui(new Ui::DownloadDialog) { // make sure this dialog does not get deleted on close @@ -25,11 +25,22 @@ DownloadsWidget::DownloadsWidget(const QString &downloadPath, QWidget *parent) : setWindowTitle(tr("Downloads")); ui->setupUi(this); - ui->filePath->setWordWrap(true); m_downloadPath = downloadPath; - connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int))); + connect(ui->listWidget, &QListWidget::currentItemChanged, this, [this](QListWidgetItem *current, QListWidgetItem *previous) { + DownloadItemWidget *currentWidget = qobject_cast<DownloadItemWidget*>(ui->listWidget->itemWidget(current)); + currentWidget->showDetails(); + currentWidget->adjustSize(); + current->setSizeHint(currentWidget->size()); + + DownloadItemWidget *previousWidget = qobject_cast<DownloadItemWidget*>(ui->listWidget->itemWidget(previous)); + if(previousWidget != nullptr) { + previousWidget->hideDetails(); + previousWidget->adjustSize(); + previous->setSizeHint(previousWidget->size()); + } + }); } DownloadsWidget::~DownloadsWidget() @@ -60,13 +71,8 @@ void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) ui->listWidget->setItemWidget(listItem, form); item->accept(); - this->show(); -} -void DownloadsWidget::showItemDetails(int index) -{ - DownloadItemWidget *form = qobject_cast<DownloadItemWidget *>(ui->listWidget->itemWidget(ui->listWidget->item(index))); - ui->mimeType_label->setText(form->item()->mimeType()); - ui->filePath_label->setText(form->item()->path()); - ui->fileSize_label->setText(QString("%1 bytes").arg(form->item()->totalBytes())); + ui->listWidget->setCurrentRow(rowIndex); + + this->show(); } diff --git a/src/lib/downloads/downloadswidget.h b/src/lib/downloads/downloadswidget.h index ffd0814..30bfa38 100644 --- a/src/lib/downloads/downloadswidget.h +++ b/src/lib/downloads/downloadswidget.h @@ -9,14 +9,14 @@ #ifndef DOWNLOADDIALOG_H #define DOWNLOADDIALOG_H -#include <QWidget> +#include <QDialog> namespace Ui { class DownloadDialog; } class QWebEngineDownloadItem; -class DownloadsWidget : public QWidget +class DownloadsWidget : public QDialog { Q_OBJECT @@ -27,9 +27,6 @@ public: public slots: void addDownload(QWebEngineDownloadItem *item); -private slots: - void showItemDetails(int index); - private: Ui::DownloadDialog *ui; QString m_downloadPath; diff --git a/src/lib/downloads/widgets/downloaditemform.ui b/src/lib/downloads/widgets/downloaditemform.ui index 8a8d148..7e63211 100644 --- a/src/lib/downloads/widgets/downloaditemform.ui +++ b/src/lib/downloads/widgets/downloaditemform.ui @@ -7,13 +7,22 @@ <x>0</x> <y>0</y> <width>500</width> - <height>70</height> + <height>100</height> </rect> </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>0</number> + </property> <item> <widget class="QLabel" name="url_label"> <property name="text"> @@ -26,14 +35,14 @@ <item> <widget class="QLabel" name="status_label"> <property name="text"> - <string>Unknown</string> + <string>Un&known</string> </property> </widget> </item> <item> <widget class="QLabel" name="filesize_label"> <property name="text"> - <string>x MiB / y MiB</string> + <string>&x MiB / y MiB</string> </property> </widget> </item> @@ -46,6 +55,19 @@ </item> </layout> </item> + <item> + <widget class="QWidget" name="detailsWidget" native="true"> + <layout class="QVBoxLayout" name="detailsLayout"> + <item> + <widget class="QLabel" name="path_label"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> </layout> </widget> <resources/> diff --git a/src/lib/downloads/widgets/downloaditemwidget.cpp b/src/lib/downloads/widgets/downloaditemwidget.cpp index df0b6fc..6145a6e 100644 --- a/src/lib/downloads/widgets/downloaditemwidget.cpp +++ b/src/lib/downloads/widgets/downloaditemwidget.cpp @@ -20,10 +20,13 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa ui->setupUi(this); ui->url_label->setText(item->url().toString()); + ui->detailsWidget->hide(); - connect(item, SIGNAL(stateChanged(QWebEngineDownloadItem::DownloadState)), this, SLOT(updateState(QWebEngineDownloadItem::DownloadState))); - connect(item, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64))); - connect(item, SIGNAL(finished()), this, SLOT(updateFinished())); + ui->path_label->setText(item->path()); + + connect(item, &QWebEngineDownloadItem::stateChanged, this, &DownloadItemWidget::updateState); + connect(item, &QWebEngineDownloadItem::downloadProgress, this, &DownloadItemWidget::updateProgress); + connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished); } DownloadItemWidget::~DownloadItemWidget() @@ -31,6 +34,16 @@ DownloadItemWidget::~DownloadItemWidget() delete ui; } +void DownloadItemWidget::showDetails() +{ + ui->detailsWidget->show(); +} + +void DownloadItemWidget::hideDetails() +{ + ui->detailsWidget->hide(); +} + QWebEngineDownloadItem *DownloadItemWidget::item() const { return m_item; diff --git a/src/lib/downloads/widgets/downloaditemwidget.h b/src/lib/downloads/widgets/downloaditemwidget.h index cffa32a..c6246da 100644 --- a/src/lib/downloads/widgets/downloaditemwidget.h +++ b/src/lib/downloads/widgets/downloaditemwidget.h @@ -24,6 +24,9 @@ public: explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); ~DownloadItemWidget(); + void showDetails(); + void hideDetails(); + QWebEngineDownloadItem *item() const; QString sizeString(int size) const; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9c1292f..2dd7628 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -246,9 +246,6 @@ void MainWindow::setDownloadsWidget(std::shared_ptr<DownloadsWidget> &widget) { Q_ASSERT(widget); m_downloadsWidget = widget; - connect(menuBar->downloadsAction(), &QAction::triggered, this, [this]() { - addTabbedDock(Qt::RightDockWidgetArea, m_downloadsWidget.get()); - }); } void MainWindow::toggleFullscreen() diff --git a/src/mainwindow.h b/src/mainwindow.h index 135f8fb..6ab7f75 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -40,6 +40,8 @@ class MainWindow : public QMainWindow friend class SearchForm; friend class UrlLineEdit; + friend class MainWindowMenuBar; + public: MainWindow(std::shared_ptr<Configuration> config, QWidget *parent = nullptr); ~MainWindow() override; diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp index b5ce229..f8e8ecd 100644 --- a/src/widgets/mainwindowmenubar.cpp +++ b/src/widgets/mainwindowmenubar.cpp @@ -15,6 +15,7 @@ #include <settings/configuration.h> #include "browser.h" +#include "downloads/downloadswidget.h" MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, MainWindow *parent) : QMenuBar(parent) @@ -56,6 +57,9 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, Main m_downloadsAction = toolsMenu->addAction(tr("Downloads")); m_downloadsAction->setParent(parent); m_downloadsAction->setShortcut(QKeySequence(config->value<std::string>("downloads.shortcut").value().c_str())); + connect(m_downloadsAction, &QAction::triggered, [parent]() { + parent->m_downloadsWidget->show(); + }); m_bookmarksAction = toolsMenu->addAction(tr("Bookmarks")); m_bookmarksAction->setParent(parent); @@ -82,12 +86,6 @@ QAction *MainWindowMenuBar::bookmarksAction() return m_bookmarksAction; } -QAction *MainWindowMenuBar::downloadsAction() -{ - Q_CHECK_PTR(m_downloadsAction); - return m_downloadsAction; -} - void MainWindowMenuBar::setProfileName(const QString &name) { Q_CHECK_PTR(m_profileAction); diff --git a/src/widgets/mainwindowmenubar.h b/src/widgets/mainwindowmenubar.h index 9154f67..367525b 100644 --- a/src/widgets/mainwindowmenubar.h +++ b/src/widgets/mainwindowmenubar.h @@ -21,7 +21,6 @@ public: explicit MainWindowMenuBar(std::shared_ptr<Configuration> config, MainWindow *parent = nullptr); QAction *bookmarksAction(); - QAction *downloadsAction(); void setProfileName(const QString &name); private slots: |