diff --git a/bin/app/data/gui/splash_blue.png b/bin/app/data/gui/splash_blue.png new file mode 100755 index 00000000..85b8a0cf Binary files /dev/null and b/bin/app/data/gui/splash_blue.png differ diff --git a/bin/app/data/gui/splash_white.png b/bin/app/data/gui/splash_white.png new file mode 100755 index 00000000..e9cb70fb Binary files /dev/null and b/bin/app/data/gui/splash_white.png differ diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 075eddaf..3a1301be 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -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 diff --git a/src/app/main.cpp b/src/app/main.cpp index 70edb8d7..9d135f5b 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,9 +1,14 @@ #include #include +#include +#include +#include +#include #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 app = Application::create(&viewFactory); + if(splash) + { + delete splash; + } + return qtApp.exec(); } diff --git a/src/app/qt/element/QtSplashScreen.cpp b/src/app/qt/element/QtSplashScreen.cpp new file mode 100644 index 00000000..80605192 --- /dev/null +++ b/src/app/qt/element/QtSplashScreen.cpp @@ -0,0 +1,63 @@ +#include "QtSplashScreen.h" + +#include + +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); +} + diff --git a/src/app/qt/element/QtSplashScreen.h b/src/app/qt/element/QtSplashScreen.h new file mode 100644 index 00000000..65d454ab --- /dev/null +++ b/src/app/qt/element/QtSplashScreen.h @@ -0,0 +1,34 @@ +#ifndef QTSPLASHSCREEN_H +#define QTSPLASHSCREEN_H + +#include +#include +#include + +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