-QTextCharFormat UiStyle::mergedFormat(quint32 ftype) {
- if(_cachedFormats.contains(ftype)) return _cachedFormats.value(ftype);
- if(ftype == Invalid) return QTextCharFormat();
- // Now we construct the merged format, starting with the default
- QTextCharFormat fmt = format(None);
- // First: general message format
- fmt.merge(format((FormatType)(ftype & 0x0f)));
- // now more specific ones
- for(quint32 mask = 0x0010; mask <= 0x2000; mask <<= 1) {
- if(ftype & mask) fmt.merge(format((FormatType)mask));
+QTextCharFormat UiStyle::format(quint32 ftype, quint32 label_) {
+ if(ftype == Invalid)
+ return QTextCharFormat();
+
+ quint64 label = (quint64)label_ << 32;
+
+ // check if we have exactly this format readily cached already
+ QTextCharFormat fmt = cachedFormat(label|ftype);
+ if(fmt.properties().count())
+ return fmt;
+
+ mergeFormat(fmt, ftype, label & Q_UINT64_C(0xffff000000000000));
+
+ for(quint64 mask = Q_UINT64_C(0x0000000100000000); mask <= (quint64)Selected << 32; mask <<=1) {
+ if(label & mask)
+ mergeFormat(fmt, ftype, mask | Q_UINT64_C(0xffff000000000000));
+ }
+
+ setCachedFormat(fmt, ftype, label_);
+ return fmt;
+}
+
+void UiStyle::mergeFormat(QTextCharFormat &fmt, quint32 ftype, quint64 label) {
+ mergeSubElementFormat(fmt, ftype & 0x000f, label);
+
+ // TODO: allow combinations for mirc formats and colors (each), e.g. setting a special format for "bold and italic"
+ // or "foreground 01 and background 03"
+ if((ftype & 0xfff0)) { // element format
+ for(quint32 mask = 0x0010; mask <= 0x2000; mask <<= 1) {
+ if(ftype & mask) {
+ mergeSubElementFormat(fmt, mask | 0x0f, label);
+ }
+ }