From fd694c5bac94513d0a188e3847c9576c24c4e863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Thu, 24 May 2012 22:22:50 +0200 Subject: [PATCH] Make decoration kcm more responsive REVIEW: 105021 --- kcmkwin/kwindecoration/decorationmodel.cpp | 28 +++++++++++++++--- kcmkwin/kwindecoration/decorationmodel.h | 9 ++++-- kcmkwin/kwindecoration/kwindecoration.cpp | 34 ++++++++++++++++++---- kcmkwin/kwindecoration/kwindecoration.h | 6 +++- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index e38f6712ee..e24fcd111e 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -255,11 +255,32 @@ void DecorationModel::setButtons(bool custom, const QString& left, const QString m_rightButtons = right; } -void DecorationModel::regeneratePreviews() +void DecorationModel::regenerateNextPreview() { - for (int i = 0; i < m_decorations.count(); i++) { - regeneratePreview(index(i), QSize(qobject_cast(QObject::parent())->itemWidth(), 150)); + if (m_nextPreviewIndex < m_lastUpdateIndex && m_nextPreviewIndex < m_decorations.count()) + regeneratePreview(index(m_nextPreviewIndex), + QSize(qobject_cast(QObject::parent())->itemWidth(), 150)); + ++m_nextPreviewIndex; + if (m_nextPreviewIndex >= m_lastUpdateIndex && m_firstUpdateIndex > 0) { + // do the above ones + m_lastUpdateIndex = qMin(m_firstUpdateIndex, m_decorations.count()); + m_firstUpdateIndex = m_nextPreviewIndex = 0; } + if (m_nextPreviewIndex < m_lastUpdateIndex) + QMetaObject::invokeMethod(this, "regenerateNextPreview", Qt::QueuedConnection); +} + +void DecorationModel::regeneratePreviews(int firstIndex) +{ + m_firstUpdateIndex = firstIndex; + m_lastUpdateIndex = m_decorations.count(); + m_nextPreviewIndex = firstIndex; + regenerateNextPreview(); +} + +void DecorationModel::stopPreviewGeneration() +{ + m_firstUpdateIndex = m_lastUpdateIndex = m_nextPreviewIndex = 0; } void DecorationModel::regeneratePreview(const QModelIndex& index, const QSize& size) @@ -286,7 +307,6 @@ void DecorationModel::regeneratePreview(const QModelIndex& index, const QSize& s 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)) m_preview->enablePreview(); diff --git a/kcmkwin/kwindecoration/decorationmodel.h b/kcmkwin/kwindecoration/decorationmodel.h index a932b15ced..0a5a11600b 100644 --- a/kcmkwin/kwindecoration/decorationmodel.h +++ b/kcmkwin/kwindecoration/decorationmodel.h @@ -107,10 +107,12 @@ public: QModelIndex indexOfName(const QString& decoName) const; QModelIndex indexOfAuroraeName(const QString& auroraeName) const; + void regeneratePreviews(int firstIndex = 0); + void stopPreviewGeneration(); public slots: void regeneratePreview(const QModelIndex& index, const QSize& size); - void regeneratePreviews(); - +private slots: + void regenerateNextPreview(); private: void findDecorations(); void findAuroraeThemes(); @@ -123,6 +125,9 @@ private: QString m_rightButtons; KSharedConfigPtr m_config; QWidget* m_renderWidget; + int m_nextPreviewIndex; + int m_firstUpdateIndex; + int m_lastUpdateIndex; }; } // namespace KWin diff --git a/kcmkwin/kwindecoration/kwindecoration.cpp b/kcmkwin/kwindecoration/kwindecoration.cpp index 6d9e729670..2185d15f99 100644 --- a/kcmkwin/kwindecoration/kwindecoration.cpp +++ b/kcmkwin/kwindecoration/kwindecoration.cpp @@ -75,6 +75,8 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList & , m_showTooltips(false) , m_configLoaded(false) , m_decorationButtons(new DecorationButtons(this)) + , m_lastPreviewWidth(-1) + , m_previewUpdateTimer(NULL) { qmlRegisterType("org.kde.kwin.aurorae", 0, 1, "AuroraeTheme"); m_ui = new KWinDecorationForm(this); @@ -98,15 +100,14 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList & m_ui->decorationList->rootContext()->setContextProperty("decorationModel", m_proxyModel); m_ui->decorationList->rootContext()->setContextProperty("options", m_decorationButtons); m_ui->decorationList->rootContext()->setContextProperty("highlightColor", m_ui->decorationList->palette().color(QPalette::Highlight)); + m_ui->decorationList->rootContext()->setContextProperty("sliderWidth", m_ui->decorationList->verticalScrollBar()->width()); m_ui->decorationList->rootContext()->setContextProperty("auroraeSource", KStandardDirs::locate("data", "kwin/aurorae/aurorae.qml")); m_ui->decorationList->setSource(KStandardDirs::locate("data", "kwin/kcm_kwindecoration/main.qml")); readConfig(style); connect(m_ui->decorationList->rootObject(), SIGNAL(currentIndexChanged()), SLOT(slotSelectionChanged())); - connect(m_ui->decorationList->rootObject(), SIGNAL(widthChanged()), m_model, SLOT(regeneratePreviews())); - connect(m_ui->decorationList->rootObject(), SIGNAL(contentYChanged()), SLOT(updateScrollbarValue())); - connect(m_ui->decorationList->rootObject(), SIGNAL(contentHeightChanged()), SLOT(updateScrollbarRange())); + connect(m_ui->decorationList->rootObject(), SIGNAL(widthChanged()), SLOT(updatePreviewWidth())); connect(m_ui->configureButtonsButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureButtons())); connect(m_ui->ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNSClicked())); connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString))); @@ -114,6 +115,8 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList & m_ui->decorationList->disconnect(m_ui->decorationList->verticalScrollBar()); m_ui->decorationList->verticalScrollBar()->disconnect(m_ui->decorationList); + connect(m_ui->decorationList->rootObject(), SIGNAL(contentYChanged()), SLOT(updateScrollbarValue())); + connect(m_ui->decorationList->rootObject(), SIGNAL(contentHeightChanged()), SLOT(updateScrollbarRange())); connect(m_ui->decorationList->verticalScrollBar(), SIGNAL(rangeChanged(int, int )), SLOT(updateScrollbarRange())); connect(m_ui->decorationList->verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(updateViewPosition(int))); @@ -126,8 +129,7 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList & ki18n("(c) 2001 Karol Szwed")); about->addAuthor(ki18n("Karol Szwed"), KLocalizedString(), "gallium@kde.org"); setAboutData(about); - m_model->regeneratePreviews(); - QMetaObject::invokeMethod(this, "setSliderWidth", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "updatePreviews", Qt::QueuedConnection); } @@ -364,9 +366,29 @@ bool KWinDecorationModule::eventFilter(QObject *o, QEvent *e) updateScrollbarRange(); return KCModule::eventFilter(o, e); } -void KWinDecorationModule::setSliderWidth() + +void KWinDecorationModule::updatePreviews() { m_ui->decorationList->rootContext()->setContextProperty("sliderWidth", m_ui->decorationList->verticalScrollBar()->width()); + const int newWidth = m_ui->decorationList->rootObject()->property("width").toInt(); + if (newWidth == m_lastPreviewWidth) + return; + m_lastPreviewWidth = newWidth; + const int h = m_ui->decorationList->rootObject()->property("contentHeight").toInt(); + const int y = m_ui->decorationList->rootObject()->property("contentY").toInt(); + // start at first element in sight + m_model->regeneratePreviews(y*m_model->rowCount()/h); +} + +void KWinDecorationModule::updatePreviewWidth() +{ + if (!m_previewUpdateTimer) { + m_previewUpdateTimer = new QTimer(this); + m_previewUpdateTimer->setSingleShot(true); + connect(m_previewUpdateTimer, SIGNAL(timeout()), this, SLOT(updatePreviews())); + } + m_model->stopPreviewGeneration(); + m_previewUpdateTimer->start(100); } void KWinDecorationModule::updateScrollbarRange() diff --git a/kcmkwin/kwindecoration/kwindecoration.h b/kcmkwin/kwindecoration/kwindecoration.h index e1d7556daa..07d84f6f0c 100644 --- a/kcmkwin/kwindecoration/kwindecoration.h +++ b/kcmkwin/kwindecoration/kwindecoration.h @@ -119,7 +119,8 @@ private: void readConfig(const KConfigGroup& conf); void writeConfig(KConfigGroup &conf); private slots: - void setSliderWidth(); + void updatePreviews(); + void updatePreviewWidth(); void updateScrollbarRange(); void updateScrollbarValue(); void updateViewPosition(int v); @@ -133,6 +134,9 @@ private: QSortFilterProxyModel* m_proxyModel; bool m_configLoaded; DecorationButtons *m_decorationButtons; + + int m_lastPreviewWidth; + QTimer *m_previewUpdateTimer; }; } //namespace