1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
9 require 'plugins/plugin'
10 require 'observer_utils'
12 class SimpleMoveList < Qt::ListView
16 plugin :name => 'Simple Move List',
17 :interface => :movelist
19 class LinearHistoryModel < Qt::StringListModel
25 @history = match.history
26 @serializer = match.game.serializer.new(:compact)
28 @history.add_observer(self)
30 insert_rows(0, @history.size)
31 (0...@history.size).each do |i|
37 if @history.size > rowCount
38 insert_rows(rowCount, @history.size - rowCount)
40 remove_rows(@history.size, rowCount - @history.size)
42 update_row(@history.current)
46 def on_current_changed
47 fire :change_current => index(@history.current, 0)
54 state = @history[i - 1].state
55 move = @history[i].move
56 san = @serializer.serialize(move, state)
65 "#{count}#{dots} #{san}"
70 set_data(index(i, 0), move(i), Qt::DisplayRole)
75 Qt::ItemIsSelectable | Qt::ItemIsEnabled
82 def initialize(controller, opts = {})
83 super(controller.table)
84 @controller = controller
85 self.font = opts[:font] if opts[:font]
87 @controller.table.add_observer(self)
91 if match.game.respond_to?(:serializer)
92 self.model = LinearHistoryModel.new(match)
93 model.observe(:change_current) do |current|
96 sig = 'selectionChanged(QItemSelection, QItemSelection)'
97 selection_model.on(sig) do |selected, deselected|
98 match.history.go_to(selected.indexes.first.row)
101 select(model.index(model.row_count - 1, 0))
108 selection_model.select(index,
109 Qt::ItemSelectionModel::ClearAndSelect)