void NetworkEditorView::focusInEvent(QFocusEvent* e) {
    auto enable = networkEditor_->selectedItems().size() > 0;

    setupAction("Cut", enable, [&]() {
        auto data = networkEditor_->cut();

        auto mimedata = util::make_unique<QMimeData>();
        mimedata->setData(QString("application/x.vnd.inviwo.network+xml"), data);
        mimedata->setData(QString("text/plain"), data);
        QApplication::clipboard()->setMimeData(mimedata.release());
    });
    
    setupAction("Copy", enable, [&]() {
        auto data = networkEditor_->copy();

        auto mimedata = util::make_unique<QMimeData>();
        mimedata->setData(QString("application/x.vnd.inviwo.network+xml"), data);
        mimedata->setData(QString("text/plain"), data);
        QApplication::clipboard()->setMimeData(mimedata.release());
    });

    setupAction("Paste", true, [&]() {
        auto clipboard = QApplication::clipboard();
        auto mimeData = clipboard->mimeData();
        if (mimeData->formats().contains(QString("application/x.vnd.inviwo.network+xml"))) {
            networkEditor_->paste(mimeData->data(QString("application/x.vnd.inviwo.network+xml")));
        } else if (mimeData->formats().contains(QString("text/plain"))) {
            networkEditor_->paste(mimeData->data(QString("text/plain")));
        }
    });

    setupAction("Delete", enable, [&]() { networkEditor_->deleteSelection(); });

    QGraphicsView::focusInEvent(e);
}
    virtual Q3DragObject *dragObject ()
    {
      int count = 0;
      for ( Q3IconViewItem *it = firstItem(); it; it = it->nextItem() ) {
        if ( it->isSelected() ) {
          ++count;
        }
      }

      QPixmap pixmap;
      if ( count > 1 ) {
        pixmap = KIconLoader::global()->loadIcon( "mail-attachment", KIconLoader::Desktop );
      }
      if ( pixmap.isNull() ) {
        pixmap = static_cast<AttachmentIconItem *>( currentItem() )->icon();
      }

      QPoint hotspot( pixmap.width() / 2, pixmap.height() / 2 );

      QDrag *drag = new QDrag( this );
      drag->setMimeData( mimeData() );

      drag->setPixmap( pixmap );
      drag->setHotSpot( hotspot );
      drag->exec( Qt::CopyAction );
      return 0;
    }
Example #3
0
/*!
    Returns the clipboard image, or returns a null image if the
    clipboard does not contain an image or if it contains an image in
    an unsupported image format.

    The \a mode argument is used to control which part of the system
    clipboard is used.  If \a mode is QClipboard::Clipboard, the
    image is retrieved from the global clipboard.  If \a mode is
    QClipboard::Selection, the image is retrieved from the global
    mouse selection. 

    \sa setImage() pixmap() mimeData(), QImage::isNull()
*/
QImage QClipboard::image(Mode mode) const
{
    const QMimeData *data = mimeData(mode);
    if (!data)
        return QImage();
    return qvariant_cast<QImage>(data->imageData());
}
Example #4
0
QMimeData* StartPageModel::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));

		itemFromIndex(indexes.at(0))->setData(true, IsDraggedRole);
	}

	for (int i = 0; i < indexes.count(); ++i)
	{
		if (indexes.at(i).isValid() && static_cast<BookmarksModel::BookmarkType>(indexes.at(i).data(BookmarksModel::TypeRole).toInt()) == BookmarksModel::UrlBookmark)
		{
			texts.append(indexes.at(i).data(BookmarksModel::UrlRole).toString());
			urls.append(indexes.at(i).data(BookmarksModel::UrlRole).toUrl());
		}
	}

	mimeData->setText(texts.join(QLatin1String(", ")));
	mimeData->setUrls(urls);

	connect(mimeData, SIGNAL(destroyed()), this, SLOT(dragEnded()));

	return mimeData;
}
void LXQtTaskButton::mouseMoveEvent(QMouseEvent* event)
{
    if (!(event->buttons() & Qt::LeftButton))
        return;

    if ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())
        return;

    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData());
    QIcon ico = icon();
    QPixmap img = ico.pixmap(ico.actualSize({32, 32}));
    drag->setPixmap(img);
    switch (parentTaskBar()->panel()->position())
    {
        case ILXQtPanel::PositionLeft:
        case ILXQtPanel::PositionTop:
            drag->setHotSpot({0, 0});
            break;
        case ILXQtPanel::PositionRight:
        case ILXQtPanel::PositionBottom:
            drag->setHotSpot(img.rect().bottomRight());
            break;
    }

    sDraggging = true;
    drag->exec();

    // if button is dropped out of panel (e.g. on desktop)
    // it is not deleted automatically by Qt
    drag->deleteLater();
    sDraggging = false;

    QAbstractButton::mouseMoveEvent(event);
}
Example #6
0
void MyTreeWidget::startDrag(Qt::DropActions /*supportedActions*/)
{
    QMimeData* const dragMimeData = mimeData(selectionModel()->selectedIndexes());
    QDrag* const drag             = new QDrag(this);
    drag->setMimeData(dragMimeData);
    drag->start(Qt::CopyAction);
}
Example #7
0
void FavoritePlacesModel::moveRow(int from, int to)
{
    // Simulate a move by drag'n'drop because moving the row this way
    // is the only way to get rowsMoved() signals instead of remove+insert
    QMimeData *data = mimeData(QModelIndexList() << index(from, 0));
    Q_ASSERT(data);
    if (from < to) {
        ++to;
    }
    dropMimeData(data, Qt::MoveAction, to, 0, QModelIndex());
}
Example #8
0
void ScriptModel::copyActions(const QList<int> &rows)
{
	QModelIndexList indexes;

	for(int row: rows)
	{
		indexes << index(row, 0, QModelIndex());
	}

	QClipboard *clipboard = QApplication::clipboard();
	clipboard->setMimeData(mimeData(indexes));
}
Example #9
0
/*!
    \fn QMimeSource *QClipboard::data(Mode mode) const
    \compat

    Use mimeData() instead.
*/
QMimeSource *QClipboard::data(Mode mode) const
{
    Q_D(const QClipboard);

    if (supportsMode(mode) == false)
        return 0;

    if (d->compat_data[mode])
        return d->compat_data[mode];

    d->wrapper[mode]->data = mimeData(mode);
    return d->wrapper[mode];
}
Example #10
0
void Smb4KSharesView::startDrag(Qt::DropActions supported)
{
  if (m_tooltipItem)
  {
    emit aboutToHideToolTip(m_tooltipItem);
    m_tooltipItem->tooltip()->hide();
    m_tooltipItem = 0;
  }
  else
  {
    // Do nothing
  }

  QList<QListWidgetItem *> list = selectedItems();

  if (!list.isEmpty())
  {
    QMimeData *data = mimeData(list);

    if (!data)
    {
      return;
    }

    QDrag *drag = new QDrag(this);

    QPixmap pixmap;

    if (list.count() == 1)
    {
      Smb4KSharesViewItem *item = static_cast<Smb4KSharesViewItem *>(list.first());
      pixmap = item->icon().pixmap(KIconLoader::SizeMedium);
    }
    else
    {
      pixmap = KDE::icon("document-multiple").pixmap(KIconLoader::SizeMedium);
    }

    drag->setPixmap(pixmap);
    drag->setMimeData(data);

    drag->exec(supported, Qt::IgnoreAction);
  }
  else
  {
    // Do nothing
  }
}
Example #11
0
void ToolBarDragAreaWidget::mouseMoveEvent(QMouseEvent *event)
{
	if (!event->buttons().testFlag(Qt::LeftButton) || (event->pos() - m_dragStartPosition).manhattanLength() < QApplication::startDragDistance() || !m_toolBar->isMovable())
	{
		return;
	}

	m_toolBar->startToolBarDragging();

	QMimeData *mimeData(new QMimeData());
	mimeData->setData(QLatin1String("x-toolbar-identifier"), QString::number(m_toolBar->getIdentifier()).toUtf8());

	QDrag *drag(new QDrag(this));
	drag->setMimeData(mimeData);
	drag->exec(Qt::MoveAction);
}
Example #12
0
 void CopySelectedItems()
 {
   const Playlist::Model::Ptr model = Controller->GetModel();
   if (const std::size_t itemsCount = model->CountItems())
   {
     const Playlist::Model::IndexSet::Ptr items = View->GetSelectedItems();
     const QStringList& paths = model->GetItemsPaths(*items);
     QByteArray data;
     {
       QDataStream stream(&data, QIODevice::WriteOnly);
       stream << paths;
     }
     std::unique_ptr<QMimeData> mimeData(new QMimeData());
     mimeData->setData(ITEMS_MIMETYPE, data);
     QApplication::clipboard()->setMimeData(mimeData.release());
   }
 }
Example #13
0
void DragJComponent::mousePressEvent(QMouseEvent *e)
{
 QString text = mimeData();
 if(text != "")
 {
  if(e->button()&Qt::LeftButton)
  {
   QDrag *dr = new QDrag(this);
   QMimeData *data = new QMimeData;
   //data->setText(_dataFlavor->toString());
   data->setText(text);
   // Assign ownership of the QMimeData object to the QDrag object.
   dr->setMimeData(data);
   dr->start();
  }
 }
}
void BtTreeView::mouseMoveEvent(QMouseEvent *event)
{
   // Return if the left button isn't down
   if (!(event->buttons() & Qt::LeftButton))
      return;

   // Return if the length of movement isn't far enough.
   if ((event->pos() - dragStart).manhattanLength() < QApplication::startDragDistance())
      return;

   if ( doubleClick )
      return;

   QDrag *drag = new QDrag(this);
   QMimeData *data = mimeData(selectionModel()->selectedRows());

   drag->setMimeData(data);
   drag->start(Qt::CopyAction);
} 
Example #15
0
/*!
    \overload

    Returns the clipboard text in subtype \a subtype, or an empty string
    if the clipboard does not contain any text. If \a subtype is null,
    any subtype is acceptable, and \a subtype is set to the chosen
    subtype.

    The \a mode argument is used to control which part of the system
    clipboard is used.  If \a mode is QClipboard::Clipboard, the
    text is retrieved from the global clipboard.  If \a mode is
    QClipboard::Selection, the text is retrieved from the global
    mouse selection.

    Common values for \a subtype are "plain" and "html".

    Note that calling this function repeatedly, for instance from a
    key event handler, may be slow. In such cases, you should use the
    \c dataChanged() signal instead.

    \sa setText(), mimeData()
*/
QString QClipboard::text(QString &subtype, Mode mode) const
{
    const QMimeData *data = mimeData(mode);
    if (!data)
        return QString();
    if (subtype.isEmpty()) {
        QStringList formats = data->formats();
        if (formats.contains(QLatin1String("text/plain")))
            subtype = QLatin1String("plain");
        else {
            for (int i = 0; i < formats.size(); ++i)
                if (formats.at(i).startsWith(QLatin1String("text/"))) {
                    subtype = formats.at(i).mid(5);
                    break;
                }
        }
    }
    if (subtype.isEmpty())
        return QString();
    if (subtype == QLatin1String("plain"))
        return data->text();
    return QString::fromUtf8(data->data(QLatin1String("text/") + subtype));
}
Example #16
0
void ToolsListView::startDrag(Qt::DropActions /*supportedActions*/)
{
    QList<QTreeWidgetItem*> items = selectedItems();

    if (items.isEmpty())
    {
        return;
    }

    QPixmap icon(DesktopIcon("system-run", 48));
    int w = icon.width();
    int h = icon.height();

    QPixmap pix(w + 4, h + 4);
    QString text(QString::number(items.count()));

    QPainter p(&pix);
    p.fillRect(0, 0, pix.width() - 1, pix.height() - 1, QColor(Qt::white));
    p.setPen(QPen(Qt::black, 1));
    p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
    p.drawPixmap(2, 2, icon);
    QRect r = p.boundingRect(2, 2, w, h, Qt::AlignLeft | Qt::AlignTop, text);
    r.setWidth(qMax(r.width(), r.height()));
    r.setHeight(qMax(r.width(), r.height()));
    p.fillRect(r, QColor(0, 80, 0));
    p.setPen(Qt::white);
    QFont f(font());
    f.setBold(true);
    p.setFont(f);
    p.drawText(r, Qt::AlignCenter, text);
    p.end();

    QDrag* drag = new QDrag(this);
    drag->setMimeData(mimeData(items));
    drag->setPixmap(pix);
    drag->exec();
}
Example #17
0
/*!
    \overload

    Returns the clipboard text in subtype \a subtype, or an empty string
    if the clipboard does not contain any text. If \a subtype is null,
    any subtype is acceptable, and \a subtype is set to the chosen
    subtype.

    The \a mode argument is used to control which part of the system
    clipboard is used.  If \a mode is QClipboard::Clipboard, the
    text is retrieved from the global clipboard.  If \a mode is
    QClipboard::Selection, the text is retrieved from the global
    mouse selection.

    Common values for \a subtype are "plain" and "html".

    Note that calling this function repeatedly, for instance from a
    key event handler, may be slow. In such cases, you should use the
    \c dataChanged() signal instead.

    \sa setText(), mimeData()
*/
QString QClipboard::text(QString &subtype, Mode mode) const
{
    const QMimeData *const data = mimeData(mode);
    if (!data)
        return QString();

    const QStringList formats = data->formats();
    if (subtype.isEmpty()) {
        if (formats.contains(QLatin1String("text/plain")))
            subtype = QLatin1String("plain");
        else {
            for (int i = 0; i < formats.size(); ++i)
                if (formats.at(i).startsWith(QLatin1String("text/"))) {
                    subtype = formats.at(i).mid(5);
                    break;
                }
            if (subtype.isEmpty())
                return QString();
        }
    } else if (!formats.contains(QLatin1String("text/") + subtype)) {
        return QString();
    }

    const QByteArray rawData = data->data(QLatin1String("text/") + subtype);

#ifndef QT_NO_TEXTCODEC
    QTextCodec* codec = QTextCodec::codecForMib(106); // utf-8 is default
    if (subtype == QLatin1String("html"))
        codec = QTextCodec::codecForHtml(rawData, codec);
    else
        codec = QTextCodec::codecForUtfText(rawData, codec);
    return codec->toUnicode(rawData);
#else //QT_NO_TEXTCODEC
    return rawData;
#endif //QT_NO_TEXTCODEC
}
Example #18
0
void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event)
{
    if ( !m_enabled
         || QLineF(event->screenPos(), m_buttonDownPos).length()
            < m_startDragDistance) {
        return;
    }

    if (m_draggingJustStarted) {
        grabMouse();
        m_draggingJustStarted = false;
        //qDebug() << "************ DDDD new QDrag" << objectName();
        QDrag *drag = new QDrag(parent());
        DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it.
        dataCopy->setText(objectName());
        drag->setMimeData(dataCopy);
        //qDebug() << "-----> data: dragarea: " << this << x() << y() << " mimedata: " << m_data << (dataCopy->hasColor() ? dataCopy->color().name() : " no color") ;

        const QSize _s(48,48); // FIXME: smarter, please

        if (!m_delegateImage.isNull()) {
            drag->setPixmap(QPixmap::fromImage(m_delegateImage));
//             qDebug() << "++++++delegateImage";
        } else {
//             qDebug() << "DDD NO Delegte image";
            if (m_delegate) {
                // This is just highly unreliable, let's completely skip this
                // until we have a non-digusting way of "attaching an item to
                // the cursor
//                 QRectF rf;
//                 qDebug() << "DDD +++ delegate" << m_delegate;
//                 rf = QRectF(0, 0, m_delegate->width(), m_delegate->height());
//                 rf = m_delegate->mapRectToScene(rf);
//                 QImage grabbed = window()->grabWindow();
//                 //rf = rf.intersected(QRectF(0, 0, grabbed.width(), grabbed.height()));
//                 grabbed = grabbed.copy(rf.toAlignedRect());
// //                 qDebug() << " +++++++++++++++++++++++ dim: " << rf;
//                 grabbed.save("file:///tmp/grabbed.png");
//                 QPixmap pm = QPixmap::fromImage(grabbed);
//                 qDebug() << " set new pixmap" << grabbed.size();
//                 drag->setPixmap(pm);

            } else if (mimeData()->hasImage()) {
//                 qDebug() << "++++++hasImage";
                QImage im = qvariant_cast<QImage>(mimeData()->imageData());
                drag->setPixmap(QPixmap::fromImage(im));
            } else if (mimeData()->hasColor()) {
//                 qDebug() << "++++++color";
                QPixmap px(_s);
                px.fill(mimeData()->color());
                drag->setPixmap(px);
            } else {
                // icons otherwise
                QStringList icons;
//                 qDebug() << "DDD adding icons dan maar";
                if (mimeData()->hasText()) {
                    icons << "text-plain";
                }
                if (mimeData()->hasHtml()) {
                    icons << "text-html";
                }
                if (mimeData()->hasUrls()) {
                    Q_FOREACH (const QVariant &u, mimeData()->urls()) {
                        Q_UNUSED(u);
                        icons << "text-html";
                    }
                }
                if (icons.count()) {
                    const int _w = 48;
                    QPixmap pm(_w*icons.count(), _w);
                    pm.fill(Qt::transparent);
                    QPainter p(&pm);
                    int i = 0;
                    Q_FOREACH (const QString &ic, icons) {
                        p.drawPixmap(QPoint(i*_w, 0), KisIconUtils::loadIcon(ic).pixmap(_w, _w));
                        i++;
                    }
                    p.end();
                    drag->setPixmap(pm);
                }
                //qDebug() << "DD pixmaps set for icons: " << icons;
            }
Example #19
0
/*!
    Returns the clipboard pixmap, or null if the clipboard does not
    contain a pixmap. Note that this can lose information. For
    example, if the image is 24-bit and the display is 8-bit, the
    result is converted to 8 bits, and if the image has an alpha
    channel, the result just has a mask.

    The \a mode argument is used to control which part of the system
    clipboard is used.  If \a mode is QClipboard::Clipboard, the
    pixmap is retrieved from the global clipboard.  If \a mode is
    QClipboard::Selection, the pixmap is retrieved from the global
    mouse selection.

    \sa setPixmap() image() mimeData() QPixmap::convertFromImage()
*/
QPixmap QClipboard::pixmap(Mode mode) const
{
    const QMimeData *data = mimeData(mode);
    return data ? qvariant_cast<QPixmap>(data->imageData()) : QPixmap();
}
Example #20
0
/*!
    Returns the clipboard text as plain text, or an empty string if the
    clipboard does not contain any text.

    The \a mode argument is used to control which part of the system
    clipboard is used.  If \a mode is QClipboard::Clipboard, the
    text is retrieved from the global clipboard.  If \a mode is
    QClipboard::Selection, the text is retrieved from the global
    mouse selection. If \a mode is QClipboard::FindBuffer, the
    text is retrieved from the search string buffer.

    \sa setText(), mimeData()
*/
QString QClipboard::text(Mode mode) const
{
    const QMimeData *data = mimeData(mode);
    return data ? data->text() : QString();
}