1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
23 #include "STD_MDIDesktop.h"
25 #include <SUIT_Session.h>
26 #include <SUIT_ViewWindow.h>
27 #include <SUIT_ResourceMgr.h>
29 #include <QtxWorkspace.h>
30 #include <QtxActionMenuMgr.h>
31 #include <QtxWorkspaceAction.h>
34 #include <QVBoxLayout>
41 STD_MDIDesktop::STD_MDIDesktop()
44 myWorkspaceAction( 0 )
46 QFrame* base = new QFrame( this );
47 QVBoxLayout* main = new QVBoxLayout( base );
49 base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
51 setCentralWidget( base );
53 myWorkspace = new QtxWorkspace( base );
54 main->addWidget( myWorkspace );
56 connect( myWorkspace, SIGNAL( windowActivated( QWidget* ) ),
57 this, SLOT( onWindowActivated( QWidget* ) ) );
65 STD_MDIDesktop::~STD_MDIDesktop()
70 \retval SUIT_ViewWindow - return const active window.
72 SUIT_ViewWindow* STD_MDIDesktop::activeWindow() const
74 SUIT_ViewWindow* wnd = 0;
76 QWidget* wid = myWorkspace->activeWindow();
77 if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
78 wnd = (SUIT_ViewWindow*)wid;
84 \retval QList<SUIT_ViewWindow> - return const active window list.
86 QList<SUIT_ViewWindow*> STD_MDIDesktop::windows() const
88 QList<SUIT_ViewWindow*> winList;
90 QWidgetList children = myWorkspace->windowList();
91 for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
93 SUIT_ViewWindow* vw = ::qobject_cast<SUIT_ViewWindow*>( *it );
102 Add the new widget into desktop.
104 void STD_MDIDesktop::addWindow( QWidget* w )
106 if ( !w || !workspace() )
109 workspace()->addWindow( w );
112 /*!Call method perform for operation \a type.*/
113 void STD_MDIDesktop::windowOperation( const int type )
115 myWorkspaceAction->perform( operationFlag( type ) );
118 /*!Sets window operations by \a first ... parameters.*/
119 void STD_MDIDesktop::setWindowOperations( const int first, ... )
122 va_start( ints, first );
129 typeList.append( cur );
130 cur = va_arg( ints, int );
133 setWindowOperations( typeList );
136 /*!Sets window operations by variable \a opList - operation list.*/
137 void STD_MDIDesktop::setWindowOperations( const QList<int>& opList )
141 for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
142 flags = flags | operationFlag( *it );
144 myWorkspaceAction->setMenuActions( flags );
148 \retval QtxWorkspace pointer - work space.
150 QtxWorkspace* STD_MDIDesktop::workspace() const
156 Emit window activated.
158 void STD_MDIDesktop::onWindowActivated( QWidget* w )
160 if ( w && w->inherits( "SUIT_ViewWindow" ) )
161 emit windowActivated( (SUIT_ViewWindow*)w );
165 Create actions: cascade, Tile, Tile Horizontal, Tile Vertical
167 void STD_MDIDesktop::createActions()
169 if ( myWorkspaceAction )
172 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
176 myWorkspaceAction = new QtxWorkspaceAction( workspace(), this );
178 myWorkspaceAction->setMenuActions( QtxWorkspaceAction::Cascade | QtxWorkspaceAction::Tile |
179 QtxWorkspaceAction::HTile | QtxWorkspaceAction::VTile |
180 QtxWorkspaceAction::Windows );
183 myWorkspaceAction->setIcon( QtxWorkspaceAction::Cascade,
184 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_CASCADE" ) ) );
185 myWorkspaceAction->setText( QtxWorkspaceAction::Cascade, tr( "MEN_DESK_WINDOW_CASCADE" ) );
186 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Cascade, tr( "PRP_DESK_WINDOW_CASCADE" ) );
189 myWorkspaceAction->setIcon( QtxWorkspaceAction::Tile,
190 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_TILE" ) ) );
191 myWorkspaceAction->setText( QtxWorkspaceAction::Tile, tr( "MEN_DESK_WINDOW_TILE" ) );
192 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Tile, tr( "PRP_DESK_WINDOW_TILE" ) );
195 myWorkspaceAction->setIcon( QtxWorkspaceAction::HTile,
196 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HTILE" ) ) );
197 myWorkspaceAction->setText( QtxWorkspaceAction::HTile, tr( "MEN_DESK_WINDOW_HTILE" ) );
198 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::HTile, tr( "PRP_DESK_WINDOW_HTILE" ) );
201 myWorkspaceAction->setIcon( QtxWorkspaceAction::VTile,
202 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VTILE" ) ) );
203 myWorkspaceAction->setText( QtxWorkspaceAction::VTile, tr( "MEN_DESK_WINDOW_VTILE" ) );
204 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::VTile, tr( "PRP_DESK_WINDOW_VTILE" ) );
206 QtxActionMenuMgr* mMgr = menuMgr();
210 int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
211 mMgr->insert( myWorkspaceAction, winMenuId, -1 );
212 mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
215 /*!Convert STD_MDIDesktop enumerations to QtxWorkspaceAction.*/
216 int STD_MDIDesktop::operationFlag( const int type ) const
222 res = QtxWorkspaceAction::Cascade;
225 res = QtxWorkspaceAction::Tile;
228 res = QtxWorkspaceAction::HTile;
231 res = QtxWorkspaceAction::VTile;