##// END OF EJS Templates
Tooltip for spectrograms (1)...
Alexandre Leroux -
r1024:2ecd8b335419
parent child
Show More
@@ -26,7 +26,9 const auto OVERLAY_LAYER = QStringLiteral("overlay");
26 /// Pixmap used to show x-axis properties
26 /// Pixmap used to show x-axis properties
27 const auto SHOW_AXIS_ICON_PATH = QStringLiteral(":/icones/up.png");
27 const auto SHOW_AXIS_ICON_PATH = QStringLiteral(":/icones/up.png");
28
28
29 const auto TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2");
29 /// Tooltip format for graphs
30 const auto GRAPH_TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2");
31
30
32
31 /// Offset used to shift the tooltip of the mouse
33 /// Offset used to shift the tooltip of the mouse
32 const auto TOOLTIP_OFFSET = QPoint{20, 20};
34 const auto TOOLTIP_OFFSET = QPoint{20, 20};
@@ -195,6 +197,8 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce
195 impl->m_PointTracer->setVisible(false);
197 impl->m_PointTracer->setVisible(false);
196 impl->m_Plot.replot();
198 impl->m_Plot.replot();
197
199
200 QString tooltip{};
201
198 // Gets the graph under the mouse position
202 // Gets the graph under the mouse position
199 auto eventPos = event->pos();
203 auto eventPos = event->pos();
200 if (auto graph = qobject_cast<QCPGraph *>(impl->m_Plot.plottableAt(eventPos))) {
204 if (auto graph = qobject_cast<QCPGraph *>(impl->m_Plot.plottableAt(eventPos))) {
@@ -204,8 +208,10 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce
204 // Gets the closest data point to the mouse
208 // Gets the closest data point to the mouse
205 auto graphDataIt = graphData->findBegin(mouseKey);
209 auto graphDataIt = graphData->findBegin(mouseKey);
206 if (graphDataIt != graphData->constEnd()) {
210 if (graphDataIt != graphData->constEnd()) {
211 // Sets tooltip
207 auto key = formatValue(graphDataIt->key, *graph->keyAxis());
212 auto key = formatValue(graphDataIt->key, *graph->keyAxis());
208 auto value = formatValue(graphDataIt->value, *graph->valueAxis());
213 auto value = formatValue(graphDataIt->value, *graph->valueAxis());
214 tooltip = GRAPH_TOOLTIP_FORMAT.arg(key, value);
209
215
210 // Displays point tracer
216 // Displays point tracer
211 impl->m_PointTracer->setGraph(graph);
217 impl->m_PointTracer->setGraph(graph);
@@ -214,17 +220,22 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexce
214 impl->m_Plot.layer("main")); // Tracer is set on top of the plot's main layer
220 impl->m_Plot.layer("main")); // Tracer is set on top of the plot's main layer
215 impl->m_PointTracer->setVisible(true);
221 impl->m_PointTracer->setVisible(true);
216 impl->m_Plot.replot();
222 impl->m_Plot.replot();
223 }
224 }
225 else if (auto colorMap = qobject_cast<QCPColorMap *>(impl->m_Plot.plottableAt(eventPos))) {
226 /// @todo
227 tooltip = "TODO";
228 }
217
229
218 // Starts timer to show tooltip after timeout
230 if (!tooltip.isEmpty()) {
219 auto showTooltip = [ tooltip = TOOLTIP_FORMAT.arg(key, value), eventPos, this ]()
231 // Starts timer to show tooltip after timeout
220 {
232 auto showTooltip = [tooltip, eventPos, this]() {
221 QToolTip::showText(impl->m_Plot.mapToGlobal(eventPos) + TOOLTIP_OFFSET, tooltip,
233 QToolTip::showText(impl->m_Plot.mapToGlobal(eventPos) + TOOLTIP_OFFSET, tooltip,
222 &impl->m_Plot, TOOLTIP_RECT);
234 &impl->m_Plot, TOOLTIP_RECT);
223 };
235 };
224
236
225 QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTooltip);
237 QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTooltip);
226 impl->m_TracerTimer.start();
238 impl->m_TracerTimer.start();
227 }
228 }
239 }
229 }
240 }
230
241
General Comments 0
You need to be logged in to leave comments. Login now