QTfrontend/main.cpp
changeset 13188 16b375b21af1
parent 13086 8d569c7b36a2
parent 13182 d2f8dafdb080
child 13212 e9e4cc867b6e
equal deleted inserted replaced
13187:e2a83a7b783c 13188:16b375b21af1
    18 
    18 
    19 #include "HWApplication.h"
    19 #include "HWApplication.h"
    20 
    20 
    21 #include <QTranslator>
    21 #include <QTranslator>
    22 #include <QLocale>
    22 #include <QLocale>
    23 #include <QPlastiqueStyle>
       
    24 #include <QRegExp>
    23 #include <QRegExp>
    25 #include <QMap>
    24 #include <QMap>
    26 #include <QSettings>
    25 #include <QSettings>
    27 #include <QStringListModel>
    26 #include <QStringListModel>
    28 #include <QDate>
    27 #include <QDate>
    29 #include <QDesktopWidget>
    28 #include <QDesktopWidget>
    30 #include <QLabel>
    29 #include <QLabel>
    31 #include <QLibraryInfo>
    30 #include <QLibraryInfo>
       
    31 #include <QStyle>
       
    32 #include <QStyleFactory>
    32 
    33 
    33 #include "hwform.h"
    34 #include "hwform.h"
    34 #include "hwconsts.h"
    35 #include "hwconsts.h"
    35 #include "newnetclient.h"
    36 #include "newnetclient.h"
    36 
    37 
   153 .arg(HWApplication::tr("Custom path for configuration data and user data", "command-line"))
   154 .arg(HWApplication::tr("Custom path for configuration data and user data", "command-line"))
   154 .arg(HWApplication::tr("Custom path to the game data folder", "command-line"))
   155 .arg(HWApplication::tr("Custom path to the game data folder", "command-line"))
   155 .arg(HWApplication::tr("Hedgewars can use a %1 (e.g. \"%2\") to connect on start.", "command-line").arg(HWApplication::tr("CONNECTSTRING", "command-line")).arg(QString("hwplay://") + NETGAME_DEFAULT_SERVER));
   156 .arg(HWApplication::tr("Hedgewars can use a %1 (e.g. \"%2\") to connect on start.", "command-line").arg(HWApplication::tr("CONNECTSTRING", "command-line")).arg(QString("hwplay://") + NETGAME_DEFAULT_SERVER));
   156 }
   157 }
   157 
   158 
   158 int main(int argc, char *argv[])
   159 int main(int argc, char *argv[]) {
   159 {
   160     /* Qt5 Base removed Motif, Plastique. These are now in the Qt style plugins
       
   161     (Ubuntu: qt5-style-plugins, which was NOT backported by Debian/Ubuntu to stable/LTS).
       
   162     Windows appears to render best of the remaining options but still isn't quite right. */
       
   163 
       
   164     // Try setting Plastique if available
       
   165     QStyle* coreStyle;
       
   166     coreStyle = QStyleFactory::create("Plastique");
       
   167     if(coreStyle != 0) {
       
   168         QApplication::setStyle(coreStyle);
       
   169         qDebug("Qt style set: Plastique");
       
   170     } else {
       
   171         // Use Windows as fallback.
       
   172         // FIXME: Under Windows style, some widgets like scrollbars don't render as nicely
       
   173         coreStyle = QStyleFactory::create("Windows");
       
   174         if(coreStyle != 0) {
       
   175             QApplication::setStyle(coreStyle);
       
   176             qDebug("Qt style set: Windows");
       
   177         } else {
       
   178             // Windows style should not be missing in Qt5 Base. If it does, something went terribly wrong!
       
   179             qWarning("No Qt style could be set! Using the default one.");
       
   180         }
       
   181     }
       
   182 
   160     // Since we're calling this first, closeResources() will be the last thing called after main() returns.
   183     // Since we're calling this first, closeResources() will be the last thing called after main() returns.
   161     atexit(closeResources);
   184     atexit(closeResources);
   162 
   185 
   163 #ifdef __APPLE__
   186 #ifdef __APPLE__
   164     cocoaInit = new CocoaInitializer(); // Creates the autoreleasepool preventing cocoa object leaks on OS X.
   187     cocoaInit = new CocoaInitializer(); // Creates the autoreleasepool preventing cocoa object leaks on OS X.
   252     QPixmap pixmap(":/res/splash.png");
   275     QPixmap pixmap(":/res/splash.png");
   253     QSplashScreen splash(pixmap);
   276     QSplashScreen splash(pixmap);
   254     splash.show();
   277     splash.show();
   255 #endif
   278 #endif
   256 
   279 
   257     app.setStyle(new QPlastiqueStyle());
       
   258 
       
   259     QDateTime now = QDateTime::currentDateTime();
   280     QDateTime now = QDateTime::currentDateTime();
   260     srand(now.toTime_t());
   281     srand(now.toTime_t());
   261     rand();
   282     rand();
   262 
   283 
   263     Q_INIT_RESOURCE(hedgewars);
   284     Q_INIT_RESOURCE(hedgewars);
   351         {
   372         {
   352             cc = QLocale::system().name();
   373             cc = QLocale::system().name();
   353 
   374 
   354             // Fallback to current input locale if "C" locale is returned
   375             // Fallback to current input locale if "C" locale is returned
   355             if(cc == "C")
   376             if(cc == "C")
   356                 cc = HWApplication::keyboardInputLocale().name();
   377                 cc = HWApplication::inputMethod()->locale().name();
   357         }
   378         }
       
   379         qDebug("Frontend uses locale: %s", qPrintable(cc));
   358 
   380 
   359         // Load locale files into translators
   381         // Load locale files into translators
   360         if (!TranslatorHedgewars.load(QString("physfs://Locale/hedgewars_%1").arg(cc)))
   382         if (!TranslatorHedgewars.load(QString("hedgewars_%1").arg(cc), QString("physfs://Locale")))
   361             qWarning("Failed to install Hedgewars translation (%s)", qPrintable(cc));
   383             qWarning("Failed to install Hedgewars translation (%s)", qPrintable(cc));
   362         if (!TranslatorQt.load(QString("%1/qt_%2").arg(QLibraryInfo::location(QLibraryInfo::TranslationsPath), cc)))
   384         if (!TranslatorQt.load(QString("qt_%1").arg(cc), QString(QLibraryInfo::location(QLibraryInfo::TranslationsPath))))
   363             qWarning("Failed to install Qt translation (%s)", qPrintable(cc));
   385             qWarning("Failed to install Qt translation (%s)", qPrintable(cc));
   364         app.installTranslator(&TranslatorHedgewars);
   386         app.installTranslator(&TranslatorHedgewars);
   365         app.installTranslator(&TranslatorQt);
   387         app.installTranslator(&TranslatorQt);
   366         app.setLayoutDirection(QLocale(cc).textDirection());
   388         app.setLayoutDirection(QLocale(cc).textDirection());
   367     }
   389     }