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_BasePanel.cxx
24 // Author : Oleg Uvarov
27 #include "VisuGUI_BasePanel.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>
37 //#include <QToolButton>
42 \brief Frame inserted in viewport with redefined sizeHint method
43 in order to avoid unreasonable increasing of viewport size
45 class VisuGUI_BasePanel::MainFrame : public QFrame
50 \param theParent parent widget
52 MainFrame( QWidget* theParent = 0 )
58 \brief Gets frame size hint
59 \return frame size hint
61 virtual QSize sizeHint() const
63 return minimumSizeHint();
68 \class VisuGUI_BasePanel
69 \brief Base class for VISU interactive sub-panels.
71 Set of classes is derived from this class and are intended for representing widgets
72 (GUI controls) for different operations. VisuGUI_BasePanel consists of main frame
73 inserted in scroll view and four push buttons. So all widgets of derived sub-panels
74 should be inherited from mainframe() instead of
\93this
\94 pointer.
78 \brief Constructor creates panels look and feel
79 \param theName name of the panel
80 \param theParent parent widget
82 VisuGUI_BasePanel::VisuGUI_BasePanel( const QString& theName,
85 : QGroupBox( theName, theParent ),
92 myView = new QScrollArea( this );
95 myMainFrame = new MainFrame( myView );
96 myMainFrame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
98 myView->setWidget( myMainFrame );
99 myView->setAlignment( Qt::AlignCenter );
100 myView->setWidgetResizable( true );
101 myView->setMinimumWidth( myMainFrame->sizeHint().width() + 22 );
104 QWidget* aBtnWg = new QWidget( this );
105 QHBoxLayout* aBtnWgLayout = new QHBoxLayout( aBtnWg );
106 //aBtnWgLayout->setSpacing( 5 );
108 aBtnWgLayout->addStretch();
110 if( theBtns & OKBtn )
112 //myOK = new QToolButton( aBtnWg );
113 //myOK->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_OK" ) ) );
114 myOK = new QPushButton( tr( "BUT_OK" ), aBtnWg );
115 aBtnWgLayout->addWidget( myOK );
116 connect( myOK, SIGNAL( clicked() ), SLOT( onOK() ) );
118 if( theBtns & ApplyBtn )
120 //myApply = new QToolButton( aBtnWg );
121 //myApply->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_APPLY" ) ) );
122 myApply = new QPushButton( tr( "BUT_APPLY" ), aBtnWg );
123 aBtnWgLayout->addWidget( myApply );
124 connect( myApply, SIGNAL( clicked() ), SLOT( onApply() ) );
126 if( theBtns & CloseBtn )
128 //myClose = new QToolButton( aBtnWg );
129 //myClose->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_CLOSE" ) ) );
130 myClose = new QPushButton( tr( "BUT_CLOSE" ), aBtnWg );
131 aBtnWgLayout->addWidget( myClose );
132 connect( myClose, SIGNAL( clicked() ), SLOT( onClose() ) );
134 if( theBtns & HelpBtn )
136 //myHelp = new QToolButton( aBtnWg );
137 //myHelp->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_HELP" ) ) );
138 myHelp = new QPushButton( tr( "BUT_HELP" ), aBtnWg );
139 aBtnWgLayout->addWidget( myHelp );
140 connect( myHelp, SIGNAL( clicked() ), SLOT( onHelp() ) );
143 aBtnWgLayout->addStretch();
146 QVBoxLayout* aLay = new QVBoxLayout( this );
147 aLay->setContentsMargins( 0, 0, 0, 0 );
148 //aLay->setSpacing( 5 );
149 aLay->addWidget( myView, 1 );
150 aLay->addWidget( aBtnWg );
156 VisuGUI_BasePanel::~VisuGUI_BasePanel()
161 \brief Verifies validity of input data
163 This virtual method should be redefined in derived classes. Usually operator
164 corresponding to the sub-panel calls this method to check validity of input
165 data when Apply/OK button is pressed.
167 \param theErrMsg Error message.
169 If data is invalid when panel can return message using this parameter given
170 clear explanation what is wrong
172 \return TRUE if data is valid, FALSE otherwise
174 bool VisuGUI_BasePanel::isValid( QString& /*theErrMsg*/ )
179 \brief Virtual methods should be redefined in derived classes and
180 clears all GUI controls
182 void VisuGUI_BasePanel::clear()
187 \brief Virtual slot called when
\93OK
\94 button pressed emits corresponding signal.
189 This slot moves focus in OK button before emitting signal. Mainly it provides
190 application with correct moving data from currently edited controls to internal
191 structure. For example QTable moves data from cell editor to table item when
195 void VisuGUI_BasePanel::onOK()
200 qApp->processEvents();
206 \brief Virtual slot called when
\93Apply
\94 button pressed emits corresponding signal.
209 void VisuGUI_BasePanel::onApply()
214 qApp->processEvents();
220 \brief Virtual slot called when
\93Close
\94 button pressed emits corresponding signal.
223 void VisuGUI_BasePanel::onClose()
231 \brief Virtual slot called when
\93Help
\94 button pressed emits corresponding signal.
234 void VisuGUI_BasePanel::onHelp()
242 \brief Gets frame inserted in scroll view. All controls of derived
243 panels should use it as parent
244 \return QFrame* object
246 QFrame* VisuGUI_BasePanel::mainFrame()