File indexing completed on 2024-05-12 04:57:59
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2014 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #ifndef BOOKMARKSTREEVIEW_H 0019 #define BOOKMARKSTREEVIEW_H 0020 0021 #include <QTreeView> 0022 0023 #include "qzcommon.h" 0024 0025 class Bookmarks; 0026 class BookmarkItem; 0027 class BookmarksModel; 0028 class BookmarksFilterModel; 0029 0030 class FALKON_EXPORT BookmarksTreeView : public QTreeView 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 enum ViewType { 0036 BookmarksManagerViewType, 0037 BookmarksSidebarViewType 0038 }; 0039 0040 explicit BookmarksTreeView(QWidget* parent = nullptr); 0041 0042 ViewType viewType() const; 0043 void setViewType(ViewType type); 0044 0045 // Returns null if more than one (or zero) bookmarks are selected 0046 BookmarkItem* selectedBookmark() const; 0047 // Returns all selected bookmarks 0048 QList<BookmarkItem*> selectedBookmarks() const; 0049 0050 void selectBookmark(BookmarkItem* item); 0051 // Expand up to root item 0052 void ensureBookmarkVisible(BookmarkItem* item); 0053 0054 public Q_SLOTS: 0055 void search(const QString &string); 0056 0057 Q_SIGNALS: 0058 // Open bookmark in current tab 0059 void bookmarkActivated(BookmarkItem* item); 0060 // Open bookmark in new tab 0061 void bookmarkCtrlActivated(BookmarkItem* item); 0062 // Open bookmark in new window 0063 void bookmarkShiftActivated(BookmarkItem* item); 0064 // Context menu signal with point mapped to global 0065 void contextMenuRequested(const QPoint &point); 0066 // If all bookmarks have been deselected, items is empty 0067 void bookmarksSelected(const QList<BookmarkItem*> &items); 0068 0069 private Q_SLOTS: 0070 void indexExpanded(const QModelIndex &parent); 0071 void indexCollapsed(const QModelIndex &parent); 0072 0073 private: 0074 void restoreExpandedState(const QModelIndex &parent); 0075 void rowsInserted(const QModelIndex &parent, int start, int end) override; 0076 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; 0077 0078 void contextMenuEvent(QContextMenuEvent* event) override; 0079 void mouseMoveEvent(QMouseEvent* event) override; 0080 void mousePressEvent(QMouseEvent* event) override; 0081 void mouseReleaseEvent(QMouseEvent* event) override; 0082 void mouseDoubleClickEvent(QMouseEvent* event) override; 0083 void keyPressEvent(QKeyEvent* event) override; 0084 0085 Bookmarks* m_bookmarks; 0086 BookmarksModel* m_model; 0087 BookmarksFilterModel* m_filter; 0088 ViewType m_type; 0089 }; 0090 0091 #endif // BOOKMARKSTREEVIEW_H