Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / QxScene / QxScene_ViewModel.cxx
1 //  Copyright (C) 2007-2008  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.
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 #include "QxScene_ViewModel.h"
23 #include "QxScene_ViewWindow.h"
24 #include "QxScene_ViewManager.h"
25 #include "QxScene_Def.h"
26
27 #include "SUIT_Desktop.h"
28 #include "SUIT_ViewWindow.h"
29 #include "SUIT_Session.h"
30
31 #include <qcolordialog.h>
32 #include <QMenu>
33 #include <QToolBar>
34
35 //#define _DEVDEBUG_
36 #include "DebTrace.hxx"
37
38 /*!
39   Constructor
40 */
41 QxScene_Viewer::QxScene_Viewer()
42   :SUIT_ViewModel()
43 {
44   DEBTRACE("QxScene_Viewer::QxScene_Viewer");
45 }
46
47 /*!
48   Destructor
49 */
50 QxScene_Viewer::~QxScene_Viewer() 
51 {
52   DEBTRACE("QxScene_Viewer::~QxScene_Viewer");
53 }
54
55 void QxScene_Viewer::setViewManager( SUIT_ViewManager* mgr)
56 {
57   DEBTRACE("QxScene_Viewer::setViewManager");
58    SUIT_ViewModel::setViewManager( mgr );
59 }
60
61 /*!
62   Start initialization of view window
63   \param view - view window to be initialized
64 */
65 void QxScene_Viewer::initView( QxScene_ViewWindow* view )
66 {
67   DEBTRACE("QxScene_Viewer::initView");
68   if ( view )
69   {
70     view->initLayout();
71   }
72 }
73
74 /*!
75   Creates new view window
76   \param theDesktop - main window of application
77 */
78 SUIT_ViewWindow* QxScene_Viewer::createView(SUIT_Desktop* theDesktop)
79 {
80   DEBTRACE("QxScene_Viewer::createView");
81   QxScene_ViewWindow* aRes = new QxScene_ViewWindow( theDesktop, this );
82   initView( aRes );
83   return aRes;
84 }
85
86 /*!
87   Builds popup for QxScene viewer
88 */
89 void QxScene_Viewer::contextMenuPopup(QMenu* thePopup)
90 {
91   DEBTRACE("QxScene_Viewer::contextMenuPopup");
92 }
93
94 /*!
95   SLOT: called if background color is to be changed changed, passes new color to current canvas view
96 */
97 void QxScene_Viewer::onChangeBgColor()
98 {
99   QxScene_ViewWindow* aView = (QxScene_ViewWindow*)(myViewManager->getActiveView());
100   if( !aView )
101     return;
102   QColor aColorActive = aView->backgroundColor();
103
104   QColor selColor = QColorDialog::getColor( aColorActive, aView);
105   if ( selColor.isValid() )
106     aView->setBackgroundColor(selColor);
107 }
108
109 /*!
110   SLOT: called when popup item "Show toolbar" is activated, shows toolbar of active view window
111 */
112 void QxScene_Viewer::onShowToolbar()
113 {
114   QxScene_ViewWindow* aView = (QxScene_ViewWindow*)(myViewManager->getActiveView());
115   if ( aView )
116     aView->getToolBar()->show();    
117 }