Skip to content

Commit

Permalink
add animations
Browse files Browse the repository at this point in the history
  • Loading branch information
dragondjf committed Aug 6, 2014
1 parent ff3daaa commit 7a51739
Show file tree
Hide file tree
Showing 25 changed files with 129 additions and 14 deletions.
8 changes: 8 additions & 0 deletions QCFramer.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -1910,4 +1910,12 @@
<qresource prefix="/about">
<file>skin/html/about.html</file>
</qresource>
<qresource prefix="/ball">
<file>skin/ball/black.png</file>
<file>skin/ball/blue.png</file>
<file>skin/ball/green.png</file>
<file>skin/ball/red.png</file>
<file>skin/ball/white.png</file>
<file>skin/ball/yellow.png</file>
</qresource>
</RCC>
17 changes: 8 additions & 9 deletions functionpages/waterview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ FGraphicsEllipseItem::FGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h, Q

void FGraphicsEllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem myoption = (*option);
myoption.state &= !QStyle::State_Selected;
QGraphicsEllipseItem::paint(painter, &myoption, widget);
// QStyleOptionGraphicsItem myoption = (*option);
// myoption.state &= !QStyle::State_Selected;
// QGraphicsEllipseItem::paint(painter, &myoption, widget);
}

FGraphicsPixmapItem::FGraphicsPixmapItem(QGraphicsItem *parent):
Expand Down Expand Up @@ -69,15 +69,14 @@ void WaterView::initData()
void WaterView::initUI()
{
QGraphicsScene* scene = new QGraphicsScene;
scene->addText("Hello, world!");
setSceneRect(0, 0, 800, 600);
setSceneRect(-100, -100, 700, 700);
setScene(scene);
for(int i=0; i<20; i++){
FGraphicsEllipseItem *item = new FGraphicsEllipseItem(i * 20 + 20, 0, 40, 40);
QRadialGradient bgradient(i * 20 + 20, 0 , 20, i * 20 + 20, 0);
bgradient.setColorAt(0,QColor(255, 255, 255));
QRadialGradient bgradient(0, 0 , 20, 0, 0);
bgradient.setColorAt(0,QColor(63, 120, 137));
bgradient.setColorAt(0.5,QColor(61, 235, 188));
bgradient.setColorAt(1.0,QColor(63, 120, 137));
bgradient.setColorAt(1.0,QColor(255, 255, 255));
item->setBrush(QBrush(bgradient));
item->setPen(QPen(Qt::NoPen));
item->setFlags(FGraphicsEllipseItem::ItemIsMovable| FGraphicsEllipseItem::ItemIsSelectable);
Expand All @@ -100,7 +99,7 @@ void WaterView::initConnect()

void WaterView::resizeEvent(QResizeEvent *event)
{
QLinearGradient bgradient(-event->size().width()/2, 0, event->size().width()/2, 0);
QLinearGradient bgradient(0, 100, 100, 0);
bgradient.setSpread(QGradient::PadSpread);
bgradient.setColorAt(0, QColor(63, 120, 137));
bgradient.setColorAt(0.25, QColor(61, 235, 188));
Expand Down
98 changes: 95 additions & 3 deletions functionpages/waterwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "waterwidget.h"

#include <QPixmap>
#include <QBitmap>
#include <QPropertyAnimation>
WaterWidget::WaterWidget(QWidget *parent) :
QLabel(parent)
{
Expand All @@ -10,7 +12,17 @@ WaterWidget::WaterWidget(QWidget *parent) :

void WaterWidget::initData()
{

// ballpaths << QString(":/ball/skin/ball/white.png");
ballpaths << QString(":/ball/skin/ball/green.png");
ballpaths << QString(":/ball/skin/ball/red.png");
ballpaths << QString(":/ball/skin/ball/blue.png");
ballpaths << QString(":/ball/skin/ball/yellow.png");
ballpaths << QString(":/ball/skin/ball/black.png");
count = 0;
animationFlag = true;
durations << 1000 << 2000 << 3000 << 4000 << 5000;
parallelAnimationGroup = new QParallelAnimationGroup;
sequentialAnimationGroup = new QSequentialAnimationGroup;
}

void WaterWidget::initUI()
Expand All @@ -23,9 +35,89 @@ void WaterWidget::initUI()
stop:1 rgba(63, 120, 137, 255));\
}";
setStyleSheet(style);

switchButton = new QPushButton(tr("sequential"), this);
switchButton->setFixedSize(100, 60);

for(int i=0; i<20 ; i++)
{
QLabel * ball = new QLabel(this);
labels.append(ball);
QPixmap m_Pixmap;
m_Pixmap.load(ballpaths[i % 5]);
m_Pixmap = m_Pixmap.scaled(m_Pixmap.size() / 3);
ball->setPixmap(m_Pixmap);
ball->resize(m_Pixmap.size());
ball->setMask(m_Pixmap.mask());
ball->move(i*60, 0);
}
initAnimations();
parallelAnimationGroup->start();

}

void WaterWidget::initConnect()
{
connect(parallelAnimationGroup, SIGNAL(finished()), this, SLOT(updateCount()));
connect(sequentialAnimationGroup, SIGNAL(finished()), this, SLOT(updateCount()));
connect(switchButton, SIGNAL(clicked()), this, SLOT(swicthAnimationType()));
}

void WaterWidget::updateCount()
{
count = count + 1;

if (animationFlag){
foreach (QPropertyAnimation* animation, sequentialAnimations) {
animation->setDuration(durations[qrand() % 5]);
animation->setEasingCurve(static_cast<QEasingCurve::Type>(qrand() % 41));
}
sequentialAnimationGroup->start();

}else{
foreach (QPropertyAnimation* animation, parallelAnimations) {
animation->setDuration(durations[qrand() % 5]);
animation->setEasingCurve(static_cast<QEasingCurve::Type>(qrand() % 41));
}
parallelAnimationGroup->start();
}
}

void WaterWidget::swicthAnimationType()
{
if(animationFlag){
switchButton->setText(tr("parallel"));
sequentialAnimationGroup->stop();
parallelAnimationGroup->start();
}else{
switchButton->setText(tr("sequential"));
parallelAnimationGroup->stop();
sequentialAnimationGroup->start();
}
animationFlag = not animationFlag;
}

void WaterWidget::initConnect()\
void WaterWidget::initAnimations()
{
for(int i=0; i<labels.length(); i++)
{
QPropertyAnimation* animation_pos = new QPropertyAnimation(labels[i], "pos");
animation_pos->setDuration(durations[qrand() % 5]);
animation_pos->setStartValue(QPoint(labels[i]->x(),0));
animation_pos->setEndValue(QPoint(labels[i]->x(), 600));
animation_pos->setEasingCurve(QEasingCurve::OutBounce);
parallelAnimationGroup->addAnimation(animation_pos);
parallelAnimations.append(animation_pos);
}

for(int i=0; i<labels.length(); i++)
{
QPropertyAnimation* animation_pos = new QPropertyAnimation(labels[i], "pos");
animation_pos->setDuration(durations[qrand() % 5]);
animation_pos->setStartValue(QPoint(labels[i]->x(),0));
animation_pos->setEndValue(QPoint(labels[i]->x(), 600));
animation_pos->setEasingCurve(QEasingCurve::OutBounce);
sequentialAnimationGroup->addAnimation(animation_pos);
sequentialAnimations.append(animation_pos);
}
}
20 changes: 18 additions & 2 deletions functionpages/waterwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,38 @@
#define WATERWIDGET_H

#include <QLabel>

#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QSequentialAnimationGroup>
#include <QPushButton>
class WaterWidget : public QLabel
{
Q_OBJECT
private:
QList<QLabel* > labels;
QList<QPropertyAnimation *> parallelAnimations;
QList<QPropertyAnimation *> sequentialAnimations;
QStringList ballpaths;
QParallelAnimationGroup *parallelAnimationGroup;
QSequentialAnimationGroup *sequentialAnimationGroup;
QList<int> durations;
QPushButton* switchButton;
int count;
bool animationFlag;
private:
void initData();
void initUI();
void initConnect();
void initAnimations();

public:
explicit WaterWidget(QWidget *parent = 0);

signals:

public slots:

void updateCount();
void swicthAnimationType();
};

#endif // WATERWIDGET_H
Binary file added skin/ball/Hustler_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_058.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_060.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_062.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_066.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_067.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_068.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_069.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_070.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_071.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/Hustler_072.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/ball/yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a51739

Please sign in to comment.