コード例 #1
0
ファイル: task_list.cpp プロジェクト: ep3998/task-list
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);

    }
}
コード例 #2
0
ファイル: treeview.cpp プロジェクト: radtek/isoftstone
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);
}
コード例 #3
0
ファイル: finalwidget.cpp プロジェクト: 3163504123/phantomjs
void FinalWidget::mouseMoveEvent(QMouseEvent *event)
{
    if (!(event->buttons() & Qt::LeftButton))
        return;
    if ((event->pos() - dragStartPosition).manhattanLength()
         < QApplication::startDragDistance())
        return;
    if (!hasImage)
        return;

    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;

//! [0]
    QByteArray output;
    QBuffer outputBuffer(&output);
    outputBuffer.open(QIODevice::WriteOnly);
    imageLabel->pixmap()->toImage().save(&outputBuffer, "PNG");
    mimeData->setData("image/png", output);
//! [0]
/*
//! [1]
    mimeData->setImageData(QVariant(*imageLabel->pixmap()));
//! [1]
*/
    drag->setMimeData(mimeData);
    drag->setPixmap(imageLabel->pixmap()->scaled(64, 64, Qt::KeepAspectRatio));
//! [2]
    drag->setHotSpot(QPoint(drag->pixmap().width()/2,
                            drag->pixmap().height()));
//! [2]

    drag->start();
}
コード例 #4
0
void bottom_label::mousePressEvent(QMouseEvent *event){
	if (event->button() == Qt::LeftButton) {
		QDrag* drag = new QDrag(this);

		//const QPixmap *pPixmap = pixmap();   
		//      drag->setPixmap(*pPixmap); //ÕâÀïÉèÖÃÍÏקʱ¸úËæÊó±êµÄͼƬ  
		//int w=pPixmap->size().width();
		//int h=pPixmap->size().height();
		//QPoint t;
		//t.setX(w);
		//t.setY(h);
		//      drag->setHotSpot(t); //ÉèÖøúËæͼƬµÄÖÐÐÄµã  



		QMimeData *mimeData = new QMimeData;
		QString send_mes = QString::number(id);
		send_mes += "|2";
		mimeData->setText(send_mes);
		drag->setMimeData(mimeData);
		//drag->setPixmap(iconPixmap);
		Qt::DropAction dropAction = drag->exec();
		drag->start(Qt::MoveAction);
	}
}
コード例 #5
0
ファイル: psitabbar.cpp プロジェクト: AlekSi/Jabbin
/*
 * Used for starting drags of tabs
 */
void PsiTabBar::mouseMoveEvent(QMouseEvent *event) {
	if (!dragsEnabled_) {
		return;
	}
	if (!(event->buttons() & Qt::LeftButton)) {
		return;
	}
	if ((event->pos() - dragStartPosition_).manhattanLength()
		< QApplication::startDragDistance()) {
		return;
	}

	if (dragTab_ != -1) {
		QDrag *drag = new QDrag(this);
		QMimeData *mimeData = new QMimeData;
		QByteArray data;
		QPixmap icon;

		data.setNum(dragTab_);

		mimeData->setData("psiTabDrag", data);
		drag->setMimeData(mimeData);
		drag->setPixmap(icon);

		Qt::DropAction dropAction = drag->start(Qt::MoveAction);
		Q_UNUSED(dropAction);
	}

	event->accept();
}
コード例 #6
0
void DualColorButton::mouseMoveEvent(QMouseEvent *event)
{
	if(dragSource_ != NODRAG && (event->buttons() & Qt::LeftButton) &&
			(event->pos() - dragStart_).manhattanLength()
		> QApplication::startDragDistance())
	{
		QDrag *drag = new QDrag(this);

		QMimeData *mimedata = new QMimeData;
		const QColor color = (dragSource_ == FOREGROUND)?foreground_:background_;
		mimedata->setColorData(color);

		drag->setMimeData(mimedata);
		drag->start(Qt::CopyAction);
	}
	// Higlight clickable areas
	QRectF fgr = foregroundRect();
	QRectF bgr = backgroundRect();
	if(fgr.contains(event->pos()))
		hilite_ = 1;
	else if(bgr.contains(event->pos()))
		hilite_ = 2;
	else if(event->pos().x() > fgr.right() && event->pos().y() < bgr.top())
		hilite_ = 3;
	else if(event->pos().x() < bgr.left() && event->pos().y() > fgr.bottom())
		hilite_ = 4;
	else
		hilite_ = 0;
	update();
}
コード例 #7
0
ファイル: PlayListView.cpp プロジェクト: UIKit0/rosegarden
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);
    
    
}
コード例 #8
0
void DragLabel::mousePressEvent(QMouseEvent * e)
{
     
     QString str = text(); 
     QPixmap pix;
     pix = pix.grabWidget(this);

     QByteArray data;
     QDataStream stream(&data,QIODevice::WriteOnly);
     stream << str << QPoint(e->pos()-rect().topLeft());
     QMimeData *mimeData = new QMimeData;
     mimeData->setData("Drag-Text",data);
     mimeData->setText(str);

     QDrag *drag = new QDrag(this);
     drag->setMimeData(mimeData);
     drag->setHotSpot(QPoint(e->pos() - rect().topLeft()));
     drag->setPixmap(pix);
     
     hide();

     Qt::DropAction dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
  
     if (dropAction == Qt::MoveAction) 
         close();
     else
     	 show();
}
コード例 #9
0
void PanelBrowserMenu::mouseMoveEvent(QMouseEvent *e)
{
    QMenu::mouseMoveEvent(e);

    if (!(e->buttons() & Qt::LeftButton)) return;
    if(_lastpress == QPoint(-1, -1)) return;

    // DND delay
    if((_lastpress - e->pos()).manhattanLength() < 12) return;

    // get id
    int id = static_cast<QMenuItem*>(actionAt(_lastpress))->id();
    if(!_filemap.contains(id)) return;

    // reset _lastpress
    _lastpress = QPoint(-1, -1);

    // start drag
    KUrl url;
    url.setPath(path() + '/' + _filemap[id]);
    KUrl::List files(url);
    QDrag* drag = new QDrag(this);
    QMimeData* data = new QMimeData;
    files.populateMimeData(data);
    connect(drag, SIGNAL(destroyed(QObject*)), this, SLOT(dragObjectDestroyed(QObject*)));
    drag->setPixmap(iconSet(id).pixmap());
    drag->start();
}
コード例 #10
0
void QDesignerMenuBar::startDrag(const QPoint &pos)
{
    const int index = findAction(pos);
    if (m_currentIndex == -1 || index >= realActionCount())
        return;

    QAction *action = safeActionAt(index);

    QDesignerFormWindowInterface *fw = formWindow();
    RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw);
    cmd->init(this, action, actions().at(index + 1));
    fw->commandHistory()->push(cmd);

    adjustSize();

    hideMenu(index);

    QDrag *drag = new QDrag(this);
    drag->setPixmap(ActionRepositoryMimeData::actionDragPixmap(action));
    drag->setMimeData(new ActionRepositoryMimeData(action, Qt::MoveAction));

    const int old_index = m_currentIndex;
    m_currentIndex = -1;

    if (drag->start(Qt::MoveAction) == Qt::IgnoreAction) {
        InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
        cmd->init(this, action, safeActionAt(index));
        fw->commandHistory()->push(cmd);

        m_currentIndex = old_index;
        adjustSize();
    }
}
コード例 #11
0
void KonqCombo::mouseMoveEvent( QMouseEvent *e )
{
    KComboBox::mouseMoveEvent( e );
    if ( m_dragStart.isNull() || currentText().isEmpty() )
        return;

    if ( e->buttons() & Qt::LeftButton &&
         (e->pos() - m_dragStart).manhattanLength() >
         KGlobalSettings::dndEventDelay() )
    {
        KUrl url( currentText() );
        if ( url.isValid() )
        {
            QDrag* drag = new QDrag(this);
            QMimeData* mime = new QMimeData();
            url.populateMimeData(mime);
            drag->setMimeData(mime);
            QPixmap pix = KonqPixmapProvider::self()->pixmapFor( currentText(),
                                                                 KIconLoader::SizeMedium );
            if ( !pix.isNull() )
                drag->setPixmap( pix );
            drag->start();
        }
    }
}
コード例 #12
0
void ListView::startDrag(Qt::DropActions supportedActions)
{
    QModelIndexList indexes = selectedIndexes();
    if (indexes.count() > 0) {
        QMimeData *data = model()->mimeData(indexes);
        if (!data) {
            return;
        }
        QDrag *drag = new QDrag(this);
        drag->setMimeData(data);
        QPixmap pix;

        if (1==indexes.count()) {
            QVariant var=model()->data(indexes.first(), ItemView::Role_Image);
            QImage img=var.value<QImage>();
            if (img.isNull()) {
                pix=var.value<QPixmap>();
            } else {
                pix=QPixmap::fromImage(img);
            }
        }
        if (pix.isNull()) {
            drag->setPixmap(Icons::self()->albumIcon.pixmap(64, 64));
        } else {
            drag->setPixmap(pix.width()<64 ? pix : pix.scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation));
        }
        drag->start(supportedActions);
    }
}
コード例 #13
0
ファイル: userview.cpp プロジェクト: j0wl/licq
void UserView::mouseMoveEvent(QMouseEvent* event)
{
  UserViewBase::mouseMoveEvent(event);

  QModelIndex index = currentIndex();
  if (index.isValid() == false)
    return;

  if (static_cast<ContactListModel::ItemType>
      (index.data(ContactListModel::ItemTypeRole).toInt()) != ContactListModel::UserItem)
    return;

  QString id = index.data(ContactListModel::AccountIdRole).toString();
  unsigned long ppid = index.data(ContactListModel::PpidRole).toUInt();

  if ((event->buttons() & Qt::LeftButton) && !myMousePressPos.isNull() &&
      (QPoint(event->pos() - myMousePressPos).manhattanLength() >= QApplication::startDragDistance()))
  {
    QString data(Licq::protocolId_toString(ppid).c_str());
    data += id;

    QDrag* drag = new QDrag(this);
    QMimeData* mimeData = new QMimeData;
    mimeData->setText(data);
    drag->setMimeData(mimeData);
    drag->start(Qt::CopyAction);
  }
}
コード例 #14
0
void BookmarkToolBar::startDrag()
{
    KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(m_dragAction);
    if (action)
    {
        QMimeData *mimeData = new QMimeData;
        KBookmark bookmark = action->bookmark();

        QByteArray address = bookmark.address().toLatin1();
        mimeData->setData(BookmarkManager::bookmark_mime_type(), address);
        bookmark.populateMimeData(mimeData);

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

        if (bookmark.isGroup())
        {
            drag->setPixmap(KIcon(bookmark.icon()).pixmap(24, 24));
        }
        else
        {
            drag->setPixmap(IconManager::self()->iconForUrl(action->bookmark().url()).pixmap(24, 24));
        }

        drag->start(Qt::MoveAction);
        connect(drag, SIGNAL(destroyed()), this, SLOT(dragDestroyed()));
    }
}
コード例 #15
0
ファイル: ktabwidgettest.cpp プロジェクト: fluxer/kdelibs
void Test::initiateDrag( QWidget *w )
{
   QDrag *drag = new QDrag( this );
   QMimeData *mimeData = new QMimeData;
   mimeData->setText(mWidget->tabText( mWidget->indexOf(w)));
   drag->setMimeData(mimeData);
   drag->start(); // do NOT delete d.
}
コード例 #16
0
void ImageButton::startDrag()
{
    if ( !mPicture.data().isNull() ) {
        QDrag *drag = new QDrag( this );
        drag->setMimeData( new QMimeData() );
        drag->mimeData()->setImageData( mPicture.data() );
        drag->start();
    }
}
コード例 #17
0
ファイル: palette.cpp プロジェクト: dc7kr/MuseScore
void Palette::mouseMoveEvent(QMouseEvent* ev)
      {
      if ((currentIdx != -1) && (dragIdx == currentIdx) && (ev->buttons() & Qt::LeftButton)
         && (ev->pos() - dragStartPosition).manhattanLength() > QApplication::startDragDistance()) {
            PaletteCell* cell = cells[currentIdx];
            if (cell && cell->element) {
                  QDrag* drag = new QDrag(this);
                  QMimeData* mimeData = new QMimeData;
                  Element* el  = cell->element;
                  qreal mag    = PALETTE_SPATIUM * extraMag / gscore->spatium();
                  QPointF spos = QPointF(dragStartPosition) / mag;
                  spos        -= QPointF(cells[currentIdx]->x, cells[currentIdx]->y);

                  // DEBUG:
                  spos.setX(0.0);
                  mimeData->setData(mimeSymbolFormat, el->mimeData(spos));
                  drag->setMimeData(mimeData);

                  dragSrcIdx = currentIdx;
                  emit startDragElement(el);
                  if (_readOnly) {
                        drag->start(Qt::CopyAction);
                        }
                  else {
                        /*Qt::DropAction action = */
                        drag->start(Qt::DropActions(Qt::CopyAction | Qt::MoveAction));
                        }
                  }
            }
      else {
            QRect r;
            if (currentIdx != -1)
                  r = idxRect(currentIdx);
            currentIdx = idx(ev->pos());
            if (currentIdx != -1) {
                  if (cells[currentIdx] == 0)
                        currentIdx = -1;
                  else
                        r |= idxRect(currentIdx);
                  }
            update(r);
            }
      }
コード例 #18
0
ファイル: ksnapshot.cpp プロジェクト: Berrrry/Qtqq
void KSnapshot::slotDragSnapshot()
{
    QDrag *drag = new QDrag(this);

    drag->setMimeData(new QMimeData);
    drag->mimeData()->setImageData(snapshot);
    drag->mimeData()->setData("application/x-kde-suggestedfilename", QFileInfo(file_path_).fileName().toUtf8());
    drag->setPixmap(preview());
    drag->start();
}
コード例 #19
0
ファイル: ObjectListView.cpp プロジェクト: UNINETT/fwbuilder
void ObjectListView::mouseMoveEvent(QMouseEvent *event)
{
    if (startingDrag)
    {
        QDrag *dr = dragObject();
        if (dr) dr->start();
        startingDrag = false;
    }
    QTreeWidget::mouseMoveEvent(event);
}
コード例 #20
0
ファイル: DraggablePiece.cpp プロジェクト: quinsmpang/Tools
void DraggablePiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    QMimeData *data = new QMimeData;
	QVariant variant = QVariant::fromValue((int)Qt::green);
	data->setColorData(variant);

	QDrag *drag = new QDrag((QObject*)event->widget());
    drag->setMimeData(data);
    drag->start();
}
コード例 #21
0
void ExtendedTableWidget::mouseMoveEvent(QMouseEvent * event)
{
    QTableWidgetItem *item = itemAt(event->pos());
    if (item) {
        QDrag *drag = new QDrag(this);
        QMimeData *mimeData = new QMimeData;
        mimeData->setText(item->text());
        mimeData->setData(NUMBER_MIMETYPE, "");
        drag->setMimeData(mimeData);
        drag->start(Qt::CopyAction | Qt::MoveAction);
    }
}
コード例 #22
0
void EffectItemBase::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    ConnectorItem * connector = connectorAtPosition(event->scenePos());
    if (!connector)
        return;

    ConnectorMimeData *data = new ConnectorMimeData(connector);

    QDrag *drag = new QDrag(event->widget());
    drag->setMimeData(data);
    drag->start();
}
コード例 #23
0
ファイル: qlineedit_p.cpp プロジェクト: 2gis/2gisqt5android
void QLineEditPrivate::drag()
{
    Q_Q(QLineEdit);
    dndTimer.stop();
    QMimeData *data = new QMimeData;
    data->setText(control->selectedText());
    QDrag *drag = new QDrag(q);
    drag->setMimeData(data);
    Qt::DropAction action = drag->start();
    if (action == Qt::MoveAction && !control->isReadOnly() && drag->target() != q)
        control->removeSelection();
}
コード例 #24
0
void QGo4BrowserTreeWidget::mouseMoveEvent(QMouseEvent *event)
{
   // if not left button - return
   if (event->buttons() & Qt::LeftButton) {
      QDrag *drag = 0;
      // request from browser drag
       emit RequestDragObject(&drag);

      if (drag)
         drag->start(Qt::CopyAction | Qt::MoveAction);
   }
}
コード例 #25
0
ファイル: actionrepository.cpp プロジェクト: Fale/qtmoko
void startActionDrag(QWidget *dragParent, ActionModel *model, const QModelIndexList &indexes, Qt::DropActions supportedActions)
{
    if (indexes.empty())
        return;

    QDrag *drag = new QDrag(dragParent);
    QMimeData *data = model->mimeData(indexes);
    drag->setMimeData(data);
    if (ActionRepositoryMimeData *actionMimeData = qobject_cast<ActionRepositoryMimeData *>(data))
        drag->setPixmap(ActionRepositoryMimeData::actionDragPixmap(actionMimeData->actionList().front()));

    drag->start(supportedActions);
}
コード例 #26
0
ファイル: imagewidget.cpp プロジェクト: quazgar/kdepimlibs
void ImageWidget::mouseMoveEvent(QMouseEvent *event)
{
    if ((event->buttons() & Qt::LeftButton) &&
            (event->pos() - mDragStartPos).manhattanLength() > QApplication::startDragDistance()) {

        if (mHasImage) {
            QDrag *drag = new QDrag(this);
            drag->setMimeData(new QMimeData());
            drag->mimeData()->setImageData(mPicture.data());
            drag->start();
        }
    }
}
コード例 #27
0
ファイル: imagewidget.cpp プロジェクト: mtparet/PecsQt
void ImageWIdget::makeDrag()
{
    QDrag *dr = new QDrag(this);
    // The data to be transferred by the drag and drop operation is contained in a QMimeData object
    QMimeData *data = new QMimeData;
    data->setText(myS.img.image_file);

    // Assign ownership of the QMimeData object to the QDrag object.
    dr->setMimeData(data);
    // Start the drag and drop operation
    dr->start();

}
コード例 #28
0
ファイル: paletteTree.cpp プロジェクト: programmerr47/qreal
void PaletteTree::DraggableElement::mousePressEvent(QMouseEvent *event)
{
	QWidget *atMouse = childAt(event->pos());
	if (!atMouse || atMouse == this) {
		return;
	}

	DraggableElement *child = dynamic_cast<DraggableElement *>(atMouse->parent());
	if (!child) {
		child = dynamic_cast<DraggableElement *>(atMouse);
	}
	if (!child) {
		return;
	}

	Q_ASSERT(child->id().idSize() == 3);  // it should be element type

	// new element's ID is being generated here
	// may this epic event should take place in some more appropriate place

	Id elementId(child->id(), QUuid::createUuid().toString());

	QByteArray itemData;
	bool isFromLogicalModel = false;

	QDataStream stream(&itemData, QIODevice::WriteOnly);
	stream << elementId.toString();  // uuid
	stream << Id::rootId().toString();  // pathToItem
	stream << QString("(" + child->text() + ")");
	stream << QPointF(0, 0);
	stream << isFromLogicalModel;

	QMimeData *mimeData = new QMimeData;
	mimeData->setData("application/x-real-uml-data", itemData);

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

	QPixmap p = child->icon().pixmap(96, 96);

	if (!p.isNull()) {
		drag->setPixmap(child->icon().pixmap(96, 96));
	}

	if (drag->start(Qt::CopyAction | Qt::MoveAction) == Qt::MoveAction) {
		child->close();
	} else {
		child->show();
	}
}
コード例 #29
0
ファイル: species_widget.cpp プロジェクト: nextgis/padb
void pa_db::species_widget::mouseMoveEvent( QMouseEvent *event )
{
	if ( event->buttons() & Qt::LeftButton )
	{
		if ( currentItem() )
		{
			QDrag *drag = new QDrag( this );
			QMimeData *mimeData = new QMimeData;
			mimeData->setData( "application/x-qt-windows-mime;value=\"species_mime_data\"", currentItem()->data( Qt::UserRole ).toByteArray() );
			drag->setMimeData( mimeData );
			drag->start( Qt::CopyAction );
		}
	}
}
コード例 #30
0
void ProjectListWidget::startDrag()
{
    QListWidgetItem *item = currentItem();
    if (item) {
        QMimeData *mimeData = new QMimeData;
        mimeData->setText(item->text());

        QDrag *drag = new QDrag(this);
        drag->setMimeData(mimeData);
        drag->setPixmap(QPixmap(":/images/person.png"));
        if (drag->start(Qt::MoveAction) == Qt::MoveAction)
            delete item;
    }
}