Back to index

salome-gui  6.5.0
STD_TabDesktop.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_TabDesktop.h"
00024 
00025 #include <SUIT_Session.h>
00026 #include <SUIT_ViewWindow.h>
00027 #include <SUIT_ResourceMgr.h>
00028 
00029 #include <QtxWorkstack.h>
00030 #include <QtxActionMenuMgr.h>
00031 #include <QtxWorkstackAction.h>
00032 
00033 #include <QFrame>
00034 #include <QVBoxLayout>
00035 
00036 #include <stdarg.h>
00037 
00039 STD_TabDesktop::STD_TabDesktop()
00040 : SUIT_Desktop(),
00041 myWorkstack( 0 ),
00042 myWorkstackAction( 0 )
00043 {
00044   QFrame* base = new QFrame( this );
00045   base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00046 
00047   QVBoxLayout* main = new QVBoxLayout( base );
00048   main->setMargin( 0 );
00049 
00050   setCentralWidget( base );
00051 
00052   myWorkstack = new QtxWorkstack( base );
00053   main->addWidget( myWorkstack );
00054   // setting Expanding size policy for central workstack.  If there are several widgets
00055   // in central area of Desktop, other widgets will be added below the workstack (CATHARE, TRIPOLI modules).
00056   // But the workstack must occupy as much space as possible -- set Expanding for it.
00057   myWorkstack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
00058 
00059   myWorkstack->setAccel( QtxWorkstack::SplitVertical,   Qt::ALT + Qt::SHIFT + Qt::Key_V );
00060   myWorkstack->setAccel( QtxWorkstack::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
00061   //myWorkstack->setAccel( QtxWorkstack::Close,           Qt::CTRL + Qt::Key_F4 );
00062 
00063   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00064   if ( resMgr ) {
00065     myWorkstack->setIcon( QtxWorkstack::SplitVertical,
00066                           resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
00067     myWorkstack->setIcon( QtxWorkstack::SplitHorizontal,
00068                           resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
00069     myWorkstack->setIcon( QtxWorkstack::Close,
00070                           resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ));
00071   }
00072 
00073   connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
00074            this, SLOT( onWindowActivated( QWidget* ) ) );
00075 
00076   createActions();
00077 }
00078 
00082 STD_TabDesktop::~STD_TabDesktop()
00083 {
00084 }
00085 
00089 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
00090 {
00091   SUIT_ViewWindow* wnd = 0;
00092 
00093   QWidget* wid = myWorkstack->activeWindow();
00094   if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
00095     wnd = (SUIT_ViewWindow*)wid;
00096 
00097   return wnd;
00098 }
00099 
00103 QList<SUIT_ViewWindow*> STD_TabDesktop::windows() const
00104 {
00105   QList<SUIT_ViewWindow*> winList;
00106 
00107   QWidgetList children = myWorkstack->windowList();
00108   for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
00109   {
00110     if ( (*it)->inherits( "SUIT_ViewWindow" ) )
00111       winList.append( (SUIT_ViewWindow*)*it );
00112   }
00113 
00114   return winList;
00115 }
00116 
00120 void STD_TabDesktop::addWindow( QWidget* w )
00121 {
00122   if ( !w || !workstack() )
00123     return;
00124 
00125   workstack()->addWindow( w );
00126 }
00127 
00131 void STD_TabDesktop::windowOperation( const int type )
00132 {
00133   myWorkstackAction->perform( operationFlag( type ) );
00134 }
00135 
00139 void STD_TabDesktop::setWindowOperations( const int first, ... )
00140 {
00141   va_list ints;
00142         va_start( ints, first );
00143 
00144         QList<int> typeList;
00145 
00146         int cur = first;
00147         while ( cur )
00148         {
00149           typeList.append( cur );
00150                 cur = va_arg( ints, int );
00151   }
00152 
00153         setWindowOperations( typeList );
00154 }
00155 
00159 void STD_TabDesktop::setWindowOperations( const QList<int>& opList )
00160 {
00161   int flags = 0;
00162 
00163   for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
00164     flags = flags | operationFlag( *it );
00165 
00166 //  myWorkstackAction->setItems( flags );
00167 }
00168 
00172 QtxWorkstack* STD_TabDesktop::workstack() const
00173 {
00174   return myWorkstack;
00175 }
00176 
00180 void STD_TabDesktop::onWindowActivated( QWidget* w )
00181 {
00182   if ( w && w->inherits( "SUIT_ViewWindow" ) )
00183     emit windowActivated( (SUIT_ViewWindow*)w );
00184 }
00185 
00189 void STD_TabDesktop::createActions()
00190 {
00191   if ( myWorkstackAction )
00192     return;
00193 
00194   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00195   if ( !resMgr )
00196     return;
00197 
00198   myWorkstackAction = new QtxWorkstackAction( workstack(), this );
00199 
00200   myWorkstackAction->setMenuActions( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
00201 
00202   // Split Horizontal
00203   myWorkstackAction->setIcon( QtxWorkstackAction::SplitHorizontal,
00204                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
00205   myWorkstackAction->setText( QtxWorkstackAction::SplitHorizontal, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
00206   myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitHorizontal, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
00207   myWorkstackAction->setAccel( QtxWorkstackAction::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
00208 
00209   // Split Vertical
00210   myWorkstackAction->setIcon( QtxWorkstackAction::SplitVertical,
00211                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
00212   myWorkstackAction->setText( QtxWorkstackAction::SplitVertical, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
00213   myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitVertical, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
00214   myWorkstackAction->setAccel( QtxWorkstackAction::SplitVertical,   Qt::ALT + Qt::SHIFT + Qt::Key_V );
00215 
00216   QtxActionMenuMgr* mMgr = menuMgr();
00217   if ( !mMgr )
00218     return;
00219 
00220   int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
00221   mMgr->insert( myWorkstackAction, winMenuId, -1 );
00222   mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
00223 }
00224 
00228 int STD_TabDesktop::operationFlag( const int type ) const
00229 {
00230   int res = 0;
00231   switch ( type )
00232   {
00233   case SplitVertical:
00234     res = QtxWorkstackAction::SplitVertical;
00235     break;
00236   case SplitHorizontal:
00237     res = QtxWorkstackAction::SplitHorizontal;
00238     break;
00239   }
00240 
00241   return res;
00242 }