Commit 41d51fb8 authored by Jan Möbius's avatar Jan Möbius

Dennis: Initial version of a simple examiner widget.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6661 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0ae97767
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5979 $
// $Author: moebius $
// $Date: 2009-05-07 10:57:06 +0200 (Do, 07. Mai 2009) $
//
//=============================================================================
//=============================================================================
//
// CLASS SimpleGLGraphicsScene - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <QApplication>
#include <QPainter>
#include <QPaintEngine>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneDragDropEvent>
#include "simpleGLGraphicsScene.hh"
//== NAMESPACES ===============================================================
//== IMPLEMENTATION ===========================================================
SimpleGLGraphicsScene::SimpleGLGraphicsScene () :
QGraphicsScene (),
view_(),
initialized_(false)
{
}
void SimpleGLGraphicsScene::drawBackground(QPainter *_painter, const QRectF &_rect)
{
if (_painter->paintEngine()->type() != QPaintEngine::OpenGL) {
std::cerr << "SimpleGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
return;
}
if (!view_)
return;
if (!initialized_)
{
// we use GLEW to manage extensions
// initialize it first
glewInit();
view_->initializeGL();
initialized_ = true;
}
_painter->setBackground(QApplication::palette().window());
_painter->eraseRect(_rect);
view_->paintGL();
}
void SimpleGLGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* _e)
{
QGraphicsScene::mouseMoveEvent(_e);
if (_e->isAccepted())
return;
if (view_)
view_->mouseMoveEvent(_e);
}
void SimpleGLGraphicsScene::setView(glViewer * _view)
{
view_ = _view;
}
//=============================================================================
//=============================================================================
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5979 $
// $Author: moebius $
// $Date: 2009-05-07 10:57:06 +0200 (Do, 07. Mai 2009) $
//
//=============================================================================
#ifndef SIMPLEGLGRAPHICSSCENE_HH
#define SIMPLEGLGRAPHICSSCENE_HH
//=============================================================================
//
// CLASS SimpleGLGraphicsScene - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <OpenFlipper/common/GlobalDefines.hh>
#include <QGraphicsScene>
#include <QGraphicsItem>
//== FORWARDDECLARATIONS ======================================================
class glViewer;
//== NAMESPACES ===============================================================
//== CLASS DEFINITION =========================================================
/** OpenGL drawing area and widget scene -- for \a internal use only.
The scene basically redirects calls to a
ACG::QtWidgets::glViewer, the corresponding virtual methods there
are prefixed with \c gl.
\sa ACG::QtWidgets::glViewer
*/
class DLLEXPORT SimpleGLGraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
SimpleGLGraphicsScene();
void setView (glViewer *_view);
protected:
virtual void drawBackground(QPainter *_painter, const QRectF &_rect);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* _e);
private:
glViewer *view_;
bool initialized_;
};
#endif
//=============================================================================
//=============================================================================
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5162 $
// $Author: moebius $
// $Date: 2009-02-27 17:40:45 +0100 (Fr, 27. Feb 2009) $
//
//=============================================================================
//=============================================================================
//
// CLASS SimpleViewer - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include "simpleGLGraphicsScene.hh"
#include "simpleViewer.hh"
//== NAMESPACES ===============================================================
//== CLASS DEFINITION =========================================================
SimpleViewer::SimpleViewer(QWidget* _parent) :
QGraphicsView (_parent),
actionMode_ (Viewer::ExamineMode)
{
QGLWidget *share = PluginFunctions::shareGLWidget ();
if (!share)
initialize (QGLFormat::defaultFormat (), 0);
else
initialize (share->format(), share);
}
SimpleViewer::~SimpleViewer()
{
}
void SimpleViewer::resizeEvent(QResizeEvent *_event) {
QGraphicsView::resizeEvent(_event);
if (scene())
{
scene()->setSceneRect(QRect(QPoint(0, 0), _event->size()));
mainWidget_->setGeometry (QRect(QPoint(0, 0), _event->size()));
}
}
//=============================================================================
//=============================================================================
void SimpleViewer::initialize (const QGLFormat & _format, QGLWidget *_shareWidget)
{
connect (&props_, SIGNAL( getPickMode(std::string&) ),
this, SLOT( getPickMode(std::string&) ),Qt::DirectConnection );
connect (&props_, SIGNAL( getActionMode(Viewer::ActionMode&) ),
this, SLOT( getActionMode(Viewer::ActionMode&) ),Qt::DirectConnection );
connect (&props_, SIGNAL( setActionMode(const Viewer::ActionMode) ),
this, SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection );
glWidget_ = new QGLWidget (_format, 0, _shareWidget);
setFocusPolicy (Qt::StrongFocus);
setAcceptDrops (true);
setViewport(glWidget_);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
scene_ = new SimpleGLGraphicsScene ();
setScene (scene_);
mainWidget_ = new glViewer (scene_, glWidget_, props_);
scene_->addItem (mainWidget_);
scene_->setView (mainWidget_);
mainWidget_->setGeometry (QRect(QPoint(0, 0), size()));
mainWidget_->sceneGraph (PluginFunctions::getSceneGraphRootNode (), true);
props_.drawMode (OpenFlipper::Options::standardDrawMode());
}
void SimpleViewer::setActionMode(const Viewer::ActionMode _am)
{
actionMode_ = _am;
}
void SimpleViewer::getActionMode(Viewer::ActionMode & _am)
{
_am = actionMode_;
}
void SimpleViewer::getPickMode(std::string & _name)
{
_name = "SimpleViewer";
}
Viewer::ViewerProperties & SimpleViewer::properties()
{
return props_;
}
glViewer * SimpleViewer::viewer()
{
return mainWidget_;
}
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5162 $
// $Author: moebius $
// $Date: 2009-02-27 17:40:45 +0100 (Fr, 27. Feb 2009) $
//
//=============================================================================
#ifndef SIMPLEVIEWER_HH
#define SIMPLEVIEWER_HH
//=============================================================================
//
// CLASS simpleViewer - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <OpenFlipper/common/ViewerProperties.hh>
#include <OpenFlipper/common/GlobalDefines.hh>
#include <QGraphicsView>
#include <QGLFormat>
//== NAMESPACES ===============================================================
//== FORWARDDECLARATIONS ======================================================
class SimpleGLGraphicsScene;
class glViewer;
//== CLASS DEFINITION =========================================================
/** simple scene graph viewer
*/
class DLLEXPORT SimpleViewer : public QGraphicsView
{
Q_OBJECT
public:
/// Constructor
SimpleViewer(QWidget* _parent = NULL);
/// Destructor
~SimpleViewer();
/// Viewer properties
Viewer::ViewerProperties& properties ();
/// Viewer
glViewer * viewer ();
protected:
// handle resizes
virtual void resizeEvent(QResizeEvent *_event);
private:
// initalisation
void initialize (const QGLFormat &_format, QGLWidget *_shareWidget = NULL);
private slots:
// action mode handling for ViewerProperties
void setActionMode(const Viewer::ActionMode _am);
void getActionMode(Viewer::ActionMode& _am);
// pick mode name handling for ViewerProperties
void getPickMode(std::string& _name);
private:
QGLWidget *glWidget_;
Viewer::ViewerProperties props_;
SimpleGLGraphicsScene *scene_;
glViewer *mainWidget_;
Viewer::ActionMode actionMode_;
};
//=============================================================================
//=============================================================================
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment