mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-22 11:13:47 +08:00
Screenrecorder: adjust button position (#214)
* 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
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -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) {
|
||||
|
||||
@@ -19,10 +19,6 @@ public:
|
||||
ScreenRecoder(QWidget *parent = 0);
|
||||
virtual ~ScreenRecoder();
|
||||
|
||||
public slots:
|
||||
void btnReleased(void);
|
||||
void btnPressed(void);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
|
||||
@@ -32,6 +28,7 @@ private:
|
||||
long long started;
|
||||
int src_width, src_height;
|
||||
int dst_width, dst_height;
|
||||
int rec_btn_size;
|
||||
|
||||
QColor recording_color;
|
||||
int frame;
|
||||
|
||||
Reference in New Issue
Block a user