Fixed pool update.
[tagua/yd.git] / src / clock.h
blobea3deda190a842f56f0850f797c4d06ebef44441
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 CLOCK_H
12 #define CLOCK_H
14 #include <QPixmap>
15 #include <QTimer>
16 #include <QTime>
17 #include "kgamecanvas.h"
18 #include "player.h"
19 #include "pixmaploader.h"
20 #include "clickablecanvas.h"
23 class ConstrainedText;
25 class Clock : public QObject, public ClickableCanvas {
26 Q_OBJECT
28 int m_color;
29 QTimer m_timer;
30 QTime m_time;
31 int m_total_time;
33 bool m_running;
34 bool m_active;
36 KGameCanvasPixmap* m_background;
37 ConstrainedText* m_caption;
38 ConstrainedText* m_time_label;
39 ConstrainedText* m_player_name;
40 ConstrainedText* m_decs;
42 QPixmap m_active_pixmap;
43 QPixmap m_inactive_pixmap;
45 QColor m_active_text;
46 QColor m_inactive_text;
48 int m_height;
51 /** the @a PixmapLoader used for controls */
52 PixmapLoader m_controls_loader;
55 void computeTime();
56 static QString playerString(const Player& player);
58 public:
59 Clock(int col, KGameCanvasAbstract* canvas);
60 ~Clock();
62 /** returns a reference to the loader used to load controls pixmaps */
63 PixmapLoader* controlsLoader() { return &m_controls_loader; }
65 bool running() { return m_running; }
66 void start();
67 void stop();
68 bool active() { return m_active; }
69 void activate(bool);
71 void setPlayer(const Player& p);
72 void setTime(int t);
74 virtual void onMousePress(const QPoint& pos, int button);
75 virtual void onMouseRelease(const QPoint& /*pos*/, int /*button*/) { }
76 virtual void onMouseMove(const QPoint& /*pos*/, int /*button*/) { }
78 void resize(int size);
79 int height() { return m_height; }
80 void settingsChanged();
82 private slots:
83 void tick();
85 signals:
86 void labelClicked(int);
90 #if 1-1
92 class Clock : public QObject, public ClickableCanvas {
93 Q_OBJECT
95 /**
96 * Structure containing information for a player.
98 class Info : public KGameCanvasGroup {
99 Player m_player;
100 QTime m_time;
101 bool m_running;
102 int m_total_time;
103 KGameCanvasRectangle* m_background;
104 KGameCanvasRectangle* m_frame[4];
105 KGameCanvasText* m_caption;
106 KGameCanvasText* m_time_label;
107 KGameCanvasText* m_player_name;
108 KGameCanvasText* m_decs;
109 QRect m_rect;
111 void computeTime() const;
112 void update();
113 public:
114 Info()
115 : m_player(QString(), 0)
116 , m_running(false)
117 , m_rect(0, 0, 0, 0) { }
119 void setup(const Player& player, const QRect& p,
120 const QString& caption, KGameCanvasAbstract* canvas);
121 void setTime(int);
122 void start();
123 void stop();
124 void activate(bool);
125 void tick();
127 QString playerString(const Player& player) const;
128 void setPlayer(const Player& player);
130 void resize(const QRect& rect);
131 void reload();
132 QRect eventRect() const;
134 /** changed settings handler */
135 virtual void settingsChanged();
138 Info m_info[2];
139 QTimer m_timer;
140 int m_running;
141 int m_active;
142 public:
143 Clock(KGameCanvasAbstract* parent);
145 void setTime(int index, int value);
146 void start(int index);
147 void stop();
148 void activate(int index);
150 void setPlayers(const Player& white, const Player& black);
152 bool running() const { return m_running != -1; }
153 void resize(QSize size);
154 void reload();
156 virtual void onMousePress(const QPoint& pos, int button);
157 virtual void onMouseRelease(const QPoint& /*pos*/, int /*button*/) { }
158 virtual void onMouseMove(const QPoint& /*pos*/, int /*button*/) { }
160 /** changed settings handler */
161 virtual void settingsChanged();
162 private slots:
163 void tick();
164 signals:
165 void labelClicked(int);
168 #endif
170 #endif // CLOCK_H