parent
5d1816e2b8
commit
e6742151aa
10 changed files with 4 additions and 249 deletions
@ -1,120 +0,0 @@ |
|||||||
#include "selfdrive/ui/qt/spinner.h" |
|
||||||
|
|
||||||
#include <algorithm> |
|
||||||
#include <cstdio> |
|
||||||
#include <iostream> |
|
||||||
#include <string> |
|
||||||
|
|
||||||
#include <QApplication> |
|
||||||
#include <QGridLayout> |
|
||||||
#include <QPainter> |
|
||||||
#include <QString> |
|
||||||
#include <QTransform> |
|
||||||
|
|
||||||
#include "system/hardware/hw.h" |
|
||||||
#include "selfdrive/ui/qt/qt_window.h" |
|
||||||
#include "selfdrive/ui/qt/util.h" |
|
||||||
|
|
||||||
TrackWidget::TrackWidget(QWidget *parent) : QWidget(parent) { |
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent); |
|
||||||
setFixedSize(spinner_size); |
|
||||||
|
|
||||||
// pre-compute all the track imgs. make this a gif instead?
|
|
||||||
QPixmap comma_img = loadPixmap("../assets/img_spinner_comma.png", spinner_size); |
|
||||||
QPixmap track_img = loadPixmap("../assets/img_spinner_track.png", spinner_size); |
|
||||||
|
|
||||||
QTransform transform(1, 0, 0, 1, width() / 2, height() / 2); |
|
||||||
QPixmap pm(spinner_size); |
|
||||||
QPainter p(&pm); |
|
||||||
p.setRenderHint(QPainter::SmoothPixmapTransform); |
|
||||||
for (int i = 0; i < track_imgs.size(); ++i) { |
|
||||||
p.resetTransform(); |
|
||||||
p.fillRect(0, 0, spinner_size.width(), spinner_size.height(), Qt::black); |
|
||||||
p.drawPixmap(0, 0, comma_img); |
|
||||||
p.setTransform(transform.rotate(360 / spinner_fps)); |
|
||||||
p.drawPixmap(-width() / 2, -height() / 2, track_img); |
|
||||||
track_imgs[i] = pm.copy(); |
|
||||||
} |
|
||||||
|
|
||||||
m_anim.setDuration(1000); |
|
||||||
m_anim.setStartValue(0); |
|
||||||
m_anim.setEndValue(int(track_imgs.size() -1)); |
|
||||||
m_anim.setLoopCount(-1); |
|
||||||
m_anim.start(); |
|
||||||
connect(&m_anim, SIGNAL(valueChanged(QVariant)), SLOT(update())); |
|
||||||
} |
|
||||||
|
|
||||||
void TrackWidget::paintEvent(QPaintEvent *event) { |
|
||||||
QPainter painter(this); |
|
||||||
painter.drawPixmap(0, 0, track_imgs[m_anim.currentValue().toInt()]); |
|
||||||
} |
|
||||||
|
|
||||||
// Spinner
|
|
||||||
|
|
||||||
Spinner::Spinner(QWidget *parent) : QWidget(parent) { |
|
||||||
QGridLayout *main_layout = new QGridLayout(this); |
|
||||||
main_layout->setSpacing(0); |
|
||||||
main_layout->setMargin(200); |
|
||||||
|
|
||||||
main_layout->addWidget(new TrackWidget(this), 0, 0, Qt::AlignHCenter | Qt::AlignVCenter); |
|
||||||
|
|
||||||
text = new QLabel(); |
|
||||||
text->setWordWrap(true); |
|
||||||
text->setVisible(false); |
|
||||||
text->setAlignment(Qt::AlignCenter); |
|
||||||
main_layout->addWidget(text, 1, 0, Qt::AlignHCenter); |
|
||||||
|
|
||||||
progress_bar = new QProgressBar(); |
|
||||||
progress_bar->setRange(5, 100); |
|
||||||
progress_bar->setTextVisible(false); |
|
||||||
progress_bar->setVisible(false); |
|
||||||
progress_bar->setFixedHeight(20); |
|
||||||
main_layout->addWidget(progress_bar, 1, 0, Qt::AlignHCenter); |
|
||||||
|
|
||||||
setStyleSheet(R"( |
|
||||||
Spinner { |
|
||||||
background-color: black; |
|
||||||
} |
|
||||||
QLabel { |
|
||||||
color: white; |
|
||||||
font-size: 80px; |
|
||||||
background-color: transparent; |
|
||||||
} |
|
||||||
QProgressBar { |
|
||||||
background-color: #373737; |
|
||||||
width: 1000px; |
|
||||||
border solid white; |
|
||||||
border-radius: 10px; |
|
||||||
} |
|
||||||
QProgressBar::chunk { |
|
||||||
border-radius: 10px; |
|
||||||
background-color: white; |
|
||||||
} |
|
||||||
)"); |
|
||||||
|
|
||||||
notifier = new QSocketNotifier(fileno(stdin), QSocketNotifier::Read); |
|
||||||
QObject::connect(notifier, &QSocketNotifier::activated, this, &Spinner::update); |
|
||||||
} |
|
||||||
|
|
||||||
void Spinner::update(int n) { |
|
||||||
std::string line; |
|
||||||
std::getline(std::cin, line); |
|
||||||
|
|
||||||
if (line.length()) { |
|
||||||
bool number = std::all_of(line.begin(), line.end(), ::isdigit); |
|
||||||
text->setVisible(!number); |
|
||||||
progress_bar->setVisible(number); |
|
||||||
text->setText(QString::fromStdString(line)); |
|
||||||
if (number) { |
|
||||||
progress_bar->setValue(std::stoi(line)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char *argv[]) { |
|
||||||
initApp(argc, argv); |
|
||||||
QApplication a(argc, argv); |
|
||||||
Spinner spinner; |
|
||||||
setMainWindow(&spinner); |
|
||||||
return a.exec(); |
|
||||||
} |
|
@ -1,37 +0,0 @@ |
|||||||
#include <array> |
|
||||||
|
|
||||||
#include <QLabel> |
|
||||||
#include <QPixmap> |
|
||||||
#include <QProgressBar> |
|
||||||
#include <QSocketNotifier> |
|
||||||
#include <QVariantAnimation> |
|
||||||
#include <QWidget> |
|
||||||
|
|
||||||
constexpr int spinner_fps = 30; |
|
||||||
constexpr QSize spinner_size = QSize(360, 360); |
|
||||||
|
|
||||||
class TrackWidget : public QWidget { |
|
||||||
Q_OBJECT |
|
||||||
public: |
|
||||||
TrackWidget(QWidget *parent = nullptr); |
|
||||||
|
|
||||||
private: |
|
||||||
void paintEvent(QPaintEvent *event) override; |
|
||||||
std::array<QPixmap, spinner_fps> track_imgs; |
|
||||||
QVariantAnimation m_anim; |
|
||||||
}; |
|
||||||
|
|
||||||
class Spinner : public QWidget { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit Spinner(QWidget *parent = 0); |
|
||||||
|
|
||||||
private: |
|
||||||
QLabel *text; |
|
||||||
QProgressBar *progress_bar; |
|
||||||
QSocketNotifier *notifier; |
|
||||||
|
|
||||||
public slots: |
|
||||||
void update(int n); |
|
||||||
}; |
|
@ -1,3 +0,0 @@ |
|||||||
version https://git-lfs.github.com/spec/v1 |
|
||||||
oid sha256:81d7073d16e8ddc40d4d81fc88f8fc11c434df241593b455e2787935371383e4 |
|
||||||
size 3821728 |
|
@ -1,64 +0,0 @@ |
|||||||
#include <QApplication> |
|
||||||
#include <QLabel> |
|
||||||
#include <QPushButton> |
|
||||||
#include <QScrollBar> |
|
||||||
#include <QVBoxLayout> |
|
||||||
#include <QWidget> |
|
||||||
|
|
||||||
#include "system/hardware/hw.h" |
|
||||||
#include "selfdrive/ui/qt/util.h" |
|
||||||
#include "selfdrive/ui/qt/qt_window.h" |
|
||||||
#include "selfdrive/ui/qt/widgets/scrollview.h" |
|
||||||
|
|
||||||
int main(int argc, char *argv[]) { |
|
||||||
initApp(argc, argv); |
|
||||||
QApplication a(argc, argv); |
|
||||||
QWidget window; |
|
||||||
setMainWindow(&window); |
|
||||||
|
|
||||||
QGridLayout *main_layout = new QGridLayout(&window); |
|
||||||
main_layout->setMargin(50); |
|
||||||
|
|
||||||
QLabel *label = new QLabel(argv[1]); |
|
||||||
label->setWordWrap(true); |
|
||||||
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
||||||
ScrollView *scroll = new ScrollView(label); |
|
||||||
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
|
||||||
main_layout->addWidget(scroll, 0, 0, Qt::AlignTop); |
|
||||||
|
|
||||||
// Scroll to the bottom
|
|
||||||
QObject::connect(scroll->verticalScrollBar(), &QAbstractSlider::rangeChanged, [=]() { |
|
||||||
scroll->verticalScrollBar()->setValue(scroll->verticalScrollBar()->maximum()); |
|
||||||
}); |
|
||||||
|
|
||||||
QPushButton *btn = new QPushButton(); |
|
||||||
#ifdef __aarch64__ |
|
||||||
btn->setText(QObject::tr("Reboot")); |
|
||||||
QObject::connect(btn, &QPushButton::clicked, [=]() { |
|
||||||
Hardware::reboot(); |
|
||||||
}); |
|
||||||
#else |
|
||||||
btn->setText(QObject::tr("Exit")); |
|
||||||
QObject::connect(btn, &QPushButton::clicked, &a, &QApplication::quit); |
|
||||||
#endif |
|
||||||
main_layout->addWidget(btn, 0, 0, Qt::AlignRight | Qt::AlignBottom); |
|
||||||
|
|
||||||
window.setStyleSheet(R"( |
|
||||||
* { |
|
||||||
outline: none; |
|
||||||
color: white; |
|
||||||
background-color: black; |
|
||||||
font-size: 60px; |
|
||||||
} |
|
||||||
QPushButton { |
|
||||||
padding: 50px; |
|
||||||
padding-right: 100px; |
|
||||||
padding-left: 100px; |
|
||||||
border: 2px solid white; |
|
||||||
border-radius: 20px; |
|
||||||
margin-right: 40px; |
|
||||||
} |
|
||||||
)"); |
|
||||||
|
|
||||||
return a.exec(); |
|
||||||
} |
|
@ -1,3 +0,0 @@ |
|||||||
version https://git-lfs.github.com/spec/v1 |
|
||||||
oid sha256:61f539845ebfc9568c8d28867f1e5642e882f52ead8862c9b2224b7139f4a552 |
|
||||||
size 3787480 |
|
@ -1,7 +0,0 @@ |
|||||||
#!/bin/sh |
|
||||||
|
|
||||||
if [ -f /TICI ] && [ ! -f _spinner ]; then |
|
||||||
cp qt/spinner_larch64 _spinner |
|
||||||
fi |
|
||||||
|
|
||||||
exec ./_spinner "$1" |
|
@ -1,7 +0,0 @@ |
|||||||
#!/bin/sh |
|
||||||
|
|
||||||
if [ -f /TICI ] && [ ! -f _text ]; then |
|
||||||
cp qt/text_larch64 _text |
|
||||||
fi |
|
||||||
|
|
||||||
exec ./_text "$1" |
|
Loading…
Reference in new issue