From ef1692eea6912c7a70773901bcfd91fb70d0b8cf Mon Sep 17 00:00:00 2001 From: Valerio Pilo Date: Thu, 3 Jan 2019 15:26:21 +0100 Subject: [PATCH] [kcmkwin/kwindecoration] Set current decoration index on start Summary: Fixes the preselected decoration style on module load. Also: * Prevent the module state to be set to modified on resize. * Fix QML errors in logs. Reviewers: davidedmundson Reviewed By: davidedmundson Subscribers: davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D17775 --- kcmkwin/kwindecoration/kcm.cpp | 5 +++-- kcmkwin/kwindecoration/qml/Previews.qml | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/kcmkwin/kwindecoration/kcm.cpp b/kcmkwin/kwindecoration/kcm.cpp index 995041c8b7..013d21f495 100644 --- a/kcmkwin/kwindecoration/kcm.cpp +++ b/kcmkwin/kwindecoration/kcm.cpp @@ -106,6 +106,7 @@ ConfigurationModule::ConfigurationModule(QWidget *parent, const QVariantList &ar m_quickView->rootContext()->setContextProperty("leftButtons", m_leftButtons); m_quickView->rootContext()->setContextProperty("rightButtons", m_rightButtons); m_quickView->rootContext()->setContextProperty("availableButtons", m_availableButtons); + m_quickView->rootContext()->setContextProperty("initialThemeIndex", -1); m_quickView->rootContext()->setContextProperty("titleFont", QFontDatabase::systemFont(QFontDatabase::TitleFont)); m_quickView->setResizeMode(QQuickView::SizeRootObjectToView); @@ -113,7 +114,7 @@ ConfigurationModule::ConfigurationModule(QWidget *parent, const QVariantList &ar if (m_quickView->status() == QQuickView::Ready) { auto listView = m_quickView->rootObject()->findChild("listView"); if (listView) { - connect(listView, SIGNAL(currentIndexChanged()), this, SLOT(changed())); + connect(listView, SIGNAL(userChangedSelection()), this, SLOT(changed())); } } @@ -313,7 +314,7 @@ void ConfigurationModule::load() m_ui->borderSizesCombo->setCurrentIndex(m_ui->borderSizesCombo->findData(border)); int themeIndex = m_proxyModel->mapFromSource(m_model->findDecoration(plugin, theme)).row(); - m_quickView->rootContext()->setContextProperty("savedIndex", themeIndex); + m_quickView->rootContext()->setContextProperty("initialThemeIndex", themeIndex); // buttons const auto &left = readDecorationButtons(config, "ButtonsOnLeft", QVector{ diff --git a/kcmkwin/kwindecoration/qml/Previews.qml b/kcmkwin/kwindecoration/qml/Previews.qml index 0916920019..9a04f87499 100644 --- a/kcmkwin/kwindecoration/qml/Previews.qml +++ b/kcmkwin/kwindecoration/qml/Previews.qml @@ -28,16 +28,17 @@ ScrollView { GridView { id: gridView objectName: "listView" + signal userChangedSelection() model: decorationsModel cellWidth: 20 * units.gridUnit cellHeight: cellWidth / 1.6 + highlightFollowsCurrentItem: true onContentHeightChanged: { - if (gridView.currentIndex == -1) { - gridView.currentIndex = savedIndex; + if (gridView.currentIndex == -1 && initialThemeIndex != -1) { + gridView.currentIndex = initialThemeIndex } - gridView.positionViewAtIndex(gridView.currentIndex, GridView.Visible); + gridView.positionViewAtIndex(gridView.currentIndex, GridView.Visible) } - Rectangle { z: -1 anchors.fill: parent @@ -63,11 +64,17 @@ ScrollView { bridge: bridgeItem.bridge borderSizesIndex: gridView.borderSizesIndex } + Component.onCompleted: { + if (gridView.currentIndex == -1 && initialThemeIndex != -1) { + gridView.currentIndex = initialThemeIndex + } + } MouseArea { hoverEnabled: false anchors.fill: parent onClicked: { - gridView.currentIndex = index; + gridView.currentIndex = index + gridView.userChangedSelection() } } ColumnLayout { @@ -107,7 +114,8 @@ ScrollView { hoverEnabled: false anchors.fill: parent onClicked: { - gridView.currentIndex = index; + gridView.currentIndex = index + gridView.userChangedSelection() } } Layout.fillWidth: true @@ -138,6 +146,7 @@ ScrollView { text: i18n("Configure %1...", decorationPreviews.themeName) onClicked: { gridView.currentIndex = index + gridView.userChangedSelection() bridgeItem.bridge.configure() } }