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 // Dump view custom event
17 const int DUMP_EVENT = QEvent::User + 123;
19 //////////////////////////////////////////////////////////////////////
20 // Construction/Destruction
21 //////////////////////////////////////////////////////////////////////
23 SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
24 : QMainWindow( theDesktop, "SUIT_ViewWindow", Qt::WDestructiveClose )
26 myDesktop = theDesktop;
29 SUIT_ViewWindow::~SUIT_ViewWindow()
33 //***************************************************************
34 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
36 QMainWindow::closeEvent( theEvent );
40 //****************************************************************
41 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
43 if ( e->reason() != QContextMenuEvent::Mouse )
44 emit contextMenuRequested( e );
47 //****************************************************************
48 void SUIT_ViewWindow::onDumpView()
50 qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
51 qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
54 //****************************************************************
55 bool SUIT_ViewWindow::event( QEvent* e )
57 if ( e->type() == DUMP_EVENT ) {
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() ) {
64 QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 );
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();
74 bOk = true; // cancelled
79 SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
83 return QMainWindow::event( e );
86 //****************************************************************