Warning, file /education/kstars/kstars/ekos/focus/sensorgraphic.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2023 John Evans <john.e.evans.email@googlemail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "sensorgraphic.h"
0010 #include <QPainter>
0011 #include <QPen>
0012 #include <QFileInfo>
0013 
0014 namespace Ekos
0015 {
0016 
0017 SensorGraphic::SensorGraphic(const QWidget *parent, const int SW, const int SH, const int tileSize) :
0018     m_Parent(parent), m_SW(SW), m_SH(SH), m_tileSize(tileSize)
0019 {
0020     setWindowFlags(Qt::FramelessWindowHint | Qt::WindowTransparentForInput | Qt::WindowStaysOnTopHint);
0021 
0022     // Scale the Picture to 100 pixels in the largest dimension
0023     m_SW = std::max(100, m_SW);
0024     m_SH = std::max(100, m_SH);
0025     double scaling = static_cast<double>(std::max(m_SW, m_SH)) / 100.0;
0026     m_SW /= scaling;
0027     m_SH /= scaling;
0028     m_tileSize /= scaling;
0029 
0030     // Check if the picture resource exists
0031     QFileInfo check_file(m_picturePath);
0032     if (check_file.exists() || check_file.isFile())
0033     {
0034         m_PW = m_SW * 1.35;
0035         m_PH = m_SH * 1.4;
0036     }
0037     else
0038     {
0039         m_PW = m_SW;
0040         m_PH = m_SH;
0041         m_picturePath = "";
0042     }
0043     resize(m_PW, m_PH);
0044 }
0045 
0046 SensorGraphic::~SensorGraphic()
0047 {
0048 }
0049 
0050 void SensorGraphic::paintEvent(QPaintEvent *)
0051 {
0052     // Draw the picture with the correct width / height aspect
0053     QRectF sensor(0.0, 0.0, m_PW, m_PH);
0054     QPainter painter(this);
0055     // Check if the picture resource exists; if so use it otherwise draw a black box
0056     if (m_picturePath.isEmpty())
0057         painter.fillRect(sensor, "black");
0058     else
0059         painter.drawImage(sensor, QImage(m_picturePath));
0060 
0061     // Setup the 9 rectangular tiles of the mosaic relative to sensor (later we will adjust this relative to the picture)
0062     QRectF tiles[NUM_TILES];
0063     tiles[0].setRect(0, 0, m_tileSize, m_tileSize);
0064     tiles[1].setRect((m_SW - m_tileSize) / 2, 0, m_tileSize, m_tileSize);
0065     tiles[2].setRect(m_SW - m_tileSize, 0, m_tileSize, m_tileSize);
0066     tiles[3].setRect(0, (m_SH - m_tileSize) / 2, m_tileSize, m_tileSize);
0067     tiles[4].setRect((m_SW - m_tileSize) / 2, (m_SH - m_tileSize) / 2, m_tileSize, m_tileSize);
0068     tiles[5].setRect(m_SW - m_tileSize, (m_SH - m_tileSize) / 2, m_tileSize, m_tileSize);
0069     tiles[6].setRect(0, m_SH - m_tileSize, m_tileSize, m_tileSize);
0070     tiles[7].setRect((m_SW - m_tileSize) / 2, m_SH - m_tileSize, m_tileSize, m_tileSize);
0071     tiles[8].setRect(m_SW - m_tileSize, m_SH - m_tileSize, m_tileSize, m_tileSize);
0072 
0073     // Setup an offset point to translate from sensor coordinates to picture coordinates
0074     QPointF offset = QPointF((m_PW - m_SW) / 2, (m_PH - m_SH) / 2);
0075 
0076     // Loop through each mosaic tile painting it appropriately
0077     for (int i = 0; i < NUM_TILES; i++)
0078     {
0079         // If not interested in this tile do nothing
0080         if (!m_useTile[i])
0081             continue;
0082 
0083         // Translate from sensor coordinates to picture coordinates
0084         tiles[i].translate(offset);
0085 
0086         // Paint the tile grey to start with
0087         painter.fillRect(tiles[i], "white");
0088 
0089         if (i == m_Highlight)
0090         {
0091             painter.setPen(TILE_COLOUR[m_Highlight]);
0092             painter.drawRect(tiles[i]);
0093         }
0094         else
0095             painter.setPen("black");
0096 
0097         painter.drawText(tiles[i], Qt::AlignCenter, TILE_NAME[i]);
0098     }
0099 }
0100 
0101 void SensorGraphic::setHighlight(int highlight)
0102 {
0103     m_Highlight = highlight;
0104 }
0105 
0106 void SensorGraphic::setTiles(bool useTiles[NUM_TILES])
0107 {
0108     for (int i = 0; i < NUM_TILES; i++)
0109         m_useTile[i] = useTiles[i];
0110 }
0111 
0112 }