VirtualBox

Ignore:
Timestamp:
Aug 26, 2020 4:56:11 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9510. Add a context menu to copy the runtime information table data into clipboard.

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

    r82968 r85891  
    1717
    1818/* Qt includes: */
     19#include <QAction>
    1920#include <QApplication>
     21#include <QClipboard>
    2022#include <QHeaderView>
     23#include <QMenu>
    2124#include <QVBoxLayout>
    2225#include <QTableWidget>
     
    7073    void updateClipboardMode(KClipboardMode enmMode = KClipboardMode_Max);
    7174    void updateDnDMode(KDnDMode enmMode = KDnDMode_Max);
     75    QString tableData();
    7276
    7377protected:
     
    143147    , m_pTimer(0)
    144148{
     149    setContextMenuPolicy(Qt::CustomContextMenu);
    145150    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    146151    setAlternatingRowColors(true);
     
    411416}
    412417
     418QString UIRuntimeInfoWidget::tableData()
     419{
     420    QStringList stringData;
     421    for (int i = 0; i < rowCount(); ++i)
     422    {
     423        /* Skip the first column as it is used for icon: */
     424        for (int j = 1; j < columnCount(); ++j)
     425        {
     426            QTableWidgetItem *pItem = item(i, j);
     427            if (!pItem || pItem->text().isEmpty())
     428                continue;
     429            stringData << pItem->text();
     430            if (j == 1)
     431                stringData << ": ";
     432        }
     433        stringData << "\n";
     434    }
     435    return stringData.join(QString());
     436}
     437
     438
    413439void UIRuntimeInfoWidget::updateInfoRow(InfoRow enmLine, const QString &strColumn0, const QString &strColumn1)
    414440{
     
    464490    , m_pMainLayout(0)
    465491    , m_pRuntimeInfoWidget(0)
     492    , m_pCopyWholeTableAction(0)
    466493{
    467494    if (!m_console.isNull())
     
    479506void UIInformationRuntime::retranslateUi()
    480507{
     508    if (m_pCopyWholeTableAction)
     509        m_pCopyWholeTableAction->setText(QApplication::translate("UIVMInformationDialog", "Copy All"));
    481510}
    482511
     
    489518
    490519    m_pRuntimeInfoWidget = new UIRuntimeInfoWidget(0, m_machine, m_console);
     520    AssertReturnVoid(m_pRuntimeInfoWidget);
     521    connect(m_pRuntimeInfoWidget, &UIRuntimeInfoWidget::customContextMenuRequested,
     522            this, &UIInformationRuntime::sltHandleTableContextMenuRequest);
    491523    m_pMainLayout->addWidget(m_pRuntimeInfoWidget);
    492524    m_pRuntimeInfoWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
     525
     526    m_pCopyWholeTableAction = new QAction(this);
     527    connect(m_pCopyWholeTableAction, &QAction::triggered, this, &UIInformationRuntime::sltHandleCopyWholeTable);
    493528}
    494529
     
    525560}
    526561
     562void UIInformationRuntime::sltHandleTableContextMenuRequest(const QPoint &position)
     563{
     564    if (!m_pCopyWholeTableAction)
     565        return;
     566
     567    QMenu menu(this);
     568    menu.addAction(m_pCopyWholeTableAction);
     569    menu.exec(mapToGlobal(position));
     570}
     571
     572void UIInformationRuntime::sltHandleCopyWholeTable()
     573{
     574    QClipboard *pClipboard = QApplication::clipboard();
     575    if (!pClipboard)
     576        return;
     577    if (!m_pRuntimeInfoWidget)
     578        return;
     579
     580    pClipboard->setText(m_pRuntimeInfoWidget->tableData(), QClipboard::Clipboard);
     581}
     582
    527583#include "UIInformationRuntime.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.h

    r82968 r85891  
    3535
    3636/* Forward declarations: */
     37class QAction;
    3738class QVBoxLayout;
    3839class UISession;
     
    6667        void sltDnDModeChange(KDnDMode enmMode);
    6768    /** @} */
     69    void sltHandleTableContextMenuRequest(const QPoint &position);
     70    void sltHandleCopyWholeTable();
    6871
    6972private:
     
    7881    QVBoxLayout *m_pMainLayout;
    7982    UIRuntimeInfoWidget *m_pRuntimeInfoWidget;
     83    QAction *m_pCopyWholeTableAction;
    8084};
    8185
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