本文整理汇总了C++中QMimeData::setUrls方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData::setUrls方法的具体用法?C++ QMimeData::setUrls怎么用?C++ QMimeData::setUrls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeData
的用法示例。
在下文中一共展示了QMimeData::setUrls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setUrls
void tst_QMimeData::setUrls() const
{
QMimeData mimeData;
QList<QUrl> shortUrlList;
QList<QUrl> longUrlList;
// set up
shortUrlList += QUrl("http://qt-project.org");
longUrlList = shortUrlList;
longUrlList += QUrl("http://www.google.com");
// verify initial state
QCOMPARE(mimeData.hasUrls(), false);
// set a few, verify
mimeData.setUrls(shortUrlList);
QCOMPARE(mimeData.urls(), shortUrlList);
QCOMPARE(mimeData.text(), QString("http://qt-project.org"));
// change them, verify
mimeData.setUrls(longUrlList);
QCOMPARE(mimeData.urls(), longUrlList);
QCOMPARE(mimeData.text(), QString("http://qt-project.org\nhttp://www.google.com\n"));
// clear, verify
mimeData.clear();
QCOMPARE(mimeData.hasUrls(), false);
QCOMPARE(mimeData.hasText(), false);
}
示例2: mouseMoveEvent
void task_list::mouseMoveEvent(QMouseEvent *event)
{
// if not left button - return
if (!(event->buttons() & Qt::LeftButton)) return;
// if no item selected, return (else it would crash)
if (currentItem() == NULL) return;
if(currentItem()->type()==0)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
list.append(QUrl(this->currentItem()->text(0)));
list.append(QUrl(this->currentItem()->text(1)));
list.append(QUrl(this->currentItem()->text(2)));
list.append(QUrl(this->currentItem()->text(3)));
list.append(QUrl(this->currentItem()->text(4)));
// mime stuff
mimeData->setUrls(list);
drag->setMimeData(mimeData);
// start drag
drag->start(Qt::CopyAction | Qt::MoveAction);
}
if(currentItem()->type()==1)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
list.append(QUrl(this->currentItem()->text(0)));
list.append(QUrl(this->currentItem()->text(1)));
list.append(QUrl(this->currentItem()->text(2)));
list.append(QUrl(this->currentItem()->text(3)));
list.append(QUrl(this->currentItem()->text(4)));
// mime stuff
mimeData->setUrls(list);
drag->setMimeData(mimeData);
// start drag
drag->start( Qt::CopyAction | Qt::MoveAction);
}
}
示例3: mouseMoveEvent
void PlayListView::mouseMoveEvent(QMouseEvent *event){
//
// if not left button - return
if (!(event->buttons() & Qt::LeftButton)) return;
// if no item selected, return (else it would crash)
if (currentItem() == NULL) return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
QString line;
line = currentItem()->text(0); // 0 == first Column of QTreeWidgetItem
list.append( QUrl(line) ); // only QUrl in list will be text of actual item
// mime stuff
mimeData->setUrls(list);
//mimeData->setData( line.toUtf8(), "text/uri-list" );
drag->setMimeData(mimeData);
RG_DEBUG << "Starting drag from PlayListView::mouseMoveEvent() with mime : " << mimeData->formats() << " - " << mimeData->urls()[0] << endl;
// start drag
drag->start(Qt::CopyAction | Qt::MoveAction);
}
示例4: startDragDrop
void StudioPaletteTreeViewer::startDragDrop() {
TRepetitionGuard guard;
if (!guard.hasLock()) return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QList<QUrl> urls;
QList<QTreeWidgetItem *> items = selectedItems();
int i;
for (i = 0; i < items.size(); i++) {
// Sposto solo le palette.
TFilePath path = getItemPath(items[i]);
if (!path.isEmpty() &&
(path.getType() == "tpl" || path.getType() == "pli" ||
path.getType() == "tlv" || path.getType() == "tnz"))
urls.append(pathToUrl(path));
}
if (urls.isEmpty()) return;
mimeData->setUrls(urls);
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
viewport()->update();
}
示例5: copyItem
// Copy/cut current file item(s) to clipboard.
void qtractorFileListView::copyItem ( bool bCut )
{
// Build URL list...
QList<QUrl> urls;
int iUpdate = 0;
QList<QTreeWidgetItem *> items = selectedItems();
QListIterator<QTreeWidgetItem *> iter(items);
while (iter.hasNext()) {
QTreeWidgetItem *pItem = iter.next();
if (pItem->type() == qtractorFileListView::FileItem) {
qtractorFileListItem *pFileItem
= static_cast<qtractorFileListItem *> (pItem);
if (pFileItem) {
urls.append(QUrl::fromLocalFile(pFileItem->path()));
if (bCut) {
delete pFileItem;
++iUpdate;
}
}
}
}
// Copy it to system clipboard...
if (!urls.isEmpty()) {
QMimeData *pMimeData = new QMimeData();
pMimeData->setUrls(urls);
QApplication::clipboard()->setMimeData(pMimeData);
}
// Make proper notifications...
if (iUpdate > 0)
emit contentsChanged();
}
示例6: testPasteActionText
void KIOPasteTest::testPasteActionText()
{
QFETCH(QList<QUrl>, urls);
QFETCH(bool, data);
QFETCH(bool, expectedEnabled);
QFETCH(QString, expectedText);
QMimeData mimeData;
if (!urls.isEmpty()) {
mimeData.setUrls(urls);
}
if (data) {
mimeData.setText(QStringLiteral("foo"));
}
QCOMPARE(KIO::canPasteMimeData(&mimeData), expectedEnabled);
bool canPaste;
KFileItem destItem(QUrl::fromLocalFile(QDir::homePath()));
QCOMPARE(KIO::pasteActionText(&mimeData, &canPaste, destItem), expectedText);
QCOMPARE(canPaste, expectedEnabled);
KFileItem nonWritableDestItem(QUrl::fromLocalFile(QStringLiteral("/nonwritable")));
QCOMPARE(KIO::pasteActionText(&mimeData, &canPaste, nonWritableDestItem), expectedText);
QCOMPARE(canPaste, false);
KFileItem emptyUrlDestItem = KFileItem(QUrl());
QCOMPARE(KIO::pasteActionText(&mimeData, &canPaste, emptyUrlDestItem), expectedText);
QCOMPARE(canPaste, false);
KFileItem nullDestItem;
QCOMPARE(KIO::pasteActionText(&mimeData, &canPaste, nullDestItem), expectedText);
QCOMPARE(canPaste, false);
}
示例7: mouseMoveEvent
void SiteIcon::mouseMoveEvent(QMouseEvent* e)
{
if (!m_locationBar || !(e->buttons() & Qt::LeftButton)) {
ToolButton::mouseMoveEvent(e);
return;
}
int manhattanLength = (e->pos() - m_dragStartPosition).manhattanLength();
if (manhattanLength <= QApplication::startDragDistance()) {
ToolButton::mouseMoveEvent(e);
return;
}
const QUrl url = m_locationBar->webView()->url();
const QString title = m_locationBar->webView()->title();
if (url.isEmpty() || title.isEmpty()) {
ToolButton::mouseMoveEvent(e);
return;
}
QDrag* drag = new QDrag(this);
QMimeData* mime = new QMimeData;
mime->setUrls(QList<QUrl>() << url);
mime->setText(title);
mime->setImageData(icon().pixmap(16, 16).toImage());
drag->setMimeData(mime);
drag->setPixmap(QzTools::createPixmapForSite(icon(), title, url.toString()));
drag->exec();
}
示例8: mouseMoveEvent
void BookmarksToolBar::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton)) {
QToolBar::mouseMoveEvent(event);
return;
}
if ((event->pos() - m_dragStartPosition).manhattanLength()
< QApplication::startDragDistance()) {
QToolBar::mouseMoveEvent(event);
return;
}
QAction *action = actionAt(m_dragStartPosition);
QModelIndex index = this->index(action);
if (!index.isValid()) {
QToolBar::mouseMoveEvent(event);
return;
}
QString title = index.data().toString();
QUrl url = index.data(BookmarksModel::UrlRole).toUrl();
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData();
mimeData->setText(title);
mimeData->setUrls(QList<QUrl>() << url);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
示例9: dropMimeData
bool PlaylistModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
// Internal reorder
if (action == Qt::MoveAction) {
m_dropRow = row;
return true;
}
// Dragged from player or file manager
else if (data->hasFormat("application/mlt+xml") || data->hasUrls()) {
emit dropped(data, row);
return true;
}
// Dragged from Recent dock
else if (data->hasFormat("application/x-qabstractitemmodeldatalist")) {
QByteArray encoded = data->data("application/x-qabstractitemmodeldatalist");
QDataStream stream(&encoded, QIODevice::ReadOnly);
QMap<int, QVariant> roleDataMap;
while (!stream.atEnd()) {
int row, col;
stream >> row >> col >> roleDataMap;
}
if (roleDataMap.contains(Qt::ToolTipRole)) {
QMimeData *mimeData = new QMimeData;
QList<QUrl> urls;
// DisplayRole is just basename, ToolTipRole contains full path
urls.append(roleDataMap[Qt::ToolTipRole].toUrl());
mimeData->setUrls(urls);
emit dropped(mimeData, row);
return true;
}
}
示例10: mousePressEvent
void CTreeView::mousePressEvent(QMouseEvent *event)
{
// if not left button - return
QTreeView::mousePressEvent(event);
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
// if no item selected, return (else it would crash)
QModelIndex index = currentIndex();
if (index.isValid() == false)
{
return;
}
if (index.parent().isValid() == false)
{
return;
}
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
list.push_back(index.parent().child(index.row(), 0).data().toUrl());
list.push_back(index.parent().child(index.row(), 1).data().toUrl());
// mime stuff
mimeData->setUrls(list);
mimeData->setText("Item");
drag->setMimeData(mimeData);
// start drag
drag->start(Qt::CopyAction | Qt::MoveAction);
}
示例11: mimeData
QMimeData* BrowseTableModel::mimeData(const QModelIndexList &indexes) const {
QMimeData *mimeData = new QMimeData();
QList<QUrl> urls;
// Ok, so the list of indexes we're given contains separates indexes for
// each column, so even if only one row is selected, we'll have like 7
// indexes. We need to only count each row once:
QList<int> rows;
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
if (!rows.contains(index.row())) {
rows.push_back(index.row());
QUrl url = QUrl::fromLocalFile(getTrackLocation(index));
if (!url.isValid()) {
qDebug() << "ERROR invalid url\n";
} else {
urls.append(url);
qDebug() << "Appending URL:" << url;
}
}
}
}
mimeData->setUrls(urls);
return mimeData;
}
示例12: mouseMoveEvent
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton) {
#if QT_VERSION >= 0x040500
int diffX = event->pos().x() - m_dragStartPos.x();
int diffY = event->pos().y() - m_dragStartPos.y();
#endif
if ((event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()
#if QT_VERSION >= 0x040500
&& diffX < 3 && diffX > -3
&& diffY < -10
#endif
) {
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QList<QUrl> urls;
int index = tabAt(event->pos());
QUrl url = tabData(index).toUrl();
urls.append(url);
mimeData->setUrls(urls);
mimeData->setText(tabText(index));
mimeData->setData(QLatin1String("action"), "tab-reordering");
drag->setMimeData(mimeData);
drag->exec();
}
}
QTabBar::mouseMoveEvent(event);
}
示例13: mimeData
QMimeData* BookmarksModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QStringList texts;
QList<QUrl> urls;
if (indexes.count() == 1)
{
mimeData->setProperty("x-item-index", indexes.at(0));
}
for (int i = 0; i < indexes.count(); ++i)
{
if (indexes.at(i).isValid() && static_cast<BookmarkType>(indexes.at(i).data(TypeRole).toInt()) == UrlBookmark)
{
texts.append(indexes.at(i).data(UrlRole).toString());
urls.append(indexes.at(i).data(UrlRole).toUrl());
}
}
mimeData->setText(texts.join(QLatin1String(", ")));
mimeData->setUrls(urls);
return mimeData;
}
示例14: kopiuj
void FormPlaylist::kopiuj()
{
QMimeData *mimeData = new QMimeData;
QList<QUrl> urls = getCopyData();
mimeData->setUrls( urls );
urls.clear();
clipboard->setMimeData(mimeData);
}
示例15: mimeDataFor
static QMimeData* mimeDataFor(const KUrl& url)
{
QMimeData* data = new QMimeData();
QList<QUrl> urlList;
urlList.append(QUrl(url));
data->setUrls(urlList);
return data;
}