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>
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
;
84 int CalibrationPanel::getCalibrationValue(int row
, int column
)
88 return generalSettings
.calibSpanNeg
[row
];
90 return generalSettings
.calibMid
[row
];
92 return generalSettings
.calibSpanPos
[row
];
97 void CalibrationPanel::setCalibrationValue(int row
, int column
, int value
)
101 generalSettings
.calibSpanNeg
[row
] = value
;
104 generalSettings
.calibMid
[row
] = value
;
107 generalSettings
.calibSpanPos
[row
] = value
;