From b4a7b1ac844f2ced04f63b8c5e5d7c2d6619b7cb Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 7 Aug 2018 00:57:47 +0300 Subject: [PATCH] restructure windows previews to plasma design --previews showed some strange behavior by re-introducing faulty or empty previews under X11. Best way to approach this is to follow up plasma design idea in order for the code to be comparable. The code was updated and the introduced issue shows to be fixed but this wants users feedback. BUG: 397193 FIXED-IN: 0.8.1 --- plasmoid/package/contents/ui/MouseHandler.qml | 2 +- .../package/contents/ui/ToolTipDelegate2.qml | 166 +++++++++--------- .../package/contents/ui/ToolTipInstance.qml | 34 ++-- .../contents/ui/ToolTipWindowMouseArea.qml | 5 +- plasmoid/package/contents/ui/main.qml | 10 +- .../package/contents/ui/task/TaskDelegate.qml | 2 +- 6 files changed, 104 insertions(+), 115 deletions(-) diff --git a/plasmoid/package/contents/ui/MouseHandler.qml b/plasmoid/package/contents/ui/MouseHandler.qml index 294d441da..81a5cb4af 100644 --- a/plasmoid/package/contents/ui/MouseHandler.qml +++ b/plasmoid/package/contents/ui/MouseHandler.qml @@ -176,7 +176,7 @@ Item { activationTimer.stop(); } - if (hoveredItem && windowsPreviewDlg.visible && toolTipDelegate.parentIndex !== hoveredItem.itemIndex ) { + if (hoveredItem && windowsPreviewDlg.visible && toolTipDelegate.rootIndex !== hoveredItem.modelIndex() ) { windowsPreviewDlg.hide(6); } } diff --git a/plasmoid/package/contents/ui/ToolTipDelegate2.qml b/plasmoid/package/contents/ui/ToolTipDelegate2.qml index 2283722d3..1fe6eb761 100644 --- a/plasmoid/package/contents/ui/ToolTipDelegate2.qml +++ b/plasmoid/package/contents/ui/ToolTipDelegate2.qml @@ -38,7 +38,7 @@ import org.kde.taskmanager 0.1 as TaskManager PlasmaExtras.ScrollArea { id: mainToolTip property Item parentTask - property int parentIndex: -1 + property var rootIndex property string appName property int pidParent @@ -62,7 +62,7 @@ PlasmaExtras.ScrollArea { property bool isOnAllVirtualDesktopsParent property var activitiesParent // - readonly property bool isVerticalPanel: plasmoid.formFactor == PlasmaCore.Types.Vertical + readonly property bool isVerticalPanel: plasmoid.formFactor === PlasmaCore.Types.Vertical Layout.minimumWidth: contentItem.width Layout.maximumWidth: Layout.minimumWidth @@ -83,19 +83,18 @@ PlasmaExtras.ScrollArea { return isVerticalPanel ? contentItem.height > viewport.height : contentItem.width > viewport.width }); } + Item{ width: contentItem.width height: contentItem.height + //! DropArea DropArea { id: dropMainArea - anchors.fill: contentItem + anchors.fill: parent enabled: isGroup - preventStealing: true - property bool dragInside: false - property QtObject currentWindow onDragLeave: { @@ -103,120 +102,117 @@ PlasmaExtras.ScrollArea { } onDragMove: { - var current = groupTask.childAtPos(event.x, event.y); + var current = mainToolTip.instanceAtPos(event.x, event.y); if (current && currentWindow !== current && current.submodelIndex) { currentWindow = current; tasksModel.requestActivate(current.submodelIndex); } } - } + } //! DropArea + //! Underneath MouseArea MouseArea { - id: contentItem - width: childrenRect.width - height: childrenRect.height - + id: contentItemMouseArea + anchors.fill: parent hoverEnabled: true onContainsMouseChanged: { - checkMouseInside(); + mainToolTip.mouseIsInside(); } + }//! MouseArea - function checkMouseInside(){ - var isInside = containsMouse || childrenContainMouse() || (parentTask && parentTask.containsMouse); - if (isInside){ - //root.disableRestoreZoom = true; - mainToolTip.containsMouse = true; - - if(!root.latteDock) - checkListHovered.stop(); - } - else{ - //root.disableRestoreZoom = false; - mainToolTip.containsMouse = false; - - if(!root.latteDock) - checkListHovered.startDuration(100); - else - root.latteDock.startCheckRestoreZoomTimer(); - } - } + Loader { + id: contentItem + active: mainToolTip.rootIndex !== undefined + asynchronous: true + sourceComponent: isGroup ? groupToolTip : singleTooltip - function childrenContainMouse() { - return singleTask.containsMouse() || groupTask.containsMouse(); - } + Component { + id: singleTooltip - ToolTipInstance { - id: singleTask - visible: !isGroup + ToolTipInstance { + submodelIndex: mainToolTip.rootIndex + } } - Grid { - id: groupTask - rows: !isVerticalPanel - columns: isVerticalPanel - flow: isVerticalPanel ? Grid.TopToBottom : Grid.LeftToRight - spacing: units.largeSpacing - - width: isGroup ? childrenRect.width : 0 - height: isGroup ? childrenRect.height : 0 + Component { + id: groupToolTip - visible: isGroup && parentIndex !== -1 + Grid { + rows: !isVerticalPanel + columns: isVerticalPanel + flow: isVerticalPanel ? Grid.TopToBottom : Grid.LeftToRight + spacing: units.largeSpacing - Loader { - id: modelLoader - active: groupTask.visible - - sourceComponent: Repeater { + Repeater { id: groupRepeater - model: DelegateModel { - id: delegateModel + model: mainToolTip.rootIndex ? tasksModel : null + rootIndex: mainToolTip.rootIndex - model: parentIndex !== -1 && isGroup ? tasksModel : undefined - rootIndex: tasksModel.makeModelIndex(parentIndex, -1) - delegate: ToolTipInstance {} - } - - Component.onCompleted: { - parent = groupTask + delegate: ToolTipInstance { + submodelIndex: tasksModel.makeModelIndex(mainToolTip.rootIndex.row, index) + } } } } + } + } //! Loader + } //! Item + //! Central Functionality + function mouseIsInside(){ + var isInside = contentItemMouseArea.containsMouse || instancesContainMouse() || (parentTask && parentTask.containsMouse); - function containsMouse(){ - for(var i=1; i=0; --i) { + if( (typeof(previewInstances[i].containsMouse) === "function") //ignore unrelevant objects + && previewInstances[i].containsMouse()) + return true; + } - var choords = contentItem.mapFromItem(task,0, 0); + return false; + } - if(choords.y < 0) - choords.y = 0; - if(choords.x < 0) - choords.x = 0; + function instanceAtPos(x, y){ + var previewInstances = isGroup ? contentItem.children[0].children : contentItem.children; + var instancesLength = previewInstances.length; - if( (x>=choords.x) && (x<=choords.x+task.width) - && (y>=choords.y) && (y<=choords.y+task.height)){ - return task; - } - } + for(var i=0; i=choords.x) && (x<=choords.x+instance.width) + && (y>=choords.y) && (y<=choords.y+instance.height)){ + return instance; } } + return null; } } + + diff --git a/plasmoid/package/contents/ui/ToolTipInstance.qml b/plasmoid/package/contents/ui/ToolTipInstance.qml index 5d0398213..dcc1b666f 100644 --- a/plasmoid/package/contents/ui/ToolTipInstance.qml +++ b/plasmoid/package/contents/ui/ToolTipInstance.qml @@ -38,7 +38,7 @@ import org.kde.latte 0.1 as Latte Column { id: instance - property var submodelIndex: tasksModel.makeModelIndex(parentIndex, isGroup ? itemIndex : -1) + property var submodelIndex property int flatIndex: isGroup && itemIndex>=0 ? itemIndex : 0 property bool isActive: (typeof model !== 'undefined') && (typeof model.IsActive !== 'undefined') ? IsActive : false @@ -166,7 +166,7 @@ Column { tasksModel.requestClose(submodelIndex) } - onContainsMouseChanged: contentItem.checkMouseInside(); + onContainsMouseChanged: mainToolTip.mouseIsInside(); PlasmaCore.IconItem { anchors.fill: parent @@ -196,7 +196,7 @@ Column { readonly property bool isMinimized: isGroup ? instance.isMinimized : mainToolTip.isMinimizedParent // TODO: this causes XCB error message when being visible the first time - property int winId: isWin && windows[flatIndex] != undefined ? windows[flatIndex] : 0 + property int winId: isWin && windows[flatIndex] !== undefined ? windows[flatIndex] : 0 Loader{ @@ -356,7 +356,7 @@ Column { acceptedButtons: Qt.LeftButton hoverEnabled: true onClicked: mpris2Source.goPrevious(mprisSourceName) - onContainsMouseChanged: contentItem.checkMouseInside(); + onContainsMouseChanged: mainToolTip.mouseIsInside(); PlasmaCore.IconItem { anchors.fill: parent @@ -377,7 +377,7 @@ Column { acceptedButtons: Qt.LeftButton hoverEnabled: true onClicked: mpris2Source.playPause(mprisSourceName) - onContainsMouseChanged: contentItem.checkMouseInside(); + onContainsMouseChanged: mainToolTip.mouseIsInside(); PlasmaCore.IconItem { anchors.fill: parent @@ -398,7 +398,7 @@ Column { acceptedButtons: Qt.LeftButton hoverEnabled: true onClicked: mpris2Source.goNext(mprisSourceName) - onContainsMouseChanged: contentItem.checkMouseInside(); + onContainsMouseChanged: mainToolTip.mouseIsInside(); PlasmaCore.IconItem { anchors.fill: parent @@ -451,8 +451,8 @@ Column { text = text.replace(/\s*(?:-|—)*\s*$/, ""); // Add counter back at the end. - if (counter != null) { - if (text == "") { + if (counter !== null) { + if (text === "") { text = counter; } else { text = text + " " + counter; @@ -461,14 +461,14 @@ Column { // In case the window title had only redundant informations (i.e. appName), text is now empty. // Add a hyphen to indicate that and avoid empty space. - if (text == "") { + if (text === "") { text = "—"; } return text.toString(); } function generateSubText() { - if (activitiesParent == undefined) { + if (activitiesParent === undefined) { return ""; } @@ -479,9 +479,9 @@ Column { if (!plasmoid.configuration.showOnlyCurrentDesktop && virtualDesktopInfo.numberOfDesktops > 1 && (isGroup ? IsOnAllVirtualDesktops : isOnAllVirtualDesktopsParent) !== true - && vd != -1 - && vd != undefined - && virtualDesktopInfo.desktopNames[vd - 1] != undefined) { + && vd !== -1 + && vd !== undefined + && virtualDesktopInfo.desktopNames[vd - 1] !== undefined) { subTextEntries.push(i18n("On %1", virtualDesktopInfo.desktopNames[vd - 1])); } @@ -491,7 +491,7 @@ Column { return subTextEntries.join("\n"); } - if (act.length == 0 && activityInfo.numberOfRunningActivities > 1) { + if (act.length === 0 && activityInfo.numberOfRunningActivities > 1) { subTextEntries.push(i18nc("Which virtual desktop a window is currently on", "Available on all activities")); } else if (act.length > 0) { @@ -500,14 +500,14 @@ Column { for (var i = 0; i < act.length; i++) { var activity = act[i]; var activityName = activityInfo.activityName(act[i]); - if (activityName == "") { + if (activityName === "") { continue; } if (plasmoid.configuration.showOnlyCurrentActivity) { - if (activity != activityInfo.currentActivity) { + if (activity !== activityInfo.currentActivity) { activityNames.push(activityName); } - } else if (activity != activityInfo.currentActivity) { + } else if (activity !== activityInfo.currentActivity) { activityNames.push(activityName); } } diff --git a/plasmoid/package/contents/ui/ToolTipWindowMouseArea.qml b/plasmoid/package/contents/ui/ToolTipWindowMouseArea.qml index c77dc0f49..6a75e9811 100644 --- a/plasmoid/package/contents/ui/ToolTipWindowMouseArea.qml +++ b/plasmoid/package/contents/ui/ToolTipWindowMouseArea.qml @@ -41,12 +41,11 @@ MouseArea { root.createContextMenu(rootTask, modelIndex).show(); } icList.hoveredIndex = -1; - windowsPreviewDlg.hide(); - //rootTask.hideToolTipTemporarily(); + windowsPreviewDlg.hide("7.1"); } onContainsMouseChanged: { - contentItem.checkMouseInside(); + mainToolTip.mouseIsInside(); root.windowsHovered([winId], containsMouse); } } diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index ac0030c00..3e7a0f265 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -494,7 +494,7 @@ Item { } function hide(debug){ - //console.log("on hide previews event called: "+debug); + // console.log("on hide previews event called: "+debug); if (latteDock && signalSent) { //it is used to unblock dock hiding @@ -505,12 +505,6 @@ Item { windowsPreviewDlg.activeItem = null; - toolTipDelegate.containsMouse = false; - toolTipDelegate.parentTask = null; - toolTipDelegate.parentIndex = -1; - toolTipDelegate.windows = []; - toolTipDelegate.isGroup = false; - if (!contextMenu) root.disableRestoreZoom = false; @@ -522,7 +516,7 @@ Item { return; } - //console.log("preview show called..."); + // console.log("preview show called..."); if ((!activeItem || (activeItem !== taskItem)) && !root.contextMenu) { //console.log("preview show called: accepted..."); diff --git a/plasmoid/package/contents/ui/task/TaskDelegate.qml b/plasmoid/package/contents/ui/task/TaskDelegate.qml index fce98432b..8b55e1510 100644 --- a/plasmoid/package/contents/ui/task/TaskDelegate.qml +++ b/plasmoid/package/contents/ui/task/TaskDelegate.qml @@ -1007,7 +1007,7 @@ MouseArea{ windowsPreviewDlg.visualParent = previewsVisualParent; toolTipDelegate.parentTask = mainItemContainer; - toolTipDelegate.parentIndex = itemIndex; + toolTipDelegate.rootIndex = tasksModel.makeModelIndex(itemIndex, -1); toolTipDelegate.hideCloseButtons = hideClose;