Changeset 83517 in vbox
- Timestamp:
- Apr 2, 2020 5:22:58 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp
r83512 r83517 67 67 68 68 /********************************************************************************************************************************* 69 * Class UIVMResourceMonitorDoughnutChart definition. * 70 *********************************************************************************************************************************/ 71 72 class UIVMResourceMonitorDoughnutChart : public QWidget 73 { 74 75 Q_OBJECT; 76 77 public: 78 79 UIVMResourceMonitorDoughnutChart(QWidget *pParent = 0); 80 void updateData(quint64 iData0, quint64 iData1); 81 void setChartColors(const QColor &color0, const QColor &color1); 82 void setChartCenterString(const QString &strCenter); 83 void setDataMaximum(quint64 iMax); 84 85 protected: 86 87 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 88 89 private: 90 91 quint64 m_iData0; 92 quint64 m_iData1; 93 quint64 m_iDataMaximum; 94 int m_iMargin; 95 QColor m_color0; 96 QColor m_color1; 97 /** If not empty this text is drawn at the center of the doughnut chart. */ 98 QString m_strCenter; 99 }; 100 101 102 /********************************************************************************************************************************* 69 103 * Class UIVMResourceMonitorHostStats definition. * 70 104 *********************************************************************************************************************************/ … … 85 119 86 120 /********************************************************************************************************************************* 87 * Class UIVMResourceMonitorHostCPUWidget definition. *88 *********************************************************************************************************************************/89 90 class UIVMResourceMonitorHostCPUWidget : public QWidget91 {92 93 Q_OBJECT;94 95 public:96 97 UIVMResourceMonitorHostCPUWidget(QWidget *pParent = 0);98 void setCPULoad(quint64 iUserLoad, quint64 iKernelLoad, quint64 iCPUFreq);99 void setChartColors(const QColor &CPUUserLoadColor, const QColor &CPUKernelLoadColor);100 101 protected:102 103 virtual void paintEvent(QPaintEvent *pEvent) /* override */;104 105 private:106 107 quint64 m_iCPUUserLoad;108 quint64 m_iCPUKernelLoad;109 quint64 m_iCPUFreq;110 int m_iMargin;111 QColor m_CPUUserColor;112 QColor m_CPUKernelColor;113 };114 115 116 /*********************************************************************************************************************************117 * Class UIVMResourceMonitorHostRAMWidget definition. *118 *********************************************************************************************************************************/119 120 class UIVMResourceMonitorHostRAMWidget : public QWidget121 {122 123 Q_OBJECT;124 125 public:126 127 UIVMResourceMonitorHostRAMWidget(QWidget *pParent = 0);128 void setRAMStats(quint64 iTotalRAM, quint64 iFreeRAM);129 void setChartColors(const QColor &RAMFreeColor, const QColor &RAMUsedColor);130 131 protected:132 133 virtual void paintEvent(QPaintEvent *pEvent) /* override */;134 135 private:136 137 quint64 m_iTotalRAM;138 quint64 m_iFreeRAM;139 140 int m_iMargin;141 QColor m_RAMFreeColor;142 QColor m_RAMUsedColor;143 };144 145 146 /*********************************************************************************************************************************147 121 * Class UIVMResourceMonitorHostStatsWidget definition. * 148 122 *********************************************************************************************************************************/ … … 167 141 void updateLabels(); 168 142 169 UIVMResourceMonitor HostCPUWidget *m_pHostCPUChart;170 UIVMResourceMonitor HostRAMWidget *m_pHostRAMChart;143 UIVMResourceMonitorDoughnutChart *m_pHostCPUChart; 144 UIVMResourceMonitorDoughnutChart *m_pHostRAMChart; 171 145 QLabel *m_pCPUTitleLabel; 172 146 QLabel *m_pCPUUserLabel; … … 378 352 379 353 /********************************************************************************************************************************* 380 * Class UIVMResourceMonitor HostCPUWidget implementation. *381 *********************************************************************************************************************************/ 382 383 UIVMResourceMonitor HostCPUWidget::UIVMResourceMonitorHostCPUWidget(QWidget *pParent /* = 0 */)354 * Class UIVMResourceMonitorDoughnutChart implementation. * 355 *********************************************************************************************************************************/ 356 357 UIVMResourceMonitorDoughnutChart::UIVMResourceMonitorDoughnutChart(QWidget *pParent /* = 0 */) 384 358 :QWidget(pParent) 385 , m_iCPUUserLoad(0) 386 , m_iCPUKernelLoad(0) 387 , m_iCPUFreq(0) 388 { 389 m_iMargin = 3; 390 } 391 392 void UIVMResourceMonitorHostCPUWidget::setCPULoad(quint64 iUserLoad, quint64 iKernelLoad, quint64 iFreq) 393 { 394 m_iCPUUserLoad = iUserLoad; 395 m_iCPUKernelLoad = iKernelLoad; 396 m_iCPUFreq = iFreq; 359 , m_iData0(0) 360 , m_iData1(0) 361 , m_iDataMaximum(0) 362 , m_iMargin(3) 363 { 364 } 365 366 void UIVMResourceMonitorDoughnutChart::updateData(quint64 iData0, quint64 iData1) 367 { 368 m_iData0 = iData0; 369 m_iData1 = iData1; 397 370 update(); 398 371 } 399 372 400 void UIVMResourceMonitorHostCPUWidget::setChartColors(const QColor &CPUUserLoadColor, const QColor &CPUKernelLoadColor) 401 { 402 m_CPUUserColor = CPUUserLoadColor; 403 m_CPUKernelColor = CPUKernelLoadColor; 404 } 405 406 void UIVMResourceMonitorHostCPUWidget::paintEvent(QPaintEvent *pEvent) 373 void UIVMResourceMonitorDoughnutChart::setChartColors(const QColor &color0, const QColor &color1) 374 { 375 m_color0 = color0; 376 m_color1 = color1; 377 } 378 379 void UIVMResourceMonitorDoughnutChart::setChartCenterString(const QString &strCenter) 380 { 381 m_strCenter = strCenter; 382 } 383 384 void UIVMResourceMonitorDoughnutChart::setDataMaximum(quint64 iMax) 385 { 386 m_iDataMaximum = iMax; 387 } 388 389 void UIVMResourceMonitorDoughnutChart::paintEvent(QPaintEvent *pEvent) 407 390 { 408 391 QWidget::paintEvent(pEvent); … … 414 397 QRectF outerRect = QRectF(QPoint(m_iMargin,m_iMargin), QSize(iFrameHeight, iFrameHeight)); 415 398 QRectF innerRect = UIMonitorCommon::getScaledRect(outerRect, 0.6f, 0.6f); 416 UIMonitorCommon::drawCombinedDoughnutChart(m_i CPUKernelLoad, m_CPUKernelColor,417 m_i CPUUserLoad, m_CPUUserColor,418 painter, 100,399 UIMonitorCommon::drawCombinedDoughnutChart(m_iData0, m_color0, 400 m_iData1, m_color1, 401 painter, m_iDataMaximum, 419 402 outerRect, innerRect, 80); 420 float mul = 1.f / 1.4f; 421 QRectF textRect = UIMonitorCommon::getScaledRect(innerRect, mul, mul); 422 painter.setPen(Qt::black); 423 painter.drawText(textRect, Qt::AlignCenter, QString("%1\nMHz").arg(QString::number(m_iCPUFreq))); 424 } 425 426 427 /********************************************************************************************************************************* 428 * Class UIVMResourceMonitorHostRAMWidget implementation. * 429 *********************************************************************************************************************************/ 430 431 UIVMResourceMonitorHostRAMWidget::UIVMResourceMonitorHostRAMWidget(QWidget *pParent /* = 0 */) 432 :QWidget(pParent) 433 , m_iTotalRAM(0) 434 , m_iFreeRAM(0) 435 { 436 m_iMargin = 3; 437 } 438 void UIVMResourceMonitorHostRAMWidget::setRAMStats(quint64 iTotalRAM, quint64 iFreeRAM) 439 { 440 m_iTotalRAM = iTotalRAM; 441 m_iFreeRAM = iFreeRAM; 442 update(); 443 } 444 445 void UIVMResourceMonitorHostRAMWidget::setChartColors(const QColor &RAMFreeColor, const QColor &RAMUsedColor) 446 { 447 m_RAMFreeColor = RAMFreeColor; 448 m_RAMUsedColor = RAMUsedColor; 449 } 450 451 void UIVMResourceMonitorHostRAMWidget::paintEvent(QPaintEvent *pEvent) 452 { 453 454 QWidget::paintEvent(pEvent); 455 456 QPainter painter(this); 457 painter.setRenderHint(QPainter::Antialiasing); 458 459 int iFrameHeight = height()- 2 * m_iMargin; 460 QRectF outerRect = QRectF(QPoint(m_iMargin,m_iMargin), QSize(iFrameHeight, iFrameHeight)); 461 QRectF innerRect = UIMonitorCommon::getScaledRect(outerRect, 0.6f, 0.6f); 462 quint64 iUsedRAM = m_iTotalRAM - m_iFreeRAM; 463 464 UIMonitorCommon::drawCombinedDoughnutChart(iUsedRAM, m_RAMUsedColor, 465 m_iFreeRAM, m_RAMFreeColor, 466 painter, m_iTotalRAM, 467 outerRect, innerRect, 80); 468 469 if (m_iTotalRAM != 0) 403 if (!m_strCenter.isEmpty()) 470 404 { 471 405 float mul = 1.f / 1.4f; 472 406 QRectF textRect = UIMonitorCommon::getScaledRect(innerRect, mul, mul); 473 407 painter.setPen(Qt::black); 474 int iPercent = 100 * (iUsedRAM / (float) m_iTotalRAM); 475 painter.drawText(textRect, Qt::AlignCenter, QString("%1%\nUsed").arg(QString::number(iPercent))); 476 } 477 408 painter.drawText(textRect, Qt::AlignCenter, m_strCenter); 409 } 478 410 } 479 411 … … 514 446 m_hostStats = hostStats; 515 447 if (m_pHostCPUChart) 516 m_pHostCPUChart->setCPULoad(m_hostStats.m_iCPUUserLoad, m_hostStats.m_iCPUKernelLoad, m_hostStats.m_iCPUFreq); 448 { 449 m_pHostCPUChart->updateData(m_hostStats.m_iCPUUserLoad, m_hostStats.m_iCPUKernelLoad); 450 QString strCenter = QString("%1\nMHz").arg(m_hostStats.m_iCPUFreq); 451 m_pHostCPUChart->setChartCenterString(strCenter); 452 } 517 453 if (m_pHostRAMChart) 518 m_pHostRAMChart->setRAMStats(m_hostStats.m_iTotalRAM, m_hostStats.m_iFreeRAM); 454 { 455 quint64 iUsedRAM = m_hostStats.m_iTotalRAM - m_hostStats.m_iFreeRAM; 456 m_pHostRAMChart->updateData(iUsedRAM, m_hostStats.m_iFreeRAM); 457 m_pHostRAMChart->setDataMaximum(m_hostStats.m_iTotalRAM); 458 if (m_hostStats.m_iTotalRAM != 0) 459 { 460 quint64 iUsedRamPer = 100 * (iUsedRAM / (float) m_hostStats.m_iTotalRAM); 461 QString strCenter = QString("%1%\n%2").arg(iUsedRamPer).arg(tr("Used")); 462 m_pHostRAMChart->setChartCenterString(strCenter); 463 } 464 } 519 465 updateLabels(); 520 466 } … … 556 502 pCPULabelsLayout->addWidget(m_pCPUTotalLabel); 557 503 pCPULabelsLayout->setAlignment(Qt::AlignTop); 558 //pLayout->setAlignment(Qt::AlignTop);559 504 pCPULabelsLayout->setSpacing(0); 560 505 /* Host CPU chart widget: */ 561 m_pHostCPUChart = new UIVMResourceMonitor HostCPUWidget;506 m_pHostCPUChart = new UIVMResourceMonitorDoughnutChart; 562 507 if (m_pHostCPUChart) 563 508 { 564 509 m_pHostCPUChart->setMinimumSize(iMinimumSize, iMinimumSize); 510 m_pHostCPUChart->setDataMaximum(100); 565 511 pLayout->addWidget(m_pHostCPUChart); 566 512 m_pHostCPUChart->setChartColors(m_CPUUserColor, m_CPUKernelColor); … … 585 531 pRAMLabelsLayout->addWidget(m_pRAMTotalLabel); 586 532 587 m_pHostRAMChart = new UIVMResourceMonitor HostRAMWidget;533 m_pHostRAMChart = new UIVMResourceMonitorDoughnutChart; 588 534 if (m_pHostRAMChart) 589 535 { 590 536 m_pHostRAMChart->setMinimumSize(iMinimumSize, iMinimumSize); 591 537 pLayout->addWidget(m_pHostRAMChart); 592 m_pHostRAMChart->setChartColors(m_RAM FreeColor, m_RAMUsedColor);538 m_pHostRAMChart->setChartColors(m_RAMUsedColor, m_RAMFreeColor); 593 539 } 594 540 }
Note:
See TracChangeset
for help on using the changeset viewer.