File indexing completed on 2024-05-12 05:39:49

0001 /***************************************************************************
0002  *   Copyright (C) 2015 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   rolisteam 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                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef CHARACTERVISION_H
0022 #define CHARACTERVISION_H
0023 
0024 #include <QObject>
0025 #include <QPainterPath>
0026 #include <QPointF>
0027 
0028 #include <network_global.h>
0029 
0030 /**
0031  * @brief The Vision class
0032  */
0033 class NETWORK_EXPORT CharacterVision : public QObject
0034 {
0035     Q_OBJECT
0036     Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
0037     Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
0038     Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
0039     Q_PROPERTY(QPointF position READ position WRITE setPosition NOTIFY positionChanged)
0040     Q_PROPERTY(SHAPE shape READ shape WRITE setShape NOTIFY shapeChanged)
0041     Q_PROPERTY(QPainterPath path READ path WRITE setPath NOTIFY pathChanged)
0042     Q_PROPERTY(qreal side READ side WRITE setSide NOTIFY sideChanged FINAL)
0043     Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
0044     Q_PROPERTY(bool cornerVisible READ cornerVisible WRITE setCornerVisible NOTIFY cornerVisibleChanged)
0045     Q_PROPERTY(bool removed READ removed WRITE setRemoved NOTIFY removedChanged FINAL)
0046 public:
0047     enum SHAPE
0048     {
0049         DISK,
0050         ANGLE
0051     };
0052     Q_ENUM(SHAPE)
0053 
0054     enum class ChangedProperty {
0055         NONE=0x0,
0056         ANGLE= 0x1,
0057         ROTATION=0x2,
0058         POSITION=0x4,
0059         RADIUS=0x8,
0060         PATH=0xF
0061     };
0062     Q_DECLARE_FLAGS(Changes, ChangedProperty)
0063     Q_FLAG(Changes)
0064 
0065     CharacterVision(QObject* parent= nullptr);
0066     virtual ~CharacterVision();
0067 
0068     void setAngle(qreal);
0069     void setRadius(qreal);
0070     void setPosition(const QPointF& p);
0071     void setShape(CharacterVision::SHAPE s);
0072     void setVisible(bool);
0073 
0074     qreal angle() const;
0075     qreal radius() const;
0076     QPointF position() const;
0077     CharacterVision::SHAPE shape() const;
0078     bool visible() const;
0079     bool cornerVisible() const;
0080 
0081     QPainterPath path() const;
0082     void setPath(QPainterPath newPath);
0083 
0084     qreal rotation() const;
0085     void setRotation(qreal newRotation);
0086 
0087     qreal side() const;
0088     void setSide(qreal newSide);
0089 
0090     bool removed() const;
0091     void setRemoved(bool newRemoved);
0092 
0093 public slots:
0094     void updatePosition();
0095     void setCornerVisible(bool b);
0096     void endOfGeometryChanges();
0097 
0098 signals:
0099     void radiusChanged(qreal);
0100     void angleChanged(qreal);
0101     void positionChanged(QPointF);
0102     void shapeChanged(SHAPE);
0103     void visibleChanged(bool);
0104     void cornerVisibleChanged(bool);
0105     void pathChanged();
0106     void rotationChanged();
0107     void sideChanged();
0108     void removedChanged();
0109 
0110     //edited
0111     void radiusEdited();
0112     void angleEdited();
0113     void rotationEdited();
0114     void positionEdited();
0115     void pathEdited();
0116 
0117 private:
0118     CharacterVision::SHAPE m_shape= ANGLE;
0119     QPointF m_pos;
0120     qreal m_angle= 120;
0121     bool m_cornerVisible= false;
0122     bool m_visible= false;
0123     qreal m_radius= 50;
0124     QPainterPath m_path;
0125     qreal m_rotation= 0.;
0126     Changes m_changes{ChangedProperty::NONE};
0127     qreal m_side;
0128     bool m_removed{false};
0129 };
0130 
0131 #endif // CHARACTERVISION_H