1 // SUIT_ViewWindow.cxx: implementation of the SUIT_ViewWindow class.
3 //////////////////////////////////////////////////////////////////////
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"
13 #include "qpopupmenu.h"
14 #include "qapplication.h"
16 /*!\class SUIT_ViewWindow
17 * Class provide view window.
20 /*! Dump view custom event*/
21 const int DUMP_EVENT = QEvent::User + 123;
24 SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
25 : QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose )
27 myDesktop = theDesktop;
30 SUIT_ViewWindow::~SUIT_ViewWindow()
34 /*! Close event \a theEvent.
36 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
38 QMainWindow::closeEvent( theEvent );
42 /*! Context menu requested for event \a e.
44 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
46 if ( e->reason() != QContextMenuEvent::Mouse )
47 emit contextMenuRequested( e );
50 /*! Post events on dump view.
52 void SUIT_ViewWindow::onDumpView()
54 qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
55 qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
58 /*! Reaction view window on event \a e.
60 bool SUIT_ViewWindow::event( QEvent* e )
62 if ( e->type() == DUMP_EVENT ) {
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() ) {
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();
79 bOk = true; // cancelled
84 SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
88 return QMainWindow::event( e );