FrogPilot 0.9.7

This commit is contained in:
FrogAi
2024-06-27 10:22:08 -07:00
parent da00915ac8
commit b705b02e70
682 changed files with 181798 additions and 1348 deletions
+27
View File
@@ -132,6 +132,10 @@ public:
toggle.update();
}
void refresh() {
toggle.togglePosition();
}
signals:
void toggleFlipped(bool state);
@@ -221,10 +225,12 @@ public:
button->setMinimumWidth(minimum_button_width);
hlayout->addWidget(button);
button_group->addButton(button, i);
button->installEventFilter(this);
}
QObject::connect(button_group, QOverload<int>::of(&QButtonGroup::buttonClicked), [=](int id) {
params.put(key, std::to_string(id));
emit buttonClicked(id);
});
}
@@ -234,6 +240,12 @@ public:
}
}
void setEnabledButtons(int id, bool enable) {
if (QAbstractButton *button = button_group->button(id)) {
button->setEnabled(enable);
}
}
void setCheckedButton(int id) {
button_group->button(id)->setChecked(true);
}
@@ -247,6 +259,21 @@ public:
refresh();
}
signals:
void buttonClicked(int id);
void disabledButtonClicked(int id);
protected:
bool eventFilter(QObject *obj, QEvent *event) override {
if (event->type() == QEvent::MouseButtonPress) {
QPushButton *button = qobject_cast<QPushButton *>(obj);
if (button && !button->isEnabled()) {
emit disabledButtonClicked(button_group->id(button));
}
}
return AbstractControl::eventFilter(obj, event);
}
private:
std::string key;
Params params;
+21 -4
View File
@@ -141,19 +141,25 @@ InputDialog::InputDialog(const QString &title, QWidget *parent, const QString &s
QObject::connect(k, &Keyboard::emitEnter, this, &InputDialog::handleEnter);
QObject::connect(k, &Keyboard::emitBackspace, this, [=]() {
line->backspace();
updateMaxLengthSublabel(line->text());
});
QObject::connect(k, &Keyboard::emitKey, this, [=](const QString &key) {
line->insert(key.left(1));
if (line->text().length() < maxLength || maxLength == DEFAULT_MAX_LENGTH) {
line->insert(key.left(1));
updateMaxLengthSublabel(line->text());
}
});
main_layout->addWidget(k, 2, Qt::AlignBottom);
}
QString InputDialog::getText(const QString &prompt, QWidget *parent, const QString &subtitle,
bool secret, int minLength, const QString &defaultText) {
bool secret, int minLength, const QString &defaultText, int maxLength) {
InputDialog d = InputDialog(prompt, parent, subtitle, secret);
d.line->setText(defaultText);
d.setMinLength(minLength);
d.setMaxLength(maxLength);
d.updateMaxLengthSublabel(defaultText);
const int ret = d.exec();
return ret ? d.text() : QString();
}
@@ -186,10 +192,21 @@ void InputDialog::setMinLength(int length) {
minLength = length;
}
// FrogPilot functions
void InputDialog::setMaxLength(int length) {
maxLength = length;
}
void InputDialog::updateMaxLengthSublabel(const QString &text) {
if (maxLength != DEFAULT_MAX_LENGTH) {
sublabel->setText(tr("Characters: %1/%2").arg(text.length()).arg(maxLength));
}
}
// ConfirmationDialog
ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString &confirm_text, const QString &cancel_text,
const bool rich, QWidget *parent) : DialogBase(parent) {
const bool rich, QWidget *parent, const bool is_long) : DialogBase(parent) {
QFrame *container = new QFrame(this);
container->setStyleSheet(R"(
QFrame { background-color: #1B1B1B; color: #C9C9C9; }
@@ -197,7 +214,7 @@ ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString
#confirm_btn:pressed { background-color: #3049F4; }
)");
QVBoxLayout *main_layout = new QVBoxLayout(container);
main_layout->setContentsMargins(32, rich ? 32 : 120, 32, 32);
main_layout->setContentsMargins(32, rich || is_long ? 32 : 120, 32, 32);
QLabel *prompt = new QLabel(prompt_text, this);
prompt->setWordWrap(true);
+12 -2
View File
@@ -9,6 +9,7 @@
#include "selfdrive/ui/qt/widgets/keyboard.h"
const int DEFAULT_MAX_LENGTH = 512;
class DialogBase : public QDialog {
Q_OBJECT
@@ -27,12 +28,15 @@ class InputDialog : public DialogBase {
public:
explicit InputDialog(const QString &title, QWidget *parent, const QString &subtitle = "", bool secret = false);
static QString getText(const QString &title, QWidget *parent, const QString &subtitle = "",
bool secret = false, int minLength = -1, const QString &defaultText = "");
bool secret = false, int minLength = -1, const QString &defaultText = "", int maxLength = DEFAULT_MAX_LENGTH);
QString text();
void setMessage(const QString &message, bool clearInputField = true);
void setMinLength(int length);
void show();
// FrogPilot widgets
void setMaxLength(int length);
private:
int minLength;
QLineEdit *line;
@@ -42,6 +46,12 @@ private:
QVBoxLayout *main_layout;
QPushButton *eye_btn;
// FrogPilot widgets
void updateMaxLengthSublabel(const QString &text);
// FrogPilot variables
int maxLength;
private slots:
void handleEnter();
@@ -55,7 +65,7 @@ class ConfirmationDialog : public DialogBase {
public:
explicit ConfirmationDialog(const QString &prompt_text, const QString &confirm_text,
const QString &cancel_text, const bool rich, QWidget* parent);
const QString &cancel_text, const bool rich, QWidget* parent, const bool is_long=false);
static bool alert(const QString &prompt_text, QWidget *parent);
static bool confirm(const QString &prompt_text, const QString &confirm_text, QWidget *parent);
static bool rich(const QString &prompt_text, QWidget *parent);
+12
View File
@@ -32,6 +32,17 @@ AbstractAlert::AbstractAlert(bool hasRebootBtn, QWidget *parent) : QFrame(parent
footer_layout->addWidget(dismiss_btn, 0, Qt::AlignBottom | Qt::AlignLeft);
QObject::connect(dismiss_btn, &QPushButton::clicked, this, &AbstractAlert::dismiss);
disable_check_btn = new QPushButton(tr("Disable Internet Check"));
disable_check_btn->setVisible(false);
disable_check_btn->setFixedSize(625, 125);
footer_layout->addWidget(disable_check_btn, 1, Qt::AlignBottom | Qt::AlignCenter);
QObject::connect(disable_check_btn, &QPushButton::clicked, [=]() {
params.putBool("DeviceManagement", true);
params.putBool("OfflineMode", true);
});
QObject::connect(disable_check_btn, &QPushButton::clicked, this, &AbstractAlert::dismiss);
disable_check_btn->setStyleSheet(R"(color: white; background-color: #4F4F4F;)");
snooze_btn = new QPushButton(tr("Snooze Update"));
snooze_btn->setVisible(false);
snooze_btn->setFixedSize(550, 125);
@@ -107,6 +118,7 @@ int OffroadAlert::refresh() {
label->setVisible(!text.isEmpty());
alertCount += !text.isEmpty();
}
disable_check_btn->setVisible(!alerts["Offroad_ConnectivityNeeded"]->text().isEmpty());
snooze_btn->setVisible(!alerts["Offroad_ConnectivityNeeded"]->text().isEmpty());
return alertCount;
}
+1
View File
@@ -15,6 +15,7 @@ class AbstractAlert : public QFrame {
protected:
AbstractAlert(bool hasRebootBtn, QWidget *parent = nullptr);
QPushButton *disable_check_btn;
QPushButton *snooze_btn;
QVBoxLayout *scrollable_layout;
Params params;
+2
View File
@@ -18,7 +18,9 @@ SshControl::SshControl() :
}
} else {
params.remove("GithubUsername");
params_storage.remove("GithubUsername");
params.remove("GithubSshKeys");
params_storage.remove("GithubSshKeys");
refresh();
}
});
+3
View File
@@ -29,4 +29,7 @@ private:
void refresh();
void getUserKeys(const QString &username);
// FrogPilot variables
Params params_storage{"/persist/params"};
};
+1 -1
View File
@@ -75,7 +75,7 @@ void Toggle::setEnabled(bool value) {
enabled = value;
if (value) {
circleColor.setRgb(0xfafafa);
green.setRgb(0x33ab4c);
green.setRgb(0x178644);
} else {
circleColor.setRgb(0x888888);
green.setRgb(0x227722);
+30 -1
View File
@@ -81,6 +81,35 @@ WiFiPromptWidget::WiFiPromptWidget(QWidget *parent) : QFrame(parent) {
}
stack->addWidget(uploading);
// not uploading data
QWidget *notUploading = new QWidget;
QVBoxLayout *not_uploading_layout = new QVBoxLayout(notUploading);
not_uploading_layout->setContentsMargins(64, 56, 64, 56);
not_uploading_layout->setSpacing(36);
{
QHBoxLayout *title_layout = new QHBoxLayout;
{
QLabel *title = new QLabel(tr("Uploading disabled"));
title->setStyleSheet("font-size: 64px; font-weight: 600;");
title->setWordWrap(true);
title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
title_layout->addWidget(title);
title_layout->addStretch();
QLabel *icon = new QLabel;
QPixmap pixmap("../frogpilot/assets/other_images/icon_wifi_uploading_disabled.svg");
icon->setPixmap(pixmap.scaledToWidth(120, Qt::SmoothTransformation));
title_layout->addWidget(icon);
}
not_uploading_layout->addLayout(title_layout);
QLabel *desc = new QLabel(tr("Toggle off the 'Turn Off Data Uploads' toggle to re-enable uploads."));
desc->setStyleSheet("font-size: 48px; font-weight: 400;");
desc->setWordWrap(true);
not_uploading_layout->addWidget(desc);
}
stack->addWidget(notUploading);
setStyleSheet(R"(
WiFiPromptWidget {
background-color: #333333;
@@ -99,5 +128,5 @@ void WiFiPromptWidget::updateState(const UIState &s) {
auto network_type = sm["deviceState"].getDeviceState().getNetworkType();
auto uploading = network_type == cereal::DeviceState::NetworkType::WIFI ||
network_type == cereal::DeviceState::NetworkType::ETHERNET;
stack->setCurrentIndex(uploading ? 1 : 0);
stack->setCurrentIndex(s.scene.no_uploads ? 2 : uploading ? 1 : 0);
}
+4
View File
@@ -18,6 +18,10 @@ signals:
public slots:
void updateState(const UIState &s);
private:
// FrogPilot variables
Params params;
protected:
QStackedLayout *stack;
};