/*
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                 ┃
┃            Class Name: GammaSmith.h                                                             ┃
┃                Author: Michael Krämer                                                           ┃
┃                 Email: Michael@dk8pp.de                                                         ┃
┃                  Date: 27.11.2024 13:25:54                                                      ┃
┃                  Tool: Qt                                                                       ┃
┃                Device: Windows/Linux                                                            ┃
┃               Version: 0.1                                                                      ┃
┃        Program status: still testing                                                            ┃
┃                                                                                                 ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃                                                                                                 ┃
┃  Purpose: Display Gamma-/Smith-chart                                                            ┃
┃                                                                                                 ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃                                                                                                 ┃
┃  © Copyright 2025 Michael Krämer, DK8PP                                                         ┃
┃                                                                                                 ┃
┃  This program is free software: you can redistribute it and/or modify it under the terms of     ┃
┃  the GNU Lesser General Public License as published by the Free Software Foundation, either     ┃
┃  version 3 of the License, or (at your option) any later version.                               ┃
┃                                                                                                 ┃
┃  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;      ┃
┃  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.      ┃
┃  See the GNU Lesser General Public License for more details.                                    ┃
┃                                                                                                 ┃
┃  You should have received a copy of the GNU Lesser General Public License along with this       ┃
┃  program.   If not, see <http://www.gnu.org/licenses/>.                                         ┃
┃                                                                                                 ┃
┃  ============================================================================================   ┃
┃                                                                                                 ┃
┃  Dieses Programm ist Freie Software: Sie können es unter den Bedingungen der GNU Lesser         ┃
┃  General Public License, wie von der Free Software Foundation, Version 3 der Lizenz oder        ┃
┃  (nach Ihrer Wahl) jeder neueren veröffentlichten Version, weiter verteilen und/oder            ┃
┃  modifizieren.                                                                                  ┃
┃                                                                                                 ┃
┃  Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch OHNE   ┃
┃  JEDE GEWÄHR,; sogar ohne die implizite Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN        ┃
┃  BESTIMMTEN ZWECK. Siehe die GNU Lesser General Public License für weitere Einzelheiten.        ┃
┃                                                                                                 ┃
┃  Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit diesem Programm      ┃
┃  erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.                             ┃
┃                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
#ifndef GAMMASMITH_H
#define GAMMASMITH_H

/*
╭─────────────────────────────────────────────────────────────────────────────────────────────────╮
│       Includes                                                                                  │
╰─────────────────────────────────────────────────────────────────────────────────────────────────╯
*/
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QGraphicsSceneWheelEvent>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsEllipseItem>
#include <QDoubleSpinBox>
#include <QTimer>
#include <QPainter>
#include <QPaintDevice>
#include <QPainterPath>
#include <QQuickWidget>
#include <QGraphicsSimpleTextItem>
#include <QMenu>
#include <QFont>
#include <QSettings>
#include <complex>
#include "SmithBasics.h"
#include "infodialog.h"

/*
╭─────────────────────────────────────────────────────────────────────────────────────────────────╮
│       Defines                                                                                   │
╰─────────────────────────────────────────────────────────────────────────────────────────────────╯
*/
/* definitions for registry */
#define OrganizationName QString("DK8PP Freeware")
#define ApplicationName QString("GammaSmith")
#define KEY_PGM QString("Program/")
#define KEY_SMITH QString("SmithChart/")

/* program information */
#define PURPOSE "Purpose: Blend between reflection coefficent Gamma and Smith Chart\n\n"
#define PROGRAMVERSION 10               /* will be displayed as n.nn */
#define AUTHOR "Michael Krämer, DK8PP"
#define COPYRIGHT " Copyright © 2024-2025 "
#define COPYRIGHTDETAILS "\nThis program comes with ABSOLUTELY NO WARRANTY;\n" \
                         "This is free software, and you are welcome to redistribute it under certain conditions.\n" \
                         "Press the LGPL button for details.\n\n"
#define VERSION_STRING (" - Version " + QString::number(PROGRAMVERSION/100) + "." + QString::number(PROGRAMVERSION%100).rightJustified(2,'0'))
#define COMPILE_DT (QString("compiled on ") + __DATE__ + ", " + __TIME__)

#define PROGRAM_INFO \
           ApplicationName + VERSION_STRING + ", " + COMPILE_DT + "\n\n" + \
           PURPOSE + ApplicationName + COPYRIGHT + AUTHOR + COPYRIGHTDETAILS + \
           "for updates check: http://freeware.dk8pp.de/ or email to: Michael@dk8pp.de"

#define _USE_MATH_DEFINES
#define Z0 50.0         /* real part of reference impedance */
constexpr int swr_circle_count = 2 ; /* count of SWR circles */
constexpr int RES_COUNT = 200 ; /* count of resistance values for slider movement */

/*
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                 ┃
┃  Class definitions                                                                              ┃
┃                                                                                                 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/

QT_BEGIN_NAMESPACE
namespace Ui {
class GammaSmith;
}
QT_END_NAMESPACE

/*
╭─────────────────────────────────────────────────────────────────────────────────────────────────╮
│       MainWindow                                                                                │
╰─────────────────────────────────────────────────────────────────────────────────────────────────╯
*/
class MainWindow : public QMainWindow, public SmithBasics
{
   Q_OBJECT

public:
   MainWindow(QWidget *parent = nullptr);
   ~MainWindow();
   void updateSlider() ;
   void updateEdits() ;
   void read_spb();
   void open_smith() ;
   void close_smith() ;

public slots:
   void QS_setR(int value);
   void QS_setX(int value) ;
   void QS_setG(int value);
   void QS_setB(int value) ;
   void LED_setR();
   void LED_setX();
   void LED_setG();
   void LED_setB();
   void LED_setGammaR() ;
   void LED_setGammaI() ;
   void LED_setGammaM() ;
   void LED_setGammaP() ;
   void NewGamma(complex_dbl new_gamma) ;

protected:
   void resizeEvent(QResizeEvent *event) override ;
   void closeEvent(QCloseEvent *event) override ;

private slots:
   void on_PUB_Info_clicked();

private:
   std::complex<double> z0 = {Z0, 0.0} ;          /* complex reference impedance */
   std::complex<double> gamma = {0.0, 0.0} ;      /* complex gamma */
   Ui::GammaSmith *ui;
   bool updating_ZL = false ;
   void loadSettings() ;
   void saveSettings() ;
   void Init_Controls() ;
   void opacity(int value) ;
   std::array <double,swr_circle_count> swr = {1.0, 1.0} ; /* SWR circles */
   std::array <qreal, RES_COUNT> reslist ;
   QString ProgramInfo = PROGRAM_INFO ;

} ;

#endif // GAMMASMITH_H
