summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/ruboids/ruboids/WorldWindow.rb
blob: 56459729371ce9c047216222f116b80783cdc613 (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
#
# Copyright (c) 2001 by Jim Menard <jimm@io.com>
#
# Released under the same license as Ruby. See
# http://www.ruby-lang.org/en/LICENSE.txt.
#

require 'Qt'
require 'Canvas'
require 'CameraDialog'

class WorldWindow < TQt::MainWindow
	slots 'slotMenuActivated(int)'
	
    MENU_CAMERA_DIALOG = 1

    attr_accessor :canvas

    def initialize
	super
	setCaption("Boids")
	setupMenubar()

	@canvas = Canvas.new(self, "TheDamnCanvas")
	setCentralWidget(@canvas)
	setGeometry(0, 0, $PARAMS['window_width'],
		    $PARAMS['window_height'])
    end

    def setupMenubar

	# Create and populate file menu
    menu = TQt::PopupMenu.new(self)
    menu.insertItem("Exit", $qApp, SLOT("quit()"), TQt::KeySequence.new(CTRL+Key_Q))

	# Add file menu to menu bar
	menuBar.insertItem("&File", menu)

	# Create and populate options menu
	menu = TQt::PopupMenu.new(self)
	menu.insertItem("&Camera...", MENU_CAMERA_DIALOG, -1)

	# Add options menu to menu bar and link it to method below
	menuBar.insertItem("&Options", menu)
	connect(menu, SIGNAL("activated(int)"), self, SLOT('slotMenuActivated(int)'))

    end

    def slotMenuActivated(id)
	if id == MENU_CAMERA_DIALOG
	    CameraDialog.new(nil).exec()
	end
    end
end