~mutse-young/chinese-calendar/trunk

1 by Shine Huang
new trunk v0.7 Refactor the project
1
/*
2
 * This file is part of the chinese-calendar project
5.1.8 by abel
fix copyright,change icon
3
 * Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd
1 by Shine Huang
new trunk v0.7 Refactor the project
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 3 as
7
 * published by the Free Software Foundation.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * This project is developed by "UbuntuKylin Members" team,
18
 * see <https://launchpad.net/~ubuntukylin~members>
19
 * Authors: Abel Liu <guiltyritter@gmail.com>
20
 *                 Shine Huang <hostc@163.com>
21
 */
22
23
#include "chinesecalendar.h"
24
12 by abel
add note
25
Cnote *note = 0;
26
1 by Shine Huang
new trunk v0.7 Refactor the project
27
ChineseCalendar::ChineseCalendar(QWidget *parent)
28
    : QWidget(parent)
29
{
30
    setupUi(this);
31
12 by abel
add note
32
    note = new Cnote;
33
    QDesktopWidget desktop;
34
    int width = desktop.screenGeometry().width();
35
    int height = desktop.screenGeometry().height();
16 by abel
fix bug #1154050,#1154063,#1154079
36
    note->setGeometry(QRect(width-400,80,224,280));
12 by abel
add note
37
    note->hide();
38
5.1.4 by abel
changelog
39
    bg = new QPixmap(":/img/chinesecalendarBGyellow.png");
8 by Shine Huang
add new indicator icon
40
    icon = QIcon(":/img/icon.png");
41
    icon64 = QIcon(":/img/chinesecalendar-64.png");
1 by Shine Huang
new trunk v0.7 Refactor the project
42
    mycalendat=new CCBO;
43
    mycalendat->InitConnection(QDir::currentPath ());
44
    selectedDate = QDate::currentDate();
45
	monthCombo->setCurrentIndex(selectedDate.month() - 1);
9 by abel
fix bug #1129925
46
    YearSelect->setCurrentIndex(selectedDate.year()-1900);
1 by Shine Huang
new trunk v0.7 Refactor the project
47
    connect(monthCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setMonth(int)));
48
    connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int)));
9 by abel
fix bug #1129925
49
    connect(YearSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(setYear(int)));
1 by Shine Huang
new trunk v0.7 Refactor the project
50
    connect(this->backtotoday, SIGNAL(clicked()), this, SLOT(backtoday()));
12 by abel
add note
51
    connect(note,SIGNAL(save(QString)),this,SLOT(savedata(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
52
13 by heyize
add note
53
54
5 by Shine Huang
create New UI,ready to publish.
55
    this->TbnextMonth->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
56
    this->TbnextYear->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
57
    this->TbpreviousMonth->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
58
    this->TbpreviousYear->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
59
    this->backtotoday->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
9 by abel
fix bug #1129925
60
    this->YearSelect->setStyleSheet("QComboBox{border: 2px solid lightgray;border-radius: 5px;font:12pt;}");
5 by Shine Huang
create New UI,ready to publish.
61
    this->monthCombo->setStyleSheet("QComboBox{border: 2px solid lightgray;border-radius: 5px;font:12pt;}");
62
    this->label->setStyleSheet("QLabel{font:12pt;}");
63
    this->label_2->setStyleSheet("QLabel{font:12pt;}");
4 by Shine Huang
64
1 by Shine Huang
new trunk v0.7 Refactor the project
65
    QDateTime dateTime;
66
    QString currentTime;
67
    QString week;
68
    dateTime = QDateTime::currentDateTime();
69
    if(dateTime.toString("ddd") == "Mon")
70
        week = "星期一";
71
    if(dateTime.toString("ddd") == "Tue")
72
        week = "星期二";
73
    if(dateTime.toString("ddd") == "Wed")
74
        week = "星期三";
75
    if(dateTime.toString("ddd") == "Thu")
76
        week = "星期四";
77
    if(dateTime.toString("ddd") == "Fri")
78
        week = "星期五";
79
    if(dateTime.toString("ddd") == "Sat")
80
        week = "星期六";
81
    if(dateTime.toString("ddd") == "Sun")
82
        week = "星期日";
3.1.1 by abel
add background
83
    currentTime = dateTime.toString("yyyy-MM-dd %1").arg(week);
1 by Shine Huang
new trunk v0.7 Refactor the project
84
    QDate day = QDate::currentDate();
85
    struct CCalendar datebase;
86
    mycalendat->ctcl_solar_to_lunar(day.year(),day.month(),day.day(),&datebase);
87
    QString chinesemonth = datebase.cmonth;
5.1.2 by abel
fix copyright
88
    if (chinesemonth == "一月")
89
        chinesemonth = "正月";
1 by Shine Huang
new trunk v0.7 Refactor the project
90
    if (chinesemonth == "十一月")
91
        chinesemonth = "冬月";
92
    if (chinesemonth == "十二月")
93
        chinesemonth = "腊月";
94
    QString chineseday = QString("农历 %1%2").arg(chinesemonth).arg(datebase.cday);
95
    QString chineseyear = QString("%1年(%2年)").arg(datebase.ganzhi).arg(datebase.shengxiao);
5 by Shine Huang
create New UI,ready to publish.
96
10 by heyize
add lunar yiji
97
    QString chineseyi = QString("%1").arg(datebase.yi);
98
    QStringList chineseyilist = chineseyi.split("、");
99
    QString chineseji = QString("%2").arg(datebase.ji);
100
    QStringList chinesejilist = chineseji.split("、");
101
5 by Shine Huang
create New UI,ready to publish.
102
    QFont font;
103
    QPalette pa;
104
    font.setPointSize(48);
105
    font.setBold(true);
106
    this->label_10->setFont(font);
1 by Shine Huang
new trunk v0.7 Refactor the project
107
    this->label_10->setText(QString::number(day.day()));
5 by Shine Huang
create New UI,ready to publish.
108
    font.setBold(false);
3.1.1 by abel
add background
109
    font.setPointSize(9);
1 by Shine Huang
new trunk v0.7 Refactor the project
110
    this->label_12->setFont(font);
111
    this->label_12->setText(currentTime);
3.1.1 by abel
add background
112
    font.setPointSize(10);
1 by Shine Huang
new trunk v0.7 Refactor the project
113
    this->label_13->setFont(font);
114
    this->label_13->setText(chineseday);
115
    this->label_14->setFont(font);
116
    this->label_14->setText(chineseyear);
117
    font.setPointSize(15);
118
    this->label_15->setFont(font);
10 by heyize
add lunar yiji
119
    font.setPointSize(10);
120
    this->label_17->setFont(font);
121
    this->label_18->setFont(font);
13 by heyize
add note
122
    QString yi=QString("");
123
    QString ji=QString("");
124
    if(chineseyilist.count() == 0 )
125
       yi =QString("");
126
    if(chineseyilist.count() >= 5)
127
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1)).append("\n").append(chineseyilist.at(2)).append("\n").append(chineseyilist.at(3)).append("\n").append(chineseyilist.at(4));
128
    if(chineseyilist.count() == 4)
129
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1)).append("\n").append(chineseyilist.at(2)).append("\n").append(chineseyilist.at(3));
130
    if (chineseyilist.count() == 3)
131
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1)).append("\n").append(chineseyilist.at(2));
132
    if (chineseyilist.count() == 2)
133
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1));
134
    if (chineseyilist.count() == 1)
135
       yi = QString("").append(chineseyilist.at(0)).append("\n");
136
    this->label_17->setText(yi);
137
138
    if(chinesejilist.count() == 0 )
139
       ji =QString("");
140
    if(chinesejilist.count() >= 5)
141
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1)).append("\n").append(chinesejilist.at(2)).append("\n").append(chinesejilist.at(3)).append("\n").append(chinesejilist.at(4));
142
    if(chinesejilist.count() == 4)
143
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1)).append("\n").append(chinesejilist.at(2)).append("\n").append(chinesejilist.at(3));
144
    if (chinesejilist.count() == 3)
145
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1)).append("\n").append(chinesejilist.at(2));
146
    if (chinesejilist.count() == 2)
147
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1));
148
    if (chinesejilist.count() == 1)
149
       ji = QString("").append(chinesejilist.at(0)).append("\n");
10 by heyize
add lunar yiji
150
    this->label_18->setText(ji);
13 by heyize
add note
151
19 by abel
fix bug
152
    QString cnote=mycalendat->ctcl_displaydata(day.year(),day.month(),day.day());
13 by heyize
add note
153
    QString haveplan=QString("今日有行程安排");
154
    QString noplan=QString("今日无行程安排");
18 by abel
fix bug
155
    int num=cnote.count();
156
    while( num > 0 && cnote.at(num-1).isSpace())
17 by heyize
fix bug #1154075
157
    {
18 by abel
fix bug
158
        num--;
17 by heyize
fix bug #1154075
159
    }
18 by abel
fix bug
160
    if(cnote.isEmpty() || num == 0)
13 by heyize
add note
161
        this->label_19->setText(noplan);
162
    else
163
        this->label_19->setText(haveplan);
3.1.1 by abel
add background
164
    pa.setColor(QPalette::WindowText,Qt::white);
165
    this->label->setPalette(pa);
166
    this->label_2->setPalette(pa);
167
    this->label_15->setPalette(pa);
5 by Shine Huang
create New UI,ready to publish.
168
    this->label_4->setPalette(pa);
169
    this->label_5->setPalette(pa);
170
    this->label_6->setPalette(pa);
171
    this->label_7->setPalette(pa);
172
    this->label_8->setPalette(pa);
3.1.1 by abel
add background
173
5 by Shine Huang
create New UI,ready to publish.
174
    pa.setColor(QPalette::WindowText,QColor(255,255,255));
1 by Shine Huang
new trunk v0.7 Refactor the project
175
    this->label_3->setPalette(pa);
10 by heyize
add lunar yiji
176
    this->label_9->setPalette(pa); 
177
178
    pa.setColor(QPalette::WindowText,Qt::black);
179
    this->label_18->setPalette(pa);
13 by heyize
add note
180
    this->label_19->setPalette(pa);
1 by Shine Huang
new trunk v0.7 Refactor the project
181
5 by Shine Huang
create New UI,ready to publish.
182
    pa.setColor(QPalette::WindowText,Qt::red);
1 by Shine Huang
new trunk v0.7 Refactor the project
183
    this->label_10->setPalette(pa);
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
184
    this->label_11->setPalette(pa);
1 by Shine Huang
new trunk v0.7 Refactor the project
185
    this->label_12->setPalette(pa);
186
    this->label_13->setPalette(pa);
187
    this->label_14->setPalette(pa);
10 by heyize
add lunar yiji
188
    this->label_17->setPalette(pa);
1 by Shine Huang
new trunk v0.7 Refactor the project
189
190
    map = new QMap<QString, DateItem *>();
191
    DateItem *dateitem00 = new DateItem(this);
192
    dateitem00->show();
193
    map->insert(QString("1-1"), dateitem00 );
194
    connect(dateitem00, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
195
    connect(dateitem00, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
196
197
    DateItem *dateitem01 = new DateItem(this);
198
    dateitem01->show();
199
    map->insert(QString("1-2"), dateitem01 );
200
    connect(dateitem01, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
201
    connect(dateitem01, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
202
203
    DateItem *dateitem02 = new DateItem(this);
204
    dateitem02->show();
205
    map->insert(QString("1-3"), dateitem02 );
206
    connect(dateitem02, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
207
    connect(dateitem02, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
208
209
    DateItem *dateitem03 = new DateItem(this);
210
    dateitem03->show();
211
    map->insert(QString("1-4"), dateitem03 );
212
    connect(dateitem03, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
213
    connect(dateitem03, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
214
215
    DateItem *dateitem04 = new DateItem(this);
216
    dateitem04->show();
217
    map->insert(QString("1-5"), dateitem04 );
218
    connect(dateitem04, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
219
    connect(dateitem04, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
220
221
    DateItem *dateitem05 = new DateItem(this);
222
    dateitem05->show();
223
    map->insert(QString("1-6"), dateitem05 );
224
    connect(dateitem05, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
225
    connect(dateitem05, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
226
227
    DateItem *dateitem06 = new DateItem(this);
228
    dateitem06->show();
229
    map->insert(QString("1-7"), dateitem06 );
230
    connect(dateitem06, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
231
    connect(dateitem06, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
232
233
    DateItem *dateitem10 = new DateItem(this);
234
    dateitem10->show();
235
    map->insert(QString("2-1"), dateitem10 );
236
    connect(dateitem10, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
237
    connect(dateitem10, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
238
239
    DateItem *dateitem11 = new DateItem(this);
240
    dateitem11->show();
241
    map->insert(QString("2-2"), dateitem11 );
242
    connect(dateitem11, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
243
    connect(dateitem11, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
244
245
    DateItem *dateitem12 = new DateItem(this);
246
    dateitem12->show();
247
    map->insert(QString("2-3"), dateitem12 );
248
    connect(dateitem12, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
249
    connect(dateitem12, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
250
251
    DateItem *dateitem13 = new DateItem(this);
252
    dateitem13->show();
253
    map->insert(QString("2-4"), dateitem13 );
254
    connect(dateitem13, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
255
    connect(dateitem13, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
256
257
    DateItem *dateitem14 = new DateItem(this);
258
    dateitem14->show();
259
    map->insert(QString("2-5"), dateitem14 );
260
    connect(dateitem14, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
261
    connect(dateitem14, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
262
263
    DateItem *dateitem15 = new DateItem(this);
264
    dateitem15->show();
265
    map->insert(QString("2-6"), dateitem15 );
266
    connect(dateitem15, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
267
    connect(dateitem15, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
268
269
    DateItem *dateitem16 = new DateItem(this);
270
    dateitem16->show();
271
    map->insert(QString("2-7"), dateitem16 );
272
    connect(dateitem16, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
273
    connect(dateitem16, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
274
275
    DateItem *dateitem20 = new DateItem(this);
276
    dateitem20->show();
277
    map->insert(QString("3-1"), dateitem20 );
278
    connect(dateitem20, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
279
    connect(dateitem20, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
280
281
    DateItem *dateitem21 = new DateItem(this);
282
    dateitem21->show();
283
    map->insert(QString("3-2"), dateitem21 );
284
    connect(dateitem21, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
285
    connect(dateitem21, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
286
287
    DateItem *dateitem22 = new DateItem(this);
288
    dateitem22->show();
289
    map->insert(QString("3-3"), dateitem22 );
290
    connect(dateitem22, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
291
    connect(dateitem22, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
292
293
    DateItem *dateitem23 = new DateItem(this);
294
    dateitem23->show();
295
    map->insert(QString("3-4"), dateitem23 );
296
    connect(dateitem23, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
297
    connect(dateitem23, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
298
299
    DateItem *dateitem24 = new DateItem(this);
300
    dateitem24->show();
301
    map->insert(QString("3-5"), dateitem24 );
302
    connect(dateitem24, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
303
    connect(dateitem24, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
304
305
    DateItem *dateitem25 = new DateItem(this);
306
    dateitem25->show();
307
    map->insert(QString("3-6"), dateitem25 );
308
    connect(dateitem25, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
309
    connect(dateitem25, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
310
311
    DateItem *dateitem26 = new DateItem(this);
312
    dateitem26->show();
313
    map->insert(QString("3-7"), dateitem26 );
314
    connect(dateitem26, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
315
    connect(dateitem26, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
316
317
    DateItem *dateitem30 = new DateItem(this);
318
    dateitem30->show();
319
    map->insert(QString("4-1"), dateitem30 );
320
    connect(dateitem30, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
321
    connect(dateitem30, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
322
323
    DateItem *dateitem31 = new DateItem(this);
324
    dateitem31->show();
325
    map->insert(QString("4-2"), dateitem31 );
326
    connect(dateitem31, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
327
    connect(dateitem31, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
328
329
    DateItem *dateitem32 = new DateItem(this);
330
    dateitem32->show();
331
    map->insert(QString("4-3"), dateitem32 );
332
    connect(dateitem32, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
333
    connect(dateitem32, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
334
335
    DateItem *dateitem33 = new DateItem(this);
336
    dateitem33->show();
337
    map->insert(QString("4-4"), dateitem33 );
338
    connect(dateitem33, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
339
    connect(dateitem33, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
340
341
    DateItem *dateitem34 = new DateItem(this);
342
    dateitem34->show();
343
    map->insert(QString("4-5"), dateitem34 );
344
    connect(dateitem34, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
345
    connect(dateitem34, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
346
347
    DateItem *dateitem35 = new DateItem(this);
348
    dateitem35->show();
349
    map->insert(QString("4-6"), dateitem35 );
350
    connect(dateitem35, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
351
    connect(dateitem35, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
352
353
    DateItem *dateitem36 = new DateItem(this);
354
    dateitem36->show();
355
    map->insert(QString("4-7"), dateitem36 );
356
    connect(dateitem36, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
357
    connect(dateitem36, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
358
359
    DateItem *dateitem40 = new DateItem(this);
360
    dateitem40->show();
361
    map->insert(QString("5-1"), dateitem40 );
362
    connect(dateitem40, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
363
    connect(dateitem40, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
364
365
    DateItem *dateitem41 = new DateItem(this);
366
    dateitem41->show();
367
    map->insert(QString("5-2"), dateitem41 );
368
    connect(dateitem41, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
369
    connect(dateitem41, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
370
371
    DateItem *dateitem42 = new DateItem(this);
372
    dateitem42->show();
373
    map->insert(QString("5-3"), dateitem42 );
374
    connect(dateitem42, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
375
    connect(dateitem42, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
376
377
    DateItem *dateitem43 = new DateItem(this);
378
    dateitem43->show();
379
    map->insert(QString("5-4"), dateitem43 );
380
    connect(dateitem43, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
381
    connect(dateitem43, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
382
383
    DateItem *dateitem44 = new DateItem(this);
384
    dateitem44->show();
385
    map->insert(QString("5-5"), dateitem44 );
386
    connect(dateitem44, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
387
    connect(dateitem44, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
388
389
    DateItem *dateitem45 = new DateItem(this);
390
    dateitem45->show();
391
    map->insert(QString("5-6"), dateitem45 );
392
    connect(dateitem45, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
393
    connect(dateitem45, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
394
395
    DateItem *dateitem46 = new DateItem(this);
396
    dateitem46->show();
397
    map->insert(QString("5-7"), dateitem46 );
398
    connect(dateitem46, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
399
    connect(dateitem46, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
400
401
    DateItem *dateitem50 = new DateItem(this);
402
    dateitem50->hide();
403
    map->insert(QString("6-1"), dateitem50 );
404
    connect(dateitem50, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
405
    connect(dateitem50, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
406
407
    DateItem *dateitem51 = new DateItem(this);
408
    dateitem51->hide();
409
    map->insert(QString("6-2"), dateitem51 );
410
    connect(dateitem51, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
12 by abel
add note
411
    connect(dateitem51, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
1 by Shine Huang
new trunk v0.7 Refactor the project
412
413
    DateItem *dateitem52 = new DateItem(this);
414
    dateitem52->hide();
415
    map->insert(QString("6-3"), dateitem52 );
416
417
    DateItem *dateitem53 = new DateItem(this);
418
    dateitem53->hide();
419
    map->insert(QString("6-4"), dateitem53 );
420
421
    DateItem *dateitem54 = new DateItem(this);
422
    dateitem54->hide();
423
    map->insert(QString("6-5"), dateitem54 );
424
425
    DateItem *dateitem55 = new DateItem(this);
426
    dateitem55->hide();
427
    map->insert(QString("6-6"), dateitem55 );
428
429
    DateItem *dateitem56 = new DateItem(this);
430
    dateitem56->hide();
431
    map->insert(QString("6-7"), dateitem56 );
432
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
433
    setItemLayout();
1 by Shine Huang
new trunk v0.7 Refactor the project
434
    setCalendar();
435
436
    QTimer *timer = new QTimer(this);
437
    timer->setInterval(1000);
438
    connect(timer,SIGNAL(timeout()),this,SLOT(setTime()));
439
    timer->start();
440
441
    QBitmap objBitmap(size());
442
    QPainter painter(&objBitmap);
443
    painter.fillRect(rect(),Qt::white);
444
    painter.setBrush(QColor(0,0,0));
445
    painter.drawRoundedRect(this->rect(),10,10);
446
    setMask(objBitmap);
447
6 by Shine Huang
add indicator support
448
449
    this->createTray();
1 by Shine Huang
new trunk v0.7 Refactor the project
450
}
451
452
ChineseCalendar::~ChineseCalendar()
453
{
454
  delete mycalendat;
455
}
456
12 by abel
add note
457
void ChineseCalendar::setclickday(QString day)
458
{
459
    clickday = day.toInt();
13 by heyize
add note
460
    int year = this->YearSelect->currentText().toInt();
461
    int month = this->monthCombo->currentText().toInt();
462
    int today = clickday;
16 by abel
fix bug #1154050,#1154063,#1154079
463
    QString dateplan = QString("%1月%2日计划安排").arg(this->monthCombo->currentText()).arg(day);
13 by heyize
add note
464
    QString data;
19 by abel
fix bug
465
    data=mycalendat->ctcl_displaydata(year,month,today);
13 by heyize
add note
466
    note->textedit->setText(data);
16 by abel
fix bug #1154050,#1154063,#1154079
467
    note->datelabel->setText(dateplan);
12 by abel
add note
468
}
469
470
void ChineseCalendar::savedata(QString data)
471
{
472
    int year = this->YearSelect->currentText().toInt();
473
    int month = this->monthCombo->currentText().toInt();
474
    int day = clickday;
13 by heyize
add note
475
    QString note = data;  
476
    mycalendat->ctcl_savenote(year,month,day,data);
12 by abel
add note
477
478
}
479
13 by heyize
add note
480
6 by Shine Huang
add indicator support
481
void ChineseCalendar::createTray()
482
{
483
    this->actionShow = new QAction(tr("隐藏/显示"), this);
484
    connect(actionShow, SIGNAL(triggered()), this, SLOT(showOrHide()));
485
486
    this->actionStaysOnTop = new QAction(tr("总在最前"), this);
487
    this->actionStaysOnTop->setCheckable(true);
488
    connect(actionStaysOnTop, SIGNAL(triggered()), this, SLOT(setMode()));
489
490
    this->actionStaysOnBottom = new QAction(tr("总在最后"), this);
491
    this->actionStaysOnBottom->setCheckable(true);
492
    connect(actionStaysOnBottom, SIGNAL(triggered()), this, SLOT(setMode()));
493
494
    this->actionStaysNormal = new QAction(tr("普通模式"), this);
495
    this->actionStaysNormal->setCheckable(true);
496
    this->actionStaysNormal->setChecked(true);
497
    connect(actionStaysNormal, SIGNAL(triggered()), this, SLOT(setMode()));
498
499
    this->ag = new QActionGroup(this);
500
    this->ag->addAction(actionStaysOnTop);
501
    this->ag->addAction(actionStaysOnBottom);
502
    this->ag->addAction(actionStaysNormal);
503
504
    this->actionQuit = new QAction(tr("退出程序"), this);
505
    connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
506
507
    this->trayMenu = new QMenu(this);
508
    this->trayMenu->addAction(actionShow);
509
    this->trayMenu->addSeparator();
510
    this->trayMenu->addAction(actionStaysOnTop);
511
    this->trayMenu->addAction(actionStaysOnBottom);
512
    this->trayMenu->addAction(actionStaysNormal);
513
    this->trayMenu->addSeparator();
514
    this->trayMenu->addAction(actionQuit);
515
516
    this->trayIcon = new QSystemTrayIcon(this);
5.1.4 by abel
changelog
517
    this->trayIcon->setIcon(icon);
6 by Shine Huang
add indicator support
518
    this->trayIcon->setContextMenu(trayMenu);
519
    this->trayIcon->show();
520
}
521
2 by Shine Huang
new bg add
522
void ChineseCalendar::paintEvent(QPaintEvent *)
523
{
4 by Shine Huang
524
    QPainter painter(this);
525
    painter.drawPixmap(0,0,width(),height(),*bg);
2 by Shine Huang
new bg add
526
5 by Shine Huang
create New UI,ready to publish.
527
//    painter.setPen(Qt::gray);
528
    painter.setPen(QColor(255,121,3,100));
529
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
530
    if(!isTall)
531
    {
5 by Shine Huang
create New UI,ready to publish.
532
    //row
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
533
        painter.drawLine(5,108,390,108);
534
        painter.drawLine(5,147,390,147);
535
        painter.drawLine(5,186,390,186);
536
        painter.drawLine(5,225,390,225);
537
        painter.drawLine(5,264,390,264);
538
//        painter.drawLine(5,303,390,303);
539
    }
540
    else
541
    {
542
        painter.drawLine(5,116,390,116);
543
        painter.drawLine(5,163,390,163);
544
        painter.drawLine(5,210,390,210);
545
        painter.drawLine(5,257,390,257);
546
//        painter.drawLine(5,304,390,304);
547
    }
5 by Shine Huang
create New UI,ready to publish.
548
    //column
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
549
    painter.drawLine(60,69,60,303);
550
    painter.drawLine(115,69,115,303);
551
    painter.drawLine(170,69,170,303);
552
    painter.drawLine(225,69,225,303);
553
    painter.drawLine(280,69,280,303);
554
    painter.drawLine(335,69,335,303);
555
}
556
557
void ChineseCalendar::setItemLayout()
558
{
559
    if(isTall == false)
560
    {
561
        map->value("1-1")->resizeItem(55,47);
562
        map->value("1-2")->resizeItem(55,47);
563
        map->value("1-3")->resizeItem(55,47);
564
        map->value("1-4")->resizeItem(55,47);
565
        map->value("1-5")->resizeItem(55,47);
566
        map->value("1-6")->resizeItem(55,47);
567
        map->value("1-7")->resizeItem(55,47);
568
        map->value("2-1")->resizeItem(55,47);
569
        map->value("2-2")->resizeItem(55,47);
570
        map->value("2-3")->resizeItem(55,47);
571
        map->value("2-4")->resizeItem(55,47);
572
        map->value("2-5")->resizeItem(55,47);
573
        map->value("2-6")->resizeItem(55,47);
574
        map->value("2-7")->resizeItem(55,47);
575
        map->value("3-1")->resizeItem(55,47);
576
        map->value("3-2")->resizeItem(55,47);
577
        map->value("3-3")->resizeItem(55,47);
578
        map->value("3-4")->resizeItem(55,47);
579
        map->value("3-5")->resizeItem(55,47);
580
        map->value("3-6")->resizeItem(55,47);
581
        map->value("3-7")->resizeItem(55,47);
582
        map->value("4-1")->resizeItem(55,47);
583
        map->value("4-2")->resizeItem(55,47);
584
        map->value("4-3")->resizeItem(55,47);
585
        map->value("4-4")->resizeItem(55,47);
586
        map->value("4-5")->resizeItem(55,47);
587
        map->value("4-6")->resizeItem(55,47);
588
        map->value("4-7")->resizeItem(55,47);
589
        map->value("5-1")->resizeItem(55,47);
590
        map->value("5-2")->resizeItem(55,47);
591
        map->value("5-3")->resizeItem(55,47);
592
        map->value("5-4")->resizeItem(55,47);
593
        map->value("5-5")->resizeItem(55,47);
594
        map->value("5-6")->resizeItem(55,47);
595
        map->value("5-7")->resizeItem(55,47);
596
        map->value("6-1")->resizeItem(55,47);
597
        map->value("6-2")->resizeItem(55,47);
598
        map->value("6-3")->resizeItem(55,47);
599
        map->value("6-4")->resizeItem(55,47);
600
        map->value("6-5")->resizeItem(55,47);
601
        map->value("6-6")->resizeItem(55,47);
602
        map->value("6-7")->resizeItem(55,47);
603
        isTall = true;
604
    }
605
    map->value("1-1")->move(5,69);
606
    map->value("1-2")->move(60,69);
607
    map->value("1-3")->move(115,69);
608
    map->value("1-4")->move(170,69);
609
    map->value("1-5")->move(225,69);
610
    map->value("1-6")->move(280,69);
611
    map->value("1-7")->move(335,69);
612
    map->value("2-1")->move(5,116);
613
    map->value("2-2")->move(60,116);
614
    map->value("2-3")->move(115,116);
615
    map->value("2-4")->move(170,116);
616
    map->value("2-5")->move(225,116);
617
    map->value("2-6")->move(280,116);
618
    map->value("2-7")->move(335,116);
619
    map->value("3-1")->move(5,163);
620
    map->value("3-2")->move(60,163);
621
    map->value("3-3")->move(115,163);
622
    map->value("3-4")->move(170,163);
623
    map->value("3-5")->move(225,163);
624
    map->value("3-6")->move(280,163);
625
    map->value("3-7")->move(335,163);
626
    map->value("4-1")->move(5,210);
627
    map->value("4-2")->move(60,210);
628
    map->value("4-3")->move(115,210);
629
    map->value("4-4")->move(170,210);
630
    map->value("4-5")->move(225,210);
631
    map->value("4-6")->move(280,210);
632
    map->value("4-7")->move(335,210);
633
    map->value("5-1")->move(5,257);
634
    map->value("5-2")->move(60,257);
635
    map->value("5-3")->move(115,257);
636
    map->value("5-4")->move(170,257);
637
    map->value("5-5")->move(225,257);
638
    map->value("5-6")->move(280,257);
639
    map->value("5-7")->move(335,257);
640
    map->value("6-1")->move(5,304);
641
    map->value("6-2")->move(60,304);
642
    map->value("6-3")->move(115,304);
643
    map->value("6-4")->move(170,304);
644
    map->value("6-5")->move(225,304);
645
    map->value("6-6")->move(280,304);
646
    map->value("6-7")->move(335,304);
647
}
648
649
void ChineseCalendar::resetItemLayout()
650
{
651
    map->value("1-1")->resizeItem(55,39);
652
    map->value("1-2")->resizeItem(55,39);
653
    map->value("1-3")->resizeItem(55,39);
654
    map->value("1-4")->resizeItem(55,39);
655
    map->value("1-5")->resizeItem(55,39);
656
    map->value("1-6")->resizeItem(55,39);
657
    map->value("1-7")->resizeItem(55,39);
658
    map->value("2-1")->resizeItem(55,39);
659
    map->value("2-2")->resizeItem(55,39);
660
    map->value("2-3")->resizeItem(55,39);
661
    map->value("2-4")->resizeItem(55,39);
662
    map->value("2-5")->resizeItem(55,39);
663
    map->value("2-6")->resizeItem(55,39);
664
    map->value("2-7")->resizeItem(55,39);
665
    map->value("3-1")->resizeItem(55,39);
666
    map->value("3-2")->resizeItem(55,39);
667
    map->value("3-3")->resizeItem(55,39);
668
    map->value("3-4")->resizeItem(55,39);
669
    map->value("3-5")->resizeItem(55,39);
670
    map->value("3-6")->resizeItem(55,39);
671
    map->value("3-7")->resizeItem(55,39);
672
    map->value("4-1")->resizeItem(55,39);
673
    map->value("4-2")->resizeItem(55,39);
674
    map->value("4-3")->resizeItem(55,39);
675
    map->value("4-4")->resizeItem(55,39);
676
    map->value("4-5")->resizeItem(55,39);
677
    map->value("4-6")->resizeItem(55,39);
678
    map->value("4-7")->resizeItem(55,39);
679
    map->value("5-1")->resizeItem(55,39);
680
    map->value("5-2")->resizeItem(55,39);
681
    map->value("5-3")->resizeItem(55,39);
682
    map->value("5-4")->resizeItem(55,39);
683
    map->value("5-5")->resizeItem(55,39);
684
    map->value("5-6")->resizeItem(55,39);
685
    map->value("5-7")->resizeItem(55,39);
686
    map->value("6-1")->resizeItem(55,39);
687
    map->value("6-2")->resizeItem(55,39);
688
    map->value("6-3")->resizeItem(55,39);
689
    map->value("6-4")->resizeItem(55,39);
690
    map->value("6-5")->resizeItem(55,39);
691
    map->value("6-6")->resizeItem(55,39);
692
    map->value("6-7")->resizeItem(55,39);
693
    isTall = false;
694
695
    map->value("1-1")->move(5,69);
696
    map->value("1-2")->move(60,69);
697
    map->value("1-3")->move(115,69);
698
    map->value("1-4")->move(170,69);
699
    map->value("1-5")->move(225,69);
700
    map->value("1-6")->move(280,69);
701
    map->value("1-7")->move(335,69);
702
    map->value("2-1")->move(5,108);
703
    map->value("2-2")->move(60,108);
704
    map->value("2-3")->move(115,108);
705
    map->value("2-4")->move(170,108);
706
    map->value("2-5")->move(225,108);
707
    map->value("2-6")->move(280,108);
708
    map->value("2-7")->move(335,108);
709
    map->value("3-1")->move(5,147);
710
    map->value("3-2")->move(60,147);
711
    map->value("3-3")->move(115,147);
712
    map->value("3-4")->move(170,147);
713
    map->value("3-5")->move(225,147);
714
    map->value("3-6")->move(280,147);
715
    map->value("3-7")->move(335,147);
716
    map->value("4-1")->move(5,186);
717
    map->value("4-2")->move(60,186);
718
    map->value("4-3")->move(115,186);
719
    map->value("4-4")->move(170,186);
720
    map->value("4-5")->move(225,186);
721
    map->value("4-6")->move(280,186);
722
    map->value("4-7")->move(335,186);
723
    map->value("5-1")->move(5,225);
724
    map->value("5-2")->move(60,225);
725
    map->value("5-3")->move(115,225);
726
    map->value("5-4")->move(170,225);
727
    map->value("5-5")->move(225,225);
728
    map->value("5-6")->move(280,225);
729
    map->value("5-7")->move(335,225);
730
    map->value("6-1")->move(5,264);
731
    map->value("6-2")->move(60,264);
732
    map->value("6-3")->move(115,264);
733
    map->value("6-4")->move(170,264);
734
    map->value("6-5")->move(225,264);
735
    map->value("6-6")->move(280,264);
736
    map->value("6-7")->move(335,264);
2 by Shine Huang
new bg add
737
}
738
1 by Shine Huang
new trunk v0.7 Refactor the project
739
void ChineseCalendar::setTime()
740
{
741
    QDateTime dateTime = QDateTime::currentDateTime();
742
    this->label_15->setText(dateTime.toString("hh:mm:ss"));
743
}
744
745
void ChineseCalendar::resetcalendardate(QString day)
746
{
9 by abel
fix bug #1129925
747
    QDate date(this->YearSelect->currentText().toInt(),this->monthCombo->currentText().toInt(),day.toInt());
1 by Shine Huang
new trunk v0.7 Refactor the project
748
    clearbackground();
749
    QString weekday;
750
    if(date.toString("ddd") == "Mon")
751
        weekday = "星期一";
752
    if(date.toString("ddd") == "Tue")
753
        weekday = "星期二";
754
    if(date.toString("ddd") == "Wed")
755
        weekday = "星期三";
756
    if(date.toString("ddd") == "Thu")
757
        weekday = "星期四";
758
    if(date.toString("ddd") == "Fri")
759
        weekday = "星期五";
760
    if(date.toString("ddd") == "Sat")
761
        weekday = "星期六";
762
    if(date.toString("ddd") == "Sun")
763
        weekday = "星期日";
3.1.1 by abel
add background
764
    QString selecttime = date.toString("yyyy-MM-dd %1").arg(weekday);
1 by Shine Huang
new trunk v0.7 Refactor the project
765
    struct CCalendar d;
766
    mycalendat->ctcl_solar_to_lunar(date.year(),date.month(),date.day(),&d);
767
    QString selectmonth = d.cmonth;
5.1.2 by abel
fix copyright
768
    if (selectmonth == "一月")
769
        selectmonth = "正月";
1 by Shine Huang
new trunk v0.7 Refactor the project
770
    if (selectmonth == "十一月")
771
        selectmonth = "冬月";
772
    if (selectmonth == "十二月")
773
        selectmonth = "腊月";
5.1.11 by abel
fix Bug #1124849
774
    struct CCalendar f = fixshengxiao(date);
1 by Shine Huang
new trunk v0.7 Refactor the project
775
    QString selectday = QString("农历 %1%2").arg(selectmonth).arg(d.cday);
5.1.11 by abel
fix Bug #1124849
776
    QString selectyear = QString("%1年(%2年)").arg(f.ganzhi).arg(f.shengxiao);
1 by Shine Huang
new trunk v0.7 Refactor the project
777
    this->label_10->setText(day);
778
    this->label_12->setText(selecttime);
779
    this->label_13->setText(selectday);
780
    this->label_14->setText(selectyear);
10 by heyize
add lunar yiji
781
13 by heyize
add note
782
    QString cnote=QString("");
783
    QString haveplan=QString("今日有行程安排");
784
    QString noplan=QString("今日无行程安排");
19 by abel
fix bug
785
    cnote=mycalendat->ctcl_displaydata(date.year(),date.month(),date.day());
18 by abel
fix bug
786
    int num=cnote.count();
787
    while( num > 0 && cnote.at(num-1).isSpace())
17 by heyize
fix bug #1154075
788
    {
18 by abel
fix bug
789
        num--;
17 by heyize
fix bug #1154075
790
    }
18 by abel
fix bug
791
    if(cnote.isEmpty() || num == 0)
13 by heyize
add note
792
        this->label_19->setText(noplan);
793
    else
794
        this->label_19->setText(haveplan);
795
10 by heyize
add lunar yiji
796
    QString yi = QString("");
797
    QString ji = QString("");
798
    QString selectyi = QString("%1").arg(f.yi);
799
    QStringList selectyilist = selectyi.split("、");
800
    if(selectyilist.count() == 0 )
801
       yi =QString("");
802
    if(selectyilist.count() >= 5)
803
       yi = QString("").append(selectyilist.at(0)).append("\n").append(selectyilist.at(1)).append("\n").append(selectyilist.at(2)).append("\n").append(selectyilist.at(3)).append("\n").append(selectyilist.at(4));
804
    if(selectyilist.count() == 4)
805
       yi = QString("").append(selectyilist.at(0)).append("\n").append(selectyilist.at(1)).append("\n").append(selectyilist.at(2)).append("\n").append(selectyilist.at(3));
806
    if (selectyilist.count() == 3)
807
       yi = QString("").append(selectyilist.at(0)).append("\n").append(selectyilist.at(1)).append("\n").append(selectyilist.at(2));
808
    if (selectyilist.count() == 2)
809
       yi = QString("").append(selectyilist.at(0)).append("\n").append(selectyilist.at(1));
810
    if (selectyilist.count() == 1)
811
       yi = QString("").append(selectyilist.at(0)).append("\n");
812
813
    QString selectji = QString("%2").arg(f.ji);
814
    QStringList selectjilist = selectji.split("、");
815
    if(selectjilist.count() == 0 )
816
       ji =QString("");
817
    if(selectjilist.count() >= 5)
818
       ji = QString("").append(selectjilist.at(0)).append("\n").append(selectjilist.at(1)).append("\n").append(selectjilist.at(2)).append("\n").append(selectjilist.at(3)).append("\n").append(selectjilist.at(4));
819
    if(selectjilist.count() == 4)
820
       ji = QString("").append(selectjilist.at(0)).append("\n").append(selectjilist.at(1)).append("\n").append(selectjilist.at(2)).append("\n").append(selectjilist.at(3));
821
    if (selectjilist.count() == 3)
822
       ji = QString("").append(selectjilist.at(0)).append("\n").append(selectjilist.at(1)).append("\n").append(selectjilist.at(2));
823
    if (selectjilist.count() == 2)
824
       ji = QString("").append(selectjilist.at(0)).append("\n").append(selectjilist.at(1));
825
    if (selectjilist.count() == 1)
826
       ji = QString("").append(selectjilist.at(0)).append("\n");
827
    this->label_17->setText(yi);
828
    this->label_18->setText(ji);
1 by Shine Huang
new trunk v0.7 Refactor the project
829
}
830
5.1.11 by abel
fix Bug #1124849
831
CCalendar ChineseCalendar::fixshengxiao(QDate date)
832
{
833
    QDate fixdate = date.addDays(1);
834
    struct CCalendar fix;
835
    mycalendat->ctcl_solar_to_lunar(fixdate.year(),fixdate.month(),fixdate.day(),&fix);
836
    if (fix.sterm == "立春")
837
    {
838
        fixdate = fixdate.addDays(-2);
839
        mycalendat->ctcl_solar_to_lunar(fixdate.year(),fixdate.month(),fixdate.day(),&fix);
840
        return fix;
841
    }
842
    else
843
    {
844
        fixdate = fixdate.addDays(-1);
845
        mycalendat->ctcl_solar_to_lunar(fixdate.year(),fixdate.month(),fixdate.day(),&fix);
846
        return fix;
847
    }
848
}
849
1 by Shine Huang
new trunk v0.7 Refactor the project
850
void ChineseCalendar::backtoday()
851
{
852
    QDate today = QDate::currentDate();
9 by abel
fix bug #1129925
853
    YearSelect->setCurrentIndex(today.year() - 1900);
1 by Shine Huang
new trunk v0.7 Refactor the project
854
    monthCombo->setCurrentIndex(today.month() - 1);
855
    setCalendar();
856
857
}
858
859
void ChineseCalendar::setCalendar()
860
{
861
    struct CCalendar c;
862
    cleardate();
863
    QDate date(selectedDate.year(), selectedDate.month(), 1);
864
    while (date.month() == selectedDate.month()) {
865
        int weekDay = date.dayOfWeek();
866
        mycalendat->ctcl_solar_to_lunar(selectedDate.year(),selectedDate.month(),date.day(),&c);
867
        QString mycday;
868
        mycday=c.cday;
869
        if(c.sterm.at(0) >=QChar('0') && c.sterm.at(0) <= QChar('9'))
870
          mycday=c.cday;
871
        else
872
        {
873
          if(c.laststerm)
874
              mycday=c.cday;
875
          else
876
              mycday=c.sterm;
877
        }
878
        int day = date.day();
879
        if (weekDay == 7)
880
            weekDay = 0;
881
        int row = (day + (6 - weekDay) + 7 -1)/7;
882
        QString site = QString("%1-%2").arg(row).arg(weekDay+1);
883
        map->value(site)->setday(date.day());
884
        map->value(site)->setcday(mycday);
885
        if(weekDay == 6 || weekDay == 0)
886
            map->value(site)->setcolor();
887
         date = date.addDays(1);
888
    }
889
890
    if (!map->value("6-1")->day().isNull())
891
    {
892
        map->value("6-1")->show();
893
        map->value("6-2")->show();
894
        map->value("6-3")->show();
895
        map->value("6-4")->show();
896
        map->value("6-5")->show();
897
        map->value("6-6")->show();
898
        map->value("6-7")->show();
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
899
        resetItemLayout();
900
    } 
1 by Shine Huang
new trunk v0.7 Refactor the project
901
902
    QDate today = QDate::currentDate();
903
    if(today.year() == selectedDate.year() && today.month() == selectedDate.month())
904
    {
905
        int d = today.day();
906
        int w = today.dayOfWeek();
907
        if (w == 7)
908
            w = 0;
909
        int r = (d + (6 - w) + 7 -1)/7;
910
        QString add = QString("%1-%2").arg(r).arg(w+1);
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
911
        resetcalendardate(QString::number(today.day()));
5 by Shine Huang
create New UI,ready to publish.
912
        map->value(add)->setToday();
1 by Shine Huang
new trunk v0.7 Refactor the project
913
    }
914
}
915
916
void ChineseCalendar::clearbackground()
917
{
918
    map->value("1-1")->clearstyle();
919
    map->value("1-2")->clearstyle();
920
    map->value("1-3")->clearstyle();
921
    map->value("1-4")->clearstyle();
922
    map->value("1-5")->clearstyle();
923
    map->value("1-6")->clearstyle();
924
    map->value("1-7")->clearstyle();
925
    map->value("2-1")->clearstyle();
926
    map->value("2-2")->clearstyle();
927
    map->value("2-3")->clearstyle();
928
    map->value("2-4")->clearstyle();
929
    map->value("2-5")->clearstyle();
930
    map->value("2-6")->clearstyle();
931
    map->value("2-7")->clearstyle();
932
    map->value("3-1")->clearstyle();
933
    map->value("3-2")->clearstyle();
934
    map->value("3-3")->clearstyle();
935
    map->value("3-4")->clearstyle();
936
    map->value("3-5")->clearstyle();
937
    map->value("3-6")->clearstyle();
938
    map->value("3-7")->clearstyle();
939
    map->value("4-1")->clearstyle();
940
    map->value("4-2")->clearstyle();
941
    map->value("4-3")->clearstyle();
942
    map->value("4-4")->clearstyle();
943
    map->value("4-5")->clearstyle();
944
    map->value("4-6")->clearstyle();
945
    map->value("4-7")->clearstyle();
946
    map->value("5-1")->clearstyle();
947
    map->value("5-2")->clearstyle();
948
    map->value("5-3")->clearstyle();
949
    map->value("5-4")->clearstyle();
950
    map->value("5-5")->clearstyle();
951
    map->value("5-6")->clearstyle();
952
    map->value("5-7")->clearstyle();
953
    map->value("6-1")->clearstyle();
954
    map->value("6-2")->clearstyle();
955
    map->value("6-3")->clearstyle();
956
    map->value("6-4")->clearstyle();
957
    map->value("6-5")->clearstyle();
958
    map->value("6-6")->clearstyle();
959
    map->value("6-7")->clearstyle();
960
}
961
962
void ChineseCalendar::cleardate()
963
{
964
    map->value("1-1")->clear();
965
    map->value("1-2")->clear();
966
    map->value("1-3")->clear();
967
    map->value("1-4")->clear();
968
    map->value("1-5")->clear();
969
    map->value("1-6")->clear();
970
    map->value("1-7")->clear();
971
    map->value("2-1")->clear();
972
    map->value("2-2")->clear();
973
    map->value("2-3")->clear();
974
    map->value("2-4")->clear();
975
    map->value("2-5")->clear();
976
    map->value("2-6")->clear();
977
    map->value("2-7")->clear();
978
    map->value("3-1")->clear();
979
    map->value("3-2")->clear();
980
    map->value("3-3")->clear();
981
    map->value("3-4")->clear();
982
    map->value("3-5")->clear();
983
    map->value("3-6")->clear();
984
    map->value("3-7")->clear();
985
    map->value("4-1")->clear();
986
    map->value("4-2")->clear();
987
    map->value("4-3")->clear();
988
    map->value("4-4")->clear();
989
    map->value("4-5")->clear();
990
    map->value("4-6")->clear();
991
    map->value("4-7")->clear();
992
    map->value("5-1")->clear();
993
    map->value("5-2")->clear();
994
    map->value("5-3")->clear();
995
    map->value("5-4")->clear();
996
    map->value("5-5")->clear();
997
    map->value("5-6")->clear();
998
    map->value("5-7")->clear();
999
    map->value("6-1")->clear();
1000
    map->value("6-2")->clear();
1001
    map->value("6-3")->clear();
1002
    map->value("6-4")->clear();
1003
    map->value("6-5")->clear();
1004
    map->value("6-6")->clear();
1005
    map->value("6-7")->clear();
1006
    map->value("6-1")->hide();
1007
    map->value("6-2")->hide();
1008
    map->value("6-3")->hide();
1009
    map->value("6-4")->hide();
1010
    map->value("6-5")->hide();
1011
    map->value("6-6")->hide();
1012
    map->value("6-7")->hide();
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
1013
    setItemLayout();
1 by Shine Huang
new trunk v0.7 Refactor the project
1014
}
1015
1016
void ChineseCalendar::mousePressEvent(QMouseEvent *event)
1017
{
1018
    if (event->button() == Qt::LeftButton)
1019
    {
1020
        if (map->value("6-1")->isHidden())
1021
        {
5 by Shine Huang
create New UI,ready to publish.
1022
            if (event->x()>5 && event->x()<390 && event->y()>69 && event->y()<304)
1 by Shine Huang
new trunk v0.7 Refactor the project
1023
                moveable = false;
1024
            else moveable = true;
1025
        }
1026
        else
1027
        {
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
1028
            if (event->x()>5 && event->x()<390 && event->y()>69 && event->y()<304)
1 by Shine Huang
new trunk v0.7 Refactor the project
1029
                moveable = false ;
1030
            else moveable = true;
1031
        }
1032
        dragPos = event->globalPos() - frameGeometry().topLeft();
1033
        event->accept();
1034
    }
1035
1036
}
1037
1038
void ChineseCalendar::mouseMoveEvent(QMouseEvent *event)
1039
{
1040
    if (event->buttons() & Qt::LeftButton && moveable == true )
1041
    {
1042
        if (map->value("6-1")->isHidden())
1043
        {
3.1.1 by abel
add background
1044
            if (event->x()>5 && event->x()<390 && event->y()>69 && event->y()<304)
1 by Shine Huang
new trunk v0.7 Refactor the project
1045
                return ;
1046
            else move(event->globalPos() - dragPos);
1047
        }
1048
        else
1049
        {
5.1.1 by abel
repaint dateItem, add debian directory, resize program's size 520*350
1050
            if (event->x()>5 && event->x()<390 && event->y()>69 && event->y()<304)
1 by Shine Huang
new trunk v0.7 Refactor the project
1051
                return ;
1052
            else move(event->globalPos() - dragPos);
1053
        }
1054
        setWindowOpacity(0.5);
1055
    }
1056
    event->accept();
1057
1058
}
1059
1060
void ChineseCalendar::mouseReleaseEvent(QMouseEvent *event)
1061
{
1062
    if (event->button() == Qt::LeftButton)
1063
    {
2 by Shine Huang
new bg add
1064
        setWindowOpacity(1);
1 by Shine Huang
new trunk v0.7 Refactor the project
1065
    }
1066
    event->accept();
1067
}
1068
1069
void ChineseCalendar::setMonth(int month)
1070
{
1071
1072
    int day=0;
1073
    int newmonth = month+1;
1074
    if(newmonth<=0)
1075
    {
1076
        newmonth = 12;
1077
        monthCombo->setCurrentIndex(11);
1078
    }
1079
    if(newmonth>12)
1080
    {
1081
        newmonth = 1;
1082
    }
1083
    if(newmonth ==1 || newmonth ==3 || newmonth == 5 || newmonth == 7 || newmonth  == 8 || newmonth == 10 || newmonth ==12)
1084
    {
1085
        day =31;
1086
    }
1087
    else if(newmonth ==4 || newmonth==6 || newmonth ==9 || newmonth ==11)
1088
    {
1089
       day =30;
1090
    }
1091
   if(selectedDate.year()%4 ==0 && selectedDate.year()%100!=0)
1092
    {
1093
            day = 29;
1094
    }
1095
    else if(selectedDate.year()%400 ==0)
1096
    {
1097
            day = 29;
1098
    }
1099
    else
1100
    {
1101
            day = 28;
1102
    }
1103
    selectedDate = QDate(selectedDate.year(),newmonth,day);
1104
    setCalendar();
1105
}
1106
9 by abel
fix bug #1129925
1107
void ChineseCalendar::setYear(int year)
1 by Shine Huang
new trunk v0.7 Refactor the project
1108
{
9 by abel
fix bug #1129925
1109
    selectedDate = QDate(year+1900, selectedDate.month(), selectedDate.day());
1 by Shine Huang
new trunk v0.7 Refactor the project
1110
    setCalendar();
1111
}
1112
1113
void ChineseCalendar::on_TbpreviousYear_clicked()
1114
{
9 by abel
fix bug #1129925
1115
    if(YearSelect->currentIndex() != 0)
1116
        YearSelect->setCurrentIndex(YearSelect->currentIndex()-1);
1 by Shine Huang
new trunk v0.7 Refactor the project
1117
}
1118
1119
void ChineseCalendar::on_TbpreviousMonth_clicked()
1120
{
9 by abel
fix bug #1129925
1121
    if (monthCombo->currentIndex() == 0 && YearSelect->currentIndex() != 0)
3.1.1 by abel
add background
1122
    {
9 by abel
fix bug #1129925
1123
        YearSelect->setCurrentIndex(YearSelect->currentIndex()-1);
3.1.1 by abel
add background
1124
        monthCombo->setCurrentIndex(11);
1125
    }
1126
    else
1127
        monthCombo->setCurrentIndex(monthCombo->currentIndex()-1);
1 by Shine Huang
new trunk v0.7 Refactor the project
1128
}
1129
1130
void ChineseCalendar::on_TbnextMonth_clicked()
1131
{
9 by abel
fix bug #1129925
1132
    if (monthCombo->currentIndex() == 11 && YearSelect->currentIndex() != 150)
3.1.1 by abel
add background
1133
    {
9 by abel
fix bug #1129925
1134
        YearSelect->setCurrentIndex(YearSelect->currentIndex()+1);
3.1.1 by abel
add background
1135
        monthCombo->setCurrentIndex(0);
1136
    }
1137
    else
1138
        monthCombo->setCurrentIndex(monthCombo->currentIndex()+1);
1 by Shine Huang
new trunk v0.7 Refactor the project
1139
}
1140
1141
void ChineseCalendar::on_TbnextYear_clicked()
1142
{
9 by abel
fix bug #1129925
1143
    if(YearSelect->currentIndex() != 150)
1144
        YearSelect->setCurrentIndex(YearSelect->currentIndex()+1);
1 by Shine Huang
new trunk v0.7 Refactor the project
1145
}
1146
6 by Shine Huang
add indicator support
1147
void ChineseCalendar::showOrHide()
1148
{
1149
    if(this->isHidden())
1150
    {
1151
        this->show();
1152
    }else
1153
        this->hide();
1154
}
1155
1156
void ChineseCalendar::setMode()
1157
{
1158
    if(this->actionStaysOnTop->isChecked())
1159
    {
1160
        this->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
1161
        this->show();
1162
    } else if(this->actionStaysOnBottom->isChecked())
1163
    {
1164
        this->setWindowFlags(Qt::WindowStaysOnBottomHint | Qt::FramelessWindowHint);
1165
        this->show();
1166
    } else
1167
    {
1168
        this->setWindowFlags(Qt::FramelessWindowHint);
1169
        this->show();
1170
    }
1171
}