digiKam
bookmarksmenu.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2017-05-15
7  * Description : menu to manage bookmarks
8  *
9  * Copyright (C) 2017-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_BOOKMARKS_MENU_H
25 #define DIGIKAM_BOOKMARKS_MENU_H
26 
27 // Qt includes
28 
29 #include <QMenu>
30 #include <QList>
31 #include <QAction>
32 #include <QWidget>
33 #include <QModelIndex>
34 #include <QAbstractItemModel>
35 
36 // Local includes
37 
38 #include "bookmarksmngr.h"
39 
40 namespace Digikam
41 {
42 
46 class ModelMenu : public QMenu
47 {
48  Q_OBJECT
49 
50 public:
51 
52  explicit ModelMenu(QWidget* const parent = nullptr);
53  ~ModelMenu() override;
54 
55  void setModel(QAbstractItemModel* model);
56  QAbstractItemModel* model() const;
57 
58  void setMaxRows(int max);
59  int maxRows() const;
60 
61  void setFirstSeparator(int offset);
62  int firstSeparator() const;
63 
64  void setRootIndex(const QModelIndex& index);
65  QModelIndex rootIndex() const;
66 
67  void setHoverRole(int role);
68  int hoverRole() const;
69 
70  void setSeparatorRole(int role);
71  int separatorRole() const;
72 
73  QAction* makeAction(const QIcon& icon, const QString& text, QObject* const parent);
74 
75 Q_SIGNALS:
76 
77  void activated(const QModelIndex& index);
78  void hovered(const QString& text);
79 
80 protected:
81 
83  virtual bool prePopulated();
84 
86  virtual void postPopulated();
87 
89  void createMenu(const QModelIndex& parent, int max, QMenu* parentMenu = nullptr, QMenu* menu = nullptr);
90 
91 private Q_SLOTS:
92 
93  void slotAboutToShow();
94  void slotTriggered(QAction* action);
95  void slotHovered(QAction* action);
96 
97 private:
98 
99  QAction* makeAction(const QModelIndex& index);
100 
101 private:
102 
103  class Private;
104  Private* const d;
105 };
106 
107 // ---------------------------------------------------------------------------
108 
112 class BookmarksMenu : public ModelMenu
113 {
114  Q_OBJECT
115 
116 public:
117 
118  explicit BookmarksMenu(BookmarksManager* const mngr, QWidget* const parent = nullptr);
119  ~BookmarksMenu() override;
120 
121  void setInitialActions(const QList<QAction*>& actions);
122 
123 Q_SIGNALS:
124 
125  void openUrl(const QUrl& url);
126 
127 protected:
128 
129  bool prePopulated() override;
130 
131 private Q_SLOTS:
132 
133  void slotActivated(const QModelIndex& index);
134 
135 private:
136 
137  class Private;
138  Private* const d;
139 };
140 
141 } // namespace Digikam
142 
143 #endif // DIGIKAM_BOOKMARKS_MENU_H
Definition: bookmarksmngr.h:214
Definition: bookmarksmenu.h:113
void setInitialActions(const QList< QAction * > &actions)
Definition: bookmarksmenu.cpp:361
BookmarksMenu(BookmarksManager *const mngr, QWidget *const parent=nullptr)
Definition: bookmarksmenu.cpp:312
~BookmarksMenu() override
Definition: bookmarksmenu.cpp:326
void openUrl(const QUrl &url)
bool prePopulated() override
add any actions before the tree, return true if any actions are added.
Definition: bookmarksmenu.cpp:336
Definition: bookmarksmenu.h:47
int hoverRole() const
Definition: bookmarksmenu.cpp:133
QAction * makeAction(const QIcon &icon, const QString &text, QObject *const parent)
Definition: bookmarksmenu.cpp:256
void setMaxRows(int max)
Definition: bookmarksmenu.cpp:98
void hovered(const QString &text)
void activated(const QModelIndex &index)
int maxRows() const
Definition: bookmarksmenu.cpp:103
int separatorRole() const
Definition: bookmarksmenu.cpp:143
virtual bool prePopulated()
add any actions before the tree, return true if any actions are added.
Definition: bookmarksmenu.cpp:79
~ModelMenu() override
Definition: bookmarksmenu.cpp:74
void setHoverRole(int role)
Definition: bookmarksmenu.cpp:128
QModelIndex rootIndex() const
Definition: bookmarksmenu.cpp:123
void createMenu(const QModelIndex &parent, int max, QMenu *parentMenu=nullptr, QMenu *menu=nullptr)
put all of the children of parent into menu up to max
Definition: bookmarksmenu.cpp:186
virtual void postPopulated()
add any actions after the tree
Definition: bookmarksmenu.cpp:84
void setRootIndex(const QModelIndex &index)
Definition: bookmarksmenu.cpp:118
int firstSeparator() const
Definition: bookmarksmenu.cpp:113
ModelMenu(QWidget *const parent=nullptr)
Definition: bookmarksmenu.cpp:64
void setModel(QAbstractItemModel *model)
Definition: bookmarksmenu.cpp:88
void setSeparatorRole(int role)
Definition: bookmarksmenu.cpp:138
QAbstractItemModel * model() const
Definition: bookmarksmenu.cpp:93
void setFirstSeparator(int offset)
Definition: bookmarksmenu.cpp:108
Definition: datefolderview.cpp:43