Back to index

salome-gui  6.5.0
STD_MDIDesktop.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "STD_MDIDesktop.h"
00024 
00025 #include <SUIT_Session.h>
00026 #include <SUIT_ViewWindow.h>
00027 #include <SUIT_ResourceMgr.h>
00028 
00029 #include <QtxWorkspace.h>
00030 #include <QtxActionMenuMgr.h>
00031 #include <QtxWorkspaceAction.h>
00032 
00033 #include <QFrame>
00034 #include <QVBoxLayout>
00035 
00036 #include <stdarg.h>
00037 
00041 STD_MDIDesktop::STD_MDIDesktop()
00042 : SUIT_Desktop(),
00043 myWorkspace( 0 ),
00044 myWorkspaceAction( 0 )
00045 {
00046   QFrame* base = new QFrame( this );
00047   QVBoxLayout* main = new QVBoxLayout( base );
00048   main->setMargin( 0 );
00049   base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00050 
00051   setCentralWidget( base );
00052 
00053   myWorkspace = new QtxWorkspace( base );
00054   main->addWidget( myWorkspace );
00055 
00056   connect( myWorkspace, SIGNAL( windowActivated( QWidget* ) ),
00057            this, SLOT( onWindowActivated( QWidget* ) ) );
00058 
00059   createActions();
00060 }
00061 
00065 STD_MDIDesktop::~STD_MDIDesktop()
00066 {
00067 }
00068 
00072 SUIT_ViewWindow* STD_MDIDesktop::activeWindow() const
00073 {
00074   SUIT_ViewWindow* wnd = 0;
00075 
00076   QWidget* wid = myWorkspace->activeWindow();
00077   if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
00078     wnd = (SUIT_ViewWindow*)wid;
00079 
00080   return wnd;
00081 }
00082 
00086 QList<SUIT_ViewWindow*> STD_MDIDesktop::windows() const
00087 {
00088   QList<SUIT_ViewWindow*> winList;
00089 
00090   QWidgetList children = myWorkspace->windowList();
00091   for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
00092   {
00093     SUIT_ViewWindow* vw = ::qobject_cast<SUIT_ViewWindow*>( *it );
00094     if ( vw )
00095       winList.append( vw );
00096   }
00097 
00098   return winList;
00099 }
00100 
00104 void STD_MDIDesktop::addWindow( QWidget* w )
00105 {
00106   if ( !w || !workspace() )
00107     return;
00108 
00109   workspace()->addWindow( w );
00110 }
00111 
00113 void STD_MDIDesktop::windowOperation( const int type )
00114 {
00115   myWorkspaceAction->perform( operationFlag( type ) );
00116 }
00117 
00119 void STD_MDIDesktop::setWindowOperations( const int first, ... )
00120 {
00121   va_list ints;
00122   va_start( ints, first );
00123 
00124   QList<int> typeList;
00125   
00126   int cur = first;
00127   while ( cur )
00128   {
00129     typeList.append( cur );
00130     cur = va_arg( ints, int );
00131   }
00132 
00133   setWindowOperations( typeList );
00134 }
00135 
00137 void STD_MDIDesktop::setWindowOperations( const QList<int>& opList )
00138 {
00139   int flags = 0;
00140 
00141   for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
00142     flags = flags | operationFlag( *it );
00143 
00144   myWorkspaceAction->setMenuActions( flags );
00145 }
00146 
00150 QtxWorkspace* STD_MDIDesktop::workspace() const
00151 {
00152   return myWorkspace;
00153 }
00154 
00158 void STD_MDIDesktop::onWindowActivated( QWidget* w )
00159 {
00160   if ( w && w->inherits( "SUIT_ViewWindow" ) )
00161     emit windowActivated( (SUIT_ViewWindow*)w );
00162 }
00163 
00167 void STD_MDIDesktop::createActions()
00168 {
00169   if ( myWorkspaceAction )
00170     return;
00171 
00172   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00173   if ( !resMgr )
00174     return;
00175 
00176   myWorkspaceAction = new QtxWorkspaceAction( workspace(), this );
00177 
00178   myWorkspaceAction->setMenuActions( QtxWorkspaceAction::Cascade | QtxWorkspaceAction::Tile  |
00179                                      QtxWorkspaceAction::HTile   | QtxWorkspaceAction::VTile |
00180                                      QtxWorkspaceAction::Windows );
00181 
00182   // Cascade
00183   myWorkspaceAction->setIcon( QtxWorkspaceAction::Cascade,
00184                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_CASCADE" ) ) );
00185   myWorkspaceAction->setText( QtxWorkspaceAction::Cascade, tr( "MEN_DESK_WINDOW_CASCADE" ) );
00186   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Cascade, tr( "PRP_DESK_WINDOW_CASCADE" ) );
00187 
00188   // Tile
00189   myWorkspaceAction->setIcon( QtxWorkspaceAction::Tile,
00190                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_TILE" ) ) );
00191   myWorkspaceAction->setText( QtxWorkspaceAction::Tile, tr( "MEN_DESK_WINDOW_TILE" ) );
00192   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Tile, tr( "PRP_DESK_WINDOW_TILE" ) );
00193 
00194   // Tile Horizontal
00195   myWorkspaceAction->setIcon( QtxWorkspaceAction::HTile,
00196                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HTILE" ) ) );
00197   myWorkspaceAction->setText( QtxWorkspaceAction::HTile, tr( "MEN_DESK_WINDOW_HTILE" ) );
00198   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::HTile, tr( "PRP_DESK_WINDOW_HTILE" ) );
00199 
00200   // Tile Vertical
00201   myWorkspaceAction->setIcon( QtxWorkspaceAction::VTile,
00202                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VTILE" ) ) );
00203   myWorkspaceAction->setText( QtxWorkspaceAction::VTile, tr( "MEN_DESK_WINDOW_VTILE" ) );
00204   myWorkspaceAction->setStatusTip( QtxWorkspaceAction::VTile, tr( "PRP_DESK_WINDOW_VTILE" ) );
00205 
00206   QtxActionMenuMgr* mMgr = menuMgr();
00207   if ( !mMgr )
00208     return;
00209 
00210   int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
00211   mMgr->insert( myWorkspaceAction, winMenuId, -1 );
00212   mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
00213 }
00214 
00216 int STD_MDIDesktop::operationFlag( const int type ) const
00217 {
00218   int res = 0;
00219   switch ( type )
00220   {
00221   case Cascade:
00222     res = QtxWorkspaceAction::Cascade;
00223     break;
00224   case Tile:
00225     res = QtxWorkspaceAction::Tile;
00226     break;
00227   case HTile:
00228     res = QtxWorkspaceAction::HTile;
00229     break;
00230   case VTile:
00231     res = QtxWorkspaceAction::VTile;
00232     break;
00233   }
00234   return res;
00235 }