Salome HOME
Fix for bug 10438: Crash during Explode on Blocks operation (Global selection on...
[modules/gui.git] / src / SUIT / SUIT_ViewWindow.cxx
1 // SUIT_ViewWindow.cxx: implementation of the SUIT_ViewWindow class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "SUIT_ViewWindow.h"
6 #include "SUIT_Desktop.h"
7 #include "SUIT_Application.h"
8 #include "SUIT_Study.h"
9 #include "SUIT_ViewManager.h"
10 #include "SUIT_Tools.h"
11 #include "SUIT_MessageBox.h"
12 #include "qhbox.h"
13 #include "qpopupmenu.h"
14 #include "qapplication.h"
15
16 /*!\class SUIT_ViewWindow
17  * Class provide view window.
18  */
19
20 /*! Dump view custom event*/
21 const int DUMP_EVENT = QEvent::User + 123;
22
23 /*! Constructor.*/
24 SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
25 : QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose )
26 {
27   myDesktop = theDesktop;
28 }
29
30 /*! Destructor.*/
31 SUIT_ViewWindow::~SUIT_ViewWindow()
32 {
33 }
34
35 /*! Close event \a theEvent.
36 */
37 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
38 {
39   QMainWindow::closeEvent( theEvent );
40   emit closing( this );
41 }
42
43 /*! Context menu requested for event \a e.
44 */
45 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
46 {
47   if ( e->reason() != QContextMenuEvent::Mouse )
48     emit contextMenuRequested( e );
49 }
50
51 /*! Post events on dump view.
52 */
53 void SUIT_ViewWindow::onDumpView()
54 {
55   qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
56   qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
57 }
58
59 /*! Reaction view window on event \a e.
60 */
61 bool SUIT_ViewWindow::event( QEvent* e )
62 {
63   if ( e->type() == DUMP_EVENT ) {
64     bool bOk = false;
65     if ( myManager && myManager->study() && myManager->study()->application() ) {
66       // first create an image (this is small trick to avoid dialog box overlapping)
67       QImage img = dumpView();
68       if ( !img.isNull() ) {
69         // get file name
70         QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 );
71         if ( !fileName.isEmpty() ) {
72           QString fmt = SUIT_Tools::extension( fileName ).upper();
73           if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
74           if ( fmt == "JPG" )  fmt = "JPEG";
75           QApplication::setOverrideCursor( Qt::waitCursor );
76           bOk = img.save( fileName, fmt.latin1() );
77           QApplication::restoreOverrideCursor();
78         }
79         else {
80           bOk = true; // cancelled
81         }
82       }
83     }
84     if ( !bOk ) {
85       SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
86     }
87     return TRUE;
88   }
89   return QMainWindow::event( e );
90 }
91
92 /*! Called by SUIT_Accel::onActivated() when a key accelerator was activated and this window was active
93 */
94 void SUIT_ViewWindow::onAccelAction( int _action )
95 {
96   action( _action );
97 }
98
99 /*! action  handle standard action (zoom, pan) or custom action.  to be redefined in successors.
100 */
101 void SUIT_ViewWindow::action( const int  )
102 {
103 }