iCub-main
loadingwidget.cpp
Go to the documentation of this file.
1 #include "loadingwidget.h"
2 #include "ui_loadingwidget.h"
3 #include <QFontMetrics>
4 
5 LoadingWidget::LoadingWidget(QWidget *parent) :
6  QDialog(parent),
7  ui(new Ui::LoadingWidget)
8 {
9  ui->setupUi(this);
10 
11  setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
12  setAttribute(Qt::WA_TranslucentBackground);
13 
14  setModal(true);
15 
16 
17  splashTimer.setInterval(50);
18  splashTimer.setSingleShot(false);
19  connect(&splashTimer,SIGNAL(timeout()),this,SLOT(onSplashTimer()),Qt::DirectConnection);
20 }
21 
23 {
24  delete ui;
25 }
26 
27 
28 void LoadingWidget::onSplashTimer()
29 {
30  QString name = QString(":/images/splash/bg%1.png").arg(counter+1);
31  counter++;
32  counter = counter % 8;
33  ui->loadingIco->setPixmap(QPixmap(name));
34  ui->loadingIco->repaint();
35 }
36 
37 
38 int LoadingWidget::start(QString msg)
39 {
40  if(!msg.isEmpty()){
41  ui->text->setText(msg);
42  QFont f = ui->text->font();
43  QFontMetrics metric = QFontMetrics(f);
44 
45  int w = metric.width(msg);
46 
47  if(w > width()){
48  setMinimumWidth(w);
49  setMaximumWidth(w);
50  }
51  }
52  QWidget *w =((QWidget*)parent());
53  int x = w->x() + ((w->width() - width()) / 2);
54  int y = w->y() + ((w->height() - height()) / 2);
55  this->setGeometry(x,y,width(),height());
56  splashTimer.start();
57  //return exec();
58  show();
59  return 0;
60 }
61 
63 {
64  //accept();
65  hide();
66  splashTimer.stop();
67 }
LoadingWidget(QWidget *parent=0)