File indexing completed on 2024-04-28 03:43:43
0001 /* 0002 SPDX-FileCopyrightText: 2021 Jasem Mutlaq <mutlaqja@ikarustech.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QGraphicsItem> 0010 #include <QBrush> 0011 #include <QPen> 0012 0013 #include "skypoint.h" 0014 0015 namespace Ekos 0016 { 0017 0018 class MosaicTilesManager : public QObject, public QGraphicsItem 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 // TODO: make this struct a QGraphicsItem 0024 typedef struct 0025 { 0026 QPointF pos; 0027 QPointF center; 0028 SkyPoint skyCenter; 0029 double rotation; 0030 int index; 0031 } OneTile; 0032 0033 public: 0034 MosaicTilesManager(QWidget *parent = nullptr); 0035 ~MosaicTilesManager(); 0036 0037 public: 0038 void setSkyCenter(SkyPoint center); 0039 void setPositionAngle(double positionAngle); 0040 void setGridDimensions(int width, int height); 0041 void setSingleTileFOV(double fov_x, double fov_y); 0042 void setMosaicFOV(double mfov_x, double mfov_y); 0043 void setOverlap(double value); 0044 void setPixelScale(const QSizeF &scale) {m_PixelScale = scale;} 0045 0046 public: 0047 int getWidth() 0048 { 0049 return m_HorizontalTiles; 0050 } 0051 0052 int getHeight() 0053 { 0054 return m_VerticalTiles; 0055 } 0056 0057 double getOverlap() 0058 { 0059 return overlap; 0060 } 0061 0062 double getPA() 0063 { 0064 return pa; 0065 } 0066 0067 void setPainterAlpha(int v) 0068 { 0069 m_PainterAlpha = v; 0070 } 0071 0072 public: 0073 /// @internal Returns scaled offsets for a pixel local coordinate. 0074 /// 0075 /// This uses the mosaic center as reference and the argument resolution of the sky map at that center. 0076 QSizeF adjustCoordinate(QPointF tileCoord); 0077 virtual QRectF boundingRect() const override; 0078 void updateTiles(QPointF skymapCenter, bool s_shaped); 0079 OneTile *getTile(int row, int col); 0080 0081 QList<OneTile *> getTiles() const 0082 { 0083 return tiles; 0084 } 0085 0086 protected: 0087 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override; 0088 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; 0089 void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override; 0090 QPointF rotatePoint(QPointF pointToRotate, QPointF centerPoint, double paDegrees); 0091 0092 signals: 0093 void newOffset(const QPointF &offset); 0094 0095 private: 0096 SkyPoint skyCenter; 0097 double overlap { 0 }; 0098 uint8_t m_HorizontalTiles { 1 }; 0099 uint8_t m_VerticalTiles { 1 }; 0100 double fovW { 0 }; 0101 double fovH { 0 }; 0102 double mfovW { 0 }; 0103 double mfovH { 0 }; 0104 double pa { 0 }; 0105 0106 QSizeF m_PixelScale; 0107 QBrush brush; 0108 QPen pen; 0109 0110 QBrush textBrush; 0111 QPen textPen; 0112 0113 int m_PainterAlpha { 50 }; 0114 0115 QPointF m_LastPosition; 0116 QList<OneTile *> tiles; 0117 }; 0118 0119 }