Added ability to hide point details on chart by second click.

This commit is contained in:
23rd 2023-09-08 13:08:03 +03:00 committed by John Preston
parent b606a7b21d
commit ecce9dbaaa

View file

@ -1192,6 +1192,7 @@ void ChartWidget::setupDetails() {
switch (state.mouseState) { switch (state.mouseState) {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
case QEvent::MouseMove: { case QEvent::MouseMove: {
const auto wasXIndex = _details.widget->xIndex();
const auto chartRect = chartAreaRect(); const auto chartRect = chartAreaRect();
const auto currentXLimits = _animationController.finalXLimits(); const auto currentXLimits = _animationController.finalXLimits();
const auto nearestXIndex = _chartView->findXIndexByPosition( const auto nearestXIndex = _chartView->findXIndexByPosition(
@ -1218,6 +1219,10 @@ void ChartWidget::setupDetails() {
if (_details.widget->isHidden()) { if (_details.widget->isHidden()) {
_details.hideOnAnimationEnd = false; _details.hideOnAnimationEnd = false;
_details.animation.start(); _details.animation.start();
} else if ((state.mouseState == QEvent::MouseButtonPress)
&& (wasXIndex == nearestXIndex)) {
_details.hideOnAnimationEnd = true;
_details.animation.start();
} }
_details.widget->show(); _details.widget->show();
_chartArea->update(); _chartArea->update();
@ -1233,7 +1238,6 @@ void ChartWidget::setupDetails() {
0., 0.,
1.); 1.);
const auto alpha = _details.hideOnAnimationEnd ? (1. - value) : value; const auto alpha = _details.hideOnAnimationEnd ? (1. - value) : value;
_chartArea->update();
if (_details.widget) { if (_details.widget) {
_details.widget->setAlpha(alpha); _details.widget->setAlpha(alpha);
_details.widget->update(); _details.widget->update();
@ -1245,6 +1249,7 @@ void ChartWidget::setupDetails() {
} }
_details.animation.stop(); _details.animation.stop();
} }
_chartArea->update();
}); });
} }