VirtualBox

Ignore:
Timestamp:
Aug 21, 2019 11:43:11 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132834
Message:

FE/Qt: bugref:9510: Using QTableWidget in UIInformationRuntime instead of model/view structure

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationConfiguration.h

    r80357 r80369  
    3232
    3333/* GUI includes: */
    34 #include "UITextTable.h"
    3534#include "UIInformationWidget.h"
    3635
     
    4039
    4140
    42 /** QWidget extension
    43   * providing GUI with configuration-information tab in session-information window. */
    4441class UIInformationConfiguration : public UIInformationWidget
    4542{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.cpp

    r77594 r80369  
    1717
    1818/* Qt includes: */
     19#include <QApplication>
     20#include <QTableWidget>
     21#include <QTextDocument>
    1922#include <QVBoxLayout>
    20 #include <QApplication>
    2123
    2224/* GUI includes: */
     25#include "UICommon.h"
     26#include "UIConverter.h"
     27#include "UIIconPool.h"
    2328#include "UIInformationRuntime.h"
    2429#include "UIInformationDataItem.h"
     
    2833#include "UIInformationModel.h"
    2934
     35/* COM includes: */
     36#include "CDisplay.h"
     37#include "CMachineDebugger.h"
     38#include "CVRDEServerInfo.h"
    3039
    3140UIInformationRuntime::UIInformationRuntime(QWidget *pParent, const CMachine &machine, const CConsole &console)
    32     : QWidget(pParent)
    33     , m_machine(machine)
    34     , m_console(console)
    35     , m_pMainLayout(0)
    36     , m_pModel(0)
    37     , m_pView(0)
    38 {
    39     /* Prepare layout: */
    40     prepareLayout();
    41 
    42     /* Prepare model: */
    43     prepareModel();
    44 
    45     /* Prepare view: */
    46     prepareView();
    47 }
    48 
    49 void UIInformationRuntime::prepareLayout()
    50 {
    51     /* Create layout: */
    52     m_pMainLayout = new QVBoxLayout(this);
    53     AssertPtrReturnVoid(m_pMainLayout);
    54     {
    55         /* Configure layout: */
    56         m_pMainLayout->setSpacing(0);
    57     }
    58 }
    59 
    60 void UIInformationRuntime::prepareModel()
    61 {
    62     /* Create information-model: */
    63     m_pModel = new UIInformationModel(this, m_machine, m_console);
    64     AssertPtrReturnVoid(m_pModel);
    65     {
    66         /* Create runtime-attributes data-item: */
    67         UIInformationDataRuntimeAttributes *pGeneral = new UIInformationDataRuntimeAttributes(m_machine, m_console, m_pModel);
    68         AssertPtrReturnVoid(pGeneral);
     41    : UIInformationWidget(pParent,machine, console)
     42{
     43    retranslateUi();
     44    createTableItems();
     45}
     46
     47void UIInformationRuntime::retranslateUi()
     48{
     49    m_strRuntimeTitle = QApplication::translate("UIVMInformationDialog", "Runtime Attributes");
     50}
     51
     52void UIInformationRuntime::createTableItems()
     53{
     54    if (!m_pTableWidget)
     55        return;
     56    QFontMetrics fontMetrics(m_pTableWidget->font());
     57    QTextDocument textDocument;
     58    int iMaxColumn1Length = 0;
     59
     60    insertTitleRow(m_strRuntimeTitle, UIIconPool::iconSet(":/state_running_16px.png"), fontMetrics);
     61
     62
     63    insertInfoRows(runTimeAttributes(),
     64                   fontMetrics, textDocument, iMaxColumn1Length);
     65
     66
     67
     68    m_pTableWidget->resizeColumnToContents(0);
     69    /* Resize the column 1 a bit larger than the max string if contains: */
     70    m_pTableWidget->setColumnWidth(1, 1.5 * iMaxColumn1Length);
     71    m_pTableWidget->resizeColumnToContents(2);
     72}
     73
     74UITextTable UIInformationRuntime::runTimeAttributes()
     75{
     76    UITextTable textTable;
     77
     78    ULONG cGuestScreens = m_machine.GetMonitorCount();
     79    QVector<QString> aResolutions(cGuestScreens);
     80    for (ULONG iScreen = 0; iScreen < cGuestScreens; ++iScreen)
     81    {
     82        /* Determine resolution: */
     83        ULONG uWidth = 0;
     84        ULONG uHeight = 0;
     85        ULONG uBpp = 0;
     86        LONG xOrigin = 0;
     87        LONG yOrigin = 0;
     88        KGuestMonitorStatus monitorStatus = KGuestMonitorStatus_Enabled;
     89        m_console.GetDisplay().GetScreenResolution(iScreen, uWidth, uHeight, uBpp, xOrigin, yOrigin, monitorStatus);
     90        QString strResolution = QString("%1x%2").arg(uWidth).arg(uHeight);
     91        if (uBpp)
     92            strResolution += QString("x%1").arg(uBpp);
     93        strResolution += QString(" @%1,%2").arg(xOrigin).arg(yOrigin);
     94        if (monitorStatus == KGuestMonitorStatus_Disabled)
    6995        {
    70             /* Add runtime-attributes data-item to model: */
    71             m_pModel->addItem(pGeneral);
     96            strResolution += QString(" ");
     97            strResolution += QString(QApplication::translate("UIVMInformationDialog", "turned off"));
    7298        }
    73 
    74         /* Create network-statistics data-item: */
    75         UIInformationDataNetworkStatistics *pNetwork = new UIInformationDataNetworkStatistics(m_machine, m_console, m_pModel);
    76         AssertPtrReturnVoid(pNetwork);
    77         {
    78             /* Add network-statistics data-item to model: */
    79             m_pModel->addItem(pNetwork);
    80         }
    81 
    82         /* Create storage-statistics data-item: */
    83         UIInformationDataStorageStatistics *pStorage = new UIInformationDataStorageStatistics(m_machine, m_console, m_pModel);
    84         AssertPtrReturnVoid(pStorage);
    85         {
    86             /* Add storage-statistics data-item to model: */
    87             m_pModel->addItem(pStorage);
    88         }
    89     }
    90 }
    91 
    92 void UIInformationRuntime::prepareView()
    93 {
    94     /* Create information-view: */
    95     m_pView = new UIInformationView;
    96     AssertPtrReturnVoid(m_pView);
    97     {
    98         /* Configure information-view: */
    99         m_pView->setResizeMode(QListView::Adjust);
    100 
    101         /* Create information-delegate item: */
    102         UIInformationItem *pItem = new UIInformationItem(m_pView);
    103         AssertPtrReturnVoid(pItem);
    104         {
    105             /* Set item-delegate for information-view: */
    106             m_pView->setItemDelegate(pItem);
    107         }
    108         /* Connect data changed signal: */
    109         connect(m_pModel, &UIInformationModel::dataChanged, m_pView, &UIInformationView::updateData);
    110 
    111         /* Set model for view: */
    112         m_pView->setModel(m_pModel);
    113         /* Add information-view to the layout: */
    114         m_pMainLayout->addWidget(m_pView);
    115     }
    116 }
     99        aResolutions[iScreen] = strResolution;
     100    }
     101
     102    /* Determine uptime: */
     103    CMachineDebugger debugger = m_console.GetDebugger();
     104    uint32_t uUpSecs = (debugger.GetUptime() / 5000) * 5;
     105    char szUptime[32];
     106    uint32_t uUpDays = uUpSecs / (60 * 60 * 24);
     107    uUpSecs -= uUpDays * 60 * 60 * 24;
     108    uint32_t uUpHours = uUpSecs / (60 * 60);
     109    uUpSecs -= uUpHours * 60 * 60;
     110    uint32_t uUpMins  = uUpSecs / 60;
     111    uUpSecs -= uUpMins * 60;
     112    RTStrPrintf(szUptime, sizeof(szUptime), "%dd %02d:%02d:%02d",
     113                uUpDays, uUpHours, uUpMins, uUpSecs);
     114    QString strUptime = QString(szUptime);
     115
     116    /* Determine clipboard mode: */
     117    QString strClipboardMode = gpConverter->toString(m_machine.GetClipboardMode());
     118    /* Determine Drag&Drop mode: */
     119    QString strDnDMode = gpConverter->toString(m_machine.GetDnDMode());
     120
     121    /* Determine virtualization attributes: */
     122    QString strVirtualization = debugger.GetHWVirtExEnabled() ?
     123        QApplication::translate("UIVMInformationDialog", "Active") :
     124        QApplication::translate("UIVMInformationDialog", "Inactive");
     125
     126    QString strExecutionEngine;
     127    switch (debugger.GetExecutionEngine())
     128    {
     129        case KVMExecutionEngine_HwVirt:
     130            strExecutionEngine = "VT-x/AMD-V";  /* no translation */
     131            break;
     132        case KVMExecutionEngine_RawMode:
     133            strExecutionEngine = "raw-mode";    /* no translation */
     134            break;
     135        case KVMExecutionEngine_NativeApi:
     136            strExecutionEngine = "native API";  /* no translation */
     137            break;
     138        default:
     139            AssertFailed();
     140            RT_FALL_THRU();
     141        case KVMExecutionEngine_NotSet:
     142            strExecutionEngine = QApplication::translate("UIVMInformationDialog", "not set");
     143            break;
     144    }
     145    QString strNestedPaging = debugger.GetHWVirtExNestedPagingEnabled() ?
     146        QApplication::translate("UIVMInformationDialog", "Active"):
     147        QApplication::translate("UIVMInformationDialog", "Inactive");
     148
     149    QString strUnrestrictedExecution = debugger.GetHWVirtExUXEnabled() ?
     150        QApplication::translate("UIVMInformationDialog", "Active"):
     151        QApplication::translate("UIVMInformationDialog", "Inactive");
     152
     153        QString strParavirtProvider = gpConverter->toString(m_machine.GetEffectiveParavirtProvider());
     154
     155    /* Guest information: */
     156    CGuest guest = m_console.GetGuest();
     157    QString strGAVersion = guest.GetAdditionsVersion();
     158    if (strGAVersion.isEmpty())
     159        strGAVersion = tr("Not Detected", "guest additions");
     160    else
     161    {
     162        ULONG uRevision = guest.GetAdditionsRevision();
     163        if (uRevision != 0)
     164            strGAVersion += QString(" r%1").arg(uRevision);
     165    }
     166    QString strOSType = guest.GetOSTypeId();
     167    if (strOSType.isEmpty())
     168        strOSType = tr("Not Detected", "guest os type");
     169    else
     170        strOSType = uiCommon().vmGuestOSTypeDescription(strOSType);
     171
     172    /* VRDE information: */
     173    int iVRDEPort = m_console.GetVRDEServerInfo().GetPort();
     174    QString strVRDEInfo = (iVRDEPort == 0 || iVRDEPort == -1)?
     175        tr("Not Available", "details report (VRDE server port)") :
     176        QString("%1").arg(iVRDEPort);
     177
     178    /* Searching for longest string: */
     179    QStringList values;
     180    for (ULONG iScreen = 0; iScreen < cGuestScreens; ++iScreen)
     181        values << aResolutions[iScreen];
     182    values << strUptime
     183           << strExecutionEngine << strNestedPaging << strUnrestrictedExecution
     184           << strGAVersion << strOSType << strVRDEInfo;
     185    int iMaxLength = 0;
     186    foreach (const QString &strValue, values)
     187        iMaxLength = iMaxLength < QApplication::fontMetrics().width(strValue)
     188                                  ? QApplication::fontMetrics().width(strValue) : iMaxLength;
     189
     190    /* Summary: */
     191    for (ULONG iScreen = 0; iScreen < cGuestScreens; ++iScreen)
     192    {
     193        QString strLabel(tr("Screen Resolution"));
     194        /* The screen number makes sense only if there are multiple monitors in the guest: */
     195        if (cGuestScreens > 1)
     196            strLabel += QString(" %1").arg(iScreen + 1);
     197        textTable << UITextTableLine(strLabel, aResolutions[iScreen]);
     198    }
     199
     200    textTable << UITextTableLine(tr("VM Uptime"), strUptime);
     201    textTable << UITextTableLine(tr("Clipboard Mode"), strClipboardMode);
     202    textTable << UITextTableLine(tr("Drag and Drop Mode"), strDnDMode);
     203    textTable << UITextTableLine(tr("VM Execution Engine", "details report"), strExecutionEngine);
     204    textTable << UITextTableLine(tr("Nested Paging", "details report"), strNestedPaging);
     205    textTable << UITextTableLine(tr("Unrestricted Execution", "details report"), strUnrestrictedExecution);
     206    textTable << UITextTableLine(tr("Paravirtualization Interface", "details report"), strParavirtProvider);
     207    textTable << UITextTableLine(tr("Guest Additions"), strGAVersion);
     208    textTable << UITextTableLine(tr("Guest OS Type", "details report"), strOSType);
     209    textTable << UITextTableLine(tr("Remote Desktop Server Port", "details report (VRDE Server)"), strVRDEInfo);
     210
     211    return textTable;
     212}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.h

    r80357 r80369  
    3030#include "CConsole.h"
    3131
     32/* GUI includes: */
     33#include "UIInformationWidget.h"
     34
    3235/* Forward declarations: */
    3336class QVBoxLayout;
     
    3740
    3841
    39 /** QWidget extension
    40   * providing GUI with configuration-information tab in session-information window. */
    41 class UIInformationRuntime : public QWidget
     42class UIInformationRuntime : public UIInformationWidget
    4243{
    4344    Q_OBJECT;
     
    4546public:
    4647
    47     /** Constructs information-tab passing @a pParent to the QWidget base-class constructor.
    48       * @param machine is machine reference.
    49       * @param console is machine console reference. */
    5048    UIInformationRuntime(QWidget *pParent, const CMachine &machine, const CConsole &console);
    5149
     50protected:
     51
     52    void retranslateUi() /* override */;
     53    void createTableItems() /* override */;
     54
    5255private:
     56    UITextTable runTimeAttributes();
    5357
    54     /** Prepares layout. */
    55     void prepareLayout();
     58    /** @name Cached translated string.
     59     * @{ */
     60       QString m_strRuntimeTitle;
     61    /** @} */
    5662
    57     /** Prepares model. */
    58     void prepareModel();
    59 
    60     /** Prepares view. */
    61     void prepareView();
    62 
    63     /** Holds the machine instance. */
    64     CMachine m_machine;
    65     /** Holds the console instance. */
    66     CConsole m_console;
    67     /** Holds the instance of layout we create. */
    68     QVBoxLayout *m_pMainLayout;
    69     /** Holds the instance of model we create. */
    70     UIInformationModel *m_pModel;
    71     /** Holds the instance of view we create. */
    72     UIInformationView *m_pView;
    7363};
    7464
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationWidget.h

    r80357 r80369  
    5252
    5353    virtual void retranslateUi() /* override */ = 0;
     54    virtual void createTableItems() /* override */ = 0;
     55
    5456    void insertTitleRow(const QString &strTitle, const QIcon &icon, const QFontMetrics &fontMetrics);
    5557    void insertInfoRows(const UITextTable &table, const QFontMetrics &fontMetrics,
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp

    r80341 r80369  
    271271
    272272        /* Set Runtime Information tab as default: */
    273         m_pTabWidget->setCurrentIndex(0);
     273        m_pTabWidget->setCurrentIndex(1);
    274274
    275275        /* Assign tab-widget page change handler: */
Note: See TracChangeset for help on using the changeset viewer.

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