From 521b230734d76184667461b7ab87e4e7b165d52c Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Sat, 10 Oct 2009 00:20:48 +0200 Subject: [PATCH] Performance optimization: Initialize fonts in constructor, not on every paint --- src/playlist/PrettyItemDelegate.cpp | 14 ++++++-------- src/playlist/PrettyItemDelegate.h | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/playlist/PrettyItemDelegate.cpp b/src/playlist/PrettyItemDelegate.cpp index 59843fe..2c6f21f 100644 --- a/src/playlist/PrettyItemDelegate.cpp +++ b/src/playlist/PrettyItemDelegate.cpp @@ -9,6 +9,12 @@ const qreal PrettyItemDelegate::THUMB_WIDTH = 120.0; const qreal PrettyItemDelegate::PADDING = 10.0; PrettyItemDelegate::PrettyItemDelegate( QObject* parent ) : QStyledItemDelegate( parent ) { + + boldFont.setBold(true); + smallerFont.setPointSize(smallerFont.pointSize()*.85); + smallerBoldFont.setBold(true); + smallerBoldFont.setPointSize(smallerBoldFont.pointSize()*.85); + createPlayIcon(); } @@ -60,14 +66,6 @@ void PrettyItemDelegate::paintBody( QPainter* painter, QPalette palette; - QFont boldFont; - boldFont.setBold(true); - QFont smallerFont; - smallerFont.setPointSize(smallerFont.pointSize()*.85); - QFont smallerBoldFont; - smallerBoldFont.setBold(true); - smallerBoldFont.setPointSize(smallerBoldFont.pointSize()*.85); - const bool isActive = index.data( ActiveTrackRole ).toBool(); const bool isSelected = option.state & QStyle::State_Selected; diff --git a/src/playlist/PrettyItemDelegate.h b/src/playlist/PrettyItemDelegate.h index 723dcaa..6fc547b 100644 --- a/src/playlist/PrettyItemDelegate.h +++ b/src/playlist/PrettyItemDelegate.h @@ -34,6 +34,9 @@ private: static const qreal PADDING; QPixmap playIcon; + QFont boldFont; + QFont smallerFont; + QFont smallerBoldFont; }; #endif -- 2.39.5