WQtNavGLWidget.cpp 2.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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.
//
// OpenWalnut 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

25
#include <string>
26
#include <iostream>
27

28 29
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
30
#include <QtGui/QKeyEvent>
31
#include <QtGui/QApplication>
32

33
#include "../../graphicsEngine/WGEViewer.h"
34
#include "../../graphicsEngine/WGEScene.h"
35 36 37 38
#include "events/WPropertyChangedEvent.h"
#include "events/WEventTypes.h"

#include "WQtNavGLWidget.h"
39

40 41 42
WQtNavGLWidget::WQtNavGLWidget( QString title, QWidget* parent, std::string sliderTitle )
    : QDockWidget( title, parent ),
    m_propWidget( NULL )
43
{
44
    m_sliderTitle = QString( sliderTitle.c_str() );
45

46 47 48 49 50
    setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
    setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );

    QWidget* panel = new QWidget( this );

51
    m_layout = new QVBoxLayout();
52

53
    m_glWidget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( title.toStdString(), panel, WGECamera::ORTHOGRAPHIC ) );
54
    m_glWidget->setFixedSize( 150, 150 );
55
    m_glWidget->initialize();
56

57
    setMinimumSize( 160, 240 );
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
58
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
59

60
    m_scene = new WGEScene();
61
    m_scene->setDataVariance( osg::Object::DYNAMIC );
62
    m_glWidget->getViewer()->getView()->requestContinuousUpdate( false );
63
    m_glWidget->getViewer()->setScene( m_scene );
64

65
    m_layout->addWidget( m_glWidget.get() );
66

67
    panel->setLayout( m_layout );
68 69 70 71 72 73

    setWidget( panel );
}

WQtNavGLWidget::~WQtNavGLWidget()
{
74
    if ( m_propWidget )
75
    {
76
        delete m_propWidget;
77
    }
78 79
}

80 81 82 83 84 85 86 87
void WQtNavGLWidget::closeEvent( QCloseEvent* event )
{
    // forward events
    m_glWidget->close();

    event->accept();
}

88
void WQtNavGLWidget::setSliderTitle( std::string title )
89
{
90
    m_sliderTitle = QString( title.c_str() );
91 92
}

93
boost::shared_ptr<WQtGLWidget>WQtNavGLWidget::getGLWidget()
94
{
95
    return m_glWidget;
96 97
}

98 99
void WQtNavGLWidget::setSliderProperty( WPropInt prop )
{
100 101
    m_propWidget = new WPropertyIntWidget( prop, NULL, parentWidget() );
    m_layout->addWidget( m_propWidget );
102 103
}