Tentative Randomless-Entropy variant.
[tagua/yd.git] / src / movelist_widget.h
blobf810816dcc65880ff013f1252cc2ae96dadc279e
1 /*
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.
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 class ThemeInfo;
29 namespace MoveList {
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;
40 class Notifier;
41 class Table;
42 class Settings;
44 /**
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 {
51 private:
52 Q_OBJECT
53 friend class FancyItem;
54 friend class Entry;
55 friend class Brace;
56 friend class Text;
57 friend class Comment;
59 friend class Table;
61 History history;
63 int entry_size;
65 Index curr_highlight;
66 int curr_highlight_type;
67 Index curr_selected;
69 boost::weak_ptr<Entry> edited_comment;
70 int edited_comment_variation;
71 class QTextEdit* comment_editor;
73 int layout_max_width;
74 bool layout_pending;
75 int layout_style;
76 int layout_time;
77 bool layout_goto_selected;
78 bool layout_width_changed;
79 bool layout_must_relayout;
81 Notifier *notifier;
82 QHash<QString, QPixmap> loaded_pixmaps;
83 Table *owner_table;
84 Settings *m_settings;
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);
92 void stopEditing();
94 void layout();
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 );
109 private Q_SLOTS:
110 void doLayout();
112 public:
113 Widget(QWidget *parent = NULL, Table *o = NULL);
114 virtual ~Widget();
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 */
124 void reset();
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) {
133 layout_style = x;
134 layout();
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);
161 } //end namespace
163 #endif