]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
minor changes
authorouv <ouv@opencascade.com>
Wed, 31 Jan 2007 10:51:30 +0000 (10:51 +0000)
committerouv <ouv@opencascade.com>
Wed, 31 Jan 2007 10:51:30 +0000 (10:51 +0000)
src/GLViewer/GLViewer_ViewFrame.cxx
src/GLViewer/GLViewer_ViewFrame.h
src/GLViewer/GLViewer_Viewer.cxx
src/GLViewer/GLViewer_Viewer.h

index 1a94c30a1afdd3d75aec509ae5bda7f96c98960f..38edf40b1027635e11c182c5b427a239159ce868 100644 (file)
 #include <SUIT_MessageBox.h>
 
 #include <qcolor.h>
-#include <qfiledialog.h>
 #include <qimage.h>
 #include <qlayout.h>
 #include <qstring.h>
+#include <qclipboard.h>
+#include <qfiledialog.h>
+#include <qapplication.h>
 
 /*!
     Constructor
@@ -252,12 +254,22 @@ void GLViewer_ViewFrame::onUpdate( int )
 {
 }
 
+/*!
+   Copy view content to clipboard [ virtual public ]
+*/
+void GLViewer_ViewFrame::copyView()
+{
+    //QImage anImage = dumpView();
+    //QClipboard* aClipboard = QApplication::clipboard();
+    //aClipboard->setImage( anImage, QClipboard::Clipboard );
+}
+
 //#include <windows.h>
 
 /*!
-  SLOT: called on dump view operation is activated, stores scene to raster file
+    Return view content as QImage [ virtual public ]
 */
-void GLViewer_ViewFrame::onViewDump()
+QImage GLViewer_ViewFrame::dumpView()
 {
     GLViewer_Widget* aWidget = ((GLViewer_ViewPort2d*)myVP)->getGLWidget();
     int width, height;
@@ -271,9 +283,7 @@ void GLViewer_ViewFrame::onViewDump()
     imageSize = (width+reserve_bytes)*height*3;
     imageBits = new unsigned char[imageSize];
 
-    
 #ifdef WNT
-
     int num;
     HBITMAP hBmp;
     HDC hdc_old, hdc;
@@ -288,7 +298,7 @@ void GLViewer_ViewFrame::onViewDump()
     if( !hdc )
     {
         cout << "Can't create compatible DC. Last Error Code: " << GetLastError() << endl;
-        return;
+        return QImage();
     }
 
     int sizeBmi = Standard_Integer( sizeof(BITMAPINFO) + sizeof(RGBQUAD)*3 );
@@ -334,12 +344,12 @@ void GLViewer_ViewFrame::onViewDump()
     if( !hglrc )
     {
         cout << "Can't create new GL Context. Last Error Code: " << GetLastError() << endl;
-        return;
+        return QImage();
     }
     if( !wglMakeCurrent( hdc, hglrc) )
     {
         cout << "Can't make current new context!" << endl;
-        return;
+        return QImage();
     }
     
     glViewport( 0, 0, width, height );
@@ -374,13 +384,10 @@ void GLViewer_ViewFrame::onViewDump()
 
     wglMakeCurrent( hdc_old, hglrc_old );
     wglDeleteContext( hglrc );
-    
-
-#else //XWindows
 #endif
 
     unsigned int* aPix = NULL;
-    QImage  anImage( width, height, 32 );
+    QImage anImage( width, height, 32 );
     for( int i = 0; i < height; i++ )
     {
         memset( anImage.scanLine( i ), 0, sizeof(unsigned int)*width );
@@ -395,6 +402,18 @@ void GLViewer_ViewFrame::onViewDump()
 
     delete [] imageBits;
 
+//#ifdef WNT
+//    return anImage;
+//#else
+    return aWidget->grabFrameBuffer();
+//#endif
+}
+
+/*!
+  SLOT: called on dump view operation is activated, stores scene to raster file
+*/
+void GLViewer_ViewFrame::onViewDump()
+{
     QString aFilter( "*.bmp\n*.png" );
 
     QFileDialog aFileDlg( QDir::current().absPath(), aFilter, this );
@@ -429,11 +448,8 @@ void GLViewer_ViewFrame::onViewDump()
             aFileName += ".png";
         aSaveOp = "PNG";
 
-//#ifdef WNT
-//    if( !anImage.save( aFileName, aSaveOp ) )
-//#else
-    if( !aWidget->grabFrameBuffer().save( aFileName, aSaveOp ) )
-//#endif
+    QImage anImage = dumpView();
+    if( !anImage.save( aFileName, aSaveOp ) )
     {
         SUIT_MessageBox::error1( this,
                                 tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ),
index 27ffdabb06cd93a8663ab8debc6b4688ffc2f66f..37996a3b2e142a49f32c8030e1fd45e9302af3f1 100644 (file)
@@ -69,7 +69,11 @@ public:
   virtual void            onUpdate( int );
 
   virtual QString         getVisualParameters();
-  virtual void            setVisualParameters( const QString& parameters );  
+  virtual void            setVisualParameters( const QString& parameters );
+
+  virtual QImage          dumpView();
+
+  virtual void            copyView();
   
 signals:
   void                    vfDrawExternal( QPainter* );
index 3363add169b5160859fbfac273458aba8526fef0..778bc38b4b79082e09e7fbe6c75b1d92dbb54029 100644 (file)
@@ -68,6 +68,9 @@ void GLViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
   SUIT_ViewModel::setViewManager(theViewManager);
   if (theViewManager) 
   {
+    connect(theViewManager, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), 
+            this, SLOT(onKeyEvent(SUIT_ViewWindow*, QKeyEvent*)));
+
     connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
             this, SLOT(onMouseEvent(SUIT_ViewWindow*, QMouseEvent*)));
 
@@ -319,7 +322,6 @@ bool GLViewer_Viewer::eventFilter( QObject* o, QEvent* e )
     {   /* terminate all */
         activateTransform( NoTransform );
         activateSketching( NoSketching );
-        //cout << "mouseClickedOutside || anyKeyPressed" << endl;
     }
     return QObject::eventFilter( o, e );
 }
@@ -343,8 +345,15 @@ void GLViewer_Viewer::onSelectionCancel()
 /*!
     Listens to key events of the active view. [ virtual protected slot ]
 */
-void GLViewer_Viewer::onKeyEvent( SUIT_ViewWindow*, QKeyEvent* )
+void GLViewer_Viewer::onKeyEvent( SUIT_ViewWindow*, QKeyEvent* )
 {
+    switch( e->type() )
+    {
+        case QEvent::KeyRelease:
+            handleKeyRelease( e );
+            break;
+        default: break;
+    }
 }
 
 /*!
@@ -352,7 +361,6 @@ void GLViewer_Viewer::onKeyEvent( SUIT_ViewWindow*, QKeyEvent* )
 */
 void GLViewer_Viewer::onMouseEvent( SUIT_ViewWindow*, QMouseEvent* e )
 {
-    //cout << "GLViewer_Viewer::onMouseEvent" << endl;
     switch( e->type() )
     {
         case QEvent::MouseButtonPress:
@@ -373,7 +381,6 @@ void GLViewer_Viewer::onMouseEvent( SUIT_ViewWindow*, QMouseEvent* e )
 */
 void GLViewer_Viewer::onWheelEvent( SUIT_ViewWindow*, QWheelEvent* e )
 {
-    //cout << "GLViewer_Viewer::onMouseEvent" << endl;
     switch( e->type() )
     {
         case QEvent::Wheel:
@@ -417,6 +424,13 @@ void GLViewer_Viewer::unhilightDetected()
         getSelector()->undetectAll();
 }
 
+/*!
+    Key release handler
+*/
+void GLViewer_Viewer::handleKeyRelease( QKeyEvent* e )
+{
+}
+
 /*!
     Mouse press handler. If 'accelKey()' is pressed, activates default
     transformations( Zoom or Pan ) in the active viewport. [ private ]
index 0d68a450da8fb43ec6e3885adee7cd350340137d..21a588147a8a741d89c439b3ecd59c9d4eaf4823 100644 (file)
@@ -116,6 +116,7 @@ protected slots:
     virtual void                 onChangeBgColor();
 
 private:
+    void                         handleKeyRelease( QKeyEvent* );
     void                         handleMouseMove( QMouseEvent* );
     void                         handleMousePress( QMouseEvent* );
     void                         handleMouseRelease( QMouseEvent* );