forked from vnotex/vnote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvinsertselector.h
More file actions
90 lines (64 loc) · 1.83 KB
/
vinsertselector.h
File metadata and controls
90 lines (64 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef VINSERTSELECTOR_H
#define VINSERTSELECTOR_H
#include <QWidget>
#include <QVector>
class QPushButton;
class QKeyEvent;
class QShowEvent;
class QPaintEvent;
struct VInsertSelectorItem
{
VInsertSelectorItem()
{
}
VInsertSelectorItem(const QString &p_name,
const QString &p_toolTip,
QChar p_shortcut = QChar())
: m_name(p_name), m_toolTip(p_toolTip), m_shortcut(p_shortcut)
{
}
QString m_name;
QString m_toolTip;
QChar m_shortcut;
};
class VSelectorItemWidget : public QWidget
{
Q_OBJECT
public:
explicit VSelectorItemWidget(QWidget *p_parent = nullptr);
VSelectorItemWidget(const VInsertSelectorItem &p_item, QWidget *p_parent = nullptr);
signals:
// This item widget is clicked.
void clicked(const QString &p_name);
private:
QString m_name;
QPushButton *m_btn;
};
class VInsertSelector : public QWidget
{
Q_OBJECT
public:
explicit VInsertSelector(int p_nrRows,
const QVector<VInsertSelectorItem> &p_items,
QWidget *p_parent = nullptr);
const QString &getClickedItem() const;
signals:
void accepted(bool p_accepted = true);
protected:
void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
void showEvent(QShowEvent *p_event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *p_event) Q_DECL_OVERRIDE;
private slots:
void itemClicked(const QString &p_name);
private:
void setupUI(int p_nrRows);
QWidget *createItemWidget(const VInsertSelectorItem &p_item);
const VInsertSelectorItem *findItemByShortcut(QChar p_shortcut) const;
QVector<VInsertSelectorItem> m_items;
QString m_clickedItemName;
};
inline const QString &VInsertSelector::getClickedItem() const
{
return m_clickedItemName;
}
#endif // VINSERTSELECTOR_H