move timeout animation from setlabel to new position

This commit is contained in:
doitux
2009-04-20 21:13:49 +00:00
parent a3944f1379
commit a75abcbb6a
6 changed files with 148 additions and 143 deletions
+121 -4
View File
@@ -256,6 +256,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout3">
<property name="geometry">
<rect>
<x>12</x>
<y>70</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
<item>
@@ -461,6 +474,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout2">
<property name="geometry">
<rect>
<x>12</x>
<y>61</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
<item>
@@ -673,6 +699,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout4">
<property name="geometry">
<rect>
<x>12</x>
<y>70</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
<item>
@@ -865,6 +904,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout5">
<property name="geometry">
<rect>
<x>12</x>
<y>70</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
<item>
@@ -1057,6 +1109,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout6">
<property name="geometry">
<rect>
<x>12</x>
<y>70</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
</layout>
@@ -1269,6 +1334,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout7">
<property name="geometry">
<rect>
<x>12</x>
<y>70</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
<item>
@@ -1474,6 +1552,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout8">
<property name="geometry">
<rect>
<x>12</x>
<y>61</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
<item>
@@ -2118,6 +2209,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout1">
<property name="geometry">
<rect>
<x>12</x>
<y>61</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
<item>
@@ -2313,10 +2417,10 @@
<widget class="MyTimeoutLabel" name="label_Timeout0">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>50</width>
<height>17</height>
<x>12</x>
<y>61</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
@@ -2515,6 +2619,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="MyTimeoutLabel" name="label_Timeout9">
<property name="geometry">
<rect>
<x>12</x>
<y>61</y>
<width>52</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
</layout>
+19 -8
View File
@@ -255,6 +255,19 @@ gameTableImpl::gameTableImpl(ConfigFile *c, QMainWindow *parent)
playerAvatarLabelArray[i]->setMyId(i);
}
// timeoutLabelArray init
timeoutLabelArray[0] = label_Timeout0;
timeoutLabelArray[1] = label_Timeout1;
timeoutLabelArray[2] = label_Timeout2;
timeoutLabelArray[3] = label_Timeout3;
timeoutLabelArray[4] = label_Timeout4;
timeoutLabelArray[5] = label_Timeout5;
timeoutLabelArray[6] = label_Timeout6;
timeoutLabelArray[7] = label_Timeout7;
timeoutLabelArray[8] = label_Timeout8;
timeoutLabelArray[9] = label_Timeout9;
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) { timeoutLabelArray[i]->setMyW(this); }
// setLabelArray init
setLabelArray[0] = textLabel_Set0;
setLabelArray[1] = textLabel_Set1;
@@ -1498,14 +1511,13 @@ void gameTableImpl::startTimeoutAnimation(int playerId, int timeoutSec) {
assert(playerId >= 0 && playerId < myStartWindow->getSession()->getCurrentGame()->getStartQuantityPlayers());
//beep for player 0
if(playerId) { setLabelArray[playerId]->startTimeOutAnimation(timeoutSec, FALSE); }
else { setLabelArray[playerId]->startTimeOutAnimation(timeoutSec, TRUE); }
label_Timeout0->startTimeOutAnimation(timeoutSec, FALSE);
if(playerId) { timeoutLabelArray[playerId]->startTimeOutAnimation(timeoutSec, FALSE); }
else { timeoutLabelArray[playerId]->startTimeOutAnimation(timeoutSec, TRUE); }
}
void gameTableImpl::stopTimeoutAnimation(int playerId) {
assert(playerId >= 0 && playerId < myStartWindow->getSession()->getCurrentGame()->getStartQuantityPlayers());
setLabelArray[playerId]->stopTimeOutAnimation();
timeoutLabelArray[playerId]->stopTimeOutAnimation();
}
void gameTableImpl::disableMyButtons() {
@@ -2390,7 +2402,7 @@ void gameTableImpl::nextRoundCleanGui() {
boardCardsArray[i]->setPixmap(onePix, FALSE);
boardCardsArray[i]->setFadeOutAction(FALSE);
boardCardsArray[i]->stopFlipCardsAnimation();
setLabelArray[i]->stopTimeOutAnimation();
timeoutLabelArray[i]->stopTimeOutAnimation();
}
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++ ) {
@@ -2590,8 +2602,7 @@ void gameTableImpl::keyPressEvent ( QKeyEvent * event ) {
else { keyUpDownChatCounter = 0; }
//TESTING UNIT
//if (event->key() == Qt::Key_M) { startVoteOnKick(3,60, 6); }
//if (event->key() == Qt::Key_N) { endVoteOnKick(); }
//if (event->key() == Qt::Key_M) { startVoteOnKick(3,60, 6); }
}
void gameTableImpl::changePlayingMode() {
@@ -2760,7 +2771,7 @@ void gameTableImpl::localGameModification() {
int i;
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++ ) {
setLabelArray[i]->stopTimeOutAnimation();
timeoutLabelArray[i]->stopTimeOutAnimation();
playerAvatarLabelArray[i]->setEnabledContextMenu(FALSE);
}
+1
View File
@@ -356,6 +356,7 @@ private:
QLabel *actionLabelArray[MAX_NUMBER_OF_PLAYERS];
QLabel *playerNameLabelArray[MAX_NUMBER_OF_PLAYERS];
MyAvatarLabel *playerAvatarLabelArray[MAX_NUMBER_OF_PLAYERS];
MyTimeoutLabel *timeoutLabelArray[MAX_NUMBER_OF_PLAYERS];
QGroupBox *groupBoxArray[MAX_NUMBER_OF_PLAYERS];
MyCardsPixmapLabel *boardCardsArray[5];
+1 -97
View File
@@ -16,12 +16,8 @@
using namespace std;
MySetLabel::MySetLabel(QGroupBox* parent)
: QLabel(parent), timeOutAnimation(FALSE), timeOutValue(0), timeOutFrame(0), waitFrames(0), timerIntervall(0), isBeep(0), isBeepPlayed(0)
: QLabel(parent)
{
timeOutAnimationTimer = new QTimer;
connect(timeOutAnimationTimer, SIGNAL(timeout()), this, SLOT(nextTimeOutAnimationFrame()));
}
@@ -29,99 +25,7 @@ MySetLabel::~MySetLabel()
{
}
void MySetLabel::startTimeOutAnimation(int secs, bool beep) {
isBeepPlayed = FALSE;
isBeep = beep;
timeOutValue = secs;
timeOutFrame = 1;
timeOutAnimationWidth = 103;
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;
}
}
waitFrames = 3000/timerIntervall;
//start the real timer
realTimer.reset();
realTimer.start();
// std::cout << timerIntervall << endl;
timeOutAnimation = TRUE;
timeOutAnimationTimer->start(timerIntervall);
}
void MySetLabel::startTimeOutAnimationNow() {
timeOutAnimation = TRUE;
timeOutAnimationTimer->start(83);
}
void MySetLabel::stopTimeOutAnimation() {
// timeOutAnimationKickOnTimer->stop();
timeOutAnimationTimer->stop();
timeOutAnimation = FALSE;
update();
}
void MySetLabel::nextTimeOutAnimationFrame() {
if(timeOutAnimationWidth >=0) {
if(timeOutFrame > waitFrames) {
//play beep after waitFrames one time
if(isBeep && !isBeepPlayed) {
myW->getMySDLPlayer()->playSound("yourturn",0);
isBeepPlayed = TRUE;
}
//save gfx ressources and never play more the 10 pps
unsigned int realTimerValue = realTimer.elapsed().total_milliseconds();
timeOutAnimationWidth = 103-(((realTimerValue-3000)*103)/((timeOutValue-3)*1000));
}
timeOutFrame++;
update();
}
else {
stopTimeOutAnimation();
// no callback is called here.
// the server initiates any action required.
}
}
void MySetLabel::paintEvent(QPaintEvent * event) {
if(!timeOutAnimation || timeOutFrame <= waitFrames) {
QLabel::paintEvent(event);
}
if(timeOutAnimation && timeOutFrame > waitFrames) {
QPainter painter(this);
QLinearGradient linearGrad(QPointF(0, 10), QPointF(98, 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));
painter.drawRect(0,2,timeOutAnimationWidth-1,8);
}
}
+2 -30
View File
@@ -16,8 +16,6 @@
#include <QtGui>
#include <QtCore>
#include <third_party/boost/timers.hpp>
#include "sdlplayer.h"
class gameTableImpl;
@@ -31,40 +29,14 @@ public:
void setMyW ( gameTableImpl* theValue ) { myW = theValue; }
void startTimeOutAnimation(int secs, bool beep);
void stopTimeOutAnimation();
void paintEvent(QPaintEvent * event);
void paintEvent(QPaintEvent * event);
public slots:
void startTimeOutAnimationNow();
void nextTimeOutAnimationFrame();
private:
gameTableImpl *myW;
QTimer *timeOutAnimationTimer;
QTimer *timeOutAnimationKickOnTimer;
// boost::shared_ptr<SDLPlayer> mySDLPlayer;
gameTableImpl *myW;
boost::timers::portable::microsec_timer realTimer;
bool timeOutAnimation;
int timeOutAnimationWidth;
int timeOutValue;
int timeOutFrame;
int waitFrames;
int decreaseWidthIntervall;
int timerIntervall;
bool isBeep;
bool isBeepPlayed;
};
#endif
+4 -4
View File
@@ -36,7 +36,7 @@ void MyTimeoutLabel::startTimeOutAnimation(int secs, bool beep) {
timeOutValue = secs;
timeOutFrame = 1;
timeOutAnimationWidth = 50;
timeOutAnimationWidth = 52;
int preTimerIntervall = ((timeOutValue-3) * 1000)/timeOutAnimationWidth;
@@ -90,7 +90,7 @@ void MyTimeoutLabel::nextTimeOutAnimationFrame() {
}
//save gfx ressources and never play more the 10 pps
unsigned int realTimerValue = realTimer.elapsed().total_milliseconds();
timeOutAnimationWidth = 50-(((realTimerValue-3000)*50)/((timeOutValue-3)*1000));
timeOutAnimationWidth = 52-(((realTimerValue-3000)*52)/((timeOutValue-3)*1000));
}
timeOutFrame++;
@@ -114,7 +114,7 @@ void MyTimeoutLabel::paintEvent(QPaintEvent * event) {
QPainter painter(this);
QLinearGradient linearGrad(QPointF(0, 10), QPointF(45, 10));
QLinearGradient linearGrad(QPointF(0, 10), QPointF(47, 10));
linearGrad.setColorAt(0, Qt::red);
linearGrad.setColorAt(0.5, Qt::yellow);
linearGrad.setColorAt(1, Qt::green);
@@ -122,6 +122,6 @@ void MyTimeoutLabel::paintEvent(QPaintEvent * event) {
painter.setBrush(linearGrad);
painter.setPen(QColor(0,0,0));
painter.drawRect(0,2,timeOutAnimationWidth-1,8);
painter.drawRect(0,1,timeOutAnimationWidth-1,8);
}
}