Skip to content

Commit c753dbe

Browse files
committed
trying to fix the hover issue on Ubuntu
1 parent 274e1ff commit c753dbe

6 files changed

Lines changed: 104 additions & 63 deletions

File tree

EasyReflectometryApp/Gui/Pages/Analysis/MainContent/AnalysisView.qml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Rectangle {
133133
axisY.minAfterReset: Globals.BackendWrapper.plottingAnalysisMinY - yRange * 0.01
134134
axisY.maxAfterReset: Globals.BackendWrapper.plottingAnalysisMaxY + yRange * 0.01
135135

136-
calcSerie.onHovered: (point, state) => showMainTooltip(chartView, point, state)
136+
onChartHovered: (chartX, chartY, screenX, screenY, active) => showMainTooltip(chartX, chartY, screenX, screenY, active)
137137
calcSerie.color: {
138138
const models = Globals.BackendWrapper.sampleModels
139139
const idx = Globals.BackendWrapper.sampleCurrentModelIndex
@@ -445,15 +445,14 @@ Rectangle {
445445

446446
// Logic
447447

448-
function showMainTooltip(chart, point, state) {
448+
function showMainTooltip(chartX, chartY, screenX, screenY, active) {
449449
if (!chartView.allowHover) {
450450
return
451451
}
452-
const pos = chart.mapToPosition(Qt.point(point.x, point.y))
453-
dataToolTip.x = pos.x
454-
dataToolTip.y = pos.y
455-
dataToolTip.text = `<p align="left">x: ${point.x.toFixed(3)}<br\>y: ${point.y.toFixed(3)}</p>`
456-
dataToolTip.parent = chart
457-
dataToolTip.visible = state
452+
dataToolTip.x = screenX
453+
dataToolTip.y = screenY
454+
dataToolTip.text = `<p align="left">x: ${chartX.toFixed(3)}<br\>y: ${chartY.toFixed(3)}</p>`
455+
dataToolTip.parent = chartView
456+
dataToolTip.visible = active
458457
}
459458
}

EasyReflectometryApp/Gui/Pages/Analysis/MainContent/CombinedView.qml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Rectangle {
256256
axisY.minAfterReset: Globals.BackendWrapper.plottingAnalysisMinY - yRange * 0.01
257257
axisY.maxAfterReset: Globals.BackendWrapper.plottingAnalysisMaxY + yRange * 0.01
258258

259-
calcSerie.onHovered: (point, state) => showMainTooltip(analysisChartView, analysisDataToolTip, point, state)
259+
onChartHovered: (chartX, chartY, screenX, screenY, active) => showMainTooltip(analysisChartView, analysisDataToolTip, chartX, chartY, screenX, screenY, active)
260260
calcSerie.color: {
261261
const models = Globals.BackendWrapper.sampleModels
262262
const idx = Globals.BackendWrapper.sampleCurrentModelIndex
@@ -473,15 +473,14 @@ Rectangle {
473473
}
474474

475475
// Logic
476-
function showMainTooltip(chart, tooltip, point, state) {
476+
function showMainTooltip(chart, tooltip, chartX, chartY, screenX, screenY, active) {
477477
if (!chart.allowHover) {
478478
return
479479
}
480-
const pos = chart.mapToPosition(Qt.point(point.x, point.y))
481-
tooltip.x = pos.x
482-
tooltip.y = pos.y
483-
tooltip.text = `<p align="left">x: ${point.x.toFixed(3)}<br\>y: ${point.y.toFixed(3)}</p>`
480+
tooltip.x = screenX
481+
tooltip.y = screenY
482+
tooltip.text = `<p align="left">x: ${chartX.toFixed(3)}<br\>y: ${chartY.toFixed(3)}</p>`
484483
tooltip.parent = chart
485-
tooltip.visible = state
484+
tooltip.visible = active
486485
}
487486
}

EasyReflectometryApp/Gui/Pages/Experiment/MainContent/ExperimentView.qml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Rectangle {
220220
axisY.minAfterReset: Globals.BackendWrapper.plottingExperimentMinY - yRange * 0.01
221221
axisY.maxAfterReset: Globals.BackendWrapper.plottingExperimentMaxY + yRange * 0.01
222222

223-
calcSerie.onHovered: (point, state) => showMainTooltip(chartView, point, state)
223+
onChartHovered: (chartX, chartY, screenX, screenY, active) => showMainTooltip(chartX, chartY, screenX, screenY, active)
224224

225225
// Multi-experiment series management
226226
function updateMultiExperimentSeries() {
@@ -569,15 +569,14 @@ Rectangle {
569569

570570
// Logic
571571

572-
function showMainTooltip(chart, point, state) {
572+
function showMainTooltip(chartX, chartY, screenX, screenY, active) {
573573
if (!chartView.allowHover) {
574574
return
575575
}
576-
const pos = chart.mapToPosition(Qt.point(point.x, point.y))
577-
dataToolTip.x = pos.x
578-
dataToolTip.y = pos.y
579-
dataToolTip.text = `<p align="left">x: ${point.x.toFixed(3)}<br\>y: ${point.y.toFixed(3)}</p>`
580-
dataToolTip.parent = chart
581-
dataToolTip.visible = state
576+
dataToolTip.x = screenX
577+
dataToolTip.y = screenY
578+
dataToolTip.text = `<p align="left">x: ${chartX.toFixed(3)}<br\>y: ${chartY.toFixed(3)}</p>`
579+
dataToolTip.parent = chartView
580+
dataToolTip.visible = active
582581
}
583582
}

EasyReflectometryApp/Gui/Pages/Sample/MainContent/CombinedView.qml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,33 @@ Rectangle {
247247
textFormat: Text.RichText
248248
}
249249

250+
// Cross-platform hover tracking for tooltips
251+
HoverHandler {
252+
id: sampleChartHoverHandler
253+
onHoveredChanged: {
254+
if (!hovered) {
255+
sampleDataToolTip.visible = false
256+
}
257+
}
258+
onPointChanged: {
259+
if (hovered && sampleChartView.allowHover) {
260+
const pos = point.position
261+
const pa = sampleChartView.plotArea
262+
if (pos.x >= pa.x && pos.x <= pa.x + pa.width &&
263+
pos.y >= pa.y && pos.y <= pa.y + pa.height) {
264+
const val = sampleChartView.mapToValue(pos)
265+
sampleDataToolTip.x = pos.x
266+
sampleDataToolTip.y = pos.y
267+
sampleDataToolTip.text = `<p align="left">x: ${val.x.toFixed(3)}<br\>y: ${val.y.toFixed(3)}</p>`
268+
sampleDataToolTip.parent = sampleChartView
269+
sampleDataToolTip.visible = true
270+
} else {
271+
sampleDataToolTip.visible = false
272+
}
273+
}
274+
}
275+
}
276+
250277
// Zoom rectangle
251278
Rectangle {
252279
id: sampleRecZoom
@@ -445,8 +472,6 @@ Rectangle {
445472
sampleLine.color = models[k].color
446473
sampleLine.width = 2
447474
sampleLine.useOpenGL = EaGlobals.Vars.useOpenGL
448-
// Connect hovered signal for tooltip
449-
sampleLine.hovered.connect((point, state) => showMainTooltip(sampleChartView, sampleDataToolTip, point, state))
450475
sampleSeries.push(sampleLine)
451476
}
452477

@@ -471,16 +496,5 @@ Rectangle {
471496
}
472497
}
473498

474-
// Logic
475-
function showMainTooltip(chart, tooltip, point, state) {
476-
if (!chart.allowHover) {
477-
return
478-
}
479-
const pos = chart.mapToPosition(Qt.point(point.x, point.y))
480-
tooltip.x = pos.x
481-
tooltip.y = pos.y
482-
tooltip.text = `<p align="left">x: ${point.x.toFixed(3)}<br\>y: ${point.y.toFixed(3)}</p>`
483-
tooltip.parent = chart
484-
tooltip.visible = state
485-
}
499+
486500
}

EasyReflectometryApp/Gui/Pages/Sample/MainContent/SampleView.qml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,33 @@ Rectangle {
225225
textFormat: Text.RichText
226226
}
227227

228+
// Cross-platform hover tracking for tooltips
229+
HoverHandler {
230+
id: chartHoverHandler
231+
onHoveredChanged: {
232+
if (!hovered) {
233+
dataToolTip.visible = false
234+
}
235+
}
236+
onPointChanged: {
237+
if (hovered && chartView.allowHover) {
238+
const pos = point.position
239+
const pa = chartView.plotArea
240+
if (pos.x >= pa.x && pos.x <= pa.x + pa.width &&
241+
pos.y >= pa.y && pos.y <= pa.y + pa.height) {
242+
const val = chartView.mapToValue(pos)
243+
dataToolTip.x = pos.x
244+
dataToolTip.y = pos.y
245+
dataToolTip.text = `<p align="left">x: ${val.x.toFixed(3)}<br\>y: ${val.y.toFixed(3)}</p>`
246+
dataToolTip.parent = chartView
247+
dataToolTip.visible = true
248+
} else {
249+
dataToolTip.visible = false
250+
}
251+
}
252+
}
253+
}
254+
228255
// Zoom rectangle
229256
Rectangle {
230257
id: recZoom
@@ -391,8 +418,6 @@ Rectangle {
391418
line.color = models[k].color
392419
line.width = 2
393420
line.useOpenGL = EaGlobals.Vars.useOpenGL
394-
// Connect hovered signal for tooltip
395-
line.hovered.connect((point, state) => showMainTooltip(chartView, point, state))
396421
sampleSeries.push(line)
397422
}
398423

@@ -413,17 +438,6 @@ Rectangle {
413438
}
414439
}
415440

416-
// Logic
417-
function showMainTooltip(chart, point, state) {
418-
if (!chartView.allowHover) {
419-
return
420-
}
421-
const pos = chart.mapToPosition(Qt.point(point.x, point.y))
422-
dataToolTip.x = pos.x
423-
dataToolTip.y = pos.y
424-
dataToolTip.text = `<p align="left">x: ${point.x.toFixed(3)}<br\>y: ${point.y.toFixed(3)}</p>`
425-
dataToolTip.parent = chart
426-
dataToolTip.visible = state
427-
}
441+
428442
}
429443

EasyReflectometryApp/Gui/SldChart.qml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,33 @@ Rectangle {
196196
textFormat: Text.RichText
197197
}
198198

199+
// Cross-platform hover tracking for tooltips
200+
HoverHandler {
201+
id: chartHoverHandler
202+
onHoveredChanged: {
203+
if (!hovered) {
204+
dataToolTip.visible = false
205+
}
206+
}
207+
onPointChanged: {
208+
if (hovered && chartView.allowHover) {
209+
const pos = point.position
210+
const pa = chartView.plotArea
211+
if (pos.x >= pa.x && pos.x <= pa.x + pa.width &&
212+
pos.y >= pa.y && pos.y <= pa.y + pa.height) {
213+
const val = chartView.mapToValue(pos)
214+
dataToolTip.x = pos.x
215+
dataToolTip.y = pos.y
216+
dataToolTip.text = `<p align="left">x: ${val.x.toFixed(3)}<br\>y: ${val.y.toFixed(3)}</p>`
217+
dataToolTip.parent = chartView
218+
dataToolTip.visible = true
219+
} else {
220+
dataToolTip.visible = false
221+
}
222+
}
223+
}
224+
}
225+
199226
// Zoom rectangle
200227
Rectangle {
201228
id: recZoom
@@ -353,7 +380,6 @@ Rectangle {
353380
line.color = models[k].color
354381
line.width = 2
355382
line.useOpenGL = EaGlobals.Vars.useOpenGL
356-
line.hovered.connect((point, state) => showMainTooltip(point, state))
357383
sldSeries.push(line)
358384
}
359385

@@ -374,15 +400,5 @@ Rectangle {
374400
}
375401
}
376402

377-
function showMainTooltip(point, state) {
378-
if (!chartView.allowHover) {
379-
return
380-
}
381-
const pos = chartView.mapToPosition(Qt.point(point.x, point.y))
382-
dataToolTip.x = pos.x
383-
dataToolTip.y = pos.y
384-
dataToolTip.text = `<p align="left">x: ${point.x.toFixed(3)}<br\>y: ${point.y.toFixed(3)}</p>`
385-
dataToolTip.parent = chartView
386-
dataToolTip.visible = state
387-
}
403+
388404
}

0 commit comments

Comments
 (0)