feat(color): key shortcuts and quick menu favorites can be set to run stand alone Lua tools (#7083)
Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "autocombobox.h"
|
||||
#include "compounditemmodels.h"
|
||||
#include "exclusivecombogroup.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
@@ -32,22 +33,76 @@ GeneralFavsPanel::GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSe
|
||||
board(firmware->getBoard()),
|
||||
params(new QList<QWidget *>),
|
||||
row(0),
|
||||
col(0)
|
||||
col(0),
|
||||
lock(true),
|
||||
cboFavTools(new QList<AutoComboBox *>),
|
||||
strFavTools(new QList<QString *>)
|
||||
{
|
||||
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 QVariant &value) { return value == GeneralSettings::QM_NONE ||
|
||||
value == GeneralSettings::QM_APP; });
|
||||
const int cnt = firmware->getCapability(QMFavourites);
|
||||
|
||||
// add lua tool scripts from radio profile sdcard
|
||||
QStringList toolsSet = getListLuaTools();
|
||||
QStandardItemModel *mdl = new QStandardItemModel(this);
|
||||
|
||||
for (int i = 0; i < toolsSet.size(); i++) {
|
||||
QStandardItem *item = new QStandardItem(toolsSet[i]);
|
||||
mdl->appendRow(item);
|
||||
}
|
||||
|
||||
// Ensure existing configured tool is included in toolsSet as the radio profile
|
||||
// sdcard contents may not match radio
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
if (generalSettings.qmFavorites[i] == GeneralSettings::QM_APP) {
|
||||
QString temp(generalSettings.qmFavoritesTools[i]);
|
||||
if (!temp.isEmpty() && mdl->findItems(temp).size() < 1) {
|
||||
QStandardItem *item = new QStandardItem(temp);
|
||||
mdl->appendRow(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QSortFilterProxyModel *mdlTools = new QSortFilterProxyModel(this);
|
||||
mdlTools->setSourceModel(mdl);
|
||||
mdlTools->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
mdlTools->setFilterKeyColumn(0);
|
||||
mdlTools->sort(0);
|
||||
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
addLabel(tr("# %1").arg(i + 1));
|
||||
AutoComboBox *cbo = new AutoComboBox(this);
|
||||
AutoComboBox *cboFav = new AutoComboBox(this);
|
||||
cboFav->setProperty("index", i);
|
||||
// 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);
|
||||
cboFav->setModel(generalSettings.quickMenuItemModel(false));
|
||||
cboFav->setField(generalSettings.qmFavorites[i], this);
|
||||
connect(cboFav, &AutoComboBox::currentDataChanged, this, &GeneralFavsPanel::on_favChanged);
|
||||
cboQMGrp->addCombo(cboFav);
|
||||
params->append(cboFav);
|
||||
|
||||
AutoComboBox *cboFavTool = new AutoComboBox(this);
|
||||
cboFavTool->setProperty("index", i);
|
||||
cboFavTool->setModel(mdlTools);
|
||||
// AutoComboBox does not support char * so use a proxy
|
||||
QString *str = new QString(generalSettings.qmFavoritesTools[i]);
|
||||
strFavTools->append(str);
|
||||
cboFavTool->setField(*str, this);
|
||||
|
||||
if (generalSettings.qmFavorites[i] == GeneralSettings::QM_APP) {
|
||||
if (cboFavTool->currentIndex() < 0)
|
||||
cboFavTool->setCurrentIndex(0);
|
||||
cboFavTool->setVisible(true);
|
||||
} else {
|
||||
cboFavTool->setCurrentIndex(0);
|
||||
cboFavTool->setVisible(false);
|
||||
}
|
||||
|
||||
connect(cboFavTool, &AutoComboBox::currentDataChanged, this, &GeneralFavsPanel::on_favToolChanged);
|
||||
cboFavTools->append(cboFavTool);
|
||||
params->append(cboFavTool);
|
||||
addParams();
|
||||
}
|
||||
|
||||
@@ -66,6 +121,7 @@ GeneralFavsPanel::GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSe
|
||||
params->append(reset);
|
||||
addParams();
|
||||
|
||||
lock = false;
|
||||
initComboQMGroup();
|
||||
addVSpring(grid, 0, grid->rowCount());
|
||||
addHSpring(grid, grid->columnCount(), 0);
|
||||
@@ -74,7 +130,25 @@ GeneralFavsPanel::GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSe
|
||||
|
||||
GeneralFavsPanel::~GeneralFavsPanel()
|
||||
{
|
||||
if (cboFavTools) {
|
||||
delete cboFavTools; // dialog destructor will delete members
|
||||
}
|
||||
|
||||
if (strFavTools) {
|
||||
for (auto it = strFavTools->begin(); it != strFavTools->end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
delete strFavTools;
|
||||
}
|
||||
|
||||
if (params) {
|
||||
for (auto it = params->begin(); it != params->end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
delete params;
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralFavsPanel::addLabel(QString text)
|
||||
@@ -122,3 +196,42 @@ void GeneralFavsPanel::initComboQMGroup()
|
||||
cboQMGrp->handleActivated(cbo, cbo->currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralFavsPanel::on_favChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
const int idx = sender()->property("index").toInt();
|
||||
const int i = cboFavTools->at(idx)->currentIndex();
|
||||
cboFavTools->at(idx)->setCurrentIndex(0);
|
||||
|
||||
if (i == cboFavTools->at(idx)->currentIndex())
|
||||
setToolName(idx); // force update
|
||||
|
||||
cboFavTools->at(idx)->setVisible(generalSettings.qmFavorites[idx] == GeneralSettings::QM_APP);
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralFavsPanel::on_favToolChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
bool ok;
|
||||
const int index = sender()->property("index").toInt(&ok);
|
||||
if (ok) setToolName(index);
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralFavsPanel::setToolName(int index)
|
||||
{
|
||||
if (generalSettings.qmFavoritesTools[index])
|
||||
delete generalSettings.qmFavoritesTools[index];
|
||||
|
||||
if (generalSettings.qmFavorites[index] == GeneralSettings::QM_APP) {
|
||||
// obtain current value from proxy
|
||||
std::string str = strFavTools->at(index)->toStdString();
|
||||
generalSettings.qmFavoritesTools[index] = new char[str.size() + 1];
|
||||
strncpy(generalSettings.qmFavoritesTools[index], str.c_str(), str.size());
|
||||
generalSettings.qmFavoritesTools[index][str.size()] = 0;
|
||||
} else {
|
||||
generalSettings.qmFavoritesTools[index] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "generaledit.h"
|
||||
#include "autocombobox.h"
|
||||
|
||||
class ExclusiveComboGroup;
|
||||
class QGridLayout;
|
||||
@@ -34,17 +35,25 @@ class GeneralFavsPanel : public GeneralPanel
|
||||
GeneralFavsPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
virtual ~GeneralFavsPanel();
|
||||
|
||||
private slots:
|
||||
void on_favChanged();
|
||||
void on_favToolChanged();
|
||||
|
||||
private:
|
||||
Board::Type board;
|
||||
QGridLayout *grid;
|
||||
QList<QWidget *> *params;
|
||||
int row;
|
||||
int col;
|
||||
bool lock;
|
||||
ExclusiveComboGroup *cboQMGrp;
|
||||
QList<AutoComboBox *> *cboFavTools;
|
||||
QList<QString *> *strFavTools;
|
||||
|
||||
void addLabel(QString text);
|
||||
void addLine();
|
||||
void addParams();
|
||||
void addSection(QString text);
|
||||
void initComboQMGroup();
|
||||
void setToolName(int index);
|
||||
};
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
*/
|
||||
|
||||
#include "generalkeyshortcuts.h"
|
||||
#include "autocombobox.h"
|
||||
#include "compounditemmodels.h"
|
||||
#include "exclusivecombogroup.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
@@ -32,32 +32,79 @@ GeneralKeysPanel::GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSe
|
||||
board(firmware->getBoard()),
|
||||
params(new QList<QWidget *>),
|
||||
row(0),
|
||||
col(0)
|
||||
col(0),
|
||||
lock(true),
|
||||
cboShortcuts(new QList<AutoComboBox *>),
|
||||
cboShortcutTools(new QList<AutoComboBox *>),
|
||||
strKeyShortcutTools(new QList<QString *>)
|
||||
{
|
||||
grid = new QGridLayout(this);
|
||||
// All values except QM_NONE are mutually exclusive
|
||||
// All values except QM_NONE and QM_APP are mutually exclusive
|
||||
cboQMGrp = new ExclusiveComboGroup(this,
|
||||
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE; });
|
||||
[=](const QVariant &value) { return value == GeneralSettings::QM_NONE ||
|
||||
value == GeneralSettings::QM_APP; });
|
||||
const int cnt = firmware->getCapability(KeyShortcuts);
|
||||
|
||||
// add lua tool scripts from radio profile sdcard
|
||||
QStringList toolsSet = getListLuaTools();
|
||||
QStandardItemModel *mdl = new QStandardItemModel(this);
|
||||
|
||||
for (int i = 0; i < toolsSet.size(); i++) {
|
||||
QStandardItem *item = new QStandardItem(toolsSet[i]);
|
||||
mdl->appendRow(item);
|
||||
}
|
||||
|
||||
// Ensure existing configured tool is included in toolsSet as the radio profile
|
||||
// sdcard contents may not match radio
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
if (generalSettings.qmFavorites[i] == GeneralSettings::QM_APP) {
|
||||
QString temp(generalSettings.qmFavoritesTools[i]);
|
||||
if (!temp.isEmpty() && mdl->findItems(temp).size() < 1) {
|
||||
QStandardItem *item = new QStandardItem(temp);
|
||||
mdl->appendRow(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QSortFilterProxyModel *mdlTools = new QSortFilterProxyModel(this);
|
||||
mdlTools->setSourceModel(mdl);
|
||||
mdlTools->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
mdlTools->setFilterKeyColumn(0);
|
||||
mdlTools->sort(0);
|
||||
|
||||
const int split = 2;
|
||||
|
||||
for (int i = 0; i < split; i++) {
|
||||
if (i == 0) {
|
||||
addSection(tr("Short Press"));
|
||||
addSection(tr("Short Press"));
|
||||
} else {
|
||||
addLine();
|
||||
addSection(tr("Long Press"));
|
||||
}
|
||||
|
||||
for (int j = 0; j < (cnt / split); j++) {
|
||||
const int idx = (i * (split + 1)) + j;
|
||||
addLabel(j == 0 ? tr("MDL") : (j == 1 ? tr("SYS") : tr("TELE")));
|
||||
AutoComboBox *cbo = new AutoComboBox(this);
|
||||
AutoComboBox *cboShortcut = new AutoComboBox(this);
|
||||
cboShortcut->setProperty("index", idx);
|
||||
// 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);
|
||||
cboShortcut->setModel(generalSettings.quickMenuItemModel(true));
|
||||
cboShortcut->setField(generalSettings.keyShortcuts[idx], this);
|
||||
connect(cboShortcut, &AutoComboBox::currentDataChanged, this, &GeneralKeysPanel::on_shortcutChanged);
|
||||
cboShortcuts->append(cboShortcut);
|
||||
cboQMGrp->addCombo(cboShortcut);
|
||||
params->append(cboShortcut);
|
||||
|
||||
AutoComboBox *cboShortcutTool = new AutoComboBox(this);
|
||||
cboShortcutTool->setProperty("index", idx);
|
||||
cboShortcutTool->setModel(mdlTools);
|
||||
// AutoComboBox does not support char * so use a proxy
|
||||
QString *str = new QString(generalSettings.keyShortcutTools[idx]);
|
||||
strKeyShortcutTools->append(str);
|
||||
cboShortcutTool->setField(*str, this);
|
||||
connect(cboShortcutTool, &AutoComboBox::currentDataChanged, this, &GeneralKeysPanel::on_shortcutToolChanged);
|
||||
cboShortcutTools->append(cboShortcutTool);
|
||||
params->append(cboShortcutTool);
|
||||
addParams();
|
||||
}
|
||||
}
|
||||
@@ -68,23 +115,45 @@ GeneralKeysPanel::GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSe
|
||||
connect(reset, &QPushButton::clicked, [&] ()
|
||||
{
|
||||
generalSettings.setDefaultKeyShortcuts();
|
||||
|
||||
foreach(AutoComboBox *cb, findChildren<AutoComboBox*>())
|
||||
cb->updateValue();
|
||||
|
||||
update();
|
||||
initComboQMGroup();
|
||||
});
|
||||
params->append(reset);
|
||||
addParams();
|
||||
|
||||
update();
|
||||
initComboQMGroup();
|
||||
addVSpring(grid, 0, grid->rowCount());
|
||||
addHSpring(grid, grid->columnCount(), 0);
|
||||
disableMouseScrolling();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
GeneralKeysPanel::~GeneralKeysPanel()
|
||||
{
|
||||
if (cboShortcutTools) {
|
||||
delete cboShortcutTools; // dialog destructor will delete members
|
||||
}
|
||||
|
||||
if (cboShortcuts) {
|
||||
delete cboShortcuts; // dialog destructor will delete members
|
||||
}
|
||||
|
||||
if (strKeyShortcutTools) {
|
||||
for (auto it = strKeyShortcutTools->begin(); it != strKeyShortcutTools->end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
delete strKeyShortcutTools;
|
||||
}
|
||||
|
||||
if (params) {
|
||||
for (auto it = params->begin(); it != params->end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
delete params;
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralKeysPanel::addLabel(QString text)
|
||||
@@ -132,3 +201,62 @@ void GeneralKeysPanel::initComboQMGroup()
|
||||
cboQMGrp->handleActivated(cbo, cbo->currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralKeysPanel::on_shortcutChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
const int idx = sender()->property("index").toInt();
|
||||
if (generalSettings.keyShortcuts[idx] == GeneralSettings::QM_APP)
|
||||
cboShortcutTools->at(idx)->setCurrentIndex(0);
|
||||
setToolName(idx);
|
||||
updateRow(idx);
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralKeysPanel::on_shortcutToolChanged()
|
||||
{
|
||||
if (!lock) {
|
||||
bool ok;
|
||||
const int index = sender()->property("index").toInt(&ok);
|
||||
if (ok) setToolName(index);
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralKeysPanel::setToolName(int index)
|
||||
{
|
||||
if (generalSettings.keyShortcutTools[index])
|
||||
delete generalSettings.keyShortcutTools[index];
|
||||
|
||||
if (generalSettings.keyShortcuts[index] == GeneralSettings::QM_APP) {
|
||||
// obtain current value from proxy
|
||||
std::string str = strKeyShortcutTools->at(index)->toStdString();
|
||||
generalSettings.keyShortcutTools[index] = new char[str.size() + 1];
|
||||
strncpy(generalSettings.keyShortcutTools[index], str.c_str(), str.size());
|
||||
generalSettings.keyShortcutTools[index][str.size()] = 0;
|
||||
} else {
|
||||
generalSettings.keyShortcutTools[index] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralKeysPanel::update()
|
||||
{
|
||||
const int cnt = cboShortcuts->count();
|
||||
for (int i = 0; i < cnt; i++)
|
||||
updateRow(i);
|
||||
|
||||
}
|
||||
|
||||
void GeneralKeysPanel::updateRow(const int index)
|
||||
{
|
||||
lock = true;
|
||||
cboShortcuts->at(index)->updateValue();
|
||||
|
||||
if (generalSettings.keyShortcuts[index] == GeneralSettings::QM_APP) {
|
||||
cboShortcutTools->at(index)->updateValue();
|
||||
cboShortcutTools->at(index)->setVisible(true);
|
||||
} else {
|
||||
cboShortcutTools->at(index)->setVisible(false);
|
||||
}
|
||||
|
||||
lock = false;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "generaledit.h"
|
||||
#include "autocombobox.h"
|
||||
|
||||
class ExclusiveComboGroup;
|
||||
class QGridLayout;
|
||||
@@ -34,17 +35,28 @@ class GeneralKeysPanel : public GeneralPanel
|
||||
GeneralKeysPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
virtual ~GeneralKeysPanel();
|
||||
|
||||
private slots:
|
||||
void on_shortcutChanged();
|
||||
void on_shortcutToolChanged();
|
||||
|
||||
private:
|
||||
Board::Type board;
|
||||
QGridLayout *grid;
|
||||
QList<QWidget *> *params;
|
||||
int row;
|
||||
int col;
|
||||
bool lock;
|
||||
ExclusiveComboGroup *cboQMGrp;
|
||||
QList<AutoComboBox *> *cboShortcuts;
|
||||
QList<AutoComboBox *> *cboShortcutTools;
|
||||
QList<QString *> *strKeyShortcutTools;
|
||||
|
||||
void addLabel(QString text);
|
||||
void addLine();
|
||||
void addParams();
|
||||
void addSection(QString text);
|
||||
void initComboQMGroup();
|
||||
void setToolName(int index);
|
||||
void update();
|
||||
void updateRow(const int index);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user