Warning, /plasma/plasma-workspace/kcms/wallpaper/ui/ScreenView.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
0003 SPDX-FileCopyrightText: 2023 Méven Car <meven@kde.org>
0004
0005 SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC2
0010
0011 QQC2.Pane {
0012 id: pane
0013
0014 signal screenSelected(string screenName)
0015
0016 property var outputs
0017 property var selectedScreen
0018
0019 readonly property int xOffset: (width - totalSize.width / relativeFactor) / 2;
0020 readonly property int yOffset: (height - totalSize.height / relativeFactor) / 2;
0021
0022 readonly property rect totalSize: {
0023 var topleft_x = outputs[0].geometry.x;
0024 var topleft_y = outputs[0].geometry.y;
0025 var bottomRight_x = outputs[0].geometry.x + outputs[0].geometry.width;
0026 var bottomRight_y = outputs[0].geometry.y + outputs[0].geometry.height;
0027
0028 for (let i = 1; i < outputs.length; ++i) {
0029 var out = outputs[i].geometry
0030
0031 if (out.x < topleft_x) {
0032 topleft_x = out.x
0033 }
0034 if (out.y < topleft_y) {
0035 topleft_y = out.y
0036 }
0037 if (out.x + out.width > bottomRight_x) {
0038 bottomRight_x = out.x + out.width
0039 }
0040 if (out.y + out.height > bottomRight_y) {
0041 bottomRight_y = out.y + out.height
0042 }
0043 }
0044 return Qt.rect(topleft_x, topleft_y, bottomRight_x - topleft_x, bottomRight_y - topleft_y);
0045 }
0046
0047 readonly property real relativeFactor: {
0048 var relativeSize = Qt.size(width === 0 ? 1 : totalSize.width / (0.8 * width),
0049 height === 0 ? 1 : totalSize.height / (0.8 * height));
0050 if (relativeSize.width > relativeSize.height) {
0051 // Available width smaller than height, optimize for width (we have
0052 // '>' because the available width, height is in the denominator).
0053 return relativeSize.width;
0054 } else {
0055 return relativeSize.height;
0056 }
0057 }
0058
0059 Repeater {
0060 model: outputs
0061 delegate: Output {
0062 relativeFactor: pane.relativeFactor
0063 xOffset: pane.xOffset
0064 yOffset: pane.yOffset
0065 screen: outputs[index]
0066 onScreenSelected: (screenName) => { pane.screenSelected(screenName) }
0067 isSelected: pane.selectedScreen ? outputs[index].name === pane.selectedScreen.name : false
0068 }
0069 }
0070 }