source: trunk/src/qt3support/other/q3dragobject.cpp@ 439

Last change on this file since 439 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 41.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt3Support module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qplatformdefs.h"
43
44#ifndef QT_NO_MIME
45
46#include "q3dragobject.h"
47#include "qpixmap.h"
48#include "qevent.h"
49#include "qfile.h"
50#include "qtextcodec.h"
51#include "qapplication.h"
52#include "qpoint.h"
53#include "qwidget.h"
54#include "qbuffer.h"
55#include "qimagereader.h"
56#include "qimagewriter.h"
57#include "qimage.h"
58#include "qregexp.h"
59#include "qdir.h"
60#include "qdrag.h"
61#include "q3strlist.h"
62#include "q3cstring.h"
63
64#include <private/qobject_p.h>
65
66#include <ctype.h>
67#if defined(Q_OS_WINCE)
68#include <winsock.h>
69#include "qfunctions_wince.h"
70#endif
71
72QT_BEGIN_NAMESPACE
73
74static QWidget *last_target = 0;
75
76class QDragMime;
77
78class Q3DragObjectPrivate : public QObjectPrivate
79{
80 Q_DECLARE_PUBLIC(Q3DragObject)
81public:
82 Q3DragObjectPrivate(): hot(0,0),pm_cursor(0) {}
83 QPixmap pixmap;
84 QPoint hot;
85 // store default cursors
86 QPixmap *pm_cursor;
87};
88
89class Q3TextDragPrivate : public Q3DragObjectPrivate
90{
91 Q_DECLARE_PUBLIC(Q3TextDrag)
92public:
93 Q3TextDragPrivate() { setSubType(QLatin1String("plain")); }
94 void setSubType(const QString & st) {
95 subtype = st;
96 fmt = QString(QLatin1String("text/")).toLatin1() + subtype.toLatin1();
97 }
98
99 QString txt;
100 QString subtype;
101 QByteArray fmt;
102};
103
104class Q3StoredDragPrivate : public Q3DragObjectPrivate
105{
106 Q_DECLARE_PUBLIC(Q3StoredDrag)
107public:
108 Q3StoredDragPrivate() {}
109 const char* fmt;
110 QByteArray enc;
111};
112
113class Q3ImageDragPrivate : public Q3DragObjectPrivate
114{
115 Q_DECLARE_PUBLIC(Q3ImageDrag)
116public:
117 QImage img;
118 QList<QByteArray> ofmts;
119};
120
121class QDragMime : public QMimeData
122{
123public:
124 QDragMime(Q3DragObject *parent) : QMimeData(), dragObject(parent) { }
125 ~QDragMime();
126
127 QByteArray data(const QString &mimetype) const;
128 bool hasFormat(const QString &mimetype) const;
129 QStringList formats() const;
130
131 QPointer<Q3DragObject> dragObject;
132};
133
134QDragMime::~QDragMime()
135{
136 delete dragObject;
137}
138QByteArray QDragMime::data(const QString &mimetype) const
139{
140 return dragObject->encodedData(mimetype.latin1());
141}
142
143bool QDragMime::hasFormat(const QString &mimetype) const
144{
145 return dragObject->provides(mimetype.latin1());
146}
147
148QStringList QDragMime::formats() const
149{
150 int i = 0;
151 const char *format;
152 QStringList f;
153 while ((format = dragObject->format(i))) {
154 f.append(QLatin1String(format));
155 ++i;
156 }
157 return f;
158}
159
160/*!
161 Constructs a drag object called \a name with a parent \a
162 dragSource.
163
164 Note that the drag object will be deleted when the \a dragSource is
165 deleted.
166*/
167
168Q3DragObject::Q3DragObject(QWidget * dragSource, const char * name)
169 : QObject(*(new Q3DragObjectPrivate), dragSource)
170{
171 setObjectName(QLatin1String(name));
172}
173
174/*! \internal */
175Q3DragObject::Q3DragObject(Q3DragObjectPrivate &dd, QWidget *dragSource)
176 : QObject(dd, dragSource)
177{
178}
179
180/*!
181 Destroys the drag object, canceling any drag and drop operation in
182 which it is involved.
183*/
184
185Q3DragObject::~Q3DragObject()
186{
187}
188
189#ifndef QT_NO_DRAGANDDROP