Exemple #1
0
QPixmap QDragManager::dragCursor(Qt::DropAction action) const
{
    QDragPrivate * d = dragPrivate();
    if (d && d->customCursors.contains(action))
        return d->customCursors[action];
    else if (action == Qt::MoveAction)
        return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragMoveCursor);
    else if (action == Qt::CopyAction)
        return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragCopyCursor);
    else if (action == Qt::LinkAction)
        return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragLinkCursor);
#ifdef Q_WS_WIN
    else if (action == Qt::IgnoreAction)
        return QApplicationPrivate::instance()->getPixmapCursor(Qt::ForbiddenCursor);
#endif
    return QPixmap();
}
QPixmap QDragManager::dragCursor(Qt::DropAction action) const
{
    QDragPrivate * d = dragPrivate();
    if (d && d->customCursors.contains(action))
        return d->customCursors[action];
    else if (action == Qt::MoveAction)
        return pm_cursor[0];
    else if (action == Qt::CopyAction)
        return pm_cursor[1];
    else if (action == Qt::LinkAction)
        return pm_cursor[2];
#ifdef Q_WS_WIN
    else if (action == Qt::IgnoreAction)
        return pm_cursor[3];
#endif
    return QPixmap();
}
Qt::DropAction QDragManager::drag(QDrag *o)
{
    Q_ASSERT(!qt_symbian_dnd_dragging);
    if (object == o || !o || !o->source())
         return Qt::IgnoreAction;

    if (object) {
        cancel();
        qApp->removeEventFilter(this);
        beingCancelled = false;
    }

    object = drag_object = o;

    oldstate = Qt::NoModifier; // #### Should use state that caused the drag
    willDrop = false;
    updatePixmap();
    updateCursor();

#ifndef QT_NO_CURSOR
    qt_symbian_set_cursor_visible(true); //force cursor on even for touch phone
#endif

    object->d_func()->target = 0;

    qApp->installEventFilter(this);

    global_accepted_action = defaultAction(dragPrivate()->possible_actions, Qt::NoModifier);
    qt_symbian_dnd_dragging = true;

    eventLoop = new QEventLoop;
    // block
    (void) eventLoop->exec(QEventLoop::AllEvents);
    delete eventLoop;
    eventLoop = 0;

#ifndef QT_NO_CURSOR
    qt_symbian_set_cursor_visible(false);

    overrideCursor = QCursor(); //deref the cursor data
    qt_symbian_dnd_dragging = false;
#endif

    return global_accepted_action;
}
Qt::DropAction QDragManager::defaultAction(Qt::DropActions possibleActions,
                                           Qt::KeyboardModifiers modifiers) const
{
#ifdef QDND_DEBUG
    qDebug("QDragManager::defaultAction(Qt::DropActions possibleActions)");
    qDebug("keyboard modifiers : %s", KeyboardModifiersToString(modifiers).latin1());
#endif

    QDragPrivate *d = dragPrivate();
    Qt::DropAction defaultAction = d ? d->defaultDropAction : Qt::IgnoreAction;

    if (defaultAction == Qt::IgnoreAction) {
        //This means that the drag was initiated by QDrag::start and we need to
        //preserve the old behavior
#ifdef Q_WS_MAC
        defaultAction = Qt::MoveAction;
#else
        defaultAction = Qt::CopyAction;
#endif
    }

#ifdef Q_WS_MAC
    if (modifiers & Qt::ControlModifier && modifiers & Qt::AltModifier)
        defaultAction = Qt::LinkAction;
    else if (modifiers & Qt::AltModifier)
        defaultAction = Qt::CopyAction;
    else if (modifiers & Qt::ControlModifier)
        defaultAction = Qt::MoveAction;
#else
    if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier)
        defaultAction = Qt::LinkAction;
    else if (modifiers & Qt::ControlModifier)
        defaultAction = Qt::CopyAction;
    else if (modifiers & Qt::ShiftModifier)
        defaultAction = Qt::MoveAction;
    else if (modifiers & Qt::AltModifier)
        defaultAction = Qt::LinkAction;
#endif

    // if the object is set take the list of possibles from it
    if (object)
        possibleActions = object->d_func()->possible_actions;

#ifdef QDND_DEBUG
    qDebug("possible actions : %s", dragActionsToString(possibleActions).latin1());
#endif

    // Check if the action determined is allowed
    if (!(possibleActions & defaultAction)) {
        if (possibleActions & Qt::CopyAction)
            defaultAction = Qt::CopyAction;
        else if (possibleActions & Qt::MoveAction)
            defaultAction = Qt::MoveAction;
        else if (possibleActions & Qt::LinkAction)
            defaultAction = Qt::LinkAction;
        else
            defaultAction = Qt::IgnoreAction;
    }

#ifdef QDND_DEBUG
    qDebug("default action : %s", dragActionsToString(defaultAction).latin1());
#endif

    return defaultAction;
}
bool QDragManager::hasCustomDragCursors() const
{
    QDragPrivate * d = dragPrivate();
    return d && !d->customCursors.isEmpty();
}