ui: offroad experimental mode button (#26498)
* draft
* draft
* before qpushbutton
* icon, clean up button, clicked goes to toggles
* fix icon
* add imgs
* img
* make square
* works with layouts!
* fix gradient
* this looks good
* clean up
* clean up
* remove padding around couch
* use scene's experimental_model, new onroad design
* rename widget
* def want 3
* update translations
* add img
* add 25px of padding!
* make 300px (no change)
* clean up old images
* 5 px smaller
* add white img
* fix from merge
* no style sheets
* see how this looks on device
* aliased vertical line (clean up)
* clean up
* imgs
* couch
* delete
* bye bye
* expand toggle support
* clean up
* fix dynamic icon
* make exp icon dynamic
* order
* move to offroad
old-commit-hash: 58b84fb401
taco
v0.9.0
parent
ac0055307f
commit
dcd22dda7a
22 changed files with 232 additions and 13 deletions
@ -0,0 +1,3 @@ |
|||||||
|
version https://git-lfs.github.com/spec/v1 |
||||||
|
oid sha256:64708889e701acf7f2f43fd9c3696eb7f2c849ae67693ce581ad8f92433b3b24 |
||||||
|
size 204140 |
@ -0,0 +1,3 @@ |
|||||||
|
version https://git-lfs.github.com/spec/v1 |
||||||
|
oid sha256:ea87cc840ba1b0b96351bbde97af171c3cda462559459e186a5689f9f4aba82e |
||||||
|
size 2311 |
@ -0,0 +1,3 @@ |
|||||||
|
version https://git-lfs.github.com/spec/v1 |
||||||
|
oid sha256:c26afadff128244567a7cf98f1c998f97056b19209301ff7fc8851eb807fb748 |
||||||
|
size 2193 |
@ -0,0 +1,3 @@ |
|||||||
|
version https://git-lfs.github.com/spec/v1 |
||||||
|
oid sha256:5ae28a53171567c8a0d52eec75cc49004cb8dd19dcab9a360784718ab8ec7c02 |
||||||
|
size 1931 |
@ -0,0 +1,3 @@ |
|||||||
|
version https://git-lfs.github.com/spec/v1 |
||||||
|
oid sha256:99be696be983700d7eb1768bd1c840198a4eb9525b71e28efea49f13c358e519 |
||||||
|
size 1891 |
@ -0,0 +1,75 @@ |
|||||||
|
#include "selfdrive/ui/qt/offroad/experimental_mode.h" |
||||||
|
|
||||||
|
#include <QDebug> |
||||||
|
#include <QHBoxLayout> |
||||||
|
#include <QPainter> |
||||||
|
#include <QStyle> |
||||||
|
|
||||||
|
#include "selfdrive/ui/ui.h" |
||||||
|
|
||||||
|
ExperimentalModeButton::ExperimentalModeButton(QWidget *parent) : QPushButton(parent) { |
||||||
|
chill_pixmap = QPixmap("../assets/img_couch.svg").scaledToWidth(img_width, Qt::SmoothTransformation); |
||||||
|
experimental_pixmap = QPixmap("../assets/img_experimental_grey.svg").scaledToWidth(img_width, Qt::SmoothTransformation); |
||||||
|
|
||||||
|
// go to toggles and expand experimental mode description
|
||||||
|
connect(this, &QPushButton::clicked, [=]() { emit openSettings(2, "ExperimentalMode"); }); |
||||||
|
|
||||||
|
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) { |
||||||
|
experimental_mode = params.getBool("ExperimentalMode"); |
||||||
|
mode_icon->setPixmap(experimental_mode ? experimental_pixmap : chill_pixmap); |
||||||
|
mode_label->setText(experimental_mode ? tr("EXPERIMENTAL MODE ON") : tr("CHILL MODE ON")); |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <QLabel> |
||||||
|
#include <QPushButton> |
||||||
|
|
||||||
|
#include "common/params.h" |
||||||
|
|
||||||
|
class ExperimentalModeButton : public QPushButton { |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
explicit ExperimentalModeButton(QWidget* parent = 0); |
||||||
|
|
||||||
|
signals: |
||||||
|
void openSettings(int index = 0, const QString &toggle = ""); |
||||||
|
|
||||||
|
private: |
||||||
|
void showEvent(QShowEvent *event) override; |
||||||
|
|
||||||
|
Params params; |
||||||
|
bool experimental_mode; |
||||||
|
int img_width = 100; |
||||||
|
int horizontal_padding = 30; |
||||||
|
QPixmap experimental_pixmap; |
||||||
|
QPixmap chill_pixmap; |
||||||
|
QLabel *mode_label; |
||||||
|
QLabel *mode_icon; |
||||||
|
|
||||||
|
protected: |
||||||
|
void paintEvent(QPaintEvent *event) override; |
||||||
|
}; |
Loading…
Reference in new issue