Verified Commit fd0b7475 authored by ivan tkachenko's avatar ivan tkachenko
Browse files

plasmoidviewer/shell: Sync to the plasma-desktop code

See also: plasma-desktop!966
parent 1d9daac3
Pipeline #184862 passed with stage
in 59 seconds
/*
* SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.plasmoid 2.0
import org.kde.kquickcontrolsaddons 2.0
......@@ -30,85 +29,88 @@ PlasmaCore.ToolTipArea {
onCompactRepresentationChanged: {
if (compactRepresentation) {
compactRepresentation.parent = root;
compactRepresentation.anchors.fill = root;
compactRepresentation.anchors.fill = null;
compactRepresentation.parent = compactRepresentationParent;
compactRepresentation.anchors.fill = compactRepresentationParent;
compactRepresentation.visible = true;
}
root.visible = true;
}
onFullRepresentationChanged: {
if (!fullRepresentation) {
return;
if (fullRepresentation) {
fullRepresentation.anchors.fill = null;
fullRepresentation.parent = appletParent;
fullRepresentation.anchors.fill = appletParent;
}
}
//if the fullRepresentation size was restored to a stored size, or if is dragged from the desktop, restore popup size
if (fullRepresentation.Layout && fullRepresentation.Layout.preferredWidth > 0) {
popupWindow.mainItem.width = Qt.binding(function() {
return fullRepresentation.Layout.preferredWidth
})
} else if (fullRepresentation.implicitWidth > 0) {
popupWindow.mainItem.width = Qt.binding(function() {
return fullRepresentation.implicitWidth
})
} else if (fullRepresentation.width > 0) {
popupWindow.mainItem.width = Qt.binding(function() {
return fullRepresentation.width
})
} else {
popupWindow.mainItem.width = Qt.binding(function() {
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).width * 35
})
FocusScope {
id: compactRepresentationParent
anchors.fill: parent
activeFocusOnTab: true
onActiveFocusChanged: {
// When the scope gets the active focus, try to focus its first descendant,
// if there is on which has activeFocusOnTab
if (!activeFocus) {
return;
}
let nextItem = nextItemInFocusChain();
let candidate = nextItem;
while (candidate.parent) {
if (candidate === compactRepresentationParent) {
nextItem.forceActiveFocus();
return;
}
candidate = candidate.parent;
}
}
if (fullRepresentation.Layout && fullRepresentation.Layout.preferredHeight > 0) {
popupWindow.mainItem.height = Qt.binding(function() {
return fullRepresentation.Layout.preferredHeight
})
} else if (fullRepresentation.implicitHeight > 0) {
popupWindow.mainItem.height = Qt.binding(function() {
return fullRepresentation.implicitHeight
})
} else if (fullRepresentation.height > 0) {
popupWindow.mainItem.height = Qt.binding(function() {
return fullRepresentation.height
})
} else {
popupWindow.mainItem.height = Qt.binding(function() {
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height * 25
})
Accessible.name: root.mainText
Accessible.description: i18n("Open %1", root.subText)
Accessible.role: Accessible.Button
Accessible.onPressAction: Plasmoid.nativeInterface.activated()
Keys.onPressed: {
switch (event.key) {
case Qt.Key_Space:
case Qt.Key_Enter:
case Qt.Key_Return:
case Qt.Key_Select:
Plasmoid.nativeInterface.activated();
break;
}
}
fullRepresentation.parent = appletParent;
fullRepresentation.anchors.fill = fullRepresentation.parent;
}
PlasmaCore.FrameSvgItem {
id: expandedItem
// skip containerMargins code from plasma-desktop, as we are not on a panel here.
anchors.fill: parent
imagePath: "widgets/tabbar"
visible: fromCurrentTheme && opacity > 0
prefix: {
var prefix;
let prefix;
switch (Plasmoid.location) {
case PlasmaCore.Types.LeftEdge:
prefix = "west-active-tab";
break;
case PlasmaCore.Types.TopEdge:
prefix = "north-active-tab";
break;
case PlasmaCore.Types.RightEdge:
prefix = "east-active-tab";
break;
default:
prefix = "south-active-tab";
}
if (!hasElementPrefix(prefix)) {
prefix = "active-tab";
}
return prefix;
case PlasmaCore.Types.LeftEdge:
prefix = "west-active-tab";
break;
case PlasmaCore.Types.TopEdge:
prefix = "north-active-tab";
break;
case PlasmaCore.Types.RightEdge:
prefix = "east-active-tab";
break;
default:
prefix = "south-active-tab";
}
if (!hasElementPrefix(prefix)) {
prefix = "active-tab";
}
return prefix;
}
opacity: Plasmoid.expanded ? 1 : 0
Behavior on opacity {
NumberAnimation {
......@@ -126,13 +128,16 @@ PlasmaCore.ToolTipArea {
Connections {
target: Plasmoid.action("configure")
function onTriggered() { Plasmoid.expanded = false }
function onTriggered() {
if (Plasmoid.hideOnWindowDeactivate) {
Plasmoid.expanded = false
}
}
}
Connections {
// TODO KF6: strip `.self` as it is a workaround that is no longer needed in Qt 6
target: Plasmoid.self
function onContextualActionsAboutToShow() { root.hideToolTip() }
function onContextualActionsAboutToShow() { root.hideImmediately() }
}
PlasmaCore.Dialog {
......@@ -140,12 +145,18 @@ PlasmaCore.ToolTipArea {
objectName: "popupWindow"
flags: Qt.WindowStaysOnTopHint
visible: Plasmoid.expanded && fullRepresentation
visualParent: compactRepresentation ? compactRepresentation : null
visualParent: root.compactRepresentation
location: Plasmoid.location
hideOnWindowDeactivate: Plasmoid.hideOnWindowDeactivate
backgroundHints: (Plasmoid.containmentDisplayHints & PlasmaCore.Types.DesktopFullyCovered) ? PlasmaCore.Dialog.SolidBackground : PlasmaCore.Dialog.StandardBackground
property var oldStatus: PlasmaCore.Types.UnknownStatus
appletInterface: {
if (!fullRepresentation || !fullRepresentation.appletInterface)
return null
return fullRepresentation.appletInterface
}
type: PlasmaCore.Dialog.AppletPopup
//It's a MouseEventListener to get all the events, so the eventfilter will be able to catch them
mainItem: MouseEventListener {
......@@ -160,20 +171,43 @@ PlasmaCore.ToolTipArea {
LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
LayoutMirroring.childrenInherit: true
Layout.minimumWidth: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.minimumWidth : 0
Layout.minimumHeight: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.minimumHeight: 0
Layout.minimumWidth: fullRepresentation ? fullRepresentation.Layout.minimumWidth : 0
Layout.minimumHeight: fullRepresentation ? fullRepresentation.Layout.minimumHeight : 0
Layout.preferredWidth: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.preferredWidth : -1
Layout.preferredHeight: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.preferredHeight: -1
Layout.preferredWidth: fullRepresentation ? fullRepresentation.Layout.preferredWidth : -1
Layout.preferredHeight: fullRepresentation ? fullRepresentation.Layout.preferredHeight : -1
Layout.maximumWidth: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.maximumWidth : Infinity
Layout.maximumHeight: (fullRepresentation && fullRepresentation.Layout) ? fullRepresentation.Layout.maximumHeight: Infinity
Layout.maximumWidth: fullRepresentation ? fullRepresentation.Layout.maximumWidth : Infinity
Layout.maximumHeight: fullRepresentation ? fullRepresentation.Layout.maximumHeight : Infinity
width: {
if (root.fullRepresentation !== null) {
/****/ if (root.fullRepresentation.Layout.preferredWidth > 0) {
return root.fullRepresentation.Layout.preferredWidth;
} else if (root.fullRepresentation.implicitWidth > 0) {
return root.fullRepresentation.implicitWidth;
}
}
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).width * 35;
}
height: {
if (root.fullRepresentation !== null) {
/****/ if (fullRepresentation.Layout.preferredHeight > 0) {
return fullRepresentation.Layout.preferredHeight;
} else if (fullRepresentation.implicitHeight > 0) {
return fullRepresentation.implicitHeight;
}
}
return PlasmaCore.Theme.mSize(PlasmaCore.Theme.defaultFont).height * 25;
}
onActiveFocusChanged: {
if (activeFocus && fullRepresentation) {
fullRepresentation.forceActiveFocus()
}
}
// skip a line between the applet dialog and the panel code from plasma-desktop, as we are not on a panel here.
}
onVisibleChanged: {
......@@ -188,6 +222,5 @@ PlasmaCore.ToolTipArea {
popupWindow.requestActivate();
}
}
}
}
/*
* SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
import QtQuick 2.0
import QtQuick.Layouts 1.1
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
PlasmaCore.IconItem {
id: icon
readonly property bool inPanel: (Plasmoid.location === PlasmaCore.Types.TopEdge
|| Plasmoid.location === PlasmaCore.Types.RightEdge
|| Plasmoid.location === PlasmaCore.Types.BottomEdge
|| Plasmoid.location === PlasmaCore.Types.LeftEdge)
readonly property bool inPanel: [PlasmaCore.Types.TopEdge, PlasmaCore.Types.RightEdge, PlasmaCore.Types.BottomEdge, PlasmaCore.Types.LeftEdge]
.includes(Plasmoid.location)
Layout.minimumWidth: {
switch (Plasmoid.formFactor) {
......@@ -40,10 +36,10 @@ PlasmaCore.IconItem {
}
}
Layout.maximumWidth: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1;
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1;
Layout.maximumWidth: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
Layout.maximumHeight: inPanel ? PlasmaCore.Units.iconSizeHints.panel : -1
source: Plasmoid.icon ? Plasmoid.icon : "plasma"
source: Plasmoid.icon || "plasma"
active: mouseArea.containsMouse
MouseArea {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment