Salome HOME
61bc79c2a67dcd7bae8df85aa279da29cb639f91
[modules/gui.git] / src / QxScene / QxScene_ViewModel.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "QxScene_ViewModel.h"
21 #include "QxScene_ViewWindow.h"
22 #include "QxScene_ViewManager.h"
23 #include "QxScene_Def.h"
24
25 #include "SUIT_Desktop.h"
26 #include "SUIT_ViewWindow.h"
27 #include "SUIT_Session.h"
28
29 #include <qcolordialog.h>
30 #include <QMenu>
31 #include <QToolBar>
32
33 //#define _DEVDEBUG_
34 #include "DebTrace.hxx"
35
36 /*!
37   Constructor
38 */
39 QxScene_Viewer::QxScene_Viewer()
40   :SUIT_ViewModel()
41 {
42   DEBTRACE("QxScene_Viewer::QxScene_Viewer");
43 }
44
45 /*!
46   Destructor
47 */
48 QxScene_Viewer::~QxScene_Viewer() 
49 {
50   DEBTRACE("QxScene_Viewer::~QxScene_Viewer");
51 }
52
53 void QxScene_Viewer::setViewManager( SUIT_ViewManager* mgr)
54 {
55   DEBTRACE("QxScene_Viewer::setViewManager");
56    SUIT_ViewModel::setViewManager( mgr );
57 }
58
59 /*!
60   Start initialization of view window
61   \param view - view window to be initialized
62 */
63 void QxScene_Viewer::initView( QxScene_ViewWindow* view )
64 {
65   DEBTRACE("QxScene_Viewer::initView");
66   if ( view )
67   {
68     view->initLayout();
69   }
70 }
71
72 /*!
73   Creates new view window
74   \param theDesktop - main window of application
75 */
76 SUIT_ViewWindow* QxScene_Viewer::createView(SUIT_Desktop* theDesktop)
77 {
78   DEBTRACE("QxScene_Viewer::createView");
79   QxScene_ViewWindow* aRes = new QxScene_ViewWindow( theDesktop, this );
80   initView( aRes );
81   return aRes;
82 }
83
84 /*!
85   Builds popup for QxScene viewer
86 */
87 void QxScene_Viewer::contextMenuPopup(QMenu* /*thePopup*/)
88 {
89   DEBTRACE("QxScene_Viewer::contextMenuPopup");
90 }
91
92 /*!
93   SLOT: called if background color is to be changed changed, passes new color to current canvas view
94 */
95 void QxScene_Viewer::onChangeBgColor()
96 {
97   QxScene_ViewWindow* aView = (QxScene_ViewWindow*)(myViewManager->getActiveView());
98   if( !aView )
99     return;
100   QColor aColorActive = aView->backgroundColor();
101
102   QColor selColor = QColorDialog::getColor( aColorActive, aView);
103   if ( selColor.isValid() )
104     aView->setBackgroundColor(selColor);
105 }
106
107 /*!
108   SLOT: called when popup item "Show toolbar" is activated, shows toolbar of active view window
109 */
110 void QxScene_Viewer::onShowToolbar()
111 {
112   QxScene_ViewWindow* aView = (QxScene_ViewWindow*)(myViewManager->getActiveView());
113   if ( aView )
114     aView->getToolBar()->show();    
115 }