本文整理汇总了C++中QMimeData类的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData类的具体用法?C++ QMimeData怎么用?C++ QMimeData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMimeData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Q_ASSERT
// -------------------------------------------------------------------------------
QMimeData* CCollectionModel::mimeData( const QModelIndexList& indexes ) const
// -------------------------------------------------------------------------------
{
//std::cout<<"CCollectionModel::mimeData()"<<std::endl;
Q_ASSERT( NULLPTR != mpCollection );
if ( !mpCollection )
return NULLPTR;
if ( indexes.isEmpty() )
return NULLPTR;
QModelIndex firstIndex = indexes.first();
if ( !firstIndex.isValid() )
return NULLPTR;
CTreeInformationElement* pTIE = mapIndexToIE( firstIndex );
if ( !pTIE )
return NULLPTR;
QByteArray encodedData;
encodedData.append( mpCollection->toXML( pTIE ).toUtf8() );
debugTrace( "[CCollectionModel::mimeData] encodedData = '" + encodedData + "'" );
//std::cout<<"[DragContent]"<<QString(encodedData).toStdString()<<"[/DragContent]"<<std::endl;
// TODO: Check whether the encoding for umlauts, accents, etc. is correct.
// If not it might be accomplished like this:
//QTextStream t( &encodedData, QIODevice::WriteOnly );
//t.setCodec( "UTF-8" );
//t << mpCollection->toXML( pTIE );
QMimeData* pMimeData = new QMimeData();
pMimeData->setData( TUXCARDS_DRAGDROP_TYPE, encodedData );
return pMimeData;
}
示例2: itemAt
void SeList::mouseMoveEvent(QMouseEvent* e)
{
if ((Mpressed) && ((Mpos - e->pos()).manhattanLength() > 4))
{
Mpressed = false;
QListWidgetItem *item = itemAt(Mpos);
if (!item)
return;
QMimeData *mimeData = new QMimeData;
QString pageName = item->data(Qt::UserRole).toString();
mimeData->setData("page/magic", "1" + pageName.toLocal8Bit());
mimeData->setText("1" + pageName);
QDrag *dr = new QDrag(this);
dr->setMimeData(mimeData);
const QPixmap& pm = IconManager::instance()->loadPixmap("doc.png");
dr->setPixmap(pm);
// dr->setDragCursor(pm, Qt::CopyAction);
// dr->setDragCursor(pm, Qt::MoveAction);
dr->exec(Qt::CopyAction | Qt::MoveAction);
QApplication::setOverrideCursor(Qt::ArrowCursor);
}
}
示例3: cloneData
QVariantMap cloneData(const QMimeData &data)
{
QStringList formats;
for ( const auto &mime : data.formats() ) {
// ignore uppercase mimetypes (e.g. UTF8_STRING, TARGETS, TIMESTAMP)
// and internal type to check clipboard owner
if ( !mime.isEmpty() && mime[0].isLower() )
formats.append(mime);
}
return cloneData(data, formats);
}
示例4: foreach
//virtual
QMimeData * EffectsListWidget::mimeData(const QList<QTreeWidgetItem *> list) const
{
QDomDocument doc;
bool transitionMode = false;
foreach(QTreeWidgetItem *item, list) {
if (item->flags() & Qt::ItemIsDragEnabled) {
int type = item->data(0, TypeRole).toInt();
if (type == EffectsList::TRANSITION_TYPE) {
transitionMode = true;
}
QStringList info = item->data(0, IdRole).toStringList();
const QDomElement e = itemEffect(type, info);
if (!e.isNull())
doc.appendChild(doc.importNode(e, true));
}
}
QMimeData *mime = new QMimeData;
QByteArray data;
data.append(doc.toString().toUtf8());
mime->setData(transitionMode ? "kdenlive/transitionslist" : "kdenlive/effectslist", data);
return mime;
}
示例5: dataStream
void DummyBlock::mousePressEvent(QMouseEvent *event)
{
cout << "Starting Drag" << endl;
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << QPoint(event->pos());
QMimeData *mimeData = new QMimeData;
mimeData->setData("application/x-dnditemdata", itemData);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setHotSpot(event->pos());
drag->setPixmap(this->grab());
if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction)
{
// this->close();
}
}
示例6: QMimeData
QMimeData *TableModelAnovaWithinSubjectCells::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream dataStream(&encodedData, QIODevice::WriteOnly);
dataStream << indexes.length();
foreach (const QModelIndex &index, indexes)
{
if (index.isValid())
{
Term term = _variables.at(index.row());
dataStream << term.asQString();
}
}
mimeData->setData("application/vnd.list.variable", encodedData);
return mimeData;
}
示例7: QByteArray
QMimeData* BasketTreeListView::mimeData(const QList<QTreeWidgetItem *> items) const
{
QString mimeType = TREE_ITEM_MIME_STRING;
QByteArray data = QByteArray();
QDataStream out(&data, QIODevice::WriteOnly);
if(items.isEmpty())
return new QMimeData();
for (int i = 0; i < items.count(); ++i) {
BasketListViewItem *basketItem = static_cast<BasketListViewItem*>(items[i]);
out << basketItem->basket()->basketName() << basketItem->basket()->folderName()
<< basketItem->basket()->icon();
}
QMimeData *mimeData = new QMimeData();
mimeData->setData(mimeType, data);
return mimeData;
}
示例8: testCut
void KIOPasteTest::testCut()
{
QMimeData *mimeData = new QMimeData;
QUrl localURL1(QStringLiteral("file:///tmp/Mat%C3%A9riel"));
QUrl localURL2(QStringLiteral("file:///tmp"));
QList<QUrl> localURLs; localURLs << localURL1 << localURL2;
KUrlMimeData::setUrls(QList<QUrl>(), localURLs, mimeData);
KIO::setClipboardDataCut(mimeData, true);
QVERIFY(mimeData->hasUrls());
const QList<QUrl> lst = KUrlMimeData::urlsFromMimeData(mimeData);
QCOMPARE(lst.count(), 2);
QCOMPARE(lst[0].url(), localURL1.url());
QCOMPARE(lst[1].url(), localURL2.url());
const bool isCut = KIO::isClipboardDataCut(mimeData);
QVERIFY(isCut);
delete mimeData;
}
示例9: QDrag
void QtRosterWidget::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton)) {
return;
}
if ((event->pos() - dragStartPosition).manhattanLength()< QApplication::startDragDistance()) {
return;
}
clickedIndex=indexAt(event->pos());
if (!clickedIndex.isValid()) {
return;
}
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData();
RosterItem* item = static_cast<RosterItem*>(clickedIndex.internalPointer());
ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
std::string jid=contact->getJID().toString();
QString str=QString::P2QSTRING(jid);
mimeData->setText(str);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction | Qt::MoveAction);
}
示例10: mousePressEvent
void DragableLabel::mousePressEvent(QMouseEvent *event)
{
QPoint hotSpot = event->pos();
QMimeData *mimeData = new QMimeData;
mimeData->setText(this->text());
mimeData->setData("application/x-hotspot",
QByteArray::number(hotSpot.x()) + " " + QByteArray::number(hotSpot.y()));
QPixmap pixmap(this->size());
this->render(&pixmap);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
drag->setHotSpot(hotSpot);
Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
if (dropAction == Qt::MoveAction)
this->close();
}
示例11: testPopulate
void KIOPasteTest::testPopulate()
{
QMimeData *mimeData = new QMimeData;
// Those URLs don't have to exist.
QUrl mediaURL(QStringLiteral("media:/hda1/tmp/Mat%C3%A9riel"));
QUrl localURL(QStringLiteral("file:///tmp/Mat%C3%A9riel"));
QList<QUrl> kdeURLs; kdeURLs << mediaURL;
QList<QUrl> mostLocalURLs; mostLocalURLs << localURL;
KUrlMimeData::setUrls(kdeURLs, mostLocalURLs, mimeData);
QVERIFY(mimeData->hasUrls());
const QList<QUrl> lst = KUrlMimeData::urlsFromMimeData(mimeData);
QCOMPARE(lst.count(), 1);
QCOMPARE(lst[0].url(), mediaURL.url());
const bool isCut = KIO::isClipboardDataCut(mimeData);
QVERIFY(!isCut);
delete mimeData;
}
示例12: lock
QMimeData* DisplayModel::mimeData(const QModelIndexList& indexes) const
{
DatabaseLocker lock(db_);
QMimeData *mimeData = new QMimeData();
QList<QUrl> list;
for (const QModelIndex &index: indexes)
{
if (index.isValid())
{
QStandardItem* qitem = this->itemFromIndex(index);
file_hash_t hash = qitem->data(IMAGE_QVARIANT_ROLE).value<file_hash_t>();
ImageDescription_ptr desc = db_->images().get_image_description(hash);
list << QUrl("file:///" + db_->images().storage_location() + "/" + desc->path);
}
}
mimeData->setUrls(list);
return mimeData;
}
示例13: QMimeData
QMimeData *StatsListModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
int ind = data(index, Qt::UserRole).toInt();
int alpha = data(index, Qt::UserRole+1).toInt();
QModelIndex checkindex = StatsListModel::createIndex(index.row(), 1, 999);
bool draw = data(checkindex, Qt::CheckStateRole).toBool();
bool drawgrid = data(index, Qt::UserRole+2).toBool();
QString name = data(index, Qt::DisplayRole).toString();
stream << ind << alpha << draw << drawgrid << name;
}
}
mimeData->setData("application/YUView-Statistics", encodedData);
return mimeData;
}
示例14: QMimeData
QMimeData *BookmarksModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly);
QList<QUrl> urls;
foreach (const QModelIndex &index, indexes) {
if (index.column() != 0 || !index.isValid())
continue;
QByteArray encodedData;
QBuffer buffer(&encodedData);
buffer.open(QBuffer::ReadWrite);
XbelWriter writer;
const BookmarkNode *parentNode = node(index);
writer.write(&buffer, parentNode);
stream << encodedData;
urls.append(index.data(BookmarksModel::UrlRole).toUrl());
}
mimeData->setData(MIMETYPE, data);
mimeData->setUrls(urls);
return mimeData;
}
示例15: QMimeData
QMimeData *GraphModel::mimeData(const QModelIndexList &indexes) const
{
if(QApplication::keyboardModifiers() & Qt::ShiftModifier)
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (const QModelIndex &index, indexes)
{
if (index.isValid())
{
GraphItem *item = static_cast<GraphItem *>(index.internalPointer());
QVariant uData = PointerHolder<GraphItem *>::ToQVariant(item);
stream << uData;
}
}
mimeData->setData("application/tree.userdata", encodedData);
return mimeData;
}