-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoolmenu.h
60 lines (48 loc) · 1.37 KB
/
toolmenu.h
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
#ifndef TOOLMENU_H
#define TOOLMENU_H
#include <QDialog>
#include <QLabel>
#include <QMenu>
#include <QToolButton>
#include <functional>
namespace Ui {
class ToolMenu;
}
class ToolMenu : public QDialog
{
Q_OBJECT
public:
enum TipAlign{
UP,
DOWN,
LEFT,
RIGHT
};
public:
explicit ToolMenu(QWidget *parent = nullptr);
~ToolMenu();
QToolButton* addMenu(QMenu* menu, const QPoint& offset);
void setBtnText(QToolButton* btn, const QString& text);
QToolButton* addAction(const QString& text, const QPoint& offset, std::function<void(void)> todo);
QLabel* addLabelTip(QToolButton* target, const QString& text = "", TipAlign align = UP, int margin = 4);
void setLabelTip(QToolButton* target, QLabel* label, const QString& text, TipAlign align, int margin = 4);
void setCenter(QWidget* wgt, const QPoint& center);
private:
Ui::ToolMenu *ui;
QList<QToolButton*> btnMenuList;
QToolButton* lastHoverBtn = nullptr;
QTimer* timer = nullptr;
signals:
void closed(void);
void showed(void);
// QObject interface
public:
virtual bool eventFilter(QObject *watched, QEvent *event) override;
// QWidget interface
protected:
virtual void showEvent(QShowEvent *event) override;
// QWidget interface
protected:
virtual void closeEvent(QCloseEvent *event) override;
};
#endif // TOOLMENU_H