Add UiStyle::toTextLayoutList(), since we need that functionality in several places
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 7 Jul 2008 19:08:24 +0000 (21:08 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 2 Aug 2008 13:17:09 +0000 (15:17 +0200)
src/uisupport/uistyle.cpp
src/uisupport/uistyle.h

index b0a2a3a..3b55d68 100644 (file)
@@ -40,7 +40,7 @@ UiStyle::UiStyle(const QString &settingsKey) : _settingsKey(settingsKey) {
   _defaultPlainFormat.font().setFixedPitch(true);
   _defaultPlainFormat.font().setStyleHint(QFont::TypeWriter);
   setFormat(None, _defaultPlainFormat, Settings::Default);
   _defaultPlainFormat.font().setFixedPitch(true);
   _defaultPlainFormat.font().setStyleHint(QFont::TypeWriter);
   setFormat(None, _defaultPlainFormat, Settings::Default);
-  
+
   // Load saved custom formats
   UiStyleSettings s(_settingsKey);
   foreach(FormatType type, s.availableFormats()) {
   // Load saved custom formats
   UiStyleSettings s(_settingsKey);
   foreach(FormatType type, s.availableFormats()) {
@@ -166,6 +166,20 @@ QString UiStyle::formatCode(FormatType ftype) const {
   return _formatCodes.key(ftype);
 }
 
   return _formatCodes.key(ftype);
 }
 
+QList<QTextLayout::FormatRange> UiStyle::toTextLayoutList(const FormatList &formatList, int textLength) {
+  QList<QTextLayout::FormatRange> formatRanges;
+  QTextLayout::FormatRange range;
+  int i = 0;
+  for(i = 0; i < formatList.count(); i++) {
+    range.format = mergedFormat(formatList.at(i).second);
+    range.start = formatList.at(i).first;
+    if(i > 0) formatRanges.last().length = range.start - formatRanges.last().start;
+    formatRanges.append(range);
+  }
+  if(i > 0) formatRanges.last().length = textLength - formatRanges.last().start;
+  return formatRanges;
+}
+
 // This method expects a well-formatted string, there is no error checking!
 // Since we create those ourselves, we should be pretty safe that nobody does something crappy here.
 UiStyle::StyledString UiStyle::styleString(const QString &s_) {
 // This method expects a well-formatted string, there is no error checking!
 // Since we create those ourselves, we should be pretty safe that nobody does something crappy here.
 UiStyle::StyledString UiStyle::styleString(const QString &s_) {
index cd6458e..8745d11 100644 (file)
@@ -141,6 +141,8 @@ class UiStyle {
 
     inline QFont defaultFont() const { return _defaultFont; }
 
 
     inline QFont defaultFont() const { return _defaultFont; }
 
+    QList<QTextLayout::FormatRange> toTextLayoutList(const FormatList &, int textLength);
+
   protected:
 
 
   protected: