Esempio n. 1
0
bool QDeclarativeMouseArea::setPressed(bool p)
{
    Q_D(QDeclarativeMouseArea);
    bool dragged = d->drag && d->drag->active();
    bool isclick = d->pressed == true && p == false && dragged == false && d->hovered == true;

    if (d->pressed != p) {
        d->pressed = p;
        QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress);
        if (d->pressed) {
            if (!d->doubleClick)
                emit pressed(&me);
            me.setX(d->lastPos.x());
            me.setY(d->lastPos.y());
            emit mousePositionChanged(&me);
            emit pressedChanged();
        } else {
            emit released(&me);
            me.setX(d->lastPos.x());
            me.setY(d->lastPos.y());
            emit pressedChanged();
            if (isclick && !d->longPress && !d->doubleClick)
                emit clicked(&me);
        }

        return me.isAccepted();
    }
    return false;
}
Esempio n. 2
0
PushButton::PushButton(QGraphicsWidget *parent)
    : QGraphicsProxyWidget(parent),
      d(new PushButtonPrivate(this))
{
    d->background = new FrameSvg(this);
    d->background->setImagePath("widgets/button");
    d->background->setCacheAllRenderedFrames(true);

    d->background->setElementPrefix("normal");

    d->hoverAnimation = Animator::create(Animator::PixmapTransitionAnimation);
    d->hoverAnimation->setTargetWidget(this);

    KPushButton *native = new KPushButton;
    connect(native, SIGNAL(pressed()), this, SIGNAL(pressed()));
    connect(native, SIGNAL(pressed()), this, SLOT(pressedChanged()));
    connect(native, SIGNAL(released()), this, SIGNAL(released()));
    connect(native, SIGNAL(released()), this, SLOT(pressedChanged()));
    connect(native, SIGNAL(clicked()), this, SIGNAL(clicked()));
    connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
    setWidget(native);
    native->setAttribute(Qt::WA_NoSystemBackground);
    native->setWindowIcon(QIcon());

    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

    d->focusIndicator = new FocusIndicator(this, d->background);

    d->syncBorders();
    setAcceptHoverEvents(true);

    connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
    d->initTheming();
    d->syncFrame();
}
Esempio n. 3
0
bool QQuickMouseArea::setPressed(Qt::MouseButton button, bool p)
{
    Q_D(QQuickMouseArea);

#ifndef QT_NO_DRAGANDDROP
    bool dragged = d->drag && d->drag->active();
#else
    bool dragged = false;
#endif
    bool wasPressed = d->pressed & button;
    bool isclick = wasPressed && p == false && dragged == false && d->hovered == true;
    Qt::MouseButtons oldPressed = d->pressed;

    if (wasPressed != p) {
        QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress);
        if (p) {
            d->pressed |= button;
            if (!d->doubleClick)
                emit pressed(&me);
            me.setPosition(d->lastPos);
            emit mouseXChanged(&me);
            me.setPosition(d->lastPos);
            emit mouseYChanged(&me);
            if (!oldPressed) {
                emit pressedChanged();
                emit containsPressChanged();
            }
            emit pressedButtonsChanged();
        } else {
            d->pressed &= ~button;
            emit released(&me);
            me.setPosition(d->lastPos);
            if (!d->pressed) {
                emit pressedChanged();
                emit containsPressChanged();
            }
            emit pressedButtonsChanged();
            if (isclick && !d->longPress && !d->doubleClick){
                me.setAccepted(d->isClickConnected());
                emit clicked(&me);
                if (!me.isAccepted())
                    d->propagate(&me, QQuickMouseAreaPrivate::Click);
            }
        }

        return me.isAccepted();
    }
    return false;
}
Esempio n. 4
0
void QQuickMouseArea::ungrabMouse()
{
    Q_D(QQuickMouseArea);
    if (d->pressed) {
        // if our mouse grab has been removed (probably by Flickable), fix our
        // state
        d->pressed = 0;
        d->stealMouse = false;
        d->doubleClick = false;
        setKeepMouseGrab(false);

#ifndef QT_NO_DRAGANDDROP
        if (d->drag)
            d->drag->setActive(false);
#endif

        emit canceled();
        emit pressedChanged();
        emit containsPressChanged();
        emit pressedButtonsChanged();

        if (d->hovered && !isUnderMouse()) {
            d->hovered = false;
            emit hoveredChanged();
        }
    }
}
Esempio n. 5
0
/*!
    \qmlproperty bool QtQuick::TouchPoint::pressed

    This property holds whether the touch point is currently pressed.
*/
void QQuickTouchPoint::setPressed(bool pressed)
{
    if (_pressed == pressed)
        return;
    _pressed = pressed;
    emit pressedChanged();
}
void MaskedMouseArea::setPressed(bool pressed)
{
    if (m_pressed != pressed) {
        m_pressed = pressed;
        emit pressedChanged();
    }
}
Esempio n. 7
0
bool QDeclarativeGeoMapMouseArea::setPressed(bool pressed, QDeclarativeGeoMapMouseEvent *event)
{
    if (pressed_ == pressed)
        return false;

    bool isClick = pressed_ && !pressed;// && hovered_;

    pressed_ = pressed;

    if (pressed_) {
        if (!doubleClick_)
            emit QDeclarativeGeoMapMouseArea::pressed(event);
    } else {
        emit released(event);
        // TODO set saved position in event?
        if (isClick && !longPress_ && !doubleClick_) {
            emit clicked(event);

        }
    }

    emit pressedChanged(pressed_);

    return event->accepted();
}
Esempio n. 8
0
bool QDeclarativeMouseArea::sendMouseEvent(QGraphicsSceneMouseEvent *event)
{
    Q_D(QDeclarativeMouseArea);
    QGraphicsSceneMouseEvent mouseEvent(event->type());
    QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect();

    QGraphicsScene *s = scene();
    QDeclarativeItem *grabber = s ? qobject_cast<QDeclarativeItem*>(s->mouseGrabberItem()) : 0;
    bool stealThisEvent = d->stealMouse;
    if ((stealThisEvent || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) {
        mouseEvent.setAccepted(false);
        for (int i = 0x1; i <= 0x10; i <<= 1) {
            if (event->buttons() & i) {
                Qt::MouseButton button = Qt::MouseButton(i);
                mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button)));
            }
        }
        mouseEvent.setScenePos(event->scenePos());
        mouseEvent.setLastScenePos(event->lastScenePos());
        mouseEvent.setPos(mapFromScene(event->scenePos()));
        mouseEvent.setLastPos(mapFromScene(event->lastScenePos()));

        switch(mouseEvent.type()) {
        case QEvent::GraphicsSceneMouseMove:
            mouseMoveEvent(&mouseEvent);
            break;
        case QEvent::GraphicsSceneMousePress:
            mousePressEvent(&mouseEvent);
            break;
        case QEvent::GraphicsSceneMouseRelease:
            mouseReleaseEvent(&mouseEvent);
            break;
        default:
            break;
        }
        grabber = qobject_cast<QDeclarativeItem*>(s->mouseGrabberItem());
        if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this)
            grabMouse();

        return stealThisEvent;
    }
    if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) {
        if (d->pressed) {
            d->pressed = false;
            d->stealMouse = false;
            if (s && s->mouseGrabberItem() == this)
                ungrabMouse();
            emit canceled();
            emit pressedChanged();
            if (d->hovered) {
                d->hovered = false;
                emit hoveredChanged();
            }
        }
    }
    return false;
}
Esempio n. 9
0
void KeyOutputEvent::setPressed(bool pressed)
{
  if(pressed != _pressed)
  {
    _pressed = pressed;
    emit pressedChanged(_pressed);
    emit event(getType(), getCode(), pressed ? 1 : 0);
  }
}
Esempio n. 10
0
bool QQuickMouseArea::sendMouseEvent(QMouseEvent *event)
{
    Q_D(QQuickMouseArea);
    QPointF localPos = mapFromScene(event->windowPos());

    QQuickWindow *c = window();
    QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
    bool stealThisEvent = d->stealMouse;
    if ((stealThisEvent || contains(localPos)) && (!grabber || !grabber->keepMouseGrab())) {
        QMouseEvent mouseEvent(event->type(), localPos, event->windowPos(), event->screenPos(),
                               event->button(), event->buttons(), event->modifiers());
        mouseEvent.setAccepted(false);

        switch (event->type()) {
        case QEvent::MouseMove:
            mouseMoveEvent(&mouseEvent);
            break;
        case QEvent::MouseButtonPress:
            mousePressEvent(&mouseEvent);
            break;
        case QEvent::MouseButtonRelease:
            mouseReleaseEvent(&mouseEvent);
            stealThisEvent = d->stealMouse;
            break;
        default:
            break;
        }
        grabber = c ? c->mouseGrabberItem() : 0;
        if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this)
            grabMouse();

        return stealThisEvent;
    }
    if (event->type() == QEvent::MouseButtonRelease) {
        if (d->pressed) {
            d->pressed &= ~event->button();
            emit pressedButtonsChanged();
            if (!d->pressed) {
                // no other buttons are pressed
                d->stealMouse = false;
                if (c && c->mouseGrabberItem() == this)
                    ungrabMouse();
                emit canceled();
                emit pressedChanged();
                emit containsPressChanged();
                if (d->hovered) {
                    d->hovered = false;
                    emit hoveredChanged();
                }
            }
        }
    }
    return false;
}
Esempio n. 11
0
bool QDeclarativeMouseArea::sceneEvent(QEvent *event)
{
    bool rv = QDeclarativeItem::sceneEvent(event);
    if (event->type() == QEvent::UngrabMouse) {
        Q_D(QDeclarativeMouseArea);
        if (d->pressed) {
            // if our mouse grab has been removed (probably by Flickable), fix our
            // state
            d->pressed = false;
            setKeepMouseGrab(false);
            QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, false);
            emit released(&me);
            emit pressedChanged();
            setHovered(false);
        }
    }
    return rv;
}
Esempio n. 12
0
void QQuickMouseArea::ungrabMouse()
{
    Q_D(QQuickMouseArea);
    if (d->pressed) {
        // if our mouse grab has been removed (probably by Flickable), fix our
        // state
        d->pressed = 0;
        d->stealMouse = false;
        setKeepMouseGrab(false);
        emit canceled();
        emit pressedChanged();
        emit pressedButtonsChanged();
        if (d->hovered) {
            d->hovered = false;
            emit hoveredChanged();
        }
    }
}
Esempio n. 13
0
bool QDeclarativeMouseArea::sceneEvent(QEvent *event)
{
    bool rv = QDeclarativeItem::sceneEvent(event);
    if (event->type() == QEvent::UngrabMouse) {
        Q_D(QDeclarativeMouseArea);
        if (d->pressed) {
            // if our mouse grab has been removed (probably by Flickable), fix our
            // state
            d->pressed = false;
            setKeepMouseGrab(false);
            emit canceled();
            emit pressedChanged();
            if (d->hovered) {
                d->hovered = false;
                emit hoveredChanged();
            }
        }
    }
    return rv;
}