- Timestamp:
- May 20, 2019 1:42:42 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp
r78597 r78598 17 17 18 18 /* Qt includes: */ 19 #include <QDrag> 20 #include <QDragMoveEvent> 19 21 #include <QHeaderView> 20 22 #include <QItemEditorFactory> 21 23 #include <QMenu> 24 #include <QMimeData> 22 25 #include <QMouseEvent> 23 26 #include <QScrollBar> … … 1959 1962 1960 1963 /* Then we have to make sure moved attachment is valid: */ 1961 if (enmDeviceType != KDeviceType_Null && !uMediumId.isNull())1964 if (enmDeviceType != KDeviceType_Null) 1962 1965 { 1963 1966 /* And create new attachment item finally: */ … … 2245 2248 }; 2246 2249 2250 2251 /* static */ 2252 const QString UIMachineSettingsStorage::ControllerMimeType = QString("application/virtualbox;value=StorageControllerID"); 2253 const QString UIMachineSettingsStorage::AttachmentMimeType = QString("application/virtualbox;value=StorageAttachmentID"); 2247 2254 2248 2255 UIMachineSettingsStorage::UIMachineSettingsStorage() … … 3431 3438 void UIMachineSettingsStorage::sltHandleMouseMove(QMouseEvent *pEvent) 3432 3439 { 3440 /* Make sure event is valid: */ 3441 AssertPtrReturnVoid(pEvent); 3442 3433 3443 const QModelIndex index = m_pTreeStorage->indexAt(pEvent->pos()); 3434 3444 const QRect indexRect = m_pTreeStorage->visualRect(index); … … 3514 3524 if (m_pModelStorage->data(index, StorageModel::R_ToolTipType).value<StorageModel::ToolTipType>() != StorageModel::DefaultToolTip) 3515 3525 m_pModelStorage->setData(index, StorageModel::DefaultToolTip, StorageModel::R_ToolTipType); 3526 3527 /* Check whether we should initiate dragging: */ 3528 if ( !m_mousePressPosition.isNull() 3529 && QLineF(pEvent->screenPos(), m_mousePressPosition).length() >= QApplication::startDragDistance()) 3530 { 3531 /* Forget last mouse press position: */ 3532 m_mousePressPosition = QPoint(); 3533 3534 /* Check what item we are hovering currently: */ 3535 QModelIndex index = m_pTreeStorage->indexAt(pEvent->pos()); 3536 AbstractItem *pItem = static_cast<AbstractItem*>(index.internalPointer()); 3537 /* And make sure this is attachment item, we are supporting dragging for this kind only: */ 3538 AttachmentItem *pItemAttachment = qobject_cast<AttachmentItem*>(pItem); 3539 if (pItemAttachment) 3540 { 3541 /* Initialize dragging: */ 3542 QDrag *pDrag = new QDrag(this); 3543 if (pDrag) 3544 { 3545 /* Assign pixmap: */ 3546 pDrag->setPixmap(pItem->pixmap()); 3547 /* Prepare mime: */ 3548 QMimeData *pMimeData = new QMimeData; 3549 if (pMimeData) 3550 { 3551 pMimeData->setData(ControllerMimeType, pItemAttachment->parent()->id().toString().toLatin1()); 3552 pMimeData->setData(AttachmentMimeType, pItemAttachment->id().toString().toLatin1()); 3553 pDrag->setMimeData(pMimeData); 3554 } 3555 /* Start dragging: */ 3556 pDrag->exec(); 3557 } 3558 } 3559 } 3516 3560 } 3517 3561 3518 3562 void UIMachineSettingsStorage::sltHandleMouseClick(QMouseEvent *pEvent) 3519 3563 { 3564 /* Make sure event is valid: */ 3565 AssertPtrReturnVoid(pEvent); 3566 3567 /* Remember last mouse press position: */ 3568 m_mousePressPosition = pEvent->globalPos(); 3569 3520 3570 const QModelIndex index = m_pTreeStorage->indexAt(pEvent->pos()); 3521 3571 const QRect indexRect = m_pTreeStorage->visualRect(index); … … 3577 3627 } 3578 3628 3629 void UIMachineSettingsStorage::sltHandleMouseRelease(QMouseEvent *) 3630 { 3631 /* Forget last mouse press position: */ 3632 m_mousePressPosition = QPoint(); 3633 } 3634 3635 void UIMachineSettingsStorage::sltHandleDragEnter(QDragEnterEvent *pEvent) 3636 { 3637 /* Make sure event is valid: */ 3638 AssertPtrReturnVoid(pEvent); 3639 3640 /* Accept event but not the proposed action: */ 3641 pEvent->accept(); 3642 } 3643 3644 void UIMachineSettingsStorage::sltHandleDragMove(QDragMoveEvent *pEvent) 3645 { 3646 /* Make sure event is valid: */ 3647 AssertPtrReturnVoid(pEvent); 3648 /* And mime-data is set: */ 3649 const QMimeData *pMimeData = pEvent->mimeData(); 3650 AssertPtrReturnVoid(pMimeData); 3651 3652 /* Make sure mime-data format is valid: */ 3653 if ( !pMimeData->hasFormat(UIMachineSettingsStorage::ControllerMimeType) 3654 || !pMimeData->hasFormat(UIMachineSettingsStorage::AttachmentMimeType)) 3655 return; 3656 3657 /* Get controller id: */ 3658 const QString strControllerId = pMimeData->data(UIMachineSettingsStorage::ControllerMimeType); 3659 3660 /* Check what item we are hovering currently: */ 3661 QModelIndex index = m_pTreeStorage->indexAt(pEvent->pos()); 3662 AbstractItem *pItem = static_cast<AbstractItem*>(index.internalPointer()); 3663 /* And make sure this is controller item, we are supporting dropping for this kind only: */ 3664 ControllerItem *pItemController = qobject_cast<ControllerItem*>(pItem); 3665 if (!pItemController || pItemController->id().toString() == strControllerId) 3666 return; 3667 /* Also make sure there is enough place for new attachment: */ 3668 const KStorageBus enmBus = pItemController->ctrBusType(); 3669 const int uMaxPortCount = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(enmBus); 3670 const int uMaxDevicePerPortCount = vboxGlobal().virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus(enmBus); 3671 const SlotsList usedSlots = pItemController->ctrUsedSlots(); 3672 if (usedSlots.size() >= uMaxPortCount * uMaxDevicePerPortCount) 3673 return; 3674 3675 /* Accept drag-enter event: */ 3676 pEvent->acceptProposedAction(); 3677 } 3678 3679 void UIMachineSettingsStorage::sltHandleDragDrop(QDropEvent *pEvent) 3680 { 3681 /* Make sure event is valid: */ 3682 AssertPtrReturnVoid(pEvent); 3683 /* And mime-data is set: */ 3684 const QMimeData *pMimeData = pEvent->mimeData(); 3685 AssertPtrReturnVoid(pMimeData); 3686 3687 /* Check what item we are hovering currently: */ 3688 QModelIndex index = m_pTreeStorage->indexAt(pEvent->pos()); 3689 AbstractItem *pItem = static_cast<AbstractItem*>(index.internalPointer()); 3690 /* And make sure this is controller item, we are supporting dropping for this kind only: */ 3691 ControllerItem *pItemController = qobject_cast<ControllerItem*>(pItem); 3692 if (pItemController) 3693 { 3694 /* Get controller/attachment ids: */ 3695 const QString strControllerId = pMimeData->data(UIMachineSettingsStorage::ControllerMimeType); 3696 const QString strAttachmentId = pMimeData->data(UIMachineSettingsStorage::AttachmentMimeType); 3697 m_pModelStorage->moveAttachment(strAttachmentId, strControllerId, pItemController->id()); 3698 } 3699 } 3700 3579 3701 void UIMachineSettingsStorage::prepare() 3580 3702 { … … 3633 3755 mLsLeftPane->setBuddy(m_pTreeStorage); 3634 3756 m_pTreeStorage->setMouseTracking(true); 3757 m_pTreeStorage->setAcceptDrops(true); 3635 3758 m_pTreeStorage->setContextMenuPolicy(Qt::CustomContextMenu); 3636 3759 … … 3858 3981 connect(m_pTreeStorage, SIGNAL(mouseMoved(QMouseEvent *)), 3859 3982 this, SLOT(sltHandleMouseMove(QMouseEvent *))); 3860 connect(m_pTreeStorage, SIGNAL(mousePressed(QMouseEvent *)), 3861 this, SLOT(sltHandleMouseClick(QMouseEvent *))); 3983 connect(m_pTreeStorage, &QITreeView::mousePressed, 3984 this, &UIMachineSettingsStorage::sltHandleMouseClick); 3985 connect(m_pTreeStorage, &QITreeView::mouseReleased, 3986 this, &UIMachineSettingsStorage::sltHandleMouseRelease); 3862 3987 connect(m_pTreeStorage, SIGNAL(mouseDoubleClicked(QMouseEvent *)), 3863 3988 this, SLOT(sltHandleMouseClick(QMouseEvent *))); 3989 connect(m_pTreeStorage, &QITreeView::dragEntered, 3990 this, &UIMachineSettingsStorage::sltHandleDragEnter); 3991 connect(m_pTreeStorage, &QITreeView::dragMoved, 3992 this, &UIMachineSettingsStorage::sltHandleDragMove); 3993 connect(m_pTreeStorage, &QITreeView::dragDropped, 3994 this, &UIMachineSettingsStorage::sltHandleDragDrop); 3864 3995 3865 3996 /* Create model: */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.h
r78597 r78598 556 556 public: 557 557 558 /** Holds the controller mime-type for the D&D system. */ 559 static const QString ControllerMimeType; 560 /** Holds the attachment mime-type for the D&D system. */ 561 static const QString AttachmentMimeType; 562 558 563 /** Constructs Storage settings page. */ 559 564 UIMachineSettingsStorage(); … … 676 681 /** Handles mouse-click @a pEvent. */ 677 682 void sltHandleMouseClick(QMouseEvent *pEvent); 683 /** Handles mouse-release @a pEvent. */ 684 void sltHandleMouseRelease(QMouseEvent *pEvent); 685 686 /** Handles drag-enter @a pEvent. */ 687 void sltHandleDragEnter(QDragEnterEvent *pEvent); 688 /** Handles drag-move @a pEvent. */ 689 void sltHandleDragMove(QDragMoveEvent *pEvent); 690 /** Handles drag-drop @a pEvent. */ 691 void sltHandleDragDrop(QDropEvent *pEvent); 678 692 679 693 private: … … 790 804 bool m_fLoadingInProgress; 791 805 806 /** Holds the last mouse-press position. */ 807 QPoint m_mousePressPosition; 808 792 809 /** Holds the page data cache instance. */ 793 810 UISettingsCacheMachineStorage *m_pCache;
Note:
See TracChangeset
for help on using the changeset viewer.