• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

DragAndDrop

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • draganddrop
DeclarativeMimeData.cpp
Go to the documentation of this file.
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.
22 */
23 
24 #include "DeclarativeMimeData.h"
25 
45 DeclarativeMimeData::DeclarativeMimeData(const QMimeData* copy)
46  : QMimeData(),
47  m_source(0)
48 {
49  // Copy the standard MIME data
50  foreach(QString format, copy->formats()) {
51  QMimeData::setData(format, copy->data(format));
52  }
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  }
59 }
60 
61 
68 QUrl DeclarativeMimeData::url() const
69 {
70  if ( this->hasUrls() && !this->urls().isEmpty()) {
71  return QMimeData::urls().first();
72  }
73  return QUrl();
74 }
75 void DeclarativeMimeData::setUrl(const QUrl &url)
76 {
77  if (this->url() == url)
78  return;
79 
80  QList<QUrl> urlList;
81  urlList.append(url);
82  QMimeData::setUrls(urlList);
83  emit urlChanged();
84 }
85 
86 QVariantList DeclarativeMimeData::urls() const
87 {
88  QVariantList varUrls;
89  foreach (const QUrl &url, QMimeData::urls()) {
90  varUrls << url;
91  }
92  return varUrls;
93 }
94 
95 void DeclarativeMimeData::setUrls(const QVariantList &urls)
96 {
97  QList<QUrl> urlList;
98  foreach (const QVariant &varUrl, urls) {
99  urlList << varUrl.value<QUrl>();
100  }
101  QMimeData::setUrls(urlList);
102  emit urlsChanged();
103 }
104 
105 // color
106 QColor DeclarativeMimeData::color() const
107 {
108  if ( this->hasColor()) {
109  return qvariant_cast<QColor>(this->colorData());
110  }
111  return QColor();
112 }
113 void DeclarativeMimeData::setColor(const QColor &color)
114 {
115  if (this->color() != color) {
116  this->setColorData(color);
117  emit colorChanged();
118  }
119 }
120 
121 void DeclarativeMimeData::setData(const QString &mimeType, const QVariant &data)
122 {
123  if (data.type() == QVariant::ByteArray) {
124  QMimeData::setData(mimeType, data.toByteArray());
125  } else if (data.canConvert(QVariant::String)) {
126  QMimeData::setData(mimeType, data.toString().toLatin1());
127  }
128 }
129 
139 QDeclarativeItem* DeclarativeMimeData::source() const
140 {
141  return m_source;
142 }
143 void DeclarativeMimeData::setSource(QDeclarativeItem* source)
144 {
145  if (m_source != source) {
146  m_source = source;
147  emit sourceChanged();
148  }
149 }
QVariant::canConvert
bool canConvert(Type t) const
QVariant::toByteArray
QByteArray toByteArray() const
QMimeData::data
QByteArray data(const QString &mimeType) const
DeclarativeMimeData::setUrl
void setUrl(const QUrl &url)
Definition: DeclarativeMimeData.cpp:75
QMimeData::setColorData
void setColorData(const QVariant &color)
QVariant::value
T value() const
DeclarativeMimeData::source
QDeclarativeItem * source() const
DeclarativeMimeData::url
QUrl url() const
QMimeData
DeclarativeMimeData::urlChanged
void urlChanged()
DeclarativeMimeData::DeclarativeMimeData
DeclarativeMimeData()
Definition: DeclarativeMimeData.h:69
DeclarativeMimeData::sourceChanged
void sourceChanged()
QList::append
void append(const T &value)
DeclarativeMimeData.h
DeclarativeMimeData::urls
QVariantList urls() const
DeclarativeMimeData::colorChanged
void colorChanged()
QString
QList
QColor
DeclarativeMimeData::source
QDeclarativeItem source
The graphical item on the scene that started the drag event.
Definition: DeclarativeMimeData.h:65
DeclarativeMimeData::setColor
void setColor(const QColor &color)
Definition: DeclarativeMimeData.cpp:113
QMimeData::colorData
QVariant colorData() const
DeclarativeMimeData::setUrls
void setUrls(const QVariantList &urls)
Definition: DeclarativeMimeData.cpp:95
QUrl
DeclarativeMimeData::color
QColor color() const
DeclarativeMimeData::setSource
void setSource(QDeclarativeItem *source)
Definition: DeclarativeMimeData.cpp:143
DeclarativeMimeData
Definition: DeclarativeMimeData.h:32
QString::toLatin1
QByteArray toLatin1() const
QMimeData::hasUrls
bool hasUrls() const
QMimeData::urls
QList< QUrl > urls() const
QMimeData::formats
virtual QStringList formats() const
QDeclarativeItem
QMimeData::setData
void setData(const QString &mimeType, const QByteArray &data)
QVariant::type
Type type() const
DeclarativeMimeData::setData
Q_INVOKABLE void setData(const QString &mimeType, const QVariant &data)
Definition: DeclarativeMimeData.cpp:121
QVariant::toString
QString toString() const
DeclarativeMimeData::urlsChanged
void urlsChanged()
QMimeData::setUrls
void setUrls(const QList< QUrl > &urls)
QMimeData::hasColor
bool hasColor() const
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:31 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

DragAndDrop

Skip menu "DragAndDrop"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal