feat(color): allow user to change key shortcut action; add Favorites quick menu (#6753)

Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
philmoz
2025-11-19 18:40:23 +10:00
committed by GitHub
co-authored by elecpower
parent 5c96b1e15c
commit 72d290f89f
103 changed files with 2605 additions and 921 deletions
@@ -136,6 +136,49 @@ static const YamlLookupTable hatsModeLut = {
{ GeneralSettings::HATSMODE_SWITCHABLE, "SWITCHABLE" },
};
static const YamlLookupTable QMPageLut = {
{ GeneralSettings::QM_NONE, "NONE" },
{ GeneralSettings::QM_OPEN_QUICK_MENU, "OPEN_QUICK_MENU" },
{ GeneralSettings::QM_MANAGE_MODELS, "MANAGE_MODELS" },
{ GeneralSettings::QM_MODEL_SETUP, "MODEL_SETUP" },
{ GeneralSettings::QM_MODEL_FLIGHTMODES, "MODEL_FLIGHTMODES" },
{ GeneralSettings::QM_MODEL_INPUTS, "MODEL_INPUTS" },
{ GeneralSettings::QM_MODEL_MIXES, "MODEL_MIXES" },
{ GeneralSettings::QM_MODEL_OUTPUTS, "MODEL_OUTPUTS" },
{ GeneralSettings::QM_MODEL_CURVES, "MODEL_CURVES" },
{ GeneralSettings::QM_MODEL_GVARS, "MODEL_GVARS" },
{ GeneralSettings::QM_MODEL_LS, "MODEL_LS" },
{ GeneralSettings::QM_MODEL_SF, "MODEL_SF" },
{ GeneralSettings::QM_MODEL_SCRIPTS, "MODEL_SCRIPTS" },
{ GeneralSettings::QM_MODEL_TELEMETRY, "MODEL_TELEMETRY" },
{ GeneralSettings::QM_MODEL_NOTES, "MODEL_NOTES" },
{ GeneralSettings::QM_RADIO_SETUP, "RADIO_SETUP" },
{ GeneralSettings::QM_RADIO_GF, "RADIO_GF" },
{ GeneralSettings::QM_RADIO_TRAINER, "RADIO_TRAINER" },
{ GeneralSettings::QM_RADIO_HARDWARE, "RADIO_HARDWARE" },
{ GeneralSettings::QM_RADIO_VERSION, "RADIO_VERSION" },
{ GeneralSettings::QM_UI_THEMES, "UI_THEMES" },
{ GeneralSettings::QM_UI_SETUP, "UI_SETUP" },
{ GeneralSettings::QM_UI_SCREEN1, "UI_SCREEN1" },
{ GeneralSettings::QM_UI_SCREEN2, "UI_SCREEN2" },
{ GeneralSettings::QM_UI_SCREEN3, "UI_SCREEN3" },
{ GeneralSettings::QM_UI_SCREEN4, "UI_SCREEN4" },
{ GeneralSettings::QM_UI_SCREEN5, "UI_SCREEN5" },
{ GeneralSettings::QM_UI_SCREEN6, "UI_SCREEN6" },
{ GeneralSettings::QM_UI_SCREEN7, "UI_SCREEN7" },
{ GeneralSettings::QM_UI_SCREEN8, "UI_SCREEN8" },
{ GeneralSettings::QM_UI_SCREEN9, "UI_SCREEN9" },
{ GeneralSettings::QM_UI_SCREEN10, "UI_SCREEN10" },
{ GeneralSettings::QM_UI_ADD_PG, "UI_ADD_PG" },
{ GeneralSettings::QM_TOOLS_APPS, "TOOLS_APPS" },
{ GeneralSettings::QM_TOOLS_STORAGE, "TOOLS_STORAGE" },
{ GeneralSettings::QM_TOOLS_RESET, "TOOLS_RESET" },
{ GeneralSettings::QM_TOOLS_CHAN_MON, "TOOLS_CHAN_MON" },
{ GeneralSettings::QM_TOOLS_LS_MON, "TOOLS_LS_MON" },
{ GeneralSettings::QM_TOOLS_STATS, "TOOLS_STATS" },
{ GeneralSettings::QM_TOOLS_DEBUG, "TOOLS_DEBUG" },
};
YamlTelemetryBaudrate::YamlTelemetryBaudrate(
const unsigned int* moduleBaudrate)
{
@@ -343,6 +386,15 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
node["modelCustomScriptsDisabled"] = (int)rhs.modelCustomScriptsDisabled;
node["modelTelemetryDisabled"] = (int)rhs.modelTelemetryDisabled;
if (hasColorLcd) {
for (int i = 0; i < MAX_KEYSHORTCUTS; i += 1)
if (rhs.keyShortcuts[i] != GeneralSettings::QM_NONE)
node["keyShortcuts"][std::to_string(i)]["shortcut"] = QMPageLut << rhs.keyShortcuts[i];
for (int i = 0; i < MAX_QMFAVOURITES; i += 1)
if (rhs.qmFavorites[i] != GeneralSettings::QM_NONE)
node["qmFavorites"][std::to_string(i)]["shortcut"] = QMPageLut << rhs.qmFavorites[i];
}
return node;
}
@@ -653,6 +705,15 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
node["labelMultiMode"] >> rhs.labelMultiMode;
node["favMultiMode"] >> rhs.favMultiMode;
if (node["keyShortcuts"]) {
for (int i = 0; i < MAX_KEYSHORTCUTS; i += 1)
node["keyShortcuts"][std::to_string(i)]["shortcut"] >> QMPageLut >> rhs.keyShortcuts[i];
}
if (node["qmFavorites"]) {
for (int i = 0; i < MAX_QMFAVOURITES; i += 1)
node["qmFavorites"][std::to_string(i)]["shortcut"] >> QMPageLut >> rhs.qmFavorites[i];
}
// override critical settings after import
// TODO: for consistency move up call stack to use existing eeprom and profile conversions
if (needsConversion)
@@ -172,6 +172,8 @@ enum Capability {
HasIntModuleELRS,
HasIntModuleFlySky,
BacklightLevelMin,
QMFavourites,
KeyShortcuts,
};
float ValToTim(int value);
+138
View File
@@ -241,6 +241,8 @@ void GeneralSettings::init()
}
stickDeadZone = (IS_FLYSKY_NV14(board) || IS_FAMILY_PL18(board)) ? 2 : 0;
setDefaultFavorites();
setDefaultKeyShortcuts();
}
void GeneralSettings::setDefaultControlTypes(Board::Type board)
@@ -960,3 +962,139 @@ AbstractStaticItemModel * GeneralSettings::backlightModeItemModel()
mdl->loadItemList();
return mdl;
}
// static
QString GeneralSettings::quickMenuToString(int value, bool keys)
{
switch(value) {
case QM_NONE:
return tr("None");
case QM_OPEN_QUICK_MENU:
return tr("Open Quick Menu");
case QM_MANAGE_MODELS:
return tr("MANAGE MODELS");
// Model menu
case QM_MODEL_SETUP:
return tr("Model Setup - Model Settings");
case QM_MODEL_FLIGHTMODES:
return tr("Model Setup - Flight Modes");
case QM_MODEL_INPUTS:
return tr("Model Setup - Inputs");
case QM_MODEL_MIXES:
return tr("Model Setup - Mixes");
case QM_MODEL_OUTPUTS:
return tr("Model Setup - Outputs");
case QM_MODEL_CURVES:
return tr("Model Setup - Curves");
case QM_MODEL_GVARS:
return tr("Model Setup - Global Variables");
case QM_MODEL_LS:
return tr("Model Setup - Logical Switches");
case QM_MODEL_SF:
return tr("Model Setup - Special Functions");
case QM_MODEL_SCRIPTS:
return tr("Model Setup - Mixer Scripts");
case QM_MODEL_TELEMETRY:
return tr("Model Setup - Telemetry");
case QM_MODEL_NOTES:
return tr("Model Setup - Notes");
// Radio menu
case QM_RADIO_SETUP:
return tr("Radio Setup - Radio Settings");
case QM_RADIO_GF:
return tr("Radio Setup - Global Functions");
case QM_RADIO_TRAINER:
return tr("Radio Setup - Trainer");
case QM_RADIO_HARDWARE:
return tr("Radio Setup - Hardware");
case QM_RADIO_VERSION:
return tr("Radio Setup - About EdgeTX");
// UI menu
case QM_UI_THEMES:
return tr("UI Setup - Themes");
case QM_UI_SETUP:
return tr("UI Setup - Top Bar");
case QM_UI_SCREEN1:
return keys ? tr("UI Setup - Current Screen") : tr("UI Setup - Screen 1");
case QM_UI_SCREEN2:
return tr("UI Setup - Screen 2");
case QM_UI_SCREEN3:
return tr("UI Setup - Screen 3");
case QM_UI_SCREEN4:
return tr("UI Setup - Screen 4");
case QM_UI_SCREEN5:
return tr("UI Setup - Screen 5");
case QM_UI_SCREEN6:
return tr("UI Setup - Screen 6");
case QM_UI_SCREEN7:
return tr("UI Setup - Screen 7");
case QM_UI_SCREEN8:
return tr("UI Setup - Screen 8");
case QM_UI_SCREEN9:
return tr("UI Setup - Screen 9");
case QM_UI_SCREEN10:
return tr("UI Setup - Screen 10");
case QM_UI_ADD_PG:
return tr("UI Setup - Add Screen");
// Tools menu
case QM_TOOLS_APPS:
return tr("Tools - Apps");
case QM_TOOLS_STORAGE:
return tr("Tools - Storage");
case QM_TOOLS_RESET:
return tr("Tools - Flight Reset");
case QM_TOOLS_CHAN_MON:
return tr("Tools - Channel Monitor");
case QM_TOOLS_LS_MON:
return tr("Tools - Logical Switch Monitor");
case QM_TOOLS_STATS:
return tr("Tools - Statistics");
case QM_TOOLS_DEBUG:
return tr("Tools - Debug");
default:
return CPN_STR_UNKNOWN_ITEM;
}
}
// static
bool GeneralSettings::isQuickMenuAvailable(int value, bool keys)
{
if (keys) {
if (value >= QM_UI_SCREEN2 && value <= QM_UI_ADD_PG)
return false;
} else if (value == QM_OPEN_QUICK_MENU)
return false;
return true;
}
// static
AbstractStaticItemModel * GeneralSettings::quickMenuItemModel(bool keys)
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName(AIM_GS_QUICKMENU);
for (int i = 0; i < QM_COUNT; i++) {
if (isQuickMenuAvailable(i, keys))
mdl->appendToItemList(quickMenuToString(i, keys), i);
}
mdl->loadItemList();
return mdl;
}
void GeneralSettings::setDefaultFavorites()
{
for (int i = 0; i < MAX_QMFAVOURITES; i++)
qmFavorites[i] = QM_NONE;
}
void GeneralSettings::setDefaultKeyShortcuts()
{
keyShortcuts[0] = QM_MODEL_SETUP; // MDL short
keyShortcuts[1] = QM_OPEN_QUICK_MENU; // SYS short
keyShortcuts[2] = QM_UI_SCREEN1; // TELE short
keyShortcuts[3] = QM_MANAGE_MODELS; // MDL long
keyShortcuts[4] = QM_TOOLS_APPS; // SYS long
keyShortcuts[5] = QM_TOOLS_CHAN_MON; // TELE long
}
+63
View File
@@ -47,13 +47,18 @@ constexpr char AIM_GS_HATSMODE[] {"gs.hatsmode"};
constexpr char AIM_GS_STICKMODE[] {"gs.stickmode"};
constexpr char AIM_GS_TEMPLATESETUP[] {"gs.templatesetup"};
constexpr char AIM_GS_BACKLIGHTMODE[] {"gs.backlightmode"};
constexpr char AIM_GS_QUICKMENU[] {"gs.quickmenu"};
constexpr char AIM_TRAINERMIX_MODE[] {"trainermix.mode"};
constexpr char AIM_TRAINERMIX_SRC[] {"trainermix.src"};
constexpr int MAX_KEYSHORTCUTS {6};
constexpr int MAX_QMFAVOURITES {12};
static const QStringList moduleBaudratesList({"115K", "400K", "921K", "1.87M",
"3.75M", "5.25M"});
enum UartModes {
UART_MODE_NONE,
UART_MODE_TELEMETRY_MIRROR,
@@ -225,6 +230,55 @@ class GeneralSettings {
BACKLIGHT_MODE_COUNT,
};
// Match equivalent enum in radio/src/gui/colorlcd/setup_menus/quick_menu.h
enum QMPage {
QM_NONE = 0,
QM_OPEN_QUICK_MENU,
QM_MANAGE_MODELS,
// Model menu
QM_MODEL_SETUP,
QM_MODEL_FLIGHTMODES,
QM_MODEL_INPUTS,
QM_MODEL_MIXES,
QM_MODEL_OUTPUTS,
QM_MODEL_CURVES,
QM_MODEL_GVARS,
QM_MODEL_LS,
QM_MODEL_SF,
QM_MODEL_SCRIPTS,
QM_MODEL_TELEMETRY,
QM_MODEL_NOTES,
// Radio menu
QM_RADIO_SETUP,
QM_RADIO_GF,
QM_RADIO_TRAINER,
QM_RADIO_HARDWARE,
QM_RADIO_VERSION,
// UI menu
QM_UI_THEMES,
QM_UI_SETUP,
QM_UI_SCREEN1,
QM_UI_SCREEN2,
QM_UI_SCREEN3,
QM_UI_SCREEN4,
QM_UI_SCREEN5,
QM_UI_SCREEN6,
QM_UI_SCREEN7,
QM_UI_SCREEN8,
QM_UI_SCREEN9,
QM_UI_SCREEN10,
QM_UI_ADD_PG,
// Tools menu
QM_TOOLS_APPS,
QM_TOOLS_STORAGE,
QM_TOOLS_RESET,
QM_TOOLS_CHAN_MON,
QM_TOOLS_LS_MON,
QM_TOOLS_STATS,
QM_TOOLS_DEBUG,
QM_COUNT,
};
GeneralSettings() { clear(); }
void clear();
void init();
@@ -235,6 +289,8 @@ class GeneralSettings {
RawSource getDefaultSource(unsigned int channel) const;
int getDefaultChannel(unsigned int stick) const;
bool fix6POSCalibration();
void setDefaultFavorites();
void setDefaultKeyShortcuts();
bool manuallyEdited;
@@ -394,6 +450,10 @@ class GeneralSettings {
};
SwitchConfig switchConfig[CPN_MAX_SWITCHES];
unsigned int keyShortcuts[MAX_KEYSHORTCUTS];
unsigned int qmFavorites[MAX_QMFAVOURITES];
void switchConfigClear();
bool switchPositionAllowed(int index) const;
@@ -410,6 +470,7 @@ class GeneralSettings {
bool isSwitchFunc(int index) const;
bool unassignedInputFlexSwitches() const;
static bool isBacklightModeAvailable(int index);
static bool isQuickMenuAvailable(int value, bool keys);
QString antennaModeToString() const;
QString bluetoothModeToString() const;
@@ -432,6 +493,7 @@ class GeneralSettings {
static QString stickModeToString(int value);
static QString templateSetupToString(int value, bool isBoardAir);
static QString backlightModeToString(int value);
static QString quickMenuToString(int value, bool keys);
static AbstractStaticItemModel * antennaModeItemModel(bool model_setup = false);
static AbstractStaticItemModel * bluetoothModeItemModel();
@@ -443,6 +505,7 @@ class GeneralSettings {
static AbstractStaticItemModel * stickModeItemModel();
static AbstractStaticItemModel * templateSetupItemModel();
static AbstractStaticItemModel * backlightModeItemModel();
static AbstractStaticItemModel * quickMenuItemModel(bool keys);
void validateFlexSwitches();
};
@@ -357,6 +357,10 @@ int OpenTxFirmware::getCapability(::Capability capability)
} else {
return 46;
}
case QMFavourites:
return Boards::getCapability(board, Board::HasColorLcd) ? MAX_QMFAVOURITES : 0;
case KeyShortcuts:
return Boards::getCapability(board, Board::HasColorLcd) ? MAX_KEYSHORTCUTS : 0;
default:
return 0;
}
+2
View File
@@ -3,6 +3,8 @@ project(generaledit)
set(${PROJECT_NAME}_NAMES
generaledit
generalfavorites
generalkeyshortcuts
generaloptions
generalsetup
hardware
@@ -31,6 +31,8 @@
#include "scrollarea.h"
#include "compounditemmodels.h"
#include "firmwares/edgetx/edgetxinterface.h"
#include "generalfavorites.h"
#include "generalkeyshortcuts.h"
GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * firmware) :
QDialog(parent),
@@ -56,6 +58,10 @@ GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * fir
auto hwpnl = new HardwarePanel(this, generalSettings, firmware, editorItemModels);
addTab(hwpnl, tr("Hardware"));
addTab(new GeneralOptionsPanel(this, generalSettings, firmware), tr("Enabled Features"));
if (firmware->getCapability(QMFavourites))
addTab(new GeneralFavsPanel(this, generalSettings, firmware), tr("Favourites"));
if (firmware->getCapability(KeyShortcuts))
addTab(new GeneralKeysPanel(this, generalSettings, firmware), tr("Key Shortcuts"));
connect(hwpnl, &HardwarePanel::internalModuleChanged, this, [&] { intModChanged = true; });
@@ -0,0 +1,124 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* 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 "generalfavorites.h"
#include "autocombobox.h"
#include "compounditemmodels.h"
#include "exclusivecombogroup.h"
#include <QLabel>
#include <QGridLayout>
GeneralFavsPanel::GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware):
GeneralPanel(parent, generalSettings, firmware),
board(firmware->getBoard()),
params(new QList<QWidget *>),
row(0),
col(0)
{
grid = new QGridLayout(this);
// All values except QM_NONE are mutually exclusive
cboQMGrp = new ExclusiveComboGroup(this,
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE; });
const int cnt = firmware->getCapability(QMFavourites);
for (int i = 0; i < cnt; i++) {
addLabel(tr("# %1").arg(i + 1));
AutoComboBox *cbo = new AutoComboBox(this);
// separate item model per combo box due to mutual exclusivity
cbo->setModel(generalSettings.quickMenuItemModel(false));
cbo->setField(generalSettings.qmFavorites[i], this);
cboQMGrp->addCombo(cbo);
params->append(cbo);
addParams();
}
addLine();
QPushButton *reset = new QPushButton(tr("Reset"));
connect(reset, &QPushButton::clicked, [&] ()
{
generalSettings.setDefaultFavorites();
foreach(AutoComboBox *cb, findChildren<AutoComboBox*>())
cb->updateValue();
initComboQMGroup();
});
params->append(reset);
addParams();
initComboQMGroup();
addVSpring(grid, 0, grid->rowCount());
addHSpring(grid, grid->columnCount(), 0);
disableMouseScrolling();
}
GeneralFavsPanel::~GeneralFavsPanel()
{
}
void GeneralFavsPanel::addLabel(QString text)
{
QLabel *label = new QLabel(this);
label->setText(text);
grid->addWidget(label, row, col);
}
void GeneralFavsPanel::addLine()
{
QFrame *line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setLineWidth(1);
line->setMidLineWidth(0);
grid->addWidget(line, row++, 0, 1, grid->columnCount());
}
void GeneralFavsPanel::addParams()
{
int col = 0;
QGridLayout *subgrid = new QGridLayout();
for (int i = 0; i < params->size(); i++) {
subgrid->addWidget(params->at(i), 0, col++);
}
addHSpring(subgrid, col, 0);
grid->addLayout(subgrid, row++, this->col + 1);
params->clear();
}
void GeneralFavsPanel::addSection(QString text)
{
addLabel(QString("<b>%1</b>").arg(text));
row++;
}
void GeneralFavsPanel::initComboQMGroup()
{
// force mutually exclusive update to lists
for (int i = 0; i < cboQMGrp->getComboBoxes()->size(); i++) {
QComboBox *cbo = cboQMGrp->getComboBoxes()->at(i);
cboQMGrp->handleActivated(cbo, cbo->currentIndex());
}
}
@@ -0,0 +1,50 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* 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.
*/
#pragma once
#include "generaledit.h"
class ExclusiveComboGroup;
class QGridLayout;
class GeneralFavsPanel : public GeneralPanel
{
Q_OBJECT
public:
GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware);
virtual ~GeneralFavsPanel();
private:
Board::Type board;
QGridLayout *grid;
QList<QWidget *> *params;
int row;
int col;
ExclusiveComboGroup *cboQMGrp;
void addLabel(QString text);
void addLine();
void addParams();
void addSection(QString text);
void initComboQMGroup();
};
@@ -0,0 +1,135 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* 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 "generalkeyshortcuts.h"
#include "autocombobox.h"
#include "compounditemmodels.h"
#include "exclusivecombogroup.h"
#include <QLabel>
#include <QGridLayout>
GeneralKeysPanel::GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware):
GeneralPanel(parent, generalSettings, firmware),
board(firmware->getBoard()),
params(new QList<QWidget *>),
row(0),
col(0)
{
grid = new QGridLayout(this);
// All values except QM_NONE are mutually exclusive
cboQMGrp = new ExclusiveComboGroup(this,
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE; });
const int cnt = firmware->getCapability(KeyShortcuts);
const int split = 2;
for (int i = 0; i < split; i++) {
if (i == 0) {
addSection(tr("Short Press"));
} else {
addLine();
addSection(tr("Long Press"));
}
for (int j = 0; j < (cnt / split); j++) {
addLabel(j == 0 ? tr("MDL") : (j == 1 ? tr("SYS") : tr("TELE")));
AutoComboBox *cbo = new AutoComboBox(this);
// separate item model per combo box due to mutual exclusivity
cbo->setModel(generalSettings.quickMenuItemModel(true));
cbo->setField(generalSettings.keyShortcuts[(i * (split + 1)) + j], this);
cboQMGrp->addCombo(cbo);
params->append(cbo);
addParams();
}
}
addLine();
QPushButton *reset = new QPushButton(tr("Reset"));
connect(reset, &QPushButton::clicked, [&] ()
{
generalSettings.setDefaultKeyShortcuts();
foreach(AutoComboBox *cb, findChildren<AutoComboBox*>())
cb->updateValue();
initComboQMGroup();
});
params->append(reset);
addParams();
initComboQMGroup();
addVSpring(grid, 0, grid->rowCount());
addHSpring(grid, grid->columnCount(), 0);
disableMouseScrolling();
}
GeneralKeysPanel::~GeneralKeysPanel()
{
}
void GeneralKeysPanel::addLabel(QString text)
{
QLabel *label = new QLabel(this);
label->setText(text);
grid->addWidget(label, row, col);
}
void GeneralKeysPanel::addLine()
{
QFrame *line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setLineWidth(1);
line->setMidLineWidth(0);
grid->addWidget(line, row++, 0, 1, grid->columnCount());
}
void GeneralKeysPanel::addParams()
{
int col = 0;
QGridLayout *subgrid = new QGridLayout();
for (int i = 0; i < params->size(); i++) {
subgrid->addWidget(params->at(i), 0, col++);
}
addHSpring(subgrid, col, 0);
grid->addLayout(subgrid, row++, this->col + 1);
params->clear();
}
void GeneralKeysPanel::addSection(QString text)
{
addLabel(QString("<b>%1</b>").arg(text));
row++;
}
void GeneralKeysPanel::initComboQMGroup()
{
// force mutually exclusive update to lists
for (int i = 0; i < cboQMGrp->getComboBoxes()->size(); i++) {
QComboBox *cbo = cboQMGrp->getComboBoxes()->at(i);
cboQMGrp->handleActivated(cbo, cbo->currentIndex());
}
}
@@ -0,0 +1,50 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* 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.
*/
#pragma once
#include "generaledit.h"
class ExclusiveComboGroup;
class QGridLayout;
class GeneralKeysPanel : public GeneralPanel
{
Q_OBJECT
public:
GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware);
virtual ~GeneralKeysPanel();
private:
Board::Type board;
QGridLayout *grid;
QList<QWidget *> *params;
int row;
int col;
ExclusiveComboGroup *cboQMGrp;
void addLabel(QString text);
void addLine();
void addParams();
void addSection(QString text);
void initComboQMGroup();
};