]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/proxguiqt.cpp
Update cmdhficlass.h
[proxmark3-svn] / client / proxguiqt.cpp
index c0aff8b6a5ce3b89035bab3e8ca8c37aec708f00..dc8279b52ec340596c6420deb94634c561bd7457 100644 (file)
@@ -7,7 +7,9 @@
 //-----------------------------------------------------------------------------
 // GUI (QT)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // GUI (QT)
 //-----------------------------------------------------------------------------
+#include "proxguiqt.h"
 
 
+#include <stdbool.h>
 #include <iostream>
 #include <QPainterPath>
 #include <QBrush>
 #include <iostream>
 #include <QPainterPath>
 #include <QBrush>
 #include <math.h>
 #include <limits.h>
 #include <stdio.h>
 #include <math.h>
 #include <limits.h>
 #include <stdio.h>
+#include <QSlider>
 #include <QHBoxLayout>
 #include <string.h>
 #include <QHBoxLayout>
 #include <string.h>
-#include "proxguiqt.h"
 #include "proxgui.h"
 #include <QtGui>
 //#include <ctime>
 
 #include "proxgui.h"
 #include <QtGui>
 //#include <ctime>
 
-
+bool g_useOverlays = false;
+int g_absVMax = 0;
 int startMax;
 int PageWidth;
 int startMax;
 int PageWidth;
+int unlockStart = 0;
 
 void ProxGuiQT::ShowGraphWindow(void)
 {
 
 void ProxGuiQT::ShowGraphWindow(void)
 {
@@ -45,6 +49,11 @@ void ProxGuiQT::HideGraphWindow(void)
        emit HideGraphWindowSignal();
 }
 
        emit HideGraphWindowSignal();
 }
 
+void ProxGuiQT::Exit(void)
+{
+       emit ExitSignal();
+}
+
 void ProxGuiQT::_ShowGraphWindow(void)
 {
        if(!plotapp)
 void ProxGuiQT::_ShowGraphWindow(void)
 {
        if(!plotapp)
@@ -72,6 +81,21 @@ void ProxGuiQT::_HideGraphWindow(void)
        plotwidget->hide();
 }
 
        plotwidget->hide();
 }
 
+void ProxGuiQT::_Exit(void) {
+       delete this;
+}
+
+void ProxGuiQT::_StartProxmarkThread(void) {
+       if (!proxmarkThread)
+               return;
+
+       // 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();
+}
+
 void ProxGuiQT::MainLoop()
 {
        plotapp = new QApplication(argc, argv);
 void ProxGuiQT::MainLoop()
 {
        plotapp = new QApplication(argc, argv);
@@ -79,26 +103,29 @@ void ProxGuiQT::MainLoop()
        connect(this, SIGNAL(ShowGraphWindowSignal()), this, SLOT(_ShowGraphWindow()));
        connect(this, SIGNAL(RepaintGraphWindowSignal()), this, SLOT(_RepaintGraphWindow()));
        connect(this, SIGNAL(HideGraphWindowSignal()), this, SLOT(_HideGraphWindow()));
        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()));
+
+       //start proxmark thread after starting event loop
+       QTimer::singleShot(200, this, SLOT(_StartProxmarkThread()));
 
        plotapp->exec();
 }
 
 
        plotapp->exec();
 }
 
-ProxGuiQT::ProxGuiQT(int argc, char **argv) : plotapp(NULL), plotwidget(NULL),
-       argc(argc), argv(argv)
+ProxGuiQT::ProxGuiQT(int argc, char **argv, WorkerThread *wthread) : plotapp(NULL), plotwidget(NULL),
+       argc(argc), argv(argv), proxmarkThread(wthread)
 {
 }
 
 ProxGuiQT::~ProxGuiQT(void)
 {
 {
 }
 
 ProxGuiQT::~ProxGuiQT(void)
 {
-       if (plotwidget) {
-               //plotwidget->close();
-               delete plotwidget;
-               plotwidget = NULL;
-       }
-
+       //if (plotwidget) {
+               //plotwidget->destroy(true,true);
+       //      delete plotwidget;
+       //      plotwidget = NULL;
+       //}
        if (plotapp) {
                plotapp->quit();
        if (plotapp) {
                plotapp->quit();
-               delete plotapp;
+               // delete plotapp;
                plotapp = NULL;
        }
 }
                plotapp = NULL;
        }
 }
@@ -106,38 +133,48 @@ ProxGuiQT::~ProxGuiQT(void)
 //--------------------
 void ProxWidget::applyOperation()
 {
 //--------------------
 void ProxWidget::applyOperation()
 {
-       printf("ApplyOperation()");
-       save_restoreGB(1);
-       memcpy(GraphBuffer,s_Buff, sizeof(int) * GraphTraceLen);
+       //printf("ApplyOperation()");
+       save_restoreGB(GRAPH_SAVE);
+       memcpy(GraphBuffer, s_Buff, sizeof(int) * GraphTraceLen);
        RepaintGraphWindow();
        RepaintGraphWindow();
-
 }
 void ProxWidget::stickOperation()
 {
 }
 void ProxWidget::stickOperation()
 {
-       save_restoreGB(0);
-       printf("stickOperation()");
+       save_restoreGB(GRAPH_RESTORE);
+       //printf("stickOperation()");
 }
 void ProxWidget::vchange_autocorr(int v)
 {
 }
 void ProxWidget::vchange_autocorr(int v)
 {
-       autoCorr(GraphBuffer,s_Buff, GraphTraceLen, v);
-       printf("vchange_autocorr(%d)\n", v);
+       int ans;
+       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();
+}
+void ProxWidget::vchange_askedge(int v)
+{
+       int ans;
+       //extern int AskEdgeDetect(const int *in, int *out, int len, int threshold);
+       ans = AskEdgeDetect(GraphBuffer, s_Buff, GraphTraceLen, v);
+       if (g_debugMode) printf("vchange_askedge(w:%d)%d\n", v, ans);
+       g_useOverlays = true;
        RepaintGraphWindow();
 }
 void ProxWidget::vchange_dthr_up(int v)
 {
        int down = opsController->horizontalSlider_dirthr_down->value();
        RepaintGraphWindow();
 }
 void ProxWidget::vchange_dthr_up(int v)
 {
        int down = opsController->horizontalSlider_dirthr_down->value();
-       directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, down);
-       printf("vchange_dthr_up(%d)", v);
+       directionalThreshold(GraphBuffer, s_Buff, GraphTraceLen, v, down);
+       //printf("vchange_dthr_up(%d)", v);
+       g_useOverlays = true;
        RepaintGraphWindow();
        RepaintGraphWindow();
-
 }
 void ProxWidget::vchange_dthr_down(int v)
 {
 }
 void ProxWidget::vchange_dthr_down(int v)
 {
-       printf("vchange_dthr_down(%d)", v);
+       //printf("vchange_dthr_down(%d)", v);
        int up = opsController->horizontalSlider_dirthr_up->value();
        directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up);
        int up = opsController->horizontalSlider_dirthr_up->value();
        directionalThreshold(GraphBuffer,s_Buff, GraphTraceLen, v, up);
+       g_useOverlays = true;
        RepaintGraphWindow();
        RepaintGraphWindow();
-
 }
 ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
 {
 }
 ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
 {
@@ -146,13 +183,18 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
 
        /** Setup the controller widget **/
 
 
        /** Setup the controller widget **/
 
-       QWidget* controlWidget = new QWidget();
+       controlWidget = new QWidget();
        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 = 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_apply, SIGNAL(clicked()), this, SLOT(applyOperation()));
@@ -160,6 +202,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
        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_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)));
 
        controlWidget->show();
 
 
        controlWidget->show();
 
@@ -180,6 +223,41 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent)
        //printf("Proxwidget Constructor just set layout\r\n");
 }
 
        //printf("Proxwidget Constructor just set layout\r\n");
 }
 
+// not 100% sure what i need in this block
+// feel free to fix - marshmellow...
+ProxWidget::~ProxWidget(void)
+{
+       if (controlWidget) {
+               controlWidget->close();
+               delete controlWidget;
+               controlWidget = NULL;
+       }
+
+       if (opsController) {
+               delete opsController;
+               opsController = NULL;
+       }
+
+       if (plot) {
+               plot->close();
+               delete plot;
+               plot = NULL;
+       }
+}
+void ProxWidget::closeEvent(QCloseEvent *event)
+{
+       event->ignore();
+       this->hide();
+       g_useOverlays = false;
+}
+void ProxWidget::hideEvent(QHideEvent *event) {
+       controlWidget->hide();
+       plot->hide();
+}
+void ProxWidget::showEvent(QShowEvent *event) {
+       controlWidget->show();
+       plot->show();
+}
 
 //----------- Plotting
 
 
 //----------- Plotting
 
@@ -214,6 +292,32 @@ QColor Plot::getColor(int graphNum)
        }
 }
 
        }
 }
 
+void Plot::setMaxAndStart(int *buffer, int len, QRect plotRect)
+{
+       if (len == 0) return;
+       startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
+       if(startMax < 0) {
+               startMax = 0;
+       }
+       if(GraphStart > startMax) {
+               GraphStart = startMax;
+       }
+       if (GraphStart > len) return;
+       int vMin = INT_MAX, vMax = INT_MIN, v = 0;
+       int sample_index = GraphStart ;
+       for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
+
+               v = buffer[sample_index];
+               if(v < vMin) vMin = v;
+               if(v > vMax) vMax = v;
+       }
+
+       g_absVMax = 0;
+       if(fabs( (double) vMin) > g_absVMax) g_absVMax = (int)fabs( (double) vMin);
+       if(fabs( (double) vMax) > g_absVMax) g_absVMax = (int)fabs( (double) vMax);
+       g_absVMax = (int)(g_absVMax*1.25 + 1);
+}
+
 void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
 {
        if (len == 0 || PlotGridX <= 0) return;
 void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, int plotOffset)
 {
        if (len == 0 || PlotGridX <= 0) return;
@@ -230,7 +334,7 @@ void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotati
        // round down
        if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1;
        first_delta_x += BitStart * PlotGridX;
        // round down
        if (DemodStart-plotOffset > 0) BitStart = (int)(((DemodStart-plotOffset)+(PlotGridX-1))/PlotGridX)-1;
        first_delta_x += BitStart * PlotGridX;
-       if (BitStart > len) return;
+       if (BitStart > (int)len) return;
        int delta_x = 0;
        int v = 0;
        //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
        int delta_x = 0;
        int v = 0;
        //printf("first_delta_x %i, grid_delta_x %i, DemodStart %i, BitStart %i\n",first_delta_x,grid_delta_x,DemodStart, BitStart);
@@ -243,8 +347,8 @@ void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotati
        penPath.moveTo(x, y);
        delta_x = 0;
        int clk = first_delta_x;
        penPath.moveTo(x, y);
        delta_x = 0;
        int clk = first_delta_x;
-       for(int i = BitStart; i < len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) {
-               for (int ii = 0; ii < (clk) && i < len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) {
+       for(int i = BitStart; i < (int)len && xCoordOf(delta_x+DemodStart, plotRect) < plotRect.right(); i++) {
+               for (int ii = 0; ii < (clk) && i < (int)len && xCoordOf(DemodStart+delta_x+ii, plotRect) < plotRect.right() ; ii++ ) {
                        x = xCoordOf(DemodStart+delta_x+ii, plotRect);
                        v = buffer[i]*200-100;
 
                        x = xCoordOf(DemodStart+delta_x+ii, plotRect);
                        v = buffer[i]*200-100;
 
@@ -275,47 +379,16 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
        if (len == 0) return;
        //clock_t begin = clock();
        QPainterPath penPath;
        if (len == 0) return;
        //clock_t begin = clock();
        QPainterPath penPath;
-
-       startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint));
-       if(startMax < 0) {
-               startMax = 0;
-       }
-       if(GraphStart > startMax) {
-               GraphStart = startMax;
-       }
-       if (GraphStart > len) return;
-       int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, absVMax = 0;
-       int sample_index = GraphStart ;
-       for( ; sample_index < len && xCoordOf(sample_index,plotRect) < plotRect.right() ; sample_index++) {
-
-               v = buffer[sample_index];
-               if(v < vMin) vMin = v;
-               if(v > vMax) vMax = v;
-               vMean += v;
-       }
-
-       vMean /= (sample_index - GraphStart);
-
-       if(fabs( (double) vMin) > absVMax) absVMax = (int)fabs( (double) vMin);
-       if(fabs( (double) vMax) > absVMax) absVMax = (int)fabs( (double) vMax);
-       absVMax = (int)(absVMax*1.25 + 1);
-       // number of points that will be plotted
-       int span = (int)((plotRect.right() - plotRect.left()) / GraphPixelsPerPoint);
-       // one label every 100 pixels, let us say
-       int labels = (plotRect.right() - plotRect.left() - 40) / 100;
-       if(labels <= 0) labels = 1;
-       int pointsPerLabel = span / labels;
-       if(pointsPerLabel <= 0) pointsPerLabel = 1;
-
+       int vMin = INT_MAX, vMax = INT_MIN, vMean = 0, v = 0, i = 0;
        int x = xCoordOf(GraphStart, plotRect);
        int x = xCoordOf(GraphStart, plotRect);
-       int y = yCoordOf(buffer[GraphStart],plotRect,absVMax);
+       int y = yCoordOf(buffer[GraphStart],plotRect,g_absVMax);
        penPath.moveTo(x, y);
        penPath.moveTo(x, y);
-       for(int i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
+       for(i = GraphStart; i < len && xCoordOf(i, plotRect) < plotRect.right(); i++) {
 
                x = xCoordOf(i, plotRect);
                v = buffer[i];
 
 
                x = xCoordOf(i, plotRect);
                v = buffer[i];
 
-               y = yCoordOf( v, plotRect, absVMax);//(y * (r.top() - r.bottom()) / (2*absYMax)) + zeroHeight;
+               y = yCoordOf( v, plotRect, g_absVMax);
 
                penPath.lineTo(x, y);
 
 
                penPath.lineTo(x, y);
 
@@ -323,7 +396,12 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
                        QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
                        painter->fillRect(f, QColor(100, 255, 100));
                }
                        QRect f(QPoint(x - 3, y - 3),QPoint(x + 3, y + 3));
                        painter->fillRect(f, QColor(100, 255, 100));
                }
+               //catch stats
+               if(v < vMin) vMin = v;
+               if(v > vMax) vMax = v;
+               vMean += v;
        }
        }
+       vMean /= (i - GraphStart);
 
        painter->setPen(getColor(graphNum));
 
 
        painter->setPen(getColor(graphNum));
 
@@ -331,7 +409,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
        int xo = 5+(graphNum*40);
        painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
 
        int xo = 5+(graphNum*40);
        painter->drawLine(xo, plotRect.top(),xo, plotRect.bottom());
 
-       int vMarkers = (absVMax - (absVMax % 10)) / 5;
+       int vMarkers = (g_absVMax - (g_absVMax % 10)) / 5;
        int minYDist = 40; //Minimum pixel-distance between markers
 
        char yLbl[20];
        int minYDist = 40; //Minimum pixel-distance between markers
 
        char yLbl[20];
@@ -339,10 +417,10 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
        int n = 0;
        int lasty0 = 65535;
 
        int n = 0;
        int lasty0 = 65535;
 
-       for(int v = vMarkers; yCoordOf(v,plotRect,absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
+       for(v = vMarkers; yCoordOf(v,plotRect,g_absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
        {
        {
-               int y0 = yCoordOf(v,plotRect,absVMax);
-               int y1 = yCoordOf(-v,plotRect,absVMax);
+               int y0 = yCoordOf(v,plotRect,g_absVMax);
+               int y1 = yCoordOf(-v,plotRect,g_absVMax);
 
                if(lasty0 - y0 < minYDist) continue;
 
 
                if(lasty0 - y0 < minYDist) continue;
 
@@ -361,7 +439,7 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
        painter->drawPath(penPath);
        char str[200];
        sprintf(str, "max=%d  min=%d  mean=%d  n=%d/%d  CursorAVal=[%d]  CursorBVal=[%d]",
        painter->drawPath(penPath);
        char str[200];
        sprintf(str, "max=%d  min=%d  mean=%d  n=%d/%d  CursorAVal=[%d]  CursorBVal=[%d]",
-                       vMax, vMin, vMean, sample_index, len, buffer[CursorAPos], buffer[CursorBPos]);
+                       vMax, vMin, vMean, i, len, buffer[CursorAPos], buffer[CursorBPos]);
        painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
 
        //clock_t end = clock();
        painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
 
        //clock_t end = clock();
@@ -371,20 +449,29 @@ void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,
 
 void Plot::plotGridLines(QPainter* painter,QRect r)
 {
 
 void Plot::plotGridLines(QPainter* painter,QRect r)
 {
-       int zeroHeight = r.top() + (r.bottom() - r.top()) / 2;
+       // set GridOffset
+       if (PlotGridX <= 0) return;
+       int offset = GridOffset;
+       if (GridLocked && PlotGridX) {
+               offset = GridOffset + PlotGridX - (GraphStart % PlotGridX);
+       } else if (!GridLocked && GraphStart > 0 && PlotGridX) {
+               offset = PlotGridX-((GraphStart - offset) % PlotGridX) + GraphStart - unlockStart;
+       }
+       offset %= PlotGridX;
+       if (offset < 0) offset += PlotGridX;
 
        int i;
        int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
 
        int i;
        int grid_delta_x = (int) (PlotGridX * GraphPixelsPerPoint);
-       int grid_delta_y = (int) (PlotGridY * GraphPixelsPerPoint);
+       int grid_delta_y = PlotGridY;
        if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
        if ((PlotGridX > 0) && ((PlotGridX * GraphPixelsPerPoint) > 1)) {
-               for(i = (GridOffset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
+               for(i = (offset * GraphPixelsPerPoint); i < r.right(); i += grid_delta_x) {
                        painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
                } 
                        painter->drawLine(r.left()+i, r.top(), r.left()+i, r.bottom());
                } 
-       } 
-       if ((PlotGridY > 0) && ((PlotGridY * GraphPixelsPerPoint) > 1)){
-               for(i = 0; i < ((r.top() + r.bottom())>>1); i += grid_delta_y) {
-                       painter->drawLine(r.left(),zeroHeight + i,r.right(),zeroHeight + i);
-                       painter->drawLine(r.left(),zeroHeight - i,r.right(),zeroHeight - i);
+       }
+       if (PlotGridY > 0) {
+               for(i = 0; yCoordOf(i,r,g_absVMax) > r.top(); i += grid_delta_y) {
+                       painter->drawLine( r.left(), yCoordOf(i,r,g_absVMax), r.right(), yCoordOf(i,r,g_absVMax) );
+                       painter->drawLine( r.left(), yCoordOf(i*-1,r,g_absVMax), r.right(), yCoordOf(i*-1,r,g_absVMax) );
                }
        }
 }
                }
        }
 }
@@ -394,9 +481,8 @@ void Plot::plotGridLines(QPainter* painter,QRect r)
 
 void Plot::paintEvent(QPaintEvent *event)
 {
 
 void Plot::paintEvent(QPaintEvent *event)
 {
+
        QPainter painter(this);
        QPainter painter(this);
-       //QPainterPath penPath, whitePath, greyPath, lightgreyPath, cursorAPath, cursorBPath, cursorCPath, cursorDPath;
-       //QRect r;
        QBrush brush(QColor(100, 255, 100));
        QPen pen(QColor(100, 255, 100));
 
        QBrush brush(QColor(100, 255, 100));
        QPen pen(QColor(100, 255, 100));
 
@@ -423,6 +509,9 @@ void Plot::paintEvent(QPaintEvent *event)
        //Black foreground
        painter.fillRect(plotRect, QColor(0, 0, 0));
 
        //Black foreground
        painter.fillRect(plotRect, QColor(0, 0, 0));
 
+       //init graph variables
+       setMaxAndStart(GraphBuffer,GraphTraceLen,plotRect);
+
        // center line
        int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
        painter.setPen(QColor(100, 100, 100));
        // center line
        int zeroHeight = plotRect.top() + (plotRect.bottom() - plotRect.top()) / 2;
        painter.setPen(QColor(100, 100, 100));
@@ -432,10 +521,14 @@ void Plot::paintEvent(QPaintEvent *event)
 
        //Start painting graph
        PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
 
        //Start painting graph
        PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
-       PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
        if (showDemod && DemodBufferLen > 8) {
                PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
        }
        if (showDemod && DemodBufferLen > 8) {
                PlotDemod(DemodBuffer, DemodBufferLen,plotRect,infoRect,&painter,2,g_DemodStartIdx);
        }
+       if (g_useOverlays) {
+               //init graph variables
+               setMaxAndStart(s_Buff,GraphTraceLen,plotRect);
+               PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
+       }
        // End graph drawing
 
        //Draw the cursors
        // End graph drawing
 
        //Draw the cursors
@@ -472,6 +565,7 @@ void Plot::paintEvent(QPaintEvent *event)
 
 Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
 {
 
 Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
 {
+       //Need to set this, otherwise we don't receive keypress events
        setFocusPolicy( Qt::StrongFocus);
        resize(600, 300);
 
        setFocusPolicy( Qt::StrongFocus);
        resize(600, 300);
 
@@ -491,6 +585,7 @@ void Plot::closeEvent(QCloseEvent *event)
 {
        event->ignore();
        this->hide();
 {
        event->ignore();
        this->hide();
+       g_useOverlays = false;
 }
 
 void Plot::mouseMoveEvent(QMouseEvent *event)
 }
 
 void Plot::mouseMoveEvent(QMouseEvent *event)
@@ -512,9 +607,6 @@ void Plot::mouseMoveEvent(QMouseEvent *event)
 void Plot::keyPressEvent(QKeyEvent *event)
 {
        int     offset;
 void Plot::keyPressEvent(QKeyEvent *event)
 {
        int     offset;
-       int     gridchanged;
-
-       gridchanged= 0;
 
        if(event->modifiers() & Qt::ShiftModifier) {
                if (PlotGridX)
 
        if(event->modifiers() & Qt::ShiftModifier) {
                if (PlotGridX)
@@ -542,53 +634,18 @@ void Plot::keyPressEvent(QKeyEvent *event)
 
                case Qt::Key_Right:
                        if(GraphPixelsPerPoint < 20) {
 
                case Qt::Key_Right:
                        if(GraphPixelsPerPoint < 20) {
-                               if (PlotGridX && GridLocked && GraphStart < startMax){
-                                       GridOffset -= offset;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart += offset;
                        } else {
                                GraphStart += offset;
                        } else {
-                               if (PlotGridX && GridLocked && GraphStart < startMax){
-                                       GridOffset--;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart++;
                        }
                                GraphStart++;
                        }
-                       if(GridOffset < 0) {
-                               GridOffset += PlotGridX;
-                       }
-                       if (gridchanged)
-                               if (GraphStart > startMax) {
-                                       GridOffset += (GraphStart - startMax);
-                                       GridOffset %= PlotGridX;
-                               }
                        break;
 
                case Qt::Key_Left:
                        if(GraphPixelsPerPoint < 20) {
                        break;
 
                case Qt::Key_Left:
                        if(GraphPixelsPerPoint < 20) {
-                               if (PlotGridX && GridLocked && GraphStart > 0){
-                                       GridOffset += offset;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart -= offset;
                        } else {
                                GraphStart -= offset;
                        } else {
-                               if (PlotGridX && GridLocked && GraphStart > 0){
-                                       GridOffset++;
-                                       GridOffset %= PlotGridX;
-                                       gridchanged= 1;
-                               }
                                GraphStart--;
                        }
                                GraphStart--;
                        }
-                       if (gridchanged){
-                               if (GraphStart < 0)
-                                       GridOffset += GraphStart;
-                               if(GridOffset < 0)
-                                       GridOffset += PlotGridX;
-                       GridOffset %= PlotGridX;
-                       }
                        break;
 
                case Qt::Key_G:
                        break;
 
                case Qt::Key_G:
@@ -598,7 +655,7 @@ void Plot::keyPressEvent(QKeyEvent *event)
                        } else {
                                PlotGridX= PlotGridXdefault;
                                PlotGridY= PlotGridYdefault;
                        } else {
                                PlotGridX= PlotGridXdefault;
                                PlotGridY= PlotGridYdefault;
-                               }
+                       }
                        break;
 
                case Qt::Key_H:
                        break;
 
                case Qt::Key_H:
@@ -623,7 +680,11 @@ void Plot::keyPressEvent(QKeyEvent *event)
                        break;
 
                case Qt::Key_L:
                        break;
 
                case Qt::Key_L:
-                       GridLocked= !GridLocked;
+                       GridLocked = !GridLocked;
+                       if (GridLocked)
+                               GridOffset += (GraphStart - unlockStart);
+                       else
+                               unlockStart = GraphStart;
                        break;
 
                case Qt::Key_Q:
                        break;
 
                case Qt::Key_Q:
Impressum, Datenschutz