1 // Copyright (C) 2007-2016 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>
35 #include <QMdiSubWindow>
42 STD_MDIDesktop::STD_MDIDesktop()
45 myWorkspaceAction( 0 )
47 QFrame* base = new QFrame( this );
48 QVBoxLayout* main = new QVBoxLayout( base );
50 base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
52 setCentralWidget( base );
54 myWorkspace = new QtxWorkspace( base );
55 main->addWidget( myWorkspace );
57 connect( myWorkspace, SIGNAL( windowActivated( QWidget* ) ),
58 this, SLOT( onWindowActivated( QWidget* ) ) );
66 STD_MDIDesktop::~STD_MDIDesktop()
71 \retval SUIT_ViewWindow - return const active window.
73 SUIT_ViewWindow* STD_MDIDesktop::activeWindow() const
75 return qobject_cast<SUIT_ViewWindow*>( myWorkspace->activeSubWindow()->widget() );
79 \retval QList<SUIT_ViewWindow> - return const active window list.
81 QList<SUIT_ViewWindow*> STD_MDIDesktop::windows() const
83 QList<SUIT_ViewWindow*> winList;
85 QList<QMdiSubWindow *> children = myWorkspace->subWindowList();
86 for ( QList<QMdiSubWindow *>::iterator it = children.begin(); it != children.end(); ++it )
88 SUIT_ViewWindow* vw = ::qobject_cast<SUIT_ViewWindow*>( (*it)->widget() );
97 Add the new widget into desktop.
99 void STD_MDIDesktop::addWindow( QWidget* w )
101 if ( !w || !workspace() )
104 workspace()->addSubWindow( w );
107 /*!Call method perform for operation \a type.*/
108 void STD_MDIDesktop::windowOperation( const int type )
110 myWorkspaceAction->perform( operationFlag( type ) );
113 /*!Sets window operations by \a first ... parameters.*/
114 void STD_MDIDesktop::setWindowOperations( const int first, ... )
117 va_start( ints, first );
124 typeList.append( cur );
125 cur = va_arg( ints, int );
128 setWindowOperations( typeList );
131 /*!Sets window operations by variable \a opList - operation list.*/
132 void STD_MDIDesktop::setWindowOperations( const QList<int>& opList )
136 for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
137 flags = flags | operationFlag( *it );
139 myWorkspaceAction->setMenuActions( flags );
143 \retval QtxWorkspace pointer - work space.
145 QtxWorkspace* STD_MDIDesktop::workspace() const
151 Emit window activated.
153 void STD_MDIDesktop::onWindowActivated( QWidget* w )
155 if ( w && w->inherits( "SUIT_ViewWindow" ) )
156 emit windowActivated( (SUIT_ViewWindow*)w );
160 Create actions: cascade, Tile, Tile Horizontal, Tile Vertical
162 void STD_MDIDesktop::createActions()
164 if ( myWorkspaceAction )
167 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
171 myWorkspaceAction = new QtxWorkspaceAction( workspace(), this );
173 myWorkspaceAction->setMenuActions( QtxWorkspaceAction::Cascade | QtxWorkspaceAction::Tile |
174 QtxWorkspaceAction::HTile | QtxWorkspaceAction::VTile |
175 QtxWorkspaceAction::Windows );
178 myWorkspaceAction->setIcon( QtxWorkspaceAction::Cascade,
179 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_CASCADE" ) ) );
180 myWorkspaceAction->setText( QtxWorkspaceAction::Cascade, tr( "MEN_DESK_WINDOW_CASCADE" ) );
181 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Cascade, tr( "PRP_DESK_WINDOW_CASCADE" ) );
184 myWorkspaceAction->setIcon( QtxWorkspaceAction::Tile,
185 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_TILE" ) ) );
186 myWorkspaceAction->setText( QtxWorkspaceAction::Tile, tr( "MEN_DESK_WINDOW_TILE" ) );
187 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::Tile, tr( "PRP_DESK_WINDOW_TILE" ) );
190 myWorkspaceAction->setIcon( QtxWorkspaceAction::HTile,
191 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HTILE" ) ) );
192 myWorkspaceAction->setText( QtxWorkspaceAction::HTile, tr( "MEN_DESK_WINDOW_HTILE" ) );
193 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::HTile, tr( "PRP_DESK_WINDOW_HTILE" ) );
196 myWorkspaceAction->setIcon( QtxWorkspaceAction::VTile,
197 resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VTILE" ) ) );
198 myWorkspaceAction->setText( QtxWorkspaceAction::VTile, tr( "MEN_DESK_WINDOW_VTILE" ) );
199 myWorkspaceAction->setStatusTip( QtxWorkspaceAction::VTile, tr( "PRP_DESK_WINDOW_VTILE" ) );
201 QtxActionMenuMgr* mMgr = menuMgr();
205 int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
206 mMgr->insert( myWorkspaceAction, winMenuId, -1 );
207 mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
210 /*!Convert STD_MDIDesktop enumerations to QtxWorkspaceAction.*/
211 int STD_MDIDesktop::operationFlag( const int type ) const
217 res = QtxWorkspaceAction::Cascade;
220 res = QtxWorkspaceAction::Tile;
223 res = QtxWorkspaceAction::HTile;
226 res = QtxWorkspaceAction::VTile;