From da688a422ec94e342467f102c3361c0be3d7fd44 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 20 Mar 2017 18:44:46 +0100 Subject: Dockable DownloadsWidget --- src/forms/bookmarkswidget.cpp | 29 +-------- src/forms/bookmarkswidget.h | 16 +---- src/forms/downloaddialog.cpp | 77 ------------------------ src/forms/downloaddialog.h | 49 --------------- src/forms/downloaddialog.ui | 134 ------------------------------------------ src/forms/downloadsform.ui | 81 +++++++++++++++++++++++++ src/forms/downloadswidget.cpp | 77 ++++++++++++++++++++++++ src/forms/downloadswidget.h | 49 +++++++++++++++ 8 files changed, 211 insertions(+), 301 deletions(-) delete mode 100644 src/forms/downloaddialog.cpp delete mode 100644 src/forms/downloaddialog.h delete mode 100644 src/forms/downloaddialog.ui create mode 100644 src/forms/downloadsform.ui create mode 100644 src/forms/downloadswidget.cpp create mode 100644 src/forms/downloadswidget.h (limited to 'src/forms') diff --git a/src/forms/bookmarkswidget.cpp b/src/forms/bookmarkswidget.cpp index ee945cb..63062a2 100644 --- a/src/forms/bookmarkswidget.cpp +++ b/src/forms/bookmarkswidget.cpp @@ -23,19 +23,8 @@ #include "browser.h" #include -DockWidget::DockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags) : - QDockWidget(title, parent, flags) -{ -} - -void DockWidget::closeEvent(QCloseEvent *event) -{ - setParent(0); - event->ignore(); -} - BookmarksWidget::BookmarksWidget(QWidget *parent) : - QWidget(parent), + DockingWidget(tr("Bookmarks"), parent), ui(new Ui::BookmarksDialog) { // make sure this dialog does not get deleted on close @@ -44,11 +33,6 @@ BookmarksWidget::BookmarksWidget(QWidget *parent) : ui->setupUi(this); ui->treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch); - window = nullptr; - dock = new DockWidget(tr("Bookmarks"), 0); - dock->setWidget(this); - dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - QStyle *style = ui->treeWidget->style(); ui->addFolder_toolButton->setIcon(style->standardPixmap(QStyle::SP_DirIcon)); ui->addBookmark_toolButton->setIcon(style->standardPixmap(QStyle::SP_FileIcon)); @@ -91,17 +75,8 @@ void BookmarksWidget::show() { // show() gets called by a QAction in MainWindow window = qobject_cast(sender()->parent()); - if(window) { - - // dockable widgets - dock->setParent(window); - window->addDockWidget(Qt::RightDockWidgetArea, dock); - - } else { - qWarning("BookmarksWidget not called by MainWindow"); - } - QWidget::show(); + DockingWidget::show(); } void BookmarksWidget::deleteCurrentItem() diff --git a/src/forms/bookmarkswidget.h b/src/forms/bookmarkswidget.h index ca0889b..19c49e5 100644 --- a/src/forms/bookmarkswidget.h +++ b/src/forms/bookmarkswidget.h @@ -21,27 +21,16 @@ #ifndef BOOKMARKSDIALOG_H #define BOOKMARKSDIALOG_H -#include +#include "widgets/dockingwidget.h" #include #include "xbel.h" #include "mainwindow.h" -class DockWidget : public QDockWidget -{ - Q_OBJECT - -public: - explicit DockWidget(const QString &title, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); - -protected: - void closeEvent(QCloseEvent *event); -}; - namespace Ui { class BookmarksDialog; } -class BookmarksWidget : public QWidget +class BookmarksWidget : public DockingWidget { Q_OBJECT @@ -65,7 +54,6 @@ private slots: private: MainWindow *window; - DockWidget *dock; Ui::BookmarksDialog *ui; Xbel *xbel; }; diff --git a/src/forms/downloaddialog.cpp b/src/forms/downloaddialog.cpp deleted file mode 100644 index d182076..0000000 --- a/src/forms/downloaddialog.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/** LICENSE ******************************************************************** - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#include "downloaddialog.h" -#include "ui_downloaddialog.h" - -#include -#include -#include -#include -#include -#include "webengine/downloaditemform.h" -#include "browser.h" - -DownloadDialog::DownloadDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::DownloadDialog) -{ - ui->setupUi(this); - ui->filePath->setWordWrap(true); - - connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int))); -} - -DownloadDialog::~DownloadDialog() -{ - delete ui; -} - -void DownloadDialog::addDownload(QWebEngineDownloadItem *item) -{ - QString filepath = QFileDialog::getSaveFileName(this, tr("Save"), sSettings->value("downloads.path").toString() + "/" + QFileInfo(item->path()).fileName()); - - if(filepath.isEmpty()) { - // user cancelled the save dialog - item->cancel(); - return; - } - - item->setPath(filepath); - - QListWidgetItem *listItem = new QListWidgetItem(); - int rowIndex = ui->listWidget->count(); - ui->listWidget->insertItem(rowIndex, listItem); - - DownloadItemForm *form = new DownloadItemForm(item, this); - listItem->setSizeHint(form->size()); - ui->listWidget->setItemWidget(listItem, form); - - item->accept(); - this->show(); -} - -void DownloadDialog::showItemDetails(int index) -{ - DownloadItemForm *form = qobject_cast(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())); -} diff --git a/src/forms/downloaddialog.h b/src/forms/downloaddialog.h deleted file mode 100644 index 9a74cf0..0000000 --- a/src/forms/downloaddialog.h +++ /dev/null @@ -1,49 +0,0 @@ -/** LICENSE ******************************************************************** - ** - ** smolbote: yet another qute browser - ** Copyright (C) 2017 Xian Nox - ** - ** This program is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** This program is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . - ** - ******************************************************************************/ - -#ifndef DOWNLOADDIALOG_H -#define DOWNLOADDIALOG_H - -#include - -namespace Ui { -class DownloadDialog; -} - -class QWebEngineDownloadItem; -class DownloadDialog : public QDialog -{ - Q_OBJECT - -public: - explicit DownloadDialog(QWidget *parent = 0); - ~DownloadDialog(); - -public slots: - void addDownload(QWebEngineDownloadItem *item); - -private slots: - void showItemDetails(int index); - -private: - Ui::DownloadDialog *ui; -}; - -#endif // DOWNLOADDIALOG_H diff --git a/src/forms/downloaddialog.ui b/src/forms/downloaddialog.ui deleted file mode 100644 index 2e21106..0000000 --- a/src/forms/downloaddialog.ui +++ /dev/null @@ -1,134 +0,0 @@ - - - DownloadDialog - - - - 0 - 0 - 820 - 480 - - - - Downloads - - - - - - - - - - - - 250 - 0 - - - - - 250 - 16777215 - - - - Details - - - - - - Type - - - - - - - - - - - - - - Path - - - - - - - Size - - - - - - - - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - - - - buttonBox - accepted() - DownloadDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - DownloadDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/forms/downloadsform.ui b/src/forms/downloadsform.ui new file mode 100644 index 0000000..5ab770f --- /dev/null +++ b/src/forms/downloadsform.ui @@ -0,0 +1,81 @@ + + + DownloadDialog + + + + 0 + 0 + 420 + 600 + + + + + 420 + 600 + + + + Downloads + + + + + + + + + Details + + + + + + Type + + + + + + + + + + + + + + Path + + + + + + + Size + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/forms/downloadswidget.cpp b/src/forms/downloadswidget.cpp new file mode 100644 index 0000000..45c458d --- /dev/null +++ b/src/forms/downloadswidget.cpp @@ -0,0 +1,77 @@ +/** LICENSE ******************************************************************** + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#include "downloadswidget.h" +#include "ui_downloadsform.h" + +#include +#include +#include +#include +#include +#include "widgets/downloaditemwidget.h" +#include "browser.h" + +DownloadsWidget::DownloadsWidget(QWidget *parent) : + DockingWidget(tr("Downloads"), parent), + ui(new Ui::DownloadDialog) +{ + ui->setupUi(this); + ui->filePath->setWordWrap(true); + + connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(showItemDetails(int))); +} + +DownloadsWidget::~DownloadsWidget() +{ + delete ui; +} + +void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) +{ + QString filepath = QFileDialog::getSaveFileName(this, tr("Save"), sSettings->value("downloads.path").toString() + "/" + QFileInfo(item->path()).fileName()); + + if(filepath.isEmpty()) { + // user cancelled the save dialog + item->cancel(); + return; + } + + item->setPath(filepath); + + QListWidgetItem *listItem = new QListWidgetItem(); + int rowIndex = ui->listWidget->count(); + ui->listWidget->insertItem(rowIndex, listItem); + + DownloadItemWidget *form = new DownloadItemWidget(item, this); + listItem->setSizeHint(form->size()); + ui->listWidget->setItemWidget(listItem, form); + + item->accept(); + this->show(); +} + +void DownloadsWidget::showItemDetails(int index) +{ + DownloadItemWidget *form = qobject_cast(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())); +} diff --git a/src/forms/downloadswidget.h b/src/forms/downloadswidget.h new file mode 100644 index 0000000..1ae29ee --- /dev/null +++ b/src/forms/downloadswidget.h @@ -0,0 +1,49 @@ +/** LICENSE ******************************************************************** + ** + ** smolbote: yet another qute browser + ** Copyright (C) 2017 Xian Nox + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + +#ifndef DOWNLOADDIALOG_H +#define DOWNLOADDIALOG_H + +#include "widgets/dockingwidget.h" + +namespace Ui { +class DownloadDialog; +} + +class QWebEngineDownloadItem; +class DownloadsWidget : public DockingWidget +{ + Q_OBJECT + +public: + explicit DownloadsWidget(QWidget *parent = 0); + ~DownloadsWidget(); + +public slots: + void addDownload(QWebEngineDownloadItem *item); + +private slots: + void showItemDetails(int index); + +private: + Ui::DownloadDialog *ui; +}; + +#endif // DOWNLOADDIALOG_H -- cgit v1.2.1