QTfrontend/main.cpp
changeset 6579 fc52f7c22c9b
parent 6376 60e2031db563
child 6600 5810e42d8375
equal deleted inserted replaced
6578:d4ad42283125 6579:fc52f7c22c9b
    24 #include <QPlastiqueStyle>
    24 #include <QPlastiqueStyle>
    25 #include <QRegExp>
    25 #include <QRegExp>
    26 #include <QMap>
    26 #include <QMap>
    27 #include <QSettings>
    27 #include <QSettings>
    28 #include <QStringListModel>
    28 #include <QStringListModel>
       
    29 #include <QDate>
    29 
    30 
    30 #include "hwform.h"
    31 #include "hwform.h"
    31 #include "hwconsts.h"
    32 #include "hwconsts.h"
    32 
    33 
    33 #include "HWDataManager.h"
    34 #include "HWDataManager.h"
    36 #include <Shlobj.h>
    37 #include <Shlobj.h>
    37 #endif
    38 #endif
    38 #ifdef __APPLE__
    39 #ifdef __APPLE__
    39 #include "CocoaInitializer.h"
    40 #include "CocoaInitializer.h"
    40 #endif
    41 #endif
       
    42 
       
    43 
       
    44 //Determines the day of easter in year
       
    45 //from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++
       
    46 QDate calculateEaster(long year)
       
    47 {
       
    48     int c, n, k, i, j, l, m, d;
       
    49     
       
    50     c = year/100;
       
    51     n = year - 19*(year/19);
       
    52     k = (c - 17)/25;
       
    53     i = c - c/4 - (c - k)/3 + 19*n + 15;
       
    54     i = i - 30*(i/30);
       
    55     i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11));
       
    56     j = year + year/4 + i + 2 - c + c/4;
       
    57     j = j - 7*(j/7);
       
    58     l = i - j;
       
    59     m = 3 + (l + 40)/44;
       
    60     d = l + 28 - 31*(m / 4);
       
    61 
       
    62     return QDate(year, m, d);
       
    63 }
       
    64 
       
    65 //Checks season and assigns it to the variable season in "hwconsts.h"
       
    66 void checkSeason()
       
    67 {
       
    68    QDate date = QDate::currentDate();
       
    69    
       
    70    //Christmas?
       
    71    if (date.month() == 12 && date.daysInMonth() >= 24 
       
    72 	&& date.daysInMonth() <= 26)
       
    73 	season = SEASON_CHRISTMAS;
       
    74    //Hedgewars birthday?
       
    75    else if (date.month() == 10 && date.daysInMonth() == 31)
       
    76    {
       
    77    	season = SEASON_HWBDAY;
       
    78 	years_since_foundation = date.year() - 2004;
       
    79    }
       
    80    //Easter?
       
    81    else if (calculateEaster(date.year()) == date)
       
    82 	season = SEASON_EASTER;
       
    83    else
       
    84 	season = SEASON_NONE;
       
    85 }
    41 
    86 
    42 bool checkForDir(const QString & dir)
    87 bool checkForDir(const QString & dir)
    43 {
    88 {
    44     QDir tmpdir;
    89     QDir tmpdir;
    45     if (!tmpdir.exists(dir))
    90     if (!tmpdir.exists(dir))
   242     // this creates the autoreleasepool that prevents leaking
   287     // this creates the autoreleasepool that prevents leaking
   243     CocoaInitializer initializer;
   288     CocoaInitializer initializer;
   244 #endif
   289 #endif
   245 
   290 
   246     QString style = "";
   291     QString style = "";
       
   292     QString fname;
       
   293     
       
   294     checkSeason();
       
   295     //For each season, there is an extra stylesheet
       
   296     //Todo: change background for easter and birthday
       
   297     //(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png
       
   298     //with an appropriate background
       
   299     switch (season)
       
   300     {
       
   301     case SEASON_CHRISTMAS : fname = "christmas.css";
       
   302 			    break;
       
   303     case SEASON_EASTER : fname = "easter.css";
       
   304 			 break;
       
   305     case SEASON_HWBDAY : fname = "birthday.css";
       
   306 			 break;
       
   307     default : fname = "qt.css";
       
   308     }
   247 
   309 
   248     // load external stylesheet if there is any
   310     // load external stylesheet if there is any
   249     QFile extFile(dataMgr.findFileForRead("css/qt.css"));
   311     QFile extFile(dataMgr.findFileForRead("css/" + fname));
   250 
   312 
   251     QFile resFile(":/res/css/qt.css");
   313     QFile resFile(":/res/css/" + fname);
   252 
   314 
   253     QFile & file = (extFile.exists()?extFile:resFile);
   315     QFile & file = (extFile.exists()?extFile:resFile);
   254 
   316 
   255     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
   317     if (file.open(QIODevice::ReadOnly | QIODevice::Text))
   256     {
   318     {