VirtualBox

Changeset 59920 in vbox


Ignore:
Timestamp:
Mar 4, 2016 11:01:11 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105853
Message:

FE/Qt: ​​​bugref:8088: Rework session-information window: Fixing copy-paste of information-text issues and cleanups.

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

Legend:

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

    r59709 r59920  
    5454{
    5555    /* Create main-layout: */
    56     m_pMainLayout = new QVBoxLayout(this);
     56    m_pMainLayout = new QVBoxLayout;
    5757    AssertPtrReturnVoid(m_pMainLayout);
    5858    {
    59         /* Prepare main-layout: */
     59        /* Configure main-layout: */
    6060        m_pMainLayout->setContentsMargins(2, 0, 0, 0);
    6161        m_pMainLayout->setSpacing(0);
     
    6666void UIInformation::prepareModel()
    6767{
    68     /* Create model: */
     68    /* Create information-model: */
    6969    m_pModel = new UIInformationModel(this, m_machine, m_console);
    7070    AssertPtrReturnVoid(m_pModel);
    7171    {
    72         /* Prepare data for information-model: */
    73         /* General data-item: */
     72        /* Add data to information-model: */
     73        /* Create General data-item: */
    7474        UIInformationDataItem *pGeneral = new UIInformationDataGeneral(m_machine, m_console, m_pModel);
    7575        AssertPtrReturnVoid(pGeneral);
     
    7878        }
    7979
    80         /* System data-item: */
     80        /* Create System data-item: */
    8181        UIInformationDataItem *pSystem = new UIInformationDataSystem(m_machine, m_console, m_pModel);
    8282        AssertPtrReturnVoid(pSystem);
     
    8585        }
    8686
    87         /* Display data-item: */
     87        /* Create Display data-item: */
    8888        UIInformationDataItem *pDisplay = new UIInformationDataDisplay(m_machine, m_console, m_pModel);
    8989        AssertPtrReturnVoid(pDisplay);
     
    9292        }
    9393
    94         /* Storage data-item: */
     94        /* Create Storage data-item: */
    9595        UIInformationDataItem *pStorage = new UIInformationDataStorage(m_machine, m_console, m_pModel);
    9696        AssertPtrReturnVoid(pStorage);
     
    9999        }
    100100
    101         /* Audio data-item: */
     101        /* Create Audio data-item: */
    102102        UIInformationDataItem *pAudio = new UIInformationDataAudio(m_machine, m_console, m_pModel);
    103103        AssertPtrReturnVoid(pAudio);
     
    106106        }
    107107
    108         /* Network data-item: */
     108        /* Create Network data-item: */
    109109        UIInformationDataItem *pNetwork = new UIInformationDataNetwork(m_machine, m_console, m_pModel);
    110110        AssertPtrReturnVoid(pNetwork);
     
    113113        }
    114114
    115         /* Serial ports data-item: */
     115        /* Create Serial-ports data-item: */
    116116        UIInformationDataItem *pSerialPorts = new UIInformationDataSerialPorts(m_machine, m_console, m_pModel);
    117117        AssertPtrReturnVoid(pSerialPorts);
     
    121121
    122122#ifdef VBOX_WITH_PARALLEL_PORTS
    123         /* Parallel ports data-item: */
     123        /* Create Parallel-ports data-item: */
    124124        UIInformationDataItem *pParallelPorts = new UIInformationDataParallelPorts(m_machine, m_console, m_pModel);
    125125        AssertPtrReturnVoid(pParallelPorts);
     
    129129#endif /* VBOX_WITH_PARALLEL_PORTS */
    130130
    131         /* USB data-item: */
     131        /* Create USB data-item: */
    132132        UIInformationDataItem *pUSB = new UIInformationDataUSB(m_machine, m_console, m_pModel);
    133133        AssertPtrReturnVoid(pUSB);
     
    136136        }
    137137
    138         /* Shared folders data-item: */
     138        /* Create Shared-folders data-item: */
    139139        UIInformationDataItem *pSharedFolders = new UIInformationDataSharedFolders(m_machine, m_console, m_pModel);
    140140        AssertPtrReturnVoid(pSharedFolders);
     
    147147void UIInformation::prepareView()
    148148{
    149     /* Create view: */
     149    /* Create information-view: */
    150150    m_pView = new UIInformationView;
    151151    AssertPtrReturnVoid(m_pView);
    152152    {
    153         /* Prepare view: */
     153        /* Configure information-view: */
    154154        m_pView->setResizeMode(QListView::Adjust);
    155155        /* Create information-delegate item: */
     
    163163                m_pView, SLOT(updateData(const QModelIndex&, const QModelIndex&)));
    164164
    165         /* Set model: */
     165        /* Set model for view: */
    166166        m_pView->setModel(m_pModel);
    167         /* Layout view: */
     167        /* Add information-view to the main-layout: */
    168168        m_pMainLayout->addWidget(m_pView);
    169169    }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationItem.cpp

    r59709 r59920  
    2828/* GUI includes: */
    2929# include "UIInformationItem.h"
     30# include "VBoxGlobal.h"
    3031
    3132#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    3435    : QStyledItemDelegate(pParent)
    3536{
     37    /* Create text-document: */
    3638    m_pTextDocument = new QTextDocument(this);
     39    AssertPtrReturnVoid(m_pTextDocument);
    3740}
    3841
    3942void UIInformationItem::setIcon(const QString &strIcon) const
    4043{
     44    /* Cache icon: */
    4145    m_strIcon = strIcon;
     46    /* Update text-layout: */
    4247    updateTextLayout();
    4348}
     
    4752    /* Cache name: */
    4853    m_strName = strName;
     54    /* Update text-layout: */
    4955    updateTextLayout();
    5056}
     
    5258const UITextTable& UIInformationItem::text() const
    5359{
     60    /* Return text: */
    5461    return m_text;
    5562}
     
    6067    m_text.clear();
    6168
    62     /* For each the line of the passed table: */
     69    /* For each line of the passed table: */
    6370    foreach (const UITextTableLine &line, text)
    6471    {
     
    7885            /* Parse the 1st one to sub-lines: */
    7986            QStringList subLines = strLeftLine.split(QRegExp("\\n"));
     87            /* Parse sub-lines: */
    8088            foreach (const QString &strSubLine, subLines)
    8189                m_text << UITextTableLine(strSubLine, QString());
     
    8997void UIInformationItem::paint(QPainter *pPainter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    9098{
     99    /* Save the painter: */
    91100    pPainter->save();
     101    /* Update data: */
    92102    updateData(index);
    93103
     104    /* Draw item as per application style: */
    94105    QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &option, pPainter);
    95106    pPainter->resetTransform();
    96107    pPainter->translate(option.rect.topLeft());
    97108
     109    /* Draw the content of text-document: */
    98110    m_pTextDocument->drawContents(pPainter);
     111    /* Restore the painter: */
    99112    pPainter->restore();
    100113}
     
    102115QSize UIInformationItem::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
    103116{
     117    /* Update data: */
    104118    updateData(index);
     119    /* Return size: */
    105120    return m_pTextDocument->size().toSize();
    106121}
     
    108123void UIInformationItem::updateData(const QModelIndex &index) const
    109124{
     125    /* Set name: */
    110126    setName(index.data().toString());
     127    /* Set icon: */
    111128    setIcon(index.data(Qt::DecorationRole).toString());
     129    /* Set text: */
    112130    setText(index.data(Qt::UserRole + 1).value<UITextTable>());
     131    /* Get type of the item: */
    113132    m_type = index.data(Qt::UserRole + 2).value<InformationElementType>();
    114133}
     
    116135QString UIInformationItem::htmlData()
    117136{
     137    /* Return html-data: */
    118138    return m_pTextDocument->toHtml();
    119139}
     
    121141void UIInformationItem::updateTextLayout() const
    122142{
    123     /* Details templates */
     143    /* Details templates: */
    124144    static const char *sSectionBoldTpl =
    125145        "<tr><td width=22 rowspan=%1 align=left><img width=16 height=16 src='%2'></td>"
     
    127147            "%4";
    128148    static const char *sSectionItemTpl2 =
    129         "<tr><td width=300><nobr>%1</nobr></td><td/><td>%2</td></tr>";
     149        "<tr><td width=200><nobr>%1</nobr></td><td/><td>%2</td></tr>";
    130150
    131151    const QString &sectionTpl = sSectionBoldTpl;
     
    135155    {
    136156        QString item;
     157        /* Parse lines from text and add it to text: */
    137158        foreach (const UITextTableLine &line, m_text)
    138159            item = item + QString(sSectionItemTpl2).arg(line.first, line.second);
    139160
    140         report = sectionTpl
    141                   .arg(m_text.count() + 1) /* rows */
    142                   .arg(m_strIcon, /* icon */
    143                        m_strName, /* title */
    144                        item); /* items */
     161        /* Format the entire item: */
     162        report = sectionTpl.arg(m_text.count() + 1) /* rows */
     163                           .arg(m_strIcon, /* icon */
     164                                m_strName, /* title */
     165                                item); /* items */
    145166    }
    146167
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationModel.cpp

    r59702 r59920  
    5050}
    5151
    52 int UIInformationModel::rowCount(const QModelIndex & /*parent */) const
     52int UIInformationModel::rowCount(const QModelIndex& /*parent */) const
    5353{
     54    /* Return row-count: */
    5455    return m_list.count();
    5556}
     
    5758QVariant UIInformationModel::data(const QModelIndex &index, int role) const
    5859{
     60    /* Get row: */
    5961    int row = index.row();
    60     int col = index.column();
     62    /* Get item at the row: */
    6163    UIInformationDataItem *pItem = m_list.at(row);
     64    /* Return the data for the corresponding role: */
    6265    return pItem->data(index, role);
    6366}
     
    8184QHash<int, QByteArray> UIInformationModel::roleNames() const
    8285{
     86    /* Add supported roles and return: */
    8387    QHash<int, QByteArray> roleNames;
    8488    roleNames[Qt::DisplayRole] = "";
     
    9195void UIInformationModel::addItem(UIInformationDataItem *pItem)
    9296{
     97    /* Make sure item is valid: */
    9398    AssertPtrReturnVoid(pItem);
     99    /* Add item: */
    94100    m_list.append(pItem);
    95101}
     
    97103void UIInformationModel::updateData(const QModelIndex &idx)
    98104{
     105    /* Emit data-changed signal: */
    99106    emit dataChanged(idx, idx);
    100107}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.cpp

    r59646 r59920  
    5757    AssertPtrReturnVoid(m_pMainLayout);
    5858    {
    59         /* Prepare main-layout: */
     59        /* Configure main-layout: */
    6060        m_pMainLayout->setContentsMargins(2, 0, 0, 0);
    6161        m_pMainLayout->setSpacing(0);
     
    7070    AssertPtrReturnVoid(m_pModel);
    7171
    72     /* Prepare data for information-model: */
     72    /* Add data to information-model: */
    7373    UIInformationDataRuntimeAttributes *pGeneral = new UIInformationDataRuntimeAttributes(m_machine, m_console, m_pModel);
    7474    AssertPtrReturnVoid(pGeneral);
     
    7777    }
    7878
    79     /* Prepare data for information-model: */
     79    /* Create data for information-model: */
    8080    UIInformationDataNetworkStatistics *pNetwork = new UIInformationDataNetworkStatistics(m_machine, m_console, m_pModel);
    8181    AssertPtrReturnVoid(pNetwork);
     
    8484    }
    8585
    86     /* Prepare data for information-model: */
     86    /* Create data for information-model: */
    8787    UIInformationDataStorageStatistics *pStorage = new UIInformationDataStorageStatistics(m_machine, m_console, m_pModel);
    8888    AssertPtrReturnVoid(pStorage);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationView.cpp

    r59699 r59920  
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
     22# include <QTextEdit>
    2223# include <QClipboard>
     24# include <QDebug>
    2325
    2426/* GUI includes: */
     
    3133    : QListView(pParent)
    3234{
     35    /* Create a dummy textEdit for copying rich-text as,
     36     * manual copying to clipboard is not working: */
     37    m_pTextEdit = new QTextEdit(this);
     38    /* Hide textedit: */
     39    m_pTextEdit->setVisible(false);
     40    /* Set selection mode: */
     41    setSelectionMode(QAbstractItemView::ExtendedSelection);
    3342}
    3443
    3544void UIInformationView::updateData(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    3645{
     46    /* Update: */
    3747    update(topLeft);
    3848}
     
    4050void UIInformationView::keyPressEvent(QKeyEvent *pEvent)
    4151{
     52    /* Copy the text: */
    4253    if (pEvent == QKeySequence::Copy)
    4354    {
    44         if (selectionModel())
     55        QString strText;
     56        /* Get Selection model: */
     57        QItemSelectionModel *pSelectionModel = selectionModel();
     58        if (pSelectionModel)
    4559        {
    46             QString strText;
    47             foreach (const QModelIndex &index, selectionModel()->selectedIndexes())
     60            /* Check all the selected-indexes and copy the text: */
     61            foreach (const QModelIndex &index, pSelectionModel->selectedIndexes())
    4862            {
    4963                UIInformationItem *pItem = dynamic_cast<UIInformationItem*>(itemDelegate(index));
    5064                if (pItem)
    5165                {
     66                    /* Update the data corresponding data: */
     67                    pItem->updateData(index);
     68                    /* Get and add the html-data of item: */
    5269                    strText.append(pItem->htmlData());
    5370                }
    5471            }
    55             QApplication::clipboard()->setText(strText);
    56             pEvent->accept();
    5772        }
     73        /* Set the text to text-edit and copy from it: */
     74        m_pTextEdit->setText(strText);
     75        m_pTextEdit->selectAll();
     76        m_pTextEdit->copy();
     77        /* Accept/acknowledge event: */
     78        pEvent->accept();
    5879    }
     80    /* Call to base-class: */
     81    else
     82        QListView::keyPressEvent(pEvent);
    5983}
    6084
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationView.h

    r59699 r59920  
    2323#include <QModelIndex>
    2424
     25/* Forward declarations: */
     26class QTextEdit;
     27class UIInformationItem;
     28
    2529/** QListView extension
    2630  * providing GUI with information-view in session-information window. */
     
    4044    /** Handles Qt key-press @a pEvent. */
    4145    void keyPressEvent(QKeyEvent *pEvent);
     46
     47private:
     48    /** Holds the instance of textedit we create: */
     49    QTextEdit *m_pTextEdit;
    4250};
    4351
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