-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddfiledialog.cpp
195 lines (186 loc) · 5.11 KB
/
addfiledialog.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "addfiledialog.h"
#include "ui_addfiledialog.h"
AddFileDialog::AddFileDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AddFileDialog)
{
ui->setupUi(this);
//setWindowIcon(QIcon(":/logo.ico"));
setWindowFlags(Qt::Dialog);
setWindowTitle("设置文件信息");
//列出组件
QVBoxLayout * VBox = new QVBoxLayout;
QFormLayout *FormLayout = new QFormLayout;
name_edit = new QLineEdit;
type_box = new QComboBox;
subject_box = new QComboBox;
//初始化combobox
init_combo();
//设置slider
priority_slider = new QSlider;
priority_slider->setMaximum(3);
priority_slider->setPageStep(1);
priority_slider->setOrientation(Qt::Horizontal);
priority_slider->setTickPosition(QSlider::TicksBelow);
//布局输入框
FormLayout->addRow("name:",name_edit);
FormLayout->addRow("subject:",subject_box);
FormLayout->addRow("type:",type_box);
FormLayout->addRow("priority:",priority_slider);
FormLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
//布局按钮
QHBoxLayout * HBox = new QHBoxLayout;
submit_button = new QPushButton("submit");
cancel_button = new QPushButton("cancel");
HBox->addWidget(submit_button);
HBox->addWidget(cancel_button);
//最后组合
VBox->addLayout(FormLayout,4);
VBox->addLayout(HBox,1);
this->setLayout(VBox);
//信号与槽
QObject::connect(submit_button,&QPushButton::clicked,this,&AddFileDialog::save);
QObject::connect(cancel_button,&QPushButton::clicked,this,&AddFileDialog::cancel); //------------待考虑
setStyleSheet("QPushButton{\
border:2px groove gray;\
border-radius:10px;\
padding:2px 4px;\
border-style:inset;\
color:rgb(0,0,0);\
}\
QPushButton:pressed{\
background-color:rgb(200,200,200);\
border-style:inset;\
color:rgb(121,112,52);\
}\
QComboBox{\
border:1px solid #eeeeee;\
border-radius:4px;\
padding:1px 2px 1px 2px ;\
background:#ffffff;\
font-size:14px;\
color:#333333;\
font-family:KaiTi;\
}\
QComboBox:checked{\
border:1px solid #069aae;\
}\
QComboBox QAbstractItemView{\
outline: 0px solid gray;\
border:1px solid #eeeeee;\
color:#333333;\
font-size:14px;\
font-family:KaiTi;\
background-color:#ffffff;\
selection-color:#333333;\
selection-background-color:#f1f8ff;\
}\
QComboBox::drop-down {\
subcontrol-origin: padding;\
subcontrol-position: top right;\
width: 16px;\
}\
");
name_edit->setStyleSheet("QLineEdit{\
border:1px solid gray;\
border-radius:4px;\
border-bottom-right-radius:4px ;\
border-top-left-radius:4px ;\
font-family:KaiTi;\
}\
");
priority_slider->setStyleSheet("QSlider::groove:horizontal{\
border:0px solid #bbb;\
}\
QSlider::sub-page:horizontal{\
background:rgb(90,49,255);\
border-radius:2px;\
margin-top:8px;\
margin-bottom:8px;\
}\
QSlider::add-page:horizontal{\
background:rgb(255,255, 255);\
border:0px solid #777;\
border-radius:2px;\
margin-top:9px;\
margin-bottom:9px;\
}\
QSlider::handle:horizontal{\
background: rgb(193,204,208);\
width:5px;\
border:1px solid rgb(193,204,208);\
border-radius:2px;\
margin-top:6px;\
margin-bottom:6px;\
}\
QSlider::handle:horizontal:hover{\
background:rgb(193,204,208);\
width:10px;\
border:1px solid rgb(193,204,208);\
border-radius:5px;\
margin-top:4px;\
margin-bottom:4px;\
}\
");
}
void AddFileDialog::init_combo()
{
QStringList type_list;
QStringList subject_list;
vector<CourseFile> files = cfm.filter_file();
type_list<<"自定义";
subject_list<<"自定义";
for(auto file:files)
{
bool flag1 = false , flag2 = false;
for(int i = 0 ; i < type_list.size() ; i ++)
if(type_list[i] == file.get_type())
{
flag1 = true;
break;
}
for(int i = 0 ; i < subject_list.size() ; i ++)
if(subject_list[i] == file.get_subject())
{
flag2 = true;
break;
}
if(!flag1) type_list.append(file.get_type());
if(!flag2) subject_list.append(file.get_subject());
}
subject_box->setEditable(true);
type_box->setEditable(true);
type_box->addItems(type_list);
subject_box->addItems(subject_list);
}
void AddFileDialog::cancel()
{
type = "cancel";
this->close();
}
void AddFileDialog::set_file(QString name)
{
name_edit->setPlaceholderText(name);
file_name = name;
this->show();
}
void AddFileDialog::save()
{
if(name_edit->text()!="") file_name = name_edit->text();
type = type_box->currentText();
subject = subject_box->currentText();
priority = priority_slider->value();
this->close();
}
CourseFile get_course_file(QString name)
{
AddFileDialog dia;
dia.set_file(name);
dia.exec();
CourseFile cf(dia.subject.toStdString(),dia.type.toStdString(),dia.file_name.toStdString(),dia.priority);
return cf;
}
AddFileDialog::~AddFileDialog()
{
delete ui;
}