Files
pokerth/src/gui/qt/mainwindow/mysetlabel.cpp
T

124 lines
2.8 KiB
C++
Raw Normal View History

//
// C++ Implementation: mycardspixmaplabel
//
// Description:
//
//
// Author: FThauer FHammer <f.thauer@web.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "mysetlabel.h"
2007-05-30 07:21:24 +00:00
#include "mainwindowimpl.h"
using namespace std;
MySetLabel::MySetLabel(QGroupBox* parent)
2007-06-10 20:43:48 +00:00
: QLabel(parent), timeOutAnimation(FALSE), timeOutValue(0), timeOutFrame(0), waitFrames(0), decreaseWidthIntervall(1), timerIntervall(0)
{
timeOutAnimationTimer = new QTimer;
2007-06-08 20:35:36 +00:00
connect(timeOutAnimationTimer, SIGNAL(timeout()), this, SLOT(nextTimeOutAnimationFrame()));
}
MySetLabel::~MySetLabel()
{
}
void MySetLabel::startTimeOutAnimation(int secs) {
2007-06-10 20:43:48 +00:00
decreaseWidthIntervall = 1;
timeOutValue = secs;
timeOutFrame = 1;
timeOutAnimationWidth = 118;
2007-06-10 20:43:48 +00:00
int preTimerIntervall = ((timeOutValue-3) * 1000)/timeOutAnimationWidth;
timerIntervall = preTimerIntervall;
//save gfx ressources and never play more the 10 pps
while(timerIntervall < 100) {
if(secs <= 9 && secs >= 6) {
//fix inaccuracies caused by integer division
timerIntervall = timerIntervall + preTimerIntervall + 5;
}
else {
timerIntervall = timerIntervall + preTimerIntervall;
}
decreaseWidthIntervall++;
}
waitFrames = 3000/timerIntervall;
2007-06-14 23:27:13 +00:00
//start the real timer
realTimer.reset();
realTimer.start();
2007-06-10 20:43:48 +00:00
2007-06-10 21:45:31 +00:00
// std::cout << timerIntervall << endl;
2007-06-10 20:43:48 +00:00
timeOutAnimation = TRUE;
timeOutAnimationTimer->start(timerIntervall);
}
2007-06-08 20:35:36 +00:00
void MySetLabel::startTimeOutAnimationNow() {
timeOutAnimation = TRUE;
timeOutAnimationTimer->start(83);
}
void MySetLabel::stopTimeOutAnimation() {
2007-06-10 20:43:48 +00:00
// timeOutAnimationKickOnTimer->stop();
timeOutAnimationTimer->stop();
timeOutAnimation = FALSE;
update();
}
void MySetLabel::nextTimeOutAnimationFrame() {
if(timeOutAnimationWidth >=0) {
2007-06-10 20:43:48 +00:00
if(timeOutFrame > waitFrames) {
//save gfx ressources and never play more the 10 pps
2007-06-14 23:27:13 +00:00
// timeOutAnimationWidth = timeOutAnimationWidth - decreaseWidthIntervall;
unsigned int realTimerValue = realTimer.elapsed().total_milliseconds();
2007-06-14 23:34:51 +00:00
timeOutAnimationWidth = 118-(((realTimerValue-3000)*118)/((timeOutValue-3)*1000));
2007-06-14 23:27:13 +00:00
2007-06-10 20:43:48 +00:00
}
timeOutFrame++;
update();
}
2007-05-30 07:21:24 +00:00
else {
stopTimeOutAnimation();
// no callback is called here.
// the server initiates any action required.
2007-05-30 07:21:24 +00:00
}
}
void MySetLabel::paintEvent(QPaintEvent * event) {
2007-06-10 20:43:48 +00:00
if(!timeOutAnimation || timeOutFrame <= waitFrames) {
QLabel::paintEvent(event);
}
2007-06-10 20:43:48 +00:00
if(timeOutAnimation && timeOutFrame > waitFrames) {
QPainter painter(this);
QLinearGradient linearGrad(QPointF(0, 10), QPointF(113, 10));
linearGrad.setColorAt(0, Qt::red);
linearGrad.setColorAt(0.5, Qt::yellow);
linearGrad.setColorAt(1, Qt::green);
painter.setBrush(linearGrad);
painter.setPen(QColor(0,0,0));
2007-06-10 20:43:48 +00:00
painter.drawRect(0,6,timeOutAnimationWidth-1,8);
}
}