diff --git a/containment/package/contents/ui/main.qml b/containment/package/contents/ui/main.qml index 5ed77c8ad..345c1c3b8 100644 --- a/containment/package/contents/ui/main.qml +++ b/containment/package/contents/ui/main.qml @@ -1764,11 +1764,13 @@ Item { interval: 90 onTriggered: { - if (latteApplet && (latteApplet.previewContainsMouse() || latteApplet.contextMenu)) + if (latteApplet && (latteApplet.previewContainsMouse() || latteApplet.contextMenu)) { return; + } - if (latteView.contextMenuIsShown) + if (latteView.contextMenuIsShown) { return; + } if (!mouseInHoverableArea()) { setGlobalDirectRender(false); diff --git a/plasmoid/CMakeLists.txt b/plasmoid/CMakeLists.txt index 30e659849..ad01e9460 100644 --- a/plasmoid/CMakeLists.txt +++ b/plasmoid/CMakeLists.txt @@ -5,6 +5,7 @@ configure_file(metadata.desktop.cmake ${CMAKE_CURRENT_SOURCE_DIR}/package/metada plasma_install_package(package org.kde.latte.plasmoid) set(tasks_SRCS + plugin/dialog.cpp plugin/types.cpp plugin/lattetasksplugin.cpp ) @@ -13,7 +14,9 @@ add_library(lattetasksplugin SHARED ${tasks_SRCS}) target_link_libraries(lattetasksplugin Qt5::Core - Qt5::Qml) + Qt5::Qml + KF5::Plasma + KF5::PlasmaQuick) install(TARGETS lattetasksplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/latte/private/tasks) install(FILES plugin/qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/latte/private/tasks) diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index cecb226bd..d79879148 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -525,7 +525,7 @@ Item { ////BEGIN interfaces - PlasmaCore.Dialog{ + LatteTasks.Dialog{ id: windowsPreviewDlg // hideOnWindowDeactivate: false type: PlasmaCore.Dialog.Tooltip @@ -540,16 +540,31 @@ Item { Component.onCompleted: mainItem.visible = true; + onContainsMouseChanged: { + //! Orchestrate restore zoom and previews window hiding. Both should be + //! triggered together. + if (containsMouse) { + stopCheckRestoreZoomTimer(); + hidePreviewWinTimer.stop(); + } else { + hide(7.3); + } + } + function hide(debug){ // console.log("on hide previews event called: "+debug); + if (containsMouse || !visible) { + return; + } if (latteView && signalSent) { //it is used to unblock dock hiding signalSent = false; } - if (!root.contextMenu) + if (!root.contextMenu) { root.disableRestoreZoom = false; + } hidePreviewWinTimer.start(); } @@ -591,11 +606,17 @@ Item { //! Delay windows previews hiding Timer { id: hidePreviewWinTimer - interval: 350 + interval: 300 onTriggered: { - windowsPreviewDlg.visible = false; - windowsPreviewDlg.mainItem.visible = false; - windowsPreviewDlg.activeItem = null; + //! Orchestrate restore zoom and previews window hiding. Both should be + //! triggered together. + if (!windowsPreviewDlg.containsMouse + && !(windowsPreviewDlg.activeItem && windowsPreviewDlg.activeItem.containsMouse)) { + windowsPreviewDlg.visible = false; + windowsPreviewDlg.mainItem.visible = false; + windowsPreviewDlg.activeItem = null; + startCheckRestoreZoomTimer(); + } } } @@ -1773,11 +1794,7 @@ Item { } function previewContainsMouse() { - if(toolTipDelegate && toolTipDelegate.containsMouse && toolTipDelegate.parentTask) { - return true; - } else { - return false; - } + return windowsPreviewDlg.containsMouse; } function containsMouse(){ @@ -1817,8 +1834,9 @@ Item { disableRestoreZoom = false; } - if (!previewContainsMouse()) + if (!previewContainsMouse()) { windowsPreviewDlg.hide(4.2); + } if (!latteView) { initializeHoveredIndex(); @@ -1874,6 +1892,7 @@ Item { function startCheckRestoreZoomTimer(duration) { if (latteView) { + latteView.startCheckRestoreZoomTimer(); } else { if (duration > 0) { diff --git a/plasmoid/package/contents/ui/previews/ToolTipDelegate2.qml b/plasmoid/package/contents/ui/previews/ToolTipDelegate2.qml index ad0244130..7bb789c1b 100644 --- a/plasmoid/package/contents/ui/previews/ToolTipDelegate2.qml +++ b/plasmoid/package/contents/ui/previews/ToolTipDelegate2.qml @@ -53,8 +53,6 @@ PlasmaExtras.ScrollArea { property bool isLauncher property bool isMinimizedParent - property bool containsMouse: false - // Needed for generateSubtext() property string displayParent property string genericName @@ -111,17 +109,6 @@ PlasmaExtras.ScrollArea { } } //! DropArea - //! Underneath MouseArea - MouseArea { - id: contentItemMouseArea - anchors.fill: parent - hoverEnabled: true - - onContainsMouseChanged: { - mainToolTip.mouseIsInside(); - } - }//! MouseArea - Loader { id: contentItem active: mainToolTip.rootIndex !== undefined @@ -161,38 +148,6 @@ PlasmaExtras.ScrollArea { } //! Loader } //! Item - //! Central Functionality - function mouseIsInside(){ - var isInside = contentItemMouseArea.containsMouse || instancesContainMouse(); - - if (isInside){ - mainToolTip.containsMouse = true; - - if(!root.latteView) - checkListHovered.stop(); - } else { - mainToolTip.containsMouse = false; - - if(!root.latteView) - checkListHovered.startDuration(100); - else - root.latteView.startCheckRestoreZoomTimer(); - } - } - - function instancesContainMouse() { - var previewInstances = isGroup ? contentItem.children[0].children : contentItem.children; - var instancesLength = previewInstances.length; - - for(var i=instancesLength-1; i>=0; --i) { - if( (typeof(previewInstances[i].containsMouse) === "function") //ignore unrelevant objects - && previewInstances[i].containsMouse()) - return true; - } - - return false; - } - function instanceAtPos(x, y){ var previewInstances = isGroup ? contentItem.children[0].children : contentItem.children; var instancesLength = previewInstances.length; diff --git a/plasmoid/package/contents/ui/previews/ToolTipInstance.qml b/plasmoid/package/contents/ui/previews/ToolTipInstance.qml index 5c83d4152..81e3585b5 100644 --- a/plasmoid/package/contents/ui/previews/ToolTipInstance.qml +++ b/plasmoid/package/contents/ui/previews/ToolTipInstance.qml @@ -84,11 +84,6 @@ Column { readonly property string albumArt: currentMetadata["mpris:artUrl"] || "" // - function containsMouse() { - return closeButton.hovered || area2.containsMouse - || (playbackLoader.active && playbackLoader.item.containsMouse()); - } - function isTaskActive() { return (isGroup ? isActive : (parentTask ? parentTask.isActive : false)); } @@ -162,7 +157,6 @@ Column { backend.cancelHighlightWindows(); tasksModel.requestClose(submodelIndex); } - onHoveredChanged: mainToolTip.mouseIsInside() } } @@ -278,10 +272,6 @@ Column { // onClicked: mpris2Source.raise(mprisSourceName) // } - function containsMouse() { - return area3.containsMouse || canGoBackButton.hovered || playingButton.hovered || canGoNextButton.hovered; - } - Item { id: playerControlsFrostedGlass anchors.fill: parent @@ -313,9 +303,6 @@ Column { MouseArea { id: area3 anchors.fill: playerControlsRow - - hoverEnabled: true - onContainsMouseChanged: mainToolTip.mouseIsInside(); } RowLayout { @@ -359,7 +346,6 @@ Column { enabled: canGoBack iconSource: LayoutMirroring.enabled ? "media-skip-forward" : "media-skip-backward" onClicked: mpris2Source.goPrevious(mprisSourceName) - onHoveredChanged: mainToolTip.mouseIsInside() } PlasmaComponents.ToolButton { @@ -373,7 +359,6 @@ Column { mpris2Source.pause(mprisSourceName); } } - onHoveredChanged: mainToolTip.mouseIsInside() } PlasmaComponents.ToolButton { @@ -381,7 +366,6 @@ Column { enabled: canGoNext iconSource: LayoutMirroring.enabled ? "media-skip-backward" : "media-skip-forward" onClicked: mpris2Source.goNext(mprisSourceName) - onHoveredChanged: mainToolTip.mouseIsInside() } } diff --git a/plasmoid/package/contents/ui/previews/ToolTipWindowMouseArea.qml b/plasmoid/package/contents/ui/previews/ToolTipWindowMouseArea.qml index 11b906370..24d238a5a 100644 --- a/plasmoid/package/contents/ui/previews/ToolTipWindowMouseArea.qml +++ b/plasmoid/package/contents/ui/previews/ToolTipWindowMouseArea.qml @@ -57,7 +57,6 @@ MouseArea { } onContainsMouseChanged: { - mainToolTip.mouseIsInside(); root.windowsHovered([winId], containsMouse); } } diff --git a/plasmoid/plugin/dialog.cpp b/plasmoid/plugin/dialog.cpp new file mode 100644 index 000000000..0452080ed --- /dev/null +++ b/plasmoid/plugin/dialog.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "dialog.h" + + +namespace Latte { +namespace Quick { + +Dialog::Dialog(QQuickItem *parent) + : PlasmaQuick::Dialog(parent) +{ +} + +bool Dialog::containsMouse() const +{ + return m_containsMouse; +} + +void Dialog::setContainsMouse(bool contains) +{ + if (m_containsMouse == contains) { + return; + } + + m_containsMouse = contains; + emit containsMouseChanged(); +} + +bool Dialog::event(QEvent *e) +{ + if (e->type() == QEvent::Enter) { + setContainsMouse(true); + } else if (e->type() == QEvent::Leave) { + setContainsMouse(false); + } + + return PlasmaQuick::Dialog::event(e); +} + +} +} diff --git a/plasmoid/plugin/dialog.h b/plasmoid/plugin/dialog.h new file mode 100644 index 000000000..72f087ed7 --- /dev/null +++ b/plasmoid/plugin/dialog.h @@ -0,0 +1,60 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LATTEDIALOG_H +#define LATTEDIALOG_H + +// Qt +#include +#include + +// Plasma +#include + +namespace Latte { +namespace Quick { + +class Dialog : public PlasmaQuick::Dialog { + Q_OBJECT + Q_PROPERTY (bool containsMouse READ containsMouse NOTIFY containsMouseChanged) + +public: + explicit Dialog(QQuickItem *parent = nullptr); + + bool containsMouse() const; + +signals: + void containsMouseChanged(); + +protected: + bool event(QEvent *e) override; + +private slots: + void setContainsMouse(bool contains); + +private: + bool m_containsMouse{false}; + + +}; + +} +} + +#endif diff --git a/plasmoid/plugin/lattetasksplugin.cpp b/plasmoid/plugin/lattetasksplugin.cpp index a833b4693..3a0354f0b 100644 --- a/plasmoid/plugin/lattetasksplugin.cpp +++ b/plasmoid/plugin/lattetasksplugin.cpp @@ -20,14 +20,17 @@ #include "lattetasksplugin.h" // local +#include "dialog.h" #include "types.h" // Qt #include + void LatteTasksPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.latte.private.tasks")); qmlRegisterUncreatableType(uri, 0, 1, "Types", "Latte Tasks Types uncreatable"); + qmlRegisterType(uri, 0, 1, "Dialog"); } diff --git a/plasmoid/plugin/lattetasksplugin.h b/plasmoid/plugin/lattetasksplugin.h index ab060e61f..b7cf58c28 100644 --- a/plasmoid/plugin/lattetasksplugin.h +++ b/plasmoid/plugin/lattetasksplugin.h @@ -23,6 +23,9 @@ // Qt #include +// Plasma +#include + class LatteTasksPlugin : public QQmlExtensionPlugin { Q_OBJECT