Salome HOME
Update comments
[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 /*! Destructor.*/
30 SUIT_ViewWindow::~SUIT_ViewWindow()
31 {
32 }
33
34 /*! Close event \a theEvent.
35 */
36 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
37 {
38   QMainWindow::closeEvent( theEvent );
39   emit closing( this );
40 }
41
42 /*! Context menu requested for event \a e.
43 */
44 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
45 {
46   if ( e->reason() != QContextMenuEvent::Mouse )
47     emit contextMenuRequested( e );
48 }
49
50 /*! Post events on dump view.
51 */
52 void SUIT_ViewWindow::onDumpView()
53 {
54   qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
55   qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
56 }
57
58 /*! Reaction view window on event \a e.
59 */
60 bool SUIT_ViewWindow::event( QEvent* e )
61 {
62   if ( e->type() == DUMP_EVENT ) {
63     bool bOk = false;
64     if ( myManager && myManager->study() && myManager->study()->application() ) {
65       // first create an image (this is small trick to avoid dialog box overlapping)
66       QImage img = dumpView();
67       if ( !img.isNull() ) {
68         // get file name
69         QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 );
70         if ( !fileName.isEmpty() ) {
71           QString fmt = SUIT_Tools::extension( fileName ).upper();
72           if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
73           if ( fmt == "JPG" )  fmt = "JPEG";
74           QApplication::setOverrideCursor( Qt::waitCursor );
75           bOk = img.save( fileName, fmt.latin1() );
76           QApplication::restoreOverrideCursor();
77         }
78         else {
79           bOk = true; // cancelled
80         }
81       }
82     }
83     if ( !bOk ) {
84       SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
85     }
86     return TRUE;
87   }
88   return QMainWindow::event( e );
89 }