ui: splashscreen

displays an animated splayscreen
This commit is contained in:
Andreas Stallinger
2015-05-04 15:11:49 +02:00
parent 9c7e76b80a
commit 0763dc9cdf
6 changed files with 147 additions and 1 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

+2
View File
@@ -21,6 +21,8 @@ add_files(
qt/element/QtSearchBar.h
qt/element/QtSmartSearchBox.cpp
qt/element/QtSmartSearchBox.h
qt/element/QtSplashScreen.cpp
qt/element/QtSplashScreen.h
qt/element/QtStatusBar.cpp
qt/element/QtStatusBar.h
qt/element/QtUndoRedo.cpp
+48 -1
View File
@@ -1,9 +1,14 @@
#include <memory>
#include <QApplication>
#include <QBitmap>
#include <QThread>
#include <QSplashScreen>
#include <QtWidgets/qmainwindow.h>
#include "Application.h"
#include "includes.h" // defines 'void setup(int argc, char *argv[])'
#include "qt/element/QtSplashScreen.h"
#include "qt/utility/utilityQt.h"
#include "qt/view/QtViewFactory.h"
#include "utility/logging/ConsoleLogger.h"
@@ -23,16 +28,58 @@ void init()
utility::loadFontsFromDirectory("data/fonts", ".otf");
}
class InitThread : public QThread
{
public:
void run(void)
{
//min Time the Splash screen is displayed
//QThread::msleep(1000);
}
};
int main(int argc, char *argv[])
{
setup(argc, argv);
QApplication qtApp(argc, argv);
QPixmap whitePixmap(500,500);
whitePixmap.fill(Qt::white);
QPixmap p;
p.load("data/gui/splash_white.png");
QPixmap foreground = p.scaled(whitePixmap.size()*0.8);
p.load("data/gui/splash_blue.png");
QPixmap background = p.scaled(whitePixmap.size()*0.9);
QtSplashScreen* splash = new QtSplashScreen(whitePixmap, Qt::WindowStaysOnTopHint);
qtApp.processEvents();
splash->setForeground(foreground);
splash->setBackground(background);
splash->show();
splash->repaint();
qtApp.processEvents();
if (splash) splash->message( "Starting GUI" );
qtApp.processEvents();
init();
// Eventloop for Splashscreen
QEventLoop loop;
InitThread* initThread = new InitThread();
QObject::connect(initThread, SIGNAL(finished()), &loop, SLOT(quit()));
QObject::connect(initThread, SIGNAL(terminated()), &loop, SLOT(quit()));
initThread->start();
loop.exec();
QtViewFactory viewFactory;
std::shared_ptr<Application> app = Application::create(&viewFactory);
if(splash)
{
delete splash;
}
return qtApp.exec();
}
+63
View File
@@ -0,0 +1,63 @@
#include "QtSplashScreen.h"
#include <QTimer>
QtSplashScreen::QtSplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) : QSplashScreen (pixmap, f)
{
state = 0;
QTimer *timer = new QTimer( this );
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
timer->start(150);
show();
repaint();
}
QtSplashScreen::~QtSplashScreen()
{
}
void QtSplashScreen::animate()
{
state = (state+2)%120;
repaint();
}
void QtSplashScreen::setBackground(QPixmap& pixmap)
{
m_Background = pixmap;
}
void QtSplashScreen::setForeground(QPixmap &pixmap)
{
m_Foreground = pixmap;
}
void QtSplashScreen::message(const QString &str, int flag, const QColor &color)
{
QSplashScreen::showMessage(str,flag,color);
animate();
m_string = str;
}
void QtSplashScreen::drawContents(QPainter *painter)
{
painter->save();
painter->translate(rect().width()/2,rect().height()/2);
painter->rotate(state*3);
painter->drawPixmap(-rect().width()*0.9/2,-rect().height()*0.9/2,m_Background);
painter->restore();
painter->drawPixmap(rect().width()*0.1,rect().height()*0.1,m_Foreground);
painter->setPen(QColor(74,112,18));
QRect r = rect();
r.setRect(r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10);
// TODO: automated Version number
painter->drawText(r, Qt::AlignRight, "Version 0.0.0");
// Draw message at given position, limited to 43 chars
// If message is too long, string is truncated
if (m_string.length() > 40) {m_string.truncate(39); m_string += "...";}
painter->drawText(90, 16,m_string);
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef QTSPLASHSCREEN_H
#define QTSPLASHSCREEN_H
#include <QSplashScreen>
#include <QPainter>
#include <QWidget>
class QPixmap;
class QtSplashScreen : public QSplashScreen
{
Q_OBJECT
public:
QtSplashScreen(const QPixmap& pixmap, Qt::WindowFlags f = 0);
QtSplashScreen(Qt::WindowFlags f = 0);
virtual ~QtSplashScreen();
void setBackground(QPixmap& pixmap);
void setForeground(QPixmap& pixmap);
protected:
void drawContents(QPainter* painter);
public slots:
void animate();
void message(const QString& str, int flag = Qt::AlignLeft, const QColor& color = Qt::black);
private:
QString m_string;
int state;
QPixmap m_Background;
QPixmap m_Foreground;
};
#endif //QTSPLASHSCREEN_H