mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-08 06:28:27 -04:00
Squashed commit of the following:
commit990d86d481Author: bbedward <bbedward@gmail.com> Date: Sat Jul 18 10:43:22 2026 -0400 flake: update-common commit526cb157fdAuthor: bbedward <bbedward@gmail.com> Date: Thu Jul 16 17:56:40 2026 -0400 i18n: update sync scrirpt for dank-qml-common commit92ba96d9f9Author: bbedward <bbedward@gmail.com> Date: Thu Jul 16 09:24:37 2026 -0400 qs: integrate with dank-qml-common
This commit is contained in:
@@ -1,154 +1,3 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Common
|
||||
import qs.DankCommon.Widgets as DankCommon
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property string text: ""
|
||||
|
||||
function show(text, item, offsetX, offsetY, preferredSide) {
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
let windowContentItem = item.Window?.window?.contentItem;
|
||||
if (!windowContentItem) {
|
||||
let current = item;
|
||||
while (current) {
|
||||
if (current.Window?.window?.contentItem) {
|
||||
windowContentItem = current.Window.window.contentItem;
|
||||
break;
|
||||
}
|
||||
current = current.parent;
|
||||
}
|
||||
}
|
||||
if (!windowContentItem)
|
||||
return;
|
||||
|
||||
tooltip.parent = windowContentItem;
|
||||
tooltip.text = text;
|
||||
|
||||
const itemPos = item.mapToItem(windowContentItem, 0, 0);
|
||||
const parentWidth = windowContentItem.width;
|
||||
const parentHeight = windowContentItem.height;
|
||||
const tooltipWidth = tooltip.implicitWidth;
|
||||
const tooltipHeight = tooltip.implicitHeight;
|
||||
|
||||
const side = preferredSide || _determineBestSide(itemPos, item, parentWidth, parentHeight, tooltipWidth, tooltipHeight);
|
||||
|
||||
let targetX = 0;
|
||||
let targetY = 0;
|
||||
|
||||
switch (side) {
|
||||
case "left":
|
||||
targetX = itemPos.x - tooltipWidth - 8;
|
||||
targetY = itemPos.y + (item.height - tooltipHeight) / 2;
|
||||
break;
|
||||
case "right":
|
||||
targetX = itemPos.x + item.width + 8;
|
||||
targetY = itemPos.y + (item.height - tooltipHeight) / 2;
|
||||
break;
|
||||
case "top":
|
||||
targetX = itemPos.x + (item.width - tooltipWidth) / 2;
|
||||
targetY = itemPos.y - tooltipHeight - 8;
|
||||
break;
|
||||
case "bottom":
|
||||
default:
|
||||
targetX = itemPos.x + (item.width - tooltipWidth) / 2;
|
||||
targetY = itemPos.y + item.height + 8;
|
||||
break;
|
||||
}
|
||||
|
||||
tooltip.x = Math.max(4, Math.min(parentWidth - tooltipWidth - 4, targetX + (offsetX || 0)));
|
||||
tooltip.y = Math.max(4, Math.min(parentHeight - tooltipHeight - 4, targetY + (offsetY || 0)));
|
||||
|
||||
tooltip.open();
|
||||
}
|
||||
|
||||
function _determineBestSide(itemPos, item, parentWidth, parentHeight, tooltipWidth, tooltipHeight) {
|
||||
const itemCenterX = itemPos.x + item.width / 2;
|
||||
const itemCenterY = itemPos.y + item.height / 2;
|
||||
|
||||
const spaceLeft = itemPos.x;
|
||||
const spaceRight = parentWidth - (itemPos.x + item.width);
|
||||
const spaceTop = itemPos.y;
|
||||
const spaceBottom = parentHeight - (itemPos.y + item.height);
|
||||
|
||||
if (spaceRight >= tooltipWidth + 16) {
|
||||
return "right";
|
||||
}
|
||||
if (spaceLeft >= tooltipWidth + 16) {
|
||||
return "left";
|
||||
}
|
||||
if (spaceBottom >= tooltipHeight + 16) {
|
||||
return "bottom";
|
||||
}
|
||||
if (spaceTop >= tooltipHeight + 16) {
|
||||
return "top";
|
||||
}
|
||||
|
||||
if (itemCenterX > parentWidth / 2) {
|
||||
return "left";
|
||||
}
|
||||
return "right";
|
||||
}
|
||||
|
||||
function hide() {
|
||||
tooltip.close();
|
||||
}
|
||||
|
||||
Popup {
|
||||
id: tooltip
|
||||
|
||||
property string text: ""
|
||||
|
||||
leftPadding: Theme.spacingM
|
||||
rightPadding: Theme.spacingM
|
||||
topPadding: Theme.spacingS
|
||||
bottomPadding: Theme.spacingS
|
||||
closePolicy: Popup.NoAutoClose
|
||||
modal: false
|
||||
dim: false
|
||||
|
||||
background: Rectangle {
|
||||
color: Theme.surfaceContainerHigh
|
||||
radius: Theme.cornerRadius
|
||||
border.width: 1
|
||||
border.color: Theme.outlineMedium
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
id: textContent
|
||||
|
||||
width: Math.min(implicitWidth, 500)
|
||||
text: tooltip.text
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceText
|
||||
wrapMode: Text.NoWrap
|
||||
maximumLineCount: 1
|
||||
elide: Text.ElideRight
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
enter: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 0
|
||||
to: 1
|
||||
duration: Theme.shortDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
}
|
||||
|
||||
exit: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 1
|
||||
to: 0
|
||||
duration: Theme.shorterDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DankCommon.DankTooltipV2 {}
|
||||
|
||||
Reference in New Issue
Block a user