chore(cpn): generic simulator (#5692)
This commit is contained in:
@@ -26,10 +26,14 @@
|
||||
#include "radiokeywidget.h"
|
||||
#include "simulatorinterface.h"
|
||||
#include "buttonswidget.h"
|
||||
#include "appdata.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
constexpr int BUTTON_WIDTH {65};
|
||||
constexpr int BUTTON_HEIGHT {30};
|
||||
|
||||
//#define FLASH_DURATION 10
|
||||
//#define CBEEP_ON "QLabel { background-color: #FF364E }"
|
||||
//#define CBEEP_OFF "QLabel { }"
|
||||
@@ -195,11 +199,10 @@ void SimulatedUIWidget::mouseReleaseEvent(QMouseEvent * event)
|
||||
void SimulatedUIWidget::setLcd(LcdWidget * lcd)
|
||||
{
|
||||
m_lcd = lcd;
|
||||
Board::Type board = getCurrentBoard();
|
||||
|
||||
auto width = Boards::getCapability(board, Board::LcdWidth);
|
||||
auto height = Boards::getCapability(board, Board::LcdHeight);
|
||||
auto depth = Boards::getCapability(board, Board::LcdDepth);
|
||||
auto width = Boards::getCapability(m_board, Board::LcdWidth);
|
||||
auto height = Boards::getCapability(m_board, Board::LcdHeight);
|
||||
auto depth = Boards::getCapability(m_board, Board::LcdDepth);
|
||||
m_lcd->setData(width, height, depth);
|
||||
|
||||
if (!m_backlightColors.size())
|
||||
@@ -235,6 +238,7 @@ void SimulatedUIWidget::connectScrollActions()
|
||||
// static
|
||||
int SimulatedUIWidget::strKeyToInt(std::string key)
|
||||
{
|
||||
// MUST be kept in sync with EnumKeys
|
||||
QStringList keys = {
|
||||
"KEY_MENU",
|
||||
"KEY_EXIT",
|
||||
@@ -257,115 +261,203 @@ int SimulatedUIWidget::strKeyToInt(std::string key)
|
||||
return keys.indexOf(key.c_str());
|
||||
}
|
||||
|
||||
// Notes: unused rows will be hidden and squashed
|
||||
static const QList<RadioKeyDefinition> radioKeyDefinitions = {
|
||||
{ KEY_SYS, 'L', 0, QList<int>() << Qt::Key_S, SIMU_STR_HLP_KEY_S, SIMU_STR_HLP_ACT_SYS },
|
||||
|
||||
{ KEY_MODEL, 'R', 0, QList<int>() << Qt::Key_M, SIMU_STR_HLP_KEY_M, SIMU_STR_HLP_ACT_MDL },
|
||||
|
||||
{ KEY_PAGEUP, 'L', 1, QList<int>() << Qt::Key_PageUp, SIMU_STR_HLP_KEY_PGUP, SIMU_STR_HLP_ACT_PGUP },
|
||||
|
||||
{ KEY_PAGEDN, 'R', 1, QList<int>() << Qt::Key_PageDown, SIMU_STR_HLP_KEY_PGDN, SIMU_STR_HLP_ACT_PGDN },
|
||||
|
||||
{ KEY_UP, 'L', 2, QList<int>() << Qt::Key_Up, SIMU_STR_HLP_KEY_UP, SIMU_STR_HLP_ACT_UP },
|
||||
|
||||
{ KEY_DOWN, 'R', 2, QList<int>() << Qt::Key_Down, SIMU_STR_HLP_KEY_DN, SIMU_STR_HLP_ACT_DOWN },
|
||||
|
||||
{ KEY_LEFT, 'L', 3, QList<int>() << Qt::Key_Left, SIMU_STR_HLP_KEY_LFT, SIMU_STR_HLP_ACT_LFT },
|
||||
|
||||
{ KEY_RIGHT, 'R', 3, QList<int>() << Qt::Key_Right, SIMU_STR_HLP_KEY_RGT, SIMU_STR_HLP_ACT_RGT },
|
||||
|
||||
{ KEY_MINUS, 'L', 4, QList<int>() << Qt::Key_Minus, SIMU_STR_HLP_KEY_MIN, SIMU_STR_HLP_ACT_MIN },
|
||||
|
||||
{ KEY_PLUS, 'R', 4, QList<int>() << Qt::Key_Plus, SIMU_STR_HLP_KEY_PLS, SIMU_STR_HLP_ACT_PLS },
|
||||
|
||||
{ KEY_TELE, 'R', 5, QList<int>() << Qt::Key_T, SIMU_STR_HLP_KEY_T, SIMU_STR_HLP_ACT_TELE },
|
||||
|
||||
{ KEY_MENU, 'L', 6, QList<int>() << Qt::Key_Equal, SIMU_STR_HLP_KEY_EQL, SIMU_STR_HLP_ACT_MENU },
|
||||
|
||||
{ KEY_SHIFT, 'R', 6, QList<int>() << Qt::Key_Insert, SIMU_STR_HLP_KEY_INS, SIMU_STR_HLP_ACT_SHIFT },
|
||||
|
||||
{ KEY_EXIT, 'L', 7, QList<int>() << Qt::Key_Escape
|
||||
<< Qt::Key_Backspace, SIMU_STR_HLP_KEYS_EXIT, SIMU_STR_HLP_ACT_EXIT },
|
||||
|
||||
{ KEY_ENTER, 'R', 7, QList<int>() << Qt::Key_Enter
|
||||
<< Qt::Key_Return, SIMU_STR_HLP_KEYS_ENTER, SIMU_STR_HLP_ACT_ENTER },
|
||||
|
||||
// keep these on the last row
|
||||
{ KEY_SCRLUP, 'L', 8, QList<int>() << Qt::Key_Comma, SIMU_STR_HLP_KEYS_SCRLUP, SIMU_STR_HLP_ACT_ROT_LFT },
|
||||
|
||||
{ KEY_SCRLDN, 'R', 8, QList<int>() << Qt::Key_Period, SIMU_STR_HLP_KEYS_SCRLDN, SIMU_STR_HLP_ACT_ROT_RGT },
|
||||
};
|
||||
|
||||
void SimulatedUIWidget::addScrollActions()
|
||||
{
|
||||
// Note: the keys cannot duplicate those used for radio buttons
|
||||
m_scrollUpAction = new RadioUiAction(-1, QList<int>() << Qt::Key_Minus,
|
||||
SIMU_STR_HLP_KEY_MIN % "|" % SIMU_STR_HLP_MOUSE_UP, SIMU_STR_HLP_ACT_ROT_LFT);
|
||||
m_scrollDnAction = new RadioUiAction(-1, QList<int>() << Qt::Key_Plus << Qt::Key_Equal,
|
||||
SIMU_STR_HLP_KEY_PLS % "|" % SIMU_STR_HLP_MOUSE_DN, SIMU_STR_HLP_ACT_ROT_RGT);
|
||||
if (g.simuScrollButtons() || !getCurrentFirmware()->getCapability(RotaryEncoderNavigation))
|
||||
return;
|
||||
|
||||
const RadioKeyDefinition *updefn = getRadioKeyDefinition(KEY_SCRLUP);
|
||||
if (updefn)
|
||||
m_scrollUpAction = new RadioUiAction(-2, updefn->keys, updefn->helpKeys, updefn->helpActions);
|
||||
|
||||
const RadioKeyDefinition *downdefn = getRadioKeyDefinition(KEY_SCRLDN);
|
||||
if (downdefn)
|
||||
m_scrollDnAction = new RadioUiAction(-3, downdefn->keys, downdefn->helpKeys, downdefn->helpActions);
|
||||
|
||||
connectScrollActions();
|
||||
}
|
||||
|
||||
void SimulatedUIWidget::addMouseActions()
|
||||
{
|
||||
m_mouseMidClickAction = new RadioUiAction(KEY_ENTER, QList<int>() << Qt::Key_Enter << Qt::Key_Return,
|
||||
SIMU_STR_HLP_KEYS_ACTIVATE, SIMU_STR_HLP_ACT_ROT_DN);
|
||||
const RadioKeyDefinition *defn = getRadioKeyDefinition(KEY_ENTER);
|
||||
if (defn)
|
||||
m_mouseMidClickAction = new RadioUiAction(defn->index, defn->keys, defn->helpKeys, defn->helpActions);
|
||||
}
|
||||
|
||||
// Notes: unused rows will be hidden and squashed
|
||||
// keys cannot duplicate those used for scrolling tefer m_mouseMidClickAction
|
||||
static const QList<GenericKeyDefinition> genericKeyDefinitions = {
|
||||
{ KEY_SYS, 'R', 0, 0, QList<int>() << Qt::Key_Left, SIMU_STR_HLP_KEY_LFT, SIMU_STR_HLP_ACT_SYS },
|
||||
|
||||
{ KEY_MODEL, 'R', 0, 1, QList<int>() << Qt::Key_Up, SIMU_STR_HLP_KEY_UP, SIMU_STR_HLP_ACT_MDL },
|
||||
|
||||
{ KEY_PAGEUP, 'R', 1, 0, QList<int>() << Qt::Key_PageUp, SIMU_STR_HLP_KEY_PGUP, SIMU_STR_HLP_ACT_PGUP },
|
||||
|
||||
{ KEY_PAGEDN, 'R', 1, 1, QList<int>() << Qt::Key_PageDown, SIMU_STR_HLP_KEY_PGDN, SIMU_STR_HLP_ACT_PGDN },
|
||||
|
||||
{ KEY_UP, 'R', 2, 0, QList<int>() << Qt::Key_Up
|
||||
<< Qt::Key_PageUp, SIMU_STR_HLP_KEYS_GO_UP, SIMU_STR_HLP_ACT_UP },
|
||||
|
||||
{ KEY_DOWN, 'R', 2, 1, QList<int>() << Qt::Key_Down
|
||||
<< Qt::Key_PageDown, SIMU_STR_HLP_KEYS_GO_DN, SIMU_STR_HLP_ACT_DN },
|
||||
|
||||
{ KEY_LEFT, 'R', 3, 0, QList<int>() << Qt::Key_Left
|
||||
<< Qt::Key_Minus, SIMU_STR_HLP_KEY_LFT % "|" % SIMU_STR_HLP_KEY_MIN, SIMU_STR_HLP_ACT_MIN },
|
||||
|
||||
{ KEY_RIGHT, 'R', 3, 1, QList<int>() << Qt::Key_Right
|
||||
<< Qt::Key_Plus, SIMU_STR_HLP_KEY_RGT % "|" % SIMU_STR_HLP_KEY_PLS, SIMU_STR_HLP_ACT_PLS },
|
||||
|
||||
{ KEY_MINUS, 'R', 4, 0, QList<int>() << Qt::Key_Minus
|
||||
<< Qt::Key_Right, SIMU_STR_HLP_KEY_RGT % "|" % SIMU_STR_HLP_KEY_MIN % "|" % SIMU_STR_HLP_MOUSE_DN, SIMU_STR_HLP_ACT_MIN },
|
||||
|
||||
{ KEY_PLUS, 'R', 4, 1, QList<int>() << Qt::Key_Plus
|
||||
<< Qt::Key_Equal
|
||||
<< Qt::Key_Left, SIMU_STR_HLP_KEY_LFT % "|" % SIMU_STR_HLP_KEY_PLS % "|" % SIMU_STR_HLP_MOUSE_UP, SIMU_STR_HLP_ACT_PLS },
|
||||
|
||||
{ KEY_TELE, 'R', 5, 1, QList<int>() << Qt::Key_Right, SIMU_STR_HLP_KEY_RGT, SIMU_STR_HLP_ACT_TELE },
|
||||
|
||||
{ KEY_MENU, 'R', 6, 0, QList<int>() << Qt::Key_Up
|
||||
<< Qt::Key_PageUp, SIMU_STR_HLP_KEYS_GO_UP, SIMU_STR_HLP_ACT_MENU },
|
||||
|
||||
{ KEY_SHIFT, 'R', 6, 1, QList<int>() << Qt::Key_S, SIMU_STR_HLP_KEY_SHIFT, SIMU_STR_HLP_ACT_SHIFT },
|
||||
|
||||
{ KEY_EXIT, 'R', 7, 0, QList<int>() << Qt::Key_Down
|
||||
<< Qt::Key_Delete
|
||||
<< Qt::Key_Escape
|
||||
<< Qt::Key_Backspace, SIMU_STR_HLP_KEYS_EXIT, SIMU_STR_HLP_ACT_EXIT },
|
||||
|
||||
{ KEY_ENTER, 'R', 7, 1, QList<int>() << Qt::Key_Enter
|
||||
<< Qt::Key_Return, SIMU_STR_HLP_KEYS_ACTIVATE, SIMU_STR_HLP_ACT_ROT_DN },
|
||||
};
|
||||
|
||||
void SimulatedUIWidget::addGenericPushButtons(ButtonsWidget * leftButtons, ButtonsWidget * rightButtons)
|
||||
void SimulatedUIWidget::addPushButtons(ButtonsWidget * leftButtons, ButtonsWidget * rightButtons)
|
||||
{
|
||||
QGridLayout * gridLeft = new QGridLayout((QWidget *)leftButtons);
|
||||
QGridLayout * leftButtonsGrid = new QGridLayout();
|
||||
|
||||
if (g.simuGenericKeysPos() != AppData::SIMU_GENERIC_KEYS_RIGHT) {
|
||||
leftButtons->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
||||
gridLeft->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
|
||||
|
||||
int width = 0;
|
||||
int col = 0;
|
||||
leftButtonsGrid->setColumnMinimumWidth(col++, BUTTON_WIDTH);
|
||||
width += BUTTON_WIDTH;
|
||||
|
||||
if (g.simuGenericKeysPos() == AppData::SIMU_GENERIC_KEYS_LEFT) {
|
||||
leftButtonsGrid->setColumnMinimumWidth(col++, 2);
|
||||
width += 2;
|
||||
leftButtonsGrid->setColumnMinimumWidth(col++, BUTTON_WIDTH);
|
||||
width += BUTTON_WIDTH;
|
||||
}
|
||||
|
||||
leftButtonsGrid->setColumnMinimumWidth(col++, 2);
|
||||
width += 2;
|
||||
leftButtons->setMinimumWidth(width);
|
||||
gridLeft->addLayout(leftButtonsGrid, 0, 1);
|
||||
}
|
||||
else {
|
||||
leftButtons->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
leftButtons->setFixedSize(0, 0);
|
||||
}
|
||||
|
||||
QGridLayout * gridRight = new QGridLayout((QWidget *)rightButtons);
|
||||
QGridLayout * rightButtonsGrid = new QGridLayout();
|
||||
|
||||
if (g.simuGenericKeysPos() != AppData::SIMU_GENERIC_KEYS_LEFT) {
|
||||
rightButtons->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
||||
int width = 0;
|
||||
int col = 0;
|
||||
rightButtonsGrid->setColumnMinimumWidth(col++, BUTTON_WIDTH);
|
||||
width += BUTTON_WIDTH;
|
||||
|
||||
if (g.simuGenericKeysPos() == AppData::SIMU_GENERIC_KEYS_RIGHT) {
|
||||
rightButtonsGrid->setColumnMinimumWidth(col++, 2);
|
||||
width += 2;
|
||||
rightButtonsGrid->setColumnMinimumWidth(col++, BUTTON_WIDTH);
|
||||
width += BUTTON_WIDTH;
|
||||
}
|
||||
|
||||
rightButtonsGrid->setColumnMinimumWidth(col++, 2);
|
||||
width += 2;
|
||||
|
||||
rightButtons->setMinimumWidth(width);
|
||||
gridRight->addLayout(rightButtonsGrid, 0, 0);
|
||||
gridRight->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
|
||||
}
|
||||
else {
|
||||
rightButtons->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
rightButtons->setFixedSize(0, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Boards::getCapability(m_board, Board::Keys); i++) {
|
||||
Board::KeyInfo info = Boards::getKeyInfo(i, m_board);
|
||||
int idx = strKeyToInt(info.key);
|
||||
//qDebug() << "key:" << info.key.c_str() << info.name.c_str() << info.label.c_str() << idx;
|
||||
if (idx >= 0)
|
||||
addGenericPushButton(idx, info.label.c_str(), leftButtons, leftButtonsGrid, rightButtons, rightButtonsGrid);
|
||||
addPushButton(idx, info.label.c_str(), leftButtons, leftButtonsGrid, rightButtons, rightButtonsGrid);
|
||||
else
|
||||
qDebug() << "Unknown key:" << info.key.c_str() << info.name.c_str() << info.label.c_str();
|
||||
}
|
||||
|
||||
QGridLayout * gridLeft = new QGridLayout((QWidget *)leftButtons);
|
||||
gridLeft->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
|
||||
gridLeft->addLayout(leftButtonsGrid, 0, 1);
|
||||
//gridLeft->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
|
||||
|
||||
QGridLayout * gridRight = new QGridLayout((QWidget *)rightButtons);
|
||||
//gridRight->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
|
||||
gridRight->addLayout(rightButtonsGrid, 0, 1);
|
||||
gridRight->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
|
||||
if (g.simuScrollButtons() && getCurrentFirmware()->getCapability(RotaryEncoderNavigation)) {
|
||||
addPushButton(KEY_SCRLUP, tr("Scrl Up"), leftButtons, leftButtonsGrid, rightButtons, rightButtonsGrid);
|
||||
addPushButton(KEY_SCRLDN, tr("Scrl Dn"), leftButtons, leftButtonsGrid, rightButtons, rightButtonsGrid);
|
||||
connectScrollActions();
|
||||
}
|
||||
}
|
||||
|
||||
void SimulatedUIWidget::addGenericPushButton(int index, QString label, ButtonsWidget * leftButtons, QGridLayout * leftButtonsGrid,
|
||||
ButtonsWidget * rightButtons, QGridLayout * rightButtonsGrid)
|
||||
void SimulatedUIWidget::addPushButton(int index, QString label, ButtonsWidget * leftButtons, QGridLayout * leftButtonsGrid,
|
||||
ButtonsWidget * rightButtons, QGridLayout * rightButtonsGrid)
|
||||
{
|
||||
if (index >= genericKeyDefinitions.size())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < genericKeyDefinitions.size(); i++) {
|
||||
const GenericKeyDefinition defn = genericKeyDefinitions.at(i);
|
||||
for (int i = 0; i < radioKeyDefinitions.size(); i++) {
|
||||
const RadioKeyDefinition defn = radioKeyDefinitions.at(i);
|
||||
|
||||
if (defn.index == index) {
|
||||
QPushButton * b = new QPushButton(label);
|
||||
b->setToolTip(tr("Shortcut: %1").arg(defn.helpKeys));
|
||||
b->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
b->setMinimumSize(60, 30);
|
||||
b->setMaximumSize(60, 30);
|
||||
RadioUiAction * act = new RadioUiAction();
|
||||
ButtonsWidget * btns = defn.side == 'L' ? leftButtons : rightButtons;
|
||||
QGridLayout * grid = defn.side == 'L' ? leftButtonsGrid : rightButtonsGrid;
|
||||
grid->addWidget(b, defn.gridRow, defn.gridCol);
|
||||
act = new RadioUiAction(defn.index, defn.keys, defn.helpKeys, defn.helpActions);
|
||||
b->setMinimumSize(BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||
b->setMaximumSize(b->minimumSize());
|
||||
ButtonsWidget * btns = g.simuGenericKeysPos() == AppData::SIMU_GENERIC_KEYS_DEFAULT ? (defn.side == 'L' ? leftButtons : rightButtons) :
|
||||
(g.simuGenericKeysPos() == AppData::SIMU_GENERIC_KEYS_LEFT ? leftButtons : rightButtons);
|
||||
QGridLayout * grid = g.simuGenericKeysPos() == AppData::SIMU_GENERIC_KEYS_DEFAULT ? (defn.side == 'L' ? leftButtonsGrid : rightButtonsGrid) :
|
||||
(g.simuGenericKeysPos() == AppData::SIMU_GENERIC_KEYS_LEFT ? leftButtonsGrid : rightButtonsGrid);
|
||||
int col = g.simuGenericKeysPos() == AppData::SIMU_GENERIC_KEYS_DEFAULT ? 0 : (defn.side == 'L' ? 0 : 2);
|
||||
grid->setRowMinimumHeight(defn.gridRow, BUTTON_HEIGHT);
|
||||
grid->addWidget(b, defn.gridRow, col);
|
||||
int idx = -1;
|
||||
|
||||
switch (defn.index) {
|
||||
case KEY_SCRLUP:
|
||||
idx = -2;
|
||||
break;
|
||||
case KEY_SCRLDN:
|
||||
idx = -3;
|
||||
break;
|
||||
default:
|
||||
idx = defn.index;
|
||||
}
|
||||
|
||||
RadioUiAction * act = new RadioUiAction(idx, defn.keys, defn.helpKeys, defn.helpActions);
|
||||
|
||||
switch (defn.index) {
|
||||
case KEY_SCRLUP:
|
||||
m_scrollUpAction = act;
|
||||
break;
|
||||
case KEY_SCRLDN:
|
||||
m_scrollDnAction = act;
|
||||
break;
|
||||
}
|
||||
|
||||
addRadioWidget(btns->addPushButton(b, act));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const RadioKeyDefinition * SimulatedUIWidget::getRadioKeyDefinition(const int key) const
|
||||
{
|
||||
for (int i = 0; i < radioKeyDefinitions.size(); i++) {
|
||||
const RadioKeyDefinition defn = radioKeyDefinitions.at(i);
|
||||
if (defn.index == key)
|
||||
return &radioKeyDefinitions.at(i);
|
||||
}
|
||||
|
||||
qDebug() << "Unknown key:" << key;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user