1 require 'plugins/plugin'
2 require 'observer_utils'
4 class SimpleMoveList < Qt::ListView
8 plugin :name => 'Simple Move List',
9 :interface => :movelist
11 class LinearHistoryModel < Qt::StringListModel
17 @history = match.history
18 @serializer = match.game.serializer.new(:compact)
20 @history.add_observer(self)
22 insert_rows(0, @history.size)
23 (0...@history.size).each do |i|
29 if @history.size > rowCount
30 insert_rows(rowCount, @history.size - rowCount)
32 remove_rows(@history.size, rowCount - @history.size)
34 update_row(@history.current)
38 def on_current_changed
39 fire :change_current => index(@history.current, 0)
46 state = @history[i - 1].state
47 move = @history[i].move
48 san = @serializer.serialize(move, state)
57 "#{count}#{dots} #{san}"
62 set_data(index(i, 0), move(i), Qt::DisplayRole)
67 Qt::ItemIsSelectable | Qt::ItemIsEnabled
74 def initialize(controller, opts = {})
75 super(controller.table)
76 @controller = controller
77 self.font = opts[:font] if opts[:font]
79 @controller.table.add_observer(self)
83 if match.game.respond_to?(:serializer)
84 self.model = LinearHistoryModel.new(match)
85 model.observe(:change_current) do |current|
88 sig = 'selectionChanged(QItemSelection, QItemSelection)'
89 selection_model.on(sig) do |selected, deselected|
90 match.history.go_to(selected.indexes.first.row)
93 select(model.index(model.row_count - 1, 0))
100 selection_model.select(index,
101 Qt::ItemSelectionModel::ClearAndSelect)