Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEGUI / QAD_StudyFrame.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
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   : QAD_StudyFrame.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 /*!
30   \class QAD_StudyFrame QAD_StudyFrame.h
31   \brief Frame window which contains QAD_LeftFrame and QAD_RightFrame.
32 */
33
34 #include "QAD_StudyFrame.h"
35 #include "QAD_StudyFrame.h"
36 #include "QAD_RightFrame.h"
37 #include "QAD_LeftFrame.h"
38 #include "QAD_Splitter.h"
39 #include "QAD_Application.h"
40 #include "QAD_Desktop.h"
41 #include "QAD_Study.h"
42 #include "QAD_ObjectBrowser.h"
43 #include "QAD_PyInterp.h"
44
45 #include <qvaluelist.h>
46
47 using namespace std;
48
49 /*!
50     Constructor
51 */
52 QAD_StudyFrame::QAD_StudyFrame(QAD_Study* theStudy, QWidget* theParent, 
53                                const QString& theTitle, ViewType theTypeView,
54                                QAD_PyInterp*& theInterp, QMutex* theMutex):
55   QMainWindow( theParent , theTitle,  WStyle_NormalBorder | 
56                WStyle_MinMax | WStyle_SysMenu | WDestructiveClose),
57   myTitle(theTitle),
58   myEntry(""),
59   myTypeView(theTypeView),
60   myStudy(theStudy), 
61   myInterp(theInterp)
62 {
63   setCaption( myTitle );
64   setPalette(QAD_Application::getPalette());
65
66   mySplitter = new QAD_Splitter( Qt::Horizontal, this);
67   mySplitter->setCompressEnabled( true );
68
69   setCentralWidget(mySplitter);
70   myLeftFrm = new QAD_LeftFrame(myStudy->getStudyDocument(), mySplitter, theTitle );
71   myRightFrm = new QAD_RightFrame( mySplitter, theTitle, myTypeView, myInterp, theMutex);
72
73   QValueList<int> sizes;
74   sizes.append( (int)(0.30*QAD_Application::getDesktop()->getMainFrame()->width()) );
75   sizes.append( (int)(0.50*QAD_Application::getDesktop()->getMainFrame()->width()) );
76   mySplitter->setSizes( sizes );
77
78   QAD_ASSERT_DEBUG_ONLY ( theParent->inherits("QWorkspaceP") );
79   QAD_ASSERT ( QObject::connect( (QWorkspaceP*)theParent, SIGNAL(windowActivated(QWidget*)), 
80                                  this, SLOT(onStudyFrameActivated(QWidget*))) );
81 }
82
83
84 /*!
85     Destructor
86 */
87 QAD_StudyFrame::~QAD_StudyFrame()
88
89 }
90
91 /*!
92     Returns the rightframe of this frame        
93 */
94 QAD_RightFrame* QAD_StudyFrame::getRightFrame() const
95 {
96   return myRightFrm;
97 }
98
99 /*!
100     Returns the leftframe of this frame 
101 */
102 QAD_LeftFrame* QAD_StudyFrame::getLeftFrame() const
103 {
104   return myLeftFrm;
105 }
106
107 /*!
108     Returns 'true' if studyframe is visible
109 */
110 void QAD_StudyFrame::setVisible( bool visible )
111 {
112   if ( visible == isVisible() )
113     return;
114   
115   if ( visible ) show();
116   else hide();
117 }
118
119 /*!
120    Called when StudyFrame is about to close
121 */
122 void QAD_StudyFrame::closeEvent(QCloseEvent* e)
123 {
124   if ( IsPyLocked() ) {
125     e->ignore();
126     return;
127   }
128
129   emit sfStudyFrameClosing(this); 
130 }
131
132 /*!
133   Call when  
134  */
135 void QAD_StudyFrame::compressLeft()
136 {
137   QSplitterPHandle* h = mySplitter->getHandleAfter(myLeftFrm);
138   if( h ) 
139     h->compressBefore();
140 }
141
142 void QAD_StudyFrame::compressRight()
143 {
144   QSplitterPHandle* h = mySplitter->getHandleAfter(myLeftFrm);
145   if( h )
146     h->compressAfter();
147 }
148
149 void QAD_StudyFrame::unCompressLeft()
150 {
151   QSplitterPHandle* h = mySplitter->getHandleAfter(myLeftFrm);
152   if( h )
153     h->unCompressBefore();
154 }
155
156 void QAD_StudyFrame::unCompressRight()
157 {
158   QSplitterPHandle* h = mySplitter->getHandleAfter(myLeftFrm);
159   if( h )
160     h->unCompressAfter();
161 }
162
163 bool QAD_StudyFrame::isCompressedLeft() const
164 {
165   return mySplitter->isCompressed(myLeftFrm);
166 }
167
168 bool QAD_StudyFrame::isCompressedRight() const
169 {
170   return mySplitter->isCompressed(myRightFrm);
171 }
172
173 /*!
174     Returns the title of studyframe
175 */
176 const QString& QAD_StudyFrame::title() const
177 {
178     return myTitle;
179 }
180
181 /*!
182     Sets the new title of studyframe
183 */
184 void QAD_StudyFrame::setTitle( const QString& title )
185 {
186   myTitle = title;      
187   setCaption( myTitle );
188 }
189
190 /*!
191     Returns the entry of studyframe
192 */
193 const QString& QAD_StudyFrame::entry() const
194 {
195   return myEntry;
196 }
197
198 /*!
199     Sets the new entru of studyframe
200 */
201 void QAD_StudyFrame::setEntry( const QString& entry )
202 {
203   myEntry = entry;      
204 }
205
206 ViewType QAD_StudyFrame::getTypeView() const
207 {
208   return myTypeView;    
209 }
210
211 /*!
212     The slot is called when a studyframe is activated
213 */
214 void QAD_StudyFrame::onStudyFrameActivated ( QWidget* activeWindow )
215 {
216   emit sfStudyFrameActivated( (QAD_StudyFrame*) activeWindow );
217   getRightFrame()->getViewFrame()->Activate( getStudy() );
218 }
219
220 /*!
221   Returns the Python interpreter that belongs to this study
222 */
223 QAD_PyInterp* QAD_StudyFrame::get_PyInterp(void)
224 {
225   return myInterp;
226 }