File indexing completed on 2025-01-19 03:58:03
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2017-05-15 0007 * Description : menu to manage bookmarks 0008 * 0009 * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_BOOKMARKS_MENU_H 0016 #define DIGIKAM_BOOKMARKS_MENU_H 0017 0018 // Qt includes 0019 0020 #include <QMenu> 0021 #include <QList> 0022 #include <QAction> 0023 #include <QWidget> 0024 #include <QModelIndex> 0025 #include <QAbstractItemModel> 0026 0027 // Local includes 0028 0029 #include "bookmarksmngr.h" 0030 0031 namespace Digikam 0032 { 0033 0034 /** 0035 * A QMenu that is dynamically populated from a QAbstractItemModel 0036 */ 0037 class ModelMenu : public QMenu 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 0043 explicit ModelMenu(QWidget* const parent = nullptr); 0044 ~ModelMenu() override; 0045 0046 void setModel(QAbstractItemModel* model); 0047 QAbstractItemModel* model() const; 0048 0049 void setMaxRows(int max); 0050 int maxRows() const; 0051 0052 void setFirstSeparator(int offset); 0053 int firstSeparator() const; 0054 0055 void setRootIndex(const QModelIndex& index); 0056 QModelIndex rootIndex() const; 0057 0058 void setHoverRole(int role); 0059 int hoverRole() const; 0060 0061 void setSeparatorRole(int role); 0062 int separatorRole() const; 0063 0064 QAction* makeAction(const QIcon& icon, const QString& text, QObject* const parent); 0065 0066 Q_SIGNALS: 0067 0068 void activated(const QModelIndex& index); 0069 void hovered(const QString& text); 0070 0071 protected: 0072 0073 /// add any actions before the tree, return true if any actions are added. 0074 virtual bool prePopulated(); 0075 0076 /// add any actions after the tree 0077 virtual void postPopulated(); 0078 0079 /// put all of the children of parent into menu up to max 0080 void createMenu(const QModelIndex& parent, int max, QMenu* parentMenu = nullptr, QMenu* menu = nullptr); 0081 0082 private Q_SLOTS: 0083 0084 void slotAboutToShow(); 0085 void slotTriggered(QAction* action); 0086 void slotHovered(QAction* action); 0087 0088 private: 0089 0090 QAction* makeAction(const QModelIndex& index); 0091 0092 private: 0093 0094 class Private; 0095 Private* const d; 0096 }; 0097 0098 // --------------------------------------------------------------------------- 0099 0100 /** 0101 * Menu that is dynamically populated from the bookmarks 0102 */ 0103 class BookmarksMenu : public ModelMenu 0104 { 0105 Q_OBJECT 0106 0107 public: 0108 0109 explicit BookmarksMenu(BookmarksManager* const mngr, QWidget* const parent = nullptr); 0110 ~BookmarksMenu() override; 0111 0112 void setInitialActions(const QList<QAction*>& actions); 0113 0114 Q_SIGNALS: 0115 0116 void openUrl(const QUrl& url); 0117 0118 protected: 0119 0120 bool prePopulated() override; 0121 0122 private Q_SLOTS: 0123 0124 void slotActivated(const QModelIndex& index); 0125 0126 private: 0127 0128 class Private; 0129 Private* const d; 0130 }; 0131 0132 } // namespace Digikam 0133 0134 #endif // DIGIKAM_BOOKMARKS_MENU_H