Qt 4.8
Public Functions | Properties | List of all members
QOleDropSource Class Reference
Inheritance diagram for QOleDropSource:

Public Functions

void createCursors ()
 
STDMETHOD() GiveFeedback (DWORD dwEffect)
 
 QOleDropSource ()
 
STDMETHOD() QueryContinueDrag (BOOL fEscapePressed, DWORD grfKeyState)
 
STDMETHOD() QueryInterface (REFIID riid, void **ppvObj)
 
 STDMETHOD_ (ULONG, AddRef)(void)
 
 STDMETHOD_ (ULONG, Release)(void)
 
virtual ~QOleDropSource ()
 

Properties

Qt::DropAction currentAction
 
Qt::MouseButtons currentButtons
 
QMap< Qt::DropAction, QCursorcursors
 
ULONG m_refs
 

Detailed Description

Definition at line 346 of file qdnd_win.cpp.

Constructors and Destructors

◆ QOleDropSource()

QOleDropSource::QOleDropSource ( )

Definition at line 372 of file qdnd_win.cpp.

373 {
375  m_refs = 1;
377 }
Qt::MouseButtons currentButtons
Definition: qdnd_win.cpp:364
Qt::DropAction currentAction
Definition: qdnd_win.cpp:365

◆ ~QOleDropSource()

QOleDropSource::~QOleDropSource ( )
virtual

Definition at line 379 of file qdnd_win.cpp.

380 {
381 }

Functions

◆ createCursors()

void QOleDropSource::createCursors ( )

Definition at line 383 of file qdnd_win.cpp.

Referenced by QOleDropTarget::Drop().

384 {
385  QDragManager *manager = QDragManager::self();
386  if (manager && manager->object
387  && (!manager->object->pixmap().isNull()
388  || manager->hasCustomDragCursors())) {
389  QPixmap pm = manager->object->pixmap();
390  QList<Qt::DropAction> actions;
392  if (!manager->object->pixmap().isNull())
393  actions << Qt::IgnoreAction;
394  QPoint hotSpot = manager->object->hotSpot();
395  for (int cnum = 0; cnum < actions.size(); ++cnum) {
396  QPixmap cpm = manager->dragCursor(actions.at(cnum));
397  int w = cpm.width();
398  int h = cpm.height();
399 
400  if (!pm.isNull()) {
401  int x1 = qMin(-hotSpot.x(), 0);
402  int x2 = qMax(pm.width() - hotSpot.x(), cpm.width());
403  int y1 = qMin(-hotSpot.y(), 0);
404  int y2 = qMax(pm.height() - hotSpot.y(), cpm.height());
405 
406  w = x2 - x1 + 1;
407  h = y2 - y1 + 1;
408  }
409 
410  QRect srcRect = pm.rect();
411  QPoint pmDest = QPoint(qMax(0, -hotSpot.x()), qMax(0, -hotSpot.y()));
412  QPoint newHotSpot = hotSpot;
413 
414 #if defined(Q_OS_WINCE)
415  // Limited cursor size
416  int reqw = GetSystemMetrics(SM_CXCURSOR);
417  int reqh = GetSystemMetrics(SM_CYCURSOR);
418 
419  QPoint hotspotInPM = newHotSpot - pmDest;
420  if (reqw < w) {
421  // Not wide enough - move objectpm right
422  qreal r = qreal(newHotSpot.x()) / w;
423  newHotSpot = QPoint(int(r * reqw), newHotSpot.y());
424  if (newHotSpot.x() + cpm.width() > reqw)
425  newHotSpot.setX(reqw - cpm.width());
426 
427  srcRect = QRect(QPoint(hotspotInPM.x() - newHotSpot.x(), srcRect.top()), QSize(reqw, srcRect.height()));
428  }
429  if (reqh < h) {
430  qreal r = qreal(newHotSpot.y()) / h;
431  newHotSpot = QPoint(newHotSpot.x(), int(r * reqh));
432  if (newHotSpot.y() + cpm.height() > reqh)
433  newHotSpot.setY(reqh - cpm.height());
434 
435  srcRect = QRect(QPoint(srcRect.left(), hotspotInPM.y() - newHotSpot.y()), QSize(srcRect.width(), reqh));
436  }
437  // Always use system cursor size
438  w = reqw;
439  h = reqh;
440 #endif
441 
442  QPixmap newCursor(w, h);
443  if (!pm.isNull()) {
444  newCursor.fill(QColor(0, 0, 0, 0));
445  QPainter p(&newCursor);
446  p.drawPixmap(pmDest, pm, srcRect);
447  p.drawPixmap(qMax(0,newHotSpot.x()),qMax(0,newHotSpot.y()),cpm);
448  } else {
449  newCursor = cpm;
450  }
451 
452 #ifndef QT_NO_CURSOR
453  cursors[actions.at(cnum)] = QCursor(newCursor, pm.isNull() ? 0 : qMax(0,newHotSpot.x()),
454  pm.isNull() ? 0 : qMax(0,newHotSpot.y()));
455 #endif
456  }
457  }
458 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QMap< Qt::DropAction, QCursor > cursors
Definition: qdnd_win.cpp:366
double qreal
Definition: qglobal.h:1193
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QDrag * object
Definition: qdnd_p.h:238
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QPixmap pixmap() const
Returns the pixmap used to represent the data in a drag and drop operation.
Definition: qdrag.cpp:175
static QDragManager * self()
Definition: qdnd.cpp:163
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
#define SM_CYCURSOR
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QPixmap dragCursor(Qt::DropAction action) const
Definition: qdnd.cpp:170
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
#define SM_CXCURSOR
bool hasCustomDragCursors() const
Definition: qdnd.cpp:188
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
QPoint hotSpot() const
Returns the position of the hot spot relative to the top-left corner of the cursor.
Definition: qdrag.cpp:199
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ GiveFeedback()

QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QOleDropSource::GiveFeedback ( DWORD  dwEffect)

Definition at line 551 of file qdnd_win.cpp.

552 {
553  Qt::DropAction action = translateToQDragDropAction(dwEffect);
554 
555 #ifdef QDND_DEBUG
556  qDebug("QOleDropSource::GiveFeedback(DWORD dwEffect)");
557  qDebug("dwEffect = %s", dragActionsToString(action).toLatin1().data());
558 #endif
559 
560  if (currentAction != action) {
561  currentAction = action;
563  }
564 
566 #ifndef QT_NO_CURSOR
567  SetCursor(cursors[currentAction].handle());
568 #endif
569  return ResultFromScode(S_OK);
570  }
571 
572  return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
573 }
QMap< Qt::DropAction, QCursor > cursors
Definition: qdnd_win.cpp:366
Qt::DropAction translateToQDragDropAction(DWORD pdwEffect)
Definition: qdnd_win.cpp:295
void emitActionChanged(Qt::DropAction newAction)
Definition: qdnd_p.h:253
Q_CORE_EXPORT void qDebug(const char *,...)
static const char * data(const QByteArray &arr)
DropAction
Definition: qnamespace.h:1597
static QDragManager * self()
Definition: qdnd.cpp:163
Qt::DropAction currentAction
Definition: qdnd_win.cpp:365
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553

◆ QueryContinueDrag()

QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP QOleDropSource::QueryContinueDrag ( BOOL  fEscapePressed,
DWORD  grfKeyState 
)

Definition at line 519 of file qdnd_win.cpp.

520 {
521 #ifdef QDND_DEBUG
522  qDebug("QOleDropSource::QueryContinueDrag(fEscapePressed %d, grfKeyState %d)", fEscapePressed, grfKeyState);
523 #endif
524 
525  if (fEscapePressed) {
526  return ResultFromScode(DRAGDROP_S_CANCEL);
527  } else if ((GetAsyncKeyState(VK_LBUTTON) == 0)
528  && (GetAsyncKeyState(VK_MBUTTON) == 0)
529  && (GetAsyncKeyState(VK_RBUTTON) == 0)) {
530  // grfKeyState is broken on CE & some Windows XP versions,
531  // therefore we need to check the state manually
532  return ResultFromScode(DRAGDROP_S_DROP);
533  } else {
534 #if !defined(Q_OS_WINCE)
535  if (currentButtons == Qt::NoButton) {
537  } else {
538  Qt::MouseButtons buttons = keystate_to_mousebutton(grfKeyState);
539  if (!(currentButtons & buttons))
540  return ResultFromScode(DRAGDROP_S_DROP);
541  }
542 #else
543  Q_UNUSED(grfKeyState);
544 #endif
546  return NOERROR;
547  }
548 }
Qt::MouseButtons currentButtons
Definition: qdnd_win.cpp:364
static Qt::MouseButtons buttons
static Qt::MouseButtons keystate_to_mousebutton(DWORD grfKeyState)
Definition: qdnd_win.cpp:499
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
Q_CORE_EXPORT void qDebug(const char *,...)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ QueryInterface()

STDMETHODIMP QOleDropSource::QueryInterface ( REFIID  riid,
void **  ppvObj 
)

Definition at line 468 of file qdnd_win.cpp.

469 {
470  if(iid == IID_IUnknown || iid == IID_IDropSource)
471  {
472  *ppv = this;
473  ++m_refs;
474  return NOERROR;
475  }
476  *ppv = NULL;
477  return ResultFromScode(E_NOINTERFACE);
478 }

◆ STDMETHOD_() [1/2]

QOleDropSource::STDMETHOD_ ( ULONG  ,
AddRef   
)

◆ STDMETHOD_() [2/2]

QOleDropSource::STDMETHOD_ ( ULONG  ,
Release   
)

Properties

◆ currentAction

Qt::DropAction QOleDropSource::currentAction
private

Definition at line 365 of file qdnd_win.cpp.

◆ currentButtons

Qt::MouseButtons QOleDropSource::currentButtons
private

Definition at line 364 of file qdnd_win.cpp.

◆ cursors

QMap<Qt::DropAction, QCursor> QOleDropSource::cursors
private

Definition at line 366 of file qdnd_win.cpp.

◆ m_refs

ULONG QOleDropSource::m_refs
private

Definition at line 368 of file qdnd_win.cpp.


The documentation for this class was generated from the following file: