qoccframe.cpp

Go to the documentation of this file.
00001 /************************************************************************************
00002 **
00003 ** This file is part of the QtOPENCASCADE Toolkit.
00004 **
00005 ** Copyright (C) 2006, 2007, 2008 QtOCC Team Members
00006 **               Peter Dolbey, Marc Britten, Stephane Routelous
00007 **               Stefan Boeykens, Pawel Dobrolowski, Walter Steffe
00008 **               Álvaro Castro Castilla, Dirk Burski, Fotis Sioutis
00009 **
00010 ** This library is free software; you can redistribute it and/or
00011 ** modify it under the terms of the GNU Lesser General Public
00012 ** License as published by the Free Software Foundation; either
00013 ** version 2.1 of the License, or (at your option) any later version.
00014 ** 
00015 ** This library is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 ** Lesser General Public License for more details.
00019 ** 
00020 ** You should have received a copy of the GNU Lesser General Public
00021 ** License along with this library; if not, write to the Free Software
00022 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 **
00024 ***********************************************************************************/
00025 
00026 /*!
00027 \class  QoccFrame
00028 \brief  This class provides a QFrame derived object containing a toolbar and an
00029                 OpenCascade viewer widget (\see Qocc3dWidget). The toolbar wraps several 
00030                 utility functions that manipulate the view.
00031 \author Peter C. Dolbey
00032 */
00033 #include <QtGui/QVBoxLayout>
00034 #include <QtGui/QAction>
00035 
00036 #include "qoccframe.h"
00037 #include "qocc3dwidget.h"
00038 #include "qoccmainwindow.h"
00039 
00040 /*!
00041 \brief  Constructor for QoccFrame.
00042                 This constructor creates an uninitialised window for rendering a
00043                 Handle_V3d_View based OpenCASCADE 3D viewer.
00044 \param  aContext The widget's AIS context
00045 \param  parent The widget's parent widget
00046 \param  wflags The widget's window configuration flags
00047 \see    initialize
00048 */
00049 QoccFrame::QoccFrame(   QoccController* aController, 
00050                                                 QWidget *parent, 
00051                                                 Qt::WindowFlags wflags ) : 
00052         QFrame( parent, wflags )
00053 {
00054         myController = aController;
00055         myParent = static_cast<QoccMainWindow*> (parent);
00056         myLayout = new QVBoxLayout( this );
00057         myLayout->setObjectName(QString::fromUtf8("vboxLayout"));
00058         myLayout->setMargin(0);
00059         myLayout->setSpacing(0);
00060 
00061         myToolBar = new QToolBar( this );
00062         myToolBar->setAutoFillBackground(true);   
00063         
00064         myWidget = new Qocc3dWidget( myController, parent, wflags );
00065 
00066         createActions();
00067         setToolbarActions();
00068         connectActions();
00069         connectParent();
00070 
00071         myLayout->addWidget( myToolBar );
00072         myLayout->addWidget( myWidget );
00073 
00074 }
00075 /*! 
00076 \brief  The class destructor
00077 */
00078 QoccFrame::~QoccFrame()
00079 {
00080         disconnectActions();
00081         disconnectParent();
00082 
00083         delete actionFitExtents;
00084         delete actionFitArea;
00085         delete actionFitAll;
00086         delete actionZoomGroup;
00087 
00088     delete myToolBar;
00089         delete myLayout;
00090         delete myWidget;
00091 }
00092 
00093 /*!
00094 \brief  createActions sets up all the singleton toolbar actions, and calls 
00095                 the grouped action functions.
00096 */
00097 void QoccFrame::createActions( void)
00098 {
00099         actionIdle = new QAction( tr("Idle"), this );
00100         actionIdle->setStatusTip(tr("Selection Mode"));
00101         actionIdle->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/arrow.png")));
00102 
00103         createZoomGroup();
00104         createViewGroup();
00105 }
00106 
00107 void QoccFrame::createZoomGroup( void )
00108 {
00109         actionZoomGroup = new QAction( this );
00110         {
00111                 actionFitExtents = new QAction(tr("&Fit to Extents"), this);
00112                 actionFitExtents->setStatusTip(tr("Show entire drawing"));
00113                 actionFitExtents->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/viewmagall.png")));
00114 
00115                 actionFitArea = new QAction(tr("&Zoom Selected Area"), this);
00116                 actionFitArea->setStatusTip(tr("Zoom to selected region"));
00117                 actionFitArea->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/viewmagfit.png")));
00118 
00119                 actionFitAll = new QAction(tr("Zoom &All"), this);
00120                 actionFitAll->setStatusTip(tr("Zoom entire object"));
00121                 actionFitAll->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/viewmag.png")));
00122 
00123                 popupZoomGroup = new QMenu ( this );
00124                 popupZoomGroup->addAction (actionFitExtents);
00125                 popupZoomGroup->addAction (actionFitArea);
00126                 popupZoomGroup->addAction (actionFitAll);
00127         }
00128         actionZoomGroup->setText(actionFitExtents->text());
00129         actionZoomGroup->setStatusTip(actionFitExtents->statusTip());
00130         actionZoomGroup->setIcon(actionFitExtents->icon());
00131         actionZoomGroup->setMenu(popupZoomGroup);
00132 }
00133 
00134 void QoccFrame::createViewGroup( void )
00135 {
00136         actionViewGroup = new QAction ( this );
00137         {
00138                 actionViewTop = new QAction(tr("View from &Top"), this);
00139                 actionViewTop->setStatusTip(tr("Top View"));
00140                 actionViewTop->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/planview.png")));
00141 
00142                 actionViewFront = new QAction(tr("View from &Front"), this);
00143                 actionViewFront->setStatusTip(tr("Front View"));
00144                 actionViewFront->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/frontview.png")));
00145 
00146                 actionViewLeft = new QAction(tr("View from &Left"), this);
00147                 actionViewLeft->setStatusTip(tr("Left View"));
00148                 actionViewLeft->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/leftview.png")));
00149 
00150                 actionViewTopFront = new QAction(tr("View from Top Front"), this);
00151                 actionViewTopFront->setStatusTip(tr("Top Front View"));
00152                 actionViewTopFront->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/topfrontview.png")));
00153 
00154                 actionViewAxo = new QAction(tr("&Axonometric View"), this);
00155                 actionViewAxo->setStatusTip(tr("Axo View"));
00156                 actionViewAxo->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/axoview.png")));
00157 
00158                 popupViewGroup = new QMenu ( this );
00159                 popupViewGroup->addAction (actionViewTop);
00160                 popupViewGroup->addAction (actionViewFront);
00161                 popupViewGroup->addAction (actionViewLeft);
00162                 popupViewGroup->addSeparator ();
00163                 popupViewGroup->addAction (actionViewTopFront);
00164                 popupViewGroup->addAction (actionViewAxo);
00165         }
00166         actionViewGroup->setText(actionViewAxo->text());
00167         actionViewGroup->setStatusTip(actionViewAxo->statusTip());
00168         actionViewGroup->setIcon(actionViewAxo->icon());
00169         actionViewGroup->setMenu(popupViewGroup);
00170 }
00171 
00172 void QoccFrame::setToolbarActions()
00173 {
00174         myToolBar->addAction(actionIdle);
00175         myToolBar->addSeparator();
00176         myToolBar->addAction(actionZoomGroup);
00177         myToolBar->addSeparator();
00178         myToolBar->addAction(actionViewGroup);
00179 }
00180 
00181 void QoccFrame::connectActions()
00182 {
00183         connect( actionIdle, SIGNAL(triggered()), myWidget, SLOT(idle()));
00184 
00185         connect( actionZoomGroup,  SIGNAL(triggered()), myWidget, SLOT(fitExtents()) );
00186         {
00187                 connect( actionFitExtents, SIGNAL(triggered()), this, SLOT(fitExtents()) );
00188                 connect( actionFitArea,    SIGNAL(triggered()), this, SLOT(fitArea()) );
00189                 connect( actionFitAll,     SIGNAL(triggered()), this, SLOT(fitAll()) );
00190         }
00191         connect( actionViewGroup,  SIGNAL(triggered()), myWidget, SLOT(viewAxo()) );
00192         {
00193                 connect( actionViewTop,      SIGNAL(triggered()), this, SLOT(viewTop()) );
00194                 connect( actionViewLeft,     SIGNAL(triggered()), this, SLOT(viewLeft()) );
00195                 connect( actionViewFront,    SIGNAL(triggered()), this, SLOT(viewFront()) );
00196                 connect( actionViewTopFront, SIGNAL(triggered()), this, SLOT(viewTopFront()) );
00197                 connect( actionViewAxo,      SIGNAL(triggered()), this, SLOT(viewAxo()) );
00198         }
00199 }
00200 
00201 void QoccFrame::disconnectActions()
00202 {
00203         actionIdle->disconnect();
00204         
00205         actionZoomGroup->disconnect();
00206         actionFitExtents->disconnect();
00207         actionFitArea->disconnect();
00208         actionFitAll->disconnect();
00209 }
00210 
00211 void QoccFrame::connectParent()
00212 {
00213         // Connect the messages from this widget to the status bar
00214         // display on the main window.
00215         connect( myWidget, SIGNAL(sendStatus(const QString)), 
00216                          myParent, SLOT  (statusMessage(const QString)) );
00217 
00218         // Connect application event signals to the widget
00219         connect( myParent, SIGNAL(fileOpening()), 
00220                      myWidget, SLOT  (refresh()) );
00221         connect( myParent, SIGNAL(fileOpened()),  
00222                      myWidget, SLOT  (newShape()) );
00223 
00224         // connect widget events to the context wrapper
00225         connect( myWidget,       SIGNAL(mouseMoved(Qocc3dWidget*, QMouseEvent*)), 
00226                      myController,   SLOT  (moveEvent(Qocc3dWidget*,  QMouseEvent*)) );
00227         // connect widget events to the context wrapper
00228         connect( myWidget,       SIGNAL(mouseClicked(Qocc3dWidget*, QMouseEvent*)), 
00229                      myController,   SLOT  (clickEvent(Qocc3dWidget*,   QMouseEvent*)) );
00230 
00231 }
00232 
00233 void QoccFrame::disconnectParent()
00234 {
00235         myWidget->disconnect();
00236 }
00237 
00238 void QoccFrame::invokeAction( QAction* group, QAction* action, const char* signal )
00239 {
00240         group->setText     ( action->text() );
00241         group->setStatusTip( action->statusTip() );
00242         group->setIcon     ( action->icon() );
00243         if ( myWidget )
00244         {
00245                 group->disconnect( );
00246                 connect ( group, SIGNAL(triggered()), myWidget, signal );
00247                 group->trigger();
00248         }
00249 }
00250 
00251 void QoccFrame::fitExtents( void )
00252 {
00253         invokeAction ( actionZoomGroup,  actionFitExtents, SLOT(fitExtents()) );
00254 }
00255 
00256 void QoccFrame::fitArea( void )
00257 {
00258         invokeAction ( actionZoomGroup,  actionFitArea, SLOT( fitArea()) );
00259 }
00260 
00261 void QoccFrame::fitAll( void )
00262 {
00263         invokeAction ( actionZoomGroup,  actionFitAll, SLOT(fitAll()) );
00264 }
00265 
00266 void QoccFrame::viewAxo( void )
00267 {
00268         invokeAction ( actionViewGroup, actionViewAxo, SLOT(viewAxo()) );
00269 }
00270 
00271 void QoccFrame::viewTop( void )
00272 {
00273         invokeAction ( actionViewGroup, actionViewTop, SLOT(viewTop()) );
00274 }
00275 
00276 void QoccFrame::viewFront( void )
00277 {
00278         invokeAction ( actionViewGroup,  actionViewFront, SLOT(viewFront()) );
00279 }
00280 
00281 void QoccFrame::viewTopFront( void )
00282 {
00283         invokeAction ( actionViewGroup,  actionViewTopFront, SLOT(viewTopFront()) );
00284 }
00285 
00286 void QoccFrame::viewLeft( void )
00287 {
00288         invokeAction ( actionViewGroup, actionViewLeft, SLOT(viewLeft()) );
00289 }
00290 

Generated on Sat Feb 23 21:22:15 2008 for QtGEOM by  doxygen 1.4.7