Kstars

sensorgraphic.cpp
1/*
2 SPDX-FileCopyrightText: 2023 John Evans <john.e.evans.email@googlemail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "sensorgraphic.h"
8#include <QPainter>
9#include <QPen>
10#include <QFileInfo>
11
12namespace Ekos
13{
14
15SensorGraphic::SensorGraphic(const QWidget *parent, const int SW, const int SH, const int tileSize) :
16 m_Parent(parent), m_SW(SW), m_SH(SH), m_tileSize(tileSize)
17{
19
20 // Scale the Picture to 100 pixels in the largest dimension
21 m_SW = std::max(100, m_SW);
22 m_SH = std::max(100, m_SH);
23 double scaling = static_cast<double>(std::max(m_SW, m_SH)) / 100.0;
24 m_SW /= scaling;
25 m_SH /= scaling;
26 m_tileSize /= scaling;
27
28 // Check if the picture resource exists
29 QFileInfo check_file(m_picturePath);
30 if (check_file.exists() || check_file.isFile())
31 {
32 m_PW = m_SW * 1.35;
33 m_PH = m_SH * 1.4;
34 }
35 else
36 {
37 m_PW = m_SW;
38 m_PH = m_SH;
39 m_picturePath = "";
40 }
41 resize(m_PW, m_PH);
42}
43
44SensorGraphic::~SensorGraphic()
45{
46}
47
48void SensorGraphic::paintEvent(QPaintEvent *)
49{
50 // Draw the picture with the correct width / height aspect
51 QRectF sensor(0.0, 0.0, m_PW, m_PH);
52 QPainter painter(this);
53 // Check if the picture resource exists; if so use it otherwise draw a black box
54 if (m_picturePath.isEmpty())
55 painter.fillRect(sensor, "black");
56 else
57 painter.drawImage(sensor, QImage(m_picturePath));
58
59 // Setup the 9 rectangular tiles of the mosaic relative to sensor (later we will adjust this relative to the picture)
60 QRectF tiles[NUM_TILES];
61 tiles[0].setRect(0, 0, m_tileSize, m_tileSize);
62 tiles[1].setRect((m_SW - m_tileSize) / 2, 0, m_tileSize, m_tileSize);
63 tiles[2].setRect(m_SW - m_tileSize, 0, m_tileSize, m_tileSize);
64 tiles[3].setRect(0, (m_SH - m_tileSize) / 2, m_tileSize, m_tileSize);
65 tiles[4].setRect((m_SW - m_tileSize) / 2, (m_SH - m_tileSize) / 2, m_tileSize, m_tileSize);
66 tiles[5].setRect(m_SW - m_tileSize, (m_SH - m_tileSize) / 2, m_tileSize, m_tileSize);
67 tiles[6].setRect(0, m_SH - m_tileSize, m_tileSize, m_tileSize);
68 tiles[7].setRect((m_SW - m_tileSize) / 2, m_SH - m_tileSize, m_tileSize, m_tileSize);
69 tiles[8].setRect(m_SW - m_tileSize, m_SH - m_tileSize, m_tileSize, m_tileSize);
70
71 // Setup an offset point to translate from sensor coordinates to picture coordinates
72 QPointF offset = QPointF((m_PW - m_SW) / 2, (m_PH - m_SH) / 2);
73
74 // Loop through each mosaic tile painting it appropriately
75 for (int i = 0; i < NUM_TILES; i++)
76 {
77 // If not interested in this tile do nothing
78 if (!m_useTile[i])
79 continue;
80
81 // Translate from sensor coordinates to picture coordinates
82 tiles[i].translate(offset);
83
84 // Paint the tile grey to start with
85 painter.fillRect(tiles[i], "white");
86
87 if (i == m_Highlight)
88 {
89 painter.setPen(TILE_COLOUR[m_Highlight]);
90 painter.drawRect(tiles[i]);
91 }
92 else
93 painter.setPen("black");
94
95 painter.drawText(tiles[i], Qt::AlignCenter, TILE_NAME[i]);
96 }
97}
98
99void SensorGraphic::setHighlight(int highlight)
100{
101 m_Highlight = highlight;
102}
103
104void SensorGraphic::setTiles(bool useTiles[NUM_TILES])
105{
106 for (int i = 0; i < NUM_TILES; i++)
107 m_useTile[i] = useTiles[i];
108}
109
110}
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
void setRect(qreal x, qreal y, qreal width, qreal height)
void translate(const QPointF &offset)
AlignCenter
FramelessWindowHint
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.