QTfrontend/ui/widget/bgwidget.cpp
changeset 6574 ec059b55aa72
parent 6243 9777d802be1a
child 6579 fc52f7c22c9b
equal deleted inserted replaced
6573:632fa142c2cf 6574:ec059b55aa72
    80 {
    80 {
    81     fY = qrand() % (wParent->height() + 1);
    81     fY = qrand() % (wParent->height() + 1);
    82     fX = qrand() % (wParent->width() + 1);
    82     fX = qrand() % (wParent->width() + 1);
    83 }
    83 }
    84 
    84 
    85 BGWidget::BGWidget(QWidget * parent) : QWidget(parent)
    85 BGWidget::BGWidget(QWidget * parent) : QWidget(parent), enabled(false)
    86 {
    86 {
    87     setAttribute(Qt::WA_NoSystemBackground, true);
    87     setAttribute(Qt::WA_NoSystemBackground, true);
    88     sprite.load(":/res/Star.png");
    88     sprite.load(":/res/Star.png");
    89 
    89 
    90     setAutoFillBackground(false);
    90     setAutoFillBackground(false);
   121 }
   121 }
   122 
   122 
   123 void BGWidget::paintEvent(QPaintEvent *event)
   123 void BGWidget::paintEvent(QPaintEvent *event)
   124 {
   124 {
   125     Q_UNUSED(event);
   125     Q_UNUSED(event);
       
   126     if (!enabled)
       
   127         return;
   126 
   128 
   127     QPainter p;
   129     QPainter p;
   128 
   130 
   129     p.begin(this);
   131     p.begin(this);
   130 
   132 
   137     p.end();
   139     p.end();
   138 }
   140 }
   139 
   141 
   140 void BGWidget::animate()
   142 void BGWidget::animate()
   141 {
   143 {
       
   144     if (!enabled)
       
   145         return;
       
   146 
   142     for (int i = 0; i < SPRITE_MAX; i++)
   147     for (int i = 0; i < SPRITE_MAX; i++)
   143     {
   148     {
   144         QPoint oldPos = spritePositions[i]->pos();
   149         QPoint oldPos = spritePositions[i]->pos();
   145         spritePositions[i]->move();
   150         spritePositions[i]->move();
   146         QPoint newPos = spritePositions[i]->pos();
   151         QPoint newPos = spritePositions[i]->pos();
   157 }
   162 }
   158 
   163 
   159 void BGWidget::stopAnimation()
   164 void BGWidget::stopAnimation()
   160 {
   165 {
   161     timerAnimation->stop();
   166     timerAnimation->stop();
       
   167     repaint();
   162 }
   168 }
   163 
   169 
   164 void BGWidget::init()
   170 void BGWidget::init()
   165 {
   171 {
   166     for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i]->init();
   172     for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i]->init();