Skip to content

Commit

Permalink
Screenrecorder: adjust button position (commaai#214)
Browse files Browse the repository at this point in the history
* screenrecorder: small fixes

* remove QPushButton press, use mouse release instead

* Revert "remove QPushButton press, use mouse release instead"

This reverts commit 02821f63bf428332c41301a1aeb577b838ac6885.

* use horizonal layout to store buttons

* make button smaller and center text
  • Loading branch information
sunnyhaibin authored Aug 4, 2023
1 parent eee9b8b commit dc98584
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
11 changes: 8 additions & 3 deletions selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,14 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par
main_layout->addWidget(experimental_btn, 0, Qt::AlignTop | Qt::AlignRight);

map_settings_btn = new MapSettingsButton(this);
main_layout->addWidget(map_settings_btn, 0, Qt::AlignBottom | Qt::AlignRight);

dm_img = loadPixmap("../assets/img_driver_face.png", {img_size + 5, img_size + 5});
map_img = loadPixmap("../assets/img_world_icon.png", {subsign_img_size, subsign_img_size});
left_img = loadPixmap("../assets/img_turn_left_icon.png", {subsign_img_size, subsign_img_size});
right_img = loadPixmap("../assets/img_turn_right_icon.png", {subsign_img_size, subsign_img_size});

QHBoxLayout *buttons_layout = new QHBoxLayout(this);

// screen recoder - neokii

#ifdef ENABLE_DASHCAM
Expand All @@ -389,11 +390,15 @@ AnnotatedCameraWidget::AnnotatedCameraWidget(VisionStreamType type, QWidget* par
record_timer->start(1000/UI_FREQ);

recorder = new ScreenRecoder(this);
main_layout->addWidget(recorder);
main_layout->addWidget(recorder, 0, Qt::AlignRight | Qt::AlignBottom);
buttons_layout->addWidget(recorder);

QObject::connect(uiState(), &UIState::offroadTransition, this, &AnnotatedCameraWidget::offroadTransition);
#endif

buttons_layout->addSpacing(60);
buttons_layout->addWidget(map_settings_btn);
buttons_layout->setAlignment(Qt::AlignBottom | Qt::AlignRight);
main_layout->addLayout(buttons_layout);
}

#ifdef ENABLE_DASHCAM
Expand Down
28 changes: 15 additions & 13 deletions selfdrive/ui/qt/screenrecorder/screenrecorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ ScreenRecoder::ScreenRecoder(QWidget *parent) : QPushButton(parent), image_queue
recording = false;
started = 0;
frame = 0;
rec_btn_size = 120;

setVisible(false);
setFixedSize(btn_size, btn_size);
setFixedSize(rec_btn_size, rec_btn_size);
setFocusPolicy(Qt::NoFocus);
connect(this, SIGNAL(pressed()),this,SLOT(btnPressed()));
connect(this, SIGNAL(released()),this,SLOT(btnReleased()));
QObject::connect(this, &QPushButton::clicked, [=]() {
toggle();
});

std::string path = "/data/media/0/videos";
src_width = 2160;
Expand Down Expand Up @@ -65,24 +67,24 @@ void ScreenRecoder::paintEvent(QPaintEvent *event) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);

QPoint center(btn_size / 2 - 25, btn_size / 2 + 10 - 30);
QRect rec_btn(36 - 25, 36 + 10 - 30, 120, 120);
QPoint center(rec_btn_size / 2, rec_btn_size / 2);

p.setOpacity(1.0);
p.setPen(Qt::NoPen);
p.setBrush(QBrush(recording ? recording_color : QColor(252, 255, 253, 70)));
p.setOpacity(isDown() ? 0.8 : 1.0);
p.drawEllipse(center, 120 / 2, 120 / 2);
p.setOpacity(isDown() ? 0.6 : 1.0);
p.drawEllipse(center, rec_btn_size / 2, rec_btn_size / 2);

p.setPen(Qt::white);
p.setFont(QFont("Arial", 30));
p.drawText(rec_btn, Qt::AlignCenter, "REC");
}
QFontMetrics fontMetrics(p.font());
int textWidth = fontMetrics.width("REC");
int textHeight = fontMetrics.height();

void ScreenRecoder::btnReleased(void) {
toggle();
}
int textX = center.x() - textWidth / 2;
int textY = center.y() / 1.5; // Adjust vertically for proper alignment

void ScreenRecoder::btnPressed(void) {
p.drawText(textX, textY, textWidth, textHeight, Qt::AlignCenter, "REC");
}

void ScreenRecoder::openEncoder(const char* filename) {
Expand Down
5 changes: 1 addition & 4 deletions selfdrive/ui/qt/screenrecorder/screenrecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ class ScreenRecoder : public QPushButton {
ScreenRecoder(QWidget *parent = 0);
virtual ~ScreenRecoder();

public slots:
void btnReleased(void);
void btnPressed(void);

protected:
void paintEvent(QPaintEvent*) override;

Expand All @@ -32,6 +28,7 @@ public slots:
long long started;
int src_width, src_height;
int dst_width, dst_height;
int rec_btn_size;

QColor recording_color;
int frame;
Expand Down

0 comments on commit dc98584

Please sign in to comment.