1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-26 18:03:42 +03:00

each view now keeps one indicator configui

--curent view indicator config ui is not deleted
when the PrimaryConfigView changes its parent view.
For each view there is one indicator config ui
that is kept available to be shown when appropriate.
This way we avoid unnecessary recreations of indicator
config uis when the user cycles between different views
settings.
This commit is contained in:
Michail Vourlakos 2020-07-31 02:13:34 +03:00
parent 1c0f5acde8
commit 582de7afe3
4 changed files with 30 additions and 5 deletions

View File

@ -322,6 +322,16 @@ void Indicator::configUiFor(QString type, QQuickItem *parent)
return;
}
if (m_lastCreatedConfigUi && m_lastCreatedConfigUiType == type && !type.isEmpty()) {
//! config ui has already been created and can be provided again
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_lastCreatedConfigUi->rootObject());
if (qmlItem) {
qmlItem->setParentItem(parent);
qmlItem->setVisible(true);
}
return;
}
if (m_lastCreatedConfigUi) {
delete m_lastCreatedConfigUi;
m_lastCreatedConfigUi = nullptr;
@ -341,7 +351,7 @@ void Indicator::configUiFor(QString type, QQuickItem *parent)
QString uiPath = metadata.value("X-Latte-ConfigUi");
if (!uiPath.isEmpty()) {
m_lastCreatedConfigUi = new KDeclarative::QmlObjectSharedEngine(parent);
m_lastCreatedConfigUi = new KDeclarative::QmlObjectSharedEngine(this);
m_lastCreatedConfigUi->setTranslationDomain(QLatin1String("latte_indicator_") + m_metadata.pluginId());
m_lastCreatedConfigUi->setInitializationDelayed(true);
uiPath = m_pluginPath + "package/" + uiPath;
@ -353,14 +363,26 @@ void Indicator::configUiFor(QString type, QQuickItem *parent)
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_lastCreatedConfigUi->rootObject());
if (qmlItem) {
qmlItem->setParentItem(parent);
m_lastCreatedConfigUiType = type;
setProvidesConfigUi(true);
}
} else {
m_lastCreatedConfigUiType = "";
setProvidesConfigUi(false);
}
}
}
void Indicator::hideConfigUi()
{
if (m_lastCreatedConfigUi) {
QQuickItem *qmlItem = qobject_cast<QQuickItem*>(m_lastCreatedConfigUi->rootObject());
if (qmlItem) {
qmlItem->setVisible(false);
}
}
}
void Indicator::releaseConfigUi()
{
if (m_lastCreatedConfigUi) {

View File

@ -130,6 +130,7 @@ public slots:
Q_INVOKABLE void addIndicator();
Q_INVOKABLE void downloadIndicator();
Q_INVOKABLE void removeIndicator(QString pluginId);
void hideConfigUi();
void releaseConfigUi();
signals:
@ -181,6 +182,8 @@ private:
QPointer<IndicatorPart::Resources> m_resources;
QPointer<KDeclarative::ConfigPropertyMap> m_configuration;
QString m_lastCreatedConfigUiType;
QPointer<KDeclarative::QmlObjectSharedEngine> m_lastCreatedConfigUi;
};

View File

@ -245,8 +245,8 @@ void PrimaryConfigView::initParentView(Latte::View *view)
setIsReady(false);
if (m_latteView && m_latteView->indicator()) {
//! destroy indicator config ui when the configuration window is closed
m_latteView->indicator()->releaseConfigUi();
//! hide indicator config ui when parent view is changing
m_latteView->indicator()->hideConfigUi();
}
SubConfigView::initParentView(view);

View File

@ -421,9 +421,9 @@ PlasmaComponents.Page {
onCurrentChanged: {
if (current.checked) {
if (current === customIndicator.button) {
latteView.indicator.type = customIndicator.type
latteView.indicator.type = customIndicator.type;
} else {
latteView.indicator.type = current.type
latteView.indicator.type = current.type;
}
}
}