Files
pokerth/src/gui/qt/gametable/mycardspixmaplabel.cpp
T

285 lines
7.4 KiB
C++
Raw Normal View History

/*****************************************************************************
* PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
* *
* Additional permission under GNU AGPL version 3 section 7 *
* *
* If you modify this program, or any covered work, by linking or *
* combining it with the OpenSSL project's OpenSSL library (or a *
* modified version of that library), containing parts covered by the *
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
* permission to convey the resulting work. *
* Corresponding Source for a non-source form of such a combination *
* shall include the source code for the parts of OpenSSL used as well *
* as that of the covered work. *
2011-07-03 19:45:08 +00:00
*****************************************************************************/
#include "mycardspixmaplabel.h"
2008-05-05 07:46:19 +00:00
#include "gametableimpl.h"
// using namespace std;
2009-03-25 22:59:01 +00:00
MyCardsPixmapLabel::MyCardsPixmapLabel(QGroupBox* parent)
: QLabel(parent), myW(NULL)
2008-05-05 07:46:19 +00:00
{
this->setMouseTracking(TRUE);
fadeOutAction = FALSE;
flipCardsAction1 = FALSE;
flipCardsAction2 = FALSE;
mousePress = FALSE;
2008-05-05 07:46:19 +00:00
fastFlipCardsFront = FALSE;
2008-05-05 07:46:19 +00:00
// rotationIntervall = 0.03;
2008-05-05 07:46:19 +00:00
isFlipside = FALSE;
2008-05-05 07:46:19 +00:00
fadeOutTimer = new QTimer;
connect(fadeOutTimer, SIGNAL(timeout()), this, SLOT(nextFadeOutFrame()));
flipCardsTimer = new QTimer;
connect(flipCardsTimer, SIGNAL(timeout()), this, SLOT(nextFlipCardsFrame()));
connect(this, SIGNAL(signalFastFlipCards(bool)), this, SLOT(fastFlipCards(bool)));
}
MyCardsPixmapLabel::~MyCardsPixmapLabel()
{
}
void MyCardsPixmapLabel::startFadeOut(int speed)
{
2009-03-25 22:59:01 +00:00
frameOpacity = 1.0;
2008-05-05 07:46:19 +00:00
if(speed <= 4) {
opacityRaiseInterval = 0.01;
}
if(speed > 4 && speed <= 7) {
opacityRaiseInterval = 0.02;
}
if(speed > 7 && speed <= 10) {
opacityRaiseInterval = 0.04;
}
2008-05-05 07:46:19 +00:00
if(speed != 11) {
fadeOutAction = TRUE;
2009-03-25 22:59:01 +00:00
frameOpacity = 1.0;
2008-05-05 07:46:19 +00:00
fadeOutTimer->start(40);
}
2008-05-05 07:46:19 +00:00
}
void MyCardsPixmapLabel::stopFadeOut()
{
fadeOutTimer->stop();
fadeOutAction = FALSE;
frameOpacity = 1.0;
update();
}
2008-05-05 07:46:19 +00:00
void MyCardsPixmapLabel::nextFadeOutFrame()
{
2008-05-05 07:46:19 +00:00
2009-03-25 22:59:01 +00:00
if (frameOpacity > 0.25) {
frameOpacity -= opacityRaiseInterval;
update();
} else {
fadeOutTimer->stop();
2008-05-05 07:46:19 +00:00
// fadeOutAction = FALSE;
}
}
void MyCardsPixmapLabel::startFlipCards(int speed, const QPixmap &frontPix, const QPixmap &flipsidePix)
{
stopFadeOut();
2008-05-05 07:46:19 +00:00
stopFlipCards = FALSE;
isFlipside = FALSE;
2008-05-05 07:46:19 +00:00
QLabel::setPixmap(frontPix);
frameFlipCardsAction1Size = 1.0;
2012-12-21 01:01:01 +01:00
frameFlipCardsAction2Size = 0.0;
2008-05-05 07:46:19 +00:00
front = frontPix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);;
flipside = flipsidePix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);;
if(speed <= 4) {
flipCardsScaleIntervall = 0.1;
}
if(speed > 4 && speed <= 6) {
flipCardsScaleIntervall = 0.20;
}
if(speed > 6 && speed <= 8) {
flipCardsScaleIntervall = 0.25;
}
if(speed > 8 && speed <= 10) {
flipCardsScaleIntervall = 0.5;
2012-12-21 01:01:01 +01:00
}
2008-05-05 07:46:19 +00:00
if(speed != 11) {
flipCardsAction1 = TRUE;
flipCardsTimer->start(40);
}
2008-05-05 07:46:19 +00:00
}
void MyCardsPixmapLabel::stopFlipCardsAnimation()
{
2008-05-05 07:46:19 +00:00
flipCardsTimer->stop();
flipCardsAction1 = FALSE;
flipCardsAction2 = FALSE;
stopFlipCards = TRUE;
update();
}
void MyCardsPixmapLabel::nextFlipCardsFrame()
{
2008-05-05 07:46:19 +00:00
2012-12-21 01:01:01 +01:00
if (frameFlipCardsAction1Size > 0.1 ) {
2008-05-05 07:46:19 +00:00
//erst flipside verkleinern
frameFlipCardsAction1Size -= flipCardsScaleIntervall;
update();
} else {
if(flipCardsAction1) {
2008-05-05 07:46:19 +00:00
flipCardsAction1 = FALSE;
flipCardsAction2 = TRUE;
} else {
2008-05-05 07:46:19 +00:00
//dann front vergrößern
2012-12-21 01:01:01 +01:00
if (frameFlipCardsAction2Size < 0.95 ) {
2008-05-05 07:46:19 +00:00
frameFlipCardsAction2Size += flipCardsScaleIntervall;
2012-12-21 01:01:01 +01:00
update();
} else {
2008-05-05 07:46:19 +00:00
flipCardsAction2 = FALSE;
flipCardsTimer->stop();
2008-05-05 07:46:19 +00:00
}
}
}
}
void MyCardsPixmapLabel::setPixmap(const QPixmap &pic, const bool flipsideIs)
{
2008-05-05 07:46:19 +00:00
QLabel::setPixmap(pic);
isFlipside = flipsideIs;
}
void MyCardsPixmapLabel::setHiddenFrontPixmap ( const QPixmap &pic )
{
2008-05-05 07:46:19 +00:00
myHiddenFront = pic.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);;
}
void MyCardsPixmapLabel::paintEvent(QPaintEvent * event)
{
2008-05-05 07:46:19 +00:00
2009-03-25 22:59:01 +00:00
if (!(flipCardsAction1 || flipCardsAction2 || fadeOutAction)) {
2008-05-05 07:46:19 +00:00
QLabel::paintEvent(event);
}
2009-03-25 22:59:01 +00:00
if (fadeOutAction && !fastFlipCardsFront) {
2008-05-05 07:46:19 +00:00
QPainter painter(this);
painter.setOpacity(frameOpacity);
if(isFlipside)
painter.drawPixmap(0,0, flipside);
else
painter.drawPixmap(0,0, front);
2008-05-05 07:46:19 +00:00
}
if (flipCardsAction1) {
QPainter painter2(this);
QPointF center(flipside.width()/2.0, flipside.height()/2.0);
painter2.translate(center);
painter2.scale(frameFlipCardsAction1Size ,1);
painter2.translate(-center);
painter2.drawPixmap(0,0, flipside);
}
2008-05-05 07:46:19 +00:00
if (flipCardsAction2) {
QPainter painter3(this);
QPointF center(front.width()/2.0, front.height()/2.0);
painter3.translate(center);
painter3.scale(frameFlipCardsAction2Size ,1);
painter3.translate(-center);
painter3.drawPixmap(0,0, front);
}
if (fastFlipCardsFront && !flipCardsAction1 && !flipCardsAction2) {
2008-05-05 07:46:19 +00:00
if(objectName().contains("pixmapLabel_card0")) {
QPainter painter4(this);
if(fadeOutAction) {
2009-03-25 22:59:01 +00:00
painter4.setOpacity(0.25);
}
painter4.drawPixmap(0,0, myHiddenFront);
2008-05-05 07:46:19 +00:00
}
}
}
void MyCardsPixmapLabel::fastFlipCards(bool front)
{
2008-05-05 07:46:19 +00:00
if (front) {
fastFlipCardsFront = TRUE;
2008-05-05 07:46:19 +00:00
update();
} else {
fastFlipCardsFront = FALSE;
2008-05-05 07:46:19 +00:00
update();
}
}
void MyCardsPixmapLabel::mousePressEvent(QMouseEvent * event)
{
2008-05-05 07:46:19 +00:00
if (!mousePress && objectName().contains("pixmapLabel_card0")) {
mousePress = TRUE;
myW->mouseOverFlipCards(TRUE);
2008-05-05 07:46:19 +00:00
}
QLabel::mousePressEvent(event);
2008-05-05 07:46:19 +00:00
}
void MyCardsPixmapLabel::mouseReleaseEvent(QMouseEvent * event)
{
2008-05-05 07:46:19 +00:00
if (mousePress && objectName().contains("pixmapLabel_card0")) {
mousePress = FALSE;
2008-05-05 07:46:19 +00:00
myW->mouseOverFlipCards(FALSE);
}
2008-05-05 07:46:19 +00:00
QLabel::mouseReleaseEvent(event);
2008-05-05 07:46:19 +00:00
}
void MyCardsPixmapLabel::setFront ( const QPixmap& theValue )
{
#ifdef GUI_800x480
2012-12-21 01:01:01 +01:00
front = theValue.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);;
#else
2012-12-21 01:01:01 +01:00
front = theValue;
#endif
}