Salome HOME
New item (FontItem), allowing to show information about font setting and to select...
[modules/gui.git] / src / SUIT / SUIT_ViewWindow.cxx
index 4eb47e3ef6706bef2dfbbaba7600eff1bd926413..7886b415bfbb19adff3cec5d40e9d812be3d9d6f 100755 (executable)
@@ -4,8 +4,18 @@
 
 #include "SUIT_ViewWindow.h"
 #include "SUIT_Desktop.h"
+#include "SUIT_Application.h"
+#include "SUIT_Study.h"
+#include "SUIT_ViewManager.h"
+#include "SUIT_Tools.h"
+#include "SUIT_MessageBox.h"
 #include "qhbox.h"
 #include "qpopupmenu.h"
+#include "qapplication.h"
+
+// Dump view custom event
+const int DUMP_EVENT = QEvent::User + 123;
+
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
@@ -33,3 +43,44 @@ void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e )
   if ( e->reason() != QContextMenuEvent::Mouse )
     emit contextMenuRequested( e );
 }
+
+//****************************************************************
+void SUIT_ViewWindow::onDumpView()
+{
+  qApp->postEvent( this, new QPaintEvent( QRect( 0, 0, width(), height() ), TRUE ) );
+  qApp->postEvent( this, new QCustomEvent( DUMP_EVENT ) );
+}
+
+//****************************************************************
+bool SUIT_ViewWindow::event( QEvent* e )
+{
+  if ( e->type() == DUMP_EVENT ) {
+    bool bOk = false;
+    if ( myManager && myManager->study() && myManager->study()->application() ) {
+      // first create an image (this is small trick to avoid dialog box overlapping)
+      QImage img = dumpView();
+      if ( !img.isNull() ) {
+        // get file name
+        QString fileName = myManager->study()->application()->getFileName( false, QString::null, tr( "TLT_IMAGE_FILES" ), tr( "TLT_DUMP_VIEW" ), 0 );
+        if ( !fileName.isEmpty() ) {
+          QString fmt = SUIT_Tools::extension( fileName ).upper();
+          if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
+         if ( fmt == "JPG" )  fmt = "JPEG";
+          QApplication::setOverrideCursor( Qt::waitCursor );
+         bOk = img.save( fileName, fmt.latin1() );
+         QApplication::restoreOverrideCursor();
+        }
+       else {
+          bOk = true; // cancelled
+        }
+      }
+    }
+    if ( !bOk ) {
+      SUIT_MessageBox::error1( this, tr( "ERROR" ), tr( "ERR_CANT_DUMP_VIEW" ), tr( "BUT_OK" ) );
+    }
+    return TRUE;
+  }
+  return QMainWindow::event( e );
+}
+
+//****************************************************************