| [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 | 
 | 
|---|
| [b375e7] | 26 | #include "CodePatterns/ObservedValue.hpp"
 | 
|---|
 | 27 | #include "CodePatterns/Observer/Observable.hpp"
 | 
|---|
| [8859b5] | 28 | #include "CodePatterns/Observer/Observer.hpp"
 | 
|---|
 | 29 | 
 | 
|---|
| [7641d4] | 30 | 
 | 
|---|
| [c01fec] | 31 | class QtToolBar : public QToolBar, public Observer
 | 
|---|
| [7641d4] | 32 | {
 | 
|---|
 | 33 |   Q_OBJECT
 | 
|---|
 | 34 | public:
 | 
|---|
 | 35 |   QtToolBar(QWidget * _parent=0);
 | 
|---|
 | 36 |   virtual ~QtToolBar();
 | 
|---|
 | 37 | 
 | 
|---|
| [8859b5] | 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
 | 
|---|
| [c01fec] | 43 |    * @return ref to newly created action
 | 
|---|
| [8859b5] | 44 |    */
 | 
|---|
| [c01fec] | 45 |   QAction * addActionItem(
 | 
|---|
 | 46 |       const std::string &token,
 | 
|---|
 | 47 |       const std::string &description,
 | 
|---|
 | 48 |       const std::string &icon_name);
 | 
|---|
| [8859b5] | 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 | 
 | 
|---|
| [c01fec] | 66 |   void update(Observable *publisher);
 | 
|---|
 | 67 |   void subjectKilled(Observable *publisher);
 | 
|---|
 | 68 |   void recieveNotification(Observable *publisher, Notification_ptr notification);
 | 
|---|
 | 69 | 
 | 
|---|
| [7641d4] | 70 | private:
 | 
|---|
 | 71 |   std::list<QtMenuPipe*> plumbing;
 | 
|---|
 | 72 | 
 | 
|---|
| [8859b5] | 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 | 
 | 
|---|
| [b375e7] | 103 |     void resetQueuedAction();
 | 
|---|
 | 104 |     std::string updateQueuedAction() const;
 | 
|---|
 | 105 | 
 | 
|---|
| [8859b5] | 106 |   private:
 | 
|---|
| [b375e7] | 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 | 
 | 
|---|
| [8859b5] | 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;
 | 
|---|
| [7641d4] | 123 | 
 | 
|---|
| [8859b5] | 124 |   //!> set of already present action icons
 | 
|---|
 | 125 |   present_actions_t present_actions;
 | 
|---|
| [c01fec] | 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;
 | 
|---|
| [7641d4] | 133 | };
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | 
 | 
|---|
 | 136 | #endif /* QTTOOLBAR_HPP_ */
 | 
|---|