[Simulator] Asynchronous SimulatorInterface & a few new features. (#4738)
[opentx.git] / companion / src / simulation / simulateduiwidget9X.cpp
blobdaa809a2066f5925388949050e7ff203ef33d04f
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "simulateduiwidget.h"
22 #include "ui_simulateduiwidget9X.h"
23 #include "eeprominterface.h"
25 SimulatedUIWidget9X::SimulatedUIWidget9X(SimulatorInterface * simulator, QWidget * parent):
26 SimulatedUIWidget(simulator, parent),
27 ui(new Ui::SimulatedUIWidget9X)
29 RadioUiAction * act;
30 QPolygon polygon;
32 ui->setupUi(this);
34 bool hasRotEnc = getCurrentFirmware()->getCapability(Capability::RotaryEncoders);
36 // add actions in order of appearance on the help menu
38 int x = 68, y = 91, oR = 63;
40 polygon << QPoint(x, y) << polyArc(x, y, oR, -45, 45);
41 act = new RadioUiAction(3, QList<int>() << Qt::Key_Up << Qt::Key_PageUp, tr(SIMU_STR_HLP_KEYS_GO_UP) % (hasRotEnc ? "" : tr("|" SIMU_STR_HLP_MOUSE_UP)), tr(SIMU_STR_HLP_ACT_UP));
42 addRadioWidget(ui->leftbuttons->addArea(polygon, "9X/9xcursup.png", act));
44 polygon.clear();
45 polygon << QPoint(x, y) << polyArc(x, y, oR, 135, 225);
46 act = new RadioUiAction(2, QList<int>() << Qt::Key_Down << Qt::Key_PageDown, tr(SIMU_STR_HLP_KEYS_GO_DN) % (hasRotEnc ? "" : tr("|" SIMU_STR_HLP_MOUSE_DN)), tr(SIMU_STR_HLP_ACT_DN));
47 addRadioWidget(ui->leftbuttons->addArea(polygon, "9X/9xcursdown.png", act));
49 polygon.clear();
50 polygon << QPoint(x, y) << polyArc(x, y, oR, 45, 135);
51 act = new RadioUiAction(4, QList<int>() << Qt::Key_Right << Qt::Key_Minus, tr(SIMU_STR_HLP_KEY_RGT "|" SIMU_STR_HLP_KEY_MIN), tr(SIMU_STR_HLP_ACT_MIN));
52 addRadioWidget(ui->leftbuttons->addArea(polygon, "9X/9xcursmin.png", act));
54 polygon.clear();
55 polygon << QPoint(x, y) << polyArc(x, y, oR, 225, 315);
56 act = new RadioUiAction(5, QList<int>() << Qt::Key_Left << Qt::Key_Plus << Qt::Key_Equal, tr(SIMU_STR_HLP_KEY_LFT "|" SIMU_STR_HLP_KEY_PLS), tr(SIMU_STR_HLP_ACT_PLS));
57 addRadioWidget(ui->leftbuttons->addArea(polygon, "9X/9xcursplus.png", act));
59 act = new RadioUiAction(0, QList<int>() << Qt::Key_Enter << Qt::Key_Return, tr(SIMU_STR_HLP_KEY_ENTER), tr(SIMU_STR_HLP_ACT_MENU));
60 addRadioWidget(ui->rightbuttons->addArea(QRect(16, 54, 60, 34), "9X/9xmenumenu.png", act));
62 if (!hasRotEnc) {
63 m_mouseMidClickAction = act;
64 m_mouseMidClickAction->setText(act->getText() % "|" SIMU_STR_HLP_MOUSE_MID);
67 act = new RadioUiAction(1, QList<int>() << Qt::Key_Delete << Qt::Key_Escape << Qt::Key_Backspace, tr(SIMU_STR_HLP_KEYS_EXIT), tr(SIMU_STR_HLP_ACT_EXIT));
68 addRadioWidget(ui->rightbuttons->addArea(QRect(16, 114, 60, 34), "9X/9xmenuexit.png", act));
70 addRadioWidget(ui->leftbuttons->addArea(QRect(6, 149, 30, 30), "9X/9xcursphoto.png", m_screenshotAction));
72 if (hasRotEnc) {
73 addRadioAction(new RadioUiAction(-1, 0, tr(SIMU_STR_HLP_MOUSE_SCRL), tr(SIMU_STR_HLP_ROTENC " " SIMU_STR_HLP_ROTENC_LR)));
74 m_mouseMidClickAction = new RadioUiAction(14, Qt::Key_Insert, tr(SIMU_STR_HLP_KEY_INS "|" SIMU_STR_HLP_MOUSE_MID), tr(SIMU_STR_HLP_ACT_ROT_DN));
75 addRadioWidget(ui->leftbuttons->addArea(QRect(0, 0, 0, 0), "9X/9xcurs.png", m_mouseMidClickAction));
78 m_backlightColors << QColor(159,165,247);
79 m_backlightColors << QColor(166,247,159);
80 m_backlightColors << QColor(247,159,166);
81 m_backlightColors << QColor(255,195,151);
82 m_backlightColors << QColor(247,242,159);
84 setLcd(ui->lcd);
87 SimulatedUIWidget9X::~SimulatedUIWidget9X()
89 delete ui;
92 void SimulatedUIWidget9X::setLightOn(bool enable)
94 static QStringList list = QStringList() << "bl" << "gr" << "rd" << "or" << "yl";
95 static QString bgfmt = "background:url(:/images/simulator/9X/9xd%1%2.png);";
96 QString bg = "";
97 if (enable && (int)m_backLight < list.size()) {
98 bg = "-" + list[m_backLight];
100 ui->top->setStyleSheet(bgfmt.arg("t").arg(bg));
101 ui->bottom->setStyleSheet(bgfmt.arg("b").arg(bg));
102 ui->left->setStyleSheet(bgfmt.arg("l").arg(bg));
103 ui->right->setStyleSheet(bgfmt.arg("r").arg(bg));