diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-12-08 21:01:02 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-12-08 21:01:02 +0100 |
commit | 44cbf54997f9a61836729d111cd9190df6250a4b (patch) | |
tree | 79ac9c3d71492d045bc7d3291754bb3a1765d5d7 | |
parent | Merge branch 'master' of neueland-git:smolbote (diff) | |
download | smolbote-44cbf54997f9a61836729d111cd9190df6250a4b.tar.xz |
Fixed showing bookmarks and downloads widgets
-rw-r--r-- | data/poi.cfg | 2 | ||||
-rw-r--r-- | src/browser.cpp | 9 | ||||
-rw-r--r-- | src/browser.h | 8 | ||||
-rw-r--r-- | src/mainwindow.cpp | 55 | ||||
-rw-r--r-- | src/mainwindow.h | 9 | ||||
-rw-r--r-- | src/widgets/mainwindowmenubar.cpp | 45 | ||||
-rw-r--r-- | src/widgets/mainwindowmenubar.h | 4 |
7 files changed, 86 insertions, 46 deletions
diff --git a/data/poi.cfg b/data/poi.cfg index 68503e1..0731ba2 100644 --- a/data/poi.cfg +++ b/data/poi.cfg @@ -50,9 +50,11 @@ profile = { // Bookmark settings bookmarks = { path = "~/.config/smolbote/bookmarks.xbel"; + shortcut = "Ctrl+B"; }; // Downloads settings downloads = { path = "~/Downloads" + shortcut = "Ctrl+D"; }; diff --git a/src/browser.cpp b/src/browser.cpp index 60b8810..354b179 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -19,9 +19,10 @@ ******************************************************************************/ #include "browser.h" +#include <bookmarks/bookmarkswidget.h> +#include <downloads/downloadswidget.h> #include "mainwindow.h" #include <QtWebEngine> - #include <QDir> Browser::Browser(int &argc, char *argv[]) : @@ -46,8 +47,8 @@ void Browser::setConfiguration(std::shared_ptr<Configuration> &config) { m_config = config; -// m_bookmarksManager = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value())); -// m_downloadManager = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value())); + m_bookmarksManager = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value())); + m_downloadManager = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value())); } void Browser::loadProfiles() @@ -118,6 +119,8 @@ MainWindow *Browser::createWindow() { // the window will delete itself when it closes, so we don't need to delete it MainWindow *window = new MainWindow(m_config); + window->setBookmarksWidget(m_bookmarksManager); + window->setDownloadsWidget(m_downloadManager); window->setProfile(m_defaultProfile); m_windows.append(window); diff --git a/src/browser.h b/src/browser.h index ee9e917..b3af5e6 100644 --- a/src/browser.h +++ b/src/browser.h @@ -22,8 +22,6 @@ #define BROWSER_H #include "singleapplication.h" -//#include <bookmarks/bookmarkswidget.h> -//#include <downloads/downloadswidget.h> #include "webengine/webengineprofile.h" //#include "filter/blockermanager.h" @@ -34,6 +32,8 @@ #include "settings/configuration.h" class MainWindow; +class BookmarksWidget; +class DownloadsWidget; class Browser : public SingleApplication { Q_OBJECT @@ -68,8 +68,8 @@ private: WebEngineProfile* m_defaultProfile; // UrlRequestInterceptor *m_urlRequestInterceptor = nullptr; -// std::shared_ptr<BookmarksWidget> m_bookmarksManager; -// std::shared_ptr<DownloadsWidget> m_downloadManager; + std::shared_ptr<BookmarksWidget> m_bookmarksManager; + std::shared_ptr<DownloadsWidget> m_downloadManager; // BlockerManager *m_blocklistManager = nullptr; }; 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()) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 4a0c87d..07c6b2f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -41,6 +41,9 @@ class MainWindow; } class Configuration; +class BookmarksWidget; +class DownloadsWidget; +class MainWindowMenuBar; class MainWindow : public QMainWindow { Q_OBJECT @@ -58,6 +61,8 @@ public slots: void newWindow(const QUrl &url = QUrl("")); void setProfile(WebEngineProfile *profile); + void setBookmarksWidget(std::shared_ptr<BookmarksWidget> &widget); + void setDownloadsWidget(std::shared_ptr<DownloadsWidget> &widget); void toggleFullscreen(); @@ -77,6 +82,8 @@ private: WebViewTabBar *tabBar; WebView *m_currentView; + MainWindowMenuBar *menuBar; + // navigation NavigationButton *m_backButton, *m_forwardButton, *m_reloadButton; AddressBar *m_addressBar; @@ -84,6 +91,8 @@ private: bool m_tabBarAdded = false; std::shared_ptr<Configuration> m_config; + std::shared_ptr<BookmarksWidget> m_bookmarksWidget; + std::shared_ptr<DownloadsWidget> m_downloadsWidget; }; #endif // MAINWINDOW_H diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp index c233d29..992163e 100644 --- a/src/widgets/mainwindowmenubar.cpp +++ b/src/widgets/mainwindowmenubar.cpp @@ -59,33 +59,16 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, Main // Tools menu QMenu *toolsMenu = new QMenu(tr("Tools"), this); addMenu(toolsMenu); - QAction *downloadsAction = toolsMenu->addAction(tr("Downloads")); - downloadsAction->setParent(parent); - //downloadsAction->setShortcut(QKeySequence::fromString(browser->settings()->value("downloads.dialogShortcut").toString())); - //connect(downloadsAction, &QAction::triggered, this, [&]() { - // m_parentWindow->addTabbedDock(Qt::RightDockWidgetArea, browser->downloads()); - //}); - - QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks")); - bookmarksAction->setParent(parent); - //bookmarksAction->setShortcut(QKeySequence(browser->settings()->value("bookmarks.dialogShortcut").toString())); - //connect(bookmarksAction, &QAction::triggered, this, [&]() { - // m_parentWindow->addTabbedDock(Qt::RightDockWidgetArea, browser->bookmarks()); - //}); - toolsMenu->addSeparator(); - //toolsMenu->addAction(tr("Filter"), browser->blocklists(), SLOT(show()), QKeySequence::fromString(browser->settings()->value("blocker.shortcut").toString())); - // Plugins -// if(qApp->plugin("")) { -// GuiInterface *gui = qobject_cast<GuiInterface *>(qApp->plugin("")); -// if(gui) { -// toolsMenu->addAction(gui->action()); -// } else { -// qDebug("Plugin doesn't gui"); -// } -// } else { -// qDebug("No plugin!"); -// } + m_downloadsAction = toolsMenu->addAction(tr("Downloads")); + m_downloadsAction->setParent(parent); + m_downloadsAction->setShortcut(QKeySequence(config->value<std::string>("downloads.shortcut").value().c_str())); + + m_bookmarksAction = toolsMenu->addAction(tr("Bookmarks")); + m_bookmarksAction->setParent(parent); + m_bookmarksAction->setShortcut(QKeySequence(config->value<std::string>("bookmarks.shortcut").value().c_str())); + + //toolsMenu->addAction(tr("Filter"), browser->blocklists(), SLOT(show()), QKeySequence::fromString(browser->settings()->value("blocker.shortcut").toString())); // Profile menu QMenu *profileMenu = new QMenu(tr("Profile"), this); @@ -100,6 +83,16 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, Main pageMenu->addAction(tr("Zoom"))->setEnabled(false); } +QAction *MainWindowMenuBar::bookmarksAction() +{ + return m_bookmarksAction; +} + +QAction *MainWindowMenuBar::downloadsAction() +{ + return m_downloadsAction; +} + QAction *MainWindowMenuBar::printAction() { return m_printAction; diff --git a/src/widgets/mainwindowmenubar.h b/src/widgets/mainwindowmenubar.h index e5e5f38..bbfc3fc 100644 --- a/src/widgets/mainwindowmenubar.h +++ b/src/widgets/mainwindowmenubar.h @@ -32,12 +32,16 @@ class MainWindowMenuBar : public QMenuBar public: explicit MainWindowMenuBar(std::shared_ptr<Configuration> config, MainWindow *parent = nullptr); + QAction *bookmarksAction(); + QAction *downloadsAction(); QAction *printAction(); private slots: void handleLoadProfile(MainWindow *window); private: + QAction *m_bookmarksAction; + QAction *m_downloadsAction; QAction *m_printAction; }; |