2010-02-21 08:47:22 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-26 05:57:35 +08:00
|
|
|
// Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
|
|
|
|
//
|
2010-02-21 08:47:22 +08:00
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// GUI (QT)
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-07-28 03:32:15 +08:00
|
|
|
#include "proxguiqt.h"
|
2020-10-05 03:01:08 +08:00
|
|
|
#include <inttypes.h>
|
2017-07-28 03:32:15 +08:00
|
|
|
#include <stdbool.h>
|
2009-04-09 14:43:20 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <QPainterPath>
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <math.h>
|
|
|
|
#include <limits.h>
|
2009-11-23 17:34:57 +08:00
|
|
|
#include <stdio.h>
|
2017-07-28 03:32:15 +08:00
|
|
|
#include <QSlider>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <string.h>
|
|
|
|
#include <QtGui>
|
2020-05-03 18:46:46 +08:00
|
|
|
#include "proxgui.h"
|
2020-05-03 18:23:55 +08:00
|
|
|
#include "ui.h"
|
|
|
|
#include "comms.h"
|
|
|
|
#include "graph.h"
|
|
|
|
#include "cmddata.h"
|
2018-10-07 15:01:24 +08:00
|
|
|
#include "util_darwin.h"
|
2020-05-03 18:46:46 +08:00
|
|
|
|
|
|
|
extern "C" int preferences_save(void);
|
2018-10-07 15:01:24 +08:00
|
|
|
|
2020-06-02 02:45:37 +08:00
|
|
|
static int s_Buff[MAX_GRAPH_TRACE_LEN];
|
|
|
|
static bool g_useOverlays = false;
|
|
|
|
static int g_absVMax = 0;
|
|
|
|
static uint32_t startMax; // Maximum offset in the graph (right side of graph)
|
|
|
|
static uint32_t PageWidth; // How many samples are currently visible on this 'page' / graph
|
|
|
|
static int unlockStart = 0;
|
2012-01-21 21:32:54 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::ShowGraphWindow(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
emit ShowGraphWindowSignal();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::RepaintGraphWindow(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
emit RepaintGraphWindowSignal();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::HideGraphWindow(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
emit HideGraphWindowSignal();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::Exit(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
emit ExitSignal();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::_ShowGraphWindow(void) {
|
2019-03-10 07:00:59 +08:00
|
|
|
if (!plotapp)
|
2019-03-10 06:35:06 +08:00
|
|
|
return;
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
if (!plotwidget) {
|
2019-03-09 16:11:08 +08:00
|
|
|
|
2018-10-07 15:01:24 +08:00
|
|
|
#if defined(__MACH__) && defined(__APPLE__)
|
2019-03-10 06:35:06 +08:00
|
|
|
makeFocusable();
|
2019-03-09 16:11:08 +08:00
|
|
|
#endif
|
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
plotwidget = new ProxWidget();
|
|
|
|
}
|
|
|
|
plotwidget->show();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::_RepaintGraphWindow(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (!plotapp || !plotwidget)
|
|
|
|
return;
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
plotwidget->update();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::_HideGraphWindow(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (!plotapp || !plotwidget)
|
|
|
|
return;
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
plotwidget->hide();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::_Exit(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
delete this;
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::_StartProxmarkThread(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (!proxmarkThread)
|
|
|
|
return;
|
2017-10-21 02:39:57 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
// if thread finished delete self and delete application
|
|
|
|
QObject::connect(proxmarkThread, SIGNAL(finished()), proxmarkThread, SLOT(deleteLater()));
|
|
|
|
QObject::connect(proxmarkThread, SIGNAL(finished()), this, SLOT(_Exit()));
|
|
|
|
// start proxmark thread
|
|
|
|
proxmarkThread->start();
|
2017-10-21 02:39:57 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxGuiQT::MainLoop() {
|
2019-03-10 06:35:06 +08:00
|
|
|
plotapp = new QApplication(argc, argv);
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow()));
|
|
|
|
connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow()));
|
|
|
|
connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
|
|
|
|
connect(this, SIGNAL(ExitSignal()), this, SLOT(_Exit()));
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
//start proxmark thread after starting event loop
|
|
|
|
QTimer::singleShot(200, this, SLOT(_StartProxmarkThread()));
|
2017-10-21 02:39:57 +08:00
|
|
|
|
2018-10-07 15:01:24 +08:00
|
|
|
#if defined(__MACH__) && defined(__APPLE__)
|
2019-03-10 06:35:06 +08:00
|
|
|
//Prevent the terminal from loosing focus during launch by making the client unfocusable
|
|
|
|
makeUnfocusable();
|
2018-10-07 15:01:24 +08:00
|
|
|
#endif
|
|
|
|
|
2019-03-09 16:11:08 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
plotapp->exec();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2017-10-21 02:39:57 +08:00
|
|
|
ProxGuiQT::ProxGuiQT(int argc, char **argv, WorkerThread *wthread) : plotapp(NULL), plotwidget(NULL),
|
2019-03-10 18:20:22 +08:00
|
|
|
argc(argc), argv(argv), proxmarkThread(wthread) {
|
2017-10-21 02:39:57 +08:00
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
ProxGuiQT::~ProxGuiQT(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (plotapp) {
|
|
|
|
plotapp->quit();
|
|
|
|
plotapp = NULL;
|
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
2020-04-13 07:32:47 +08:00
|
|
|
|
|
|
|
// -------------------------------------------------
|
2020-04-16 15:01:14 +08:00
|
|
|
// Slider Widget form based on a class to enable
|
2020-04-13 07:32:47 +08:00
|
|
|
// Event override functions
|
|
|
|
// -------------------------------------------------
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
SliderWidget::SliderWidget() {
|
2020-04-13 07:32:47 +08:00
|
|
|
// Set the initail postion and size from settings
|
|
|
|
if (session.preferences_loaded)
|
2020-04-18 16:04:08 +08:00
|
|
|
setGeometry(session.overlay.x, session.overlay.y, session.overlay.w, session.overlay.h);
|
2020-04-13 07:32:47 +08:00
|
|
|
else
|
|
|
|
resize(800, 400);
|
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void SliderWidget::resizeEvent(QResizeEvent *event) {
|
2020-04-18 16:04:08 +08:00
|
|
|
session.overlay.h = event->size().height();
|
|
|
|
session.overlay.w = event->size().width();
|
2020-04-13 14:17:57 +08:00
|
|
|
session.window_changed = true;
|
|
|
|
|
2020-04-13 07:32:47 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 15:01:14 +08:00
|
|
|
void SliderWidget::moveEvent(QMoveEvent *event) {
|
2020-04-18 16:04:08 +08:00
|
|
|
session.overlay.x = event->pos().x();
|
|
|
|
session.overlay.y = event->pos().y();
|
2020-04-13 14:17:57 +08:00
|
|
|
session.window_changed = true;
|
2020-04-12 18:24:56 +08:00
|
|
|
}
|
2020-04-13 07:32:47 +08:00
|
|
|
|
2017-07-28 03:32:15 +08:00
|
|
|
//--------------------
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::applyOperation() {
|
2019-03-10 06:35:06 +08:00
|
|
|
//printf("ApplyOperation()");
|
|
|
|
save_restoreGB(GRAPH_SAVE);
|
|
|
|
memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen);
|
|
|
|
RepaintGraphWindow();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::stickOperation() {
|
2019-03-10 06:35:06 +08:00
|
|
|
save_restoreGB(GRAPH_RESTORE);
|
|
|
|
//printf("stickOperation()");
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::vchange_autocorr(int v) {
|
2019-03-10 06:35:06 +08:00
|
|
|
int ans = AutoCorrelate(GraphBuffer, s_Buff, GraphTraceLen, v, true, false);
|
|
|
|
if (g_debugMode) printf("vchange_autocorr(w:%d): %d\n", v, ans);
|
|
|
|
g_useOverlays = true;
|
|
|
|
RepaintGraphWindow();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::vchange_askedge(int v) {
|
2019-03-10 06:35:06 +08:00
|
|
|
//extern int AskEdgeDetect(const int *in, int *out, int len, int threshold);
|
|
|
|
int ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v);
|
|
|
|
if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans);
|
|
|
|
g_useOverlays = true;
|
|
|
|
RepaintGraphWindow();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::vchange_dthr_up(int v) {
|
2019-03-10 06:35:06 +08:00
|
|
|
int down = opsController->horizontalSlider_dirthr_down->value();
|
|
|
|
directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down);
|
|
|
|
//printf("vchange_dthr_up(%d)", v);
|
|
|
|
g_useOverlays = true;
|
|
|
|
RepaintGraphWindow();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::vchange_dthr_down(int v) {
|
2019-03-10 06:35:06 +08:00
|
|
|
//printf("vchange_dthr_down(%d)", v);
|
|
|
|
int up = opsController->horizontalSlider_dirthr_up->value();
|
2019-03-10 07:00:59 +08:00
|
|
|
directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, up);
|
2019-03-10 06:35:06 +08:00
|
|
|
g_useOverlays = true;
|
|
|
|
RepaintGraphWindow();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
|
2019-03-10 06:35:06 +08:00
|
|
|
this->master = master;
|
2020-04-10 13:04:11 +08:00
|
|
|
// Set the initail postion and size from settings
|
2020-04-12 11:07:25 +08:00
|
|
|
if (session.preferences_loaded)
|
2020-04-18 16:04:08 +08:00
|
|
|
setGeometry(session.plot.x, session.plot.y, session.plot.w, session.plot.h);
|
2020-04-10 13:04:11 +08:00
|
|
|
else
|
|
|
|
resize(800, 400);
|
2019-03-10 06:35:06 +08:00
|
|
|
|
|
|
|
// Setup the controller widget
|
2020-04-16 15:01:14 +08:00
|
|
|
controlWidget = new SliderWidget(); //new QWidget();
|
2019-03-10 06:35:06 +08:00
|
|
|
opsController = new Ui::Form();
|
|
|
|
opsController->setupUi(controlWidget);
|
|
|
|
//Due to quirks in QT Designer, we need to fiddle a bit
|
|
|
|
opsController->horizontalSlider_dirthr_down->setMinimum(-128);
|
|
|
|
opsController->horizontalSlider_dirthr_down->setMaximum(0);
|
|
|
|
opsController->horizontalSlider_dirthr_down->setValue(-20);
|
|
|
|
opsController->horizontalSlider_dirthr_up->setMinimum(-40);
|
|
|
|
opsController->horizontalSlider_dirthr_up->setMaximum(128);
|
|
|
|
opsController->horizontalSlider_dirthr_up->setValue(20);
|
|
|
|
opsController->horizontalSlider_askedge->setValue(25);
|
|
|
|
opsController->horizontalSlider_window->setValue(4000);
|
|
|
|
|
|
|
|
QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation()));
|
|
|
|
QObject::connect(opsController->pushButton_sticky, SIGNAL(clicked()), this, SLOT(stickOperation()));
|
|
|
|
QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int)));
|
|
|
|
QObject::connect(opsController->horizontalSlider_dirthr_up, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_up(int)));
|
|
|
|
QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int)));
|
|
|
|
QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(int)));
|
|
|
|
|
2020-04-18 16:04:08 +08:00
|
|
|
controlWidget->setGeometry(session.overlay.x, session.overlay.y, session.overlay.w, session.overlay.h);
|
2020-04-13 07:32:47 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
// Set up the plot widget, which does the actual plotting
|
|
|
|
plot = new Plot(this);
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
layout->addWidget(plot);
|
|
|
|
setLayout(layout);
|
2020-01-29 22:16:50 +08:00
|
|
|
|
|
|
|
// plot window title
|
2020-06-01 05:09:26 +08:00
|
|
|
QString pt = QString("[*]Plot [ %1 ]").arg(conn.serial_port_name);
|
2020-01-29 22:16:50 +08:00
|
|
|
setWindowTitle(pt);
|
|
|
|
|
|
|
|
// shows plot window on the screen.
|
|
|
|
show();
|
2019-03-10 06:35:06 +08:00
|
|
|
|
2020-04-13 07:32:47 +08:00
|
|
|
// Set Slider/Overlay position if no settings.
|
2020-04-16 15:01:14 +08:00
|
|
|
if (!session.preferences_loaded) {
|
2020-04-11 15:26:43 +08:00
|
|
|
// Move controller widget below plot
|
|
|
|
controlWidget->move(x(), y() + frameSize().height());
|
|
|
|
controlWidget->resize(size().width(), 200);
|
|
|
|
}
|
2020-04-12 11:07:25 +08:00
|
|
|
|
2020-01-29 22:16:50 +08:00
|
|
|
// Olverlays / slider window title
|
2020-06-01 05:09:26 +08:00
|
|
|
QString ct = QString("[*]Slider [ %1 ]").arg(conn.serial_port_name);
|
2020-01-29 22:16:50 +08:00
|
|
|
controlWidget->setWindowTitle(ct);
|
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
controlWidget->show();
|
2020-04-16 15:01:14 +08:00
|
|
|
|
2020-04-13 14:17:57 +08:00
|
|
|
// now that is up, reset pos/size change flags
|
|
|
|
session.window_changed = false;
|
|
|
|
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2017-07-28 03:32:15 +08:00
|
|
|
// not 100% sure what i need in this block
|
|
|
|
// feel free to fix - marshmellow...
|
2019-03-10 18:20:22 +08:00
|
|
|
ProxWidget::~ProxWidget(void) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (controlWidget) {
|
|
|
|
controlWidget->close();
|
|
|
|
delete controlWidget;
|
|
|
|
controlWidget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opsController) {
|
|
|
|
delete opsController;
|
|
|
|
opsController = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plot) {
|
|
|
|
plot->close();
|
|
|
|
delete plot;
|
|
|
|
plot = NULL;
|
|
|
|
}
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2020-04-13 14:17:57 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::closeEvent(QCloseEvent *event) {
|
2019-03-10 06:35:06 +08:00
|
|
|
event->ignore();
|
|
|
|
this->hide();
|
|
|
|
g_useOverlays = false;
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::hideEvent(QHideEvent *event) {
|
2019-03-10 06:35:06 +08:00
|
|
|
controlWidget->hide();
|
|
|
|
plot->hide();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2019-03-10 18:20:22 +08:00
|
|
|
void ProxWidget::showEvent(QShowEvent *event) {
|
2019-03-10 06:35:06 +08:00
|
|
|
controlWidget->show();
|
|
|
|
plot->show();
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2020-04-13 07:32:47 +08:00
|
|
|
void ProxWidget::moveEvent(QMoveEvent *event) {
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.x = event->pos().x();
|
|
|
|
session.plot.y = event->pos().y();
|
2020-04-13 14:17:57 +08:00
|
|
|
session.window_changed = true;
|
2020-04-13 07:32:47 +08:00
|
|
|
}
|
|
|
|
void ProxWidget::resizeEvent(QResizeEvent *event) {
|
2020-04-18 16:04:08 +08:00
|
|
|
session.plot.h = event->size().height();
|
|
|
|
session.plot.w = event->size().width();
|
2020-04-13 14:17:57 +08:00
|
|
|
session.window_changed = true;
|
2020-04-12 18:24:56 +08:00
|
|
|
}
|
2009-07-08 08:17:06 +08:00
|
|
|
|
2017-07-28 03:32:15 +08:00
|
|
|
//----------- Plotting
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
int Plot::xCoordOf(int i, QRect r) {
|
2019-03-10 06:35:06 +08:00
|
|
|
return r.left() + (int)((i - GraphStart) * GraphPixelsPerPoint);
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
int Plot::yCoordOf(int v, QRect r, int maxVal) {
|
2019-03-10 06:35:06 +08:00
|
|
|
int z = (r.bottom() - r.top()) / 2;
|
2019-03-10 07:00:59 +08:00
|
|
|
if (maxVal == 0) ++maxVal;
|
2019-03-10 06:35:06 +08:00
|
|
|
return -(z * v) / maxVal + z;
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2009-07-22 00:10:58 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
int Plot::valueOf_yCoord(int y, QRect r, int maxVal) {
|
2019-03-10 07:00:59 +08:00
|
|
|
int z = (r.bottom() - r.top()) / 2;
|
|
|
|
return (y - z) * maxVal / z;
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2017-08-01 02:45:16 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
static const QColor GREEN = QColor(100, 255, 100);
|
|
|
|
static const QColor RED = QColor(255, 100, 100);
|
|
|
|
static const QColor BLUE = QColor(100, 100, 255);
|
|
|
|
static const QColor GRAY = QColor(240, 240, 240);
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
QColor Plot::getColor(int graphNum) {
|
2019-03-10 06:35:06 +08:00
|
|
|
switch (graphNum) {
|
2019-03-10 07:00:59 +08:00
|
|
|
case 0:
|
|
|
|
return GREEN; //Green
|
|
|
|
case 1:
|
|
|
|
return RED; //Red
|
|
|
|
case 2:
|
|
|
|
return BLUE; //Blue
|
|
|
|
default:
|
|
|
|
return GRAY; //Gray
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2012-01-24 01:57:42 +08:00
|
|
|
|
2019-04-14 05:38:34 +08:00
|
|
|
void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (len == 0) return;
|
2019-04-14 17:05:32 +08:00
|
|
|
startMax = 0;
|
|
|
|
if (plotRect.right() >= plotRect.left() + 40) {
|
|
|
|
uint32_t t = (plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint;
|
|
|
|
if (len >= t)
|
|
|
|
startMax = len - t;
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
if (GraphStart > startMax) {
|
|
|
|
GraphStart = startMax;
|
|
|
|
}
|
|
|
|
if (GraphStart > len) return;
|
2020-04-26 19:49:06 +08:00
|
|
|
int vMin = INT_MAX, vMax = INT_MIN;
|
2019-04-14 05:38:34 +08:00
|
|
|
uint32_t sample_index = GraphStart ;
|
2019-03-10 07:00:59 +08:00
|
|
|
for (; sample_index < len && xCoordOf(sample_index, plotRect) < plotRect.right() ; sample_index++) {
|
2019-03-10 06:35:06 +08:00
|
|
|
|
2020-04-26 19:49:06 +08:00
|
|
|
int v = buffer[sample_index];
|
2019-03-10 06:35:06 +08:00
|
|
|
if (v < vMin) vMin = v;
|
|
|
|
if (v > vMax) vMax = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_absVMax = 0;
|
2019-03-10 07:00:59 +08:00
|
|
|
if (fabs((double) vMin) > g_absVMax) g_absVMax = (int)fabs((double) vMin);
|
|
|
|
if (fabs((double) vMax) > g_absVMax) g_absVMax = (int)fabs((double) vMax);
|
2019-03-10 06:35:06 +08:00
|
|
|
g_absVMax = (int)(g_absVMax * 1.25 + 1);
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-04-14 05:38:34 +08:00
|
|
|
void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, uint32_t plotOffset) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (len == 0 || PlotGridX <= 0) return;
|
|
|
|
//clock_t begin = clock();
|
|
|
|
QPainterPath penPath;
|
|
|
|
|
|
|
|
int grid_delta_x = PlotGridX;
|
|
|
|
int first_delta_x = grid_delta_x; //(plotOffset > 0) ? PlotGridX : (PlotGridX +);
|
2019-03-10 07:00:59 +08:00
|
|
|
if (GraphStart > plotOffset) first_delta_x -= (GraphStart - plotOffset);
|
2019-03-10 06:35:06 +08:00
|
|
|
int DemodStart = GraphStart;
|
|
|
|
if (plotOffset > GraphStart) DemodStart = plotOffset;
|
|
|
|
|
|
|
|
int BitStart = 0;
|
|
|
|
// round down
|
2019-03-10 07:00:59 +08:00
|
|
|
if (DemodStart - plotOffset > 0) BitStart = (int)(((DemodStart - plotOffset) + (PlotGridX - 1)) / PlotGridX) - 1;
|
2019-03-10 06:35:06 +08:00
|
|
|
first_delta_x += BitStart * PlotGridX;
|
|
|
|
if (BitStart > (int)len) return;
|
|
|
|
int delta_x = 0;
|
2020-04-26 19:49:06 +08:00
|
|
|
// int v = 0;
|
2019-03-10 06:35:06 +08:00
|
|
|
//printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
|
|
|
|
|
|
|
|
painter->setPen(getColor(graphNum));
|
|
|
|
char str[5];
|
2019-03-10 07:00:59 +08:00
|
|
|
int absVMax = (int)(100 * 1.05 + 1);
|
2019-03-10 06:35:06 +08:00
|
|
|
int x = xCoordOf(DemodStart, plotRect);
|
2019-03-10 07:00:59 +08:00
|
|
|
int y = yCoordOf((buffer[BitStart] * 200 - 100) * -1, plotRect, absVMax);
|
2019-03-10 06:35:06 +08:00
|
|
|
penPath.moveTo(x, y);
|
|
|
|
delta_x = 0;
|
|
|
|
int clk = first_delta_x;
|
2019-03-10 07:00:59 +08:00
|
|
|
for (int i = BitStart; i < (int)len && xCoordOf(delta_x + DemodStart, plotRect) < plotRect.right(); i++) {
|
2020-04-26 19:49:06 +08:00
|
|
|
for (int j = 0; j < (clk) && i < (int)len && xCoordOf(DemodStart + delta_x + j, plotRect) < plotRect.right() ; j++) {
|
|
|
|
x = xCoordOf(DemodStart + delta_x + j, plotRect);
|
|
|
|
int v = buffer[i] * 200 - 100;
|
2019-03-10 06:35:06 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
y = yCoordOf(v, plotRect, absVMax);
|
2019-03-10 06:35:06 +08:00
|
|
|
|
|
|
|
penPath.lineTo(x, y);
|
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
if (GraphPixelsPerPoint > 10) {
|
|
|
|
QRect f(QPoint(x - 3, y - 3), QPoint(x + 3, y + 3));
|
2019-03-10 06:35:06 +08:00
|
|
|
painter->fillRect(f, QColor(100, 255, 100));
|
|
|
|
}
|
2020-04-26 19:49:06 +08:00
|
|
|
if (j == (int)clk / 2) {
|
2019-03-10 06:35:06 +08:00
|
|
|
//print label
|
2019-03-10 07:00:59 +08:00
|
|
|
sprintf(str, "%u", buffer[i]);
|
|
|
|
painter->drawText(x - 8, y + ((buffer[i] > 0) ? 18 : -6), str);
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delta_x += clk;
|
|
|
|
clk = grid_delta_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Graph annotations
|
|
|
|
painter->drawPath(penPath);
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
|
|
|
|
2019-04-14 05:38:34 +08:00
|
|
|
void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum) {
|
2019-03-10 06:35:06 +08:00
|
|
|
if (len == 0) return;
|
|
|
|
// clock_t begin = clock();
|
|
|
|
QPainterPath penPath;
|
2020-10-05 02:01:08 +08:00
|
|
|
int vMin = INT_MAX, vMax = INT_MIN, v = 0;
|
|
|
|
int64_t vMean = 0;
|
2019-04-14 05:38:34 +08:00
|
|
|
uint32_t i = 0;
|
2019-03-10 06:35:06 +08:00
|
|
|
int x = xCoordOf(GraphStart, plotRect);
|
|
|
|
int y = yCoordOf(buffer[GraphStart], plotRect, g_absVMax);
|
|
|
|
penPath.moveTo(x, y);
|
2019-03-10 07:00:59 +08:00
|
|
|
for (i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
x = xCoordOf(i, plotRect);
|
|
|
|
v = buffer[i];
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
y = yCoordOf(v, plotRect, g_absVMax);
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
penPath.lineTo(x, y);
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
if (GraphPixelsPerPoint > 10) {
|
2019-03-10 07:00:59 +08:00
|
|
|
QRect f(QPoint(x - 3, y - 3), QPoint(x + 3, y + 3));
|
2019-03-10 06:35:06 +08:00
|
|
|
painter->fillRect(f, QColor(100, 255, 100));
|
|
|
|
}
|
|
|
|
// catch stats
|
|
|
|
if (v < vMin) vMin = v;
|
|
|
|
if (v > vMax) vMax = v;
|
|
|
|
vMean += v;
|
|
|
|
}
|
2020-10-05 02:01:08 +08:00
|
|
|
GraphStop = i;
|
|
|
|
vMean /= (GraphStop - GraphStart);
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
painter->setPen(getColor(graphNum));
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
// Draw y-axis
|
|
|
|
int xo = 5 + (graphNum * 40);
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawLine(xo, plotRect.top(), xo, plotRect.bottom());
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5;
|
|
|
|
int minYDist = 40; // Minimum pixel-distance between markers
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
char yLbl[20];
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
int n = 0;
|
|
|
|
int lasty0 = 65535;
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
for (v = vMarkers; yCoordOf(v, plotRect, g_absVMax) > plotRect.top() && n < 20; v += vMarkers, n++) {
|
2019-03-10 06:35:06 +08:00
|
|
|
int y0 = yCoordOf(v, plotRect, g_absVMax);
|
|
|
|
int y1 = yCoordOf(-v, plotRect, g_absVMax);
|
2016-03-21 02:33:59 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
if (lasty0 - y0 < minYDist) continue;
|
2017-03-02 21:53:50 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawLine(xo - 5, y0, xo + 5, y0);
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
sprintf(yLbl, "%d", v);
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawText(xo + 8, y0 + 7, yLbl);
|
2016-03-21 02:33:59 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawLine(xo - 5, y1, xo + 5, y1);
|
2019-03-10 06:35:06 +08:00
|
|
|
sprintf(yLbl, "%d", -v);
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawText(xo + 8, y1 + 5, yLbl);
|
2019-03-10 06:35:06 +08:00
|
|
|
lasty0 = y0;
|
|
|
|
}
|
2016-03-21 02:33:59 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
//Graph annotations
|
|
|
|
painter->drawPath(penPath);
|
|
|
|
char str[200];
|
2020-10-05 02:01:08 +08:00
|
|
|
sprintf(str, "max=%d min=%d mean=%" PRId64 " n=%u/%zu CursorAVal=[%d] CursorBVal=[%d]",
|
|
|
|
vMax, vMin, vMean, GraphStop - GraphStart, len, buffer[CursorAPos], buffer[CursorBPos]);
|
2019-03-10 06:35:06 +08:00
|
|
|
painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
|
|
|
|
//clock_t end = clock();
|
|
|
|
//double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
|
|
|
|
//printf("Plot time %f\n", elapsed_secs);
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void Plot::plotGridLines(QPainter *painter, QRect r) {
|
2019-03-09 16:11:08 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
// set GridOffset
|
|
|
|
if (PlotGridX <= 0) return;
|
|
|
|
|
|
|
|
int offset = GridOffset;
|
|
|
|
if (GridLocked && PlotGridX) {
|
|
|
|
offset = GridOffset + PlotGridX - (GraphStart % PlotGridX);
|
|
|
|
} else if (!GridLocked && GraphStart > 0 && PlotGridX) {
|
2019-03-10 07:00:59 +08:00
|
|
|
offset = PlotGridX - ((GraphStart - offset) % PlotGridX) + GraphStart - unlockStart;
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
offset %= PlotGridX;
|
|
|
|
if (offset < 0) offset += PlotGridX;
|
|
|
|
|
|
|
|
int i;
|
2019-03-10 07:00:59 +08:00
|
|
|
int grid_delta_x = (int)(PlotGridX * GraphPixelsPerPoint);
|
2019-03-10 06:35:06 +08:00
|
|
|
int grid_delta_y = PlotGridY;
|
|
|
|
|
|
|
|
if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
|
|
|
|
for (i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawLine(r.left() + i, r.top(), r.left() + i, r.bottom());
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PlotGridY > 0) {
|
|
|
|
for (i = 0; yCoordOf(i, r, g_absVMax) > r.top(); i += grid_delta_y) {
|
|
|
|
// line above mid
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawLine(r.left(), yCoordOf(i, r, g_absVMax), r.right(), yCoordOf(i, r, g_absVMax));
|
2019-03-10 06:35:06 +08:00
|
|
|
// line below mid
|
2019-03-10 07:00:59 +08:00
|
|
|
painter->drawLine(r.left(), yCoordOf(-i, r, g_absVMax), r.right(), yCoordOf(-i, r, g_absVMax));
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
}
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2017-07-28 03:32:15 +08:00
|
|
|
#define HEIGHT_INFO 60
|
|
|
|
#define WIDTH_AXES 80
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void Plot::paintEvent(QPaintEvent *event) {
|
2019-03-10 06:35:06 +08:00
|
|
|
QPainter painter(this);
|
|
|
|
QBrush brush(QColor(100, 255, 100));
|
|
|
|
QPen pen(QColor(100, 255, 100));
|
|
|
|
|
|
|
|
painter.setFont(QFont("Courier New", 10));
|
|
|
|
|
|
|
|
if (CursorAPos > GraphTraceLen)
|
2019-03-10 07:00:59 +08:00
|
|
|
CursorAPos = 0;
|
2019-03-10 06:35:06 +08:00
|
|
|
if (CursorBPos > GraphTraceLen)
|
2019-03-10 07:00:59 +08:00
|
|
|
CursorBPos = 0;
|
2019-03-10 06:35:06 +08:00
|
|
|
if (CursorCPos > GraphTraceLen)
|
2019-03-10 07:00:59 +08:00
|
|
|
CursorCPos = 0;
|
2019-03-10 06:35:06 +08:00
|
|
|
if (CursorDPos > GraphTraceLen)
|
2019-03-10 07:00:59 +08:00
|
|
|
CursorDPos = 0;
|
2019-03-10 06:35:06 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
QRect plotRect(WIDTH_AXES, 0, width() - WIDTH_AXES, height() - HEIGHT_INFO);
|
|
|
|
QRect infoRect(0, height() - HEIGHT_INFO, width(), HEIGHT_INFO);
|
2019-05-14 08:39:27 +08:00
|
|
|
PageWidth = plotRect.width() / GraphPixelsPerPoint;
|
2019-03-10 06:35:06 +08:00
|
|
|
|
|
|
|
//Grey background
|
|
|
|
painter.fillRect(rect(), QColor(60, 60, 60));
|
|
|
|
//Black foreground
|
|
|
|
painter.fillRect(plotRect, QColor(0, 0, 0));
|
|
|
|
|
|
|
|
//init graph variables
|
2019-03-10 07:00:59 +08:00
|
|
|
setMaxAndStart(GraphBuffer, GraphTraceLen, plotRect);
|
2019-03-10 06:35:06 +08:00
|
|
|
|
|
|
|
// center line
|
|
|
|
int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
|
|
|
|
painter.setPen(QColor(100, 100, 100));
|
|
|
|
painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight);
|
|
|
|
// plot X and Y grid lines
|
|
|
|
plotGridLines(&painter, plotRect);
|
|
|
|
|
|
|
|
//Start painting graph
|
2019-03-10 07:00:59 +08:00
|
|
|
PlotGraph(GraphBuffer, GraphTraceLen, plotRect, infoRect, &painter, 0);
|
2019-03-10 06:35:06 +08:00
|
|
|
if (showDemod && DemodBufferLen > 8) {
|
2019-03-10 07:00:59 +08:00
|
|
|
PlotDemod(DemodBuffer, DemodBufferLen, plotRect, infoRect, &painter, 2, g_DemodStartIdx);
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
if (g_useOverlays) {
|
|
|
|
//init graph variables
|
2019-03-10 07:00:59 +08:00
|
|
|
setMaxAndStart(s_Buff, GraphTraceLen, plotRect);
|
|
|
|
PlotGraph(s_Buff, GraphTraceLen, plotRect, infoRect, &painter, 1);
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
// End graph drawing
|
|
|
|
|
|
|
|
//Draw the cursors
|
|
|
|
if (CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right()) {
|
|
|
|
painter.setPen(QColor(255, 255, 0));
|
2019-03-10 07:00:59 +08:00
|
|
|
painter.drawLine(xCoordOf(CursorAPos, plotRect), plotRect.top(), xCoordOf(CursorAPos, plotRect), plotRect.bottom());
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
if (CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right()) {
|
|
|
|
painter.setPen(QColor(255, 0, 255));
|
2019-03-10 07:00:59 +08:00
|
|
|
painter.drawLine(xCoordOf(CursorBPos, plotRect), plotRect.top(), xCoordOf(CursorBPos, plotRect), plotRect.bottom());
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
if (CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right()) {
|
|
|
|
painter.setPen(QColor(255, 153, 0)); //orange
|
2019-03-10 07:00:59 +08:00
|
|
|
painter.drawLine(xCoordOf(CursorCPos, plotRect), plotRect.top(), xCoordOf(CursorCPos, plotRect), plotRect.bottom());
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
if (CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right()) {
|
|
|
|
painter.setPen(QColor(0, 0, 205)); //light blue
|
2019-03-10 07:00:59 +08:00
|
|
|
painter.drawLine(xCoordOf(CursorDPos, plotRect), plotRect.top(), xCoordOf(CursorDPos, plotRect), plotRect.bottom());
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//Draw annotations
|
|
|
|
char str[200];
|
2020-10-05 02:01:08 +08:00
|
|
|
char scalestr[30] = {0};
|
|
|
|
if (CursorScaleFactor != 1) {
|
|
|
|
if (CursorScaleFactorUnit[0] == '\x00') {
|
|
|
|
sprintf(scalestr, "[%2.2f] ", ((int32_t)(CursorBPos - CursorAPos)) / CursorScaleFactor);
|
|
|
|
} else {
|
|
|
|
sprintf(scalestr, "[%2.2f %s] ", ((int32_t)(CursorBPos - CursorAPos)) / CursorScaleFactor, CursorScaleFactorUnit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(str, "@%u..%u dt=%i %szoom=%2.2f CursorAPos=%u CursorBPos=%u GridX=%d GridY=%d (%s) GridXoffset=%d",
|
2019-03-10 06:35:06 +08:00
|
|
|
GraphStart,
|
2020-10-05 02:01:08 +08:00
|
|
|
GraphStop,
|
2019-03-10 06:35:06 +08:00
|
|
|
CursorBPos - CursorAPos,
|
2020-10-05 02:01:08 +08:00
|
|
|
scalestr,
|
2019-03-10 06:35:06 +08:00
|
|
|
GraphPixelsPerPoint,
|
|
|
|
CursorAPos,
|
|
|
|
CursorBPos,
|
|
|
|
PlotGridXdefault,
|
|
|
|
PlotGridYdefault,
|
|
|
|
GridLocked ? "Locked" : "Unlocked",
|
|
|
|
GridOffset
|
2019-03-10 07:00:59 +08:00
|
|
|
);
|
2019-03-10 06:35:06 +08:00
|
|
|
painter.setPen(QColor(255, 255, 255));
|
|
|
|
painter.drawText(20, infoRect.bottom() - 3, str);
|
2017-07-28 03:32:15 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) {
|
2019-03-10 06:35:06 +08:00
|
|
|
//Need to set this, otherwise we don't receive keypress events
|
2019-03-10 07:00:59 +08:00
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2019-03-10 06:35:06 +08:00
|
|
|
resize(400, 200);
|
2009-04-09 14:43:20 +08:00
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
QPalette palette(QColor(0, 0, 0, 0));
|
|
|
|
palette.setColor(QPalette::WindowText, QColor(255, 255, 255));
|
|
|
|
palette.setColor(QPalette::Text, QColor(255, 255, 255));
|
2019-03-10 06:35:06 +08:00
|
|
|
palette.setColor(QPalette::Button, QColor(100, 100, 100));
|
|
|
|
setPalette(palette);
|
|
|
|
setAutoFillBackground(true);
|
|
|
|
CursorAPos = 0;
|
|
|
|
CursorBPos = 0;
|
2017-07-28 03:32:15 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
setWindowTitle(tr("Sliders"));
|
2019-03-09 16:11:08 +08:00
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
master = parent;
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void Plot::closeEvent(QCloseEvent *event) {
|
2019-03-10 06:35:06 +08:00
|
|
|
event->ignore();
|
|
|
|
this->hide();
|
|
|
|
g_useOverlays = false;
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2020-09-21 22:05:38 +08:00
|
|
|
void Plot::Zoom(float factor, int refX) {
|
2020-09-30 20:27:19 +08:00
|
|
|
if (factor >= 1) { // Zoom in
|
2020-09-21 22:05:38 +08:00
|
|
|
if (GraphPixelsPerPoint <= 25 * factor) {
|
|
|
|
GraphPixelsPerPoint *= factor;
|
|
|
|
GraphStart += (refX - GraphStart) - ((refX - GraphStart) / factor);
|
|
|
|
}
|
|
|
|
} else { // Zoom out
|
|
|
|
if (GraphPixelsPerPoint >= 0.01 / factor) {
|
|
|
|
GraphPixelsPerPoint *= factor;
|
|
|
|
if (GraphStart >= ((refX - GraphStart) / factor) - (refX - GraphStart)) {
|
|
|
|
GraphStart -= ((refX - GraphStart) / factor) - (refX - GraphStart);
|
|
|
|
} else {
|
|
|
|
GraphStart = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Plot::Move(int offset) {
|
|
|
|
if (offset > 0) { // Move right
|
|
|
|
if (GraphPixelsPerPoint < 20) {
|
|
|
|
GraphStart += offset;
|
|
|
|
} else {
|
|
|
|
GraphStart++;
|
|
|
|
}
|
|
|
|
} else { // Move left
|
|
|
|
if (GraphPixelsPerPoint < 20) {
|
2020-09-30 20:27:19 +08:00
|
|
|
if (GraphStart >= (uint) - offset) {
|
2020-09-21 22:05:38 +08:00
|
|
|
GraphStart += offset;
|
|
|
|
} else {
|
|
|
|
GraphStart = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (GraphStart > 0) {
|
|
|
|
GraphStart--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 02:01:27 +08:00
|
|
|
void Plot::Trim(void) {
|
|
|
|
uint32_t lref, rref;
|
|
|
|
if ((CursorAPos == 0) || (CursorBPos == 0)) { // if we don't have both cursors set
|
|
|
|
lref = GraphStart;
|
|
|
|
rref = GraphStop;
|
|
|
|
} else {
|
|
|
|
lref = CursorAPos < CursorBPos ? CursorAPos : CursorBPos;
|
|
|
|
rref = CursorAPos < CursorBPos ? CursorBPos : CursorAPos;
|
|
|
|
GraphPixelsPerPoint = GraphPixelsPerPoint * (GraphStop - GraphStart) / (rref - lref);
|
|
|
|
CursorAPos -= lref;
|
|
|
|
CursorBPos -= lref;
|
|
|
|
}
|
|
|
|
for (uint32_t i = lref; i < rref; ++i)
|
|
|
|
GraphBuffer[i - lref] = GraphBuffer[i];
|
|
|
|
GraphTraceLen = rref - lref;
|
|
|
|
GraphStart = 0;
|
|
|
|
}
|
|
|
|
|
2020-09-21 22:05:38 +08:00
|
|
|
void Plot::wheelEvent(QWheelEvent *event) {
|
|
|
|
// event->delta()
|
|
|
|
// 120 => shift right 5%
|
|
|
|
// -120 => shift left 5%
|
|
|
|
const float move_offset = 0.05;
|
|
|
|
// -120+shift => zoom in 10%
|
|
|
|
// 120+shift => zoom out 10%
|
|
|
|
const float zoom_offset = 0.1;
|
|
|
|
if (event->modifiers() & Qt::ShiftModifier) {
|
2020-09-22 17:30:05 +08:00
|
|
|
// event->position doesn't exist in QT5.12.8, both exist in 5.14.2 and event->x doesn't exist in 5.15.0
|
2020-09-22 17:51:29 +08:00
|
|
|
#if QT_VERSION >= 0x050d00
|
2020-09-22 06:15:43 +08:00
|
|
|
int x = event->position().x();
|
2020-09-22 06:32:20 +08:00
|
|
|
#else
|
|
|
|
int x = event->x();
|
|
|
|
#endif
|
2020-09-21 22:05:38 +08:00
|
|
|
x -= WIDTH_AXES;
|
|
|
|
x = (int)(x / GraphPixelsPerPoint);
|
|
|
|
x += GraphStart;
|
2020-09-22 17:30:05 +08:00
|
|
|
// event->angleDelta doesn't exist in QT4, both exist in 5.12.8 and 5.14.2 and event->delta doesn't exist in 5.15.0
|
2020-09-22 17:51:29 +08:00
|
|
|
#if QT_VERSION >= 0x050d00
|
2020-10-04 19:46:15 +08:00
|
|
|
float delta = event->angleDelta().y();
|
2020-09-22 07:22:25 +08:00
|
|
|
#else
|
2020-10-04 19:46:15 +08:00
|
|
|
float delta = event->delta();
|
2020-09-22 07:22:25 +08:00
|
|
|
#endif
|
2020-10-04 19:46:15 +08:00
|
|
|
if (delta < 0) {
|
|
|
|
Zoom(1.0 - (float)delta / (120 / zoom_offset), x);
|
|
|
|
} else {
|
|
|
|
Zoom(1.0 / (1.0 + (float)delta / (120 / zoom_offset)), x);
|
|
|
|
}
|
2020-09-21 22:05:38 +08:00
|
|
|
} else {
|
2020-09-22 17:51:29 +08:00
|
|
|
#if QT_VERSION >= 0x050d00
|
2020-09-30 20:27:19 +08:00
|
|
|
Move(PageWidth * (-(float)event->angleDelta().y() / (120 / move_offset)));
|
2020-09-22 07:24:14 +08:00
|
|
|
#else
|
2020-09-30 20:27:19 +08:00
|
|
|
Move(PageWidth * (-(float)event->delta() / (120 / move_offset)));
|
2020-09-22 07:24:14 +08:00
|
|
|
#endif
|
2020-09-21 22:05:38 +08:00
|
|
|
}
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void Plot::mouseMoveEvent(QMouseEvent *event) {
|
2019-03-10 06:35:06 +08:00
|
|
|
int x = event->x();
|
|
|
|
x -= WIDTH_AXES;
|
|
|
|
x = (int)(x / GraphPixelsPerPoint);
|
|
|
|
x += GraphStart;
|
|
|
|
if ((event->buttons() & Qt::LeftButton)) {
|
|
|
|
CursorAPos = x;
|
|
|
|
} else if (event->buttons() & Qt::RightButton) {
|
|
|
|
CursorBPos = x;
|
|
|
|
}
|
|
|
|
this->update();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void Plot::keyPressEvent(QKeyEvent *event) {
|
2019-05-14 08:39:27 +08:00
|
|
|
uint32_t offset; // Left/right movement offset (in sample size)
|
2019-03-10 06:35:06 +08:00
|
|
|
|
|
|
|
if (event->modifiers() & Qt::ShiftModifier) {
|
|
|
|
if (PlotGridX)
|
|
|
|
offset = PageWidth - (PageWidth % PlotGridX);
|
|
|
|
else
|
|
|
|
offset = PageWidth;
|
|
|
|
} else {
|
|
|
|
if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
offset = 1;
|
|
|
|
else
|
|
|
|
offset = (int)(20 / GraphPixelsPerPoint);
|
|
|
|
}
|
|
|
|
|
2019-03-10 07:00:59 +08:00
|
|
|
switch (event->key()) {
|
2019-03-10 06:35:06 +08:00
|
|
|
case Qt::Key_Down:
|
2020-09-21 22:05:38 +08:00
|
|
|
if (event->modifiers() & Qt::ShiftModifier) {
|
|
|
|
Zoom(2, CursorBPos);
|
|
|
|
} else {
|
|
|
|
Zoom(2, CursorAPos);
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_Up:
|
2020-09-21 22:05:38 +08:00
|
|
|
if (event->modifiers() & Qt::ShiftModifier) {
|
|
|
|
Zoom(0.5, CursorBPos);
|
|
|
|
} else {
|
|
|
|
Zoom(0.5, CursorAPos);
|
2019-03-10 06:35:06 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_Right:
|
2020-09-21 22:05:38 +08:00
|
|
|
Move(offset);
|
2019-03-10 06:35:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_Left:
|
2020-09-21 22:05:38 +08:00
|
|
|
Move(-offset);
|
2019-03-10 06:35:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_G:
|
|
|
|
if (PlotGridX || PlotGridY) {
|
|
|
|
PlotGridX = 0;
|
|
|
|
PlotGridY = 0;
|
|
|
|
} else {
|
2019-03-10 07:00:59 +08:00
|
|
|
if (PlotGridXdefault < 0)
|
2019-03-10 06:35:06 +08:00
|
|
|
PlotGridXdefault = 64;
|
2019-03-10 07:00:59 +08:00
|
|
|
if (PlotGridYdefault < 0)
|
2019-03-10 06:35:06 +08:00
|
|
|
PlotGridYdefault = 0;
|
|
|
|
|
|
|
|
PlotGridX = PlotGridXdefault;
|
|
|
|
PlotGridY = PlotGridYdefault;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_H:
|
|
|
|
puts("\n-----------------------------------------------------------------------");
|
|
|
|
puts("PLOT window keystrokes");
|
|
|
|
puts("\tKey Action");
|
|
|
|
puts("-----------------------------------------------------------------------");
|
2020-09-21 20:54:31 +08:00
|
|
|
puts("\tUP Zoom out around yellow cursor");
|
|
|
|
puts("\t<SHIFT> UP Zoom out around purple cursor");
|
2020-09-21 22:05:38 +08:00
|
|
|
puts("\t<SHIFT> WHEEL MOUSE UP Zoom out around mouse cursor");
|
2020-09-21 20:54:31 +08:00
|
|
|
puts("\tDOWN Zoom in around yellow cursor");
|
|
|
|
puts("\t<SHIFT> DOWN Zoom in around purple cursor");
|
2020-09-21 22:05:38 +08:00
|
|
|
puts("\t<SHIFT> WHEEL MOUSE DOWN Zoom in around mouse cursor");
|
2019-03-10 06:35:06 +08:00
|
|
|
puts("\tG Toggle grid display");
|
|
|
|
puts("\tH Show help");
|
|
|
|
puts("\tL Toggle lock grid relative to samples");
|
|
|
|
puts("\tQ Hide window");
|
2020-10-05 02:01:27 +08:00
|
|
|
puts("\tT Trim data on displayed window or on cursors if defined");
|
2019-05-14 08:39:27 +08:00
|
|
|
puts("\tHOME Move to the start of the graph");
|
|
|
|
puts("\tEND Move to the end of the graph");
|
|
|
|
puts("\tPGUP Page left");
|
|
|
|
puts("\tPGDOWN Page right");
|
2019-03-10 06:35:06 +08:00
|
|
|
puts("\tLEFT Move left");
|
|
|
|
puts("\tRIGHT Move right");
|
2020-09-21 22:16:54 +08:00
|
|
|
puts("\tWHEEL MOUSE UP Move left");
|
2020-09-21 22:05:38 +08:00
|
|
|
puts("\tWHEEL MOUSE DOWN Move right");
|
2020-09-21 22:16:54 +08:00
|
|
|
puts("\t<CTLR> LEFT Move left 1 sample");
|
2019-03-10 06:35:06 +08:00
|
|
|
puts("\t<CTLR> RIGHT Move right 1 sample");
|
2020-09-21 22:16:54 +08:00
|
|
|
puts("\t<SHIFT> LEFT Page left");
|
2019-03-10 06:35:06 +08:00
|
|
|
puts("\t<SHIFT> RIGHT Page right");
|
2020-09-21 22:16:54 +08:00
|
|
|
puts("\tLEFT MOUSE CLICK Set yellow cursor");
|
2019-03-10 06:35:06 +08:00
|
|
|
puts("\tRIGHT MOUSE CLICK Set purple cursor");
|
|
|
|
puts("-----------------------------------------------------------------------");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_L:
|
|
|
|
GridLocked = !GridLocked;
|
|
|
|
if (GridLocked)
|
|
|
|
GridOffset += (GraphStart - unlockStart);
|
|
|
|
else
|
|
|
|
unlockStart = GraphStart;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_Q:
|
|
|
|
master->hide();
|
|
|
|
break;
|
|
|
|
|
2020-10-05 02:01:27 +08:00
|
|
|
case Qt::Key_T:
|
|
|
|
Trim();
|
|
|
|
break;
|
|
|
|
|
2019-05-14 08:39:27 +08:00
|
|
|
case Qt::Key_Home:
|
|
|
|
GraphStart = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_End:
|
|
|
|
GraphStart = startMax;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
if (GraphStart >= PageWidth) {
|
|
|
|
GraphStart -= PageWidth;
|
|
|
|
} else {
|
|
|
|
GraphStart = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
GraphStart += PageWidth;
|
2019-05-14 23:12:46 +08:00
|
|
|
if (GraphStart > startMax)
|
|
|
|
GraphStart = startMax;
|
2019-05-14 08:39:27 +08:00
|
|
|
break;
|
|
|
|
|
2019-03-10 06:35:06 +08:00
|
|
|
default:
|
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->update();
|
2009-04-09 14:43:20 +08:00
|
|
|
}
|