Qt spinner (#2494)
	
		
	
				
					
				
			* move android spinner * qt spinner * rotation * nothing by default * spin spin * fix rotate * style * spinner for all * -2 * unusedpull/2498/head
							parent
							
								
									c6e1beb402
								
							
						
					
					
						commit
						6c86afee16
					
				
				 15 changed files with 192 additions and 68 deletions
			
			
		| @ -1,14 +0,0 @@ | ||||
| #ifndef COMMON_SPINNER_H | ||||
| #define COMMON_SPINNER_H | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
| 
 | ||||
| int spin(int argc, char** argv); | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
| @ -1,2 +1,5 @@ | ||||
| moc_* | ||||
| *.moc | ||||
| 
 | ||||
| qt/text | ||||
| qt/spinner | ||||
|  | ||||
| @ -0,0 +1,126 @@ | ||||
| #include <stdio.h> | ||||
| #include <string> | ||||
| #include <iostream> | ||||
| 
 | ||||
| #include <QString> | ||||
| #include <QGridLayout> | ||||
| #include <QApplication> | ||||
| #include <QDesktopWidget> | ||||
| 
 | ||||
| #ifdef QCOM2 | ||||
| #include <qpa/qplatformnativeinterface.h> | ||||
| #include <QPlatformSurfaceEvent> | ||||
| #include <wayland-client-protocol.h> | ||||
| #endif | ||||
| 
 | ||||
| #include "spinner.hpp" | ||||
| 
 | ||||
| 
 | ||||
| Spinner::Spinner(QWidget *parent) { | ||||
|   QGridLayout *main_layout = new QGridLayout(); | ||||
|   main_layout->setSpacing(0); | ||||
|   main_layout->setMargin(50); | ||||
| 
 | ||||
|   const int img_size = 500; | ||||
| 
 | ||||
|   comma = new QLabel(); | ||||
|   comma->setPixmap(QPixmap("../assets/img_spinner_comma.png").scaled(img_size, img_size, Qt::KeepAspectRatio)); | ||||
|   comma->setFixedSize(img_size, img_size); | ||||
|   main_layout->addWidget(comma, 0, 0, Qt::AlignHCenter | Qt::AlignVCenter); | ||||
| 
 | ||||
|   track_img = QPixmap("../assets/img_spinner_track.png").scaled(img_size, img_size, Qt::KeepAspectRatio); | ||||
|   track = new QLabel(); | ||||
|   track->setPixmap(track_img); | ||||
|   track->setFixedSize(img_size, img_size); | ||||
|   main_layout->addWidget(track, 0, 0, Qt::AlignHCenter | Qt::AlignVCenter); | ||||
| 
 | ||||
|   text = new QLabel("building boardd"); | ||||
|   text->setVisible(false); | ||||
|   text->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||||
|   main_layout->addWidget(text, 1, 0, Qt::AlignHCenter); | ||||
| 
 | ||||
|   progress_bar = new QProgressBar(); | ||||
|   progress_bar->setMinimum(5); | ||||
|   progress_bar->setMaximum(100); | ||||
|   progress_bar->setTextVisible(false); | ||||
|   progress_bar->setVisible(false); | ||||
|   progress_bar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||||
|   main_layout->addWidget(progress_bar, 1, 0, Qt::AlignHCenter); | ||||
| 
 | ||||
|   setLayout(main_layout); | ||||
|   setStyleSheet(R"( | ||||
|     Spinner { | ||||
|       background-color: black; | ||||
|     } | ||||
|     QLabel { | ||||
|       color: white; | ||||
|       font-size: 80px; | ||||
|     } | ||||
|     QProgressBar { | ||||
|       background-color: #373737; | ||||
|       border: none; | ||||
|       margin: 100px; | ||||
|       height: 50px; | ||||
|       width: 1000px; | ||||
|     } | ||||
|     QProgressBar::chunk { | ||||
|       background-color: white; | ||||
|     } | ||||
|   )"); | ||||
| 
 | ||||
|   rotate_timer = new QTimer(this); | ||||
|   rotate_timer->start(1000/30.); | ||||
|   QObject::connect(rotate_timer, SIGNAL(timeout()), this, SLOT(rotate())); | ||||
| 
 | ||||
|   notifier = new QSocketNotifier(fileno(stdin), QSocketNotifier::Read); | ||||
|   QObject::connect(notifier, SIGNAL(activated(int)), this, SLOT(update(int))); | ||||
| }; | ||||
| 
 | ||||
| void Spinner::rotate() { | ||||
|   transform.rotate(5); | ||||
| 
 | ||||
|   QPixmap r = track_img.transformed(transform); | ||||
|   int x = (r.width() - track_img.width()) / 2; | ||||
|   int y = (r.height() - track_img.height()) / 2; | ||||
|   track->setPixmap(r.copy(x, y, track_img.width(), track_img.height())); | ||||
| }; | ||||
| 
 | ||||
| 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[]) { | ||||
|   QApplication a(argc, argv); | ||||
| 
 | ||||
|   Spinner *spinner = new Spinner(); | ||||
| 
 | ||||
|   // TODO: get size from QScreen, doesn't work on tici
 | ||||
| #ifdef QCOM2 | ||||
|   int w = 2160, h = 1080; | ||||
| #else | ||||
|   int w = 1920, h = 1080; | ||||
| #endif | ||||
|   spinner->setFixedSize(w, h); | ||||
|   spinner->show(); | ||||
| 
 | ||||
| #ifdef QCOM2 | ||||
|   QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); | ||||
|   wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", spinner->windowHandle())); | ||||
|   wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270); | ||||
|   wl_surface_commit(s); | ||||
|   spinner->showFullScreen(); | ||||
| #endif | ||||
| 
 | ||||
|   return a.exec(); | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| #include <QTimer> | ||||
| #include <QLabel> | ||||
| #include <QWidget> | ||||
| #include <QPixmap> | ||||
| #include <QProgressBar> | ||||
| #include <QTransform> | ||||
| #include <QSocketNotifier> | ||||
| 
 | ||||
| class Spinner : public QWidget { | ||||
|   Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|   explicit Spinner(QWidget *parent = 0); | ||||
| 
 | ||||
| private: | ||||
|   QPixmap track_img; | ||||
|   QTimer *rotate_timer; | ||||
|   QLabel *comma, *track; | ||||
|   QLabel *text; | ||||
|   QProgressBar *progress_bar; | ||||
|   QTransform transform; | ||||
|   QSocketNotifier *notifier; | ||||
| 
 | ||||
| public slots: | ||||
|   void rotate(); | ||||
|   void update(int n); | ||||
| }; | ||||
| @ -0,0 +1,8 @@ | ||||
| #!/bin/sh | ||||
| 
 | ||||
| if [ -f /EON ]; then | ||||
|   export LD_LIBRARY_PATH="/system/lib64:$LD_LIBRARY_PATH" | ||||
|   exec ./android/spinner/spinner "$1" | ||||
| else | ||||
|   exec ./qt/spinner "$1" | ||||
| fi | ||||
| @ -1,21 +0,0 @@ | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <stdbool.h> | ||||
| #include <math.h> | ||||
| #include <unistd.h> | ||||
| #include <assert.h> | ||||
| 
 | ||||
| #include <GLES3/gl3.h> | ||||
| #include <EGL/egl.h> | ||||
| #include <EGL/eglext.h> | ||||
| 
 | ||||
| #include "common/framebuffer.h" | ||||
| #include "common/spinner.h" | ||||
| 
 | ||||
| int main(int argc, char** argv) { | ||||
|   int err; | ||||
| 
 | ||||
|   spin(argc, argv); | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue