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

KDE's Doxygen guidelines are available online.