Refactor utilities package.
This commit is contained in:
141
src/main.cpp
141
src/main.cpp
@@ -17,99 +17,98 @@
|
||||
#include "src/utilities/languageswitcher.h"
|
||||
QString loadFontFromFile(QString path)
|
||||
{
|
||||
static QString font;
|
||||
static bool loaded = false;
|
||||
if (!loaded)
|
||||
{
|
||||
loaded = true;
|
||||
int loadedFontID = QFontDatabase::addApplicationFont(path);
|
||||
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);
|
||||
if (!loadedFontFamilies.empty())
|
||||
font = loadedFontFamilies.at(0);
|
||||
}
|
||||
return font;
|
||||
static QString font;
|
||||
static bool loaded = false;
|
||||
if (!loaded)
|
||||
{
|
||||
loaded = true;
|
||||
int loadedFontID = QFontDatabase::addApplicationFont(path);
|
||||
QStringList loadedFontFamilies = QFontDatabase::applicationFontFamilies(loadedFontID);
|
||||
if (!loadedFontFamilies.empty())
|
||||
font = loadedFontFamilies.at(0);
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//QLocale::setDefault(QLocale::English);
|
||||
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
|
||||
//QLocale::setDefault(QLocale::English);
|
||||
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
|
||||
#ifdef CUTE_STYLE
|
||||
qputenv("QT_VIRTUALKEYBOARD_STYLE", QByteArray("retro"));
|
||||
qputenv("QT_VIRTUALKEYBOARD_STYLE", QByteArray("retro"));
|
||||
#endif // CUTE_STYLE
|
||||
|
||||
//qputenv("QT_LOGGING_RULES", QByteArray("qt.virtualkeyboard=true"));
|
||||
//qputenv("QT_LOGGING_RULES", QByteArray("qt.virtualkeyboard=true"));
|
||||
|
||||
|
||||
QApplication a(argc, argv);
|
||||
QString layouts_path = QString(QCoreApplication::applicationDirPath()).append("/layouts");
|
||||
qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", QByteArray(layouts_path.toStdString().c_str()));
|
||||
QApplication a(argc, argv);
|
||||
QString layouts_path = QString(QCoreApplication::applicationDirPath()).append("/layouts");
|
||||
qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", QByteArray(layouts_path.toStdString().c_str()));
|
||||
|
||||
QTextCodec* codec = QTextCodec::codecForName("utf8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
QTextCodec* codec = QTextCodec::codecForName("utf8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
|
||||
|
||||
//multi-language suppport
|
||||
QTranslator translator;
|
||||
LanguageSwitcher::Instance()->setTranslator(&translator);
|
||||
LanguageSwitcher::Instance()->setDefaultLanguage(JsonObject::Instance()->defaultLanguage());
|
||||
a.installTranslator(&translator);
|
||||
//multi-language suppport
|
||||
LanguageSwitcher::getInstance()->setDefaultLanguage(JsonObject::Instance()->defaultLanguage());
|
||||
a.installTranslator(LanguageSwitcher::getInstance()->getTranslator());
|
||||
|
||||
|
||||
//QString fontName = loadFontFromFile(":/fonts/MicrosoftYahei.ttf");
|
||||
QString fontName = loadFontFromFile(":/fonts/DroidSansFallback.ttf");
|
||||
QFont font(fontName);
|
||||
QApplication::setFont(font);
|
||||
//QString fontName = loadFontFromFile(":/fonts/MicrosoftYahei.ttf");
|
||||
QString fontName = loadFontFromFile(":/fonts/DroidSansFallback.ttf");
|
||||
QFont font(fontName);
|
||||
QApplication::setFont(font);
|
||||
|
||||
InputObject* obj = new InputObject();
|
||||
a.installEventFilter(obj);
|
||||
SQLHelper::Open();
|
||||
MainWindow w;
|
||||
UserOperationLog::Default()->init();
|
||||
InputObject* obj = new InputObject();
|
||||
a.installEventFilter(obj);
|
||||
SQLHelper::Open();
|
||||
MainWindow w;
|
||||
UserOperationLog::Default()->init();
|
||||
|
||||
//暂时为了调试关闭锁屏
|
||||
//Locker::Instance()->start();
|
||||
//QObject::connect(obj, SIGNAL(touchScreen()), Locker::Instance(), SLOT(refreshTimer()));
|
||||
QList<Qt::GestureType> gestures;
|
||||
gestures << Qt::SwipeGesture;
|
||||
gestures << Qt::PanGesture;
|
||||
w.grabGestures(gestures);
|
||||
//暂时为了调试关闭锁屏
|
||||
//Locker::Instance()->start();
|
||||
//QObject::connect(obj, SIGNAL(touchScreen()), Locker::Instance(), SLOT(refreshTimer()));
|
||||
QList<Qt::GestureType> gestures;
|
||||
gestures << Qt::SwipeGesture;
|
||||
gestures << Qt::PanGesture;
|
||||
w.grabGestures(gestures);
|
||||
|
||||
QStringList app_args = a.arguments();
|
||||
int ret = 0;
|
||||
QStringList app_args = a.arguments();
|
||||
int ret = 0;
|
||||
|
||||
if (app_args.contains("-d"))
|
||||
//if (true)
|
||||
{
|
||||
if (app_args.contains("-d"))
|
||||
//if (true)
|
||||
{
|
||||
|
||||
w.debugConsoleOn();
|
||||
w.showFullScreen();
|
||||
w.debugConsoleOn();
|
||||
w.showFullScreen();
|
||||
|
||||
qInstallMessageHandler(MainWindow::QMessageOutput);
|
||||
QThread thread;
|
||||
StdOutRedirector redir;
|
||||
redir.setOutputTF(w.getEdit());
|
||||
QTimer Timer;
|
||||
redir.moveToThread(&thread);
|
||||
QObject::connect(&Timer, SIGNAL(timeout()), &redir, SLOT(readOutsToTF()));
|
||||
fflush(stdout);
|
||||
Timer.start(1000);
|
||||
thread.start();
|
||||
qInstallMessageHandler(MainWindow::QMessageOutput);
|
||||
QThread thread;
|
||||
StdOutRedirector redir;
|
||||
redir.setOutputTF(w.getEdit());
|
||||
QTimer Timer;
|
||||
redir.moveToThread(&thread);
|
||||
QObject::connect(&Timer, SIGNAL(timeout()), &redir, SLOT(readOutsToTF()));
|
||||
fflush(stdout);
|
||||
Timer.start(1000);
|
||||
thread.start();
|
||||
|
||||
|
||||
DeviceManager::Default()->initDevice();
|
||||
w.requestLogin();
|
||||
DeviceManager::Default()->initDevice();
|
||||
w.requestLogin();
|
||||
|
||||
ret = a.exec();
|
||||
thread.terminate();
|
||||
ret = a.exec();
|
||||
thread.terminate();
|
||||
|
||||
}
|
||||
else {
|
||||
w.showFullScreen();
|
||||
DeviceManager::Default()->initDevice();
|
||||
w.requestLogin();
|
||||
ret = a.exec();
|
||||
}
|
||||
DeviceManager::Default()->close();
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
w.showFullScreen();
|
||||
DeviceManager::Default()->initDevice();
|
||||
w.requestLogin();
|
||||
ret = a.exec();
|
||||
}
|
||||
DeviceManager::Default()->close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user