]> SALOME platform Git repositories - modules/gui.git/blob - src/SUIT/SUIT_ViewWindow.cxx
Salome HOME
no 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 /*!\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   if ( myDesktop->icon() )
30     setIcon( *myDesktop->icon() );
31 }
32
33 /*! Destructor.*/
34 SUIT_ViewWindow::~SUIT_ViewWindow()
35 {
36 }
37
38 /*! Close event \a theEvent.
39 */
40 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
41 {
42   QMainWindow::closeEvent( theEvent );
43   emit closing( this );
44 }
45
46 /*! Context menu requested for event \a e.
47 */
48 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
49 {
50   if ( e->reason() != QContextMenuEvent::Mouse )
51     emit contextMenuRequested( e );
52 }
53
54 /*! Post events on dump view.
55 */
56 void SUIT_ViewWindow::onDumpView()
57 {
58   qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
59   qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
60 }
61
62 /*! Reaction view window on event \a e.
63 */
64 bool SUIT_ViewWindow::event( QEvent* e )
65 {
66   if ( e->type() == DUMP_EVENT ) {
67     bool bOk = false;
68     if ( myManager && myManager->study() && myManager->study()->application() ) {
69       // first create an image (this is small trick to avoid dialog box overlapping)
70       QImage img = dumpView();
71       if ( !img.isNull() ) {
72         // get file name
73         QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 );
74         if ( !fileName.isEmpty() ) {
75           QString fmt = SUIT_Tools::extension( fileName ).upper();
76           if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
77           if ( fmt == "JPG" )  fmt = "JPEG";
78           QApplication::setOverrideCursor( Qt::waitCursor );
79           bOk = img.save( fileName, fmt.latin1() );
80           QApplication::restoreOverrideCursor();
81         }
82         else {
83           bOk = true; // cancelled
84         }
85       }
86     }
87     if ( !bOk ) {
88       SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
89     }
90     return TRUE;
91   }
92   return QMainWindow::event( e );
93 }
94
95 /*! Called by SUIT_Accel::onActivated() when a key accelerator was activated and this window was active
96 */
97 void SUIT_ViewWindow::onAccelAction( int _action )
98 {
99   action( _action );
100 }
101
102 /*! action  handle standard action (zoom, pan) or custom action.  to be redefined in successors.
103 */
104 void SUIT_ViewWindow::action( const int  )
105 {
106 }