8 #include <KConfigGroup>
17 #include <QGraphicsScene>
21 #include "kconfiggroup.h"
22 #include "canvasitem.h"
26 #include <kolflib_export.h>
27 #include "kolfsvgrenderer.h"
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
};
54 void saveState(KConfigGroup
*cfgGroup
);
55 void loadState(KConfigGroup
*cfgGroup
);
63 class BallStateList
: public QList
<BallStateInfo
>
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
; }
106 typedef QList
<Player
> PlayerList
;
108 class AntiAliasedLine
: public QGraphicsLineItem
111 AntiAliasedLine(QGraphicsItem
*parent
, QGraphicsScene
*scene
);
112 void paint(QPainter
*p
, const QStyleOptionGraphicsItem
*style
, QWidget
*widget
);
115 class Arrow
: public AntiAliasedLine
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
);
128 virtual void moveBy(double, double);
130 virtual void setZValue(double newz
);
134 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
136 double baseLineThickness
;
140 QGraphicsLineItem
*line1
;
141 QGraphicsLineItem
*line2
;
148 virtual ~RectItem(){}
149 virtual void newSize(double /*width*/, double /*height*/) {}
150 virtual void updateBaseResizeInfo() {}
153 class RectPoint
: public QGraphicsEllipseItem
, public CanvasItem
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();
175 class KolfEllipse
: public QGraphicsEllipseItem
, public CanvasItem
, public RectItem
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();
215 bool m_changeEnabled
;
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
;
227 class EllipseConfig
: public Config
232 EllipseConfig(KolfEllipse
*ellipse
, QWidget
*);
235 void value1Changed(int news
);
236 void value2Changed(int news
);
237 void check1Changed(bool on
);
238 void check2Changed(bool on
);
241 QVBoxLayout
*m_vlayout
;
250 KolfEllipse
*ellipse
;
253 class Puddle
: public KolfEllipse
256 Puddle(QGraphicsItem
* parent
, QGraphicsScene
*scene
);
257 virtual bool collision(Ball
*ball
, long int id
);
259 class PuddleObj
: public Object
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
269 Sand(QGraphicsItem
* parent
, QGraphicsScene
*scene
);
270 virtual bool collision(Ball
*ball
, long int id
);
272 class SandObj
: public Object
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
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
); }
290 class Bumper
: public QGraphicsEllipseItem
, public CanvasItem
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();
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
;
315 class BumperObj
: public Object
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
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();
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
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
); }
356 class BlackHoleConfig
: public Config
361 BlackHoleConfig(BlackHole
*blackHole
, QWidget
*parent
);
364 void degChanged(int);
365 void minChanged(double);
366 void maxChanged(double);
369 BlackHole
*blackHole
;
372 class BlackHoleExit
: public AntiAliasedLine
, public CanvasItem
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
;
395 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
397 double baseArrowPenThickness
;
400 class BlackHoleTimer
: public QObject
405 BlackHoleTimer(Ball
*ball
, double speed
, int msec
);
408 void eject(Ball
*ball
, double speed
);
419 class BlackHole
: public QObject
, public QGraphicsEllipseItem
, public CanvasItem
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
); }
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();
461 void eject(Ball
*ball
, double speed
);
466 BlackHoleExit
*exitItem
;
469 virtual HoleResult
result(const QPointF
, double, bool *wasCenter
);
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
;
481 QGraphicsLineItem
*infoLine
;
482 void finishMe(double width
=0);
484 class BlackHoleObj
: public Object
487 BlackHoleObj() { m_name
= i18n("Black Hole"); m__name
= "blackhole"; }
488 virtual QGraphicsItem
*newObject(QGraphicsItem
* parent
, QGraphicsScene
*scene
) { return new BlackHole(parent
, scene
); }
492 class Wall
: public AntiAliasedLine
, public CanvasItem
495 Wall( QGraphicsItem
* parent
, QGraphicsScene
*scene
, bool antialiasing
=1);
496 virtual void aboutToDie();
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() ); }
531 virtual void updateBaseResizeInfo() {}
534 WallPoint
*startItem
;
540 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
547 friend class WallPoint
;
549 class WallPoint
: public QGraphicsEllipseItem
, public CanvasItem
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
;
586 class WallObj
: public Object
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
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
);
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)
634 QGraphicsLineItem
*guideLine
;
635 bool m_showGuideLine
;
640 class BridgeConfig
: public Config
645 BridgeConfig(Bridge
*bridge
, QWidget
*);
648 void topWallChanged(bool);
649 void botWallChanged(bool);
650 void leftWallChanged(bool);
651 void rightWallChanged(bool);
654 QVBoxLayout
*m_vlayout
;
663 class Bridge
: public QGraphicsRectItem
, public CanvasItem
, public RectItem
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();
705 bool pixmapInitialised
;
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
;
723 class BridgeObj
: public Object
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"); }
731 class SignConfig
: public BridgeConfig
736 SignConfig(Sign
*sign
, QWidget
*parent
);
739 void textChanged(const QString
&);
744 class Sign
: public Bridge
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
);
759 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
761 double baseFontPixelSize
, fontPixelSize
;
763 QString m_untranslatedText
;
765 class SignObj
: public Object
768 SignObj() { m_name
= i18n("Sign"); m__name
= "sign"; }
769 virtual QGraphicsItem
*newObject(QGraphicsItem
* parent
, QGraphicsScene
*scene
) { return new Sign(parent
, scene
); }
773 class WindmillGuard
: public Wall
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
; }
786 class WindmillConfig
: public BridgeConfig
791 WindmillConfig(Windmill
*windmill
, QWidget
*parent
);
794 void speedChanged(int news
);
795 void endChanged(bool yes
);
800 class Windmill
: public Bridge
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();
820 WindmillGuard
*guard
;
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
;
833 class WindmillObj
: public Object
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
); }
841 class HoleConfig
: public Config
846 HoleConfig(HoleInfo
*holeInfo
, QWidget
*);
849 void authorChanged(const QString
&);
850 void parChanged(int);
851 void maxStrokesChanged(int);
852 void nameChanged(const QString
&);
853 void borderWallsChanged(bool);
858 class HoleInfo
: public CanvasItem
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
; }
884 QString m_untranslatedName
;
888 int m_lowestMaxStrokes
;
891 class StrokeCircle
: public QGraphicsItem
894 StrokeCircle(QGraphicsItem
*parent
, QGraphicsScene
*scene
);
896 void resize(double resizeFactor
);
897 void setValue(double v
);
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;
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
; }
920 QString untranslatedName
;
926 class KOLFLIB_EXPORT KolfGame
: public QGraphicsView
931 KolfGame(ObjectList
*obj
, PlayerList
*players
, const QString
&filename
, QWidget
*parent
=0);
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
); }
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(); }
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
; }
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
;
967 void toggleEditMode();
968 void setModified(bool mod
= true);
969 void addNewObject(Object
*newObj
);
971 void switchHole(int);
972 void switchHole(const QString
&);
978 void playSound(const QString
&file
, float vol
= 1);
979 void showInfoDlg(bool = false);
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
);
992 void saveScores(KConfig
*);
993 void startFirstHole(int hole
);
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();
1010 void maxStrokesReached(const QString
&);
1011 void currentHole(int);
1012 void modifiedChanged(bool);
1013 void newStatusText(const QString
&);
1018 void startNextHole();
1020 void putterTimeout();
1021 void autoSaveTimeout();
1022 void addItemsToMoveableList(QList
<QGraphicsItem
*>);
1023 void addItemToFastAdvancersList(CanvasItem
*);
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
);
1052 QGraphicsScene
*course
;
1054 PlayerList
*players
;
1055 PlayerList::Iterator curPlayer
;
1057 StrokeCircle
*strokeCircle
;
1060 QTimer
*autoSaveTimer
;
1062 QTimer
*putterTimer
;
1066 QList
<QGraphicsItem
*> items
;
1067 QList
<QGraphicsItem
*> extraMoveable
;
1068 QList
<Wall
*> borderWalls
;
1073 int putterTimerMsec
;
1080 bool finishStroking
;
1103 bool recalcHighestHole
;
1109 QPoint storedMousePos
;
1112 QGraphicsItem
*movingItem
;
1113 CanvasItem
*movingCanvasItem
;
1114 QGraphicsItem
*selectedItem
;
1115 QGraphicsRectItem
*highlighter
;
1118 QGraphicsPixmapItem
*banner
;
1121 Phonon::MediaObject
*m_player
;
1126 bool m_ignoreEvents
;
1131 BallStateList ballStateList
;
1132 void loadStateList();
1133 void recreateStateList();
1134 void addHoleInfo(BallStateList
&list
);
1139 int scoreboardHoles
;
1140 inline void resetHoleScores();
1147 KConfigGroup cfgGroup
;
1149 inline void addBorderWall(const QPoint
&start
, const QPoint
&end
);
1151 void startBall(const Vector
&vector
);
1155 inline bool allPlayersDone();
1158 bool m_useAdvancedPutting
;
1160 QList
<CanvasItem
*> fastAdvancers
;
1161 bool fastAdvancedExist
;
1163 QString playerWhoMaxed
;