melawy-plasma-plasmoid-Menu.../AndromedaLauncher/contents/ui/MenuRepresentation.qml

262 lines
9.8 KiB
QML

/*****************************************************************************
* Copyright (C) 2014 by Weng Xuetian <wengxt@gmail.com> *
* Copyright (C) 2013-2017 by Eike Hein <hein@kde.org> *
* Copyright (C) 2021 by Prateek SU <pankajsunal123@gmail.com> *
* Copyright (C) 2022 by Friedrich Schriewer <friedrich.schriewer@gmx.net> *
* *
* This program 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. *
* *
* This program 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
****************************************************************************/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQml 2.15
import org.kde.plasma.core as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.plasmoid 2.0
import org.kde.kirigami as Kirigami
PlasmaCore.Dialog {
id: root
objectName: "popupWindow"
flags: Qt.WindowStaysOnTopHint
location: Plasmoid.configuration.floating || Plasmoid.configuration.launcherPosition == 2 ? "Floating" : Plasmoid.location
hideOnWindowDeactivate: true
Plasmoid.status: root.visible ? PlasmaCore.Types.RequiresAttentionStatus : PlasmaCore.Types.PassiveStatus
property int iconSize: {
switch(Plasmoid.configuration.appsIconSize){
case 0: return Kirigami.Units.iconSizes.smallMedium;
case 1: return Kirigami.Units.iconSizes.medium;
case 2: return Kirigami.Units.iconSizes.large;
case 3: return Kirigami.Units.iconSizes.huge;
default: return 64
}
}
property int cellSizeHeight: iconSize
+ Kirigami.Units.gridUnit * 2
+ (2 * Math.max(highlightItemSvg.margins.top + highlightItemSvg.margins.bottom,
highlightItemSvg.margins.left + highlightItemSvg.margins.right))
property int cellSizeWidth: cellSizeHeight //+ Kirigami.Units.gridUnit
onVisibleChanged: {
if (!visible) {
reset();
} else {
main.updateStartpage()
var pos = popupPosition(width, height);
x = pos.x;
y = pos.y;
requestActivate();
}
}
onHeightChanged: {
var pos = popupPosition(width, height);
x = pos.x;
y = pos.y;
}
onWidthChanged: {
var pos = popupPosition(width, height);
x = pos.x;
y = pos.y;
}
function toggle() {
root.visible = false;
}
function reset() {
main.reset()
}
// function popupPosition(width, height) {
// var screenAvail = Plasmoid.availableScreenRect;
// var screen = kicker.screenGeometry;
//
// var offset = 0
//
// if (Plasmoid.configuration.offsetX > 0 && Plasmoid.configuration.floating) {
// offset = Plasmoid.configuration.offsetX
// } else {
// offset = plasmoid.configuration.floating ? parent.height * 0.35 : 0
// }
// // Fall back to bottom-left of screen area when the applet is on the desktop or floating.
// var x = offset;
// var y = screen.height - height - offset;
// var horizMidPoint = screen.x + (screen.width / 2);
// var vertMidPoint = screen.y + (screen.height / 2);
// var appletTopLeft = parent.mapToGlobal(0, 0);
// var appletBottomLeft = parent.mapToGlobal(0, parent.height);
//
// if (Plasmoid.configuration.launcherPosition != 0){
// x = horizMidPoint - width / 2;
// } else {
// x = (appletTopLeft.x < horizMidPoint) ? screen.x : (screen.x + screen.width) - width;
// if (Plasmoid.configuration.floating) {
// if (appletTopLeft.x < horizMidPoint) {
// x += offset
// } else if (appletTopLeft.x + width > horizMidPoint){
// x -= offset
// }
// }
// }
//
// if (Plasmoid.configuration.launcherPosition != 2){
// if (Plasmoid.location == PlasmaCore.Types.TopEdge) {
// if (Plasmoid.configuration.floating) {
// /*this is floatingAvatar.width*/
// if (Plasmoid.configuration.offsetY > 0) {
// offset = (125 * 1) / 2 + Plasmoid.configuration.offsetY
// } else {
// offset = (125 * 1) / 2 + parent.height * 0.125
// }
// }
// y = screen.y + parent.height + panelSvg.margins.bottom + offset;
// } else {
// if (Plasmoid.configuration.offsetY > 0) {
// offset = Plasmoid.configuration.offsetY
// }
// y = screen.y + screen.height - parent.height - height - panelSvg.margins.top - offset * 2.5;
// }
// } else {
// y = vertMidPoint - height / 2
// }
//
// return Qt.point(x, y);
// }
function popupPosition(width, height) {
var screenAvail = kicker.availableScreenRect;
var screen = kicker.screenGeometry;
// var offset = 0
var offset = Kirigami.Units.smallSpacing * 2;
// Fall back to bottom-left of screen area when the applet is on the desktop or floating.
var x = offset;
var y = screen.height - height - offset;
var horizMidPoint = screen.x + (screen.width / 2);
var vertMidPoint = screen.y + (screen.height / 2);
var panelH = kicker.height
var panelW = kicker.width
var appletTopLeft = parent.mapToGlobal(0, 0);
var appletBottomLeft = parent.mapToGlobal(0, parent.height);
switch (Plasmoid.configuration.launcherPosition) {
case 0:
switch (plasmoid.location) {
case PlasmaCore.Types.BottomEdge:
var y = appletTopLeft.y - height - offset
var x = appletTopLeft.x
break;
case PlasmaCore.Types.TopEdge:
x = appletTopLeft.x < screen.width - width ? appletTopLeft.x + panelW - Kirigami.Units.gridUnit / 3 : screen.width - width;
y = appletTopLeft.y + kicker.height + Kirigami.Units.gridUnit
break;
case PlasmaCore.Types.LeftEdge:
x = appletTopLeft.x + panelW + Kirigami.Units.gridUnit / 2;
y = appletTopLeft.y < screen.height - height ? appletTopLeft.y : appletTopLeft.y - height + iconUser.height / 2;
break;
case PlasmaCore.Types.RightEdge:
x = appletTopLeft.x - width - Kirigami.Units.gridUnit / 2;
y = appletTopLeft.y < screen.height - height ? appletTopLeft.y : screen.height - height - Kirigami.Units.gridUnit / 5;
break;
default:
return;
}
break;
case 1:
horizMidPoint = screen.x + (screen.width / 2);
vertMidPoint = screen.y + (screen.height / 2);
x = horizMidPoint - width / 2;
// y = screen.y + screen.height - height - offset - panelH - Kirigami.Units.gridUnit;
// y = screen.y + screen.height - height - offset - panelH - Kirigami.Units.gridUnit / 2;
y = screen.y + screen.height - height - offset - panelH - Kirigami.Units.largeSpacing * 1.5;
break;
case 2:
horizMidPoint = screen.x + (screen.width / 2);
vertMidPoint = screen.y + (screen.height / 2);
x = horizMidPoint - width / 2;
y = vertMidPoint - height / 2;
break;
default:
return;
}
return Qt.point(x, y);
}
FocusScope {
id: fs
focus: true
Layout.minimumWidth: (root.cellSizeWidth * Plasmoid.configuration.numberColumns) + scrollBarMetrics.width + innerPadding*2
Layout.minimumHeight: 550 * 1
Layout.maximumWidth: Layout.minimumWidth
Layout.maximumHeight: Layout.minimumHeight
// We want the MainView to have an uniform margin through different plasma themes
property real innerPadding: 15
Item {
id: mainItem
x: - dialogSvg.margins.left
y: - dialogSvg.margins.top
width: parent.width + dialogSvg.margins.left + dialogSvg.margins.right
height: parent.height + dialogSvg.margins.top + dialogSvg.margins.bottom
MainView {
id: main
width: mainItem.width - (fs.innerPadding*2)
height: mainItem.height - (fs.innerPadding*2)
x: fs.innerPadding
y: fs.innerPadding
}
}
Keys.onPressed: event => {
if (event.key == Qt.Key_Escape) {
root.visible = false;
}
}
}
function refreshModel() {
main.reload()
}
Component.onCompleted: {
kicker.reset.connect(reset);
// windowSystem.hidden.connect(reset);
rootModel.refresh();
}
}