-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtdjtree.cpp
More file actions
239 lines (188 loc) · 5.69 KB
/
tdjtree.cpp
File metadata and controls
239 lines (188 loc) · 5.69 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
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
/*
The Daily Journal - A PIM program
Qt version
begin : 12 July 2013
copyright : (C) Kartik Patel
email : letapk@gmail.com
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*/
//Last modified 19 June 2022
#include "tdj.h"
void MainWindow::save_contact ()
//item changed
{
QString s;
s = contacteditor->toHtml();
if (catflag == 0){//contact data item
cur_con->setText(1, s);
modify_name (cur_con);
}
else {//category data item
cur_cat->setText(1, s);
modify_name(cur_cat);
}
}
void MainWindow::modify_name (QTreeWidgetItem *it)
{
QString s1, s;
int i;
QTextDocument doc;
s1 = it->text(1);
doc.setHtml(s1);
s = doc.toPlainText();
for (i = 0; i < s.length(); i++){
if (s[i] == QChar (QLatin1Char('\n')))
s.chop (s.length() - i);
}
it->setText(0, s);
}
void MainWindow::show_contact ()
{
QString s;
int i;
//bring contacts tab to foreground
i = tabcontainer->indexOf(contacted);
tabcontainer->setCurrentIndex(i);
s.clear();
if (catflag == 0){//contact selected
s.append(cur_con->text(1));
modify_name (cur_con);
}
else {//category selected
s.append(cur_cat->text(1));
modify_name(cur_cat);
}
contacteditor->setHtml(s);
}
void MainWindow::set_contact (QTreeWidgetItem *it)
//item clicked
{
QString s;
int i;
//bring contacts tab to foreground
i = tabcontainer->indexOf(contacted);
tabcontainer->setCurrentIndex(i);
save_contact ();
if (it->parent() != NULL) {//contact item
cur_cat = it->parent();
cur_con = it;
catflag = 0;
}
else {//category item
cur_cat = it;
cur_con = it;
catflag = 1;
}
show_contact();
}
void MainWindow::add_category()
{
QString s;
if (contreeempty == false) {
save_contact ();
}
con_item = new QTreeWidgetItem (contree);
s.clear();
s.append(tr("New Group"));
con_item->setText(0, s);
s.clear();
s.append(tr("New Group<p></p>Enter group description here. The first line becomes the group name in the tree on the left."));
con_item->setText(1, s);
cur_cat = con_item;
catflag = 1;
contree->setCurrentItem(cur_cat);
contreeempty = false;
statustext->setText(tr("Added an empty group"));
show_contact();
}
void MainWindow::add_contact()
{
QString s;
if (contreeempty == true) {
statustext->setText(tr("Add a group first"));
return;
}
save_contact ();
con_item = new QTreeWidgetItem ();
s.clear();
s.append(tr("New Contact"));
con_item->setText(0, s);
s.clear();
s.append(tr("New Contact<p></p>Enter contact data here. The first line becomes the contact name in the tree on the left."));
con_item->setText(1, s);
cur_con = con_item;
cur_cat->addChild(cur_con);
catflag = 0;
contree->setCurrentItem(cur_con);
contreeempty = false;
statustext->setText(tr("Added an empty contact"));
show_contact();
}
void MainWindow::del_item()
{
int i, j;
QTreeWidgetItem *above, *below;
if (contreeempty == true) {
statustext->setText(tr("Nothing to delete!"));
return;
}
if (catflag == 1) {//category selected
i = cur_cat->childCount();
if (i > 0) {//category contains contacts
statustext->setText(tr("The group is not empty. Please delete the contacts."));
return;
}
else {//empty category
j = contree->indexOfTopLevelItem(cur_cat);
above = contree->itemAbove(cur_cat);
below = contree->itemBelow(cur_cat);
if (above != NULL){//there is an item above
contree->takeTopLevelItem(j);
if (above->parent() == NULL) {//the item above is a category
cur_cat = above;
cur_con = above;
catflag = 1;
}
else {//the item above is a contact
cur_cat = above->parent();
cur_con = above;
catflag = 0;
}
contree->setCurrentItem(above);
statustext->setText(tr("Group deleted"));
contreeempty = false;
show_contact();
}
else if (below != NULL) {//no item above but there is an item below
contree->takeTopLevelItem(j);
cur_cat = below;//which has to be a category
cur_con = below;
contree->setCurrentItem(cur_cat);
catflag = 1;
statustext->setText(tr("Group deleted"));
contreeempty = false;
show_contact();
}
else {//cur_cat is the last item
contree->takeTopLevelItem(j);
contreeempty = true;
statustext->setText(tr("Last group deleted"));
}
}//empty category
}//catflag = 1
else {//contact selected
cur_con = contree->currentItem();
i = cur_cat->indexOfChild(cur_con);
cur_cat->takeChild(i);
contree->setCurrentItem(cur_cat);
catflag = 1;
statustext->setText(tr("Deleted contact"));
contreeempty = false;
show_contact();
}
}