Added real animations to the Shogi animator.
[tagua.git] / src / movelist_widget.h
blobbd40e5413334d07d328194af6de62c643b8ebc2c
1 /*
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.
9 */
11 #ifndef MOVELISTWIDGET_H
12 #define MOVELISTWIDGET_H
14 #include <map>
15 #include <vector>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/weak_ptr.hpp>
18 #include <QWidget>
19 #include <QHash>
20 #include <map>
21 #include <vector>
22 #include "index.h"
23 #include "decoratedmove.h"
24 #include "pixmaploader.h"
25 #include "kgamecanvas.h"
27 namespace MoveList {
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;
38 class Notifier;
39 class Table;
40 class Settings;
42 /**
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 {
49 private:
50 Q_OBJECT
51 friend class FancyItem;
52 friend class Entry;
53 friend class Brace;
54 friend class Text;
55 friend class Comment;
57 friend class Table;
59 History history;
61 int entry_size;
63 Index curr_highlight;
64 int curr_highlight_type;
65 Index curr_selected;
67 boost::weak_ptr<Entry> edited_comment;
68 int edited_comment_variation;
69 class QTextEdit* comment_editor;
71 int layout_max_width;
72 bool layout_pending;
73 int layout_style;
74 int layout_time;
75 bool layout_goto_selected;
76 bool layout_width_changed;
77 bool layout_must_relayout;
79 Notifier *notifier;
80 QHash<QString, QPixmap> loaded_pixmaps;
81 Table *owner_table;
82 Settings *m_settings;
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);
90 void stopEditing();
92 void layout();
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 );
107 private slots:
108 void doLayout();
110 public:
111 Widget(QWidget *parent = NULL, Table *o = NULL);
112 virtual ~Widget();
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 */
122 void reset();
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) {
131 layout_style = x;
132 layout();
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);
159 } //end namespace
161 #endif