Make decoration kcm more responsive

REVIEW: 105021
This commit is contained in:
Thomas Lübking 2012-05-24 22:22:50 +02:00
parent 52caeffe22
commit fd694c5bac
4 changed files with 64 additions and 13 deletions

View file

@ -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<KWinDecorationModule*>(QObject::parent())->itemWidth(), 150));
if (m_nextPreviewIndex < m_lastUpdateIndex && m_nextPreviewIndex < m_decorations.count())
regeneratePreview(index(m_nextPreviewIndex),
QSize(qobject_cast<KWinDecorationModule*>(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("<div style=\"color: %1\" align=\"center\">%2</div>").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();

View file

@ -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

View file

@ -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<Aurorae::AuroraeTheme>("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()

View file

@ -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