Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[modules/kernel.git] / src / PatchQt / qworkspaceP.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Module      : PatchQt
3 // File        : qworkspaceP.h
4 // Description : the patch for Qt's QWorkspace class (qworkspace.h)
5 /////////////////////////////////////////////////////////////////////////////
6
7 /****************************************************************************
8 ** $Id$
9 **
10 ** Definition of the QWorkspace class
11 **
12 ** Created : 990210
13 **
14 ** Copyright (C) 1999-2000 Trolltech AS.  All rights reserved.
15 **
16 ** This file is part of the workspace module of the Qt GUI Toolkit.
17 **
18 ** This file may be distributed under the terms of the Q Public License
19 ** as defined by Trolltech AS of Norway and appearing in the file
20 ** LICENSE.QPL included in the packaging of this file.
21 **
22 ** This file may be distributed and/or modified under the terms of the
23 ** GNU General Public License version 2 as published by the Free Software
24 ** Foundation and appearing in the file LICENSE.GPL included in the
25 ** packaging of this file.
26 **
27 ** Licensees holding valid Qt Enterprise Edition licenses may use this
28 ** file in accordance with the Qt Commercial License Agreement provided
29 ** with the Software.
30 **
31 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
32 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33 **
34 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
35 **   information about Qt Commercial License Agreements.
36 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
37 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
38 **
39 ** Contact info@trolltech.com if any conditions of this licensing are
40 ** not clear to you.
41 **
42 **********************************************************************/
43
44 #ifndef QWORKSPACEP_H
45 #define QWORKSPACEP_H
46
47 #ifndef QT_H
48 #include <qobject.h>
49 #include <qwidget.h>
50 #include <qwidgetlist.h>
51 #include <qframe.h>
52 #include <qguardedptr.h>
53 #include <qbutton.h>
54 #include <qlabel.h>
55 #endif // QT_H
56
57 class QWorkspacePChild;
58 class QShowEvent;
59 class QWorkspacePPrivate;
60 class QPopupMenu;
61 class QWidgetResizeHandlerP;
62 class QTitleBarP;
63
64 class Q_EXPORT QWorkspaceP : public QWidget
65 {
66     Q_OBJECT
67     Q_PROPERTY( bool scrollBarsEnabled READ scrollBarsEnabled WRITE setScrollBarsEnabled )
68 public:
69     QWorkspaceP( QWidget* parent=0, const char* name=0 );
70     ~QWorkspaceP();
71
72     QWidget* activeWindow() const;
73     QWidgetList windowList() const;
74
75     QSize sizeHint() const;
76
77     bool scrollBarsEnabled() const;
78     void setScrollBarsEnabled( bool enable );
79
80     void setPaletteBackgroundColor( const QColor & );
81     void setPaletteBackgroundPixmap( const QPixmap & );
82
83 signals:
84     void windowActivated( QWidget* w);
85
86 public slots:
87     void cascade();
88     void tile();
89
90 protected:
91 #ifndef QT_NO_STYLE
92     void styleChange( QStyle& );
93 #endif
94     void childEvent( QChildEvent * );
95     void resizeEvent( QResizeEvent * );
96     bool eventFilter( QObject *, QEvent * );
97     void showEvent( QShowEvent *e );
98     void hideEvent( QHideEvent *e );
99 #ifndef QT_NO_WHEELEVENT
100     void wheelEvent( QWheelEvent *e );
101 #endif
102
103 private slots:
104     void closeActiveWindow();
105     void closeAllWindows();
106     void normalizeActiveWindow();
107     void minimizeActiveWindow();
108     void showOperationMenu();
109     void popupOperationMenu( const QPoint& );
110     void operationMenuActivated( int );
111     void operationMenuAboutToShow();
112     void toolMenuAboutToShow();
113     void scrollBarChanged();
114 public slots:
115     void activateNextWindow();
116     void activatePreviousWindow();
117
118 public:
119     void activateWindow( QWidget* w, bool change_focus = TRUE );
120
121 private:
122     void insertIcon( QWidget* w);
123     void removeIcon( QWidget* w);
124     void place( QWidget* );
125
126     QWorkspacePChild* findChild( QWidget* w);
127     void showMaximizeControls();
128     void hideMaximizeControls();
129     void showWindow( QWidget* w);
130     void maximizeWindow( QWidget* w);
131     void minimizeWindow( QWidget* w);
132     void normalizeWindow( QWidget* w);
133
134     QRect updateWorkspace();
135
136     QPopupMenu* popup;
137     QWorkspacePPrivate* d;
138
139     friend class QWorkspacePChild;
140
141 private:        // Disabled copy constructor and operator=
142 #if defined(Q_DISABLE_COPY)
143     QWorkspaceP( const QWorkspaceP & );
144     QWorkspaceP& operator=( const QWorkspaceP & );
145 #endif
146 };
147
148 class QWorkspacePChild : public QFrame
149 {
150     Q_OBJECT
151
152     friend class QWorkspaceP;
153     friend class QTitleBarP;
154
155 public:
156     QWorkspacePChild( QWidget* window,
157                      QWorkspaceP* parent=0, const char* name=0 );
158     ~QWorkspacePChild();
159
160     void setActive( bool );
161     bool isActive() const;
162
163     void adjustToFullscreen();
164     void adjustSize();
165
166     QWidget* windowWidget() const;
167     QWidget* iconWidget() const;
168
169     void doResize();
170     void doMove();
171
172     QSize sizeHint() const;
173     QSize minimumSizeHint() const;
174
175     QSize baseSize() const;
176
177 signals:
178     void showOperationMenu();
179     void popupOperationMenu( const QPoint& );
180
181 public slots:
182     void activate();
183     void showMinimized();
184     void showMaximized();
185     void showNormal();
186     void showShaded();
187     void setCaption( const QString& );
188     void internalRaise();
189     void titleBarDoubleClicked();
190
191     void move( int x, int y );
192
193 protected:
194     void enterEvent( QEvent * );
195     void leaveEvent( QEvent * );
196     void childEvent( QChildEvent* );
197     void resizeEvent( QResizeEvent * );
198     void moveEvent( QMoveEvent * );
199     bool eventFilter( QObject *, QEvent * );
200
201     bool focusNextPrevChild( bool );
202
203     void drawFrame( QPainter * );
204     void styleChange( QStyle & );
205
206 private:
207     QWidget* childWidget;
208     QWidget* lastfocusw;
209     QWidgetResizeHandlerP *widgetResizeHandler;
210     QTitleBarP* titlebar;
211     QGuardedPtr<QTitleBarP> iconw;
212     QSize windowSize;
213     QSize shadeRestore;
214     QSize shadeRestoreMin;
215     bool act                :1;
216     bool shademode          :1;
217     bool snappedRight       :1;
218     bool snappedDown        :1;
219 };
220
221 #ifndef QT_H
222 #endif // QT_H
223 class QMouseEvent;
224 class QKeyEvent;
225
226 class Q_EXPORT QWidgetResizeHandlerP : public QObject
227 {
228     Q_OBJECT
229
230 public:
231     QWidgetResizeHandlerP( QWidget *parent, QWidget *cw = 0, const char *name = 0 );
232     void setActive( bool b ) { active = b; if ( !active ) setMouseCursor( Nowhere ); }
233     bool isActive() const { return active; }
234     void setMovingEnabled( bool b ) { moving = b; }
235     bool isMovingEnabled() const { return moving; }
236
237     bool isButtonDown() const { return buttonDown; }
238
239     void setExtraHeight( int h ) { extrahei = h; }
240     void setSizeProtection( bool b ) { sizeprotect = b; }
241
242     void doResize();
243     void doMove();
244
245 signals:
246     void activate();
247
248 protected:
249     bool eventFilter( QObject *o, QEvent *e );
250     void mouseMoveEvent( QMouseEvent *e );
251     void keyPressEvent( QKeyEvent *e );
252
253 private:
254     enum MousePosition {
255         Nowhere,
256         TopLeft, BottomRight, BottomLeft, TopRight,
257         Top, Bottom, Left, Right,
258         Center
259     };
260
261     QWidget *widget;
262     QWidget *childWidget;
263     QPoint moveOffset;
264     QPoint invertedMoveOffset;
265     MousePosition mode;
266     int extrahei;
267     int range;
268     uint buttonDown         :1;
269     uint moveResizeMode     :1;
270     uint active             :1;
271     uint sizeprotect        :1;
272     uint moving             :1; 
273
274     void setMouseCursor( MousePosition m );
275     bool isMove() const {
276         return moveResizeMode && mode == Center;
277     }
278     bool isResize() const {
279         return moveResizeMode && !isMove();
280     }
281
282 private:        // Disabled copy constructor and operator=
283 #if defined(Q_DISABLE_COPY)
284     QWidgetResizeHandlerP( const QWidgetResizeHandlerP & );
285     QWidgetResizeHandlerP& operator=( const QWidgetResizeHandlerP & );
286 #endif
287
288 };
289
290 class QToolTip;
291 class QTitleBarPPrivate;
292 class QPixmap;
293
294 class Q_EXPORT QTitleBarP : public QWidget
295 {
296     Q_OBJECT
297     Q_PROPERTY( bool autoRaise READ autoRaise WRITE setAutoRaise )
298     Q_PROPERTY( bool movable READ isMovable WRITE setMovable )
299
300 public:
301     QTitleBarP (QWidget* w, QWidget* parent, const char* name=0);
302     ~QTitleBarP();
303
304     bool isActive() const;
305     bool usesActiveColor() const;
306     virtual QString visibleText() const;
307
308     bool isMovable() const;
309     void setMovable(bool);
310
311     bool autoRaise() const;
312     void setAutoRaise(bool);
313
314     QWidget *window() const;
315
316     QSize sizeHint() const;
317
318 public slots:
319     void setActive( bool );
320     void setCaption( const QString& title );
321     void setIcon( const QPixmap& icon );
322
323 signals:
324     void doActivate();
325     void doNormal();
326     void doClose();
327     void doMaximize();
328     void doMinimize();
329     void doShade();
330     void showOperationMenu();
331     void popupOperationMenu( const QPoint& );
332     void doubleClicked();
333
334 protected:
335     bool event( QEvent *);
336     void resizeEvent( QResizeEvent *);
337     void contextMenuEvent( QContextMenuEvent * );
338     void mousePressEvent( QMouseEvent * );
339     void mouseDoubleClickEvent( QMouseEvent * );
340     void mouseReleaseEvent( QMouseEvent * );
341     void mouseMoveEvent( QMouseEvent * );
342     void enterEvent( QEvent *e );
343     void leaveEvent( QEvent *e );
344     void paintEvent( QPaintEvent *p );
345
346     virtual void cutText();
347
348 private:
349     void readColors();
350
351     QTitleBarPPrivate *d;
352 };
353
354 #endif // QWORKSPACEP_H