VirtualBox

Changeset 88895 in vbox for trunk


Ignore:
Timestamp:
May 6, 2021 10:23:17 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9510. Adding a follow mouse feature

Location:
trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.cpp

    r88886 r88895  
    9999    void setIsAvailable(bool fIsAvailable);
    100100
     101    void setMouseOver(bool isOver);
     102
    101103protected:
    102104
     
    122124       void drawPieChart(QPainter &painter, quint64 iMaximum, int iDataIndex, const QRectF &chartRect, bool fWithBorder = true);
    123125       void drawCombinedPieCharts(QPainter &painter, quint64 iMaximum);
    124 
     126       QString YAxisValueLabel(quint64 iValue) const;
    125127       /** Drawing an overlay rectangle over the charts to indicate that they are disabled. */
    126128       void drawDisabledChartRectangle(QPainter &painter);
     
    161163    QString m_strPieChartToggleActionLabel;
    162164    QString m_strAreaChartToggleActionLabel;
     165    bool    m_fDrawCurenValueIndicators;
    163166};
    164167
     
    180183    , m_fIsAvailable(true)
    181184    , m_fIsAreaChartAllowed(false)
     185    , m_fDrawCurenValueIndicators(true)
    182186{
    183187    m_axisFont = font();
     
    191195    m_dataSeriesColor[1] = QColor(0, 0, 200, 255);
    192196
    193     m_iMarginLeft = 1 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
    194     m_iMarginRight = 9 * QFontMetrics(m_axisFont).width('X');
     197    m_iMarginLeft = 3 * QFontMetrics(m_axisFont).averageCharWidth();
     198    m_iMarginRight = 9 * QFontMetrics(m_axisFont).averageCharWidth();
    195199    m_iMarginTop = 0.3 * qApp->QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
    196200    m_iMarginBottom = QFontMetrics(m_axisFont).height();
     
    309313}
    310314
     315void UIChart::setMouseOver(bool isOver)
     316{
     317    if (!isOver)
     318        m_iDataIndexUnderCursor = -1;
     319}
     320
    311321QSize UIChart::minimumSizeHint() const
    312322{
     
    338348void UIChart::mouseMoveEvent(QMouseEvent *pEvent)
    339349{
    340     int iX = pEvent->x();
     350    int iX = width() - pEvent->x() - m_iMarginRight;
    341351    m_iDataIndexUnderCursor = -1;
    342352    if (iX > m_iMarginLeft && iX <= width() - m_iMarginRight)
    343         m_iDataIndexUnderCursor = (int)(g_iMaximumQueueSize -  (iX - m_iMarginLeft) / m_fPixelPerDataPoint);
     353        m_iDataIndexUnderCursor = (int)((iX) / m_fPixelPerDataPoint) + 1;
     354    update();
    344355    QIWithRetranslateUI<QWidget>::mouseMoveEvent(pEvent);
    345356}
     
    399410
    400411    quint64 iMaximum = m_pMetric->maximum();
     412    QFontMetrics fontMetrics(painter.font());
     413    int iFontHeight = fontMetrics.height();
     414    int iAverageFontWidth = fontMetrics.averageCharWidth();
     415
    401416    /* Draw a straight line per data series: */
    402417    if (iMaximum == 0)
     
    404419        for (int k = 0; k < DATA_SERIES_SIZE; ++k)
    405420        {
    406 
    407421            QLineF bar(0 + m_iMarginLeft, height() - m_iMarginBottom,
    408422                       width() - m_iMarginRight, height() - m_iMarginBottom);
    409423            painter.drawLine(bar);
    410424            painter.setPen(QPen(m_dataSeriesColor[k], 2.5));
    411 
    412425            painter.setBrush(m_dataSeriesColor[k]);
    413 
    414426        }
    415427    }
     
    428440                painter.setPen(QPen(gradient, 2.5));
    429441            }
    430 
    431442            const QQueue<quint64> *data = m_pMetric->data(k);
    432443            if (!m_fUseGradientLineColor)
     
    467478                }
    468479            }
     480            /* Draw a horizontal and vertical line on data point under the mouse cursor
     481             * and draw the value on the left hand side of the chart: */
     482            if (m_fDrawCurenValueIndicators && m_iDataIndexUnderCursor >= 0 && m_iDataIndexUnderCursor < data->size())
     483            {
     484                painter.setPen(QPen(m_dataSeriesColor[k], 0.5));
     485                float fHeight = fH * data->at(data->size() - m_iDataIndexUnderCursor);
     486                if (fHeight > 0)
     487                {
     488                    painter.drawLine(m_iMarginLeft, height() - (fHeight + m_iMarginBottom),
     489                                     width() - m_iMarginRight, height() - (fHeight + m_iMarginBottom));
     490                    QPoint cursorPosition = mapFromGlobal(cursor().pos());
     491                    painter.setPen(mainAxisColor);
     492                    painter.drawLine(cursorPosition.x(), 0,
     493                                     cursorPosition.x(), height() - m_iMarginBottom);
     494                    QString strValue = QString::number(data->at(data->size() - m_iDataIndexUnderCursor));
     495                    painter.drawText(m_iMarginLeft - fontMetrics.width(strValue) - iAverageFontWidth,
     496                                     height() - (fHeight + m_iMarginBottom) + 0.5 * iFontHeight, strValue);
     497
     498                }
     499            }
    469500        }
    470501    }// else of if (iMaximum == 0)
    471 
    472     QFontMetrics fontMetrics(painter.font());
    473     int iFontHeight = fontMetrics.height();
    474502
    475503    /* Draw YAxis tick labels: */
     
    481509            break;
    482510        int iTextY = 0.5 * iFontHeight + m_iMarginTop + i * m_lineChartRect.height() / (float) (iYSubAxisCount + 1);
    483         QString strValue;
    484511        quint64 iValue = (iYSubAxisCount + 1 - i) * (iMaximum / (float) (iYSubAxisCount + 1));
    485         if (m_pMetric->unit().compare("%", Qt::CaseInsensitive) == 0)
    486             strValue = QString::number(iValue);
    487         else if (m_pMetric->unit().compare("kb", Qt::CaseInsensitive) == 0)
    488             strValue = uiCommon().formatSize(_1K * (quint64)iValue, g_iDecimalCount);
    489         else if (m_pMetric->unit().compare("b", Qt::CaseInsensitive) == 0 ||
    490                  m_pMetric->unit().compare("b/s", Qt::CaseInsensitive) == 0)
    491             strValue = uiCommon().formatSize(iValue, g_iDecimalCount);
    492         else if (m_pMetric->unit().compare("times", Qt::CaseInsensitive) == 0)
    493             strValue = UICommon::addMetricSuffixToNumber(iValue);
    494 
     512        QString strValue = YAxisValueLabel(iValue);
    495513        painter.drawText(width() - 0.9 * m_iMarginRight, iTextY, strValue);
    496514    }
     
    499517        drawCombinedPieCharts(painter, iMaximum);
    500518}
     519
     520QString UIChart::YAxisValueLabel(quint64 iValue) const
     521{
     522    if (m_pMetric->unit().compare("%", Qt::CaseInsensitive) == 0)
     523        return QString::number(iValue);
     524    else if (m_pMetric->unit().compare("kb", Qt::CaseInsensitive) == 0)
     525        return uiCommon().formatSize(_1K * (quint64)iValue, g_iDecimalCount);
     526    else if (m_pMetric->unit().compare("b", Qt::CaseInsensitive) == 0 ||
     527             m_pMetric->unit().compare("b/s", Qt::CaseInsensitive) == 0)
     528        return uiCommon().formatSize(iValue, g_iDecimalCount);
     529    else if (m_pMetric->unit().compare("times", Qt::CaseInsensitive) == 0)
     530        return UICommon::addMetricSuffixToNumber(iValue);
     531    return QString();
     532}
     533
    501534
    502535void UIChart::drawXAxisLabels(QPainter &painter, int iXSubAxisCount)
     
    9761009}
    9771010
     1011bool UIVMActivityMonitor::eventFilter(QObject *pObj, QEvent *pEvent)
     1012{
     1013    if (pEvent-> type() == QEvent::Enter ||
     1014        pEvent-> type() == QEvent::Leave)
     1015    {
     1016        UIChart *pChart = qobject_cast<UIChart*>(pObj);
     1017        if (pChart)
     1018            pChart->setMouseOver(pEvent-> type() == QEvent::Enter);
     1019    }
     1020    return false;
     1021}
     1022
    9781023void UIVMActivityMonitor::prepareWidgets()
    9791024{
     
    10211066
    10221067        UIChart *pChart = new UIChart(this, &(m_metrics[strMetricName]));
     1068        pChart->installEventFilter(this);
    10231069        connect(pChart, &UIChart::sigExportMetricsToFile,
    10241070                this, &UIVMActivityMonitor::sltExportMetricsToFile);
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.h

    r88881 r88895  
    148148protected:
    149149
    150     void retranslateUi();
     150    virtual void retranslateUi() /* override */;
     151    virtual bool eventFilter(QObject *pObj, QEvent *pEvent) /* override */;
    151152
    152153private slots:
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