Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt

2013-05-08 Thread Robert Milharcic

On 8.5.2013 7:04, Sujan Dasmahapatra wrote:
I am trying to implement a mouse press event with QT and OSG but 
unable to do it. Pls help.


Below is my ViewerWidget class which is derived from QWidget and 
osg::CompositeViewer..In the constructor I got gView which is a 
osg::GLWidget, I am trying override mousePressEvent but when I click 
message not coming. What I am doing wrong pls help..


[snip]

osg::Camera* ViewerWidget::createCamera( int x, int y, int w, int h, 
const std::string name, bool windowDecoration )

{
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptrosg::GraphicsContext::Traits traits = new 
osg::GraphicsContext::Traits;

traits-windowName = name;
traits-windowDecoration = windowDecoration;
traits-x = x;
traits-y = y;
traits-width = w;
traits-height = h;
traits-doubleBuffer = true;
traits-alpha = ds-getMinimumNumAlphaBits();
traits-stencil = ds-getMinimumNumStencilBits();
traits-sampleBuffers = ds-getMultiSamples();
traits-samples = ds-getNumMultiSamples();
osg::ref_ptrosg::Camera camera = new osg::Camera;
camera-setGraphicsContext( new 
osgQt::GraphicsWindowQt(traits.get()) );

camera-setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
camera-setViewport( new osg::Viewport(0, 0, traits-width, 
traits-height) );

camera-setProjectionMatrixAsPerspective(
30.0f, 
static_castdouble(traits-width)/static_castdouble(traits-height), 1.0f, 
1.0f );

return camera.release();
 }

I don't know why this code didn't crash, I think it should. Anyway, you 
should create an instance of the CSGraphicsView somewhere within 
createCamera:


CSGraphicsView* gView = new CSGraphicsView;
gView-setGeometry(x, y, w, h);
traits-inheritedWindowData = new osgQt::GraphicsWindowQt::WindowData( 
gView );


...
or you can pass an instance of the CSGraphicsView to the 
osgQt::GraphicsWindowQt constructor.



Robert Milharcic
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt

2013-05-08 Thread Sujan Dasmahapatra
Thanks Robert. It is working fine...

On the left mouse press I am showing a message using QMessagBox. But on the
middle mouse press was having pan and right mouse press was having zoom in
zoom out. How can I retain those functionalities. With this these
functionalities are gone.

void CSGraphicsView::mousePressEvent(QMouseEvent *e)
{
if(e-button()==Qt::LeftButton)
{
QMessageBox msg;
msg.setText(Mouse pressed);
msg.exec();
}
}


On Wed, May 8, 2013 at 3:59 PM, Robert Milharcic 
robert.milhar...@ib-caddy.si wrote:

 On 8.5.2013 7:04, Sujan Dasmahapatra wrote:

 I am trying to implement a mouse press event with QT and OSG but unable
 to do it. Pls help.

 Below is my ViewerWidget class which is derived from QWidget and
 osg::CompositeViewer..In the constructor I got gView which is a
 osg::GLWidget, I am trying override mousePressEvent but when I click
 message not coming. What I am doing wrong pls help..

 [snip]


 osg::Camera* ViewerWidget::createCamera( int x, int y, int w, int h,
 const std::string name, bool windowDecoration )
 {
 osg::DisplaySettings* ds = osg::DisplaySettings::**
 instance().get();
 osg::ref_ptrosg::**GraphicsContext::Traits traits = new
 osg::GraphicsContext::Traits;
 traits-windowName = name;
 traits-windowDecoration = windowDecoration;
 traits-x = x;
 traits-y = y;
 traits-width = w;
 traits-height = h;
 traits-doubleBuffer = true;
 traits-alpha = ds-getMinimumNumAlphaBits();
 traits-stencil = ds-getMinimumNumStencilBits()**;
 traits-sampleBuffers = ds-getMultiSamples();
 traits-samples = ds-getNumMultiSamples();
 osg::ref_ptrosg::Camera camera = new osg::Camera;
 camera-setGraphicsContext( new 
 osgQt::GraphicsWindowQt(**traits.get())
 );
 camera-setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
 camera-setViewport( new osg::Viewport(0, 0, traits-width,
 traits-height) );
 camera-**setProjectionMatrixAsPerspecti**ve(
 30.0f, static_castdouble(traits-**
 width)/static_castdouble(**traits-height), 1.0f, 1.0f );
 return camera.release();
  }

  I don't know why this code didn't crash, I think it should. Anyway, you
 should create an instance of the CSGraphicsView somewhere within
 createCamera:

 CSGraphicsView* gView = new CSGraphicsView;
 gView-setGeometry(x, y, w, h);
 traits-inheritedWindowData = new osgQt::GraphicsWindowQt::**WindowData(
 gView );

 ...
 or you can pass an instance of the CSGraphicsView to the
 osgQt::GraphicsWindowQt constructor.


 Robert Milharcic
 __**_
 osg-users mailing list
 osg-users@lists.**openscenegraph.org osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.**org/listinfo.cgi/osg-users-**
 openscenegraph.orghttp://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




-- 
Thanks  Regards
Sujan
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt

2013-05-08 Thread Robert Milharcic

On 8.5.2013 10:16, Sujan Dasmahapatra wrote:

Thanks Robert. It is working fine...

On the left mouse press I am showing a message using QMessagBox. But 
on the middle mouse press was having pan and right mouse press was 
having zoom in zoom out. How can I retain those functionalities. With 
this these functionalities are gone.


void CSGraphicsView::mousePressEvent(QMouseEvent *e)
{
if(e-button()==Qt::LeftButton)
{
QMessageBox msg;
msg.setText(Mouse pressed);
msg.exec();
}
}

Call base class implementation in a case where you need to retain 
original functionality:


void CSGraphicsView::mousePressEvent(QMouseEvent *e)
{
if(e-button()==Qt::LeftButton)
{
QMessageBox msg;
msg.setText(Mouse pressed);
msg.exec();
}
else
GLWidget::mousePressEvent(e);
}

Also, calling frame on paintEvent might not be enough. You should also 
call frame on every user input, on all mouse and keyboard events for 
example... or you can mount a QTimer and make it call frame at some 
interval.


Robert Milharcic
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt

2013-05-08 Thread Sujan Dasmahapatra
Thats right Robert. Thanks a lot for your suggestions I appreciate it.
Thanks Sujan


On Wed, May 8, 2013 at 5:40 PM, Robert Milharcic 
robert.milhar...@ib-caddy.si wrote:

  On 8.5.2013 10:16, Sujan Dasmahapatra wrote:

 Thanks Robert. It is working fine...

  On the left mouse press I am showing a message using QMessagBox. But on
 the middle mouse press was having pan and right mouse press was having zoom
 in zoom out. How can I retain those functionalities. With this these
 functionalities are gone.

  void CSGraphicsView::mousePressEvent(QMouseEvent *e)
 {
  if(e-button()==Qt::LeftButton)
  {
  QMessageBox msg;
  msg.setText(Mouse pressed);
  msg.exec();
  }
 }

  Call base class implementation in a case where you need to retain
 original functionality:

  void CSGraphicsView::mousePressEvent(QMouseEvent *e)
 {
  if(e-button()==Qt::LeftButton)
  {
  QMessageBox msg;
  msg.setText(Mouse pressed);
  msg.exec();
  }
 else
  GLWidget::mousePressEvent(e);
 }

 Also, calling frame on paintEvent might not be enough. You should also
 call frame on every user input, on all mouse and keyboard events for
 example... or you can mount a QTimer and make it call frame at some
 interval.

 Robert Milharcic

 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




-- 
Thanks  Regards
Sujan
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] MousepressEvent not able to capture from osg::Viewer by Qt

2013-05-07 Thread Sujan Dasmahapatra
I am trying to implement a mouse press event with QT and OSG but unable to
do it. Pls help.

Below is my ViewerWidget class which is derived from QWidget and
osg::CompositeViewer..In the constructor I got gView which is a
osg::GLWidget, I am trying override mousePressEvent but when I click
message not coming. What I am doing wrong pls help..

My gView pointer is of class CSGraphicsView as below
/
#ifndef GVIEW_H
#define GVIEW_H
#include osg\GraphicsContext
#include osgQt\GraphicsWindowQt
#include QtGui\qwidget.h
#include QtCore\qobject.h
#include QtGui\qmouseeventtransition.h
class CSGraphicsView : public osgQt::GLWidget
{
public:
CSGraphicsView(QWidget* parent=0);
~CSGraphicsView();

virtual void mousePressEvent(QMouseEvent *e);
};

#endif // GVIEW_H


//Implementations is
void CSGraphicsView::mousePressEvent(QMouseEvent *e)
{
QMessageBox msg;
msg.setText(Mouse pressed);
msg.exec();
}//But this msg is not coming when i am pressing mouse.
/

/
ViewerWidget::ViewerWidget(osgViewer::ViewerBase::ThreadingModel
threadingModel, osg::Group* scene) : QWidget()
{
setThreadingModel(threadingModel);

gView = static_castCSGraphicsView* (addViewWidget(
createCamera(0,0,100,100), scene ));

QGridLayout* grid = new QGridLayout;
grid-addWidget( gView, 0, 0 );
setLayout( grid );

connect( _timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}

osgQt::GLWidget* ViewerWidget::addViewWidget( osg::Camera* camera,
osg::Group* scene )
{
osgViewer::View* view = new osgViewer::View;
view-setCamera( camera );
addView( view );

view-setSceneData( scene );
view-addEventHandler( new osgViewer::StatsHandler );
view-setCameraManipulator( new osgGA::TrackballManipulator );

gw = dynamic_castosgQt::GraphicsWindowQt* (
camera-getGraphicsContext() );
return gw ? gw-getGLWidget() : NULL;
}


osg::Camera* ViewerWidget::createCamera( int x, int y, int w, int h, const
std::string name, bool windowDecoration )
{
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptrosg::GraphicsContext::Traits traits = new
osg::GraphicsContext::Traits;
traits-windowName = name;
traits-windowDecoration = windowDecoration;
traits-x = x;
traits-y = y;
traits-width = w;
traits-height = h;
traits-doubleBuffer = true;
traits-alpha = ds-getMinimumNumAlphaBits();
traits-stencil = ds-getMinimumNumStencilBits();
traits-sampleBuffers = ds-getMultiSamples();
traits-samples = ds-getNumMultiSamples();

osg::ref_ptrosg::Camera camera = new osg::Camera;
camera-setGraphicsContext( new
osgQt::GraphicsWindowQt(traits.get()) );

camera-setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
camera-setViewport( new osg::Viewport(0, 0, traits-width,
traits-height) );
camera-setProjectionMatrixAsPerspective(
30.0f,
static_castdouble(traits-width)/static_castdouble(traits-height),
1.0f, 1.0f );
return camera.release();
 }



void ViewerWidget::paintEvent( QPaintEvent* event )
{
frame();
}
/
-- 
Thanks  Regards
Sujan
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org