1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-26 17:55:12 +03:00

[Simulator] LCD screenshot file name now includes radio type; Remove unnecessary class dependence in SimulatedUIWidget initializer; Show exit status debug; Cosmetics.

This commit is contained in:
Max Paperno 2017-02-07 12:08:47 -05:00
parent 62bcfb52c0
commit c4acbf6054
9 changed files with 81 additions and 67 deletions

View file

@ -24,10 +24,10 @@
#include "radiouiaction.h"
#include "simulatorinterface.h"
SimulatedUIWidget::SimulatedUIWidget(SimulatorInterface * simulator, SimulatorDialog * simuDialog, QWidget * parent) :
SimulatedUIWidget::SimulatedUIWidget(SimulatorInterface * simulator, QWidget * parent) :
QWidget(parent),
m_simulator(simulator),
m_simuDialog(simuDialog),
m_parent(parent),
m_lcd(NULL),
m_scrollUpAction(NULL),
m_scrollDnAction(NULL),
@ -63,12 +63,12 @@ RadioUiAction * SimulatedUIWidget::addRadioUiAction(RadioUiAction * act)
RadioUiAction * SimulatedUIWidget::addRadioUiAction(int index, int key, const QString & text, const QString & descript)
{
return addRadioUiAction(new RadioUiAction(index, key, m_simuDialog, text, descript));
return addRadioUiAction(new RadioUiAction(index, key, m_parent, text, descript));
}
RadioUiAction * SimulatedUIWidget::addRadioUiAction(int index, QList<int> keys, const QString & text, const QString & descript)
{
return addRadioUiAction(new RadioUiAction(index, keys, m_simuDialog, text, descript));
return addRadioUiAction(new RadioUiAction(index, keys, m_parent, text, descript));
}
QPolygon SimulatedUIWidget::polyArc(int ctrX, int ctrY, int radius, int startAngle, int endAngle, int step)
@ -116,18 +116,22 @@ void SimulatedUIWidget::updateUi()
void SimulatedUIWidget::captureScreenshot()
{
QString fileName = "";
QString fileName;
if (!g.snapToClpbrd()) {
QString path = g.snapshotDir();
if (path.isEmpty())
path = "./";
QDir dir(path);
if (!dir.exists() || !dir.isReadable()) {
// m_simulator->traceCallback("SIMULATOR ERROR - Cannot open screenshot folder, check your settings.\n");
// m_simulator->traceCallback("SIMULATOR ERROR - Cannot open screenshot folder, check your settings.\n");
qDebug() << "SIMULATOR ERROR - Cannot open screenshot folder, check your settings.";
return;
}
fileName += QString("%1/screenshot_%2.png").arg(dir.absolutePath(), QDateTime::currentDateTime().toString("yy-MM-dd_HH-mm-ss"));
QStringList fwid = getCurrentFirmware()->getId().split("-", QString::SkipEmptyParts);
QString flavor = fwid.at(qMin(1, fwid.size()));
QString fnpfx = tr("screenshot", "Simulator LCD screenshot file name prefix");
fileName = "%1/%2_%3_%4.png";
fileName = fileName.arg(dir.absolutePath(), fnpfx, flavor, QDateTime::currentDateTime().toString("yy-MM-dd_HH-mm-ss"));
}
m_lcd->makeScreenshot(fileName);
}

View file

@ -45,7 +45,7 @@ class SimulatedUIWidget : public QWidget
protected:
explicit SimulatedUIWidget(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
explicit SimulatedUIWidget(SimulatorInterface * simulator, QWidget * parent = NULL);
public:
@ -72,12 +72,13 @@ class SimulatedUIWidget : public QWidget
void mouseReleaseEvent(QMouseEvent *event);
protected:
void setLcd(LcdWidget * lcd);
void connectScrollActions();
virtual void setLightOn(bool enable) { }
SimulatorInterface * m_simulator;
SimulatorDialog * m_simuDialog;
QWidget * m_parent;
LcdWidget * m_lcd;
QVector<QColor> m_backlightColors;
QVector<keymapHelp_t> m_keymapHelp;
@ -92,6 +93,9 @@ class SimulatedUIWidget : public QWidget
int m_beepShow;
int m_beepVal;
signals:
void customStyleRequest(const QString & style);
};
@ -109,14 +113,12 @@ class SimulatedUIWidget9X: public SimulatedUIWidget
Q_OBJECT
public:
explicit SimulatedUIWidget9X(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
explicit SimulatedUIWidget9X(SimulatorInterface * simulator, QWidget * parent = NULL);
virtual ~SimulatedUIWidget9X();
protected:
void setLightOn(bool enable);
protected slots:
private:
Ui::SimulatedUIWidget9X * ui;
@ -127,11 +129,9 @@ class SimulatedUIWidgetX7: public SimulatedUIWidget
Q_OBJECT
public:
explicit SimulatedUIWidgetX7(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
explicit SimulatedUIWidgetX7(SimulatorInterface * simulator, QWidget * parent = NULL);
virtual ~SimulatedUIWidgetX7();
protected:
private:
Ui::SimulatedUIWidgetX7 * ui;
};
@ -141,11 +141,9 @@ class SimulatedUIWidgetX9: public SimulatedUIWidget
Q_OBJECT
public:
explicit SimulatedUIWidgetX9(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
explicit SimulatedUIWidgetX9(SimulatorInterface * simulator, QWidget * parent = NULL);
virtual ~SimulatedUIWidgetX9();
protected:
private:
Ui::SimulatedUIWidgetX9 * ui;
};
@ -155,11 +153,9 @@ class SimulatedUIWidgetX9E: public SimulatedUIWidget
Q_OBJECT
public:
explicit SimulatedUIWidgetX9E(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
explicit SimulatedUIWidgetX9E(SimulatorInterface * simulator, QWidget * parent = NULL);
virtual ~SimulatedUIWidgetX9E();
protected:
private:
Ui::SimulatedUIWidgetX9E * ui;
};
@ -169,11 +165,9 @@ class SimulatedUIWidgetX12: public SimulatedUIWidget
Q_OBJECT
public:
explicit SimulatedUIWidgetX12(SimulatorInterface * simulator, SimulatorDialog * simuDialog = NULL, QWidget * parent = NULL);
explicit SimulatedUIWidgetX12(SimulatorInterface * simulator, QWidget * parent = NULL);
virtual ~SimulatedUIWidgetX12();
protected:
private:
Ui::SimulatedUIWidgetX12 * ui;
};

View file

@ -21,8 +21,8 @@
#include "simulateduiwidget.h"
#include "ui_simulateduiwidget9X.h"
SimulatedUIWidget9X::SimulatedUIWidget9X(SimulatorInterface * simulator, SimulatorDialog * simuDialog, QWidget * parent):
SimulatedUIWidget(simulator, simuDialog, parent),
SimulatedUIWidget9X::SimulatedUIWidget9X(SimulatorInterface * simulator, QWidget * parent):
SimulatedUIWidget(simulator, parent),
ui(new Ui::SimulatedUIWidget9X)
{
RadioUiAction * act;

View file

@ -21,8 +21,8 @@
#include "simulateduiwidget.h"
#include "ui_simulateduiwidgetX12.h"
SimulatedUIWidgetX12::SimulatedUIWidgetX12(SimulatorInterface *simulator, SimulatorDialog * simuDialog, QWidget * parent):
SimulatedUIWidget(simulator, simuDialog, parent),
SimulatedUIWidgetX12::SimulatedUIWidgetX12(SimulatorInterface *simulator, QWidget * parent):
SimulatedUIWidget(simulator, parent),
ui(new Ui::SimulatedUIWidgetX12)
{
RadioUiAction * act;

View file

@ -1,8 +1,8 @@
#include "simulateduiwidget.h"
#include "ui_simulateduiwidgetX7.h"
SimulatedUIWidgetX7::SimulatedUIWidgetX7(SimulatorInterface *simulator, SimulatorDialog * simuDialog, QWidget * parent):
SimulatedUIWidget(simulator, simuDialog, parent),
SimulatedUIWidgetX7::SimulatedUIWidgetX7(SimulatorInterface *simulator, QWidget * parent):
SimulatedUIWidget(simulator, parent),
ui(new Ui::SimulatedUIWidgetX7)
{
RadioUiAction * act;
@ -43,11 +43,19 @@ SimulatedUIWidgetX7::SimulatedUIWidgetX7(SimulatorInterface *simulator, Simulato
setLcd(ui->lcd);
// try to match the gradient on the white radio images.
m_simuDialog->setUiAreaStyle("background-color: qlineargradient(spread:reflect, x1:0, y1:0, x2:0, y2:1, " \
"stop:0 rgba(255, 255, 255, 255), " \
"stop:0.757062 rgba(241, 238, 238, 255), " \
"stop:1 rgba(247, 245, 245, 255));");
QString css = "#radioUiWidget {"
"background-color: qlineargradient(spread:reflect, x1:0, y1:0, x2:0, y2:1,"
"stop:0 rgba(255, 255, 255, 255),"
"stop:0.757062 rgba(241, 238, 238, 255),"
"stop:1 rgba(247, 245, 245, 255));"
"}";
QTimer * tim = new QTimer(this);
tim->setSingleShot(true);
connect(tim, &QTimer::timeout, [this, css]() {
emit customStyleRequest(css);
});
tim->start(100);
}
SimulatedUIWidgetX7::~SimulatedUIWidgetX7()

View file

@ -21,8 +21,8 @@
#include "simulateduiwidget.h"
#include "ui_simulateduiwidgetX9.h"
SimulatedUIWidgetX9::SimulatedUIWidgetX9(SimulatorInterface *simulator, SimulatorDialog * simuDialog, QWidget * parent):
SimulatedUIWidget(simulator, simuDialog, parent),
SimulatedUIWidgetX9::SimulatedUIWidgetX9(SimulatorInterface *simulator, QWidget * parent):
SimulatedUIWidget(simulator, parent),
ui(new Ui::SimulatedUIWidgetX9)
{
RadioUiAction * act;
@ -30,9 +30,6 @@ SimulatedUIWidgetX9::SimulatedUIWidgetX9(SimulatorInterface *simulator, Simulato
ui->setupUi(this);
//getCurrentFirmware()->getCapability(Capability(RotaryEncoders)); // not working for X9E ?
bool rotaryOnly = IS_TARANIS_X9E(m_board);
// add actions in order of appearance on the help menu
act = addRadioUiAction(0, QList<int>() << Qt::Key_PageUp, tr("PG-UP"), tr("[ MENU ]"));
@ -47,16 +44,8 @@ SimulatedUIWidgetX9::SimulatedUIWidgetX9(SimulatorInterface *simulator, Simulato
polygon.setPoints(6, 24, 154, 32, 144, 46, 146, 57, 156, 46, 167, 29, 166);
ui->leftbuttons->addArea(polygon, "Taranis/x9l3.png", act);
if (rotaryOnly) {
m_keymapHelp.append(keymapHelp_t(tr("WHEEL/PAD SCRL"), tr("Rotary Selector")));
m_scrollUpAction = addRadioUiAction(-1, QList<int>() << Qt::Key_Minus << Qt::Key_Equal << Qt::Key_Up, tr("-/UP"), tr("Rotary UP"));
m_scrollDnAction = addRadioUiAction(-1, QList<int>() << Qt::Key_Plus << Qt::Key_Down, tr("+/DN"), tr("Rotary DOWN"));
connectScrollActions();
}
else {
m_scrollUpAction = addRadioUiAction(4, QList<int>() << Qt::Key_Plus << Qt::Key_Equal << Qt::Key_Up, tr("+/UP"), tr("[ + ]"));
m_scrollDnAction = addRadioUiAction(5, QList<int>() << Qt::Key_Minus << Qt::Key_Down, tr("-/DN"), tr("[ - ]"));
}
polygon.setPoints(6, 64, 60, 71, 50, 90, 50, 100, 60, 90, 73, 72, 73);
ui->rightbuttons->addArea(polygon, "Taranis/x9r1.png", m_scrollUpAction);
@ -64,13 +53,12 @@ SimulatedUIWidgetX9::SimulatedUIWidgetX9(SimulatorInterface *simulator, Simulato
polygon.setPoints(6, 63, 109, 73, 100, 88, 100, 98, 109, 88, 119, 72, 119);
ui->rightbuttons->addArea(polygon, "Taranis/x9r2.png", m_scrollDnAction);
act = addRadioUiAction(2, QList<int>() << Qt::Key_Enter << Qt::Key_Return, tr("ENTER/MOUSE-MID"), (rotaryOnly ? tr("Selector Press") : tr("[ ENT ]")));
act = addRadioUiAction(2, QList<int>() << Qt::Key_Enter << Qt::Key_Return, tr("ENTER/MOUSE-MID"), tr("[ ENT ]"));
polygon.setPoints(6, 63, 155, 72, 146, 90, 146, 98, 155, 88, 166, 72, 166);
ui->rightbuttons->addArea(polygon, "Taranis/x9r3.png", act);
ui->leftbuttons->addArea(90, 177, 118, 197, "Taranis/x9l4.png", m_screenshotAction);
if (!rotaryOnly)
m_keymapHelp.append(keymapHelp_t(tr("WHEEL/PAD SCRL"), tr("[ + ]/[ - ]")));
m_backlightColors << QColor(47, 123, 227); // Taranis Blue

View file

@ -21,8 +21,8 @@
#include "simulateduiwidget.h"
#include "ui_simulateduiwidgetX9E.h"
SimulatedUIWidgetX9E::SimulatedUIWidgetX9E(SimulatorInterface *simulator, SimulatorDialog * simuDialog, QWidget * parent):
SimulatedUIWidget(simulator, simuDialog, parent),
SimulatedUIWidgetX9E::SimulatedUIWidgetX9E(SimulatorInterface *simulator, QWidget * parent):
SimulatedUIWidget(simulator, parent),
ui(new Ui::SimulatedUIWidgetX9E)
{
RadioUiAction * act;
@ -66,10 +66,19 @@ SimulatedUIWidgetX9E::SimulatedUIWidgetX9E(SimulatorInterface *simulator, Simula
setLcd(ui->lcd);
m_simuDialog->setUiAreaStyle("background-color: qlineargradient(spread:pad, x1:1, y1:0.9, x2:0, y2:0, "
"stop:0 rgba(255, 255, 255, 255), "
"stop:0.35 rgba(250, 250, 250, 255), stop:0.5 rgba(242, 241, 241, 255), "
"stop:0.61 rgba(241, 241, 241, 255), stop:1.0 rgba(251, 251, 251, 255));");
QString css = "#radioUiWidget {"
"background-color: qlineargradient(spread:pad, x1:1, y1:0.9, x2:0, y2:0,"
"stop:0 rgba(255, 255, 255, 255),"
"stop:0.35 rgba(250, 250, 250, 255), stop:0.5 rgba(242, 241, 241, 255),"
"stop:0.61 rgba(241, 241, 241, 255), stop:1.0 rgba(251, 251, 251, 255));"
"}";
QTimer * tim = new QTimer(this);
tim->setSingleShot(true);
connect(tim, &QTimer::timeout, [this, css]() {
emit customStyleRequest(css);
});
tim->start(100);
}
SimulatedUIWidgetX9E::~SimulatedUIWidgetX9E()

View file

@ -103,6 +103,8 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator
radioUiWidget->setFocusPolicy(Qt::WheelFocus);
radioUiWidget->setFocus();
connect(radioUiWidget, &SimulatedUIWidget::customStyleRequest, this, &SimulatorDialog::setUiAreaStyle);
vJoyLeft = new VirtualJoystickWidget(this, 'L');
ui->leftStickLayout->addWidget(vJoyLeft);
@ -184,6 +186,7 @@ bool SimulatorDialog::setStartupData(const QByteArray & dataSource, bool fromFil
RadioData simuData;
quint16 ret = 1;
QString error;
QString fileName(dataSource);
// If <dataSource> is blank but we have a data path, use that for individual radio/model files.
if (dataSource.isEmpty() && !radioDataPath.isEmpty()) {
@ -192,19 +195,20 @@ bool SimulatorDialog::setStartupData(const QByteArray & dataSource, bool fromFil
// to avoid hard-coding paths like "RADIO" here. E.g. did it fail due to no data at all, or corrupt data, or...?
if (QDir(QString(radioDataPath).append("/RADIO")).exists()) {
SdcardFormat sdcard(radioDataPath);
if (!(ret = sdcard.load(simuData)))
if (!(ret = sdcard.load(simuData))) {
error = sdcard.error();
}
}
}
// Supposedly we're being given a file name to use, try that out.
else if (fromFile && !dataSource.isEmpty()) {
Storage store = Storage(QString(dataSource));
else if (fromFile && !fileName.isEmpty()) {
Storage store = Storage(fileName);
ret = store.load(simuData);
if (!ret && QFile(QString(dataSource)).exists()) {
if (!ret && QFile(fileName).exists()) {
error = store.error();
}
else {
if (QString(dataSource).endsWith(".otx", Qt::CaseInsensitive)) {
if (fileName.endsWith(".otx", Qt::CaseInsensitive)) {
// no radios can work with .otx files directly, so we load contents into either
// a temporary folder (Horus) or local data array (other radios) which we'll save back to .otx upon exit
if ((ret = setRadioData(&simuData))) {
@ -254,9 +258,10 @@ bool SimulatorDialog::setRadioData(RadioData * radioData)
if (ret) {
if (radioDataPath.isEmpty()) {
startupData.fill(0, getEEpromSize(m_board));
if (firmware->getEEpromInterface()->save((uint8_t *)startupData.data(), *radioData, 0, firmware->getCapability(SimulatorVariant)) <= 0)
if (firmware->getEEpromInterface()->save((uint8_t *)startupData.data(), *radioData, 0, firmware->getCapability(SimulatorVariant)) <= 0) {
ret = false;
}
}
else {
ret = saveRadioData(radioData, radioDataPath);
}
@ -271,7 +276,9 @@ bool SimulatorDialog::setRadioData(RadioData * radioData)
bool SimulatorDialog::setOptions(SimulatorOptions & options, bool withSave)
{
bool ret = false;
setSdPath(options.sdPath);
if (options.startupDataType == SimulatorOptions::START_WITH_FOLDER && !options.dataFolder.isEmpty()) {
setDataPath(options.dataFolder);
ret = setStartupData();
@ -299,6 +306,7 @@ bool SimulatorDialog::saveRadioData(RadioData * radioData, const QString & path,
QString dir = path;
if (dir.isEmpty())
dir = radioDataPath;
if (radioData && !dir.isEmpty()) {
SdcardFormat sdcard(dir);
bool ret = sdcard.write(*radioData);
@ -306,6 +314,7 @@ bool SimulatorDialog::saveRadioData(RadioData * radioData, const QString & path,
*error = sdcard.error();
return ret;
}
return false;
}
@ -359,9 +368,10 @@ bool SimulatorDialog::saveTempData()
}
else {
SdcardFormat sdcard(radioDataPath);
if (!(ret = sdcard.load(radioData)))
if (!(ret = sdcard.load(radioData))) {
error = sdcard.error();
}
}
if (ret) {
Storage store(file);
if (!(ret = store.write(radioData)))
@ -400,7 +410,7 @@ void SimulatorDialog::saveState()
void SimulatorDialog::setUiAreaStyle(const QString & style)
{
ui->radioUiWidget->setStyleSheet(style);
setStyleSheet(style);
}
void SimulatorDialog::captureScreenshot(bool)

View file

@ -270,6 +270,7 @@ int main(int argc, char *argv[])
int finish(int exitCode)
{
qDebug() << "SIMULATOR EXIT" << exitCode;
unregisterSimulators();
unregisterOpenTxFirmwares();