本文整理汇总了C++中QMimeData::setImageData方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData::setImageData方法的具体用法?C++ QMimeData::setImageData怎么用?C++ QMimeData::setImageData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeData
的用法示例。
在下文中一共展示了QMimeData::setImageData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pushImageToClipboard
void ResultsJsInterface::pushImageToClipboard(const QByteArray &base64, const QString &html)
{
QMimeData *mimeData = new QMimeData();
QByteArray byteArray = QByteArray::fromBase64(base64);
QImage pm;
if(pm.loadFromData(byteArray))
{
#ifdef __WIN32__ //needed because jpegs/clipboard doesn't support transparency in windows
QImage image2(pm.size(), QImage::Format_ARGB32);
image2.fill(Qt::white);
QPainter painter(&image2);
painter.drawImage(0, 0, pm);
mimeData->setImageData(image2);
#else
mimeData->setImageData(pm);
#endif
}
if ( ! html.isEmpty())
mimeData->setHtml(html);
if (mimeData->hasImage() || mimeData->hasHtml())
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setMimeData(mimeData, QClipboard::Clipboard);
}
}
示例2: onCopyToClipboard
void TerrainProfileGraph::onCopyToClipboard()
{
const osgEarth::Util::TerrainProfile profile = _calculator->getProfile();
if (profile.getNumElevations() > 0)
{
const QLatin1String fieldSeparator(",");
GeoPoint startPt = _calculator->getStart(ALTMODE_ABSOLUTE);
GeoPoint endPt = _calculator->getEnd(ALTMODE_ABSOLUTE);
QString profileInfo = QString("Start:,%1,%2\nEnd:,%3,%4\n")
.arg(_coordinateFormatter->format(startPt).c_str()).arg(startPt.alt())
.arg(_coordinateFormatter->format(endPt).c_str()).arg(endPt.alt());
QString distanceInfo("Distance:");
QString elevationInfo("Elevation:");
for (unsigned int i = 0; i < profile.getNumElevations(); i++)
{
distanceInfo += fieldSeparator + QString::number(profile.getDistance(i));
elevationInfo += fieldSeparator + QString::number(profile.getElevation(i));
}
profileInfo += distanceInfo + QString("\n") + elevationInfo;
QImage graphImage(_graphWidth, _graphHeight, QImage::Format_RGB32);
QPainter p;
p.begin(&graphImage);
_scene->render(&p);
p.end();
QMimeData* clipData = new QMimeData();
clipData->setText(profileInfo);
clipData->setImageData(graphImage);
QApplication::clipboard()->setMimeData(clipData);
}
}
示例3: 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();
}
示例4: copyFromLayer
void Document::copyFromLayer(int layer)
{
if(!m_canvas) {
qWarning("copyFromLayer: no canvas!");
return;
}
QMimeData *data = new QMimeData;
data->setImageData(m_canvas->selectionToImage(layer));
// Store also original coordinates
QPoint srcpos;
if(m_canvas->selection()) {
srcpos = m_canvas->selection()->boundingRect().center();
} else {
QSize s = m_canvas->layerStack()->size();
srcpos = QPoint(s.width()/2, s.height()/2);
}
QByteArray srcbuf = QByteArray::number(srcpos.x()) + "," + QByteArray::number(srcpos.y());
data->setData("x-drawpile/pastesrc", srcbuf);
QApplication::clipboard()->setMimeData(data);
}
示例5: mouseMoveEvent
void LayerEditScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if(!event->buttons() & Qt::LeftButton) {
return;
}
if((event->scenePos() - _dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
return;
}
qDebug() << "LayerEditScene::mouseMoveEvent - Starting a drag";
// Get the pixmap item related to the start of the drag.
QGraphicsItem *item = itemAt(_dragStartPosition, QTransform());
if(item == 0) {
// Couldn't find an item at the location for some reason.
qDebug() << "LayerEditScene::mouseMoveEvent - Could not find a sprite at the drag location.";
return;
}
// Static cast is safe because this scene only adds QGraphicsPixmapItem
QGraphicsPixmapItem *pixmapItem = static_cast<QGraphicsPixmapItem *>(item);
// Remove item from scene
Sprite sprite = _pixmapToSprite[pixmapItem]; // Save sprite before it's removed.
qDebug() << "LayerEditScene::mouseMoveEvent - Dragging " << sprite.getFileInfo().fileName();
int index = _previews.indexOf(pixmapItem);
if(index != -1) {
removeSprite(index);
recalculatePositions();
}
// Create a new drag event and put the source image into the mime data.
QDrag *drag = new QDrag((QObject *)event->widget());
QMimeData *data = new QMimeData();
data->setImageData(sprite.getTexture());
data->setText(sprite.getFileInfo().absoluteFilePath());
drag->setMimeData(data);
// Put the pixmap that was selected onto the cursor
QPixmap pixmap = pixmapItem->pixmap();
drag->setPixmap(pixmap);
drag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2));
// Execute the drag with a move action.
qDebug() << "LayerEditScene::mouseMoveEvent - Executing drag as MoveAction";
Qt::DropAction action = drag->exec(Qt::MoveAction, Qt::MoveAction);
if(action != Qt::MoveAction) {
// Put sprite back
qDebug() << "LayerEditScene::mouseMoveEvent - Move action failed, putting sprite back where it was.";
insertSprite(index, sprite);
recalculatePositions();
} else {
// Delete the old item
qDebug() << "LayerEditScene::mouseMoveEvent - Move succeeded, deleting old sprite.";
delete pixmapItem;
}
}
示例6: dragObject
QMimeData* PictureImage::dragObject(QWidget *dragSource, const char *name)
{
Q_UNUSED(dragSource); // Was used in Qt3?
QMimeData* mimeData = new QMimeData();
mimeData->setImageData(m_originalImage);
mimeData->setObjectName(name);
return mimeData;
}
示例7: mouseMoveEvent
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if(drag_start_ && (event->buttons() & Qt::LeftButton) && (event->pos() - drag_start_pos_).manhattanLength() >= QApplication::startDragDistance()) {
QDrag *d = new QDrag(this);
QMimeData *m = new QMimeData();
if(drag_use_rc_)
m->setImageData(this->img_transview_);
else
m->setImageData(this->img_original_);
d->setMimeData(m);
ignore_drops_ = true;
d->exec(Qt::CopyAction);
ignore_drops_ = drag_start_ = false;
}
}
示例8: mousePressEvent
//! [2]
void MyWidget::mousePressEvent(QMouseEvent *event)
{
//! [2]
QString text = dataLabel->text();
QPixmap iconPixmap(32, 32);
iconPixmap.fill(qRgba(255, 0, 0, 127));
QImage image(100, 100, QImage::Format_RGB32);
image.fill(qRgb(0, 0, 255));
//! [3]
if (event->button() == Qt::LeftButton) {
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setText(text);
mimeData->setImageData(image);
drag->setMimeData(mimeData);
drag->setPixmap(iconPixmap);
Qt::DropAction dropAction = drag->exec();
//! [3]
// ...
//! [4]
event->accept();
}
//! [4]
else if (event->button() == Qt::MidButton) {
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setImageData(image);
drag->setMimeData(mimeData);
drag->setPixmap(iconPixmap);
Qt::DropAction dropAction = drag->exec();
// ...
event->accept();
}
//! [5]
}
示例9: startDrag
void TeamPokeButton::startDrag()
{
QMimeData * data = new QMimeData();
data->setText(this->text());
data->setImageData(*pokeIcon->pixmap());
QDrag * drag = new QDrag(this);
drag->setMimeData(data);
drag->setPixmap(*pokeIcon->pixmap());
drag->exec(Qt::MoveAction);
emit clicked();
}
示例10: dragObject
QMimeData* PictureBase::dragObject(QWidget * dragSource, const char * name)
{
Q_UNUSED(dragSource);
QImage image(generateImage(getOriginalSize()));
if (image.isNull())
return 0;
else {
QMimeData* mimeData = new QMimeData();
mimeData->setImageData(image);
mimeData->setObjectName(name);
return mimeData; // XXX: Qt3 use dragsource here?
}
}
示例11: startDrag
void TB_PokemonItem::startDrag()
{
QMimeData * data = new QMimeData();
QVariant v;
v.setValue(box);
data->setProperty("Box", v);
data->setProperty("Item", box->getNumOf(this));
data->setImageData(pixmap());
QDrag * drag = new QDrag(box->parentWidget());
drag->setMimeData(data);
drag->setPixmap(pixmap());
drag->setHotSpot(QPoint(pixmap().width()/2,pixmap().height()/2));
drag->exec(Qt::MoveAction);
}
示例12: mousePressEvent
void UBGraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QMimeData* pMime = new QMimeData();
pMime->setImageData(pixmap().toImage());
mDelegate->setMimeData(pMime);
if (mDelegate->mousePressEvent(event))
{
//NOOP
}
else
{
QGraphicsPixmapItem::mousePressEvent(event);
}
}
示例13: mousePressEvent
void QDragLabel::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton){
QDrag* drag = new QDrag(this);
QMimeData* mime = new QMimeData;
mime->setText(this->class_name);
mime->setImageData(this->pixmap()->toImage());
drag->setMimeData(mime);
drag->setPixmap(*this->pixmap());
Qt::DropAction dropAction = drag->exec();
}
}
示例14: dragPixmap
void DraggableLabel::dragPixmap()
{
const QPixmap *currentPixmap = pixmap();
if (currentPixmap == NULL)
return;
// Make temp file
QTemporaryFile *tempFile = new QTemporaryFile(AppTools::addPathSeparator(QDir::tempPath()) + DRAG_LABEL_FILENAME_TEMPLATE);
tempFile->setAutoRemove(false);
if (!tempFile->open())
{
delete tempFile;
return;
}
// Arrange data
QMimeData *data = new QMimeData;
data->setImageData(currentPixmap->toImage());
// Save pixmap
QString tempFileName = tempFile->fileName();
currentPixmap->save(tempFileName);
delete tempFile;
QDEBUG("Dragged file saved to " << tempFileName);
// Keep its name
QList <QUrl> urls;
urls.append(QUrl::fromLocalFile(tempFileName));
data->setUrls(urls);
QPixmap preview = currentPixmap->scaled(DRAG_LABEL_PREVIEW_WIDTH, DRAG_LABEL_PREVIEW_HEIGHT, Qt::KeepAspectRatio);
QPixmap preview2(preview.width(), preview.height());
preview2.fill(QColor(180, 180, 180));
preview.setAlphaChannel(preview2);
// Go drag
QDrag *drag = new QDrag(this);
drag->setPixmap(preview);
drag->setMimeData(data);
drag->setHotSpot(QPoint(preview.width() / 2, preview.height() / 2));
// Let's go!
drag->exec(Qt::MoveAction);
}
示例15: mouseMoveEvent
//! [5]
void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton))
.length() < QApplication::startDragDistance()) {
return;
}
QDrag *drag = new QDrag(event->widget());
QMimeData *mime = new QMimeData;
drag->setMimeData(mime);
//! [5]
//! [6]
static int n = 0;
if (n++ > 2 && (qrand() % 3) == 0) {
QImage image(":/images/head.png");
mime->setImageData(image);
drag->setPixmap(QPixmap::fromImage(image).scaled(30, 40));
drag->setHotSpot(QPoint(15, 30));
//! [6]
//! [7]
} else {
mime->setColorData(color);
mime->setText(QString("#%1%2%3")
.arg(color.red(), 2, 16, QLatin1Char('0'))
.arg(color.green(), 2, 16, QLatin1Char('0'))
.arg(color.blue(), 2, 16, QLatin1Char('0')));
QPixmap pixmap(34, 34);
pixmap.fill(Qt::white);
QPainter painter(&pixmap);
painter.translate(15, 15);
painter.setRenderHint(QPainter::Antialiasing);
paint(&painter, 0, 0);
painter.end();
pixmap.setMask(pixmap.createHeuristicMask());
drag->setPixmap(pixmap);
drag->setHotSpot(QPoint(15, 20));
}
//! [7]
//! [8]
drag->exec();
setCursor(Qt::OpenHandCursor);
}