Skip to content

Commit 103a7a6

Browse files
committed
Removed Rectangle and Text and changed to NBox and NLabel
1 parent 455d8b0 commit 103a7a6

1 file changed

Lines changed: 208 additions & 0 deletions

File tree

ScreenShotOverlayCommon.qml

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
import QtQuick
2+
import QtQuick.Layouts
3+
import Quickshell.Wayland
4+
import qs.Commons
5+
import qs.Widgets
6+
7+
Item {
8+
id: overlay
9+
property var host: null
10+
11+
anchors.fill: parent
12+
13+
ScreencopyView {
14+
anchors.fill: parent
15+
live: false
16+
captureSource: host?.screen
17+
}
18+
19+
Repeater {
20+
model: host?.windowRegions ?? []
21+
delegate: NBox {
22+
required property var modelData
23+
z: 1
24+
x: modelData.x
25+
y: modelData.y
26+
width: modelData.width
27+
height: modelData.height
28+
color: targeted ? Color.mPrimaryContainer : "transparent"
29+
border.color: targeted ? Color.mPrimary : Color.mOnSurfaceVariant
30+
border.width: targeted ? Math.max(2, Math.round(3 * (host?.uiScale ?? 1))) : Math.max(1, Math.round(host?.uiScale ?? 1))
31+
visible: !(host?.dragging ?? false) && (host?.mouseOnThisScreen ?? false)
32+
33+
readonly property bool targeted:
34+
host?.hoveredWindow !== null && host?.hoveredWindow?.address === modelData.address
35+
36+
Behavior on border.width { NumberAnimation { duration: 80 } }
37+
Behavior on color { ColorAnimation { duration: 80 } }
38+
}
39+
}
40+
41+
NBox {
42+
id: darkenOverlay
43+
z: 1
44+
anchors {
45+
left: parent.left
46+
top: parent.top
47+
leftMargin: (host?.regionX ?? 0) - border.width
48+
topMargin: (host?.regionY ?? 0) - border.width
49+
}
50+
width: (host?.regionWidth ?? 0) + border.width * 2
51+
height: (host?.regionHeight ?? 0) + border.width * 2
52+
color: "transparent"
53+
border.color: Color.mErrorContainer
54+
border.width: Math.max(parent.width, parent.height)
55+
visible: (host?.dragging ?? false) && (host?.mouseOnThisScreen ?? false)
56+
}
57+
58+
NBox {
59+
z: 2
60+
x: host?.regionX ?? 0
61+
y: host?.regionY ?? 0
62+
width: host?.regionWidth ?? 0
63+
height: host?.regionHeight ?? 0
64+
color: "transparent"
65+
border.color: Color.mOnSurface
66+
border.width: Math.max(1, Math.round(2 * (host?.uiScale ?? 1)))
67+
visible: (host?.dragging ?? false) && (host?.mouseOnThisScreen ?? false)
68+
}
69+
70+
NLabel {
71+
z: 3
72+
x: (host?.regionX ?? 0) + (host?.regionWidth ?? 0) - width - (8 * (host?.uiScale ?? 1))
73+
y: (host?.regionY ?? 0) + (host?.regionHeight ?? 0) + (8 * (host?.uiScale ?? 1))
74+
text: (host?.dragging ?? false) ? `${Math.round(host?.regionWidth ?? 0)} x ${Math.round(host?.regionHeight ?? 0)}` : ""
75+
color: Color.mOnSurface
76+
font.pixelSize: Math.max(10, Math.round(13 * (host?.uiScale ?? 1)))
77+
visible: (host?.dragging ?? false) && (host?.mouseOnThisScreen ?? false)
78+
}
79+
80+
NBox {
81+
visible: (host?.mouseInside ?? false) && (host?.enableCross ?? false) && (host?.mouseOnThisScreen ?? false)
82+
opacity: 0.4
83+
z: 2
84+
x: host?.mouseX ?? 0
85+
anchors { top: parent.top; bottom: parent.bottom }
86+
width: Math.max(1, Math.round(host?.uiScale ?? 1))
87+
color: Color.mOnSurface
88+
}
89+
NBox {
90+
visible: (host?.mouseInside ?? false) && (host?.enableCross ?? false) && (host?.mouseOnThisScreen ?? false)
91+
opacity: 0.4
92+
z: 2
93+
y: host?.mouseY ?? 0
94+
anchors { left: parent.left; right: parent.right }
95+
height: Math.max(1, Math.round(host?.uiScale ?? 1))
96+
color: Color.mOnSurface
97+
}
98+
99+
NBox {
100+
anchors.fill: parent
101+
color: Color.mErrorContainer
102+
visible: !(host?.dragging ?? false) && (host?.mouseOnThisScreen ?? false)
103+
z: 0
104+
}
105+
106+
MouseArea {
107+
anchors.fill: parent
108+
hoverEnabled: true
109+
cursorShape: (host?.enableCross ?? false) ? Qt.CrossCursor : Qt.ArrowCursor
110+
acceptedButtons: Qt.LeftButton | Qt.RightButton
111+
z: 10
112+
113+
onPositionChanged: (mouse) => {
114+
host.mouseOnThisScreen = true
115+
host.mouseX = mouse.x
116+
host.mouseY = mouse.y
117+
host.mouseInside = true
118+
if (host.dragging) {
119+
host.draggingX = mouse.x
120+
host.draggingY = mouse.y
121+
} else if (typeof host.findWindowAt === "function") {
122+
host.hoveredWindow = host.findWindowAt(mouse.x, mouse.y)
123+
}
124+
}
125+
onEntered: {
126+
host.mouseOnThisScreen = true
127+
host.mouseInside = true
128+
}
129+
onExited: {
130+
host.mouseInside = false
131+
host.mouseOnThisScreen = false
132+
if (host.hoveredWindow !== undefined) {
133+
host.hoveredWindow = null
134+
}
135+
}
136+
onPressed: (mouse) => {
137+
host.dragStartX = mouse.x
138+
host.dragStartY = mouse.y
139+
host.draggingX = mouse.x
140+
host.draggingY = mouse.y
141+
host.dragging = true
142+
host.mouseButton = mouse.button
143+
}
144+
onReleased: (mouse) => {
145+
host.dragging = false
146+
host.finish()
147+
}
148+
}
149+
150+
NBox {
151+
id: rowBackground
152+
color: Color.mPrimary
153+
radius: Style.radiusM
154+
width: rowLayout.implicitWidth + Style.marginL * 2
155+
height: rowLayout.implicitHeight + Style.marginM * 2
156+
anchors.horizontalCenter: parent.horizontalCenter
157+
anchors.bottom: parent.bottom
158+
anchors.bottomMargin: Style.marginM
159+
z: 20
160+
visible: host?.mouseOnThisScreen ?? false
161+
opacity: (host?.mouseOnThisScreen ?? false) ? 1 : 0
162+
163+
RowLayout {
164+
z: 20
165+
id: rowLayout
166+
anchors.fill: parent
167+
anchors.margins: Style.marginM
168+
spacing: Style.marginM
169+
170+
NIcon {
171+
icon: host?.targetMeta?.iconForTarget(host?.target)
172+
color: Color.mOnPrimary
173+
}
174+
175+
NText {
176+
text: host?.targetMeta?.labelForTarget(host?.pluginApi, host?.target)
177+
color: Color.mOnPrimary
178+
}
179+
180+
NButton {
181+
z: 20
182+
icon: "close"
183+
backgroundColor: Color.mError
184+
textColor: Color.mOnError
185+
onClicked: {
186+
host?.closeSelector()
187+
}
188+
}
189+
}
190+
191+
Behavior on opacity { NumberAnimation { duration: Style.animationNormal; easing.type: Easing.OutQuad } }
192+
}
193+
194+
Item {
195+
anchors.fill: parent
196+
focus: true
197+
Keys.onPressed: (event) => {
198+
if (event.key === Qt.Key_Escape) {
199+
event.accepted = true
200+
host?.closeSelector()
201+
}
202+
}
203+
204+
Component.onCompleted: {
205+
forceActiveFocus()
206+
}
207+
}
208+
}

0 commit comments

Comments
 (0)