VirtualBox

Changeset 80523 in vbox


Ignore:
Timestamp:
Sep 1, 2019 8:55:31 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133030
Message:

FE/Qt: bugref:9510: Updating screen info and uptime.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.cpp

    r80520 r80523  
    5454enum InfoLine
    5555{
     56    InfoLine_Title = 0,
    5657    InfoLine_Resolution,
    5758    InfoLine_Uptime,
     
    7980
    8081    UIRuntimeInfoWidget(QWidget *pParent, const CMachine &machine, const CConsole &console);
     82    void guestMonitorChange(ulong uScreenId);
    8183
    8284protected:
     
    8688    virtual QSize minimumSizeHint() const /* override */;
    8789
     90private slots:
     91
     92    void sltTimeout();
     93
    8894private:
    8995
    9096    void runTimeAttributes();
    91     QString screenResolutions();
    92 
    93     void insertInfoLine(InfoLine enmInfoLine, const QString& strLabel, const QString &strInfo);
     97    void updateScreenInfo(int iScreenId = -1);
     98    void updateUpTime();
     99    QString screenResolution(int iScreenId);
     100    /** Creates to QTableWidgetItems of tye @enmInfoLine using the @p strLabel and @p strInfo and inserts it
     101     * to the row @p iRow. If @p iRow is -1 then the items inserted to the end of the table. */
     102    void insertInfoLine(InfoLine enmInfoLine, const QString& strLabel, const QString &strInfo, int iRow = -1);
    94103    void computeMinimumWidth();
    95104
     
    122131    /** Computed by computing the maximum length line. Used to avoid having horizontal scroll bars. */
    123132    int m_iMinimumWidth;
     133    QVector<QString> m_screenResolutions;
     134    QTimer *m_pTimer;
    124135};
    125136
     
    212223    , m_console(console)
    213224    , m_iMinimumWidth(0)
     225    , m_pTimer(0)
    214226
    215227{
     
    226238    setSelectionMode(QAbstractItemView::NoSelection);
    227239
     240
     241    m_pTimer = new QTimer(this);
     242    if (m_pTimer)
     243    {
     244        connect(m_pTimer, &QTimer::timeout, this, &UIRuntimeInfoWidget::sltTimeout);
     245        m_pTimer->start(5000);
     246    }
     247
     248
    228249    retranslateUi();
    229250    /* Add the title row: */
    230     QTableWidgetItem *pTitleItem = new QTableWidgetItem(UIIconPool::iconSet(":/state_running_16px.png"), m_strTableTitle);
     251    QTableWidgetItem *pTitleItem = new QTableWidgetItem(UIIconPool::iconSet(":/state_running_16px.png"), m_strTableTitle, InfoLine_Title);
    231252    QFont titleFont(font());
    232253    titleFont.setBold(true);
     
    234255    insertRow(0);
    235256    setItem(0, 0, pTitleItem);
    236 
    237257    /* Make the API calls and populate the table: */
    238258    runTimeAttributes();
    239259    computeMinimumWidth();
     260}
     261
     262void UIRuntimeInfoWidget::guestMonitorChange(ulong uScreenId)
     263{
     264    updateScreenInfo(uScreenId);
    240265}
    241266
     
    272297}
    273298
    274 void UIRuntimeInfoWidget::insertInfoLine(InfoLine enmInfoLine, const QString& strLabel, const QString &strInfo)
     299void UIRuntimeInfoWidget::insertInfoLine(InfoLine enmInfoLine, const QString& strLabel, const QString &strInfo, int iRow /* = -1 */)
    275300{
    276301    int iMargin = 0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin);
    277     int iRow = rowCount();
    278     insertRow(iRow);
    279     setItem(iRow, 0, new QTableWidgetItem(strLabel, enmInfoLine));
    280     setItem(iRow, 1, new QTableWidgetItem(strInfo, enmInfoLine));
    281     setRowHeight(iRow, 2 * iMargin + m_iFontHeight);
    282 }
    283 
    284 QString UIRuntimeInfoWidget::screenResolutions()
    285 {
    286     QString strResolutions;
    287     return strResolutions;
    288 }
    289 
    290 void UIRuntimeInfoWidget::runTimeAttributes()
    291 {
    292     ULONG cGuestScreens = m_machine.GetMonitorCount();
    293     QVector<QString> aResolutions(cGuestScreens);
    294     for (ULONG iScreen = 0; iScreen < cGuestScreens; ++iScreen)
    295     {
    296         /* Determine resolution: */
    297         ULONG uWidth = 0;
    298         ULONG uHeight = 0;
    299         ULONG uBpp = 0;
    300         LONG xOrigin = 0;
    301         LONG yOrigin = 0;
    302         KGuestMonitorStatus monitorStatus = KGuestMonitorStatus_Enabled;
    303         m_console.GetDisplay().GetScreenResolution(iScreen, uWidth, uHeight, uBpp, xOrigin, yOrigin, monitorStatus);
    304         QString strResolution = QString("%1x%2").arg(uWidth).arg(uHeight);
    305         if (uBpp)
    306             strResolution += QString("x%1").arg(uBpp);
    307         strResolution += QString(" @%1,%2").arg(xOrigin).arg(yOrigin);
    308         if (monitorStatus == KGuestMonitorStatus_Disabled)
    309         {
    310             strResolution += QString(" ");
    311             strResolution += m_strMonitorTurnedOff;
    312         }
    313         aResolutions[iScreen] = strResolution;
    314     }
    315 
    316     /* Determine uptime: */
     302    int iNewRow = rowCount();
     303    if (iRow != -1 && iRow <= iNewRow)
     304        iNewRow = iRow;
     305    insertRow(iNewRow);
     306    setItem(iNewRow, 0, new QTableWidgetItem(strLabel, enmInfoLine));
     307    setItem(iNewRow, 1, new QTableWidgetItem(strInfo, enmInfoLine));
     308    setRowHeight(iNewRow, 2 * iMargin + m_iFontHeight);
     309}
     310
     311QString UIRuntimeInfoWidget::screenResolution(int iScreenID)
     312{
     313    /* Determine resolution: */
     314    ULONG uWidth = 0;
     315    ULONG uHeight = 0;
     316    ULONG uBpp = 0;
     317    LONG xOrigin = 0;
     318    LONG yOrigin = 0;
     319    KGuestMonitorStatus monitorStatus = KGuestMonitorStatus_Enabled;
     320    m_console.GetDisplay().GetScreenResolution(iScreenID, uWidth, uHeight, uBpp, xOrigin, yOrigin, monitorStatus);
     321    QString strResolution = QString("%1x%2").arg(uWidth).arg(uHeight);
     322    if (uBpp)
     323        strResolution += QString("x%1").arg(uBpp);
     324    strResolution += QString(" @%1,%2").arg(xOrigin).arg(yOrigin);
     325    if (monitorStatus == KGuestMonitorStatus_Disabled)
     326    {
     327        strResolution += QString(" ");
     328        strResolution += m_strMonitorTurnedOff;
     329    }
     330
     331    return strResolution;
     332}
     333
     334void UIRuntimeInfoWidget::sltTimeout()
     335{
     336    updateUpTime();
     337}
     338
     339void UIRuntimeInfoWidget::updateScreenInfo(int iScreenID /* = -1 */)
     340{
     341    ULONG uGuestScreens = m_machine.GetMonitorCount();
     342    m_screenResolutions.resize(uGuestScreens);
     343
     344    if (iScreenID != -1 && iScreenID >= (int)uGuestScreens)
     345        return;
     346    if (iScreenID == -1)
     347    {
     348        for (ULONG iScreen = 0; iScreen < uGuestScreens; ++iScreen)
     349            m_screenResolutions[iScreen] = screenResolution(iScreen);
     350    }
     351    else
     352        m_screenResolutions[iScreenID] = screenResolution(iScreenID);
     353    /* Delete all the rows (not only the updated screen's row) and reinsert them: */
     354    int iRowCount = rowCount();
     355    for (int i = iRowCount - 1; i >= 0; --i)
     356    {
     357        QTableWidgetItem *pItem = item(i, 0);
     358        if (pItem && pItem->type() == InfoLine_Resolution)
     359            removeRow(i);
     360    }
     361
     362    for (ULONG iScreen = 0; iScreen < uGuestScreens; ++iScreen)
     363    {
     364        QString strLabel = uGuestScreens > 1 ?
     365            QString("%1 %2:").arg(m_strScreenResolutionLabel).arg(QString::number(iScreen)) :
     366            QString("%1:").arg(m_strScreenResolutionLabel);
     367        /* Insert the screen resolution row at the top of the table. Row 0 is the title row: */
     368        insertInfoLine(InfoLine_Resolution, strLabel, m_screenResolutions[iScreen], iScreen + 1);
     369    }
     370    resizeColumnToContents(1);
     371}
     372
     373void UIRuntimeInfoWidget::updateUpTime()
     374{
    317375    CMachineDebugger debugger = m_console.GetDebugger();
    318376    uint32_t uUpSecs = (debugger.GetUptime() / 5000) * 5;
     
    328386    QString strUptime = QString(szUptime);
    329387
     388    QTableWidgetItem *pItem = 0;
     389    for (int i = 0; i < rowCount() && !pItem; ++i)
     390    {
     391        pItem = item(i, 1);
     392        if (!pItem)
     393            continue;
     394        if (pItem->type() != InfoLine_Uptime)
     395            pItem = 0;
     396    }
     397    if (!pItem)
     398        insertInfoLine(InfoLine_Uptime, QString("%1:").arg(m_strUptimeLabel), strUptime);
     399    else
     400        pItem->setText(strUptime);
     401}
     402
     403void UIRuntimeInfoWidget::runTimeAttributes()
     404{
     405    updateScreenInfo();
     406    updateUpTime();
     407
    330408    /* Determine clipboard mode: */
    331409    QString strClipboardMode = gpConverter->toString(m_machine.GetClipboardMode());
     
    334412
    335413    /* Determine virtualization attributes: */
     414    CMachineDebugger debugger = m_console.GetDebugger();
     415
    336416    QString strVirtualization = debugger.GetHWVirtExEnabled() ?
    337417        m_strActive : m_strInactive;
     
    386466        m_strNotAvailable : QString("%1").arg(iVRDEPort);
    387467
    388     /* Searching for longest string: */
    389     QStringList values;
    390     for (ULONG iScreen = 0; iScreen < cGuestScreens; ++iScreen)
    391         values << aResolutions[iScreen];
    392     values << strUptime
    393            << strExecutionEngine << strNestedPaging << strUnrestrictedExecution
    394            << strGAVersion << strOSType << strVRDEInfo;
    395     int iMaxLength = 0;
    396     foreach (const QString &strValue, values)
    397         iMaxLength = iMaxLength < QApplication::fontMetrics().width(strValue)
    398                                   ? QApplication::fontMetrics().width(strValue) : iMaxLength;
    399 
    400     /* Summary: */
    401     for (ULONG iScreen = 0; iScreen < cGuestScreens; ++iScreen)
    402     {
    403         QString strLabel = cGuestScreens > 1 ?
    404             QString("%1 %2:").arg(m_strScreenResolutionLabel).arg(QString::number(iScreen)) :
    405             QString("%1:").arg(m_strScreenResolutionLabel);
    406         insertInfoLine(InfoLine_Resolution, strLabel, aResolutions[iScreen]);
    407     }
    408 
    409     insertInfoLine(InfoLine_Uptime, QString("%1:").arg(m_strUptimeLabel), strUptime);
     468
    410469    insertInfoLine(InfoLine_ClipboardMode, QString("%1:").arg(m_strClipboardModeLabel), strClipboardMode);
    411470    insertInfoLine(InfoLine_DnDMode, QString("%1:").arg(m_strDragAndDropLabel), strDnDMode);
     
    10261085        m_comGuest = m_console.GetGuest();
    10271086    m_fGuestAdditionsAvailable = guestAdditionsAvailable(6 /* minimum major version */);
    1028 
    10291087    connect(pSession, &UISession::sigAdditionsStateChange, this, &UIInformationRuntime::sltGuestAdditionsStateChange);
     1088    connect(pSession, &UISession::sigGuestMonitorChange, this, &UIInformationRuntime::sltGuestMonitorChange);
     1089
    10301090    prepareMetrics();
    10311091    prepareObjects();
     
    11561216        m_charts[m_strCPUMetricName]->setWithPieChart(true);
    11571217
    1158     UIRuntimeInfoWidget *m_pRuntimeInfoWidget = new UIRuntimeInfoWidget(0, m_machine, m_console);
     1218    m_pRuntimeInfoWidget = new UIRuntimeInfoWidget(0, m_machine, m_console);
    11591219    pContainerLayout->addWidget(m_pRuntimeInfoWidget, iRow, 0, 2, 2);
    11601220    m_pRuntimeInfoWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
     
    12851345}
    12861346
     1347void UIInformationRuntime::sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo)
     1348{
     1349    Q_UNUSED(changeType);
     1350    Q_UNUSED(screenGeo);
     1351    printf("%lu\n", uScreenId);
     1352    if (m_pRuntimeInfoWidget)
     1353        m_pRuntimeInfoWidget->guestMonitorChange(uScreenId);
     1354}
     1355
    12871356void UIInformationRuntime::prepareMetrics()
    12881357{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.h

    r80494 r80523  
    154154    void sltTimeout();
    155155    void sltGuestAdditionsStateChange();
     156    void sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo);
    156157
    157158private:
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