KIO

kurlnavigatormenu.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Rahman Duran <rahman.duran@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "kurlnavigatormenu_p.h"
8
9#include <QApplication>
10#include <QKeyEvent>
11#include <QMimeData>
12
13namespace KDEPrivate
14{
15KUrlNavigatorMenu::KUrlNavigatorMenu(QWidget *parent)
16 : QMenu(parent)
17 , m_initialMousePosition(QCursor::pos())
18 , m_mouseMoved(false)
19{
20 setAcceptDrops(true);
21 setMouseTracking(true);
22}
23
24KUrlNavigatorMenu::~KUrlNavigatorMenu()
25{
26}
27
28void KUrlNavigatorMenu::dragEnterEvent(QDragEnterEvent *event)
29{
30 if (event->mimeData()->hasUrls()) {
31 event->acceptProposedAction();
32 }
33}
34
35void KUrlNavigatorMenu::dragMoveEvent(QDragMoveEvent *event)
36{
37 const QPointF eventPosition = event->position();
38 const QPointF globalEventPosition = mapToGlobal(eventPosition);
39 QMouseEvent mouseEvent(QMouseEvent(QEvent::MouseMove, eventPosition, globalEventPosition, Qt::LeftButton, event->buttons(), event->modifiers()));
40 mouseMoveEvent(&mouseEvent);
41}
42
43void KUrlNavigatorMenu::dropEvent(QDropEvent *event)
44{
45 QAction *action = actionAt(event->position().toPoint());
46 if (action != nullptr) {
47 Q_EMIT urlsDropped(action, event);
48 }
49}
50
51void KUrlNavigatorMenu::mouseMoveEvent(QMouseEvent *event)
52{
53 if (!m_mouseMoved) {
54 QPoint moveDistance = mapToGlobal(event->pos()) - m_initialMousePosition;
55 m_mouseMoved = (moveDistance.manhattanLength() >= QApplication::startDragDistance());
56 }
57 // Don't pass the event to the base class until we consider
58 // that the mouse has moved. This prevents menu items from
59 // being highlighted too early.
60 if (m_mouseMoved) {
62 }
63}
64
65void KUrlNavigatorMenu::mouseReleaseEvent(QMouseEvent *event)
66{
67 Qt::MouseButton btn = event->button();
68 // Since menu is opened on mouse press, we may receive
69 // the corresponding mouse release event. Let's ignore
70 // it unless mouse was moved.
71 if (m_mouseMoved || (btn != Qt::LeftButton)) {
72 QAction *action = actionAt(event->pos());
73 if (action != nullptr) {
74 Q_EMIT mouseButtonClicked(action, btn);
75
76 // Prevent QMenu default activation, in case
77 // triggered signal is used
78 setActiveAction(nullptr);
79 }
81 }
82 m_mouseMoved = true;
83}
84
85} // namespace KDEPrivate
86
87#include "moc_kurlnavigatormenu_p.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
virtual void mouseMoveEvent(QMouseEvent *e) override
virtual void mouseReleaseEvent(QMouseEvent *e) override
int manhattanLength() const const
LeftButton
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:04:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.