1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU VISUGUI : GUI of VISU component
21 // File : VisuGUI_Panel.cxx
22 // Author : Oleg Uvarov
25 #include "VisuGUI_Panel.h"
28 #include "VisuGUI_Tools.h"
30 #include "SUIT_ResourceMgr.h"
32 #include <QScrollArea>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
35 #include <QApplication>
36 #include <QPushButton>
41 \brief Frame inserted in viewport with redefined sizeHint method
42 in order to avoid unreasonable increasing of viewport size
44 class VisuGUI_Panel::MainFrame : public QWidget
49 \param theParent parent widget
51 MainFrame( QWidget* theParent = 0 )
52 : QWidget( theParent )
57 \brief Gets frame size hint
58 \return frame size hint
60 virtual QSize sizeHint() const
62 return minimumSizeHint();
68 \brief Base class for VISU interactive dockable panels.
70 Set of classes is derived from this class and are intended for representing widgets
71 (GUI controls) for different operations. VisuGUI_Panel consists of main frame
72 inserted in scroll view and four push buttons. So all widgets of derived sub-panels
73 should be inherited from mainframe() instead of
\93this
\94 pointer.
77 \brief Constructor creates panels look and feel
78 \param theName panel title
79 \param theModule parent VISU GUI module
80 \param theParent parent widget
81 \param theBtns panel buttons
83 VisuGUI_Panel::VisuGUI_Panel( const QString& theName,
87 : QtxDockWidget( true, theParent ),
88 myModule( theModule ),
94 setObjectName( theName );
96 QWidget* aGrp = new QWidget( this );
100 myView = new QScrollArea( aGrp );
101 myView->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
104 myMainFrame = new MainFrame( myView );
106 myView->setWidget( myMainFrame );
107 myView->setAlignment( Qt::AlignCenter );
108 myView->setWidgetResizable( true );
109 myView->setMinimumWidth( myMainFrame->sizeHint().width() + 22 );
112 QHBoxLayout* aBtnWgLayout = new QHBoxLayout;
113 aBtnWgLayout->setMargin( 0 );
115 aBtnWgLayout->addStretch();
117 if( theBtns & OKBtn )
119 myOK = new QPushButton( tr( "BUT_OK" ), aGrp );
120 aBtnWgLayout->addWidget( myOK );
121 connect( myOK, SIGNAL( clicked() ), SLOT( onOK() ) );
123 if( theBtns & ApplyBtn )
125 myApply = new QPushButton( tr( "BUT_APPLY" ), aGrp );
126 aBtnWgLayout->addWidget( myApply );
127 connect( myApply, SIGNAL( clicked() ), SLOT( onApply() ) );
129 if( theBtns & CloseBtn )
131 myClose = new QPushButton( tr( "BUT_CLOSE" ), aGrp );
132 aBtnWgLayout->addWidget( myClose );
133 connect( myClose, SIGNAL( clicked() ), SLOT( onClose() ) );
135 if( theBtns & HelpBtn )
137 myHelp = new QPushButton( tr( "BUT_HELP" ), aGrp );
138 aBtnWgLayout->addWidget( myHelp );
139 connect( myHelp, SIGNAL( clicked() ), SLOT( onHelp() ) );
142 aBtnWgLayout->addStretch();
145 QVBoxLayout* aLay = new QVBoxLayout( aGrp );
146 aLay->setMargin( 2 );
147 aLay->addWidget( myView, 1 );
148 aLay->addLayout( aBtnWgLayout );
150 connect( theModule, SIGNAL( moduleDeactivated() ), SLOT( onModuleDeactivated() ) );
151 connect( theModule, SIGNAL( moduleActivated() ), SLOT( onModuleActivated() ) );
157 VisuGUI_Panel::~VisuGUI_Panel()
162 \brief Verifies validity of input data
164 This virtual method should be redefined in derived classes. Usually operator
165 corresponding to the sub-panel calls this method to check validity of input
166 data when Apply/OK button is pressed.
168 \param theErrMsg Error message.
170 If data is invalid when panel can return message using this parameter given
171 clear explanation what is wrong
173 \return TRUE if data is valid, FALSE otherwise
175 bool VisuGUI_Panel::isValid( QString& /*theErrMsg*/ )
180 \brief Virtual methods should be redefined in derived classes and
181 clears all GUI controls
183 void VisuGUI_Panel::clear()
188 \brief Virtual slot called when
\93OK
\94 button pressed emits corresponding signal.
190 This slot moves focus in OK button before emitting signal. Mainly it provides
191 application with correct moving data from currently edited controls to internal
192 structure. For example QTable moves data from cell editor to table item when
196 void VisuGUI_Panel::onOK()
201 qApp->processEvents();
206 \brief Virtual slot called when
\93Apply
\94 button pressed emits corresponding signal.
209 void VisuGUI_Panel::onApply()
214 qApp->processEvents();
219 \brief Virtual slot called when
\93Close
\94 button pressed emits corresponding signal.
222 void VisuGUI_Panel::onClose()
230 \brief Virtual slot called when
\93Help
\94 button pressed emits corresponding signal.
233 void VisuGUI_Panel::onHelp()
240 \brief Gets frame inserted in scroll view. All controls of derived
241 panels should use it as parent
242 \return QFrame* object
244 QWidget* VisuGUI_Panel::mainFrame()
249 void VisuGUI_Panel::onModuleActivated()
251 widget()->setHidden( false );
254 void VisuGUI_Panel::onModuleDeactivated()
256 widget()->setHidden( true );