dragonpilot - 基於 openpilot 的開源駕駛輔助系統
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

109 lines
2.8 KiB

#pragma once
#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include "common/params.h"
#include "toggle.hpp"
QFrame *horizontal_line(QWidget *parent = nullptr);
class AbstractControl : public QFrame {
Q_OBJECT
protected:
AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "");
QSize minimumSizeHint() const override {
QSize size = QFrame::minimumSizeHint();
size.setHeight(120);
return size;
};
QHBoxLayout *hlayout;
QLabel *title_label;
};
// widget to display a value
class LabelControl : public AbstractControl {
Q_OBJECT
public:
LabelControl(const QString &title, const QString &text, const QString &desc = "") : AbstractControl(title, desc, "") {
label.setText(text);
label.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
hlayout->addWidget(&label);
}
void setText(const QString &text) { label.setText(text); }
private:
QLabel label;
};
// widget for a button with a label
class ButtonControl : public AbstractControl {
Q_OBJECT
public:
template <typename Functor>
ButtonControl(const QString &title, const QString &text, const QString &desc, Functor functor, const QString &icon = "") : AbstractControl(title, desc, icon) {
btn.setText(text);
btn.setStyleSheet(R"(
padding: 0;
border-radius: 50px;
font-size: 35px;
font-weight: 500;
color: #E4E4E4;
background-color: #393939;
)");
btn.setFixedSize(250, 100);
QObject::connect(&btn, &QPushButton::released, functor);
hlayout->addWidget(&btn);
}
void setText(const QString &text) { btn.setText(text); }
private:
QPushButton btn;
};
class ToggleControl : public AbstractControl {
Q_OBJECT
public:
ToggleControl(const QString &title, const QString &desc = "", const QString &icon = "", const bool state = false) : AbstractControl(title, desc, icon) {
toggle.setFixedSize(150, 100);
if (state) {
toggle.togglePosition();
}
hlayout->addWidget(&toggle);
QObject::connect(&toggle, &Toggle::stateChanged, this, &ToggleControl::toggleFlipped);
}
void setEnabled(bool enabled) { toggle.setEnabled(enabled); }
signals:
void toggleFlipped(bool state);
protected:
Toggle toggle;
};
// widget to toggle params
class ParamControl : public ToggleControl {
Q_OBJECT
public:
ParamControl(const QString &param, const QString &title, const QString &desc, const QString &icon) : ToggleControl(title, desc, icon) {
// set initial state from param
if (Params().read_db_bool(param.toStdString().c_str())) {
toggle.togglePosition();
}
QObject::connect(this, &ToggleControl::toggleFlipped, [=](int state) {
char value = state ? '1' : '0';
Params().write_db_value(param.toStdString().c_str(), &value, 1);
});
}
};