|
@@ -3,6 +3,78 @@
|
|
#include <QPixmap>
|
|
#include <QPixmap>
|
|
#include <QDesktopWidget>
|
|
#include <QDesktopWidget>
|
|
#include <QSplashScreen>
|
|
#include <QSplashScreen>
|
|
|
|
+#include <QMovie>
|
|
|
|
+#include <QTimer>
|
|
|
|
+#include <cmath>
|
|
|
|
+
|
|
|
|
+class AlmondSplashScreen : public QSplashScreen
|
|
|
|
+{
|
|
|
|
+private:
|
|
|
|
+ float animOff = 0.0f;
|
|
|
|
+ QTimer animUpdate;
|
|
|
|
+ volatile bool updated = true;
|
|
|
|
+public:
|
|
|
|
+ AlmondSplashScreen(QPixmap splash) :
|
|
|
|
+ QSplashScreen{ splash },
|
|
|
|
+ animUpdate{ this }
|
|
|
|
+ {
|
|
|
|
+ animUpdate.start(10);
|
|
|
|
+ //loading.start();
|
|
|
|
+ //this->add(loading);
|
|
|
|
+ //connect(&loading, &QMovie::updated, this, &AlmondSplashScreen::nextFrame);
|
|
|
|
+ connect(&animUpdate, &QTimer::timeout, this, &AlmondSplashScreen::nextFrame);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ~AlmondSplashScreen(void)
|
|
|
|
+ {
|
|
|
|
+ animUpdate.stop();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void drawContents(QPainter* painter) override
|
|
|
|
+ {
|
|
|
|
+ QSplashScreen::drawContents(painter);
|
|
|
|
+ drawAnimation(painter);
|
|
|
|
+ updated = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void drawAnimation(QPainter* painter)
|
|
|
|
+ {
|
|
|
|
+ const auto minimum = [] (auto a, auto b, auto c) {
|
|
|
|
+ return a < b ? (a < c ? a : c) : (b < c ? b : c);
|
|
|
|
+ };
|
|
|
|
+ int width = this->width();
|
|
|
|
+ int height = this->height();
|
|
|
|
+ int pieces = 7;
|
|
|
|
+ float off = ::fmod(animOff, width / pieces);
|
|
|
|
+ for (int i = 0; i < pieces; i++) {
|
|
|
|
+ float x = off + i * width / pieces;
|
|
|
|
+ float accelOff = 0;
|
|
|
|
+
|
|
|
|
+ if (x < 160)
|
|
|
|
+ accelOff = (160 - x) * (160 - x) / 160 ;
|
|
|
|
+ else if (x > width - 160)
|
|
|
|
+ accelOff = -(width - 160 - x) * (width - 160 - x) / 160 ;
|
|
|
|
+
|
|
|
|
+ x -= accelOff;
|
|
|
|
+
|
|
|
|
+ if (x < 0 || x > width)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ float opacity = minimum(x, width - x, 130);
|
|
|
|
+ QPen pen(QColor(255, 255, 255, int(opacity)));
|
|
|
|
+ pen.setWidth(4);
|
|
|
|
+ painter->setPen(pen);
|
|
|
|
+ painter->drawEllipse(QRectF{ x, height - 40, 16, 16 });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+public slots:
|
|
|
|
+ void nextFrame() //(const QRect& rect)
|
|
|
|
+ {
|
|
|
|
+ emit this->repaint();
|
|
|
|
+ animOff += 7;
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
int main(int argc, char *argv[])
|
|
{
|
|
{
|
|
@@ -13,13 +85,16 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
QPixmap splashImg(":/splash/splash");
|
|
QPixmap splashImg(":/splash/splash");
|
|
QPixmap splashScaled = splashImg.scaled(splashW, splashW * splashImg.height() / splashImg.width());
|
|
QPixmap splashScaled = splashImg.scaled(splashW, splashW * splashImg.height() / splashImg.width());
|
|
- QSplashScreen splash{ splashScaled };
|
|
|
|
|
|
+ AlmondSplashScreen splash{ splashScaled };
|
|
splash.show();
|
|
splash.show();
|
|
- a.processEvents();
|
|
|
|
-
|
|
|
|
|
|
+ /*for (int i = 0; i < 100; i++) {
|
|
|
|
+ a.processEvents();
|
|
|
|
+ system("sleep 0.03");
|
|
|
|
+ }*/
|
|
Almond w;
|
|
Almond w;
|
|
- w.show();
|
|
|
|
|
|
+ a.processEvents();
|
|
splash.finish(&w);
|
|
splash.finish(&w);
|
|
|
|
+ w.show();
|
|
return a.exec();
|
|
return a.exec();
|
|
}
|
|
}
|
|
|
|
|