=begin
/****************************************************************************
** $Id: qt/examples/sharedbox/globjwin.cpp   2.2.2   edited 2000-08-31 $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
=end
#include <qpushbutton.h>
#include <qslider.h>
#include <qlayout.h>
#include <qframe.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qapplication.h>
#include <qkeycode.h>
#include "globjwin.h"
#include "glbox.h"
require "qt2"
include Qt2
require "opengl"
include GL
require "qt2gl"
include Qt2gl

class GLObjectWindow < QWidget
def initialize(  parent=nil,  name="" )
    super( parent, name )

    #// Create a menu
    file = QPopupMenu.new( self )
    file.insertItem( "Delete Left QGLWidget", self, 
		      "deleteFirstWidget()" )
    file.insertItem( "Exit",  QApplication::qApp, "quit()", CTRL+Key_Q )

    #// Create a menu bar
    m = QMenuBar.new( self )
    m.setSeparator( QMenuBar::InWindowsStyle )
    m.insertItem("&File", file )

    #// Create nice frames to put around the OpenGL widgets
    f1 = QFrame.new( self, "frame1" )
    f1.setFrameStyle( QFrame::Sunken | QFrame::Panel )
    f1.setLineWidth( 2 )
    f2 = QFrame.new( self, "frame2" )
    f2.setFrameStyle( QFrame::Sunken | QFrame::Panel )
    f2.setLineWidth( 2 )

    #// Create an OpenGL widget
    @c1 = GLBox.new( f1, "glbox1" )
    
    #// Create another OpenGL widget that shares display lists with the first
    @c2 = GLBox.new( f2, "glbox2", @c1 )

    #// Create the three sliders one for each rotation axis
    #// Make them spin the boxes, but not in synch
    x = QSlider.new ( 0, 360, 60, 0, QSlider::Vertical, self, "xsl" )
    x.setTickmarks( QSlider::Left )
    connect( x, QSIGNAL("valueChanged(int)"), @c1, "setXRotation(int)" )
    connect( x, QSIGNAL("valueChanged(int)"), @c2, "setZRotation(int)" )

    y = QSlider.new ( 0, 360, 60, 0, QSlider::Vertical, self, "ysl" )
    y.setTickmarks( QSlider::Left )
    connect( y, QSIGNAL("valueChanged(int)"), @c1, "setYRotation(int)" )
    connect( y, QSIGNAL("valueChanged(int)"), @c2, "setXRotation(int)" )

    z = QSlider.new ( 0, 360, 60, 0, QSlider::Vertical, self, "zsl" )
    z.setTickmarks( QSlider::Left )
    connect( z, QSIGNAL("valueChanged(int)"), @c1, "setZRotation(int)")
    connect( z, QSIGNAL("valueChanged(int)"), @c2, "setYRotation(int)")


    #// Now that we have all the widgets, put them into a nice layout

    #// Put the sliders on top of each other
    vlayout = QVBoxLayout.new( 20, "vlayout")
    vlayout.addWidget( x )
    vlayout.addWidget( y )
    vlayout.addWidget( z )

    #// Put the GL widgets inside the frames
    flayout1 = QHBoxLayout.new( f1, 2, 2, "flayout1")
    flayout1.addWidget( @c1, 1 )
    flayout2 =  QHBoxLayout.new( f2, 2, 2, "flayout2")
    flayout2.addWidget( @c2, 1 )

    #// Top level layout, puts the sliders to the left of the frame/GL widget
     hlayout = QHBoxLayout.new( self, 20, 20, "hlayout")
    hlayout.setMenuBar( m )
    hlayout.addLayout( vlayout )
    hlayout.addWidget( f1, 1 )
    hlayout.addWidget( f2, 1 )

end


def deleteFirstWidget()

    #// Delete only c1 c2 will keep working and use the shared display list
    if ( @c1 != nil )
             @c1.finalize
	deleteQObj @c1
	@c1 = GLBox.new
    end
end
end
