Skip to content

Commit 5ffbe94

Browse files
Fixed showing selection popup
1 parent 61a46e9 commit 5ffbe94

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/presentation/desktop/readingPage/MDocumentView.qml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ Pane {
2424
event.accepted = true
2525
}
2626

27+
Connections {
28+
target: root.bookController
29+
30+
function onGoToPosition(pageNumber, y) {
31+
; // TODO
32+
}
33+
34+
function onTextSelectionFinished(centerX, topY) {
35+
selectionOptionsPopup.highlight = ""
36+
37+
internal.openSelectionOptionsPopup(centerX, topY)
38+
}
39+
40+
function onHighlightSelected(centerX, topY, highlightUuid) {
41+
// Remove selection if there is one when selecting a highlight
42+
activeFocusItem.removeSelection()
43+
selectionOptionsPopup.highlight = highlightUuid
44+
45+
internal.openSelectionOptionsPopup(centerX, topY)
46+
}
47+
}
48+
2749
Connections {
2850
target: DictionaryController
2951

@@ -151,6 +173,44 @@ Pane {
151173
y: root.height / 2 - translationPopup.height / 2
152174
}
153175

176+
QtObject {
177+
id: internal
178+
property string optionNameCursorModeHiddenAfterDelay: "Hidden after delay"
179+
180+
function openSelectionOptionsPopup(centerX, bottomY) {
181+
if (centerX === -1 && bottomY === -1) {
182+
centerX = selectionOptionsPopup.highlightCenterX
183+
bottomY = selectionOptionsPopup.highlightBottomY
184+
}
185+
selectionOptionsPopup.highlightCenterX = centerX
186+
selectionOptionsPopup.highlightBottomY = bottomY
187+
188+
internal.openPopupAt(selectionOptionsPopup, centerX, bottomY)
189+
}
190+
191+
function openPopupAt(popup, centerX, bottomY) {
192+
let pageYOffset = documentView.contentY - activeFocusItem.y
193+
let pageXOffset = documentView.contentX - activeFocusItem.x
194+
195+
let posY = bottomY + -pageYOffset + 6
196+
let spaceToBottom = (documentView.y + root.height) - (posY + popup.height)
197+
if (spaceToBottom < 0)
198+
posY = posY + spaceToBottom
199+
200+
let posX = centerX + documentView.x - popup.width / 2 - pageXOffset
201+
let spaceToRight = (documentView.x + documentView.width) - (posX + popup.width)
202+
if (spaceToRight < 0)
203+
posX = posX + spaceToRight
204+
205+
let spaceToLeft = (documentView.x + documentView.width) - (posX + popup.width)
206+
207+
popup.x = posX
208+
popup.y = posY
209+
210+
popup.open()
211+
}
212+
}
213+
154214
function setZoom(newZoom) {
155215
documentView.currentZoom = newZoom
156216
}

0 commit comments

Comments
 (0)