=begin
/****************************************************************************
** $Id: qt/extensions/opengl/examples/texture/globjwin.cpp   2.1.0-beta3   edited 2000-01-31 $
**
** Implementation of GLObjectWindow widget class
**
****************************************************************************/
=end
require "qt2"
include Qt2
require "gltexobj.rb"

ToggleAnimation = 1

class GLObjectWindow < QWidget

def initialize


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

    #// Create an OpenGL widget
    @c = GLTexobj.new( f1, "glbox1")

    #// Create a menu
    #file = QPopupMenu.new( self )
    file = QPopupMenu.new()
    file.insertItem( "Toggle Animation", ToggleAnimation) 
#c, SLOT(toggleAnimation()),
		      #CTRL+Key_A )
    file.insertSeparator()
    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 )
    
    Qt::connect(m,QSIGNAL("activated(int)"),self,"menuActivated")

    #// Create the three sliders one for each rotation axis
    x = QSlider.new ( 0, 360, 60, 0, QSlider::Vertical, self, "xsl" )
    x.setTickmarks( QSlider::Left )
    x.setMinimumSize(x.sizeHint())
    Qt::connect( x, QSIGNAL("valueChanged(int)"), @c, "setXRotation" )

    y = QSlider.new ( 0, 360, 60, 0, QSlider::Vertical, self, "ysl" )
    y.setTickmarks( QSlider::Left )
    y.setMinimumSize(y.sizeHint())
    Qt::connect( y, QSIGNAL("valueChanged(int)"), @c, "setYRotation" )

    z = QSlider.new ( 0, 360, 60, 0, QSlider::Vertical, self, "zsl" )
    z.setTickmarks( QSlider::Left )
    z.setMinimumSize(z.sizeHint())
    Qt::connect( z, QSIGNAL("valueChanged(int)"), @c, "setZRotation" )


    #// Now that we have all the widgets, put them into a nice layout
    #// Top level layout, puts the sliders to the left of the frame/GL widget
    hlayout = QHBoxLayout.new( self, 20, 20, "hlayout")
    hlayout.setMenuBar( m )

    #// Put the sliders on top of each other
    vlayout = QVBoxLayout.new( nil,20,20, "vlayout")
    hlayout.addLayout( vlayout )
    hlayout.addWidget( f1, 1 )
    #// Put the GL widget inside the frame
    flayout1 = QHBoxLayout.new( f1, 2, 2, "flayout1")
    flayout1.addWidget( @c, 1 )
    flayout1.activate()

    vlayout.addWidget( x )
    vlayout.addWidget( y )
    vlayout.addWidget( z )

    hlayout.activate()
end
def menuActivated id
print "menuAcitvated\n"
print "id = #{id}\n"
    case id
    when ToggleAnimation
       @c.toggleAnimation
    end
end

end
