RunHorse::RunHorse(QWidget *parent, QString str)
: QWidget(parent), s_mark(""), ibl(0), ibtm(0), wcoins(0), icount(0)
{
ui.setupUi(this);
setWindowModality(Qt::ApplicationModal);
setWindowFlags(windowFlags()&~ Qt::WindowMinMaxButtonsHint );
setWindowTitle(QString("跑马进行中......"));
setWindowIcon(QIcon(":/window/horse.ico"));
//resize(1040, 772);
ui.label_bl->hide();
QStringList strList = str.split(",");
qDebug() << strList.count();
s_mark = strList.at(0);
ibl = strList.at(1).toInt();
ibtm = strList.at(2).toInt();
tcoins = strList.at(3).toInt();
wcoins = ibtm * ibl;
ui.label_coins->setText(strList.at(3));
mv = new QMovie(s_mark+".dat");
mv->setScaledSize(ui.label->size());
timer = new QTimer(this);
timer->setInterval(500);
connect(mv, SIGNAL(frameChanged(int)), this, SLOT(stopMovie(int)));
connect(timer, SIGNAL(timeout()), this, SLOT(showInfo()));
m_play = new MediaPlay(this);
m_play->setMedia("qrc:/music/run.MP3");
m_play->play();
ui.label->setMovie(mv);
mv->start();
this->setMaximumSize(this->size());
this->setMinimumSize(this->size());
}
RunHorse::~RunHorse()
{
delete mv;
delete timer;
delete m_play;
}
void RunHorse::stopMovie(int fra)
{
if (fra == mv->frameCount() - 1)
{
mv->stop();
ui.label_won->setText(QString("%1").arg(ibl*ibtm));
ui.label_coins->setText(QString("%1").arg(tcoins + ibl*ibtm));
timer->start();
m_play->setMedia("qrc:/music/win.MP3");
m_play->play();
}
}
void RunHorse::showInfo()
{
ui.label_bl->setText(QString("%1").arg(ibl));
if (ui.label_bl->isVisible())
ui.label_bl->setVisible(false);
else
ui.label_bl->setVisible(true);
icount++;
QString sinfo = QString("[中马:" + s_mark + "倍率%1,押注%2,赢%3],nil,nil").arg(ibl).arg(ibtm).arg(wcoins);
if (icount == 8)
{
//emit sendInfo(sinfo);
timer->stop();
m_play->stop();
//emit finished_run();
close();
}
}
void RunHorse::closeEvent(QCloseEvent *e)
{
m_play->stop();
//timer->stop();
QString sinfo = QString("[中马:" + s_mark + "倍率%1-押注%2-赢%3],nil,nil").arg(ibl).arg(ibtm).arg(wcoins);
emit sendInfo(sinfo);
emit finished_run();
}