#include #include #include #include #include "mainwindow.h" #include "ui_mainwindow.h" /* #undef qDebug #define qDebug(p, ...) */ static const char * TrigerChannelTexts [] = { "Channel A", "Channel B" }; static const char * TrigerModeTexts [] = { "Auto", "Normal", "Single" }; static const char * TrigerEdgeTexts [] = { "Rising", "Faling" }; static const char * TrigerSelectTexts [] = { "Trig.Value", "Trig.Offset", "Marker A", "Marker B", "Time Zoom" }; static const char * TimeBaseTexts [] = { "2μs", "5μs", "10μs", "20μs", "50μs", "100μs", "200μs","500μs", "1ms", "2ms", "5ms", "10ms", "20ms", "50ms", "100ms", "200ms", "500ms", "1s", }; MainWindow::MainWindow (QWidget * parent) : QMainWindow (parent), firmware(parent) { ui = new Ui_MainWindow; ui->setupUi (this); ui->radio_a->setChecked(true); ui->Display->setTrigger (firmware.getTrigger()); for (auto & e: TrigerModeTexts) ui->comboMode ->addItem(QString(e)); for (auto & e: TrigerChannelTexts) ui->comboChannel ->addItem(QString(e)); for (auto & e: TrigerEdgeTexts) ui->comboRissing ->addItem(QString(e)); for (auto & e: TrigerSelectTexts) ui->comboValue ->addItem(QString(e)); for (auto & e: TimeBaseTexts) ui->comboTimeRange->addItem(QString(e)); setWindowTitle ("Scope"); setWindowIcon (QIcon(":ico")); //setWindowFlags(Qt::Window | Qt::FramelessWindowHint); connect (&firmware, SIGNAL (Channels_received(QVector, QVector)), ui->Display, SLOT (DispChannels (QVector, QVector))); connect (&firmware, SIGNAL (PaketTriggered()), this, SLOT(PaketTriggered())); connect (ui->Display, SIGNAL(SettingsChanged(int)), &firmware, SLOT(SettingChanged(int))); connect (ui->buttonStart,SIGNAL(pressed()), this, SLOT(Started())); connect (ui->actionQuit, SIGNAL(triggered(bool)), this, SLOT(close())); connect (ui->radio_a, SIGNAL(toggled(bool)), this, SLOT(MarkerChanged(bool))); connect (ui->actionExport_Image, SIGNAL(triggered(bool)), this, SLOT(ExportImage (bool))); connect (ui->actionSaveSet, SIGNAL(triggered(bool)), this, SLOT(SaveSettings(bool))); connect (ui->actionRestSet, SIGNAL(triggered(bool)), this, SLOT(RestSettings(bool))); connect (ui->comboMode, SIGNAL(activated(int)), this, SLOT(SendTrigerMode(int))); connect (ui->comboRissing, SIGNAL(activated(int)), this, SLOT(SendTrigerEdge(int))); connect (ui->comboChannel, SIGNAL(activated(int)), this, SLOT(SendTrigerChan(int))); connect (ui->comboValue, SIGNAL(activated(int)), this, SLOT(TriggerValues (int))); connect (ui->comboTimeRange, SIGNAL(activated(int)), this, SLOT(TimeBaseRange (int))); ui->comboTimeRange->setCurrentIndex(6); ui->buttonStart->setEnabled(false); } MainWindow::~MainWindow () { delete ui; } void MainWindow::Started() { firmware.Start(); } void MainWindow::MarkerChanged(bool b) { ui->Display->MarkerChanged (b); } void MainWindow::TriggerValues (int n) { ui->Display->TriggerValues(n); } void MainWindow::SendTrigerMode (int n) { if (n == TRIGER_MODE_SINGLE) ui->buttonStart->setEnabled(true); else ui->buttonStart->setEnabled(false); firmware.SendTrigerMode(n); } void MainWindow::SendTrigerEdge (int n) { firmware.SendTrigerEdge(n); } void MainWindow::SendTrigerChan (int n) { firmware.SendTrigerChan(n); } void MainWindow::TimeBaseRange (int n) { firmware.SendBaseRange(n); ui->Display->TimeBaseRange(n); } void MainWindow::PaketTriggered () { statusBar()->showMessage(QString("TRIGER"), 500); } void MainWindow::ExportImage (bool) { QWidget * pw = ui->Display; QString fileName = QFileDialog::getSaveFileName (this, tr ("Save File"), ".", "Images Files(*.png)"); if (!fileName.isEmpty()) { QImage img (pw->width(), pw->height(), QImage::Format_ARGB32_Premultiplied); QPainter painter(&img); pw->render (&painter); img.save (fileName, "png", 0); } } void MainWindow::SaveSettings(bool) { qDebug ("Save Settings"); QSettings setting ("Kizarm", "Scope"); setting.beginGroup("Trigger"); const TrigerSettings * const ts = firmware.getTrigger(); setting.setValue("Value", ts->value); setting.setValue("Offset", ts->offset); setting.setValue("Mode", ts->mode); setting.setValue("Channel", ts->channel); setting.setValue("Edge", ts->rising); setting.endGroup(); setting.beginGroup("Markers"); ui->Display->saveSettings (setting); setting.endGroup(); } void MainWindow::RestSettings(bool) { qDebug ("Restore Settings"); QSettings setting ("Kizarm", "Scope"); setting.beginGroup("Trigger"); TrigerSettings ts; ts.value = setting.value ("Value").toInt(); ts.offset = setting.value ("Offset").toInt(); ts.mode = static_cast (setting.value ("Mode").toInt()); ui->comboMode->setCurrentIndex(ts.mode); ts.channel = static_cast (setting.value ("Channel").toInt()); ui->comboChannel->setCurrentIndex(ts.channel); ts.rising = setting.value ("Edge").toBool(); ui->comboRissing->setCurrentIndex(ts.value ? 1 : 0); memcpy (firmware.getTrigger(), & ts, sizeof(TrigerSettings)); setting.endGroup(); SendTrigerMode (ts.mode); firmware.SettingChanged(MOVE_VALUE); firmware.SettingChanged(MOVE_OFSET); setting.beginGroup("Markers"); ui->Display->restSettings (setting); const int n = setting.value("TimeBaseIndex").toInt(); TimeBaseRange(n); ui->comboTimeRange->setCurrentIndex(n); setting.endGroup(); }