File make-kmail-faster.patch of Package kdepim4

From: idoenmez@suse.com
Subject: ?
Index: kdepim-4.7.2/messagelist/core/themedelegate.cpp
===================================================================
--- kdepim-4.7.2.orig/messagelist/core/themedelegate.cpp
+++ kdepim-4.7.2/messagelist/core/themedelegate.cpp
@@ -51,8 +51,11 @@ ThemeDelegate::ThemeDelegate( QAbstractI
 {
   mItemView = parent;
   mTheme = 0;
+  connect( KGlobalSettings::self(), SIGNAL( kdisplayFontChanged() ), this,  SLOT( slotGeneralFontChanged() ) );
 }
 
+QString ThemeDelegate::mGeneralFontKey = KGlobalSettings::generalFont().key();
+
 ThemeDelegate::~ThemeDelegate()
 {
 }
@@ -87,6 +90,7 @@ void ThemeDelegate::setTheme( const Them
     break;
   }
   mItemView->reset();
+
 }
 
 // FIXME: gcc will refuse to inline these functions loudly complaining
@@ -118,6 +122,18 @@ static int cachedFontHeight( const QFont
   return fontHeightCache[ fontKey ];
 }
 
+static int cachedFontHeightKey( const QFont &font, const QString &fontKey )
+{
+  static QHash<QString, int> fontHeightCache;
+
+  if ( !fontHeightCache.contains( fontKey ) ) {
+    fontHeightCache.insert( fontKey, cachedFontMetrics( font ).height() );
+  }
+
+  return fontHeightCache[ fontKey ];
+}
+
+
 static inline void paint_right_aligned_elided_text( const QString &text, Theme::ContentItem * ci, QPainter * painter, int &left, int top, int &right, Qt::LayoutDirection layoutDir, const QFont &font )
 {
   painter->setFont( font );
@@ -501,7 +517,8 @@ static inline void compute_size_hint_for
   if ( ci->displaysText() )
   {
     const QFont font = ThemeDelegate::itemFont( ci, item );
-    const int fontHeight = cachedFontHeight( font );
+    const QString fontKey = ThemeDelegate::itemFontKey( ci, item );
+    const int fontHeight = cachedFontHeightKey( font, fontKey );
     if ( fontHeight > maxh )
       maxh = fontHeight;
     totalw += ci->displaysLongText() ? 128 : 64;
@@ -1670,3 +1687,20 @@ QFont ThemeDelegate::itemFont( const The
   return KGlobalSettings::generalFont();
 }
 
+QString ThemeDelegate::itemFontKey( const Theme::ContentItem *ci, const Item *item )
+{
+  if ( ci && ci->useCustomFont() )
+    return ci->fontKey();
+
+  if ( item && ( item->type() == Item::Message ) )
+    return static_cast< const MessageItem * >( item )->fontKey();
+
+  return mGeneralFontKey;
+}
+
+// Store the new fontKey when the generalFont changes.
+void ThemeDelegate::slotGeneralFontChanged()
+{
+  ThemeDelegate::mGeneralFontKey = KGlobalSettings::generalFont().key();
+}
+
Index: kdepim-4.7.2/messagelist/core/themedelegate.h
===================================================================
--- kdepim-4.7.2.orig/messagelist/core/themedelegate.h
+++ kdepim-4.7.2/messagelist/core/themedelegate.h
@@ -44,6 +44,8 @@ class Item;
  */
 class ThemeDelegate : public QStyledItemDelegate
 {
+  Q_OBJECT
+
 public:
   ThemeDelegate( QAbstractItemView * parent );
   ~ThemeDelegate();
@@ -51,6 +53,7 @@ public:
 private:
   const Theme * mTheme; ///< Shallow pointer to the current theme
   QAbstractItemView * mItemView;
+  static QString mGeneralFontKey;
 
   QColor mGroupHeaderBackgroundColor; // cache
 
@@ -194,6 +197,9 @@ public:
   /// return the font to paint given item with, checking global kmail settings and theme settings
   static QFont itemFont( const Theme::ContentItem *ci, const Item *item );
 
+  /// return the font key to paint given item with, checking global kmail settings and theme settings
+  static QString itemFontKey( const Theme::ContentItem *ci, const Item *item );
+
 protected:
   /**
    * Returns the Item for the specified model index. Pure virtual: must be reimplemented
@@ -211,6 +217,11 @@ protected:
    */
   QSize sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
 
+private slots:
+  /**
+   * Called when the global fonts change (from systemsettings)
+   */
+  void slotGeneralFontChanged();
 };
 
 } // namespace Core
Index: kdepim-4.7.2/messagelist/core/theme.cpp
===================================================================
--- kdepim-4.7.2.orig/messagelist/core/theme.cpp
+++ kdepim-4.7.2/messagelist/core/theme.cpp
@@ -167,6 +167,7 @@ bool Theme::ContentItem::applicableToGro
 void Theme::ContentItem::setFont( const QFont &font )
 {
   mFont = font;
+  mFontKey = font.key();
 }
 
 void Theme::ContentItem::save( QDataStream &stream ) const
Index: kdepim-4.7.2/messagelist/core/theme.h
===================================================================
--- kdepim-4.7.2.orig/messagelist/core/theme.h
+++ kdepim-4.7.2/messagelist/core/theme.h
@@ -242,6 +242,7 @@ public:
      unsigned int mFlags;             ///< The flags of the item
 
      QFont mFont;                     ///< The font to use with this content item, meaningful only if displaysText() returns true.
+     QString mFontKey;                ///< The font key to speedup theme positioning. QFont.key() is called too many times otherwise.
      QColor mCustomColor;             ///< The color to use with this content item, meaningful only if canUseCustomColor() return true.
 
   public:
@@ -420,6 +421,16 @@ public:
       { return mFont; };
 
     /**
+     * Returns the font key used by this item. It may be a custom font key set by setFont()
+     * or the default application font (returned by KGlobalSettings::generalFont()).
+     * This setting is valid as long as you have called updateFontMetrics()
+     * with the appropriate paint device.
+     * It is primary used to avoid to calculate the key every time an item is displayed.
+     */
+    const QString & fontKey() const
+      { return mFontKey; };
+
+    /**
      * Returns the custom color set for this item.
      * The return value is meaningful only if canUseCustomColor() returns true
      * returns true and setUseCustomColor( true ) has been called.
Index: kdepim-4.7.2/messagelist/core/messageitem_p.h
===================================================================
--- kdepim-4.7.2.orig/messagelist/core/messageitem_p.h
+++ kdepim-4.7.2/messagelist/core/messageitem_p.h
@@ -80,6 +80,11 @@ public:
   static QFont mFontUnreadMessage;
   static QFont mFontImportantMessage;
   static QFont mFontToDoMessage;
+  static QString mFontKey;
+  static QString mFontNewMessageKey;
+  static QString mFontUnreadMessageKey;
+  static QString mFontImportantMessageKey;
+  static QString mFontToDoMessageKey;
 
 private:
 
Index: kdepim-4.7.2/messagelist/core/messageitem.h
===================================================================
--- kdepim-4.7.2.orig/messagelist/core/messageitem.h
+++ kdepim-4.7.2/messagelist/core/messageitem.h
@@ -134,6 +134,8 @@ public:
 
   QFont font() const;
 
+  QString fontKey() const;
+
   SignatureState signatureState() const;
 
   void setSignatureState( SignatureState state );
Index: kdepim-4.7.2/messagelist/core/messageitem.cpp
===================================================================
--- kdepim-4.7.2.orig/messagelist/core/messageitem.cpp
+++ kdepim-4.7.2/messagelist/core/messageitem.cpp
@@ -44,6 +44,7 @@ public:
   QColor mTextColor;
   QColor mBackgroundColor;
   QFont  mFont;
+  QString  mFontKey;
   int    mPriority;
 };
 
@@ -123,6 +124,11 @@ QFont MessageItemPrivate::mFont;
 QFont MessageItemPrivate::mFontUnreadMessage;
 QFont MessageItemPrivate::mFontImportantMessage;
 QFont MessageItemPrivate::mFontToDoMessage;
+QString MessageItemPrivate::mFontKey;
+QString MessageItemPrivate::mFontNewMessageKey;
+QString MessageItemPrivate::mFontUnreadMessageKey;
+QString MessageItemPrivate::mFontImportantMessageKey;
+QString MessageItemPrivate::mFontToDoMessageKey;
 
 MessageItemPrivate::MessageItemPrivate( MessageItem* qq )
   : ItemPrivate( qq ),
@@ -403,6 +409,35 @@ QFont MessageItem::font() const
   return font;
 }
 
+QString MessageItem::fontKey() const
+{
+  Q_D( const MessageItem );
+
+  // for performance reasons we don't want font retrieval to trigger
+  // full tags loading, as the font is used for geometry calculation
+  // and thus this method called for each item
+  if ( d->tagListInitialized() ) {
+    const Tag *bestTag = d->bestTag();
+    if ( bestTag != 0 && bestTag->font() != QFont() ) {
+      return bestTag->font().key();
+    }
+  }
+
+  // from KDE3: "important" overrides "new" overrides "unread" overrides "todo"
+  Akonadi::MessageStatus messageStatus = status();
+  if ( messageStatus.isImportant() ) {
+    return d->mFontImportantMessageKey;
+  } else if ( !messageStatus.isRead() ) {
+    return d->mFontUnreadMessageKey;
+  } else if ( messageStatus.isToAct() ) {
+    return d->mFontToDoMessageKey;
+  } else {
+    return d->mFontKey;
+  }
+
+}
+
+
 MessageItem::SignatureState MessageItem::signatureState() const
 {
   Q_D( const MessageItem );
@@ -572,21 +607,25 @@ void MessageItem::setToDoMessageColor( c
 void MessageItem::setGeneralFont( const QFont &font )
 {
   MessageItemPrivate::mFont = font;
+  MessageItemPrivate::mFontKey = font.key();
 }
 
 void MessageItem::setUnreadMessageFont( const QFont &font )
 {
   MessageItemPrivate::mFontUnreadMessage = font;
+  MessageItemPrivate::mFontUnreadMessageKey = font.key();
 }
 
 void MessageItem::setImportantMessageFont( const QFont &font )
 {
   MessageItemPrivate::mFontImportantMessage = font;
+  MessageItemPrivate::mFontImportantMessageKey = font.key();
 }
 
 void MessageItem::setToDoMessageFont( const QFont &font )
 {
   MessageItemPrivate::mFontToDoMessage = font;
+  MessageItemPrivate::mFontToDoMessageKey = font.key();
 }
 
 FakeItemPrivate::FakeItemPrivate( FakeItem *qq ) : MessageItemPrivate( qq )
openSUSE Build Service is sponsored by