[companion] Adjust GVAR not possible in global functions (fix #5425)
[opentx.git] / companion / src / generaledit / calibration.cpp
blobe07a874b11e3b38dcbdd0aa2c2784dda757d87d0
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <QVBoxLayout>
22 #include <QHeaderView>
23 #include <QSpinBox>
24 #include "calibration.h"
27 CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware):
28 GeneralPanel(parent, generalSettings, firmware)
31 tableWidget = new QTableWidget();
32 QVBoxLayout * layout = new QVBoxLayout();
33 layout->addWidget(tableWidget);
34 layout->setContentsMargins(0, 0, 0, 0);
35 this->setLayout(layout);
37 tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
38 tableWidget->setColumnCount(3);
39 tableWidget->setShowGrid(false);
40 tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
41 tableWidget->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
42 tableWidget->setStyleSheet("QTableWidget {background-color: transparent;}");
43 QStringList headerLabels;
44 headerLabels << QObject::tr("Negative span") << QObject::tr("Mid value") << QObject::tr("Positive span");
45 tableWidget->setHorizontalHeaderLabels(headerLabels);
47 int rows = CPN_MAX_STICKS + getBoardCapability(getCurrentBoard(), Board::Pots) + getBoardCapability(getCurrentBoard(), Board::Sliders) + getBoardCapability(getCurrentBoard(), Board::MouseAnalogs);
48 tableWidget->setRowCount(rows);
50 for(int i = 0; i < rows; ++i) {
52 QTableWidgetItem *newItem = new QTableWidgetItem(firmware->getAnalogInputName(i));
53 newItem->setTextAlignment(Qt::AlignLeft);
54 tableWidget->setVerticalHeaderItem(i, newItem);
56 for(int j = 0; j < 3; ++j) {
57 QSpinBox * newItem = new QSpinBox();
58 newItem->setMinimum(-9999);
59 newItem->setMaximum(9999);
60 newItem->setSingleStep(1);
61 newItem->setValue(getCalibrationValue(i, j));
62 newItem->setProperty("row", i);
63 newItem->setProperty("column", j);
64 tableWidget->setCellWidget(i, j, newItem);
65 connect(newItem, SIGNAL(valueChanged(int)), this, SLOT(onCellChanged(int)));
68 disableMouseScrolling();
71 void CalibrationPanel::onCellChanged(int value)
73 QSpinBox * sb = qobject_cast<QSpinBox*>(sender());
74 int row = sb->property("row").toInt();
75 int column = sb->property("column").toInt();
77 if (value != getCalibrationValue(row, column)) {
78 setCalibrationValue(row,column, value);
79 qDebug() << "CalibrationPanel::onCellChanged" << row << column << "to" << value;
80 emit modified();
84 int CalibrationPanel::getCalibrationValue(int row, int column)
86 switch(column) {
87 case 0:
88 return generalSettings.calibSpanNeg[row];
89 case 1:
90 return generalSettings.calibMid[row];
91 case 2:
92 return generalSettings.calibSpanPos[row];
94 return 0;
97 void CalibrationPanel::setCalibrationValue(int row, int column, int value)
99 switch(column) {
100 case 0:
101 generalSettings.calibSpanNeg[row] = value;
102 break;
103 case 1:
104 generalSettings.calibMid[row] = value;
105 break;
106 case 2:
107 generalSettings.calibSpanPos[row] = value;
108 break;