added language setting, version variable etc.

master
Qiaoyong Zhong 11 years ago
parent 0b0690d162
commit 194054e6fd

@ -31,4 +31,7 @@ HEADERS += \
TRANSLATIONS = ts/2048-qt_zh_CN.ts TRANSLATIONS = ts/2048-qt_zh_CN.ts
VERSION = 0.1.0 VERSION = 0.1.1
VERSTR = '\\"$${VERSION}\\"'
DEFINES += VER=\"$${VERSTR}\"

@ -13,7 +13,7 @@ A clone of [2048](https://github.com/gabrielecirulli/2048), implemented in Qt.
- PRC (天朝) - PRC (天朝)
- Multi-language support, currently - Multi-language support, currently
- English - English
- Chinese - Simplified Chinese
## Screenshots ## Screenshots
@ -25,13 +25,15 @@ A clone of [2048](https://github.com/gabrielecirulli/2048), implemented in Qt.
## Downloads ## Downloads
Check https://github.com/xiaoyong/2048-Qt/releases for compiled binary executable files.
### Windows ### 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 ### 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 ## Todo

Binary file not shown.

@ -9,9 +9,11 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
Settings settings(0, "xiaoyong", "2048-Qt");
settings.setVersion(QString(VER));
// Localization // Localization
QString locale = QLocale::system().name(); QString locale = settings.value("language", QLocale::system().name()).toString();
QString tsFile = "2048-qt_" + locale; QString tsFile = "2048-qt_" + locale;
QTranslator translator; QTranslator translator;
@ -29,7 +31,6 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("myClass", &myClass); engine.rootContext()->setContextProperty("myClass", &myClass);
// Access C++ object "settings" from QML as "settings" // Access C++ object "settings" from QML as "settings"
Settings settings(0, "xiaoyong", "2048-Qt");
engine.rootContext()->setContextProperty("settings", &settings); engine.rootContext()->setContextProperty("settings", &settings);
engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));

@ -17,6 +17,8 @@ ApplicationWindow {
y: (Screen.height - height) / 2 y: (Screen.height - height) / 2
ExclusiveGroup { id: labelSettingsGroup } ExclusiveGroup { id: labelSettingsGroup }
ExclusiveGroup { id: languageSettingsGroup }
menuBar: MenuBar { menuBar: MenuBar {
Menu { Menu {
title: qsTr("File") title: qsTr("File")
@ -34,6 +36,8 @@ ApplicationWindow {
Menu { Menu {
title: qsTr("Settings") title: qsTr("Settings")
Menu {
title: qsTr("Labeling")
MenuItem { MenuItem {
text: qsTr("2048") text: qsTr("2048")
checkable: true checkable: true
@ -83,6 +87,34 @@ ApplicationWindow {
} }
} }
} }
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();
}
}
}
}
}
Menu { Menu {
id: helpMenu id: helpMenu
@ -152,7 +184,7 @@ ApplicationWindow {
Text { Text {
text: (index == 0) ? qsTr("SCORE") : qsTr("BEST") text: (index == 0) ? qsTr("SCORE") : qsTr("BEST")
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
y: 7 y: 6
font.family: localFont.name font.family: localFont.name
font.pixelSize: 13 font.pixelSize: 13
color: helper.myColors.fglight color: helper.myColors.fglight
@ -160,7 +192,7 @@ ApplicationWindow {
Text { Text {
text: scoreText text: scoreText
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
y: 25 y: 22
font.family: localFont.name font.family: localFont.name
font.pixelSize: 25 font.pixelSize: 25
font.bold: true 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 { MessageDialog {
id: aboutDialog id: aboutDialog
title: qsTr("About 2048-Qt") title: qsTr("About 2048-Qt")
text: qsTr("<p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version 0.1</p><p>2014 Qiaoyong Zhong</p>") text: qsTr("<p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version " + settings.getVersion() + "</p><p>2014 Qiaoyong Zhong &lt;solary.sh@gmail.com&gt;</p>")
standardButtons: StandardButton.Ok standardButtons: StandardButton.Ok
} }

@ -15,3 +15,11 @@ void Settings::setValue(const QString &key, const QVariant &value) {
QVariant Settings::value(const QString &key, const QVariant &defaultValue) const { QVariant Settings::value(const QString &key, const QVariant &defaultValue) const {
return settings_->value(key, defaultValue); return settings_->value(key, defaultValue);
} }
void Settings::setVersion(QString version) {
appVersion = version;
}
QString Settings::getVersion() {
return appVersion;
}

@ -13,6 +13,9 @@ public:
Q_INVOKABLE void setValue(const QString &key, const QVariant &value); Q_INVOKABLE void setValue(const QString &key, const QVariant &value);
Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
Q_INVOKABLE QString getVersion();
void setVersion(const QString version);
signals: signals:
@ -20,7 +23,7 @@ public slots:
private: private:
QSettings *settings_; QSettings *settings_;
QString appVersion;
}; };
#endif // SETTINGS_H #endif // SETTINGS_H

Binary file not shown.

@ -9,103 +9,128 @@
<translation>2048</translation> <translation>2048</translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="22"/> <location filename="../qml/main.qml" line="24"/>
<source>File</source> <source>File</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="24"/> <location filename="../qml/main.qml" line="26"/>
<location filename="../qml/main.qml" line="230"/> <location filename="../qml/main.qml" line="264"/>
<source>New Game</source> <source>New Game</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="29"/> <location filename="../qml/main.qml" line="31"/>
<source>Exit</source> <source>Exit</source>
<translation>退</translation> <translation>退</translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="36"/> <location filename="../qml/main.qml" line="38"/>
<source>Settings</source> <source>Settings</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="38"/> <location filename="../qml/main.qml" line="40"/>
<source>Labeling</source>
<translation></translation>
</message>
<message>
<location filename="../qml/main.qml" line="42"/>
<source>2048</source> <source>2048</source>
<translation>2048</translation> <translation>2048</translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="50"/> <location filename="../qml/main.qml" line="54"/>
<source>Degree</source> <source>Degree</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="62"/> <location filename="../qml/main.qml" line="66"/>
<source>Military Rank</source> <source>Military Rank</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="74"/> <location filename="../qml/main.qml" line="78"/>
<source>PRC</source> <source>PRC</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="89"/> <location filename="../qml/main.qml" line="91"/>
<source>Language</source>
<translation></translation>
</message>
<message>
<location filename="../qml/main.qml" line="93"/>
<source>English</source>
<translation></translation>
</message>
<message>
<location filename="../qml/main.qml" line="105"/>
<source>Simplified Chinese</source>
<translation></translation>
</message>
<message>
<location filename="../qml/main.qml" line="121"/>
<source>Help</source> <source>Help</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="91"/> <location filename="../qml/main.qml" line="123"/>
<source>About</source> <source>About</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="95"/> <location filename="../qml/main.qml" line="127"/>
<source>About Qt</source> <source>About Qt</source>
<translation>Qt</translation> <translation>Qt</translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="151"/> <location filename="../qml/main.qml" line="185"/>
<source>SCORE</source> <source>SCORE</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="151"/> <location filename="../qml/main.qml" line="185"/>
<source>BEST</source> <source>BEST</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="211"/> <location filename="../qml/main.qml" line="245"/>
<source>Join the numbers and get to the &lt;b&gt;2048 tile&lt;/b&gt;!</source> <source>Join the numbers and get to the &lt;b&gt;2048 tile&lt;/b&gt;!</source>
<translation>&lt;b&gt;2048&lt;/b&gt;</translation> <translation>&lt;b&gt;2048&lt;/b&gt;</translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="268"/> <location filename="../qml/main.qml" line="302"/>
<source>About 2048-Qt</source> <source>Language Setting Hint</source>
<translation>2048-Qt</translation> <translation></translation>
</message>
<message>
<location filename="../qml/main.qml" line="303"/>
<source>Please restart the program to make the language setting take effect.</source>
<translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="269"/> <location filename="../qml/main.qml" line="309"/>
<source>&lt;p style=&apos;font-weight: bold; font-size: 24px&apos;&gt;2048-Qt&lt;/p&gt;&lt;p&gt;Version 0.1&lt;/p&gt;&lt;p&gt;2014 Qiaoyong Zhong&lt;/p&gt;</source> <source>About 2048-Qt</source>
<translation type="unfinished"></translation> <translation>2048-Qt</translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="275"/> <location filename="../qml/main.qml" line="316"/>
<source>Game Over</source> <source>Game Over</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="276"/> <location filename="../qml/main.qml" line="317"/>
<source>Game Over!</source> <source>Game Over!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="286"/> <location filename="../qml/main.qml" line="327"/>
<source>You Win</source> <source>You Win</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/main.qml" line="287"/> <location filename="../qml/main.qml" line="328"/>
<source>You win! Continue playing?</source> <source>You win! Continue playing?</source>
<translation></translation> <translation></translation>
</message> </message>

Loading…
Cancel
Save