VirtualBox

Changeset 80357 in vbox


Ignore:
Timestamp:
Aug 20, 2019 12:55:49 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132822
Message:

FE/Qt: bugref:9510: Moving some code to a base class to enable reusing some parts and pieces in 'Runtime Information' widget

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
4 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r80200 r80357  
    736736        src/runtime/information/UIInformationRuntime.h \
    737737        src/runtime/information/UIInformationView.h \
     738        src/runtime/information/UIInformationWidget.h \
    738739        src/runtime/information/UIPerformanceMonitor.h \
    739740        src/runtime/information/UIVMInformationDialog.h \
     
    12031204        src/runtime/information/UIInformationRuntime.cpp \
    12041205        src/runtime/information/UIInformationView.cpp \
     1206        src/runtime/information/UIInformationWidget.cpp \
    12051207        src/runtime/information/UIPerformanceMonitor.cpp \
    12061208        src/runtime/information/UIVMInformationDialog.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationConfiguration.cpp

    r80356 r80357  
    2323#include <QTableWidget>
    2424#include <QTextDocument>
    25 #include <QVBoxLayout>
    2625
    2726/* GUI includes: */
     
    3433
    3534UIInformationConfiguration::UIInformationConfiguration(QWidget *pParent, const CMachine &machine, const CConsole &console)
    36     : QIWithRetranslateUI<QWidget>(pParent)
    37     , m_machine(machine)
    38     , m_console(console)
    39     , m_pMainLayout(0)
    40     , m_pTableWidget(0)
    41     , m_iColumCount(3)
    42     , m_iRowLeftMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin))
    43     , m_iRowTopMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin))
    44     , m_iRowRightMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin))
    45     , m_iRowBottomMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin))
     35    : UIInformationWidget(pParent, machine, console)
     36
    4637{
    47     /* Prepare view: */
    48     prepareObjects();
    4938    retranslateUi();
    5039    createTableItems();
    51 
    5240    connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineDataChange,
    5341            this, &UIInformationConfiguration::sltMachineDataChanged);
     
    5846    resetTable();
    5947    createTableItems();
    60 }
    61 
    62 UIInformationConfiguration::~UIInformationConfiguration()
    63 {
    6448}
    6549
     
    7761}
    7862
    79 void UIInformationConfiguration::prepareObjects()
    80 {
    81     /* Create layout: */
    82     m_pMainLayout = new QVBoxLayout(this);
    83     if (!m_pMainLayout)
    84         return;
    85     m_pMainLayout->setSpacing(0);
    86 
    87     m_pTableWidget = new QTableWidget;
    88     if (m_pTableWidget)
    89     {
    90         /* Configure the table by hiding the headers etc.: */
    91         m_pTableWidget->setColumnCount(m_iColumCount);
    92         m_pTableWidget->verticalHeader()->hide();
    93         m_pTableWidget->horizontalHeader()->hide();
    94         m_pTableWidget->setShowGrid(false);
    95         m_pMainLayout->addWidget(m_pTableWidget);
    96     }
    97 }
    9863
    9964void UIInformationConfiguration::createTableItems()
     
    165130    m_pTableWidget->resizeColumnToContents(2);
    166131}
    167 
    168 void UIInformationConfiguration::insertInfoRows(const UITextTable &table, const QFontMetrics &fontMetrics,
    169                                                 QTextDocument &textDocument, int &iMaxColumn1Length)
    170 {
    171     foreach (const UITextTableLine &line, table)
    172     {
    173         textDocument.setHtml(line.string2());
    174         insertInfoRow(line.string1(), textDocument.toPlainText(), fontMetrics, iMaxColumn1Length);
    175     }
    176 }
    177 
    178 void UIInformationConfiguration::insertTitleRow(const QString &strTitle, const QIcon &icon, const QFontMetrics &fontMetrics)
    179 {
    180     int iRow = m_pTableWidget->rowCount();
    181     m_pTableWidget->insertRow(iRow);
    182     QSize iconSize;
    183     icon.actualSize(iconSize);
    184     m_pTableWidget->setRowHeight(iRow,
    185                                  qMax(fontMetrics.height() + m_iRowTopMargin + m_iRowBottomMargin, iconSize.height()));
    186     QTableWidgetItem *pIconItem = new QTableWidgetItem(icon, "");
    187     m_pTableWidget->setItem(iRow, 0, pIconItem);
    188     QTableWidgetItem *pTitleItem = new QTableWidgetItem(strTitle);
    189     QFont font = pTitleItem->font();
    190     font.setBold(true);
    191     pTitleItem->setFont(font);
    192 
    193     m_pTableWidget->setItem(iRow, 1, pTitleItem);
    194     m_tableItems << pIconItem;
    195     m_tableItems << pTitleItem;
    196 }
    197 
    198 void UIInformationConfiguration::insertInfoRow(const QString strText1, const QString &strText2,
    199                                                const QFontMetrics &fontMetrics, int &iMaxColumn1Length)
    200 {
    201     int iRow = m_pTableWidget->rowCount();
    202     m_pTableWidget->insertRow(iRow);
    203     m_pTableWidget->setRowHeight(iRow, fontMetrics.height() + m_iRowTopMargin + m_iRowBottomMargin);
    204     iMaxColumn1Length = qMax(iMaxColumn1Length, fontMetrics.width(strText1));
    205     QTableWidgetItem *pCol1 = new QTableWidgetItem(strText1);
    206     QTableWidgetItem *pCol2 = new QTableWidgetItem(strText2);
    207     m_tableItems << pCol1;
    208     m_tableItems << pCol2;
    209     m_pTableWidget->setItem(iRow, 1, pCol1);
    210     m_pTableWidget->setItem(iRow, 2, pCol2);
    211 }
    212 
    213 void UIInformationConfiguration::resetTable()
    214 {
    215     if (m_pTableWidget)
    216     {
    217         m_pTableWidget->clear();
    218         m_pTableWidget->setRowCount(0);
    219         m_pTableWidget->setColumnCount(m_iColumCount);
    220     }
    221 }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationConfiguration.h

    r80356 r80357  
    2828#include "COMEnums.h"
    2929#include "CGuest.h"
    30 
    3130#include "CMachine.h"
    3231#include "CConsole.h"
    3332
    3433/* GUI includes: */
    35 #include "QIWithRetranslateUI.h"
    3634#include "UITextTable.h"
     35#include "UIInformationWidget.h"
    3736
    3837/* Forward declarations: */
    39 class QVBoxLayout;
    40 class QTableWidget;
    4138class QTableWidgetItem;
    4239class QTextDocument;
     
    4542/** QWidget extension
    4643  * providing GUI with configuration-information tab in session-information window. */
    47 class UIInformationConfiguration : public QIWithRetranslateUI<QWidget>
     44class UIInformationConfiguration : public UIInformationWidget
    4845{
    4946    Q_OBJECT;
     
    5552      * @param console is machine console reference. */
    5653    UIInformationConfiguration(QWidget *pParent, const CMachine &machine, const CConsole &console);
    57     ~UIInformationConfiguration();
    5854
    5955protected:
     
    6763private:
    6864
    69     void prepareObjects();
    7065    void createTableItems();
    7166
    72     void insertTitleRow(const QString &strTitle, const QIcon &icon, const QFontMetrics &fontMetrics);
    73     void insertInfoRows(const UITextTable &table, const QFontMetrics &fontMetrics,
    74                         QTextDocument &textDocument, int &iMaxColumn1Length);
    75     void insertInfoRow(const QString strText1, const QString &strText2,
    76                        const QFontMetrics &fontMetrics, int &iMaxColumn1Length);
    77 
    78     void resetTable();
    79     /** Holds the machine instance. */
    80     CMachine m_machine;
    81     /** Holds the console instance. */
    82     CConsole m_console;
    83     /** Holds the instance of layout we create. */
    84     QVBoxLayout *m_pMainLayout;
    85     QTableWidget *m_pTableWidget;
    86     //QMap<TableRow, UIInformationTableRow*> m_rows;
    87     QList<QTableWidgetItem*> m_tableItems;
    8867   /** @name Cached translated string.
    8968      * @{ */
     
    9877        QString m_strSharedFoldersTitle;
    9978    /** @} */
    100     const int m_iColumCount;
    101     const int m_iRowLeftMargin;
    102     const int m_iRowTopMargin;
    103     const int m_iRowRightMargin;
    104     const int m_iRowBottomMargin;
    10579};
    10680
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.h

    r76581 r80357  
    7474
    7575#endif /* !FEQT_INCLUDED_SRC_runtime_information_UIInformationRuntime_h */
    76 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationWidget.cpp

    r80342 r80357  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIInformationView class implementation.
     3 * VBox Qt GUI - UIInformationWidget class implementation.
    44 */
    55
     
    1717
    1818/* Qt includes: */
    19 #include <QClipboard>
    20 #include <QTextEdit>
     19#include <QHeaderView>
     20#include <QTableWidget>
     21#include <QTextDocument>
     22#include <QVBoxLayout>
    2123
    2224/* GUI includes: */
    23 #include "UIInformationView.h"
     25#include "UIInformationWidget.h"
    2426#include "UIInformationItem.h"
    2527
    2628
    27 UIInformationView::UIInformationView(QWidget *pParent)
    28     : QListView(pParent)
     29UIInformationWidget::UIInformationWidget(QWidget *pParent, const CMachine &machine, const CConsole &console)
     30    : QIWithRetranslateUI<QWidget>(pParent)
     31    , m_machine(machine)
     32    , m_console(console)
     33    , m_pMainLayout(0)
     34    , m_pTableWidget(0)
     35    , m_iColumCount(3)
     36    , m_iRowLeftMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin))
     37    , m_iRowTopMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin))
     38    , m_iRowRightMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin))
     39    , m_iRowBottomMargin(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin))
    2940{
    30     // WORKAROUND:
    31     // Create a dummy text-edit for copying rich-text
    32     // as manual copying to clipboard is not working:
    33     m_pTextEdit = new QTextEdit(this);
    34     m_pTextEdit->setVisible(false);
    35     /* Set selection mode: */
    36     setSelectionMode(QAbstractItemView::ExtendedSelection);
    37     /* Set scrolling mode to per pixel: */
    38     setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
     41    prepareObjects();
    3942}
    4043
    41 void UIInformationView::updateData(const QModelIndex &topLeft, const QModelIndex &bottomRight)
     44void UIInformationWidget::prepareObjects()
    4245{
    43     /* Iterate through all indexes: */
    44     for (int iRowIndex = topLeft.row(); iRowIndex <= bottomRight.row(); ++iRowIndex)
     46    /* Create layout: */
     47    m_pMainLayout = new QVBoxLayout(this);
     48    if (!m_pMainLayout)
     49        return;
     50    m_pMainLayout->setSpacing(0);
     51
     52    m_pTableWidget = new QTableWidget;
     53    if (m_pTableWidget)
    4554    {
    46         /* Get the index for current row: */
    47         const QModelIndex index = topLeft.sibling(iRowIndex, topLeft.column());
    48         /* If index is valid: */
    49         if (index.isValid())
    50         {
    51             /* Get the row-count of data-table: */
    52             const int iCount = index.data(Qt::UserRole + 1).value<UITextTable>().count();
    53             /* If there is no data hide the item: */
    54             if (iCount == 0)
    55                 setRowHidden(index.row(), true);
    56         }
     55        /* Configure the table by hiding the headers etc.: */
     56        m_pTableWidget->setColumnCount(m_iColumCount);
     57        m_pTableWidget->verticalHeader()->hide();
     58        m_pTableWidget->horizontalHeader()->hide();
     59        m_pTableWidget->setShowGrid(false);
     60        m_pTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
     61        m_pTableWidget->setFocusPolicy(Qt::NoFocus);
     62        m_pTableWidget->setSelectionMode(QAbstractItemView::NoSelection);
     63        m_pMainLayout->addWidget(m_pTableWidget);
    5764    }
    5865}
    5966
    60 void UIInformationView::keyPressEvent(QKeyEvent *pEvent)
     67
     68
     69void UIInformationWidget::insertInfoRows(const UITextTable &table, const QFontMetrics &fontMetrics,
     70                                                QTextDocument &textDocument, int &iMaxColumn1Length)
    6171{
    62     /* Copy the text: */
    63     if (pEvent == QKeySequence::Copy)
     72    foreach (const UITextTableLine &line, table)
    6473    {
    65         QString strText;
    66         /* Get selection model: */
    67         QItemSelectionModel *pSelectionModel = selectionModel();
    68         if (pSelectionModel)
    69         {
    70             /* Check all the selected-indexes and copy the text: */
    71             foreach (const QModelIndex &index, pSelectionModel->selectedIndexes())
    72             {
    73                 UIInformationItem *pItem = dynamic_cast<UIInformationItem*>(itemDelegate(index));
    74                 if (pItem)
    75                 {
    76                     /* Update the corresponding data: */
    77                     pItem->updateData(index);
    78                     /* Get and add the html-data of item: */
    79                     strText.append(pItem->htmlData());
    80                 }
    81             }
    82         }
    83         /* Set the text to text-edit and copy from it: */
    84         m_pTextEdit->setText(strText);
    85         m_pTextEdit->selectAll();
    86         m_pTextEdit->copy();
    87         /* Accept/acknowledge event: */
    88         pEvent->accept();
     74        textDocument.setHtml(line.string2());
     75        insertInfoRow(line.string1(), textDocument.toPlainText(), fontMetrics, iMaxColumn1Length);
    8976    }
    90     /* Call to base-class: */
    91     else
    92         QListView::keyPressEvent(pEvent);
    9377}
    9478
     79void UIInformationWidget::insertTitleRow(const QString &strTitle, const QIcon &icon, const QFontMetrics &fontMetrics)
     80{
     81    int iRow = m_pTableWidget->rowCount();
     82    m_pTableWidget->insertRow(iRow);
     83    QSize iconSize;
     84    icon.actualSize(iconSize);
     85    m_pTableWidget->setRowHeight(iRow,
     86                                 qMax(fontMetrics.height() + m_iRowTopMargin + m_iRowBottomMargin, iconSize.height()));
     87    m_pTableWidget->setItem(iRow, 0, new QTableWidgetItem(icon, ""));
     88    QTableWidgetItem *pTitleItem = new QTableWidgetItem(strTitle);
     89    QFont font = pTitleItem->font();
     90    font.setBold(true);
     91    pTitleItem->setFont(font);
     92    m_pTableWidget->setItem(iRow, 1, pTitleItem);
     93}
     94
     95void UIInformationWidget::insertInfoRow(const QString strText1, const QString &strText2,
     96                                               const QFontMetrics &fontMetrics, int &iMaxColumn1Length)
     97{
     98    int iRow = m_pTableWidget->rowCount();
     99    m_pTableWidget->insertRow(iRow);
     100    m_pTableWidget->setRowHeight(iRow, fontMetrics.height() + m_iRowTopMargin + m_iRowBottomMargin);
     101    iMaxColumn1Length = qMax(iMaxColumn1Length, fontMetrics.width(strText1));
     102    m_pTableWidget->setItem(iRow, 1, new QTableWidgetItem(strText1));
     103    m_pTableWidget->setItem(iRow, 2, new QTableWidgetItem(strText2));
     104}
     105
     106void UIInformationWidget::resetTable()
     107{
     108    if (m_pTableWidget)
     109    {
     110        m_pTableWidget->clear();
     111        m_pTableWidget->setRowCount(0);
     112        m_pTableWidget->setColumnCount(m_iColumCount);
     113    }
     114}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationWidget.h

    r80342 r80357  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIInformationView class declaration.
     3 * VBox Qt GUI - UIInformationWidget class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_runtime_information_UIInformationView_h
    19 #define FEQT_INCLUDED_SRC_runtime_information_UIInformationView_h
     18#ifndef FEQT_INCLUDED_SRC_runtime_information_UIInformationWidget_h
     19#define FEQT_INCLUDED_SRC_runtime_information_UIInformationWidget_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
     
    2323
    2424/* Qt includes: */
    25 #include <QListView>
    26 #include <QModelIndex>
     25#include <QWidget>
     26
     27/* COM includes: */
     28#include "COMEnums.h"
     29#include "CGuest.h"
     30#include "CMachine.h"
     31#include "CConsole.h"
     32
     33/* GUI includes: */
     34#include "QIWithRetranslateUI.h"
     35#include "UITextTable.h"
    2736
    2837/* Forward declarations: */
    29 class QTextEdit;
    30 class UIInformationItem;
     38class QTableWidget;
     39class QVBoxLayout;
    3140
    32 
    33 /** QListView extension
    34   * providing GUI with information-view in session-information window. */
    35 class UIInformationView : public QListView
     41/** An abstract base class for showing tabular data in Session Information dialog. */
     42class UIInformationWidget  : public QIWithRetranslateUI<QWidget>
    3643{
    3744    Q_OBJECT;
     
    4047
    4148    /** Constructs information-view passing @a pParent to the base-class. */
    42     UIInformationView(QWidget *pParent = 0);
     49    UIInformationWidget(QWidget *pParent, const CMachine &machine, const CConsole &console);
    4350
    44 public slots:
     51protected:
    4552
    46     /** Handles updating data for the index-range @a topLeft to @a bottomRight. */
    47     void updateData(const QModelIndex &topLeft, const QModelIndex &bottomRight);
     53    virtual void retranslateUi() /* override */ = 0;
     54    void insertTitleRow(const QString &strTitle, const QIcon &icon, const QFontMetrics &fontMetrics);
     55    void insertInfoRows(const UITextTable &table, const QFontMetrics &fontMetrics,
     56                        QTextDocument &textDocument, int &iMaxColumn1Length);
     57    void insertInfoRow(const QString strText1, const QString &strText2,
     58                       const QFontMetrics &fontMetrics, int &iMaxColumn1Length);
     59    void resetTable();
    4860
    49 protected slots:
    50 
    51     /** Handles Qt key-press @a pEvent. */
    52     void keyPressEvent(QKeyEvent *pEvent);
     61    CMachine m_machine;
     62    CConsole m_console;
     63    QVBoxLayout *m_pMainLayout;
     64    QTableWidget *m_pTableWidget;
     65    const int m_iColumCount;
    5366
    5467private:
     68    void prepareObjects();
    5569
    56     /** Holds the text-edit instance. */
    57     QTextEdit *m_pTextEdit;
     70    const int m_iRowLeftMargin;
     71    const int m_iRowTopMargin;
     72    const int m_iRowRightMargin;
     73    const int m_iRowBottomMargin;
    5874};
    5975
    60 #endif /* !FEQT_INCLUDED_SRC_runtime_information_UIInformationView_h */
    61 
     76#endif /* !FEQT_INCLUDED_SRC_runtime_information_UIInformationWidget_h */
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