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;
29 if ( myDesktop->icon() )
30 setIcon( *myDesktop->icon() );
34 SUIT_ViewWindow::~SUIT_ViewWindow()
38 /*! Close event \a theEvent.
40 void SUIT_ViewWindow::closeEvent(QCloseEvent* theEvent)
42 QMainWindow::closeEvent( theEvent );
46 /*! Context menu requested for event \a e.
48 void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
50 if ( e->reason() != QContextMenuEvent::Mouse )
51 emit contextMenuRequested( e );
54 /*! Post events on dump view.
56 void SUIT_ViewWindow::onDumpView()
58 qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
59 qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
62 /*! Reaction view window on event \a e.
64 bool SUIT_ViewWindow::event( QEvent* e )
66 if ( e->type() == DUMP_EVENT ) {
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() ) {
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();
83 bOk = true; // cancelled
88 SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
92 return QMainWindow::event( e );
95 /*! Called by SUIT_Accel::onActivated() when a key accelerator was activated and this window was active
97 void SUIT_ViewWindow::onAccelAction( int _action )
102 /*! action handle standard action (zoom, pan) or custom action. to be redefined in successors.
104 void SUIT_ViewWindow::action( const int )