From cbe9a588b89270638bee311d3220e65d77d7d7f5 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 2 Feb 2021 17:51:28 +0200 Subject: [PATCH] Loaders for all dock settings windows --this way we make sure that plasmoid and latteView objects are always available to them when needed --- .../configuration/CanvasConfiguration.qml | 193 ++-- .../configuration/LatteDockConfiguration.qml | 900 +++++++++--------- .../LatteDockSecondaryConfiguration.qml | 51 +- 3 files changed, 577 insertions(+), 567 deletions(-) diff --git a/shell/package/contents/configuration/CanvasConfiguration.qml b/shell/package/contents/configuration/CanvasConfiguration.qml index 5d46a6bac..08c5056cb 100644 --- a/shell/package/contents/configuration/CanvasConfiguration.qml +++ b/shell/package/contents/configuration/CanvasConfiguration.qml @@ -28,126 +28,129 @@ import org.kde.latte.private.containment 0.1 as LatteContainment import "canvas" as CanvasComponent -Item{ - id: root +Loader { + active: plasmoid && plasmoid.configuration && latteView + + sourceComponent: Item{ + id: root + readonly property bool isVertical: plasmoid.formFactor === PlasmaCore.Types.Vertical + readonly property bool isHorizontal: !isVertical + + property int animationSpeed: LatteCore.WindowSystem.compositingActive ? 500 : 0 + property int panelAlignment: plasmoid.configuration.alignment + + readonly property real appliedOpacity: imageTiler.opacity + readonly property real maxOpacity: plasmoid.configuration.inConfigureAppletsMode || !LatteCore.WindowSystem.compositingActive ? + 1 : plasmoid.configuration.editBackgroundOpacity + + property real offset: { + if (root.isHorizontal) { + return width * (plasmoid.configuration.offset/100); + } else { + return height * (plasmoid.configuration.offset/100) + } + } - readonly property bool isVertical: plasmoid.formFactor === PlasmaCore.Types.Vertical - readonly property bool isHorizontal: !isVertical + property string appChosenShadowColor: { + if (plasmoid.configuration.shadowColorType === LatteContainment.Types.ThemeColorShadow) { + var strC = String(theme.textColor); + return strC.indexOf("#") === 0 ? strC.substr(1) : strC; + } else if (plasmoid.configuration.shadowColorType === LatteContainment.Types.UserColorShadow) { + return plasmoid.configuration.shadowColor; + } - property int animationSpeed: LatteCore.WindowSystem.compositingActive ? 500 : 0 - property int panelAlignment: plasmoid.configuration.alignment + // default shadow color + return "080808"; + } - readonly property real appliedOpacity: imageTiler.opacity - readonly property real maxOpacity: plasmoid.configuration.inConfigureAppletsMode || !LatteCore.WindowSystem.compositingActive ? - 1 : plasmoid.configuration.editBackgroundOpacity + property string appShadowColorSolid: "#" + appChosenShadowColor - property real offset: { - if (root.isHorizontal) { - return width * (plasmoid.configuration.offset/100); - } else { - return height * (plasmoid.configuration.offset/100) + //// BEGIN OF Behaviors + Behavior on offset { + NumberAnimation { + id: offsetAnimation + duration: animationSpeed + easing.type: Easing.OutCubic + } } - } + //// END OF Behaviors - property string appChosenShadowColor: { - if (plasmoid.configuration.shadowColorType === LatteContainment.Types.ThemeColorShadow) { - var strC = String(theme.textColor); - return strC.indexOf("#") === 0 ? strC.substr(1) : strC; - } else if (plasmoid.configuration.shadowColorType === LatteContainment.Types.UserColorShadow) { - return plasmoid.configuration.shadowColor; + Item { + id: graphicsSystem + readonly property bool isAccelerated: (GraphicsInfo.api !== GraphicsInfo.Software) + && (GraphicsInfo.api !== GraphicsInfo.Unknown) } - // default shadow color - return "080808"; - } - - property string appShadowColorSolid: "#" + appChosenShadowColor - - //// BEGIN OF Behaviors - Behavior on offset { - NumberAnimation { - id: offsetAnimation - duration: animationSpeed - easing.type: Easing.OutCubic + Image{ + id: imageTiler + anchors.fill: parent + opacity: root.maxOpacity + fillMode: Image.Tile + source: latteView.layout ? latteView.layout.background : "../images/canvas/blueprint.jpg" + + Behavior on opacity { + NumberAnimation { + duration: 0.8 * root.animationSpeed + easing.type: Easing.OutCubic + } + } } - } - //// END OF Behaviors - Item { - id: graphicsSystem - readonly property bool isAccelerated: (GraphicsInfo.api !== GraphicsInfo.Software) - && (GraphicsInfo.api !== GraphicsInfo.Unknown) - } + MouseArea { + id: editBackMouseArea + anchors.fill: imageTiler + visible: !plasmoid.configuration.inConfigureAppletsMode + hoverEnabled: true - Image{ - id: imageTiler - anchors.fill: parent - opacity: root.maxOpacity - fillMode: Image.Tile - source: latteView.layout ? latteView.layout.background : "../images/canvas/blueprint.jpg" + property bool wheelIsBlocked: false; + readonly property double opacityStep: 0.1 + readonly property string tooltip: i18nc("opacity for background under edit mode, %0% is opacity percentage", + "You can use mouse wheel to change background opacity of %0%").arg(Math.round(plasmoid.configuration.editBackgroundOpacity * 100)) - Behavior on opacity { - NumberAnimation { - duration: 0.8 * root.animationSpeed - easing.type: Easing.OutCubic + onWheel: { + processWheel(wheel); } - } - } - MouseArea { - id: editBackMouseArea - anchors.fill: imageTiler - visible: !plasmoid.configuration.inConfigureAppletsMode - hoverEnabled: true - property bool wheelIsBlocked: false; - readonly property double opacityStep: 0.1 - readonly property string tooltip: i18nc("opacity for background under edit mode, %0% is opacity percentage", - "You can use mouse wheel to change background opacity of %0%").arg(Math.round(plasmoid.configuration.editBackgroundOpacity * 100)) + function processWheel(wheel) { + if (wheelIsBlocked) { + return; + } - onWheel: { - processWheel(wheel); - } + wheelIsBlocked = true; + scrollDelayer.start(); + var angle = wheel.angleDelta.y / 8; - function processWheel(wheel) { - if (wheelIsBlocked) { - return; + if (angle > 10) { + plasmoid.configuration.editBackgroundOpacity = Math.min(100, plasmoid.configuration.editBackgroundOpacity + opacityStep) + } else if (angle < -10) { + plasmoid.configuration.editBackgroundOpacity = Math.max(0, plasmoid.configuration.editBackgroundOpacity - opacityStep) + } } - wheelIsBlocked = true; - scrollDelayer.start(); + //! A timer is needed in order to handle also touchpads that probably + //! send too many signals very fast. This way the signals per sec are limited. + //! The user needs to have a steady normal scroll in order to not + //! notice a annoying delay + Timer{ + id: scrollDelayer - var angle = wheel.angleDelta.y / 8; - - if (angle > 10) { - plasmoid.configuration.editBackgroundOpacity = Math.min(100, plasmoid.configuration.editBackgroundOpacity + opacityStep) - } else if (angle < -10) { - plasmoid.configuration.editBackgroundOpacity = Math.max(0, plasmoid.configuration.editBackgroundOpacity - opacityStep) + interval: 80 + onTriggered: editBackMouseArea.wheelIsBlocked = false; } } - //! A timer is needed in order to handle also touchpads that probably - //! send too many signals very fast. This way the signals per sec are limited. - //! The user needs to have a steady normal scroll in order to not - //! notice a annoying delay - Timer{ - id: scrollDelayer - - interval: 80 - onTriggered: editBackMouseArea.wheelIsBlocked = false; + PlasmaComponents.Button { + anchors.fill: editBackMouseArea + opacity: 0 + tooltip: editBackMouseArea.tooltip } - } - PlasmaComponents.Button { - anchors.fill: editBackMouseArea - opacity: 0 - tooltip: editBackMouseArea.tooltip - } - - //! Settings Overlay - CanvasComponent.SettingsOverlay { - id: settingsOverlay - anchors.fill: parent + //! Settings Overlay + CanvasComponent.SettingsOverlay { + id: settingsOverlay + anchors.fill: parent + } } } diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index 4c9777112..e53df98be 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -39,608 +39,612 @@ import org.kde.latte.components 1.0 as LatteComponents import "pages" as Pages import "../controls" as LatteExtraControls -FocusScope { - id: dialog - width: appliedWidth - height: appliedHeight +Loader { + active: plasmoid && plasmoid.configuration && latteView - readonly property bool basicLevel: !advancedLevel - readonly property bool advancedLevel: universalSettings.inAdvancedModeForEditSettings + sourceComponent: FocusScope { + id: dialog + width: appliedWidth + height: appliedHeight - readonly property bool inConfigureAppletsMode: plasmoid.configuration.inConfigureAppletsMode || !LatteCore.WindowSystem.compositingActive + readonly property bool basicLevel: !advancedLevel + readonly property bool advancedLevel: universalSettings.inAdvancedModeForEditSettings - readonly property bool kirigamiLibraryIsFound: LatteCore.Environment.frameworksVersion >= LatteCore.Environment.makeVersion(5,69,0) + readonly property bool inConfigureAppletsMode: plasmoid.configuration.inConfigureAppletsMode || !LatteCore.WindowSystem.compositingActive - //! max size based on screen resolution - //! TODO: if we can access availableScreenGeometry.height this can be improved, currently - //! we use 100px. or 50px. in order to give space for othe views to be shown and to have also - //! some space around the settings window - property int maxHeight: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? - viewConfig.availableScreenGeometry.height - (latteView.editThickness - latteView.maxNormalThickness) - units.largeSpacing : - viewConfig.availableScreenGeometry.height - 2 * units.largeSpacing + readonly property bool kirigamiLibraryIsFound: LatteCore.Environment.frameworksVersion >= LatteCore.Environment.makeVersion(5,69,0) - property int maxWidth: 0.6 * latteView.screenGeometry.width + //! max size based on screen resolution + //! TODO: if we can access availableScreenGeometry.height this can be improved, currently + //! we use 100px. or 50px. in order to give space for othe views to be shown and to have also + //! some space around the settings window + property int maxHeight: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? + viewConfig.availableScreenGeometry.height - (latteView.editThickness - latteView.maxNormalThickness) - units.largeSpacing : + viewConfig.availableScreenGeometry.height - 2 * units.largeSpacing - //! propose size based on font size - property int proposedWidth: 0.82 * proposedHeight + units.smallSpacing * 2 - property int proposedHeight: 36 * theme.mSize(theme.defaultFont).height + property int maxWidth: 0.6 * latteView.screenGeometry.width - //! chosen size to be applied, if the user has set or not a different scale for the settings window - property int chosenWidth: userScaleWidth !== 1 ? userScaleWidth * proposedWidth : proposedWidth - property int chosenHeight: userScaleHeight !== 1 ? userScaleHeight * heightLevel * proposedHeight : heightLevel * proposedHeight + //! propose size based on font size + property int proposedWidth: 0.82 * proposedHeight + units.smallSpacing * 2 + property int proposedHeight: 36 * theme.mSize(theme.defaultFont).height - readonly property int optionsWidth: appliedWidth - units.smallSpacing * 10 + //! chosen size to be applied, if the user has set or not a different scale for the settings window + property int chosenWidth: userScaleWidth !== 1 ? userScaleWidth * proposedWidth : proposedWidth + property int chosenHeight: userScaleHeight !== 1 ? userScaleHeight * heightLevel * proposedHeight : heightLevel * proposedHeight - //! user set scales based on its preference, e.g. 96% of the proposed size - property real userScaleWidth: 1 - property real userScaleHeight: 1 + readonly property int optionsWidth: appliedWidth - units.smallSpacing * 10 - readonly property real heightLevel: (dialog.advancedLevel ? 100 : 1) //in order to use all available space + //! user set scales based on its preference, e.g. 96% of the proposed size + property real userScaleWidth: 1 + property real userScaleHeight: 1 - onHeightChanged: viewConfig.syncGeometry(); + readonly property real heightLevel: (dialog.advancedLevel ? 100 : 1) //in order to use all available space - //! applied size in order to not be out of boundaries - //! width can be between 200px - maxWidth - //! height can be between 400px - maxHeight - property int appliedWidth: Math.min(maxWidth, Math.max(200, chosenWidth)) - property int appliedHeight: universalSettings.inAdvancedModeForEditSettings ? maxHeight : Math.min(maxHeight, Math.max(400, chosenHeight)) + onHeightChanged: viewConfig.syncGeometry(); - Layout.minimumWidth: width - Layout.minimumHeight: height - LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft - LayoutMirroring.childrenInherit: true + //! applied size in order to not be out of boundaries + //! width can be between 200px - maxWidth + //! height can be between 400px - maxHeight + property int appliedWidth: Math.min(maxWidth, Math.max(200, chosenWidth)) + property int appliedHeight: universalSettings.inAdvancedModeForEditSettings ? maxHeight : Math.min(maxHeight, Math.max(400, chosenHeight)) - readonly property bool viewIsPanel: latteView.type === LatteCore.Types.PanelView + Layout.minimumWidth: width + Layout.minimumHeight: height + LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft + LayoutMirroring.childrenInherit: true + + readonly property bool viewIsPanel: latteView.type === LatteCore.Types.PanelView - property bool panelIsVertical: plasmoid.formFactor === PlasmaCore.Types.Vertical - property int subGroupSpacing: units.largeSpacing + units.smallSpacing * 1.5 + property bool panelIsVertical: plasmoid.formFactor === PlasmaCore.Types.Vertical + property int subGroupSpacing: units.largeSpacing + units.smallSpacing * 1.5 - property color bC: theme.backgroundColor - property color transparentBackgroundColor: Qt.rgba(bC.r, bC.g, bC.b, 0.7) + property color bC: theme.backgroundColor + property color transparentBackgroundColor: Qt.rgba(bC.r, bC.g, bC.b, 0.7) - readonly property Item currentPage: pagesStackView.currentItem + readonly property Item currentPage: pagesStackView.currentItem - readonly property Item behaviorPage: behaviorLoader.item - readonly property Item appearancePage: appearanceLoader.item - readonly property Item effectsPage: effectsLoader.item + readonly property Item behaviorPage: behaviorLoader.item + readonly property Item appearancePage: appearanceLoader.item + readonly property Item effectsPage: effectsLoader.item - onAdvancedLevelChanged: { - //! switch to appearancePage when effectsPage becomes hidden because - //! advancedLevel was disabled by the user - if (!advancedLevel && tabBar.currentTab === effectsTabBtn) { - tabBar.currentTab = appearanceTabBtn; + onAdvancedLevelChanged: { + //! switch to appearancePage when effectsPage becomes hidden because + //! advancedLevel was disabled by the user + if (!advancedLevel && tabBar.currentTab === effectsTabBtn) { + tabBar.currentTab = appearanceTabBtn; + } } - } - Component.onCompleted: { - updateScales(); - } + Component.onCompleted: { + updateScales(); + } - Connections { - target: latteView.positioner - onCurrentScreenNameChanged: dialog.updateScales(); - } + Connections { + target: latteView.positioner + onCurrentScreenNameChanged: dialog.updateScales(); + } - function updateScales() { - userScaleWidth = universalSettings.screenWidthScale(latteView.positioner.currentScreenName); - userScaleHeight = universalSettings.screenHeightScale(latteView.positioner.currentScreenName); - } + function updateScales() { + userScaleWidth = universalSettings.screenWidthScale(latteView.positioner.currentScreenName); + userScaleHeight = universalSettings.screenHeightScale(latteView.positioner.currentScreenName); + } - PlasmaCore.FrameSvgItem{ - id: backgroundFrameSvgItem - anchors.fill: parent - imagePath: "dialogs/background" - enabledBorders: viewConfig.enabledBorders + PlasmaCore.FrameSvgItem{ + id: backgroundFrameSvgItem + anchors.fill: parent + imagePath: "dialogs/background" + enabledBorders: viewConfig.enabledBorders - onEnabledBordersChanged: viewConfig.updateEffects() - Component.onCompleted: viewConfig.updateEffects() + onEnabledBordersChanged: viewConfig.updateEffects() + Component.onCompleted: viewConfig.updateEffects() - LatteExtraControls.DragCorner { - id: dragCorner + LatteExtraControls.DragCorner { + id: dragCorner + } } - } - PlasmaComponents.Label{ - anchors.top: parent.top - anchors.horizontalCenter: parent.horizontalCenter - text: dialog.advancedLevel ? - i18nc("view settings width scale","Width %0%").arg(userScaleWidth * 100) : - i18nc("view settings width scale","Width %0% / Height %1%").arg(userScaleWidth * 100).arg(userScaleHeight * 100) - visible: dragCorner.isActive - } + PlasmaComponents.Label{ + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + text: dialog.advancedLevel ? + i18nc("view settings width scale","Width %0%").arg(userScaleWidth * 100) : + i18nc("view settings width scale","Width %0% / Height %1%").arg(userScaleWidth * 100).arg(userScaleHeight * 100) + visible: dragCorner.isActive + } - ColumnLayout { - id: content + ColumnLayout { + id: content - Layout.minimumWidth: width - Layout.minimumHeight: calculatedHeight - Layout.preferredWidth: width - Layout.preferredHeight: calculatedHeight - width: (dialog.appliedWidth - units.smallSpacing * 2) + Layout.minimumWidth: width + Layout.minimumHeight: calculatedHeight + Layout.preferredWidth: width + Layout.preferredHeight: calculatedHeight + width: (dialog.appliedWidth - units.smallSpacing * 2) - anchors.horizontalCenter: parent.horizontalCenter - anchors.top: parent.top - spacing: units.smallSpacing + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: parent.top + spacing: units.smallSpacing - property int calculatedHeight: header.height + headerSpacer.height+ tabBar.height + pagesBackground.height + actionButtons.height + spacing * 3 + property int calculatedHeight: header.height + headerSpacer.height+ tabBar.height + pagesBackground.height + actionButtons.height + spacing * 3 - Keys.onPressed: { - if (event.key === Qt.Key_Escape) { - viewConfig.hideConfigWindow(); + Keys.onPressed: { + if (event.key === Qt.Key_Escape) { + viewConfig.hideConfigWindow(); + } } - } - Component.onCompleted: forceActiveFocus(); + Component.onCompleted: forceActiveFocus(); - RowLayout { - id: header - Layout.fillWidth: true + RowLayout { + id: header + Layout.fillWidth: true - spacing: 0 + spacing: 0 - Item { - id: trademark - Layout.alignment: Qt.AlignLeft | Qt.AlignTop - Layout.fillWidth: false - Layout.topMargin: units.smallSpacing - Layout.preferredWidth: width - Layout.preferredHeight: height + Item { + id: trademark + Layout.alignment: Qt.AlignLeft | Qt.AlignTop + Layout.fillWidth: false + Layout.topMargin: units.smallSpacing + Layout.preferredWidth: width + Layout.preferredHeight: height - width: latteTrademark.width + units.smallSpacing - height: trademarkHeight + width: latteTrademark.width + units.smallSpacing + height: trademarkHeight - readonly property int trademarkHeight: 48 + readonly property int trademarkHeight: 48 - PlasmaCore.SvgItem{ - id: latteTrademark - width: Qt.application.layoutDirection !== Qt.RightToLeft ? Math.ceil(1.70 * height) : height - height: trademark.height + PlasmaCore.SvgItem{ + id: latteTrademark + width: Qt.application.layoutDirection !== Qt.RightToLeft ? Math.ceil(1.70 * height) : height + height: trademark.height - svg: PlasmaCore.Svg{ - imagePath: Qt.application.layoutDirection !== Qt.RightToLeft ? universalSettings.trademarkPath() : universalSettings.trademarkIconPath() + svg: PlasmaCore.Svg{ + imagePath: Qt.application.layoutDirection !== Qt.RightToLeft ? universalSettings.trademarkPath() : universalSettings.trademarkIconPath() + } } } - } - Item{ - id: headerSpacer - Layout.minimumHeight: advancedSettings.height + 2*units.smallSpacing - } + Item{ + id: headerSpacer + Layout.minimumHeight: advancedSettings.height + 2*units.smallSpacing + } - ColumnLayout { - PlasmaComponents3.ToolButton { - id: pinButton + ColumnLayout { + PlasmaComponents3.ToolButton { + id: pinButton - Layout.fillWidth: false - Layout.fillHeight: false - Layout.preferredWidth: width - Layout.preferredHeight: height - Layout.alignment: Qt.AlignRight | Qt.AlignVCenter - Layout.bottomMargin: units.smallSpacing * 1.5 - //!avoid editMode box shadow - Layout.topMargin: units.smallSpacing * 3 - Layout.rightMargin: units.smallSpacing * 2 + Layout.fillWidth: false + Layout.fillHeight: false + Layout.preferredWidth: width + Layout.preferredHeight: height + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter + Layout.bottomMargin: units.smallSpacing * 1.5 + //!avoid editMode box shadow + Layout.topMargin: units.smallSpacing * 3 + Layout.rightMargin: units.smallSpacing * 2 - icon.name: "window-pin" - checkable: true + icon.name: "window-pin" + checkable: true - width: 7 * units.smallSpacing - height: width + width: 7 * units.smallSpacing + height: width - property bool inStartup: true + property bool inStartup: true - onClicked: { - plasmoid.configuration.configurationSticker = checked - viewConfig.setSticker(checked) - } + onClicked: { + plasmoid.configuration.configurationSticker = checked + viewConfig.setSticker(checked) + } - Component.onCompleted: { - checked = plasmoid.configuration.configurationSticker - viewConfig.setSticker(plasmoid.configuration.configurationSticker) + Component.onCompleted: { + checked = plasmoid.configuration.configurationSticker + viewConfig.setSticker(plasmoid.configuration.configurationSticker) + } } - } - - RowLayout { - id: advancedSettings - Layout.fillWidth: true - Layout.rightMargin: units.smallSpacing * 2 - Layout.alignment: Qt.AlignRight | Qt.AlignTop - PlasmaComponents.Label { + RowLayout { + id: advancedSettings Layout.fillWidth: true - Layout.alignment: Qt.AlignRight - } + Layout.rightMargin: units.smallSpacing * 2 + Layout.alignment: Qt.AlignRight | Qt.AlignTop - PlasmaComponents.Label { - id: advancedLbl - Layout.alignment: Qt.AlignRight - // opacity: dialog.basicLevel ? basicOpacity : 1 + PlasmaComponents.Label { + Layout.fillWidth: true + Layout.alignment: Qt.AlignRight + } - //! TODO: the term here is not accurate because the expert settings mode - //! is used currently. In the future this term will be rethought if - //! it must remain or be changed - text: i18nc("advanced settings", "Advanced") + PlasmaComponents.Label { + id: advancedLbl + Layout.alignment: Qt.AlignRight + // opacity: dialog.basicLevel ? basicOpacity : 1 - readonly property real textColorBrightness: colorBrightness(theme.textColor) - readonly property real basicOpacity: textColorBrightness > 127 ? 0.7 : 0.3 + //! TODO: the term here is not accurate because the expert settings mode + //! is used currently. In the future this term will be rethought if + //! it must remain or be changed + text: i18nc("advanced settings", "Advanced") - color: { - if (dialog.basicLevel) { - return textColorBrightness > 127 ? Qt.darker(theme.textColor, 1.4) : Qt.lighter(theme.textColor, 2.8); - } + readonly property real textColorBrightness: colorBrightness(theme.textColor) + readonly property real basicOpacity: textColorBrightness > 127 ? 0.7 : 0.3 - return theme.textColor; - } + color: { + if (dialog.basicLevel) { + return textColorBrightness > 127 ? Qt.darker(theme.textColor, 1.4) : Qt.lighter(theme.textColor, 2.8); + } - function colorBrightness(color) { - return colorBrightnessFromRGB(color.r * 255, color.g * 255, color.b * 255); - } + return theme.textColor; + } - // formula for brightness according to: - // https://www.w3.org/TR/AERT/#color-contrast - function colorBrightnessFromRGB(r, g, b) { - return (r * 299 + g * 587 + b * 114) / 1000 - } + function colorBrightness(color) { + return colorBrightnessFromRGB(color.r * 255, color.g * 255, color.b * 255); + } + + // formula for brightness according to: + // https://www.w3.org/TR/AERT/#color-contrast + function colorBrightnessFromRGB(r, g, b) { + return (r * 299 + g * 587 + b * 114) / 1000 + } - MouseArea { - id: advancedMouseArea - anchors.fill: parent - hoverEnabled: true - onClicked: { - advancedSwitch.checked = !advancedSwitch.checked; + MouseArea { + id: advancedMouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: { + advancedSwitch.checked = !advancedSwitch.checked; + } } } - } - LatteComponents.Switch { - id: advancedSwitch - checked: universalSettings.inAdvancedModeForEditSettings && viewConfig.isReady + LatteComponents.Switch { + id: advancedSwitch + checked: universalSettings.inAdvancedModeForEditSettings && viewConfig.isReady - onCheckedChanged: { - if (viewConfig.isReady) { - universalSettings.inAdvancedModeForEditSettings = checked; + onCheckedChanged: { + if (viewConfig.isReady) { + universalSettings.inAdvancedModeForEditSettings = checked; + } } } } } } - } - PlasmaComponents.TabBar { - id: tabBar - Layout.fillWidth: true - Layout.maximumWidth: (dialog.appliedWidth - units.smallSpacing * 2) + PlasmaComponents.TabBar { + id: tabBar + Layout.fillWidth: true + Layout.maximumWidth: (dialog.appliedWidth - units.smallSpacing * 2) - readonly property int visibleStaticPages: dialog.advancedLevel ? 3 : 2 + readonly property int visibleStaticPages: dialog.advancedLevel ? 3 : 2 - PlasmaComponents.TabButton { - id: behaviorTabBtn - text: i18n("Behavior") - onCheckedChanged: { - if (checked && pagesStackView.currentItem !== behaviorPage) { - pagesStackView.forwardSliding = true; - pagesStackView.replace(pagesStackView.currentItem, behaviorPage); + PlasmaComponents.TabButton { + id: behaviorTabBtn + text: i18n("Behavior") + onCheckedChanged: { + if (checked && pagesStackView.currentItem !== behaviorPage) { + pagesStackView.forwardSliding = true; + pagesStackView.replace(pagesStackView.currentItem, behaviorPage); + } } - } - Connections { - target: viewConfig - onIsReadyChanged: { - if (viewConfig.isReady) { - tabBar.currentTab = behaviorTabBtn; + Connections { + target: viewConfig + onIsReadyChanged: { + if (viewConfig.isReady) { + tabBar.currentTab = behaviorTabBtn; + } } } } - } - PlasmaComponents.TabButton { - id: appearanceTabBtn - text: i18n("Appearance") - onCheckedChanged: { - if (checked && pagesStackView.currentItem !== appearancePage) { - pagesStackView.forwardSliding = (pagesStackView.currentItem.pageIndex > 1); - pagesStackView.replace(pagesStackView.currentItem, appearancePage); + PlasmaComponents.TabButton { + id: appearanceTabBtn + text: i18n("Appearance") + onCheckedChanged: { + if (checked && pagesStackView.currentItem !== appearancePage) { + pagesStackView.forwardSliding = (pagesStackView.currentItem.pageIndex > 1); + pagesStackView.replace(pagesStackView.currentItem, appearancePage); + } } } - } - PlasmaComponents.TabButton { - id: effectsTabBtn - text: i18n("Effects") - visible: dialog.advancedLevel - - onCheckedChanged: { - if (checked && pagesStackView.currentItem !== effectsPage) { - pagesStackView.forwardSliding = (pagesStackView.currentItem.pageIndex > 2); - pagesStackView.replace(pagesStackView.currentItem, effectsPage); + PlasmaComponents.TabButton { + id: effectsTabBtn + text: i18n("Effects") + visible: dialog.advancedLevel + + onCheckedChanged: { + if (checked && pagesStackView.currentItem !== effectsPage) { + pagesStackView.forwardSliding = (pagesStackView.currentItem.pageIndex > 2); + pagesStackView.replace(pagesStackView.currentItem, effectsPage); + } } } - } - Repeater { - id: tasksTabButtonRepeater - model: latteView.extendedInterface.latteTasksModel + Repeater { + id: tasksTabButtonRepeater + model: latteView.extendedInterface.latteTasksModel - PlasmaComponents.TabButton { - text: index >= 1 ? i18nc("tasks header and index","Tasks <%0>").arg(index+1) : i18n("Tasks") - onCheckedChanged: { - if (checked && pagesStackView.currentItem !== tasksRepeater.itemAt(index)) { - pagesStackView.forwardSliding = (pagesStackView.currentItem.pageIndex > (tabBar.visibleStaticPages + index)); - pagesStackView.replace(pagesStackView.currentItem, tasksRepeater.itemAt(index)); + PlasmaComponents.TabButton { + text: index >= 1 ? i18nc("tasks header and index","Tasks <%0>").arg(index+1) : i18n("Tasks") + onCheckedChanged: { + if (checked && pagesStackView.currentItem !== tasksRepeater.itemAt(index)) { + pagesStackView.forwardSliding = (pagesStackView.currentItem.pageIndex > (tabBar.visibleStaticPages + index)); + pagesStackView.replace(pagesStackView.currentItem, tasksRepeater.itemAt(index)); + } } } } } - } - - Rectangle { - id: pagesBackground - Layout.fillWidth: true - Layout.fillHeight: false - Layout.minimumWidth: dialog.appliedWidth - units.smallSpacing * 4 - Layout.minimumHeight: height - Layout.maximumHeight: height - - width: dialog.appliedWidth - units.smallSpacing * 3 - height: availableFreeHeight + units.smallSpacing * 4 - - color: transparentBackgroundColor - border.width: 1 - border.color: theme.backgroundColor - //fix the height binding loop when showing the configuration window - property int availableFreeHeight: dialog.appliedHeight - header.height - headerSpacer.height - tabBar.height - actionButtons.height - 2 * units.smallSpacing + Rectangle { + id: pagesBackground + Layout.fillWidth: true + Layout.fillHeight: false + Layout.minimumWidth: dialog.appliedWidth - units.smallSpacing * 4 + Layout.minimumHeight: height + Layout.maximumHeight: height - PlasmaExtras.ScrollArea { - id: scrollArea + width: dialog.appliedWidth - units.smallSpacing * 3 + height: availableFreeHeight + units.smallSpacing * 4 - anchors.fill: parent - verticalScrollBarPolicy: Qt.ScrollBarAsNeeded - horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff + color: transparentBackgroundColor + border.width: 1 + border.color: theme.backgroundColor - flickableItem.flickableDirection: Flickable.VerticalFlick + //fix the height binding loop when showing the configuration window + property int availableFreeHeight: dialog.appliedHeight - header.height - headerSpacer.height - tabBar.height - actionButtons.height - 2 * units.smallSpacing - QtQuickControls212.StackView { - id: pagesStackView - width: currentItem.width - height: currentItem.height + PlasmaExtras.ScrollArea { + id: scrollArea - property bool forwardSliding: true + anchors.fill: parent + verticalScrollBarPolicy: Qt.ScrollBarAsNeeded + horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff + + flickableItem.flickableDirection: Flickable.VerticalFlick + + QtQuickControls212.StackView { + id: pagesStackView + width: currentItem.width + height: currentItem.height + + property bool forwardSliding: true + + replaceEnter: Transition { + ParallelAnimation { + PropertyAnimation { + property: "x" + from: pagesStackView.forwardSliding ? -pagesBackground.width : pagesBackground.width + to: 0 + duration: 350 + } + + PropertyAnimation { + property: "opacity" + from: 0 + to: 1 + duration: 350 + } + } + } - replaceEnter: Transition { - ParallelAnimation { - PropertyAnimation { - property: "x" - from: pagesStackView.forwardSliding ? -pagesBackground.width : pagesBackground.width - to: 0 - duration: 350 + replaceExit: Transition { + ParallelAnimation { + PropertyAnimation { + property: "x" + from: 0 + to: pagesStackView.forwardSliding ? pagesBackground.width : -pagesBackground.width + duration: 350 + } + + PropertyAnimation { + property: "opacity" + from: 1 + to: 0 + duration: 350 + } } + } - PropertyAnimation { - property: "opacity" - from: 0 - to: 1 - duration: 350 + onDepthChanged: { + if (depth === 0) { + pagesStackView.forwardSliding = true; + push(behaviorPage); } } } + } - replaceExit: Transition { - ParallelAnimation { - PropertyAnimation { - property: "x" - from: 0 - to: pagesStackView.forwardSliding ? pagesBackground.width : -pagesBackground.width - duration: 350 + Item { + id:hiddenPages + anchors.fill: parent + visible: false + + Loader { + id: behaviorLoader + anchors.fill: parent + active: plasmoid && plasmoid.configuration && latteView + sourceComponent: Pages.BehaviorConfig { + id: _behaviorPage + readonly property int pageIndex:0 + Component.onCompleted: { + pagesStackView.push(_behaviorPage); } + } + } - PropertyAnimation { - property: "opacity" - from: 1 - to: 0 - duration: 350 - } + Loader { + id: appearanceLoader + active: plasmoid && plasmoid.configuration && latteView + sourceComponent: Pages.AppearanceConfig { + readonly property int pageIndex:1 } } - onDepthChanged: { - if (depth === 0) { - pagesStackView.forwardSliding = true; - push(behaviorPage); + Loader { + id: effectsLoader + active: plasmoid && plasmoid.configuration && latteView + sourceComponent: Pages.EffectsConfig { + readonly property int pageIndex:2 } } - } - } - Item { - id:hiddenPages - anchors.fill: parent - visible: false + Repeater { + id: tasksRepeater + model: plasmoid && plasmoid.configuration && latteView ? latteView.extendedInterface.latteTasksModel : 0 - Loader { - id: behaviorLoader - anchors.fill: parent - active: plasmoid && plasmoid.configuration && latteView - sourceComponent: Pages.BehaviorConfig { - id: _behaviorPage - readonly property int pageIndex:0 - Component.onCompleted: { - pagesStackView.push(_behaviorPage); + Pages.TasksConfig { + readonly property int pageIndex: tabBar.visibleStaticPages+index } } } + } - Loader { - id: appearanceLoader - active: plasmoid && plasmoid.configuration && latteView - sourceComponent: Pages.AppearanceConfig { - readonly property int pageIndex:1 - } - } + RowLayout { + id: actionButtons + Layout.fillWidth: true + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter - Loader { - id: effectsLoader - active: plasmoid && plasmoid.configuration && latteView - sourceComponent: Pages.EffectsConfig { - readonly property int pageIndex:2 - } - } + spacing: units.largeSpacing - Repeater { - id: tasksRepeater - model: plasmoid && plasmoid.configuration && latteView ? latteView.extendedInterface.latteTasksModel : 0 + LatteComponents.ComboBoxButton { + id: actionsComboBtn + Layout.fillWidth: true + implicitWidth: removeView.implicitWidth + implicitHeight: removeView.implicitHeight - Pages.TasksConfig { - readonly property int pageIndex: tabBar.visibleStaticPages+index - } - } - } - } + buttonEnabled: true + buttonText: i18n("New Dock") + buttonIconSource: "list-add" + buttonToolTip: i18n("Add a new dock") - RowLayout { - id: actionButtons - Layout.fillWidth: true - Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + comboBoxEnabled: true + comboBoxBlankSpaceForEmptyIcons: true + comboBoxPopUpAlignRight: Qt.application.layoutDirection === Qt.RightToLeft + comboBoxEnabledRole: "enabled" + comboBoxTextRole: "name" + comboBoxIconRole: "icon" + comboBoxMinimumPopUpWidth: actionsModel.count > 1 ? dialog.width / 2 : 150 - spacing: units.largeSpacing + property var centralLayoutsNames: [] - LatteComponents.ComboBoxButton { - id: actionsComboBtn - Layout.fillWidth: true - implicitWidth: removeView.implicitWidth - implicitHeight: removeView.implicitHeight - - buttonEnabled: true - buttonText: i18n("New Dock") - buttonIconSource: "list-add" - buttonToolTip: i18n("Add a new dock") - - comboBoxEnabled: true - comboBoxBlankSpaceForEmptyIcons: true - comboBoxPopUpAlignRight: Qt.application.layoutDirection === Qt.RightToLeft - comboBoxEnabledRole: "enabled" - comboBoxTextRole: "name" - comboBoxIconRole: "icon" - comboBoxMinimumPopUpWidth: actionsModel.count > 1 ? dialog.width / 2 : 150 - - property var centralLayoutsNames: [] - - Component.onCompleted: { - comboBox.model = actionsModel; - } + Component.onCompleted: { + comboBox.model = actionsModel; + } - ListModel { - id: actionsModel - } + ListModel { + id: actionsModel + } - Connections{ - target: actionsComboBtn.comboBox + Connections{ + target: actionsComboBtn.comboBox - Component.onCompleted:actionsComboBtn.updateModel(); + Component.onCompleted:actionsComboBtn.updateModel(); - onActivated: { - if (index==0) { - latteView.copyView(); - } else if (index>=1) { - var layouts = actionsComboBtn.centralLayoutsNames; + onActivated: { + if (index==0) { + latteView.copyView(); + } else if (index>=1) { + var layouts = actionsComboBtn.centralLayoutsNames; - latteView.positioner.hideDockDuringMovingToLayout(layouts[index-1]); - } + latteView.positioner.hideDockDuringMovingToLayout(layouts[index-1]); + } - actionsComboBtn.comboBox.currentIndex = -1; - } + actionsComboBtn.comboBox.currentIndex = -1; + } - onEnabledChanged: { - if (enabled) { - actionsComboBtn.updateModel(); - } else { - actionsComboBtn.emptyModel(); + onEnabledChanged: { + if (enabled) { + actionsComboBtn.updateModel(); + } else { + actionsComboBtn.emptyModel(); + } } } - } - Connections{ - target: actionsComboBtn.button - onClicked: latteView.layout.addNewView(); - } + Connections{ + target: actionsComboBtn.button + onClicked: latteView.layout.addNewView(); + } - Connections{ - target: latteView - onTypeChanged: actionsComboBtn.updateCopyText() - onLayoutChanged: actionsComboBtn.updateModel(); - } + Connections{ + target: latteView + onTypeChanged: actionsComboBtn.updateCopyText() + onLayoutChanged: actionsComboBtn.updateModel(); + } - Connections{ - target: viewConfig - onIsReadyChanged: { - if (viewConfig.isReady) { - actionsComboBtn.updateModel(); + Connections{ + target: viewConfig + onIsReadyChanged: { + if (viewConfig.isReady) { + actionsComboBtn.updateModel(); + } } } - } - function updateModel() { - actionsModel.clear(); + function updateModel() { + actionsModel.clear(); - var copy = {actionId: 'copy:', enabled: true, name: '', icon: 'edit-copy'}; - actionsModel.append(copy); + var copy = {actionId: 'copy:', enabled: true, name: '', icon: 'edit-copy'}; + actionsModel.append(copy); - updateCopyText(); + updateCopyText(); - var tempCentralLayouts = layoutsManager.centralLayoutsNames(); + var tempCentralLayouts = layoutsManager.centralLayoutsNames(); - if (tempCentralLayouts.length > 0) { - var curIndex = tempCentralLayouts.indexOf(latteView.layout.name); - if (curIndex >=0) { - tempCentralLayouts.splice(curIndex,1); - } + if (tempCentralLayouts.length > 0) { + var curIndex = tempCentralLayouts.indexOf(latteView.layout.name); + if (curIndex >=0) { + tempCentralLayouts.splice(curIndex,1); + } - centralLayoutsNames = tempCentralLayouts; - var iconArrow = Qt.application.layoutDirection === Qt.RightToLeft ? 'arrow-left' : 'arrow-right'; + centralLayoutsNames = tempCentralLayouts; + var iconArrow = Qt.application.layoutDirection === Qt.RightToLeft ? 'arrow-left' : 'arrow-right'; - for(var i=0; i