mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-11 20:32:13 +08:00
96 lines
3.3 KiB
C++
96 lines
3.3 KiB
C++
#include "selfdrive/ui/qt/offroad/experimental_mode.h"
|
|
|
|
#include <QDebug>
|
|
#include <QHBoxLayout>
|
|
#include <QPainter>
|
|
#include <QPainterPath>
|
|
#include <QStyle>
|
|
|
|
#include "selfdrive/ui/ui.h"
|
|
|
|
ExperimentalModeButton::ExperimentalModeButton(QWidget *parent) : QPushButton(parent) {
|
|
chill_pixmap = QPixmap("../assets/icons/couch.svg").scaledToWidth(img_width, Qt::SmoothTransformation);
|
|
experimental_pixmap = QPixmap("../assets/icons/experimental_grey.svg").scaledToWidth(img_width, Qt::SmoothTransformation);
|
|
|
|
// go to toggles and expand whichever mode control is actually active
|
|
connect(this, &QPushButton::clicked, [=]() {
|
|
const QString toggle = params.getBool("ConditionalExperimental") ? "ConditionalExperimental" :
|
|
params.getBool("ConditionalChill") ? "ConditionalChill" :
|
|
"ExperimentalMode";
|
|
emit openSettings(2, toggle);
|
|
});
|
|
|
|
setFixedHeight(125);
|
|
QHBoxLayout *main_layout = new QHBoxLayout;
|
|
main_layout->setContentsMargins(horizontal_padding, 0, horizontal_padding, 0);
|
|
|
|
mode_label = new QLabel;
|
|
mode_icon = new QLabel;
|
|
mode_icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
|
|
|
|
main_layout->addWidget(mode_label, 1, Qt::AlignLeft);
|
|
main_layout->addWidget(mode_icon, 0, Qt::AlignRight);
|
|
|
|
setLayout(main_layout);
|
|
|
|
setStyleSheet(R"(
|
|
QPushButton {
|
|
border: none;
|
|
}
|
|
|
|
QLabel {
|
|
font-size: 45px;
|
|
font-weight: 300;
|
|
text-align: left;
|
|
font-family: JetBrainsMono;
|
|
color: #000000;
|
|
}
|
|
)");
|
|
}
|
|
|
|
void ExperimentalModeButton::paintEvent(QPaintEvent *event) {
|
|
QPainter p(this);
|
|
p.setPen(Qt::NoPen);
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
QPainterPath path;
|
|
path.addRoundedRect(rect(), 10, 10);
|
|
|
|
// gradient
|
|
bool pressed = isDown();
|
|
QLinearGradient gradient(rect().left(), 0, rect().right(), 0);
|
|
if (experimental_mode) {
|
|
gradient.setColorAt(0, QColor(255, 155, 63, pressed ? 0xcc : 0xff));
|
|
gradient.setColorAt(1, QColor(219, 56, 34, pressed ? 0xcc : 0xff));
|
|
} else {
|
|
gradient.setColorAt(0, QColor(20, 255, 171, pressed ? 0xcc : 0xff));
|
|
gradient.setColorAt(1, QColor(35, 149, 255, pressed ? 0xcc : 0xff));
|
|
}
|
|
p.fillPath(path, gradient);
|
|
|
|
// vertical line
|
|
p.setPen(QPen(QColor(0, 0, 0, 0x4d), 3, Qt::SolidLine));
|
|
int line_x = rect().right() - img_width - (2 * horizontal_padding);
|
|
p.drawLine(line_x, rect().bottom(), line_x, rect().top());
|
|
}
|
|
|
|
void ExperimentalModeButton::showEvent(QShowEvent *event) {
|
|
if (params.getBool("ConditionalExperimental")) {
|
|
int status = params_memory.getInt("CEStatus");
|
|
if ((status != 1 && status != 2) && params.getBool("PersistExperimentalState")) {
|
|
status = params.getInt("PersistedCEStatus");
|
|
}
|
|
experimental_mode = !params.getBool("SafeMode") && status == 2;
|
|
} else if (params.getBool("ConditionalChill")) {
|
|
int status = params_memory.getInt("CCStatus");
|
|
if ((status != 1 && status != 2) && params.getBool("PersistChillState")) {
|
|
status = params.getInt("PersistedCCStatus");
|
|
}
|
|
experimental_mode = !params.getBool("SafeMode") && (status == 0 || status == 1);
|
|
} else {
|
|
experimental_mode = params.getBool("ExperimentalMode") && !params.getBool("SafeMode");
|
|
}
|
|
mode_icon->setPixmap(experimental_mode ? experimental_pixmap : chill_pixmap);
|
|
mode_label->setText(experimental_mode ? tr("EXPERIMENTAL MODE ON") : tr("CHILL MODE ON"));
|
|
}
|