From eea675e1f33d29550c9f3e90eb6b6b2402e5ef37 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 28 Jan 2020 14:59:23 +0200 Subject: Add bookmarks toolbar Bookmarks Toolbar displays the contents of the top-level "Bookmarks Toolbar" folder. --- src/bookmarks/bookmarkstoolbar.cpp | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/bookmarks/bookmarkstoolbar.cpp (limited to 'src/bookmarks/bookmarkstoolbar.cpp') diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp new file mode 100644 index 0000000..11dd712 --- /dev/null +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -0,0 +1,62 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "bookmarkstoolbar.h" +#include "bookmarkmodel.h" +#include "mainwindow/mainwindow.h" +#include + +BookmarksToolbar::BookmarksToolbar(const BookmarkModel *model, MainWindow *parent) + : QToolBar(parent) +{ + m_window = parent; + + const auto *root = model->root(); + for(int i = 0; i < root->childCount(); ++i) { + const auto *child = root->child(i); + if(child->type() == BookmarkItem::Folder && child->data(BookmarkItem::Title).toString() == "Bookmarks Toolbar") { + addFolder(child); + break; + } + } +} + +void BookmarksToolbar::addBookmark(const BookmarkItem *item, QMenu *where) +{ + QAction *action = nullptr; + if(where) + action = where->addAction(item->data(BookmarkItem::Title).toString()); + else + action = addAction(item->data(BookmarkItem::Title).toString()); + + action->setIcon(item->icon()); + + const auto url = item->data(BookmarkItem::Href).toUrl(); + connect(action, &QAction::triggered, m_window, [this, url]() { + m_window->createTab(url); + }); +} + +void BookmarksToolbar::addFolder(const BookmarkItem *item, QMenu *where) +{ + for(int i = 0; i < item->childCount(); ++i) { + auto *child = item->child(i); + + if(child->type() == BookmarkItem::Bookmark) + addBookmark(child, where); + + else if(child->type() == BookmarkItem::Folder) { + auto *action = addAction(child->data(BookmarkItem::Title).toString()); + //action->setIcon(child->icon()); + + auto *menu = new QMenu(this); + addFolder(child, menu); + action->setMenu(menu); + } + } +} -- cgit v1.2.1