-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecbox.cpp
More file actions
97 lines (87 loc) · 2.15 KB
/
Copy pathrecbox.cpp
File metadata and controls
97 lines (87 loc) · 2.15 KB
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
#include "recbox.h"
#include "recboxitem.h"
#include "ui_recbox.h"
RecBox::RecBox(QWidget *parent)
: QWidget(parent)
, ui(new Ui::RecBox)
,_row(1)
,_col(4)
,_currentindex(0)
{
ui->setupUi(this);
}
RecBox::~RecBox()
{
delete ui;
}
//recbox只负责加入item 图片等资源的获取交给qqmusic
void RecBox::InitRecBoxItem(QJsonArray data, int row)
{
if(row==2)
{
this->_row=row;
this->_col=8;
}else
{
ui->ListDown->hide();
}
//错误1:count在images之前使用永远无法换页
this-> _images=data;
_count=ceil(_images.size()/_col);
CreatItem();
}
void RecBox::CreatItem()
{
//删除以前的元素解决元素重复的问题
QList<RecBoxItem*> child=ui->ListUp->findChildren<RecBoxItem*>();
for(auto e: child)
{
ui->UpLayout->removeWidget(e);
delete e;
}
QList<RecBoxItem*> kid=ui->ListDown->findChildren<RecBoxItem*>();
for(auto x: kid)
{
ui->DownLayout->removeWidget(x);
delete x;
}
//定义index代替原本的i去对上下的list进行分流
int index=0;
//元素进行了分组所以每一次开始都应该在当前组的第一个结束在当前组的最后一个
for(int i=_currentindex*_col;i<_currentindex*_col+_col;++i)
{
//构造item对象
RecBoxItem *item=new RecBoxItem();
//从arr中获取json数据对item进行初始化
QJsonObject tmp=_images[i].toObject();
item->SetImage(tmp.value("path").toString());
item->SetText(tmp.value("text").toString());
//如果行<2的直接走else,行大于2还要满足当前图片的序号大于一行的一半才能走if
if(index>=_col/2&&_row==2)
{
ui->DownLayout->addWidget(item);
}else
{
ui->UpLayout->addWidget(item);
}
++index;
}
}
void RecBox::on_LaterBt_clicked()
{
_currentindex--;
if(_currentindex<0)
{
_currentindex=_count-1;
}
CreatItem();
}
void RecBox::on_NextBt_clicked()
{
_currentindex++;
if(_currentindex>=_count)
{
_currentindex=0;
}
CreatItem();
}