1 // Copyright (C) 2007-2008 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.
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
22 // SUIT_ViewWindow.cxx: implementation of the SUIT_ViewWindow class.
24 #include "SUIT_ViewWindow.h"
26 #include "SUIT_Tools.h"
27 #include "SUIT_Study.h"
28 #include "SUIT_Desktop.h"
29 #include "SUIT_MessageBox.h"
30 #include "SUIT_Application.h"
31 #include "SUIT_ViewManager.h"
32 #include "QtxActionToolMgr.h"
36 #include <QApplication>
37 #include <QContextMenuEvent>
39 /*!\class SUIT_ViewWindow
40 * Class provide view window.
43 /*! Dump view custom event*/
44 const int DUMP_EVENT = QEvent::User + 123;
47 SUIT_ViewWindow::SUIT_ViewWindow( SUIT_Desktop* theDesktop )
48 : QMainWindow( theDesktop )
50 myDesktop = theDesktop;
52 setWindowIcon( myDesktop->windowIcon() );
54 setAttribute( Qt::WA_DeleteOnClose );
56 myToolMgr = new QtxActionToolMgr( this );
60 SUIT_ViewWindow::~SUIT_ViewWindow()
65 Sets new view manager for window
66 \param theManager - new view manager
68 void SUIT_ViewWindow::setViewManager( SUIT_ViewManager* theManager )
70 myManager = theManager;
74 \return view manager of window
76 SUIT_ViewManager* SUIT_ViewWindow::getViewManager() const
82 \return QImage, containing all scene rendering in window
84 QImage SUIT_ViewWindow::dumpView()
90 Saves image to file according to the format
92 \param fileName - name of file
93 \param format - string contains name of format (for example, "BMP"(default) or "JPEG", "JPG")
95 bool SUIT_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
100 QString fmt = format;
102 fmt = QString( "BMP" ); // default format
103 else if( fmt == "JPG" )
106 QApplication::setOverrideCursor( Qt::WaitCursor );
107 bool res = img.save( fileName, fmt.toLatin1() );
108 QApplication::restoreOverrideCursor();
113 Saves scene rendering in window to file
114 \param fileName - name of file
115 \param format - string contains name of format (for example, "BMP"(default) or "JPEG", "JPG")
117 bool SUIT_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& format )
119 return dumpViewToFormat( dumpView(), fileName, format );
123 Set or clear flag Qt::WDestructiveClose
125 void SUIT_ViewWindow::setDestructiveClose( const bool on )
127 setAttribute( Qt::WA_DeleteOnClose, on );
130 /*! Close event \a theEvent.
132 void SUIT_ViewWindow::closeEvent( QCloseEvent* e )
135 emit closing( this );
138 /*! Context menu requested for event \a e.
140 void SUIT_ViewWindow::contextMenuEvent( QContextMenuEvent* e )
144 QMainWindow::contextMenuEvent( e );
146 if ( e->isAccepted() )
149 if ( e->reason() != QContextMenuEvent::Mouse )
150 emit contextMenuRequested( e );
153 /*! Post events on dump view.
155 void SUIT_ViewWindow::onDumpView()
157 QApplication::postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ) ) );
158 QApplication::postEvent( this, new QEvent( (QEvent::Type)DUMP_EVENT ) );
162 \return filters for image files
164 QString SUIT_ViewWindow::filter() const
166 return tr( "TLT_IMAGE_FILES" );
169 /*! Reaction view window on event \a e.
171 bool SUIT_ViewWindow::event( QEvent* e )
173 if ( e->type() == DUMP_EVENT )
176 if ( myManager && myManager->study() && myManager->study()->application() )
178 QImage im = dumpView();
181 SUIT_Application* app = myManager->study()->application();
182 QString fileName = app->getFileName( false, QString(), filter(), tr( "TLT_DUMP_VIEW" ), 0 );
183 if ( !fileName.isEmpty() )
185 QString fmt = SUIT_Tools::extension( fileName ).toUpper();
186 bOk = dumpViewToFormat( im, fileName, fmt );
189 bOk = true; // cancelled
192 SUIT_MessageBox::critical( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ) );
196 return QMainWindow::event( e );
199 /*! Called by SUIT_Accel::onActivated() when a key accelerator was activated and this window was active
201 bool SUIT_ViewWindow::onAccelAction( int _action )
203 return action( _action );
206 /*! action handle standard action (zoom, pan) or custom action. to be redefined in successors.
208 bool SUIT_ViewWindow::action( const int )
214 \return string containing visual parameters of window
216 QString SUIT_ViewWindow::getVisualParameters()
222 Sets visual parameters of window by its string representation
223 \param parameters - string with visual parameters
225 void SUIT_ViewWindow::setVisualParameters( const QString& /*parameters*/ )
230 \return associated tool bar manager
232 QtxActionToolMgr* SUIT_ViewWindow::toolMgr() const
238 \return window unique identifier
240 int SUIT_ViewWindow::getId() const
242 return int(long(this));