]> SALOME platform Git repositories - modules/gui.git/blob - src/STD/STD_TabDesktop.cxx
Salome HOME
try to avoid to add detached viewer on desktop viewer tab
[modules/gui.git] / src / STD / STD_TabDesktop.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "STD_TabDesktop.h"
24
25 #include <SUIT_Session.h>
26 #include <SUIT_ViewManager.h>
27 #include <SUIT_ViewWindow.h>
28 #include <SUIT_ResourceMgr.h>
29
30 #include <QtxWorkstack.h>
31 #include <QtxActionMenuMgr.h>
32 #include <QtxWorkstackAction.h>
33
34 #include <QFrame>
35 #include <QVBoxLayout>
36
37 #include <stdarg.h>
38
39 /*!Constructor.Create new instances of QVBox and QtxWorkstack.*/
40 STD_TabDesktop::STD_TabDesktop()
41 : SUIT_Desktop(),
42 myWorkstack( 0 ),
43 myWorkstackAction( 0 )
44 {
45   QFrame* base = new QFrame( this );
46   base->setFrameStyle( QFrame::Panel | QFrame::Sunken );
47
48   QVBoxLayout* main = new QVBoxLayout( base );
49   main->setMargin( 0 );
50
51   setCentralWidget( base );
52
53   myWorkstack = new QtxWorkstack( base );
54   main->addWidget( myWorkstack );
55   // setting Expanding size policy for central workstack.  If there are several widgets
56   // in central area of Desktop, other widgets will be added below the workstack (CATHARE, TRIPOLI modules).
57   // But the workstack must occupy as much space as possible -- set Expanding for it.
58   myWorkstack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
59
60   myWorkstack->setAccel( QtxWorkstack::SplitVertical,   Qt::ALT + Qt::SHIFT + Qt::Key_V );
61   myWorkstack->setAccel( QtxWorkstack::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
62   //myWorkstack->setAccel( QtxWorkstack::Close,           Qt::CTRL + Qt::Key_F4 );
63
64   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
65   if ( resMgr ) {
66     myWorkstack->setIcon( QtxWorkstack::SplitVertical,
67                           resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
68     myWorkstack->setIcon( QtxWorkstack::SplitHorizontal,
69                           resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
70     myWorkstack->setIcon( QtxWorkstack::Close,
71                           resMgr->loadPixmap( "STD", tr( "ICON_FILE_CLOSE" ) ));
72   }
73
74   connect( myWorkstack, SIGNAL( windowActivated( QWidget* ) ),
75            this, SLOT( onWindowActivated( QWidget* ) ) );
76
77   createActions();
78 }
79
80 /*!
81   Destructor.
82 */
83 STD_TabDesktop::~STD_TabDesktop()
84 {
85 }
86
87 /*!
88   \retval SUIT_ViewWindow - return const active window.
89 */
90 SUIT_ViewWindow* STD_TabDesktop::activeWindow() const
91 {
92   SUIT_ViewWindow* wnd = 0;
93
94   QWidget* wid = myWorkstack->activeWindow();
95   if ( wid && wid->inherits( "SUIT_ViewWindow" ) )
96     wnd = (SUIT_ViewWindow*)wid;
97
98   return wnd;
99 }
100
101 /*!
102   Set active window
103   \param wnd - view window
104 */
105 void STD_TabDesktop::setActiveWindow(SUIT_ViewWindow* wnd)
106 {
107   if (wnd) {
108     myWorkstack->setActiveWindow(wnd);
109     wnd->setFocus();
110   }
111 }
112
113 /*!
114   \retval QPtrList<SUIT_ViewWindow> - return const active window list.
115 */
116 QList<SUIT_ViewWindow*> STD_TabDesktop::windows() const
117 {
118   QList<SUIT_ViewWindow*> winList;
119
120   QWidgetList children = myWorkstack->windowList();
121   for ( QWidgetList::iterator it = children.begin(); it != children.end(); ++it )
122   {
123     if ( (*it)->inherits( "SUIT_ViewWindow" ) )
124       winList.append( (SUIT_ViewWindow*)*it );
125   }
126
127   return winList;
128 }
129
130 /*!
131   Insert new widget into desktop.
132 */
133 void STD_TabDesktop::addWindow( QWidget* w )
134 {
135   if ( !w || !workstack() )
136     return;
137   if ( w && w->inherits( "SUIT_ViewWindow" ) )
138         {
139           SUIT_ViewWindow* wid = (SUIT_ViewWindow*)w;
140           if ( wid->getViewManager()->getDetached() )
141                 return;
142         }
143
144   workstack()->addWindow( w );
145 }
146
147 /*!
148   Call method perform for operation \a type.
149 */
150 void STD_TabDesktop::windowOperation( const int type )
151 {
152   myWorkstackAction->perform( operationFlag( type ) );
153 }
154
155 /*!
156   Sets window operations by \a first ... parameters.
157 */
158 void STD_TabDesktop::setWindowOperations( const int first, ... )
159 {
160   va_list ints;
161         va_start( ints, first );
162
163         QList<int> typeList;
164
165         int cur = first;
166         while ( cur )
167         {
168           typeList.append( cur );
169                 cur = va_arg( ints, int );
170   }
171
172         setWindowOperations( typeList );
173 }
174
175 /*!
176   Sets window operations by variable \a opList - operation list.
177 */
178 void STD_TabDesktop::setWindowOperations( const QList<int>& opList )
179 {
180   int flags = 0;
181
182   for ( QList<int>::const_iterator it = opList.begin(); it != opList.end(); ++it )
183     flags = flags | operationFlag( *it );
184
185 //  myWorkstackAction->setItems( flags );
186 }
187
188 /*!
189   \retval QtxWorkstack pointer - Qt work stack.
190 */
191 QtxWorkstack* STD_TabDesktop::workstack() const
192 {
193   return myWorkstack;
194 }
195
196 /*!
197   Emit window activated.
198 */
199 void STD_TabDesktop::onWindowActivated( QWidget* w )
200 {
201   if ( w && w->inherits( "SUIT_ViewWindow" ) )
202     emit windowActivated( (SUIT_ViewWindow*)w );
203 }
204
205 /*!
206   Create actions for window.
207 */
208 void STD_TabDesktop::createActions()
209 {
210   if ( myWorkstackAction )
211     return;
212
213   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
214   if ( !resMgr )
215     return;
216
217   myWorkstackAction = new QtxWorkstackAction( workstack(), this );
218
219   myWorkstackAction->setMenuActions( QtxWorkstackAction::Split | QtxWorkstackAction::Windows );
220
221   // Split Horizontal
222   myWorkstackAction->setIcon( QtxWorkstackAction::SplitHorizontal,
223                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_HSPLIT" ) ) );
224   myWorkstackAction->setText( QtxWorkstackAction::SplitHorizontal, tr( "MEN_DESK_WINDOW_HSPLIT" ) );
225   myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitHorizontal, tr( "PRP_DESK_WINDOW_HSPLIT" ) );
226   myWorkstackAction->setAccel( QtxWorkstackAction::SplitHorizontal, Qt::ALT + Qt::SHIFT + Qt::Key_H );
227
228   // Split Vertical
229   myWorkstackAction->setIcon( QtxWorkstackAction::SplitVertical,
230                               resMgr->loadPixmap( "STD", tr( "ICON_DESK_WINDOW_VSPLIT" ) ) );
231   myWorkstackAction->setText( QtxWorkstackAction::SplitVertical, tr( "MEN_DESK_WINDOW_VSPLIT" ) );
232   myWorkstackAction->setStatusTip( QtxWorkstackAction::SplitVertical, tr( "PRP_DESK_WINDOW_VSPLIT" ) );
233   myWorkstackAction->setAccel( QtxWorkstackAction::SplitVertical,   Qt::ALT + Qt::SHIFT + Qt::Key_V );
234
235   QAction* anArrangeViewsAction = myWorkstackAction->getArrangeViewsAction();
236   if( anArrangeViewsAction )
237     connect( anArrangeViewsAction, SIGNAL( triggered() ), this, SLOT( onArrangeViews() ) );
238
239   QtxActionMenuMgr* mMgr = menuMgr();
240   if ( !mMgr )
241     return;
242
243   int winMenuId = mMgr->insert( tr( "MEN_DESK_WINDOW" ), -1, 100 );
244   mMgr->insert( anArrangeViewsAction, winMenuId, -1 );
245   mMgr->insert( myWorkstackAction, winMenuId, -1 );
246   mMgr->insert( QtxActionMenuMgr::separator(), winMenuId, -1 );
247 }
248
249 /*!
250   Emit Arrange Views menu activated.
251 */
252 void STD_TabDesktop::onArrangeViews()
253 {
254   QtxSplitDlg ArrangeViewsDlg( this, workstack(), ArrangeViews );
255   ArrangeViewsDlg.exec();
256 }
257
258 /*!
259   Convert STD_TabDesktop enumerations to QtxWorkstackAction
260 */
261 int STD_TabDesktop::operationFlag( const int type ) const
262 {
263   int res = 0;
264   switch ( type )
265   {
266   case SplitVertical:
267     res = QtxWorkstackAction::SplitVertical;
268     break;
269   case SplitHorizontal:
270     res = QtxWorkstackAction::SplitHorizontal;
271     break;
272   }
273
274   return res;
275 }