void ChannelList::mouseMoveEvent(QMouseEvent* event){ if(dragging && event->state() == Qt::LeftButton){ QDragObject* drag = new QTextDrag(currentText(),this); drag->dragMove(); dragging = FALSE; } }
STDMETHODIMP QOleDataObject::GetData( FORMATETC *pformatetcIn, STGMEDIUM *pmedium ) { // is data is in our format? HRESULT hr = QueryGetData( pformatetcIn ); if ( hr != S_OK ) return hr; int cf = pformatetcIn->cfFormat; pmedium->tymed = TYMED_HGLOBAL; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { QByteArray ba = m_dragObj->encodedData( mime ); ba = c->convertFromMime( ba, mime, cf ); HGLOBAL hGlobal = GlobalAlloc ( GMEM_MOVEABLE | GMEM_SHARE, ba.size() ); if ( !hGlobal ) return E_OUTOFMEMORY; memcpy ( GlobalLock ( hGlobal ), ba.data(), ba.size() ); GlobalUnlock ( hGlobal ); pmedium->hGlobal = hGlobal; pmedium->pUnkForRelease = NULL; return S_OK; } } return E_UNEXPECTED; }
STDMETHODIMP QOleDataObject::GetDataHere( FORMATETC *pformatetc, STGMEDIUM *pmedium ) { // is data is in our format? HRESULT hr = QueryGetData( pformatetc ); if ( hr != S_OK ) return hr; if ( pmedium->tymed != TYMED_HGLOBAL ) return DV_E_TYMED; if ( !pmedium->hGlobal ) return STG_E_MEDIUMFULL; HGLOBAL hGlobal = pmedium->hGlobal; uint size = GlobalSize( hGlobal ); int cf = pformatetc->cfFormat; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { QByteArray ba = m_dragObj->encodedData( mime ); if ( ba.size() > size ) return STG_E_MEDIUMFULL; memcpy ( GlobalLock ( hGlobal ), ba.data(), ba.size() ); GlobalUnlock ( hGlobal ); return S_OK; } } return E_UNEXPECTED; }
STDMETHODIMP QOleDataObject::EnumFormatEtc( DWORD dwDir, IEnumFORMATETC **ppenumFormatEtc ) { if ( dwDir == DATADIR_SET ) return E_NOTIMPL; int count = 0; while ( m_dragObj->format( count ) ) count++; int *formats = new int[ count ]; for ( int i = 0; i < count; i++ ) { const char *mime = m_dragObj->format( i ); QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { int cf = c->cfFor( mime ); if ( cf ) { formats[ i ] = cf; break; } } } qIEnumFORMATETC *pEnum = new qIEnumFORMATETC( formats, count ); pEnum->AddRef(); *ppenumFormatEtc = pEnum; delete[] formats; return ResultFromScode( S_OK ); }
void KSnapshot::slotDragSnapshot() { QDragObject *drobj = new QImageDrag(snapshot.convertToImage(), this); Q_CHECK_PTR(drobj); drobj->setPixmap(mainWidget->preview()); drobj->dragCopy(); }
void mousePressEvent(QMouseEvent *e) { if(e->button() == LeftButton) { if(labeltype == Des) return; QDragObject *drobj = 0; if(pixmap()) { // 如果有圖片 // 產生QDragObject drobj = new QImageDrag(pixmap()->convertToImage(), this); QPixmap pm; // 產生縮圖 pm.convertFromImage( pixmap()->convertToImage().smoothScale(25, 25)); // 拖曳時的顯示圖形與游標位移 drobj->setPixmap(pm, QPoint(-14, -20)); } else if(text()) { // 如果有文字 drobj = new QTextDrag(text(), this); drobj->setPixmap(QPixmap("text.gif"), QPoint(-25, -15)); } // ?#125;始拖放動作 if(drobj) drobj->dragCopy(); } }
void DragListBox::mouseMoveEvent( QMouseEvent * ) { if ( dragging ) { QDragObject *drag = new QTextDrag( currentText(), this ); drag->dragMove(); dragging = FALSE; } }
void TextShow::startDrag() { QDragObject *drag = new QTextDrag(selectedText(), viewport()); if ( isReadOnly() ) { drag->dragCopy(); } else { if ( drag->drag() && QDragObject::target() != this && QDragObject::target() != viewport() ) removeSelectedText(); } }
QDragObject *KNCollectionView::dragObject() { KFolderTreeItem *item = static_cast<KFolderTreeItem *> (itemAt(viewport()->mapFromGlobal(QCursor::pos()))); if(item && item->protocol() == KFolderTreeItem::Local && item->type() == KFolderTreeItem::Other) { QDragObject *d = new QStoredDrag("x-knode-drag/folder", viewport()); d->setPixmap(SmallIcon("folder")); return d; } return 0; }
// Start a drag. void QsciScintillaQt::StartDrag() { inDragDrop = ddDragging; QDragObject *dobj = new QTextDrag(textRange(&drag), qsb->viewport()); // Remove the dragged text if it was a move to another widget or // application. if (dobj->drag() && dobj->target() != qsb->viewport()) ClearSelection(); SetDragPosition(QSCI_SCI_NAMESPACE(SelectionPosition)()); inDragDrop = ddNone; }
void DropSite::mousePressEvent( QMouseEvent * /*e*/ ) { QDragObject *d; if ( pixmap() ) { d = new QImageDrag( pixmap()->convertToImage(), this ); QPixmap pm; pm.convertFromImage(pixmap()->convertToImage().smoothScale( pixmap()->width()/3,pixmap()->height()/3)); d->setPixmap(pm,QPoint(-5,-7)); } else { d = new QTextDrag( text(), this ); } d->dragCopy(); }
QDragObject* KonqSidebarTree::dragObject() { KonqSidebarTreeItem* item = static_cast<KonqSidebarTreeItem *>( selectedItem() ); if ( !item ) return 0; QDragObject* drag = item->dragObject( viewport(), false ); if ( !drag ) return 0; const QPixmap *pix = item->pixmap(0); if ( pix && drag->pixmap().isNull() ) drag->setPixmap( *pix ); return drag; }
STDMETHODIMP QOleDataObject::QueryGetData( FORMATETC *pformatetc ) { #ifdef DEBUG_QDND_SRC qDebug( "QOleDataObject::QueryGetData( %p )", pformatetc ); #endif if ( !pformatetc ) { return E_INVALIDARG; } if ( pformatetc->lindex != -1 ) { return DV_E_LINDEX; } if ( pformatetc->dwAspect != DVASPECT_CONTENT ) { return DV_E_DVASPECT; } int tymed = pformatetc->tymed; /* Currently we only support HGLOBAL */ if ( !( tymed & TYMED_HGLOBAL ) ) { return DV_E_TYMED; } int cf = pformatetc->cfFormat; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { return S_OK; } } return DV_E_FORMATETC; }
/*! mouseMoveEvent - mouse move on the list box */ void DDListBox::mouseMoveEvent( QMouseEvent * ) { if (count() == max_items && max_items != 0 && flag) { for (unsigned int i = 0; i < count(); i++) changeItem( QPixmap( green_icon ) , text(i) , i); flag = false; } if ( dragging && item(currentItem())->isSelectable() ) { QDragObject *d = new QTextDrag( currentText() , this ); d->dragCopy(); // do NOT delete d. dragging = FALSE; unsigned int current = currentItem(); if (count() == max_items && max_items != 0) { char s[100]; strcpy(s, currentText()); char * traits; traits = strtok(s," "); traits = strtok(NULL, " "); traits = strtok(NULL, " "); traits = strtok(NULL, " "); for (unsigned int i = 0; i < max_items; i++) { char s_i[100]; strcpy(s_i, text(i)); char * traits_i; traits_i = strtok(s_i," "); traits_i = strtok(NULL, " "); traits_i = strtok(NULL, " "); traits_i = strtok(NULL, " "); bool b = (strcmp(traits,traits_i) == 0); if (!b && i != current ) { changeItem( QPixmap( white_icon ) , text(i) , i); item(i)->setSelectable( b ); } } } removeItem ( current ); } }
void Summary::mouseMoveEvent(QMouseEvent *event) { if((event->state() & LeftButton) && (event->pos() - mDragStartPoint).manhattanLength() > 4) { QDragObject *drag = new QTextDrag("", this, "SummaryWidgetDrag"); QPixmap pm = QPixmap::grabWidget(this); if(pm.width() > 300) pm = pm.convertToImage().smoothScale(300, 300, QImage::ScaleMin); QPainter painter; painter.begin(&pm); painter.setPen(Qt::gray); painter.drawRect(0, 0, pm.width(), pm.height()); painter.end(); drag->setPixmap(pm); drag->dragMove(); } else QWidget::mouseMoveEvent(event); }
void KstViewWidget::leaveEvent(QEvent *e) { //kstdDebug() << "Leave event" << endl; QWidget::leaveEvent(e); if (_view->viewMode() != KstTopLevelView::DisplayMode) { if (_menu) { return; } if (!_view->tracking()) { //kstdDebug() << "Not tracking" << endl; _view->clearFocus(); } else { //kstdDebug() << "Tracking" << endl; if (_view->trackingIsMove() && _dragEnabled) { QDragObject *d = dragObject(); if (d) { // First cancel any operations _view->cancelMouseOperations(); _view->paint(KstPainter::P_PAINT); d->drag(); } } } } }
static QByteArray qt_xdnd_obtain_data( const char * format ) { QByteArray result; QWidget* w; if ( qt_xdnd_dragsource_xid && qt_xdnd_source_object && (w=QWidget::find( qt_xdnd_dragsource_xid )) && (!w->isDesktop() || w->acceptDrops()) ) { QDragObject * o = qt_xdnd_source_object; if ( o->provides( format ) ) result = o->encodedData(format); return result; } Atom * a = qt_xdnd_str_to_atom( format ); if ( !a || !*a ) return result; if ( !qt_xdnd_target_data ) qt_xdnd_target_data = new QIntDict<QByteArray>( 17 ); if ( qt_xdnd_target_data->find( (int)*a ) ) { result = *(qt_xdnd_target_data->find( (int)*a )); } else { if ( XGetSelectionOwner( qt_xdisplay(), qt_xdnd_selection ) == None ) return result; // should never happen? QWidget* tw = qt_xdnd_current_widget; if ( !tw || qt_xdnd_current_widget->isDesktop() ) { tw = new QWidget; } XConvertSelection( qt_xdisplay(), qt_xdnd_selection, *a, qt_xdnd_selection, tw->winId(), CurrentTime ); XFlush( qt_xdisplay() ); XEvent xevent; bool got=qt_xclb_wait_for_event( qt_xdisplay(), tw->winId(), SelectionNotify, &xevent, 5000); if ( got ) { Atom type; if ( qt_xclb_read_property( qt_xdisplay(), tw->winId(), qt_xdnd_selection, TRUE, &result, 0, &type, 0, FALSE ) ) { if ( type == qt_incr_atom ) { int nbytes = result.size() >= 4 ? *((int*)result.data()) : 0; result = qt_xclb_read_incremental_property( qt_xdisplay(), tw->winId(), qt_xdnd_selection, nbytes, FALSE ); } else if ( type != *a ) { // (includes None) debug( "Qt clipboard: unknown atom %ld", type); } if ( type != None ) qt_xdnd_target_data->insert( (int)((long)a), new QByteArray(result) ); } } if ( !qt_xdnd_current_widget || qt_xdnd_current_widget->isDesktop() ) { delete tw; } } return result; }
//! [0] void MyQt3Widget::customStartDragFunction() { QDragObject *d = new QTextDrag( myHighlightedText(), this ); d->dragCopy(); // do NOT delete d. }
void Test::initiateDrag( QWidget *w ) { QDragObject *d = new QTextDrag( mWidget->label( mWidget->indexOf( w ) ), this ); d->dragCopy(); // do NOT delete d. }