Merge pull request #2281 from opentx/romolo/curveeditor_cutandpaste

Romolo/curveeditor cutandpaste
This commit is contained in:
Bertrand Songis
2015-05-11 06:40:51 +02:00
5 changed files with 696 additions and 3790 deletions
+58 -58
View File
@@ -7,6 +7,7 @@
#include <QCheckBox> #include <QCheckBox>
#include <QPushButton> #include <QPushButton>
#include <QMessageBox> #include <QMessageBox>
#include <QAction>
#define GFX_MARGIN 16 #define GFX_MARGIN 16
@@ -119,20 +120,6 @@ Curves::Curves(QWidget * parent, ModelData & model, GeneralSettings & generalSet
for (int i=0; i<numcurves; i++) { for (int i=0; i<numcurves; i++) {
visibleCurves[i] = false; visibleCurves[i] = false;
// The reset curve button
QPushButton * reset = new QPushButton(this);
reset->setProperty("index", i);
reset->setMinimumSize(QSize(0, 0));
reset->setMaximumSize(QSize(16, 16));
reset->setIcon(CompanionIcon("clear.png"));
reset->setIconSize(QSize(14, 14));
connect(reset, SIGNAL(clicked()), this, SLOT(resetCurve()));
if (i<limit) {
ui->curvesLayout->addWidget(reset, i, 0, 1, 1);
} else {
ui->curvesLayout2->addWidget(reset, i-limit, 0, 1, 1);
}
// The edit curve button // The edit curve button
QPushButton * edit = new QPushButton(this); QPushButton * edit = new QPushButton(this);
edit->setProperty("index", i); edit->setProperty("index", i);
@@ -146,6 +133,8 @@ Curves::Curves(QWidget * parent, ModelData & model, GeneralSettings & generalSet
#endif #endif
edit->setPalette(palette); edit->setPalette(palette);
edit->setText(tr("Curve %1").arg(i+1)); edit->setText(tr("Curve %1").arg(i+1));
edit->setContextMenuPolicy(Qt::CustomContextMenu);
connect(edit, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&)));
connect(edit, SIGNAL(clicked()), this, SLOT(editCurve())); connect(edit, SIGNAL(clicked()), this, SLOT(editCurve()));
if (i<limit) { if (i<limit) {
ui->curvesLayout->addWidget(edit, i, 1, 1, 1); ui->curvesLayout->addWidget(edit, i, 1, 1, 1);
@@ -224,18 +213,6 @@ void Curves::editCurve()
update(); update();
} }
void Curves::resetCurve()
{
QPushButton *button = (QPushButton *)sender();
int index = button->property("index").toInt();
int res = QMessageBox::question(this, "companion", tr("Are you sure you want to reset curve %1 ?").arg(index+1), QMessageBox::Yes | QMessageBox::No);
if (res == QMessageBox::Yes) {
model->curves[index].clear(5);
update();
emit modified();
}
}
void Curves::plotCurve(bool checked) void Curves::plotCurve(bool checked)
{ {
QCheckBox *chk = (QCheckBox *)sender(); QCheckBox *chk = (QCheckBox *)sender();
@@ -588,41 +565,64 @@ void Curves::on_curveApply_clicked()
emit modified(); emit modified();
} }
#if 0 void Curves::ShowContextMenu(const QPoint& pos) // this is a slot
void ModelEdit::clearCurves(bool ask)
{ {
if (ask) { QPushButton *button = (QPushButton *)sender();
int res = QMessageBox::question(this, tr("Clear Curves?"), tr("Really clear all the curves?"), QMessageBox::Yes | QMessageBox::No); int index = button->property("index").toInt();
if (res!=QMessageBox::Yes) return; const QClipboard *clipboard = QApplication::clipboard();
const QMimeData *mimeData = clipboard->mimeData();
QPoint globalPos = button->mapToGlobal(pos);
QMenu myMenu;
QAction *action;
action = myMenu.addAction(CompanionIcon("copy.png"),tr("Copy"));
action->setProperty("index", CURVE_COPY);
action = myMenu.addAction(CompanionIcon("paste.png"),tr("Paste"));
if (!mimeData->hasFormat("application/x-companion-curve-item")) {
action->setEnabled(false);
}
action->setProperty("index", CURVE_PASTE);
action = myMenu.addAction(CompanionIcon("clear.png"),tr("Clear"));
action->setProperty("index", CURVE_RESET);
action = myMenu.addAction(CompanionIcon("clear.png"),tr("Clear all curves"));
action->setProperty("index", CURVE_RESETALL);
QAction* selectedItem = myMenu.exec(globalPos);
if (selectedItem) {
int action=selectedItem->property("index").toInt();
if (action==CURVE_COPY) {
QByteArray curveData;
QMimeData *mimeData2 = new QMimeData;
curveData.append((char*)&model->curves[index], sizeof(CurveData));
mimeData2->setData("application/x-companion-curve-item", curveData);
QApplication::clipboard()->setMimeData(mimeData2, QClipboard::Clipboard);
} }
curvesLock=true; else if (action==CURVE_PASTE) {
for (int j=0; j<16; j++) { QByteArray curveData = mimeData->data("application/x-companion-curve-item");
model->curves[j].count = 5; CurveData *curve = &model->curves[index];
model->curves[j].custom = false; memcpy(curve, curveData.constData(), sizeof(CurveData));
memset(model->curves[j].name, 0, sizeof(model->curves[j].name)); update();
for (int i=0; i<17; i++) { emit modified();
model->curves[j].points[i].x = 0; }
model->curves[j].points[i].y = 0; else if (action==CURVE_RESET) {
int res = QMessageBox::question(this, "companion", tr("Are you sure you want to reset curve %1?").arg(index+1), QMessageBox::Yes | QMessageBox::No);
if (res == QMessageBox::Yes) {
model->curves[index].clear(5);
update();
emit modified();
} }
} }
for (int i=0; i<17; i++) { else if (action==CURVE_RESETALL) {
spnx[i]->setMinimum(-100); int res = QMessageBox::question(this, "companion", tr("Are you sure you want to reset all curves?"), QMessageBox::Yes | QMessageBox::No);
spnx[i]->setMaximum(100); if (res == QMessageBox::Yes) {
spnx[i]->setValue(0); int numcurves = firmware->getCapability(NumCurves);
spny[i]->setValue(0); for (int i=0; i<numcurves; i++) {
model->curves[i].clear(5);
}
update();
emit modified();
}
} }
currentCurve=0; }
curvesLock=false;
ui->curvetype_CB->setCurrentIndex(2);
ui->curveName->clear();
updateSettings();
drawCurve();
} }
void ModelEdit::ControlCurveSignal(bool flag)
{
foreach(QSpinBox *sb, findChildren<QSpinBox *>(QRegExp("curvePt[0-9]+"))) {
sb->blockSignals(flag);
}
}
#endif
+8 -1
View File
@@ -5,6 +5,13 @@
#include "eeprominterface.h" #include "eeprominterface.h"
#include <QSpinBox> #include <QSpinBox>
enum CopyAction {
CURVE_COPY,
CURVE_PASTE,
CURVE_RESET,
CURVE_RESETALL
};
namespace Ui { namespace Ui {
class Curves; class Curves;
} }
@@ -28,8 +35,8 @@ class Curves : public ModelPanel
virtual void update(); virtual void update();
private slots: private slots:
void resetCurve();
void editCurve(); void editCurve();
void ShowContextMenu(const QPoint& pos);
void plotCurve(bool checked); void plotCurve(bool checked);
void on_curveName_editingFinished(); void on_curveName_editingFinished();
void on_curvePoints_currentIndexChanged(int index); void on_curvePoints_currentIndexChanged(int index);
+1 -1
View File
@@ -563,7 +563,7 @@ void CustomFunctionsPanel::fswPaste()
if (mimeData->hasFormat("application/x-companion-fsw")) { if (mimeData->hasFormat("application/x-companion-fsw")) {
QByteArray fswData = mimeData->data("application/x-companion-fsw"); QByteArray fswData = mimeData->data("application/x-companion-fsw");
CustomFunctionData *fsw = &functions[selectedFunction]; CustomFunctionData *fsw = &functions[selectedFunction];
memcpy(fsw, fswData.mid(0, sizeof(CustomFunctionData)).constData(), sizeof(CustomFunctionData)); memcpy(fsw, fswData.constData(), sizeof(CustomFunctionData));
lock = true; lock = true;
populateSwitchCB(fswtchSwtch[selectedFunction], functions[selectedFunction].swtch, generalSettings, model ? SpecialFunctionsContext : GlobalFunctionsContext); populateSwitchCB(fswtchSwtch[selectedFunction], functions[selectedFunction].swtch, generalSettings, model ? SpecialFunctionsContext : GlobalFunctionsContext);
populateFuncCB(fswtchFunc[selectedFunction], functions[selectedFunction].func); populateFuncCB(fswtchFunc[selectedFunction], functions[selectedFunction].func);
+9 -9
View File
@@ -461,15 +461,15 @@ void LogicalSwitchesPanel::update()
void LogicalSwitchesPanel::cswPaste() void LogicalSwitchesPanel::cswPaste()
{ {
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-csw")) { if (mimeData->hasFormat("application/x-companion-csw")) {
QByteArray cswData = mimeData->data("application/x-companion-csw"); QByteArray cswData = mimeData->data("application/x-companion-csw");
LogicalSwitchData *csw = &model->logicalSw[selectedSwitch]; LogicalSwitchData *csw = &model->logicalSw[selectedSwitch];
memcpy(csw, cswData.mid(0, sizeof(LogicalSwitchData)).constData(), sizeof(LogicalSwitchData)); memcpy(csw, cswData.constData(), sizeof(LogicalSwitchData));
emit modified(); emit modified();
updateLine(selectedSwitch); updateLine(selectedSwitch);
} }
} }
void LogicalSwitchesPanel::cswDelete() void LogicalSwitchesPanel::cswDelete()
File diff suppressed because it is too large Load Diff