Merge lp:~jinlj/chinese-calendar/chinese-calendar into lp:chinese-calendar

Proposed by jinlj
Status: Merged
Merge reported by: Shine Huang
Merged at revision: not available
Proposed branch: lp:~jinlj/chinese-calendar/chinese-calendar
Merge into: lp:chinese-calendar
Diff against target: 539 lines (+134/-75)
9 files modified
ccbo.cpp (+60/-45)
ccbo.h (+14/-4)
chinese-calendar.pro (+26/-22)
chinesecalendar.h (+4/-0)
cnote.h (+5/-0)
dateitem.h (+6/-2)
datemaskwidget.h (+10/-2)
main.cpp (+7/-0)
qtsingleapplication/src/qtlocalpeer.cpp (+2/-0)
To merge this branch: bzr merge lp:~jinlj/chinese-calendar/chinese-calendar
Reviewer Review Type Date Requested Status
Shine Huang Approve
Review via email: mp+332978@code.launchpad.net

Description of the change

Add support for Qt5 (on Ubuntu 16.04)

To post a comment you must log in.
Revision history for this message
Shine Huang (shine) wrote :

add qt 5 support

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ccbo.cpp'
2--- ccbo.cpp 2014-03-18 13:37:25 +0000
3+++ ccbo.cpp 2017-10-30 07:41:12 +0000
4@@ -19,6 +19,9 @@
5 * see <https://launchpad.net/~ubuntukylin~members>
6 * Authors: Abel Liu <guiltyritter@gmail.com>
7 * Shine Huang <hostc@163.com>
8+ *
9+ * Modified @ 2017.10.30 14:09:58 CST
10+ * Jinlj <jincsu@126.com>
11 */
12 /*
13 * Chinese Tradional Calendar Library
14@@ -40,18 +43,18 @@
15 if(m>0 && m<=12 && d>0 && d<=days_of_month[m])
16 return(1);
17 else
18- return(-1);
19- }else if(y==1582 && m==10 && d>=5 && d<=14){
20+ return(-1);
21+ }else if(y==1582 && m==10 && d>=5 && d<=14){
22 return(-1);
23 }else{
24 if(y%4==0)days_of_month[2]++;
25 if(m>0 && m<=12 && d>0 && d<=days_of_month[m])
26 return(0);
27- else
28- return(-1);
29+ else
30+ return(-1);
31 }
32 }
33-
34+
35 if(opt==2)
36 return(1);
37 return(0);
38@@ -91,8 +94,8 @@
39 if(x<=d || i==12){
40 m=i;
41 break;
42- }else{
43- x-=d;
44+ }else{
45+ x-=d;
46 }
47 }
48 return 100*m+x;
49@@ -118,7 +121,7 @@
50 {
51 int type=ctcl_calendar_type(y,m,d,1);
52 double jt=(h+(min+sec/60.0)/60.0)/24.0-0.5-zone/24.0;
53- double jd=(type!=0) ? (ctcl_standard_days(y,m,d)+1721425+jt) :
54+ double jd=(type!=0) ? (ctcl_standard_days(y,m,d)+1721425+jt) :
55 (ctcl_standard_days(y,m,d)+1721425+jt);
56 return jd;
57 }
58@@ -133,7 +136,7 @@
59 double jd = y * (365.2423112 - 6.4e-14*(y-100)*(y-100) - 3.047e-8*(y-100))
60 + 15.218427 * n + 1721050.71301;
61 double zeta = 3.0e-4 * y - 0.372781384 - 0.2617913325 * n;
62- double yd = ( 1.945 * sin(zeta) - 0.01206 * sin(2*zeta) )
63+ double yd = ( 1.945 * sin(zeta) - 0.01206 * sin(2*zeta) )
64 * ( 1.048994 - 2.583e-5 *y );
65 double sd =-18e-4*sin(2.313908653*y-0.439822951-3.0443*n);
66 return (t==1)?(jd+yd+sd-ctcl_standard_days(y,1,0)-1721425)
67@@ -166,7 +169,7 @@
68
69 int CCBO::ctcl_year_ganzhi(int y,int m,int d,int h)
70 {
71- if ( (ctcl_date_to_days(y,m,d)+h/24.0)
72+ if ( (ctcl_date_to_days(y,m,d)+h/24.0)
73 < ctcl_solar_term(y,3,1)-1.0 )
74 y-=1;
75 return ctcl_round( ctcl_rem(y-3.0,60.0) );
76@@ -189,11 +192,11 @@
77 double fc=0.1734-3.93e-4*t;
78 double j0=693595+29*ms;
79 double aa0=ang(ms,t,0.08084821133,359.2242/rpi,
80- 0.0000333/rpi,0.00000347/rpi);
81+ 0.0000333/rpi,0.00000347/rpi);
82 double ab0=ang(ms,t,7.171366127999999e-2,306.0253/rpi,
83- -0.0107306/rpi,-0.00001236/rpi);
84+ -0.0107306/rpi,-0.00001236/rpi);
85 double ac0=ang(ms,t,0.08519585128,21.2964/rpi,
86- 0.0016528/rpi,0.00000239/rpi);
87+ 0.0016528/rpi,0.00000239/rpi);
88 int i;
89 for(i=-1;i<=13;i+=1){
90 double aa=aa0+0.507984293*i;
91@@ -205,20 +208,20 @@
92 int diff=ctcl_standard_days(y,m,d)-floor(j);
93 if( diff>=0 && diff<=29 )
94 lunar_date=diff+1;
95- }
96+ }
97 return(lunar_date);
98 }
99
100 int CCBO::ctcl_leap_month(int y)
101 {
102- char leap=lunarstr.mid(y-beginning_year,2).at(0);
103- if(leap=='a')
104- leap='0'+10;
105- if(leap=='b')
106- leap='0'+11;
107- if(leap=='c')
108- leap='0'+12;
109- return leap-'0';
110+ char leap=lunarstr.mid(y-beginning_year,2).at(0);
111+ if(leap=='a')
112+ leap='0'+10;
113+ if(leap=='b')
114+ leap='0'+11;
115+ if(leap=='c')
116+ leap='0'+12;
117+ return leap-'0';
118 }
119
120 int CCBO::ctcl_lunar_month(int y,int m,int d)
121@@ -229,21 +232,21 @@
122 int i;
123 int non_leap;
124 int lunar_month;
125-
126+
127 for(i=-849;i<=y;i++){
128 if(ctcl_leap_month(i)!=0)
129 leap_num++;
130 }
131-
132+
133 non_leap=ctcl_round((ctcl_standard_days(y,m,d)
134- -ctcl_standard_days(-849,1,21)
135- -lunar_days)/29.530588)-leap_num;
136-
137+ -ctcl_standard_days(-849,1,21)
138+ -lunar_days)/29.530588)-leap_num;
139+
140 if(y<=240) non_leap++;
141 if(y<=237) non_leap--;
142 if(y<24) non_leap++;
143 if(y<9) non_leap--;
144- if(y<=-255) non_leap++;
145+ if(y<=-255) non_leap++;
146 if(y<=-256) non_leap+=2;
147 if(y<=-722) non_leap++;
148
149@@ -256,7 +259,7 @@
150 lunar_month++;
151 else lunar_month=ctcl_round(ctcl_rem(lunar_month-1,12)+1);
152
153- return lunar_month;
154+ return lunar_month;
155 }
156 QString CCBO::ctcl_displaydata(int y, int m, int d)
157 {
158@@ -279,10 +282,10 @@
159 if(textedit.isEmpty()&&note.isEmpty())
160 return 0;
161 if(note.isEmpty())
162- { InsertStr=QString("INSERT INTO cnote(y,m,d,note) VALUES(%1,%2,%3,'%4');").arg(y).arg(m).arg(d).arg(textedit);
163+ { InsertStr=QString("INSERT INTO cnote(y,m,d,note) VALUES(%1,%2,%3,'%4');").arg(y).arg(m).arg(d).arg(textedit);
164 ctcl_common_query("cnote",InsertStr);
165 }else{
166- UpdateStr=QString("UPDATE cnote SET note = '%4' where y=%1 and m=%2 and d=%3").arg(y).arg(m).arg(d).arg(textedit);
167+ UpdateStr=QString("UPDATE cnote SET note = '%4' where y=%1 and m=%2 and d=%3").arg(y).arg(m).arg(d).arg(textedit);
168 ctcl_common_query("cnote",UpdateStr);
169 }
170 }
171@@ -292,7 +295,13 @@
172 int r,i;
173 char buf[10];
174 ::qsnprintf(buf, 10, "%02d%02d", m,d);
175+
176+#if QT_VERSION < 0x050000
177 QString MD = QString::fromAscii(buf);
178+#else
179+ QString MD = QString::fromLatin1(buf);
180+#endif
181+
182 QString QueryStr;
183
184 QueryStr=QString("select Ji from yiji where Year=%1 and Month=%2 and Day=%3").arg(y).arg(m).arg(d);
185@@ -301,11 +310,11 @@
186 ctc->yi=ctcl_common_query("yiji",QueryStr);
187
188
189- QueryStr=QString("select VALUE from holiday where DATA='"+MD+"'");
190+ QueryStr=QString("select VALUE from holiday where DATA='"+MD+"'");
191 ctc->holiday=ctcl_common_query("holiday",QueryStr);
192
193 int type=ctcl_calendar_type(y,m,d,1);
194- QueryStr=QString("select VALUE from caltype where ID=%1").arg(type);
195+ QueryStr=QString("select VALUE from caltype where ID=%1").arg(type);
196 ctc->caltype=ctcl_common_query("caltype",QueryStr);
197
198 if(type==-1)return -1;
199@@ -405,9 +414,15 @@
200 ::qsnprintf(buf, 10, "%02d%02d", qAbs(ctc->month),ctc->day);
201 else if(qAbs(ctc->month)==13)
202 ::qsnprintf(buf, 10, "%02d%02d", 1,ctc->day);
203- MD = QString::fromAscii(buf);
204+
205+#if QT_VERSION < 0x050000
206+ MD = QString::fromAscii(buf);
207+#else
208+ MD = QString::fromLatin1(buf);
209+#endif
210+
211 if(ctc->month>0){
212- QueryStr=QString("select VALUE from choliday where DATA='"+MD+"'");
213+ QueryStr=QString("select VALUE from choliday where DATA='"+MD+"'");
214 ctc->choliday=ctcl_common_query("choliday",QueryStr);
215 //logSqlError("choliday",QueryStr);
216 }
217@@ -459,26 +474,26 @@
218 query.last();
219 maxyear=query.value(0).toInt();
220 lunarstr=query.value(1).toByteArray ();
221-
222+
223 return true;
224 }
225
226 void CCBO::logSqlError(const QString& Type, const QString& error)
227 {
228- QFile f("chinesecalendar.log" );
229- if ( !f.open(QIODevice::ReadWrite | QIODevice::Append ) )
230- return;
231- QTextStream t( &f );
232- t << "Error time: " << QDateTime::currentDateTime().toString() << "\n";
233- t << Type << "\n";
234- t << error << "\n";
235- f.close();
236+ QFile f("chinesecalendar.log" );
237+ if ( !f.open(QIODevice::ReadWrite | QIODevice::Append ) )
238+ return;
239+ QTextStream t( &f );
240+ t << "Error time: " << QDateTime::currentDateTime().toString() << "\n";
241+ t << Type << "\n";
242+ t << error << "\n";
243+ f.close();
244 }
245
246 QString CCBO::ctcl_common_query(QString type,QString querystr)
247 {
248 QSqlQuery query;
249- query.prepare(querystr);
250+ query.prepare(querystr);
251 if(!query.exec())
252 logSqlError(type,query.lastError().text());
253 if (query.last()) {
254
255=== modified file 'ccbo.h'
256--- ccbo.h 2014-03-18 13:37:25 +0000
257+++ ccbo.h 2017-10-30 07:41:12 +0000
258@@ -19,6 +19,9 @@
259 * see <https://launchpad.net/~ubuntukylin~members>
260 * Authors: Abel Liu <guiltyritter@gmail.com>
261 * Shine Huang <hostc@163.com>
262+ *
263+ * Modified @ 2017.10.30 14:09:58 CST
264+ * Jinlj <jincsu@126.com>
265 */
266 /*
267 * Chinese Tradional Calendar Library
268@@ -26,7 +29,13 @@
269 * Copyright (C) 2003 donaldzju@zju.edu.cn
270 */
271
272-#pragma once
273+#ifndef CCBO_H
274+#define CCBO_H
275+
276+#ifdef QT5XX
277+#include <QtWidgets>
278+#endif
279+
280 #include <math.h>
281 #include <QByteArray>
282 #include <QFile>
283@@ -93,12 +102,12 @@
284 double ctcl_solar_term(int y,int n,int t);
285 double ctcl_tail(double x);
286 double ctcl_rem(double x,double w);
287- double ctcl_round(double x);
288+ double ctcl_round(double x);
289 int ctcl_gan(int x);
290 int ctcl_zhi(int x);
291 int ctcl_year_ganzhi(int y,int m,int d,int h);
292- double ang(double x,double t,double c1,double t0,double t2,double t3);
293- int ctcl_lunar_date(int y,int m,int d);
294+ double ang(double x,double t,double c1,double t0,double t2,double t3);
295+ int ctcl_lunar_date(int y,int m,int d);
296 int ctcl_leap_month(int y);
297 int ctcl_lunar_month(int y,int m,int d);
298 void logSqlError( const QString& Type, const QString& error);
299@@ -106,3 +115,4 @@
300
301
302 };
303+#endif
304
305=== added file 'chinese-calendar'
306Binary files chinese-calendar 1970-01-01 00:00:00 +0000 and chinese-calendar 2017-10-30 07:41:12 +0000 differ
307=== modified file 'chinese-calendar.pro'
308--- chinese-calendar.pro 2016-04-06 03:10:18 +0000
309+++ chinese-calendar.pro 2017-10-30 07:41:12 +0000
310@@ -1,5 +1,5 @@
311 TEMPLATE = app
312-TARGET +=
313+TARGET +=
314 DEPENDPATH += $$PWD/
315 INCLUDEPATH += $$PWD/
316
317@@ -14,18 +14,18 @@
318 inst4.files += chinese-calendar-autostart
319 inst4.path = /usr/bin
320 default_skin.files += skin/default/chinesecalendarBGyellow.png \
321- skin/default/no.png \
322- skin/default/note.png \
323- skin/default/ok.png
324+ skin/default/no.png \
325+ skin/default/note.png \
326+ skin/default/ok.png
327 default_skin.path = /usr/share/chinese-calendar/skin/default
328 blue_skin.files += skin/blue/yijibg.png \
329- skin/blue/no.png \
330- skin/blue/note.png \
331- skin/blue/ok.png \
332- skin/blue/left-1.png \
333- skin/blue/left-2.png \
334- skin/blue/right-1.png \
335- skin/blue/right-2.png \
336+ skin/blue/no.png \
337+ skin/blue/note.png \
338+ skin/blue/ok.png \
339+ skin/blue/left-1.png \
340+ skin/blue/left-2.png \
341+ skin/blue/right-1.png \
342+ skin/blue/right-2.png \
343 skin/blue/normaldate.png \
344 skin/blue/corner1.png \
345 skin/blue/corner2.png \
346@@ -33,18 +33,18 @@
347 skin/blue/corner4.png
348 blue_skin.path = /usr/share/chinese-calendar/skin/blue
349 black_skin.files += skin/black/chinesecalendar.png \
350- skin/black/no.png \
351- skin/black/no-hover.png \
352- skin/black/ok.png \
353- skin/black/ok-hover.png \
354- skin/black/note.png \
355- skin/black/arrow-left.png \
356- skin/black/arrow-right.png \
357- skin/black/arrow-down.png
358+ skin/black/no.png \
359+ skin/black/no-hover.png \
360+ skin/black/ok.png \
361+ skin/black/ok-hover.png \
362+ skin/black/note.png \
363+ skin/black/arrow-left.png \
364+ skin/black/arrow-right.png \
365+ skin/black/arrow-down.png
366 black_skin.path = /usr/share/chinese-calendar/skin/black
367 qss.files += skin/default-skin.qss \
368- skin/blue-skin.qss \
369- skin/black.qss
370+ skin/blue-skin.qss \
371+ skin/black.qss
372 qss.path = /usr/share/chinese-calendar/skin
373 readme.files += skin/README.md
374 readme.path = /usr/share/chinese-calendar/skin
375@@ -69,7 +69,11 @@
376 sql \
377 svg
378
379-HEADERS += \
380+
381+greaterThan(4, QT_MAJOR_VERSION): QT += widgets
382+
383+
384+HEADERS += \
385 dateitem.h \
386 datemaskwidget.h \
387 chinesecalendar.h \
388
389=== modified file 'chinesecalendar.h'
390--- chinesecalendar.h 2014-03-18 13:37:25 +0000
391+++ chinesecalendar.h 2017-10-30 07:41:12 +0000
392@@ -42,6 +42,10 @@
393 #include "cnote.h"
394 #include "aboutdialog.h"
395
396+#if QT_VERSION >= 0x050000
397+#include <QtWidgets>
398+#endif
399+
400 class CCBO;
401 class ChineseCalendar: public QWidget, private Ui::Calendar
402 {
403
404=== modified file 'cnote.h'
405--- cnote.h 2014-10-10 09:26:49 +0000
406+++ cnote.h 2017-10-30 07:41:12 +0000
407@@ -3,6 +3,11 @@
408
409 #include <QWidget>
410 #include <QtGui>
411+
412+#if QT_VERSION >= 0x050000
413+#include <QtWidgets>
414+#endif
415+
416 #include <QDialog>
417
418 class Cnote : public QDialog
419
420=== modified file 'dateitem.h'
421--- dateitem.h 2016-04-06 03:10:18 +0000
422+++ dateitem.h 2017-10-30 07:41:12 +0000
423@@ -28,6 +28,10 @@
424 #include "datemaskwidget.h"
425 #include "ui_dateitem.h"
426
427+#ifdef QT5XX
428+#include <QtWidgets>
429+#endif
430+
431 namespace Ui {
432 class DateItem;
433 }
434@@ -35,7 +39,7 @@
435 class DateItem : public QWidget
436 {
437 Q_OBJECT
438-
439+
440 public:
441 explicit DateItem(QWidget *parent = 0);
442 ~DateItem();
443@@ -60,7 +64,7 @@
444 public slots:
445 void click();
446 void clickday();
447-
448+
449 signals:
450 void clicked(QString);
451 void day(QString);
452
453=== modified file 'datemaskwidget.h'
454--- datemaskwidget.h 2014-03-18 13:37:25 +0000
455+++ datemaskwidget.h 2017-10-30 07:41:12 +0000
456@@ -18,6 +18,9 @@
457 * see <https://launchpad.net/~ubuntukylin~members>
458 * Authors: Abel Liu <guiltyritter@gmail.com>
459 * Shine Huang <hostc@163.com>
460+ *
461+ * Modified @ 2017.10.30 14:09:58 CST
462+ * Jinlj <jincsu@126.com>
463 */
464
465 #ifndef DATEMASKWIDGET_H
466@@ -27,12 +30,17 @@
467 #include <QMouseEvent>
468 #include "cnote.h"
469
470+
471+#if QT_VERSION >= 0x050000
472+#include <QtWidgets>
473+#endif
474+
475 class DateMaskWidget : public QWidget
476 {
477 Q_OBJECT
478 public:
479 explicit DateMaskWidget(QWidget *parent = 0);
480-
481+
482 signals:
483 void clicked();
484 void clickday();
485@@ -42,7 +50,7 @@
486
487 private:
488 QPoint mousePos;
489-
490+
491 };
492
493 #endif // DATEMASKWIDGET_H
494
495=== modified file 'main.cpp'
496--- main.cpp 2016-03-30 02:52:48 +0000
497+++ main.cpp 2017-10-30 07:41:12 +0000
498@@ -18,6 +18,9 @@
499 * see <https://launchpad.net/~ubuntukylin~members>
500 * Authors: Abel Liu <guiltyritter@gmail.com>
501 * Shine Huang <hostc@163.com>
502+ *
503+ * Modified @ 2017.10.30 14:09:58 CST
504+ * Jinlj <jincsu@126.com>
505 */
506
507 #include <QtGui>
508@@ -30,14 +33,18 @@
509
510 int main(int argc, char *argv[])
511 {
512+ printf("First, you should copy database to `/usr/share/chinese-calendar/db/KylinLunar.db`\n\n");
513 //单程序运行处理
514 QtSingleApplication app(argc, argv);
515 if (app.isRunning())
516 return 0;
517
518+#if QT_VERSION < 0x050000
519 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
520 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
521 // QApplication app(argc, argv);
522+#endif
523+
524 QTranslator translator;
525 QTranslator translatorMenu;
526
527
528=== modified file 'qtsingleapplication/src/qtlocalpeer.cpp'
529--- qtsingleapplication/src/qtlocalpeer.cpp 2014-02-12 02:40:32 +0000
530+++ qtsingleapplication/src/qtlocalpeer.cpp 2017-10-30 07:41:12 +0000
531@@ -43,6 +43,8 @@
532 #include <QCoreApplication>
533 #include <QTime>
534
535+#include <QDataStream>
536+
537 #if defined(Q_OS_WIN)
538 #include <QLibrary>
539 #include <qt_windows.h>

Subscribers

People subscribed via source and target branches

to all changes: