// taken from libqtxdg: XdgMenuWidget bool XdgCachedMenu::event(QEvent* event) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *e = static_cast<QMouseEvent*>(event); if (e->button() == Qt::LeftButton) mDragStartPosition = e->pos(); } else if (event->type() == QEvent::MouseMove) { QMouseEvent *e = static_cast<QMouseEvent*>(event); handleMouseMoveEvent(e); } else if(event->type() == QEvent::ToolTip) { QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event); QAction* action = actionAt(helpEvent->pos()); if(action && action->menu() == NULL) QToolTip::showText(helpEvent->globalPos(), action->toolTip(), this); } return QMenu::event(event); }
void FilterExpressionToolBar::onCustomMenuHandler(const QPoint& pos) { QAction * filterAction = actionAt(pos); if ( ! filterAction ) return; QMenu * filterMenu = new QMenu(this); QAction *actFilter = filterMenu->addAction(tr("Filter Button Preferences...")); connect(actFilter, SIGNAL(triggered()), this, SLOT(toolBarShowPreferences())); actFilter->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_)); actFilter->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_)); actFilter->setData(filterAction->data()); filterMenu->addSeparator(); QAction * actEdit = filterMenu->addAction(tr("Edit")); connect(actEdit, SIGNAL(triggered()), this, SLOT(editFilter())); actEdit->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_)); actEdit->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_)); actEdit->setData(filterAction->data()); QAction * actDisable = filterMenu->addAction(tr("Disable")); connect(actDisable, SIGNAL(triggered()), this, SLOT(disableFilter())); actDisable->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_)); actDisable->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_)); actDisable->setData(filterAction->data()); QAction * actRemove = filterMenu->addAction(tr("Remove")); connect(actRemove, SIGNAL(triggered()), this, SLOT(removeFilter())); actRemove->setProperty(dfe_property_label_, filterAction->property(dfe_property_label_)); actRemove->setProperty(dfe_property_expression_, filterAction->property(dfe_property_expression_)); actRemove->setData(filterAction->data()); filterMenu->exec(mapToGlobal(pos)); }
void PanelBrowserMenu::mouseMoveEvent(QMouseEvent *e) { QMenu::mouseMoveEvent(e); if (!(e->buttons() & Qt::LeftButton)) return; if(_lastpress == QPoint(-1, -1)) return; // DND delay if((_lastpress - e->pos()).manhattanLength() < 12) return; // get id int id = static_cast<QMenuItem*>(actionAt(_lastpress))->id(); if(!_filemap.contains(id)) return; // reset _lastpress _lastpress = QPoint(-1, -1); // start drag KUrl url; url.setPath(path() + '/' + _filemap[id]); KUrl::List files(url); QDrag* drag = new QDrag(this); QMimeData* data = new QMimeData; files.populateMimeData(data); connect(drag, SIGNAL(destroyed(QObject*)), this, SLOT(dragObjectDestroyed(QObject*))); drag->setPixmap(iconSet(id).pixmap()); drag->start(); }
void Menu::mouseReleaseEvent(QMouseEvent *event) { QAction *action = actionAt(event->pos()); if (action && action->data().type() == QVariant::ULongLong) { TaskManager::TaskPtr taskPointer = TaskManager::TaskManager::self()->findTask(action->data().toULongLong()); if (taskPointer) { TaskManager::GroupManager *groupManager = new TaskManager::GroupManager(this); Task *task = new Task(new TaskManager::TaskItem(groupManager, taskPointer), groupManager); if (event->button() == Qt::LeftButton) { task->activate(); } else if (event->button() == Qt::MidButton) { task->close(); } delete task; delete groupManager; } } KMenu::mouseReleaseEvent(event); }
void BookmarksToolBar::contextMenuRequested(const QPoint &position) { QAction *action = actionAt(position); QMenu menu; if (action) { QVariant variant = action->data(); Q_ASSERT(variant.canConvert<QModelIndex>()); QAction *menuAction = 0; if (!action->menu()) { menuAction = menu.addAction(tr("Open"), this, SLOT(openBookmarkInCurrentTab())); menuAction->setData(variant); menuAction = menu.addAction(tr("Open in New &Tab"), this, SLOT(openBookmarkInNewTab())); menuAction->setData(variant); menu.addSeparator(); } menuAction = menu.addAction(tr("Remove"), this, SLOT(removeBookmark())); menuAction->setData(variant); menu.addSeparator(); } menu.addAction(tr("Add Bookmark..."), this, SLOT(newBookmark())); menu.addAction(tr("Add Folder..."), this, SLOT(newFolder())); menu.exec(QCursor::pos()); }
void BookmarksToolBar::mouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) { QToolBar::mouseMoveEvent(event); return; } if ((event->pos() - m_dragStartPosition).manhattanLength() < QApplication::startDragDistance()) { QToolBar::mouseMoveEvent(event); return; } QAction *action = actionAt(m_dragStartPosition); QModelIndex index = this->index(action); if (!index.isValid()) { QToolBar::mouseMoveEvent(event); return; } QString title = index.data().toString(); QUrl url = index.data(BookmarksModel::UrlRole).toUrl(); QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData(); mimeData->setText(title); mimeData->setUrls(QList<QUrl>() << url); drag->setMimeData(mimeData); drag->exec(Qt::CopyAction); }
void Menu::mouseReleaseEvent(QMouseEvent* e) { QAction* qact = actionAt(e->pos()); Action* act = qobject_cast<Action*> (qact); if (qact && qact->menu()) { Menu* m = qobject_cast<Menu*> (qact->menu()); if (!m) { QMenu::mouseReleaseEvent(e); return; } if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) { closeAllMenus(); emit menuMiddleClicked(m); } } if (!act) { QMenu::mouseReleaseEvent(e); return; } if (e->button() == Qt::LeftButton && e->modifiers() == Qt::NoModifier) { closeAllMenus(); act->trigger(); e->accept(); } else if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) { closeAllMenus(); act->triggerMiddleClick(); e->accept(); } }
bool RiuToolTipMenu::event(QEvent* e) { if (e->type() == QEvent::ToolTip) { QHelpEvent* he = dynamic_cast<QHelpEvent*>(e); QAction* act = actionAt(he->pos()); if (act) { // Remove ampersand as this is used to define shortcut key QString actionTextWithoutAmpersand = act->text().remove("&"); if (actionTextWithoutAmpersand != act->toolTip()) { QToolTip::showText(he->globalPos(), act->toolTip(), this); } return true; } } else if (e->type() == QEvent::Paint && QToolTip::isVisible()) { QToolTip::hideText(); } return QMenu::event(e); }
void KUrlNavigatorMenu::dropEvent(QDropEvent* event) { QAction* action = actionAt(event->pos()); if (action != 0) { emit urlsDropped(action, event); } }
void Menu::contextMenuEvent(QContextMenuEvent *event) { if (m_role == BookmarksMenuRole) { QAction *action = actionAt(event->pos()); if (action && action->isEnabled() && action->data().type() == QVariant::ModelIndex) { m_bookmark = dynamic_cast<BookmarksItem*>(BookmarksManager::getModel()->itemFromIndex(action->data().toModelIndex())); QMenu contextMenu(this); contextMenu.addAction(Utils::getIcon(QLatin1String("document-open")), tr("Open"), this, SLOT(openBookmark())); contextMenu.addAction(tr("Open in New Tab"), this, SLOT(openBookmark()))->setData(WindowsManager::NewTabOpen); contextMenu.addAction(tr("Open in New Background Tab"), this, SLOT(openBookmark()))->setData(static_cast<int>(WindowsManager::NewTabOpen | WindowsManager::BackgroundOpen)); contextMenu.addSeparator(); contextMenu.addAction(tr("Open in New Window"), this, SLOT(openBookmark()))->setData(WindowsManager::NewWindowOpen); contextMenu.addAction(tr("Open in New Background Window"), this, SLOT(openBookmark()))->setData(static_cast<int>(WindowsManager::NewWindowOpen | WindowsManager::BackgroundOpen)); contextMenu.exec(event->globalPos()); return; } } QMenu::contextMenuEvent(event); }
void Menu::mouseReleaseEvent(QMouseEvent *event) { if (m_role == BookmarksMenuRole && (event->button() == Qt::LeftButton || event->button() == Qt::MiddleButton)) { QAction *action = actionAt(event->pos()); if (action && action->isEnabled() && action->data().type() == QVariant::ModelIndex) { QWidget *menu = this; while (menu) { menu->close(); menu = menu->parentWidget(); if (!menu || !menu->inherits(QLatin1String("QMenu").data())) { break; } } MainWindow *mainWindow = MainWindow::findMainWindow(parent()); if (mainWindow) { mainWindow->getWindowsManager()->open(dynamic_cast<BookmarksItem*>(BookmarksManager::getModel()->itemFromIndex(action->data().toModelIndex())), WindowsManager::calculateOpenHints(event->modifiers(), event->button())); return; } } } QMenu::mouseReleaseEvent(event); }
void BookmarksToolBar::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); if (mimeData->hasUrls() && mimeData->hasText()) { QList<QUrl> urls = mimeData->urls(); QAction *action = actionAt(event->pos()); QString dropText; if (action) dropText = action->text(); int row = -1; QModelIndex parentIndex = m_root; for (int i = 0; i < m_bookmarksModel->rowCount(m_root); ++i) { QModelIndex idx = m_bookmarksModel->index(i, 0, m_root); QString title = idx.data().toString(); if (title == dropText) { row = i; if (m_bookmarksModel->hasChildren(idx)) { parentIndex = idx; row = -1; } break; } } BookmarkNode *bookmark = new BookmarkNode(BookmarkNode::Bookmark); bookmark->url = urls.at(0).toString(); bookmark->title = mimeData->text(); BookmarkNode *parent = m_bookmarksModel->node(parentIndex); BookmarksManager *bookmarksManager = m_bookmarksModel->bookmarksManager(); bookmarksManager->addBookmark(parent, bookmark, row); event->acceptProposedAction(); } QToolBar::dropEvent(event); }
// Determine the geometry of the indicator by retrieving // the action under mouse and positioning the bar within its geometry. QRect ActionProviderBase::indicatorGeometry(const QPoint &pos, Qt::LayoutDirection layoutDirection) const { QAction *action = actionAt(pos); if (!action) return QRect(); QRect rc = actionGeometry(action); return orientation() == Qt::Horizontal ? horizontalIndicatorRect(rc, layoutDirection) : verticalIndicatorRect(rc); }
void ClickableMenu::mouseReleaseEvent(QMouseEvent *e) { QAction *action = actionAt(e->pos()); if (action) { action->activate(QAction::Trigger); return; } QMenu::mouseReleaseEvent(e); }
void KUrlNavigatorMenu::mouseReleaseEvent(QMouseEvent* event) { if (event->button() == Qt::MidButton) { QAction* action = actionAt(event->pos()); if (action != 0) { emit middleMouseButtonClicked(action); } } KMenu::mouseReleaseEvent(event); }
void ClickableMenu::mouseReleaseEvent(QMouseEvent* event) { QAction* const actionAtEvent = actionAt(event->pos()); if(actionAtEvent) { actionAtEvent->trigger(); } QMenu::mouseReleaseEvent(event); }
void PopupMenu::mouseReleaseEvent(QMouseEvent *e) { DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent this:%p\n", this); if(_contextMenu && _contextMenu->isVisible()) return; // Removed by Tim. Why not stay-open scrollable menus? // if(MusEGlobal::config.scrollableSubMenus) // { // QMenu::mouseReleaseEvent(e); // return; // } QAction* action = actionAt(e->pos()); if (!(action && action == activeAction() && !action->isSeparator() && action->isEnabled())) action=NULL; #ifdef POPUP_MENU_DISABLE_STAY_OPEN if (action && action->menu() != NULL && action->isCheckable()) action->activate(QAction::Trigger); QMenu::mouseReleaseEvent(e); if (action && action->menu() != NULL && action->isCheckable()) close(); return; #else // Check for Ctrl to stay open. const bool stay_open = _stayOpen && (MusEGlobal::config.popupsDefaultStayOpen || (e->modifiers() & Qt::ControlModifier)); // Stay open? Or does the action have a submenu, but also a checkbox of its own? if(action && (stay_open || (action->isEnabled() && action->menu() && action->isCheckable()))) { DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent: stay open\n"); action->trigger(); // Trigger the action. e->accept(); if(!stay_open) closeUp(); return; // We handled it. } // Otherwise let ancestor QMenu handle it... e->ignore(); QMenu::mouseReleaseEvent(e); #endif // POPUP_MENU_DISABLE_STAY_OPEN }
void ToolBar::mouseMoveEvent(QMouseEvent *e) { if (isMovable() && (e->buttons() & Qt::LeftButton) && (MouseStart - e->pos()).manhattanLength() >= 15) { QAction *action = actionAt(MouseStart); if (!action) return; foreach (const ToolBarAction &toolBarAction, ToolBarActions) { if (toolBarAction.action == action) { QDrag *drag = new ActionDrag(toolBarAction.actionName, toolBarAction.style, this); drag->exec(Qt::MoveAction); e->accept(); } } }
void BookmarkToolBar::contextMenu(const QPoint &point) { KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface*>(actionAt(point)); KBookmark bookmark = BookmarkManager::self()->manager()->toolbar(); bool nullAction = true; if (action) { bookmark = action->bookmark(); nullAction = false; } BookmarksContextMenu menu(bookmark, BookmarkManager::self()->manager(), BookmarkManager::self()->owner(), nullAction); menu.exec(mapToGlobal(point)); }
//---------------------------------------------------------------------------------- void ActionToolbar::contextMenuEvent(QContextMenuEvent *evt) { QMenu* contextMenu = new QMenu(this); QAction *act; mCurrentAction = actionAt(evt->pos()); contextMenu->addAction(QIcon(":/icons/additional.svg"), tr("Add Script Action"), mOgitorMainWindow, SLOT(onAddScriptAction())); act = contextMenu->addAction(QIcon(":/icons/trash.svg"), tr("Remove Script Action"), this, SLOT(onRemoveScriptAction())); act->setEnabled(mCurrentAction != 0); act = contextMenu->addAction(QIcon(":/icons/editrename.svg"), tr("Edit Script Action"), this, SLOT(onEditScriptAction())); act->setEnabled(mCurrentAction != 0); contextMenu->exec(QCursor::pos()); delete contextMenu; evt->accept(); }
void Menu::contextMenuEvent(QContextMenuEvent *event) { QAction *action = actionAt(event->pos()); if (action && action->data().type() == QVariant::ULongLong) { TaskManager::TaskPtr taskPointer = TaskManager::TaskManager::self()->findTask(action->data().toULongLong()); if (taskPointer) { TaskManager::GroupManager *groupManager = new TaskManager::GroupManager(this); Task *task = new Task(new TaskManager::TaskItem(groupManager, taskPointer), groupManager); KMenu *menu = task->contextMenu(); menu->exec(event->globalPos()); delete task; delete groupManager; delete menu; } } }
void Menu::dragMoveEvent(QDragMoveEvent *event) { event->acceptProposedAction(); QAction *action = actionAt(event->pos()); if (action && action->data().toULongLong() && action != m_currentAction) { m_currentAction = action; TaskManager::TaskPtr taskPointer = TaskManager::TaskManager::self()->findTask(action->data().toULongLong()); if (taskPointer) { TaskManager::GroupManager *groupManager = new TaskManager::GroupManager(this); Task *task = new Task(new TaskManager::TaskItem(groupManager, taskPointer), groupManager); task->activateWindow(); delete task; delete groupManager; } } }
bool UIMenu::event(QEvent *pEvent) { /* Handle particular event-types: */ switch (pEvent->type()) { /* Tool-tip request handler: */ case QEvent::ToolTip: { /* Get current help-event: */ QHelpEvent *pHelpEvent = static_cast<QHelpEvent*>(pEvent); /* Get action which caused help-event: */ QAction *pAction = actionAt(pHelpEvent->pos()); /* If action present => show action's tool-tip if needed: */ if (pAction && m_fShowToolTips) QToolTip::showText(pHelpEvent->globalPos(), pAction->toolTip()); break; } default: break; } /* Base-class event-handler: */ return QMenu::event(pEvent); }
void BookmarksToolBar::dropEvent(QDropEvent *event) { const QMimeData *mimeData = event->mimeData(); if (mimeData->hasUrls()) { QUrl url = mimeData->urls().at(0); QString title = mimeData->text(); if (url.isEmpty()) { QToolBar::dropEvent(event); return; } if (title.isEmpty()) title = QString::fromUtf8(url.toEncoded()); QModelIndex parentIndex = m_root; QAction *action = actionAt(event->pos()); QModelIndex index = this->index(action); if (action && action->menu() && index.isValid()) parentIndex = index; BookmarkNode *node = new BookmarkNode(BookmarkNode::Bookmark); node->url = QString::fromUtf8(url.toEncoded()); node->title = title; int row = m_bookmarksModel->rowCount(parentIndex); BookmarkNode *parent = m_bookmarksModel->node(parentIndex); BookmarksManager *bookmarksManager = m_bookmarksModel->bookmarksManager(); bookmarksManager->addBookmark(parent, node, row); event->acceptProposedAction(); } QToolBar::dropEvent(event); }
// taken from libqtxdg: XdgMenuWidget void XdgCachedMenu::handleMouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) return; if ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; XdgCachedMenuAction *a = qobject_cast<XdgCachedMenuAction*>(actionAt(event->pos())); if (!a) return; QList<QUrl> urls; char* desktop_file = menu_cache_item_get_file_path(a->item()); urls << QUrl(desktop_file); g_free(desktop_file); QMimeData *mimeData = new QMimeData(); mimeData->setUrls(urls); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->exec(Qt::CopyAction | Qt::LinkAction); }
bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) { if (m_currentMenu && m_currentMenu->isVisible() && !m_currentMenu->rect().contains(m_currentMenu->mapFromGlobal(QCursor::pos()))) { // To switch root folders as in a menubar KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(actionAt(mapFromGlobal(QCursor::pos()))); if (event->type() == QEvent::MouseMove && act && act->menu() != m_currentMenu) { m_currentMenu->hide(); QPoint pos = mapToGlobal(widgetForAction(act)->pos()); act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height())); } else if (event->type() == QEvent::MouseButtonPress && act) { m_currentMenu->hide(); } return QObject::eventFilter(watched, event); } switch (event->type()) { case QEvent::Show: { if (!m_filled) { BookmarkManager::self()->fillBookmarkBar(this); m_filled = true; } } break; case QEvent::ActionRemoved: { QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); } } } break; case QEvent::ParentChange: { QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); } } } break; case QEvent::DragEnter: { QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event); if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type()) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { QFrame* dropIndicatorWidget = new QFrame(this); dropIndicatorWidget->setFrameShape(QFrame::VLine); m_dropAction = insertWidget(actionAt(dragEvent->pos()), dropIndicatorWidget); dragEvent->accept(); } } break; case QEvent::DragLeave: { QDragLeaveEvent *dragEvent = static_cast<QDragLeaveEvent*>(event); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } delete m_dropAction; m_dropAction = 0; dragEvent->accept(); } break; case QEvent::DragMove: { QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent*>(event); if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type()) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { QAction *overAction = actionAt(dragEvent->pos()); KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction); QWidget *widgetAction = widgetForAction(overAction); if (overAction != m_dropAction && overActionBK && widgetAction && m_dropAction) { removeAction(m_dropAction); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } if (!overActionBK->bookmark().isGroup()) { if ((dragEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2)) { if (actions().count() > actions().indexOf(overAction) + 1) { insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { addAction(m_dropAction); } } else { insertAction(overAction, m_dropAction); } } else { if ((dragEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75)) { if (actions().count() > actions().indexOf(overAction) + 1) { insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { addAction(m_dropAction); } } else if ((dragEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25)) { insertAction(overAction, m_dropAction); } else { overAction->setCheckable(true); overAction->setChecked(true); m_checkedAction = overAction; } } dragEvent->accept(); } } } break; case QEvent::Drop: { QDropEvent *dropEvent = static_cast<QDropEvent*>(event); KBookmark bookmark; KBookmarkGroup root = BookmarkManager::self()->manager()->toolbar(); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } if (dropEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type())) { QByteArray addresses = dropEvent->mimeData()->data(BookmarkManager::bookmark_mime_type()); bookmark = BookmarkManager::self()->findByAddress(QString::fromLatin1(addresses.data())); if (bookmark.isNull()) return false; } else if (dropEvent->mimeData()->hasFormat("text/uri-list")) { // DROP is URL QString url = dropEvent->mimeData()->urls().at(0).toString(); WebWindow *w = qobject_cast<WebWindow *>(parent()); QString title = url.contains(w->url().url()) ? w->title() : url; bookmark = root.addBookmark(title, url); } else if (dropEvent->mimeData()->hasFormat("text/plain")) { // DROP is TEXT QString url = dropEvent->mimeData()->text(); KUrl u(url); if (u.isValid()) { WebWindow *w = qobject_cast<WebWindow *>(parent()); QString title = url.contains(w->url().url()) ? w->title() : url; bookmark = root.addBookmark(title, url); } } else { return false; } QAction *destAction = actionAt(dropEvent->pos()); if (destAction && destAction == m_dropAction) { if (actions().indexOf(m_dropAction) > 0) { destAction = actions().at(actions().indexOf(m_dropAction) - 1); } else { destAction = actions().at(1); } } if (destAction) { KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction); QWidget *widgetAction = widgetForAction(destAction); if (destBookmarkAction && !destBookmarkAction->bookmark().isNull() && widgetAction && bookmark.address() != destBookmarkAction->bookmark().address()) { KBookmark destBookmark = destBookmarkAction->bookmark(); if (!destBookmark.isGroup()) { if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() / 2)) { root.moveBookmark(bookmark, destBookmark); } else { root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); } } else { if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75)) { root.moveBookmark(bookmark, destBookmark); } else if ((dropEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25)) { root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); } else { destBookmark.toGroup().addBookmark(bookmark); } } BookmarkManager::self()->emitChanged(); } } else { root.deleteBookmark(bookmark); bookmark = root.addBookmark(bookmark); if (dropEvent->pos().x() < widgetForAction(actions().first())->pos().x()) { root.moveBookmark(bookmark, KBookmark()); } BookmarkManager::self()->emitChanged(); } dropEvent->accept(); } break; default: break; } QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); // These events need to be handled only for Bookmark actions and not the bar if (watched != this && mouseEvent) { switch (event->type()) { case QEvent::MouseButtonPress: // drag handling { QPoint pos = mapFromGlobal(QCursor::pos()); KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos)); if (action && mouseEvent->button() != Qt::MiddleButton) { m_dragAction = actionAt(pos); m_startDragPos = pos; // The menu is displayed only when the mouse button is released if (action->bookmark().isGroup()) return true; } } break; case QEvent::MouseMove: { int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength(); if (!m_currentMenu && distance >= QApplication::startDragDistance()) { startDrag(); } } break; case QEvent::MouseButtonRelease: { QPoint destPos = mapFromGlobal(QCursor::pos()); int distance = (destPos - m_startDragPos).manhattanLength(); KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(destPos)); if (action) { if (action->bookmark().isGroup()) { if (mouseEvent->button() == Qt::MiddleButton) { BookmarkManager::self()->owner()->loadBookmarkFolder(action->bookmark()); } else if (distance < QApplication::startDragDistance()) { KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu *>(actionAt(m_startDragPos)); QPoint actionPos = mapToGlobal(widgetForAction(menu)->pos()); menu->menu()->popup(QPoint(actionPos.x(), actionPos.y() + widgetForAction(menu)->height())); } } else { if (!action->bookmark().isNull() && !action->bookmark().isSeparator()) { if (mouseEvent->button() == Qt::MiddleButton) { BookmarkManager::self()->owner()->loadBookmarkInNewTab(action->bookmark()); } } } } } break; default: break; } } return QObject::eventFilter(watched, event); }