]> SALOME platform Git repositories - modules/gui.git/blob - src/SUIT/SUIT_ViewWindow.cxx
Salome HOME
800bfa73a349be9902e56493c1a485d62daaee29
[modules/gui.git] / src / SUIT / SUIT_ViewWindow.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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/
18 //
19 // SUIT_ViewWindow.cxx: implementation of the SUIT_ViewWindow class.
20 //
21 //////////////////////////////////////////////////////////////////////
22
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"
30 #include "qhbox.h"
31 #include "qpopupmenu.h"
32 #include "qapplication.h"
33
34 /*!\class SUIT_ViewWindow
35  * Class provide view window.
36  */
37
38 /*! Dump view custom event*/
39 const int DUMP_EVENT = QEvent::User + 123;
40
41 /*! Constructor.*/
42 SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
43 : QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose )
44 {
45   myDesktop = theDesktop;
46
47   if ( myDesktop->icon() )
48     setIcon( *myDesktop->icon() );
49 }
50
51 /*! Destructor.*/
52 SUIT_ViewWindow::~SUIT_ViewWindow()
53 {
54 }
55
56 /*! Close event \a theEvent.
57 */
58 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
59 {
60   QMainWindow::closeEvent( theEvent );
61   emit closing( this );
62 }
63
64 /*! Context menu requested for event \a e.
65 */
66 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
67 {
68   if ( e->reason() != QContextMenuEvent::Mouse )
69     emit contextMenuRequested( e );
70 }
71
72 /*! Post events on dump view.
73 */
74 void SUIT_ViewWindow::onDumpView()
75 {
76   qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
77   qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
78 }
79
80 /*! Reaction view window on event \a e.
81 */
82 bool SUIT_ViewWindow::event( QEvent* e )
83 {
84   if ( e->type() == DUMP_EVENT ) {
85     bool bOk = false;
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() ) {
90         // get file name
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();
99         }
100         else {
101           bOk = true; // cancelled
102         }
103       }
104     }
105     if ( !bOk ) {
106       SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
107     }
108     return TRUE;
109   }
110   return QMainWindow::event( e );
111 }
112
113 /*! Called by SUIT_Accel::onActivated() when a key accelerator was activated and this window was active
114 */
115 void SUIT_ViewWindow::onAccelAction( int _action )
116 {
117   action( _action );
118 }
119
120 /*! action  handle standard action (zoom, pan) or custom action.  to be redefined in successors.
121 */
122 void SUIT_ViewWindow::action( const int  )
123 {
124 }