2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #ifndef MOVELISTWIDGET_H
12 #define MOVELISTWIDGET_H
16 #include <boost/shared_ptr.hpp>
17 #include <boost/weak_ptr.hpp>
23 #include "decoratedmove.h"
24 #include "pixmaploader.h"
25 #include "kgamecanvas.h"
31 typedef boost::shared_ptr
<class Entry
> EntryPtr
;
32 typedef boost::shared_ptr
<class Brace
> BracePtr
;
33 typedef boost::shared_ptr
<class Text
> TextPtr
;
34 typedef boost::shared_ptr
<class Comment
> CommentPtr
;
35 typedef std::vector
<EntryPtr
> History
;
36 typedef std::map
<int, History
> Variations
;
37 typedef std::map
<int, BracePtr
> Braces
;
38 typedef std::map
<int, CommentPtr
> VComments
;
45 * @class Widget <movelist_widget.h>
46 * @brief The widget can be used to display a tree of moves.
48 * This class is a widget that can be used to display a tree of moves
50 class Widget
: public KGameCanvasWidget
{
53 friend class FancyItem
;
66 int curr_highlight_type
;
69 boost::weak_ptr
<Entry
> edited_comment
;
70 int edited_comment_variation
;
71 class QTextEdit
* comment_editor
;
77 bool layout_goto_selected
;
78 bool layout_width_changed
;
79 bool layout_must_relayout
;
82 QHash
<QString
, QPixmap
> loaded_pixmaps
;
85 PixmapLoader m_loader
;
87 History
* fetchRef(const Index
& ix
, int* idx
= NULL
);
88 EntryPtr
fetch(const Index
& ix
);
90 bool eventFilter(QObject
*obj
, QEvent
*event
);
91 void startEditing(const Index
& ix
, int v
);
95 int layoutHistory(History
& array
, int at_x
, int at_y
, int prev_turn
, int mv_num
,
96 int sub_mv_num
, bool visible
);
98 void fixIndices(const Index
& ix
);
99 void setComment(EntryPtr e
, int v
, const QString
& comment
);
101 QPixmap
getPixmap(const QString
& s
, bool selected
= false);
103 virtual void resizeEvent ( QResizeEvent
* event
);
104 virtual void mouseMoveEvent ( QMouseEvent
* event
);
105 virtual void mousePressEvent ( QMouseEvent
* event
);
106 virtual void mouseReleaseEvent ( QMouseEvent
* event
);
113 Widget(QWidget
*parent
= NULL
, Table
*o
= NULL
);
116 Notifier
* getNotifier();
117 void setNotifier(Notifier
* n
, bool detach_prev
=true);
119 void settingsChanged();
121 void setLoaderTheme(const ThemeInfo
& theme
);
123 /** Clears all the moves */
126 /** returns the style of layout */
127 int layoutStyle(){ return layout_style
; }
129 /** sets the style of layout. 0 mean the the moves are paired, like in chess.
130 any value x>0 will layout the moves in x columns for each player (useful
131 for progressive chess, for instance) */
132 void setLayoutStyle(int x
) {
137 /** Sets the move comment at the given index */
138 void setComment(const Index
& index
, const QString
& comment
);
140 /** Sets the comment at the given index before the give subvariation */
141 void setVComment(const Index
& index
, int v
, const QString
& comment
);
143 /** Sets the move at the given index */
144 void setMove(const Index
& index
, int turn
, const DecoratedMove
& move
,
145 const QString
& comment
= QString());
147 /** Sets the move at the given index */
148 void setMove(const Index
& index
, int turn
, const QString
& move
,
149 const QString
& comment
= QString());
151 /** Removes the given index and all those that come after */
152 void remove(const Index
& index
);
154 /** Promotes the given variation in the main line */
155 void promoteVariation(const Index
& ix
, int v
);
157 /** Sets the currently selected index */
158 void select(const Index
& index
);