Index: trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp	(revision 83516)
+++ trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp	(revision 83517)
@@ -67,4 +67,38 @@
 
 /*********************************************************************************************************************************
+*   Class UIVMResourceMonitorDoughnutChart definition.                                                                           *
+*********************************************************************************************************************************/
+
+class UIVMResourceMonitorDoughnutChart : public QWidget
+{
+
+    Q_OBJECT;
+
+public:
+
+    UIVMResourceMonitorDoughnutChart(QWidget *pParent = 0);
+    void updateData(quint64 iData0, quint64 iData1);
+    void setChartColors(const QColor &color0, const QColor &color1);
+    void setChartCenterString(const QString &strCenter);
+    void setDataMaximum(quint64 iMax);
+
+protected:
+
+    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
+
+private:
+
+    quint64 m_iData0;
+    quint64 m_iData1;
+    quint64 m_iDataMaximum;
+    int m_iMargin;
+    QColor m_color0;
+    QColor m_color1;
+    /** If not empty this text is drawn at the center of the doughnut chart. */
+    QString m_strCenter;
+};
+
+
+/*********************************************************************************************************************************
 *   Class UIVMResourceMonitorHostStats definition.                                                                               *
 *********************************************************************************************************************************/
@@ -85,64 +119,4 @@
 
 /*********************************************************************************************************************************
-*   Class UIVMResourceMonitorHostCPUWidget definition.                                                                           *
-*********************************************************************************************************************************/
-
-class UIVMResourceMonitorHostCPUWidget : public QWidget
-{
-
-    Q_OBJECT;
-
-public:
-
-    UIVMResourceMonitorHostCPUWidget(QWidget *pParent = 0);
-    void setCPULoad(quint64 iUserLoad, quint64 iKernelLoad, quint64 iCPUFreq);
-    void setChartColors(const QColor &CPUUserLoadColor, const QColor &CPUKernelLoadColor);
-
-protected:
-
-    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
-
-private:
-
-    quint64 m_iCPUUserLoad;
-    quint64 m_iCPUKernelLoad;
-    quint64 m_iCPUFreq;
-    int m_iMargin;
-    QColor m_CPUUserColor;
-    QColor m_CPUKernelColor;
-};
-
-
-/*********************************************************************************************************************************
-*   Class UIVMResourceMonitorHostRAMWidget definition.                                                                           *
-*********************************************************************************************************************************/
-
-class UIVMResourceMonitorHostRAMWidget : public QWidget
-{
-
-    Q_OBJECT;
-
-public:
-
-    UIVMResourceMonitorHostRAMWidget(QWidget *pParent = 0);
-    void setRAMStats(quint64 iTotalRAM, quint64 iFreeRAM);
-    void setChartColors(const QColor &RAMFreeColor, const QColor &RAMUsedColor);
-
-protected:
-
-    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
-
-private:
-
-    quint64 m_iTotalRAM;
-    quint64 m_iFreeRAM;
-
-    int m_iMargin;
-    QColor m_RAMFreeColor;
-    QColor m_RAMUsedColor;
-};
-
-
-/*********************************************************************************************************************************
 *   Class UIVMResourceMonitorHostStatsWidget definition.                                                                         *
 *********************************************************************************************************************************/
@@ -167,6 +141,6 @@
     void updateLabels();
 
-    UIVMResourceMonitorHostCPUWidget   *m_pHostCPUChart;
-    UIVMResourceMonitorHostRAMWidget   *m_pHostRAMChart;
+    UIVMResourceMonitorDoughnutChart   *m_pHostCPUChart;
+    UIVMResourceMonitorDoughnutChart   *m_pHostRAMChart;
     QLabel                             *m_pCPUTitleLabel;
     QLabel                             *m_pCPUUserLabel;
@@ -378,31 +352,40 @@
 
 /*********************************************************************************************************************************
-*   Class UIVMResourceMonitorHostCPUWidget implementation.                                                                       *
-*********************************************************************************************************************************/
-
-UIVMResourceMonitorHostCPUWidget::UIVMResourceMonitorHostCPUWidget(QWidget *pParent /* = 0 */)
+*   Class UIVMResourceMonitorDoughnutChart implementation.                                                                       *
+*********************************************************************************************************************************/
+
+UIVMResourceMonitorDoughnutChart::UIVMResourceMonitorDoughnutChart(QWidget *pParent /* = 0 */)
     :QWidget(pParent)
-    , m_iCPUUserLoad(0)
-    , m_iCPUKernelLoad(0)
-    , m_iCPUFreq(0)
-{
-    m_iMargin = 3;
-}
-
-void UIVMResourceMonitorHostCPUWidget::setCPULoad(quint64 iUserLoad, quint64 iKernelLoad, quint64 iFreq)
-{
-    m_iCPUUserLoad = iUserLoad;
-    m_iCPUKernelLoad = iKernelLoad;
-    m_iCPUFreq = iFreq;
+    , m_iData0(0)
+    , m_iData1(0)
+    , m_iDataMaximum(0)
+    , m_iMargin(3)
+{
+}
+
+void UIVMResourceMonitorDoughnutChart::updateData(quint64 iData0, quint64 iData1)
+{
+    m_iData0 = iData0;
+    m_iData1 = iData1;
     update();
 }
 
-void UIVMResourceMonitorHostCPUWidget::setChartColors(const QColor &CPUUserLoadColor, const QColor &CPUKernelLoadColor)
-{
-    m_CPUUserColor = CPUUserLoadColor;
-    m_CPUKernelColor = CPUKernelLoadColor;
-}
-
-void UIVMResourceMonitorHostCPUWidget::paintEvent(QPaintEvent *pEvent)
+void UIVMResourceMonitorDoughnutChart::setChartColors(const QColor &color0, const QColor &color1)
+{
+    m_color0 = color0;
+    m_color1 = color1;
+}
+
+void UIVMResourceMonitorDoughnutChart::setChartCenterString(const QString &strCenter)
+{
+    m_strCenter = strCenter;
+}
+
+void UIVMResourceMonitorDoughnutChart::setDataMaximum(quint64 iMax)
+{
+    m_iDataMaximum = iMax;
+}
+
+void UIVMResourceMonitorDoughnutChart::paintEvent(QPaintEvent *pEvent)
 {
     QWidget::paintEvent(pEvent);
@@ -414,66 +397,15 @@
     QRectF outerRect = QRectF(QPoint(m_iMargin,m_iMargin), QSize(iFrameHeight, iFrameHeight));
     QRectF innerRect = UIMonitorCommon::getScaledRect(outerRect, 0.6f, 0.6f);
-    UIMonitorCommon::drawCombinedDoughnutChart(m_iCPUKernelLoad, m_CPUKernelColor,
-                                               m_iCPUUserLoad, m_CPUUserColor,
-                                               painter, 100,
+    UIMonitorCommon::drawCombinedDoughnutChart(m_iData0, m_color0,
+                                               m_iData1, m_color1,
+                                               painter, m_iDataMaximum,
                                                outerRect, innerRect, 80);
-    float mul = 1.f / 1.4f;
-    QRectF textRect =  UIMonitorCommon::getScaledRect(innerRect, mul, mul);
-    painter.setPen(Qt::black);
-    painter.drawText(textRect, Qt::AlignCenter, QString("%1\nMHz").arg(QString::number(m_iCPUFreq)));
-}
-
-
-/*********************************************************************************************************************************
-*   Class UIVMResourceMonitorHostRAMWidget implementation.                                                                       *
-*********************************************************************************************************************************/
-
-UIVMResourceMonitorHostRAMWidget::UIVMResourceMonitorHostRAMWidget(QWidget *pParent /* = 0 */)
-    :QWidget(pParent)
-    , m_iTotalRAM(0)
-    , m_iFreeRAM(0)
-{
-    m_iMargin = 3;
-}
-void UIVMResourceMonitorHostRAMWidget::setRAMStats(quint64 iTotalRAM, quint64 iFreeRAM)
-{
-    m_iTotalRAM = iTotalRAM;
-    m_iFreeRAM = iFreeRAM;
-    update();
-}
-
-void UIVMResourceMonitorHostRAMWidget::setChartColors(const QColor &RAMFreeColor, const QColor &RAMUsedColor)
-{
-    m_RAMFreeColor = RAMFreeColor;
-    m_RAMUsedColor = RAMUsedColor;
-}
-
-void UIVMResourceMonitorHostRAMWidget::paintEvent(QPaintEvent *pEvent)
-{
-
-    QWidget::paintEvent(pEvent);
-
-    QPainter painter(this);
-    painter.setRenderHint(QPainter::Antialiasing);
-
-    int iFrameHeight = height()- 2 * m_iMargin;
-    QRectF outerRect = QRectF(QPoint(m_iMargin,m_iMargin), QSize(iFrameHeight, iFrameHeight));
-    QRectF innerRect = UIMonitorCommon::getScaledRect(outerRect, 0.6f, 0.6f);
-    quint64 iUsedRAM = m_iTotalRAM - m_iFreeRAM;
-
-    UIMonitorCommon::drawCombinedDoughnutChart(iUsedRAM, m_RAMUsedColor,
-                                               m_iFreeRAM, m_RAMFreeColor,
-                                               painter, m_iTotalRAM,
-                                               outerRect, innerRect, 80);
-
-    if (m_iTotalRAM != 0)
+    if (!m_strCenter.isEmpty())
     {
         float mul = 1.f / 1.4f;
         QRectF textRect =  UIMonitorCommon::getScaledRect(innerRect, mul, mul);
         painter.setPen(Qt::black);
-        int iPercent = 100 * (iUsedRAM / (float) m_iTotalRAM);
-        painter.drawText(textRect, Qt::AlignCenter, QString("%1%\nUsed").arg(QString::number(iPercent)));
-    }
-
+        painter.drawText(textRect, Qt::AlignCenter, m_strCenter);
+    }
 }
 
@@ -514,7 +446,21 @@
     m_hostStats = hostStats;
     if (m_pHostCPUChart)
-        m_pHostCPUChart->setCPULoad(m_hostStats.m_iCPUUserLoad, m_hostStats.m_iCPUKernelLoad, m_hostStats.m_iCPUFreq);
+    {
+        m_pHostCPUChart->updateData(m_hostStats.m_iCPUUserLoad, m_hostStats.m_iCPUKernelLoad);
+        QString strCenter = QString("%1\nMHz").arg(m_hostStats.m_iCPUFreq);
+        m_pHostCPUChart->setChartCenterString(strCenter);
+    }
     if (m_pHostRAMChart)
-        m_pHostRAMChart->setRAMStats(m_hostStats.m_iTotalRAM, m_hostStats.m_iFreeRAM);
+    {
+        quint64 iUsedRAM = m_hostStats.m_iTotalRAM - m_hostStats.m_iFreeRAM;
+        m_pHostRAMChart->updateData(iUsedRAM, m_hostStats.m_iFreeRAM);
+        m_pHostRAMChart->setDataMaximum(m_hostStats.m_iTotalRAM);
+        if (m_hostStats.m_iTotalRAM != 0)
+        {
+            quint64 iUsedRamPer = 100 * (iUsedRAM / (float) m_hostStats.m_iTotalRAM);
+            QString strCenter = QString("%1%\n%2").arg(iUsedRamPer).arg(tr("Used"));
+            m_pHostRAMChart->setChartCenterString(strCenter);
+        }
+    }
     updateLabels();
 }
@@ -556,11 +502,11 @@
         pCPULabelsLayout->addWidget(m_pCPUTotalLabel);
         pCPULabelsLayout->setAlignment(Qt::AlignTop);
-        //pLayout->setAlignment(Qt::AlignTop);
         pCPULabelsLayout->setSpacing(0);
         /* Host CPU chart widget: */
-        m_pHostCPUChart = new UIVMResourceMonitorHostCPUWidget;
+        m_pHostCPUChart = new UIVMResourceMonitorDoughnutChart;
         if (m_pHostCPUChart)
         {
             m_pHostCPUChart->setMinimumSize(iMinimumSize, iMinimumSize);
+            m_pHostCPUChart->setDataMaximum(100);
             pLayout->addWidget(m_pHostCPUChart);
             m_pHostCPUChart->setChartColors(m_CPUUserColor, m_CPUKernelColor);
@@ -585,10 +531,10 @@
         pRAMLabelsLayout->addWidget(m_pRAMTotalLabel);
 
-        m_pHostRAMChart = new UIVMResourceMonitorHostRAMWidget;
+        m_pHostRAMChart = new UIVMResourceMonitorDoughnutChart;
         if (m_pHostRAMChart)
         {
             m_pHostRAMChart->setMinimumSize(iMinimumSize, iMinimumSize);
             pLayout->addWidget(m_pHostRAMChart);
-            m_pHostRAMChart->setChartColors(m_RAMFreeColor, m_RAMUsedColor);
+            m_pHostRAMChart->setChartColors(m_RAMUsedColor, m_RAMFreeColor);
         }
     }
