Skip to content
Snippets Groups Projects
Commit 285791a2 authored by Mohammad Mahadi Hasan's avatar Mohammad Mahadi Hasan
Browse files

redigned splash screen

parent d25019eb
No related branches found
No related tags found
No related merge requests found
#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...");
}
#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
#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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment