-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchoosetagwindow.cpp
More file actions
153 lines (141 loc) · 4.26 KB
/
choosetagwindow.cpp
File metadata and controls
153 lines (141 loc) · 4.26 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
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
#include "choosetagwindow.h"
extern UserManager g_umUserManager;
extern double xscale;
extern double yscale;
ChooseTagWindow::ChooseTagWindow(QWidget *parent)
:PostureWindow(parent)
{
m_iFavor = 0;
BuildBottomRight();
}
ChooseTagWindow::~ChooseTagWindow()
{
}
void ChooseTagWindow::InitWidgets()
{
QVBoxLayout *mainLayout = new QVBoxLayout();
m_qlTitle = new QLabel("Follow 5 favors\nThen we'll build a custom home feed for you", m_qwBottomRight);
m_qlTitle->setObjectName("error");
mainLayout->addStretch();
mainLayout->addWidget(m_qlTitle);
mainLayout->addStretch();
QGridLayout *layout = new QGridLayout();
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 4; j++)
{
m_qpbFavor = new QPushButton(favors[i*4+j], m_qwBottomRight);
m_qpbFavor->setObjectName("favorTag");
m_qpbFavor->setFixedSize(FAVORTAG_W*xscale, FAVORTAG_H*yscale);
m_qpbFavor->setStyleSheet(QString("QPushButton#favorTag{background-image:url(:/img/Resources/%1.jpg);}\
QPushButton#favorTag:hover{background-image:url();background-color:rgba(%2,%3,%4,0.4);}")
.arg(favors[i*4+j])
.arg(rand() % 255)
.arg(rand() % 255)
.arg(rand() % 255));
m_qpbFavor->setProperty("isChoosed", 0);
connect(m_qpbFavor, SIGNAL(clicked()), this, SLOT(choose()));
SourceManager sm;
UserPro up;
sm.GetUserProfile(up);
for (int k = 0; k < up.m_vFavors.size(); k++)
{
if (up.m_vFavors[k] == favors[i * 4 + j].toStdString())
{
m_qpbFavor->setIcon(QIcon(g_sImgRoot + "whiteicon.png"));
m_qpbFavor->setIconSize(QSize(ICONWIDTH, ICONHEIGHT));
m_qpbFavor->setProperty("isChoosed", 1);
m_qpbFavor->setStyleSheet(QString("background-image:url();font:bold 15pt 'Myriad Pro Light SemiExt';background-color:rgba(%1, %2, %3, 0.4);")
.arg(rand() % 255)
.arg(rand() % 255)
.arg(rand() % 255));
m_iFavor++;
}
}
layout->addWidget(m_qpbFavor,i,j,1,1,Qt::AlignCenter);
}
}
layout->setMargin(0);
layout->setAlignment(Qt::AlignCenter);
mainLayout->addLayout(layout);
mainLayout->addStretch();
m_qpbSubmit = new QPushButton("Done", m_qwBottomRight);
m_qpbSubmit->setObjectName("detail");
m_qpbSubmit->setFixedSize(DETAIL_W*xscale, DETAIL_H*yscale);
if (m_iFavor < 5)
m_qpbSubmit->setDisabled(true);
connect(m_qpbSubmit, SIGNAL(clicked()), this, SLOT(done()));
mainLayout->addWidget(m_qpbSubmit);
mainLayout->addStretch();
m_qwBottomRight->setLayout(mainLayout);
}
void ChooseTagWindow::BuildBottomRight()
{
InitWidgets();
}
void ChooseTagWindow::choose()
{
QPushButton *btn = qobject_cast<QPushButton*>(sender());
if (btn->property("isChoosed").toInt() == 0)
{
btn->setIcon(QIcon(g_sImgRoot+"whiteicon.png"));
btn->setIconSize(QSize(ICONWIDTH, ICONHEIGHT));
btn->setStyleSheet(QString("background-image:url();font:bold 15pt 'Myriad Pro Light SemiExt';background-color:rgba(%1, %2, %3, 0.4);")
.arg(rand() % 255)
.arg(rand() % 255)
.arg(rand() % 255));
btn->setProperty("isChoosed", 1);
m_sFavor.push_back(btn->text());
for (int i = 0; i < m_sFavorRemove.size(); i++)
{
if (btn->text() == m_sFavorRemove[i])
{
m_sFavorRemove.erase(m_sFavorRemove.begin() + i);
}
}
m_iFavor++;
if (m_iFavor >= 5)
m_qpbSubmit->setEnabled(true);
}
else
{
btn->setIcon(QIcon(""));
btn->setIconSize(QSize(0, 0));
btn->setProperty("isChoosed", 0);
btn->setStyleSheet(QString("QPushButton#favorTag{background-image:url(:/img/Resources/%1.jpg);}\
QPushButton#favorTag:hover{background-image:url();background-color:rgba(%2,%3,%4,0.4);}")
.arg(btn->text())
.arg(rand() % 255)
.arg(rand() % 255)
.arg(rand() % 255));
m_sFavorRemove.push_back(btn->text());
for (int i = 0; i < m_sFavor.size(); i++)
{
if (btn->text() == m_sFavor[i])
{
m_sFavor.erase(m_sFavor.begin() + i);
}
}
m_iFavor--;
if (m_iFavor < 5)
m_qpbSubmit->setDisabled(true);
}
}
void ChooseTagWindow::done()
{
for (int i = 0; i < m_sFavor.size(); i++)
{
if (g_umUserManager.AddFavor(m_sFavor[i].toStdString()) == FAVORERRO)
{
qDebug() << "Oops!";
}
}
for (int i = 0; i < m_sFavorRemove.size(); i++)
{
if (g_umUserManager.RemoveFavor(m_sFavorRemove[i].toStdString()) == FAVORERRO)
{
qDebug() << "Oops!";
}
}
emit addSuccess("");
}