Salome HOME
*** empty log message ***
[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 // Dump view custom event
17 const int DUMP_EVENT = QEvent::User + 123;
18
19 //////////////////////////////////////////////////////////////////////
20 // Construction/Destruction
21 //////////////////////////////////////////////////////////////////////
22
23 SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
24 : QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose )
25 {
26   myDesktop = theDesktop;
27 }
28
29 SUIT_ViewWindow::~SUIT_ViewWindow()
30 {
31 }
32
33 //***************************************************************
34 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
35 {
36   QMainWindow::closeEvent( theEvent );
37   emit closing( this );
38 }
39
40 //****************************************************************
41 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
42 {
43   if ( e->reason() != QContextMenuEvent::Mouse )
44     emit contextMenuRequested( e );
45 }
46
47 //****************************************************************
48 void SUIT_ViewWindow::onDumpView()
49 {
50   qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
51   qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
52 }
53
54 //****************************************************************
55 bool SUIT_ViewWindow::event( QEvent* e )
56 {
57   if ( e->type() == DUMP_EVENT ) {
58     bool bOk = false;
59     if ( myManager && myManager->study() && myManager->study()->application() ) {
60       // first create an image (this is small trick to avoid dialog box overlapping)
61       QImage img = dumpView();
62       if ( !img.isNull() ) {
63         // get file name
64         QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 );
65         if ( !fileName.isEmpty() ) {
66           QString fmt = SUIT_Tools::extension( fileName ).upper();
67           if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
68           if ( fmt == "JPG" )  fmt = "JPEG";
69           QApplication::setOverrideCursor( Qt::waitCursor );
70           bOk = img.save( fileName, fmt.latin1() );
71           QApplication::restoreOverrideCursor();
72         }
73         else {
74           bOk = true; // cancelled
75         }
76       }
77     }
78     if ( !bOk ) {
79       SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
80     }
81     return TRUE;
82   }
83   return QMainWindow::event( e );
84 }
85
86 //****************************************************************