-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtdjlist.cpp
More file actions
144 lines (110 loc) · 3.14 KB
/
tdjlist.cpp
File metadata and controls
144 lines (110 loc) · 3.14 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
/*
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"
#include <QTextCodec>
void MainWindow::save_list ()
//item changed
{
QString s;
s = listeditor->toHtml();
cur_list->setText(1, s);
modify_name(cur_list);
}
void MainWindow::set_list (QTreeWidgetItem *it)
//item clicked
{
QString s;
save_list ();
cur_list = it;
show_list();
}
void MainWindow::add_list()
{
QString s;
if (listreeempty == false) {
save_list();
}
con_item = new QTreeWidgetItem (listree);
s.clear();
s.append(tr("New list"));
con_item->setText(0, s);
s.clear();
s.append(tr("New list"));
con_item->setText(1, s);
cur_list = con_item;
listree->setCurrentItem(cur_list);
listreeempty = false;
statustext->setText(tr("Added an empty list"));
show_list();
}
void MainWindow::show_list ()
{
QString s;
int i;
//bring lists tab to foreground
i = tabcontainer->indexOf(listed);
tabcontainer->setCurrentIndex(i);
//first way
s.clear();
s.append(cur_list->text(1));
listeditor->setHtml(s);
//second way
//QTextDocument *doc = new QTextDocument ();
//doc->setHtml(cur_list->text(1));
//listeditor->setDocument(doc);
//third way
//QByteArray data = (cur_list->text(1)).toUtf8();
//QTextCodec *codec = Qt::codecForHtml(data);
//s = codec->toUnicode(data);
//listeditor->setHtml(s);
}
void MainWindow::del_list ()
{
int j;
QTreeWidgetItem *above, *below;
QTextDocument *doc;
QString s;
doc = new QTextDocument ();
doc->setHtml(cur_list->text(1));
s = doc->toPlainText();
if (s.length() != 0){
statustext->setText(tr("List contains data. Please delete that, first."));
return;
}
j = listree->indexOfTopLevelItem(cur_list);
above = listree->itemAbove(cur_list);
below = listree->itemBelow(cur_list);
if (above != NULL){//there is an item above
listree->takeTopLevelItem(j);
statustext->setText(tr("List deleted"));
listree->setCurrentItem(above);
cur_list = above;
listreeempty = false;
show_list();
}
else if (below != NULL) {//no item above but there is an item below
listree->takeTopLevelItem(j);
statustext->setText(tr("List deleted"));
listree->setCurrentItem(cur_list);
cur_list = below;
listreeempty = false;
show_list();
}
else {//cur_list is the last item
listree->takeTopLevelItem(j);
listreeempty = true;
statustext->setText(tr("Last list deleted"));
}
}