1 /* 2 * Replacement fot QT Bindings that were removed from QT5 3 * Copyright (C) 2020 Pedro de Carvalho Gomes <pedrogomes81@gmail.com> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef CORELOCALE_H 20 #define CORELOCALE_H 21 22 #include "QtBinding.h" 23 24 #include <QObject> 25 #include <QLocale> 26 27 class QJSEngine; 28 29 namespace QtBindings 30 { 31 namespace Core 32 { 33 class Locale : public QObject, public QLocale, public QtBindings::Base<Locale> 34 { 35 Q_OBJECT 36 public: 37 Q_INVOKABLE Locale(); 38 Q_INVOKABLE Locale(const QString &name); 39 Q_INVOKABLE Locale(Language language, Country country = AnyCountry); 40 Q_INVOKABLE Locale(Language language, Script script, Country country); 41 Q_INVOKABLE Locale(const QLocale &other); 42 Q_INVOKABLE Locale(const Locale &other); 43 Q_INVOKABLE static QLocale c(); 44 Q_INVOKABLE static QString countryToString(Country country); 45 Q_INVOKABLE static QString languageToString(Language language); 46 Q_INVOKABLE static QString scriptToString(Script script); 47 Q_INVOKABLE static void setDefault(const QLocale &locale); 48 Q_INVOKABLE static Locale system(); 49 Locale &operator=(const Locale& other); 50 public slots: 51 QString amText() const; 52 QString bcp47Name() const; 53 Country country() const; 54 QString createSeparatedList(const QStringList &strl) const; 55 QString currencySymbol(CurrencySymbolFormat format = CurrencySymbol) const; 56 QString dateFormat(FormatType format = LongFormat) const; 57 QString dateTimeFormat(FormatType format = LongFormat) const; 58 QString dayName(int day, FormatType format = LongFormat) const; 59 QChar decimalPoint() const; 60 QChar exponential() const; 61 Qt::DayOfWeek firstDayOfWeek() const; 62 QChar groupSeparator() const; 63 Language language() const; 64 MeasurementSystem measurementSystem() const; 65 QString monthName(int month, FormatType format = LongFormat) const; 66 QString name() const; 67 QString nativeCountryName() const; 68 QString nativeLanguageName() const; 69 QChar negativeSign() const; 70 NumberOptions numberOptions() const; 71 QChar percent() const; 72 QString pmText() const; 73 QChar positiveSign() const; 74 QString quoteString(const QStringRef &str, QuotationStyle style = StandardQuotation) const; 75 QString quoteString(const QString &str, QuotationStyle style = StandardQuotation) const; 76 Script script() const; 77 void setNumberOptions(NumberOptions options); 78 QString standaloneDayName(int day, FormatType format = LongFormat) const; 79 QString standaloneMonthName(int month, FormatType format = LongFormat) const; 80 void swap(QLocale &other); 81 Qt::LayoutDirection textDirection() const; 82 QString timeFormat(FormatType format = LongFormat) const; 83 QString toCurrencyString(double value, const QString &symbol, int precision) const; 84 QString toCurrencyString(double value, const QString &symbol = QString()) const; 85 QString toCurrencyString(float i, const QString &symbol, int precision) const; 86 QString toCurrencyString(float i, const QString &symbol = QString()) const; 87 QString toCurrencyString(int value, const QString &symbol = QString()) const; 88 QString toCurrencyString(qlonglong value, const QString &symbol = QString()) const; 89 QString toCurrencyString(qulonglong value, const QString &symbol = QString()) const; 90 QString toCurrencyString(short value, const QString &symbol = QString()) const; 91 QString toCurrencyString(uint value, const QString &symbol = QString()) const; 92 QString toCurrencyString(ushort value, const QString &symbol = QString()) const; 93 QDate toDate(const QString &string, const QString &format) const; 94 QDate toDate(const QString &string, FormatType format = LongFormat) const; 95 QDateTime toDateTime(const QString &string, const QString &format) const; 96 QDateTime toDateTime(const QString &string, FormatType format = LongFormat) const; 97 double toDouble(const QStringRef &s, bool *ok = Q_NULLPTR) const; 98 double toDouble(const QString &s, bool *ok = Q_NULLPTR) const; 99 float toFloat(const QStringRef &s, bool *ok = Q_NULLPTR) const; 100 float toFloat(const QString &s, bool *ok = Q_NULLPTR) const; 101 int toInt(const QStringRef &s, bool *ok = Q_NULLPTR) const; 102 int toInt(const QString &s, bool *ok = Q_NULLPTR) const; 103 qlonglong toLongLong(const QStringRef &s, bool *ok = Q_NULLPTR) const; 104 qlonglong toLongLong(const QString &s, bool *ok = Q_NULLPTR) const; 105 QString toLower(const QString &str) const; 106 short toShort(const QStringRef &s, bool *ok = Q_NULLPTR) const; 107 short toShort(const QString &s, bool *ok = Q_NULLPTR) const; 108 QString toString(const QDate &date, const QString &formatStr) const; 109 QString toString(const QDate &date, FormatType format = LongFormat) const; 110 QString toString(const QDateTime &dateTime, const QString &format) const; 111 QString toString(const QDateTime &dateTime, FormatType format = LongFormat) const; 112 QString toString(const QTime &time, const QString &formatStr) const; 113 QString toString(const QTime &time, FormatType format = LongFormat) const; 114 QString toString(double i, char f = 'g', int prec = 6) const; 115 QString toString(float i, char f = 'g', int prec = 6) const; 116 QString toString(int i) const; 117 QString toString(qlonglong i) const; 118 QString toString(qulonglong i) const; 119 QString toString(short i) const; 120 QString toString(uint i) const; 121 QString toString(ushort i) const; 122 QTime toTime(const QString &string, const QString &format) const; 123 QTime toTime(const QString &string, FormatType format = LongFormat) const; 124 uint toUInt(const QStringRef &s, bool *ok = Q_NULLPTR) const; 125 uint toUInt(const QString &s, bool *ok = Q_NULLPTR) const; 126 qulonglong toULongLong(const QStringRef &s, bool *ok = Q_NULLPTR) const; 127 qulonglong toULongLong(const QString &s, bool *ok = Q_NULLPTR) const; 128 QString toUpper(const QString &str) const; 129 ushort toUShort(const QStringRef &s, bool *ok = Q_NULLPTR) const; 130 ushort toUShort(const QString &s, bool *ok = Q_NULLPTR) const; 131 QStringList uiLanguages() const; 132 QList<Qt::DayOfWeek> weekdays() const; 133 QChar zeroDigit() const; 134 QList<Country> countriesForLanguage(Language lang); 135 QList<QLocale> matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Country country); 136 }; 137 } 138 } 139 Q_DECLARE_METATYPE(QtBindings::Core::Locale) 140 #endif //CORELOCALE_H 141