~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to plasma/declarativeimports/draganddrop/DeclarativeMimeData.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
        Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
3
 
        Original author: Gregory Schlomoff <greg@betterinbox.com>
4
 
 
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:
11
 
 
12
 
        The above copyright notice and this permission notice shall be included in
13
 
        all copies or substantial portions of the Software.
14
 
 
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
21
 
        THE SOFTWARE.
 
2
    Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
 
3
    Original author: Gregory Schlomoff <greg@betterinbox.com>
 
4
 
 
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:
 
11
 
 
12
    The above copyright notice and this permission notice shall be included in
 
13
    all copies or substantial portions of the Software.
 
14
 
 
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
 
21
    THE SOFTWARE.
22
22
*/
23
23
 
24
24
#include "DeclarativeMimeData.h"
25
25
 
26
26
/*!
27
 
        \qmlclass MimeData DeclarativeMimeData
 
27
    \qmlclass MimeData DeclarativeMimeData
28
28
 
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.
30
30
*/
31
31
 
32
32
/*!
33
 
        \internal
34
 
        \class DeclarativeMimeData
35
 
 
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"
42
 
 
43
 
        This method will try to cast the QMimeData to DeclarativeMimeData, and will clone our extensions to QMimeData as well
 
33
    \internal
 
34
    \class DeclarativeMimeData
 
35
 
 
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"
 
42
 
 
43
    This method will try to cast the QMimeData to DeclarativeMimeData, and will clone our extensions to QMimeData as well
44
44
*/
45
45
DeclarativeMimeData::DeclarativeMimeData(const QMimeData* copy)
46
 
        : QMimeData(),
47
 
        m_source(0)
 
46
    : QMimeData(),
 
47
    m_source(0)
48
48
{
49
 
        // Copy the standard MIME data
50
 
        foreach(QString format, copy->formats()) {
51
 
                        this->setData(format, copy->data(format));
52
 
        }
 
49
    // Copy the standard MIME data
 
50
    foreach(QString format, copy->formats()) {
 
51
            this->setData(format, copy->data(format));
 
52
    }
53
53
 
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());
58
 
        }
 
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());
 
58
    }
59
59
}
60
60
 
61
61
 
62
62
/*!
63
 
        \qmlproperty url MimeData::url
 
63
    \qmlproperty url MimeData::url
64
64
 
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.
67
67
*/
68
68
QUrl DeclarativeMimeData::url() const
69
69
{
70
 
        if ( this->hasUrls() && !this->urls().isEmpty()) {
71
 
                return QMimeData::urls().first();
72
 
         }
73
 
        return QUrl();
 
70
    if ( this->hasUrls() && !this->urls().isEmpty()) {
 
71
        return QMimeData::urls().first();
 
72
     }
 
73
    return QUrl();
74
74
}
75
75
void DeclarativeMimeData::setUrl(const QUrl &url)
76
76
{
77
 
        if (this->url() == url)
78
 
                return;
 
77
    if (this->url() == url)
 
78
        return;
79
79
 
80
 
        QList<QUrl> urlList;
81
 
        urlList.append(url);
82
 
        QMimeData::setUrls(urlList);
83
 
        emit urlChanged();
 
80
    QList<QUrl> urlList;
 
81
    urlList.append(url);
 
82
    QMimeData::setUrls(urlList);
 
83
    emit urlChanged();
84
84
}
85
85
 
86
86
QVariantList DeclarativeMimeData::urls() const
105
105
// color
106
106
QColor DeclarativeMimeData::color() const
107
107
{
108
 
        if ( this->hasColor()) {
109
 
                 return qvariant_cast<QColor>(this->colorData());
110
 
         }
111
 
        return QColor();
 
108
    if ( this->hasColor()) {
 
109
         return qvariant_cast<QColor>(this->colorData());
 
110
     }
 
111
    return QColor();
112
112
}
113
113
void DeclarativeMimeData::setColor(const QColor &color)
114
114
{
115
 
        if (this->color() != color) {
116
 
                this->setColorData(color);
117
 
                emit colorChanged();
118
 
        }
 
115
    if (this->color() != color) {
 
116
        this->setColorData(color);
 
117
        emit colorChanged();
 
118
    }
 
119
}
 
120
 
 
121
void DeclarativeMimeData::setData(const QString &mimeType, const QString &data)
 
122
{
 
123
    QMimeData::setData(mimeType, data.toLatin1());
119
124
}
120
125
 
121
126
/*!
129
134
*/
130
135
QDeclarativeItem* DeclarativeMimeData::source() const
131
136
{
132
 
        return m_source;
 
137
    return m_source;
133
138
}
134
139
void DeclarativeMimeData::setSource(QDeclarativeItem* source)
135
140
{
136
 
        if (m_source != source) {
137
 
                m_source = source;
138
 
                emit sourceChanged();
139
 
        }
 
141
    if (m_source != source) {
 
142
        m_source = source;
 
143
        emit sourceChanged();
 
144
    }
140
145
}