From 036cc8502bd05e97f4294925edb162eb9c31215b Mon Sep 17 00:00:00 2001 From: Micah Stanley Date: Mon, 21 Apr 2025 14:01:54 +0000 Subject: [PATCH] Folio: Add ability to lock layout Adds a new setting to lock the layout of the home screen so one will not accidentally modify it. Closes https://invent.kde.org/plasma/plasma-mobile/-/issues/459 --- .../homescreens/folio/foliosettings.cpp | 18 ++++++++++++++++++ containments/homescreens/folio/foliosettings.h | 6 ++++++ .../package/contents/ui/AppDrawerGrid.qml | 3 +++ .../package/contents/ui/FavouritesBar.qml | 4 ++++ .../folio/package/contents/ui/FolderView.qml | 4 ++++ .../package/contents/ui/HomeScreenPage.qml | 13 ++++++++++++- .../ui/delegate/WidgetDelegateConfig.qml | 2 ++ .../contents/ui/private/ContextMenuLoader.qml | 1 + .../contents/ui/settings/SettingsWindow.qml | 15 ++++++++++++++- 9 files changed, 64 insertions(+), 2 deletions(-) diff --git a/containments/homescreens/folio/foliosettings.cpp b/containments/homescreens/folio/foliosettings.cpp index bcb5629a..5956789c 100644 --- a/containments/homescreens/folio/foliosettings.cpp +++ b/containments/homescreens/folio/foliosettings.cpp @@ -14,6 +14,7 @@ const QString CFG_KEY_HOMESCREEN_ROWS = QStringLiteral("homeScreenRows"); const QString CFG_KEY_HOMESCREEN_COLS = QStringLiteral("homeScreenColumns"); const QString CFG_KEY_SHOW_PAGES_APPLABELS = QStringLiteral("showPagesAppLabels"); const QString CFG_KEY_SHOW_FAVORITES_APPLABELS = QStringLiteral("showFavoritesAppLabels"); +const QString CFG_KEY_LOCK_LAYOUT = QStringLiteral("lockLayout"); const QString CFG_KEY_DELEGATE_ICON_SIZE = QStringLiteral("delegateIconSize"); const QString CFG_KEY_SHOW_FAVORITES_BAR_BACKGROUND = QStringLiteral("showFavoritesBarBackground"); const QString CFG_KEY_PAGE_TRANSITION_EFFECT = QStringLiteral("pageTransitionEffect"); @@ -82,6 +83,20 @@ void FolioSettings::setShowFavouritesAppLabels(bool showFavouritesAppLabels) } } +bool FolioSettings::lockLayout() const +{ + return m_lockLayout; +} + +void FolioSettings::setLockLayout(bool lockLayout) +{ + if (m_lockLayout != lockLayout) { + m_lockLayout = lockLayout; + Q_EMIT lockLayoutChanged(); + save(); + } +} + int FolioSettings::delegateIconSize() const { return m_delegateIconSize; @@ -148,6 +163,7 @@ void FolioSettings::save() m_homeScreen->config().writeEntry(CFG_KEY_HOMESCREEN_COLS, m_homeScreenColumns); m_homeScreen->config().writeEntry(CFG_KEY_SHOW_PAGES_APPLABELS, m_showPagesAppLabels); m_homeScreen->config().writeEntry(CFG_KEY_SHOW_FAVORITES_APPLABELS, m_showFavouritesAppLabels); + m_homeScreen->config().writeEntry(CFG_KEY_LOCK_LAYOUT, m_lockLayout); m_homeScreen->config().writeEntry(CFG_KEY_DELEGATE_ICON_SIZE, m_delegateIconSize); m_homeScreen->config().writeEntry(CFG_KEY_SHOW_FAVORITES_BAR_BACKGROUND, m_showFavouritesBarBackground); m_homeScreen->config().writeEntry(CFG_KEY_PAGE_TRANSITION_EFFECT, (int)m_pageTransitionEffect); @@ -166,6 +182,7 @@ void FolioSettings::load() m_homeScreenColumns = m_homeScreen->config().readEntry(CFG_KEY_HOMESCREEN_COLS, 4); m_showPagesAppLabels = m_homeScreen->config().readEntry(CFG_KEY_SHOW_PAGES_APPLABELS, true); m_showFavouritesAppLabels = m_homeScreen->config().readEntry(CFG_KEY_SHOW_FAVORITES_APPLABELS, false); + m_lockLayout = m_homeScreen->config().readEntry(CFG_KEY_LOCK_LAYOUT, false); m_delegateIconSize = m_homeScreen->config().readEntry(CFG_KEY_DELEGATE_ICON_SIZE, 48); m_showFavouritesBarBackground = m_homeScreen->config().readEntry(CFG_KEY_SHOW_FAVORITES_BAR_BACKGROUND, true); m_pageTransitionEffect = static_cast(m_homeScreen->config().readEntry(CFG_KEY_PAGE_TRANSITION_EFFECT, (int)SlideTransition)); @@ -175,6 +192,7 @@ void FolioSettings::load() Q_EMIT homeScreenColumnsChanged(); Q_EMIT showPagesAppLabels(); Q_EMIT showFavouritesAppLabelsChanged(); + Q_EMIT lockLayoutChanged(); Q_EMIT delegateIconSizeChanged(); Q_EMIT showWallpaperBlurChanged(); } diff --git a/containments/homescreens/folio/foliosettings.h b/containments/homescreens/folio/foliosettings.h index 03b74ea5..aa6529b1 100644 --- a/containments/homescreens/folio/foliosettings.h +++ b/containments/homescreens/folio/foliosettings.h @@ -18,6 +18,7 @@ class FolioSettings : public QObject Q_PROPERTY(int homeScreenColumns READ homeScreenColumns WRITE setHomeScreenColumns NOTIFY homeScreenColumnsChanged) Q_PROPERTY(bool showPagesAppLabels READ showPagesAppLabels WRITE setShowPagesAppLabels NOTIFY showPagesAppLabelsChanged) Q_PROPERTY(bool showFavouritesAppLabels READ showFavouritesAppLabels WRITE setShowFavouritesAppLabels NOTIFY showFavouritesAppLabelsChanged) + Q_PROPERTY(bool lockLayout READ lockLayout WRITE setLockLayout NOTIFY lockLayoutChanged) Q_PROPERTY(int delegateIconSize READ delegateIconSize WRITE setDelegateIconSize NOTIFY delegateIconSizeChanged) Q_PROPERTY(bool showFavouritesBarBackground READ showFavouritesBarBackground WRITE setShowFavouritesBarBackground NOTIFY showFavouritesBarBackgroundChanged) Q_PROPERTY( @@ -52,6 +53,9 @@ public: bool showFavouritesAppLabels() const; void setShowFavouritesAppLabels(bool showFavouritesAppLabels); + bool lockLayout() const; + void setLockLayout(bool lockLayout); + int delegateIconSize() const; void setDelegateIconSize(int delegateIconSize); @@ -74,6 +78,7 @@ Q_SIGNALS: void homeScreenColumnsChanged(); void showPagesAppLabelsChanged(); void showFavouritesAppLabelsChanged(); + void lockLayoutChanged(); void delegateIconSizeChanged(); void showFavouritesBarBackgroundChanged(); void pageTransitionEffectChanged(); @@ -88,6 +93,7 @@ private: int m_homeScreenColumns{4}; bool m_showPagesAppLabels{false}; bool m_showFavouritesAppLabels{false}; + bool m_lockLayout{false}; qreal m_delegateIconSize{48}; bool m_showFavouritesBarBackground{false}; PageTransitionEffect m_pageTransitionEffect{SlideTransition}; diff --git a/containments/homescreens/folio/package/contents/ui/AppDrawerGrid.qml b/containments/homescreens/folio/package/contents/ui/AppDrawerGrid.qml index 04ee8813..a406a4f9 100644 --- a/containments/homescreens/folio/package/contents/ui/AppDrawerGrid.qml +++ b/containments/homescreens/folio/package/contents/ui/AppDrawerGrid.qml @@ -91,6 +91,9 @@ MobileShell.GridView { height: root.cellHeight onPressAndHold: { + // prevent editing if lock layout is enabled + if (folio.FolioSettings.lockLayout) return; + const mappedCoords = root.homeScreen.prepareStartDelegateDrag(model.delegate, appDelegate.delegateItem, true); folio.HomeScreenState.closeAppDrawer(); diff --git a/containments/homescreens/folio/package/contents/ui/FavouritesBar.qml b/containments/homescreens/folio/package/contents/ui/FavouritesBar.qml index 939646e0..f002a3ea 100644 --- a/containments/homescreens/folio/package/contents/ui/FavouritesBar.qml +++ b/containments/homescreens/folio/package/contents/ui/FavouritesBar.qml @@ -108,6 +108,9 @@ MouseArea { labelOpacity: delegate.opacity onPressAndHold: { + // prevent editing if lock layout is enabled + if (folio.FolioSettings.lockLayout) return; + let mappedCoords = root.homeScreen.prepareStartDelegateDrag(delegate.delegateModel, appDelegate.delegateItem); folio.HomeScreenState.startDelegateFavouritesDrag( mappedCoords.x, @@ -149,6 +152,7 @@ MouseArea { Kirigami.Action { icon.name: "emblem-favorite" text: i18n("Remove") + enabled: !folio.FolioSettings.lockLayout onTriggered: folio.FavouritesModel.removeEntry(delegate.index) } ] diff --git a/containments/homescreens/folio/package/contents/ui/FolderView.qml b/containments/homescreens/folio/package/contents/ui/FolderView.qml index 2e318c16..54ffdf31 100644 --- a/containments/homescreens/folio/package/contents/ui/FolderView.qml +++ b/containments/homescreens/folio/package/contents/ui/FolderView.qml @@ -246,6 +246,9 @@ Folio.DelegateTouchArea { labelOpacity: delegate.opacity onPressAndHold: { + // prevent editing if lock layout is enabled + if (folio.FolioSettings.lockLayout) return; + let mappedCoords = root.homeScreen.prepareStartDelegateDrag(delegate.delegateModel, appDelegate.delegateItem); folio.HomeScreenState.startDelegateFolderDrag( mappedCoords.x, @@ -288,6 +291,7 @@ Folio.DelegateTouchArea { Kirigami.Action { icon.name: "emblem-favorite" text: i18n("Remove") + enabled: !folio.FolioSettings.lockLayout onTriggered: root.folder.removeDelegate(delegate.index) } ] diff --git a/containments/homescreens/folio/package/contents/ui/HomeScreenPage.qml b/containments/homescreens/folio/package/contents/ui/HomeScreenPage.qml index 314a774e..6aa6e9bb 100644 --- a/containments/homescreens/folio/package/contents/ui/HomeScreenPage.qml +++ b/containments/homescreens/folio/package/contents/ui/HomeScreenPage.qml @@ -174,6 +174,9 @@ Item { labelOpacity: delegate.opacity onPressAndHold: { + // prevent editing if lock layout is enabled + if (folio.FolioSettings.lockLayout) return; + let mappedCoords = root.homeScreen.prepareStartDelegateDrag(delegate.pageDelegate, appDelegate.delegateItem); folio.HomeScreenState.startDelegatePageDrag( mappedCoords.x, @@ -216,6 +219,7 @@ Item { Kirigami.Action { icon.name: "emblem-favorite" text: i18n("Remove") + enabled: !folio.FolioSettings.lockLayout onTriggered: delegate.removeSelf() } ] @@ -253,6 +257,9 @@ Item { } onPressAndHold: { + // prevent editing if lock layout is enabled + if (folio.FolioSettings.lockLayout) return; + let mappedCoords = root.homeScreen.prepareStartDelegateDrag(delegate.pageDelegate, appFolderDelegate.delegateItem); folio.HomeScreenState.startDelegatePageDrag( mappedCoords.x, @@ -296,6 +303,7 @@ Item { Kirigami.Action { icon.name: "emblem-favorite" text: i18n("Remove") + enabled: !folio.FolioSettings.lockLayout onTriggered: deleteDialog.open() } ] @@ -326,6 +334,9 @@ Item { widget: suppressAppletReparent ? null : delegate.pageDelegate.widget onStartEditMode: (pressPoint) => { + // prevent editing if lock layout is enabled + if (folio.FolioSettings.lockLayout) return; + let mappedCoords = root.homeScreen.prepareStartDelegateDrag(delegate.pageDelegate, widgetDelegate); folio.HomeScreenState.startDelegatePageDrag( mappedCoords.x, @@ -348,7 +359,7 @@ Item { } } - layer.enabled: widgetDelegate.editMode + layer.enabled: widgetDelegate.editMode && folio.FolioSettings.lockLayout === false layer.effect: DarkenEffect {} PC3.ToolTip { diff --git a/containments/homescreens/folio/package/contents/ui/delegate/WidgetDelegateConfig.qml b/containments/homescreens/folio/package/contents/ui/delegate/WidgetDelegateConfig.qml index ba15ae8f..79b5b5a2 100644 --- a/containments/homescreens/folio/package/contents/ui/delegate/WidgetDelegateConfig.qml +++ b/containments/homescreens/folio/package/contents/ui/delegate/WidgetDelegateConfig.qml @@ -43,6 +43,8 @@ Item { signal closed() function startOpen() { + // prevent config overlay if lock layout is enabled + if (folio.FolioSettings.lockLayout) return; configOverlay.open(); } diff --git a/containments/homescreens/folio/package/contents/ui/private/ContextMenuLoader.qml b/containments/homescreens/folio/package/contents/ui/private/ContextMenuLoader.qml index 589d3093..b039b409 100644 --- a/containments/homescreens/folio/package/contents/ui/private/ContextMenuLoader.qml +++ b/containments/homescreens/folio/package/contents/ui/private/ContextMenuLoader.qml @@ -35,6 +35,7 @@ Loader { delegate: PC3.MenuItem { icon.name: modelData.iconName text: modelData.text + enabled: modelData.enabled onClicked: modelData.triggered() } } diff --git a/containments/homescreens/folio/package/contents/ui/settings/SettingsWindow.qml b/containments/homescreens/folio/package/contents/ui/settings/SettingsWindow.qml index e4b68d1d..659d1cbc 100644 --- a/containments/homescreens/folio/package/contents/ui/settings/SettingsWindow.qml +++ b/containments/homescreens/folio/package/contents/ui/settings/SettingsWindow.qml @@ -194,7 +194,20 @@ Window { } } - FormCard.FormDelegateSeparator { above: showLabelsInFavourites; below: pageTransitionCombobox } + FormCard.FormDelegateSeparator { above: showLabelsInFavourites; below: lockLayout } + + FormCard.FormSwitchDelegate { + id: lockLayout + text: i18n("Lock layout") + checked: folio.FolioSettings.lockLayout + onCheckedChanged: { + if (checked != folio.FolioSettings.lockLayout) { + folio.FolioSettings.lockLayout = checked; + } + } + } + + FormCard.FormDelegateSeparator { above: lockLayout; below: pageTransitionCombobox } FormCard.FormComboBoxDelegate { id: pageTransitionCombobox