Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+52
@@ -0,0 +1,52 @@
|
||||
# copy of displayPanelSimulator for testing with dotMatrixDisplay
|
||||
|
||||
|
||||
SET(displayPanelSimulator_SRCS
|
||||
cmdlineparser.cpp
|
||||
displayPanelSimulatorMain.cpp
|
||||
displayPanelSimulatorTcpServer.cpp
|
||||
displayPanelSimulatorWidget.cpp
|
||||
nglsettings.cpp
|
||||
debugmessages.cpp
|
||||
)
|
||||
|
||||
SET(displayPanelSimulator_HDRS
|
||||
cmdlineparser.h
|
||||
displayPanelSimulatorTcpServer.h
|
||||
displayPanelSimulatorWidget.h
|
||||
nglsettings.h
|
||||
customMapsAndEnum.h
|
||||
debugmessages.h
|
||||
)
|
||||
|
||||
SET(displayPanelSimulator_UICS
|
||||
ui/displayPanelSimulatorWidget.ui
|
||||
ui/debugmessages.ui
|
||||
)
|
||||
|
||||
NGL_WRAP_UI(displayPanelSimulator_SRCS ${displayPanelSimulator_UICS})
|
||||
|
||||
NGL_ADD_EXECUTABLE(WS NO_TRANSLATION displayPanelSimulator
|
||||
${displayPanelSimulator_SRCS}
|
||||
${displayPanelSimulator_HDRS}
|
||||
)
|
||||
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(displayPanelSimulator
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(displayPanelSimulator
|
||||
qledline
|
||||
nglapplication
|
||||
nglwidgets
|
||||
NGLLogger
|
||||
nglsettings
|
||||
Qt5::Core
|
||||
Qt5::Gui
|
||||
Qt5::Widgets
|
||||
Qt5::Network
|
||||
)
|
||||
CONFIGURE_FILE(rheinmetall.jpg ${CMAKE_BINARY_DIR}/rheinmetall.jpg COPYONLY)
|
||||
|
||||
NGL_INSTALL_TARGET_DEVEL(displayPanelSimulator)
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#include "cmdlineparser.h"
|
||||
#include "nglsettings.h"
|
||||
|
||||
|
||||
CmdLineParser::CmdLineParser()
|
||||
: QCommandLineParser()
|
||||
, m_portCount(0)
|
||||
, m_showPort(false)
|
||||
, m_window(false)
|
||||
{
|
||||
}
|
||||
|
||||
CmdLineParser::~CmdLineParser()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool CmdLineParser::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CmdLineParser::setWindow(bool state)
|
||||
{
|
||||
m_window = state;
|
||||
}
|
||||
|
||||
void CmdLineParser::setMode(const QString &mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
}
|
||||
|
||||
void CmdLineParser::setImagePath(const QString &path)
|
||||
{
|
||||
m_imagePath = path;
|
||||
}
|
||||
|
||||
void CmdLineParser::setShowPort(bool port)
|
||||
{
|
||||
m_showPort = port;
|
||||
}
|
||||
|
||||
void CmdLineParser::setPortCount(int count)
|
||||
{
|
||||
m_portCount = count;
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QString>
|
||||
|
||||
class CmdLineParser : public QObject, public QCommandLineParser
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CmdLineParser();
|
||||
~CmdLineParser();
|
||||
bool init();
|
||||
|
||||
// Getters
|
||||
int portCount() const { return m_portCount; }
|
||||
bool showPort() const { return m_showPort; }
|
||||
bool windowMode() const { return m_window; }
|
||||
QString port() const { return m_port; }
|
||||
QString mode() const { return m_mode; }
|
||||
QString ini() const { return m_ini; }
|
||||
QString imagePath() const { return m_imagePath; }
|
||||
|
||||
// Setters
|
||||
void setWindow(bool state);
|
||||
void setPort(const QString &port) { m_port = port; }
|
||||
void setMode(const QString &mode);
|
||||
void setIni(const QString &ini) { m_ini = ini; }
|
||||
void setImagePath(const QString &path);
|
||||
void setShowPort(bool port);
|
||||
void setPortCount(int count);
|
||||
|
||||
private:
|
||||
int m_portCount;
|
||||
bool m_showPort;
|
||||
bool m_window;
|
||||
QString m_port;
|
||||
QString m_mode;
|
||||
QString m_ini;
|
||||
QString m_imagePath;
|
||||
};
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Provides structs, typedefs and an enum
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
|
||||
struct Mode
|
||||
{
|
||||
QString name;
|
||||
int lines = 0;
|
||||
int letters = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
struct Port
|
||||
{
|
||||
int port = 0;
|
||||
QString name;
|
||||
};
|
||||
|
||||
typedef QMap<QString, Mode> ModeMap;
|
||||
typedef QMap<int, Port> PortMap;
|
||||
|
||||
enum MsgLvl
|
||||
{
|
||||
MSGLVL_TRACE = 1,
|
||||
MSGLVL_DEBUG = 2,
|
||||
MSGLVL_INFO = 3,
|
||||
MSGLVL_WARNING = 4,
|
||||
MSGLVL_ERROR = 5,
|
||||
MSGLVL_FATAL = 6
|
||||
};
|
||||
|
||||
inline static QString levelName(MsgLvl lvl)
|
||||
{
|
||||
switch (lvl)
|
||||
{
|
||||
case MSGLVL_TRACE:
|
||||
return QStringLiteral("Trace");
|
||||
case MSGLVL_DEBUG:
|
||||
return QStringLiteral("Debug");
|
||||
case MSGLVL_INFO:
|
||||
return QStringLiteral("Info");
|
||||
case MSGLVL_WARNING:
|
||||
return QStringLiteral("Warning");
|
||||
case MSGLVL_ERROR:
|
||||
return QStringLiteral("Error");
|
||||
case MSGLVL_FATAL:
|
||||
return QStringLiteral("Fatal");
|
||||
}
|
||||
return QStringLiteral("Unknown (%1)").arg(lvl);
|
||||
}
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Pop-Up-Window, shows the Debug-Log
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 18. Mar 2016
|
||||
*/
|
||||
#include "debugmessages.h"
|
||||
#include "ui_debugmessages.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
DebugMessages::DebugMessages(QWidget *parent)
|
||||
: NGLDialog(parent)
|
||||
, m_ui(new Ui::DebugMessages)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onClose,
|
||||
this, &DebugMessages::hide);
|
||||
connect(m_ui->nglDialogButtonBox, &NGLDialogButtonBox::onReset,
|
||||
m_ui->tbMain, &QTextBrowser::clear);
|
||||
}
|
||||
|
||||
DebugMessages::~DebugMessages()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void DebugMessages::onMessage(int port, const QString &msg, const MsgLvl &lvl)
|
||||
{
|
||||
QString color;
|
||||
switch (lvl)
|
||||
{
|
||||
case MSGLVL_DEBUG:
|
||||
case MSGLVL_TRACE:
|
||||
case MSGLVL_INFO:
|
||||
default:
|
||||
color = QStringLiteral("black");
|
||||
break;
|
||||
case MSGLVL_WARNING:
|
||||
color = QStringLiteral("orange");
|
||||
break;
|
||||
case MSGLVL_ERROR:
|
||||
case MSGLVL_FATAL:
|
||||
color = QStringLiteral("red");
|
||||
break;
|
||||
}
|
||||
|
||||
// Output to the to the Debug-Window
|
||||
m_ui->tbMain->append(QStringLiteral("<div style='color:%1'>%2\t \t| %3\t| %4 %6: %5</div>")
|
||||
.arg(color, QDateTime::currentDateTime().toString(), levelName(lvl), tr("port"), msg)
|
||||
.arg(port));
|
||||
|
||||
if (lvl == MSGLVL_FATAL)
|
||||
QMessageBox::warning(this, tr("Error"), msg);
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Provides structs, typedefs and an enum
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nglwidgets/ngldialog.h>
|
||||
|
||||
#include "customMapsAndEnum.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class DebugMessages;
|
||||
}
|
||||
|
||||
class DebugMessages : public NGLDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DebugMessages(QWidget *parent = nullptr);
|
||||
~DebugMessages();
|
||||
|
||||
public slots:
|
||||
void onMessage(int port, const QString &msg, const MsgLvl &lvl);
|
||||
|
||||
private:
|
||||
Ui::DebugMessages *m_ui;
|
||||
};
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Display Panel Simulator main programm; collects commandline options
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
|
||||
#include <nglapplication/nglapplication.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <memory>
|
||||
|
||||
#include "displayPanelSimulatorWidget.h"
|
||||
#include "nglsettings.h"
|
||||
#include "cmdlineparser.h"
|
||||
|
||||
/**
|
||||
* Main entry point for program.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NGLApplication application(argc, argv);
|
||||
|
||||
application.setOrganizationName(QStringLiteral("RME"));
|
||||
application.setApplicationName(QStringLiteral("Dot Matrix Display Simulator"));
|
||||
application.createLogger("DispSim", "log4cxx_displayPanelSimulator.props");
|
||||
|
||||
int ret = -1;
|
||||
|
||||
{
|
||||
std::unique_ptr<CmdLineParser> parser(new CmdLineParser);
|
||||
if (!parser->init())
|
||||
return ret;
|
||||
|
||||
QCommandLineOption modeOption({ QLatin1String("m"), QLatin1String("mode")}, QLatin1String("mode (not valid for use with -c)"), QLatin1String("?"));
|
||||
QCommandLineOption portOption({ QLatin1String("p"), QLatin1String("port")}, QLatin1String("Port(s), comma separated; better be over 9000"), QLatin1String("9000"));
|
||||
QCommandLineOption showPortOption({ QLatin1String("s"), QLatin1String("showport")}, QLatin1String("Set, for showing the portnumbers"));
|
||||
QCommandLineOption countOption({ QLatin1String("c"), QLatin1String("count")}, QLatin1String("Ports added on startport; ignored, when port has multiple"), QLatin1String("-1"));
|
||||
QCommandLineOption windowOption({ QLatin1String("w"), QLatin1String("window")}, QLatin1String("Starts application in window mode (overrides ini)"));
|
||||
QCommandLineOption inifileOption({ QLatin1String("i"), QLatin1String("inifile")}, QLatin1String("Path/Name for saving and loading settings to an .ini File"), QLatin1String("my.ini"));
|
||||
QCommandLineOption graphicOption({ QLatin1String("g"), QLatin1String("graphic")}, QLatin1String("Path/Name for loading a graphic from a .png File"), QLatin1String("rde.ico"));
|
||||
|
||||
parser->addOption(modeOption);
|
||||
parser->addOption(portOption);
|
||||
parser->addOption(showPortOption);
|
||||
parser->addOption(countOption);
|
||||
parser->addOption(windowOption);
|
||||
parser->addOption(inifileOption);
|
||||
parser->addOption(graphicOption);
|
||||
|
||||
parser->addHelpOption();
|
||||
parser->process(application);
|
||||
|
||||
|
||||
// ---------- Getting mode ----------
|
||||
if (parser->isSet(modeOption))
|
||||
parser->setMode(parser->value(modeOption));
|
||||
QString mode = parser->mode();
|
||||
|
||||
|
||||
// ---------- Getting ports ----------
|
||||
QStringList portList = parser->value(portOption).split(QLatin1Char(','));
|
||||
// QStringList portList = parser->port().split(QLatin1Char(','));
|
||||
portList.removeAll(QStringLiteral("0"));
|
||||
QVector<int> portNumbers;
|
||||
|
||||
// ---------- Count ports ----------
|
||||
if (parser->isSet(countOption))
|
||||
{
|
||||
int count = parser->value(countOption).toInt();
|
||||
parser->setPortCount(count);
|
||||
}
|
||||
|
||||
if (portList.count() > 1)
|
||||
{
|
||||
portNumbers.reserve(portList.size());
|
||||
for (const QString &s : qAsConst(portList))
|
||||
portNumbers << s.toInt();
|
||||
}
|
||||
else if (portList.count() == 1 && !portList.first().isEmpty())
|
||||
{
|
||||
portNumbers.reserve(parser->portCount());
|
||||
for (int i = 0; i < parser->portCount(); ++i)
|
||||
portNumbers << (portList[0].toInt() + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
// no port given -> use default
|
||||
}
|
||||
|
||||
// ---------- Getting showPort option ----------
|
||||
if (parser->isSet(showPortOption))
|
||||
parser->setShowPort(true);
|
||||
|
||||
// ---------- Getting window option ----------
|
||||
if (parser->isSet(windowOption))
|
||||
parser->setWindow(true);
|
||||
|
||||
|
||||
// ---------- Getting inifile option ----------
|
||||
if (parser->isSet(inifileOption))
|
||||
parser->setIni(parser->value(inifileOption));
|
||||
NGLSettings::instance(parser->ini());
|
||||
|
||||
|
||||
// ---------- Gettings Image Path/Name ----------
|
||||
if (parser->isSet(graphicOption))
|
||||
parser->setImagePath(parser->value(graphicOption));
|
||||
|
||||
NGL::INGLLogger &logger = application.baseLogger();
|
||||
|
||||
STARTUP_LOG(logger);
|
||||
|
||||
std::unique_ptr<DisplayPanelSimulatorWidget> displayPanelWidget(new DisplayPanelSimulatorWidget);
|
||||
|
||||
if (displayPanelWidget->initialize(mode, portNumbers, !parser->windowMode(), parser->showPort(), parser->imagePath()) != 0)
|
||||
exit(-1);
|
||||
|
||||
ret = application.exec();
|
||||
SHUTDOWN_LOG(logger);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Display Panel Simulator TCP Server; observes the given port and emits the incoming messages
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
//===Include specifications==================================================
|
||||
#include "displayPanelSimulatorTcpServer.h"
|
||||
#include <QtNetwork/QTcpServer>
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
//===DisplayPanelSimulatorTcpServer==========================================
|
||||
|
||||
//---Constructors/Destructors------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
DisplayPanelSimulatorTcpServer::DisplayPanelSimulatorTcpServer(QObject *parent)
|
||||
: QObject(parent)
|
||||
, mp_server(new QTcpServer(this))
|
||||
, mp_socket(nullptr)
|
||||
, m_port(0)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("DispSim.DisplayPanelSimulatorWidget"))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
DisplayPanelSimulatorTcpServer::~DisplayPanelSimulatorTcpServer()
|
||||
{
|
||||
delete mp_server;
|
||||
}
|
||||
|
||||
//---Private slots-----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Handles the 'newConnection' signal of the TCP server.
|
||||
*/
|
||||
void DisplayPanelSimulatorTcpServer::handleServerNewConnection()
|
||||
{
|
||||
mp_socket = mp_server->nextPendingConnection();
|
||||
connect(mp_socket, &QTcpSocket::readyRead,
|
||||
this, &DisplayPanelSimulatorTcpServer::handleSocketReadyRead);
|
||||
emit debugMessage(m_port, QStringLiteral("Socket connected!"), MSGLVL_DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'readyRead' signal of the TCP socket.
|
||||
*/
|
||||
void DisplayPanelSimulatorTcpServer::handleSocketReadyRead()
|
||||
{
|
||||
evaluateData(mp_socket->readAll());
|
||||
}
|
||||
|
||||
//---Private methods---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Evaluates the received data from the TCP socket.
|
||||
*/
|
||||
void DisplayPanelSimulatorTcpServer::evaluateData(const QByteArray &data)
|
||||
{
|
||||
QByteArray page;
|
||||
QString message;
|
||||
bool ackRequested = false;
|
||||
bool dataOk = false;
|
||||
|
||||
if (data.isEmpty())
|
||||
return;
|
||||
|
||||
char cs = data.at(data.size() - 1);
|
||||
char csCalc = calculateChecksum(data);
|
||||
if (data.size() >= 5)
|
||||
ackRequested = data[4] & 0x08;
|
||||
if (data.size() < 10)
|
||||
{
|
||||
message = tr("Message to small!");
|
||||
|
||||
ERROR_LOG(m_logger) << "Error in message data evaluation";
|
||||
}
|
||||
else if (data[0] != 0)
|
||||
{
|
||||
message = tr("No SYNC in Message!");
|
||||
|
||||
ERROR_LOG(m_logger) << "Error in message data evaluation";
|
||||
}
|
||||
else if (cs != csCalc)
|
||||
{
|
||||
const QByteArray ba = "Wrong Checksum: 0x" + QByteArray::number(cs, 16) + " <-> 0x" + QByteArray::number(csCalc, 16);
|
||||
qDebug() << ba.data();
|
||||
message = QString::fromLatin1(ba);
|
||||
|
||||
ERROR_LOG(m_logger) << "Error in message data evaluation";
|
||||
}
|
||||
else
|
||||
{
|
||||
page = data.mid(5, 3);
|
||||
const QByteArray ba = data.mid(11, (data.size() - 13));
|
||||
message = QString::fromUtf8(ba.data(), ba.size());
|
||||
emit plainMessage(message);
|
||||
emit debugMessage(m_port, tr("New message received: %1").arg(message), MSGLVL_INFO);
|
||||
|
||||
INFO_LOG(m_logger) << "New message received";
|
||||
|
||||
dataOk = true;
|
||||
}
|
||||
if (!dataOk/* || page == "001"*/)
|
||||
{
|
||||
emit debugMessage(m_port, message, MSGLVL_ERROR);
|
||||
|
||||
ERROR_LOG(m_logger) << "Error in message data evaluation";
|
||||
|
||||
}
|
||||
if (ackRequested)
|
||||
{
|
||||
if (dataOk)
|
||||
{
|
||||
mp_socket->write("\x06"); // ACK
|
||||
}
|
||||
else
|
||||
{
|
||||
mp_socket->write("\x15"); // NAK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the checksum of the received data from the TCP socket.
|
||||
*/
|
||||
char DisplayPanelSimulatorTcpServer::calculateChecksum(const QByteArray &data)
|
||||
{
|
||||
char checksum = 0;
|
||||
for (const auto c : data)
|
||||
checksum ^= c;
|
||||
|
||||
return checksum;
|
||||
}
|
||||
|
||||
//---Public methods----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Starts the TCP server.
|
||||
*/
|
||||
void DisplayPanelSimulatorTcpServer::start(int port)
|
||||
{
|
||||
m_port = port;
|
||||
connect(mp_server, &QTcpServer::newConnection,
|
||||
this, &DisplayPanelSimulatorTcpServer::handleServerNewConnection);
|
||||
emit debugMessage(m_port, tr("Waiting for connection"), MSGLVL_DEBUG);
|
||||
|
||||
if (!mp_server->listen(QHostAddress::Any, port))
|
||||
{
|
||||
emit debugMessage(m_port, tr("Opening socket failed! May be in use!"), MSGLVL_ERROR);
|
||||
|
||||
ERROR_LOG(m_logger) << "Opening socket failed; Port: " << port;
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Display Panel Simulator TCP Server; observes the given port and emits the incoming messages
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
//===Include specifications==================================================
|
||||
#include <QtCore/QObject>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
#include "customMapsAndEnum.h"
|
||||
|
||||
//===Forward declarations====================================================
|
||||
class QLabel;
|
||||
class QTcpServer;
|
||||
class QTcpSocket;
|
||||
class QLedLine;
|
||||
|
||||
//===Class specifications====================================================
|
||||
/**
|
||||
* Display panel simulator TCP server.
|
||||
*/
|
||||
class DisplayPanelSimulatorTcpServer: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
// References -------------------------------------------------------------
|
||||
private:
|
||||
/**
|
||||
* Reference of the display panel simulator TCP server.
|
||||
*/
|
||||
QTcpServer *mp_server;
|
||||
|
||||
/**
|
||||
* Reference of the display panel simulator TCP socket.
|
||||
*/
|
||||
QTcpSocket *mp_socket;
|
||||
|
||||
int m_port;
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
// Slots ------------------------------------------------------------------
|
||||
private Q_SLOTS:
|
||||
void handleServerNewConnection();
|
||||
void handleSocketReadyRead();
|
||||
|
||||
// Signals ----------------------------------------------------------------
|
||||
Q_SIGNALS:
|
||||
void debugMessage(int port, const QString &message, MsgLvl lvl);
|
||||
void plainMessage(const QString &message);
|
||||
|
||||
// Methods ----------------------------------------------------------------
|
||||
private:
|
||||
void evaluateData(const QByteArray &data);
|
||||
static char calculateChecksum(const QByteArray &data);
|
||||
|
||||
public:
|
||||
explicit DisplayPanelSimulatorTcpServer(QObject *parent = nullptr);
|
||||
virtual ~DisplayPanelSimulatorTcpServer();
|
||||
void start(int port);
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Display Panel Simulator widget; manages the LED-lines and servers
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
//===Include specifications==================================================
|
||||
#include "displayPanelSimulatorWidget.h"
|
||||
#include "ui_displayPanelSimulatorWidget.h"
|
||||
#include "displayPanelSimulatorTcpServer.h"
|
||||
#include "nglsettings.h"
|
||||
#include "debugmessages.h"
|
||||
#include "ui_debugmessages.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QLabel>
|
||||
#include <QStatusBar>
|
||||
#include <QSettings>
|
||||
#include <QBoxLayout>
|
||||
#include <QImage>
|
||||
#include <QLedLine/qledline.h>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
|
||||
DisplayPanelSimulatorWidget::DisplayPanelSimulatorWidget()
|
||||
: QMainWindow()
|
||||
, m_servers()
|
||||
, m_ui(new Ui::DisplayPanelSimulatorWidget)
|
||||
, m_ports()
|
||||
, m_ledLines()
|
||||
, m_mode()
|
||||
, m_message()
|
||||
, m_debugMessages(new DebugMessages(this))
|
||||
, m_statusLabel(new QLabel(this))
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("DispSim.DisplayPanelSimulatorWidget"))
|
||||
, m_charSize()
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
restoreGeometry(NGLSettings::instance()->windowGeometry());
|
||||
restoreState(NGLSettings::instance()->windowState());
|
||||
|
||||
m_statusLabel->setStyleSheet(QStringLiteral("QLabel {color: red;}"));
|
||||
m_statusLabel->setContentsMargins(0, 0, 0, 1);
|
||||
m_ui->statusBar->addPermanentWidget(m_statusLabel);
|
||||
|
||||
connect(m_ui->fullscreenAction, &QAction::toggled,
|
||||
this, &DisplayPanelSimulatorWidget::onFullscreenAction);
|
||||
connect(m_ui->debugInfosAction, &QAction::triggered,
|
||||
this, &DisplayPanelSimulatorWidget::onDebugInfosAction);
|
||||
connect(m_ui->exitAction, &QAction::triggered,
|
||||
this, &DisplayPanelSimulatorWidget::onExitAction);
|
||||
connect(m_ui->saveSettingsAction, &QAction::triggered,
|
||||
this, &DisplayPanelSimulatorWidget::onSaveSettingsAction);
|
||||
DEBUG_LOG(m_logger) << "DisplayPanelSimulatorWidget finished";
|
||||
}
|
||||
|
||||
DisplayPanelSimulatorWidget::~DisplayPanelSimulatorWidget()
|
||||
{
|
||||
qDeleteAll(m_servers);
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
//---Private slots-----------------------------------------------------------
|
||||
|
||||
void DisplayPanelSimulatorWidget::onExitAction()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void DisplayPanelSimulatorWidget::onSaveSettingsAction()
|
||||
{
|
||||
NGLSettings::instance()->setPorts(m_ports);
|
||||
NGLSettings::instance()->setLastMode(m_mode.name);
|
||||
|
||||
INFO_LOG(m_logger) << "Save settings action triggered";
|
||||
}
|
||||
|
||||
void DisplayPanelSimulatorWidget::onDebugInfosAction()
|
||||
{
|
||||
m_debugMessages->show();
|
||||
m_debugMessages->raise();
|
||||
m_debugMessages->activateWindow();
|
||||
|
||||
INFO_LOG(m_logger) << "Debug console triggered";
|
||||
}
|
||||
|
||||
void DisplayPanelSimulatorWidget::writeMultiLiners(const QString &string)
|
||||
{
|
||||
QString fullString = string.leftJustified((m_mode.letters * m_mode.lines), QLatin1Char(' '), true);
|
||||
for (int i = 0; i < fullString.size(); i += m_mode.letters)
|
||||
m_ledLines[i / m_mode.letters]->setText(fullString.mid(i, m_mode.letters));
|
||||
}
|
||||
|
||||
void DisplayPanelSimulatorWidget::onErrorMsg(int port, const QString &string, MsgLvl lvl)
|
||||
{
|
||||
if (lvl < MSGLVL_ERROR)
|
||||
return;
|
||||
|
||||
m_statusLabel->setText(tr("%1: %2 %3 <|> %4").arg(levelName(lvl), tr("Port")).arg(port).arg(string));
|
||||
}
|
||||
|
||||
void DisplayPanelSimulatorWidget::onFullscreenAction(bool fullscreen)
|
||||
{
|
||||
if (fullscreen)
|
||||
{
|
||||
NGLSettings::instance()->setPreFullscreenWindowState(saveState());
|
||||
NGLSettings::instance()->setPreFullscreenWindowGeometry(saveGeometry());
|
||||
this->setWindowState(Qt::WindowFullScreen);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setWindowState(Qt::WindowNoState);
|
||||
restoreState(NGLSettings::instance()->preFullscreenwindowState());
|
||||
restoreGeometry(NGLSettings::instance()->preFullscreenwindowGeometry());
|
||||
}
|
||||
}
|
||||
|
||||
//---Protected methods-------------------------------------------------------
|
||||
|
||||
void DisplayPanelSimulatorWidget::changeEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
m_ui->retranslateUi(this);
|
||||
QMainWindow::changeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void DisplayPanelSimulatorWidget::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
hide();
|
||||
NGLSettings::instance()->setFullscreen(m_ui->fullscreenAction->isChecked());
|
||||
m_ui->fullscreenAction->setChecked(false);
|
||||
NGLSettings::instance()->setWindowGeometry(saveGeometry());
|
||||
NGLSettings::instance()->setWindowState(saveState());
|
||||
|
||||
event->accept();
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void DisplayPanelSimulatorWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape)
|
||||
m_ui->fullscreenAction->setChecked(false);
|
||||
|
||||
QMainWindow::keyPressEvent(event);
|
||||
}
|
||||
|
||||
//---Private Methods----------------------------------------------------------
|
||||
|
||||
// Note: Can return comma separated list which is special case.
|
||||
QString DisplayPanelSimulatorWidget::findFullMode(const QString &stubMode, const ModeMap &map)
|
||||
{
|
||||
QStringList retVal;
|
||||
for (auto it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
if (it.key().startsWith(stubMode, Qt::CaseInsensitive))
|
||||
retVal << it.key();
|
||||
}
|
||||
return retVal.join(QStringLiteral(", "));
|
||||
}
|
||||
|
||||
//---Public methods----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initializes the widget itself.
|
||||
*
|
||||
* @return Result code:
|
||||
* 0 = Initialize ok.
|
||||
* 1 = Member initialisation failed.
|
||||
* 2 = Signal/slot initialisation failed.
|
||||
* 3 = Mode is ambigious.
|
||||
* 4 = Mode not found.
|
||||
*/
|
||||
int DisplayPanelSimulatorWidget::initialize(const QString &mode_, const QVector<int> &ports, bool fullscreen, bool showPort, const QString &imagePath)
|
||||
{
|
||||
if (!ports.isEmpty())
|
||||
{
|
||||
Port p;
|
||||
for (int i = 0; i < ports.size(); ++i)
|
||||
{
|
||||
p.name = tr("Port: %1").arg(ports[i]);
|
||||
p.port = ports[i];
|
||||
m_ports.insert(i, p);
|
||||
}
|
||||
}
|
||||
else
|
||||
m_ports = NGLSettings::instance()->ports();
|
||||
|
||||
const QString mode = (mode_.isEmpty() ? NGLSettings::instance()->lastMode() : mode_);
|
||||
|
||||
m_debugMessages->onMessage(m_ports[0].port, tr("Mode: %1").arg(mode), MSGLVL_DEBUG);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Mode: " << mode;
|
||||
|
||||
const ModeMap modeMap = NGLSettings::instance()->modes();
|
||||
|
||||
QString fullmode = findFullMode(mode, modeMap);
|
||||
if (fullmode.contains(QLatin1Char(',')))
|
||||
{
|
||||
m_debugMessages->onMessage(m_ports[0].port, tr("Mode '%1' is ambigious: %2.").arg(mode, fullmode), MSGLVL_FATAL);
|
||||
ERROR_LOG(m_logger) << "Mode '" << mode << "' is ambigious: " << fullmode << ".";
|
||||
return 3;
|
||||
}
|
||||
if (fullmode.isEmpty())
|
||||
{
|
||||
m_debugMessages->onMessage(m_ports[0].port, tr("Mode '%1' not found.").arg(mode), MSGLVL_FATAL);
|
||||
ERROR_LOG(m_logger) << "Mode '" << mode << "' not found.";
|
||||
return 4;
|
||||
}
|
||||
|
||||
m_mode = modeMap[fullmode];
|
||||
|
||||
QHBoxLayout *centralLayout = static_cast<QHBoxLayout *>(this->centralWidget()->layout());
|
||||
QVBoxLayout *vLayout = new QVBoxLayout();
|
||||
QLabel *label = nullptr;
|
||||
|
||||
// Member initialisation
|
||||
if (m_mode.lines == 1)
|
||||
{
|
||||
// Single line modes ----------------------------------------------
|
||||
for (int i = 0; i < m_ports.size(); ++i)
|
||||
{
|
||||
m_debugMessages->onMessage(m_ports[0].port, tr("Opening port %1 with mode %2").arg(m_ports[0].port).arg(m_mode.name), MSGLVL_DEBUG);
|
||||
DEBUG_LOG(m_logger) << "Opening port " << m_ports[0].port << " with mode " << m_mode.name;
|
||||
|
||||
if (showPort)
|
||||
{
|
||||
// Heading
|
||||
label = new QLabel(this);
|
||||
label->setText(m_ports[i].name);
|
||||
label->setAlignment(Qt::AlignHCenter);
|
||||
vLayout->addWidget(label);
|
||||
}
|
||||
|
||||
// LedLine
|
||||
QLedLine *ledLine = new QLedLine(this);
|
||||
ledLine->setCharCountAndHeight(m_mode.letters, m_mode.height);
|
||||
m_ledLines.append(ledLine);
|
||||
vLayout->addWidget(ledLine);
|
||||
|
||||
// Server connection
|
||||
DisplayPanelSimulatorTcpServer *server = new DisplayPanelSimulatorTcpServer(this);
|
||||
m_servers.append(server);
|
||||
connect(server, &DisplayPanelSimulatorTcpServer::plainMessage, ledLine, &QLedLine::setText); // Text to LedLine
|
||||
connect(server, &DisplayPanelSimulatorTcpServer::debugMessage, m_debugMessages, &DebugMessages::onMessage); // Debug-stuff to debug window
|
||||
connect(server, &DisplayPanelSimulatorTcpServer::debugMessage, this, &DisplayPanelSimulatorWidget::onErrorMsg); // Debug to status bar
|
||||
server->start(m_ports[i].port);
|
||||
}
|
||||
// \Single line modes ----------------------------------------------
|
||||
}
|
||||
else
|
||||
{
|
||||
// Multi line modes ----------------------------------------------
|
||||
m_debugMessages->onMessage(m_ports[0].port, tr("Opening port %1 with mode %2").arg(m_ports[0].port).arg(m_mode.name), MSGLVL_DEBUG);
|
||||
DEBUG_LOG(m_logger) << "Opening port " << m_ports[0].port << " with mode " << m_mode.name;
|
||||
|
||||
int linesNeeded = m_mode.lines;
|
||||
|
||||
if (showPort)
|
||||
{
|
||||
//Heading
|
||||
label = new QLabel(this);
|
||||
label->setText(m_ports[0].name);
|
||||
label->setAlignment(Qt::AlignHCenter);
|
||||
vLayout->addWidget(label);
|
||||
}
|
||||
|
||||
// Server connection
|
||||
DisplayPanelSimulatorTcpServer *server = new DisplayPanelSimulatorTcpServer(this);
|
||||
m_servers.append(server);
|
||||
connect(server, &DisplayPanelSimulatorTcpServer::plainMessage, this, &DisplayPanelSimulatorWidget::writeMultiLiners); // Text to LedLine
|
||||
connect(server, &DisplayPanelSimulatorTcpServer::debugMessage, m_debugMessages, &DebugMessages::onMessage); // Debug-stuff to debug window
|
||||
connect(server, &DisplayPanelSimulatorTcpServer::debugMessage, this, &DisplayPanelSimulatorWidget::onErrorMsg); // Debug to status bar
|
||||
server->start(m_ports[0].port);
|
||||
|
||||
for (int i = 0; i < linesNeeded; ++i)
|
||||
{
|
||||
// LedLine
|
||||
QLedLine *ledLine = new QLedLine(this);
|
||||
ledLine->setCharCountAndHeight(m_mode.letters, m_mode.height);
|
||||
m_ledLines.append(ledLine);
|
||||
vLayout->addWidget(ledLine);
|
||||
}
|
||||
// \Multi line modes ----------------------------------------------
|
||||
}
|
||||
|
||||
// Graphic show -------------------------------------------
|
||||
// Todo: Zentriert? Nein, gibt keine Flag, evtl. extra Image erstellen und prependen etc.
|
||||
|
||||
QImage image(imagePath.isEmpty() ? QStringLiteral("./rheinmetall.jpg") : imagePath);
|
||||
if (!image.isNull())
|
||||
{
|
||||
scaleImage(image);
|
||||
for (int i = 0; i < m_ledLines.size(); ++i)
|
||||
{
|
||||
const QImage lineImage = image.copy(0, (m_charSize.height() * i), image.width(), m_charSize.height());
|
||||
m_ledLines[i]->setImage(lineImage);
|
||||
}
|
||||
}
|
||||
// \Graphic show -------------------------------------------
|
||||
|
||||
vLayout->setContentsMargins(0, 0, 0, 0);
|
||||
vLayout->setSpacing(0);
|
||||
|
||||
centralLayout->addLayout(vLayout);
|
||||
centralLayout->addSpacerItem(new QSpacerItem(0, 0,
|
||||
QSizePolicy::Minimum,
|
||||
QSizePolicy::Expanding));
|
||||
|
||||
INFO_LOG(m_logger) << "All LedLines initialised";
|
||||
|
||||
fullscreen |= NGLSettings::instance()->fullscreen();
|
||||
m_ui->fullscreenAction->setChecked(fullscreen);
|
||||
show();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DisplayPanelSimulatorWidget::scaleImage(QImage &image)
|
||||
{
|
||||
m_charSize = m_ledLines[0]->charSize();
|
||||
|
||||
// Width per QLedChar times QLedChars per QLedLine; and Height per QLedChar times QLedLines needed
|
||||
QSize maxPxSize((m_charSize.width() * m_mode.letters), (m_charSize.height() * (m_mode.lines == 1 ? m_ports.size() : m_mode.lines)));
|
||||
|
||||
image = image.scaled(maxPxSize, Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Display Panel Simulator widget; manages the LED-lines and servers
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
//===Include specifications==================================================
|
||||
#include "customMapsAndEnum.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QVector>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class DisplayPanelSimulatorWidget;
|
||||
}
|
||||
|
||||
class DisplayPanelSimulatorTcpServer;
|
||||
class QLedLine;
|
||||
class DebugMessages;
|
||||
class QLabel;
|
||||
class QImage;
|
||||
class QSize;
|
||||
|
||||
|
||||
class DisplayPanelSimulatorWidget : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DisplayPanelSimulatorWidget(/*QWidget *parent = nullptr*/);
|
||||
~DisplayPanelSimulatorWidget();
|
||||
static DisplayPanelSimulatorWidget *self();
|
||||
int initialize(const QString &mode_, const QVector<int> &ports, bool fullscreen, bool showPort, const QString &imagePath);
|
||||
|
||||
|
||||
protected:
|
||||
virtual void changeEvent(QEvent *event);
|
||||
virtual void closeEvent(QCloseEvent *event);
|
||||
virtual void keyPressEvent(QKeyEvent *e);
|
||||
|
||||
|
||||
public slots:
|
||||
void onDebugInfosAction();
|
||||
void onFullscreenAction(bool fullscreen);
|
||||
|
||||
private Q_SLOTS:
|
||||
void writeMultiLiners(const QString &string);
|
||||
void onErrorMsg(int port, const QString &string, MsgLvl lvl);
|
||||
void onExitAction();
|
||||
void onSaveSettingsAction();
|
||||
|
||||
|
||||
private:
|
||||
static QString findFullMode(const QString &stubMode, const ModeMap &map);
|
||||
void scaleImage(QImage &image);
|
||||
|
||||
|
||||
QVector<DisplayPanelSimulatorTcpServer *> m_servers;
|
||||
Ui::DisplayPanelSimulatorWidget *m_ui;
|
||||
PortMap m_ports;
|
||||
QVector<QLedLine *> m_ledLines;
|
||||
Mode m_mode;
|
||||
QString m_message;
|
||||
DebugMessages *m_debugMessages;
|
||||
QLabel *m_statusLabel;
|
||||
NGL::INGLLogger &m_logger;
|
||||
QSize m_charSize;
|
||||
};
|
||||
|
||||
Executable
+186
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Settings for Display Panel Simulator
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
#include "nglsettings.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
static NGLSettings *s_instance = nullptr;
|
||||
|
||||
static void cleanupSettings()
|
||||
{
|
||||
delete s_instance;
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
NGLSettings::NGLSettings(const QString &iniFileName)
|
||||
: NGL::Settings(iniFileName)
|
||||
{
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
NGLSettings::~NGLSettings()
|
||||
{
|
||||
}
|
||||
|
||||
PortMap NGLSettings::ports()
|
||||
{
|
||||
PortMap portMap;
|
||||
settings()->beginGroup(QStringLiteral("Ports"));
|
||||
{
|
||||
int size = settings()->beginReadArray(QStringLiteral("Port"));
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
Port p;
|
||||
settings()->setArrayIndex(i);
|
||||
p.port = settings()->value(QStringLiteral("PortNumber")).toInt();
|
||||
p.name = settings()->value(QStringLiteral("Title")).toString();
|
||||
portMap.insert(i, p);
|
||||
}
|
||||
}
|
||||
settings()->endArray();
|
||||
}
|
||||
settings()->endGroup();
|
||||
return portMap;
|
||||
}
|
||||
|
||||
void NGLSettings::setPorts(const PortMap &portMap)
|
||||
{
|
||||
settings()->beginGroup(QStringLiteral("Ports"));
|
||||
{
|
||||
settings()->remove(QString());
|
||||
settings()->beginWriteArray(QStringLiteral("Port"));
|
||||
{
|
||||
int i = 0;
|
||||
for (const Port &port : portMap)
|
||||
{
|
||||
settings()->setArrayIndex(i++);
|
||||
settings()->setValue(QStringLiteral("PortNumber"), port.port);
|
||||
settings()->setValue(QStringLiteral("Title"), port.name.isEmpty() ? QObject::tr("Port: %1").arg(port.port, 5) : port.name);
|
||||
}
|
||||
}
|
||||
settings()->endArray();
|
||||
}
|
||||
settings()->endGroup();
|
||||
}
|
||||
|
||||
QString NGLSettings::lastMode()
|
||||
{
|
||||
return settings()->value(QStringLiteral("lastMode")).toString();
|
||||
}
|
||||
|
||||
void NGLSettings::setLastMode(const QString &modeName)
|
||||
{
|
||||
settings()->setValue(QStringLiteral("lastMode"), modeName);
|
||||
}
|
||||
|
||||
QByteArray NGLSettings::windowGeometry()
|
||||
{
|
||||
return settings()->value(QStringLiteral("Window/Geometry")).toByteArray();
|
||||
}
|
||||
|
||||
void NGLSettings::setWindowGeometry(const QByteArray &ba)
|
||||
{
|
||||
settings()->setValue(QStringLiteral("Window/Geometry"), ba);
|
||||
}
|
||||
|
||||
QByteArray NGLSettings::windowState()
|
||||
{
|
||||
return settings()->value(QStringLiteral("Window/WindowState")).toByteArray();
|
||||
}
|
||||
|
||||
void NGLSettings::setWindowState(const QByteArray &ba)
|
||||
{
|
||||
settings()->setValue(QStringLiteral("Window/WindowState"), ba);
|
||||
}
|
||||
|
||||
QByteArray NGLSettings::preFullscreenwindowState()
|
||||
{
|
||||
return settings()->value(QStringLiteral("Window/PreFullscreenState")).toByteArray();
|
||||
}
|
||||
|
||||
void NGLSettings::setPreFullscreenWindowState(const QByteArray &ba)
|
||||
{
|
||||
settings()->setValue(QStringLiteral("Window/PreFullscreenState"), ba);
|
||||
}
|
||||
|
||||
QByteArray NGLSettings::preFullscreenwindowGeometry()
|
||||
{
|
||||
return settings()->value(QStringLiteral("Window/PreFullscreenGeometry")).toByteArray();
|
||||
}
|
||||
|
||||
void NGLSettings::setPreFullscreenWindowGeometry(const QByteArray &ba)
|
||||
{
|
||||
settings()->setValue(QStringLiteral("Window/PreFullscreenGeometry"), ba);
|
||||
}
|
||||
|
||||
ModeMap NGLSettings::modes()
|
||||
{
|
||||
ModeMap modemap;
|
||||
settings()->beginGroup(QStringLiteral("Modes"));
|
||||
{
|
||||
int size = settings()->beginReadArray(QStringLiteral("Mode"));
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
settings()->setArrayIndex(i);
|
||||
Mode m;
|
||||
m.name = settings()->value(QStringLiteral("name")).toString();
|
||||
m.lines = settings()->value(QStringLiteral("lines")).toInt();
|
||||
m.letters = settings()->value(QStringLiteral("letters")).toInt();
|
||||
m.height = settings()->value(QStringLiteral("height")).toInt();
|
||||
modemap.insert(m.name, m);
|
||||
}
|
||||
}
|
||||
settings()->endArray();
|
||||
}
|
||||
settings()->endGroup();
|
||||
|
||||
return modemap;
|
||||
}
|
||||
|
||||
void NGLSettings::addMode(const Mode &mode)
|
||||
{
|
||||
settings()->beginGroup(QStringLiteral("Modes"));
|
||||
{
|
||||
settings()->beginWriteArray(QStringLiteral("Mode"));
|
||||
{
|
||||
settings()->setValue(QStringLiteral("name"), mode.name);
|
||||
settings()->setValue(QStringLiteral("lines"), mode.lines);
|
||||
settings()->setValue(QStringLiteral("letters"), mode.letters);
|
||||
settings()->setValue(QStringLiteral("height"), mode.height);
|
||||
}
|
||||
settings()->endArray();
|
||||
}
|
||||
settings()->endGroup();
|
||||
}
|
||||
|
||||
bool NGLSettings::fullscreen()
|
||||
{
|
||||
return settings()->value(QStringLiteral("lastFullscreen")).toBool();
|
||||
}
|
||||
|
||||
void NGLSettings::setFullscreen(bool fullscreen)
|
||||
{
|
||||
settings()->setValue(QStringLiteral("lastFullscreen"), fullscreen);
|
||||
}
|
||||
|
||||
NGLSettings *NGLSettings::instance(const QString &iniFileName)
|
||||
{
|
||||
if (!s_instance)
|
||||
qAddPostRoutine(cleanupSettings);
|
||||
|
||||
delete s_instance;
|
||||
s_instance = new NGLSettings((!s_instance && iniFileName.isEmpty()) ? QStringLiteral("DotMatrixDisplay.ini") : iniFileName);
|
||||
|
||||
return s_instance;
|
||||
}
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Settings for Display Panel Simulator
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Florian Schult, SLSE, 2016-03-18
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "customMapsAndEnum.h"
|
||||
|
||||
#include <nglsettings/nglsettings_settings.h>
|
||||
#include <QMap>
|
||||
|
||||
class NGLSettings : public NGL::Settings
|
||||
{
|
||||
explicit NGLSettings(const QString &iniFileName = QString());
|
||||
|
||||
public:
|
||||
virtual ~NGLSettings();
|
||||
|
||||
PortMap ports();
|
||||
void setPorts(const PortMap &portMap);
|
||||
|
||||
QString lastMode();
|
||||
void setLastMode(const QString &modeName);
|
||||
|
||||
QByteArray windowGeometry();
|
||||
void setWindowGeometry(const QByteArray &ba);
|
||||
|
||||
QByteArray windowState();
|
||||
void setWindowState(const QByteArray &ba);
|
||||
|
||||
QByteArray preFullscreenwindowState();
|
||||
void setPreFullscreenWindowState(const QByteArray &ba);
|
||||
|
||||
QByteArray preFullscreenwindowGeometry();
|
||||
void setPreFullscreenWindowGeometry(const QByteArray &ba);
|
||||
|
||||
bool fullscreen();
|
||||
void setFullscreen(bool fullscreen);
|
||||
|
||||
ModeMap modes();
|
||||
|
||||
void addMode(const Mode &mode);
|
||||
|
||||
static NGLSettings *instance(const QString &iniFileName = QString());
|
||||
|
||||
private:
|
||||
QString m_ini;
|
||||
};
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 7.4 KiB |
+39
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DebugMessages</class>
|
||||
<widget class="QDialog" name="DebugMessages">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>636</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Debug Messages</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextBrowser" name="tbMain"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="NGLDialogButtonBox" name="nglDialogButtonBox">
|
||||
<property name="standardButtons">
|
||||
<set>NGLStandardButton::Close|NGLStandardButton::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>NGLDialogButtonBox</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>nglwidgets/ngldialogbuttonbox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DisplayPanelSimulatorWidget</class>
|
||||
<widget class="QMainWindow" name="DisplayPanelSimulatorWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>489</width>
|
||||
<height>307</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string comment="Window title">Display panel simulator</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>489</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuDesktop">
|
||||
<property name="title">
|
||||
<string comment="'Desktop' menu title">&Desktop</string>
|
||||
</property>
|
||||
<addaction name="saveSettingsAction"/>
|
||||
<addaction name="debugInfosAction"/>
|
||||
<addaction name="fullscreenAction"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="exitAction"/>
|
||||
</widget>
|
||||
<addaction name="menuDesktop"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="exitAction">
|
||||
<property name="text">
|
||||
<string comment="'Exit' action text">&Exit</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string comment="Exit action statusTip">The application will be closed.</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="saveSettingsAction">
|
||||
<property name="text">
|
||||
<string>&Save Settings</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Saves the latest settings.</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="debugInfosAction">
|
||||
<property name="text">
|
||||
<string>&Debug Infos</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Opens the debug console.</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+D</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="fullscreenAction">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Fullscreen</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Toggles the windows Size.</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+F</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in new issue
Block a user