From 6e158f3e228628caadd6997065eec6c00267524a Mon Sep 17 00:00:00 2001 From: aqua Date: Wed, 14 Sep 2022 15:21:28 +0300 Subject: Add Bookmarks toolbar --- src/bookmarks/CMakeLists.txt | 3 +- src/bookmarks/bookmarksmenu.cpp | 2 - src/bookmarks/bookmarksmenu.hpp | 2 - src/bookmarks/bookmarkstoolbar.cpp | 93 ++++++++++++++++---------------------- src/bookmarks/bookmarkstoolbar.h | 67 --------------------------- src/bookmarks/bookmarkstoolbar.hpp | 58 ++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 126 deletions(-) delete mode 100644 src/bookmarks/bookmarkstoolbar.h create mode 100644 src/bookmarks/bookmarkstoolbar.hpp (limited to 'src/bookmarks') diff --git a/src/bookmarks/CMakeLists.txt b/src/bookmarks/CMakeLists.txt index 1d0f846f..d2651ce9 100644 --- a/src/bookmarks/CMakeLists.txt +++ b/src/bookmarks/CMakeLists.txt @@ -1,6 +1,4 @@ add_library(bookmarks STATIC -# bookmarkowner.cpp bookmarkowner.h -# bookmarkstoolbar.cpp bookmarkstoolbar.h # Bookmarks Model bookmark.cpp bookmark.hpp bookmarkstreeitem.cpp bookmarkstreeitem.hpp @@ -9,6 +7,7 @@ add_library(bookmarks STATIC bookmarkstreeformat_xbel_read.cpp bookmarkstreeformat_xbel_write.cpp # UI bookmarksmenu.cpp bookmarksmenu.hpp + bookmarkstoolbar.cpp bookmarkstoolbar.hpp ) target_include_directories(bookmarks PUBLIC ${CMAKE_SOURCE_DIR}/src) target_link_libraries(bookmarks PUBLIC Qt6::Core Qt6::Widgets) diff --git a/src/bookmarks/bookmarksmenu.cpp b/src/bookmarks/bookmarksmenu.cpp index 761a0026..aad7289e 100644 --- a/src/bookmarks/bookmarksmenu.cpp +++ b/src/bookmarks/bookmarksmenu.cpp @@ -6,8 +6,6 @@ * Copyright (C) 2010 by Yoann Laissus * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua - * ============================================================ - * Description: rekonq bookmarks menu * ============================================================ */ #include "bookmarksmenu.hpp" diff --git a/src/bookmarks/bookmarksmenu.hpp b/src/bookmarks/bookmarksmenu.hpp index ad175991..f162244e 100644 --- a/src/bookmarks/bookmarksmenu.hpp +++ b/src/bookmarks/bookmarksmenu.hpp @@ -6,8 +6,6 @@ * Copyright (C) 2010 by Yoann Laissus * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua - * ============================================================ - * Description: rekonq bookmarks menu * ============================================================ */ #pragma once diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index 658aa0c0..353e61b9 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -1,70 +1,56 @@ /* ============================================================ - * - * This file is a part of the rekonq project - * + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later * Copyright (C) 2008-2013 by Andrea Diamantini * Copyright (C) 2010 by Yoann Laissus - * - * - * 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 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * 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 . - * + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua * ============================================================ */ -// Self Includes -#include "bookmarkstoolbar.h" -#include "bookmarkstoolbar.moc" +#include "bookmarkstoolbar.hpp" +#include "bookmarkstreemodel.hpp" +#include -// Local Includes -#include "bookmarkmanager.h" -#include "bookmarkowner.h" -#include "bookmarkscontextmenu.h" +BookmarkToolBar::BookmarkToolBar(QWidget *parent) : QToolBar(parent) +{ + /* +setContextMenuPolicy(Qt::CustomContextMenu); -#include "iconmanager.h" -#include "webwindow.h" +connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint))); +connect(BookmarkManager::self()->manager(), SIGNAL(changed(QString, QString)), this, SLOT(hideMenu())); -// KDE Includes -#include +setAcceptDrops(true); +installEventFilter(this); +setShortcutEnabled(false); -// Qt Includes -#include -#include -#include +if (isVisible()) { + BookmarkManager::self()->fillBookmarkBar(this); + m_filled = true; +} +*/ +} -BookmarkToolBar::BookmarkToolBar(QWidget *parent) - : KToolBar(parent, false, false), m_currentMenu(0), m_dragAction(0), m_dropAction(0), m_checkedAction(0), - m_filled(false) +void BookmarkToolBar::showEvent(QShowEvent *event) { - setContextMenuPolicy(Qt::CustomContextMenu); - - connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint))); - connect(BookmarkManager::self()->manager(), SIGNAL(changed(QString, QString)), this, SLOT(hideMenu())); - - setAcceptDrops(true); - installEventFilter(this); - setShortcutEnabled(false); - - if (isVisible()) { - BookmarkManager::self()->fillBookmarkBar(this); - m_filled = true; + Q_CHECK_PTR(model); + + clear(); + + const auto *root = model->item(); + Q_CHECK_PTR(root); + for (int i = 0; i < root->childCount(); ++i) { + const auto *child = root->child(i); + if (child->type() != BookmarksTreeItem::Bookmark) continue; + auto *action = addAction(child->data(BookmarksTreeItem::Title).toString(), this, [this, child]() { + emit loadUrl(child->data(BookmarksTreeItem::Href).toUrl(), rekonq::CurrentTab); + }); } -} -BookmarkToolBar::~BookmarkToolBar() { clear(); } + event->accept(); +} +/* void BookmarkToolBar::contextMenu(const QPoint &point) { KBookmarkActionInterface *action = dynamic_cast(actionAt(point)); @@ -402,3 +388,4 @@ void BookmarkToolBar::dragDestroyed() delete m_dropAction; m_dropAction = 0; } +*/ diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h deleted file mode 100644 index d325def4..00000000 --- a/src/bookmarks/bookmarkstoolbar.h +++ /dev/null @@ -1,67 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2013 by Andrea Diamantini -* Copyright (C) 2010 by Yoann Laissus -* -* -* 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 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* 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 BOOKMARKSTOOLBAR_H -#define BOOKMARKSTOOLBAR_H - -#include "rekonq.hpp" -#include - -/** - * This class manage the bookmark toolbar. - * Some events from the toolbar are handled to allow the drag and drop - */ - -class BookmarkToolBar : public QToolBar { - Q_OBJECT - -public: - explicit BookmarkToolBar(QWidget *parent); - ~BookmarkToolBar(); - -protected: - bool eventFilter(QObject *watched, QEvent *event); - -private Q_SLOTS: - void contextMenu(const QPoint &); - void menuDisplayed(); - void menuHidden(); - void hideMenu(); - void dragDestroyed(); - -private: - void startDrag(); - - KMenu *m_currentMenu; - QPoint m_startDragPos; - QAction *m_dragAction; - QAction *m_dropAction; - QAction *m_checkedAction; - bool m_filled; -}; - -#endif // BOOKMARKSTOOLBAR_H diff --git a/src/bookmarks/bookmarkstoolbar.hpp b/src/bookmarks/bookmarkstoolbar.hpp new file mode 100644 index 00000000..6aaa750a --- /dev/null +++ b/src/bookmarks/bookmarkstoolbar.hpp @@ -0,0 +1,58 @@ +/* ============================================================ + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2008-2013 by Andrea Diamantini + * Copyright (C) 2010 by Yoann Laissus + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua + * ============================================================ */ + +#pragma once + +#include "rekonq.hpp" +#include + +class BookmarksTreeModel; + +/** + * This class manage the bookmark toolbar. + * Some events from the toolbar are handled to allow the drag and drop + */ +class BookmarkToolBar : public QToolBar { + Q_OBJECT + +public: + explicit BookmarkToolBar(QWidget *parent = nullptr); + ~BookmarkToolBar() override = default; + + void setModel(BookmarksTreeModel *ptr) + { + Q_CHECK_PTR(ptr); + model = ptr; + } + +signals: + void loadUrl(const QUrl &url, rekonq::OpenType type); + +protected: + void showEvent(QShowEvent *event) override; + // bool eventFilter(QObject *watched, QEvent *event); + +private slots: + // void contextMenu(const QPoint &); + // void menuDisplayed(); + // void menuHidden(); + // void hideMenu(); + // void dragDestroyed(); + +private: + BookmarksTreeModel *model = nullptr; + void startDrag(); + + QPoint m_startDragPos; + QAction *m_dragAction = nullptr; + QAction *m_dropAction = nullptr; + QAction *m_checkedAction = nullptr; + bool m_filled = false; +}; -- cgit v1.2.1