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 // SUIT_ViewWindow.cxx: implementation of the SUIT_ViewWindow class.
21 //////////////////////////////////////////////////////////////////////
23 #include "SUIT_ViewWindow.h"
24 #include "SUIT_Desktop.h"
25 #include "SUIT_Application.h"
26 #include "SUIT_Study.h"
27 #include "SUIT_ViewManager.h"
28 #include "SUIT_Tools.h"
29 #include "SUIT_MessageBox.h"
31 #include "qpopupmenu.h"
32 #include "qapplication.h"
34 /*!\class SUIT_ViewWindow
35 * Class provide view window.
38 /*! Dump view custom event*/
39 const int DUMP_EVENT = QEvent::User + 123;
42 SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
43 : QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose )
45 myDesktop = theDesktop;
47 if ( myDesktop->icon() )
48 setIcon( *myDesktop->icon() );
52 SUIT_ViewWindow::~SUIT_ViewWindow()
56 /*! Close event \a theEvent.
58 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
60 QMainWindow::closeEvent( theEvent );
64 /*! Context menu requested for event \a e.
66 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
68 if ( e->reason() != QContextMenuEvent::Mouse )
69 emit contextMenuRequested( e );
72 /*! Post events on dump view.
74 void SUIT_ViewWindow::onDumpView()
76 qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
77 qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
80 /*! Reaction view window on event \a e.
82 bool SUIT_ViewWindow::event( QEvent* e )
84 if ( e->type() == DUMP_EVENT ) {
86 if ( myManager && myManager->study() && myManager->study()->application() ) {
87 // first create an image (this is small trick to avoid dialog box overlapping)
88 QImage img = dumpView();
89 if ( !img.isNull() ) {
91 QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 );
92 if ( !fileName.isEmpty() ) {
93 QString fmt = SUIT_Tools::extension( fileName ).upper();
94 if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
95 if ( fmt == "JPG" ) fmt = "JPEG";
96 QApplication::setOverrideCursor( Qt::waitCursor );
97 bOk = img.save( fileName, fmt.latin1() );
98 QApplication::restoreOverrideCursor();
101 bOk = true; // cancelled
106 SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
110 return QMainWindow::event( e );
113 /*! Called by SUIT_Accel::onActivated() when a key accelerator was activated and this window was active
115 void SUIT_ViewWindow::onAccelAction( int _action )
120 /*! action handle standard action (zoom, pan) or custom action. to be redefined in successors.
122 void SUIT_ViewWindow::action( const int )