aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 28a0ebb..bf70710 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -35,6 +35,9 @@
#include <settings/configuration.h>
+#include <bookmarks/bookmarkswidget.h>
+#include <downloads/downloadswidget.h>
+
MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
@@ -63,7 +66,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent) :
setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North);
// Main menu
- MainWindowMenuBar *menuBar = new MainWindowMenuBar(config, this);
+ menuBar = new MainWindowMenuBar(config, this);
menuBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
connect(menuBar->printAction(), &QAction::triggered, this, [&]() {
@@ -113,17 +116,6 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> config, QWidget *parent) :
});
connect(tabBar, SIGNAL(currentTabChanged(WebView*)), this, SLOT(handleTabChanged(WebView*)));
-// connect(browser->bookmarks(), &BookmarksWidget::openUrl, this, [&](const QUrl &url) {
-// if(this->isActiveWindow()) {
-// this->newTab(url);
-// }
-// });
-
- // Load profile
- //tabBar->setProfile(browser->profile(browser->settings()->value("browser.profile.default").toString()));
- // Adding a tab here, because otherwise tabs won't show up
- //newTab();
-
// loading bar
ui->statusBar->addPermanentWidget(m_progressBar);
@@ -155,8 +147,19 @@ MainWindow::~MainWindow()
void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget)
{
- // create a list for the dock widgets we're appending to
+ // get all dock widgets
QList<QDockWidget*> allDockWidgets = findChildren<QDockWidget*>();
+
+ // check if the widget we're adding is there already
+ for(QDockWidget *w : allDockWidgets) {
+ if(w->widget() == widget) {
+ // widget is already shown --> return
+ w->show();
+ return;
+ }
+ }
+
+ // we haven't shown this widget, so let's make a list of widgets in the area we want
QVector<QDockWidget*> areaDockWidgets;
for(QDockWidget *w : allDockWidgets) {
if(dockWidgetArea(w) == area) {
@@ -164,6 +167,8 @@ void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget)
}
}
+ // create a dock widget
+ // this dock widget will be destroyed with the MainWindow
QDockWidget *dock = new QDockWidget(widget->windowTitle(), this);
dock->setWidget(widget);
@@ -171,6 +176,7 @@ void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QWidget *widget)
// no other widgets
addDockWidget(area, dock);
} else {
+ // there are other widgets, so put it after the last one
tabifyDockWidget(areaDockWidgets.last(), dock);
}
}
@@ -213,6 +219,29 @@ void MainWindow::setProfile(WebEngineProfile *profile)
tabBar->setProfile(profile);
}
+void MainWindow::setBookmarksWidget(std::shared_ptr<BookmarksWidget> &widget)
+{
+ Q_ASSERT(widget);
+ m_bookmarksWidget = widget;
+ connect(menuBar->bookmarksAction(), &QAction::triggered, this, [this]() {
+ addTabbedDock(Qt::RightDockWidgetArea, m_bookmarksWidget.get());
+ });
+ connect(m_bookmarksWidget.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) {
+ if(isActiveWindow()) {
+ newTab(url);
+ }
+ });
+}
+
+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()
{
if(isFullScreen()) {