Changeset 651 for trunk/demos/embedded/anomaly
- Timestamp:
- Mar 8, 2010, 12:52:58 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 21 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.2 (added) merged: 650 /branches/vendor/nokia/qt/current merged: 649 /branches/vendor/nokia/qt/4.6.1 removed
- Property svn:mergeinfo changed
-
trunk/demos/embedded/anomaly/anomaly.pro
r561 r651 9 9 src/flickcharm.h \ 10 10 src/ZoomStrip.h \ 11 src/ControlStrip.h 11 src/ControlStrip.h \ 12 src/webview.h 12 13 SOURCES += src/Main.cpp \ 13 14 src/BrowserWindow.cpp \ … … 19 20 src/flickcharm.cpp \ 20 21 src/ZoomStrip.cpp \ 21 src/ControlStrip.cpp 22 src/ControlStrip.cpp \ 23 src/webview.cpp 22 24 RESOURCES += src/anomaly.qrc 23 25 -
trunk/demos/embedded/anomaly/src/AddressBar.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/AddressBar.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/BookmarksView.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/BookmarksView.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/BrowserView.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 49 49 #include "TitleBar.h" 50 50 #include "flickcharm.h" 51 51 52 #include "ZoomStrip.h" 52 53 … … 63 64 { 64 65 m_titleBar = new TitleBar(this); 65 m_webView = new QWebView(this);66 m_webView = new WebView(this); 66 67 m_zoomStrip = new ZoomStrip(this); 67 68 m_controlStrip = new ControlStrip(this); … … 96 97 connect(m_webView, SIGNAL(urlChanged(QUrl)), SLOT(updateTitleBar())); 97 98 98 m_webView->setHtml(" Will try to load page soon!");99 m_webView->setHtml(""); 99 100 m_webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 100 101 m_webView->setFocus(); -
trunk/demos/embedded/anomaly/src/BrowserView.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 50 50 class TitleBar; 51 51 class ControlStrip; 52 52 53 class ZoomStrip; 53 54 … … 82 83 private: 83 84 TitleBar *m_titleBar; 84 QWebView *m_webView;85 WebView *m_webView; 85 86 ZoomStrip *m_zoomStrip; 86 87 ControlStrip *m_controlStrip; … … 91 92 92 93 #endif // BROWSERVIEW_H 94 -
trunk/demos/embedded/anomaly/src/BrowserWindow.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/BrowserWindow.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/ControlStrip.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/ControlStrip.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/HomeView.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/HomeView.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/Main.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/TitleBar.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/TitleBar.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/ZoomStrip.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/ZoomStrip.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) -
trunk/demos/embedded/anomaly/src/flickcharm.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 50 50 #include <QMouseEvent> 51 51 #include <QScrollBar> 52 52 53 #include <QWebFrame> 53 54 #include <QWebView> … … 55 56 #include <QDebug> 56 57 58 59 57 60 struct 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; 59 67 State state; 60 68 QWidget *widget; 61 69 QPoint pressPos; 62 QPoint offset; 63 QPoint dragPos; 70 QPoint lastPos; 64 71 QPoint speed; 72 65 73 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 66 158 }; 67 159 … … 71 163 QHash<QWidget*, FlickData*> flickData; 72 164 QBasicTimer ticker; 165 166 167 168 169 170 171 73 172 }; 74 173 … … 149 248 } 150 249 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 250 static 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); 168 258 return QPoint(x, y); 169 259 } 170 260 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 194 261 bool FlickCharm::eventFilter(QObject *object, QEvent *event) 195 262 { … … 197 264 return false; 198 265 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) 215 284 return false; 216 285 … … 220 289 return false; 221 290 291 222 292 bool consumed = false; 223 293 switch (data->state) { 224 294 225 295 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; 240 301 QMouseEvent *event1 = new QMouseEvent(QEvent::MouseButtonPress, 241 302 data->pressPos, Qt::LeftButton, 242 303 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); 244 307 245 308 data->ignored << event1; … … 247 310 QApplication::postEvent(object, event1); 248 311 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; 256 319 } 257 320 break; 258 321 259 322 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) { 266 327 consumed = true; 267 328 data->state = FlickData::AutoScroll; 329 330 268 331 } 269 332 break; 270 333 271 334 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) { 280 343 consumed = true; 281 344 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; 300 363 default: 301 364 break; 302 365 } 303 304 return consumed;366 data->lastPos = mousePos; 367 return ; 305 368 } 306 369 … … 312 375 item.next(); 313 376 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) 327 389 data->state = FlickData::Steady; 390 391 392 328 393 } 329 394 } … … 331 396 if (!count) 332 397 d->ticker.stop(); 398 399 333 400 334 401 QObject::timerEvent(event); -
trunk/demos/embedded/anomaly/src/flickcharm.h
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 20 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected])
Note:
See TracChangeset
for help on using the changeset viewer.