SVN_SILENT made messages (.desktop file)
[kdegames.git] / kolf / game.h
blobfd34ff3643e5f77b1ab983e5b577bc1a63b87f0e
1 #ifndef GAME_H
2 #define GAME_H
4 //#define SOUND
6 #include <kdebug.h>
7 #include <klocale.h>
8 #include <KConfigGroup>
10 #include <math.h>
12 #include <QMap>
13 #include <QPoint>
14 #include <QRect>
15 #include <QPixmap>
16 #include <QKeyEvent>
17 #include <QGraphicsScene>
19 #include "object.h"
20 #include "config.h"
21 #include "kconfiggroup.h"
22 #include "canvasitem.h"
23 #include "ball.h"
24 #include "statedb.h"
25 #include "rtti.h"
26 #include <kolflib_export.h>
27 #include "kolfsvgrenderer.h"
29 class QLabel;
30 class QSlider;
31 class QCheckBox;
32 class QTimer;
33 class QKeyEvent;
34 class QMouseEvent;
35 class QResizeEvent;
36 class QVBoxLayout;
37 class QPainter;
38 class QPrinter;
39 class KConfig;
40 class KolfGame;
42 namespace Phonon
44 class MediaObject;
47 enum Direction { D_Left, D_Right, Forwards, Backwards };
48 enum Amount { Amount_Less, Amount_Normal, Amount_More };
49 enum HoleResult { Result_Holed, Result_Miss, Result_LipOut };
51 class BallStateInfo
53 public:
54 void saveState(KConfigGroup *cfgGroup);
55 void loadState(KConfigGroup *cfgGroup);
57 int id;
58 QPoint spot;
59 BallState state;
60 bool beginningOfHole;
61 int score;
63 class BallStateList : public QList<BallStateInfo>
65 public:
66 int hole;
67 int player;
68 bool canUndo;
69 Vector vector;
72 class Player
74 public:
75 Player() : m_ball(new Ball(0)) {}
76 Ball *ball() const { return m_ball; }
77 void setBall(Ball *ball) { m_ball = ball; }
78 BallStateInfo stateInfo(int hole) const { BallStateInfo ret; ret.spot = QPoint((int)m_ball->getBaseX(), (int)m_ball->getBaseY()); ret.state = m_ball->curState(); ret.score = score(hole); ret.beginningOfHole = m_ball->beginningOfHole(); ret.id = m_id; return ret; }
80 QList<int> scores() const { return m_scores; }
81 void setScores(const QList<int> &newScores) { m_scores = newScores; }
82 int score(int hole) const { return m_scores.at(hole - 1); }
83 int lastScore() const { return m_scores.last(); }
84 int firstScore() const { return m_scores.first(); }
86 void addStrokeToHole(int hole) { (*(m_scores.begin() + (hole -1)))++; }
87 void setScoreForHole(int score, int hole) { (*(m_scores.begin() + (hole - 1))) = score; }
88 void subtractStrokeFromHole(int hole) { (*(m_scores.begin() + (hole -1))--); }
89 void resetScore(int hole) { (*(m_scores.begin() + (hole - 1))) = 0; }
90 void addHole() { m_scores.append(0); }
91 unsigned int numHoles() const { return m_scores.count(); }
93 QString name() const { return m_name; }
94 void setName(const QString &name) { m_name = name; m_ball->setName(name); }
96 void setId(int id) { m_id = id; }
97 int id() const { return m_id; }
99 private:
100 Ball *m_ball;
101 QList<int> m_scores;
102 QString m_name;
103 int m_id;
106 typedef QList<Player> PlayerList;
108 class AntiAliasedLine : public QGraphicsLineItem
110 public:
111 AntiAliasedLine(QGraphicsItem *parent, QGraphicsScene *scene);
112 void paint(QPainter *p, const QStyleOptionGraphicsItem *style, QWidget *widget);
115 class Arrow : public AntiAliasedLine
117 public:
118 Arrow(QGraphicsItem * parent, QGraphicsScene *scene);
119 void setAngle(double newAngle) { m_angle = newAngle; }
120 double angle() const { return m_angle; }
121 void setLength(double newLength) { m_length = newLength; }
122 double length() const { return m_length; }
123 void setReversed(bool yes) { m_reversed = yes; }
124 bool reversed() const { return m_reversed; }
125 virtual void setVisible(bool);
126 virtual void setPen(QPen p);
127 void aboutToDie();
128 virtual void moveBy(double, double);
129 void updateSelf();
130 virtual void setZValue(double newz);
132 private:
134 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
136 double baseLineThickness;
137 double m_angle;
138 double m_length;
139 bool m_reversed;
140 QGraphicsLineItem *line1;
141 QGraphicsLineItem *line2;
144 class RectPoint;
145 class RectItem
147 public:
148 virtual ~RectItem(){}
149 virtual void newSize(double /*width*/, double /*height*/) {}
150 virtual void updateBaseResizeInfo() {}
153 class RectPoint : public QGraphicsEllipseItem, public CanvasItem
155 public:
156 RectPoint(const QColor &color, RectItem *, QGraphicsItem * parent, QGraphicsScene *scene);
157 void dontMove() { dontmove = true; }
158 virtual void moveBy(double dx, double dy);
159 virtual Config *config(QWidget *parent);
160 virtual bool deleteable() const { return false; }
161 virtual bool cornerResize() const { return true; }
162 virtual CanvasItem *itemToDelete() { return dynamic_cast<CanvasItem *>(rect); }
163 void setSizeFactor(double newFactor) { m_sizeFactor = newFactor; }
164 void setSize(double, double);
165 void updateBaseResizeInfo();
167 protected:
168 RectItem *rect;
169 double m_sizeFactor;
171 private:
172 bool dontmove;
175 class KolfEllipse : public QGraphicsEllipseItem, public CanvasItem, public RectItem
177 public:
178 KolfEllipse(QGraphicsItem * parent, QGraphicsScene *scene, const QString &type);
179 void firstMove(int x, int y);
180 virtual void advance(int phase);
181 void resize(double resizeFactor);
183 int changeEvery() const { return m_changeEvery; }
184 void setChangeEvery(int news) { m_changeEvery = news; }
185 bool changeEnabled() const { return m_changeEnabled; }
186 void setChangeEnabled(bool news);
188 virtual void aboutToDie();
189 virtual void aboutToSave();
190 virtual void savingDone();
192 virtual QList<QGraphicsItem *> moveableItems() const;
194 virtual void newSize(double width, double height);
195 void setSize(double width, double height);
196 void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
198 virtual void moveBy(double dx, double dy);
200 virtual void editModeChanged(bool changed);
202 virtual void save(KConfigGroup *cfgGroup);
203 virtual void load(KConfigGroup *cfgGroup);
205 virtual Config *config(QWidget *parent);
207 double width() { return rect().width(); }
208 double height() { return rect().height(); }
210 void updateBaseResizeInfo();
212 protected:
213 RectPoint *point;
214 int m_changeEvery;
215 bool m_changeEnabled;
217 private:
218 int count;
219 bool dontHide;
221 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
223 double baseX, baseY, baseHeight, baseWidth, resizeFactor;
224 QString type;
225 QPixmap pixmap;
227 class EllipseConfig : public Config
229 Q_OBJECT
231 public:
232 EllipseConfig(KolfEllipse *ellipse, QWidget *);
234 private slots:
235 void value1Changed(int news);
236 void value2Changed(int news);
237 void check1Changed(bool on);
238 void check2Changed(bool on);
240 protected:
241 QVBoxLayout *m_vlayout;
243 private:
244 QLabel *slow1;
245 QLabel *fast1;
246 QLabel *slow2;
247 QLabel *fast2;
248 QSlider *slider1;
249 QSlider *slider2;
250 KolfEllipse *ellipse;
253 class Puddle : public KolfEllipse
255 public:
256 Puddle(QGraphicsItem * parent, QGraphicsScene *scene);
257 virtual bool collision(Ball *ball, long int id);
259 class PuddleObj : public Object
261 public:
262 PuddleObj() { m_name = i18n("Puddle"); m__name = "puddle"; }
263 virtual QGraphicsItem *newObject(QGraphicsItem * parent, QGraphicsScene *scene) { return new Puddle(parent, scene); }
266 class Sand : public KolfEllipse
268 public:
269 Sand(QGraphicsItem * parent, QGraphicsScene *scene);
270 virtual bool collision(Ball *ball, long int id);
272 class SandObj : public Object
274 public:
275 SandObj() { m_name = i18n("Sand"); m__name = "sand"; }
276 virtual QGraphicsItem *newObject(QGraphicsItem * parent, QGraphicsScene *scene) { return new Sand(parent, scene); }
279 class Inside : public QGraphicsEllipseItem, public CanvasItem
281 public:
282 Inside(CanvasItem *item, QGraphicsItem * parent, QGraphicsScene *scene) : QGraphicsEllipseItem(parent, scene) { this->item = item; }
283 virtual bool collision(Ball *ball, long int id) { return item->collision(ball, id); }
284 void setSize(double width, double height) { setRect(rect().x(), rect().y(), width, height); }
286 protected:
287 CanvasItem *item;
290 class Bumper : public QGraphicsEllipseItem, public CanvasItem
292 public:
293 Bumper(QGraphicsItem * parent, QGraphicsScene *scene);
294 void paint(QPainter *painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
295 virtual void advance(int phase);
296 void moveBy(double x, double y);
297 void firstMove(int x, int y);
298 void resize(double resizeFactor);
299 virtual bool collision(Ball *ball, long int id);
300 void updateBaseResizeInfo();
302 protected:
303 Inside *inside;
305 private:
306 int count;
307 QPixmap pixmap;
308 bool pixmapInitialised;
310 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
312 double resizeFactor, baseX, baseY;
313 int baseDiameter;
315 class BumperObj : public Object
317 public:
318 BumperObj() { m_name = i18n("Bumper"); m__name = "bumper"; }
319 virtual QGraphicsItem *newObject(QGraphicsItem * parent, QGraphicsScene *scene) { return new Bumper(parent, scene); }
322 class Cup : public QGraphicsEllipseItem, public CanvasItem
324 public:
325 Cup(QGraphicsItem * parent, QGraphicsScene *scene);
326 void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
327 virtual bool place(Ball *ball, bool wasCenter);
328 void moveBy(double x, double y);
329 void firstMove(int x, int y);
330 void resize(double resizeFactor);
331 virtual void save(KConfigGroup *cfgGroup);
332 void saveState(StateDB *db);
333 void loadState(StateDB *db);
334 virtual bool canBeMovedByOthers() const { return true; }
335 virtual bool collision(Ball *ball, long int id);
336 void updateBaseResizeInfo();
338 protected:
339 QPixmap pixmap;
340 bool pixmapInitialised;
342 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
344 double baseX, baseY, baseDiameter, resizeFactor;
345 virtual HoleResult result(const QPointF, double, bool *wasCenter);
348 class CupObj : public Object
350 public:
351 CupObj() { m_name = i18n("Cup"); m__name = "cup"; m_addOnNewHole = true; }
352 virtual QGraphicsItem *newObject(QGraphicsItem * parent, QGraphicsScene *scene) { return new Cup(parent, scene); }
355 class BlackHole;
356 class BlackHoleConfig : public Config
358 Q_OBJECT
360 public:
361 BlackHoleConfig(BlackHole *blackHole, QWidget *parent);
363 private slots:
364 void degChanged(int);
365 void minChanged(double);
366 void maxChanged(double);
368 private:
369 BlackHole *blackHole;
372 class BlackHoleExit : public AntiAliasedLine, public CanvasItem
374 public:
375 BlackHoleExit(BlackHole *blackHole, QGraphicsItem * parent, QGraphicsScene *scene);
376 virtual void aboutToDie();
377 virtual void moveBy(double dx, double dy);
378 virtual bool deleteable() const { return false; }
379 virtual bool canBeMovedByOthers() const { return true; }
380 virtual void editModeChanged(bool editing);
381 virtual void setPen(QPen p);
382 virtual void showInfo();
383 virtual void hideInfo();
384 void updateArrowAngle();
385 void updateArrowLength(double resizeFactor=1);
386 void setArrowPen(QPen pen) { arrow->setPen(pen); }
387 virtual Config *config(QWidget *parent);
388 BlackHole *blackHole;
389 double getBaseArrowPenThickness() { return baseArrowPenThickness; }
390 void updateBaseResizeInfo();
391 double resizeFactor, baseX, baseY;
393 protected:
395 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
397 double baseArrowPenThickness;
398 Arrow *arrow;
400 class BlackHoleTimer : public QObject
402 Q_OBJECT
404 public:
405 BlackHoleTimer(Ball *ball, double speed, int msec);
407 signals:
408 void eject(Ball *ball, double speed);
409 void halfway();
411 protected slots:
412 void mySlot();
413 void myMidSlot();
415 protected:
416 double m_speed;
417 Ball *m_ball;
419 class BlackHole : public QObject, public QGraphicsEllipseItem, public CanvasItem
421 Q_OBJECT
423 public:
424 BlackHole(QGraphicsItem * parent, QGraphicsScene *scene);
425 virtual bool canBeMovedByOthers() const { return true; }
426 void paint(QPainter *painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
427 virtual void aboutToDie();
428 void resize(double resizeFactor);
429 virtual void showInfo();
430 virtual void hideInfo();
431 virtual bool place(Ball *ball, bool wasCenter);
432 virtual void save(KConfigGroup *cfgGroup);
433 virtual void load(KConfigGroup *cfgGroup);
434 virtual Config *config(QWidget *parent) { return new BlackHoleConfig(this, parent); }
435 virtual QList<QGraphicsItem *> moveableItems() const;
436 double minSpeed() const { return m_minSpeed; }
437 double maxSpeed() const { return m_maxSpeed; }
438 void setMinSpeed(double news) { m_minSpeed = news; exitItem->updateArrowLength(); }
439 void setMaxSpeed(double news) { m_maxSpeed = news; exitItem->updateArrowLength(); }
441 int curExitDeg() const { return exitDeg; }
442 void setExitDeg(int newdeg);
444 virtual void editModeChanged(bool editing) { exitItem->editModeChanged(editing); }
445 void updateInfo();
447 virtual void shotStarted() { runs = 0; }
449 virtual void moveBy(double dx, double dy);
451 void setSize(double width, double height) { setRect(rect().x(), rect().y
452 (), width, height); }
453 double width() { return rect().width(); }
454 double height() { return rect().height(); }
456 virtual bool collision(Ball *ball, long int id);
458 void updateBaseResizeInfo();
460 public slots:
461 void eject(Ball *ball, double speed);
462 void halfway();
464 protected:
465 int exitDeg;
466 BlackHoleExit *exitItem;
467 double m_minSpeed;
468 double m_maxSpeed;
469 virtual HoleResult result(const QPointF, double, bool *wasCenter);
471 private:
472 QPixmap pixmap;
473 bool pixmapInitialised;
475 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
477 double baseX, baseY, resizeFactor;
478 double baseInfoLineThickness, baseExitLineWidth;
479 double baseWidth, baseHeight;
480 int runs;
481 QGraphicsLineItem *infoLine;
482 void finishMe(double width=0);
484 class BlackHoleObj : public Object
486 public:
487 BlackHoleObj() { m_name = i18n("Black Hole"); m__name = "blackhole"; }
488 virtual QGraphicsItem *newObject(QGraphicsItem * parent, QGraphicsScene *scene) { return new BlackHole(parent, scene); }
491 class WallPoint;
492 class Wall : public AntiAliasedLine, public CanvasItem
494 public:
495 Wall( QGraphicsItem * parent, QGraphicsScene *scene, bool antialiasing=1);
496 virtual void aboutToDie();
497 double dampening;
499 void setAlwaysShow(bool yes);
500 void paint(QPainter *p, const QStyleOptionGraphicsItem *style, QWidget *widget);
501 virtual void setZValue(double newz);
502 void resize(double resizeFactor);
503 void setBasePenWidth(double basePenWidth) { this->basePenWidth=basePenWidth; }
504 void setLine(const QLineF & line);
505 void setLine(qreal x1, qreal y1, qreal x2, qreal y2);
506 virtual void setPen(QPen p);
507 virtual bool collision(Ball *ball, long int id);
508 virtual void save(KConfigGroup *cfgGroup);
509 virtual void load(KConfigGroup *cfgGroup);
510 virtual void selectedItem(QGraphicsItem *item);
511 virtual void editModeChanged(bool changed);
512 virtual void moveBy(double dx, double dy);
513 virtual void setPos(double x, double y);
514 virtual void setVelocity(double vx, double vy);
515 virtual void clean();
517 // must reimp because we gotta move the end items,
518 // and we do that in moveBy()
519 virtual void setPoints(double xa, double ya, double xb, double yb) { setLine(xa, ya, xb, yb); moveBy(0, 0); }
521 virtual QList<QGraphicsItem *> moveableItems() const;
522 virtual void setGame(KolfGame *game);
523 virtual void setVisible(bool);
525 QPointF startPointF() const { return QPointF(line().x1(), line().y1() ); }
526 QPointF endPointF() const { return QPointF(line().x2(), line().y2() ); }
527 QPoint startPoint() const { return QPoint((int)line().x1(), (int)line().y1() ); }
528 QPoint endPoint() const { return QPoint((int)line().x2(), (int)line().y2() ); }
530 void doAdvance();
531 virtual void updateBaseResizeInfo() {}
533 protected:
534 WallPoint *startItem;
535 WallPoint *endItem;
536 bool editing;
538 private:
540 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
542 double resizeFactor;
543 double basePenWidth;
544 bool antialiasing;
545 long int lastId;
547 friend class WallPoint;
549 class WallPoint : public QGraphicsEllipseItem, public CanvasItem
551 public:
552 WallPoint(bool start, Wall *wall, QGraphicsItem * parent, QGraphicsScene *scene);
553 void setAlwaysShow(bool yes) { alwaysShow = yes; updateVisible(); }
554 virtual void editModeChanged(bool changed);
555 virtual void moveBy(double dx, double dy);
556 virtual bool deleteable() const { return false; }
557 virtual bool collision(Ball *ball, long int id);
558 virtual CanvasItem *itemToDelete() { return wall; }
559 virtual void clean();
560 virtual Config *config(QWidget *parent) { return wall->config(parent); }
561 void dontMove() { dontmove = true; }
562 void updateVisible();
564 void setSize(double width, double height) { setRect(rect().x(), rect().y(), width, height); }
565 double width() { return rect().width(); }
566 double height() { return rect().height(); }
568 Wall *parentWall() { return wall; }
569 void updateBaseResizeInfo();
571 double baseX, baseY, resizeFactor;
573 protected:
574 Wall *wall;
575 bool editing;
576 bool visible;
578 private:
579 bool alwaysShow;
580 bool start;
581 bool dontmove;
582 long int lastId;
584 friend class Wall;
586 class WallObj : public Object
588 public:
589 WallObj() { m_name = i18n("Wall"); m__name = "wall"; }
590 virtual QGraphicsItem *newObject( QGraphicsItem * parent, QGraphicsScene *scene) { return new Wall(parent, scene); }
593 class Putter : public AntiAliasedLine, public CanvasItem
595 public:
596 Putter(QGraphicsScene *scene);
597 void resize(double resizeFactor);
598 void go(Direction, Amount amount = Amount_Normal);
599 void setOrigin(double x, double y);
600 double curLen() const { return guideLineLength; }
601 double curAngle() const { return angle; }
602 int curDeg() const { return rad2deg(angle); }
603 virtual void showInfo();
604 virtual void hideInfo();
605 void setAngle(double news) { angle = news; finishMe(); }
606 void setDeg(int news) { angle = deg2rad(news); finishMe(); }
607 double curMaxAngle() const { return maxAngle; }
608 virtual void setVisible(bool yes);
609 void saveAngle(Ball *ball) { angleMap[ball] = angle; }
610 void setAngle(Ball *ball);
611 void resetAngles() { angleMap.clear(); setZValue(999999); }
612 virtual bool canBeMovedByOthers() const { return true; }
613 virtual void moveBy(double dx, double dy);
614 void setShowGuideLine(bool yes);
616 private:
617 QPointF midPoint;
618 double maxAngle;
619 double angle;
620 double oneDegree;
621 QMap<Ball *, double> angleMap;
623 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
625 double guideLineLength, baseGuideLineLength;
626 double baseGuideLineThickness;
627 double basePutterThickness;
628 double basePutterWidth, putterWidth;
630 * resizeFactor is the number to multiply base numbers by to get their resized value (i.e. if it is 1 then use default size, if it is >1 then everything needs to be bigger, and if it is <1 then everything needs to be smaller)
632 double resizeFactor;
633 void finishMe();
634 QGraphicsLineItem *guideLine;
635 bool m_showGuideLine;
639 class Bridge;
640 class BridgeConfig : public Config
642 Q_OBJECT
644 public:
645 BridgeConfig(Bridge *bridge, QWidget *);
647 protected slots:
648 void topWallChanged(bool);
649 void botWallChanged(bool);
650 void leftWallChanged(bool);
651 void rightWallChanged(bool);
653 protected:
654 QVBoxLayout *m_vlayout;
655 QCheckBox *top;
656 QCheckBox *bot;
657 QCheckBox *left;
658 QCheckBox *right;
660 private:
661 Bridge *bridge;
663 class Bridge : public QGraphicsRectItem, public CanvasItem, public RectItem
665 public:
666 Bridge(const QRect &rect, QGraphicsItem *parent, QGraphicsScene *scene, const QString &type);
667 void paint(QPainter *p, const QStyleOptionGraphicsItem *style, QWidget *widget=0);
668 virtual bool collision(Ball *ball, long int id);
669 virtual void resize(double resizeFactor);
670 virtual void aboutToDie();
671 virtual void editModeChanged(bool changed);
672 virtual void moveBy(double dx, double dy);
673 virtual void load(KConfigGroup *cfgGroup);
674 virtual void save(KConfigGroup *cfgGroup);
675 virtual bool vStrut() const { return true; }
676 void doLoad(KConfigGroup *cfgGroup);
677 void doSave(KConfigGroup *cfgGroup);
678 virtual void newSize(double width, double height);
679 virtual void setGame(KolfGame *game);
680 virtual Config *config(QWidget *parent) { return new BridgeConfig(this, parent); }
681 void setSize(double width, double height);
682 virtual QList<QGraphicsItem *> moveableItems() const;
684 void setWallColor(const QColor &color);
685 QPen wallPen() const { return topWall->pen(); }
687 double wallZ() const { return topWall->zValue(); }
688 void setWallZ(double);
690 void setTopWallVisible(bool yes) { topWall->setVisible(yes); }
691 void setBotWallVisible(bool yes) { botWall->setVisible(yes); }
692 void setLeftWallVisible(bool yes) { leftWall->setVisible(yes); }
693 void setRightWallVisible(bool yes) { rightWall->setVisible(yes); }
694 bool topWallVisible() const { return topWall->isVisible(); }
695 bool botWallVisible() const { return botWall->isVisible(); }
696 bool leftWallVisible() const { return leftWall->isVisible(); }
697 bool rightWallVisible() const { return rightWall->isVisible(); }
699 double width() {return QGraphicsRectItem::rect().width(); }
700 double height() {return QGraphicsRectItem::rect().height(); }
702 virtual void updateBaseResizeInfo();
704 protected:
705 bool pixmapInitialised;
706 QPixmap pixmap;
707 QString type;
709 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
711 double baseX, baseY, baseWidth, baseHeight;
712 double baseTopWallX, baseTopWallY;
713 double baseBotWallX, baseBotWallY;
714 double baseLeftWallX, baseLeftWallY;
715 double baseRightWallX, baseRightWallY;
716 double resizeFactor;
717 Wall *topWall;
718 Wall *botWall;
719 Wall *leftWall;
720 Wall *rightWall;
721 RectPoint *point;
723 class BridgeObj : public Object
725 public:
726 BridgeObj() { m_name = i18n("Bridge"); m__name = "bridge"; }
727 virtual QGraphicsItem *newObject(QGraphicsItem *parent, QGraphicsScene *scene) { return new Bridge(QRect(0, 0, 80, 40), parent, scene, "bridge"); }
730 class Sign;
731 class SignConfig : public BridgeConfig
733 Q_OBJECT
735 public:
736 SignConfig(Sign *sign, QWidget *parent);
738 private slots:
739 void textChanged(const QString &);
741 private:
742 Sign *sign;
744 class Sign : public Bridge
746 public:
747 Sign(QGraphicsItem * parent, QGraphicsScene *scene);
748 void resize(double resizeFactor);
749 void setText(const QString &text);
750 QString text() const { return m_text; }
751 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
752 virtual bool vStrut() const { return false; }
753 virtual Config *config(QWidget *parent) { return new SignConfig(this, parent); }
754 virtual void save(KConfigGroup *cfgGroup);
755 virtual void load(KConfigGroup *cfgGroup);
757 protected:
759 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
761 double baseFontPixelSize, fontPixelSize;
762 QString m_text;
763 QString m_untranslatedText;
765 class SignObj : public Object
767 public:
768 SignObj() { m_name = i18n("Sign"); m__name = "sign"; }
769 virtual QGraphicsItem *newObject(QGraphicsItem * parent, QGraphicsScene *scene) { return new Sign(parent, scene); }
772 class Windmill;
773 class WindmillGuard : public Wall
775 public:
776 WindmillGuard(QGraphicsItem * parent, QGraphicsScene *scene) : Wall(parent, scene, false) {}
777 void setBetween(double newmin, double newmax) { max = newmax; min = newmin; }
778 virtual void advance(int phase);
779 double getMax() { return max; }
780 double getMin() { return min; }
782 protected:
783 double max;
784 double min;
786 class WindmillConfig : public BridgeConfig
788 Q_OBJECT
790 public:
791 WindmillConfig(Windmill *windmill, QWidget *parent);
793 private slots:
794 void speedChanged(int news);
795 void endChanged(bool yes);
797 private:
798 Windmill *windmill;
800 class Windmill : public Bridge
802 public:
803 Windmill(const QRect &rect, QGraphicsItem * parent, QGraphicsScene *scene);
804 virtual void aboutToDie();
805 virtual void newSize(double width, double height);
806 virtual void save(KConfigGroup *cfgGroup);
807 virtual void load(KConfigGroup *cfgGroup);
808 virtual void setGame(KolfGame *game);
809 virtual Config *config(QWidget *parent) { return new WindmillConfig(this, parent); }
810 void setSize(double width, double height);
811 virtual void resize(double resizeFactor);
812 virtual void moveBy(double dx, double dy);
813 void setSpeed(double news);
814 double curSpeed() const { return speed; }
815 void setBottom(bool yes);
816 bool bottom() const { return m_bottom; }
817 void updateBaseResizeInfo();
819 protected:
820 WindmillGuard *guard;
821 Wall *left;
822 Wall *right;
824 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
826 double baseGuardX, baseGuardY, baseGuardMin, baseGuardMax, baseGuardSpeed;
827 double baseLeftX, baseLeftY, baseRightX, baseRightY;
828 double resizeFactor;
829 int speedfactor;
830 double speed;
831 bool m_bottom;
833 class WindmillObj : public Object
835 public:
836 WindmillObj() { m_name = i18n("Windmill"); m__name = "windmill"; }
837 virtual QGraphicsItem *newObject(QGraphicsItem * parent, QGraphicsScene *scene) { return new Windmill(QRect(0, 0, 80, 40), parent, scene); }
840 class HoleInfo;
841 class HoleConfig : public Config
843 Q_OBJECT
845 public:
846 HoleConfig(HoleInfo *holeInfo, QWidget *);
848 private slots:
849 void authorChanged(const QString &);
850 void parChanged(int);
851 void maxStrokesChanged(int);
852 void nameChanged(const QString &);
853 void borderWallsChanged(bool);
855 private:
856 HoleInfo *holeInfo;
858 class HoleInfo : public CanvasItem
860 public:
861 HoleInfo() { m_lowestMaxStrokes = 4; }
862 virtual ~HoleInfo() {}
863 void setPar(int newpar) { m_par = newpar; }
864 int par() const { return m_par; }
865 void setMaxStrokes(int newMaxStrokes) { m_maxStrokes = newMaxStrokes; }
866 int lowestMaxStrokes() const { return m_lowestMaxStrokes; }
867 int maxStrokes() const { return m_maxStrokes; }
868 bool hasMaxStrokes() const { return m_maxStrokes != m_lowestMaxStrokes; }
869 void setAuthor(QString newauthor) { m_author = newauthor; }
870 QString author() const { return m_author; }
872 void setName(QString newname) { m_name = newname; }
873 void setUntranslatedName(QString newname) { m_untranslatedName = newname; }
874 QString name() const { return m_name; }
875 QString untranslatedName() const { return m_untranslatedName; }
877 virtual Config *config(QWidget *parent) { return new HoleConfig(this, parent); }
878 void borderWallsChanged(bool yes);
879 bool borderWalls() const { return m_borderWalls; }
881 private:
882 QString m_author;
883 QString m_name;
884 QString m_untranslatedName;
885 bool m_borderWalls;
886 int m_par;
887 int m_maxStrokes;
888 int m_lowestMaxStrokes;
891 class StrokeCircle : public QGraphicsItem
893 public:
894 StrokeCircle(QGraphicsItem *parent, QGraphicsScene *scene);
896 void resize(double resizeFactor);
897 void setValue(double v);
898 double value();
899 void setMaxValue(double m);
900 void setSize(double w, double h);
901 void setThickness(double t);
902 double thickness() const;
903 double width() const;
904 double height() const;
905 virtual void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
906 virtual QRectF boundingRect() const;
907 virtual bool collidesWithItem(const QGraphicsItem*, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
909 private:
910 double dvalue, dmax;
911 double ithickness, iwidth, iheight;
914 struct KOLFLIB_EXPORT CourseInfo
916 CourseInfo(const QString &_name, const QString &_untranslatedName, const QString &_author, unsigned int _holes, unsigned int _par) { name = _name; untranslatedName = _untranslatedName, author = _author; holes = _holes; par = _par; }
917 CourseInfo();
919 QString name;
920 QString untranslatedName;
921 QString author;
922 unsigned int holes;
923 unsigned int par;
926 class KOLFLIB_EXPORT KolfGame : public QGraphicsView
928 Q_OBJECT
930 public:
931 KolfGame(ObjectList *obj, PlayerList *players, const QString &filename, QWidget *parent=0);
932 ~KolfGame();
933 void setObjects(ObjectList *obj) { this->obj = obj; }
934 void setFilename(const QString &filename);
935 QString curFilename() const { return filename; }
936 void emitLargestHole() { emit largestHole(highestHole); }
937 QGraphicsScene *scene() const { return course; }
938 void removeItem(QGraphicsItem *item) { items.removeAll(item); }
939 bool askSave(bool);
940 bool isEditing() const { return editing; }
941 int currentHole() { return curHole; }
942 void setStrict(bool yes) { strict = yes; }
943 // returns true when you shouldn't do anything
944 bool isPaused() const { return paused; }
945 Ball *curBall() const { return (*curPlayer).ball(); }
946 void updateMouse();
947 void ballMoved();
948 void updateHighlighter();
949 QGraphicsItem *curSelectedItem() const { return selectedItem; }
950 void setBorderWalls(bool);
951 void setInPlay(bool yes) { inPlay = yes; }
952 bool isInPlay() { return inPlay; }
953 bool isInfoShowing() { return m_showInfo; }
954 void stoppedBall();
955 QString courseName() const { return holeInfo.name(); }
956 void hidePutter() { putter->setVisible(false); }
957 void ignoreEvents(bool ignore) { m_ignoreEvents = ignore; }
959 static void scoresFromSaved(KConfig*, PlayerList &players);
960 static void courseInfo(CourseInfo &info, const QString &filename);
961 KolfSvgRenderer *renderer;
963 public slots:
964 void pause();
965 void unPause();
966 void save();
967 void toggleEditMode();
968 void setModified(bool mod = true);
969 void addNewObject(Object *newObj);
970 void addNewHole();
971 void switchHole(int);
972 void switchHole(const QString &);
973 void nextHole();
974 void prevHole();
975 void firstHole();
976 void lastHole();
977 void randHole();
978 void playSound(const QString &file, float vol = 1);
979 void showInfoDlg(bool = false);
980 void resetHole();
981 void clearHole();
982 void print(QPrinter &, bool printTitle);
983 void setShowInfo(bool yes);
984 void toggleShowInfo();
985 void updateShowInfo();
986 void setUseMouse(bool yes) { m_useMouse = yes; }
987 void setUseAdvancedPutting(bool yes);
988 void setShowGuideLine(bool yes);
989 void setSound(bool yes);
990 void undoShot();
991 void timeout();
992 void saveScores(KConfig *);
993 void startFirstHole(int hole);
994 void sayWhosGoing();
996 signals:
997 void holesDone();
998 void newHole(int);
999 void parChanged(int, int);
1000 void titleChanged(const QString &);
1001 void largestHole(int);
1002 void scoreChanged(int, int, int);
1003 void newPlayersTurn(Player *);
1004 void newSelectedItem(CanvasItem *);
1005 void checkEditing();
1006 void editingStarted();
1007 void editingEnded();
1008 void inPlayStart();
1009 void inPlayEnd();
1010 void maxStrokesReached(const QString &);
1011 void currentHole(int);
1012 void modifiedChanged(bool);
1013 void newStatusText(const QString &);
1015 private slots:
1016 void shotDone();
1017 void holeDone();
1018 void startNextHole();
1019 void fastTimeout();
1020 void putterTimeout();
1021 void autoSaveTimeout();
1022 void addItemsToMoveableList(QList<QGraphicsItem *>);
1023 void addItemToFastAdvancersList(CanvasItem *);
1025 void emitMax();
1027 protected:
1028 void mouseMoveEvent(QMouseEvent *e);
1029 void mousePressEvent(QMouseEvent *e);
1030 void mouseReleaseEvent(QMouseEvent *e);
1031 void mouseDoubleClickEvent(QMouseEvent *e);
1033 void handleMousePressEvent(QMouseEvent *e);
1034 void handleMouseDoubleClickEvent(QMouseEvent *e);
1035 void handleMouseMoveEvent(QMouseEvent *e);
1036 void handleMouseReleaseEvent(QMouseEvent *e);
1037 void keyPressEvent(QKeyEvent *e);
1038 void keyReleaseEvent(QKeyEvent *e);
1041 * resizes view to make sure it is square and calls resizeAllItems
1043 void resizeEvent(QResizeEvent *);
1045 * resizes and moves all items in the game
1047 void resizeAllItems(double resizeFactor, bool resizeBorderWalls=1);
1049 QPoint viewportToViewport(const QPoint &p);
1051 private:
1052 QGraphicsScene *course;
1053 Putter *putter;
1054 PlayerList *players;
1055 PlayerList::Iterator curPlayer;
1056 Ball *whiteBall;
1057 StrokeCircle *strokeCircle;
1059 QTimer *timer;
1060 QTimer *autoSaveTimer;
1061 QTimer *fastTimer;
1062 QTimer *putterTimer;
1063 bool regAdv;
1065 ObjectList *obj;
1066 QList<QGraphicsItem *> items;
1067 QList<QGraphicsItem *> extraMoveable;
1068 QList<Wall *> borderWalls;
1070 int timerMsec;
1071 int autoSaveMsec;
1072 int fastTimerMsec;
1073 int putterTimerMsec;
1075 void puttPress();
1076 void puttRelease();
1077 bool inPlay;
1078 bool putting;
1079 bool stroking;
1080 bool finishStroking;
1081 double strength;
1082 double maxStrength;
1083 int puttCount;
1084 bool puttReverse;
1086 int curHole;
1087 int highestHole;
1088 int curPar;
1090 int wallWidth;
1091 int height;
1092 int width;
1093 int margin;
1094 QColor grass;
1096 int advancePeriod;
1098 int lastDelId;
1100 bool paused;
1102 QString filename;
1103 bool recalcHighestHole;
1104 void openFile();
1106 bool strict;
1108 bool editing;
1109 QPoint storedMousePos;
1110 bool moving;
1111 bool dragging;
1112 QGraphicsItem *movingItem;
1113 CanvasItem *movingCanvasItem;
1114 QGraphicsItem *selectedItem;
1115 QGraphicsRectItem *highlighter;
1117 //For intro banner
1118 QGraphicsPixmapItem *banner;
1120 #ifdef SOUND
1121 Phonon::MediaObject *m_player;
1122 #endif
1123 bool m_sound;
1124 QString soundDir;
1126 bool m_ignoreEvents;
1128 HoleInfo holeInfo;
1129 StateDB stateDB;
1131 BallStateList ballStateList;
1132 void loadStateList();
1133 void recreateStateList();
1134 void addHoleInfo(BallStateList &list);
1136 bool dontAddStroke;
1138 bool addingNewHole;
1139 int scoreboardHoles;
1140 inline void resetHoleScores();
1142 bool m_showInfo;
1144 bool infoShown;
1146 KConfig *cfg;
1147 KConfigGroup cfgGroup;
1149 inline void addBorderWall(const QPoint &start, const QPoint &end);
1150 void shotStart();
1151 void startBall(const Vector &vector);
1153 bool modified;
1155 inline bool allPlayersDone();
1157 bool m_useMouse;
1158 bool m_useAdvancedPutting;
1160 QList<CanvasItem *> fastAdvancers;
1161 bool fastAdvancedExist;
1163 QString playerWhoMaxed;
1166 #endif