-
Notifications
You must be signed in to change notification settings - Fork 0
/
showboardwidget.cpp
177 lines (152 loc) · 4.11 KB
/
showboardwidget.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "showboardwidget.h"
#include "ui_showboardwidget.h"
ShowBoardWidget::ShowBoardWidget(QWidget *parent) :
QDialog(parent),
ui(new Ui::ShowBoardWidget)
{
ui->setupUi(this);
setFixedSize(255,288);
getLBSum(10);
initData();
initLayout();
initConnect();
setLBText();
}
ShowBoardWidget::~ShowBoardWidget()
{
delete ui;
}
void ShowBoardWidget::initData()
{
drag_wheelPressedFlag = false;
drag_mousePressedFlag = false;
drag_beginPoint = QPoint(0,0);
currentPosHead = QPoint(2,40*0+10);
currentPosTail = QPoint(2,40*6+10);
}
void ShowBoardWidget::initLayout()
{
// 无边框设置
this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
for (int i = 0; i < m_LBSum; i++)
{
lb_labelBoard[i] = new QLabel(this);
lb_labelBoard[i]->setGeometry(2,40*i+10,235,30);
lb_labelBoard[i]->setStyleSheet("QLabel{background:transparent;}"
"QLabel{border-image:url(:/image/softImage/framework/labelboard.png)}");
// lb_labelBoard[i]->setAlignment(Qt::AlignCenter);
}
}
void ShowBoardWidget::initConnect()
{
}
void ShowBoardWidget::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
drag_wheelPressedFlag = true;
drag_mousePressedFlag = true;
for (int i = 0; i < m_LBSum; i++)
{
drag_beginPoint = event->pos();
currentPos[i] = lb_labelBoard[i]->pos();
}
}
if(event->button()==Qt::RightButton)
{
//暂未设计
}
}
void ShowBoardWidget::mouseMoveEvent(QMouseEvent *event)
{
if(drag_mousePressedFlag)
{
for (int i = 0; i < m_LBSum; i++)
{
lb_labelBoard[i]->move(2,currentPos[i].y()+event->pos().y()-drag_beginPoint.y());
}
}
}
void ShowBoardWidget::mouseReleaseEvent(QMouseEvent *event)
{
drag_mousePressedFlag = false;
for (int i = 0; i < m_LBSum; i++)
{
currentPos[i] = lb_labelBoard[i]->pos();
}
if(currentPos[0].y() - currentPosHead.y() > 0) //回弹效果
{
for (int i = 0; i < m_LBSum; i++)
{
lb_labelBoard[i]->move(2,40*i+10);
}
}
if(currentPos[m_LBSum-1].y() - currentPosTail.y() < 0)
{
for (int i = m_LBSum-1,j = 6; i >= 0; i--,j--)
{
lb_labelBoard[i]->move(2,40*j+10);
}
}
for (int i = 0; i < m_LBSum; i++)
{
currentPos[i] = lb_labelBoard[i]->pos();
}
event->accept();
}
void ShowBoardWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
// painter.drawPixmap(0,0,width(),height(),QPixmap(":/image/softImage/framework/TimeBackground.png"));
painter.drawPixmap(10,1,9,288-3,QPixmap(":/image/softImage/column.png"));
event->accept();
}
void ShowBoardWidget::wheelEvent(QWheelEvent *event)
{
if(drag_wheelPressedFlag)
{
if(event->delta() > 0) //如果滚轮往上滚
{
if(lb_labelBoard[m_LBSum-1]->pos() != currentPosTail) //并且排行榜最末处于可视排行榜最后
{
for (int i = 0; i < m_LBSum; i++)
{
lb_labelBoard[i]->move(2,currentPos[i].y()-10);
}
}
}
else //向下滚
{
if(lb_labelBoard[0]->pos() != currentPosHead) //并且排行榜第一不处于第一位置
{
for (int i = 0; i < m_LBSum; i++)
{
lb_labelBoard[i]->move(2,currentPos[i].y()+10);
}
}
}
for (int i = 0; i < m_LBSum; i++)
{
currentPos[i] = lb_labelBoard[i]->pos();
}
}
}
void ShowBoardWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
// 鼠标双击的标签显示个人信息
}
}
void ShowBoardWidget::getLBSum(const int num)
{
m_LBSum = num;
}
void ShowBoardWidget::setLBText()
{
for(int i = 0; i < m_LBSum; i++)
{
lb_labelBoard[i]->setText(" "+QString::number(i+1,10));
}
}