syntax sugar

This commit is contained in:
iceman1001 2017-08-11 18:15:01 +02:00
parent 1b4b753d98
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)
{
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;
}

View file

@ -26,7 +26,6 @@
#include <string.h>
#include "proxgui.h"
#include <QtGui>
// #include <ctime>
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();
}

View file

@ -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