| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qapplication.h"
|
|---|
| 43 |
|
|---|
| 44 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 45 |
|
|---|
| 46 | #include "qwidget.h"
|
|---|
| 47 | #include "qdatetime.h"
|
|---|
| 48 | #include "qbitmap.h"
|
|---|
| 49 | #include "qcursor.h"
|
|---|
| 50 | #include "qevent.h"
|
|---|
| 51 | #include "qpainter.h"
|
|---|
| 52 | #include "qdnd_p.h"
|
|---|
| 53 |
|
|---|
| 54 | QT_BEGIN_NAMESPACE
|
|---|
| 55 |
|
|---|
| 56 | QT_USE_NAMESPACE
|
|---|
| 57 |
|
|---|
| 58 | static QPixmap *defaultPm = 0;
|
|---|
| 59 | static const int default_pm_hotx = -2;
|
|---|
| 60 | static const int default_pm_hoty = -16;
|
|---|
| 61 | static const char *const default_pm[] = {
|
|---|
| 62 | "13 9 3 1",
|
|---|
| 63 | ". c None",
|
|---|
| 64 | " c #000000",
|
|---|
| 65 | "X c #FFFFFF",
|
|---|
| 66 | "X X X X X X X",
|
|---|
| 67 | " X X X X X X ",
|
|---|
| 68 | "X ......... X",
|
|---|
| 69 | " X.........X ",
|
|---|
| 70 | "X ......... X",
|
|---|
| 71 | " X.........X ",
|
|---|
| 72 | "X ......... X",
|
|---|
| 73 | " X X X X X X ",
|
|---|
| 74 | "X X X X X X X",
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | // Shift/Ctrl handling, and final drop status
|
|---|
| 78 | static Qt::DropAction global_accepted_action = Qt::CopyAction;
|
|---|
| 79 | static Qt::DropActions possible_actions = Qt::IgnoreAction;
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | // static variables in place of a proper cross-process solution
|
|---|
| 83 | static QDrag *drag_object;
|
|---|
| 84 | static bool qt_qws_dnd_dragging = false;
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | static Qt::KeyboardModifiers oldstate;
|
|---|
| 88 |
|
|---|
| 89 | class QShapedPixmapWidget : public QWidget {
|
|---|
| 90 | QPixmap pixmap;
|
|---|
| 91 | public:
|
|---|
| 92 | QShapedPixmapWidget() :
|
|---|
| 93 | QWidget(0, Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint)
|
|---|
| 94 | {
|
|---|
| 95 | // ### Temporary workaround for 4.2-rc1!!! To prevent flickering when
|
|---|
| 96 | // using drag'n drop in a client application. (task 126956)
|
|---|
| 97 | // setAttribute() should be done unconditionally!
|
|---|
| 98 | if (QApplication::type() == QApplication::GuiServer)
|
|---|
| 99 | setAttribute(Qt::WA_TransparentForMouseEvents);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | void setPixmap(QPixmap pm)
|
|---|
| 103 | {
|
|---|
| 104 | pixmap = pm;
|
|---|
| 105 | if (!pixmap.mask().isNull()) {
|
|---|
| 106 | setMask(pixmap.mask());
|
|---|
| 107 | } else {
|
|---|
| 108 | clearMask();
|
|---|
| 109 | }
|
|---|
| 110 | resize(pm.width(),pm.height());
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | void paintEvent(QPaintEvent*)
|
|---|
| 114 | {
|
|---|
| 115 | QPainter p(this);
|
|---|
| 116 | p.drawPixmap(0,0,pixmap);
|
|---|
| 117 | }
|
|---|
| 118 | };
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | static QShapedPixmapWidget *qt_qws_dnd_deco = 0;
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | void QDragManager::updatePixmap()
|
|---|
| 125 | {
|
|---|
| 126 | if (qt_qws_dnd_deco) {
|
|---|
| 127 | QPixmap pm;
|
|---|
| 128 | QPoint pm_hot(default_pm_hotx,default_pm_hoty);
|
|---|
| 129 | if (drag_object) {
|
|---|
| 130 | pm = drag_object->pixmap();
|
|---|
| 131 | if (!pm.isNull())
|
|---|
| 132 | pm_hot = drag_object->hotSpot();
|
|---|
| 133 | }
|
|---|
| 134 | if (pm.isNull()) {
|
|---|
| 135 | if (!defaultPm)
|
|---|
| 136 | defaultPm = new QPixmap(default_pm);
|
|---|
| 137 | pm = *defaultPm;
|
|---|
| 138 | }
|
|---|
| 139 | qt_qws_dnd_deco->setPixmap(pm);
|
|---|
| 140 | qt_qws_dnd_deco->move(QCursor::pos()-pm_hot);
|
|---|
| 141 | if (willDrop) {
|
|---|
| 142 | qt_qws_dnd_deco->show();
|
|---|
| 143 | } else {
|
|---|
| 144 | qt_qws_dnd_deco->hide();
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | void QDragManager::timerEvent(QTimerEvent *) { }
|
|---|
| 150 |
|
|---|
| 151 | void QDragManager::move(const QPoint &) { }
|
|---|
| 152 |
|
|---|
| 153 | void QDragManager::updateCursor()
|
|---|
| 154 | {
|
|---|
| 155 | #ifndef QT_NO_CURSOR
|
|---|
| 156 | if (willDrop) {
|
|---|
| 157 | if (qt_qws_dnd_deco)
|
|---|
| 158 | qt_qws_dnd_deco->show();
|
|---|
| 159 | if (currentActionForOverrideCursor != global_accepted_action) {
|
|---|
| 160 | QApplication::changeOverrideCursor(QCursor(dragCursor(global_accepted_action), 0, 0));
|
|---|
| 161 | currentActionForOverrideCursor = global_accepted_action;
|
|---|
| 162 | }
|
|---|
| 163 | } else {
|
|---|
| 164 | QCursor *overrideCursor = QApplication::overrideCursor();
|
|---|
|
|---|