31 #include "onscreendisplaysettings.h"
32 #include "onscreendisplaypagesettings.h"
34 #include "manualcontrolcommand.h"
35 #include "manualcontrolsettings.h"
37 #include "ui_osdpage.h"
50 connect(ui->applyButton, &QAbstractButton::clicked,
this, &ConfigOsdWidget::setCustomText);
51 connect(ui->saveButton, &QAbstractButton::clicked,
this, &ConfigOsdWidget::setCustomText);
52 connect(ui->reloadButton, &QAbstractButton::clicked,
this, &ConfigOsdWidget::getCustomText);
53 connect(osdSettingsObj, &OnScreenDisplaySettings::CustomText_0Changed,
this,
54 &ConfigOsdWidget::getCustomText);
58 &ConfigOsdWidget::movePageSlider);
60 this, &ConfigOsdWidget::updatePositionSlider);
63 pages[0] = ui->osdPage1;
64 pages[1] = ui->osdPage2;
65 pages[2] = ui->osdPage3;
66 pages[3] = ui->osdPage4;
68 ui_pages[0] =
new Ui::OsdPage();
69 setupOsdPage(ui_pages[0], ui->osdPage1, QStringLiteral(
"OnScreenDisplayPageSettings"));
71 ui_pages[0]->copyButton1->setText(
"Copy Page 2");
72 ui_pages[0]->copyButton2->setText(
"Copy Page 3");
73 ui_pages[0]->copyButton3->setText(
"Copy Page 4");
75 connect(ui_pages[0]->copyButton1, &QAbstractButton::released,
this, [
this]() {
78 connect(ui_pages[0]->copyButton2, &QAbstractButton::released,
this, [
this]() {
81 connect(ui_pages[0]->copyButton3, &QAbstractButton::released,
this, [
this]() {
85 ui_pages[1] =
new Ui::OsdPage();
86 setupOsdPage(ui_pages[1], ui->osdPage2, QStringLiteral(
"OnScreenDisplayPageSettings2"));
88 ui_pages[1]->copyButton1->setText(
"Copy Page 1");
89 ui_pages[1]->copyButton2->setText(
"Copy Page 3");
90 ui_pages[1]->copyButton3->setText(
"Copy Page 4");
92 connect(ui_pages[1]->copyButton1, &QAbstractButton::released,
this, [
this]() {
95 connect(ui_pages[1]->copyButton2, &QAbstractButton::released,
this, [
this]() {
98 connect(ui_pages[1]->copyButton3, &QAbstractButton::released,
this, [
this]() {
102 ui_pages[2] =
new Ui::OsdPage();
103 setupOsdPage(ui_pages[2], ui->osdPage3, QStringLiteral(
"OnScreenDisplayPageSettings3"));
105 ui_pages[2]->copyButton1->setText(
"Copy Page 1");
106 ui_pages[2]->copyButton2->setText(
"Copy Page 2");
107 ui_pages[2]->copyButton3->setText(
"Copy Page 4");
109 connect(ui_pages[2]->copyButton1, &QAbstractButton::released,
this, [
this]() {
112 connect(ui_pages[2]->copyButton2, &QAbstractButton::released,
this, [
this]() {
115 connect(ui_pages[2]->copyButton3, &QAbstractButton::released,
this, [
this]() {
119 ui_pages[3] =
new Ui::OsdPage();
120 setupOsdPage(ui_pages[3], ui->osdPage4, QStringLiteral(
"OnScreenDisplayPageSettings4"));
122 ui_pages[3]->copyButton1->setText(
"Copy Page 1");
123 ui_pages[3]->copyButton2->setText(
"Copy Page 2");
124 ui_pages[3]->copyButton3->setText(
"Copy Page 3");
126 connect(ui_pages[3]->copyButton1, &QAbstractButton::released,
this, [
this]() {
129 connect(ui_pages[3]->copyButton2, &QAbstractButton::released,
this, [
this]() {
132 connect(ui_pages[3]->copyButton3, &QAbstractButton::released,
this, [
this]() {
149 for (
auto p : ui_pages)
160 quint8 ConfigOsdWidget::scaleSwitchChannel(quint8 channelNumber, quint8 switchPositions)
162 if (channelNumber > (ManualControlSettings::CHANNELMIN_NUMELEM - 1))
164 ManualControlSettings::DataFields manualSettingsDataPriv = manualSettingsObj->getData();
165 ManualControlCommand::DataFields manualCommandDataPriv = manualCommandObj->getData();
168 int chMin = manualSettingsDataPriv.ChannelMin[channelNumber];
169 int chMax = manualSettingsDataPriv.ChannelMax[channelNumber];
170 int chNeutral = manualSettingsDataPriv.ChannelNeutral[channelNumber];
172 int value = manualCommandDataPriv.Channel[channelNumber];
173 if ((chMax > chMin && value >= chNeutral) || (chMin > chMax && value <= chNeutral)) {
174 if (chMax != chNeutral)
175 valueScaled = (float)(value - chNeutral) / (float)(chMax - chNeutral);
179 if (chMin != chNeutral)
180 valueScaled = (float)(value - chNeutral) / (float)(chNeutral - chMin);
185 if (valueScaled < -1.0)
187 else if (valueScaled > 1.0)
192 quint8 pos = ((qint16)(valueScaled * 256) + 256) * switchPositions >> 9;
193 if (pos >= switchPositions)
194 pos = switchPositions - 1;
199 void ConfigOsdWidget::movePageSlider()
201 OnScreenDisplaySettings::DataFields onScreenDisplaySettingsDataPriv = osdSettingsObj->getData();
203 switch (onScreenDisplaySettingsDataPriv.PageSwitch) {
204 case OnScreenDisplaySettings::PAGESWITCH_ACCESSORY0:
205 ui->osdPageSlider->setValue(scaleSwitchChannel(ManualControlSettings::CHANNELMIN_ACCESSORY0,
206 onScreenDisplaySettingsDataPriv.NumPages));
208 case OnScreenDisplaySettings::PAGESWITCH_ACCESSORY1:
209 ui->osdPageSlider->setValue(scaleSwitchChannel(ManualControlSettings::CHANNELMIN_ACCESSORY1,
210 onScreenDisplaySettingsDataPriv.NumPages));
212 case OnScreenDisplaySettings::PAGESWITCH_ACCESSORY2:
213 ui->osdPageSlider->setValue(scaleSwitchChannel(ManualControlSettings::CHANNELMIN_ACCESSORY2,
214 onScreenDisplaySettingsDataPriv.NumPages));
219 void ConfigOsdWidget::updatePositionSlider()
221 OnScreenDisplaySettings::DataFields onScreenDisplaySettingsDataPriv = osdSettingsObj->getData();
223 switch (onScreenDisplaySettingsDataPriv.NumPages) {
226 ui->osdPagePos6->setEnabled(
true);
229 ui->osdPagePos5->setEnabled(
true);
232 ui->osdPagePos4->setEnabled(
true);
235 ui->osdPagePos3->setEnabled(
true);
238 ui->osdPagePos2->setEnabled(
true);
241 ui->osdPagePos1->setEnabled(
true);
247 switch (onScreenDisplaySettingsDataPriv.NumPages) {
249 ui->osdPagePos1->setEnabled(
false);
252 ui->osdPagePos2->setEnabled(
false);
255 ui->osdPagePos3->setEnabled(
false);
258 ui->osdPagePos4->setEnabled(
false);
261 ui->osdPagePos5->setEnabled(
false);
264 ui->osdPagePos6->setEnabled(
false);
272 void ConfigOsdWidget::setCustomText()
274 const QString text = ui->le_custom_text->displayText();
275 unsigned int n_string = text.size();
277 for (
unsigned int i = 0;
i < OnScreenDisplaySettings::CUSTOMTEXT_NUMELEM; ++
i) {
279 osdSettingsObj->setCustomText(
i, (quint8)(text.data()[
i].toLatin1()));
281 osdSettingsObj->setCustomText(
i, 0);
286 void ConfigOsdWidget::getCustomText()
288 char text[OnScreenDisplaySettings::CUSTOMTEXT_NUMELEM];
290 for (
unsigned int i = 0;
i < OnScreenDisplaySettings::CUSTOMTEXT_NUMELEM; ++
i) {
291 text[
i] = osdSettingsObj->getCustomText(
i);
293 QString q_text = QString::fromLatin1(text, OnScreenDisplaySettings::CUSTOMTEXT_NUMELEM);
294 ui->le_custom_text->setText(q_text);
297 void ConfigOsdWidget::setupOsdPage(Ui::OsdPage *page, QWidget *page_widget,
const QString &objName)
299 page->setupUi(page_widget);
300 const QString nameRel = QStringLiteral(
"objname:%0").arg(objName);
302 for (
const auto wid : page_widget->findChildren<QWidget *>()) {
303 const auto rel = wid->property(
"objrelation");
306 auto relList = rel.toStringList();
307 for (
const auto &
s : qAsConst(relList)) {
308 if (
s.startsWith(QStringLiteral(
"fieldname:"))) {
309 relList.append(nameRel);
310 wid->setProperty(
"objrelation", relList);
317 void ConfigOsdWidget::copyOsdPage(
int to,
int from)
319 for (
const auto checkbox : pages[from]->findChildren<QCheckBox *>()) {
320 auto cb_to = pages[to]->findChild<QCheckBox *>(checkbox->objectName());
322 cb_to->setChecked(checkbox->checkState());
326 for (
const auto spinbox : pages[from]->findChildren<QSpinBox *>()) {
327 auto sb_to = pages[to]->findChild<QSpinBox *>(spinbox->objectName());
329 sb_to->setValue(spinbox->value());
333 for (
const auto combobox : pages[from]->findChildren<QComboBox *>()) {
334 auto cmb_to = pages[to]->findChild<QComboBox *>(combobox->objectName());
336 cmb_to->setCurrentIndex(combobox->currentIndex());
343 QWidget::resizeEvent(event);
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
virtual void enableControls(bool enable)
void resizeEvent(QResizeEvent *event)
ConfigOsdWidget(QWidget *parent=nullptr)