File indexing completed on 2025-02-16 06:57:51
0001 /* 0002 Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu> 0003 Copyright 2010 Stefan Majewsky <majewsky@gmx.net> 0004 0005 This program is free software; you can redistribute it and/or modify 0006 it under the terms of the GNU General Public License as published by 0007 the Free Software Foundation; either version 2 of the License, or 0008 (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0018 */ 0019 0020 #ifndef KOLF_OBJECTS_H 0021 #define KOLF_OBJECTS_H 0022 0023 //NOTE: Only refactored stuff goes into this header. 0024 0025 #include "canvasitem.h" 0026 #include "overlay.h" 0027 0028 namespace Kolf 0029 { 0030 class BlackHole; 0031 class BlackHoleOverlay; 0032 0033 class BlackHole : public EllipticalCanvasItem 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 BlackHole(QGraphicsItem* parent, b2World* world); 0039 ~BlackHole() override; 0040 //FIXME: strutted moving of exit is broken since refactoring. 0041 0042 QList<QGraphicsItem*> infoItems() const override; 0043 void save(KConfigGroup* cfgGroup) override; 0044 void load(KConfigGroup* cfgGroup) override; 0045 Config* config(QWidget* parent) override; 0046 double minSpeed() const; 0047 double maxSpeed() const; 0048 void setMinSpeed(double news); 0049 void setMaxSpeed(double news); 0050 0051 QPointF exitPos() const; 0052 void setExitPos(const QPointF& exitPos); 0053 int curExitDeg() const; 0054 void setExitDeg(int newdeg); 0055 Vector exitDirection() const; //for overlay 0056 0057 void updateInfo(); 0058 0059 void moveBy(double dx, double dy) override; 0060 0061 void shotStarted() override; 0062 bool collision(Ball* ball) override; 0063 public Q_SLOTS: 0064 void eject(Ball* ball, double speed); 0065 void halfway(); 0066 protected: 0067 Kolf::Overlay* createOverlay() override; 0068 private: 0069 double m_minSpeed, m_maxSpeed; 0070 int m_runs, m_exitDeg; 0071 QGraphicsLineItem* m_exitItem; 0072 ArrowItem* m_directionItem; 0073 QGraphicsLineItem* m_infoLine; 0074 }; 0075 0076 class BlackHoleTimer : public QObject 0077 { 0078 Q_OBJECT 0079 public: 0080 BlackHoleTimer(Ball* ball, double speed, int msec); 0081 Q_SIGNALS: 0082 void eject(Ball* ball, double speed); 0083 void halfway(); 0084 private Q_SLOTS: 0085 void emitEject(); 0086 private: 0087 double m_speed; 0088 Ball* m_ball; 0089 }; 0090 0091 class BlackHoleConfig : public Config 0092 { 0093 Q_OBJECT 0094 public: 0095 BlackHoleConfig(BlackHole* blackHole, QWidget* parent); 0096 private Q_SLOTS: 0097 void degChanged(int); 0098 void minChanged(double); 0099 void maxChanged(double); 0100 private: 0101 BlackHole* m_blackHole; 0102 }; 0103 0104 class BlackHoleOverlay : public Kolf::Overlay 0105 { 0106 Q_OBJECT 0107 public: 0108 explicit BlackHoleOverlay(Kolf::BlackHole* blackHole); 0109 void update() override; 0110 private Q_SLOTS: 0111 //interface to handles 0112 void moveHandle(const QPointF& handleScenePos); 0113 private: 0114 QGraphicsLineItem* m_exitIndicator; 0115 Kolf::OverlayHandle* m_exitHandle; 0116 Kolf::OverlayHandle* m_speedHandle; 0117 }; 0118 0119 class Cup : public EllipticalCanvasItem 0120 { 0121 public: 0122 Cup(QGraphicsItem* parent, b2World* world); 0123 0124 Kolf::Overlay* createOverlay() override; 0125 bool collision(Ball* ball) override; 0126 }; 0127 } 0128 0129 #endif // KOLF_OBJECTS_H