fix #371,support applets with fillWidth/Height

--support applets that activate fillWidth/Height
pull/1/head
Michail Vourlakos 8 years ago
parent 45cccd4199
commit 8d195354b0

@ -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<layout.children.length; ++i) {
var curApplet = layout.children[i];
if (curApplet.needsFillSpace) {
curApplet.inFillCalculations = true;
}
}
}
//! during step1/pass1 all the applets with fills
//! that use lower maximumSize than the proposed one from the
//! algorithm are updated
function computeStep1ForLayout(layout, availableSpace, sizePerApplet, noOfApplets) {
for(var i=0; i<layout.children.length; ++i) {
var curApplet = layout.children[i];
var maxSize = 0;
if (curApplet && curApplet.applet && curApplet.applet.Layout)
maxSize = root.isVertical ? curApplet.applet.Layout.maximumHeight : curApplet.applet.Layout.maximumWidth;
if (curApplet.needsFillSpace && (maxSize <= sizePerApplet) && (maxSize>=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<layout.children.length; ++i) {
var curApplet = layout.children[i];
if (curApplet.needsFillSpace && curApplet.inFillCalculations) {
curApplet.sizeForFill = sizePerApplet;
// console.log("s4_1 "+ sizePerApplet);
curApplet.inFillCalculations = false;
}
}
}
//! initialize the three layouts and execute the step1/phase1
//! it is used when the Centered (Main)Layout is only used or when the Main(Layout)
//! is empty in Justify mode
function initializationPhase(availableSpace, sizePerApplet, noOfApplets){
if (root.panelAlignment === Latte.Dock.Justify) {
initLayoutForFillsCalculations(startLayout);
initLayoutForFillsCalculations(endLayout);
}
initLayoutForFillsCalculations(mainLayout);
// console.log("s3...");
//! first pass in order to update sizes for applet that want to fill space
//! but their maximum metrics are lower than the sizePerApplet
var res = computeStep1ForLayout(mainLayout, availableSpace, sizePerApplet, noOfApplets);
availableSpace = res[0]; sizePerApplet = res[1]; noOfApplets = res[2];
if (root.panelAlignment === Latte.Dock.Justify) {
res = computeStep1ForLayout(startLayout, availableSpace, sizePerApplet, noOfApplets);
availableSpace = res[0]; sizePerApplet = res[1]; noOfApplets = res[2];
res = computeStep1ForLayout(endLayout, availableSpace, sizePerApplet, noOfApplets);
availableSpace = res[0]; sizePerApplet = res[1]; noOfApplets = res[2];
}
return [availableSpace, sizePerApplet, noOfApplets];
}
function updateSizeForAppletsInFill() {
if (visibilityManager.normalState && !root.editMode) {
// console.log("-------------");
// console.log("s1...");
var noA = startLayout.fillApplets + mainLayout.fillApplets + endLayout.fillApplets;
if (noA === 0)
return;
// console.log("s2...");
if (mainLayout.shownApplets === 0 || root.panelAlignment !== Latte.Dock.Justify) {
var availableSpace = Math.max(0, root.maxLength - startLayout.sizeWithNoFillApplets - mainLayout.sizeWithNoFillApplets - endLayout.sizeWithNoFillApplets - root.panelEdgeSpacing);
var sizePerApplet = availableSpace / noA;
var res = initializationPhase(availableSpace, sizePerApplet, noA);
availableSpace = res[0]; sizePerApplet = res[1]; noA = res[2];
// console.log("s4...");
//! second pass in order to update sizes for applet that want to fill space
//! this applets get the direct division of the available free space that
//! remained from step1
computeStep2ForLayout(startLayout, sizePerApplet);
computeStep2ForLayout(mainLayout, sizePerApplet);
computeStep2ForLayout(endLayout, sizePerApplet);
//console.log("s5...");
} else {
//! Justify mode in all remaining cases
//! compute the two free spaces around the centered layout
//! they are called start and end accordingly
var availableSpaceStart = Math.max(0, root.maxLength/2 - startLayout.sizeWithNoFillApplets - root.panelEdgeSpacing/2);
var availableSpaceEnd = Math.max(0, root.maxLength/2 - endLayout.sizeWithNoFillApplets - root.panelEdgeSpacing/2);
var availableSpace = availableSpaceStart + availableSpaceEnd - mainLayout.sizeWithNoFillApplets;
var sizePerAppletMain = mainLayout.fillApplets > 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);
}
}
}

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

@ -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."
}
}
}

@ -125,6 +125,7 @@ Item{
onNormalStateChanged: {
if (normalState) {
root.updateAutomaticIconSize();
root.updateSizeForAppletsInFill();
}
}

@ -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<children.length; ++i){
if (children[i] && children[i].applet
&& (children[i].applet.status === PlasmaCore.Types.HiddenStatus || children[i].isInternalViewSplitter)) {
//do nothing
} else if (children[i] && children[i].applet){
res = res + 1;
}
}
return res;
}
//it is used in calculations for fillWidth,fillHeight applets
property int sizeWithNoFillApplets: {
if (!visibilityManager || !visibilityManager.normalState)
return;
var space = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && !children[i].needsFillSpace) {
space = root.isHorizontal ? space + children[i].width : space + children[i].height;
}
}
return space;
}
//it is used in calculations for fillWidth,fillHeight applets
property int fillApplets:{
var no = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && children[i].needsFillSpace) {
//console.log("fill :::: " + children[i].applet.pluginName);
no++;
}
}
return no;
}
onFillAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
onShownAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
onSizeWithNoFillAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
states:[
State {
name: "bottom"
@ -1473,6 +1531,53 @@ DragDrop.DropArea {
property int beginIndex: 100
property int count: children.length
property int shownApplets: {
var res = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && children[i].applet
&& (children[i].applet.status === PlasmaCore.Types.HiddenStatus || children[i].isInternalViewSplitter)) {
//do nothing
} else if (children[i] && children[i].applet){
res = res + 1;
}
}
return res;
}
//it is used in calculations for fillWidth,fillHeight applets
property int sizeWithNoFillApplets: {
if (!visibilityManager || !visibilityManager.normalState)
return;
var space = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && !children[i].needsFillSpace) {
space = root.isHorizontal ? space + children[i].width : space + children[i].height;
}
}
return space;
}
//it is used in calculations for fillWidth,fillHeight applets
property int fillApplets:{
var no = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && children[i].needsFillSpace) {
//console.log("fill :::: " + children[i].applet.pluginName);
no++;
}
}
return no;
}
onFillAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
onShownAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
onSizeWithNoFillAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
}
Grid{
@ -1484,13 +1589,59 @@ DragDrop.DropArea {
rows: root.isHorizontal ? 1 : 0
rowSpacing: 0
Layout.preferredWidth: width
Layout.preferredHeight: height
property int beginIndex: 200
property int count: children.length
property int shownApplets: {
var res = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && children[i].applet
&& (children[i].applet.status === PlasmaCore.Types.HiddenStatus || children[i].isInternalViewSplitter)) {
//do nothing
} else if (children[i] && children[i].applet){
res = res + 1;
}
}
return res;
}
//it is used in calculations for fillWidth,fillHeight applets
property int sizeWithNoFillApplets: {
if (!visibilityManager || !visibilityManager.normalState)
return;
var space = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && !children[i].needsFillSpace) {
space = root.isHorizontal ? space + children[i].width : space + children[i].height;
}
}
return space;
}
//it is used in calculations for fillWidth,fillHeight applets
property int fillApplets:{
var no = 0;
for (var i=0; i<children.length; ++i){
if (children[i] && children[i].needsFillSpace) {
//console.log("fill :::: " + children[i].applet.pluginName);
no++;
}
}
return no;
}
onFillAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
onShownAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
onSizeWithNoFillAppletsChanged: HeuristicTools.updateSizeForAppletsInFill();
states:[
State {
name: "bottom"

@ -39,8 +39,8 @@ import "../code/activitiesTools.js" as ActivitiesTools
Item {
id:root
Layout.fillHeight: userPanelPosition === 0 ? true : false
Layout.fillWidth: userPanelPosition === 0 ? true : false
// Layout.fillHeight: userPanelPosition === 0 ? true : false
// Layout.fillWidth: userPanelPosition === 0 ? true : false
///IMPORTANT: These values must be tested when the Now Dock Panel support
///also the four new anchors. A small issue is shown between the animation

Loading…
Cancel
Save