2
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
3
Original author: Gregory Schlomoff <greg@betterinbox.com>
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
3
Original author: Gregory Schlomoff <greg@betterinbox.com>
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
24
#include "DeclarativeMimeData.h"
27
\qmlclass MimeData DeclarativeMimeData
27
\qmlclass MimeData DeclarativeMimeData
29
This is a wrapper class around QMimeData, with a few extensions to provide better support for in-qml drag & drops.
29
This is a wrapper class around QMimeData, with a few extensions to provide better support for in-qml drag & drops.
34
\class DeclarativeMimeData
36
Creates a new DeclarativeMimeData by cloning the QMimeData passed as parameter.
37
This is useful for two reasons :
38
- In DragArea, we want to clone our "working copy" of the DeclarativeMimeData instance, as Qt will automatically
39
delete it after the drag and drop operation.
40
- In the drop events, the QMimeData is const, and we have troubles passing const to QML. So we clone it to
41
remove the "constness"
43
This method will try to cast the QMimeData to DeclarativeMimeData, and will clone our extensions to QMimeData as well
34
\class DeclarativeMimeData
36
Creates a new DeclarativeMimeData by cloning the QMimeData passed as parameter.
37
This is useful for two reasons :
38
- In DragArea, we want to clone our "working copy" of the DeclarativeMimeData instance, as Qt will automatically
39
delete it after the drag and drop operation.
40
- In the drop events, the QMimeData is const, and we have troubles passing const to QML. So we clone it to
41
remove the "constness"
43
This method will try to cast the QMimeData to DeclarativeMimeData, and will clone our extensions to QMimeData as well
45
45
DeclarativeMimeData::DeclarativeMimeData(const QMimeData* copy)
49
// Copy the standard MIME data
50
foreach(QString format, copy->formats()) {
51
this->setData(format, copy->data(format));
49
// Copy the standard MIME data
50
foreach(QString format, copy->formats()) {
51
this->setData(format, copy->data(format));
54
// If the object we are copying actually is a DeclarativeMimeData, copy our extended properties as well
55
const DeclarativeMimeData* declarativeMimeData = qobject_cast<const DeclarativeMimeData*>(copy);
56
if (declarativeMimeData) {
57
this->setSource(declarativeMimeData->source());
54
// If the object we are copying actually is a DeclarativeMimeData, copy our extended properties as well
55
const DeclarativeMimeData* declarativeMimeData = qobject_cast<const DeclarativeMimeData*>(copy);
56
if (declarativeMimeData) {
57
this->setSource(declarativeMimeData->source());
63
\qmlproperty url MimeData::url
63
\qmlproperty url MimeData::url
65
Returns the first URL from the urls property of QMimeData
66
TODO: We should use QDeclarativeListProperty<QUrls> to return the whole list instead of only the first element.
65
Returns the first URL from the urls property of QMimeData
66
TODO: We should use QDeclarativeListProperty<QUrls> to return the whole list instead of only the first element.
68
68
QUrl DeclarativeMimeData::url() const
70
if ( this->hasUrls() && !this->urls().isEmpty()) {
71
return QMimeData::urls().first();
70
if ( this->hasUrls() && !this->urls().isEmpty()) {
71
return QMimeData::urls().first();
75
75
void DeclarativeMimeData::setUrl(const QUrl &url)
77
if (this->url() == url)
77
if (this->url() == url)
82
QMimeData::setUrls(urlList);
82
QMimeData::setUrls(urlList);
86
86
QVariantList DeclarativeMimeData::urls() const