Context menu enhancements (#7029)
This commit is contained in:
committed by
Bertrand Songis
parent
4b15e3910c
commit
135effa536
@@ -74,7 +74,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
|||||||
{
|
{
|
||||||
Stopwatch s1("CustomFunctionsPanel - populate");
|
Stopwatch s1("CustomFunctionsPanel - populate");
|
||||||
lock = true;
|
lock = true;
|
||||||
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
|
fswCapability = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
|
||||||
|
|
||||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext, this);
|
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext, this);
|
||||||
rawSrcAllItemModel = new RawSourceFilterItemModel(&generalSettings, model, this);
|
rawSrcAllItemModel = new RawSourceFilterItemModel(&generalSettings, model, this);
|
||||||
@@ -83,7 +83,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
|||||||
|
|
||||||
if (!firmware->getCapability(VoicesAsNumbers)) {
|
if (!firmware->getCapability(VoicesAsNumbers)) {
|
||||||
tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
|
tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
|
||||||
for (int i=0; i<num_fsw; i++) {
|
for (int i=0; i<fswCapability; i++) {
|
||||||
if (functions[i].func==FuncPlayPrompt || functions[i].func==FuncBackgroundMusic) {
|
if (functions[i].func==FuncPlayPrompt || functions[i].func==FuncBackgroundMusic) {
|
||||||
QString temp = functions[i].paramarm;
|
QString temp = functions[i].paramarm;
|
||||||
if (!temp.isEmpty()) {
|
if (!temp.isEmpty()) {
|
||||||
@@ -97,7 +97,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
|||||||
|
|
||||||
if (IS_STM32(firmware->getBoard())) {
|
if (IS_STM32(firmware->getBoard())) {
|
||||||
scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS/FUNCTIONS", QStringList() << "*.lua", firmware->getCapability(VoicesMaxLength));
|
scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS/FUNCTIONS", QStringList() << "*.lua", firmware->getCapability(VoicesMaxLength));
|
||||||
for (int i=0; i<num_fsw; i++) {
|
for (int i=0; i<fswCapability; i++) {
|
||||||
if (functions[i].func==FuncPlayScript) {
|
if (functions[i].func==FuncPlayScript) {
|
||||||
QString temp = functions[i].paramarm;
|
QString temp = functions[i].paramarm;
|
||||||
if (!temp.isEmpty()) {
|
if (!temp.isEmpty()) {
|
||||||
@@ -113,9 +113,9 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
|||||||
|
|
||||||
QStringList headerLabels;
|
QStringList headerLabels;
|
||||||
headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << tr("Enable");
|
headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << tr("Enable");
|
||||||
TableLayout * tableLayout = new TableLayout(this, num_fsw, headerLabels);
|
TableLayout * tableLayout = new TableLayout(this, fswCapability, headerLabels);
|
||||||
|
|
||||||
for (int i=0; i<num_fsw; i++) {
|
for (int i=0; i<fswCapability; i++) {
|
||||||
// The label
|
// The label
|
||||||
QLabel * label = new QLabel(this);
|
QLabel * label = new QLabel(this);
|
||||||
label->setContextMenuPolicy(Qt::CustomContextMenu);
|
label->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
@@ -244,7 +244,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
|||||||
tableLayout->resizeColumnsToContents();
|
tableLayout->resizeColumnsToContents();
|
||||||
s1.report("resizeColumnsToContents");
|
s1.report("resizeColumnsToContents");
|
||||||
tableLayout->setColumnWidth(3, 300);
|
tableLayout->setColumnWidth(3, 300);
|
||||||
tableLayout->pushRowsUp(num_fsw+1);
|
tableLayout->pushRowsUp(fswCapability+1);
|
||||||
s1.report("end");
|
s1.report("end");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,7 +579,6 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
|||||||
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
|
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fswtchFunc[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_SHOW_FUNC);
|
fswtchFunc[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_SHOW_FUNC);
|
||||||
@@ -603,8 +602,7 @@ void CustomFunctionsPanel::update()
|
|||||||
{
|
{
|
||||||
updateDataModels();
|
updateDataModels();
|
||||||
lock = true;
|
lock = true;
|
||||||
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
|
for (int i=0; i<fswCapability; i++) {
|
||||||
for (int i=0; i<num_fsw; i++) {
|
|
||||||
refreshCustomFunction(i);
|
refreshCustomFunction(i);
|
||||||
}
|
}
|
||||||
lock = false;
|
lock = false;
|
||||||
@@ -614,30 +612,28 @@ void CustomFunctionsPanel::fswPaste()
|
|||||||
{
|
{
|
||||||
const QClipboard *clipboard = QApplication::clipboard();
|
const QClipboard *clipboard = QApplication::clipboard();
|
||||||
const QMimeData *mimeData = clipboard->mimeData();
|
const QMimeData *mimeData = clipboard->mimeData();
|
||||||
if (mimeData->hasFormat("application/x-companion-fsw")) {
|
if (mimeData->hasFormat(MIMETYPE_FSW)) {
|
||||||
QByteArray fswData = mimeData->data("application/x-companion-fsw");
|
QByteArray fswData = mimeData->data(MIMETYPE_FSW);
|
||||||
CustomFunctionData *fsw = &functions[selectedFunction];
|
CustomFunctionData *fsw = &functions[selectedFunction];
|
||||||
memcpy(fsw, fswData.constData(), sizeof(CustomFunctionData));
|
memcpy(fsw, fswData.constData(), sizeof(CustomFunctionData));
|
||||||
lock = true;
|
resetCBsAndRefresh(selectedFunction);
|
||||||
fswtchSwtch[selectedFunction]->setCurrentIndex(fswtchSwtch[selectedFunction]->findData(functions[selectedFunction].swtch.toValue()));
|
|
||||||
fswtchFunc[selectedFunction]->setCurrentIndex(fswtchFunc[selectedFunction]->findData(functions[selectedFunction].func));
|
|
||||||
populateGVmodeCB(fswtchGVmode[selectedFunction], functions[selectedFunction].adjustMode);
|
|
||||||
populateFuncParamCB(fswtchParamT[selectedFunction], functions[selectedFunction].func, functions[selectedFunction].param, functions[selectedFunction].adjustMode);
|
|
||||||
refreshCustomFunction(selectedFunction);
|
|
||||||
lock = false;
|
|
||||||
emit modified();
|
emit modified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomFunctionsPanel::fswDelete()
|
void CustomFunctionsPanel::fswDelete()
|
||||||
{
|
{
|
||||||
functions[selectedFunction].clear();
|
int maxidx = fswCapability - 1;
|
||||||
// TODO update switch and func
|
for (int i=selectedFunction; i<maxidx; i++) {
|
||||||
lock = true;
|
if (!functions[i].isEmpty() || !functions[i+1].isEmpty()) {
|
||||||
fswtchSwtch[selectedFunction]->setCurrentIndex(fswtchSwtch[selectedFunction]->findData(functions[selectedFunction].swtch.toValue()));
|
CustomFunctionData *fsw1 = &functions[i];
|
||||||
fswtchFunc[selectedFunction]->setCurrentIndex(fswtchFunc[selectedFunction]->findData(functions[selectedFunction].func));
|
CustomFunctionData *fsw2 = &functions[i+1];
|
||||||
refreshCustomFunction(selectedFunction);
|
memcpy(fsw1, fsw2, sizeof(CustomFunctionData));
|
||||||
lock = false;
|
resetCBsAndRefresh(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
functions[maxidx].clear();
|
||||||
|
resetCBsAndRefresh(maxidx);
|
||||||
emit modified();
|
emit modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,34 +642,44 @@ void CustomFunctionsPanel::fswCopy()
|
|||||||
QByteArray fswData;
|
QByteArray fswData;
|
||||||
fswData.append((char*)&functions[selectedFunction], sizeof(CustomFunctionData));
|
fswData.append((char*)&functions[selectedFunction], sizeof(CustomFunctionData));
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
mimeData->setData("application/x-companion-fsw", fswData);
|
mimeData->setData(MIMETYPE_FSW, fswData);
|
||||||
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
|
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomFunctionsPanel::fswCut()
|
void CustomFunctionsPanel::fswCut()
|
||||||
{
|
{
|
||||||
fswCopy();
|
fswCopy();
|
||||||
fswDelete();
|
fswClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomFunctionsPanel::fsw_customContextMenuRequested(QPoint pos)
|
void CustomFunctionsPanel::fsw_customContextMenuRequested(QPoint pos)
|
||||||
{
|
{
|
||||||
QLabel *label = (QLabel *)sender();
|
QLabel *label = (QLabel *)sender();
|
||||||
selectedFunction = label->property("index").toInt();
|
selectedFunction = label->property("index").toInt();
|
||||||
|
|
||||||
QPoint globalPos = label->mapToGlobal(pos);
|
QPoint globalPos = label->mapToGlobal(pos);
|
||||||
|
|
||||||
const QClipboard *clipboard = QApplication::clipboard();
|
const QClipboard *clipboard = QApplication::clipboard();
|
||||||
const QMimeData *mimeData = clipboard->mimeData();
|
const QMimeData *mimeData = clipboard->mimeData();
|
||||||
bool hasData = mimeData->hasFormat("application/x-companion-fsw");
|
bool hasData = mimeData->hasFormat(MIMETYPE_FSW);
|
||||||
|
bool moveUpAllowed = (selectedFunction > 0);
|
||||||
|
bool moveDownAllowed = (selectedFunction < (fswCapability - 1));
|
||||||
|
bool insertAllowed = (selectedFunction < (fswCapability - 1)) && (functions[fswCapability - 1].isEmpty());
|
||||||
|
|
||||||
QMenu contextMenu;
|
QMenu contextMenu;
|
||||||
contextMenu.addAction(CompanionIcon("copy.png"), tr("&Copy"),this,SLOT(fswCopy()));
|
contextMenu.addAction(CompanionIcon("copy.png"), tr("Copy"),this,SLOT(fswCopy()));
|
||||||
contextMenu.addAction(CompanionIcon("cut.png"), tr("&Cut"),this,SLOT(fswCut()));
|
contextMenu.addAction(CompanionIcon("cut.png"), tr("Cut"),this,SLOT(fswCut()));
|
||||||
contextMenu.addAction(CompanionIcon("paste.png"), tr("&Paste"),this,SLOT(fswPaste()))->setEnabled(hasData);
|
contextMenu.addAction(CompanionIcon("paste.png"), tr("Paste"),this,SLOT(fswPaste()))->setEnabled(hasData);
|
||||||
contextMenu.addAction(CompanionIcon("clear.png"), tr("&Delete"),this,SLOT(fswDelete()));
|
contextMenu.addAction(CompanionIcon("clear.png"), tr("Clear"),this,SLOT(fswClear()));
|
||||||
|
contextMenu.addSeparator();
|
||||||
|
contextMenu.addAction(CompanionIcon("arrow-right.png"), tr("Insert"),this,SLOT(fswInsert()))->setEnabled(insertAllowed);
|
||||||
|
contextMenu.addAction(CompanionIcon("arrow-left.png"), tr("Delete"),this,SLOT(fswDelete()));
|
||||||
|
contextMenu.addAction(CompanionIcon("moveup.png"), tr("Move Up"),this,SLOT(fswMoveUp()))->setEnabled(moveUpAllowed);
|
||||||
|
contextMenu.addAction(CompanionIcon("movedown.png"), tr("Move Down"),this,SLOT(fswMoveDown()))->setEnabled(moveDownAllowed);
|
||||||
|
contextMenu.addSeparator();
|
||||||
|
contextMenu.addAction(CompanionIcon("clear.png"), tr("Clear All"),this,SLOT(fswClearAll()));
|
||||||
|
|
||||||
contextMenu.exec(globalPos);
|
contextMenu.exec(globalPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomFunctionsPanel::populateFuncCB(QComboBox *b, unsigned int value)
|
void CustomFunctionsPanel::populateFuncCB(QComboBox *b, unsigned int value)
|
||||||
@@ -755,3 +761,65 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi
|
|||||||
b->hide();
|
b->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomFunctionsPanel::fswMoveUp()
|
||||||
|
{
|
||||||
|
swapFuncData(selectedFunction, selectedFunction - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomFunctionsPanel::fswMoveDown()
|
||||||
|
{
|
||||||
|
swapFuncData(selectedFunction, selectedFunction + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomFunctionsPanel::fswClear()
|
||||||
|
{
|
||||||
|
functions[selectedFunction].clear();
|
||||||
|
resetCBsAndRefresh(selectedFunction);
|
||||||
|
emit modified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomFunctionsPanel::fswClearAll()
|
||||||
|
{
|
||||||
|
for (int i=0; i<fswCapability; i++) {
|
||||||
|
functions[i].clear();
|
||||||
|
resetCBsAndRefresh(i);
|
||||||
|
}
|
||||||
|
emit modified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomFunctionsPanel::fswInsert()
|
||||||
|
{
|
||||||
|
for (int i=(fswCapability - 1); i>selectedFunction; i--) {
|
||||||
|
if (!functions[i].isEmpty() || !functions[i-1].isEmpty()) {
|
||||||
|
memcpy(&functions[i], &functions[i-1], sizeof(CustomFunctionData));
|
||||||
|
resetCBsAndRefresh(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fswClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomFunctionsPanel::swapFuncData(int idx1, int idx2)
|
||||||
|
{
|
||||||
|
if ((idx1 != idx2) && (!functions[idx1].isEmpty() || !functions[idx2].isEmpty())) {
|
||||||
|
CustomFunctionData fswtmp = functions[idx2];
|
||||||
|
CustomFunctionData *fsw1 = &functions[idx1];
|
||||||
|
CustomFunctionData *fsw2 = &functions[idx2];
|
||||||
|
memcpy(fsw2, fsw1, sizeof(CustomFunctionData));
|
||||||
|
memcpy(fsw1, &fswtmp, sizeof(CustomFunctionData));
|
||||||
|
resetCBsAndRefresh(idx1);
|
||||||
|
resetCBsAndRefresh(idx2);
|
||||||
|
emit modified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomFunctionsPanel::resetCBsAndRefresh(int idx)
|
||||||
|
{
|
||||||
|
lock = true;
|
||||||
|
fswtchSwtch[idx]->setCurrentIndex(fswtchSwtch[idx]->findData(functions[idx].swtch.toValue()));
|
||||||
|
fswtchFunc[idx]->setCurrentIndex(fswtchFunc[idx]->findData(functions[idx].func));
|
||||||
|
fswtchGVmode[idx]->setCurrentIndex(functions[idx].adjustMode);
|
||||||
|
populateFuncParamCB(fswtchParamT[idx], functions[idx].func, functions[idx].param, functions[idx].adjustMode);
|
||||||
|
refreshCustomFunction(idx);
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class RawSourceFilterItemModel;
|
|||||||
class RawSwitchFilterItemModel;
|
class RawSwitchFilterItemModel;
|
||||||
class TimerEdit;
|
class TimerEdit;
|
||||||
|
|
||||||
|
constexpr char MIMETYPE_FSW[] = "application/x-companion-fsw";
|
||||||
|
|
||||||
class RepeatComboBox: public QComboBox
|
class RepeatComboBox: public QComboBox
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -53,7 +55,7 @@ class CustomFunctionsPanel : public GenericPanel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CustomFunctionsPanel(QWidget *parent, ModelData * mode, GeneralSettings & generalSettings, Firmware * firmware);
|
CustomFunctionsPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||||
~CustomFunctionsPanel();
|
~CustomFunctionsPanel();
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
@@ -77,11 +79,18 @@ class CustomFunctionsPanel : public GenericPanel
|
|||||||
void fswCopy();
|
void fswCopy();
|
||||||
void fswPaste();
|
void fswPaste();
|
||||||
void fswCut();
|
void fswCut();
|
||||||
|
void fswMoveUp();
|
||||||
|
void fswMoveDown();
|
||||||
|
void fswInsert();
|
||||||
|
void fswClear();
|
||||||
|
void fswClearAll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void populateFuncCB(QComboBox *b, unsigned int value);
|
void populateFuncCB(QComboBox *b, unsigned int value);
|
||||||
void populateGVmodeCB(QComboBox *b, unsigned int value);
|
void populateGVmodeCB(QComboBox *b, unsigned int value);
|
||||||
void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
|
void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
|
||||||
|
void swapFuncData(int idx1, int idx2);
|
||||||
|
void resetCBsAndRefresh(int idx);
|
||||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||||
RawSourceFilterItemModel * rawSrcAllItemModel;
|
RawSourceFilterItemModel * rawSrcAllItemModel;
|
||||||
RawSourceFilterItemModel * rawSrcInputsItemModel;
|
RawSourceFilterItemModel * rawSrcInputsItemModel;
|
||||||
@@ -105,6 +114,7 @@ class CustomFunctionsPanel : public GenericPanel
|
|||||||
QMediaPlayer * mediaPlayer;
|
QMediaPlayer * mediaPlayer;
|
||||||
|
|
||||||
int selectedFunction;
|
int selectedFunction;
|
||||||
|
int fswCapability;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user