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/browser.cpp | 7 +- src/browser.h | 6 +- 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 ++++++++++++++ src/mainwindow.cpp | 23 ++++++- src/mainwindow.h | 2 + src/webengine/downloaditemform.cpp | 102 ---------------------------- src/webengine/downloaditemform.h | 52 -------------- src/webengine/downloaditemform.ui | 53 --------------- src/widgets/dockingwidget.cpp | 82 +++++++++++++++++++++++ src/widgets/dockingwidget.h | 55 +++++++++++++++ src/widgets/downloaditemform.ui | 53 +++++++++++++++ src/widgets/downloaditemwidget.cpp | 102 ++++++++++++++++++++++++++++ src/widgets/downloaditemwidget.h | 52 ++++++++++++++ 20 files changed, 585 insertions(+), 516 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 delete mode 100644 src/webengine/downloaditemform.cpp delete mode 100644 src/webengine/downloaditemform.h delete mode 100644 src/webengine/downloaditemform.ui create mode 100644 src/widgets/dockingwidget.cpp create mode 100644 src/widgets/dockingwidget.h create mode 100644 src/widgets/downloaditemform.ui create mode 100644 src/widgets/downloaditemwidget.cpp create mode 100644 src/widgets/downloaditemwidget.h (limited to 'src') diff --git a/src/browser.cpp b/src/browser.cpp index f96a881..0135a4c 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -100,7 +100,7 @@ bool Browser::preLaunch(QStringList urls) m_networkAccessManager = new QNetworkAccessManager(); m_bookmarksManager = new BookmarksWidget; - m_downloadManager = new DownloadDialog; + m_downloadManager = new DownloadsWidget; QtWebEngine::initialize(); @@ -127,7 +127,7 @@ BookmarksWidget *Browser::bookmarks() return m_bookmarksManager; } -DownloadDialog *Browser::downloads() +DownloadsWidget *Browser::downloads() { return m_downloadManager; } @@ -150,8 +150,7 @@ void Browser::setConfigPath(const QString &path) #ifdef Q_OS_LINUX else if(QFile::exists("/usr/share/smolbote/poi.conf")) { m_settings = new Settings("/usr/share/smolbote/poi.conf"); - } - else if(QFile::exists("/usr/local/share/smolbote/poi.conf")) { + } else if(QFile::exists("/usr/local/share/smolbote/poi.conf")) { m_settings = new Settings("/usr/local/share/smolbote/poi.conf"); } #endif diff --git a/src/browser.h b/src/browser.h index 41a55f3..9d75036 100644 --- a/src/browser.h +++ b/src/browser.h @@ -24,7 +24,7 @@ #include #include #include "forms/bookmarkswidget.h" -#include "forms/downloaddialog.h" +#include "forms/downloadswidget.h" #include #include "settings.h" #include @@ -55,7 +55,7 @@ public: Settings *settings(); QNetworkAccessManager *network(); BookmarksWidget *bookmarks(); - DownloadDialog *downloads(); + DownloadsWidget *downloads(); void setConfigPath(const QString &path); void addWindow(MainWindow* window); @@ -73,7 +73,7 @@ private: QVector m_windows; QNetworkAccessManager *m_networkAccessManager; BookmarksWidget *m_bookmarksManager; - DownloadDialog *m_downloadManager; + DownloadsWidget *m_downloadManager; }; 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 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5cf9590..eaf061e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -41,6 +41,9 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : { // set up UI ui->setupUi(this); + setDockOptions(dockOptions() | AllowTabbedDocks | ForceTabbedDocks); + setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North); + setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); QMenuBar *menuBar = new QMenuBar(this); menuBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); @@ -59,6 +62,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : QMenu *toolsMenu = new QMenu(tr("Tools"), menuBar); menuBar->addMenu(toolsMenu); QAction *downloadsAction = toolsMenu->addAction(tr("Downloads"), Browser::instance()->downloads(), SLOT(show())); + downloadsAction->setParent(this); downloadsAction->setShortcut(QKeySequence::fromString(sSettings->value("downloads.dialogShortcut").toString())); QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks"), Browser::instance()->bookmarks(), SLOT(show())); bookmarksAction->setParent(this); @@ -125,10 +129,27 @@ MainWindow::MainWindow(const QStringList urlList, QWidget *parent) : MainWindow::~MainWindow() { - qApp->bookmarks()->setParent(0); delete ui; } +void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget) +{ + QList allDockWidgets = findChildren(); + QVector areaDockWidgets; + for(QDockWidget *w : allDockWidgets) { + if(dockWidgetArea(w) == area) { + areaDockWidgets.append(w); + } + } + + if(areaDockWidgets.empty()) { + // no other widgets + addDockWidget(area, widget); + } else { + tabifyDockWidget(areaDockWidgets.last(), widget); + } +} + void MainWindow::addNewTab(const QUrl &url) { if(!url.isEmpty()) { diff --git a/src/mainwindow.h b/src/mainwindow.h index da2b429..c032d5a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -46,6 +46,8 @@ public: MainWindow(const QStringList urlList, QWidget *parent = 0); ~MainWindow(); + void addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget); + void loadProfile(const QString &name); public slots: diff --git a/src/webengine/downloaditemform.cpp b/src/webengine/downloaditemform.cpp deleted file mode 100644 index 61d954d..0000000 --- a/src/webengine/downloaditemform.cpp +++ /dev/null @@ -1,102 +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 "downloaditemform.h" -#include "ui_downloaditemform.h" - -#include -#include - -DownloadItemForm::DownloadItemForm(QWebEngineDownloadItem *item, QWidget *parent) : - QWidget(parent), - ui(new Ui::DownloadItemForm) -{ - m_item = item; - - ui->setupUi(this); - ui->url_label->setText(item->url().toString()); - - 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())); -} - -DownloadItemForm::~DownloadItemForm() -{ - delete ui; -} - -QWebEngineDownloadItem *DownloadItemForm::item() const -{ - return m_item; -} - -QString DownloadItemForm::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 DownloadItemForm::updateState(QWebEngineDownloadItem::DownloadState state) -{ - switch (state) { - case QWebEngineDownloadItem::DownloadRequested: - ui->status_label->setText(tr("Requested")); - break; - case QWebEngineDownloadItem::DownloadInProgress: - ui->status_label->setText(tr("In progress")); - break; - case QWebEngineDownloadItem::DownloadCompleted: - ui->status_label->setText(tr("Completed")); - break; - case QWebEngineDownloadItem::DownloadCancelled: - ui->status_label->setText(tr("Cancelled")); - break; - case QWebEngineDownloadItem::DownloadInterrupted: - ui->status_label->setText(tr("Interrupted")); - break; - default: - break; - } -} - -void DownloadItemForm::updateProgress(qint64 value, qint64 total) -{ - ui->progressBar->setMaximum(total); - ui->progressBar->setValue(value); - ui->filesize_label->setText(QString("%1 / %2").arg(sizeString(value)).arg(sizeString(total))); -} - -void DownloadItemForm::updateFinished() -{ - ui->progressBar->setMaximum(100); - ui->progressBar->setValue(100); -} diff --git a/src/webengine/downloaditemform.h b/src/webengine/downloaditemform.h deleted file mode 100644 index b4cb0e5..0000000 --- a/src/webengine/downloaditemform.h +++ /dev/null @@ -1,52 +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 DOWNLOADITEMFORM_H -#define DOWNLOADITEMFORM_H - -#include -#include - -namespace Ui { -class DownloadItemForm; -} - -class DownloadItemForm : public QWidget -{ - Q_OBJECT - -public: - explicit DownloadItemForm(QWebEngineDownloadItem *item, QWidget *parent = 0); - ~DownloadItemForm(); - - QWebEngineDownloadItem *item() const; - QString sizeString(int size) const; - -private slots: - void updateState(QWebEngineDownloadItem::DownloadState state); - void updateProgress(qint64 value, qint64 total); - void updateFinished(); - -private: - Ui::DownloadItemForm *ui; - QWebEngineDownloadItem *m_item; -}; - -#endif // DOWNLOADITEMFORM_H diff --git a/src/webengine/downloaditemform.ui b/src/webengine/downloaditemform.ui deleted file mode 100644 index 8a8d148..0000000 --- a/src/webengine/downloaditemform.ui +++ /dev/null @@ -1,53 +0,0 @@ - - - DownloadItemForm - - - - 0 - 0 - 500 - 70 - - - - Form - - - - - - [url] - - - - - - - - - Unknown - - - - - - - x MiB / y MiB - - - - - - - 24 - - - - - - - - - - diff --git a/src/widgets/dockingwidget.cpp b/src/widgets/dockingwidget.cpp new file mode 100644 index 0000000..d7f7d30 --- /dev/null +++ b/src/widgets/dockingwidget.cpp @@ -0,0 +1,82 @@ +/** 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 "dockingwidget.h" +#include "mainwindow.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(); +} + +DockingWidget::DockingWidget(const QString &title, QWidget *parent) : + QWidget(parent) +{ + window = nullptr; + dock = new DockWidget(title, 0); + dock->setWidget(this); + dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + connect(qApp, &QApplication::aboutToQuit, [this]() { + this->setParent(0); + }); +} + +DockingWidget::~DockingWidget() +{ + // If the dock has a parent, it will take care of it + // calling delete later here if the dock has a parent causes a crash + if(!dock->parent()) { + dock->deleteLater(); + } +} + +void DockingWidget::show() +{ + MainWindow *caller = qobject_cast(sender()->parent()); + // if already shown and on the same window - hide the widget + if(isVisible() && window == caller) { + dock->setParent(0); + return; + } + + // show() gets called by a QAction in MainWindow + window = caller; + if(window) { + + // dockable widgets + dock->setParent(window); + //window->addDockWidget(Qt::RightDockWidgetArea, dock); + window->addTabbedDock(Qt::RightDockWidgetArea, dock); + + } else { + qWarning("DockingWidget not called by MainWindow"); + } + + QWidget::show(); +} diff --git a/src/widgets/dockingwidget.h b/src/widgets/dockingwidget.h new file mode 100644 index 0000000..bd1d210 --- /dev/null +++ b/src/widgets/dockingwidget.h @@ -0,0 +1,55 @@ +/** 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 DOCKINGWIDGET_H +#define DOCKINGWIDGET_H + +#include +#include + +// Subclass DockWidget to disable QDockWidget from committing sudoku when closing +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); +}; + +class MainWindow; +class DockingWidget : public QWidget +{ + Q_OBJECT +public: + explicit DockingWidget(const QString &title, QWidget *parent = 0); + ~DockingWidget(); + +public slots: + void show(); + +private: + MainWindow *window; + DockWidget *dock; +}; + +#endif // DOCKINGWIDGET_H diff --git a/src/widgets/downloaditemform.ui b/src/widgets/downloaditemform.ui new file mode 100644 index 0000000..8a8d148 --- /dev/null +++ b/src/widgets/downloaditemform.ui @@ -0,0 +1,53 @@ + + + DownloadItemForm + + + + 0 + 0 + 500 + 70 + + + + Form + + + + + + [url] + + + + + + + + + Unknown + + + + + + + x MiB / y MiB + + + + + + + 24 + + + + + + + + + + diff --git a/src/widgets/downloaditemwidget.cpp b/src/widgets/downloaditemwidget.cpp new file mode 100644 index 0000000..78b8a7c --- /dev/null +++ b/src/widgets/downloaditemwidget.cpp @@ -0,0 +1,102 @@ +/** 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 "downloaditemwidget.h" +#include "ui_downloaditemform.h" + +#include +#include + +DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent) : + QWidget(parent), + ui(new Ui::DownloadItemForm) +{ + m_item = item; + + ui->setupUi(this); + ui->url_label->setText(item->url().toString()); + + 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())); +} + +DownloadItemWidget::~DownloadItemWidget() +{ + delete ui; +} + +QWebEngineDownloadItem *DownloadItemWidget::item() const +{ + return m_item; +} + +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) { + case QWebEngineDownloadItem::DownloadRequested: + ui->status_label->setText(tr("Requested")); + break; + case QWebEngineDownloadItem::DownloadInProgress: + ui->status_label->setText(tr("In progress")); + break; + case QWebEngineDownloadItem::DownloadCompleted: + ui->status_label->setText(tr("Completed")); + break; + case QWebEngineDownloadItem::DownloadCancelled: + ui->status_label->setText(tr("Cancelled")); + break; + case QWebEngineDownloadItem::DownloadInterrupted: + ui->status_label->setText(tr("Interrupted")); + break; + default: + break; + } +} + +void DownloadItemWidget::updateProgress(qint64 value, qint64 total) +{ + ui->progressBar->setMaximum(total); + ui->progressBar->setValue(value); + ui->filesize_label->setText(QString("%1 / %2").arg(sizeString(value)).arg(sizeString(total))); +} + +void DownloadItemWidget::updateFinished() +{ + ui->progressBar->setMaximum(100); + ui->progressBar->setValue(100); +} diff --git a/src/widgets/downloaditemwidget.h b/src/widgets/downloaditemwidget.h new file mode 100644 index 0000000..a27f9a8 --- /dev/null +++ b/src/widgets/downloaditemwidget.h @@ -0,0 +1,52 @@ +/** 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 DOWNLOADITEMFORM_H +#define DOWNLOADITEMFORM_H + +#include +#include + +namespace Ui { +class DownloadItemForm; +} + +class DownloadItemWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); + ~DownloadItemWidget(); + + QWebEngineDownloadItem *item() const; + QString sizeString(int size) const; + +private slots: + void updateState(QWebEngineDownloadItem::DownloadState state); + void updateProgress(qint64 value, qint64 total); + void updateFinished(); + +private: + Ui::DownloadItemForm *ui; + QWebEngineDownloadItem *m_item; +}; + +#endif // DOWNLOADITEMFORM_H -- cgit v1.2.1