예제 #1
0
MouseMachine::MouseMachine(QWidget* parent, MouseMachine::Options options)
 : QObject(parent)
    , theParent(parent)
    , m_options(options)
    , machine(0)
    , trPressed2Idle(0)
    , trPressed2Man(0)
    , trManScrolling(0)
    , trIdle2Pressed(0)
    , trMan2Auto(0)
    , trMan2Idle(0)
    , trAuto2Idle(0)
    , trAuto2Man(0)
    , trDoubleclick(0)
{
#ifdef Q_OS_SYMBIAN
    iTouchFeedback = MTouchFeedback::Instance();
#endif

    speedTimer.setInterval(SPEED_INTERVAL);
    connect(&speedTimer, SIGNAL(timeout()), SLOT(slotCalculateSpeed()));

    dblclickTimer.setInterval(DBLCLICK_INTERVAL);
    dblclickTimer.setSingleShot(true);
    connect(&dblclickTimer, SIGNAL(timeout()), SLOT(slotSingleTap()));

    scrollTimeline.setCurveShape(QTimeLine::EaseOutCurve);
    scrollTimeline.setEasingCurve(QEasingCurve::OutQuad);
    connect(&scrollTimeline, SIGNAL(valueChanged(qreal)), SLOT(slotAutoscroll(qreal)));
    connect(&scrollTimeline, SIGNAL(finished()), SLOT(slotAutoscrollFinished()));

    tapHoldTimer.setInterval(TAPHOLD_TIMEOUT);
    tapHoldTimer.setSingleShot(true);

    theTarget = theParent;
    QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(theParent);
    if (scrollArea) {
        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

        theTarget = scrollArea->viewport();
        theTarget->installEventFilter(this);
    }
    theParent->installEventFilter(this);

    buildMachine();
    machine->start();
}
예제 #2
0
void FlickCharm::activateOn(QWidget *widget)
{
    QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
    if (scrollArea) {
        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

        QWidget *viewport = scrollArea->viewport();

        viewport->installEventFilter(this);
        scrollArea->installEventFilter(this);

        d->flickData.remove(viewport);
        d->flickData[viewport] = new FlickData;
        d->flickData[viewport]->widget = widget;
        d->flickData[viewport]->state = FlickData::Steady;

        return;
    }

    QWebView *webView = qobject_cast<QWebView*>(widget);
    if (webView) {
        QWebFrame *frame = webView->page()->mainFrame();
        frame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
        frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);

        webView->installEventFilter(this);

        d->flickData.remove(webView);
        d->flickData[webView] = new FlickData;
        d->flickData[webView]->widget = webView;
        d->flickData[webView]->state = FlickData::Steady;

        return;
    }

    qWarning() << "FlickCharm only works on QAbstractScrollArea (and derived classes)";
    qWarning() << "or QWebView (and derived classes)";
}