summaryrefslogtreecommitdiffstats
path: root/PerlQt/examples/opengl/box/glbox
blob: 613a2740c9d56cfa48ea0a337338e783403e9522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

package GLObjectWindow;

use strict;

use Qt;
use Qt::isa qw(Qt::Widget);          
use Qt::attributes qw(
    file
    frame
    menu
    box
    xpos
    ypos
    zpos
);

use GLBox;

sub NEW
{
    shift->SUPER::NEW(@_);

    # Create a menu
    file = Qt::PopupMenu( this );
    file->insertItem( "Exit",  Qt::app(), SLOT 'quit()', Qt::KeySequence(int &CTRL + &Key_Q ));

    # Create a menu bar
    menu = Qt::MenuBar( this );
    menu->setSeparator( &Qt::MenuBar::InWindowsStyle );
    menu->insertItem("&File", file );

    # Create a nice frame to put around the OpenGL widget
    frame = Qt::Frame( this, "frame" );
    frame->setFrameStyle( &Qt::Frame::Sunken | &Qt::Frame::Panel );
    frame->setLineWidth( 2 );

    # Create our OpenGL widget
    box = GLBox( frame, "glbox");

    # Create the three sliders; one for each rotation axis
    xpos = Qt::Slider ( 0, 360, 60, 0, &Qt::Slider::Vertical, this, "xsl" );
    xpos->setTickmarks( &Qt::Slider::Left );
    Qt::Object::connect( xpos, SIGNAL 'valueChanged(int)', box, SLOT 'setXRotation(int)' );

    ypos = Qt::Slider ( 0, 360, 60, 0, &Qt::Slider::Vertical, this, "ysl" );
    ypos->setTickmarks( &Qt::Slider::Left );
    Qt::Object::connect( ypos, SIGNAL 'valueChanged(int)', box, SLOT 'setYRotation(int)' );

    zpos = Qt::Slider ( 0, 360, 60, 0, &Qt::Slider::Vertical, this, "zsl" );
    zpos->setTickmarks( &Qt::Slider::Left );
    Qt::Object::connect( zpos, SIGNAL 'valueChanged(int)', box, SLOT 'setZRotation(int)' );


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

    # Put the sliders on top of each other
    my $vlayout = Qt::VBoxLayout( 20, "vlayout");
    $vlayout->addWidget( xpos );
    $vlayout->addWidget( ypos );
    $vlayout->addWidget( zpos );

    # Put the GL widget inside the frame
    my $flayout = Qt::HBoxLayout( frame, 2, 2, "flayout");
    $flayout->addWidget( box, 1 );

    # Top level layout, puts the sliders to the left of the frame/GL widget
    my $hlayout = Qt::HBoxLayout( this, 20, 20, "hlayout");
    $hlayout->setMenuBar( menu );
    $hlayout->addLayout( $vlayout );
    $hlayout->addWidget( frame, 1 );
}

1;

package main;

use Qt;
use GLObjectWindow;

my $a = Qt::Application(\@ARGV);

my $w = GLObjectWindow;
$w->resize(350,350);
$w->show;

$a->setMainWidget( $w);

exit $a->exec;