diff --git a/2048-qt.pro b/2048-qt.pro index 5c7ec04..49bee4d 100644 --- a/2048-qt.pro +++ b/2048-qt.pro @@ -31,4 +31,7 @@ HEADERS += \ TRANSLATIONS = ts/2048-qt_zh_CN.ts -VERSION = 0.1.0 +VERSION = 0.1.1 + +VERSTR = '\\"$${VERSION}\\"' +DEFINES += VER=\"$${VERSTR}\" diff --git a/README.md b/README.md index b46a2c6..c4ac6da 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A clone of [2048](https://github.com/gabrielecirulli/2048), implemented in Qt. - PRC (天朝) - Multi-language support, currently - English - - Chinese + - Simplified Chinese ## Screenshots @@ -25,13 +25,15 @@ A clone of [2048](https://github.com/gabrielecirulli/2048), implemented in Qt. ## Downloads +Check https://github.com/xiaoyong/2048-Qt/releases for compiled binary executable files. + ### Windows -Check https://github.com/xiaoyong/2048-Qt/releases for compiled binary files. All required Qt libraries have been packed into one .exe file. +All required Qt libraries have been packed into one .exe file. So it should work out of the box. ### Linux -The [bin/](https://github.com/xiaoyong/2048-Qt/tree/master/bin) directory contains the compiled binary file for 64-bit Linux. To run it, the Qt libraries (version >= 5.2.1) are required and should be installed on you system. +The Qt libraries (version >= 5.2.1) are required. Make sure that they are installed on you system. ## Todo diff --git a/bin/2048-qt-linux-x86_64 b/bin/2048-qt-linux-x86_64 deleted file mode 100755 index ebd74ad..0000000 Binary files a/bin/2048-qt-linux-x86_64 and /dev/null differ diff --git a/fonts/DroidSansFallback.ttf b/fonts/DroidSansFallback.ttf old mode 100755 new mode 100644 diff --git a/main.cpp b/main.cpp index 02e100b..985bf46 100644 --- a/main.cpp +++ b/main.cpp @@ -9,9 +9,11 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + Settings settings(0, "xiaoyong", "2048-Qt"); + settings.setVersion(QString(VER)); // Localization - QString locale = QLocale::system().name(); + QString locale = settings.value("language", QLocale::system().name()).toString(); QString tsFile = "2048-qt_" + locale; QTranslator translator; @@ -29,7 +31,6 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("myClass", &myClass); // Access C++ object "settings" from QML as "settings" - Settings settings(0, "xiaoyong", "2048-Qt"); engine.rootContext()->setContextProperty("settings", &settings); engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml"))); diff --git a/qml/main.qml b/qml/main.qml index bbddac4..03c97b8 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -16,7 +16,9 @@ ApplicationWindow { x: (Screen.width - width) / 2 y: (Screen.height - height) / 2 - ExclusiveGroup { id: labelSettingsGroup } + ExclusiveGroup { id: labelSettingsGroup } + ExclusiveGroup { id: languageSettingsGroup } + menuBar: MenuBar { Menu { title: qsTr("File") @@ -34,51 +36,81 @@ ApplicationWindow { Menu { title: qsTr("Settings") - MenuItem { - text: qsTr("2048") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[0] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[0]) { - MyScript.label = MyScript.labelOptions[0]; - MyScript.startupFunction(); + Menu { + title: qsTr("Labeling") + MenuItem { + text: qsTr("2048") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[0] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[0]) { + MyScript.label = MyScript.labelOptions[0]; + MyScript.startupFunction(); + } } } - } - MenuItem { - text: qsTr("Degree") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[1] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[1]) { - MyScript.label = MyScript.labelOptions[1]; - MyScript.startupFunction(); + MenuItem { + text: qsTr("Degree") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[1] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[1]) { + MyScript.label = MyScript.labelOptions[1]; + MyScript.startupFunction(); + } } } - } - MenuItem { - text: qsTr("Military Rank") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[2] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[2]) { - MyScript.label = MyScript.labelOptions[2]; - MyScript.startupFunction(); + MenuItem { + text: qsTr("Military Rank") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[2] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[2]) { + MyScript.label = MyScript.labelOptions[2]; + MyScript.startupFunction(); + } + } + } + MenuItem { + text: qsTr("PRC") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[3] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[3]) { + MyScript.label = MyScript.labelOptions[3]; + MyScript.startupFunction(); + } } } } - MenuItem { - text: qsTr("PRC") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[3] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[3]) { - MyScript.label = MyScript.labelOptions[3]; - MyScript.startupFunction(); + Menu { + title: qsTr("Language") + MenuItem { + text: qsTr("English") + checkable: true + exclusiveGroup: languageSettingsGroup + checked: settings.value("language", "en_US") === "en_US" ? true : false + onTriggered: { + if (settings.value("language", "en_US") !== "en_US") { + settings.setValue("language", "en_US"); + changeLanguageDialog.open(); + } + } + } + MenuItem { + text: qsTr("Simplified Chinese") + checkable: true + exclusiveGroup: languageSettingsGroup + checked: settings.value("language", "en_US") === "zh_CN" ? true : false + onTriggered: { + if (settings.value("language", "en_US") !== "zh_CN") { + settings.setValue("language", "zh_CN"); + changeLanguageDialog.open(); + } } } } @@ -152,7 +184,7 @@ ApplicationWindow { Text { text: (index == 0) ? qsTr("SCORE") : qsTr("BEST") anchors.horizontalCenter: parent.horizontalCenter - y: 7 + y: 6 font.family: localFont.name font.pixelSize: 13 color: helper.myColors.fglight @@ -160,7 +192,7 @@ ApplicationWindow { Text { text: scoreText anchors.horizontalCenter: parent.horizontalCenter - y: 25 + y: 22 font.family: localFont.name font.pixelSize: 25 font.bold: true @@ -265,10 +297,17 @@ ApplicationWindow { } } + MessageDialog { + id: changeLanguageDialog + title: qsTr("Language Setting Hint") + text: qsTr("Please restart the program to make the language setting take effect.") + standardButtons: StandardButton.Ok + } + MessageDialog { id: aboutDialog title: qsTr("About 2048-Qt") - text: qsTr("
2048-Qt
Version 0.1
2014 Qiaoyong Zhong
") + text: qsTr("2048-Qt
Version " + settings.getVersion() + "
2014 Qiaoyong Zhong <solary.sh@gmail.com>
") standardButtons: StandardButton.Ok } diff --git a/settings.cpp b/settings.cpp index 5af4579..5f4ba7b 100644 --- a/settings.cpp +++ b/settings.cpp @@ -15,3 +15,11 @@ void Settings::setValue(const QString &key, const QVariant &value) { QVariant Settings::value(const QString &key, const QVariant &defaultValue) const { return settings_->value(key, defaultValue); } + +void Settings::setVersion(QString version) { + appVersion = version; +} + +QString Settings::getVersion() { + return appVersion; +} diff --git a/settings.h b/settings.h index f39763c..57c5d2f 100644 --- a/settings.h +++ b/settings.h @@ -13,6 +13,9 @@ public: Q_INVOKABLE void setValue(const QString &key, const QVariant &value); Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; + Q_INVOKABLE QString getVersion(); + + void setVersion(const QString version); signals: @@ -20,7 +23,7 @@ public slots: private: QSettings *settings_; - + QString appVersion; }; #endif // SETTINGS_H diff --git a/ts/2048-qt_zh_CN.qm b/ts/2048-qt_zh_CN.qm index 13f2374..308189d 100644 Binary files a/ts/2048-qt_zh_CN.qm and b/ts/2048-qt_zh_CN.qm differ diff --git a/ts/2048-qt_zh_CN.ts b/ts/2048-qt_zh_CN.ts index 55eea72..3695eea 100644 --- a/ts/2048-qt_zh_CN.ts +++ b/ts/2048-qt_zh_CN.ts @@ -9,103 +9,128 @@