KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
sidebarwidget.h
1#ifndef SIDEBARWIDGET_H
2#define SIDEBARWIDGET_H
3
4#include <QListView>
5#include <Kanoop/entitymetadata.h>
6#include <Kanoop/gui/libkanoopgui.h>
7
8class QStandardItemModel;
9class SidebarPaintDelegate;
10
11/**
12 * @brief Icon-and-text sidebar navigation widget backed by QStandardItemModel.
13 *
14 * SidebarWidget displays a vertical list of named, optionally-iconed navigation
15 * entries. Each entry is keyed by an entity metadata type integer. Clicking an
16 * entry emits itemClicked() with the entity type. Spacing, icon size, and content
17 * margins are all adjustable.
18 */
19class LIBKANOOPGUI_EXPORT SidebarWidget : public QListView
20{
21 Q_OBJECT
22public:
23 /**
24 * @brief Construct with an optional parent.
25 * @param parent Optional QWidget parent
26 */
27 explicit SidebarWidget(QWidget *parent = nullptr);
28
29 /**
30 * @brief Add an entry to the sidebar.
31 * @param entityMetadataType Integer key for the entry
32 * @param text Display text
33 * @param imageResourceId Optional Qt resource ID for the entry icon (0 = none)
34 */
35 void addItem(int entityMetadataType, const QString& text, int imageResourceId = 0);
36
37 /**
38 * @brief Remove the entry with the given entity type.
39 * @param entityMetadataType Entity type key of the entry to remove
40 */
41 void removeItem(int entityMetadataType);
42
43 /**
44 * @brief Return whether an entry with the given entity type exists.
45 * @param entityMetadataType Entity type key to check
46 * @return true if the entry is present
47 */
48 bool containsItem(int entityMetadataType) const;
49
50 /** @brief Remove all entries from the sidebar. */
51 void clear();
52
53 /**
54 * @brief Programmatically select the entry with the given entity type.
55 * @param entityMetadataType Entity type key to select
56 */
57 void selectItem(int entityMetadataType);
58
59 /**
60 * @brief Return the content margins used by the paint delegate.
61 * @return Content margins
62 */
63 QMargins contentsMargins() const;
64
65 /**
66 * @brief Set the content margins used by the paint delegate.
67 * @param value New content margins
68 */
69 void setContentsMargins(const QMargins& value);
70
71 /**
72 * @brief Return the horizontal spacing between the icon and text.
73 * @return Horizontal spacing in pixels
74 */
75 int horizontalSpacing() const;
76
77 /**
78 * @brief Set the horizontal spacing between the icon and text.
79 * @param value Horizontal spacing in pixels
80 */
81 void setHorizontalSpacing(int value);
82
83 /**
84 * @brief Return the vertical spacing between entries.
85 * @return Vertical spacing in pixels
86 */
87 int verticalSpacing() const;
88
89 /**
90 * @brief Set the vertical spacing between entries.
91 * @param value Vertical spacing in pixels
92 */
93 void setVerticalSpacing(int value);
94
95 /**
96 * @brief Return the icon size used when rendering entries.
97 * @return Icon size
98 */
99 QSize iconSize() const;
100
101 /**
102 * @brief Set the icon size used when rendering entries.
103 * @param value New icon size
104 */
105 void setIconSize(const QSize& value);
106
107private:
108 QStandardItemModel* sourceModel() const;
109
110 SidebarPaintDelegate* _delegate;
111
112 static const QSize DefaultIconSize;
113 static const QMargins DefaultContentsMargins;
114 static const int DefaultVerticalSpacing;
115 static const int DefaultHorizontalSpacing;
116
117signals:
118 /**
119 * @brief Emitted when the user clicks a sidebar entry.
120 * @param entityType Entity type key of the clicked entry
121 */
122 void itemClicked(int entityType);
123
124private slots:
125 void onItemClicked(const QModelIndex& index);
126};
127
128#endif // SIDEBARWIDGET_H
Icon-and-text sidebar navigation widget backed by QStandardItemModel.
void setContentsMargins(const QMargins &value)
Set the content margins used by the paint delegate.
void itemClicked(int entityType)
Emitted when the user clicks a sidebar entry.
QSize iconSize() const
Return the icon size used when rendering entries.
bool containsItem(int entityMetadataType) const
Return whether an entry with the given entity type exists.
void selectItem(int entityMetadataType)
Programmatically select the entry with the given entity type.
void setVerticalSpacing(int value)
Set the vertical spacing between entries.
int verticalSpacing() const
Return the vertical spacing between entries.
void setHorizontalSpacing(int value)
Set the horizontal spacing between the icon and text.
void addItem(int entityMetadataType, const QString &text, int imageResourceId=0)
Add an entry to the sidebar.
void setIconSize(const QSize &value)
Set the icon size used when rendering entries.
void clear()
Remove all entries from the sidebar.
void removeItem(int entityMetadataType)
Remove the entry with the given entity type.
QMargins contentsMargins() const
Return the content margins used by the paint delegate.
int horizontalSpacing() const
Return the horizontal spacing between the icon and text.
SidebarWidget(QWidget *parent=nullptr)
Construct with an optional parent.