mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-09 01:23:43 +08:00
ui: add expandable row widget (#916)
* expandable_row widget * make MinMaxValue protected to allow inheritence * add function to set width * no more layout warnings * format --------- Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ widgets_src = [
|
||||
"sunnypilot/qt/widgets/toggle.cc",
|
||||
"sunnypilot/qt/widgets/controls.cc",
|
||||
"sunnypilot/qt/widgets/drive_stats.cc",
|
||||
"sunnypilot/qt/widgets/expandable_row.cc",
|
||||
"sunnypilot/qt/widgets/prime.cc",
|
||||
"sunnypilot/qt/widgets/scrollview.cc",
|
||||
"sunnypilot/qt/network/networking.cc",
|
||||
|
||||
@@ -441,15 +441,16 @@ public:
|
||||
class OptionControlSP : public AbstractControlSP_SELECTOR {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
bool is_inline_layout;
|
||||
QHBoxLayout *optionSelectorLayout = is_inline_layout ? new QHBoxLayout() : hlayout;
|
||||
|
||||
protected:
|
||||
struct MinMaxValue {
|
||||
int min_value;
|
||||
int max_value;
|
||||
};
|
||||
|
||||
private:
|
||||
bool is_inline_layout;
|
||||
QHBoxLayout *optionSelectorLayout = is_inline_layout ? new QHBoxLayout() : hlayout;
|
||||
|
||||
int getParamValue() {
|
||||
const auto param_value = QString::fromStdString(params.get(key));
|
||||
const auto result = valueMap != nullptr ? valueMap->key(param_value) : param_value;
|
||||
@@ -551,6 +552,10 @@ public:
|
||||
request_update = _update;
|
||||
}
|
||||
|
||||
void setFixedWidth(int width) {
|
||||
label.setFixedWidth(width);
|
||||
}
|
||||
|
||||
inline void setLabel(const QString &text) { label.setText(text); }
|
||||
|
||||
void setEnabled(bool enabled) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
||||
*
|
||||
* This file is part of sunnypilot and is licensed under the MIT License.
|
||||
* See the LICENSE.md file in the root directory for more details.
|
||||
*/
|
||||
|
||||
#include "selfdrive/ui/sunnypilot/qt/widgets/expandable_row.h"
|
||||
|
||||
ExpandableToggleRow::ExpandableToggleRow(const QString ¶m, const QString &title, const QString &desc, const QString &icon, QWidget *parent)
|
||||
: ToggleControlSP(title, desc, icon, false, parent) {
|
||||
|
||||
key = param.toStdString();
|
||||
QObject::connect(this, &ExpandableToggleRow::toggleFlipped, this, &ExpandableToggleRow::toggleClicked);
|
||||
|
||||
collapsibleWidget = new QFrame(this);
|
||||
collapsibleWidget->setContentsMargins(0, 0, 0, 0);
|
||||
collapsibleWidget->setVisible(false);
|
||||
QVBoxLayout *collapsible_layout = new QVBoxLayout();
|
||||
collapsibleWidget->setLayout(collapsible_layout);
|
||||
|
||||
list = new ListWidgetSP(this, false);
|
||||
|
||||
main_layout->addWidget(collapsibleWidget);
|
||||
collapsible_layout->addWidget(list);
|
||||
}
|
||||
|
||||
void ExpandableToggleRow::toggleClicked(bool state) {
|
||||
params.putBool(key, state);
|
||||
collapsibleWidget->setVisible(state);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
||||
*
|
||||
* This file is part of sunnypilot and is licensed under the MIT License.
|
||||
* See the LICENSE.md file in the root directory for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h"
|
||||
|
||||
class ExpandableToggleRow : public ToggleControlSP {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ExpandableToggleRow(const QString ¶m, const QString &title, const QString &desc, const QString &icon, QWidget *parent = nullptr);
|
||||
|
||||
void addItem(QWidget *widget) {
|
||||
list->addItem(widget);
|
||||
}
|
||||
|
||||
ListWidgetSP *innerList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
bool state = params.getBool(key);
|
||||
if (state != toggle.on) {
|
||||
toggle.togglePosition();
|
||||
}
|
||||
collapsibleWidget->setVisible(state);
|
||||
}
|
||||
|
||||
bool isToggled() {
|
||||
return params.getBool(key);
|
||||
}
|
||||
|
||||
void showEvent(QShowEvent *event) override {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private:
|
||||
void toggleClicked(bool state);
|
||||
|
||||
std::string key;
|
||||
Params params;
|
||||
|
||||
ListWidgetSP *list;
|
||||
QFrame *collapsibleWidget = nullptr;
|
||||
};
|
||||
Reference in New Issue
Block a user