From dc0e0aa93fb7985cc329cbf1a228ed1f5b4c2fe5 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 11 Aug 2017 18:15:01 +0200 Subject: [PATCH] syntax sugar --- client/proxgui.cpp | 44 +++++++++++++++++++++----------------------- client/proxguiqt.cpp | 39 +++++++++++++++++++-------------------- client/proxguiqt.h | 23 +++++++++++++---------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/client/proxgui.cpp b/client/proxgui.cpp index 338691ccb..ab4ff6bec 100644 --- a/client/proxgui.cpp +++ b/client/proxgui.cpp @@ -29,48 +29,46 @@ void WorkerThread::run() { extern "C" void ShowGraphWindow(void) { - if (!gui) - return; - - gui->ShowGraphWindow(); + if (!gui) + return; + gui->ShowGraphWindow(); } extern "C" void HideGraphWindow(void) { - if (!gui) - return; - - gui->HideGraphWindow(); + if (!gui) + return; + gui->HideGraphWindow(); } extern "C" void RepaintGraphWindow(void) { - if (!gui) - return; + if (!gui) + return; - gui->RepaintGraphWindow(); + gui->RepaintGraphWindow(); } extern "C" void MainGraphics(void) { - if (!gui) - return; + if (!gui) + return; main_loop_thread->start(); - gui->MainLoop(); + gui->MainLoop(); } extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool usb_present) { #ifdef Q_WS_X11 - bool useGUI = getenv("DISPLAY") != 0; + bool useGUI = getenv("DISPLAY") != 0; #else - bool useGUI = true; + bool useGUI = true; #endif - if (!useGUI) - return; + if (!useGUI) + return; - gui = new ProxGuiQT(argc, argv); + gui = new ProxGuiQT(argc, argv); main_loop_thread = new WorkerThread(script_cmds_file, usb_present); QObject::connect(main_loop_thread, SIGNAL(finished()), main_loop_thread, SLOT(deleteLater())); QObject::connect(main_loop_thread, SIGNAL(finished()), gui, SLOT(_Exit())); @@ -79,9 +77,9 @@ extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool extern "C" void ExitGraphics(void) { - if (!gui) - return; + if (!gui) + return; - gui->Exit(); - gui = NULL; + gui->Exit(); + gui = NULL; } diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 5ec06552f..b76fa29dd 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -26,7 +26,6 @@ #include #include "proxgui.h" #include -// #include bool g_useOverlays = false; int g_absVMax = 0; @@ -434,24 +433,22 @@ void Plot::plotGridLines(QPainter* painter,QRect r) { void Plot::paintEvent(QPaintEvent *event) { - QPainter painter(this); QBrush brush(QColor(100, 255, 100)); QPen pen(QColor(100, 255, 100)); painter.setFont(QFont("Courier New", 10)); - if(GraphStart < 0) { + if(GraphStart < 0) GraphStart = 0; - } if (CursorAPos > GraphTraceLen) CursorAPos= 0; - if(CursorBPos > GraphTraceLen) + if (CursorBPos > GraphTraceLen) CursorBPos= 0; - if(CursorCPos > GraphTraceLen) + if (CursorCPos > GraphTraceLen) CursorCPos= 0; - if(CursorDPos > GraphTraceLen) + if (CursorDPos > GraphTraceLen) CursorDPos= 0; QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO); @@ -485,23 +482,19 @@ void Plot::paintEvent(QPaintEvent *event) // End graph drawing //Draw the cursors - if(CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right()) - { + if (CursorAPos > GraphStart && xCoordOf(CursorAPos, plotRect) < plotRect.right()) { painter.setPen(QColor(255, 255, 0)); painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom()); } - if(CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right()) - { + if (CursorBPos > GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right()) { painter.setPen(QColor(255, 0, 255)); painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom()); } - if(CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right()) - { + if (CursorCPos > GraphStart && xCoordOf(CursorCPos, plotRect) < plotRect.right()) { painter.setPen(QColor(255, 153, 0)); //orange painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom()); } - if(CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right()) - { + if (CursorDPos > GraphStart && xCoordOf(CursorDPos, plotRect) < plotRect.right()) { painter.setPen(QColor(0, 0, 205)); //light blue painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom()); } @@ -509,11 +502,19 @@ void Plot::paintEvent(QPaintEvent *event) //Draw annotations char str[200]; sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d", - GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor, - GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked",GridOffset); + GraphStart, + CursorBPos - CursorAPos, + (CursorBPos - CursorAPos)/CursorScaleFactor, + GraphPixelsPerPoint, + CursorAPos, + CursorBPos, + PlotGridXdefault, + PlotGridYdefault, + GridLocked ? "Locked" : "Unlocked", + GridOffset + ); painter.setPen(QColor(255, 255, 255)); painter.drawText(20, infoRect.bottom() - 3, str); - } Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) @@ -552,8 +553,6 @@ void Plot::mouseMoveEvent(QMouseEvent *event) } else if (event->buttons() & Qt::RightButton) { CursorBPos = x; } - - this->update(); } diff --git a/client/proxguiqt.h b/client/proxguiqt.h index bb16af14a..267d4e746 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -40,6 +40,7 @@ class Plot: public QWidget int valueOf_yCoord(int y, QRect r, int maxVal); void setMaxAndStart(int *buffer, int len, QRect plotRect); QColor getColor(int graphNum); + public: Plot(QWidget *parent = 0); @@ -49,7 +50,6 @@ class Plot: public QWidget void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } void keyPressEvent(QKeyEvent *event); - }; class ProxGuiQT; @@ -98,7 +98,7 @@ class ProxGuiQT : public QObject int argc; char **argv; void (*main_func)(void); - + public: ProxGuiQT(int argc, char **argv); ~ProxGuiQT(void); @@ -107,11 +107,13 @@ class ProxGuiQT : public QObject void HideGraphWindow(void); void MainLoop(void); void Exit(void); + private slots: void _ShowGraphWindow(void); void _RepaintGraphWindow(void); void _HideGraphWindow(void); void _Exit(void); + signals: void ShowGraphWindowSignal(void); void RepaintGraphWindowSignal(void); @@ -119,16 +121,17 @@ class ProxGuiQT : public QObject void ExitSignal(void); }; - class WorkerThread : public QThread { Q_OBJECT; -public: - WorkerThread(char*, bool); - ~WorkerThread(); - void run(); -private: - char *script_cmds_file = NULL; - bool usb_present; + + public: + WorkerThread(char*, bool); + ~WorkerThread(); + void run(); + + private: + char *script_cmds_file = NULL; + bool usb_present; }; #endif // PROXGUI_QT