1 | /*
|
---|
2 | * QtToolBar.hpp
|
---|
3 | *
|
---|
4 | * Created on: Apr 26, 2012
|
---|
5 | * Author: ankele
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef QTTOOLBAR_HPP_
|
---|
9 | #define QTTOOLBAR_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 |
|
---|
17 | #include <Qt/qaction.h>
|
---|
18 | #include <QtGui/QToolBar>
|
---|
19 |
|
---|
20 | #include "Menu/Qt4/QtMenuPipe.hpp"
|
---|
21 |
|
---|
22 | #include <map>
|
---|
23 | #include <set>
|
---|
24 | #include <string>
|
---|
25 |
|
---|
26 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
27 |
|
---|
28 |
|
---|
29 | class QtToolBar : public QToolBar
|
---|
30 | {
|
---|
31 | Q_OBJECT
|
---|
32 | public:
|
---|
33 | QtToolBar(QWidget * _parent=0);
|
---|
34 | virtual ~QtToolBar();
|
---|
35 |
|
---|
36 | /** Adds an action named \a token to the toolbar.
|
---|
37 | *
|
---|
38 | * @param token token of Action
|
---|
39 | * @param description description to appear as tooltip
|
---|
40 | * @param icon_name name of icon
|
---|
41 | */
|
---|
42 | void addActionItem(const std::string &token, const std::string &description, const std::string &icon_name);
|
---|
43 |
|
---|
44 | /** Function to add a set of favorite actions.
|
---|
45 | *
|
---|
46 | * @param _max maximum number of actions to add
|
---|
47 | */
|
---|
48 | void addFavoriteActionItems(const unsigned int _max);
|
---|
49 |
|
---|
50 | //!> typedef for a set of action tokens
|
---|
51 | typedef std::set<std::string> present_actions_t;
|
---|
52 |
|
---|
53 | /** Getter for current set of present action on this toolbar.
|
---|
54 | *
|
---|
55 | * @return set of action tokens
|
---|
56 | */
|
---|
57 | const present_actions_t & getPresentActions() const
|
---|
58 | { return present_actions; }
|
---|
59 |
|
---|
60 | private:
|
---|
61 | std::list<QtMenuPipe*> plumbing;
|
---|
62 |
|
---|
63 | /** This class knows about all Actions being called and stores their frequency.
|
---|
64 | *
|
---|
65 | * This is used to know about the topmost used Actions and creating placeholder
|
---|
66 | * toolbar icons for these on program launch.
|
---|
67 | *
|
---|
68 | */
|
---|
69 | class QtFavoriteActions : public Observer
|
---|
70 | {
|
---|
71 | public:
|
---|
72 | QtFavoriteActions();
|
---|
73 | ~QtFavoriteActions();
|
---|
74 |
|
---|
75 | void addToolBarActions(
|
---|
76 | QtToolBar &_toolbar,
|
---|
77 | const unsigned int _max) const;
|
---|
78 |
|
---|
79 | void update(Observable *publisher);
|
---|
80 | void subjectKilled(Observable *publisher);
|
---|
81 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
82 |
|
---|
83 | QIcon getIcon(
|
---|
84 | const std::string &_token,
|
---|
85 | const std::string &_icon_name
|
---|
86 | ) const;
|
---|
87 |
|
---|
88 | private:
|
---|
89 | QIcon createIconPlaceholder(
|
---|
90 | const std::string &_token
|
---|
91 | ) const;
|
---|
92 |
|
---|
93 | private:
|
---|
94 | //!> typedef for the action counts
|
---|
95 | typedef std::map<std::string, unsigned int> ActionCounts_t;
|
---|
96 | //!> map counts how often each action has been called
|
---|
97 | ActionCounts_t ActionCounts;
|
---|
98 | //!> sign in to ActionQueue?
|
---|
99 | bool ActionQueue_observing;
|
---|
100 | };
|
---|
101 |
|
---|
102 | //!> instance dealing with favorite action icons
|
---|
103 | QtFavoriteActions FavActions;
|
---|
104 |
|
---|
105 | //!> set of already present action icons
|
---|
106 | present_actions_t present_actions;
|
---|
107 | };
|
---|
108 |
|
---|
109 |
|
---|
110 | #endif /* QTTOOLBAR_HPP_ */
|
---|