| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Assistant of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | #ifndef BOOKMARKMANAGER_H |
| 29 | #define BOOKMARKMANAGER_H |
| 30 | |
| 31 | #include <QtCore/QMutex> |
| 32 | #include <QtWidgets/QTreeView> |
| 33 | |
| 34 | #include "ui_bookmarkwidget.h" |
| 35 | |
| 36 | QT_BEGIN_NAMESPACE |
| 37 | |
| 38 | class BookmarkManagerWidget; |
| 39 | class BookmarkModel; |
| 40 | class BookmarkFilterModel; |
| 41 | class QKeyEvent; |
| 42 | class QSortFilterProxyModel; |
| 43 | class QToolBar; |
| 44 | |
| 45 | class BookmarkManager : public QObject |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | class BookmarkWidget; |
| 49 | class BookmarkTreeView; |
| 50 | class BookmarkListView; |
| 51 | Q_DISABLE_COPY(BookmarkManager) |
| 52 | |
| 53 | public: |
| 54 | static BookmarkManager* instance(); |
| 55 | static void destroy(); |
| 56 | |
| 57 | QWidget* bookmarkDockWidget() const; |
| 58 | void setBookmarksMenu(QMenu* menu); |
| 59 | void setBookmarksToolbar(QToolBar *toolBar); |
| 60 | |
| 61 | public slots: |
| 62 | void addBookmark(const QString &title, const QString &url); |
| 63 | |
| 64 | signals: |
| 65 | void escapePressed(); |
| 66 | void setSource(const QUrl &url); |
| 67 | void setSourceInNewTab(const QUrl &url); |
| 68 | |
| 69 | private: |
| 70 | BookmarkManager(); |
| 71 | ~BookmarkManager() override; |
| 72 | |
| 73 | void removeItem(const QModelIndex &index); |
| 74 | bool eventFilter(QObject *object, QEvent *event) override; |
| 75 | void buildBookmarksMenu(const QModelIndex &index, QMenu *menu); |
| 76 | void showBookmarkDialog(const QString &name, const QString &url); |
| 77 | |
| 78 | private slots: |
| 79 | void setupFinished(); |
| 80 | void storeBookmarks(); |
| 81 | |
| 82 | void addBookmarkActivated(); |
| 83 | void removeBookmarkActivated(); |
| 84 | void manageBookmarks(); |
| 85 | void refreshBookmarkMenu(); |
| 86 | void refreshBookmarkToolBar(); |
| 87 | void renameBookmark(const QModelIndex &index); |
| 88 | |
| 89 | void setSourceFromAction(); |
| 90 | void setSourceFromIndex(const QModelIndex &index, bool newTab); |
| 91 | |
| 92 | void focusInEventOccurred(); |
| 93 | void managerWidgetAboutToClose(); |
| 94 | void textChanged(const QString &text); |
| 95 | void customContextMenuRequested(const QPoint &point); |
| 96 | |
| 97 | private: |
| 98 | bool typeAndSearch = false; |
| 99 | |
| 100 | static QMutex mutex; |
| 101 | static BookmarkManager *bookmarkManager; |
| 102 | |
| 103 | QMenu *bookmarkMenu = nullptr; |
| 104 | QToolBar *m_toolBar = nullptr; |
| 105 | |
| 106 | BookmarkModel *bookmarkModel; |
| 107 | BookmarkFilterModel *bookmarkFilterModel = nullptr; |
| 108 | QSortFilterProxyModel *typeAndSearchModel = nullptr; |
| 109 | |
| 110 | BookmarkWidget *bookmarkWidget; |
| 111 | BookmarkTreeView *bookmarkTreeView; |
| 112 | BookmarkManagerWidget *bookmarkManagerWidget = nullptr; |
| 113 | }; |
| 114 | |
| 115 | class BookmarkManager::BookmarkWidget : public QWidget |
| 116 | { |
| 117 | Q_OBJECT |
| 118 | public: |
| 119 | BookmarkWidget(QWidget *parent = nullptr) |
| 120 | : QWidget(parent) { ui.setupUi(this); } |
| 121 | virtual ~BookmarkWidget() override {} |
| 122 | |
| 123 | Ui::BookmarkWidget ui; |
| 124 | |
| 125 | signals: |
| 126 | void focusInEventOccurred(); |
| 127 | |
| 128 | private: |
| 129 | void focusInEvent(QFocusEvent *event) override; |
| 130 | }; |
| 131 | |
| 132 | class BookmarkManager::BookmarkTreeView : public QTreeView |
| 133 | { |
| 134 | Q_OBJECT |
| 135 | public: |
| 136 | BookmarkTreeView(QWidget *parent = nullptr); |
| 137 | ~BookmarkTreeView() override {} |
| 138 | |
| 139 | void subclassKeyPressEvent(QKeyEvent *event); |
| 140 | |
| 141 | signals: |
| 142 | void editingDone(); |
| 143 | |
| 144 | protected slots: |
| 145 | void commitData(QWidget *editor) override; |
| 146 | |
| 147 | private slots: |
| 148 | void setExpandedData(const QModelIndex &index); |
| 149 | }; |
| 150 | |
| 151 | QT_END_NAMESPACE |
| 152 | |
| 153 | #endif // BOOKMARKMANAGER_H |
| 154 |
