VirtualBox

Changeset 83496 in vbox


Ignore:
Timestamp:
Mar 31, 2020 12:02:10 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9686. Moving some code to the common area.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/monitor
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/UIMonitorCommon.cpp

    r83380 r83496  
    1717
    1818/* Qt includes: */
     19#include <QPainter>
    1920#include <QXmlStreamReader>
    2021
     
    147148    }
    148149}
     150
     151/* static */
     152QPainterPath UIMonitorCommon::doughnutSlice(const QRectF &outerRectangle, const QRectF &innerRectangle, float fStartAngle, float fSweepAngle)
     153{
     154    QPainterPath subPath1;
     155    subPath1.moveTo(outerRectangle.center());
     156    subPath1.arcTo(outerRectangle, fStartAngle,
     157                   -1.f * fSweepAngle);
     158    subPath1.closeSubpath();
     159
     160    QPainterPath subPath2;
     161    subPath2.moveTo(innerRectangle.center());
     162    subPath2.arcTo(innerRectangle, fStartAngle,
     163                   -1.f * fSweepAngle);
     164    subPath2.closeSubpath();
     165
     166    return subPath1.subtracted(subPath2);
     167}
     168
     169/* static */
     170QPainterPath UIMonitorCommon::wholeArc(const QRectF &rectangle)
     171{
     172    QPainterPath arc;
     173    arc.addEllipse(rectangle);
     174    return arc;
     175}
     176
     177/* static */
     178void UIMonitorCommon::drawCombinedDoughnutChart(quint64 data1, const QColor &data1Color,
     179                               quint64 data2, const QColor &data2Color,
     180                               QPainter &painter, quint64  iMaximum,
     181                               const QRectF &chartRect, const QRectF &innerRect, int iOverlayAlpha)
     182{
     183    /* Draw two arcs. one for the inner the other for the outer circle: */
     184    painter.setPen(QPen(QColor(100, 100, 100, iOverlayAlpha), 1));
     185    painter.drawArc(chartRect, 0, 3600 * 16);
     186    painter.drawArc(innerRect, 0, 3600 * 16);
     187
     188    /* Draw a translucent white background: */
     189    QPainterPath background = wholeArc(chartRect).subtracted(wholeArc(innerRect));
     190    painter.setPen(Qt::NoPen);
     191    painter.setBrush(QColor(255, 255, 255, iOverlayAlpha));
     192    painter.drawPath(background);
     193
     194    /* Draw a doughnut slice for the first data series: */
     195    float fAngle = 360.f * data1 / (float)iMaximum;
     196    painter.setBrush(data1Color);
     197    painter.drawPath(doughnutSlice(chartRect, innerRect, 90, fAngle));
     198
     199    float fAngle2 = 360.f * data2 / (float)iMaximum;
     200    painter.setBrush(data2Color);
     201    painter.drawPath(doughnutSlice(chartRect, innerRect, 90 - fAngle, fAngle2));
     202}
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/UIMonitorCommon.h

    r83380 r83496  
    4949                               QVector<CUnknown>& objectList, quint64 &iOutTotalRAM, quint64 &iOutFreeRAM);
    5050
     51
     52        static QPainterPath doughnutSlice(const QRectF &outerRectangle, const QRectF &innerRectangle, float fStartAngle, float fSweepAngle);
     53        static QPainterPath wholeArc(const QRectF &rectangle);
     54        static void drawCombinedDoughnutChart(quint64 data1, const QColor &data1Color,
     55                                              quint64 data2, const QColor &data2Color,
     56                                              QPainter &painter, quint64  iMaximum,
     57                                              const QRectF &chartRect, const QRectF &innerRect, int iOverlayAlpha);
     58
     59
    5160private:
    5261
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/performance/UIPerformanceMonitor.cpp

    r83380 r83496  
    108108       void drawDoughnutChart(QPainter &painter, quint64 iMaximum, int iDataIndex,
    109109                              const QRectF &chartRect, const QRectF &innerRect);
    110        /** Draws a doughnut shaped shart for two data series combines. the 2nd data is added on top of 1st. */
    111        void drawCombinedDoughnutChart(QPainter &painter, quint64 iMaximum,
    112                                       const QRectF &chartRect, const QRectF &innerRect);
    113110
    114111       /** Drawing an overlay rectangle over the charts to indicate that they are disabled. */
    115112       void drawDisabledChartRectangle(QPainter &painter);
    116        /* Returns a half translucent complete arc. */
    117        QPainterPath wholeArc(const QRectF &rectangle);
    118        QPainterPath doughnutSlice(const QRectF &outerRectangle, const QRectF &innerRectangle,
    119                                   float fStartAngle, float fSweepAngle);
    120113       QConicalGradient conicalGradientForDataSeries(const QRectF &rectangle, int iDataIndex);
    121114    /** @} */
     
    187180    retranslateUi();
    188181}
    189 
    190182
    191183bool UIChart::isPieChartAllowed() const
     
    474466
    475467   /* Draw a white filled circle and that the arc for data: */
    476     QPainterPath background = wholeArc(chartRect);
     468    QPainterPath background = UIMonitorCommon::wholeArc(chartRect);
    477469    painter.setPen(Qt::NoPen);
    478470    painter.setBrush(QColor(255, 255, 255, m_iOverlayAlpha));
     
    502494
    503495    /* Draw a white filled circle and the arc for data: */
    504     QPainterPath background = wholeArc(chartRect).subtracted(wholeArc(innerRect));
     496    QPainterPath background = UIMonitorCommon::wholeArc(chartRect).subtracted(UIMonitorCommon::wholeArc(innerRect));
    505497    painter.setPen(Qt::NoPen);
    506498    painter.setBrush(QColor(255, 255, 255, m_iOverlayAlpha));
     
    510502    float fAngle = 360.f * data->back() / (float)iMaximum;
    511503    painter.setBrush(conicalGradientForDataSeries(chartRect, iDataIndex));
    512     painter.drawPath(doughnutSlice(chartRect, innerRect, 90, fAngle));
    513 }
    514 
    515 void UIChart::drawCombinedDoughnutChart(QPainter &painter, quint64  iMaximum,
    516                                const QRectF &chartRect, const QRectF &innerRect)
    517 {
    518     int iDataIndex = 0;
    519     const QQueue<quint64> *data = m_pMetric->data(iDataIndex);
    520     if (!data || data->isEmpty())
    521         return;
    522 
    523     /* Draw two arcs. one for the inner the other for the outer circle: */
    524     painter.setPen(QPen(QColor(100, 100, 100, m_iOverlayAlpha), 1));
    525     painter.drawArc(chartRect, 0, 3600 * 16);
    526     painter.drawArc(innerRect, 0, 3600 * 16);
    527 
    528     /* Draw a translucent white background: */
    529     QPainterPath background = wholeArc(chartRect).subtracted(wholeArc(innerRect));
    530     painter.setPen(Qt::NoPen);
    531     painter.setBrush(QColor(255, 255, 255, m_iOverlayAlpha));
    532     painter.drawPath(background);
    533 
    534     /* Draw a doughnut slice for the first data series: */
    535     float fAngle = 360.f * data->back() / (float)iMaximum;
    536     painter.setBrush(dataSeriesColor(iDataIndex, 50));
    537     painter.drawPath(doughnutSlice(chartRect, innerRect, 90, fAngle));
    538 
    539     /* Draw another slice for 2nd data series on top of the first if necessary: */
    540     iDataIndex = 1;
    541     const QQueue<quint64> *data2 = m_pMetric->data(iDataIndex);
    542     if (data2 && !data2->isEmpty())
    543     {
    544         float fAngle2 = 360.f * data2->back() / (float)iMaximum;
    545         painter.setBrush(dataSeriesColor(iDataIndex, 50));
    546         painter.drawPath(doughnutSlice(chartRect, innerRect, 90 - fAngle, fAngle2));
    547     }
    548 }
    549 
    550 QPainterPath UIChart::wholeArc(const QRectF &rectangle)
    551 {
    552     QPainterPath arc;
    553     arc.addEllipse(rectangle);
    554     return arc;
     504    painter.drawPath(UIMonitorCommon::doughnutSlice(chartRect, innerRect, 90, fAngle));
    555505}
    556506
     
    567517}
    568518
    569 QPainterPath UIChart::doughnutSlice(const QRectF &outerRectangle, const QRectF &innerRectangle, float fStartAngle, float fSweepAngle)
    570 {
    571     QPainterPath subPath1;
    572     subPath1.moveTo(outerRectangle.center());
    573     subPath1.arcTo(outerRectangle, fStartAngle,
    574                    -1.f * fSweepAngle);
    575     subPath1.closeSubpath();
    576 
    577     QPainterPath subPath2;
    578     subPath2.moveTo(innerRectangle.center());
    579     subPath2.arcTo(innerRectangle, fStartAngle,
    580                    -1.f * fSweepAngle);
    581     subPath2.closeSubpath();
    582 
    583     return subPath1.subtracted(subPath2);
    584 }
    585 
    586519void UIChart::drawCombinedPieCharts(QPainter &painter, quint64 iMaximum)
    587520{
     
    600533                         QSizeF(0.5 * chartRect.width(), 0.5 * chartRect.height()));
    601534        /* Draw a doughnut chart where data series are stacked on to of each other: */
    602         drawCombinedDoughnutChart(painter, iMaximum, chartRect, innerRect);
     535        if (m_pMetric->data(0) && !m_pMetric->data(0)->isEmpty() &&
     536            m_pMetric->data(1) && !m_pMetric->data(1)->isEmpty())
     537            UIMonitorCommon::drawCombinedDoughnutChart(m_pMetric->data(0)->back(), dataSeriesColor(0, 50),
     538                                                       m_pMetric->data(1)->back(), dataSeriesColor(1, 50),
     539                                                       painter, iMaximum, chartRect, innerRect, m_iOverlayAlpha);
    603540#if 0
    604541        /* Draw a doughnut shaped chart and then pie chart inside it: */
  • trunk/src/VBox/Frontends/VirtualBox/src/monitor/resource/UIResourceMonitor.cpp

    r83494 r83496  
    6161};
    6262
     63
     64/*********************************************************************************************************************************
     65*   Class UIVMResourceMonitorHostStatsWidget definition.                                                                         *
     66*********************************************************************************************************************************/
     67
     68class UIVMResourceMonitorHostStatsWidget : public QWidget
     69{
     70
     71    Q_OBJECT;
     72
     73
     74public:
     75
     76    UIVMResourceMonitorHostStatsWidget(QWidget *pParent = 0);
     77
     78};
     79
    6380/*********************************************************************************************************************************
    6481*   Class UIVMResourceMonitorTableView definition.                                                                           *
     
    167184};
    168185
    169 /*********************************************************************************************************************************
    170 *   Class UIVMResourceMonitorProxyModel definition.                                                                           *
     186
     187/*********************************************************************************************************************************
     188*   Class UIVMResourceMonitorProxyModel definition.                                                                              *
    171189*********************************************************************************************************************************/
    172190class UIResourceMonitorProxyModel : public QSortFilterProxyModel
     
    250268
    251269/*********************************************************************************************************************************
    252 *   UIVMResourceMonitorDelegate definition.                                                                                       *
     270*   UIVMResourceMonitorDelegate definition.                                                                                      *
    253271*********************************************************************************************************************************/
    254272/** A QItemDelegate child class to disable dashed lines drawn around selected cells in QTableViews */
     
    264282
    265283
    266 
    267 /*********************************************************************************************************************************
    268 *   Class UIVMResourceMonitorTableView implementation.                                                                            *
     284/*********************************************************************************************************************************
     285*   Class UIVMResourceMonitorHostStatsWidget implementation.                                                                     *
     286*********************************************************************************************************************************/
     287
     288UIVMResourceMonitorHostStatsWidget::UIVMResourceMonitorHostStatsWidget(QWidget *pParent /* = 0 */)
     289    :QWidget(pParent)
     290{
     291}
     292
     293
     294/*********************************************************************************************************************************
     295*   Class UIVMResourceMonitorTableView implementation.                                                                           *
    269296*********************************************************************************************************************************/
    270297
     
    414441
    415442/*********************************************************************************************************************************
    416 *   Class UIVMResourceMonitorHostStats implementation.                                                                            *
     443*   Class UIVMResourceMonitorHostStats implementation.                                                                           *
    417444*********************************************************************************************************************************/
    418445
     
    427454
    428455/*********************************************************************************************************************************
    429 *   Class UIVMResourceMonitorCheckBox implementation.                                                                             *
     456*   Class UIVMResourceMonitorCheckBox implementation.                                                                            *
    430457*********************************************************************************************************************************/
    431458
     
    446473
    447474/*********************************************************************************************************************************
    448 *   Class UIVMResourceMonitorProxyModel implementation.                                                                           *
     475*   Class UIVMResourceMonitorProxyModel implementation.                                                                          *
    449476*********************************************************************************************************************************/
    450477UIResourceMonitorProxyModel::UIResourceMonitorProxyModel(QObject *parent /* = 0 */)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette