Changeset 80434 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Aug 26, 2019 7:21:55 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.cpp
r80420 r80434 133 133 const QStringList &textList() const; 134 134 135 bool drawPieChart() const;136 void set DrawPieChart(bool fDrawPieChart);135 bool withPieChart() const; 136 void setWithPieChart(bool fWithPieChart); 137 137 138 138 bool useGradientLineColor() const; … … 160 160 161 161 virtual void computeFontSize(); 162 void drawXAxisLabels(QPainter &painter, int iXSubAxisCount); 163 void drawPieCharts(QPainter &painter, qulonglong iMaximum); 164 void insertInfoLine(InfoLine enmInfoLine, const QString& strLabel, const QString &strInfo); 162 /** @name Drawing helper functions. 163 * @{ */ 164 void drawXAxisLabels(QPainter &painter, int iXSubAxisCount); 165 void drawPieCharts(QPainter &painter, qulonglong iMaximum); 166 /** Drawing an overlay rectangle over the charts to indicate that they are disabled. */ 167 void drawDisabledChartRectangle(QPainter &painter); 168 /** @} */ 165 169 166 170 UIMetric *m_pMetric; … … 172 176 int m_iMarginBottom; 173 177 QStringList m_textList; 174 int m_iPieChartSize; 175 QRect m_pieChartRect[DATA_SERIES_SIZE]; 176 bool m_fDrawPieChart; 178 QRect m_lineChartRect; 179 int m_iPieChartRadius; 180 int m_iPieChartSpacing; 181 bool m_fWithPieChart; 177 182 bool m_fUseGradientLineColor; 178 183 QColor m_dataSeriesColor[DATA_SERIES_SIZE]; … … 409 414 , m_pMetric(pMetric) 410 415 , m_size(QSize(50, 50)) 411 , m_f DrawPieChart(false)416 , m_fWithPieChart(false) 412 417 , m_fUseGradientLineColor(false) 413 418 { … … 415 420 connect(this, &UIChart::customContextMenuRequested, 416 421 this, &UIChart::sltCreateContextMenu); 417 418 422 419 423 m_dataSeriesColor[0] = QColor(Qt::red); … … 424 428 m_iMarginTop = 0.3 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); 425 429 m_iMarginBottom = 2 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); 426 m_iPieChartSize = 1.5f * qApp->style()->pixelMetric(QStyle::PM_LargeIconSize); 427 m_ pieChartRect[0] = QRect(1.5 * m_iMarginLeft, 1.5 * m_iMarginTop, m_iPieChartSize, m_iPieChartSize);428 m_ pieChartRect[1] = QRect(m_pieChartRect[0].x() + m_iPieChartSize + 0.5 * m_iMarginLeft, 1.5 * m_iMarginTop, m_iPieChartSize, m_iPieChartSize);429 m_size = QSize( 6 * m_iPieChartSize, 2 * m_iPieChartSize);430 431 m_iPieChartRadius = 1.2f * qApp->style()->pixelMetric(QStyle::PM_LargeIconSize); 432 m_iPieChartSpacing = 0.3 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); 433 m_size = QSize(10 * m_iPieChartRadius, 2 * m_iPieChartRadius); 430 434 retranslateUi(); 431 435 } … … 452 456 } 453 457 454 bool UIChart:: drawPieChart() const455 { 456 return m_f DrawPieChart;457 } 458 459 void UIChart::set DrawPieChart(bool fDrawPieChart)460 { 461 if (m_f DrawPieChart == fDrawPieChart)458 bool UIChart::withPieChart() const 459 { 460 return m_fWithPieChart; 461 } 462 463 void UIChart::setWithPieChart(bool fWithPieChart) 464 { 465 if (m_fWithPieChart == fWithPieChart) 462 466 return; 463 m_f DrawPieChart = fDrawPieChart;467 m_fWithPieChart = fWithPieChart; 464 468 update(); 465 469 } … … 545 549 { 546 550 Q_UNUSED(pEvent); 551 if (!m_pMetric || iMaximumQueueSize <= 1) 552 return; 553 547 554 QPainter painter(this); 548 555 painter.setRenderHint(QPainter::Antialiasing); 549 556 550 557 /* Draw a rectanglar grid over which we will draw the line graphs: */ 551 int iChartHeight = height() - (m_iMarginTop + m_iMarginBottom); 552 int iChartWidth = width() - (m_iMarginLeft + m_iMarginRight); 558 QPoint chartTopLeft(m_iMarginLeft, m_iMarginTop); 559 QSize chartSize(width() - (m_iMarginLeft + m_iMarginRight), height() - (m_iMarginTop + m_iMarginBottom)); 560 561 m_lineChartRect = QRect(chartTopLeft, chartSize); 553 562 QColor mainAxisColor(120, 120, 120); 554 563 QColor subAxisColor(200, 200, 200); 555 564 /* Draw the main axes: */ 556 565 painter.setPen(mainAxisColor); 557 painter.drawRect( QRect(m_iMarginLeft, m_iMarginTop, iChartWidth, iChartHeight));566 painter.drawRect(m_lineChartRect); 558 567 559 568 /* draw Y subaxes: */ … … 562 571 for (int i = 0; i < iYSubAxisCount; ++i) 563 572 { 564 float fSubAxisY = m_iMarginTop + (i + 1) * iChartHeight/ (float) (iYSubAxisCount + 1);565 painter.drawLine(m_ iMarginLeft, fSubAxisY,566 width() - m_iMarginRight, fSubAxisY);573 float fSubAxisY = m_iMarginTop + (i + 1) * m_lineChartRect.height() / (float) (iYSubAxisCount + 1); 574 painter.drawLine(m_lineChartRect.left(), fSubAxisY, 575 m_lineChartRect.right(), fSubAxisY); 567 576 } 568 577 … … 571 580 for (int i = 0; i < iXSubAxisCount; ++i) 572 581 { 573 float fSubAxisX = m_iMarginLeft + (i + 1) * iChartWidth / (float) (iXSubAxisCount + 1); 574 painter.drawLine(fSubAxisX, m_iMarginTop, fSubAxisX, height() - m_iMarginBottom); 575 } 576 577 QFontMetrics fontMetrics(painter.font()); 578 int iFontHeight = fontMetrics.height(); 582 float fSubAxisX = m_lineChartRect.left() + (i + 1) * m_lineChartRect.width() / (float) (iXSubAxisCount + 1); 583 painter.drawLine(fSubAxisX, m_lineChartRect.top(), fSubAxisX, m_lineChartRect.bottom()); 584 } 579 585 580 586 /* Draw XAxis tick labels: */ … … 582 588 drawXAxisLabels(painter, iXSubAxisCount); 583 589 590 584 591 /* Draw a half-transparent rectangle over the whole widget to indicate the it is disabled: */ 585 592 if (!isEnabled()) 586 593 { 587 painter.setPen(Qt::NoPen); 588 painter.setBrush(QColor(60, 60, 60, 80)); 589 painter.drawRect(QRect(0, 0, width(), height())); 590 painter.setPen(QColor(20, 20, 20, 180)); 591 QFont font = painter.font(); 592 font.setBold(true); 593 /** @todo make this size dynamic. aka. autoscale the font. */ 594 font.setPixelSize(16); 595 painter.setFont(font); 596 painter.drawText(2 * m_iMarginLeft, 15 * m_iMarginTop, m_strGAWarning); 597 594 drawDisabledChartRectangle(painter); 598 595 return; 599 596 } 600 601 if (!m_pMetric || iMaximumQueueSize <= 1)602 return;603 597 604 598 qulonglong iMaximum = m_pMetric->maximum(); … … 606 600 return; 607 601 /* Draw the data lines: */ 608 float fBarWidth = iChartWidth/ (float) (iMaximumQueueSize - 1);609 float fH = iChartHeight/ (float)iMaximum;602 float fBarWidth = m_lineChartRect.width() / (float) (iMaximumQueueSize - 1); 603 float fH = m_lineChartRect.height() / (float)iMaximum; 610 604 for (int k = 0; k < DATA_SERIES_SIZE; ++k) 611 605 { 612 606 if (m_fUseGradientLineColor) 613 607 { 614 QLinearGradient gradient(0, 0, 0, iChartHeight);608 QLinearGradient gradient(0, 0, 0, m_lineChartRect.height()); 615 609 gradient.setColorAt(0, Qt::black); 616 610 gradient.setColorAt(1, m_dataSeriesColor[k]); … … 633 627 } 634 628 629 QFontMetrics fontMetrics(painter.font()); 630 int iFontHeight = fontMetrics.height(); 631 635 632 /* Draw YAxis tick labels: */ 636 633 painter.setPen(mainAxisColor); 637 634 for (int i = 0; i < iYSubAxisCount + 2; ++i) 638 635 { 639 int iTextY = 0.5 * iFontHeight + m_iMarginTop + i * iChartHeight/ (float) (iYSubAxisCount + 1);636 int iTextY = 0.5 * iFontHeight + m_iMarginTop + i * m_lineChartRect.height() / (float) (iYSubAxisCount + 1); 640 637 QString strValue; 641 638 qulonglong iValue = (iYSubAxisCount + 1 - i) * (iMaximum / (float) (iYSubAxisCount + 1)); … … 653 650 } 654 651 655 if (m_f DrawPieChart)652 if (m_fWithPieChart) 656 653 drawPieCharts(painter, iMaximum); 657 654 } … … 661 658 QFontMetrics fontMetrics(painter.font()); 662 659 int iFontHeight = fontMetrics.height(); 663 int iChartWidth = width() - (m_iMarginLeft + m_iMarginRight); 660 664 661 int iTotalSeconds = iPeriod * iMaximumQueueSize; 665 662 for (int i = 0; i < iXSubAxisCount + 2; ++i) 666 663 { 667 int iTextX = m_ iMarginLeft + i * iChartWidth/ (float) (iXSubAxisCount + 1);664 int iTextX = m_lineChartRect.left() + i * m_lineChartRect.width() / (float) (iXSubAxisCount + 1); 668 665 QString strCurrentSec = QString::number(iTotalSeconds - i * iTotalSeconds / (float)(iXSubAxisCount + 1)); 669 666 int iTextWidth = fontMetrics.width(strCurrentSec); … … 671 668 { 672 669 strCurrentSec += " " + m_strXAxisLabel; 673 painter.drawText(iTextX, height() - m_iMarginBottom+ iFontHeight, strCurrentSec);670 painter.drawText(iTextX, m_lineChartRect.bottom() + iFontHeight, strCurrentSec); 674 671 } 675 672 else 676 painter.drawText(iTextX - 0.5 * iTextWidth, height() - m_iMarginBottom+ iFontHeight, strCurrentSec);673 painter.drawText(iTextX - 0.5 * iTextWidth, m_lineChartRect.bottom() + iFontHeight, strCurrentSec); 677 674 } 678 675 } … … 680 677 void UIChart::drawPieCharts(QPainter &painter, qulonglong iMaximum) 681 678 { 679 int iAlpha = 80; 682 680 for (int i = 0; i < DATA_SERIES_SIZE; ++i) 683 681 { … … 686 684 if (!data || data->isEmpty()) 687 685 continue; 686 QRect chartRect(QPoint((i+1) * m_iPieChartSpacing + i * m_iPieChartRadius + m_iMarginLeft, m_iPieChartSpacing + m_iMarginTop), 687 QSize(m_iPieChartRadius, m_iPieChartRadius)); 688 688 689 689 /* Draw a whole non-filled circle: */ 690 painter.setPen(QPen(Q t::gray, 1));691 painter.drawArc( m_pieChartRect[i], 0, 3600 * 16);692 693 QPointF center( m_pieChartRect[i].center());690 painter.setPen(QPen(QColor(100, 100, 100, iAlpha), 1)); 691 painter.drawArc(chartRect, 0, 3600 * 16); 692 693 QPointF center(chartRect.center()); 694 694 QPainterPath fillPath; 695 695 fillPath.moveTo(center); 696 fillPath.arcTo( m_pieChartRect[i], 90/*startAngle*/,696 fillPath.arcTo(chartRect, 90/*startAngle*/, 697 697 -1 * 360 /*sweepLength*/); 698 698 699 699 /* First draw a white filled circle and that the arc for data: */ 700 700 painter.setPen(Qt::NoPen); 701 painter.setBrush(QColor(255, 255, 255, 175));701 painter.setBrush(QColor(255, 255, 255, iAlpha)); 702 702 painter.drawPath(fillPath); 703 703 704 704 /* Prepare the gradient for the pie chart: */ 705 705 QConicalGradient pieGradient; 706 pieGradient.setCenter( m_pieChartRect[i].center());706 pieGradient.setCenter(chartRect.center()); 707 707 pieGradient.setAngle(90); 708 pieGradient.setColorAt(0, Qt::black); 709 pieGradient.setColorAt(1, m_dataSeriesColor[i]); 708 pieGradient.setColorAt(0, QColor(0, 0, 0, iAlpha)); 709 QColor pieColor(m_dataSeriesColor[i]); 710 pieColor.setAlpha(iAlpha); 711 pieGradient.setColorAt(1, pieColor); 710 712 711 713 QPainterPath dataPath; 712 714 dataPath.moveTo(center); 713 715 float fAngle = 360.f * data->back() / (float)iMaximum; 714 dataPath.arcTo( m_pieChartRect[i], 90/*startAngle*/,716 dataPath.arcTo(chartRect, 90/*startAngle*/, 715 717 -1 * fAngle /*sweepLength*/); 716 718 painter.setBrush(pieGradient); 717 719 painter.drawPath(dataPath); 718 719 } 720 } 720 } 721 } 722 723 void UIChart::drawDisabledChartRectangle(QPainter &painter) 724 { 725 painter.setPen(Qt::NoPen); 726 painter.setBrush(QColor(60, 60, 60, 80)); 727 painter.drawRect(QRect(0, 0, width(), height())); 728 painter.setPen(QColor(20, 20, 20, 180)); 729 QFont font = painter.font(); 730 font.setBold(true); 731 /** @todo make this size dynamic. aka. autoscale the font. */ 732 font.setPixelSize(16); 733 painter.setFont(font); 734 painter.drawText(2 * m_iMarginLeft, 15 * m_iMarginTop, m_strGAWarning); 735 } 736 721 737 722 738 void UIChart::sltCreateContextMenu(const QPoint &point) … … 1033 1049 /* Configure charts: */ 1034 1050 if (m_charts.contains(m_strCPUMetricName) && m_charts[m_strCPUMetricName]) 1035 m_charts[m_strCPUMetricName]->set DrawPieChart(true);1051 m_charts[m_strCPUMetricName]->setWithPieChart(true); 1036 1052 if (m_charts.contains(m_strRAMMetricName) && m_charts[m_strRAMMetricName]) 1037 m_charts[m_strRAMMetricName]->set DrawPieChart(false);1053 m_charts[m_strRAMMetricName]->setWithPieChart(false); 1038 1054 1039 1055 QWidget *bottomSpacerWidget = new QWidget(this);
Note:
See TracChangeset
for help on using the changeset viewer.