172 lines
6.6 KiB
QML
172 lines
6.6 KiB
QML
// SPDX-License-Identifier: MIT
|
|
import QtQuick
|
|
import QtTest
|
|
import "../controller/contents/ui/areas.js" as Areas
|
|
|
|
Item {
|
|
id: scene
|
|
property Item containment: edges
|
|
property int leftPadding: edges.vertical ? 8 : 12
|
|
property int rightPadding: edges.vertical ? 8 : 14
|
|
property int topPadding: edges.vertical ? 12 : 8
|
|
property int bottomPadding: edges.vertical ? 14 : 8
|
|
width: 600
|
|
height: 100
|
|
Item {
|
|
id: panel
|
|
x: 30
|
|
y: 20
|
|
width: 500
|
|
height: 40
|
|
Item {
|
|
width: 200
|
|
height: 40
|
|
property alias applet: tasks
|
|
Item {
|
|
id: tasks
|
|
anchors.fill: parent
|
|
property QtObject plasmoid: QtObject { property string pluginName: "org.kde.plasma.taskmanager" }
|
|
Item {
|
|
id: button
|
|
width: 80
|
|
height: 40
|
|
property Item tasksRoot: tasks
|
|
property bool isWindow: true
|
|
property int index: 0
|
|
}
|
|
}
|
|
}
|
|
Item {
|
|
x: 200
|
|
width: 60
|
|
height: 40
|
|
property QtObject applet: QtObject {
|
|
property QtObject plasmoid: QtObject { property string pluginName: "org.kde.plasma.systemtray" }
|
|
}
|
|
}
|
|
Item {
|
|
id: arbitraryWidget
|
|
x: 260
|
|
width: 60
|
|
height: 40
|
|
property QtObject applet: QtObject {
|
|
property QtObject plasmoid: QtObject { property string pluginName: "third.party.widget" }
|
|
}
|
|
}
|
|
}
|
|
Item {
|
|
id: edges
|
|
x: 40
|
|
y: 10
|
|
property bool vertical: false
|
|
property bool reversed: false
|
|
width: vertical ? 60 : 400
|
|
height: vertical ? 400 : 60
|
|
Item { width: 0; height: 60 } // invisible controller's zero-width slot
|
|
Item { x: -100; y: -100; width: 50; height: 50; visible: false }
|
|
Item {
|
|
id: launcher
|
|
x: edges.vertical ? 8 : edges.reversed ? 350 : 12
|
|
y: edges.vertical ? (edges.reversed ? 350 : 12) : 8
|
|
width: edges.vertical ? 44 : 36
|
|
height: edges.vertical ? 36 : 44
|
|
property QtObject applet: QtObject {
|
|
property QtObject plasmoid: QtObject { property string pluginName: "org.kde.plasma.kickoff" }
|
|
}
|
|
}
|
|
Item {
|
|
x: edges.vertical ? 8 : 90
|
|
y: edges.vertical ? 90 : 8
|
|
width: edges.vertical ? 44 : 80
|
|
height: edges.vertical ? 80 : 44
|
|
property QtObject applet: QtObject {
|
|
property QtObject plasmoid: QtObject { property string pluginName: "org.kde.plasma.panelspacer" }
|
|
}
|
|
}
|
|
Item {
|
|
id: clock
|
|
x: edges.vertical ? 8 : edges.reversed ? 12 : 350
|
|
y: edges.vertical ? (edges.reversed ? 12 : 350) : 8
|
|
width: edges.vertical ? 44 : 36
|
|
height: edges.vertical ? 36 : 44
|
|
property QtObject applet: QtObject {
|
|
property QtObject plasmoid: QtObject { property string pluginName: "org.kde.plasma.digitalclock" }
|
|
}
|
|
}
|
|
}
|
|
TestCase {
|
|
name: "PanelAreas"
|
|
when: windowShown
|
|
function init() {
|
|
edges.vertical = false;
|
|
edges.reversed = false;
|
|
edges.x = 40;
|
|
launcher.visible = true;
|
|
}
|
|
function areaAt(along, across) {
|
|
const p = edges.mapToItem(null, edges.vertical ? across : along, edges.vertical ? along : across);
|
|
return Areas.areaAt(edges, p.x, p.y, scene);
|
|
}
|
|
function test_panelMargins_data() {
|
|
return [
|
|
{tag: "horizontal", vertical: false, x: 40},
|
|
{tag: "vertical", vertical: true, x: 40},
|
|
{tag: "fractional-origin", vertical: false, x: 40.5},
|
|
{tag: "vertical-fractional-origin", vertical: true, x: 40.5}
|
|
];
|
|
}
|
|
function test_panelMargins(data) {
|
|
edges.vertical = data.vertical;
|
|
edges.x = data.x;
|
|
compare(areaAt(-20, 58), "launcher"); // leading outer corner
|
|
compare(areaAt(30, 2), "launcher"); // thickness padding above/beside icon
|
|
compare(areaAt(420, 58), "clock"); // trailing outer corner
|
|
compare(areaAt(386, 52), "clock"); // exclusive bottom/right boundaries
|
|
compare(areaAt(385.75, 51.75), "clock"); // fractional positions just inside
|
|
compare(areaAt(65, 58), "empty"); // internal gap
|
|
compare(areaAt(120, 58), "empty"); // explicit spacer
|
|
compare(areaAt(200, 58), "empty");
|
|
edges.reversed = true; // physical order, not QObject child order
|
|
compare(areaAt(-20, 58), "clock");
|
|
compare(areaAt(420, 58), "launcher");
|
|
}
|
|
function test_panelViewDiscovery() {
|
|
compare(Areas.panelViewFor(launcher), scene);
|
|
const inside = launcher.mapToItem(null, 10, 10);
|
|
compare(Areas.areaAt(edges, inside.x, inside.y, scene), "launcher");
|
|
compare(Areas.areaAt(edges, inside.x, inside.y, null), "");
|
|
}
|
|
function test_hiddenAndZeroSizeDoNotOwnPadding() {
|
|
launcher.visible = false;
|
|
compare(areaAt(-20, 58), "empty"); // don't stretch the next widget into a real gap
|
|
compare(Areas.areaAt(null, 0, 0, scene), "");
|
|
}
|
|
function taskArea(x, y) {
|
|
return Areas.areaAt(panel, x, y, {containment: panel,
|
|
leftPadding: 0, rightPadding: 0, topPadding: 0, bottomPadding: 0});
|
|
}
|
|
function test_taskThicknessPaddingKeepsUnusedSpaceEmpty() {
|
|
compare(taskArea(40, 65), "tasks");
|
|
compare(taskArea(150, 65), "empty");
|
|
compare(taskArea(0, 65), "tasks");
|
|
}
|
|
function test_taskButtonsVersusUnusedSpace() {
|
|
compare(taskArea(40, 30), "tasks");
|
|
compare(taskArea(150, 30), "empty");
|
|
button.isWindow = false; // pinned launchers still count as buttons
|
|
compare(taskArea(40, 30), "tasks");
|
|
button.visible = false;
|
|
compare(taskArea(40, 30), "empty");
|
|
button.visible = true;
|
|
}
|
|
function test_trayAndUnrecognizedWidgetsKeepClicks() {
|
|
compare(taskArea(240, 30), "tray");
|
|
compare(taskArea(300, 30), "other");
|
|
arbitraryWidget.visible = false;
|
|
compare(taskArea(300, 30), "empty");
|
|
arbitraryWidget.visible = true;
|
|
compare(Areas.areaAt(null, 40, 30, scene), "");
|
|
}
|
|
}
|
|
}
|