Salome HOME
NRI : Merge from V1_2.
[modules/kernel.git] / src / PatchQt / qsplitterP.h
1 //  SALOME PatchQt : patch for Qt
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : qsplitterP.h
25 //  Module : SALOME
26
27 /****************************************************************************
28 ** $Id$
29 **
30 ** Defintion of  QSplitter class
31 **
32 **  Created:  980105
33 **
34 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
35 **
36 ** This file is part of the widgets module of the Qt GUI Toolkit.
37 **
38 ** This file may be distributed under the terms of the Q Public License
39 ** as defined by Trolltech AS of Norway and appearing in the file
40 ** LICENSE.QPL included in the packaging of this file.
41 **
42 ** This file may be distributed and/or modified under the terms of the
43 ** GNU General Public License version 2 as published by the Free Software
44 ** Foundation and appearing in the file LICENSE.GPL included in the
45 ** packaging of this file.
46 **
47 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
48 ** licenses may use this file in accordance with the Qt Commercial License
49 ** Agreement provided with the Software.
50 **
51 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
52 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
53 **
54 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
55 **   information about Qt Commercial License Agreements.
56 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
57 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
58 **
59 ** Contact info@trolltech.com if any conditions of this licensing are
60 ** not clear to you.
61 **
62 **********************************************************************/
63 #ifndef QSPLITTERP_H
64 #define QSPLITTERP_H
65
66 #ifndef QT_H
67 #include <qframe.h>
68 #include <qvaluelist.h>
69 #include <qwidgetlist.h>        // by STV
70 #endif // QT_H
71 #include <qpushbutton.h>
72
73 #ifndef QT_NO_COMPLEXWIDGETS
74
75 class QSplitterPHandle;
76 class QSplitterPData;
77 class QSplitterPLayoutStruct;
78
79 class Q_EXPORT QSplitterP : public QFrame
80 {
81     Q_OBJECT
82     Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
83       
84 public:
85     enum ResizeMode { Stretch, KeepSize, FollowSizeHint };
86
87     QSplitterP( QWidget *parent=0, const char *name=0 );
88     QSplitterP( Orientation, QWidget *parent=0, const char *name=0 );
89     ~QSplitterP();
90
91     virtual void setOrientation( Orientation );
92     Orientation orientation() const { return orient; }
93
94     virtual void setResizeMode( QWidget *w, ResizeMode );
95     virtual void setOpaqueResize( bool = TRUE );
96     bool opaqueResize() const;
97
98     void moveToFirst( QWidget * );
99     void moveToLast( QWidget * );
100
101     void refresh() { recalc( TRUE ); }
102     QSize sizeHint() const;
103     QSize minimumSizeHint() const;
104     QSizePolicy sizePolicy() const;
105
106     QValueList<int> sizes() const;
107     void setSizes( QValueList<int> );
108     bool isCompressEnabled() const;
109     void setCompressEnabled(bool on);
110
111     void compress(QWidget*);
112     void unCompress(QWidget*);
113
114 // VSR 21/11/02 -> ================================
115     QSplitterPHandle* getHandleAfter(QWidget* w);
116     QSplitterPHandle* getHandleBefore(QWidget* w);
117 // VSR 21/11/02 <- ================================
118
119 protected:
120     void childEvent( QChildEvent * );
121
122     bool event( QEvent * );
123     void resizeEvent( QResizeEvent * );
124
125     int idAfter( QWidget* ) const;
126     QWidget* widgetBefore( int id ) const;
127     QWidget* widgetAfter( int id ) const;
128     bool isCompressed(const QWidget*) const;
129     QSize minSize( const QWidget *w ) const;
130     QSize maxSize( const QWidget *w ) const;
131     
132     void moveSplitter( QCOORD pos, int id );
133     virtual void drawSplitter( QPainter*, QCOORD x, QCOORD y,
134                                QCOORD w, QCOORD h );
135     void styleChange( QStyle& );
136     int adjustPos( int , int );
137     virtual void setRubberband( int );
138     void getRange( int id, int*, int* );
139
140 private:
141     void init();
142     void recalc( bool update = FALSE );
143     int hit( QPoint p );
144     void doResize();
145     void storeSizes();
146     void processChildEvents();
147     QSplitterPLayoutStruct *addWidget( QWidget*, bool first = FALSE );
148     void recalcId();
149     void moveBefore( int pos, int id, bool upLeft );
150     void moveAfter( int pos, int id, bool upLeft );
151     void setG( QWidget *w, int p, int s );
152     void updateSplitterHandles() const;
153
154     QCOORD pick( const QPoint &p ) const
155     { return orient == Horizontal ? p.x() : p.y(); }
156     QCOORD pick( const QSize &s ) const
157     { return orient == Horizontal ? s.width() : s.height(); }
158
159     QCOORD trans( const QPoint &p ) const
160     { return orient == Vertical ? p.x() : p.y(); }
161     QCOORD trans( const QSize &s ) const
162     { return orient == Vertical ? s.width() : s.height(); }
163
164     QSplitterPData *data;
165     QWidgetList compressed_widgets;
166
167     Orientation orient;
168     bool compress_flag;
169     friend class QSplitterPHandle;
170 private:        // Disabled copy constructor and operator=
171 #if defined(Q_DISABLE_COPY)
172     QSplitterP( const QSplitterP & );
173     QSplitterP& operator=( const QSplitterP & );
174 #endif
175 };
176
177 #endif // QT_NO_COMPLEXWIDGETS
178
179
180 class Q_EXPORT QSplitterPHandle : public QWidget
181 {
182   Q_OBJECT
183 public:
184     QSplitterPHandle( Qt::Orientation o,
185                       QSplitterP *parent, const char* name=0 );
186     void setOrientation( Qt::Orientation o );
187     Qt::Orientation orientation() const { return orient; }
188   
189     bool opaque() const { return s->opaqueResize(); }
190
191     QSize sizeHint() const;
192     QSizePolicy sizePolicy() const;
193
194     int id() const { return myId; } // data->list.at(id())->wid == this
195     void setId( int i ) { myId = i; }
196     void updateButtonState();
197
198 // VSR 21/11/02 -> ================================
199     void compressAfter();
200     void unCompressAfter();
201     void compressBefore();
202     void unCompressBefore();
203 // VSR 21/11/02 <- ================================
204
205 protected:
206     void paintEvent( QPaintEvent * );
207     void mouseMoveEvent( QMouseEvent * );
208     void mousePressEvent( QMouseEvent * );
209     void mouseReleaseEvent( QMouseEvent * );
210
211 protected slots:
212     void onBeforeCompress();
213     void onAfterCompress();
214     void onBeforeUnCompress();
215     void onAfterUnCompress();
216
217 private:
218     Qt::Orientation orient;
219     bool opaq;
220     int myId;
221
222     QSplitterP *s;
223     int oldpos;
224     QPushButton* left;
225     QPushButton* right;
226     QPushButton* unleft;
227     QPushButton* unright;
228 };
229
230
231 #endif // QSPLITTERP_H