File indexing completed on 2024-05-12 04:04:33

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_LANDSCAPE_H
0021 #define KOLF_LANDSCAPE_H
0022 
0023 //NOTE: Only refactored stuff goes into this header.
0024 
0025 #include "canvasitem.h"
0026 #include <config.h>
0027 #include "overlay.h"
0028 
0029 namespace Kolf
0030 {
0031     class LandscapeItem : public EllipticalCanvasItem
0032     {
0033         Q_OBJECT
0034         public:
0035             LandscapeItem(const QString& type, QGraphicsItem* parent, b2World* world);
0036 
0037             bool isBlinkEnabled() const;
0038             int blinkInterval() const;
0039             void advance(int phase) override;
0040 
0041             void load(KConfigGroup* group) override;
0042             void save(KConfigGroup* group) override;
0043 
0044             Config* config(QWidget* parent) override;
0045         public Q_SLOTS:
0046             void setBlinkEnabled(bool blinkEnabled);
0047             void setBlinkInterval(int blinkInterval);
0048         protected:
0049             Kolf::Overlay* createOverlay() override;
0050         private:
0051             bool m_blinkEnabled;
0052             int m_blinkInterval, m_blinkFrame;
0053     };
0054 
0055     class LandscapeOverlay : public Kolf::Overlay
0056     {
0057         Q_OBJECT
0058         public:
0059             explicit LandscapeOverlay(Kolf::LandscapeItem* item);
0060             void update() override;
0061         private Q_SLOTS:
0062             //interface to handles
0063             void moveHandle(const QPointF& handleScenePos);
0064         private:
0065             QList<Kolf::OverlayHandle*> m_handles;
0066     };
0067 
0068     class LandscapeConfig : public Config
0069     {
0070         Q_OBJECT
0071         public:
0072             LandscapeConfig(Kolf::LandscapeItem* item, QWidget* parent);
0073         Q_SIGNALS:
0074             void blinkIntervalChanged(int blinkInterval);
0075         public Q_SLOTS:
0076             void setBlinkInterval(int sliderValue);
0077     };
0078 
0079     class Puddle : public Kolf::LandscapeItem
0080     {
0081         public:
0082             Puddle(QGraphicsItem* parent, b2World* world);
0083             bool collision(Ball* ball) override;
0084     };
0085 
0086     class Sand : public Kolf::LandscapeItem
0087     {
0088         public:
0089             Sand(QGraphicsItem* parent, b2World* world);
0090             bool collision(Ball* ball) override;
0091     };
0092 
0093     enum SlopeType
0094     {
0095         VerticalSlope = 0,
0096         HorizontalSlope,
0097         DiagonalSlope,
0098         CrossDiagonalSlope,
0099         EllipticSlope
0100     };
0101 
0102     class Slope : public Tagaro::SpriteObjectItem, public CanvasItem
0103     {
0104         Q_OBJECT
0105         public:
0106             Slope(QGraphicsItem* parent, b2World* world);
0107 
0108             double grade() const;
0109             bool isReversed() const;
0110             Kolf::SlopeType slopeType() const;
0111             bool isStuckOnGround() const;
0112 
0113             QPainterPath shape() const override;
0114             void setSize(const QSizeF& size) override;
0115             QPointF getPosition() const override;
0116             void moveBy(double dx, double dy) override;
0117 
0118             void load(KConfigGroup* group) override;
0119             void save(KConfigGroup* group) override;
0120 
0121             bool collision(Ball* ball) override;
0122             bool terrainCollisions() const override;
0123             QList<QGraphicsItem*> infoItems() const override;
0124             Config* config(QWidget* parent) override;
0125         public Q_SLOTS:
0126             void setGrade(double grade);
0127             void setReversed(bool reversed);
0128             void setSlopeType(int type);
0129             void setStuckOnGround(bool stuckOnGround);
0130         protected:
0131             Kolf::Overlay* createOverlay() override;
0132         private:
0133             void updateAppearance();
0134             void updateInfo();
0135 
0136             double m_grade;
0137             bool m_reversed, m_stuckOnGround;
0138             Kolf::SlopeType m_type;
0139 
0140             QGraphicsSimpleTextItem* m_gradeItem;
0141             QList<ArrowItem*> m_arrows;
0142     };
0143 
0144     class SlopeConfig : public Config
0145     {
0146         public:
0147             SlopeConfig(Kolf::Slope* slope, QWidget* parent);
0148     };
0149 
0150     class SlopeOverlay : public Kolf::Overlay
0151     {
0152         Q_OBJECT
0153         public:
0154             explicit SlopeOverlay(Kolf::Slope* slope);
0155             void update() override;
0156         private Q_SLOTS:
0157             //interface to handles
0158             void moveHandle(const QPointF& handleScenePos);
0159         private:
0160             QList<Kolf::OverlayHandle*> m_handles;
0161     };
0162 }
0163 
0164 #endif // KOLF_LANDSCAPE_H