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
This commit is contained in:
Marco Martin 2017-02-23 16:40:04 +01:00
parent bb4005ec50
commit 6673f713bb
3 changed files with 16 additions and 4 deletions

View file

@ -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<QQuickItem*>("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));

View file

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

View file

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