diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2009-07-13 15:26:38 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-07-13 15:26:38 (GMT) |
commit | 754d9c2f1d0dce16017b99f766c1fa3e47b0afde (patch) | |
tree | 03ed75727044ac4b5efc09517a5201cd9697c617 /src/gui/text/qtextlist.cpp | |
parent | 5ad7d11593ef18e2497053977fbbd0b734caf52a (diff) | |
parent | 9db4b800a2c8da5916a6d5da9e37a17d185cdc5e (diff) | |
download | Qt-754d9c2f1d0dce16017b99f766c1fa3e47b0afde.zip Qt-754d9c2f1d0dce16017b99f766c1fa3e47b0afde.tar.gz Qt-754d9c2f1d0dce16017b99f766c1fa3e47b0afde.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'src/gui/text/qtextlist.cpp')
-rw-r--r-- | src/gui/text/qtextlist.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/gui/text/qtextlist.cpp b/src/gui/text/qtextlist.cpp index addd7a5..02b1c63 100644 --- a/src/gui/text/qtextlist.cpp +++ b/src/gui/text/qtextlist.cpp @@ -212,6 +212,55 @@ QString QTextList::itemText(const QTextBlock &blockIt) const } } break; + case QTextListFormat::ListLowerRoman: + case QTextListFormat::ListUpperRoman: + { + if (item < 5000) { + QByteArray romanNumeral; + + // works for up to 4999 items + static const char romanSymbolsLower[] = "iiivixxxlxcccdcmmmm"; + static const char romanSymbolsUpper[] = "IIIVIXXXLXCCCDCMMMM"; + QByteArray romanSymbols; // wrap to have "mid" + if (style == QTextListFormat::ListLowerRoman) + romanSymbols = QByteArray::fromRawData(romanSymbolsLower, sizeof(romanSymbolsLower)); + else + romanSymbols = QByteArray::fromRawData(romanSymbolsUpper, sizeof(romanSymbolsUpper)); + + int c[] = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 }; + int n = item; + for (int i = 12; i >= 0; n %= c[i], i--) { + int q = n / c[i]; + if (q > 0) { + int startDigit = i + (i+3)/4; + int numDigits; + if (i % 4) { + // c[i] == 4|5|9|40|50|90|400|500|900 + if ((i-2) % 4) { + // c[i] == 4|9|40|90|400|900 => with substraction (IV, IX, XL, XC, ...) + numDigits = 2; + } + else { + // c[i] == 5|50|500 (V, L, D) + numDigits = 1; + } + } + else { + // c[i] == 1|10|100|1000 (I, II, III, X, XX, ...) + numDigits = q; + } + + romanNumeral.append(romanSymbols.mid(startDigit, numDigits)); + } + } + result = QString::fromLatin1(romanNumeral); + } + else { + result = QLatin1String("?"); + } + + } + break; default: Q_ASSERT(false); } |