void Util::setDragMode(int mode) { if (mode == dragMode()) { return; } QString modeString; switch(mode) { case DragGestures: modeString = "gestures"; break; case DragScroll: modeString = "scroll"; break; case DragSelect: modeString = "select"; break; case DragOff: default: modeString = "off"; } setSettingsValue("ui/dragMode", modeString); emit dragModeChanged(); }
void View::mouseReleaseEvent(QMouseEvent* event) { if (event->button() == s_dragMoveButton){ // disable scroll dragging, if it was enabled if(dragMode()==QGraphicsView::ScrollHandDrag){ QMouseEvent fakeEvent(event->type(), event->pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers()); QGraphicsView::mouseReleaseEvent(&fakeEvent); } } // make sure to reset the drag mode setDragMode(QGraphicsView::RubberBandDrag); QGraphicsView::mouseReleaseEvent(event); }
bool WindowManager::canDrag(QWidget *widget, QWidget *child, const QPoint &position) { // retrieve child at given position and check cursor again if (child && Qt::ArrowCursor!=child->cursor().shape()) { return false; } /* check against children from which drag should never be enabled, even if mousePress/Move has been passed to the parent */ if (child && (qobject_cast<QComboBox*>(child) || qobject_cast<QProgressBar*>(child))) { return false; } // tool buttons if (QToolButton *toolButton = qobject_cast<QToolButton*>(widget)) { if (dragMode() < WM_DRAG_ALL && !isToolBar(widget->parentWidget())) { return false; } return toolButton->autoRaise() && !toolButton->isEnabled(); } // check menubar if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(widget)) { // check if there is an active action if (menuBar->activeAction() && menuBar->activeAction()->isEnabled()) { return false; } // check if action at position exists and is enabled if (QAction *action = menuBar->actionAt(position)) { if (action->isSeparator()) { return true; } if (action->isEnabled()) { return false; } } // return true in all other cases return true; } bool toolbar=isToolBar(widget); if (dragMode() < WM_DRAG_MENU_AND_TOOLBAR && toolbar) { return false; } /* in MINIMAL mode, anything that has not been already accepted and does not come from a toolbar is rejected */ if (dragMode() < WM_DRAG_ALL) { return toolbar; } /* following checks are relevant only for WD_FULL mode */ // tabbar. Make sure no tab is under the cursor if (QTabBar *tabBar = qobject_cast<QTabBar*>(widget)) { return -1==tabBar->tabAt(position); } /* check groupboxes prevent drag if unchecking grouboxes */ if (QGroupBox *groupBox = qobject_cast<QGroupBox*>(widget)) { // non checkable group boxes are always ok if (!groupBox->isCheckable()) { return true; } // gather options to retrieve checkbox subcontrol rect QStyleOptionGroupBox opt; opt.initFrom(groupBox); if (groupBox->isFlat()) { opt.features |= QStyleOptionFrameV2::Flat; } opt.lineWidth = 1; opt.midLineWidth = 0; opt.text = groupBox->title(); opt.textAlignment = groupBox->alignment(); opt.subControls = (QStyle::SC_GroupBoxFrame | QStyle::SC_GroupBoxCheckBox); if (!groupBox->title().isEmpty()) { opt.subControls |= QStyle::SC_GroupBoxLabel; } opt.state |= (groupBox->isChecked() ? QStyle::State_On : QStyle::State_Off); // check against groupbox checkbox if (groupBox->style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxCheckBox, groupBox).contains(position)) { return false; } // check against groupbox label if (!groupBox->title().isEmpty() && groupBox->style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxLabel, groupBox).contains(position)) { return false; } return true; } // labels if (QLabel *label = qobject_cast<QLabel*>(widget)) { if (label->textInteractionFlags().testFlag(Qt::TextSelectableByMouse)) { return false; } } // abstract item views QAbstractItemView *itemView(NULL); if ((itemView = qobject_cast<QListView*>(widget->parentWidget())) || (itemView = qobject_cast<QTreeView*>(widget->parentWidget()))) { if (widget == itemView->viewport()) { // QListView if (QFrame::NoFrame!=itemView->frameShape()) { return false; } else if (QAbstractItemView::NoSelection!=itemView->selectionMode() && QAbstractItemView::SingleSelection!=itemView->selectionMode() && itemView->model() && itemView->model()->rowCount()) { return false; } else if (itemView->model() && itemView->indexAt(position).isValid()) { return false; } } } else if ((itemView = qobject_cast<QAbstractItemView*>(widget->parentWidget()))) { if (widget == itemView->viewport()) { // QAbstractItemView if (QFrame::NoFrame!=itemView->frameShape()) { return false; } else if (itemView->indexAt(position).isValid()) { return false; } } } return true; }