VirtualBox

Changeset 86226 in vbox


Ignore:
Timestamp:
Sep 22, 2020 5:08:09 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: UIDetailsElement: Rework cloud VM details element to popup menu on mouse click for any detail independent on enabled state; This allows us to have Copy value action for any detail, while Edit action will present for details with enabled state only.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/details
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsElement.cpp

    r86223 r86226  
    1818/* Qt includes: */
    1919#include <QActionGroup>
     20#include <QClipboard>
    2021#include <QGraphicsSceneMouseEvent>
    2122#include <QGraphicsView>
     
    3738#include "UIConverter.h"
    3839#include "UIDetailsElement.h"
     40#include "UIDetailsGenerator.h"
    3941#include "UIDetailsSet.h"
    4042#include "UIDetailsModel.h"
     
    607609}
    608610
     611void UIDetailsElement::sltHandleCopyRequest()
     612{
     613    /* Acquire sender: */
     614    QObject *pSender = sender();
     615    AssertPtrReturnVoid(pSender);
     616
     617    /* Acquire clipboard: */
     618    QClipboard *pClipboard = QGuiApplication::clipboard();
     619    AssertPtrReturnVoid(pClipboard);
     620    pClipboard->setText(pSender->property("contents").toString());
     621}
     622
     623void UIDetailsElement::sltHandleEditRequest()
     624{
     625    /* Acquire sender: */
     626    QObject *pSender = sender();
     627    AssertPtrReturnVoid(pSender);
     628
     629    /* Prepare popup: */
     630    QPointer<QIDialogContainer> pPopup = new QIDialogContainer(0, Qt::Tool);
     631    if (pPopup)
     632    {
     633        /* Acquire cloud machine: */
     634        CCloudMachine comCloudMachine = cloudMachine();
     635
     636        /* Prepare editor: */
     637        UISafePointerCloudMachineSettingsDialogPage pEditor = new UICloudMachineSettingsDialogPage(pPopup,
     638                                                                                                   false /* full-scale? */);
     639        if (pEditor)
     640        {
     641            /* Configure editor: */
     642            connect(pEditor.data(), &UICloudMachineSettingsDialogPage::sigValidChanged,
     643                    pPopup.data(), &QIDialogContainer::setProgressBarHidden);
     644            connect(pEditor.data(), &UICloudMachineSettingsDialogPage::sigValidChanged,
     645                    pPopup.data(), &QIDialogContainer::setOkButtonEnabled);
     646            pEditor->setFilter(pSender->property("filter").toString());
     647            /* Create get settings form task: */
     648            UITaskCloudGetSettingsForm *pTask = new UITaskCloudGetSettingsForm(comCloudMachine);
     649            /* Create get settings form receiver: */
     650            UIReceiverCloudGetSettingsForm *pReceiver = new UIReceiverCloudGetSettingsForm(pEditor);
     651            if (pReceiver)
     652            {
     653                connect(pReceiver, &UIReceiverCloudGetSettingsForm::sigTaskComplete,
     654                        pEditor.data(), &UICloudMachineSettingsDialogPage::setForm);
     655                connect(pReceiver, &UIReceiverCloudGetSettingsForm::sigTaskFailed,
     656                        pPopup.data(), &QIDialogContainer::close);
     657            }
     658            /* Start task: */
     659            if (pTask && pReceiver)
     660                uiCommon().threadPoolCloud()->enqueueTask(pTask);
     661            /* Embed editor: */
     662            pPopup->setWidget(pEditor);
     663        }
     664
     665        /* Adjust popup geometry: */
     666        pPopup->move(QCursor::pos());
     667        pPopup->resize(pPopup->minimumSizeHint());
     668
     669        // WORKAROUND:
     670        // On Windows, Tool dialogs aren't activated by default by some reason.
     671        // So we have created sltActivateWindow wrapping actual activateWindow
     672        // to fix that annoying issue.
     673        QMetaObject::invokeMethod(pPopup, "sltActivateWindow", Qt::QueuedConnection);
     674        /* Execute popup, change machine name if confirmed: */
     675        if (pPopup->exec() == QDialog::Accepted)
     676        {
     677            /* Makes sure page data committed: */
     678            if (pEditor)
     679                pEditor->makeSureDataCommitted();
     680
     681            /* Apply form: */
     682            CForm comForm = pEditor->form();
     683            applyCloudMachineSettingsForm(comCloudMachine, comForm);
     684        }
     685
     686        /* Delete popup: */
     687        delete pPopup;
     688    }
     689}
     690
    609691void UIDetailsElement::sltMountStorageMedium()
    610692{
     
    13031385void UIDetailsElement::popupCloudEditor(const QString &strValue)
    13041386{
    1305     /* Prepare popup: */
    1306     QPointer<QIDialogContainer> pPopup = new QIDialogContainer(0, Qt::Tool);
    1307     if (pPopup)
    1308     {
    1309         /* Acquire cloud machine: */
    1310         CCloudMachine comCloudMachine = cloudMachine();
    1311 
    1312         /* Prepare editor: */
    1313         UISafePointerCloudMachineSettingsDialogPage pEditor = new UICloudMachineSettingsDialogPage(pPopup,
    1314                                                                                                    false /* full-scale? */);
    1315         if (pEditor)
    1316         {
    1317             /* Configure editor: */
    1318             connect(pEditor.data(), &UICloudMachineSettingsDialogPage::sigValidChanged,
    1319                     pPopup.data(), &QIDialogContainer::setProgressBarHidden);
    1320             connect(pEditor.data(), &UICloudMachineSettingsDialogPage::sigValidChanged,
    1321                     pPopup.data(), &QIDialogContainer::setOkButtonEnabled);
    1322             pEditor->setFilter(strValue);
    1323             /* Create get settings form task: */
    1324             UITaskCloudGetSettingsForm *pTask = new UITaskCloudGetSettingsForm(comCloudMachine);
    1325             /* Create get settings form receiver: */
    1326             UIReceiverCloudGetSettingsForm *pReceiver = new UIReceiverCloudGetSettingsForm(pEditor);
    1327             if (pReceiver)
     1387    /* Prepare cloud-menu: */
     1388    UIMenu menu;
     1389    menu.setShowToolTip(true);
     1390
     1391    /* Acquire cloud machine: */
     1392    CCloudMachine comCloudMachine = cloudMachine();
     1393    /* Acquire details form: */
     1394    CForm comForm = comCloudMachine.GetDetailsForm();
     1395    /* Ignore cloud machine errors: */
     1396    if (comCloudMachine.isOk())
     1397    {
     1398        /* For each form value: */
     1399        foreach (const CFormValue &comIteratedValue, comForm.GetValues())
     1400        {
     1401            /* Acquire label: */
     1402            const QString &strIteratedLabel = comIteratedValue.GetLabel();
     1403            if (strIteratedLabel != strValue)
     1404                continue;
     1405
     1406            /* Acquire resulting value in full and compressed form: */
     1407            const QString strIteratedResultFull = UIDetailsGenerator::generateFormValueInformation(comIteratedValue);
     1408            const QString strIteratedResultShort =    strIteratedResultFull.size() > 10
     1409                                                   && strIteratedResultFull.startsWith("ocid1.")
     1410                                                 ? QString("...%1").arg(strIteratedResultFull.right(10))
     1411                                                 : strIteratedResultFull;
     1412
     1413            /* Add 'Copy' action: */
     1414            QAction *pAction = menu.addAction(tr("Copy value (%1)").arg(strIteratedResultShort),
     1415                                              this, &UIDetailsElement::sltHandleCopyRequest);
     1416            if (pAction)
    13281417            {
    1329                 connect(pReceiver, &UIReceiverCloudGetSettingsForm::sigTaskComplete,
    1330                         pEditor.data(), &UICloudMachineSettingsDialogPage::setForm);
    1331                 connect(pReceiver, &UIReceiverCloudGetSettingsForm::sigTaskFailed,
    1332                         pPopup.data(), &QIDialogContainer::close);
     1418                pAction->setToolTip(strIteratedResultFull);
     1419                pAction->setProperty("contents", strIteratedResultFull);
    13331420            }
    1334             /* Start task: */
    1335             if (pTask && pReceiver)
    1336                 uiCommon().threadPoolCloud()->enqueueTask(pTask);
    1337             /* Embed editor: */
    1338             pPopup->setWidget(pEditor);
    1339         }
    1340 
    1341         /* Adjust popup geometry: */
    1342         pPopup->move(QCursor::pos());
    1343         pPopup->resize(pPopup->minimumSizeHint());
    1344 
    1345         // WORKAROUND:
    1346         // On Windows, Tool dialogs aren't activated by default by some reason.
    1347         // So we have created sltActivateWindow wrapping actual activateWindow
    1348         // to fix that annoying issue.
    1349         QMetaObject::invokeMethod(pPopup, "sltActivateWindow", Qt::QueuedConnection);
    1350         /* Execute popup, change machine name if confirmed: */
    1351         if (pPopup->exec() == QDialog::Accepted)
    1352         {
    1353             /* Makes sure page data committed: */
    1354             if (pEditor)
    1355                 pEditor->makeSureDataCommitted();
    1356 
    1357             /* Apply form: */
    1358             CForm comForm = pEditor->form();
    1359             applyCloudMachineSettingsForm(comCloudMachine, comForm);
    1360         }
    1361 
    1362         /* Delete popup: */
    1363         delete pPopup;
    1364     }
     1421
     1422            /* Add 'Edit' action: */
     1423            if (comIteratedValue.GetEnabled())
     1424            {
     1425                QAction *pAction = menu.addAction(tr("Edit value..."),
     1426                                                  this, &UIDetailsElement::sltHandleEditRequest);
     1427                if (pAction)
     1428                    pAction->setProperty("filter", strIteratedLabel);
     1429            }
     1430
     1431            /* Quit prematurely: */
     1432            break;
     1433        }
     1434    }
     1435
     1436    /* Exec menu: */
     1437    menu.exec(QCursor::pos());
    13651438}
    13661439
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsElement.h

    r86223 r86226  
    223223        void sltElementToggleFinish(bool fToggled);
    224224
    225         /** Handles children anchor clicks. */
     225        /** Handles child anchor clicks. */
    226226        void sltHandleAnchorClicked(const QString &strAnchor);
     227        /** Handles child copy request. */
     228        void sltHandleCopyRequest();
     229        /** Handles child edit request. */
     230        void sltHandleEditRequest();
    227231    /** @} */
    228232
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