Skip to content

Commit 990b9a8

Browse files
committed
[MiniStrip] Set mode to AUTO2 on click on the mode button.
1 parent e1cb387 commit 990b9a8

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

src/aircraft.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Aircraft::Aircraft(ConfigData* config, QObject* parent): QObject(parent),
1919
status = new AircraftStatus(ac_id, this);
2020
real = config->isReal();
2121
}
22+
void Aircraft::setSetting(Setting* setting, QString value) {
23+
int idx = setting->getValues().indexOf(value);
24+
if(idx != -1) {
25+
setSetting(setting, static_cast<float>(idx));
26+
}
27+
}
2228

2329
void Aircraft::setSetting(Setting* setting, float value) {
2430
auto coef = setting->getAltUnitCoef();

src/aircraft.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Aircraft: public QObject
3232
Point2DLatLon getPosition() {return position;}
3333
void setPosition(Point2DLatLon pos) {position = pos;}
3434

35+
void setSetting(Setting*, QString value);
3536
void setSetting(Setting*, float value);
3637
void setSetting(uint8_t setting_no, float value);
3738

src/widgets/mini_strip.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,20 @@ MiniStrip::MiniStrip(QString ac_id, QWidget *parent) : QWidget(parent),
190190
gl->addLayout(th_lay, 2, 0);
191191

192192
//////// mode //////////
193-
ap_mode_label = new ColorLabel(10, this);
194-
gl->addWidget(ap_mode_label, 1, 2);
195-
ap_mode_label->setToolTip("AP mode");
193+
ap_mode_button = new QPushButton("MODE");
194+
ap_mode_button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
195+
gl->addWidget(ap_mode_button, 1, 2);
196+
ap_mode_button->setToolTip("AP mode");
197+
auto settings = ac->getSettingMenu()->getAllSettings();
198+
for(auto setting: settings) {
199+
if(setting->getName() == "autopilot.mode") {
200+
connect(ap_mode_button, &QPushButton::clicked, this, [=](){
201+
AircraftManager::get()->getAircraft(ac_id)->setSetting(setting, "AUTO2");
202+
});
203+
break;
204+
}
205+
}
206+
196207

197208

198209
///// Link, GPS, RC //////
@@ -261,12 +272,19 @@ void MiniStrip::updateFlightTime(uint32_t flight_time, uint32_t block_time, uint
261272
}
262273

263274
void MiniStrip::updateAp(QString ap_mode) {
275+
QColor color = QColor(Qt::white);
264276
if(mode_colors.contains(ap_mode)) {
265-
ap_mode_label->setBrush(QColor(mode_colors[ap_mode]));
266-
} else {
267-
ap_mode_label->setBrush(Qt::white);
277+
color = QColor(mode_colors[ap_mode]);
278+
268279
}
269-
ap_mode_label->setText(ap_mode);
280+
QString style_back = "background: rgb(%1, %2, %3);";
281+
QString style = "QPushButton {";
282+
style += style_back.arg(color.red()).arg(color.green()).arg(color.blue());
283+
style += "color:black; font-size:12px;";
284+
style += " font-weight:bold;";
285+
style += "}";
286+
ap_mode_button->setStyleSheet(style);
287+
ap_mode_button->setText(ap_mode);
270288
}
271289

272290
void MiniStrip::updateGps(QString gps_mode) {

src/widgets/mini_strip.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <QtWidgets>
55
#include <QGridLayout>
66
#include <QHBoxLayout>
7-
#include "colorlabel.h"
87

98
class MiniStrip : public QWidget
109
{
@@ -82,7 +81,7 @@ class MiniStrip : public QWidget
8281
QIcon throttle_on;
8382
QIcon throttle_killed;
8483

85-
ColorLabel* ap_mode_label;
84+
QPushButton* ap_mode_button;
8685

8786
QLabel* link_icon;
8887
QIcon link_ok;

0 commit comments

Comments
 (0)