Salome HOME
PR: merge from tag V2_2_2
[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 #if QT_VERSION > 0x030005
58 #include <qworkspace.h>
59 #define QWorkspaceP QWorkspace
60 #else
61
62 class QWorkspacePChild;
63 class QShowEvent;
64 class QWorkspacePPrivate;
65 class QPopupMenu;
66 class QWidgetResizeHandlerP;
67 class QTitleBarP;
68
69 class Q_EXPORT QWorkspaceP : public QWidget
70 {
71     Q_OBJECT
72     Q_PROPERTY( bool scrollBarsEnabled READ scrollBarsEnabled WRITE setScrollBarsEnabled )
73 public:
74     QWorkspaceP( QWidget* parent=0, const char* name=0 );
75     ~QWorkspaceP();
76
77     QWidget* activeWindow() const;
78     QWidgetList windowList() const;
79
80     QSize sizeHint() const;
81
82     bool scrollBarsEnabled() const;
83     void setScrollBarsEnabled( bool enable );
84
85     void setPaletteBackgroundColor( const QColor & );
86     void setPaletteBackgroundPixmap( const QPixmap & );
87
88 signals:
89     void windowActivated( QWidget* w);
90
91 public slots:
92     void cascade();
93     void tile();
94
95 protected:
96 #ifndef QT_NO_STYLE
97     void styleChange( QStyle& );
98 #endif
99     void childEvent( QChildEvent * );
100     void resizeEvent( QResizeEvent * );
101     bool eventFilter( QObject *, QEvent * );
102     void showEvent( QShowEvent *e );
103     void hideEvent( QHideEvent *e );
104 #ifndef QT_NO_WHEELEVENT
105     void wheelEvent( QWheelEvent *e );
106 #endif
107
108 private slots:
109     void closeActiveWindow();
110     void closeAllWindows();
111     void normalizeActiveWindow();
112     void minimizeActiveWindow();
113     void showOperationMenu();
114     void popupOperationMenu( const QPoint& );
115     void operationMenuActivated( int );
116     void operationMenuAboutToShow();
117     void toolMenuAboutToShow();
118     void scrollBarChanged();
119 public slots:
120     void activateNextWindow();
121     void activatePreviousWindow();
122
123 public:
124     void activateWindow( QWidget* w, bool change_focus = TRUE );
125
126 private:
127     void insertIcon( QWidget* w);
128     void removeIcon( QWidget* w);
129     void place( QWidget* );
130
131     QWorkspacePChild* findChild( QWidget* w);
132     void showMaximizeControls();
133     void hideMaximizeControls();
134     void showWindow( QWidget* w);
135     void maximizeWindow( QWidget* w);
136     void minimizeWindow( QWidget* w);
137     void normalizeWindow( QWidget* w);
138
139     QRect updateWorkspace();
140
141     QPopupMenu* popup;
142     QWorkspacePPrivate* d;
143
144     friend class QWorkspacePChild;
145
146 private:        // Disabled copy constructor and operator=
147 #if defined(Q_DISABLE_COPY)
148     QWorkspaceP( const QWorkspaceP & );
149     QWorkspaceP& operator=( const QWorkspaceP & );
150 #endif
151 };
152
153 class QWorkspacePChild : public QFrame
154 {
155     Q_OBJECT
156
157     friend class QWorkspaceP;
158     friend class QTitleBarP;
159
160 public:
161     QWorkspacePChild( QWidget* window,
162                      QWorkspaceP* parent=0, const char* name=0 );
163     ~QWorkspacePChild();
164
165     void setActive( bool );
166     bool isActive() const;
167
168     void adjustToFullscreen();
169     void adjustSize();
170
171     QWidget* windowWidget() const;
172     QWidget* iconWidget() const;
173
174     void doResize();
175     void doMove();
176
177     QSize sizeHint() const;
178     QSize minimumSizeHint() const;
179
180     QSize baseSize() const;
181
182 signals:
183     void showOperationMenu();
184     void popupOperationMenu( const QPoint& );
185
186 public slots:
187     void activate();
188     void showMinimized();
189     void showMaximized();
190     void showNormal();
191     void showShaded();
192     void setCaption( const QString& );
193     void internalRaise();
194     void titleBarDoubleClicked();
195
196     void move( int x, int y );
197
198 protected:
199     void enterEvent( QEvent * );
200     void leaveEvent( QEvent * );
201     void childEvent( QChildEvent* );
202     void resizeEvent( QResizeEvent * );
203     void moveEvent( QMoveEvent * );
204     bool eventFilter( QObject *, QEvent * );
205
206     bool focusNextPrevChild( bool );
207
208     void drawFrame( QPainter * );
209     void styleChange( QStyle & );
210
211 private:
212     QWidget* childWidget;
213     QWidget* lastfocusw;
214     QWidgetResizeHandlerP *widgetResizeHandler;
215     QTitleBarP* titlebar;
216     QGuardedPtr<QTitleBarP> iconw;
217     QSize windowSize;
218     QSize shadeRestore;
219     QSize shadeRestoreMin;
220     bool act                :1;
221     bool shademode          :1;
222     bool snappedRight       :1;
223     bool snappedDown        :1;
224 };
225
226 #ifndef QT_H
227 #endif // QT_H
228 class QMouseEvent;
229 class QKeyEvent;
230
231 class Q_EXPORT QWidgetResizeHandlerP : public QObject
232 {
233     Q_OBJECT
234
235 public:
236     QWidgetResizeHandlerP( QWidget *parent, QWidget *cw = 0, const char *name = 0 );
237     void setActive( bool b ) { active = b; if ( !active ) setMouseCursor( Nowhere ); }
238     bool isActive() const { return active; }
239     void setMovingEnabled( bool b ) { moving = b; }
240     bool isMovingEnabled() const { return moving; }
241
242     bool isButtonDown() const { return buttonDown; }
243
244     void setExtraHeight( int h ) { extrahei = h; }
245     void setSizeProtection( bool b ) { sizeprotect = b; }
246
247     void doResize();
248     void doMove();
249
250 signals:
251     void activate();
252
253 protected:
254     bool eventFilter( QObject *o, QEvent *e );
255     void mouseMoveEvent( QMouseEvent *e );
256     void keyPressEvent( QKeyEvent *e );
257
258 private:
259     enum MousePosition {
260         Nowhere,
261         TopLeft, BottomRight, BottomLeft, TopRight,
262         Top, Bottom, Left, Right,
263         Center
264     };
265
266     QWidget *widget;
267     QWidget *childWidget;
268     QPoint moveOffset;
269     QPoint invertedMoveOffset;
270     MousePosition mode;
271     int extrahei;
272     int range;
273     uint buttonDown         :1;
274     uint moveResizeMode     :1;
275     uint active             :1;
276     uint sizeprotect        :1;
277     uint moving             :1; 
278
279     void setMouseCursor( MousePosition m );
280     bool isMove() const {
281         return moveResizeMode && mode == Center;
282     }
283     bool isResize() const {
284         return moveResizeMode && !isMove();
285     }
286
287 private:        // Disabled copy constructor and operator=
288 #if defined(Q_DISABLE_COPY)
289     QWidgetResizeHandlerP( const QWidgetResizeHandlerP & );
290     QWidgetResizeHandlerP& operator=( const QWidgetResizeHandlerP & );
291 #endif
292
293 };
294
295 class QToolTip;
296 class QTitleBarPPrivate;
297 class QPixmap;
298
299 class Q_EXPORT QTitleBarP : public QWidget
300 {
301     Q_OBJECT
302     Q_PROPERTY( bool autoRaise READ autoRaise WRITE setAutoRaise )
303     Q_PROPERTY( bool movable READ isMovable WRITE setMovable )
304
305 public:
306     QTitleBarP (QWidget* w, QWidget* parent, const char* name=0);
307     ~QTitleBarP();
308
309     bool isActive() const;
310     bool usesActiveColor() const;
311     virtual QString visibleText() const;
312
313     bool isMovable() const;
314     void setMovable(bool);
315
316     bool autoRaise() const;
317     void setAutoRaise(bool);
318
319     QWidget *window() const;
320
321     QSize sizeHint() const;
322
323 public slots:
324     void setActive( bool );
325     void setCaption( const QString& title );
326     void setIcon( const QPixmap& icon );
327
328 signals:
329     void doActivate();
330     void doNormal();
331     void doClose();
332     void doMaximize();
333     void doMinimize();
334     void doShade();
335     void showOperationMenu();
336     void popupOperationMenu( const QPoint& );
337     void doubleClicked();
338
339 protected:
340     bool event( QEvent *);
341     void resizeEvent( QResizeEvent *);
342     void contextMenuEvent( QContextMenuEvent * );
343     void mousePressEvent( QMouseEvent * );
344     void mouseDoubleClickEvent( QMouseEvent * );
345     void mouseReleaseEvent( QMouseEvent * );
346     void mouseMoveEvent( QMouseEvent * );
347     void enterEvent( QEvent *e );
348     void leaveEvent( QEvent *e );
349     void paintEvent( QPaintEvent *p );
350
351     virtual void cutText();
352
353 private:
354     void readColors();
355
356     QTitleBarPPrivate *d;
357 };
358 #endif // QT_VERSION
359 #endif // QWORKSPACEP_H