File indexing completed on 2024-05-12 04:57:57
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 BOOKMARKSMODEL_H 0019 #define BOOKMARKSMODEL_H 0020 0021 #include <QAbstractItemModel> 0022 #include <QSortFilterProxyModel> 0023 #include <QMimeData> 0024 0025 #include "qzcommon.h" 0026 0027 class QTimer; 0028 0029 class Bookmarks; 0030 class BookmarkItem; 0031 0032 class FALKON_EXPORT BookmarksModel : public QAbstractItemModel 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 enum Roles { 0038 TypeRole = Qt::UserRole + 1, 0039 UrlRole = Qt::UserRole + 2, 0040 UrlStringRole = Qt::UserRole + 3, 0041 TitleRole = Qt::UserRole + 4, 0042 IconRole = Qt::UserRole + 5, 0043 DescriptionRole = Qt::UserRole + 6, 0044 KeywordRole = Qt::UserRole + 7, 0045 VisitCountRole = Qt::UserRole + 8, 0046 ExpandedRole = Qt::UserRole + 9, 0047 SidebarExpandedRole = Qt::UserRole + 10, 0048 MaxRole = SidebarExpandedRole 0049 }; 0050 0051 explicit BookmarksModel(BookmarkItem* root, Bookmarks* bookmarks, QObject* parent = nullptr); 0052 0053 void addBookmark(BookmarkItem* parent, int row, BookmarkItem* item); 0054 void removeBookmark(BookmarkItem* item); 0055 0056 Qt::ItemFlags flags(const QModelIndex &index) const override; 0057 QVariant data(const QModelIndex &index, int role) const override; 0058 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0059 int rowCount(const QModelIndex &parent) const override; 0060 int columnCount(const QModelIndex &parent) const override; 0061 bool hasChildren(const QModelIndex &parent) const override; 0062 0063 Qt::DropActions supportedDropActions() const override; 0064 QStringList mimeTypes() const override; 0065 QMimeData* mimeData(const QModelIndexList &indexes) const override; 0066 bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 0067 0068 QModelIndex parent(const QModelIndex &child) const override; 0069 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0070 QModelIndex index(BookmarkItem* item, int column = 0) const; 0071 0072 BookmarkItem* item(const QModelIndex &index) const; 0073 0074 private Q_SLOTS: 0075 void bookmarkChanged(BookmarkItem* item); 0076 0077 private: 0078 BookmarkItem* m_root; 0079 Bookmarks* m_bookmarks; 0080 }; 0081 0082 class FALKON_EXPORT BookmarksFilterModel : public QSortFilterProxyModel 0083 { 0084 Q_OBJECT 0085 0086 public: 0087 explicit BookmarksFilterModel(QAbstractItemModel* parent); 0088 0089 public Q_SLOTS: 0090 void setFilterFixedString(const QString &pattern); 0091 0092 protected: 0093 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0094 0095 private Q_SLOTS: 0096 void startFiltering(); 0097 0098 private: 0099 QString m_pattern; 0100 QTimer* m_filterTimer; 0101 }; 0102 0103 class FALKON_EXPORT BookmarksButtonMimeData : public QMimeData 0104 { 0105 Q_OBJECT 0106 0107 public: 0108 explicit BookmarksButtonMimeData(); 0109 0110 BookmarkItem *item() const; 0111 void setBookmarkItem(BookmarkItem *item); 0112 0113 bool hasFormat(const QString &format) const override; 0114 QStringList formats() const override; 0115 0116 static QString mimeType(); 0117 0118 private: 0119 BookmarkItem* m_item; 0120 }; 0121 0122 #endif // BOOKMARKSMODEL_H