- Timestamp:
- May 6, 2021 10:23:17 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.cpp
r88886 r88895 99 99 void setIsAvailable(bool fIsAvailable); 100 100 101 void setMouseOver(bool isOver); 102 101 103 protected: 102 104 … … 122 124 void drawPieChart(QPainter &painter, quint64 iMaximum, int iDataIndex, const QRectF &chartRect, bool fWithBorder = true); 123 125 void drawCombinedPieCharts(QPainter &painter, quint64 iMaximum); 124 126 QString YAxisValueLabel(quint64 iValue) const; 125 127 /** Drawing an overlay rectangle over the charts to indicate that they are disabled. */ 126 128 void drawDisabledChartRectangle(QPainter &painter); … … 161 163 QString m_strPieChartToggleActionLabel; 162 164 QString m_strAreaChartToggleActionLabel; 165 bool m_fDrawCurenValueIndicators; 163 166 }; 164 167 … … 180 183 , m_fIsAvailable(true) 181 184 , m_fIsAreaChartAllowed(false) 185 , m_fDrawCurenValueIndicators(true) 182 186 { 183 187 m_axisFont = font(); … … 191 195 m_dataSeriesColor[1] = QColor(0, 0, 200, 255); 192 196 193 m_iMarginLeft = 1 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);194 m_iMarginRight = 9 * QFontMetrics(m_axisFont). width('X');197 m_iMarginLeft = 3 * QFontMetrics(m_axisFont).averageCharWidth(); 198 m_iMarginRight = 9 * QFontMetrics(m_axisFont).averageCharWidth(); 195 199 m_iMarginTop = 0.3 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); 196 200 m_iMarginBottom = QFontMetrics(m_axisFont).height(); … … 309 313 } 310 314 315 void UIChart::setMouseOver(bool isOver) 316 { 317 if (!isOver) 318 m_iDataIndexUnderCursor = -1; 319 } 320 311 321 QSize UIChart::minimumSizeHint() const 312 322 { … … 338 348 void UIChart::mouseMoveEvent(QMouseEvent *pEvent) 339 349 { 340 int iX = pEvent->x();350 int iX = width() - pEvent->x() - m_iMarginRight; 341 351 m_iDataIndexUnderCursor = -1; 342 352 if (iX > m_iMarginLeft && iX <= width() - m_iMarginRight) 343 m_iDataIndexUnderCursor = (int)(g_iMaximumQueueSize - (iX - m_iMarginLeft) / m_fPixelPerDataPoint); 353 m_iDataIndexUnderCursor = (int)((iX) / m_fPixelPerDataPoint) + 1; 354 update(); 344 355 QIWithRetranslateUI<QWidget>::mouseMoveEvent(pEvent); 345 356 } … … 399 410 400 411 quint64 iMaximum = m_pMetric->maximum(); 412 QFontMetrics fontMetrics(painter.font()); 413 int iFontHeight = fontMetrics.height(); 414 int iAverageFontWidth = fontMetrics.averageCharWidth(); 415 401 416 /* Draw a straight line per data series: */ 402 417 if (iMaximum == 0) … … 404 419 for (int k = 0; k < DATA_SERIES_SIZE; ++k) 405 420 { 406 407 421 QLineF bar(0 + m_iMarginLeft, height() - m_iMarginBottom, 408 422 width() - m_iMarginRight, height() - m_iMarginBottom); 409 423 painter.drawLine(bar); 410 424 painter.setPen(QPen(m_dataSeriesColor[k], 2.5)); 411 412 425 painter.setBrush(m_dataSeriesColor[k]); 413 414 426 } 415 427 } … … 428 440 painter.setPen(QPen(gradient, 2.5)); 429 441 } 430 431 442 const QQueue<quint64> *data = m_pMetric->data(k); 432 443 if (!m_fUseGradientLineColor) … … 467 478 } 468 479 } 480 /* Draw a horizontal and vertical line on data point under the mouse cursor 481 * and draw the value on the left hand side of the chart: */ 482 if (m_fDrawCurenValueIndicators && m_iDataIndexUnderCursor >= 0 && m_iDataIndexUnderCursor < data->size()) 483 { 484 painter.setPen(QPen(m_dataSeriesColor[k], 0.5)); 485 float fHeight = fH * data->at(data->size() - m_iDataIndexUnderCursor); 486 if (fHeight > 0) 487 { 488 painter.drawLine(m_iMarginLeft, height() - (fHeight + m_iMarginBottom), 489 width() - m_iMarginRight, height() - (fHeight + m_iMarginBottom)); 490 QPoint cursorPosition = mapFromGlobal(cursor().pos()); 491 painter.setPen(mainAxisColor); 492 painter.drawLine(cursorPosition.x(), 0, 493 cursorPosition.x(), height() - m_iMarginBottom); 494 QString strValue = QString::number(data->at(data->size() - m_iDataIndexUnderCursor)); 495 painter.drawText(m_iMarginLeft - fontMetrics.width(strValue) - iAverageFontWidth, 496 height() - (fHeight + m_iMarginBottom) + 0.5 * iFontHeight, strValue); 497 498 } 499 } 469 500 } 470 501 }// else of if (iMaximum == 0) 471 472 QFontMetrics fontMetrics(painter.font());473 int iFontHeight = fontMetrics.height();474 502 475 503 /* Draw YAxis tick labels: */ … … 481 509 break; 482 510 int iTextY = 0.5 * iFontHeight + m_iMarginTop + i * m_lineChartRect.height() / (float) (iYSubAxisCount + 1); 483 QString strValue;484 511 quint64 iValue = (iYSubAxisCount + 1 - i) * (iMaximum / (float) (iYSubAxisCount + 1)); 485 if (m_pMetric->unit().compare("%", Qt::CaseInsensitive) == 0) 486 strValue = QString::number(iValue); 487 else if (m_pMetric->unit().compare("kb", Qt::CaseInsensitive) == 0) 488 strValue = uiCommon().formatSize(_1K * (quint64)iValue, g_iDecimalCount); 489 else if (m_pMetric->unit().compare("b", Qt::CaseInsensitive) == 0 || 490 m_pMetric->unit().compare("b/s", Qt::CaseInsensitive) == 0) 491 strValue = uiCommon().formatSize(iValue, g_iDecimalCount); 492 else if (m_pMetric->unit().compare("times", Qt::CaseInsensitive) == 0) 493 strValue = UICommon::addMetricSuffixToNumber(iValue); 494 512 QString strValue = YAxisValueLabel(iValue); 495 513 painter.drawText(width() - 0.9 * m_iMarginRight, iTextY, strValue); 496 514 } … … 499 517 drawCombinedPieCharts(painter, iMaximum); 500 518 } 519 520 QString UIChart::YAxisValueLabel(quint64 iValue) const 521 { 522 if (m_pMetric->unit().compare("%", Qt::CaseInsensitive) == 0) 523 return QString::number(iValue); 524 else if (m_pMetric->unit().compare("kb", Qt::CaseInsensitive) == 0) 525 return uiCommon().formatSize(_1K * (quint64)iValue, g_iDecimalCount); 526 else if (m_pMetric->unit().compare("b", Qt::CaseInsensitive) == 0 || 527 m_pMetric->unit().compare("b/s", Qt::CaseInsensitive) == 0) 528 return uiCommon().formatSize(iValue, g_iDecimalCount); 529 else if (m_pMetric->unit().compare("times", Qt::CaseInsensitive) == 0) 530 return UICommon::addMetricSuffixToNumber(iValue); 531 return QString(); 532 } 533 501 534 502 535 void UIChart::drawXAxisLabels(QPainter &painter, int iXSubAxisCount) … … 976 1009 } 977 1010 1011 bool UIVMActivityMonitor::eventFilter(QObject *pObj, QEvent *pEvent) 1012 { 1013 if (pEvent-> type() == QEvent::Enter || 1014 pEvent-> type() == QEvent::Leave) 1015 { 1016 UIChart *pChart = qobject_cast<UIChart*>(pObj); 1017 if (pChart) 1018 pChart->setMouseOver(pEvent-> type() == QEvent::Enter); 1019 } 1020 return false; 1021 } 1022 978 1023 void UIVMActivityMonitor::prepareWidgets() 979 1024 { … … 1021 1066 1022 1067 UIChart *pChart = new UIChart(this, &(m_metrics[strMetricName])); 1068 pChart->installEventFilter(this); 1023 1069 connect(pChart, &UIChart::sigExportMetricsToFile, 1024 1070 this, &UIVMActivityMonitor::sltExportMetricsToFile); -
trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.h
r88881 r88895 148 148 protected: 149 149 150 void retranslateUi(); 150 virtual void retranslateUi() /* override */; 151 virtual bool eventFilter(QObject *pObj, QEvent *pEvent) /* override */; 151 152 152 153 private slots:
Note:
See TracChangeset
for help on using the changeset viewer.