-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget_ajout.cpp
450 lines (395 loc) · 14.2 KB
/
widget_ajout.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#include <QVBoxLayout>
#include <QLineEdit>
#include <QToolBox>
#include <QGroupBox>
#include <QTreeWidgetItem>
#include "widget_ajout.h"
Widget_ajout::Widget_ajout(FirstWindow *fw,QWidget *parent) :
QWidget(parent)
{
// attributs utiles
firstW = fw;
date_aff = false;
precond_aff = false;
ordon_aff = false;
template_aff = false;
// seul le widget_ajout a le focus
firstW->setDisabled(true);
// Layout du widget ajout
QGridLayout * mainlayout = new QGridLayout();
this->setLayout(mainlayout);
this->setWindowTitle("Ajout d'une tâche");
this->setFixedWidth(350);
this->setFixedHeight(300);
// centre le widget
this->setWindowFlags(Qt::Sheet | Qt::WindowStaysOnTopHint);
mainlayout->setRowStretch(12,5);
// Titre pour le champ nom de la Tache - "tache" ou "sous tache de XXX"
QLabel * nameLabel;
if (firstW->currentItem == firstW->arbo->invisibleRootItem()){
nameLabel = new QLabel("Nouvelle tâche : ");
}
else{
nameLabel = new QLabel("Sous-tâche de <b>" + firstW->currentItem->text(0) + "</b> :");
}
name = new QLineEdit();
name->setMaxLength(100);
name->setFixedHeight(50);
name->setStyleSheet("QLineEdit{font-size : 18px;}");
name->setPlaceholderText("Nouvelle tâche");
mainlayout->addWidget(nameLabel,0,0,1,2);
mainlayout->addWidget(name,1,0,1,2);
QObject::connect(name,SIGNAL(textEdited(QString)),this,SLOT(textEdited(QString)));
// menu date dépliable
date_plus = new QPushButton("+");
date_plus->setStyleSheet("QPushButton {font-weight : bold;}");
date_plus->setFixedWidth(20);
date_plus->setToolTip("Définir une date limite pour la tâche");
mainlayout->addWidget(date_plus,2,0);
afficher_date = new QLabel("Ajouter une échéance");
mainlayout->addWidget(afficher_date,2,1);
// menu précond dépliable
precond_plus = new QPushButton("+");
precond_plus->setStyleSheet("QPushButton {font-weight : bold;}");
precond_plus->setFixedWidth(20);
precond_plus->setToolTip("Indiquer si certaines tâches doivent être réalisées avant celles-ci");
mainlayout->addWidget(precond_plus,3,0);
afficher_precond = new QLabel("Ajouter une ou des précondition(s)");
mainlayout->addWidget(afficher_precond,3,1);
// menu liste ordonnee dépliable
ordon_plus = new QPushButton("+");
ordon_plus->setStyleSheet("QPushButton {font-weight : bold;}");
ordon_plus->setFixedWidth(20);
ordon_plus->setToolTip("Avec cette option, toutes les sous-tâches seront classées dans un ordre précis");
mainlayout->addWidget(ordon_plus,4,0);
afficher_ordon = new QLabel("Ajouter l'option de liste ordonnée");
mainlayout->addWidget(afficher_ordon,4,1);
// menu template dépliable
template_plus = new QPushButton("+");
template_plus->setStyleSheet("QPushButton {font-weight : bold;}");
template_plus->setFixedWidth(20);
template_plus->setToolTip("Charger un type de tâche préalablement enregistré");
mainlayout->addWidget(template_plus,5,0);
afficher_template = new QLabel("Charger une tâche enregistrée");
mainlayout->addWidget(afficher_template,5,1);
//mainlayout->addStretch();
QFrame* line = new QFrame();
line->setGeometry(QRect(/* ... */));
line->setFrameShape(QFrame::HLine); // Replace by VLine for vertical line
line->setFrameShadow(QFrame::Sunken);
mainlayout->addWidget(line,6,0,1,2);
// Widgets dépliables
dates = new widget_date(firstW);
mainlayout->addWidget(dates,7,0,1,2);
dates->setVisible(false);
QObject::connect(date_plus,SIGNAL(clicked()),this,SLOT(afficherDate()));
QObject::connect(dates->nodatebut,SIGNAL(clicked()),this,SLOT(afficherDate()));
preconds = new widget_precond(firstW);
mainlayout->addWidget(preconds,8,0,1,2);
preconds->setVisible(false);
QObject::connect(precond_plus,SIGNAL(clicked()),this,SLOT(afficherPrecond()));
ordon_expl = new QLabel("En cochant cette option, toutes les sous-tâches seront ordonnées. Ainsi, il faudra effectuer la première sous-tâche avant la deuxième, et ainsi de suite...");
ordon_expl->setWordWrap(true);
ordon_expl->setAlignment(Qt::AlignJustify);
mainlayout->addWidget(ordon_expl,9,0,1,2);
ordon_expl->setVisible(false);
ordon = new QWidget();
QHBoxLayout * ordon_layout = new QHBoxLayout();
ordon_layout->addStretch();
ordonch = new QCheckBox("Liste ordonnée");
ordonch->setStyleSheet("QCheckBox{font-size : 18px;}");
ordon_layout->addWidget(ordonch);
ordon_layout->addStretch();
ordon->setLayout(ordon_layout);
mainlayout->addWidget(ordon,10,0,1,2);
ordon->setVisible(false);
QObject::connect(ordon_plus,SIGNAL(clicked()),this,SLOT(afficherOrdon()));
templ = new widget_templ_aff(firstW);
mainlayout->addWidget(templ,11,0,1,2);
templ->setVisible(false);
QObject::connect(template_plus,SIGNAL(clicked()),this,SLOT(afficherTempl()));
//mainlayout->addStretch();
// Bouton Annuler
QWidget * buttonsWidget = new QWidget();
QHBoxLayout * buttonsLayout = new QHBoxLayout();
boutonAnnul = new QPushButton("Annuler");
boutonAnnul->setStyleSheet("QPushButton {background : #C60800 ; color : #FFFFFF ; font-weight : bold; font-size : 18px;}");
boutonAnnul->setFixedWidth(130);
buttonsLayout->addWidget(boutonAnnul);
// Bouton Nouveau
boutonAjout = new QPushButton("Ajouter");
boutonAjout->setDisabled(true);
boutonAjout->setStyleSheet("QPushButton {background : #3A9D23 ; color : #FFFFFF ; font-weight : bold; font-size : 18px;} QPushButton:disabled{background : #CECECE;}");
boutonAjout->setFixedWidth(130);
buttonsLayout->addWidget(boutonAjout);
buttonsWidget->setLayout(buttonsLayout);
mainlayout->addWidget(buttonsWidget,12,0,1,2);
QObject::connect(boutonAnnul,SIGNAL(clicked()),this,SLOT(close()));
QObject::connect(boutonAjout,SIGNAL(clicked()),this,SLOT(addTache()));
QObject::connect(boutonAjout,SIGNAL(clicked()),this,SLOT(close()));
QObject::connect(name,SIGNAL(returnPressed()),this,SLOT(addTache()));
QObject::connect(name,SIGNAL(returnPressed()),this,SLOT(close()));
// essais groupbox
/*groupbox_date = new QGroupBox("Gestion de date");
groupbox_date->setLayout(dateLayout);
groupbox_date->setFlat(true);
groupbox_date->setVisible(false);
mainlayout->addWidget(groupbox_date);*/
QObject::connect(this,SIGNAL(WidgetClosed()),firstW,SLOT(resetDisable()));
}
Widget_ajout::~Widget_ajout()
{}
// fonction d ajout dans le modele et dans l arborescence de la nouvelle tache
void Widget_ajout::addTache()
{
if(name->text()!=""){
QTreeWidgetItem * item = new QTreeWidgetItem(firstW->currentItem);
firstW->defineCurrentTache(item->parent(),firstW->racine);
bool ordre = firstW->currentTache->getOrdon();
int numberOrd = firstW->currentTache->getSousTaches().size() + 1;
item->setCheckState(0,Qt::Unchecked);
if(ordre){
ostringstream number;
number << numberOrd;
string numberString = number.str();
item->setText(0,QString(numberString.c_str())+". "+name->text());
}
else item->setText(0,name->text());
if (dates->typeDate() == 1){
item->setText(1,dates->getDateabs().toString());
item->setTextColor(1,QColor(152,152,152));
}
if (dates->typeDate() == 2)
{
item->setText(1,QString(dates->getDaterel().c_str()));
item->setTextColor(1,QColor(152,152,152));
}
// ajout de la tache dans le modele
Tache * newtache = new Tache(name->text().toStdString());
//TODOnewtache->setDate("Date");
if(dates->typeDate() == 1)
{
newtache->setDateabs(dates->getDateabs());
newtache->setDate(1);
}
else if(dates->typeDate() == 2)
{
newtache->setDaterel(dates->getDaterel());
newtache->setDate(2);
}
else newtache->setDate(3);
newtache->setPreconditions(preconds->getPreconditions());
if (ordre && item->parent()->childCount() > 1) // Si c'est une sous-tache de liste ordonnee
{
Tache tacheprecedente(firstW->arbo->itemAbove(item),false);
newtache->addPrecondition(tacheprecedente);
}
newtache->afficherPreconds(); // VERIFICATION (test)
newtache->setOrdon(ordonch->isChecked());
// AJOUT avec template
if(templ->hasTemplate()){
for (int i=0 ; i<templ->getTempl()->childCount() ; i++)
{
QTreeWidgetItem * subItem = templ->getTempl()->child(i)->clone();
item->addChild(subItem);
Tache * soustache = new Tache(subItem->text(0).toStdString());
soustache->setMatchingItem(subItem);
newtache->addSousTache(soustache);
}
}
firstW->arbo->addTopLevelItem(item);
newtache->setMatchingItem(item);
firstW->defineCurrentTache(item->parent(),firstW->racine);
firstW->currentTache->addSousTache(newtache);
// Fermeture de la fenêtre une fois la tâche ajoutée
firstW->currentTache = firstW->racine;
firstW->currentItem = firstW->arbo->invisibleRootItem();
firstW->setDisabled(false);
this->close();
}
}
void Widget_ajout::afficherDate()
{
if (!date_aff)
{
dates->setVisible(true);
date_plus->setText("-");
date_aff = true;
this->setFixedHeight(600);
this->setFixedWidth(350);
afficher_date->setStyleSheet("QLabel{font-weight : bold;}");
if (precond_aff)
{
preconds->setVisible(false);
precond_plus->setText("+");
precond_aff = false;
afficher_precond->setStyleSheet("");
}
if (ordon_aff)
{
ordon_expl->setVisible(false);
ordon->setVisible(false);
ordon_plus->setText("+");
ordon_aff = false;
afficher_ordon->setStyleSheet("");
}
if (template_aff)
{
templ->setVisible(false);
template_plus->setText("+");
template_aff = false;
afficher_template->setStyleSheet("");
}
}
else
{
dates->setVisible(false);
date_plus->setText("+");
date_aff = false;
this->setFixedHeight(300);
this->setFixedWidth(350);
afficher_date->setStyleSheet("");
}
}
void Widget_ajout::afficherPrecond()
{
if (!precond_aff)
{
preconds->setVisible(true);
precond_plus->setText("-");
precond_aff = true;
this->setFixedHeight(600);
afficher_precond->setStyleSheet("QLabel{font-weight : bold;}");
if (date_aff)
{
dates->setVisible(false);
date_plus->setText("+");
date_aff = false;
this->setFixedWidth(350);
afficher_date->setStyleSheet("");
}
if (ordon_aff)
{
ordon_expl->setVisible(false);
ordon->setVisible(false);
ordon_plus->setText("+");
ordon_aff = false;
afficher_ordon->setStyleSheet("");
}
if (template_aff)
{
templ->setVisible(false);
template_plus->setText("+");
template_aff = false;
afficher_template->setStyleSheet("");
}
}
else
{
preconds->setVisible(false);
precond_plus->setText("+");
precond_aff = false;
this->setFixedHeight(300);
afficher_precond->setStyleSheet("");
}
}
void Widget_ajout::afficherOrdon()
{
if (!ordon_aff)
{
ordon_expl->setVisible(true);
ordon->setVisible(true);
ordon_plus->setText("-");
ordon_aff = true;
this->setFixedHeight(450);
afficher_ordon->setStyleSheet("QLabel{font-weight : bold;}");
if (date_aff)
{
dates->setVisible(false);
date_plus->setText("+");
date_aff = false;
this->setFixedWidth(350);
afficher_date->setStyleSheet("");
}
if (precond_aff)
{
preconds->setVisible(false);
precond_plus->setText("+");
precond_aff = false;
afficher_precond->setStyleSheet("");
}
if (template_aff)
{
templ->setVisible(false);
template_plus->setText("+");
template_aff = false;
afficher_template->setStyleSheet("");
}
}
else
{
ordon_expl->setVisible(false);
ordon->setVisible(false);
ordon_plus->setText("+");
ordon_aff = false;
this->setFixedHeight(300);
afficher_ordon->setStyleSheet("");
}
}
void Widget_ajout::afficherTempl()
{
if (!template_aff)
{
templ->setVisible(true);
template_plus->setText("-");
template_aff = true;
this->setFixedHeight(600);
afficher_template->setStyleSheet("QLabel{font-weight : bold;}");
if (date_aff)
{
dates->setVisible(false);
date_plus->setText("+");
date_aff = false;
this->setFixedWidth(350);
afficher_date->setStyleSheet("");
}
if (precond_aff)
{
preconds->setVisible(false);
precond_plus->setText("+");
precond_aff = false;
afficher_precond->setStyleSheet("");
}
if (ordon_aff)
{
ordon_expl->setVisible(false);
ordon->setVisible(false);
ordon_plus->setText("+");
ordon_aff = false;
afficher_ordon->setStyleSheet("");
}
}
else
{
templ->setVisible(false);
template_plus->setText("+");
template_aff = false;
this->setFixedHeight(300);
afficher_template->setStyleSheet("");
}
}
void Widget_ajout::closeEvent(QCloseEvent *event)
{
emit WidgetClosed();
event->accept();
}
// desactiver le bouton Ajouter quand le nom de la tache est vide
void Widget_ajout::textEdited(QString s)
{
if (s != ""){
boutonAjout->setEnabled(true);
}
else {
boutonAjout->setEnabled(false);
}
}