[Simulator] New main UI window, debug console, separate outputs window, more. (#4385)

* [package] Add QtSvg support DLLs for Windows.

* [Simulator] Add images/css resources for new version; Create SimulatorIcon and SimulatorStyle classes; Build with SVG support, remove unused bitmaps.

* [Simulator] Improve and simplify VirtualJoystickWidget resize event (sticks maintain X/Y position) & improve values layout w/out trims.

* [Simulator] Refactor Trainer simulator to use VirtualJoystickWidget, gains lock/hold buttons and X/Y position readout.

* [Simulator] More compact layout for Telemetry simulator, reduces min. width and adds scrolling columns to allow smaller window sizes.

* [Simulator] Add new SimulatorMainWindow and RadioOutputsWidget UI classes.

* [storage] Add non-persistent sessionId() to AppData for tracking currently active radio profile ID.

* [Simulator] Major UI updates:
    * Use a MainWindow interface with dockable/floatable windows, proper toolbar & menu;
    * Persistent size/layout state of all windows/docks/etc between uses, per radio profile;
    * Completely separate radio Outputs window with configurable layout (also persistent between uses);
    * Translations now enabled in standalone Simulator, follows main Companion setting (they need a lot of updates);
    * New custom icons throughout, toolbar icon sizes adhere to user preference in Companion.

* [Simulator] Debug Output console updates:
    * New filter feature with optional full RegEx support, can work in inclusive or exclusive modes (full help text is included in UI);
    * Up to 50 user-defined filters are saved to permanent settings, also a few predefined filters are provided;
    * Saves/restores the last filter used and if it was en/disabled;
    * Added word wrap and clear screen features;
    * Configurable scroll-back buffer size;
    * Increased efficiency & performance of the buffering/printing process.

* [Simulator][OSX] Visual UI tweaks for OS X.

* [Simulator] Fix some debug console settings not being restored properly.

* [Simulator] Add ability to hide/show menu bar; Persist view state of menu bar and radio title bar; Reduce font size on OS X; Other small visual tweaks and improvements.

* [build] Add QtSvg to Linux build scripts (a guess for Dockerfile).

* [build] Fix for Qt 5.3.

* Add OpenTx headers to new files.

* [Companion][storage] Update GeneralSettings() initializer to use current sessionId for profile data retrieval, removes workaround for standalone Simulator being started with arbitrary profile; AppData: always update sessionId when global id() changes.

* [X10] Fixes for new simulator
This commit is contained in:
Max Paperno
2017-02-04 11:59:42 +01:00
committed by Bertrand Songis
parent b493973d7d
commit 2f9d9c1a99
62 changed files with 6357 additions and 3095 deletions
+8 -2
View File
@@ -1,12 +1,14 @@
set(simulation_SRCS
debugoutput.cpp
radiooutputswidget.cpp
simulatordialog.cpp
simulatorinterface.cpp
simulateduiwidget.cpp
simulateduiwidget9X.cpp
simulateduiwidgetX7.cpp
simulateduiwidgetX9.cpp
simulateduiwidgetX12.cpp
simulatorinterface.cpp
simulatormainwindow.cpp
simulatorstartupdialog.cpp
telemetrysimu.cpp
trainersimu.cpp
@@ -16,11 +18,13 @@ set(simulation_SRCS
set(simulation_UIS
debugoutput.ui
radiooutputswidget.ui
simulatordialog.ui
simulateduiwidget9X.ui
simulateduiwidgetX7.ui
simulateduiwidgetX9.ui
simulateduiwidgetX12.ui
simulatormainwindow.ui
simulatorstartupdialog.ui
telemetrysimu.ui
trainersimu.ui
@@ -28,10 +32,12 @@ set(simulation_UIS
set(simulation_HDRS
debugoutput.h
radiooutputswidget.h
radiouiaction.h
simulateduiwidget.h
# simulator.h
simulatordialog.h
simulatormainwindow.h
simulatorstartupdialog.h
telemetrysimu.h
trainersimu.h
@@ -77,4 +83,4 @@ qt5_wrap_ui(simulation_SRCS ${simulation_UIS})
qt5_wrap_cpp(simulation_SRCS ${simulation_HDRS})
add_library(simulation ${simulation_SRCS} ${simulation_HDRS})
qt5_use_modules(simulation Widgets Xml)
qt5_use_modules(simulation Core Widgets Svg)
+339 -18
View File
@@ -21,40 +21,361 @@
#include "debugoutput.h"
#include "ui_debugoutput.h"
DebugOutput::DebugOutput(QWidget * parent):
QDialog(parent),
ui(new Ui::DebugOutput)
#include "appdata.h"
#include <QMessageBox>
#include <QScrollBar>
#include <QDebug>
#define DEBUG_OUTPUT_STATE_VERSION 1
extern AppData g; // ensure what "g" means
DebugOutput * traceCallbackInstance = 0;
const int DebugOutput::m_dataBufferMaxSize = 100; // lines of text (this is not the display buffer)
const int DebugOutput::m_dataPrintFreqDefault = 10; // ms
const quint16 DebugOutput::m_savedViewStateVersion = 1;
void traceCb(const char * text)
{
// divert C callback into simulator instance
if (traceCallbackInstance) {
traceCallbackInstance->traceCallback(text);
}
}
DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator):
QWidget(parent),
ui(new Ui::DebugOutput),
m_simulator(simulator),
m_tmrDataPrint(new QTimer()),
m_dataBuffer(QByteArray()),
m_radioProfileId(g.sessionId()),
m_dataPrintFreq(m_dataPrintFreqDefault),
m_running(false),
m_filterExclude(true)
{
ui->setupUi(this);
#ifdef __APPLE__
QFont newFont("Courier", 13);
ui->Output->setFont(newFont);
ui->Output->setAttribute(Qt::WA_MacNormalSize);
#endif
#if defined WIN32 || !defined __GNUC__
QFont newFont("Courier", 9);
ui->Output->setFont(newFont);
ui->console->setFont(newFont);
#endif
// TODO : allow selecting multiple filters, but needs to be efficient at output stage
QStringList stockFilters;
stockFilters << "^lua[A-Z].*";
stockFilters << "/(error|warning|-(E|W)-)/i";
stockFilters << "!^(GC Use|(play|load|write|find(True)?)File|convert(To|From)Simu|\\tfound( in map)?:|eeprom |f_[a-z]+\\(|(push|(p|P)op(up)?|chain)? ?Menu( .+ display)?|RamBackup).+$";
foreach (const QString & fltr, stockFilters)
ui->filterText->addItem(fltr, "no_delete");
ui->filterText->setValidator(new DebugOutputFilterValidator(ui->filterText));
ui->filterText->installEventFilter(new DeleteComboBoxItemEventFilter());
ui->actionShowFilterHelp->setIcon(SimulatorIcon("info"));
ui->actionWordWrap->setIcon(SimulatorIcon("word_wrap"));
ui->actionClearScr->setIcon(SimulatorIcon("eraser"));
ui->btnShowFilterHelp->setDefaultAction(ui->actionShowFilterHelp);
ui->btnWordWrap->setDefaultAction(ui->actionWordWrap);
ui->btnClearScr->setDefaultAction(ui->actionClearScr);
restoreState();
ui->bufferSize->setValue(ui->console->maximumBlockCount());
// install simulator TRACE hook
traceCallbackInstance = this;
m_simulator->installTraceHook(traceCb);
m_tmrDataPrint->setInterval(m_dataPrintFreq);
connect(ui->filterText, &QComboBox::currentTextChanged, this, &DebugOutput::onFilterTextChanged);
connect(m_tmrDataPrint, &QTimer::timeout, this, &DebugOutput::processBytesReceived);
}
DebugOutput::~DebugOutput()
{
traceCallbackInstance = 0;
stop();
saveState();
if (m_tmrDataPrint)
delete m_tmrDataPrint;
delete ui;
}
void DebugOutput::traceCallback(const QString & text)
void DebugOutput::start()
{
// ui->Output->appendPlainText(text);
QTextCursor cursor(ui->Output->textCursor());
m_tmrDataPrint->start();
m_running = true;
}
// is the scrollbar at the end?
bool atEnd = (ui->Output->verticalScrollBar()->value() == ui->Output->verticalScrollBar()->maximum());
void DebugOutput::stop()
{
m_tmrDataPrint->stop();
m_running = false;
}
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor, 1);
cursor.insertText(text);
void DebugOutput::saveState()
{
QStringList filters;
for (int i = 0; i < ui->filterText->count(); ++i) {
if (!ui->filterText->itemText(i).isEmpty() && ui->filterText->itemData(i).toString() != "no_delete")
filters << ui->filterText->itemText(i);
}
g.simuDbgFilters(filters);
if (atEnd) {
ui->Output->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
QByteArray state;
QDataStream stream(&state, QIODevice::WriteOnly);
stream << m_savedViewStateVersion
<< (qint16)ui->filterText->currentIndex() << (qint32)ui->console->maximumBlockCount()
<< ui->btnFilter->isChecked() << ui->actionWordWrap->isChecked();
SimulatorOptions opts = g.profile[m_radioProfileId].simulatorOptions();
opts.dbgConsoleState = state;
g.profile[m_radioProfileId].simulatorOptions(opts);
}
void DebugOutput::restoreState()
{
quint16 ver = 0;
qint16 fci = -1;
qint32 mbc = 10000;
bool flten = false, wwen = false;
QByteArray state = g.profile[m_radioProfileId].simulatorOptions().dbgConsoleState;
QDataStream stream(state);
stream >> ver;
if (ver && ver <= m_savedViewStateVersion)
stream >> fci >> mbc >> flten >> wwen;
ui->filterText->insertItems(0, g.simuDbgFilters());
ui->filterText->setCurrentIndex(fci);
ui->btnFilter->setChecked(flten);
ui->console->setMaximumBlockCount(mbc);
ui->actionWordWrap->setChecked(wwen);
onFilterTextEdited();
}
void DebugOutput::traceCallback(const char * text)
{
const static QRegExp blank("^[\\r\\n]+$");
bool isBlank;
if (!m_running)
return;
QString line(text);
isBlank = line.contains(blank);
m_mtxDataBuffer.lock();
if (isBlank && m_dataBuffer.size())
m_dataBuffer[m_dataBuffer.size()-1] += line;
else
m_dataBuffer.append(text);
if (m_dataBuffer.size() > m_dataBufferMaxSize) {
m_dataBuffer.removeFirst();
qDebug() << __FILE__ << __LINE__ << "Line buffer overflow! size >" << m_dataBufferMaxSize;
}
m_mtxDataBuffer.unlock();
}
void DebugOutput::processBytesReceived()
{
QString text;
bool fltMatch;
const QTextCursor savedCursor(ui->console->textCursor());
const int sbValue = ui->console->verticalScrollBar()->value();
const bool sbAtBottom = (sbValue == ui->console->verticalScrollBar()->maximum());
m_tmrDataPrint->stop();
while (m_dataBuffer.size() > 1) {
m_mtxDataBuffer.lock();
text = m_dataBuffer.takeFirst();
m_mtxDataBuffer.unlock();
// filter
if (ui->btnFilter->isChecked()) {
fltMatch = text.contains(m_filterRegEx);
if ((m_filterExclude && fltMatch) || (!m_filterExclude && !fltMatch)) {
continue;
}
}
ui->console->moveCursor(QTextCursor::End);
ui->console->textCursor().insertText(text);
if (sbAtBottom) {
ui->console->moveCursor(QTextCursor::End);
ui->console->verticalScrollBar()->setValue(ui->console->verticalScrollBar()->maximum());
}
else {
ui->console->setTextCursor(savedCursor);
ui->console->verticalScrollBar()->setValue(sbValue);
}
QCoreApplication::processEvents();
}
m_tmrDataPrint->start();
}
/*
* UI handlers
*/
void DebugOutput::onFilterTextEdited()
{
const QString fText = ui->filterText->currentText();
if (fText.isEmpty()) {
ui->btnFilter->setChecked(false);
m_filterRegEx = QRegularExpression();
return;
}
m_filterRegEx = makeRegEx(fText, &m_filterExclude);
if (m_filterRegEx.isValid()) {
//ui->btnFilter->setChecked(true);
ui->filterText->setStyleSheet("");
}
else {
ui->btnFilter->setChecked(false);
m_filterRegEx = QRegularExpression();
ui->filterText->setStyleSheet("background-color: rgba(255, 205, 185, 200);");
}
}
void DebugOutput::onFilterTextChanged(const QString &)
{
onFilterTextEdited();
}
void DebugOutput::on_bufferSize_editingFinished()
{
ui->console->setMaximumBlockCount(ui->bufferSize->value());
}
void DebugOutput::on_actionWordWrap_toggled(bool checked)
{
ui->console->setLineWrapMode(checked ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap);
}
void DebugOutput::on_actionClearScr_triggered()
{
ui->console->clear();
}
void DebugOutput::on_actionShowFilterHelp_triggered()
{
// TODO : find some place better for this.
QString help = \
"<html><head><style>kbd {background-color: ghostwhite; font-size: large; white-space: nowrap;}</style></head><body>"
"<p>The filter supports two syntax types: basic matching with common wildcards and well as full Perl-style (<code>pcre</code>) Regular Expressions.</p>"
"<p>By default a filter will only show lines which match (<b>inclusive</b>). To make an <b>exclusive</b> filter which removes matching lines, "
"prefix the filter expression with a <kbd>!</kbd> (exclamation mark).</p>"
"<p>To use <b>Regular Expressions</b> (RegEx), prefix the filter text with a <kbd>/</kbd> (slash) or <kbd>^</kbd> (up caret). "
"<ul>"
"<li>Put the <kbd>/</kbd> or <kbd>^</kbd> after the exclusive <kbd>!</kbd> indicator if you're using one.</li>"
"<li>By default the match is case-sensitive. To make it insensitive, add the typical <kbd>/i</kbd> (slash i) operator at the end of your RegEx.</li>"
"<li>If you use a caret (^) to denote a RegEx, it will become part of the Reg. Ex. (that is, matches from start of line).</li>"
"<li>If the RegEx is invalid, the filter edit field should show a red border and you will not be able to enable the filter.</li>"
"<li>A useful resource for testing REs (with a full reference) can be found at <a href=\"http://www.regexr.com/\">http://www.regexr.com/</a></li>"
"</ul></p>"
"<p>To use <b>basic matching</b> just type any text. Wildcards <kbd>*</kbd> (asterisk) matches any text and <kbd>?</kbd> (question mark) matches any single character."
"<ul>"
"<li>The match is always case-insensitive.</li>"
"<li>The match always starts from the beginning of a log line. To ignore characters at the start, use a leading <kbd>*</kbd> wildcard.</li>"
"<li>A trailing <kbd>*</kbd> is always implied (that is, matches anything to the end of the log line). To avoid this, use a RegEx.</li>"
"<li>You can match literal wildcard characters by prefixing them with a <kbd>\\</kbd> (backslash) character (eg. \"foo\\*bar\" matches \"foo*bar\").</li>"
"</ul></p>"
"<p>After <b>editing text</b>, press ENTER or TAB key (or click anywhere outside the box) to update the filter.</p>"
"<p>To <b>remove an entry</b> from the filter selector list, first choose it, and while in the line editor press <kbd>Shift-Delete</kbd> (or <kbd>Shift-Backspace</kbd>) key combination. "
"The default filters cannot be removed. Up to 50 filters are stored.</p>"
"</body></html>"
;
QMessageBox * msgbox = new QMessageBox(QMessageBox::NoIcon, tr("Debug Console Filter Help"), help, QMessageBox::Ok, this);
msgbox->exec();
}
// static
QRegularExpression DebugOutput::makeRegEx(const QString & input, bool * isExlusive)
{
QString output(input);
QRegularExpression re;
QRegularExpression::PatternOptions reFlags = QRegularExpression::DontCaptureOption;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
reFlags |= QRegularExpression::OptimizeOnFirstUsageOption;
#endif
if (input.left(1) == "!") {
output.remove(0, 1);
if (isExlusive)
*isExlusive = true;
}
else if (isExlusive) {
*isExlusive = false;
}
// regex?
if (output.left(1) == "/" || output.left(1) == "^") {
if (output.left(1) == "/")
output.remove(0, 1);
// check for case-insensitive flag at end ("/.../i")
if (output.endsWith("/i")) {
output.chop(2);
reFlags |= QRegularExpression::CaseInsensitiveOption;
}
else if (output.endsWith("/")) {
output.chop(1);
}
re.setPattern(output);
}
// no, convert arbitrary string to regex
else {
output.replace(QRegExp("^\\\\/"), "/"); // remove escape before fwd-slash ("\/...")
// escape all special chars except * and ?
output.replace(QRegExp("(\\\\|\\.|\\+|\\^|\\$|\\||\\)|\\(|\\]|\\[|\\}|\\{)"), "\\\\1");
output.replace("\\*", "\x30").replace("\\?", "\x31"); // save escaped wildcard chars
output.replace("*", ".*").replace("?", "."); // convert common wildcards
output.replace("\x30", "\\\\*").replace("\x31", "\\\\?"); // replace escaped wildcard chars
output.prepend("^"); // match from start of line; .append("$"); // match whole line
reFlags |= QRegularExpression::CaseInsensitiveOption;
re.setPattern(output);
}
// TODO : user option?
re.setPatternOptions(reFlags);
return re;
}
/*
* Filter input validator for RegEx syntax.
*/
QValidator::State DebugOutputFilterValidator::validate(QString & input, int &) const
{
QRegularExpression re = DebugOutput::makeRegEx(input);
if (re.isValid())
return QValidator::Acceptable;
else
return QValidator::Intermediate;
}
/*
* Event filter for editable QComboBox to allow deleting items with Shift-Delete/Backspace
*/
bool DeleteComboBoxItemEventFilter::eventFilter(QObject *obj, QEvent *event)
{
QComboBox * cb = dynamic_cast<QComboBox *>(obj);
if (cb && cb->isEditable() && cb->currentIndex() > -1 && cb->currentData().toString() != "no_delete") {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if ((keyEvent->key() == Qt::Key::Key_Delete || keyEvent->key() == Qt::Key::Key_Backspace) && keyEvent->modifiers() == Qt::ShiftModifier) {
cb->removeItem(cb->currentIndex());
cb->setCurrentIndex(-1);
return true;
}
}
}
return QObject::eventFilter(obj, event);
}
+53 -7
View File
@@ -21,30 +21,76 @@
#ifndef _DEBUGOUTPUT_H_
#define _DEBUGOUTPUT_H_
#include <QtWidgets>
#include "simulator.h"
#include "simulatorinterface.h"
#include <QMutex>
#include <QTimer>
#include <QValidator>
#include <QWidget>
namespace Ui {
class DebugOutput;
}
class QAbstractButton;
class DebugOutput : public QDialog
using namespace Simulator;
class DebugOutput : public QWidget
{
Q_OBJECT
public:
explicit DebugOutput(QWidget * parent);
explicit DebugOutput(QWidget * parent, SimulatorInterface * simulator);
virtual ~DebugOutput();
void traceCallback(const QString & text);
void start();
void stop();
void traceCallback(const char * text);
static QRegularExpression makeRegEx(const QString & input, bool * isExlusive = NULL);
protected slots:
void saveState();
void restoreState();
void processBytesReceived();
void onFilterTextEdited();
void onFilterTextChanged(const QString &);
void on_bufferSize_editingFinished();
void on_actionWordWrap_toggled(bool checked);
void on_actionClearScr_triggered();
void on_actionShowFilterHelp_triggered();
protected:
private:
Ui::DebugOutput * ui;
SimulatorInterface * m_simulator;
QTimer * m_tmrDataPrint;
QStringList m_dataBuffer;
QMutex m_mtxDataBuffer;
QRegularExpression m_filterRegEx;
private slots:
int m_radioProfileId;
int m_dataPrintFreq;
bool m_running;
bool m_filterExclude;
const static int m_dataBufferMaxSize;
const static int m_dataPrintFreqDefault;
const static quint16 m_savedViewStateVersion;
};
class DebugOutputFilterValidator : public QValidator
{
public:
DebugOutputFilterValidator(QObject *parent = Q_NULLPTR) : QValidator(parent) { }
virtual State validate(QString & input, int &) const;
};
class DeleteComboBoxItemEventFilter : public QObject
{
Q_OBJECT
protected:
bool eventFilter(QObject *obj, QEvent *event);
};
#endif // _DEBUGOUTPUT_H_
+286 -24
View File
@@ -1,15 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DebugOutput</class>
<widget class="QDialog" name="DebugOutput">
<widget class="QWidget" name="DebugOutput">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>711</width>
<height>470</height>
<width>555</width>
<height>733</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Debug Output</string>
</property>
@@ -18,30 +24,286 @@
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>7</number>
</property>
<property name="topMargin">
<number>7</number>
</property>
<property name="rightMargin">
<number>7</number>
</property>
<property name="bottomMargin">
<number>7</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPlainTextEdit" name="Output">
<property name="font">
<font>
<family>Courier New</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>7</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="btnFilter">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enable or disable the filter. If the button won't stay enabled, it is likely there is a syntax error in the Regular Expression entered.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="styleSheet">
<string notr="true">padding: 0.15em</string>
</property>
<property name="text">
<string>Filter:</string>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="filterText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter filter text here. Click the help/info button for details about using the filter. &lt;/p&gt;&lt;p&gt;
To &lt;b&gt;remove a remembered entry&lt;/b&gt; from the filter list, first choose it, and then press &lt;code&gt;Shift-Delete&lt;/code&gt; (or &lt;code&gt;Shift-Backspace&lt;/code&gt;) key combination.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="currentText">
<string/>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<property name="maxCount">
<number>50</number>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
<property name="minimumContentsLength">
<number>1</number>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnShowFilterHelp">
<property name="text">
<string notr="true">H</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Buffer:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="bufferSize">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Number of lines to keep in display.</string>
</property>
<property name="suffix">
<string/>
</property>
<property name="minimum">
<number>100</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
<property name="value">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QToolButton" name="btnWordWrap">
<property name="text">
<string notr="true">WW</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnClearScr">
<property name="text">
<string notr="true">C</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QPlainTextEdit" name="console">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier New</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="maximumBlockCount">
<number>10000</number>
</property>
</widget>
</item>
</layout>
<action name="actionShowFilterHelp">
<property name="icon">
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/info.svg</normaloff>:/images/simulator/icons/svg/info.svg</iconset>
</property>
<property name="text">
<string>Filter &amp;Help</string>
</property>
<property name="toolTip">
<string>Show information about using the filter.</string>
</property>
</action>
<action name="actionWordWrap">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/word_wrap.svg</normaloff>:/images/simulator/icons/svg/word_wrap.svg</iconset>
</property>
<property name="text">
<string>Word &amp;Wrap</string>
</property>
<property name="toolTip">
<string>Toggle word wrapping on/off.</string>
</property>
</action>
<action name="actionClearScr">
<property name="icon">
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/eraser.svg</normaloff>:/images/simulator/icons/svg/eraser.svg</iconset>
</property>
<property name="text">
<string>&amp;Clear</string>
</property>
<property name="toolTip">
<string>Clear the output window of all text.</string>
</property>
</action>
</widget>
<resources>
<include location="../companion.qrc"/>
@@ -0,0 +1,365 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "radiooutputswidget.h"
#include "ui_radiooutputswidget.h"
#include "appdata.h"
#include "constants.h"
#include "eeprominterface.h"
#include "radiodata.h"
#include "simulator.h"
#include "simulatorinterface.h"
extern AppData g; // ensure what "g" means
const int RadioOutputsWidget::m_dataUpdateFreqDefault = 10; // ms
const quint16 RadioOutputsWidget::m_savedViewStateVersion = 1;
RadioOutputsWidget::RadioOutputsWidget(SimulatorInterface * simulator, Firmware * firmware, QWidget *parent) :
QWidget(parent),
m_simulator(simulator),
m_firmware(firmware),
m_tmrUpdateData(new QTimer),
m_radioProfileId(g.sessionId()),
m_started(false),
ui(new Ui::RadioOutputsWidget)
{
ui->setupUi(this);
restoreState();
m_dataUpdateFreq = m_dataUpdateFreqDefault;
m_tmrUpdateData->setInterval(m_dataUpdateFreq);
connect(m_tmrUpdateData, &QTimer::timeout, this, &RadioOutputsWidget::setValues);
}
RadioOutputsWidget::~RadioOutputsWidget()
{
stop();
saveState();
if (m_tmrUpdateData)
delete m_tmrUpdateData;
delete ui;
}
void RadioOutputsWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void RadioOutputsWidget::showEvent(QShowEvent * event)
{
if (m_started)
m_tmrUpdateData->start();
}
void RadioOutputsWidget::hideEvent(QHideEvent * event)
{
m_tmrUpdateData->stop();
}
void RadioOutputsWidget::start()
{
setupChannelsDisplay();
setupGVarsDisplay();
setupLsDisplay();
m_tmrUpdateData->start();
m_started = true;
}
void RadioOutputsWidget::stop()
{
m_tmrUpdateData->stop();
m_started = false;
}
void RadioOutputsWidget::restart()
{
stop();
start();
}
void RadioOutputsWidget::saveState()
{
QByteArray state;
QDataStream stream(&state, QIODevice::WriteOnly);
stream << m_savedViewStateVersion
<< ui->btnLogiSw->isChecked() << ui->btnGlobalVars->isChecked() << ui->btnChannels->isChecked()
<< ui->splitter->saveState();
SimulatorOptions opts = g.profile[m_radioProfileId].simulatorOptions();
opts.radioOutputsState = state;
g.profile[m_radioProfileId].simulatorOptions(opts);
}
void RadioOutputsWidget::restoreState()
{
quint16 ver = 0;
QByteArray splitterState;
bool ls = true, gv = true, ch = true;
QByteArray state = g.profile[m_radioProfileId].simulatorOptions().radioOutputsState;
QDataStream stream(state);
stream >> ver;
if (ver && ver <= m_savedViewStateVersion)
stream >> ls >> gv >> ch >> splitterState;
ui->btnLogiSw->setChecked(ls);
ui->btnGlobalVars->setChecked(gv);
ui->btnChannels->setChecked(ch);
if (!splitterState.isEmpty())
ui->splitter->restoreState(splitterState);
}
void RadioOutputsWidget::setupChannelsDisplay()
{
int outputs = std::min(32, m_firmware->getCapability(Capability(Outputs)));
// delete old widgets if already exist
m_channelsMap.clear();
QWidget * oldChanW = ui->channelsScroll->takeWidget();
if (oldChanW)
oldChanW->deleteLater();
if (!outputs)
return;
QWidget * channelsWidget = new QWidget();
QGridLayout * channelsLayout = new QGridLayout(channelsWidget);
channelsLayout->setHorizontalSpacing(4);
channelsLayout->setVerticalSpacing(3);
channelsLayout->setContentsMargins(5, 5, 5, 5);
ui->channelsScroll->setWidget(channelsWidget);
// populate outputs
int column = 0;
for (int i=0; i < outputs; i++) {
QLabel * label = new QLabel(channelsWidget);
label->setText(" " + RawSource(SOURCE_TYPE_CH, i).toString() + " ");
label->setAlignment(Qt::AlignCenter);
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
channelsLayout->addWidget(label, 0, column, 1, 1);
QSlider * slider = new QSlider(channelsWidget);
slider->setEnabled(false);
slider->setMinimum(-1024);
slider->setMaximum(1024);
slider->setPageStep(128);
slider->setTracking(false);
slider->setOrientation(Qt::Vertical);
slider->setInvertedAppearance(false);
slider->setTickPosition(QSlider::TicksRight);
slider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
channelsLayout->addWidget(slider, 2, column, 1, 1);
channelsLayout->setAlignment(slider, Qt::AlignHCenter);
QLabel * value = new QLabel(channelsWidget);
value->setMinimumSize(QSize(value->fontMetrics().size(Qt::TextSingleLine, "-100.0").width(), 0));
value->setAlignment(Qt::AlignCenter);
value->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
channelsLayout->addWidget(value, 1, column, 1, 1);
++column;
m_channelsMap.insert(i, QPair<QLabel *, QSlider *>(value, slider));
}
}
void RadioOutputsWidget::setupGVarsDisplay()
{
int gvars = m_firmware->getCapability(Capability(Gvars));
int fmodes = m_firmware->getCapability(Capability(FlightModes));
// delete old widgets if already exist
m_globalVarsMap.clear();
QWidget * oldGv = ui->globalVarsScroll->takeWidget();
if (oldGv)
oldGv->deleteLater();
if (!gvars)
return;
QWidget * gvarsWidget = new QWidget();
QGridLayout * gvarsLayout = new QGridLayout(gvarsWidget);
gvarsLayout->setContentsMargins(5, 5, 5, 5);
gvarsLayout->setHorizontalSpacing(6);
gvarsLayout->setVerticalSpacing(3);
ui->globalVarsScroll->setWidget(gvarsWidget);
QPalette::ColorRole bgrole = QPalette::AlternateBase;
for (int fm=0; fm < fmodes; fm++) {
QLabel * label = new QLabel(gvarsWidget);
label->setText(QString("FM%1").arg(fm));
label->setAlignment(Qt::AlignCenter);
label->setBackgroundRole(bgrole);
gvarsLayout->addWidget(label, 0, fm+1);
}
QHash<int, QLabel *> fmMap;
for (int gv=0; gv < gvars; gv++) {
bgrole = ((gv % 2) ? QPalette::Background : QPalette::AlternateBase);
QLabel * label = new QLabel(gvarsWidget);
label->setText(QString("GV%1").arg(gv+1));
label->setAutoFillBackground(true);
label->setBackgroundRole(bgrole);
gvarsLayout->addWidget(label, gv+1, 0);
for (int fm=0; fm < fmodes; fm++) {
QLabel * value = new QLabel(gvarsWidget);
value->setAutoFillBackground(true);
value->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
value->setBackgroundRole(bgrole);
value->setText("0");
value->setStyleSheet("padding-right: .06em;");
gvarsLayout->addWidget(value, gv+1, fm+1);
fmMap.insert(fm, value);
}
m_globalVarsMap.insert(gv, fmMap);
}
}
void RadioOutputsWidget::setupLsDisplay()
{
int switches = m_firmware->getCapability(LogicalSwitches);
// delete old widgets if already exist
m_logicSwitchMap.clear();
QWidget * oldLsW = ui->logicalSwitchesScroll->takeWidget();
if (oldLsW)
oldLsW->deleteLater();
if (!switches)
return;
QWidget * logicalSwitches = new QWidget();
logicalSwitches->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
QGridLayout * logicalSwitchesLayout = new QGridLayout(logicalSwitches);
logicalSwitchesLayout->setHorizontalSpacing(3);
logicalSwitchesLayout->setVerticalSpacing(2);
logicalSwitchesLayout->setContentsMargins(5, 5, 5, 5);
ui->logicalSwitchesScroll->setWidget(logicalSwitches);
// populate logical switches
int rows = switches / (switches > 16 ? 4 : 2);
for (int i=0; i < switches; i++) {
QLabel * lsLbl = new QLabel;
logicalSwitchesLayout->addWidget(createLogicalSwitch(logicalSwitches, i, lsLbl), i / rows, i % rows, 1, 1);
m_logicSwitchMap.insert(i, lsLbl);
}
}
QWidget * RadioOutputsWidget::createLogicalSwitch(QWidget * parent, int switchNo, QLabel * label)
{
QFrame * swtch = new QFrame(parent);
swtch->setAutoFillBackground(true);
swtch->setFrameShape(QFrame::Panel);
swtch->setFrameShadow(QFrame::Raised);
swtch->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
swtch->setMaximumHeight(18);
QVBoxLayout * layout = new QVBoxLayout(swtch);
layout->setContentsMargins(2, 0, 2, 0);
if (label) {
QFont font;
font.setPointSize(8);
label->setParent(swtch);
label->setFont(font);
label->setText(RawSwitch(SWITCH_TYPE_VIRTUAL, switchNo+1).toString());
label->setAlignment(Qt::AlignCenter);
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
label->setAutoFillBackground(true);
layout->addWidget(label);
}
return swtch;
}
// Read various values from firmware simulator and populate values in this UI
void RadioOutputsWidget::setValues()
{
static int lastPhase = 0;
static TxOutputs prevOutputs = TxOutputs();
int currentPhase;
TxOutputs outputs;
m_simulator->getValues(outputs);
currentPhase = m_simulator->getPhase();
if (ui->channelsWidget->isVisible()) {
QHash<int, QPair<QLabel *, QSlider *> >::const_iterator ch;
for (ch = m_channelsMap.constBegin(); ch != m_channelsMap.constEnd(); ++ch) {
if (ch.key() >= CPN_MAX_CHNOUT)
continue;
ch.value().first->setText(QString("%1%").arg(outputs.chans[ch.key()] * 100 / 1024));
ch.value().second->setValue(qMin(1024, qMax(-1024, outputs.chans[ch.key()])));
}
}
if (ui->logicalSwitchesWidget->isVisible()) {
QHash<int, QLabel* >::const_iterator ls;
for (ls = m_logicSwitchMap.constBegin(); ls != m_logicSwitchMap.constEnd(); ++ls) {
if (ls.key() >= CPN_MAX_CSW || prevOutputs.vsw[ls.key()] == outputs.vsw[ls.key()])
continue;
ls.value()->setBackgroundRole(outputs.vsw[ls.key()] ? QPalette::Highlight : QPalette::Background);
prevOutputs.vsw[ls.key()] = outputs.vsw[ls.key()];
}
}
if (ui->globalVarsWidget->isVisible()) {
QFont font;
QPalette::ColorRole bgrole;
QHash<int, QHash<int, QLabel *> >::const_iterator gv;
QHash<int, QLabel *>::const_iterator fm;
for (gv = m_globalVarsMap.constBegin(); gv != m_globalVarsMap.constEnd(); ++gv) {
if (gv.key() >= CPN_MAX_GVARS)
continue;
for (fm = gv.value().constBegin(); fm != gv.value().constEnd(); ++fm) {
if (fm.key() >= CPN_MAX_FLIGHT_MODES)
continue;
if (currentPhase != lastPhase || prevOutputs.gvars[fm.key()][gv.key()] != outputs.gvars[fm.key()][gv.key()]) {
font = fm.value()->font();
bgrole = ((gv.key() % 2) ? QPalette::Background : QPalette::AlternateBase);
if (fm.key() == lastPhase) {
font.setBold(true);
bgrole = QPalette::Highlight;
}
fm.value()->setText(QString::number(outputs.gvars[fm.key()][gv.key()]));
fm.value()->setFont(font);
fm.value()->setBackgroundRole(bgrole);
prevOutputs.gvars[fm.key()][gv.key()] = outputs.gvars[fm.key()][gv.key()];
}
}
}
}
if (currentPhase != lastPhase)
lastPhase = currentPhase;
}
@@ -0,0 +1,87 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef RADIOOUTPUTSWIDGET_H
#define RADIOOUTPUTSWIDGET_H
#include "simulator.h"
#include <QTimer>
#include <QWidget>
namespace Ui {
class RadioOutputsWidget;
}
class Firmware;
class SimulatorInterface;
class QFrame;
class QLabel;
class QSlider;
using namespace Simulator;
class RadioOutputsWidget : public QWidget
{
Q_OBJECT
public:
explicit RadioOutputsWidget(SimulatorInterface * simulator, Firmware * firmware, QWidget * parent = 0);
~RadioOutputsWidget();
void start();
void stop();
void restart();
protected slots:
void saveState();
void restoreState();
void setValues();
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
protected:
void changeEvent(QEvent *e);
void setupChannelsDisplay();
void setupLsDisplay();
void setupGVarsDisplay();
QWidget * createLogicalSwitch(QWidget * parent, int switchNo, QLabel * label);
SimulatorInterface * m_simulator;
Firmware * m_firmware;
QTimer * m_tmrUpdateData;
QHash<int, QPair<QLabel *, QSlider *> > m_channelsMap; // m_channelsMap[chanIndex] = {QLabel*, QSlider*}
QHash<int, QLabel *> m_logicSwitchMap; // m_logicSwitchMap[lsIndex] = QLabel*
QHash<int, QHash<int, QLabel *> > m_globalVarsMap; // m_globalVarsMap[gvarIndex][fmodeIndex] = QLabel*
int m_radioProfileId;
int m_dataUpdateFreq;
bool m_started;
const static int m_dataUpdateFreqDefault;
const static quint16 m_savedViewStateVersion;
private:
Ui::RadioOutputsWidget * ui;
};
#endif // RADIOOUTPUTSWIDGET_H
@@ -0,0 +1,440 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RadioOutputsWidget</class>
<widget class="QWidget" name="RadioOutputsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<height>436</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>7</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>7</number>
</property>
<property name="bottomMargin">
<number>7</number>
</property>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>View:</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnLogiSw">
<property name="text">
<string>Logical Switches</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnGlobalVars">
<property name="text">
<string>Global Variables</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnChannels">
<property name="text">
<string>Channel Outputs</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QWidget" name="logicalSwitchesWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="midLineWidth">
<number>3</number>
</property>
<property name="text">
<string>L
o
g
i
c</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="heading" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="logicalSwitchesScroll">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>740</width>
<height>85</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="globalVarsWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="midLineWidth">
<number>3</number>
</property>
<property name="text">
<string>G
l
o
b
a
l</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="heading" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="globalVarsScroll">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>739</width>
<height>101</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="channelsWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>3</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="midLineWidth">
<number>3</number>
</property>
<property name="text">
<string>C
h
a
n
n
e
l
s</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="heading" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="channelsScroll">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>739</width>
<height>194</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>btnChannels</sender>
<signal>toggled(bool)</signal>
<receiver>channelsWidget</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>236</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>346</x>
<y>435</y>
</hint>
</hints>
</connection>
<connection>
<sender>btnGlobalVars</sender>
<signal>toggled(bool)</signal>
<receiver>globalVarsWidget</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>157</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>346</x>
<y>275</y>
</hint>
</hints>
</connection>
<connection>
<sender>btnLogiSw</sender>
<signal>toggled(bool)</signal>
<receiver>logicalSwitchesWidget</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>62</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>346</x>
<y>114</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+4 -1
View File
@@ -127,8 +127,10 @@ class RadioUiAction : public QObject
{
if (toggle(active)) {
emit triggered(m_hwIndex, active);
if (active)
if (active) {
emit pushed(m_hwIndex);
emit pushed();
}
}
}
@@ -146,6 +148,7 @@ class RadioUiAction : public QObject
void toggled(int index, bool active); // on programmatic or user interaction change
void triggered(int index, bool active); // on user interaction change only
void pushed(int index); // only emitted on user interaction && when 'active' is true
void pushed();
};
#endif // RADIOUIACTION_H
@@ -40,7 +40,7 @@ SimulatedUIWidget::SimulatedUIWidget(SimulatorInterface * simulator, SimulatorDi
{
m_rotEncClickAction = addRadioUiAction(-1, 0, tr("Rotary encoder click"));
m_screenshotAction = addRadioUiAction(-1, Qt::Key_Print, tr("Take Screenshot"));
connect(m_screenshotAction, &RadioUiAction::pushed, this, &SimulatedUIWidget::saveScreenshot);
connect(m_screenshotAction, static_cast<void (RadioUiAction::*)(void)>(&RadioUiAction::pushed), this, &SimulatedUIWidget::captureScreenshot);
}
SimulatedUIWidget::~SimulatedUIWidget()
@@ -114,9 +114,8 @@ void SimulatedUIWidget::updateUi()
} */
}
void SimulatedUIWidget::saveScreenshot(int idx)
void SimulatedUIWidget::captureScreenshot()
{
Q_UNUSED(idx)
QString fileName = "";
if (!g.snapToClpbrd()) {
QString path = g.snapshotDir();
@@ -124,7 +123,8 @@ void SimulatedUIWidget::saveScreenshot(int idx)
path = "./";
QDir dir(path);
if (!dir.exists() || !dir.isReadable()) {
m_simuDialog->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"));
@@ -180,12 +180,12 @@ void SimulatedUIWidget::setLcd(LcdWidget * lcd)
void SimulatedUIWidget::connectScrollActions()
{
connect(m_scrollUpAction, &RadioUiAction::pushed, [this](void) {
connect(m_scrollUpAction, static_cast<void (RadioUiAction::*)(void)>(&RadioUiAction::pushed), [this](void) {
this->simulatorWheelEvent(-1);
m_scrollUpAction->toggle(false);
});
connect(m_scrollDnAction, &RadioUiAction::pushed, [this](void) {
connect(m_scrollDnAction, static_cast<void (RadioUiAction::*)(void)>(&RadioUiAction::pushed), [this](void) {
simulatorWheelEvent(1);
m_scrollDnAction->toggle(false);
});
+1 -2
View File
@@ -64,8 +64,7 @@ class SimulatedUIWidget : public QWidget
public slots:
void updateUi();
void saveScreenshot(int idx = -1);
void captureScreenshot() { saveScreenshot(); }
void captureScreenshot();
void simulatorWheelEvent(qint8 steps);
void wheelEvent(QWheelEvent *event);
+81 -6
View File
@@ -24,16 +24,85 @@
#include <QColor>
#include <QDataStream>
#include <QDebug>
#include <QFile>
#include <QIcon>
#include <QPair>
#include <QString>
#define SIMULATOR_OPTIONS_VERSION 1
#define SIMULATOR_FLAGS_NOTX 0x01 // simulating a single model from Companion
#define SIMULATOR_FLAGS_STANDALONE 0x02 // started from stanalone simulator
namespace Simulator {
#define SIMULATOR_OPTIONS_VERSION 2
typedef QPair<QString, QString> keymapHelp_t;
namespace Simulator
{
}
typedef QPair<QString, QString> keymapHelp_t;
class SimulatorStyle
{
public:
SimulatorStyle() { }
static QString const basePath() { return ":/themes/default"; }
static QString const styleSheet()
{
QString css;
QFile fh(QString("%1/style.css").arg(basePath()));
if (fh.open(QFile::ReadOnly | QFile::Text)) {
css = fh.readAll();
fh.close();
}
#ifdef __APPLE__
fh.setFileName(QString("%1/style-osx.css").arg(basePath()));
if (fh.open(QFile::ReadOnly | QFile::Text)) {
css.append(fh.readAll());
fh.close();
}
#endif
return css;
}
}; // SimulatorStyle
class SimulatorIcon : public QIcon
{
public:
SimulatorIcon(const QString & baseImage)
{
QString baseFile = QString("%1/%2").arg(basePath(), baseImage);
addFile(QString("%1.svg").arg(baseFile));
QString addfile = QString("%1-on.svg").arg(baseFile);
if (QFile(addfile).exists())
addFile(addfile, QSize(), QIcon::Normal, QIcon::On);
addfile = QString("%1-active.svg").arg(baseFile);
if (QFile(addfile).exists())
addFile(addfile, QSize(), QIcon::Active, QIcon::Off);
addfile = QString("%1-disabled.svg").arg(baseFile);
if (QFile(addfile).exists())
addFile(addfile, QSize(), QIcon::Disabled, QIcon::Off);
}
static QString const basePath() { return ":/images/simulator/icons/svg"; }
static QSize const toolbarIconSize(int setting)
{
switch(setting) {
case 0:
return QSize(16, 16);
case 2:
return QSize(32, 32);
case 3:
return QSize(48, 48);
case 1:
default:
return QSize(24, 24);
}
}
}; // class SimulatorIcon
} // namespace Simulator
struct SimulatorOptions
{
@@ -54,14 +123,18 @@ struct SimulatorOptions
QString dataFile;
QString dataFolder;
QString sdPath;
QByteArray windowGeometry;
QByteArray windowGeometry; // SimulatorMainWindow geometry
QList<QByteArray> controlsState; // saved switch/pot/stick settings
QColor lcdColor;
// added in v2
QByteArray windowState; // SimulatorMainWindow dock/toolbar/options UI state
QByteArray dbgConsoleState; // DebugOutput UI state
QByteArray radioOutputsState; // RadioOutputsWidget UI state
friend QDataStream & operator << (QDataStream &out, const SimulatorOptions & o)
{
out << quint16(SIMULATOR_OPTIONS_VERSION) << o.startupDataType << o.firmwareId << o.dataFile << o.dataFolder
<< o.sdPath << o.windowGeometry << o.controlsState << o.lcdColor;
<< o.sdPath << o.windowGeometry << o.controlsState << o.lcdColor << o.windowState << o.dbgConsoleState << o.radioOutputsState;
return out;
}
@@ -70,6 +143,8 @@ struct SimulatorOptions
if (o._version <= SIMULATOR_OPTIONS_VERSION) {
in >> o._version >> o.startupDataType >> o.firmwareId >> o.dataFile >> o.dataFolder
>> o.sdPath >> o.windowGeometry >> o.controlsState >> o.lcdColor;
if (o._version >= 2)
in >> o.windowState >> o.dbgConsoleState >> o.radioOutputsState;
}
return in;
}
+92 -469
View File
@@ -22,7 +22,6 @@
#include "ui_simulatordialog.h"
#include "appdata.h"
#include "debugoutput.h"
#include "radiofaderwidget.h"
#include "radioknobwidget.h"
#include "radioswitchwidget.h"
@@ -31,8 +30,6 @@
#include "simulateduiwidget.h"
#include "simulatorinterface.h"
#include "storage.h"
#include "telemetrysimu.h"
#include "trainersimu.h"
#include "virtualjoystickwidget.h"
#ifdef JOYSTICKS
#include "joystick.h"
@@ -43,18 +40,8 @@
#include <QFile>
#include <iostream>
SimulatorDialog * traceCallbackInstance = 0;
void traceCb(const char * text)
{
// divert C callback into simulator instance
if (traceCallbackInstance) {
traceCallbackInstance->traceCallback(text);
}
}
SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator, quint8 flags):
QDialog(parent),
QWidget(parent),
ui(new Ui::SimulatorDialog),
simulator(simulator),
firmware(getCurrentFirmware()),
@@ -63,12 +50,8 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator
radioUiWidget(NULL),
vJoyLeft(NULL),
vJoyRight(NULL),
TelemetrySimu(NULL),
TrainerSimu(NULL),
DebugOut(NULL),
m_board(getCurrentBoard()),
flags(flags),
radioProfileId(g.id()),
lastPhase(-1),
buttonPressed(0),
trimPressed(TRIM_NONE),
@@ -78,40 +61,74 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator
middleButtonPressed(false),
firstShow(true)
{
setWindowFlags(Qt::Window);
// install simulator TRACE hook
traceCallbackInstance = this;
simulator->installTraceHook(traceCb);
#ifdef JOYSTICKS
joystick = NULL;
#endif
// defaults
setRadioProfileId(radioProfileId);
setRadioProfileId(g.sessionId());
setSdPath(g.profile[radioProfileId].sdPath());
setupUi();
ui->setupUi(this);
windowName = tr("Radio Simulator (%1)").arg(firmware->getName());
setWindowTitle(windowName);
switch(m_board) {
case Board::BOARD_TARANIS_X7 :
radioUiWidget = new SimulatedUIWidgetX7(simulator, this);
break;
case Board::BOARD_TARANIS_X9D :
case Board::BOARD_TARANIS_X9DP :
case Board::BOARD_TARANIS_X9E :
radioUiWidget = new SimulatedUIWidgetX9(simulator, this);
break;
case Board::BOARD_X12S:
case Board::BOARD_X10:
radioUiWidget = new SimulatedUIWidgetX12(simulator, this);
break;
default:
radioUiWidget = new SimulatedUIWidget9X(simulator, this);
break;
}
foreach (keymapHelp_t item, *radioUiWidget->getKeymapHelp())
keymapHelp.append(item);
ui->radioUiWidget->layout()->removeItem(ui->radioUiTempSpacer);
ui->radioUiWidget->layout()->addWidget(radioUiWidget);
vJoyLeft = new VirtualJoystickWidget(this, 'L');
ui->leftStickLayout->addWidget(vJoyLeft);
vJoyRight = new VirtualJoystickWidget(this, 'R');
ui->rightStickLayout->addWidget(vJoyRight);
connect(vJoyLeft, SIGNAL(trimButtonPressed(int)), this, SLOT(onTrimPressed(int)));
connect(vJoyLeft, SIGNAL(trimButtonReleased()), this, SLOT(onTrimReleased()));
connect(vJoyLeft, SIGNAL(trimSliderMoved(int,int)), this, SLOT(onTrimSliderMoved(int,int)));
connect(vJoyRight, SIGNAL(trimButtonPressed(int)), this, SLOT(onTrimPressed(int)));
connect(vJoyRight, SIGNAL(trimButtonReleased()), this, SLOT(onTrimReleased()));
connect(vJoyRight, SIGNAL(trimSliderMoved(int,int)), this, SLOT(onTrimSliderMoved(int,int)));
}
SimulatorDialog::~SimulatorDialog()
{
traceCallbackInstance = 0;
shutdown();
if (timer) {
timer->stop();
if (timer)
timer->deleteLater();
}
if (radioUiWidget)
radioUiWidget->deleteLater();
delete radioUiWidget;
if (vJoyLeft)
vJoyLeft->deleteLater();
delete vJoyLeft;
if (vJoyRight)
vJoyRight->deleteLater();
delete vJoyRight;
#ifdef JOYSTICKS
if (joystick)
joystick->deleteLater();
delete joystick;
#endif
firmware = NULL; // Not sure we should delete this but at least release our pointer.
@@ -125,13 +142,6 @@ SimulatorDialog::~SimulatorDialog()
* Public slots/setters
*/
void SimulatorDialog::setRadioProfileId(int value)
{
radioProfileId = value;
if (simulator)
simulator->setVolumeGain(g.profile[radioProfileId].volumeGain());
}
void SimulatorDialog::setSdPath(const QString & sdPath)
{
setPaths(sdPath, radioDataPath);
@@ -355,25 +365,20 @@ void SimulatorDialog::deleteTempData()
void SimulatorDialog::saveState()
{
SimulatorOptions opts = g.profile[radioProfileId].simulatorOptions();
opts.windowGeometry = saveGeometry();
//opts.windowGeometry = saveGeometry();
opts.controlsState = saveRadioWidgetsState();
g.profile[radioProfileId].simulatorOptions(opts);
}
void SimulatorDialog::setUiAreaStyle(const QString & style)
{
ui->radioUiTab->setStyleSheet(style);
ui->radioUiWidget->setStyleSheet(style);
}
void SimulatorDialog::traceCallback(const char * text)
void SimulatorDialog::captureScreenshot(bool)
{
// this function is called from other threads
traceMutex.lock();
// limit the size of list
if (traceList.size() < 1000) {
traceList.append(QString(text));
}
traceMutex.unlock();
if (radioUiWidget)
radioUiWidget->captureScreenshot();
}
/*
@@ -384,8 +389,6 @@ void SimulatorDialog::start()
{
setupRadioWidgets();
setupJoysticks();
setupOutputsDisplay();
setupGVarsDisplay();
restoreRadioWidgetsState();
if (startupData.isEmpty())
@@ -414,94 +417,30 @@ void SimulatorDialog::restart()
start();
}
void SimulatorDialog::shutdown()
{
stop();
saveState();
if (saveTempRadioData)
saveTempData();
if (deleteTempRadioData)
deleteTempData();
}
/*
* Setup
*/
void SimulatorDialog::setupUi()
void SimulatorDialog::setRadioProfileId(int value)
{
ui->setupUi(this);
windowName = tr("Simulating Radio (%1)").arg(firmware->getName());
setWindowTitle(windowName);
switch(m_board) {
case Board::BOARD_TARANIS_X7:
radioUiWidget = new SimulatedUIWidgetX7(simulator, this);
break;
case Board::BOARD_TARANIS_X9D:
case Board::BOARD_TARANIS_X9DP:
case Board::BOARD_TARANIS_X9E:
radioUiWidget = new SimulatedUIWidgetX9(simulator, this);
break;
case Board::BOARD_X12S:
case Board::BOARD_X10:
radioUiWidget = new SimulatedUIWidgetX12(simulator, this);
break;
default:
radioUiWidget = new SimulatedUIWidget9X(simulator, this);
break;
}
foreach (keymapHelp_t item, *radioUiWidget->getKeymapHelp()) {
keymapHelp.append(item);
}
ui->radioUiTab->layout()->addWidget(radioUiWidget);
ui->tabWidget->setTabText(0, firmware->getName());
ui->tabWidget->setFixedHeight(radioUiWidget->height() + ui->tabWidget->tabBar()->height() - 8);
vJoyLeft = new VirtualJoystickWidget(this, 'L');
ui->leftStickLayout->addWidget(vJoyLeft);
vJoyRight = new VirtualJoystickWidget(this, 'R');
ui->rightStickLayout->addWidget(vJoyRight);
ui->tabWidget->setCurrentIndex(flags & SIMULATOR_FLAGS_NOTX);
connect(vJoyLeft, SIGNAL(trimButtonPressed(int)), this, SLOT(onTrimPressed(int)));
connect(vJoyLeft, SIGNAL(trimButtonReleased()), this, SLOT(onTrimReleased()));
connect(vJoyLeft, SIGNAL(trimSliderMoved(int,int)), this, SLOT(onTrimSliderMoved(int,int)));
connect(vJoyRight, SIGNAL(trimButtonPressed(int)), this, SLOT(onTrimPressed(int)));
connect(vJoyRight, SIGNAL(trimButtonReleased()), this, SLOT(onTrimReleased()));
connect(vJoyRight, SIGNAL(trimSliderMoved(int,int)), this, SLOT(onTrimSliderMoved(int,int)));
connect(ui->btn_help, SIGNAL(released()), this, SLOT(showHelp()));
connect(ui->btn_joystickDialog, SIGNAL(released()), this, SLOT(openJoystickDialog()));
connect(ui->btn_telemSim, SIGNAL(released()), this, SLOT(openTelemetrySimulator()));
connect(ui->btn_trainerSim, SIGNAL(released()), this, SLOT(openTrainerSimulator()));
connect(ui->btn_debugConsole, SIGNAL(released()), this, SLOT(openDebugOutput()));
connect(ui->btn_luaReload, SIGNAL(released()), this, SLOT(luaReload()));
connect(ui->btn_screenshot, SIGNAL(released()), radioUiWidget, SLOT(captureScreenshot()));
connect(ui->btn_reloadSimu, SIGNAL(released()), this, SLOT(restart()));
#ifdef JOYSTICKS
bool showJoystick = true;
#else
bool showJoystick = false;
#endif
// Hide some main UI buttons based on board capabilities, and add keymap help texts.
QString role;
foreach (QPushButton * btn, ui->buttonBox->findChildren<QPushButton *>()) {
role = btn->property("role").toString();
if ((role == "joystick" && !showJoystick) ||
(role == "telemetry" && !firmware->getCapability(Capability(SportTelemetry))) ||
(role == "reloadLua" && !firmware->getCapability(Capability(LuaInputsPerScript))) )
{
btn->hide();
continue;
}
if (!btn->shortcut().isEmpty())
keymapHelp.append(keymapHelp_t(btn->shortcut().toString(QKeySequence::NativeText), btn->statusTip()));
}
radioProfileId = value;
if (simulator)
simulator->setVolumeGain(g.profile[radioProfileId].volumeGain());
}
void SimulatorDialog::setupRadioWidgets()
{
int i, midpos, aIdx, wval;
int i, midpos, aIdx;
QString wname;
Board::Type board = firmware->getBoard();
@@ -535,13 +474,12 @@ void SimulatorDialog::setupRadioWidgets()
continue;
swcfg = Board::SwitchType(radioSettings.switchConfig[i]);
wval = (swcfg == Board::SWITCH_3POS ? -1 : 0);
if ((wname = QString(radioSettings.switchName[i])).isEmpty()) {
switchInfo = getSwitchInfo(board, i);
wname = QString(switchInfo.name);
}
RadioSwitchWidget * sw = new RadioSwitchWidget(swcfg, wname, wval, ui->radioWidgetsHT);
RadioSwitchWidget * sw = new RadioSwitchWidget(swcfg, wname, -1, ui->radioWidgetsHT);
sw->setIndex(i);
ui->radioWidgetsHTLayout->addWidget(sw);
switches.append(sw);
@@ -593,172 +531,6 @@ void SimulatorDialog::setupRadioWidgets()
}
}
void SimulatorDialog::setupOutputsDisplay()
{
// setup Outputs tab
QWidget * outputsWidget;
// delete old widget if already exists
if (ui->tabWidget->count() > 1 && ui->tabWidget->widget(1)->objectName() == "RadioOutputsWidget") {
outputsWidget = ui->tabWidget->widget(1);
ui->tabWidget->removeTab(1);
outputsWidget->deleteLater();
outputsWidget = NULL;
}
channelValues.clear();
channelSliders.clear();
logicalSwitchLabels.clear();
outputsWidget = new QWidget();
outputsWidget->setObjectName("RadioOutputsWidget");
QGridLayout * gridLayout = new QGridLayout(outputsWidget);
gridLayout->setHorizontalSpacing(0);
gridLayout->setVerticalSpacing(3);
gridLayout->setContentsMargins(5, 3, 5, 3);
// logical switches area
QWidget * logicalSwitches = new QWidget(outputsWidget);
logicalSwitches->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
QGridLayout * logicalSwitchesLayout = new QGridLayout(logicalSwitches);
logicalSwitchesLayout->setHorizontalSpacing(3);
logicalSwitchesLayout->setVerticalSpacing(2);
logicalSwitchesLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->addWidget(logicalSwitches, 0, 0, 1, 1);
// channels area
QScrollArea * scrollArea = new QScrollArea(outputsWidget);
QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Preferred);
sp.setHorizontalStretch(0);
sp.setVerticalStretch(0);
scrollArea->setSizePolicy(sp);
scrollArea->setWidgetResizable(true);
QWidget * channelsWidget = new QWidget();
QGridLayout * channelsLayout = new QGridLayout(channelsWidget);
channelsLayout->setHorizontalSpacing(4);
channelsLayout->setVerticalSpacing(3);
channelsLayout->setContentsMargins(0, 0, 0, 3);
scrollArea->setWidget(channelsWidget);
gridLayout->addWidget(scrollArea, 1, 0, 1, 1);
ui->tabWidget->insertTab(1, outputsWidget, QString(tr("Outputs")));
// populate outputs
int outputs = std::min(32, firmware->getCapability(Outputs));
int column = 0;
for (int i=0; i<outputs; i++) {
QLabel * label = new QLabel(outputsWidget);
label->setText(" " + RawSource(SOURCE_TYPE_CH, i).toString() + " ");
label->setAlignment(Qt::AlignCenter);
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
channelsLayout->addWidget(label, 0, column, 1, 1);
QSlider * slider = new QSlider(outputsWidget);
slider->setEnabled(false);
slider->setMinimum(-1024);
slider->setMaximum(1024);
slider->setPageStep(128);
slider->setTracking(false);
slider->setOrientation(Qt::Vertical);
slider->setInvertedAppearance(false);
slider->setTickPosition(QSlider::TicksRight);
slider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
QLabel * value = new QLabel(outputsWidget);
value->setMinimumSize(QSize(value->fontMetrics().size(Qt::TextSingleLine, "-100.0").width(), 0));
value->setAlignment(Qt::AlignCenter);
value->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
channelValues << value;
channelsLayout->addWidget(value, 1, column, 1, 1);
channelSliders << slider;
channelsLayout->addWidget(slider, 2, column++, 1, 1);
channelsLayout->setAlignment(slider, Qt::AlignHCenter);
}
// populate logical switches
int switches = firmware->getCapability(LogicalSwitches);
int rows = switches / (switches > 16 ? 4 : 2);
for (int i=0; i<switches; i++) {
QFrame * swtch = createLogicalSwitch(outputsWidget, i, logicalSwitchLabels);
logicalSwitchesLayout->addWidget(swtch, i / rows, i % rows, 1, 1);
}
}
void SimulatorDialog::setupGVarsDisplay()
{
// setup GVars tab
int gvars = firmware->getCapability(Gvars);
int fmodes = firmware->getCapability(FlightModes);
QWidget * gvarsWidget;
// delete old widget if already exists
if (ui->tabWidget->count() > 2 && ui->tabWidget->widget(2)->objectName() == "RadioGVOutputsWidget") {
gvarsWidget = ui->tabWidget->widget(2);
ui->tabWidget->removeTab(2);
gvarsWidget->deleteLater();
gvarsWidget = NULL;
}
gvarValues.clear();
if (!gvars)
return;
gvarsWidget = new QWidget();
gvarsWidget->setObjectName("RadioGVOutputsWidget");
QGridLayout * gvarsLayout = new QGridLayout(gvarsWidget);
ui->tabWidget->insertTab(2, gvarsWidget, QString(tr("GVars")));
for (int fm=0; fm<fmodes; fm++) {
QLabel * label = new QLabel(gvarsWidget);
label->setText(QString("FM%1").arg(fm));
label->setAlignment(Qt::AlignCenter);
gvarsLayout->addWidget(label, 0, fm+1);
}
for (int i=0; i<gvars; i++) {
QLabel * label = new QLabel(gvarsWidget);
label->setText(QString("GV%1").arg(i+1));
label->setAutoFillBackground(true);
if ((i % 2) ==0 ) {
label->setStyleSheet("QLabel { background-color: rgb(220, 220, 220) }");
}
gvarsLayout->addWidget(label, i+1, 0);
for (int fm=0; fm<fmodes; fm++) {
QLabel * value = new QLabel(gvarsWidget);
value->setAutoFillBackground(true);
value->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
if ((i % 2) ==0 ) {
value->setStyleSheet("QLabel { background-color: rgb(220, 220, 220) }");
}
value->setText("0");
gvarValues << value;
gvarsLayout->addWidget(value, i+1, fm+1);
}
}
}
QFrame * SimulatorDialog::createLogicalSwitch(QWidget * parent, int switchNo, QVector<QLabel *> & labels)
{
QFrame * swtch = new QFrame(parent);
swtch->setAutoFillBackground(true);
swtch->setFrameShape(QFrame::Panel);
swtch->setFrameShadow(QFrame::Raised);
swtch->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
swtch->setMaximumHeight(18);
QVBoxLayout * layout = new QVBoxLayout(swtch);
layout->setContentsMargins(2, 0, 2, 0);
QFont font;
font.setPointSize(8);
QLabel * label = new QLabel(swtch);
label->setFont(font);
label->setText(RawSwitch(SWITCH_TYPE_VIRTUAL, switchNo+1).toString());
label->setAlignment(Qt::AlignCenter);
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
labels << label;
layout->addWidget(label);
return swtch;
}
void SimulatorDialog::setupJoysticks()
{
#ifdef JOYSTICKS
@@ -855,6 +627,16 @@ void SimulatorDialog::restoreRadioWidgetsState()
if (switchesMap.contains(switches[i]->getIndex()))
switches[i]->setStateData(switchesMap.value(switches[i]->getIndex()));
}
// Set throttle stick down and locked, side depends on mode
if (radioSettings.stickMode & 1) {
vJoyLeft->setStickConstraint(VirtualJoystickWidget::HOLD_Y, true);
vJoyLeft->setStickY(1);
}
else {
vJoyRight->setStickConstraint(VirtualJoystickWidget::HOLD_Y, true);
vJoyRight->setStickY(1);
}
}
QList<QByteArray> SimulatorDialog::saveRadioWidgetsState()
@@ -877,44 +659,8 @@ QList<QByteArray> SimulatorDialog::saveRadioWidgetsState()
// Read various values from firmware simulator and populate values in this UI
void SimulatorDialog::setValues()
{
static const int numGvars = firmware->getCapability(Gvars);
static const int numFlightModes = firmware->getCapability(FlightModes);
static TxOutputs prevOutputs;
TxOutputs outputs;
simulator->getValues(outputs);
int currentPhase = simulator->getPhase();
// Outputs tab visible?
if (ui->tabWidget->currentIndex() == 1) {
for (int i = 0; i < channelSliders.size() && i < CPN_MAX_CHNOUT; i++) {
channelSliders[i]->setValue(qMin(1024, qMax(-1024, outputs.chans[i])));
channelValues[i]->setText(QString("%1").arg((qreal)outputs.chans[i]*100/1024, 0, 'f', 1));
}
for (int i = 0; i < logicalSwitchLabels.size() && i < CPN_MAX_CSW; i++) {
// setStyleSheet() is very CPU time consuming, do it only if the actual switch state changes
if (prevOutputs.vsw[i] != outputs.vsw[i]) {
logicalSwitchLabels[i]->setStyleSheet(outputs.vsw[i] ? CSWITCH_ON : CSWITCH_OFF);
prevOutputs.vsw[i] = outputs.vsw[i];
}
}
}
// GVars tab visible?
if (ui->tabWidget->currentIndex() == 2) {
for (int gv = 0; gv < numGvars; gv++) {
for (int fm = 0; fm < numFlightModes; fm++) {
// same trick for GVARS, but this has far less effect on CPU usage as setStyleSheet()
if (currentPhase != lastPhase || prevOutputs.gvars[fm][gv] != outputs.gvars[fm][gv]) {
gvarValues[gv*numFlightModes+fm]->setText(QString((fm == lastPhase) ? "<b>%1</b>" : "%1").arg(outputs.gvars[fm][gv]));
prevOutputs.gvars[fm][gv] = outputs.gvars[fm][gv];
}
}
}
}
// display current flight mode in window title
if (currentPhase != lastPhase) {
lastPhase = currentPhase;
@@ -923,7 +669,6 @@ void SimulatorDialog::setValues()
phase_name = QString::number(currentPhase);
setWindowTitle(windowName + QString(" - Flight Mode %1").arg(phase_name));
}
}
// "get" values from this UI and send them to the firmware simulator.
@@ -995,34 +740,16 @@ void SimulatorDialog::setTrims()
* Event handlers/private slots
*/
void SimulatorDialog::closeEvent(QCloseEvent *)
{
stop();
saveState();
if (saveTempRadioData)
saveTempData();
if (deleteTempRadioData)
deleteTempData();
}
//void SimulatorDialog::showEvent(QShowEvent *)
//{
// if (firstShow && isVisible()) {
// firstShow = false;
// }
//}
void SimulatorDialog::showEvent(QShowEvent *)
{
if (firstShow) {
restoreGeometry(g.profile[radioProfileId].simulatorOptions().windowGeometry);
// The stick position needs to be set after the final show event, otherwise resizes during dialog creation will screw it up.
if (radioSettings.stickMode & 1) {
vJoyLeft->setStickConstraint(VirtualJoystickWidget::HOLD_Y, true);
vJoyLeft->setStickY(1);
}
else {
vJoyRight->setStickConstraint(VirtualJoystickWidget::HOLD_Y, true);
vJoyRight->setStickY(1);
}
firstShow = false;
}
}
//void SimulatorDialog::closeEvent(QCloseEvent *)
//{
//}
void SimulatorDialog::mousePressEvent(QMouseEvent *event)
{
@@ -1059,8 +786,6 @@ void SimulatorDialog::onTimerEvent()
setTrims();
centerSticks();
}
updateDebugOutput();
}
void SimulatorDialog::onTrimPressed(int which)
@@ -1087,111 +812,9 @@ void SimulatorDialog::centerSticks()
vJoyRight->centerStick();
}
void SimulatorDialog::openTelemetrySimulator()
{
// allow only one instance
if (TelemetrySimu == 0) {
TelemetrySimu = new TelemetrySimulator(this, simulator);
TelemetrySimu->setAttribute(Qt::WA_DeleteOnClose);
TelemetrySimu->show();
connect(TelemetrySimu, &TelemetrySimulator::destroyed, [this](QObject *) {
this->TelemetrySimu = NULL;
});
}
else if (!TelemetrySimu->isVisible()) {
TelemetrySimu->show();
}
}
void SimulatorDialog::openTrainerSimulator()
{
// allow only one instance
if (TrainerSimu == 0) {
TrainerSimu = new TrainerSimulator(this, simulator);
TrainerSimu->setAttribute(Qt::WA_DeleteOnClose);
TrainerSimu->show();
connect(TrainerSimu, &TrainerSimulator::destroyed, [this](QObject *) {
this->TrainerSimu = NULL;
});
}
else if (!TrainerSimu->isVisible()) {
TrainerSimu->show();
}
}
void SimulatorDialog::openJoystickDialog()
{
#ifdef JOYSTICKS
joystickDialog * jd = new joystickDialog(this);
if (jd->exec() == QDialog::Accepted)
setupJoysticks();
jd->deleteLater();
#endif
}
void SimulatorDialog::openDebugOutput()
{
// allow only one instance, but install signal handler to catch dialog destruction just in case
if (!DebugOut) {
DebugOut = new DebugOutput(this);
DebugOut->traceCallback(traceBuffer);
DebugOut->setAttribute(Qt::WA_DeleteOnClose);
DebugOut->show();
connect(DebugOut, &DebugOutput::destroyed, [this](QObject *) {
this->DebugOut = NULL;
});
}
else if (!DebugOut->isVisible()) {
DebugOut->show();
}
}
void SimulatorDialog::updateDebugOutput()
{
traceMutex.lock();
while (!traceList.isEmpty()) {
QString text = traceList.takeFirst();
traceBuffer.append(text);
// limit the size of traceBuffer
if (traceBuffer.size() > 10*1024) {
traceBuffer.remove(0, 1*1024);
}
if (DebugOut) {
DebugOut->traceCallback(QString(text));
}
}
traceMutex.unlock();
}
void SimulatorDialog::luaReload()
{
// force a reload of the lua environment
simulator->setLuaStateReloadPermanentScripts();
}
void SimulatorDialog::showHelp()
{
QString helpText = tr("Simulator Controls:");
helpText += "<table cellspacing=4 cellpadding=0>";
helpText += tr("<tr><th>Key/Mouse</td><th>Action</td></tr>");
QString keyTemplate = "<tr><td align='center'><pre>%1</pre></td><td align='center'>%2</td></tr>";
foreach (keymapHelp_t pair, keymapHelp)
helpText += keyTemplate.arg(pair.first, pair.second);
helpText += "</table>";
QMessageBox * msgBox = new QMessageBox(this);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setWindowFlags(msgBox->windowFlags() | Qt::WindowStaysOnTopHint);
msgBox->setStandardButtons( QMessageBox::Ok );
msgBox->setWindowTitle(tr("Simulator Help"));
msgBox->setText(helpText);
msgBox->setModal(false);
msgBox->show();
}
#ifdef JOYSTICKS
void SimulatorDialog::onjoystickAxisValueChanged(int axis, int value)
{
#ifdef JOYSTICKS
int stick;
if (axis>=0 && axis<=8) {
stick=jsmap[axis];
@@ -1225,5 +848,5 @@ void SimulatorDialog::onjoystickAxisValueChanged(int axis, int value)
analogs[stick-5]->setValue(stickval);
}
}
}
#endif
}
+9 -40
View File
@@ -26,17 +26,11 @@
#include "radiodata.h"
#include "simulator.h"
#include <QDialog>
#include <QWidget>
#include <QVector>
#include <QMutex>
#define SIMULATOR_FLAGS_NOTX 0x01 // simulating a single model from Companion
#define SIMULATOR_FLAGS_STANDALONE 0x02 // started from stanalone simulator
#define FLASH_DURATION 10
#define CSWITCH_ON "QLabel { background-color: #4CC417 }"
#define CSWITCH_OFF "QLabel { }"
#define CBEEP_ON "QLabel { background-color: #FF364E }"
#define CBEEP_OFF "QLabel { }"
@@ -45,9 +39,6 @@ void traceCb(const char * text);
class Firmware;
class SimulatorInterface;
class SimulatedUIWidget;
class TelemetrySimulator;
class TrainerSimulator;
class DebugOutput;
class RadioWidget;
class RadioSwitchWidget;
class VirtualJoystickWidget;
@@ -57,7 +48,6 @@ class Joystick;
class QWidget;
class QSlider;
class QDial;
class QLabel;
class QFrame;
@@ -67,7 +57,7 @@ namespace Ui {
using namespace Simulator;
class SimulatorDialog : public QDialog
class SimulatorDialog : public QWidget
{
Q_OBJECT
@@ -75,7 +65,6 @@ class SimulatorDialog : public QDialog
explicit SimulatorDialog(QWidget * parent, SimulatorInterface *simulator, quint8 flags=0);
virtual ~SimulatorDialog();
void setRadioProfileId(int value);
void setSdPath(const QString & sdPath);
void setDataPath(const QString & dataPath);
void setPaths(const QString & sdPath, const QString & dataPath);
@@ -89,23 +78,22 @@ class SimulatorDialog : public QDialog
void deleteTempData();
void saveState();
void setUiAreaStyle(const QString & style);
void traceCallback(const char * text);
void captureScreenshot(bool);
void setupJoysticks();
QString getSdPath() const { return sdCardPath; }
QString getDataPath() const { return radioDataPath; }
QVector<keymapHelp_t> * getKeymapHelp() { return &keymapHelp; }
public slots:
void start();
void stop();
void restart();
void shutdown();
private:
void setupUi();
void setRadioProfileId(int value);
void setupRadioWidgets();
void setupOutputsDisplay();
void setupGVarsDisplay();
void setupJoysticks();
QFrame * createLogicalSwitch(QWidget * parent, int switchNo, QVector<QLabel *> & labels);
void setupTimer();
void restoreRadioWidgetsState();
QList<QByteArray> saveRadioWidgetsState();
@@ -122,24 +110,14 @@ class SimulatorDialog : public QDialog
QTimer * timer;
QString windowName;
QString traceBuffer;
QMutex traceMutex;
QList<QString> traceList;
QVector<keymapHelp_t> keymapHelp;
SimulatedUIWidget * radioUiWidget;
VirtualJoystickWidget * vJoyLeft;
VirtualJoystickWidget * vJoyRight;
TelemetrySimulator * TelemetrySimu;
TrainerSimulator * TrainerSimu;
DebugOutput * DebugOut;
QVector<RadioSwitchWidget *> switches;
QVector<RadioWidget *> analogs;
QVector<QLabel *> logicalSwitchLabels;
QVector<QSlider *> channelSliders;
QVector<QLabel *> channelValues;
QVector<QLabel *> gvarValues;
QString sdCardPath;
QString radioDataPath;
@@ -163,8 +141,8 @@ class SimulatorDialog : public QDialog
#endif
private slots:
virtual void closeEvent(QCloseEvent *);
virtual void showEvent(QShowEvent *);
//virtual void showEvent(QShowEvent *);
//virtual void closeEvent(QCloseEvent *);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
@@ -174,16 +152,7 @@ class SimulatorDialog : public QDialog
void onTrimReleased();
void onTrimSliderMoved(int which, int value);
void centerSticks();
void openTelemetrySimulator();
void openTrainerSimulator();
void openJoystickDialog();
void openDebugOutput();
void updateDebugOutput();
void luaReload();
void showHelp();
#ifdef JOYSTICKS
void onjoystickAxisValueChanged(int axis, int value);
#endif
};
+201 -370
View File
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SimulatorDialog</class>
<widget class="QDialog" name="SimulatorDialog">
<widget class="QWidget" name="SimulatorDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>651</width>
<height>528</height>
<width>448</width>
<height>302</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -23,29 +23,26 @@
<iconset resource="../companion.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<property name="horizontalSpacing">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>3</number>
<property name="leftMargin">
<number>0</number>
</property>
<item row="1" column="0">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="controlFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@@ -54,7 +51,7 @@
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
@@ -62,414 +59,248 @@
<property name="lineWidth">
<number>2</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout" rowstretch="1,4">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>7</number>
<number>0</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>6</number>
<number>7</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
<number>0</number>
</property>
<property name="verticalSpacing">
<number>5</number>
<number>10</number>
</property>
<item row="1" column="0">
<widget class="QWidget" name="leftStickWidget" native="true">
<item row="0" column="0" colspan="2" alignment="Qt::AlignBottom">
<widget class="QFrame" name="radioWidgetsHT">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="leftStickLayout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="2">
<widget class="QWidget" name="rightStickWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="rightStickLayout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="radioWidgetsVC" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="4,1">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="VCGridLayout">
<property name="horizontalSpacing">
<number>16</number>
</property>
<property name="verticalSpacing">
<number>9</number>
</property>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QWidget" name="radioWidgetsHT" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="midLineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="radioWidgetsHTLayout">
<property name="spacing">
<number>11</number>
<number>10</number>
</property>
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
<number>9</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
<number>9</number>
</property>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QFrame" name="controlsLower">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>7</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>12</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0" rowspan="2">
<widget class="QWidget" name="leftStickWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="leftStickLayout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="radioWidgetsVC" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="3,1">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>12</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="VCGridLayout">
<property name="horizontalSpacing">
<number>16</number>
</property>
<property name="verticalSpacing">
<number>9</number>
</property>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<widget class="QWidget" name="rightStickWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="rightStickLayout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
<zorder>leftStickWidget</zorder>
<zorder>rightStickWidget</zorder>
<zorder>radioWidgetsVC</zorder>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<item alignment="Qt::AlignBottom">
<widget class="QWidget" name="radioUiWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QTabWidget::pane,
QStackedWidget {
padding: 0px;
margin: 0px;
}
QTabWidget::tab-bar{
margin-bottom: 0px;
padding-bottom: 0px;
}</string>
<string notr="true"/>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="documentMode">
<bool>false</bool>
</property>
<widget class="QWidget" name="radioUiTab">
<property name="styleSheet">
<string notr="true">background-color: qlineargradient(spread:reflect, x1:0.22, y1:0, x2:0.55065, y2:0.54, stop:0 rgba(7, 7, 7, 250), stop:0.864407 rgba(66, 66, 66, 255));
margin: 0;
padding: 0;</string>
</property>
<attribute name="title">
<string>Radio Simulator</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
</item>
<item row="0" column="0">
<widget class="QWidget" name="buttonBox" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="buttonsLayout">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>3</number>
<number>0</number>
</property>
<property name="leftMargin">
<number>1</number>
<number>0</number>
</property>
<property name="topMargin">
<number>1</number>
<number>0</number>
</property>
<property name="rightMargin">
<number>1</number>
<number>0</number>
</property>
<property name="bottomMargin">
<number>1</number>
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btn_help">
<property name="toolTip">
<string>Show Help/Keymap (F1)</string>
<spacer name="radioUiTempSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="statusTip">
<string>Show Help/Keymap</string>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="text">
<string>Keymap</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
<property name="shortcut">
<string>F1</string>
</property>
<property name="role" stdset="0">
<string>help</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_joystickDialog">
<property name="toolTip">
<string>Open the Joystick Settings window (F3)</string>
</property>
<property name="statusTip">
<string>Joystick Configuration</string>
</property>
<property name="text">
<string>Joystick Config.</string>
</property>
<property name="shortcut">
<string>F3</string>
</property>
<property name="role" stdset="0">
<string>joystick</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_telemSim">
<property name="toolTip">
<string>Open Telemetry Simulator window (F4)</string>
</property>
<property name="statusTip">
<string>Telemetry Simulator</string>
</property>
<property name="text">
<string>Telemetry Sim.</string>
</property>
<property name="shortcut">
<string>F4</string>
</property>
<property name="role" stdset="0">
<string>telemetry</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_trainerSim">
<property name="toolTip">
<string>Open Trainer Simulator window (F5)</string>
</property>
<property name="statusTip">
<string>Trainer Simulator</string>
</property>
<property name="text">
<string>Trainer Sim.</string>
</property>
<property name="shortcut">
<string>F5</string>
</property>
<property name="role" stdset="0">
<string>trainer</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_debugConsole">
<property name="toolTip">
<string>Open Debug Console window (F6)</string>
</property>
<property name="statusTip">
<string>Debug Console</string>
</property>
<property name="text">
<string>Debug Console</string>
</property>
<property name="shortcut">
<string>F6</string>
</property>
<property name="role" stdset="0">
<string>debug</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_luaReload">
<property name="toolTip">
<string>Reload Lua Scripts (F7)</string>
</property>
<property name="statusTip">
<string>Reload Lua Scripts</string>
</property>
<property name="text">
<string>Reload Lua</string>
</property>
<property name="shortcut">
<string>F7</string>
</property>
<property name="role" stdset="0">
<string>reloadLua</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_screenshot">
<property name="toolTip">
<string>Save a screenshot of the radio LCD screen (F8)</string>
</property>
<property name="statusTip">
<string>LCD Screenshot</string>
</property>
<property name="text">
<string>Screenshot</string>
</property>
<property name="shortcut">
<string>F8</string>
</property>
<property name="role" stdset="0">
<string>lcdScreenshot</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_reloadSimu">
<property name="toolTip">
<string>Reload all radio data (F9)</string>
</property>
<property name="statusTip">
<string>Reload Radio Data</string>
</property>
<property name="text">
<string>Reload Radio</string>
</property>
<property name="shortcut">
<string>F9</string>
</property>
<property name="role" stdset="0">
<string>reloadradio</string>
</property>
</widget>
</spacer>
</item>
</layout>
</widget>
@@ -0,0 +1,350 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "simulatormainwindow.h"
#include "ui_simulatormainwindow.h"
#include "appdata.h"
#include "debugoutput.h"
#include "radiooutputswidget.h"
#include "simulatordialog.h"
#include "simulatorinterface.h"
#include "telemetrysimu.h"
#include "trainersimu.h"
#ifdef JOYSTICKS
#include "joystickdialog.h"
#endif
#include <QDebug>
extern AppData g; // ensure what "g" means
const quint16 SimulatorMainWindow::m_savedUiStateVersion = 1;
SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, SimulatorInterface * simulator, quint8 flags, Qt::WindowFlags wflags) :
QMainWindow(parent, wflags),
m_simulator(simulator),
ui(new Ui::SimulatorMainWindow),
m_simulatorWidget(NULL),
m_consoleWidget(NULL),
m_outputsWidget(NULL),
m_simulatorDockWidget(NULL),
m_consoleDockWidget(NULL),
m_telemetryDockWidget(NULL),
m_trainerDockWidget(NULL),
m_outputsDockWidget(NULL),
m_radioProfileId(g.sessionId()),
m_firstShow(true),
m_showRadioTitlebar(true),
m_showMenubar(true)
{
ui->setupUi(this);
ui->centralwidget->hide();
//#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
// setDockOptions(dockOptions() | QMainWindow::GroupedDragging);
//#endif
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
m_simulatorWidget = new SimulatorDialog(this, m_simulator, flags);
m_simulatorDockWidget = new QDockWidget(m_simulatorWidget->windowTitle(), this);
m_simulatorDockWidget->setObjectName("RADIO_SIMULATOR");
m_simulatorDockWidget->setWidget(m_simulatorWidget);
m_simulatorDockWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
addDockWidget(Qt::BottomDockWidgetArea, m_simulatorDockWidget);
// setCentralWidget(m_simulatorWidget);
createDockWidgets();
ui->actionReloadLua->setIcon(SimulatorIcon("reload_script"));
ui->actionReloadRadioData->setIcon(SimulatorIcon("restart"));
ui->actionJoystickSettings->setIcon(SimulatorIcon("joystick_settings"));
ui->actionScreenshot->setIcon(SimulatorIcon("camera"));
ui->actionShowKeymap->setIcon(SimulatorIcon("info"));
ui->actionToggleRadioTitle->setIcon(ui->toolBar->toggleViewAction()->icon());
ui->actionToggleMenuBar->setIcon(ui->toolBar->toggleViewAction()->icon());
ui->toolBar->toggleViewAction()->setShortcut(tr("Alt+T"));
ui->toolBar->setIconSize(SimulatorIcon::toolbarIconSize(g.iconSize()));
ui->toolBar->insertSeparator(ui->actionReloadLua);
// add these to this window directly to maintain shorcuts when menubar is hidden
addAction(ui->toolBar->toggleViewAction());
addAction(ui->actionToggleMenuBar);
ui->menuView->addSeparator();
ui->menuView->addAction(ui->toolBar->toggleViewAction());
ui->menuView->addAction(ui->actionToggleMenuBar);
ui->menuView->addAction(ui->actionToggleRadioTitle);
// Hide some actions based on board capabilities.
Firmware * firmware = getCurrentFirmware();
if(!firmware->getCapability(Capability(LuaInputsPerScript)))
ui->actionReloadLua->setDisabled(true);
if (!firmware->getCapability(Capability(SportTelemetry)))
m_telemetryDockWidget->toggleViewAction()->setDisabled(true);
#ifndef JOYSTICKS
ui->actionJoystickSettings->setDisabled(true);
#endif
// Add radio-specific help text from simulator widget
foreach (keymapHelp_t item, *m_simulatorWidget->getKeymapHelp())
m_keymapHelp.append(item);
restoreUiState();
setStyleSheet(SimulatorStyle::styleSheet());
connect(ui->actionShowKeymap, &QAction::triggered, this, &SimulatorMainWindow::showHelp);
connect(ui->actionJoystickSettings, &QAction::triggered, this, &SimulatorMainWindow::openJoystickDialog);
connect(ui->actionReloadLua, &QAction::triggered, this, &SimulatorMainWindow::luaReload);
connect(ui->actionToggleRadioTitle, &QAction::toggled, this, &SimulatorMainWindow::showRadioTitlebar);
connect(ui->actionToggleMenuBar, &QAction::toggled, this, &SimulatorMainWindow::toggleMenuBar);
if (m_simulatorWidget) {
connect(ui->actionScreenshot, &QAction::triggered, m_simulatorWidget, &SimulatorDialog::captureScreenshot);
connect(ui->actionReloadRadioData, &QAction::triggered, m_simulatorWidget, &SimulatorDialog::restart);
}
if (m_outputsWidget)
connect(ui->actionReloadRadioData, &QAction::triggered, m_outputsWidget, &RadioOutputsWidget::restart);
// this sets the radio widget to a fixed width while docked, freeform while floating
connect(m_simulatorDockWidget, &QDockWidget::topLevelChanged, [this](bool top) {
if (top)
m_simulatorWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
else
m_simulatorWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
});
}
SimulatorMainWindow::~SimulatorMainWindow()
{
delete ui;
}
void SimulatorMainWindow::closeEvent(QCloseEvent *)
{
saveUiState();
if (m_consoleDockWidget)
delete m_consoleDockWidget;
if (m_telemetryDockWidget)
delete m_telemetryDockWidget;
if (m_trainerDockWidget)
delete m_trainerDockWidget;
if (m_outputsDockWidget)
delete m_outputsDockWidget;
if (m_simulatorDockWidget)
delete m_simulatorDockWidget;
}
void SimulatorMainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
QMenu* SimulatorMainWindow::createPopupMenu(){
QMenu * menu = QMainWindow::createPopupMenu();
menu->addAction(ui->actionToggleMenuBar);
menu->addAction(ui->actionToggleRadioTitle);
return menu;
}
void SimulatorMainWindow::saveUiState()
{
QByteArray state;
QDataStream stream(&state, QIODevice::WriteOnly);
stream << m_savedUiStateVersion << saveState() << m_showMenubar << m_showRadioTitlebar;
SimulatorOptions opts = g.profile[m_radioProfileId].simulatorOptions();
opts.windowState = state;
opts.windowGeometry = saveGeometry();
g.profile[m_radioProfileId].simulatorOptions(opts);
}
void SimulatorMainWindow::restoreUiState()
{
quint16 ver = 0;
QByteArray windowState;
QByteArray state = g.profile[m_radioProfileId].simulatorOptions().windowState;
QDataStream stream(state);
stream >> ver;
if (ver && ver <= m_savedUiStateVersion)
stream >> windowState >> m_showMenubar >> m_showRadioTitlebar;
restoreState(windowState);
restoreGeometry(g.profile[m_radioProfileId].simulatorOptions().windowGeometry);
showRadioTitlebar(m_showRadioTitlebar);
toggleMenuBar(m_showMenubar);
}
bool SimulatorMainWindow::setRadioData(RadioData * radioData)
{
return m_simulatorWidget->setRadioData(radioData);
}
bool SimulatorMainWindow::useTempDataPath(bool deleteOnClose, bool saveOnClose)
{
return m_simulatorWidget->useTempDataPath(deleteOnClose, saveOnClose);
}
bool SimulatorMainWindow::setOptions(SimulatorOptions & options, bool withSave)
{
return m_simulatorWidget->setOptions(options, withSave);
}
void SimulatorMainWindow::start()
{
if (m_consoleWidget)
m_consoleWidget->start();
if (m_simulatorWidget)
m_simulatorWidget->start();
if (m_outputsWidget)
m_outputsWidget->start();
}
void SimulatorMainWindow::createDockWidgets()
{
if (!m_outputsDockWidget) {
SimulatorIcon icon("radio_outputs");
m_outputsDockWidget = new QDockWidget(tr("Radio Outputs"), this);
m_outputsWidget = new RadioOutputsWidget(m_simulator, getCurrentFirmware(), this);
m_outputsWidget->setWindowIcon(icon);
m_outputsDockWidget->setWidget(m_outputsWidget);
m_outputsDockWidget->setObjectName("OUTPUTS");
addTool(m_outputsDockWidget, Qt::BottomDockWidgetArea, icon, QKeySequence(tr("F2")));
}
if (!m_telemetryDockWidget) {
SimulatorIcon icon("telemetry");
m_telemetryDockWidget = new QDockWidget(tr("Telemetry Simulator"), this);
TelemetrySimulator * telem = new TelemetrySimulator(this, m_simulator);
telem->setWindowIcon(icon);
m_telemetryDockWidget->setWidget(telem);
m_telemetryDockWidget->setObjectName("TELEMETRY_SIMULATOR");
addTool(m_telemetryDockWidget, Qt::LeftDockWidgetArea, icon, QKeySequence(tr("F4")));
}
if (!m_trainerDockWidget) {
SimulatorIcon icon("trainer");
m_trainerDockWidget = new QDockWidget(tr("Trainer Simulator"), this);
TrainerSimulator * trainer = new TrainerSimulator(this, m_simulator);
trainer->setWindowIcon(icon);
m_trainerDockWidget->setWidget(trainer);
m_trainerDockWidget->setObjectName("TRAINER_SIMULATOR");
addTool(m_trainerDockWidget, Qt::TopDockWidgetArea, icon, QKeySequence(tr("F5")));
}
if (!m_consoleDockWidget) {
SimulatorIcon icon("console");
m_consoleDockWidget = new QDockWidget(tr("Debug Output"), this);
m_consoleWidget = new DebugOutput(this, m_simulator);
m_consoleWidget->setWindowIcon(icon);
m_consoleDockWidget->setWidget(m_consoleWidget);
m_consoleDockWidget->setObjectName("CONSOLE");
addTool(m_consoleDockWidget, Qt::RightDockWidgetArea, icon, QKeySequence(tr("F6")));
}
}
void SimulatorMainWindow::addTool(QDockWidget * widget, Qt::DockWidgetArea area, QIcon icon, QKeySequence shortcut)
{
QAction* tempAction = widget->toggleViewAction();
tempAction->setIcon(icon);
tempAction->setShortcut(shortcut);
ui->menuView->addAction(tempAction);
ui->toolBar->insertAction(ui->actionReloadLua, tempAction);
widget->setAllowedAreas(Qt::AllDockWidgetAreas);
widget->setWindowIcon(icon);
addDockWidget(area, widget);
widget->hide();
widget->setFloating(true);
}
void SimulatorMainWindow::showRadioTitlebar(bool show)
{
m_showRadioTitlebar = show;
if (show) {
QWidget * w = m_simulatorDockWidget->titleBarWidget();
if (w)
w->deleteLater();
m_simulatorDockWidget->setTitleBarWidget(0);
}
else {
m_simulatorDockWidget->setTitleBarWidget(new QWidget());
}
if (ui->actionToggleRadioTitle->isChecked() != show)
ui->actionToggleRadioTitle->setChecked(show);
}
void SimulatorMainWindow::toggleMenuBar(bool show)
{
m_showMenubar = show;
ui->menubar->setVisible(show);
if (ui->actionToggleMenuBar->isChecked() != show)
ui->actionToggleMenuBar->setChecked(show);
}
void SimulatorMainWindow::luaReload(bool)
{
// force a reload of the lua environment
if (m_simulator)
m_simulator->setLuaStateReloadPermanentScripts();
}
void SimulatorMainWindow::openJoystickDialog(bool)
{
#ifdef JOYSTICKS
joystickDialog * jd = new joystickDialog(this);
if (jd->exec() == QDialog::Accepted && m_simulatorWidget)
m_simulatorWidget->setupJoysticks();
jd->deleteLater();
#endif
}
void SimulatorMainWindow::showHelp(bool show)
{
QString helpText = tr("Simulator Controls:");
helpText += "<table cellspacing=4 cellpadding=0>";
helpText += tr("<tr><th>Key/Mouse</td><th>Action</td></tr>");
QString keyTemplate = "<tr><td align='center'><pre>%1</pre></td><td align='center'>%2</td></tr>";
foreach (keymapHelp_t pair, m_keymapHelp)
helpText += keyTemplate.arg(pair.first, pair.second);
helpText += "</table>";
QMessageBox * msgBox = new QMessageBox(this);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setWindowFlags(msgBox->windowFlags() | Qt::WindowStaysOnTopHint);
msgBox->setStandardButtons( QMessageBox::Ok );
msgBox->setWindowTitle(tr("Simulator Help"));
msgBox->setText(helpText);
msgBox->setModal(false);
msgBox->show();
}
@@ -0,0 +1,99 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef SIMULATORMAINWINDOW_H
#define SIMULATORMAINWINDOW_H
#include "simulator.h"
#include <QDockWidget>
#include <QMainWindow>
#include <QPointer>
class DebugOutput;
class RadioData;
class RadioOutputsWidget;
class SimulatorDialog;
class SimulatorInterface;
class TrainerSimulator;
class TelemetrySimulator;
class QKeySequence;
namespace Ui {
class SimulatorMainWindow;
}
using namespace Simulator;
class SimulatorMainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit SimulatorMainWindow(QWidget * parent, SimulatorInterface * simulator, quint8 flags=0, Qt::WindowFlags wflags = Qt::WindowFlags());
~SimulatorMainWindow();
bool setRadioData(RadioData * radioData);
bool useTempDataPath(bool deleteOnClose = true, bool saveOnClose = false);
bool setOptions(SimulatorOptions & options, bool withSave = true);
QMenu * createPopupMenu();
public slots:
void start();
void showRadioTitlebar(bool show);
void toggleMenuBar(bool show);
protected slots:
virtual void closeEvent(QCloseEvent *);
virtual void changeEvent(QEvent *e);
void restoreUiState();
void saveUiState();
void luaReload(bool);
void openJoystickDialog(bool);
void showHelp(bool show);
protected:
void createDockWidgets();
void addTool(QDockWidget * widget, Qt::DockWidgetArea area, QIcon icon = QIcon(), QKeySequence shortcut = QKeySequence());
SimulatorInterface * m_simulator;
Ui::SimulatorMainWindow * ui;
SimulatorDialog * m_simulatorWidget;
DebugOutput * m_consoleWidget;
RadioOutputsWidget * m_outputsWidget;
QDockWidget * m_simulatorDockWidget;
QDockWidget * m_consoleDockWidget;
QDockWidget * m_telemetryDockWidget;
QDockWidget * m_trainerDockWidget;
QDockWidget * m_outputsDockWidget;
QVector<keymapHelp_t> m_keymapHelp;
int m_radioProfileId;
bool m_firstShow;
bool m_showRadioTitlebar;
bool m_showMenubar;
const static quint16 m_savedUiStateVersion;
};
#endif // SIMULATORMAINWINDOW_H
@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SimulatorMainWindow</class>
<widget class="QMainWindow" name="SimulatorMainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>644</width>
<height>371</height>
</rect>
</property>
<property name="windowTitle">
<string>OpenTx Simulator</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<property name="dockNestingEnabled">
<bool>true</bool>
</property>
<property name="dockOptions">
<set>QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks</set>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>644</width>
<height>21</height>
</rect>
</property>
<property name="nativeMenuBar">
<bool>false</bool>
</property>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
</widget>
<widget class="QMenu" name="menuReload">
<property name="title">
<string>Reload...</string>
</property>
<addaction name="actionReloadLua"/>
<addaction name="actionReloadRadioData"/>
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
<string>Tools</string>
</property>
<addaction name="actionScreenshot"/>
<addaction name="actionJoystickSettings"/>
<addaction name="actionShowKeymap"/>
</widget>
<addaction name="menuView"/>
<addaction name="menuReload"/>
<addaction name="menuTools"/>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>Toolbar</string>
</property>
<attribute name="toolBarArea">
<enum>LeftToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionReloadLua"/>
<addaction name="actionReloadRadioData"/>
<addaction name="separator"/>
<addaction name="actionScreenshot"/>
<addaction name="actionJoystickSettings"/>
<addaction name="actionShowKeymap"/>
</widget>
<action name="actionReloadLua">
<property name="icon">
<iconset>
<normaloff>:/images/simulator/icons/svg/reload_script.svg</normaloff>:/images/simulator/icons/svg/reload_script.svg</iconset>
</property>
<property name="text">
<string>Reload Lua Scripts</string>
</property>
<property name="toolTip">
<string>Reload the Lua environment on the simulated radio.</string>
</property>
<property name="shortcut">
<string>F7</string>
</property>
</action>
<action name="actionReloadRadioData">
<property name="icon">
<iconset>
<normaloff>:/images/simulator/icons/svg/restart.svg</normaloff>:/images/simulator/icons/svg/restart.svg</iconset>
</property>
<property name="text">
<string>Reload Radio Data</string>
</property>
<property name="toolTip">
<string>Reload all radio data without restarting the simulator.</string>
</property>
<property name="shortcut">
<string>F9</string>
</property>
</action>
<action name="actionShowKeymap">
<property name="icon">
<iconset>
<normaloff>:/images/simulator/icons/svg/info.svg</normaloff>:/images/simulator/icons/svg/info.svg</iconset>
</property>
<property name="text">
<string>Key Mapping</string>
</property>
<property name="toolTip">
<string>Show keyboard maping reference.</string>
</property>
<property name="shortcut">
<string>F1</string>
</property>
</action>
<action name="actionJoystickSettings">
<property name="icon">
<iconset>
<normaloff>:/images/simulator/icons/svg/joystick_settings.svg</normaloff>:/images/simulator/icons/svg/joystick_settings.svg</iconset>
</property>
<property name="text">
<string>Joystick Settings</string>
</property>
<property name="toolTip">
<string>Open joystick configuration settings dialog.</string>
</property>
<property name="shortcut">
<string>F3</string>
</property>
</action>
<action name="actionScreenshot">
<property name="icon">
<iconset>
<normaloff>:/images/simulator/icons/svg/camera.svg</normaloff>:/images/simulator/icons/svg/camera.svg</iconset>
</property>
<property name="text">
<string>LCD Screenshot</string>
</property>
<property name="toolTip">
<string>Save a screenshot of the current simulated LCD screen.</string>
</property>
<property name="shortcut">
<string>F8</string>
</property>
</action>
<action name="actionToggleRadioTitle">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Radio Titlebar</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The title bar on the main radio window allows you to undock it or move it around separately from the other windows. Hiding the title makes a more compact and streamlined appearance.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</action>
<action name="actionToggleMenuBar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Menu Bar</string>
</property>
<property name="toolTip">
<string>Show or hide the top menu bar.</string>
</property>
<property name="shortcut">
<string>Alt+M</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
@@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>488</width>
<height>219</height>
<width>550</width>
<height>217</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>550</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>OpenTX Simulator - Startup Options</string>
</property>
@@ -22,13 +28,28 @@
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Simulator Startup Options:</string>
</property>
<layout class="QFormLayout" name="layout_options">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="horizontalSpacing">
<number>5</number>
</property>
@@ -56,6 +77,12 @@
</item>
<item row="0" column="1">
<widget class="QComboBox" name="radioProfile">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Existing radio profiles are shown here.&lt;br /&gt;
Create or edit profiles using the Companion application.</string>
@@ -71,6 +98,12 @@ Create or edit profiles using the Companion application.</string>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="radioType">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Existing radio simulators are shown here.&lt;br /&gt;
The radio type specified in the selected profile is used by default.</string>
@@ -107,6 +140,12 @@ The radio type specified in the selected profile is used by default.</string>
</item>
<item row="3" column="1">
<widget class="QWidget" name="wdgt_dataFile" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="layout_dataFile" stretch="1,0">
<property name="spacing">
<number>4</number>
@@ -140,7 +179,7 @@ The radio type specified in the selected profile is used by default.</string>
<string>...</string>
</property>
<property name="icon">
<iconset resource="../companion.qrc">
<iconset>
<normaloff>:/themes/monoblue/16/open.png</normaloff>:/themes/monoblue/16/open.png</iconset>
</property>
<property name="toolButtonStyle">
@@ -153,6 +192,12 @@ The radio type specified in the selected profile is used by default.</string>
</item>
<item row="4" column="1">
<widget class="QWidget" name="wdgt_dataFolder" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="layout_dataFolder" stretch="1,0">
<property name="spacing">
<number>4</number>
@@ -186,7 +231,7 @@ New folder(s) with default radio/model will be created here if necessary.</strin
<string>...</string>
</property>
<property name="icon">
<iconset resource="../companion.qrc">
<iconset>
<normaloff>:/themes/monoblue/16/open.png</normaloff>:/themes/monoblue/16/open.png</iconset>
</property>
<property name="toolButtonStyle">
@@ -199,6 +244,12 @@ New folder(s) with default radio/model will be created here if necessary.</strin
</item>
<item row="5" column="1">
<widget class="QWidget" name="wdgt_sdPath" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="layout_sdPath" stretch="1,0">
<property name="spacing">
<number>4</number>
@@ -232,7 +283,7 @@ The default is configured in the chosen Radio Profile.</string>
<string>...</string>
</property>
<property name="icon">
<iconset resource="../companion.qrc">
<iconset>
<normaloff>:/themes/monoblue/16/open.png</normaloff>:/themes/monoblue/16/open.png</iconset>
</property>
<property name="toolButtonStyle">
@@ -245,6 +296,12 @@ The default is configured in the chosen Radio Profile.</string>
</item>
<item row="2" column="1">
<widget class="QWidget" name="wdgt_dataSource" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Select which of the data sources (File/Folder/SD Card) you would like to start the simulator with.</string>
</property>
@@ -312,9 +369,7 @@ The default is configured in the chosen Radio Profile.</string>
</item>
</layout>
</widget>
<resources>
<include location="../companion.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
+9 -16
View File
@@ -25,24 +25,20 @@
#include "radio/src/telemetry/frsky.h"
TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator):
QDialog(parent),
QWidget(parent),
ui(new Ui::TelemetrySimulator),
simulator(simulator)
{
ui->setupUi(this);
QPoint dialogCenter = mapToGlobal(rect().center());
QPoint parentWindowCenter = parent->window()->mapToGlobal(
parent->window()->rect().center());
move(parentWindowCenter - dialogCenter);
timer = new QTimer(this);
timer->setInterval(10);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent()));
logTimer = new QTimer(this);
connect(logTimer, SIGNAL(timeout()), this, SLOT(onLogTimerEvent()));
connect(ui->Simulate, SIGNAL(clicked(bool)), this, SLOT(onSimulateToggled(bool)));
connect(ui->Simulate, SIGNAL(toggled(bool)), this, SLOT(onSimulateToggled(bool)));
connect(ui->loadLogFile, SIGNAL(released()), this, SLOT(onLoadLogFile()));
connect(ui->play, SIGNAL(released()), this, SLOT(onPlay()));
connect(ui->rewind, SIGNAL(clicked()), this, SLOT(onRewind()));
@@ -76,7 +72,7 @@ TelemetrySimulator::~TelemetrySimulator()
void TelemetrySimulator::onSimulateToggled(bool isChecked)
{
if (isChecked) {
timer->start(10);
timer->start();
}
else {
timer->stop();
@@ -197,9 +193,6 @@ void TelemetrySimulator::showEvent(QShowEvent *event)
ui->rxbt_ratio->setValue(simulator->getSensorRatio(BATT_ID) / 10.0);
ui->A1_ratio->setValue(simulator->getSensorRatio(ADC1_ID) / 10.0);
ui->A2_ratio->setValue(simulator->getSensorRatio(ADC2_ID) / 10.0);
ui->Simulate->setChecked(true);
onSimulateToggled(true); // not sure why this doesn't fire automatically
}
void setSportPacketCrc(uint8_t * packet)
@@ -216,7 +209,7 @@ void setSportPacketCrc(uint8_t * packet)
//TRACE("crc set: %x", packet[FRSKY_SPORT_PACKET_SIZE-1]);
}
uint8_t getBit(uint8_t position, uint8_t value)
uint8_t getBit(uint8_t position, uint8_t value)
{
return (value & (uint8_t)(1 << position)) ? 1 : 0;
}
@@ -224,7 +217,7 @@ uint8_t getBit(uint8_t position, uint8_t value)
bool generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data)
{
if (dataId > 0x1B ) return false;
// generate Data ID field
uint8_t bit5 = getBit(0, dataId) ^ getBit(1, dataId) ^ getBit(2, dataId);
uint8_t bit6 = getBit(2, dataId) ^ getBit(3, dataId) ^ getBit(4, dataId);
@@ -483,7 +476,7 @@ uint32_t TelemetrySimulator::FlvssEmulator::setAllCells_GetNextPair(double cellV
// encode the double values into telemetry format
encodeAllCells();
// return the value for the current pair
// return the value for the current pair
uint32_t cellData = 0;
if (nextCellNum >= numCells) {
nextCellNum = 0;
@@ -644,7 +637,7 @@ TelemetrySimulator::LogPlaybackController::LogPlaybackController(Ui::TelemetrySi
colToFuncMap.insert("AccX(g)", ACCX);
colToFuncMap.insert("AccY(g)", ACCY);
colToFuncMap.insert("AccZ(g)", ACCZ);
// ACCX Y and Z
}
@@ -839,7 +832,7 @@ double TelemetrySimulator::LogPlaybackController::convertDegMin(QString input)
QString TelemetrySimulator::LogPlaybackController::convertGPS(QString input)
{
// input format is DDmm.mmmmH DDDmm.mmmmH (longitude latitude - degrees (2 places) minutes (2 places) decimal minutes (4 places))
// input format is DDmm.mmmmH DDDmm.mmmmH (longitude latitude - degrees (2 places) minutes (2 places) decimal minutes (4 places))
QStringList lonLat = input.simplified().split(' ');
if (lonLat.count() < 2) {
return ""; // invalid format
+128 -122
View File
@@ -22,7 +22,7 @@
#define _TELEMETRYSIMU_H_
#include <QCloseEvent>
#include <QDialog>
#include <QWidget>
#include <QTimer>
#include <QDateTime>
#include <QtCore/qmath.h>
@@ -37,102 +37,19 @@ namespace Ui {
class TelemetrySimulator;
}
class TelemetrySimulator : public QDialog
class TelemetrySimulator : public QWidget
{
Q_OBJECT
public:
explicit TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator);
virtual ~TelemetrySimulator();
protected:
protected slots:
virtual void closeEvent(QCloseEvent *event);
virtual void showEvent(QShowEvent *event);
private:
class LogPlaybackController
{
public:
LogPlaybackController(Ui::TelemetrySimulator * ui);
bool isReady();
void loadLogFile();
void play();
void stop();
void rewind();
void stepForward(bool focusOnStop);
void stepBack();
void updatePositionLabel(int32_t percentage);
void setUiDataValues();
double logFrequency; // in seconds
private:
enum CONVERT_TYPE {
RXBT_V,
RSSI,
SWR,
A1,
A2,
A3,
A4,
T1_DEGC,
T1_DEGF,
T2_DEGC,
T2_DEGF,
RPM,
FUEL,
VSPD_MS,
VSPD_FS,
ALT_FEET,
ALT_METERS,
FASV,
FASC,
CELS_GRE,
ASPD_KTS,
ASPD_KMH,
ASPD_MPH,
GALT_FEET,
GALT_METERS,
GSPD_KNTS,
GSPD_KMH,
GSPD_MPH,
GHDG_DEG,
GDATE,
G_LATLON,
ACCX,
ACCY,
ACCZ,
FUEL_QTY,
};
QMap<QString, CONVERT_TYPE> colToFuncMap; // contains all 'known' column headings and how they are to be processed
Ui::TelemetrySimulator * ui;
struct DATA_TO_FUNC_XREF {
CONVERT_TYPE functionIndex;
int32_t dataIndex;
};
QStringList csvRecords; // contents of the log file (one string per line);
QStringList columnNames;
QList<DATA_TO_FUNC_XREF> supportedCols;
int32_t recordIndex;
double convertFeetToMeters(QString input);
double convertFahrenheitToCelsius(QString input);
QString convertGPSDate(QString input);
QString convertGPS(QString input);
void addColumnHash(QString key, CONVERT_TYPE functionIndex);
double convertDegMin(QString input);
bool stepping;
QDateTime parseTransmittterTimestamp(QString row);
void calcLogFrequency();
};
private:
Ui::TelemetrySimulator * ui;
QTimer * timer;
QTimer * logTimer;
SimulatorInterface *simulator;
void generateTelemetryFrame();
TelemetrySimulator::LogPlaybackController *logPlayback;
private slots:
void onSimulateToggled(bool isChecked);
void onTimerEvent();
void onLogTimerEvent();
@@ -145,49 +62,138 @@ private:
void onPositionIndicatorChanged(int value);
void onReplayRateChanged(int value);
protected:
Ui::TelemetrySimulator * ui;
QTimer * timer;
QTimer * logTimer;
SimulatorInterface *simulator;
void generateTelemetryFrame();
// protected classes follow
class LogPlaybackController
{
public:
LogPlaybackController(Ui::TelemetrySimulator * ui);
bool isReady();
void loadLogFile();
void play();
void stop();
void rewind();
void stepForward(bool focusOnStop);
void stepBack();
void updatePositionLabel(int32_t percentage);
void setUiDataValues();
double logFrequency; // in seconds
private:
enum CONVERT_TYPE {
RXBT_V,
RSSI,
SWR,
A1,
A2,
A3,
A4,
T1_DEGC,
T1_DEGF,
T2_DEGC,
T2_DEGF,
RPM,
FUEL,
VSPD_MS,
VSPD_FS,
ALT_FEET,
ALT_METERS,
FASV,
FASC,
CELS_GRE,
ASPD_KTS,
ASPD_KMH,
ASPD_MPH,
GALT_FEET,
GALT_METERS,
GSPD_KNTS,
GSPD_KMH,
GSPD_MPH,
GHDG_DEG,
GDATE,
G_LATLON,
ACCX,
ACCY,
ACCZ,
FUEL_QTY,
};
struct DATA_TO_FUNC_XREF {
CONVERT_TYPE functionIndex;
int32_t dataIndex;
};
double convertFeetToMeters(QString input);
double convertFahrenheitToCelsius(QString input);
QString convertGPSDate(QString input);
QString convertGPS(QString input);
void addColumnHash(QString key, CONVERT_TYPE functionIndex);
double convertDegMin(QString input);
QDateTime parseTransmittterTimestamp(QString row);
void calcLogFrequency();
QMap<QString, CONVERT_TYPE> colToFuncMap; // contains all 'known' column headings and how they are to be processed
Ui::TelemetrySimulator * ui;
QStringList csvRecords; // contents of the log file (one string per line);
QStringList columnNames;
QList<DATA_TO_FUNC_XREF> supportedCols;
int32_t recordIndex;
bool stepping;
}; // LogPlaybackController
LogPlaybackController *logPlayback;
private: // private classes follow
class FlvssEmulator
{
public:
public:
uint32_t setAllCells_GetNextPair(double cellValues[6]);
static const uint32_t MAXCELLS = 6;
private:
void encodeAllCells();
void splitIntoCells(double totalVolts);
static uint32_t encodeCellPair(uint8_t cellNum, uint8_t firstCellNo, double cell1, double cell2);
double cellFloats[6];
uint32_t nextCellNum;
uint32_t numCells;
uint32_t cellData1;
uint32_t cellData2;
uint32_t cellData3;
};
private:
void encodeAllCells();
void splitIntoCells(double totalVolts);
static uint32_t encodeCellPair(uint8_t cellNum, uint8_t firstCellNo, double cell1, double cell2);
double cellFloats[6];
uint32_t nextCellNum;
uint32_t numCells;
uint32_t cellData1;
uint32_t cellData2;
uint32_t cellData3;
}; // FlvssEmulator
class GPSEmulator
{
public:
GPSEmulator();
uint32_t getNextPacketData(uint32_t packetType);
void setGPSDateTime(QString dateTime);
void setGPSLatLon(QString latLon);
void setGPSCourse(double course);
void setGPSSpeedKMH(double speed);
void setGPSAltitude(double altitude);
private:
QDateTime dt;
bool sendLat;
bool sendDate;
double lat;
double lon;
double course;
double speedKNTS;
double altitude; // in meters
uint32_t encodeLatLon(double latLon, bool isLat);
uint32_t encodeDateTime(uint8_t yearOrHour, uint8_t monthOrMinute, uint8_t dayOrSecond, bool isDate);
};
public:
GPSEmulator();
uint32_t getNextPacketData(uint32_t packetType);
void setGPSDateTime(QString dateTime);
void setGPSLatLon(QString latLon);
void setGPSCourse(double course);
void setGPSSpeedKMH(double speed);
void setGPSAltitude(double altitude);
};
private:
QDateTime dt;
bool sendLat;
bool sendDate;
double lat;
double lon;
double course;
double speedKNTS;
double altitude; // in meters
uint32_t encodeLatLon(double latLon, bool isLat);
uint32_t encodeDateTime(uint8_t yearOrHour, uint8_t monthOrMinute, uint8_t dayOrSecond, bool isDate);
}; // GPSEmulator
}; // TelemetrySimulator
#endif // _TELEMETRYSIMU_H_
File diff suppressed because it is too large Load Diff
+35 -78
View File
@@ -22,37 +22,45 @@
#include "trainersimu.h"
#include "ui_trainersimu.h"
#include "helpers.h"
#define GBALL_SIZE 20
#define RESX 512
#include "virtualjoystickwidget.h"
TrainerSimulator::TrainerSimulator(QWidget * parent, SimulatorInterface * simulator):
QDialog(parent),
QWidget(parent),
ui(new Ui::TrainerSimulator),
simulator(simulator)
{
ui->setupUi(this);
leftStick = ui->leftStick;
rightStick = ui->rightStick;
setupSticks();
vJoyLeft = new VirtualJoystickWidget(this, 'L', false);
vJoyLeft->setStickColor(Qt::cyan);
ui->leftStickLayout->addWidget(vJoyLeft);
// resize(0, 0); // to force min height, min width
setFixedSize(width(), height());
vJoyRight = new VirtualJoystickWidget(this, 'R', false);
vJoyRight->setStickColor(Qt::cyan);
ui->rightStickLayout->addWidget(vJoyRight);
timer = new QTimer(this);
timer->setInterval(10);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent()));
}
TrainerSimulator::~TrainerSimulator()
{
timer->stop();
if (timer) {
timer->stop();
delete timer;
}
if (vJoyLeft)
delete vJoyLeft;
if (vJoyRight)
delete vJoyRight;
delete ui;
}
void TrainerSimulator::showEvent(QShowEvent *event)
{
timer->start(10);
timer->start();
event->accept();
}
@@ -64,71 +72,13 @@ void TrainerSimulator::closeEvent(QCloseEvent *event)
void TrainerSimulator::centerSticks()
{
if (leftStick->scene())
nodeLeft->stepToCenter();
if (vJoyLeft)
vJoyLeft->centerStick();
if (rightStick->scene())
nodeRight->stepToCenter();
if (vJoyRight)
vJoyRight->centerStick();
}
void TrainerSimulator::setupSticks()
{
QGraphicsScene *leftScene = new QGraphicsScene(leftStick);
leftScene->setItemIndexMethod(QGraphicsScene::NoIndex);
leftStick->setScene(leftScene);
// leftStick->scene()->addLine(0,10,20,30);
QGraphicsScene *rightScene = new QGraphicsScene(rightStick);
rightScene->setItemIndexMethod(QGraphicsScene::NoIndex);
rightStick->setScene(rightScene);
// rightStick->scene()->addLine(0,10,20,30);
nodeLeft = new Node();
nodeLeft->setPos(-GBALL_SIZE/2,-GBALL_SIZE/2);
nodeLeft->setBallSize(GBALL_SIZE);
leftScene->addItem(nodeLeft);
nodeRight = new Node();
nodeRight->setPos(-GBALL_SIZE/2,-GBALL_SIZE/2);
nodeRight->setBallSize(GBALL_SIZE);
rightScene->addItem(nodeRight);
}
void TrainerSimulator::resizeEvent(QResizeEvent *event)
{
if (leftStick->scene()) {
QRect qr = leftStick->contentsRect();
qreal w = (qreal)qr.width() - GBALL_SIZE;
qreal h = (qreal)qr.height() - GBALL_SIZE;
qreal cx = (qreal)qr.width()/2;
qreal cy = (qreal)qr.height()/2;
leftStick->scene()->setSceneRect(-cx,-cy,w,h);
QPointF p = nodeLeft->pos();
p.setX(qMin(cx, qMax(p.x(), -cx)));
p.setY(qMin(cy, qMax(p.y(), -cy)));
nodeLeft->setPos(p);
}
if (rightStick->scene()) {
QRect qr = rightStick->contentsRect();
qreal w = (qreal)qr.width() - GBALL_SIZE;
qreal h = (qreal)qr.height() - GBALL_SIZE;
qreal cx = (qreal)qr.width()/2;
qreal cy = (qreal)qr.height()/2;
rightStick->scene()->setSceneRect(-cx,-cy,w,h);
QPointF p = nodeRight->pos();
p.setX(qMin(cx, qMax(p.x(), -cx)));
p.setY(qMin(cy, qMax(p.y(), -cy)));
nodeRight->setPos(p);
}
QDialog::resizeEvent(event);
}
void TrainerSimulator::onTimerEvent()
{
centerSticks();
@@ -137,8 +87,15 @@ void TrainerSimulator::onTimerEvent()
void TrainerSimulator::setTrainerInputs()
{
simulator->setTrainerInput(0, int( 512* nodeLeft->getX())); // LEFT HORZ
simulator->setTrainerInput(1, int(-512* nodeLeft->getY())); // LEFT VERT
simulator->setTrainerInput(2, int(-512*nodeRight->getY())); // RGHT VERT
simulator->setTrainerInput(3, int( 512*nodeRight->getX())); // RGHT HORZ
}
if (!simulator)
return;
if (vJoyLeft) {
simulator->setTrainerInput(0, int( 512 * vJoyLeft->getStickX())); // LEFT HORZ
simulator->setTrainerInput(1, int(-512 * vJoyLeft->getStickY())); // LEFT VERT
}
if (vJoyRight) {
simulator->setTrainerInput(2, int(-512 * vJoyRight->getStickY())); // RGHT VERT
simulator->setTrainerInput(3, int( 512 * vJoyRight->getStickX())); // RGHT HORZ
}
}
+10 -16
View File
@@ -24,17 +24,17 @@
#include <QShowEvent>
#include <QCloseEvent>
#include <QDialog>
#include <QWidget>
#include <QTimer>
#include "modeledit/node.h"
#include "simulatorinterface.h"
namespace Ui {
class TrainerSimulator;
}
class VirtualJoystickWidget;
class TrainerSimulator : public QDialog
class TrainerSimulator : public QWidget
{
Q_OBJECT
@@ -43,26 +43,20 @@ class TrainerSimulator : public QDialog
virtual ~TrainerSimulator();
protected:
protected slots:
virtual void showEvent(QShowEvent *event);
virtual void closeEvent(QCloseEvent *event);
void centerSticks();
void setTrainerInputs();
void onTimerEvent();
private:
protected:
Ui::TrainerSimulator * ui;
QTimer * timer;
SimulatorInterface *simulator;
QGraphicsView * leftStick, * rightStick;
Node *nodeLeft;
Node *nodeRight;
void centerSticks();
void setupSticks();
void resizeEvent(QResizeEvent *event = 0);
void setTrainerInputs();
private slots:
void onTimerEvent();
VirtualJoystickWidget * vJoyLeft;
VirtualJoystickWidget * vJoyRight;
};
+50 -74
View File
@@ -1,94 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TrainerSimulator</class>
<widget class="QDialog" name="TrainerSimulator">
<widget class="QWidget" name="TrainerSimulator">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<height>268</height>
<width>385</width>
<height>187</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Trainer simulator</string>
</property>
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>563</width>
<height>267</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>5</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>15</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="leftStickLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</layout>
</item>
<item row="0" column="2">
<widget class="QGraphicsView" name="rightStick">
<property name="minimumSize">
<size>
<width>245</width>
<height>245</height>
</size>
<item>
<layout class="QHBoxLayout" name="rightStickLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QGraphicsView" name="leftStick">
<property name="minimumSize">
<size>
<width>245</width>
<height>245</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
@@ -47,7 +47,7 @@ class RadioFaderWidget : public RadioWidget
SliderWidget * sl = new SliderWidget(this);
sl->setOrientation(Qt::Vertical);
sl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
sl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
sl->setMinimumHeight(75);
//sl->setMaximumHeight(75);
sl->setTickPosition(QSlider::TicksBothSides);
@@ -23,6 +23,7 @@
#include "radiowidget.h"
#include "boards.h"
#include "simulator.h"
#include <QSlider>
#include <QTimer>
@@ -65,11 +66,8 @@ class RadioSwitchWidget : public RadioWidget
m_slider->setValue(m_value);
if (swType == Board::SWITCH_TOGGLE) {
QIcon icon;
icon.addFile(QStringLiteral(":/images/simulator/icons/8/lock-locked.png"), QSize(8, 8), QIcon::Normal, QIcon::On);
icon.addFile(QStringLiteral(":/images/simulator/icons/8/lock-unlocked.png"), QSize(8, 8), QIcon::Normal, QIcon::Off);
QToolButton * lockBtn = new QToolButton(this);
lockBtn->setIcon(icon);
lockBtn->setIcon(Simulator::SimulatorIcon("toggle_lock"));
lockBtn->setIconSize(QSize(8, 8));
lockBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
lockBtn->setToolButtonStyle(Qt::ToolButtonIconOnly);
@@ -78,7 +76,7 @@ class RadioSwitchWidget : public RadioWidget
lockBtn->setToolTip(tr("Latch/unlatch the momentary switch."));
QWidget * container = new QWidget(this);
container->setFixedHeight(50);
container->setFixedHeight(56);
container->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
QVBoxLayout * cl = new QVBoxLayout(container);
cl->setContentsMargins(0, 0, 0, 0);
@@ -94,7 +92,7 @@ class RadioSwitchWidget : public RadioWidget
connect(this, &RadioWidget::flagsChanged, lockBtn, &QToolButton::setChecked);
}
else {
m_slider->setFixedHeight(50);
m_slider->setFixedHeight(56);
setWidget(m_slider);
}
@@ -18,6 +18,9 @@
* GNU General Public License for more details.
*/
#define GBALL_SIZE 20
#define RESX 1024
#include "virtualjoystickwidget.h"
#include "constants.h"
#include "sliderwidget.h"
@@ -50,7 +53,9 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
gv = new QGraphicsView(this);
gv->setSizePolicy(sizePolicy);
gv->setMinimumSize(QSize(150, 150));
gv->setMinimumSize(size);
// gv->setMaximumSize(size + size * 3);
// gv->setFixedSize(prefSize);
gv->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
gv->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -88,6 +93,9 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
vTrimSlider = vTrimWidget->findChild<SliderWidget *>();
extraSize += QSize(vTrimWidget->sizeHint().width(), hTrimWidget->sizeHint().height());
}
else {
colvx = colvy = colvt;
}
if (showBtns) {
QVBoxLayout * btnbox = new QVBoxLayout();
@@ -106,8 +114,17 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
if (showValues) {
QLayout * valX = createNodeValueLayout('X', nodeLabelX);
QLayout * valY = createNodeValueLayout('Y', nodeLabelY);
layout->addLayout(valX, 2, colvx, 1, 1);
layout->addLayout(valY, 2, colvy, 1, 1);
if (!showTrims) {
QVBoxLayout * vertXY = new QVBoxLayout();
vertXY->addLayout(valX);
vertXY->addLayout(valY);
layout->addLayout(vertXY, 1, colvx, 1, 1);
extraSize += QSize(nodeLabelX->sizeHint().width(), 0);
}
else {
layout->addLayout(valX, 2, colvx, 1, 1);
layout->addLayout(valY, 2, colvy, 1, 1);
}
}
layout->addItem(new QSpacerItem(0, 0), 0, 0, 1, 5); // r0 c0-4: top v spacer
@@ -119,7 +136,7 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
connect(node, SIGNAL(xChanged()), this, SLOT(updateNodeValueLabels()));
connect(node, SIGNAL(yChanged()), this, SLOT(updateNodeValueLabels()));
setSize(prefSize);
setSize(prefSize, frameSize());
}
void VirtualJoystickWidget::setStickX(qreal x)
@@ -144,12 +161,12 @@ void VirtualJoystickWidget::centerStick()
qreal VirtualJoystickWidget::getStickX()
{
return node->getX();
return getStickPos().x();
}
qreal VirtualJoystickWidget::getStickY()
{
return node->getY();
return getStickPos().y();
}
QPointF VirtualJoystickWidget::getStickPos()
@@ -205,7 +222,22 @@ void VirtualJoystickWidget::setStickConstraint(int which, bool active)
}
}
void VirtualJoystickWidget::setSize(QSize size)
void VirtualJoystickWidget::setStickColor(const QColor & color)
{
node->setColor(color);
}
QSize VirtualJoystickWidget::sizeHint() const {
return prefSize;
}
void VirtualJoystickWidget::resizeEvent(QResizeEvent * event)
{
QWidget::resizeEvent(event);
setSize(event->size(), event->oldSize());
}
void VirtualJoystickWidget::setSize(const QSize & size, const QSize &)
{
float thisAspectRatio = (float)size.width() / size.height();
float newGvSz, spacerSz;
@@ -237,28 +269,24 @@ void VirtualJoystickWidget::setSize(QSize size)
layout->setColumnStretch(2, newGvSz);
layout->setRowStretch(1, newGvSz);
prefSize = QSize(newGvSz + extraSize.width(), newGvSz + extraSize.height());
//prefSize = QSize(newGvSz + extraSize.width(), newGvSz + extraSize.height());
gv->resize(newGvSz, newGvSz);
gv->updateGeometry();
repositionNode();
//qDebug() << thisAspectRatio << size << newGvSz << spacerSz << extraSize << gv->geometry() << gv->contentsRect() << gv->frameRect() << getStickPos();
}
void VirtualJoystickWidget::repositionNode()
{
QRect qr = gv->contentsRect();
qreal w = (qreal)qr.width() - GBALL_SIZE;
qreal h = (qreal)qr.height() - GBALL_SIZE;
qreal cx = (qreal)qr.width()/2;
qreal cy = (qreal)qr.height()/2;
QRectF qr = (QRectF)gv->contentsRect();
qreal w = qr.width() - GBALL_SIZE;
qreal h = qr.height() - GBALL_SIZE;
qreal cx = qr.width() / 2;
qreal cy = qr.height() / 2;
qreal nodeX = node->getX();
qreal nodeY = node->getY();
scene->setSceneRect(-cx,-cy,w,h);
QPointF p = node->pos();
p.setX(qMin(cx, qMax(p.x(), -cx)));
p.setY(qMin(cy, qMax(p.y(), -cy)));
node->setPos(p);
node->setX(nodeX);
node->setY(nodeY);
updateNodeValueLabels();
//qDebug() << thisAspectRatio << size << newGvSz << spacerSz << extraSize << gv->geometry() << gv->contentsRect() << gv->frameRect() << getStickPos();
}
QWidget *VirtualJoystickWidget::createTrimWidget(QChar type)
@@ -382,6 +410,7 @@ QLayout *VirtualJoystickWidget::createNodeValueLayout(QChar type, QLabel *& valL
val->setObjectName(QString("val_%1").arg(type));
val->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
val->setAlignment(Qt::AlignCenter);
val->setMinimumWidth(val->fontMetrics().width("-100 "));
QVBoxLayout * layout = new QVBoxLayout();
layout->setContentsMargins(2, 2, 2, 2);
layout->setSpacing(2);
@@ -33,9 +33,6 @@
class Node;
class SliderWidget;
#define GBALL_SIZE 20
#define RESX 1024
class VirtualJoystickWidget : public QWidget
{
Q_OBJECT
@@ -55,7 +52,7 @@ class VirtualJoystickWidget : public QWidget
FIX_Y
};
explicit VirtualJoystickWidget(QWidget * parent = NULL, QChar side = 'L', bool showTrims = true, bool showBtns = true, bool showValues = true, QSize size = QSize(245, 245));
explicit VirtualJoystickWidget(QWidget * parent = NULL, QChar side = 'L', bool showTrims = true, bool showBtns = true, bool showValues = true, QSize size = QSize(125, 125));
void setStickX(qreal x);
void setStickY(qreal y);
@@ -70,17 +67,10 @@ class VirtualJoystickWidget : public QWidget
int getTrimValue(int which);
void setStickConstraint(int which, bool active);
void setStickColor(const QColor & color);
virtual QSize sizeHint() const
{
return prefSize;
}
virtual void resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
setSize(event->size());
}
virtual QSize sizeHint() const;
virtual void resizeEvent(QResizeEvent *event);
signals:
void trimButtonPressed(int which);
@@ -94,8 +84,7 @@ class VirtualJoystickWidget : public QWidget
void updateNodeValueLabels();
protected:
void setSize(QSize size);
void repositionNode();
void setSize(const QSize & size, const QSize &);
QWidget * createTrimWidget(QChar type);
QPushButton * createButtonWidget(int type);
QLayout * createNodeValueLayout(QChar type, QLabel *& valLabel);