Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/gui.git] / src / Qtx / QtxDockAction.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxDockAction.h
20 // Author:    Sergey TELKOV
21
22 #ifndef QTX_DOCKACTION_H
23 #define QTX_DOCKACTION_H
24
25 #include "QtxAction.h"
26
27 #include <qevent.h>
28 #include <qptrlist.h>
29 #include <qpopupmenu.h>
30
31 class QAction;
32 class QDockArea;
33 class QDockWindow;
34 class QMainWindow;
35 class QtxResourceMgr;
36
37 #ifdef WIN32
38 #pragma warning( disable:4251 )
39 #endif
40
41 class QTX_EXPORT QtxDockAction : public QtxAction
42 {
43   Q_OBJECT
44
45   Q_PROPERTY( bool autoAdd   READ isAutoAdd   WRITE setAutoAdd )
46   Q_PROPERTY( bool autoPlace READ isAutoPlace WRITE setAutoPlace )
47   Q_PROPERTY( bool separate  READ isSeparate  WRITE setSeparate )
48
49 public:
50   QtxDockAction( QMainWindow*, const char* = 0 );
51   QtxDockAction( const QString&, const QString&, QMainWindow*, const char* = 0 );
52   QtxDockAction( const QString&, const QIconSet&, const QString&, QMainWindow*, const char* = 0 );
53   virtual ~QtxDockAction();
54
55   QMainWindow* mainWindow() const;
56
57   bool         isAutoAdd() const;
58   void         setAutoAdd( const bool );
59
60   bool         isAutoPlace() const;
61   void         setAutoPlace( const bool );
62
63   bool         isSeparate() const;
64   void         setSeparate( const bool );
65
66   virtual bool addTo( QWidget* );
67   virtual bool addTo( QWidget*, const int );
68   virtual bool removeFrom( QWidget* );
69   virtual void setMenuText( const QString& );
70
71   bool         addDockWindow( QDockWindow* );
72   bool         removeDockWindow( QDockWindow* );
73
74   virtual bool eventFilter( QObject*, QEvent* );
75
76   virtual void storeGeometry( QDockWindow* = 0 );
77   virtual void restoreGeometry( QDockWindow* = 0 ) const;
78
79   virtual void loadGeometry( QtxResourceMgr*, const QString&, const bool = true );
80   virtual void saveGeometry( QtxResourceMgr*, const QString&, const bool = true ) const;
81
82 private slots:
83   void         onAboutToShow();
84   void         onToggled( bool );
85   void         onVisibilityChanged( bool );
86   void         onPopupDestroyed( QObject* );
87   void         onWindowDestroyed( QObject* );
88   void         onDockWindowPositionChanged( QDockWindow* );
89
90 protected:
91   virtual bool event( QEvent* );
92
93 private:
94   QAction*     action( QDockWindow* ) const;
95   QDockWindow* dockWindow( const QAction* ) const;
96
97   void         checkPopup( QPopupMenu* );
98   void         fillPopup( QPopupMenu* ) const;
99   int          findId( QPopupMenu*, QPopupMenu* ) const;
100
101   void         initialize( QMainWindow* );
102   void         updateInfo( QDockWindow* );
103   bool         isToolBar( QDockWindow* ) const;
104   void         dockWindows( QPtrList<QDockWindow>&, QMainWindow* = 0 ) const;
105
106   QString      windowName( QDockWindow* ) const;
107   void         savePlaceInfo( QDockWindow* );
108   void         loadPlaceInfo( QDockWindow* ) const;
109   void         loadPlaceInfo() const;
110
111   bool         autoAddDockWindow( QDockWindow* );
112   void         autoLoadPlaceInfo( QDockWindow* );
113
114   void         splitMenuText( QString&, QString& ) const;
115   QStringList  splitText( const QString&, const QString& ) const;
116
117   QDockArea*   dockArea( const int ) const;
118   int          dockPlace( const QString& ) const;
119
120   void         collectNames( const int, QStringList& ) const;
121
122   void         updateMenus();
123
124   bool         dockMainWindow( QMainWindow*, QObject* ) const;
125
126 private:
127   enum { AutoAdd = QEvent::User, LoadArea };
128
129   typedef struct { bool vis, newLine;
130                    int place, index, offset;
131                    int x, y, w, h, fixW, fixH; } GeomInfo;
132   typedef struct { QString name; QAction* a; }   DockInfo;
133   typedef struct { QPopupMenu *dock, *tool; }    MenuInfo;
134
135   typedef QMap<QDockWindow*, DockInfo>   InfoMap;
136   typedef QMap<QString, GeomInfo>        GeomMap;
137   typedef QMap<QPopupMenu*, MenuInfo>    MenuMap;
138
139 private:
140   bool         loadGeometry( QtxResourceMgr*, const QString&,
141                              const QString&, GeomInfo& ) const;
142   bool         saveGeometry( QtxResourceMgr*, const QString&,
143                              const QString&, const GeomInfo& ) const;
144   void         loadPlaceArea( const int, QMainWindow*, QDockArea*,
145                               const QPtrList<QDockWindow>&,
146                               const QMap<QDockWindow*, GeomInfo*>& ) const;
147
148 private:
149   InfoMap      myInfo;
150   MenuMap      myMenu;
151   GeomMap      myGeom;
152   QMainWindow* myMain;
153   QStringList  myNames;
154
155   bool         myAutoAdd;
156   bool         mySeparate;
157   bool         myAutoPlace;
158 };
159
160 #ifdef WIN32
161 #pragma warning( default:4251 )
162 #endif
163
164 #endif