Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / PatchQt / qsplitterP.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Module      : PatchQt
3 // File        : qsplitterP.h
4 // Description : the patch for Qt's QSplitter class (qsplitter.h)
5 /////////////////////////////////////////////////////////////////////////////
6
7 /****************************************************************************
8 ** $Id$
9 **
10 ** Defintion of  QSplitter class
11 **
12 **  Created:  980105
13 **
14 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
15 **
16 ** This file is part of the widgets 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 or Qt Professional Edition
28 ** licenses may use this file in accordance with the Qt Commercial License
29 ** Agreement provided 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 #ifndef QSPLITTERP_H
44 #define QSPLITTERP_H
45
46 #ifndef QT_H
47 #include <qframe.h>
48 #include <qvaluelist.h>
49 #include <qwidgetlist.h>        // by STV
50 #endif // QT_H
51 #include <qpushbutton.h>
52
53 #ifndef QT_NO_COMPLEXWIDGETS
54
55 class QSplitterPHandle;
56 class QSplitterPData;
57 class QSplitterPLayoutStruct;
58
59 class Q_EXPORT QSplitterP : public QFrame
60 {
61     Q_OBJECT
62     Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
63       
64 public:
65     enum ResizeMode { Stretch, KeepSize, FollowSizeHint };
66
67     QSplitterP( QWidget *parent=0, const char *name=0 );
68     QSplitterP( Orientation, QWidget *parent=0, const char *name=0 );
69     ~QSplitterP();
70
71     virtual void setOrientation( Orientation );
72     Orientation orientation() const { return orient; }
73
74     virtual void setResizeMode( QWidget *w, ResizeMode );
75     virtual void setOpaqueResize( bool = TRUE );
76     bool opaqueResize() const;
77
78     void moveToFirst( QWidget * );
79     void moveToLast( QWidget * );
80
81     void refresh() { recalc( TRUE ); }
82     QSize sizeHint() const;
83     QSize minimumSizeHint() const;
84     QSizePolicy sizePolicy() const;
85
86     QValueList<int> sizes() const;
87     void setSizes( QValueList<int> );
88     bool isCompressEnabled() const;
89     void setCompressEnabled(bool on);
90
91     void compress(QWidget*);
92     void unCompress(QWidget*);
93
94 // VSR 21/11/02 -> ================================
95     QSplitterPHandle* getHandleAfter(QWidget* w);
96     QSplitterPHandle* getHandleBefore(QWidget* w);
97 // VSR 21/11/02 <- ================================
98
99 // ASL 07/09/04
100    bool isCompressed( const QWidget* ) const;
101 // ASL 07/09/04
102
103 protected:
104     void childEvent( QChildEvent * );
105
106     bool event( QEvent * );
107     void resizeEvent( QResizeEvent * );
108
109     int idAfter( QWidget* ) const;
110     QWidget* widgetBefore( int id ) const;
111     QWidget* widgetAfter( int id ) const;
112
113     QSize minSize( const QWidget *w ) const;
114     QSize maxSize( const QWidget *w ) const;
115     
116     void moveSplitter( QCOORD pos, int id );
117     virtual void drawSplitter( QPainter*, QCOORD x, QCOORD y,
118                                QCOORD w, QCOORD h );
119     void styleChange( QStyle& );
120     int adjustPos( int , int );
121     virtual void setRubberband( int );
122     void getRange( int id, int*, int* );
123
124 private:
125     void init();
126     void recalc( bool update = FALSE );
127     int hit( QPoint p );
128     void doResize();
129     void storeSizes();
130     void processChildEvents();
131     QSplitterPLayoutStruct *addWidget( QWidget*, bool first = FALSE );
132     void recalcId();
133     void moveBefore( int pos, int id, bool upLeft );
134     void moveAfter( int pos, int id, bool upLeft );
135     void setG( QWidget *w, int p, int s );
136     void updateSplitterHandles() const;
137
138     QCOORD pick( const QPoint &p ) const
139     { return orient == Horizontal ? p.x() : p.y(); }
140     QCOORD pick( const QSize &s ) const
141     { return orient == Horizontal ? s.width() : s.height(); }
142
143     QCOORD trans( const QPoint &p ) const
144     { return orient == Vertical ? p.x() : p.y(); }
145     QCOORD trans( const QSize &s ) const
146     { return orient == Vertical ? s.width() : s.height(); }
147
148     QSplitterPData *data;
149     QWidgetList compressed_widgets;
150
151     Orientation orient;
152     bool compress_flag;
153     friend class QSplitterPHandle;
154 private:        // Disabled copy constructor and operator=
155 #if defined(Q_DISABLE_COPY)
156     QSplitterP( const QSplitterP & );
157     QSplitterP& operator=( const QSplitterP & );
158 #endif
159 };
160
161 #endif // QT_NO_COMPLEXWIDGETS
162
163
164 class Q_EXPORT QSplitterPHandle : public QWidget
165 {
166   Q_OBJECT
167 public:
168     QSplitterPHandle( Qt::Orientation o,
169                       QSplitterP *parent, const char* name=0 );
170     void setOrientation( Qt::Orientation o );
171     Qt::Orientation orientation() const { return orient; }
172   
173     bool opaque() const { return s->opaqueResize(); }
174
175     QSize sizeHint() const;
176     QSizePolicy sizePolicy() const;
177
178     int id() const { return myId; } // data->list.at(id())->wid == this
179     void setId( int i ) { myId = i; }
180     void updateButtonState();
181
182 // VSR 21/11/02 -> ================================
183     void compressAfter();
184     void unCompressAfter();
185     void compressBefore();
186     void unCompressBefore();
187 // VSR 21/11/02 <- ================================
188
189 protected:
190     void paintEvent( QPaintEvent * );
191     void mouseMoveEvent( QMouseEvent * );
192     void mousePressEvent( QMouseEvent * );
193     void mouseReleaseEvent( QMouseEvent * );
194
195 protected slots:
196     void onBeforeCompress();
197     void onAfterCompress();
198     void onBeforeUnCompress();
199     void onAfterUnCompress();
200
201 private:
202     Qt::Orientation orient;
203     bool opaq;
204     int myId;
205
206     QSplitterP *s;
207     int oldpos;
208     QPushButton* left;
209     QPushButton* right;
210     QPushButton* unleft;
211     QPushButton* unright;
212 };
213
214
215 #endif // QSPLITTERP_H