Changeset 80158 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Aug 6, 2019 3:15:11 PM (5 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/information
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIPerformanceMonitor.cpp
r80155 r80158 18 18 /* Qt includes: */ 19 19 #include <QApplication> 20 #include <QLabel> 20 21 #include <QPainter> 21 22 22 #include <QGridLayout> 23 23 #include <QTimer> … … 60 60 protected: 61 61 62 virtual void paintEvent(QPaintEvent *pEvent) /* override */ = 0;62 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 63 63 virtual QSize minimumSizeHint() const /* override */; 64 64 virtual QSize sizeHint() const /* override */; … … 70 70 int m_iMargin; 71 71 QStringList m_textList; 72 };73 74 /*********************************************************************************************************************************75 * UILineChart definition. *76 *********************************************************************************************************************************/77 class UILineChart : public UIChart78 {79 80 Q_OBJECT;81 82 public:83 84 UILineChart(QWidget *pParent, const UISubMetric *pSubMetric);85 86 protected:87 88 virtual void paintEvent(QPaintEvent *pEvent) /* override */;89 90 };91 92 /*********************************************************************************************************************************93 * UIPieChart definition. *94 *********************************************************************************************************************************/95 class UIPieChart : public UIChart96 {97 98 Q_OBJECT;99 100 public:101 102 UIPieChart(QWidget *pParent, const UISubMetric *pSubMetric);103 104 protected:105 106 virtual void paintEvent(QPaintEvent *pEvent) /* override */;107 108 private:109 110 72 int m_iPieChartSize; 111 73 QRect m_pieChartRect; 112 74 113 75 }; 76 114 77 115 78 /********************************************************************************************************************************* … … 123 86 { 124 87 m_iMargin = qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin); 88 m_iPieChartSize = 1.5f * qApp->style()->pixelMetric(QStyle::PM_LargeIconSize); 89 m_pieChartRect = QRect(1.5 * m_iMargin, 1.5 * m_iMargin, m_iPieChartSize, m_iPieChartSize); 90 m_size = QSize(6 * m_iPieChartSize, 1.8 * m_iPieChartSize); 125 91 } 126 92 … … 176 142 } 177 143 178 /********************************************************************************************************************************* 179 * UILineChart implementation. * 180 *********************************************************************************************************************************/ 181 182 UILineChart::UILineChart(QWidget *pParent, const UISubMetric *pSubMetric) 183 :UIChart(pParent, pSubMetric) 184 { 185 // QPalette pal = palette(); 186 // pal.setColor(QPalette::Background, Qt::red); 187 // setAutoFillBackground(true); 188 // setPalette(pal); 189 } 190 191 void UILineChart::paintEvent(QPaintEvent *pEvent) 144 void UIChart::paintEvent(QPaintEvent *pEvent) 192 145 { 193 146 Q_UNUSED(pEvent); … … 247 200 } 248 201 249 painter.setPen(Qt::black);250 251 QFont painterFont;252 painterFont.setPixelSize(18);253 painter.setFont(painterFont);254 }255 256 257 /*********************************************************************************************************************************258 * UIPieChart implementation. *259 *********************************************************************************************************************************/260 261 UIPieChart::UIPieChart(QWidget *pParent, const UISubMetric *pSubMetric)262 :UIChart(pParent, pSubMetric)263 {264 QPalette pal = palette();265 pal.setColor(QPalette::Background, Qt::yellow);266 setAutoFillBackground(true);267 setPalette(pal);268 269 m_iPieChartSize = 1.5f * qApp->style()->pixelMetric(QStyle::PM_LargeIconSize);270 m_pieChartRect = QRect(m_iMargin, m_iMargin, m_iPieChartSize, m_iPieChartSize);271 272 m_size = QSize(3 * m_iPieChartSize + 2 * m_iMargin,273 m_iPieChartSize + 2 * m_iMargin + 4 * QApplication::fontMetrics().height());274 275 }276 277 void UIPieChart::paintEvent(QPaintEvent *pEvent)278 {279 Q_UNUSED(pEvent);280 281 QPainter painter(this);282 painter.setRenderHint(QPainter::Antialiasing);// | QPainter::TextAntialiasing);283 if (!m_pSubMetric)284 return;285 const QQueue<ULONG> &data = m_pSubMetric->data();286 287 if (data.isEmpty() || iMaximumQueueSize == 0)288 return;289 290 float fMaximum = m_pSubMetric->maximum();291 if (m_pSubMetric->isPercentage())292 fMaximum = 100.f;293 if (fMaximum == 0)294 return;295 202 296 203 /* Draw a whole non-filled circle: */ … … 299 206 300 207 QPointF center(m_pieChartRect.center()); 301 QPainterPath myPath; 302 myPath.moveTo(center); 208 QPainterPath fillPath; 209 QPainterPath dataPath; 210 dataPath.moveTo(center); 211 fillPath.moveTo(center); 303 212 float fAngle = 360.f * data.back() / fMaximum; 304 myPath.arcTo(m_pieChartRect, 90/*startAngle*/,213 dataPath.arcTo(m_pieChartRect, 90/*startAngle*/, 305 214 -1 * fAngle /*sweepLength*/); 306 307 QConicalGradient gradient; 308 gradient.setCenter(m_pieChartRect.center()); 309 gradient.setAngle(90); 310 gradient.setColorAt(0, Qt::red); 311 gradient.setColorAt(1, Qt::green); 312 313 //painter.setBrush(Qt::red); 314 painter.setBrush(gradient); 215 fillPath.arcTo(m_pieChartRect, 90/*startAngle*/, 216 -1 * 360 /*sweepLength*/); 217 218 /* First draw a white filled circle and that the arc for data: */ 219 QConicalGradient pieGradient; 220 pieGradient.setCenter(m_pieChartRect.center()); 221 pieGradient.setAngle(90); 222 pieGradient.setColorAt(0, Qt::red); 223 pieGradient.setColorAt(1, Qt::green); 224 315 225 painter.setPen(Qt::NoPen); 316 painter.drawPath(myPath); 317 318 painter.setFont(m_font); 319 painter.setPen(Qt::black); 320 int iFontHeight = painter.fontMetrics().height(); 321 int iTextY = m_pieChartRect.bottomLeft().y() + m_iMargin + iFontHeight; 322 //QString strLastValue = QString("%1%2").arg(QString::number(data.back())).arg(m_pSubMetric->unit()); 323 for (int i = 0; i < m_textList.size(); ++i) 324 painter.drawText(m_iMargin, iTextY + i * iFontHeight, m_textList[i]); 325 } 326 226 painter.setBrush(Qt::white); 227 painter.drawPath(fillPath); 228 painter.setBrush(pieGradient); 229 painter.drawPath(dataPath); 230 } 327 231 328 232 /********************************************************************************************************************************* … … 462 366 iterator != m_subMetrics.end(); ++iterator) 463 367 { 464 UIPieChart *pPieChart = new UIPieChart(this, &(iterator.value())); 465 pPieChart->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); 466 m_charts.insert(iterator.key(), pPieChart); 467 m_pMainLayout->addWidget(pPieChart, iRow, 0); 468 469 470 UILineChart *pChart = new UILineChart(this, &(iterator.value())); 368 QLabel *pLabel = new QLabel; 369 m_pMainLayout->addWidget(pLabel, iRow, 0); 370 m_infoLabels.insert(iterator.key(), pLabel); 371 372 UIChart *pChart = new UIChart(this, &(iterator.value())); 471 373 m_charts.insert(iterator.key(), pChart); 472 374 pChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); … … 551 453 } 552 454 553 //printf("total ram %u %u\n", iTotalRAM, iFreeRAM);554 555 556 557 455 /* Update the CPU load chart with values we get from IMachineDebugger::getCPULoad(..): */ 558 456 if (m_subMetrics.contains(m_strCPUMetricName)) … … 565 463 CPUMetric.addData(aPctExecuting); 566 464 QList<UIChart*> charts = m_charts.values(m_strCPUMetricName); 567 QStringList textList; 568 textList << "CPU Load" 569 << QString("%1%2").arg(QString::number(aPctExecuting)).arg("%"); 570 foreach (UIChart* pChart, charts) 571 if (pChart) 572 pChart->setTextList(textList); 465 QString strInfo = QString("%1\n%2%3").arg("CPU Load").arg(QString::number(aPctExecuting)).arg("%"); 466 if (m_infoLabels.contains(m_strCPUMetricName)) 467 m_infoLabels[m_strCPUMetricName]->setText(strInfo); 468 if (m_charts.contains(m_strCPUMetricName)) 469 m_charts[m_strCPUMetricName]->update(); 573 470 } 574 471 … … 578 475 RAMMetric.setMaximum(iTotalRAM); 579 476 RAMMetric.addData(iTotalRAM - iFreeRAM); 580 581 QStringList textList; 582 textList << "RAM Usage" 583 << QString("%1: %2"). arg("Total:").arg(uiCommon().formatSize(_1K * iTotalRAM)) 584 << QString("%1: %2"). arg("Free:").arg(uiCommon().formatSize(_1K * (iFreeRAM))) 585 << QString("%1: %2"). arg("Used:").arg(uiCommon().formatSize(_1K * (iTotalRAM - iFreeRAM))); 586 QList<UIChart*> charts = m_charts.values(m_strRAMMetricName); 587 foreach (UIChart* pChart, charts) 588 if (pChart) 589 pChart->setTextList(textList); 477 QString strInfo = QString("%1\n%2: %3\n%4: %5\n%6: %7").arg("RAM Usage").arg("Total").arg(uiCommon().formatSize(_1K * iTotalRAM)).arg("Free:").arg(uiCommon().formatSize(_1K * (iFreeRAM))).arg("Used:").arg(uiCommon().formatSize(_1K * (iTotalRAM - iFreeRAM))); 478 if (m_infoLabels.contains(m_strRAMMetricName)) 479 m_infoLabels[m_strRAMMetricName]->setText(strInfo); 480 481 if (m_charts.contains(m_strRAMMetricName)) 482 { 483 m_charts[m_strRAMMetricName]->update(); 484 } 590 485 } 591 486 592 487 /* Try to compute a global font size so that all texts fit to widgets: */ 593 int iMinimumFontSize = 24;594 foreach (UIChart *pChart, m_charts)595 {596 if (!qobject_cast<UIPieChart*>(pChart))597 continue;598 iMinimumFontSize = qMin(pChart->fontSize(), iMinimumFontSize);599 }600 601 foreach (UIChart *pChart, m_charts)602 {603 if (!pChart)604 continue;605 pChart->setFontSize(iMinimumFontSize);606 pChart->update();607 }488 // int iMinimumFontSize = 24; 489 // foreach (UIChart *pChart, m_charts) 490 // { 491 // if (!qobject_cast<UIPieChart*>(pChart)) 492 // continue; 493 // iMinimumFontSize = qMin(pChart->fontSize(), iMinimumFontSize); 494 // } 495 496 // foreach (UIChart *pChart, m_charts) 497 // { 498 // if (!pChart) 499 // continue; 500 // pChart->setFontSize(iMinimumFontSize); 501 // pChart->update(); 502 // } 608 503 609 504 … … 653 548 if (strName.contains("RAM", Qt::CaseInsensitive) && strName.contains("Free", Qt::CaseInsensitive)) 654 549 { 655 //printf("xxxx %s %d\n", qPrintable(metrics[i].GetMetricName()), metrics[i].GetCount());656 550 QString strRAMMetricName(m_strRAMMetricName); 657 551 m_subMetrics.insert(strRAMMetricName, UISubMetric(strRAMMetricName, metrics[i].GetUnit(), iMaximumQueueSize)); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIPerformanceMonitor.h
r80132 r80158 42 42 class QTimer; 43 43 class QGridLayout; 44 class QLabel; 44 45 class UIChart; 45 46 … … 118 119 119 120 QMap<QString, UISubMetric> m_subMetrics; 120 QMultiMap<QString,UIChart*> m_charts; 121 QMap<QString,UIChart*> m_charts; 122 QMap<QString,QLabel*> m_infoLabels; 123 121 124 QString m_strCPUMetricName; 122 125 QString m_strRAMMetricName;
Note:
See TracChangeset
for help on using the changeset viewer.