-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetcalendartips.cpp
96 lines (85 loc) · 2.47 KB
/
getcalendartips.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
#include "getcalendartips.h"
#include <QTextCharFormat>
#define NUMTHREADS 5
GetCalendarTips::GetCalendarTips()
{
settings = new QSettings("Mandriva","qacdp");
for (int i =0; i < NUMTHREADS; ++i)
{
CalendarThread *ct = new CalendarThread(this);
connect(ct,SIGNAL(update(QString,QDate)),this,SLOT(update(QString,QDate)));
calendarThreads.append(ct);
}
}
void GetCalendarTips::setCalendar(QCalendarWidget *cal, QString &ses, QString &i)
{
calendar = cal;
session = ses;
id = i;
foreach(CalendarThread *ct, calendarThreads)
ct->setVars(id.toInt(),session);
}
void GetCalendarTips::update(QString text,QDate date){
if(text == settings->value( QString("Cache/%1").arg(date.toString(Qt::ISODate)) ).toString())
{
jobsDone.append(date);
return;
}
settings->setValue(QString("Cache/%1").arg(date.toString(Qt::ISODate)), text);
updateColors(date,text);
jobsDone.append(date);
}
void GetCalendarTips::enqueueJob(const QDate &date,bool force)
{
QString text = settings->value( QString("Cache/%1").arg(date.toString(Qt::ISODate)) ).toString();
if(text.length() > 0)
updateColors(date,text);
if(!jobsDone.contains(date) || force)
{
if(!jobs.contains(date) || force)
{
jobs.enqueue(date);
}
}
}
void GetCalendarTips::updateColors(const QDate &date,QString &text)
{
QBrush brush;
QTextCharFormat fmt;
QRegExp regexHoras("<td align=\"left\">Total</td>.*<td align=\"left\"><b>([0-9]*)</b></td>");
if(text.contains(regexHoras))
{
int horas = regexHoras.cap(1).toInt();
if(horas < 8)
brush.setColor(QColor(255, 255, 0, 140));
else if(horas == 8)
brush.setColor(QColor(124, 252, 0, 140));
else
brush.setColor(QColor(124, 252, 0, 240));
}
else
{
if(date.dayOfWeek() == Qt::Saturday || date.dayOfWeek() == Qt::Sunday )
brush.setColor(QColor(84, 84, 84, 40));
else
brush.setColor(QColor(255, 0, 0, 40));
text = "No entries";
}
fmt.setBackground( brush );
fmt.setToolTip( text );
calendar->setDateTextFormat( date, fmt );
}
QDate GetCalendarTips::dequeueJob()
{
QDate date;
mutex.lock();
if (!jobs.isEmpty())
date = jobs.dequeue();
mutex.unlock();
return date;
}
void GetCalendarTips::startProcessing()
{
foreach(CalendarThread *ct, calendarThreads)
ct->start();
}