Ignore:
Timestamp:
Mar 8, 2010, 12:52:58 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.2 sources.

Location:
trunk
Files:
21 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/demos/embedded/anomaly/anomaly.pro

    r561 r651  
    99    src/flickcharm.h \
    1010    src/ZoomStrip.h \
    11     src/ControlStrip.h
     11    src/ControlStrip.h \
     12    src/webview.h
    1213SOURCES += src/Main.cpp \
    1314    src/BrowserWindow.cpp \
     
    1920    src/flickcharm.cpp \
    2021    src/ZoomStrip.cpp \
    21     src/ControlStrip.cpp
     22    src/ControlStrip.cpp \
     23    src/webview.cpp
    2224RESOURCES += src/anomaly.qrc
    2325
  • trunk/demos/embedded/anomaly/src/AddressBar.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/AddressBar.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/BookmarksView.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/BookmarksView.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/BrowserView.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4949#include "TitleBar.h"
    5050#include "flickcharm.h"
     51
    5152#include "ZoomStrip.h"
    5253
     
    6364{
    6465    m_titleBar = new TitleBar(this);
    65     m_webView = new QWebView(this);
     66    m_webView = new WebView(this);
    6667    m_zoomStrip = new ZoomStrip(this);
    6768    m_controlStrip = new ControlStrip(this);
     
    9697    connect(m_webView, SIGNAL(urlChanged(QUrl)), SLOT(updateTitleBar()));
    9798
    98     m_webView->setHtml("Will try to load page soon!");
     99    m_webView->setHtml("");
    99100    m_webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    100101    m_webView->setFocus();
  • trunk/demos/embedded/anomaly/src/BrowserView.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5050class TitleBar;
    5151class ControlStrip;
     52
    5253class ZoomStrip;
    5354
     
    8283private:
    8384    TitleBar *m_titleBar;
    84     QWebView *m_webView;
     85    WebView *m_webView;
    8586    ZoomStrip *m_zoomStrip;
    8687    ControlStrip *m_controlStrip;
     
    9192
    9293#endif // BROWSERVIEW_H
     94
  • trunk/demos/embedded/anomaly/src/BrowserWindow.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/BrowserWindow.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/ControlStrip.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/ControlStrip.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/HomeView.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/HomeView.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/Main.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/TitleBar.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/TitleBar.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/ZoomStrip.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/ZoomStrip.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/demos/embedded/anomaly/src/flickcharm.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5050#include <QMouseEvent>
    5151#include <QScrollBar>
     52
    5253#include <QWebFrame>
    5354#include <QWebView>
     
    5556#include <QDebug>
    5657
     58
     59
    5760struct FlickData {
    58     typedef enum { Steady, Pressed, ManualScroll, AutoScroll, Stop } State;
     61    typedef enum {
     62        Steady, // Interaction without scrolling
     63        ManualScroll, // Scrolling manually with the finger on the screen
     64        AutoScroll, // Scrolling automatically
     65        AutoScrollAcceleration // Scrolling automatically but a finger is on the screen
     66    } State;
    5967    State state;
    6068    QWidget *widget;
    6169    QPoint pressPos;
    62     QPoint offset;
    63     QPoint dragPos;
     70    QPoint lastPos;
    6471    QPoint speed;
     72
    6573    QList<QEvent*> ignored;
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
    66158};
    67159
     
    71163    QHash<QWidget*, FlickData*> flickData;
    72164    QBasicTimer ticker;
     165
     166
     167
     168
     169
     170
     171
    73172};
    74173
     
    149248}
    150249
    151 static QPoint scrollOffset(QWidget *widget)
    152 {
    153     int x = 0, y = 0;
    154 
    155     QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
    156     if (scrollArea) {
    157         x = scrollArea->horizontalScrollBar()->value();
    158         y = scrollArea->verticalScrollBar()->value();
    159     }
    160 
    161     QWebView *webView = qobject_cast<QWebView*>(widget);
    162     if (webView) {
    163         QWebFrame *frame = webView->page()->mainFrame();
    164         x = frame->evaluateJavaScript("window.scrollX").toInt();
    165         y = frame->evaluateJavaScript("window.scrollY").toInt();
    166     }
    167 
     250static QPoint deaccelerate(const QPoint &speed, const int deltatime)
     251{
     252    const int deltaSpeed = deltatime;
     253
     254    int x = speed.x();
     255    int y = speed.y();
     256    x = (x == 0) ? x : (x > 0) ? qMax(0, x - deltaSpeed) : qMin(0, x + deltaSpeed);
     257    y = (y == 0) ? y : (y > 0) ? qMax(0, y - deltaSpeed) : qMin(0, y + deltaSpeed);
    168258    return QPoint(x, y);
    169259}
    170260
    171 static void setScrollOffset(QWidget *widget, const QPoint &p)
    172 {
    173     QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
    174     if (scrollArea) {
    175         scrollArea->horizontalScrollBar()->setValue(p.x());
    176         scrollArea->verticalScrollBar()->setValue(p.y());
    177     }
    178 
    179     QWebView *webView = qobject_cast<QWebView*>(widget);
    180     QWebFrame *frame = webView ? webView->page()->mainFrame() : 0;
    181     if (frame)
    182         frame->evaluateJavaScript(QString("window.scrollTo(%1,%2);").arg(p.x()).arg(p.y()));
    183 }
    184 
    185 static QPoint deaccelerate(const QPoint &speed, int a = 1, int max = 64)
    186 {
    187     int x = qBound(-max, speed.x(), max);
    188     int y = qBound(-max, speed.y(), max);
    189     x = (x == 0) ? x : (x > 0) ? qMax(0, x - a) : qMin(0, x + a);
    190     y = (y == 0) ? y : (y > 0) ? qMax(0, y - a) : qMin(0, y + a);
    191     return QPoint(x, y);
    192 }
    193 
    194261bool FlickCharm::eventFilter(QObject *object, QEvent *event)
    195262{
     
    197264        return false;
    198265
    199     QEvent::Type type = event->type();
    200     if (type != QEvent::MouseButtonPress &&
    201             type != QEvent::MouseButtonRelease &&
    202             type != QEvent::MouseMove)
    203         return false;
    204 
    205     QMouseEvent *mouseEvent = 0;
    206     switch (event->type()) {
    207         case QEvent::MouseButtonPress:
    208         case QEvent::MouseButtonRelease:
    209         case QEvent::MouseMove:
    210             mouseEvent = static_cast<QMouseEvent*>(event);
    211             break;
    212     }
    213 
    214     if (!mouseEvent || mouseEvent->modifiers() != Qt::NoModifier)
     266    const QEvent::Type type = event->type();
     267
     268    switch (type) {
     269    case QEvent::MouseButtonPress:
     270    case QEvent::MouseMove:
     271    case QEvent::MouseButtonRelease:
     272        break;
     273    case QEvent::MouseButtonDblClick: // skip double click
     274        return true;
     275    default:
     276        return false;
     277    }
     278
     279    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
     280    if (type == QEvent::MouseMove && mouseEvent->buttons() != Qt::LeftButton)
     281        return false;
     282
     283    if (mouseEvent->modifiers() != Qt::NoModifier)
    215284        return false;
    216285
     
    220289        return false;
    221290
     291
    222292    bool consumed = false;
    223293    switch (data->state) {
    224294
    225295    case FlickData::Steady:
    226         if (mouseEvent->type() == QEvent::MouseButtonPress)
    227             if (mouseEvent->buttons() == Qt::LeftButton) {
    228                 consumed = true;
    229                 data->state = FlickData::Pressed;
    230                 data->pressPos = mouseEvent->pos();
    231                 data->offset = scrollOffset(data->widget);
    232             }
    233         break;
    234 
    235     case FlickData::Pressed:
    236         if (mouseEvent->type() == QEvent::MouseButtonRelease) {
    237             consumed = true;
    238             data->state = FlickData::Steady;
    239 
     296        if (type == QEvent::MouseButtonPress) {
     297            consumed = true;
     298            data->pressPos = mousePos;
     299        } else if (type == QEvent::MouseButtonRelease) {
     300            consumed = true;
    240301            QMouseEvent *event1 = new QMouseEvent(QEvent::MouseButtonPress,
    241302                                                  data->pressPos, Qt::LeftButton,
    242303                                                  Qt::LeftButton, Qt::NoModifier);
    243             QMouseEvent *event2 = new QMouseEvent(*mouseEvent);
     304            QMouseEvent *event2 = new QMouseEvent(QEvent::MouseButtonRelease,
     305                                                  data->pressPos, Qt::LeftButton,
     306                                                  Qt::LeftButton, Qt::NoModifier);
    244307
    245308            data->ignored << event1;
     
    247310            QApplication::postEvent(object, event1);
    248311            QApplication::postEvent(object, event2);
    249         }
    250         if (mouseEvent->type() == QEvent::MouseMove) {
    251             consumed = true;
    252             data->state = FlickData::ManualScroll;
    253             data->dragPos = QCursor::pos();
    254             if (!d->ticker.isActive())
    255                 d->ticker.start(20, this);
     312        }
     313       
     314            ;
     315
     316            ;
     317            if ()
     318                d;
    256319        }
    257320        break;
    258321
    259322    case FlickData::ManualScroll:
    260         if (mouseEvent->type() == QEvent::MouseMove) {
    261             consumed = true;
    262             QPoint delta = mouseEvent->pos() - data->pressPos;
    263             setScrollOffset(data->widget, data->offset - delta);
    264         }
    265         if (mouseEvent->type() == QEvent::MouseButtonRelease) {
     323        if (type == QEvent::MouseMove) {
     324            consumed = true;
     325            data->scrollTo(mousePos);
     326        } else if (type == QEvent::MouseButtonRelease) {
    266327            consumed = true;
    267328            data->state = FlickData::AutoScroll;
     329
     330
    268331        }
    269332        break;
    270333
    271334    case FlickData::AutoScroll:
    272         if (mouseEvent->type() == QEvent::MouseButtonPress) {
    273             consumed = true;
    274             data->state = FlickData::Stop;
    275             data->speed = QPoint(0, 0);
    276             data->pressPos = mouseEvent->pos();
    277             data->offset = scrollOffset(data->widget);
    278         }
    279         if (mouseEvent->type() == QEvent::MouseButtonRelease) {
     335        if ( == QEvent::MouseButtonPress) {
     336            consumed = true;
     337            data->state = FlickData::;
     338            data->;
     339            data->();
     340            data->);
     341       
     342        == QEvent::MouseButtonRelease) {
    280343            consumed = true;
    281344            data->state = FlickData::Steady;
    282             data->speed = QPoint(0, 0);
    283         }
    284         break;
    285 
    286     case FlickData::Stop:
    287         if (mouseEvent->type() == QEvent::MouseButtonRelease) {
    288             consumed = true;
    289             data->state = FlickData::Steady;
    290         }
    291         if (mouseEvent->type() == QEvent::MouseMove) {
    292             consumed = true;
    293             data->state = FlickData::ManualScroll;
    294             data->dragPos = QCursor::pos();
    295             if (!d->ticker.isActive())
    296                 d->ticker.start(20, this);
    297         }
    298         break;
    299 
     345            data->);
     346        }
     347        break;
     348
     349    case FlickData:::
     350        if (e) {
     351            consumed = true;
     352            data->;
     353       
     354       
     355            ;
     356       
     357            ;
     358           
     359            ;
     360       
     361       
     362        break;
    300363    default:
    301364        break;
    302365    }
    303 
    304     return consumed;
     366    data->lastPos = mousePos;
     367    return ;
    305368}
    306369
     
    312375        item.next();
    313376        FlickData *data = item.value();
    314 
    315         if (data->state == FlickData::ManualScroll) {
    316             count++;
    317             data->speed = QCursor::pos() - data->dragPos;
    318             data->dragPos = QCursor::pos();
    319         }
    320 
    321         if (data->state == FlickData::AutoScroll) {
    322             count++;
    323             data->speed = deaccelerate(data->speed);
    324             QPoint p = scrollOffset(data->widget);
    325             setScrollOffset(data->widget, p - data->speed);
    326             if (data->speed == QPoint(0, 0))
     377        if (data->state == FlickData::AutoScrollAcceleration
     378            && data->waitingAcceleration
     379            && data->accelerationTimer.elapsed() > 40) {
     380            data->state = FlickData::ManualScroll;
     381            data->resetSpeed();
     382        }
     383        if (data->state == FlickData::AutoScroll || data->state == FlickData::AutoScrollAcceleration) {
     384            const int timeElapsed = d->timeCounter.elapsed();
     385            const QPoint delta = (data->speed) * timeElapsed / 1000;
     386            bool hasScrolled = data->scrollWidget(delta.x(), delta.y());
     387
     388            if (data->speed.isNull() || !hasScrolled)
    327389                data->state = FlickData::Steady;
     390
     391
     392
    328393        }
    329394    }
     
    331396    if (!count)
    332397        d->ticker.stop();
     398
     399
    333400
    334401    QObject::timerEvent(event);
  • trunk/demos/embedded/anomaly/src/flickcharm.h

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
Note: See TracChangeset for help on using the changeset viewer.