From 299d23230cf235ad1e129c411fdd02166c0a52f1 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 23 Feb 2017 16:40:04 +0100 Subject: [PATCH] move the view at the correct index at startup Summary: using the same trick as elsewhere, set the currentIndex and move the view to currentIndex right at startup the only way to be sure is onContentHeightChanged as there are no signals for when "the view has been populated and settled up" Test Plan: the view is at the right state since the first frame shown, no more jumping around effect Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: davidedmundson, plasma-devel, kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D4703 --- kcmkwin/kwindecoration/kcm.cpp | 13 +++++++++---- kcmkwin/kwindecoration/kcm.h | 2 ++ kcmkwin/kwindecoration/qml/Previews.qml | 5 +++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kcmkwin/kwindecoration/kcm.cpp b/kcmkwin/kwindecoration/kcm.cpp index 231b3e6a80..3a3c64d804 100644 --- a/kcmkwin/kwindecoration/kcm.cpp +++ b/kcmkwin/kwindecoration/kcm.cpp @@ -99,6 +99,7 @@ ConfigurationModule::ConfigurationModule(QWidget *parent, const QVariantList &ar m_quickView->rootContext()->setContextProperty(QStringLiteral("decorationsModel"), m_proxyModel); updateColors(); + m_quickView->rootContext()->setContextProperty("savedIndex", savedIndex()); m_quickView->rootContext()->setContextProperty("_borderSizesIndex", 3); // 3 is normal m_quickView->rootContext()->setContextProperty("leftButtons", m_leftButtons); m_quickView->rootContext()->setContextProperty("rightButtons", m_rightButtons); @@ -299,16 +300,20 @@ QVector< KDecoration2::DecorationButtonType > readDecorationButtons(const KConfi return buttonsFromString(config.readEntry(key, buttonsToString(defaultValue))); } +int ConfigurationModule::savedIndex() const +{ + const KConfigGroup config = KSharedConfig::openConfig("kwinrc")->group(s_pluginName); + const QString plugin = config.readEntry("library", s_defaultPlugin); + const QString theme = config.readEntry("theme", s_defaultTheme); + return m_proxyModel->mapFromSource(m_model->findDecoration(plugin, theme)).row(); +} + void ConfigurationModule::load() { s_loading = true; const KConfigGroup config = KSharedConfig::openConfig("kwinrc")->group(s_pluginName); const QString plugin = config.readEntry("library", s_defaultPlugin); const QString theme = config.readEntry("theme", s_defaultTheme); - const QModelIndex index = m_proxyModel->mapFromSource(m_model->findDecoration(plugin, theme)); - if (auto listView = m_quickView->rootObject()->findChild("listView")) { - listView->setProperty("currentIndex", index.isValid() ? index.row() : -1); - } m_ui->closeWindowsDoubleClick->setChecked(config.readEntry("CloseOnDoubleClickOnMenu", false)); const QVariant border = QVariant::fromValue(stringToSize(config.readEntry("BorderSize", s_borderSizeNormal))); m_ui->borderSizesCombo->setCurrentIndex(m_ui->borderSizesCombo->findData(border)); diff --git a/kcmkwin/kwindecoration/kcm.h b/kcmkwin/kwindecoration/kcm.h index 99fa431143..2a955fee2f 100644 --- a/kcmkwin/kwindecoration/kcm.h +++ b/kcmkwin/kwindecoration/kcm.h @@ -57,6 +57,8 @@ public Q_SLOTS: void defaults() override; void load() override; void save() override; + //what index is in the model the theme saved as current? needed to move the view at the proper index right at startup + int savedIndex() const; protected: void showEvent(QShowEvent *ev) override; diff --git a/kcmkwin/kwindecoration/qml/Previews.qml b/kcmkwin/kwindecoration/qml/Previews.qml index be8036c323..fa16ff2d34 100644 --- a/kcmkwin/kwindecoration/qml/Previews.qml +++ b/kcmkwin/kwindecoration/qml/Previews.qml @@ -32,6 +32,11 @@ ScrollView { model: decorationsModel cellWidth: 20 * units.gridUnit cellHeight: cellWidth / 1.6 + onContentHeightChanged: { + gridView.currentIndex = savedIndex; + gridView.positionViewAtIndex(gridView.currentIndex, GridView.Visible); + } + Rectangle { z: -1 anchors.fill: parent