diff --git a/GUI/coregui/Views/SplashScreen.cpp b/GUI/coregui/Views/SplashScreen.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b2d7d3bf31e4530fe3510a8495ecbb814a8df250 --- /dev/null +++ b/GUI/coregui/Views/SplashScreen.cpp @@ -0,0 +1,43 @@ +#include "SplashScreen.h" +#include <QStyleOptionProgressBarV2> + +SplashScreen::SplashScreen(QApplication *aApp, QWidget *parent) : + QSplashScreen(parent), app(aApp), m_progress(0) + +{ + m_width = 500; + m_height = 500; + + this->setPixmap(QPixmap(":/images/BornAgain.ico").scaled(m_width, m_height, Qt::KeepAspectRatio)); + this->setCursor(Qt::BusyCursor); + + QFont font; + font.setPointSize(10); + font.setBold(false); + this->setFont(font); + + //this->showMessage("\t\t\t\t\t\tLoading application...", Qt::AlignBottom); +} + +void SplashScreen::drawContents(QPainter *painter) +{ + QSplashScreen::drawContents(painter); + + int width = 150; + int height = 8; + + // Set style for progressbar... + QStyleOptionProgressBarV2 pbstyle; + pbstyle.initFrom(this); + pbstyle.state = QStyle::State_Enabled; + pbstyle.textVisible = false; + pbstyle.minimum = 0; + pbstyle.maximum = 100; + pbstyle.progress = m_progress; + pbstyle.invertedAppearance = false; + pbstyle.rect = QRect(m_width-width-35, m_height-height-12, width, height); + + style()->drawControl(QStyle::CE_ProgressBar, &pbstyle, painter, this); + + style()->drawItemText(painter,QRect(30, m_height-25, 200, 20),0, this->palette(), true, "Loading application..."); +} diff --git a/GUI/coregui/Views/SplashScreen.h b/GUI/coregui/Views/SplashScreen.h new file mode 100644 index 0000000000000000000000000000000000000000..837374f72e93ecf5dd271289766024c8d136fa42 --- /dev/null +++ b/GUI/coregui/Views/SplashScreen.h @@ -0,0 +1,33 @@ +#ifndef SPLASHSCREEN_H +#define SPLASHSCREEN_H + +#include <QSplashScreen> +#include <QApplication> + +class SplashScreen : public QSplashScreen +{ + Q_OBJECT +public: + explicit SplashScreen(QApplication *app, QWidget *parent = 0); + int m_progress; + QApplication *app; + +public slots: + void setProgress(int value) + { + m_progress = value; + if (m_progress > 100) + m_progress = 100; + if (m_progress < 0) + m_progress = 0; + update(); + } + +protected: + void drawContents(QPainter *painter); +private: + int m_width, m_height; + +}; + +#endif diff --git a/GUI/main/main.cpp b/GUI/main/main.cpp index 4a228a5bf50777683f633b24dbd9afaad85ff28c..e8cf4f0a50db433d4a879587348833005d02dd98 100644 --- a/GUI/main/main.cpp +++ b/GUI/main/main.cpp @@ -1,10 +1,10 @@ #include "mainwindow.h" +#include "SplashScreen.h" #include <QApplication> #include <QDebug> #include <iostream> -#include <QSplashScreen> #include <QTime> int main(int argc, char *argv[]) @@ -12,21 +12,23 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); - QPixmap pixmap(":/images/BornAgain.ico"); - QSplashScreen splash(pixmap.scaled(500,500,Qt::KeepAspectRatio)); - splash.show(); - a.processEvents(); + SplashScreen *splash = new SplashScreen(&a); + splash->show(); - QTime dieTime = QTime::currentTime().addMSecs( 1500 ); + int time = 1000; + QTime dieTime = QTime::currentTime().addMSecs(1000); + QTime timer; + timer.start(); while( QTime::currentTime() < dieTime ) { + splash->setProgress(timer.elapsed()/(time/100)); QCoreApplication::processEvents( QEventLoop::AllEvents, 100 ); } MainWindow w; w.show(); - splash.finish(&w); + splash->finish(&w); //#ifdef BORNAGAIN_CRASHHANDLER // std::cout << "BORNAGAIN_CRASHHANDLER" << std::endl;