From d5b294b88e995a5c65d046f278ddf34aa48e584b Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 10 Apr 2019 21:55:40 +0300 Subject: [PATCH] improve vastly Justify Live Editing experience --the entire Justify to Another alignment experience has been improved a lot and made much smoother than in the past --- app/view/view.h | 2 - .../package/contents/code/LayoutManager.js | 83 ++++---- .../contents/ui/editmode/ConfigOverlay.qml | 2 +- containment/package/contents/ui/main.qml | 188 ++++++++++-------- .../configuration/pages/BehaviorConfig.qml | 40 +--- 5 files changed, 149 insertions(+), 166 deletions(-) diff --git a/app/view/view.h b/app/view/view.h index f2d9b9f84..2f4288432 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -225,8 +225,6 @@ protected: void mousePressEvent(QMouseEvent *event) override; signals: - void addInternalViewSplitter(); - void removeInternalViewSplitter(); void eventTriggered(QEvent *ev); void activitiesChanged(); diff --git a/containment/package/contents/code/LayoutManager.js b/containment/package/contents/code/LayoutManager.js index 2181c145d..170d752b1 100644 --- a/containment/package/contents/code/LayoutManager.js +++ b/containment/package/contents/code/LayoutManager.js @@ -60,46 +60,48 @@ function restore() { root.addApplet(appletsOrder[i], -1, -1) } - // console.log("splitters restored:"+plasmoid.configuration.splitterPosition+ " - " + plasmoid.configuration.splitterPosition2); - //add the splitters in the correct position if they exist + if (plasmoid.configuration.panelPosition === 10 /*Justify*/) { + // console.log("splitters restored:"+plasmoid.configuration.splitterPosition+ " - " + plasmoid.configuration.splitterPosition2); + //add the splitters in the correct position if they exist - var validSplitter1 = -1; + var validSplitter1 = -1; - if(plasmoid.configuration.splitterPosition !== -1){ - var missingApplets = 0; + if(plasmoid.configuration.splitterPosition !== -1){ + var missingApplets = 0; - for (var i=0; i layout.children.length)) { + if (position < 0 || (position > layout.children.length && !item.isInternalViewSplitter)) { return; - } else if (position === layout.children.length) { + } else if (position >= layout.children.length) { addToEnd = true; } @@ -394,7 +393,7 @@ function insertAtCoordinates(item, x, y) { if (!child) { // check if dragging takes place after the end of the layout if ( ((root.isVertical && y > layout.height)||(root.isHorizontal && x > layout.width)) - && layout.children.length>0 ){ + && layout.children.length>0 ){ child = layout.children[layout.children.length-1]; } else { child = layout.children[0]; @@ -452,13 +451,13 @@ function insertAtLayoutCoordinates(tLayout, item, x, y) { var neededSpace = 1.5 * (root.iconSize + root.lengthMargin); if ( (((root.isVertical && (y - neededSpace) <= tLayout.height) && y>=0) ||(root.isHorizontal && (x - neededSpace) <= tLayout.width) && x>=0) - && tLayout.children.length>0 ){ + && tLayout.children.length>0 ){ child = tLayout.children[layout.children.length-1]; - // check if dragging takes place before the start of the layout + // check if dragging takes place before the start of the layout } else if ( ((root.isVertical && (y >= -neededSpace) && (y<=neededSpace)) - ||(root.isHorizontal && (x >= -neededSpace) && (x<=neededSpace))) - && tLayout.children.length>0 ){ - child = tLayout.children[0]; + ||(root.isHorizontal && (x >= -neededSpace) && (x<=neededSpace))) + && tLayout.children.length>0 ){ + child = tLayout.children[0]; } else { return -1; //child = tLayout.children[0]; diff --git a/containment/package/contents/ui/editmode/ConfigOverlay.qml b/containment/package/contents/ui/editmode/ConfigOverlay.qml index 04f51e377..628cc2015 100644 --- a/containment/package/contents/ui/editmode/ConfigOverlay.qml +++ b/containment/package/contents/ui/editmode/ConfigOverlay.qml @@ -343,7 +343,7 @@ MouseArea { lockButton.visible = !currentApplet.isInternalViewSplitter && (currentApplet.applet.pluginName !== "org.kde.plasma.systemtray") && (currentApplet.applet.pluginName !== root.plasmoidName) && !currentApplet.isSeparator - colorizingButton.visible = root.colorizerEnabled && !currentApplet.appletBlocksColorizing; + colorizingButton.visible = root.colorizerEnabled && !currentApplet.appletBlocksColorizing && !currentApplet.isInternalViewSplitter; label.text = currentApplet.isInternalViewSplitter ? i18n("Justify Splitter") : currentApplet.applet.title; } diff --git a/containment/package/contents/ui/main.qml b/containment/package/contents/ui/main.qml index a8536342d..bf34004f9 100644 --- a/containment/package/contents/ui/main.qml +++ b/containment/package/contents/ui/main.qml @@ -353,6 +353,8 @@ DragDrop.DropArea { ( plasmoid.configuration.panelPosition === Latte.Types.Justify ? Latte.Types.Center : plasmoid.configuration.panelPosition ) + property int panelUserSetAlignment: plasmoid.configuration.panelPosition + property real zoomFactor: Latte.WindowSystem.compositingActive ? ( 1 + (plasmoid.configuration.zoomLevel / 20) ) : 1 readonly property string plasmoidName: "org.kde.latte.plasmoid" @@ -580,14 +582,38 @@ DragDrop.DropArea { } onInConfigureAppletsModeChanged: { - updateLayouts(); + if (inConfigureAppletsMode && panelUserSetAlignment===Latte.Types.Justify) { + joinLayoutsToMainLayout(); + } else if (!inConfigureAppletsMode) { + splitMainLayoutToLayouts(); + } + } + + //! It is used only when the user chooses different alignment types + //! and not during startup + onPanelUserSetAlignmentChanged: { + if (!root.editMode) { + return; + } + + if (!inConfigureAppletsMode){ + if (panelUserSetAlignment===Latte.Types.Justify) { + addInternalViewSplitters(); + splitMainLayoutToLayouts(); + } else { + joinLayoutsToMainLayout(); + } + } else { + if (panelUserSetAlignment===Latte.Types.Justify) { + addInternalViewSplitters(); + } else { + removeInternalViewSplitters(); + } + } } onLatteViewChanged: { if (latteView) { - latteView.onAddInternalViewSplitter.connect(addInternalViewSplitters); - latteView.onRemoveInternalViewSplitter.connect(removeInternalViewSplitters); - latteView.onXChanged.connect(visibilityManager.updateMaskArea); latteView.onYChanged.connect(visibilityManager.updateMaskArea); latteView.onWidthChanged.connect(visibilityManager.updateMaskArea); @@ -797,9 +823,6 @@ DragDrop.DropArea { console.debug("Destroying Latte Dock Containment ui..."); if (latteView) { - latteView.onAddInternalViewSplitter.disconnect(addInternalViewSplitters); - latteView.onRemoveInternalViewSplitter.disconnect(removeInternalViewSplitters); - latteView.onXChanged.disconnect(visibilityManager.updateMaskArea); latteView.onYChanged.disconnect(visibilityManager.updateMaskArea); latteView.onWidthChanged.disconnect(visibilityManager.updateMaskArea); @@ -822,6 +845,7 @@ DragDrop.DropArea { Containment.onAppletAdded: { addApplet(applet, x, y); + console.log(applet.pluginName); LayoutManager.save(); updateIndexes(); } @@ -842,6 +866,7 @@ DragDrop.DropArea { lastSpacer.parent = layoutsContainer.mainLayout; } + console.log(applet.pluginName); LayoutManager.save(); updateIndexes(); @@ -1001,11 +1026,10 @@ DragDrop.DropArea { } function addInternalViewSplitters(){ - addInternalViewSplitter(-1); - addInternalViewSplitter(-1); - - console.log("Adding splitters... : " + internalViewSplittersCount()); - updateLayouts(); + if (internalViewSplittersCount() === 0) { + addInternalViewSplitter(plasmoid.configuration.splitterPosition); + addInternalViewSplitter(plasmoid.configuration.splitterPosition2); + } } function addInternalViewSplitter(pos){ @@ -1021,8 +1045,6 @@ DragDrop.DropArea { } else { LayoutManager.insertAtIndex(container, Math.floor(layoutsContainer.mainLayout.count / 2)); } - - LayoutManager.save(); } } @@ -1112,21 +1134,21 @@ DragDrop.DropArea { for (var container in layoutsContainer.startLayout.children) { var item = layoutsContainer.startLayout.children[container]; if(item && item.isInternalViewSplitter) { - splitters++; + splitters = splitters + 1; } } for (var container in layoutsContainer.mainLayout.children) { var item = layoutsContainer.mainLayout.children[container]; if(item && item.isInternalViewSplitter) { - splitters++; + splitters = splitters + 1; } } for (var container in layoutsContainer.endLayout.children) { var item = layoutsContainer.endLayout.children[container]; if(item && item.isInternalViewSplitter) { - splitters++; + splitters = splitters + 1; } } @@ -1200,28 +1222,32 @@ DragDrop.DropArea { } function removeInternalViewSplitters(){ - for (var container in layoutsContainer.startLayout.children) { - var item = layoutsContainer.mainLayout.children[container]; - if(item && item.isInternalViewSplitter) - item.destroy(); - } + if (internalViewSplittersCount() > 0) { + console.log("Removing splitters... : " + internalViewSplittersCount()); - for (var container in layoutsContainer.mainLayout.children) { - var item = layoutsContainer.mainLayout.children[container]; - if(item && item.isInternalViewSplitter) - item.destroy(); - } + for (var container in layoutsContainer.startLayout.children) { + var item = layoutsContainer.startLayout.children[container]; + if(item && item.isInternalViewSplitter) { + item.destroy(); + } + } - for (var container in layoutsContainer.endLayout.children) { - var item = layoutsContainer.mainLayout.children[container]; - if(item && item.isInternalViewSplitter) - item.destroy(); - } + for (var container in layoutsContainer.mainLayout.children) { + var item = layoutsContainer.mainLayout.children[container]; + if(item && item.isInternalViewSplitter) { + item.destroy(); + } + } - console.log("Removed splitters... : " + internalViewSplittersCount()); - updateLayouts(); + for (var container in layoutsContainer.endLayout.children) { + var item = layoutsContainer.endLayout.children[container]; + if(item && item.isInternalViewSplitter) { + item.destroy(); + } + } - LayoutManager.save(); + console.log("Removed splitters... : " + internalViewSplittersCount()); + } } function setHoveredIndex(ind) { @@ -1468,63 +1494,61 @@ DragDrop.DropArea { layoutsContainer.updateSizeForAppletsInFill(); } - function updateLayouts(){ - console.log(" Updating layouts... " + internalViewSplittersCount()); - if(!root.inConfigureAppletsMode && root.panelAlignment === Latte.Types.Justify){ - // console.log("update layout - internal view splitters count:"+internalViewSplittersCount()); - if (internalViewSplittersCount() === 2) { - console.log(" Updating layouts... Step 1.."); - var splitter = -1; - var splitter2 = -1; + function splitMainLayoutToLayouts() { + if (internalViewSplittersCount() === 2) { + console.log("LAYOUTS: Moving applets from MAIN to THREE Layouts mode..."); + var splitter = -1; + var splitter2 = -1; - var totalChildren = layoutsContainer.mainLayout.children.length; - for (var i=0; i=0 && splitter2 === -1) { - splitter2 = i; - } + if(item.isInternalViewSplitter && splitter === -1) { + splitter = i; + } else if (item.isInternalViewSplitter && splitter>=0 && splitter2 === -1) { + splitter2 = i; } + } - // console.log("update layouts 1:"+splitter + " - "+splitter2); - for (var i=0; i<=splitter; ++i){ - var item = layoutsContainer.mainLayout.children[0]; - item.parent = layoutsContainer.startLayout; - } + // console.log("update layouts 1:"+splitter + " - "+splitter2); + for (var i=0; i<=splitter; ++i){ + var item = layoutsContainer.mainLayout.children[0]; + item.parent = layoutsContainer.startLayout; + } - splitter2 = splitter2 - splitter - 1; - // console.log("update layouts 2:"+splitter + " - "+splitter2); + splitter2 = splitter2 - splitter - 1; + // console.log("update layouts 2:"+splitter + " - "+splitter2); - totalChildren = layoutsContainer.mainLayout.children.length; - for (var i=splitter2+1; i=0; --i) { - var item1 = layoutsContainer.mainLayout.children[0]; - item1.parent = layoutsContainer.startLayout; - } + } - var totalChildren2 = layoutsContainer.endLayout.children.length; + updateIndexes(); + } - for (var i=totalChildren2-1; i>=0; --i) { - var item2 = layoutsContainer.endLayout.children[0]; - item2.parent = layoutsContainer.startLayout; - } + function joinLayoutsToMainLayout() { + console.log("LAYOUTS: Moving applets from THREE to MAIN Layout mode..."); + var totalChildren1 = layoutsContainer.mainLayout.children.length; + for (var i=totalChildren1-1; i>=0; --i) { + var item1 = layoutsContainer.mainLayout.children[0]; + item1.parent = layoutsContainer.startLayout; + } - var totalChildrenL = layoutsContainer.startLayout.children.length; - for (var i=totalChildrenL-1; i>=0; --i) { - var itemL = layoutsContainer.startLayout.children[0]; - itemL.parent = layoutsContainer.mainLayout; - } - } + var totalChildren2 = layoutsContainer.endLayout.children.length; + + for (var i=totalChildren2-1; i>=0; --i) { + var item2 = layoutsContainer.endLayout.children[0]; + item2.parent = layoutsContainer.startLayout; + } + + var totalChildrenL = layoutsContainer.startLayout.children.length; + for (var i=totalChildrenL-1; i>=0; --i) { + var itemL = layoutsContainer.startLayout.children[0]; + itemL.parent = layoutsContainer.mainLayout; } updateIndexes(); diff --git a/shell/package/contents/configuration/pages/BehaviorConfig.qml b/shell/package/contents/configuration/pages/BehaviorConfig.qml index 7c464ba76..751001300 100644 --- a/shell/package/contents/configuration/pages/BehaviorConfig.qml +++ b/shell/package/contents/configuration/pages/BehaviorConfig.qml @@ -294,37 +294,7 @@ PlasmaComponents.Page { LayoutMirroring.enabled: false spacing: 2 - property int panelPosition: plasmoid.configuration.panelPosition - - property bool addSplittersSent: false - property bool removeSplittersSent: true - - onPanelPositionChanged: { - updateSplitters(); - } - - Connections { - target: dialog - onInConfigureAppletsModeChanged: { - alignmentRow.updateSplitters(); - } - } - - Component.onCompleted: { - updateSplitters(); - } - - function updateSplitters() { - if (!addSplittersSent && dialog.inConfigureAppletsMode && panelPosition === Latte.Types.Justify) { - addSplittersSent = true; - latteView.addInternalViewSplitter() - removeSplittersSent = false; - } else if(!removeSplittersSent && (panelPosition !== Latte.Types.Justify || !dialog.inConfigureAppletsMode)) { - removeSplittersSent = true; - latteView.removeInternalViewSplitter() - addSplittersSent = false; - } - } + readonly property int panelPosition: plasmoid.configuration.panelPosition ExclusiveGroup { id: alignmentGroup @@ -374,14 +344,6 @@ PlasmaComponents.Page { exclusiveGroup: alignmentGroup property int position: Latte.Types.Justify - - onClicked: { - if (!alignmentRow.addSplittersSent) { - alignmentRow.addSplittersSent = true; - latteView.addInternalViewSplitter() - alignmentRow.removeSplittersSent = false; - } - } } } }