1 require 'plugins/plugin'
3 class SimpleMoveList < Qt::ListView
7 plugin :name => 'Simple Move List',
8 :keywords => %w(movelist)
10 class LinearHistoryModel < Qt::StringListModel
16 @history = match.history
17 @serializer = match.game.serializer.new(:compact)
19 @history.add_observer(self)
21 insert_rows(0, @history.size)
22 (0...@history.size).each do |i|
28 if @history.size > rowCount
29 insert_rows(rowCount, @history.size - rowCount)
31 remove_rows(@history.size, rowCount - @history.size)
33 update_row(@history.current)
37 def on_current_changed
38 fire :change_current => index(@history.current, 0)
45 state = @history[i - 1].state
46 move = @history[i].move
47 san = @serializer.serialize(move, state)
56 "#{count}#{dots} #{san}"
61 set_data(index(i, 0), move(i), Qt::DisplayRole)
66 Qt::ItemIsSelectable | Qt::ItemIsEnabled
73 def initialize(controller, opts = {})
74 super(controller.table)
75 @controller = controller
76 self.font = opts[:font] if opts[:font]
78 @controller.table.add_observer(self)
82 if match.game.respond_to?(:serializer)
83 self.model = LinearHistoryModel.new(match)
84 model.observe(:change_current) do |current|
85 selection_model.select(current,
86 Qt::ItemSelectionModel::ClearAndSelect)
88 sig = 'selectionChanged(QItemSelection, QItemSelection)'
89 selection_model.on(sig) do |selected, deselected|
90 @controller.go_to(selected.indexes.first.row)