src/gui/styles/qstylehelper_p.h
changeset 30 5dc02b23752f
parent 18 2f34d5167611
--- a/src/gui/styles/qstylehelper_p.h	Wed Jun 23 19:07:03 2010 +0300
+++ b/src/gui/styles/qstylehelper_p.h	Tue Jul 06 15:10:48 2010 +0300
@@ -41,7 +41,9 @@
 
 #include <QtCore/qglobal.h>
 #include <QtCore/qpoint.h>
+#include <QtCore/qstring.h>
 #include <QtGui/qpolygon.h>
+#include <QtCore/qstringbuilder.h>
 
 #ifndef QSTYLEHELPER_P_H
 #define QSTYLEHELPER_P_H
@@ -79,6 +81,37 @@
                      int bottom = 0);
 }
 
+// internal helper. Converts an integer value to an unique string token
+template <typename T>
+        struct HexString
+{
+    inline HexString(const T t)
+        : val(t)
+    {}
+
+    inline void write(QChar *&dest) const
+    {
+        const ushort hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+        const char *c = reinterpret_cast<const char *>(&val);
+        for (uint i = 0; i < sizeof(T); ++i) {
+            *dest++ = hexChars[*c & 0xf];
+            *dest++ = hexChars[(*c & 0xf0) >> 4];
+            ++c;
+        }
+    }
+    const T val;
+};
+
+// specialization to enable fast concatenating of our string tokens to a string
+template <typename T>
+        struct QConcatenable<HexString<T> >
+{
+    typedef HexString<T> type;
+    enum { ExactSize = true };
+    static int size(const HexString<T> &str) { return sizeof(str.val) * 2; }
+    static inline void appendTo(const HexString<T> &str, QChar *&out) { str.write(out); }
+};
+
 QT_END_NAMESPACE
 
 #endif // QSTYLEHELPER_P_H