From 086e66f4980a96febb1dd535ed1319b6287e1937 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 31 Jan 2007 10:51:30 +0000 Subject: [PATCH] minor changes --- src/GLViewer/GLViewer_ViewFrame.cxx | 50 +++++++++++++++++++---------- src/GLViewer/GLViewer_ViewFrame.h | 6 +++- src/GLViewer/GLViewer_Viewer.cxx | 22 ++++++++++--- src/GLViewer/GLViewer_Viewer.h | 1 + 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/GLViewer/GLViewer_ViewFrame.cxx b/src/GLViewer/GLViewer_ViewFrame.cxx index 1a94c30a1..38edf40b1 100644 --- a/src/GLViewer/GLViewer_ViewFrame.cxx +++ b/src/GLViewer/GLViewer_ViewFrame.cxx @@ -35,10 +35,12 @@ #include #include -#include #include #include #include +#include +#include +#include /*! 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 /*! - 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" ), diff --git a/src/GLViewer/GLViewer_ViewFrame.h b/src/GLViewer/GLViewer_ViewFrame.h index 27ffdabb0..37996a3b2 100644 --- a/src/GLViewer/GLViewer_ViewFrame.h +++ b/src/GLViewer/GLViewer_ViewFrame.h @@ -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* ); diff --git a/src/GLViewer/GLViewer_Viewer.cxx b/src/GLViewer/GLViewer_Viewer.cxx index 3363add16..778bc38b4 100644 --- a/src/GLViewer/GLViewer_Viewer.cxx +++ b/src/GLViewer/GLViewer_Viewer.cxx @@ -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* e ) { + 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 ] diff --git a/src/GLViewer/GLViewer_Viewer.h b/src/GLViewer/GLViewer_Viewer.h index 0d68a450d..21a588147 100644 --- a/src/GLViewer/GLViewer_Viewer.h +++ b/src/GLViewer/GLViewer_Viewer.h @@ -116,6 +116,7 @@ protected slots: virtual void onChangeBgColor(); private: + void handleKeyRelease( QKeyEvent* ); void handleMouseMove( QMouseEvent* ); void handleMousePress( QMouseEvent* ); void handleMouseRelease( QMouseEvent* ); -- 2.39.2