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.
		
		
		
		
			
				
					50 lines
				
				1.8 KiB
			
		
		
			
		
	
	
					50 lines
				
				1.8 KiB
			| 
											2 years ago
										 | #include "selfdrive/ui/qt/onroad/buttons.h"
 | ||
|  | 
 | ||
|  | #include <QPainter>
 | ||
|  | 
 | ||
|  | #include "selfdrive/ui/qt/util.h"
 | ||
|  | 
 | ||
|  | void drawIcon(QPainter &p, const QPoint ¢er, const QPixmap &img, const QBrush &bg, float opacity) {
 | ||
|  |   p.setRenderHint(QPainter::Antialiasing);
 | ||
|  |   p.setOpacity(1.0);  // bg dictates opacity of ellipse
 | ||
|  |   p.setPen(Qt::NoPen);
 | ||
|  |   p.setBrush(bg);
 | ||
|  |   p.drawEllipse(center, btn_size / 2, btn_size / 2);
 | ||
|  |   p.setOpacity(opacity);
 | ||
|  |   p.drawPixmap(center - QPoint(img.width() / 2, img.height() / 2), img);
 | ||
|  |   p.setOpacity(1.0);
 | ||
|  | }
 | ||
|  | 
 | ||
|  | // ExperimentalButton
 | ||
|  | ExperimentalButton::ExperimentalButton(QWidget *parent) : experimental_mode(false), engageable(false), QPushButton(parent) {
 | ||
|  |   setFixedSize(btn_size, btn_size);
 | ||
|  | 
 | ||
|  |   engage_img = loadPixmap("../assets/img_chffr_wheel.png", {img_size, img_size});
 | ||
|  |   experimental_img = loadPixmap("../assets/img_experimental.svg", {img_size, img_size});
 | ||
|  |   QObject::connect(this, &QPushButton::clicked, this, &ExperimentalButton::changeMode);
 | ||
|  | }
 | ||
|  | 
 | ||
|  | void ExperimentalButton::changeMode() {
 | ||
|  |   const auto cp = (*uiState()->sm)["carParams"].getCarParams();
 | ||
|  |   bool can_change = hasLongitudinalControl(cp) && params.getBool("ExperimentalModeConfirmed");
 | ||
|  |   if (can_change) {
 | ||
|  |     params.putBool("ExperimentalMode", !experimental_mode);
 | ||
|  |   }
 | ||
|  | }
 | ||
|  | 
 | ||
|  | void ExperimentalButton::updateState(const UIState &s) {
 | ||
|  |   const auto cs = (*s.sm)["controlsState"].getControlsState();
 | ||
|  |   bool eng = cs.getEngageable() || cs.getEnabled();
 | ||
|  |   if ((cs.getExperimentalMode() != experimental_mode) || (eng != engageable)) {
 | ||
|  |     engageable = eng;
 | ||
|  |     experimental_mode = cs.getExperimentalMode();
 | ||
|  |     update();
 | ||
|  |   }
 | ||
|  | }
 | ||
|  | 
 | ||
|  | void ExperimentalButton::paintEvent(QPaintEvent *event) {
 | ||
|  |   QPainter p(this);
 | ||
|  |   QPixmap img = experimental_mode ? experimental_img : engage_img;
 | ||
|  |   drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0);
 | ||
|  | }
 |