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/ObservedValue.hpp"
|
---|
27 | #include "CodePatterns/Observer/Observable.hpp"
|
---|
28 | #include "CodePatterns/Observer/Observer.hpp"
|
---|
29 |
|
---|
30 |
|
---|
31 | class QtToolBar : public QToolBar, public Observer
|
---|
32 | {
|
---|
33 | Q_OBJECT
|
---|
34 | public:
|
---|
35 | QtToolBar(QWidget * _parent=0);
|
---|
36 | virtual ~QtToolBar();
|
---|
37 |
|
---|
38 | /** Adds an action named \a token to the toolbar.
|
---|
39 | *
|
---|
40 | * @param token token of Action
|
---|
41 | * @param description description to appear as tooltip
|
---|
42 | * @param icon_name name of icon
|
---|
43 | * @return ref to newly created action
|
---|
44 | */
|
---|
45 | QAction * addActionItem(
|
---|
46 | const std::string &token,
|
---|
47 | const std::string &description,
|
---|
48 | const std::string &icon_name);
|
---|
49 |
|
---|
50 | /** Function to add a set of favorite actions.
|
---|
51 | *
|
---|
52 | * @param _max maximum number of actions to add
|
---|
53 | */
|
---|
54 | void addFavoriteActionItems(const unsigned int _max);
|
---|
55 |
|
---|
56 | //!> typedef for a set of action tokens
|
---|
57 | typedef std::set<std::string> present_actions_t;
|
---|
58 |
|
---|
59 | /** Getter for current set of present action on this toolbar.
|
---|
60 | *
|
---|
61 | * @return set of action tokens
|
---|
62 | */
|
---|
63 | const present_actions_t & getPresentActions() const
|
---|
64 | { return present_actions; }
|
---|
65 |
|
---|
66 | void update(Observable *publisher);
|
---|
67 | void subjectKilled(Observable *publisher);
|
---|
68 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
69 |
|
---|
70 | private:
|
---|
71 | std::list<QtMenuPipe*> plumbing;
|
---|
72 |
|
---|
73 | /** This class knows about all Actions being called and stores their frequency.
|
---|
74 | *
|
---|
75 | * This is used to know about the topmost used Actions and creating placeholder
|
---|
76 | * toolbar icons for these on program launch.
|
---|
77 | *
|
---|
78 | */
|
---|
79 | class QtFavoriteActions : public Observer
|
---|
80 | {
|
---|
81 | public:
|
---|
82 | QtFavoriteActions();
|
---|
83 | ~QtFavoriteActions();
|
---|
84 |
|
---|
85 | void addToolBarActions(
|
---|
86 | QtToolBar &_toolbar,
|
---|
87 | const unsigned int _max) const;
|
---|
88 |
|
---|
89 | void update(Observable *publisher);
|
---|
90 | void subjectKilled(Observable *publisher);
|
---|
91 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
92 |
|
---|
93 | QIcon getIcon(
|
---|
94 | const std::string &_token,
|
---|
95 | const std::string &_icon_name
|
---|
96 | ) const;
|
---|
97 |
|
---|
98 | private:
|
---|
99 | QIcon createIconPlaceholder(
|
---|
100 | const std::string &_token
|
---|
101 | ) const;
|
---|
102 |
|
---|
103 | void resetQueuedAction();
|
---|
104 | std::string updateQueuedAction() const;
|
---|
105 |
|
---|
106 | private:
|
---|
107 | //!> cached value of ActionQueue's last action name
|
---|
108 | ObservedValue<std::string> LastActionCalled;
|
---|
109 |
|
---|
110 | //!> all channels that signal a queued action
|
---|
111 | static const Observable::channels_t ActionQueuedChannels;
|
---|
112 |
|
---|
113 | //!> typedef for the action counts
|
---|
114 | typedef std::map<std::string, unsigned int> ActionCounts_t;
|
---|
115 | //!> map counts how often each action has been called
|
---|
116 | ActionCounts_t ActionCounts;
|
---|
117 | //!> sign in to ActionQueue?
|
---|
118 | bool ActionQueue_observing;
|
---|
119 | };
|
---|
120 |
|
---|
121 | //!> instance dealing with favorite action icons
|
---|
122 | QtFavoriteActions FavActions;
|
---|
123 |
|
---|
124 | //!> set of already present action icons
|
---|
125 | present_actions_t present_actions;
|
---|
126 |
|
---|
127 | //!> sign in to ActionQueue?
|
---|
128 | bool ActionQueue_observing;
|
---|
129 | //!> ref to undoaction to gray out
|
---|
130 | QAction *undoaction;
|
---|
131 | //!> ref to redoaction to gray out
|
---|
132 | QAction *redoaction;
|
---|
133 | };
|
---|
134 |
|
---|
135 |
|
---|
136 | #endif /* QTTOOLBAR_HPP_ */
|
---|