forked from RobertKrajewski/Sync-my-L2P
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructureelement.cpp
135 lines (126 loc) · 3.66 KB
/
structureelement.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
/****************************************************************************
** This file is part of Sync-my-L2P.
**
** Sync-my-L2P is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Sync-my-L2P is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Sync-my-L2P. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "structureelement.h"
#include "myfile.h"
Structureelement::Structureelement(QString name, QUrl url, MyItemType type)
:QStandardItem(name), included(true), url(url), typeEX(type)
{
synchronised = NOT_SYNCHRONISED;
size = 0;
}
QVariant Structureelement::data(int role) const
{
if (role == includeRole)
{
return included;
}
else if (role == urlRole)
{
return url;
}
else if (role == sizeRole)
{
return size;
}
else if (role == dateRole)
{
return time;
}
else if (role == synchronisedRole)
{
return synchronised;
}
else if (role == Qt::StatusTipRole)
{
QString statustip;
if (typeEX == fileItem)
{
statustip.append(text() % " - ");
if (size > 1048576)
statustip.append(QString::number(size/1048576.0,'f',2) % " MB");
else if(size > 1024)
statustip.append(QString::number(size/1024.0,'f',2) % " KB");
else
statustip.append(QString::number(size) % " Byte");
statustip.append(" - " % ((MyFile*)this)->getTime().toString("ddd dd.MM.yy hh:mm"));
return statustip;
}
return statustip;
}
else if (role == Qt::FontRole)
{
if (typeEX == courseItem)
{
QFont BoldFont;
BoldFont.setBold(true);
return BoldFont;
}
}
else if(role == Qt::ForegroundRole)
{
if (included)
if (synchronised == NOW_SYNCHRONISED)
return QBrush(Qt::blue);
else if (synchronised == SYNCHRONISED)
return QBrush(Qt::darkGreen);
else
return QBrush(Qt::black);
else
return QBrush(Qt::red);
}
return QStandardItem::data(role);
}
bool Structureelement::operator< (const QStandardItem& other) const
{
if ((this->size == 0) && ((((Structureelement*)(&other))->size) != 0))
return true;
else if ((this->size != 0) && ((((Structureelement*)(&other))->size) == 0))
return false;
else
return (this->text().toLower() < (((Structureelement*)(&other))->text()).toLower());
}
int Structureelement::type() const
{
return typeEX;
}
void Structureelement::setData(const QVariant &value, int role)
{
if (role == includeRole)
{
this->included = value.toBool();
}
else if (role == urlRole)
{
this->url = value.toUrl();
}
else if (role == sizeRole)
{
this->size = value.toInt();
}
else if (role == dateRole)
{
this->time = value.toDateTime();
}
else if (role == synchronisedRole)
{
this->synchronised = (synchroniseStatus) value.toInt();
}
else
{
QStandardItem::setData(value, role);
}
}