Fix navigation and highlighting.
[kaya.git] / lib / mainwindow.rb
blob70aea68e8790a3183047db5f63b032cf7ecd6825
1 require 'qtutils'
2 require 'board/board'
3 require 'board/table'
4 require 'history'
5 require 'controller'
7 class MainWindow < KDE::XmlGuiWindow
8   include ActionHandler
9   
10   Theme = Struct.new(:pieces, :board)
11   
12   def initialize(loader, game)
13     super nil
14     
15     @loader = loader
16     
17     load_board(game)
18     
19     setup_actions
20     setupGUI
21   end
23 private
25   def setup_actions
26     std_action :open_new do
27       puts "new game"
28     end
29     std_action :quit, :close
30   end
31   
32   def load_board(game)
33     config = KDE::Global.config.group('themes')
34     
35     theme = Theme.new
36     theme.pieces = @loader.get_matching('Celtic', game,
37       (game.keywords || []) + ['pieces'], [], :shadow => true)
38     theme.board = @loader.get_matching(nil, game,
39       ['board'], game.keywords || [])
40     
41     scene = Qt::GraphicsScene.new
42     
43     state = game.state.new.tap {|s| s.setup }
44     
45     board = Board.new(scene, theme, game, state)
46     
47     table = Table.new(scene, self, board)
48     self.central_widget = table
50     history = History.new(state)
51     controller = Controller.new(board, history)
52   end
53 end