void CCardLabel::mouseMoveEvent(QMouseEvent *ev) { if (mLockButton) { mLockButton->setVisible(mLockButton->isChecked() || (mCard.isValid() && mLockButton->geometry().contains(ev->pos()))); } if (mLastLeftClickPos && mCard.isValid()) { QLineF moveLine(ev->globalPos(), *mLastLeftClickPos); if (moveLine.length() >= QApplication::startDragDistance()) { QDrag *drag = new QDrag(this); QMimeData *dragData = createCardLabelDropData(*this); drag->setMimeData(dragData); drag->setHotSpot(ev->pos()); const QPixmap *unitImg = pixmap(); if (unitImg) { int w = unitImg->width() / 2; int h = unitImg->height() / 2; QPixmap dragImg(w, h); dragImg.fill(Qt::transparent); QPainter painter(&dragImg); painter.setOpacity(0.75); painter.drawPixmap(0, 0, w, h, unitImg->scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter.end(); drag->setPixmap(dragImg); } if (QApplication::keyboardModifiers() == Qt::ControlModifier || !acceptDrops()) { drag->exec(Qt::CopyAction); } else { CCard cardBuf = mCard; bool lockBuf = isLocked(); setCard(CCard::INVALID_CARD); setLocked(false); if (!drag->exec(Qt::MoveAction)) { setCard(cardBuf); setLocked(lockBuf); } } delete mLastLeftClickPos; mLastLeftClickPos = 0; emit unitDragged(); } } }
void AnimationButton::mouseMoveEvent(QMouseEvent* e) { if (_dragging) { // If the left button isn't pressed anymore then return if ( !buttonDownIsLeft(e) ) { return; } // If the distance is too small then return if ( (e->pos() - _dragPos).manhattanLength() < QApplication::startDragDistance() ) { return; } // initiate Drag _knob->onCopyAnimationActionTriggered(); QDrag* drag = new QDrag(this); QMimeData* mimeData = new QMimeData; mimeData->setData("Animation", ""); drag->setMimeData(mimeData); QFontMetrics fmetrics = fontMetrics(); QString textFirstLine( tr("Copying animation from:") ); QString textSecondLine( _knob->getKnob()->getDescription().c_str() ); QString textThirdLine( tr("Drag it to another animation button.") ); int textWidth = std::max( std::max( fmetrics.width(textFirstLine), fmetrics.width(textSecondLine) ),fmetrics.width(textThirdLine) ); QImage dragImg(textWidth,(fmetrics.height() + 5) * 3,QImage::Format_ARGB32); dragImg.fill( QColor(243,137,0) ); QPainter p(&dragImg); p.drawText(QPointF(0,dragImg.height() - 2.5), textThirdLine); p.drawText(QPointF(0,dragImg.height() - fmetrics.height() - 5), textSecondLine); p.drawText(QPointF(0,dragImg.height() - fmetrics.height() * 2 - 10), textFirstLine); drag->setPixmap( QPixmap::fromImage(dragImg) ); setDown(false); drag->exec(); } else { QPushButton::mouseMoveEvent(e); } }