1 // Copyright (C) 2007-2011 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_BasePanel.cxx
22 // Author : Oleg Uvarov
25 #include "VisuGUI_BasePanel.h"
26 #include "VisuGUI_Tools.h"
28 #include "SUIT_ResourceMgr.h"
30 #include <QScrollArea>
31 #include <QHBoxLayout>
32 #include <QVBoxLayout>
33 #include <QApplication>
34 #include <QPushButton>
35 //#include <QToolButton>
40 \brief Frame inserted in viewport with redefined sizeHint method
41 in order to avoid unreasonable increasing of viewport size
43 class VisuGUI_BasePanel::MainFrame : public QFrame
48 \param theParent parent widget
50 MainFrame( QWidget* theParent = 0 )
56 \brief Gets frame size hint
57 \return frame size hint
59 virtual QSize sizeHint() const
61 return minimumSizeHint();
66 \class VisuGUI_BasePanel
67 \brief Base class for VISU interactive sub-panels.
69 Set of classes is derived from this class and are intended for representing widgets
70 (GUI controls) for different operations. VisuGUI_BasePanel consists of main frame
71 inserted in scroll view and four push buttons. So all widgets of derived sub-panels
72 should be inherited from mainframe() instead of
\93this
\94 pointer.
76 \brief Constructor creates panels look and feel
77 \param theName name of the panel
78 \param theParent parent widget
80 VisuGUI_BasePanel::VisuGUI_BasePanel( const QString& theName,
83 : QGroupBox( theName, theParent ),
90 myView = new QScrollArea( this );
93 myMainFrame = new MainFrame( myView );
94 myMainFrame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
96 myView->setWidget( myMainFrame );
97 myView->setAlignment( Qt::AlignCenter );
98 myView->setWidgetResizable( true );
99 myView->setMinimumWidth( myMainFrame->sizeHint().width() + 22 );
102 QWidget* aBtnWg = new QWidget( this );
103 QHBoxLayout* aBtnWgLayout = new QHBoxLayout( aBtnWg );
104 //aBtnWgLayout->setSpacing( 5 );
106 aBtnWgLayout->addStretch();
108 if( theBtns & OKBtn )
110 //myOK = new QToolButton( aBtnWg );
111 //myOK->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_OK" ) ) );
112 myOK = new QPushButton( tr( "BUT_OK" ), aBtnWg );
113 aBtnWgLayout->addWidget( myOK );
114 connect( myOK, SIGNAL( clicked() ), SLOT( onOK() ) );
116 if( theBtns & ApplyBtn )
118 //myApply = new QToolButton( aBtnWg );
119 //myApply->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_APPLY" ) ) );
120 myApply = new QPushButton( tr( "BUT_APPLY" ), aBtnWg );
121 aBtnWgLayout->addWidget( myApply );
122 connect( myApply, SIGNAL( clicked() ), SLOT( onApply() ) );
124 if( theBtns & CloseBtn )
126 //myClose = new QToolButton( aBtnWg );
127 //myClose->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_CLOSE" ) ) );
128 myClose = new QPushButton( tr( "BUT_CLOSE" ), aBtnWg );
129 aBtnWgLayout->addWidget( myClose );
130 connect( myClose, SIGNAL( clicked() ), SLOT( onClose() ) );
132 if( theBtns & HelpBtn )
134 //myHelp = new QToolButton( aBtnWg );
135 //myHelp->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr( "ICON_HELP" ) ) );
136 myHelp = new QPushButton( tr( "BUT_HELP" ), aBtnWg );
137 aBtnWgLayout->addWidget( myHelp );
138 connect( myHelp, SIGNAL( clicked() ), SLOT( onHelp() ) );
141 aBtnWgLayout->addStretch();
144 QVBoxLayout* aLay = new QVBoxLayout( this );
145 aLay->setContentsMargins( 0, 0, 0, 0 );
146 //aLay->setSpacing( 5 );
147 aLay->addWidget( myView, 1 );
148 aLay->addWidget( aBtnWg );
154 VisuGUI_BasePanel::~VisuGUI_BasePanel()
159 \brief Verifies validity of input data
161 This virtual method should be redefined in derived classes. Usually operator
162 corresponding to the sub-panel calls this method to check validity of input
163 data when Apply/OK button is pressed.
165 \param theErrMsg Error message.
167 If data is invalid when panel can return message using this parameter given
168 clear explanation what is wrong
170 \return TRUE if data is valid, FALSE otherwise
172 bool VisuGUI_BasePanel::isValid( QString& /*theErrMsg*/ )
177 \brief Virtual methods should be redefined in derived classes and
178 clears all GUI controls
180 void VisuGUI_BasePanel::clear()
185 \brief Virtual slot called when
\93OK
\94 button pressed emits corresponding signal.
187 This slot moves focus in OK button before emitting signal. Mainly it provides
188 application with correct moving data from currently edited controls to internal
189 structure. For example QTable moves data from cell editor to table item when
193 void VisuGUI_BasePanel::onOK()
198 qApp->processEvents();
204 \brief Virtual slot called when
\93Apply
\94 button pressed emits corresponding signal.
207 void VisuGUI_BasePanel::onApply()
212 qApp->processEvents();
218 \brief Virtual slot called when
\93Close
\94 button pressed emits corresponding signal.
221 void VisuGUI_BasePanel::onClose()
229 \brief Virtual slot called when
\93Help
\94 button pressed emits corresponding signal.
232 void VisuGUI_BasePanel::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 QFrame* VisuGUI_BasePanel::mainFrame()