diff options
| author | Peter Penz <[email protected]> | 2011-03-12 18:45:59 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-03-12 18:46:24 +0100 |
| commit | 747a86573feb65e2ffe57cdae7dedf6ad272e789 (patch) | |
| tree | 5034985dd4cae30790bef0cc3ec05f79f082183b | |
| parent | b9de2cf96f747952366da2ebc9389c1fdc238a5f (diff) | |
Details view optimization
Constructing a KColorScheme object is very expensive because of a number
of tint computations. When scrolling a big list more than 30 % of the
time was spent here. Instead, we can precompute and store the inactive
text color. (see https://git.reviewboard.kde.org/r/100826/)
Thanks to Samuel Rødal for the patch!
| -rw-r--r-- | src/views/dolphinfileitemdelegate.cpp | 17 | ||||
| -rw-r--r-- | src/views/dolphinfileitemdelegate.h | 6 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/views/dolphinfileitemdelegate.cpp b/src/views/dolphinfileitemdelegate.cpp index 9fed95bca..4d66c73f1 100644 --- a/src/views/dolphinfileitemdelegate.cpp +++ b/src/views/dolphinfileitemdelegate.cpp @@ -22,6 +22,7 @@ #include "dolphinmodel.h" #include <KColorScheme> #include <KFileItem> +#include <KGlobalSettings> #include <KIcon> #include <KIconLoader> #include <KStringHandler> @@ -37,9 +38,11 @@ DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) : KFileItemDelegate(parent), m_hasMinimizedNameColumn(false), m_cachedSize(), - m_cachedEmblems() + m_cachedEmblems(), + m_cachedInactiveTextColorDirty(true) { setJobTransfersVisible(true); + connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(handleDisplayPaletteChange())); } DolphinFileItemDelegate::~DolphinFileItemDelegate() @@ -63,8 +66,11 @@ void DolphinFileItemDelegate::paint(QPainter* painter, // Use the inactive text color for all columns except the name column. This indicates for the user that // hovering other columns does not change the actions context. QPalette palette = opt.palette; - const QColor textColor = KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText).color(); - palette.setColor(QPalette::Text, textColor); + if (m_cachedInactiveTextColorDirty) { + m_cachedInactiveTextColor = KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText).color(); + m_cachedInactiveTextColorDirty = false; + } + palette.setColor(QPalette::Text, m_cachedInactiveTextColor); opt.palette = palette; } @@ -102,6 +108,11 @@ int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOp return width; } +void DolphinFileItemDelegate::handleDisplayPaletteChange() +{ + m_cachedInactiveTextColorDirty = true; +} + void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option, const QAbstractProxyModel* proxyModel, const DolphinModel* dolphinModel, diff --git a/src/views/dolphinfileitemdelegate.h b/src/views/dolphinfileitemdelegate.h index 5eb559a79..ab4a9fd20 100644 --- a/src/views/dolphinfileitemdelegate.h +++ b/src/views/dolphinfileitemdelegate.h @@ -37,6 +37,7 @@ class QAbstractProxyModel; */ class DolphinFileItemDelegate : public KFileItemDelegate { + Q_OBJECT public: explicit DolphinFileItemDelegate(QObject* parent = 0); virtual ~DolphinFileItemDelegate(); @@ -60,6 +61,9 @@ public: */ static int nameColumnWidth(const QString& name, const QStyleOptionViewItem& option); +private slots: + void handleDisplayPaletteChange(); + private: static void adjustOptionWidth(QStyleOptionViewItemV4& option, const QAbstractProxyModel* proxyModel, @@ -75,6 +79,8 @@ private: bool m_hasMinimizedNameColumn; mutable QSize m_cachedSize; mutable QPixmap m_cachedEmblems[KVersionControlPlugin::LocallyModifiedUnstagedVersion + 1]; + mutable QColor m_cachedInactiveTextColor; + mutable bool m_cachedInactiveTextColorDirty; }; inline void DolphinFileItemDelegate::setMinimizedNameColumn(bool minimized) |
