289 lines
13 KiB
C++
289 lines
13 KiB
C++
#include "IntermediateFrequencyWidget.h"
|
||
#include <QHBoxLayout>
|
||
#include <QVBoxLayout>
|
||
#include <QVector>
|
||
#include <QPainter>
|
||
#include <QDebug>
|
||
#include "../component/FrequentShower.h"
|
||
#include "../component/ProgressBar.h"
|
||
#include "../component/ConsoleWidget.h"
|
||
#include "../component/ShowTime.h"
|
||
#include "../Global.h"
|
||
#include "../BaseWidget.h"
|
||
#include "../menu/BaseWidgetMenu.h"
|
||
#include "../BackEnd/MainWidget.h"
|
||
#include "YSGraphic_Core/Demo_Gallery/export.h"
|
||
static YSG::Range frequent_range = {-12000, 12000};
|
||
static double max = 160;
|
||
QWidget* IntermediateFrequencyWidget::createSpectrogramPowerPlot() {
|
||
class SpectrumPlot : public YSG::Plot {
|
||
public:
|
||
YSG::Frequent_Axis* xAxis{};
|
||
YSG::Axis* yAxis{};
|
||
YSG::Muti_Select_Rect* msr{};
|
||
YSG::Spectrum* sp{};
|
||
QMenu* mMenu{};
|
||
void init() override {
|
||
Plot::init();
|
||
object_name = "SpectrumPlot";
|
||
xAxis = YSG::Frequent_Axis::Builder(this, Qt::Horizontal)
|
||
.set_tick_length(-10)
|
||
.set_coord_range(frequent_range)
|
||
.set_tick_length(-10)
|
||
.set_sub_tick_length(-5)
|
||
.build();
|
||
yAxis = YSG::Axis::Builder(this, Qt::Vertical)
|
||
.set_coord_range({160, 0})
|
||
.set_unit_text("功率")
|
||
.build();
|
||
sp = YSG::Spectrum::Builder(xAxis, yAxis)
|
||
.set_frequent_range(frequent_range)
|
||
.set_use_sweep_frequent_rect(true)
|
||
.set_frequent_point_size(1024)
|
||
.build();
|
||
msr = YSG::Muti_Select_Rect::Builder(xAxis, yAxis).build();
|
||
}
|
||
protected:
|
||
void resizeEvent(QResizeEvent* event) override {
|
||
xAxis->set_x(0);
|
||
xAxis->set_y(height() - 1);
|
||
xAxis->set_pixel_size(width());
|
||
yAxis->set_x(0);
|
||
yAxis->set_y(0);
|
||
yAxis->set_pixel_size(height());
|
||
}
|
||
void contextMenuEvent(QContextMenuEvent* event) override {
|
||
if (!mMenu) {
|
||
auto ws =
|
||
bw(cw(sp, -1), "频谱图") +
|
||
bw(cw(xAxis), "频率x轴") +
|
||
bw(cw(yAxis), "功率y轴") +
|
||
bw(cw(msr), "多选框");
|
||
mMenu = createMenu(this, ws);
|
||
}
|
||
mMenu->exec(event->globalPos());
|
||
}
|
||
};
|
||
auto w = new SpectrumPlot;
|
||
w->init();
|
||
mSpectrogramLine = w->sp;
|
||
mProgressBar1->mSetValue = [this]() {
|
||
double middleFrequent = this->mSpectrogramLine->frequent_range().center();
|
||
bool ok;
|
||
this->mProgressBar1->mValue = mSpectrogramLine->get_power(middleFrequent, ok, YSG::SRC::Edit);
|
||
};
|
||
return w;
|
||
}
|
||
QWidget* IntermediateFrequencyWidget::create_Afterglow_Plot() {
|
||
class AfterglowPlot : public YSG::Plot {
|
||
public:
|
||
YSG::Frequent_Axis* xAxis{};
|
||
YSG::Axis* yAxis{};
|
||
YSG::Afterglow* ag{};
|
||
YSG::Muti_Select_Rect* msr{};
|
||
QMenu* mMenu{};
|
||
void init() override {
|
||
Plot::init();
|
||
object_name = "AfterglowPlot";
|
||
xAxis = YSG::Frequent_Axis::Builder(this, Qt::Horizontal)
|
||
.set_coord_range(frequent_range)
|
||
.set_tick_length(-10)
|
||
.set_sub_tick_length(-5)
|
||
.set_use_drag(true)
|
||
.build();
|
||
yAxis = YSG::Axis::Builder(this, Qt::Vertical)
|
||
.set_coord_range({160, 0})
|
||
.set_use_drag(true)
|
||
.build();
|
||
ag = YSG::Afterglow::Builder(xAxis, yAxis)
|
||
.set_frequent_range(frequent_range)
|
||
.set_power_range({0, 160})
|
||
.set_frequent_point_size(1024)
|
||
.build();
|
||
msr = YSG::Muti_Select_Rect::Builder(xAxis, yAxis).build();
|
||
}
|
||
protected:
|
||
void resizeEvent(QResizeEvent* event) override {
|
||
xAxis->set_x(0);
|
||
xAxis->set_y(height() - 1);
|
||
xAxis->set_pixel_size(width());
|
||
yAxis->set_x(0);
|
||
yAxis->set_y(0);
|
||
yAxis->set_pixel_size(height());
|
||
ag->set_power_point_size(ag->power_axis()->get_pixel_point_size());
|
||
}
|
||
void contextMenuEvent(QContextMenuEvent* event) override {
|
||
if (!mMenu) {
|
||
auto ws =
|
||
bw(cw(ag, -1), "余辉图") +
|
||
bw(cw(xAxis), "频率轴") +
|
||
bw(cw(yAxis), "功率概率轴") +
|
||
bw(cw(msr), "多选框");
|
||
mMenu = createMenu(this, ws);
|
||
}
|
||
mMenu->exec(event->globalPos());
|
||
}
|
||
};
|
||
auto w = new AfterglowPlot;
|
||
w->init();
|
||
mAfterglow = w->ag;
|
||
return w;
|
||
}
|
||
//mAM, mATU, mVSQL, mNB, mNR, mDNF, mPRE, mATT, mSPL, mFIL1, mAGC_A
|
||
IntermediateFrequencyWidget::IntermediateFrequencyWidget(QWidget* parent) : BaseWidget(parent) {
|
||
setObjectName("发射界面");
|
||
int fontSize = 20;
|
||
m1 = createNormal("RF Gain\n62", fontSize);
|
||
m2 = createNormal("FFT SPAN\n100K", fontSize);
|
||
m3 = createNormal("频率表\n(12)89.6MHZ", fontSize);
|
||
m4 = createNormal("MODEM\nRTTY", fontSize);
|
||
m5 = createNormal("FIL1\n20K", fontSize);
|
||
m6 = createNormal("MSG1\n", fontSize);
|
||
mFrequentShower = new FrequentShower(this);
|
||
QColor orange(255, 165, 0);
|
||
mProgressBar1 = new ProgressBar({
|
||
Tick("S", Qt::black),
|
||
{"3", Qt::black},
|
||
{"6", Qt::black},
|
||
{"9", Qt::black},
|
||
{"20", Qt::black},
|
||
{"+40", orange},
|
||
{"+60", orange},
|
||
{"+80", orange},
|
||
{"+100", Qt::red},
|
||
}, this);
|
||
mProgressBar2 = new ProgressBar({
|
||
{"1", Qt::black},
|
||
{"2", Qt::yellow},
|
||
{"3", Qt::red},
|
||
{">5", Qt::red},
|
||
}, this);
|
||
auto main = createVBoxLayout({}, this);
|
||
main->addStretch(1);
|
||
{
|
||
auto center = createHBoxLayout();
|
||
main->addLayout(center, 7);
|
||
auto front = createVBoxLayout();
|
||
center->addLayout(front, 1);
|
||
front->addWidget(m1, 3);
|
||
front->addStretch(1);
|
||
front->addWidget(m2, 3);
|
||
center->addSpacing(4);
|
||
auto middle = createVBoxLayout();
|
||
center->addLayout(middle, 9);
|
||
middle->addStretch(1);
|
||
middle->addWidget(mFrequentShower, 4);
|
||
auto middleH = createHBoxLayout();
|
||
middle->addLayout(middleH, 2);
|
||
middleH->addWidget(mProgressBar1, 5);
|
||
middleH->addStretch(1);
|
||
middleH->addWidget(mProgressBar2, 3);
|
||
center->addStretch(4);
|
||
auto back1 = createVBoxLayout();
|
||
center->addLayout(back1, 1);
|
||
back1->addWidget(m3, 3);
|
||
back1->addStretch(1);
|
||
back1->addWidget(m4, 3);
|
||
center->addSpacing(4);
|
||
auto back2 = createVBoxLayout();
|
||
center->addLayout(back2, 1);
|
||
back2->addWidget(m5, 3);
|
||
back2->addStretch(1);
|
||
back2->addWidget(m6, 3);
|
||
}
|
||
main->addStretch(1);
|
||
main->addSpacing(8);
|
||
auto aH = createHBoxLayout();
|
||
main->addLayout(aH, 12);
|
||
aH->addWidget(createSpectrogramPowerPlot(), 12);
|
||
aH->addSpacing(8);
|
||
main->addWidget(create_Afterglow_Plot(), 12);
|
||
initMenu();
|
||
}
|
||
IntermediateFrequencyWidget::~IntermediateFrequencyWidget() {}
|
||
void IntermediateFrequencyWidget::focusInEvent(QFocusEvent* event) {
|
||
QWidget::focusInEvent(event);
|
||
mFrequentShower->setFocus();
|
||
}
|
||
void IntermediateFrequencyWidget::initMenu() {
|
||
int fontSize = 30;
|
||
auto btn1 = new DoubleTextMenuButton("设置最大值标记", "取消最大值标记", fontSize, [&](bool isFirst) {
|
||
mSpectrogramLine->set_use_max_marker(isFirst);
|
||
mBaseWidgetMenu->hide();
|
||
MainWidget::instance()->getCurrentBaseWidget()->setFocus();
|
||
});
|
||
auto btn2 = new DoubleTextMenuButton("设置最小值标记", "取消最小值标记", fontSize, [&](bool isFirst) {
|
||
mSpectrogramLine->set_use_min_marker(isFirst);
|
||
mBaseWidgetMenu->hide();
|
||
MainWidget::instance()->getCurrentBaseWidget()->setFocus();
|
||
});
|
||
auto btn3 = new MenuButton("设置自定义标记", fontSize, [&]() {
|
||
mBaseWidgetMenu->hide();
|
||
MainWidget::instance()->getCurrentBaseWidget()->setFocus();
|
||
});
|
||
auto frequentStep2 = new ValueMenuButton("频率步进:%1", fontSize, [this](ValueMenuButton* that, bool add) {
|
||
int newFrequent = (int)that->mValue + (add ? 1 : -1);
|
||
that->setValue(newFrequent);
|
||
mSpectrogramLine->set_current_marker_frequent(newFrequent);
|
||
}, qMax(0.0, mSpectrogramLine->frequent_range().length() / 50.0));
|
||
auto btn_middleFrequent = new ValueMenuButton("中频:%1 Hz", fontSize, nullptr, mSpectrogramLine->middle_sweep_frequent());
|
||
auto btn_frequentWidth = new ValueMenuButton("频宽:%1 Hz", fontSize, [this, frequentStep2](ValueMenuButton* that, bool add) {
|
||
that->setValue(that->mValue + (double)(add ? frequentStep2->mValue : -frequentStep2->mValue));
|
||
double middle_sweep_frequent = mSpectrogramLine->middle_sweep_frequent();
|
||
mSpectrogramLine->set_sweep_frequent_range({middle_sweep_frequent - that->mValue, middle_sweep_frequent + that->mValue});
|
||
}, qAbs(mSpectrogramLine->sweep_frequent_range().length() / 2));
|
||
btn_middleFrequent->mValueChanged = [this, btn_frequentWidth, frequentStep2](ValueMenuButton* that, bool add) {
|
||
that->setValue(that->mValue + (double)(add ? frequentStep2->mValue : -frequentStep2->mValue));
|
||
mSpectrogramLine->set_middle_sweep_frequent(that->mValue);
|
||
mSpectrogramLine->set_sweep_frequent_range({that->mValue - btn_frequentWidth->mValue, that->mValue + btn_frequentWidth->mValue});
|
||
};
|
||
auto btn2_2 = new ValueMenuButton("参考增益:%1", fontSize, [&](ValueMenuButton* that, bool add) {
|
||
that->setValue(that->mValue + (double)(add ? 1 : -1));
|
||
}, 0);
|
||
mBaseWidgetMenu->addMenuButtonOnLayout1({btn1, btn2, btn3, btn2_2,});
|
||
mBaseWidgetMenu->addMenuButtonOnLayout2({frequentStep2, btn_middleFrequent, btn_frequentWidth,});
|
||
BaseWidgetMenu* sub1 = mBaseWidgetMenu->createSubWidgetMenu(btn3);
|
||
auto frequentStep = new ValueMenuButton("频率步进:%1", fontSize, [this](ValueMenuButton* that, bool add) {
|
||
int newFrequent = (int)that->mValue + (add ? 1 : -1);
|
||
that->setValue(newFrequent);
|
||
mSpectrogramLine->set_current_marker_frequent(newFrequent);
|
||
}, qMax(0.0, mSpectrogramLine->frequent_range().length() / 50.0));
|
||
auto markFrequent = new ValueMenuButton("更改标记频率:%1", fontSize, [frequentStep, this](ValueMenuButton* that, bool add) {
|
||
int newFrequent = (int)that->mValue + (add ? frequentStep->mValue : -frequentStep->mValue);
|
||
that->setValue(newFrequent);
|
||
mSpectrogramLine->set_current_marker_frequent(newFrequent);
|
||
}, -1);
|
||
auto addInitFrequent = new ValueMenuButton("添加初始频率:%1", fontSize, [frequentStep,this](ValueMenuButton* that, bool add) {
|
||
int newFrequent = (int)that->mValue + (add ? frequentStep->mValue : -frequentStep->mValue);
|
||
that->setValue(newFrequent);
|
||
}, mSpectrogramLine->frequent_range().lower);
|
||
auto btn1_1 = new ValueMenuButton("当前标记:%1", fontSize, [&, markFrequent](ValueMenuButton* that, bool add) {
|
||
int index = ((int)that->mValue + (add ? 1 : -1)) % mSpectrogramLine->select_line_marker_size();
|
||
that->setValue(index);
|
||
mSpectrogramLine->set_selected_line_marker(index);
|
||
markFrequent->setValue(mSpectrogramLine->get_mark_frequent(index));
|
||
}, -1);
|
||
auto btn1_2 = new MenuButton("添加标记", fontSize, [&, addInitFrequent]() {
|
||
mSpectrogramLine->add_custom_line_marker(addInitFrequent->mValue);
|
||
});
|
||
auto btn1_3 = new MenuButton("删除标记", fontSize, [&]() {
|
||
mSpectrogramLine->remove_current_marker();
|
||
int size = mSpectrogramLine->select_line_marker_size();
|
||
if (size == 0) {
|
||
mSpectrogramLine->set_selected_line_marker(-1);
|
||
}
|
||
else {
|
||
mSpectrogramLine->set_selected_line_marker(0);
|
||
}
|
||
});
|
||
connect(sub1, &BaseWidgetMenu::showThat, [&, markFrequent]() {
|
||
mSpectrogramLine->set_selected_line_marker(0);
|
||
markFrequent->setValue(mSpectrogramLine->get_mark_frequent(0));
|
||
});
|
||
connect(sub1, &BaseWidgetMenu::hideThat, [&]() {
|
||
mSpectrogramLine->un_select_marker();
|
||
});
|
||
sub1->addMenuButtonOnLayout1({btn1_1, btn1_2, btn1_3}, 2);
|
||
sub1->addMenuButtonOnLayout2({frequentStep, markFrequent, addInitFrequent}, 2);
|
||
}
|