mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-24 01:12:06 +08:00
AbstractControlSP: Inherit from stock AbstractControl
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
#include <selfdrive/ui/qt/util.h>
|
||||
|
||||
AbstractControl::AbstractControl(const QString &title, const QString &desc, const QString &icon, QWidget *parent) : QFrame(parent) {
|
||||
RETURN_IF_SUNNYPILOT
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout->setMargin(0);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class AbstractControl : public QFrame {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void setDescription(const QString &desc) {
|
||||
virtual void setDescription(const QString &desc) {
|
||||
if (description) description->setText(desc);
|
||||
}
|
||||
|
||||
@@ -48,11 +48,11 @@ public:
|
||||
title_label->setText(title);
|
||||
}
|
||||
|
||||
void setValue(const QString &val) {
|
||||
virtual void setValue(const QString &val) {
|
||||
value->setText(val);
|
||||
}
|
||||
|
||||
const QString getDescription() {
|
||||
virtual const QString getDescription() {
|
||||
return description->text();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
QPixmap icon_pixmap;
|
||||
|
||||
public slots:
|
||||
void showDescription() {
|
||||
virtual void showDescription() {
|
||||
description->setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -575,7 +575,7 @@ void SunnypilotPanel::updateToggles() {
|
||||
}
|
||||
|
||||
// toggle names to update when CustomTorqueLateral is flipped
|
||||
std::vector<AbstractControlSP*> customTorqueGroup{friction, lat_accel_factor};
|
||||
std::vector<AbstractControlSP_SELECTOR*> customTorqueGroup{friction, lat_accel_factor};
|
||||
for (const auto& customTorqueControl : customTorqueGroup) {
|
||||
customTorqueControl->setVisible(!(nnff_toggle->isToggled() || !custom_torque_lateral->isToggled()));
|
||||
customTorqueControl->setEnabled(!(nnff_toggle->isToggled() || !custom_torque_lateral->isToggled()));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
#include <selfdrive/ui/sunnypilot/sp_priv_sunnypilot_main.h>
|
||||
|
||||
QFrame *horizontal_line(QWidget *parent) {
|
||||
QFrame *line = new QFrame(parent);
|
||||
@@ -15,8 +16,10 @@ QFrame *horizontal_line(QWidget *parent) {
|
||||
return line;
|
||||
}
|
||||
|
||||
AbstractControlSP_TITLED::AbstractControlSP_TITLED(const QString &title, const QString &desc, const QString &icon, QWidget *parent) : QFrame(parent) {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
AbstractControlSP::AbstractControlSP(const QString &title, const QString &desc, const QString &icon, QWidget *parent)
|
||||
: AbstractControl(title, desc, icon, parent) {
|
||||
|
||||
main_layout = new QVBoxLayout(this);
|
||||
main_layout->setMargin(0);
|
||||
|
||||
hlayout = new QHBoxLayout;
|
||||
@@ -68,14 +71,28 @@ AbstractControlSP_TITLED::AbstractControlSP_TITLED(const QString &title, const Q
|
||||
main_layout->addStretch();
|
||||
}
|
||||
|
||||
void AbstractControlSP_TITLED::hideEvent(QHideEvent *e) {
|
||||
void AbstractControlSP::hideEvent(QHideEvent *e) {
|
||||
if (description != nullptr) {
|
||||
description->hide();
|
||||
}
|
||||
}
|
||||
|
||||
AbstractControlSP::AbstractControlSP(const QString &title, const QString &desc, const QString &icon, QWidget *parent) : QFrame(parent) {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
AbstractControlSP_SELECTOR::AbstractControlSP_SELECTOR(const QString &title, const QString &desc, const QString &icon, QWidget *parent)
|
||||
: AbstractControlSP(title, desc, icon, parent) {
|
||||
|
||||
if (value != nullptr) {
|
||||
ReplaceWidget(value, new QWidget());
|
||||
value = nullptr;
|
||||
}
|
||||
|
||||
QLayoutItem* item;
|
||||
while ((item = main_layout->takeAt(0)) != nullptr) {
|
||||
if (item->widget()) {
|
||||
delete item->widget();
|
||||
}
|
||||
delete item;
|
||||
}
|
||||
|
||||
main_layout->setMargin(0);
|
||||
|
||||
hlayout = new QHBoxLayout;
|
||||
@@ -116,12 +133,9 @@ AbstractControlSP::AbstractControlSP(const QString &title, const QString &desc,
|
||||
main_layout->addStretch();
|
||||
}
|
||||
|
||||
void AbstractControlSP::hideEvent(QHideEvent *e) {
|
||||
}
|
||||
|
||||
// controls
|
||||
|
||||
ButtonControlSP::ButtonControlSP(const QString &title, const QString &text, const QString &desc, QWidget *parent) : AbstractControlSP_TITLED(title, desc, "", parent) {
|
||||
ButtonControlSP::ButtonControlSP(const QString &title, const QString &text, const QString &desc, QWidget *parent) : AbstractControlSP(title, desc, "", parent) {
|
||||
btn.setText(text);
|
||||
btn.setStyleSheet(R"(
|
||||
QPushButton {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -12,8 +13,8 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#include "common/params.h"
|
||||
#include "selfdrive/ui/qt/widgets/controls.h"
|
||||
#include "selfdrive/ui/qt/widgets/input.h"
|
||||
//#include "selfdrive/ui/qt/widgets/toggle.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/widgets/sp_priv_toggle.h"
|
||||
|
||||
// This is for compatibility purposes, until we properly do inheritance splitting
|
||||
@@ -52,18 +53,14 @@ protected:
|
||||
QString lastText_, elidedText_;
|
||||
};
|
||||
|
||||
class AbstractControlSP_TITLED : public QFrame {
|
||||
class AbstractControlSP : public AbstractControl {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void setDescription(const QString &desc) {
|
||||
void setDescription(const QString &desc) override {
|
||||
if (description) description->setText(desc);
|
||||
}
|
||||
|
||||
void setTitle(const QString &title) {
|
||||
title_label->setText(title);
|
||||
}
|
||||
|
||||
void setValue(const QString &val, std::optional<QString> color = std::nullopt) {
|
||||
value->setText(val);
|
||||
if (color.has_value()) {
|
||||
@@ -71,84 +68,41 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const QString getDescription() {
|
||||
const QString getDescription() override {
|
||||
return description->text();
|
||||
}
|
||||
|
||||
QLabel *icon_label;
|
||||
QPixmap icon_pixmap;
|
||||
|
||||
public slots:
|
||||
void showDescription() {
|
||||
description->setVisible(true);
|
||||
}
|
||||
|
||||
void hideDescription() {
|
||||
description->setVisible(false);
|
||||
}
|
||||
|
||||
signals:
|
||||
void showDescriptionEvent();
|
||||
|
||||
protected:
|
||||
AbstractControlSP_TITLED(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr);
|
||||
void hideEvent(QHideEvent *e) override;
|
||||
|
||||
QHBoxLayout *hlayout;
|
||||
QPushButton *title_label;
|
||||
|
||||
private:
|
||||
ElidedLabel *value;
|
||||
QLabel *description = nullptr;
|
||||
};
|
||||
|
||||
|
||||
class AbstractControlSP : public QFrame {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void setDescription(const QString &desc) {
|
||||
if (description) description->setText(desc);
|
||||
}
|
||||
|
||||
void setTitle(const QString &title) {
|
||||
title_label->setText(title);
|
||||
}
|
||||
|
||||
const QString getDescription() {
|
||||
return description->text();
|
||||
}
|
||||
|
||||
public slots:
|
||||
void showDescription() {
|
||||
public slots:
|
||||
void showDescription() override {
|
||||
description->setVisible(true);
|
||||
}
|
||||
|
||||
void hideDescription() {
|
||||
description->setVisible(false);
|
||||
}
|
||||
|
||||
signals:
|
||||
void showDescriptionEvent();
|
||||
|
||||
protected:
|
||||
AbstractControlSP(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr);
|
||||
void hideEvent(QHideEvent *e) override;
|
||||
|
||||
QHBoxLayout *hlayout;
|
||||
QPushButton *title_label;
|
||||
|
||||
private:
|
||||
QVBoxLayout *main_layout;
|
||||
ElidedLabel *value;
|
||||
QLabel *description = nullptr;
|
||||
};
|
||||
|
||||
class AbstractControlSP_SELECTOR : public AbstractControlSP {
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
AbstractControlSP_SELECTOR(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
// widget to display a value
|
||||
class LabelControlSP : public AbstractControlSP_TITLED {
|
||||
class LabelControlSP : public AbstractControlSP {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LabelControlSP(const QString &title, const QString &text = "", const QString &desc = "", QWidget *parent = nullptr) : AbstractControlSP_TITLED(title, desc, "", parent) {
|
||||
LabelControlSP(const QString &title, const QString &text = "", const QString &desc = "", QWidget *parent = nullptr) : AbstractControlSP(title, desc, "", parent) {
|
||||
label.setText(text);
|
||||
label.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
hlayout->addWidget(&label);
|
||||
@@ -160,7 +114,7 @@ private:
|
||||
};
|
||||
|
||||
// widget for a button with a label
|
||||
class ButtonControlSP : public AbstractControlSP_TITLED {
|
||||
class ButtonControlSP : public AbstractControlSP {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@@ -179,11 +133,11 @@ private:
|
||||
QPushButton btn;
|
||||
};
|
||||
|
||||
class ToggleControlSP : public AbstractControlSP_TITLED {
|
||||
class ToggleControlSP : public AbstractControlSP {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ToggleControlSP(const QString &title, const QString &desc = "", const QString &icon = "", const bool state = false, QWidget *parent = nullptr) : AbstractControlSP_TITLED(title, desc, icon, parent) {
|
||||
ToggleControlSP(const QString &title, const QString &desc = "", const QString &icon = "", const bool state = false, QWidget *parent = nullptr) : AbstractControlSP(title, desc, icon, parent) {
|
||||
toggle.setFixedSize(150, 100);
|
||||
if (state) {
|
||||
toggle.togglePosition();
|
||||
@@ -250,11 +204,11 @@ private:
|
||||
bool store_confirm = false;
|
||||
};
|
||||
|
||||
class ButtonParamControlSP : public AbstractControlSP {
|
||||
class ButtonParamControlSP : public AbstractControlSP_SELECTOR {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ButtonParamControlSP(const QString ¶m, const QString &title, const QString &desc, const QString &icon,
|
||||
const std::vector<QString> &button_texts, const int minimum_button_width = 300) : AbstractControlSP(title, desc, icon), button_texts(button_texts) {
|
||||
const std::vector<QString> &button_texts, const int minimum_button_width = 300) : AbstractControlSP_SELECTOR(title, desc, icon), button_texts(button_texts) {
|
||||
const QString style = R"(
|
||||
QPushButton {
|
||||
border-radius: 20px;
|
||||
@@ -399,7 +353,7 @@ class ListWidgetSP : public QWidget {
|
||||
inline void AddWidgetAt(const int index, QWidget *new_widget) { inner_layout.insertWidget(index, new_widget); }
|
||||
inline void RemoveWidgetAt(const int index) {
|
||||
if (QLayoutItem* item; (item = inner_layout.takeAt(index)) != nullptr) {
|
||||
if(item->widget()) delete item->widget();
|
||||
if (item->widget()) delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
@@ -442,7 +396,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class OptionControlSP : public AbstractControlSP {
|
||||
class OptionControlSP : public AbstractControlSP_SELECTOR {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
@@ -453,7 +407,7 @@ private:
|
||||
|
||||
public:
|
||||
OptionControlSP(const QString ¶m, const QString &title, const QString &desc, const QString &icon,
|
||||
const MinMaxValue &range, const int per_value_change = 1) : _title(title), AbstractControlSP(title, desc, icon) {
|
||||
const MinMaxValue &range, const int per_value_change = 1) : _title(title), AbstractControlSP_SELECTOR(title, desc, icon) {
|
||||
const QString style = R"(
|
||||
QPushButton {
|
||||
border-radius: 20px;
|
||||
|
||||
Reference in New Issue
Block a user