-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.cpp
129 lines (121 loc) · 3.94 KB
/
target.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
#include "target.h"
/**
* @brief Create an empty target in a task
*/
target::target()
{
QHBoxLayout *layout = new QHBoxLayout;
this->setAttribute(Qt::WA_DeleteOnClose);
b->setCheckable(true);
b->setText("X");
b->setMaximumWidth(20);
b->setMaximumHeight(20);
b->setMinimumWidth(20);
b->setMinimumHeight(20);
b->setChecked(true);
b->setStyleSheet("QPushButton{font-size : 12pt;font-weight : 600;color: black;"
"background-color : #F25244; border-radius : 3px; height : 1em; width : 1em;}");
QString str = targetDesc;
str.truncate(c->width());
c->setText(str);
c->setMinimumHeight(20);
layout->addWidget(c);
layout->addWidget(b);
this->setLayout(layout);
QString q;
QString col;
if(c->isChecked()) {q = "#6AE68D"; col = "black";}
else {q = "rgba( 24, 26, 31, 255)"; col = "rgb(214, 216, 218)";}
this->setStyleSheet("QWidget{color: "+col+"; background-color : "+q+"; border-radius : 3px; border : none; font-weight : 200;}");
connect(b, SIGNAL(clicked()), this, SLOT(close()));
}
/**
* @brief Create a filled target
* @param targetDesc
* @param db
* @param parentTime
*/
target::target(QString targetDesc, database *db, QDateTime parentTime)
{
wdwId = QDateTime::currentDateTime();
this->db = db;
this->db->addTarget(this->wdwId, targetDesc, this->c->isChecked(), parentTime);
QHBoxLayout *layout = new QHBoxLayout;
this->setAttribute(Qt::WA_DeleteOnClose);
b->setCheckable(true);
b->setText("X");
b->setChecked(true);
b->setMaximumWidth(20);
b->setMaximumHeight(20);
b->setMinimumWidth(20);
b->setMinimumHeight(20);
b->setStyleSheet("QPushButton{font-size : 12pt;font-weight : 600;color: black;"
"background-color :#F25244; border-radius : 3px; height : 1em; width : 1em;}");
QString str = targetDesc;
str.truncate(c->width());
c->setText(str);
c->setMinimumHeight(20);
layout->addWidget(c);
layout->addWidget(b);
this->setLayout(layout);
QString q;
QString col;
if(c->isChecked()) {q = "#6AE68D"; col = "black";}
else {q = "rgba( 24, 26, 31, 255)"; col = "rgb(214, 216, 218)";}
this->setStyleSheet("QWidget{color: "+col+"; background-color : "+q+"; border-radius : 3px; border : none; font-weight : 200;}");
connect(c, SIGNAL(stateChanged(int)), this, SLOT(up()));
connect(b, SIGNAL(clicked()), this, SLOT(close()));
}
/**
* @brief target::~target
*/
target::~target()
{
this->db->deleteTarget(this->wdwId);
this->db = NULL;
delete this->db;
this->c = NULL;
delete this->c;
this->b = NULL;
delete this->b;
}
/**
* @brief Set hint to a target
* @param id
* @param check
* @param title
* @param parent
* @param db
*/
void target::set(QDateTime id, bool check, QString title, QDateTime parent, database *db)
{
this->wdwId = id;
this->parent = parent;
this->c->setChecked(check);
this->b->setChecked(!check);
this->targetDesc = title;
this->db = db;
QString str = targetDesc;
str.truncate(c->width());
c->setText(str);
QString q;
QString col;
if(c->isChecked()) {q = "#6AE68D"; col = "black";}
else {q = "rgba( 24, 26, 31, 255)"; col = "rgb(214, 216, 218)";}
this->setStyleSheet("QWidget{color: "+col+"; background-color : "+q+"; border-radius : 3px; "
"font-weight : 200; font-size: 14px; border : none;}");
connect(c, SIGNAL(stateChanged(int)), this, SLOT(up()));
}
/**
* @brief update target (mostly color)
*/
void target::up()
{
this->db->updateTarget(this->wdwId, this->c->checkState());
QString q;
QString col;
if(c->isChecked()) {q = "#6AE68D"; col = "black";}
else {q = "rgba( 24, 26, 31, 255)"; col = "rgb(214, 216, 218)";}
this->setStyleSheet("QWidget{color: "+col+"; background-color : "+q+"; border-radius : 3px; "
"font-weight : 200; font-size: 14px; border : none;}");
}