File indexing completed on 2024-04-14 03:40:54

0001 /*
0002     SPDX-FileCopyrightText: 2003 Jason Harris <kstars@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "skypoint.h"
0010 
0011 #include <QImage>
0012 #include <QList>
0013 #include <QString>
0014 #include <QDBusArgument>
0015 
0016 class QPainter;
0017 
0018 /**
0019  * @class FOV
0020  * A simple class encapsulating a Field-of-View symbol
0021  *
0022  * The FOV size, shape, name, and color can be customized. The rotation is by default 0 degrees East Of North.
0023  * @author Jason Harris
0024  * @author Jasem Mutlaq
0025  * @version 1.1
0026  */
0027 class FOV : public QObject
0028 {
0029   Q_OBJECT
0030   Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.fov")
0031 
0032   Q_PROPERTY(QString name MEMBER m_name)
0033   Q_PROPERTY(FOV::Shape shape MEMBER m_shape)
0034   Q_PROPERTY(float sizeX MEMBER m_sizeX)
0035   Q_PROPERTY(float sizeY MEMBER m_sizeY)
0036   Q_PROPERTY(float offsetX MEMBER m_offsetX)
0037   Q_PROPERTY(float offsetY MEMBER m_offsetY)
0038   Q_PROPERTY(float PA MEMBER m_PA)
0039   Q_PROPERTY(QString color MEMBER m_color)
0040   Q_PROPERTY(bool cpLock MEMBER m_lockCelestialPole)
0041 
0042   public:
0043     enum Shape
0044     {
0045         SQUARE,
0046         CIRCLE,
0047         CROSSHAIRS,
0048         BULLSEYE,
0049         SOLIDCIRCLE,
0050         UNKNOWN
0051     };
0052 
0053     /** Default constructor */
0054     FOV();
0055     FOV(const QString &name, float a, float b = -1, float xoffset = 0, float yoffset = 0, float rot = 0,
0056         Shape shape = SQUARE, const QString &color = "#FFFFFF", bool useLockedCP = false);
0057     FOV(const FOV &other);
0058 
0059     void sync(const FOV &other);
0060 
0061     inline Q_SCRIPTABLE QString name() const { return m_name; }
0062     void setName(const QString &n) { m_name = n; }
0063 
0064     inline FOV::Shape shape() const { return m_shape; }
0065     void setShape(FOV::Shape s) { m_shape = s; }
0066     //void setShape(int s);
0067 
0068     inline float sizeX() const { return m_sizeX; }
0069     inline float sizeY() const { return m_sizeY; }
0070     void setSize(float s) { m_sizeX = m_sizeY = s; }
0071     void setSize(float sx, float sy)
0072     {
0073         m_sizeX = sx;
0074         m_sizeY = sy;
0075     }
0076 
0077     void setOffset(float fx, float fy)
0078     {
0079         m_offsetX = fx;
0080         m_offsetY = fy;
0081     }
0082     inline float offsetX() const { return m_offsetX; }
0083     inline float offsetY() const { return m_offsetY; }
0084 
0085     // Position Angle
0086     void setPA(float rt) { m_PA = rt; }
0087     inline float PA() const { return m_PA; }
0088 
0089     inline QString color() const { return m_color; }
0090     void setColor(const QString &c) { m_color = c; }
0091 
0092     /**
0093      * @short draw the FOV symbol on a QPainter
0094      * @param p reference to the target QPainter. The painter should already be started.
0095      * @param zoomFactor is zoom factor as in SkyMap.
0096      */
0097     void draw(QPainter &p, float zoomFactor);
0098 
0099     /**
0100      * @short draw FOV symbol so it will be inside a rectangle
0101      * @param p reference to the target QPainter. The painter should already be started.
0102      * @param x is X size of rectangle
0103      * @param y is Y size of rectangle
0104      */
0105     void draw(QPainter &p, float x, float y);
0106 
0107     SkyPoint center() const;
0108     void setCenter(const SkyPoint &center);
0109 
0110     float northPA() const;
0111     void setNorthPA(float northPA);
0112 
0113     void setImage(const QImage &image);
0114 
0115     void setImageDisplay(bool value);
0116 
0117     bool lockCelestialPole() const;
0118     void setLockCelestialPole(bool lockCelestialPole);
0119 
0120 private:
0121     QString m_name, m_color;
0122     FOV::Shape m_shape;
0123     float m_sizeX { 0 }, m_sizeY { 0 };
0124     float m_offsetX { 0 }, m_offsetY { 0 };
0125     float m_PA { 0 };
0126     float m_northPA { 0 };
0127     SkyPoint m_center;
0128     QImage m_image;
0129     bool m_imageDisplay { false };
0130     bool m_lockCelestialPole { false };
0131 
0132     static int getID() { return m_ID++; }
0133     static int m_ID;
0134 };
0135 
0136 /**
0137  * @class FOVManager
0138  * A simple class handling FOVs.
0139  * @note Should migrate this from file (fov.dat) to using the user sqlite database
0140  * @author Jasem Mutlaq
0141  * @version 1.0
0142  */
0143 class FOVManager
0144 {
0145   public:
0146     /** @short Read list of FOVs from "fov.dat" */
0147     static const QList<FOV *> &readFOVs();
0148     /** @short Release the FOV cache */
0149     static void releaseCache();
0150     static void addFOV(FOV *newFOV)
0151     {
0152         Q_ASSERT(newFOV);
0153         m_FOVs.append(newFOV);
0154     }
0155     static void removeFOV(FOV *fov)
0156     {
0157         Q_ASSERT(fov);
0158         m_FOVs.removeOne(fov);
0159     }
0160     static const QList<FOV *> &getFOVs() { return m_FOVs; }
0161 
0162     /** @short Write list of FOVs to "fov.dat" */
0163     static bool save();
0164 
0165   private:
0166     FOVManager() = default;
0167     ~FOVManager();
0168 
0169     /** @short Fill list with default FOVs*/
0170     static QList<FOV *> defaults();
0171 
0172     static QList<FOV *> m_FOVs;
0173 };
0174 
0175 // Shape
0176 Q_DECLARE_METATYPE(FOV::Shape)
0177 QDBusArgument &operator<<(QDBusArgument &argument, const FOV::Shape& source);
0178 const QDBusArgument &operator>>(const QDBusArgument &argument, FOV::Shape &dest);