-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
121 lines (103 loc) · 3.19 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "mainwindow.h"
#include <QDebug>
#include <QtMath>
#include <QState>
#include <QStateMachine>
#include <QKeyEvent>
#include <QPropertyAnimation>
#include <QPainter>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QPixmap pix(":/images/background.jpg");
this->setFixedSize(pix.size());
QPalette palette;
palette.setBrush(QPalette::Background, pix);
this->setPalette(palette);
QStringList strList;
strList<<":/images/accessories-calculator.png";
strList<<":/images/accessories-text-editor.png";
strList<<":/images/help-browser.png";
strList<<":/images/internet-group-chat.png";
strList<<":/images/internet-mail.png";
strList<<":/images/internet-web-browser.png";
strList<<":/images/office-calendar.png";
strList<<":/images/system-users.png";
int width = this->width();
int hight = this->height();
QList<QPoint> pointList;
QList<QLabel*> labelList;
for (int i=0; i<strList.count(); i++)
{
Label *pLabel = new Label(this);
labelList<<pLabel;
pLabel->setPixmap(QPixmap(strList[i]));
pLabel->resize(QPixmap(strList[i]).size());
double x = width/2 - 30 + 170*qCos(i*3.14/4 + 20);
double y = hight/2 - 30 + 100*qSin(i*3.14/4 + 20);
pointList<<QPoint(x,y);
pLabel->move(x,y);
}
QState *parentState = new QState();
QList<QState*> stateList;
for (int i=0; i<strList.count(); i++)
{
QState *pState = new QState(parentState);
stateList<<pState;
for (int j=0; j<strList.count(); j++)
{
pState->assignProperty(labelList[j],"pos", pointList[(i+j)%pointList.count()]);
}
if (i == 0)parentState->setInitialState(pState);
}
for (int i=0; i<stateList.count(); i++)
{
stateList[i]->addTransition(this, SIGNAL(right()), stateList[(i+1)%stateList.count()]);
stateList[i]->addTransition(this, SIGNAL(left()), stateList[(i-1+stateList.count())%stateList.count()]);
}
for (int i=0; i<stateList.count(); i++)
{
for (int j=0; j<labelList.count(); j++)
{
stateList[i]->addTransition(static_cast<Label*>(labelList[j]), SIGNAL(click()), stateList[(stateList.count()-j+2)%stateList.count()]);
}
}
QStateMachine *machine = new QStateMachine;
machine->addState(parentState);
machine->setInitialState(parentState);
for(int i=0; i<labelList.count(); i++)
{
machine->addDefaultAnimation(new QPropertyAnimation(labelList.at(i), "pos"));
}
machine->start();
//////
}
MainWindow::~MainWindow()
{
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Left:
case Qt::Key_Down:
emit left();
break;
case Qt::Key_Right:
case Qt::Key_Up:
emit right();
break;
default:
break;
}
return QWidget::keyPressEvent(event);
}
void MainWindow::paintEvent(QPaintEvent *)
{
QPainter p(this);
QLinearGradient line(0,0, this->width(), this->height());
line.setColorAt(0.1, QColor(255,255,255,0));
line.setColorAt(0.9, QColor(255,255,255,255));
//p.setBrush(line);
p.fillRect(rect(), line);
}