2021-02-24 08:18:19 +00:00
|
|
|
#ifndef METER_H
|
|
|
|
#define METER_H
|
|
|
|
|
2024-02-06 05:03:08 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QComboBox>
|
2021-02-24 08:18:19 +00:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QPainter>
|
2025-02-17 19:20:26 +00:00
|
|
|
#include <QImage>
|
2025-02-21 17:57:10 +00:00
|
|
|
#include <QFontMetrics>
|
2021-07-18 21:27:21 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <numeric>
|
2025-02-21 17:57:10 +00:00
|
|
|
#include <math.h>
|
2021-07-20 06:46:11 +00:00
|
|
|
#include <cmath>
|
2021-02-24 08:18:19 +00:00
|
|
|
|
2021-07-17 00:45:07 +00:00
|
|
|
#include "rigcommander.h" // for meter types
|
2022-08-24 06:10:58 +00:00
|
|
|
#include "audiotaper.h"
|
2021-07-17 00:45:07 +00:00
|
|
|
|
2021-02-24 08:18:19 +00:00
|
|
|
class meter : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit meter(QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
signals:
|
2024-02-06 05:03:08 +00:00
|
|
|
void configureMeterSignal(meter_t type);
|
2021-02-24 08:18:19 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void paintEvent(QPaintEvent *);
|
|
|
|
|
|
|
|
void updateDrawing(int num);
|
2025-02-15 18:24:33 +00:00
|
|
|
void setLevels(double current, double peak, double average);
|
|
|
|
void setLevels(double current, double peak); // calculate avg
|
|
|
|
void setLevel(double current);
|
2024-02-06 19:06:50 +00:00
|
|
|
void setCompReverse(bool reverse);
|
2025-02-17 22:36:32 +00:00
|
|
|
void setUseGradients(bool useGrads);
|
2021-08-21 05:19:47 +00:00
|
|
|
void clearMeterOnPTTtoggle();
|
|
|
|
void clearMeter();
|
2023-05-15 12:47:45 +00:00
|
|
|
void setMeterType(meter_t type);
|
2021-07-20 06:46:11 +00:00
|
|
|
void setMeterShortString(QString);
|
|
|
|
QString getMeterShortString();
|
2023-05-15 12:47:45 +00:00
|
|
|
meter_t getMeterType();
|
2022-08-23 04:22:01 +00:00
|
|
|
void setColors(QColor current, QColor peakScale, QColor peakLevel,
|
2022-08-21 23:47:17 +00:00
|
|
|
QColor average, QColor lowLine,
|
|
|
|
QColor lowText);
|
2024-02-06 05:03:08 +00:00
|
|
|
void blockMeterType(meter_t type);
|
2021-02-24 08:18:19 +00:00
|
|
|
|
2024-11-06 09:27:15 +00:00
|
|
|
void enableCombo(bool en) { combo->setEnabled(en); }
|
2025-02-17 18:29:05 +00:00
|
|
|
void setMeterExtremities(double min, double max, double redline);
|
2024-11-06 09:27:15 +00:00
|
|
|
|
2024-02-06 05:03:08 +00:00
|
|
|
private slots:
|
|
|
|
void acceptComboItem(int item);
|
2021-02-24 08:18:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
//QPainter painter;
|
2024-02-06 05:03:08 +00:00
|
|
|
bool eventFilter(QObject *object, QEvent *event);
|
|
|
|
void handleDoubleClick();
|
|
|
|
bool freezeDrawing = false;
|
|
|
|
QComboBox *combo = NULL;
|
2025-02-17 19:20:26 +00:00
|
|
|
QImage *scaleCache = NULL;
|
|
|
|
bool scaleReady = false;
|
2023-05-15 12:47:45 +00:00
|
|
|
meter_t meterType;
|
2025-02-17 18:29:05 +00:00
|
|
|
meter_t lastDrawMeterType;
|
|
|
|
bool recentlyChangedParameters = false;
|
2021-07-20 06:46:11 +00:00
|
|
|
QString meterShortString;
|
2025-02-17 18:29:05 +00:00
|
|
|
double scaleMin = 0;
|
|
|
|
double scaleMax = 255;
|
|
|
|
double scaleRedline = 128;
|
|
|
|
bool haveExtremities = false;
|
2024-02-06 05:39:23 +00:00
|
|
|
bool haveUpdatedData = false;
|
2025-02-17 18:29:05 +00:00
|
|
|
bool haveReceivedSomeData = false;
|
2021-07-20 06:46:11 +00:00
|
|
|
int fontSize = 10;
|
2021-02-24 08:18:19 +00:00
|
|
|
int length=30;
|
2025-02-15 18:24:33 +00:00
|
|
|
double current=0.0;
|
|
|
|
double peak = 0.0;
|
|
|
|
double average = 0.0;
|
2025-02-17 18:29:05 +00:00
|
|
|
int currentRect = 0;
|
|
|
|
int averageRect = 0;
|
|
|
|
int peakRect = 0;
|
2024-11-05 18:46:21 +00:00
|
|
|
|
2024-02-06 19:06:50 +00:00
|
|
|
bool reverseCompMeter = true;
|
2021-02-24 08:18:19 +00:00
|
|
|
|
2021-07-18 21:27:21 +00:00
|
|
|
int averageBalisticLength = 30;
|
|
|
|
int peakBalisticLength = 30;
|
|
|
|
int avgPosition=0;
|
|
|
|
int peakPosition=0;
|
2025-02-17 18:29:05 +00:00
|
|
|
std::vector<double_t> avgLevels;
|
|
|
|
std::vector<double_t> peakLevels;
|
2021-07-18 21:27:21 +00:00
|
|
|
|
2021-07-18 06:39:40 +00:00
|
|
|
int peakRedLevel=0;
|
2021-08-17 06:25:11 +00:00
|
|
|
bool drawLabels = true;
|
2025-02-21 17:57:10 +00:00
|
|
|
int labelWidth = 0;
|
2025-02-17 22:36:32 +00:00
|
|
|
bool useGradients = true;
|
2021-07-20 06:46:11 +00:00
|
|
|
int mXstart = 0; // Starting point for S=0.
|
2021-07-17 00:45:07 +00:00
|
|
|
int mYstart = 14; // height, down from top, where the drawing starts
|
|
|
|
int barHeight = 10; // Height of meter "bar" indicators
|
|
|
|
int scaleLineYstart = 12;
|
2021-07-17 07:37:27 +00:00
|
|
|
int scaleTextYstart = 10;
|
2021-07-17 00:45:07 +00:00
|
|
|
|
2021-07-20 06:46:11 +00:00
|
|
|
int widgetWindowHeight = mYstart + barHeight + 0; // height of drawing canvis.
|
2021-02-24 08:18:19 +00:00
|
|
|
|
2025-02-17 18:29:05 +00:00
|
|
|
// These functions scale the data to fit the meter:
|
|
|
|
void prepareValue_dBuEMFdBm();
|
|
|
|
void scaleLinearNumbersForDrawing(); // input = current, average, peak, output = currentRect, averageRect, peakRect
|
|
|
|
void scaleLogNumbersForDrawing(); // for audio
|
|
|
|
double getValueFromPixelScale(int p); // pixel (0-255) scale to values
|
|
|
|
int getPixelScaleFromValue(double v); // scale value to pixel (0-255)
|
2025-02-21 17:57:10 +00:00
|
|
|
int nearestStep(double val, int stepSize); // round to nearest step
|
2025-02-17 18:29:05 +00:00
|
|
|
|
|
|
|
// These functions draw the rectangular bars
|
|
|
|
// for the level(s) to be represented:
|
|
|
|
void drawValue_Linear(QPainter *qp, bool reverse); // anything you wish 0-255
|
|
|
|
void drawValue_Log(QPainter *qp);
|
|
|
|
void drawValue_Center(QPainter *qp);
|
|
|
|
|
|
|
|
|
|
|
|
// These functions draw the meter scale:
|
2025-02-17 19:20:26 +00:00
|
|
|
void regenerateScale(QPainter *screenPainterHints);
|
|
|
|
void recallScale(QPainter *qp);
|
2021-07-17 00:45:07 +00:00
|
|
|
void drawScaleS(QPainter *qp);
|
2021-07-18 21:27:21 +00:00
|
|
|
void drawScaleCenter(QPainter *qp);
|
2021-07-17 00:45:07 +00:00
|
|
|
void drawScalePo(QPainter *qp);
|
|
|
|
void drawScaleRxdB(QPainter *qp);
|
|
|
|
void drawScaleALC(QPainter *qp);
|
2021-07-17 07:37:27 +00:00
|
|
|
void drawScaleSWR(QPainter *qp);
|
2021-07-17 00:45:07 +00:00
|
|
|
void drawScaleVd(QPainter *qp);
|
|
|
|
void drawScaleId(QPainter *qp);
|
2021-08-17 06:25:11 +00:00
|
|
|
void drawScaleComp(QPainter *qp);
|
2024-02-06 19:06:50 +00:00
|
|
|
void drawScaleCompInverted(QPainter *qp);
|
2022-08-24 06:10:58 +00:00
|
|
|
void drawScale_dBFs(QPainter *qp);
|
2021-07-18 21:27:21 +00:00
|
|
|
void drawScaleRaw(QPainter *qp);
|
2025-02-21 17:57:10 +00:00
|
|
|
void drawScaledBPositive(QPainter *qp);
|
|
|
|
void drawScaledBNegative(QPainter *qp);
|
2021-02-24 08:18:19 +00:00
|
|
|
|
2021-08-17 06:25:11 +00:00
|
|
|
void drawLabel(QPainter *qp);
|
2024-02-06 05:03:08 +00:00
|
|
|
void muteSingleComboItem(QComboBox *comboBox, int index);
|
2024-11-06 09:27:15 +00:00
|
|
|
void enableAllComboBoxItems(QComboBox *combobox, bool en=true);
|
2024-02-06 05:03:08 +00:00
|
|
|
void setComboBoxItemEnabled(QComboBox * comboBox, int index, bool enabled);
|
|
|
|
|
2021-08-17 06:25:11 +00:00
|
|
|
QString label;
|
|
|
|
|
2021-02-24 08:18:19 +00:00
|
|
|
QColor currentColor;
|
|
|
|
QColor averageColor;
|
|
|
|
QColor peakColor;
|
|
|
|
// S0-S9:
|
|
|
|
QColor lowTextColor;
|
|
|
|
QColor lowLineColor;
|
|
|
|
// S9+:
|
|
|
|
QColor highTextColor;
|
|
|
|
QColor highLineColor;
|
|
|
|
|
2022-08-23 04:22:01 +00:00
|
|
|
QColor midScaleColor;
|
|
|
|
QColor centerTuningColor;
|
|
|
|
|
2021-02-24 08:18:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // METER_H
|