1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 #include "SUIT_ViewManager.h"
21 #include "SUIT_Desktop.h"
22 #include "SUIT_ViewModel.h"
23 #include "SUIT_Study.h"
26 #include <qmessagebox.h>
32 /*!\class SUIT_ViewManager.
33 * Class provide manipulation with view windows.
37 SUIT_ViewManager::SUIT_ViewManager( SUIT_Study* theStudy,
38 SUIT_Desktop* theDesktop,
39 SUIT_ViewModel* theViewModel )
41 myDesktop( theDesktop ),
42 myTitle( "Default viewer" ),
47 setViewModel(theViewModel);
48 connect(theDesktop, SIGNAL(windowActivated(SUIT_ViewWindow*)),
49 this, SLOT(onWindowActivated(SUIT_ViewWindow*)));
53 connect( myStudy, SIGNAL( destroyed() ), this, SLOT( onDeleteStudy() ) );
57 SUIT_ViewManager::~SUIT_ViewManager()
61 myViewModel->setViewManager( 0 );
66 /*!Sets view model \a theViewModel to view manager.*/
67 void SUIT_ViewManager::setViewModel(SUIT_ViewModel* theViewModel)
69 if (myViewModel && myViewModel != theViewModel) {
70 myViewModel->setViewManager(0);
73 myViewModel = theViewModel;
75 myViewModel->setViewManager(this);
78 /*!Sets view name for view window \a theView.*/
79 void SUIT_ViewManager::setViewName(SUIT_ViewWindow* theView)
81 int aPos = myViews.find(theView);
82 theView->setCaption(myTitle + QString(":%1").arg(aPos+1));
85 /*! Creates View, adds it into list of views and returns just created view window*/
86 SUIT_ViewWindow* SUIT_ViewManager::createViewWindow()
88 SUIT_ViewWindow* aView = myViewModel->createView(myDesktop);
90 if ( !insertView( aView ) ){
96 //myDesktop->addViewWindow( aView );
97 //it is done automatically during creation of view
99 aView->setViewManager(this);
101 emit viewCreated(aView);
103 // Special treatment for the case when <aView> is the first one in this view manager
104 // -> call onWindowActivated() directly, because somebody may always want
105 // to use getActiveView()
107 onWindowActivated( aView );
112 /*!Create view window.*/
113 void SUIT_ViewManager::createView()
118 /*!Insert view window to view manager.
119 *\retval false - if something wrong, else true.
121 bool SUIT_ViewManager::insertView(SUIT_ViewWindow* theView)
123 unsigned int aSize = myViews.size();
124 unsigned int aNbItems = myViews.count()+1;
125 if (aNbItems > aSize) {
126 if (!myViews.resize(aNbItems)) {
127 QMessageBox::critical(myDesktop, tr("Critical error"), tr("There is no memory for the new view!!!"));
130 aSize = myViews.size();
133 connect(theView, SIGNAL(closing(SUIT_ViewWindow*)),
134 this, SLOT(onDeleteView(SUIT_ViewWindow*)));
136 connect(theView, SIGNAL(mousePressed(SUIT_ViewWindow*, QMouseEvent*)),
137 this, SLOT(onMousePressed(SUIT_ViewWindow*, QMouseEvent*)));
139 connect(theView, SIGNAL(mouseReleased(SUIT_ViewWindow*, QMouseEvent*)),
140 this, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
142 connect(theView, SIGNAL(mouseDoubleClicked(SUIT_ViewWindow*, QMouseEvent*)),
143 this, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
145 connect(theView, SIGNAL(mouseMoving(SUIT_ViewWindow*, QMouseEvent*)),
146 this, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)));
148 connect(theView, SIGNAL(wheeling(SUIT_ViewWindow*, QWheelEvent*)),
149 this, SIGNAL(wheel(SUIT_ViewWindow*, QWheelEvent*)));
151 connect(theView, SIGNAL(keyPressed(SUIT_ViewWindow*, QKeyEvent*)),
152 this, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)));
154 connect(theView, SIGNAL(keyReleased(SUIT_ViewWindow*, QKeyEvent*)),
155 this, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)));
157 connect(theView, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
158 this, SLOT (onContextMenuRequested( QContextMenuEvent * )));
160 for (uint i = 0; i < aSize; i++) {
162 myViews.insert(i, theView);
169 /*!Emit delete view. Remove view window \a theView from view manager.
171 void SUIT_ViewManager::onDeleteView(SUIT_ViewWindow* theView)
173 emit deleteView(theView);
177 /*!Remove view window \a theView from view manager.
178 *And close the last view, if it has \a theView.
180 void SUIT_ViewManager::removeView(SUIT_ViewWindow* theView)
182 theView->disconnect(this);
183 myViews.remove(myViews.find(theView));
184 if (myActiveView == theView)
186 int aNumItems = myViews.count();
188 emit lastViewClosed(this);
192 Show or hide all views (view windows)
194 void SUIT_ViewManager::setShown( const bool on )
196 for ( uint i = 0; i < myViews.count(); i++ )
197 myViews.at( i )->setShown( on );
200 /*!Emit on \a theEvent mouse pressed in \a theView.*/
201 void SUIT_ViewManager::onMousePressed(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
203 emit mousePress(theView, theEvent);
206 /*!Emit activated for view \a view.
208 void SUIT_ViewManager::onWindowActivated(SUIT_ViewWindow* view)
211 unsigned int aSize = myViews.size();
212 for (uint i = 0; i < aSize; i++) {
213 if (myViews[i] && myViews[i] == view) {
215 emit activated( this );
224 void SUIT_ViewManager::closeAllViews()
226 unsigned int aSize = myViews.size();
227 for (uint i = 0; i < aSize; i++) {
234 *\retval QString - type of view model.
236 QString SUIT_ViewManager::getType() const
238 return (!myViewModel)? "": myViewModel->getType();
242 *\retval SUIT_Study* - current study.
244 SUIT_Study* SUIT_ViewManager::study() const
250 * Sets stydy to NULL.
252 void SUIT_ViewManager::onDeleteStudy()
257 /*! invoke method of SUIT_PopupClient, which notifies about popup*/
258 void SUIT_ViewManager::onContextMenuRequested( QContextMenuEvent* e )
260 contextMenuRequest( e );
263 /*!Context menu popup for \a popup.*/
264 void SUIT_ViewManager::contextMenuPopup( QPopupMenu* popup )
266 SUIT_ViewModel* vm = getViewModel();
268 vm->contextMenuPopup( popup );