1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-08-30 09:49:25 +03:00

Tasks:introduce Tasks.Dialog

--this is just a subclass of PlasmaQuick::Dialog
that provides "containsMouse" property
This commit is contained in:
Michail Vourlakos
2020-04-28 13:12:48 +03:00
parent 3018bd0fff
commit 00127f28c0
10 changed files with 163 additions and 77 deletions

View File

@ -1764,11 +1764,13 @@ Item {
interval: 90 interval: 90
onTriggered: { onTriggered: {
if (latteApplet && (latteApplet.previewContainsMouse() || latteApplet.contextMenu)) if (latteApplet && (latteApplet.previewContainsMouse() || latteApplet.contextMenu)) {
return; return;
}
if (latteView.contextMenuIsShown) if (latteView.contextMenuIsShown) {
return; return;
}
if (!mouseInHoverableArea()) { if (!mouseInHoverableArea()) {
setGlobalDirectRender(false); setGlobalDirectRender(false);

View File

@ -5,6 +5,7 @@ configure_file(metadata.desktop.cmake ${CMAKE_CURRENT_SOURCE_DIR}/package/metada
plasma_install_package(package org.kde.latte.plasmoid) plasma_install_package(package org.kde.latte.plasmoid)
set(tasks_SRCS set(tasks_SRCS
plugin/dialog.cpp
plugin/types.cpp plugin/types.cpp
plugin/lattetasksplugin.cpp plugin/lattetasksplugin.cpp
) )
@ -13,7 +14,9 @@ add_library(lattetasksplugin SHARED ${tasks_SRCS})
target_link_libraries(lattetasksplugin target_link_libraries(lattetasksplugin
Qt5::Core Qt5::Core
Qt5::Qml) Qt5::Qml
KF5::Plasma
KF5::PlasmaQuick)
install(TARGETS lattetasksplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/latte/private/tasks) 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) install(FILES plugin/qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/latte/private/tasks)

View File

@ -525,7 +525,7 @@ Item {
////BEGIN interfaces ////BEGIN interfaces
PlasmaCore.Dialog{ LatteTasks.Dialog{
id: windowsPreviewDlg id: windowsPreviewDlg
// hideOnWindowDeactivate: false // hideOnWindowDeactivate: false
type: PlasmaCore.Dialog.Tooltip type: PlasmaCore.Dialog.Tooltip
@ -540,16 +540,31 @@ Item {
Component.onCompleted: mainItem.visible = true; 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){ function hide(debug){
// console.log("on hide previews event called: "+debug); // console.log("on hide previews event called: "+debug);
if (containsMouse || !visible) {
return;
}
if (latteView && signalSent) { if (latteView && signalSent) {
//it is used to unblock dock hiding //it is used to unblock dock hiding
signalSent = false; signalSent = false;
} }
if (!root.contextMenu) if (!root.contextMenu) {
root.disableRestoreZoom = false; root.disableRestoreZoom = false;
}
hidePreviewWinTimer.start(); hidePreviewWinTimer.start();
} }
@ -591,11 +606,17 @@ Item {
//! Delay windows previews hiding //! Delay windows previews hiding
Timer { Timer {
id: hidePreviewWinTimer id: hidePreviewWinTimer
interval: 350 interval: 300
onTriggered: { onTriggered: {
windowsPreviewDlg.visible = false; //! Orchestrate restore zoom and previews window hiding. Both should be
windowsPreviewDlg.mainItem.visible = false; //! triggered together.
windowsPreviewDlg.activeItem = null; 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() { function previewContainsMouse() {
if(toolTipDelegate && toolTipDelegate.containsMouse && toolTipDelegate.parentTask) { return windowsPreviewDlg.containsMouse;
return true;
} else {
return false;
}
} }
function containsMouse(){ function containsMouse(){
@ -1817,8 +1834,9 @@ Item {
disableRestoreZoom = false; disableRestoreZoom = false;
} }
if (!previewContainsMouse()) if (!previewContainsMouse()) {
windowsPreviewDlg.hide(4.2); windowsPreviewDlg.hide(4.2);
}
if (!latteView) { if (!latteView) {
initializeHoveredIndex(); initializeHoveredIndex();
@ -1874,6 +1892,7 @@ Item {
function startCheckRestoreZoomTimer(duration) { function startCheckRestoreZoomTimer(duration) {
if (latteView) { if (latteView) {
latteView.startCheckRestoreZoomTimer(); latteView.startCheckRestoreZoomTimer();
} else { } else {
if (duration > 0) { if (duration > 0) {

View File

@ -53,8 +53,6 @@ PlasmaExtras.ScrollArea {
property bool isLauncher property bool isLauncher
property bool isMinimizedParent property bool isMinimizedParent
property bool containsMouse: false
// Needed for generateSubtext() // Needed for generateSubtext()
property string displayParent property string displayParent
property string genericName property string genericName
@ -111,17 +109,6 @@ PlasmaExtras.ScrollArea {
} }
} //! DropArea } //! DropArea
//! Underneath MouseArea
MouseArea {
id: contentItemMouseArea
anchors.fill: parent
hoverEnabled: true
onContainsMouseChanged: {
mainToolTip.mouseIsInside();
}
}//! MouseArea
Loader { Loader {
id: contentItem id: contentItem
active: mainToolTip.rootIndex !== undefined active: mainToolTip.rootIndex !== undefined
@ -161,38 +148,6 @@ PlasmaExtras.ScrollArea {
} //! Loader } //! Loader
} //! Item } //! 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){ function instanceAtPos(x, y){
var previewInstances = isGroup ? contentItem.children[0].children : contentItem.children; var previewInstances = isGroup ? contentItem.children[0].children : contentItem.children;
var instancesLength = previewInstances.length; var instancesLength = previewInstances.length;

View File

@ -84,11 +84,6 @@ Column {
readonly property string albumArt: currentMetadata["mpris:artUrl"] || "" readonly property string albumArt: currentMetadata["mpris:artUrl"] || ""
// //
function containsMouse() {
return closeButton.hovered || area2.containsMouse
|| (playbackLoader.active && playbackLoader.item.containsMouse());
}
function isTaskActive() { function isTaskActive() {
return (isGroup ? isActive : (parentTask ? parentTask.isActive : false)); return (isGroup ? isActive : (parentTask ? parentTask.isActive : false));
} }
@ -162,7 +157,6 @@ Column {
backend.cancelHighlightWindows(); backend.cancelHighlightWindows();
tasksModel.requestClose(submodelIndex); tasksModel.requestClose(submodelIndex);
} }
onHoveredChanged: mainToolTip.mouseIsInside()
} }
} }
@ -278,10 +272,6 @@ Column {
// onClicked: mpris2Source.raise(mprisSourceName) // onClicked: mpris2Source.raise(mprisSourceName)
// } // }
function containsMouse() {
return area3.containsMouse || canGoBackButton.hovered || playingButton.hovered || canGoNextButton.hovered;
}
Item { Item {
id: playerControlsFrostedGlass id: playerControlsFrostedGlass
anchors.fill: parent anchors.fill: parent
@ -313,9 +303,6 @@ Column {
MouseArea { MouseArea {
id: area3 id: area3
anchors.fill: playerControlsRow anchors.fill: playerControlsRow
hoverEnabled: true
onContainsMouseChanged: mainToolTip.mouseIsInside();
} }
RowLayout { RowLayout {
@ -359,7 +346,6 @@ Column {
enabled: canGoBack enabled: canGoBack
iconSource: LayoutMirroring.enabled ? "media-skip-forward" : "media-skip-backward" iconSource: LayoutMirroring.enabled ? "media-skip-forward" : "media-skip-backward"
onClicked: mpris2Source.goPrevious(mprisSourceName) onClicked: mpris2Source.goPrevious(mprisSourceName)
onHoveredChanged: mainToolTip.mouseIsInside()
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
@ -373,7 +359,6 @@ Column {
mpris2Source.pause(mprisSourceName); mpris2Source.pause(mprisSourceName);
} }
} }
onHoveredChanged: mainToolTip.mouseIsInside()
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
@ -381,7 +366,6 @@ Column {
enabled: canGoNext enabled: canGoNext
iconSource: LayoutMirroring.enabled ? "media-skip-backward" : "media-skip-forward" iconSource: LayoutMirroring.enabled ? "media-skip-backward" : "media-skip-forward"
onClicked: mpris2Source.goNext(mprisSourceName) onClicked: mpris2Source.goNext(mprisSourceName)
onHoveredChanged: mainToolTip.mouseIsInside()
} }
} }

View File

@ -57,7 +57,6 @@ MouseArea {
} }
onContainsMouseChanged: { onContainsMouseChanged: {
mainToolTip.mouseIsInside();
root.windowsHovered([winId], containsMouse); root.windowsHovered([winId], containsMouse);
} }
} }

View File

@ -0,0 +1,58 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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);
}
}
}

60
plasmoid/plugin/dialog.h Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LATTEDIALOG_H
#define LATTEDIALOG_H
// Qt
#include <QEvent>
#include <QObject>
// Plasma
#include <PlasmaQuick/Dialog>
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

View File

@ -20,14 +20,17 @@
#include "lattetasksplugin.h" #include "lattetasksplugin.h"
// local // local
#include "dialog.h"
#include "types.h" #include "types.h"
// Qt // Qt
#include <QtQml> #include <QtQml>
void LatteTasksPlugin::registerTypes(const char *uri) void LatteTasksPlugin::registerTypes(const char *uri)
{ {
Q_ASSERT(uri == QLatin1String("org.kde.latte.private.tasks")); Q_ASSERT(uri == QLatin1String("org.kde.latte.private.tasks"));
qmlRegisterUncreatableType<Latte::Tasks::Types>(uri, 0, 1, "Types", "Latte Tasks Types uncreatable"); qmlRegisterUncreatableType<Latte::Tasks::Types>(uri, 0, 1, "Types", "Latte Tasks Types uncreatable");
qmlRegisterType<Latte::Quick::Dialog>(uri, 0, 1, "Dialog");
} }

View File

@ -23,6 +23,9 @@
// Qt // Qt
#include <QQmlExtensionPlugin> #include <QQmlExtensionPlugin>
// Plasma
#include <PlasmaQuick/Dialog>
class LatteTasksPlugin : public QQmlExtensionPlugin class LatteTasksPlugin : public QQmlExtensionPlugin
{ {
Q_OBJECT Q_OBJECT