MCPcopy Create free account
hub / github.com/IENT/YUView / drawInfoBox

Method drawInfoBox

YUViewLib/src/ui/views/PlotViewWidget.cpp:784–846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782}
783
784void PlotViewWidget::drawInfoBox(QPainter &painter) const
785{
786 if (!this->model)
787 return;
788
789 const auto margin = 6;
790 const auto padding = 6;
791
792 QString infoString;
793 for (auto streamIndex : this->showStreamList)
794 {
795 if (!this->currentlyHoveredPointPerStreamAndPlot.contains(streamIndex))
796 continue;
797
798 const auto streamParam = this->model->getStreamParameter(streamIndex);
799 for (unsigned plotIndex = 0; plotIndex < streamParam.getNrPlots(); plotIndex++)
800 {
801 if (!this->currentlyHoveredPointPerStreamAndPlot[streamIndex].contains(plotIndex))
802 continue;
803
804 const auto pointIndex = this->currentlyHoveredPointPerStreamAndPlot[streamIndex][plotIndex];
805 infoString += this->model->getPointInfo(streamIndex, plotIndex, pointIndex);
806 }
807 }
808
809 // Create a QTextDocument. This object can tell us the size of the rendered text.
810 QTextDocument textDocument;
811 textDocument.setHtml(infoString);
812 textDocument.setDefaultStyleSheet("* { color: #FFFFFF }");
813 textDocument.setTextWidth(textDocument.size().width());
814
815 // Translate to the position where the text box shall be
816 // Consider where the mouse is and move the box out of the way if the mouse is here
817 if (!QCursor::pos().isNull())
818 {
819 const auto mousePos = mapFromGlobal(QCursor::pos());
820 auto posX = this->plotRect.bottomRight().x() - axisMaxValueMargin - margin -
821 textDocument.size().width() - padding * 2 + 1;
822 auto posY = this->plotRect.bottomRight().y() - axisMaxValueMargin - margin -
823 textDocument.size().height() - padding * 2 + 1;
824
825 const auto margin = 5;
826 if (mousePos.x() >= posX - margin && mousePos.x() < posX + textDocument.size().width() + margin)
827 {
828 posX -= margin * 2 + textDocument.size().width();
829 posX = std::max(posX, this->plotRect.left());
830 }
831
832 painter.translate(posX, posY);
833 }
834
835 // Draw a black rectangle and then the text on top of that
836 QRect rect(QPoint(0, 0), textDocument.size().toSize() + QSize(2 * padding, 2 * padding));
837 QBrush originalBrush;
838 painter.setBrush(QColor(255, 255, 255, 150));
839 painter.setPen(Qt::black);
840 painter.drawRect(rect);
841 painter.translate(padding, padding);

Callers 1

paintEventMethod · 0.95

Calls 5

containsMethod · 0.80
getNrPlotsMethod · 0.80
getStreamParameterMethod · 0.45
getPointInfoMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected