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