2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
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"
29 typedef boost::shared_ptr
<class Entry
> EntryPtr
;
30 typedef boost::shared_ptr
<class Brace
> BracePtr
;
31 typedef boost::shared_ptr
<class Text
> TextPtr
;
32 typedef boost::shared_ptr
<class Comment
> CommentPtr
;
33 typedef std::vector
<EntryPtr
> History
;
34 typedef std::map
<int, History
> Variations
;
35 typedef std::map
<int, BracePtr
> Braces
;
36 typedef std::map
<int, CommentPtr
> VComments
;
43 * @class Widget <movelist_widget.h>
44 * @brief The widget can be used to display a tree of moves.
46 * This class is a widget that can be used to display a tree of moves
48 class Widget
: public KGameCanvasWidget
{
51 friend class FancyItem
;
64 int curr_highlight_type
;
67 boost::weak_ptr
<Entry
> edited_comment
;
68 int edited_comment_variation
;
69 class QTextEdit
* comment_editor
;
75 bool layout_goto_selected
;
76 bool layout_width_changed
;
77 bool layout_must_relayout
;
80 QHash
<QString
, QPixmap
> loaded_pixmaps
;
83 PixmapLoader m_loader
;
85 History
* fetchRef(const Index
& ix
, int* idx
= NULL
);
86 EntryPtr
fetch(const Index
& ix
);
88 bool eventFilter(QObject
*obj
, QEvent
*event
);
89 void startEditing(const Index
& ix
, int v
);
93 int layoutHistory(History
& array
, int at_x
, int at_y
, int prev_turn
, int mv_num
,
94 int sub_mv_num
, bool visible
);
96 void fixIndices(const Index
& ix
);
97 void setComment(EntryPtr e
, int v
, const QString
& comment
);
99 QPixmap
getPixmap(const QString
& s
, bool selected
= false);
101 virtual void resizeEvent ( QResizeEvent
* event
);
102 virtual void mouseMoveEvent ( QMouseEvent
* event
);
103 virtual void mousePressEvent ( QMouseEvent
* event
);
104 virtual void mouseReleaseEvent ( QMouseEvent
* event
);
111 Widget(QWidget
*parent
= NULL
, Table
*o
= NULL
);
114 Notifier
* getNotifier();
115 void setNotifier(Notifier
* n
, bool detach_prev
=true);
117 void settingsChanged();
119 void setLoaderBasePath(const QString
& p
){ m_loader
.setBasePath(p
); }
121 /** Clears all the moves */
124 /** returns the style of layout */
125 int layoutStyle(){ return layout_style
; }
127 /** sets the style of layout. 0 mean the the moves are paired, like in chess.
128 any value x>0 will layout the moves in x columns for each player (useful
129 for progressive chess, for instance) */
130 void setLayoutStyle(int x
) {
135 /** Sets the move comment at the given index */
136 void setComment(const Index
& index
, const QString
& comment
);
138 /** Sets the comment at the given index before the give subvariation */
139 void setVComment(const Index
& index
, int v
, const QString
& comment
);
141 /** Sets the move at the given index */
142 void setMove(const Index
& index
, int turn
, const DecoratedMove
& move
,
143 const QString
& comment
= QString());
145 /** Sets the move at the given index */
146 void setMove(const Index
& index
, int turn
, const QString
& move
,
147 const QString
& comment
= QString());
149 /** Removes the given index and all those that come after */
150 void remove(const Index
& index
);
152 /** Promotes the given variation in the main line */
153 void promoteVariation(const Index
& ix
, int v
);
155 /** Sets the currently selected index */
156 void select(const Index
& index
);