From f14b2572bfd79bacb03d55c9941d598b23d13502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 27 Jan 2012 11:21:30 +0100 Subject: [PATCH] Improve generation of previews code The layout text is only required for native decorations. --- kcmkwin/kwindecoration/decorationmodel.cpp | 42 +++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index 64274d2844..e38f6712ee 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -257,8 +257,6 @@ void DecorationModel::setButtons(bool custom, const QString& left, const QString void DecorationModel::regeneratePreviews() { - QList::iterator it = m_decorations.begin(); - for (int i = 0; i < m_decorations.count(); i++) { regeneratePreview(index(i), QSize(qobject_cast(QObject::parent())->itemWidth(), 150)); } @@ -267,28 +265,27 @@ void DecorationModel::regeneratePreviews() void DecorationModel::regeneratePreview(const QModelIndex& index, const QSize& size) { DecorationModelData& data = m_decorations[ index.row()]; - //Use a QTextDocument to layout the text - QTextDocument document; - - QString html = QString("%1").arg(data.name); - - if (!data.author.isEmpty()) { - QString authorCaption = i18nc("Caption to decoration preview, %1 author name", - "by %1", data.author); - - html += QString("
%2") - .arg(KGlobalSettings::smallestReadableFont().pointSize()) - .arg(authorCaption); - } - - QColor color = QApplication::palette().brush(QPalette::Text).color(); - html = QString("
%2
").arg(color.name()).arg(html); - - document.setHtml(html); - const int margin = 5; switch(data.type) { - case DecorationModelData::NativeDecoration: + case DecorationModelData::NativeDecoration: { + //Use a QTextDocument to layout the text + QTextDocument document; + + QString html = QString("%1").arg(data.name); + + if (!data.author.isEmpty()) { + QString authorCaption = i18nc("Caption to decoration preview, %1 author name", + "by %1", data.author); + + html += QString("
%2") + .arg(KGlobalSettings::smallestReadableFont().pointSize()) + .arg(authorCaption); + } + + QColor color = QApplication::palette().brush(QPalette::Text).color(); + html = QString("
%2
").arg(color.name()).arg(html); + + document.setHtml(html); m_plugins->reset(KDecoration::SettingDecoration); if (m_plugins->loadPlugin(data.libraryName) && m_preview->recreateDecoration(m_plugins)) @@ -301,6 +298,7 @@ void DecorationModel::regeneratePreview(const QModelIndex& index, const QSize& s m_preview->setTempBorderSize(m_plugins, data.borderSize); data.preview = m_preview->preview(&document, m_renderWidget); break; + } default: // nothing break;