From 8d195354b0a7e28a5b7cea480088045e18252727 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 7 Apr 2017 23:48:48 +0300 Subject: [PATCH] fix #371,support applets with fillWidth/Height --support applets that activate fillWidth/Height --- containment/contents/code/HeuristicTools.js | 181 ++++++++++++++++++ containment/contents/ui/AppletItem.qml | 96 +++++++++- containment/contents/ui/DebugWindow.qml | 97 ++++++++++ containment/contents/ui/VisibilityManager.qml | 1 + containment/contents/ui/main.qml | 161 +++++++++++++++- plasmoid/contents/ui/main.qml | 4 +- 6 files changed, 525 insertions(+), 15 deletions(-) create mode 100644 containment/contents/code/HeuristicTools.js diff --git a/containment/contents/code/HeuristicTools.js b/containment/contents/code/HeuristicTools.js new file mode 100644 index 000000000..a5246f7b2 --- /dev/null +++ b/containment/contents/code/HeuristicTools.js @@ -0,0 +1,181 @@ + +//! FILLWIDTH/FILLHEIGHT COMPUTATIONS +//! Computations in order to calculate correctly the sizes for applets +//! that are requesting fillWidth or fillHeight + + +//! initialize AppletItems flag "inFillCalculations" in orderf +//! to inform them that new calculations are taking place +function initLayoutForFillsCalculations(layout) { + for(var i=0; i=1) && (maxSize !== Infinity)) { + curApplet.sizeForFill = maxSize; + // console.log("s3_1 "+ maxSize); + curApplet.inFillCalculations = false; + availableSpace = Math.abs(availableSpace - maxSize); + noOfApplets = noOfApplets - 1; + sizePerApplet = noOfApplets > 1 ? Math.floor(availableSpace / noOfApplets) : availableSpace; + // console.log(noOfApplets + " - " + sizePerApplet + " - " + availableSpace); + } + } + + return [availableSpace, sizePerApplet, noOfApplets]; +} + +//! during step2/pass2 all the applets with fills +//! that remained with no computations from pass1 +//! are updated with the algorithm's proposed size +function computeStep2ForLayout(layout, sizePerApplet) { + for(var i=0; i 0 ? availableSpace / noA : 0 ; + + var noStart = startLayout.fillApplets; + var noMain = mainLayout.fillApplets; + var noEnd = endLayout.fillApplets; + + //! initialize the computations + initLayoutForFillsCalculations(startLayout); + initLayoutForFillsCalculations(mainLayout); + initLayoutForFillsCalculations(endLayout); + + //console.log("s3..."); + var res; + + //! first pass + if (mainLayout.fillApplets > 0){ + res = computeStep1ForLayout(mainLayout, availableSpace, sizePerAppletMain, noMain); + sizePerAppletMain = res[1]; noMain = res[2]; + var dif = (availableSpace - res[0]) / 2; + availableSpaceStart = availableSpaceStart - dif; + availableSpaceEnd = availableSpaceEnd - dif; + } + + var sizePerAppletStart = startLayout.fillApplets > 0 ? availableSpaceStart / noStart : 0 ; + var sizePerAppletEnd = endLayout.fillApplets > 0 ? availableSpaceEnd / noEnd : 0 ; + + if (startLayout.fillApplets > 0) { + res = computeStep1ForLayout(startLayout, availableSpaceStart, sizePerAppletStart, noStart); + availableSpaceStart = res[0]; sizePerAppletStart = res[1]; noStart = res[2]; + } + if (endLayout.fillApplets > 0) { + res = computeStep1ForLayout(endLayout, availableSpaceEnd, sizePerAppletEnd, noEnd); + availableSpaceEnd = res[0]; sizePerAppletEnd = res[1]; noEnd = res[2]; + } + + //// + //! second pass + if (mainLayout.shownApplets > 0) { + //var bSize = root.isHorizontal ? mainLayout.width : mainLayout.height; + sizePerAppletMain = (availableSpaceStart + availableSpaceEnd) / (noStart + noMain + noEnd); + computeStep2ForLayout(mainLayout, sizePerAppletMain); + var aSize = root.isHorizontal ? mainLayout.width : mainLayout.height; + + availableSpaceStart = availableSpaceStart - aSize/2; + availableSpaceEnd = availableSpaceEnd - aSize/2; + + sizePerAppletStart = startLayout.fillApplets > 0 ? availableSpaceStart / noStart : 0 ; + sizePerAppletEnd = endLayout.fillApplets > 0 ? availableSpaceEnd / noEnd : 0 ; + } + + if (startLayout.fillApplets > 0) + computeStep2ForLayout(startLayout, sizePerAppletStart); + if (endLayout.fillApplets > 0) + computeStep2ForLayout(endLayout, sizePerAppletEnd); + } + } +} diff --git a/containment/contents/ui/AppletItem.qml b/containment/contents/ui/AppletItem.qml index 167d26173..3c2604854 100644 --- a/containment/contents/ui/AppletItem.qml +++ b/containment/contents/ui/AppletItem.qml @@ -40,6 +40,18 @@ Item { property bool animationsEnabled: true property bool animationWasSent: false //protection flag for animation broadcasting property bool canBeHovered: true + property bool inFillCalculations: false //it is used in calculations for fillWidth,fillHeight applets + property bool needsFillSpace: { //it is used in calculations for fillWidth,fillHeight applets + if (!applet || !applet.Layout) + return false; + + if (((root.isHorizontal && applet.Layout.fillWidth===true) + || (root.isVertical && applet.Layout.fillHeight===true)) + && (applet.status !== PlasmaCore.Types.HiddenStatus)) + return true; + else + return false; + } property bool showZoomed: false property bool lockZoom: false property bool isInternalViewSplitter: (internalSplitterId > 0) @@ -68,6 +80,7 @@ Item { property int maxHeight: root.isHorizontal ? root.height : root.width property int shownAppletMargin: applet && (applet.pluginName === "org.kde.plasma.systemtray") ? 0 : appletMargin property int internalSplitterId: 0 + property int sizeForFill: -1 //it is used in calculations for fillWidth,fillHeight applets property int spacersMaxSize: Math.max(0,Math.ceil(0.55*root.iconSize) - root.iconMargin) property int status: applet ? applet.status : -1 @@ -92,7 +105,6 @@ Item { property alias containsMouse: appletMouseArea.containsMouse property alias pressed: appletMouseArea.pressed - /*onComputeHeightChanged: { if(index==0) console.log(computeHeight); @@ -341,10 +353,53 @@ Item { Item{ id: wrapper - width: container.isInternalViewSplitter && !root.editMode ? 0 : Math.round( latteApplet ? ((container.showZoomed && root.isVertical) ? - scaledWidth : latteApplet.tasksWidth) : scaledWidth ) - height: container.isInternalViewSplitter&& !root.editMode ? 0 : Math.round( latteApplet ? ((container.showZoomed && root.isHorizontal) ? - scaledHeight : latteApplet.tasksHeight ): scaledHeight ) + width: { + if (container.isInternalViewSplitter && !root.editMode) + return 0; + + if (container.needsFillSpace && (container.sizeForFill>-1) && root.isHorizontal){ + //! in edit mode shrink a bit the fill sizes because the splitters are shown + return root.editMode && container.needsFillSpace && (container.sizeForFill > 5*root.iconSize) ? + container.sizeForFill - 2.5*root.iconSize : container.sizeForFill; + //return container.sizeForFill; + } + + if (latteApplet) { + if (container.showZoomed && root.isVertical) + return Math.round(scaledWidth); + else + return Math.round(latteApplet.tasksWidth); + } else { + return Math.round(scaledWidth); + } + } + + height: { + if (container.isInternalViewSplitter && !root.editMode) + return 0; + + if (container.needsFillSpace && (container.sizeForFill>-1) && root.isVertical){ + //! in edit mode shrink a bit the fill sizes because the splitters are shown + return root.editMode && container.needsFillSpace && (container.sizeForFill > 5*root.iconSize) ? + container.sizeForFill - 2.5*root.iconSize : container.sizeForFill; + + //return container.sizeForFill; + } + + if (latteApplet) { + if (container.showZoomed && root.isHorizontal) + return Math.round(scaledHeight); + else + return Math.round(latteApplet.tasksHeight); + } else { + return Math.round(scaledHeight); + } + } + + //width: container.isInternalViewSplitter && !root.editMode ? 0 : Math.round( latteApplet ? ((container.showZoomed && root.isVertical) ? + // scaledWidth : latteApplet.tasksWidth) : scaledWidth ) + //height: container.isInternalViewSplitter&& !root.editMode ? 0 : Math.round( latteApplet ? ((container.showZoomed && root.isHorizontal) ? + // scaledHeight : latteApplet.tasksHeight ): scaledHeight ) property bool disableScaleWidth: false property bool disableScaleHeight: false @@ -555,8 +610,31 @@ Item { Item{ id:wrapperContainer - width: Math.round( container.isInternalViewSplitter ? wrapper.layoutWidth : parent.zoomScaleWidth * wrapper.layoutWidth ) - height: Math.round( container.isInternalViewSplitter ? wrapper.layoutHeight : parent.zoomScaleHeight * wrapper.layoutHeight ) + + width:{ + if (container.needsFillSpace && (container.sizeForFill>-1) && root.isHorizontal){ + return wrapper.width; + } + + if (container.isInternalViewSplitter) + return Math.round(wrapper.layoutWidth); + else + return Math.round(parent.zoomScaleWidth * wrapper.layoutWidth); + } + + height:{ + if (container.needsFillSpace && (container.sizeForFill>-1) && root.isVertical){ + return wrapper.height; + } + + if (container.isInternalViewSplitter) + return Math.round(wrapper.layoutHeight); + else + return Math.round(parent.zoomScaleHeight * wrapper.layoutHeight); + } + + //width: Math.round( container.isInternalViewSplitter ? wrapper.layoutWidth : parent.zoomScaleWidth * wrapper.layoutWidth ) + //height: Math.round( container.isInternalViewSplitter ? wrapper.layoutHeight : parent.zoomScaleHeight * wrapper.layoutHeight ) anchors.rightMargin: plasmoid.location === PlasmaCore.Types.RightEdge ? root.thickMarginBase : 0 anchors.leftMargin: plasmoid.location === PlasmaCore.Types.LeftEdge ? root.thickMarginBase : 0 @@ -726,7 +804,9 @@ Item { sourceComponent: Rectangle{ anchors.fill: parent color: "transparent" - border.color: "green" + //! red visualizer, in debug mode for the applets that use fillWidth or fillHeight + //! green, for the rest + border.color: (container.needsFillSpace && (container.sizeForFill>-1) && root.isHorizontal) ? "red" : "green" border.width: 1 } } diff --git a/containment/contents/ui/DebugWindow.qml b/containment/contents/ui/DebugWindow.qml index c3bc4845f..d5fe06b0f 100644 --- a/containment/contents/ui/DebugWindow.qml +++ b/containment/contents/ui/DebugWindow.qml @@ -553,6 +553,103 @@ Window{ Text{ text: root.animationsNeedThickness } + + Text{ + text: " ----------- " + } + + Text{ + text: " ----------- " + } + + Text{ + text: "Start Layout Shown Applets"+space + } + + Text{ + text: startLayout.shownApplets + } + + Text{ + text: "Start Layout Applets (with fill)"+space + } + + Text{ + text: startLayout.fillApplets + } + + Text{ + text: "Start Layout Size (no fill applets)"+space + } + + Text{ + text: startLayout.sizeWithNoFillApplets+" px." + } + + Text{ + text: " ----------- " + } + + Text{ + text: " ----------- " + } + + Text{ + text: "Main Layout Shown Applets"+space + } + + Text{ + text: mainLayout.shownApplets + } + + Text{ + text: "Main Layout Applets (with fill)"+space + } + + Text{ + text: mainLayout.fillApplets + } + + Text{ + text: "Main Layout Size (no fill applets)"+space + } + + Text{ + text: mainLayout.sizeWithNoFillApplets+" px." + } + + Text{ + text: " ----------- " + } + + Text{ + text: " ----------- " + } + + Text{ + text: "End Layout Shown Applets"+space + } + + Text{ + text: endLayout.shownApplets + } + + Text{ + text: "End Layout Applets (with fill)"+space + } + + Text{ + text: endLayout.fillApplets + } + + Text{ + text: "End Layout Size (no fill applets)"+space + } + + Text{ + text: endLayout.sizeWithNoFillApplets+" px." + } + } } diff --git a/containment/contents/ui/VisibilityManager.qml b/containment/contents/ui/VisibilityManager.qml index f475020e3..f6af776ea 100644 --- a/containment/contents/ui/VisibilityManager.qml +++ b/containment/contents/ui/VisibilityManager.qml @@ -125,6 +125,7 @@ Item{ onNormalStateChanged: { if (normalState) { root.updateAutomaticIconSize(); + root.updateSizeForAppletsInFill(); } } diff --git a/containment/contents/ui/main.qml b/containment/contents/ui/main.qml index 6db3abcc2..ec906f11b 100644 --- a/containment/contents/ui/main.qml +++ b/containment/contents/ui/main.qml @@ -30,7 +30,8 @@ import org.kde.plasma.plasmoid 2.0 import org.kde.latte 0.1 as Latte -import "LayoutManager.js" as LayoutManager +import "../code/LayoutManager.js" as LayoutManager +import "../code/HeuristicTools.js" as HeuristicTools DragDrop.DropArea { id: root @@ -40,11 +41,10 @@ DragDrop.DropArea { signal clearZoomSignal(); signal updateEffectsArea(); signal updateIndexes(); - //// + //// END SIGNALS ////BEGIN properties property bool debugMode: Qt.application.arguments.indexOf("--graphics")>=0 - property bool globalDirectRender: false //it is used to check both the applet and the containment for direct render property bool addLaunchersMessage: false @@ -450,6 +450,7 @@ DragDrop.DropArea { visibilityManager.updateMaskArea(); } else { updateAutomaticIconSize(); + HeuristicTools.updateSizeForAppletsInFill(); } updateLayouts(); @@ -565,6 +566,8 @@ DragDrop.DropArea { } } + onMaxLengthChanged: HeuristicTools.updateSizeForAppletsInFill(); + onToolBoxChanged: { if (toolBox) { toolBox.visible = false; @@ -1026,7 +1029,7 @@ DragDrop.DropArea { } function updateAutomaticIconSize() { - if ((visibilityManager.normalState && !root.editMode) + if ((visibilityManager.normalState && !root.editMode && root.autoDecreaseIconSize) && (iconSize===root.maxIconSize || iconSize === automaticIconSizeBasedSize) ) { var layoutLength; var maxLength = root.maxLength; @@ -1088,6 +1091,10 @@ DragDrop.DropArea { } } + function updateSizeForAppletsInFill() { + HeuristicTools.updateSizeForAppletsInFill(); + } + function updateLayouts(){ if(!root.editMode){ // console.log("update layout - internal view splitters count:"+internalViewSplittersCount()); @@ -1357,6 +1364,8 @@ DragDrop.DropArea { slotAnimationsNeedLength(1); } + HeuristicTools.updateSizeForAppletsInFill(); + delayUpdateMaskArea.start(); } } @@ -1380,6 +1389,8 @@ DragDrop.DropArea { slotAnimationsNeedLength(1); } + HeuristicTools.updateSizeForAppletsInFill(); + delayUpdateMaskArea.start(); } } @@ -1402,6 +1413,53 @@ DragDrop.DropArea { property int beginIndex: 0 property int count: children.length + property int shownApplets: { + var res = 0; + + for (var i=0; i