mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-21 19:55:20 -05:00
3dd824ad6b
The Rx meter is now a better Qt citizen and can be resized. Added a more obvious peak signal indicator. It is now a custom widget derived from QFrame and is now directly added via promotion in Designer. Added a custom widget to act as a letter spin box, this is used for sub mode control. Switched the frequency tolerance widget to a combo box with preset values so that it is more uniform across systems and font sizes. Added container widgets for group control of various UI widgets such as QSO controls, DX call controls and WSPR controls. Introduced a stacked widget to allow the WSPR controls to be swapped in in place of the "QSO" controls. The "QSO" controls are are the Rx, Tx and related controls along with the main tab widget with the message buttons and fields. This means that the WSPR version of the main window (and EME Echo mode) are now much cleaner. Increased the size of the rig control widget and styled its colour using a dynamic property so that it can be defined in the Designer UI definition. Reinstated it as a push button to do a rig control reset and retry after an error. Reset most UI widgets to default properties, particularly removing any fixed sizes so that they can resize freely when fonts are changed. The overall layout is now controlled almost exclusively by stretch factors on some of the rows and columns of the various grid layout managers. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5630 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
99 lines
2.7 KiB
C++
99 lines
2.7 KiB
C++
// Simple bargraph dB meter
|
|
// Implemented by Edson Pereira PY2SDR
|
|
//
|
|
|
|
#include "signalmeter.h"
|
|
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QPainter>
|
|
#include <QFontMetrics>
|
|
|
|
#include <meterwidget.h>
|
|
|
|
#include "moc_signalmeter.cpp"
|
|
|
|
class Scale final
|
|
: public QWidget
|
|
{
|
|
public:
|
|
explicit Scale (QWidget * parent = 0)
|
|
: QWidget {parent}
|
|
{
|
|
setSizePolicy (QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
|
|
}
|
|
|
|
QSize sizeHint () const override
|
|
{
|
|
return minimumSizeHint ();
|
|
}
|
|
|
|
QSize minimumSizeHint () const override
|
|
{
|
|
QFontMetrics font_metrics {font (), nullptr};
|
|
return {tick_length + text_indent + font_metrics.width ("00+"), (font_metrics.height () + line_spacing) * range};
|
|
}
|
|
|
|
protected:
|
|
void paintEvent (QPaintEvent * event) override
|
|
{
|
|
QWidget::paintEvent (event);
|
|
|
|
QPainter p {this};
|
|
auto const& target = contentsRect ();
|
|
QFontMetrics font_metrics {p.font (), this};
|
|
auto font_offset = font_metrics.ascent () / 2;
|
|
p.drawLine (target.left (), target.top () + font_offset, target.left (), target.bottom () - font_offset - font_metrics.descent ());
|
|
for (int i = 0; i <= range; ++i)
|
|
{
|
|
p.save ();
|
|
p.translate (target.left ()
|
|
, target.top () + font_offset + i * (target.height () - font_metrics.ascent () - font_metrics.descent ()) / range);
|
|
p.drawLine (0, 0, tick_length, 0);
|
|
auto text = i ? QString::number ((range - i) * scale) : QString {"%1%2"}.arg ((range - i) * scale).arg ('+');
|
|
p.drawText (tick_length + text_indent, font_offset, text);
|
|
p.restore ();
|
|
}
|
|
}
|
|
|
|
private:
|
|
static int const tick_length {4};
|
|
static int const text_indent {2};
|
|
static int const line_spacing {0};
|
|
static int const range {6};
|
|
static int const scale {10};
|
|
};
|
|
|
|
SignalMeter::SignalMeter (QWidget * parent)
|
|
: QFrame {parent}
|
|
{
|
|
auto outer_layout = new QVBoxLayout;
|
|
outer_layout->setSpacing (0);
|
|
|
|
auto inner_layout = new QHBoxLayout;
|
|
inner_layout->setContentsMargins (9, 0, 9, 0);
|
|
inner_layout->setSpacing (0);
|
|
|
|
m_meter = new MeterWidget;
|
|
m_meter->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
inner_layout->addWidget (m_meter);
|
|
|
|
m_scale = new Scale;
|
|
inner_layout->addWidget (m_scale);
|
|
|
|
m_reading = new QLabel(this);
|
|
|
|
outer_layout->addLayout (inner_layout);
|
|
outer_layout->addWidget (m_reading);
|
|
setLayout (outer_layout);
|
|
}
|
|
|
|
void SignalMeter::setValue(int value)
|
|
{
|
|
QFontMetrics font_metrics {m_scale->font (), nullptr};
|
|
m_meter->setContentsMargins (0, font_metrics.ascent () / 2, 0, font_metrics.ascent () / 2 + font_metrics.descent ());
|
|
m_meter->setValue(value);
|
|
m_reading->setText (QString {"%1dB"}.arg (value, 4));
|
|
}
|