anatomist  5.1.2
3D neuroimaging data viewer
controlswitch.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef ANATOMIST_CONTROLER_CONTROLSWITCH_H
36 #define ANATOMIST_CONTROLER_CONTROLSWITCH_H
37 
38 
44 
45 #include <qobject.h>
46 #include <qpushbutton.h>
47 #include <qlayout.h>
48 #include <qlabel.h>
49 #if QT_VERSION >= 0x040600
50 #include <QGestureEvent>
51 #endif
52 
53 #include <vector>
54 #include <list>
55 
56 
57 class ControlSwitch;
58 class QTextBrowser;
59 
60 
61 namespace anatomist
62 {
63 
65  {
66  public:
68  virtual ~ControlSwitchObserver( ) {}
69 
70  virtual void updateAvailableControls( ) {}
71  virtual void updateActivableControls( ) {}
72  virtual void updateActiveControl() {}
73  virtual void updateActions( ) {}
74 
75  protected:
76  };
77 
78 }
79 
80 class ToolBox : public QWidget
81 {
82 
83  Q_OBJECT
84 
85 public:
86  ToolBox( const std::string& activeControlDescription = "" );
87  virtual ~ToolBox();
88 
89  void resetActions( );
90  void updateActiveControl( const std::string& activeControlDescription );
91 
92  void addTab( QWidget * child, const QString & label,
93  const std::string & actionid = "" );
94  void showPage ( QWidget * w );
95  void showPage( const std::string & label );
96  const std::set<std::string> & actions() const;
97 
98 private slots :
99  void switchControlDescriptionActivation();
100 
101 private:
102  struct Private;
103 
104  QTabWidget * myActionTab;
105  QPushButton * myControlDescriptionActivation;
106  std::string myControlDescription;
107  QTextBrowser * myControlDescriptionWidget;
108  QLabel *l1, *l2, *l3, *l4;
109 
110  bool myDescriptionActivated;
111  Private *d;
112 };
113 
114 
115 class ControlSwitch : public QObject
116 {
117 
118  Q_OBJECT
119 
120 public:
121  virtual ~ControlSwitch();
122 
123  friend class anatomist::View;
124 
127 
132 
133  const std::map<int, std::string>& activableControls( ) const;
134  const std::map<int, std::string>& availableControls( ) const;
135  const std::set<std::string>& activableControlGroups( ) const;
136  const std::set<std::string>& availableControlGroups( ) const;
137  const std::set<std::string>& actions() const;
138  std::string controlDescription( const std::string & ctrlname ) const;
139 
140  //vector<ControlPtr>::iterator iterator;
141  typedef std::map<std::string, anatomist::ControlPtr>::const_iterator
143  typedef std::map<std::string, anatomist::ControlPtr>::iterator
145 
146  //iterator begin();
148  //iterator end();
150  void setActiveControl( const std::string& );
151  const std::string& activeControl() const;
153 
154  void keyPressEvent( QKeyEvent *);
155  void keyReleaseEvent( QKeyEvent *);
156  void mousePressEvent ( QMouseEvent * );
157  void mouseReleaseEvent ( QMouseEvent * );
158  void mouseDoubleClickEvent ( QMouseEvent * );
159  void mouseMoveEvent ( QMouseEvent * );
160  void wheelEvent ( QWheelEvent * );
161  void focusInEvent ( QFocusEvent * );
162  void focusOutEvent ( QFocusEvent * );
163  void enterEvent ( QEvent * );
164  void leaveEvent ( QEvent * );
165  void paintEvent ( QPaintEvent * );
166  void moveEvent ( QMoveEvent * );
167  void resizeEvent ( QResizeEvent * );
168  void dragEnterEvent ( QDragEnterEvent * );
169  void dragMoveEvent ( QDragMoveEvent * );
170  void dragLeaveEvent ( QDragLeaveEvent * );
171  void dropEvent ( QDropEvent * );
172  void showEvent ( QShowEvent * );
173  void hideEvent ( QHideEvent * );
175  //void customEvent ( QCustomEvent * );
176 #if QT_VERSION >= 0x040600
177  void gestureEvent( QGestureEvent * );
178 #endif
179 
180  void setAvailableControls( const std::list<std::string>& objects );
181  void setActivableControls( bool init = false);
182 
183  // void setControlBarButtons();
184 
186  // private slots:
187  // void clicked( int id );
188 
191 
192  bool isToolBoxVisible() const;
195 
196  anatomist::Action* getAction( const std::string& actionName );
197 
198  void activateKeyPressAction( const std::string & methodname ) const;
199  void activateKeyReleaseAction( const std::string & methodname ) const;
201  const std::string & methodname,
202  int x, int y ) const;
204  const std::string & methodname,
205  int x, int y ) const;
207  const std::string & methodname,
208  int x, int y ) const;
210  const std::string & methodname,
211  int x, int y ) const;
212 
213 protected:
215 
216 private:
217  void init( );
218  void getSelectedObjectNames();
219 
220  anatomist::ActionPool * myActionPool;
221  // QHButtonGroup * myControlBar;
222  std::string myViewType;
223  std::map<std::string, anatomist::ControlPtr> myControls;
224 
225  std::map<int, std::string> myAvailableControls;
226  std::map<int, std::string> myActivableControls;
227 
228  std::set<std::string> myAvailableControlGroups;
229  std::set<std::string> myActivableControlGroups;
230  std::list<std::string> mySelectedObjects;
231 
232  std::list<anatomist::ControlSwitchObserver *> myObservers;
233 
234  bool myControlEnabled;
235  std::string myActiveControl;
236 
237  ToolBox * myToolBox;
238 
239 private slots:
240  void toolBoxDestroyed();
241 
242 };
243 
244 #endif
#define slots
std::map< std::string, anatomist::ControlPtr >::iterator iterator
void dragMoveEvent(QDragMoveEvent *)
void activateKeyPressAction(const std::string &methodname) const
const std::set< std::string > & availableControlGroups() const
void notifyActiveControlChange()
const std::set< std::string > & actions() const
const std::set< std::string > & activableControlGroups() const
void focusInEvent(QFocusEvent *)
void mouseDoubleClickEvent(QMouseEvent *)
anatomist::ControlPtr activeControlInstance() const
void activateMousePressAction(const std::string &methodname, int x, int y) const
void hideEvent(QHideEvent *)
void dragEnterEvent(QDragEnterEvent *)
void moveEvent(QMoveEvent *)
void activateMouseDoubleClickAction(const std::string &methodname, int x, int y) const
ToolBox * toolBox()
void keyReleaseEvent(QKeyEvent *)
virtual ~ControlSwitch()
void showEvent(QShowEvent *)
void mouseReleaseEvent(QMouseEvent *)
void activateMouseMoveAction(const std::string &methodname, int x, int y) const
void setActiveControl(const std::string &)
bool isToolBoxVisible() const
void dragLeaveEvent(QDragLeaveEvent *)
void wheelEvent(QWheelEvent *)
const_iterator begin() const
void focusOutEvent(QFocusEvent *)
void selectionChangedEvent()
void enterEvent(QEvent *)
void updateControlDescription()
void updateToolBox()
void leaveEvent(QEvent *)
void keyPressEvent(QKeyEvent *)
void notifyActivableControlChange()
void notifyAvailableControlChange()
void activateMouseReleaseAction(const std::string &methodname, int x, int y) const
void activateKeyReleaseAction(const std::string &methodname) const
void dropEvent(QDropEvent *)
std::string controlDescription(const std::string &ctrlname) const
const std::map< int, std::string > & availableControls() const
void mousePressEvent(QMouseEvent *)
anatomist::Action * getAction(const std::string &actionName)
const std::map< int, std::string > & activableControls() const
bool attach(anatomist::ControlSwitchObserver *window)
std::map< std::string, anatomist::ControlPtr >::const_iterator const_iterator
void paintEvent(QPaintEvent *)
void mouseMoveEvent(QMouseEvent *)
void setActivableControls(bool init=false)
bool detach(anatomist::ControlSwitchObserver *window)
void setAvailableControls(const std::list< std::string > &objects)
void printControls()
void switchToolBoxVisible()
const_iterator end() const
ControlSwitch(anatomist::View *view)
const std::string & activeControl() const
void notifyActionChange()
void resizeEvent(QResizeEvent *)
void addTab(QWidget *child, const QString &label, const std::string &actionid="")
ToolBox(const std::string &activeControlDescription="")
void resetActions()
const std::set< std::string > & actions() const
virtual ~ToolBox()
void updateActiveControl(const std::string &activeControlDescription)
void showPage(const std::string &label)
void showPage(QWidget *w)
virtual void updateAvailableControls()
Definition: controlswitch.h:70
virtual void updateActivableControls()
Definition: controlswitch.h:71