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.
8 require 'plugins/plugin'
9 require 'observer_utils'
11 class SimpleMoveList < Qt::ListView
15 plugin :name => 'Simple Move List',
16 :interface => :movelist
18 class LinearHistoryModel < Qt::StringListModel
24 @history = match.history
25 @serializer = match.game.serializer.new(:compact)
27 @history.add_observer(self)
29 insert_rows(0, @history.size)
30 (0...@history.size).each do |i|
36 if @history.size > rowCount
37 insert_rows(rowCount, @history.size - rowCount)
39 remove_rows(@history.size, rowCount - @history.size)
41 update_row(@history.current)
45 def on_current_changed
46 fire :change_current => index(@history.current, 0)
53 state = @history[i - 1].state
54 move = @history[i].move
55 san = @serializer.serialize(move, state)
64 "#{count}#{dots} #{san}"
69 set_data(index(i, 0), move(i), Qt::DisplayRole)
74 Qt::ItemIsSelectable | Qt::ItemIsEnabled
81 def initialize(controller, opts = {})
82 super(controller.table)
83 @controller = controller
84 self.font = opts[:font] if opts[:font]
86 @controller.table.add_observer(self)
90 if match.game.respond_to?(:serializer)
91 self.model = LinearHistoryModel.new(match)
92 model.observe(:change_current) do |current|
95 sig = 'selectionChanged(QItemSelection, QItemSelection)'
96 selection_model.on(sig) do |selected, deselected|
97 match.history.go_to(selected.indexes.first.row)
100 select(model.index(model.row_count - 1, 0))
107 selection_model.select(index,
108 Qt::ItemSelectionModel::ClearAndSelect)