syntax sugar

This commit is contained in:
iceman1001 2017-08-11 18:15:01 +02:00
commit dc0e0aa93f
3 changed files with 53 additions and 53 deletions

View file

@ -29,48 +29,46 @@ void WorkerThread::run() {
extern "C" void ShowGraphWindow(void) extern "C" void ShowGraphWindow(void)
{ {
if (!gui) if (!gui)
return; return;
gui->ShowGraphWindow();
gui->ShowGraphWindow();
} }
extern "C" void HideGraphWindow(void) extern "C" void HideGraphWindow(void)
{ {
if (!gui) if (!gui)
return; return;
gui->HideGraphWindow();
gui->HideGraphWindow();
} }
extern "C" void RepaintGraphWindow(void) extern "C" void RepaintGraphWindow(void)
{ {
if (!gui) if (!gui)
return; return;
gui->RepaintGraphWindow(); gui->RepaintGraphWindow();
} }
extern "C" void MainGraphics(void) extern "C" void MainGraphics(void)
{ {
if (!gui) if (!gui)
return; return;
main_loop_thread->start(); main_loop_thread->start();
gui->MainLoop(); gui->MainLoop();
} }
extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool usb_present) extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, bool usb_present)
{ {
#ifdef Q_WS_X11 #ifdef Q_WS_X11
bool useGUI = getenv("DISPLAY") != 0; bool useGUI = getenv("DISPLAY") != 0;
#else #else
bool useGUI = true; bool useGUI = true;
#endif #endif
if (!useGUI) if (!useGUI)
return; return;
gui = new ProxGuiQT(argc, argv); gui = new ProxGuiQT(argc, argv);
main_loop_thread = new WorkerThread(script_cmds_file, usb_present); 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()), main_loop_thread, SLOT(deleteLater()));
QObject::connect(main_loop_thread, SIGNAL(finished()), gui, SLOT(_Exit())); 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) extern "C" void ExitGraphics(void)
{ {
if (!gui) if (!gui)
return; return;
gui->Exit(); gui->Exit();
gui = NULL; gui = NULL;
} }

View file

@ -26,7 +26,6 @@
#include <string.h> #include <string.h>
#include "proxgui.h" #include "proxgui.h"
#include <QtGui> #include <QtGui>
// #include <ctime>
bool g_useOverlays = false; bool g_useOverlays = false;
int g_absVMax = 0; int g_absVMax = 0;
@ -434,24 +433,22 @@ void Plot::plotGridLines(QPainter* painter,QRect r) {
void Plot::paintEvent(QPaintEvent *event) void Plot::paintEvent(QPaintEvent *event)
{ {
QPainter painter(this); QPainter painter(this);
QBrush brush(QColor(100, 255, 100)); QBrush brush(QColor(100, 255, 100));
QPen pen(QColor(100, 255, 100)); QPen pen(QColor(100, 255, 100));
painter.setFont(QFont("Courier New", 10)); painter.setFont(QFont("Courier New", 10));
if(GraphStart < 0) { if(GraphStart < 0)
GraphStart = 0; GraphStart = 0;
}
if (CursorAPos > GraphTraceLen) if (CursorAPos > GraphTraceLen)
CursorAPos= 0; CursorAPos= 0;
if(CursorBPos > GraphTraceLen) if (CursorBPos > GraphTraceLen)
CursorBPos= 0; CursorBPos= 0;
if(CursorCPos > GraphTraceLen) if (CursorCPos > GraphTraceLen)
CursorCPos= 0; CursorCPos= 0;
if(CursorDPos > GraphTraceLen) if (CursorDPos > GraphTraceLen)
CursorDPos= 0; CursorDPos= 0;
QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO); QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
@ -485,23 +482,19 @@ void Plot::paintEvent(QPaintEvent *event)
// End graph drawing // End graph drawing
//Draw the cursors //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.setPen(QColor(255, 255, 0));
painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom()); 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.setPen(QColor(255, 0, 255));
painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom()); 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.setPen(QColor(255, 153, 0)); //orange
painter.drawLine(xCoordOf(CursorCPos, plotRect),plotRect.top(),xCoordOf(CursorCPos, plotRect),plotRect.bottom()); 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.setPen(QColor(0, 0, 205)); //light blue
painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom()); painter.drawLine(xCoordOf(CursorDPos, plotRect),plotRect.top(),xCoordOf(CursorDPos, plotRect),plotRect.bottom());
} }
@ -509,11 +502,19 @@ void Plot::paintEvent(QPaintEvent *event)
//Draw annotations //Draw annotations
char str[200]; char str[200];
sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d", 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, GraphStart,
GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked",GridOffset); CursorBPos - CursorAPos,
(CursorBPos - CursorAPos)/CursorScaleFactor,
GraphPixelsPerPoint,
CursorAPos,
CursorBPos,
PlotGridXdefault,
PlotGridYdefault,
GridLocked ? "Locked" : "Unlocked",
GridOffset
);
painter.setPen(QColor(255, 255, 255)); painter.setPen(QColor(255, 255, 255));
painter.drawText(20, infoRect.bottom() - 3, str); painter.drawText(20, infoRect.bottom() - 3, str);
} }
Plot::Plot(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) 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) { } else if (event->buttons() & Qt::RightButton) {
CursorBPos = x; CursorBPos = x;
} }
this->update(); this->update();
} }

View file

@ -40,6 +40,7 @@ class Plot: public QWidget
int valueOf_yCoord(int y, QRect r, int maxVal); int valueOf_yCoord(int y, QRect r, int maxVal);
void setMaxAndStart(int *buffer, int len, QRect plotRect); void setMaxAndStart(int *buffer, int len, QRect plotRect);
QColor getColor(int graphNum); QColor getColor(int graphNum);
public: public:
Plot(QWidget *parent = 0); Plot(QWidget *parent = 0);
@ -49,7 +50,6 @@ class Plot: public QWidget
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); } void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); }
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
}; };
class ProxGuiQT; class ProxGuiQT;
@ -98,7 +98,7 @@ class ProxGuiQT : public QObject
int argc; int argc;
char **argv; char **argv;
void (*main_func)(void); void (*main_func)(void);
public: public:
ProxGuiQT(int argc, char **argv); ProxGuiQT(int argc, char **argv);
~ProxGuiQT(void); ~ProxGuiQT(void);
@ -107,11 +107,13 @@ class ProxGuiQT : public QObject
void HideGraphWindow(void); void HideGraphWindow(void);
void MainLoop(void); void MainLoop(void);
void Exit(void); void Exit(void);
private slots: private slots:
void _ShowGraphWindow(void); void _ShowGraphWindow(void);
void _RepaintGraphWindow(void); void _RepaintGraphWindow(void);
void _HideGraphWindow(void); void _HideGraphWindow(void);
void _Exit(void); void _Exit(void);
signals: signals:
void ShowGraphWindowSignal(void); void ShowGraphWindowSignal(void);
void RepaintGraphWindowSignal(void); void RepaintGraphWindowSignal(void);
@ -119,16 +121,17 @@ class ProxGuiQT : public QObject
void ExitSignal(void); void ExitSignal(void);
}; };
class WorkerThread : public QThread { class WorkerThread : public QThread {
Q_OBJECT; Q_OBJECT;
public:
WorkerThread(char*, bool); public:
~WorkerThread(); WorkerThread(char*, bool);
void run(); ~WorkerThread();
private: void run();
char *script_cmds_file = NULL;
bool usb_present; private:
char *script_cmds_file = NULL;
bool usb_present;
}; };
#endif // PROXGUI_QT #endif // PROXGUI_QT