1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Panel.cxx
24 // Author : Oleg Uvarov
27 #include "VisuGUI_Panel.h"
30 #include "VisuGUI_Tools.h"
32 #include "SUIT_ResourceMgr.h"
34 #include <QScrollArea>
35 #include <QHBoxLayout>
36 #include <QVBoxLayout>
37 #include <QApplication>
38 #include <QPushButton>
43 \brief Frame inserted in viewport with redefined sizeHint method
44 in order to avoid unreasonable increasing of viewport size
46 class VisuGUI_Panel::MainFrame : public QFrame
51 \param theParent parent widget
53 MainFrame( QWidget* theParent = 0 )
59 \brief Gets frame size hint
60 \return frame size hint
62 virtual QSize sizeHint() const
64 return minimumSizeHint();
70 \brief Base class for VISU interactive dockable panels.
72 Set of classes is derived from this class and are intended for representing widgets
73 (GUI controls) for different operations. VisuGUI_Panel consists of main frame
74 inserted in scroll view and four push buttons. So all widgets of derived sub-panels
75 should be inherited from mainframe() instead of
\93this
\94 pointer.
79 \brief Constructor creates panels look and feel
80 \param theName name of the panel
81 \param theParent parent widget
83 VisuGUI_Panel::VisuGUI_Panel( const QString& theName,
84 const VisuGUI* theModule,
87 : QtxDockWidget( theName, theParent ),
88 myModule( theModule ),
94 QWidget* aGrp = new QWidget( this );
98 myView = new QScrollArea( aGrp );
101 myMainFrame = new MainFrame( myView );
102 myMainFrame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
104 myView->setWidget( myMainFrame );
105 myView->setAlignment( Qt::AlignCenter );
106 myView->setWidgetResizable( true );
107 myView->setMinimumWidth( myMainFrame->sizeHint().width() + 22 );
110 QWidget* aBtnWg = new QWidget( aGrp );
111 QHBoxLayout* aBtnWgLayout = new QHBoxLayout( aBtnWg );
113 aBtnWgLayout->addStretch();
115 if( theBtns & OKBtn )
117 myOK = new QPushButton( tr( "BUT_OK" ), aBtnWg );
118 aBtnWgLayout->addWidget( myOK );
119 connect( myOK, SIGNAL( clicked() ), SLOT( onOK() ) );
121 if( theBtns & ApplyBtn )
123 myApply = new QPushButton( tr( "BUT_APPLY" ), aBtnWg );
124 aBtnWgLayout->addWidget( myApply );
125 connect( myApply, SIGNAL( clicked() ), SLOT( onApply() ) );
127 if( theBtns & CloseBtn )
129 myClose = new QPushButton( tr( "BUT_CLOSE" ), aBtnWg );
130 aBtnWgLayout->addWidget( myClose );
131 connect( myClose, SIGNAL( clicked() ), SLOT( onClose() ) );
133 if( theBtns & HelpBtn )
135 myHelp = new QPushButton( tr( "BUT_HELP" ), aBtnWg );
136 aBtnWgLayout->addWidget( myHelp );
137 connect( myHelp, SIGNAL( clicked() ), SLOT( onHelp() ) );
140 aBtnWgLayout->addStretch();
143 QVBoxLayout* aLay = new QVBoxLayout( aGrp );
144 aLay->setContentsMargins( 0, 0, 0, 0 );
145 aLay->addWidget( myView, 1 );
146 aLay->addWidget( aBtnWg );
152 VisuGUI_Panel::~VisuGUI_Panel()
157 \brief Verifies validity of input data
159 This virtual method should be redefined in derived classes. Usually operator
160 corresponding to the sub-panel calls this method to check validity of input
161 data when Apply/OK button is pressed.
163 \param theErrMsg Error message.
165 If data is invalid when panel can return message using this parameter given
166 clear explanation what is wrong
168 \return TRUE if data is valid, FALSE otherwise
170 bool VisuGUI_Panel::isValid( QString& /*theErrMsg*/ )
175 \brief Virtual methods should be redefined in derived classes and
176 clears all GUI controls
178 void VisuGUI_Panel::clear()
183 \brief Virtual slot called when
\93OK
\94 button pressed emits corresponding signal.
185 This slot moves focus in OK button before emitting signal. Mainly it provides
186 application with correct moving data from currently edited controls to internal
187 structure. For example QTable moves data from cell editor to table item when
191 void VisuGUI_Panel::onOK()
196 qApp->processEvents();
201 \brief Virtual slot called when
\93Apply
\94 button pressed emits corresponding signal.
204 void VisuGUI_Panel::onApply()
209 qApp->processEvents();
214 \brief Virtual slot called when
\93Close
\94 button pressed emits corresponding signal.
217 void VisuGUI_Panel::onClose()
224 \brief Virtual slot called when
\93Help
\94 button pressed emits corresponding signal.
227 void VisuGUI_Panel::onHelp()
234 \brief Gets frame inserted in scroll view. All controls of derived
235 panels should use it as parent
236 \return QFrame* object
238 QFrame* VisuGUI_Panel::mainFrame()