| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qplatformdrag.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qplatformdrag.h" | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #include <QtGui/private/qdnd_p.h> | - | ||||||||||||
| 43 | #include <QtGui/QKeyEvent> | - | ||||||||||||
| 44 | #include <QtGui/QGuiApplication> | - | ||||||||||||
| 45 | #include <QtCore/QEventLoop> | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||
| 50 | #ifdef QDND_DEBUG | - | ||||||||||||
| 51 | # include <QtCore/QDebug> | - | ||||||||||||
| 52 | #endif | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | QPlatformDropQtResponse::QPlatformDropQtResponse(bool accepted, Qt::DropAction acceptedAction) | - | ||||||||||||
| 55 | : m_accepted(accepted) | - | ||||||||||||
| 56 | , m_accepted_action(acceptedAction) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | } never executed: end of block | 0 | ||||||||||||
| 59 | - | |||||||||||||
| 60 | bool QPlatformDropQtResponse::isAccepted() const | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | return m_accepted; never executed: return m_accepted; | 0 | ||||||||||||
| 63 | } | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | Qt::DropAction QPlatformDropQtResponse::acceptedAction() const | - | ||||||||||||
| 66 | { | - | ||||||||||||
| 67 | return m_accepted_action; never executed: return m_accepted_action; | 0 | ||||||||||||
| 68 | } | - | ||||||||||||
| 69 | - | |||||||||||||
| 70 | QPlatformDragQtResponse::QPlatformDragQtResponse(bool accepted, Qt::DropAction acceptedAction, QRect answerRect) | - | ||||||||||||
| 71 | : QPlatformDropQtResponse(accepted,acceptedAction) | - | ||||||||||||
| 72 | , m_answer_rect(answerRect) | - | ||||||||||||
| 73 | { | - | ||||||||||||
| 74 | } never executed: end of block | 0 | ||||||||||||
| 75 | - | |||||||||||||
| 76 | QRect QPlatformDragQtResponse::answerRect() const | - | ||||||||||||
| 77 | { | - | ||||||||||||
| 78 | return m_answer_rect; never executed: return m_answer_rect; | 0 | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | class QPlatformDragPrivate { | - | ||||||||||||
| 82 | public: | - | ||||||||||||
| 83 | QPlatformDragPrivate() : cursor_drop_action(Qt::IgnoreAction) {} never executed: end of block | 0 | ||||||||||||
| 84 | - | |||||||||||||
| 85 | Qt::DropAction cursor_drop_action; | - | ||||||||||||
| 86 | }; | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | /*! | - | ||||||||||||
| 89 | \class QPlatformDrag | - | ||||||||||||
| 90 | \since 5.0 | - | ||||||||||||
| 91 | \internal | - | ||||||||||||
| 92 | \preliminary | - | ||||||||||||
| 93 | \ingroup qpa | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | \brief The QPlatformDrag class provides an abstraction for drag. | - | ||||||||||||
| 96 | */ | - | ||||||||||||
| 97 | QPlatformDrag::QPlatformDrag() : d_ptr(new QPlatformDragPrivate) | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | } never executed: end of block | 0 | ||||||||||||
| 100 | - | |||||||||||||
| 101 | QPlatformDrag::~QPlatformDrag() | - | ||||||||||||
| 102 | { | - | ||||||||||||
| 103 | delete d_ptr; | - | ||||||||||||
| 104 | } never executed: end of block | 0 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | QDrag *QPlatformDrag::currentDrag() const | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | return QDragManager::self()->object(); never executed: return QDragManager::self()->object(); | 0 | ||||||||||||
| 109 | } | - | ||||||||||||
| 110 | - | |||||||||||||
| 111 | Qt::DropAction QPlatformDrag::defaultAction(Qt::DropActions possibleActions, | - | ||||||||||||
| 112 | Qt::KeyboardModifiers modifiers) const | - | ||||||||||||
| 113 | { | - | ||||||||||||
| 114 | #ifdef QDND_DEBUG | - | ||||||||||||
| 115 | qDebug() << "QDragManager::defaultAction(Qt::DropActions possibleActions)\nkeyboard modifiers : " << modifiers; | - | ||||||||||||
| 116 | #endif | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | Qt::DropAction default_action = Qt::IgnoreAction; | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | if (currentDrag()) {
| 0 | ||||||||||||
| 121 | default_action = currentDrag()->defaultAction(); | - | ||||||||||||
| 122 | } never executed: end of block | 0 | ||||||||||||
| 123 | - | |||||||||||||
| 124 | - | |||||||||||||
| 125 | if (default_action == Qt::IgnoreAction) {
| 0 | ||||||||||||
| 126 | //This means that the drag was initiated by QDrag::start and we need to | - | ||||||||||||
| 127 | //preserve the old behavior | - | ||||||||||||
| 128 | default_action = Qt::CopyAction; | - | ||||||||||||
| 129 | } never executed: end of block | 0 | ||||||||||||
| 130 | - | |||||||||||||
| 131 | if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier)
| 0 | ||||||||||||
| 132 | default_action = Qt::LinkAction; never executed: default_action = Qt::LinkAction; | 0 | ||||||||||||
| 133 | else if (modifiers & Qt::ControlModifier)
| 0 | ||||||||||||
| 134 | default_action = Qt::CopyAction; never executed: default_action = Qt::CopyAction; | 0 | ||||||||||||
| 135 | else if (modifiers & Qt::ShiftModifier)
| 0 | ||||||||||||
| 136 | default_action = Qt::MoveAction; never executed: default_action = Qt::MoveAction; | 0 | ||||||||||||
| 137 | else if (modifiers & Qt::AltModifier)
| 0 | ||||||||||||
| 138 | default_action = Qt::LinkAction; never executed: default_action = Qt::LinkAction; | 0 | ||||||||||||
| 139 | - | |||||||||||||
| 140 | #ifdef QDND_DEBUG | - | ||||||||||||
| 141 | qDebug() << "possible actions : " << possibleActions; | - | ||||||||||||
| 142 | #endif | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | // Check if the action determined is allowed | - | ||||||||||||
| 145 | if (!(possibleActions & default_action)) {
| 0 | ||||||||||||
| 146 | if (possibleActions & Qt::CopyAction)
| 0 | ||||||||||||
| 147 | default_action = Qt::CopyAction; never executed: default_action = Qt::CopyAction; | 0 | ||||||||||||
| 148 | else if (possibleActions & Qt::MoveAction)
| 0 | ||||||||||||
| 149 | default_action = Qt::MoveAction; never executed: default_action = Qt::MoveAction; | 0 | ||||||||||||
| 150 | else if (possibleActions & Qt::LinkAction)
| 0 | ||||||||||||
| 151 | default_action = Qt::LinkAction; never executed: default_action = Qt::LinkAction; | 0 | ||||||||||||
| 152 | else | - | ||||||||||||
| 153 | default_action = Qt::IgnoreAction; never executed: default_action = Qt::IgnoreAction; | 0 | ||||||||||||
| 154 | } | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | #ifdef QDND_DEBUG | - | ||||||||||||
| 157 | qDebug() << "default action : " << default_action; | - | ||||||||||||
| 158 | #endif | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | return default_action; never executed: return default_action; | 0 | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | /*! | - | ||||||||||||
| 164 | \brief Cancels the currently active drag (only for drags of | - | ||||||||||||
| 165 | the current application initiated by QPlatformDrag::drag()). | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | The default implementation does nothing. | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | \since 5.6 | - | ||||||||||||
| 170 | */ | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | void QPlatformDrag::cancelDrag() | - | ||||||||||||
| 173 | { | - | ||||||||||||
| 174 | Q_UNIMPLEMENTED(); | - | ||||||||||||
| 175 | } never executed: end of block | 0 | ||||||||||||
| 176 | - | |||||||||||||
| 177 | /*! | - | ||||||||||||
| 178 | \brief Called to notify QDrag about changes of the current action. | - | ||||||||||||
| 179 | */ | - | ||||||||||||
| 180 | - | |||||||||||||
| 181 | void QPlatformDrag::updateAction(Qt::DropAction action) | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | Q_D(QPlatformDrag); | - | ||||||||||||
| 184 | if (d->cursor_drop_action != action) {
| 0 | ||||||||||||
| 185 | d->cursor_drop_action = action; | - | ||||||||||||
| 186 | emit currentDrag()->actionChanged(action); | - | ||||||||||||
| 187 | } never executed: end of block | 0 | ||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||
| 189 | - | |||||||||||||
| 190 | static const char *const default_pm[] = { | - | ||||||||||||
| 191 | "13 9 3 1", | - | ||||||||||||
| 192 | ". c None", | - | ||||||||||||
| 193 | " c #000000", | - | ||||||||||||
| 194 | "X c #FFFFFF", | - | ||||||||||||
| 195 | "X X X X X X X", | - | ||||||||||||
| 196 | " X X X X X X ", | - | ||||||||||||
| 197 | "X ......... X", | - | ||||||||||||
| 198 | " X.........X ", | - | ||||||||||||
| 199 | "X ......... X", | - | ||||||||||||
| 200 | " X.........X ", | - | ||||||||||||
| 201 | "X ......... X", | - | ||||||||||||
| 202 | " X X X X X X ", | - | ||||||||||||
| 203 | "X X X X X X X", | - | ||||||||||||
| 204 | }; | - | ||||||||||||
| 205 | - | |||||||||||||
| 206 | Q_GLOBAL_STATIC_WITH_ARGS(QPixmap,qt_drag_default_pixmap,(default_pm)) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||
| 207 | - | |||||||||||||
| 208 | QPixmap QPlatformDrag::defaultPixmap() | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | return *qt_drag_default_pixmap(); never executed: return *qt_drag_default_pixmap(); | 0 | ||||||||||||
| 211 | } | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | /*! | - | ||||||||||||
| 214 | \since 5.4 | - | ||||||||||||
| 215 | \brief Returns bool indicating whether QPlatformDrag takes ownership | - | ||||||||||||
| 216 | and therefore responsibility of deleting the QDrag object passed in | - | ||||||||||||
| 217 | from QPlatformDrag::drag. This can be useful on platforms where QDrag | - | ||||||||||||
| 218 | object has to be kept around. | - | ||||||||||||
| 219 | */ | - | ||||||||||||
| 220 | bool QPlatformDrag::ownsDragObject() const | - | ||||||||||||
| 221 | { | - | ||||||||||||
| 222 | return false; never executed: return false; | 0 | ||||||||||||
| 223 | } | - | ||||||||||||
| 224 | - | |||||||||||||
| 225 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |