diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-06-22 09:27:31 (GMT) |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-06-22 09:27:31 (GMT) |
commit | 112391d20adb222e6cfd93e0386031a0d27a22bf (patch) | |
tree | 7088d9f635c839aff80163469951fc5387894237 | |
parent | 628d29fc17b47160778a2a81fcaf9a0feedc34d0 (diff) | |
parent | 72f4849e17417a6854dbeccbf7a94809283eaa46 (diff) | |
download | Qt-112391d20adb222e6cfd93e0386031a0d27a22bf.zip Qt-112391d20adb222e6cfd93e0386031a0d27a22bf.tar.gz Qt-112391d20adb222e6cfd93e0386031a0d27a22bf.tar.bz2 |
Merge branch 'master' of git@scm.dev.troll.no:qt/qt-s60-public
28 files changed, 1681 insertions, 0 deletions
diff --git a/demos/embedded/anomaly/README.TXT b/demos/embedded/anomaly/README.TXT new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/demos/embedded/anomaly/README.TXT diff --git a/demos/embedded/anomaly/anomaly.pro b/demos/embedded/anomaly/anomaly.pro new file mode 100644 index 0000000..5fe5625 --- /dev/null +++ b/demos/embedded/anomaly/anomaly.pro @@ -0,0 +1,29 @@ +QT += network \ + webkit +HEADERS += src/BrowserWindow.h \ + src/BrowserView.h \ + src/TitleBar.h \ + src/HomeView.h \ + src/AddressBar.h \ + src/BookmarksView.h \ + src/flickcharm.h \ + src/ZoomStrip.h \ + src/ControlStrip.h +SOURCES += src/Main.cpp \ + src/BrowserWindow.cpp \ + src/BrowserView.cpp \ + src/TitleBar.cpp \ + src/HomeView.cpp \ + src/AddressBar.cpp \ + src/BookmarksView.cpp \ + src/flickcharm.cpp \ + src/ZoomStrip.cpp \ + src/ControlStrip.cpp +RESOURCES += src/anomaly.qrc + +symbian { + HEADERS += $$QT_SOURCE_TREE/examples/network/ftp/sym_iap_util.h + LIBS += -lesock -lconnmon + TARGET.CAPABILITY = NetworkServices + TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 +} diff --git a/demos/embedded/anomaly/src/AddressBar.cpp b/demos/embedded/anomaly/src/AddressBar.cpp new file mode 100644 index 0000000..64734c8 --- /dev/null +++ b/demos/embedded/anomaly/src/AddressBar.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "AddressBar.h" + +#include <QtCore> +#include <QtGui> + +class LineEdit: public QLineEdit +{ +public: + LineEdit(QWidget *parent = 0): QLineEdit(parent) {} + + void paintEvent(QPaintEvent *event) { + QLineEdit::paintEvent(event); + if (text().isEmpty()) { + QPainter p(this); + int flags = Qt::AlignLeft | Qt::AlignVCenter; + p.setPen(palette().color(QPalette::Disabled, QPalette::Text)); + p.drawText(rect().adjusted(10, 0, 0, 0), flags, "Enter address or search terms"); + p.end(); + } + } +}; + +AddressBar::AddressBar(QWidget *parent) + : QWidget(parent) +{ + m_lineEdit = new LineEdit(parent); + connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(processAddress())); + m_toolButton = new QToolButton(parent); + m_toolButton->setText("Go"); + connect(m_toolButton, SIGNAL(clicked()), SLOT(processAddress())); +} + +QSize AddressBar::sizeHint() const +{ + return m_lineEdit->sizeHint(); +} + +void AddressBar::processAddress() +{ + if (!m_lineEdit->text().isEmpty()) + emit addressEntered(m_lineEdit->text()); +} + +void AddressBar::resizeEvent(QResizeEvent *event) +{ + int x, y, w, h; + + m_toolButton->adjustSize(); + x = width() - m_toolButton->width(); + y = 0; + w = m_toolButton->width(); + h = height() - 1; + m_toolButton->setGeometry(x, y, w, h); + m_toolButton->show(); + + x = 0; + y = 0; + w = width() - m_toolButton->width(); + h = height() - 1; + m_lineEdit->setGeometry(x, y, w, h); + m_lineEdit->show(); +} + +void AddressBar::focusInEvent(QFocusEvent *event) +{ + m_lineEdit->setFocus(); + QWidget::focusInEvent(event); +} diff --git a/demos/embedded/anomaly/src/AddressBar.h b/demos/embedded/anomaly/src/AddressBar.h new file mode 100644 index 0000000..632ae1f --- /dev/null +++ b/demos/embedded/anomaly/src/AddressBar.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef ADDRESSBAR_H +#define ADDRESSBAR_H + +#include <QWidget> + +class QLineEdit; +class QToolButton; + +class AddressBar : public QWidget +{ + Q_OBJECT + +public: + AddressBar(QWidget *parent = 0); + QSize sizeHint() const; + +protected: + void resizeEvent(QResizeEvent *event); + void focusInEvent(QFocusEvent *event); + +signals: + void addressEntered(const QString &address); + +private slots: + void processAddress(); + +private: + QLineEdit *m_lineEdit; + QToolButton *m_toolButton; +}; + +#endif // ADDRESSBAR_H diff --git a/demos/embedded/anomaly/src/BookmarksView.cpp b/demos/embedded/anomaly/src/BookmarksView.cpp new file mode 100644 index 0000000..f705383 --- /dev/null +++ b/demos/embedded/anomaly/src/BookmarksView.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "BookmarksView.h" + +#include <QtGui> + +BookmarksView::BookmarksView(QWidget *parent) + : QWidget(parent) +{ + QListWidget *m_iconView = new QListWidget(this); + connect(m_iconView, SIGNAL(itemActivated(QListWidgetItem*)), SLOT(activate(QListWidgetItem*))); + + QVBoxLayout *layout = new QVBoxLayout(this); + setLayout(layout); + layout->addWidget(m_iconView); + + m_iconView->addItem("www.google.com"); + m_iconView->addItem("doc.trolltech.com/4.5"); + m_iconView->addItem("news.bbc.co.uk/text_only.stm"); + m_iconView->addItem("mobile.wikipedia.org"); + m_iconView->addItem("www.qtsoftware.com"); + m_iconView->addItem("en.wikipedia.org"); + + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +} + +void BookmarksView::activate(QListWidgetItem *item) +{ + QUrl url = item->text().prepend("http://"); + emit urlSelected(url); +} diff --git a/demos/embedded/anomaly/src/BookmarksView.h b/demos/embedded/anomaly/src/BookmarksView.h new file mode 100644 index 0000000..95abdd7 --- /dev/null +++ b/demos/embedded/anomaly/src/BookmarksView.h @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef BOOKMARKSVIEW_H +#define BOOKMARKSVIEW_H + +#include <QWidget> + +class QListWidgetItem; +class QUrl; + +class BookmarksView : public QWidget +{ + Q_OBJECT + +public: + BookmarksView(QWidget *parent = 0); + +signals: + void urlSelected(const QUrl &url); + +private slots: + void activate(QListWidgetItem *item); +}; + +#endif // BOOKMARKSVIEW_H diff --git a/demos/embedded/anomaly/src/BrowserView.cpp b/demos/embedded/anomaly/src/BrowserView.cpp new file mode 100644 index 0000000..e81d834 --- /dev/null +++ b/demos/embedded/anomaly/src/BrowserView.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "BrowserView.h" + +#include <QtGui> +#include <QtNetwork> +#include <QtWebKit> + +#include "ControlStrip.h" +#include "TitleBar.h" +#include "flickcharm.h" +#include "ZoomStrip.h" + +BrowserView::BrowserView(QWidget *parent) + : QWidget(parent) + , m_titleBar(0) + , m_webView(0) + , m_progress(0) + , m_currentZoom(100) +{ + m_titleBar = new TitleBar(this); + m_webView = new QWebView(this); + m_zoomStrip = new ZoomStrip(this); + m_controlStrip = new ControlStrip(this); + + m_zoomLevels << 30 << 50 << 67 << 80 << 90; + m_zoomLevels << 100; + m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300; + + QTimer::singleShot(0, this, SLOT(initialize())); +} + +void BrowserView::initialize() +{ + connect(m_zoomStrip, SIGNAL(zoomInClicked()), SLOT(zoomIn())); + connect(m_zoomStrip, SIGNAL(zoomOutClicked()), SLOT(zoomOut())); + + connect(m_controlStrip, SIGNAL(menuClicked()), SIGNAL(menuButtonClicked())); + connect(m_controlStrip, SIGNAL(backClicked()), m_webView, SLOT(back())); + connect(m_controlStrip, SIGNAL(forwardClicked()), m_webView, SLOT(forward())); + + QPalette pal = m_webView->palette(); + pal.setBrush(QPalette::Base, Qt::white); + m_webView->setPalette(pal); + + FlickCharm *flickCharm = new FlickCharm(this); + flickCharm->activateOn(m_webView); + + m_webView->setZoomFactor(static_cast<qreal>(m_currentZoom)/100.0); + connect(m_webView, SIGNAL(loadStarted()), SLOT(start())); + connect(m_webView, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); + connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(finish(bool))); + connect(m_webView, SIGNAL(urlChanged(QUrl)), SLOT(updateTitleBar())); + + m_webView->load(QUrl("http://news.bbc.co.uk/text_only.stm")); + m_webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_webView->setFocus(); +} + +void BrowserView::start() +{ + m_progress = 0; + updateTitleBar(); + //m_titleBar->setText(m_webView->url().toString()); +} + +void BrowserView::setProgress(int percent) +{ + m_progress = percent; + updateTitleBar(); + //m_titleBar->setText(QString("Loading %1%").arg(percent)); +} + +void BrowserView::updateTitleBar() +{ + QUrl url = m_webView->url(); + m_titleBar->setHost(url.host()); + m_titleBar->setTitle(m_webView->title()); + m_titleBar->setProgress(m_progress); +} + +void BrowserView::finish(bool ok) +{ + m_progress = 0; + updateTitleBar(); + + // TODO: handle error + if (!ok) { + //m_titleBar->setText("Loading failed."); + } +} + +void BrowserView::zoomIn() +{ + int i = m_zoomLevels.indexOf(m_currentZoom); + Q_ASSERT(i >= 0); + if (i < m_zoomLevels.count() - 1) + m_currentZoom = m_zoomLevels[i + 1]; + + m_webView->setZoomFactor(static_cast<qreal>(m_currentZoom)/100.0); +} + +void BrowserView::zoomOut() +{ + int i = m_zoomLevels.indexOf(m_currentZoom); + Q_ASSERT(i >= 0); + if (i > 0) + m_currentZoom = m_zoomLevels[i - 1]; + + m_webView->setZoomFactor(static_cast<qreal>(m_currentZoom)/100.0); +} + +void BrowserView::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); + + int h1 = m_titleBar->sizeHint().height(); + int h2 = m_controlStrip->sizeHint().height(); + + m_titleBar->setGeometry(0, 0, width(), h1); + m_controlStrip->setGeometry(0, height() - h2, width(), h2); + m_webView->setGeometry(0, h1, width(), height() - h1); + + int zw = m_zoomStrip->sizeHint().width(); + int zh = m_zoomStrip->sizeHint().height(); + m_zoomStrip->move(width() - zw, (height() - zh) / 2); +} + +void BrowserView::navigate(const QUrl &url) +{ + m_webView->load(url); +} diff --git a/demos/embedded/anomaly/src/BrowserView.h b/demos/embedded/anomaly/src/BrowserView.h new file mode 100644 index 0000000..36d3291 --- /dev/null +++ b/demos/embedded/anomaly/src/BrowserView.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef BROWSERVIEW_H +#define BROWSERVIEW_H + +#include <QWidget> +#include <QVector> + +class QUrl; +class QWebView; +class TitleBar; +class ControlStrip; +class ZoomStrip; + +class BrowserView : public QWidget +{ + Q_OBJECT + +public: + BrowserView(QWidget *parent = 0); + +public slots: + void navigate(const QUrl &url); + void zoomIn(); + void zoomOut(); + +private slots: + void initialize(); + void start(); + void setProgress(int percent); + void finish(bool); + void updateTitleBar(); + +signals: + void menuButtonClicked(); + +protected: + void resizeEvent(QResizeEvent *event); + +private: + TitleBar *m_titleBar; + QWebView *m_webView; + ZoomStrip *m_zoomStrip; + ControlStrip *m_controlStrip; + int m_progress; + int m_currentZoom; + QVector<int> m_zoomLevels; +}; + +#endif // BROWSERVIEW_H diff --git a/demos/embedded/anomaly/src/BrowserWindow.cpp b/demos/embedded/anomaly/src/BrowserWindow.cpp new file mode 100644 index 0000000..fd2f833 --- /dev/null +++ b/demos/embedded/anomaly/src/BrowserWindow.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "BrowserWindow.h" + +#include <QtCore> +#include <QtGui> + +#include "BrowserView.h" +#include "HomeView.h" + +BrowserWindow::BrowserWindow() + : QWidget() + , m_homeView(0) + , m_browserView(0) +{ + m_timeLine = new QTimeLine(300, this); + m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve); + QTimer::singleShot(0, this, SLOT(initialize())); +} + +void BrowserWindow::initialize() +{ + m_homeView = new HomeView(this); + m_browserView = new BrowserView(this); + + m_homeView->hide(); + m_homeView->resize(size()); + m_homeView->move(0, 0); + + m_browserView->hide(); + m_browserView->resize(size()); + m_browserView->move(0, 0); + + connect(m_homeView, SIGNAL(addressEntered(QString)), SLOT(gotoAddress(QString))); + connect(m_homeView, SIGNAL(urlActivated(QUrl)), SLOT(navigate(QUrl))); + + connect(m_browserView, SIGNAL(menuButtonClicked()), SLOT(showHomeView())); + + m_homeView->setVisible(false); + m_browserView->setVisible(false); + slide(0); + + connect(m_timeLine, SIGNAL(frameChanged(int)), SLOT(slide(int))); +} + + +// from Demo Browser +QUrl guessUrlFromString(const QString &string) +{ + QString urlStr = string.trimmed(); + QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*")); + + // Check if it looks like a qualified URL. Try parsing it and see. + bool hasSchema = test.exactMatch(urlStr); + if (hasSchema) { + QUrl url = QUrl::fromEncoded(urlStr.toUtf8(), QUrl::TolerantMode); + if (url.isValid()) + return url; + } + + // Might be a file. + if (QFile::exists(urlStr)) { + QFileInfo info(urlStr); + return QUrl::fromLocalFile(info.absoluteFilePath()); + } + + // Might be a shorturl - try to detect the schema. + if (!hasSchema) { + int dotIndex = urlStr.indexOf(QLatin1Char('.')); + if (dotIndex != -1) { + QString prefix = urlStr.left(dotIndex).toLower(); + QString schema = (prefix == QString("ftp")) ? prefix.toLatin1() : QString("http"); + QString location = schema + "://" + urlStr; + QUrl url = QUrl::fromEncoded(location.toUtf8(), QUrl::TolerantMode); + if (url.isValid()) + return url; + } + } + + // Fall back to QUrl's own tolerant parser. + QUrl url = QUrl::fromEncoded(string.toUtf8(), QUrl::TolerantMode); + + // finally for cases where the user just types in a hostname add http + if (url.scheme().isEmpty()) + url = QUrl::fromEncoded("http://" + string.toUtf8(), QUrl::TolerantMode); + return url; +} + +void BrowserWindow::gotoAddress(const QString &address) +{ + m_browserView->navigate(guessUrlFromString(address)); + showBrowserView(); +} + +void BrowserWindow::navigate(const QUrl &url) +{ + m_browserView->navigate(url); + showBrowserView(); +} + +void BrowserWindow::slide(int pos) +{ + m_browserView->move(pos, 0); + m_homeView->move(pos - width(), 0); + m_browserView->show(); + m_homeView->show(); +} + +void BrowserWindow::showHomeView() +{ + if (m_timeLine->state() != QTimeLine::NotRunning) + return; + + m_timeLine->setFrameRange(0, width()); + m_timeLine->start(); + m_homeView->setFocus(); +} + +void BrowserWindow::showBrowserView() +{ + if (m_timeLine->state() != QTimeLine::NotRunning) + return; + + m_timeLine->setFrameRange(width(), 0); + m_timeLine->start(); + m_browserView->setFocus(); +} + +void BrowserWindow::keyReleaseEvent(QKeyEvent *event) +{ + QWidget::keyReleaseEvent(event); + + if (event->key() == Qt::Key_F3) { + if (m_homeView->isVisible()) + showBrowserView(); + else + showHomeView(); + } +} + +void BrowserWindow::resizeEvent(QResizeEvent *event) +{ + if (m_homeView) + m_homeView->resize(size()); + + if (m_browserView) + m_browserView->resize(size()); +} diff --git a/demos/embedded/anomaly/src/BrowserWindow.h b/demos/embedded/anomaly/src/BrowserWindow.h new file mode 100644 index 0000000..50a6508 --- /dev/null +++ b/demos/embedded/anomaly/src/BrowserWindow.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + + +#ifndef BROWSERWINDOW_H +#define BROWSERWINDOW_H + +#include <QWidget> +class QTimeLine; +class QUrl; + +class BrowserView; +class HomeView; + +class BrowserWindow : public QWidget +{ + Q_OBJECT + +public: + BrowserWindow(); + +private slots: + void initialize(); + void navigate(const QUrl &url); + void gotoAddress(const QString &address); + +public slots: + void showBrowserView(); + void showHomeView(); + void slide(int); + +protected: + void keyReleaseEvent(QKeyEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + HomeView *m_homeView; + BrowserView *m_browserView; + QTimeLine *m_timeLine; +}; + +#endif // BROWSERWINDOW_H diff --git a/demos/embedded/anomaly/src/ControlStrip.cpp b/demos/embedded/anomaly/src/ControlStrip.cpp new file mode 100644 index 0000000..72bc485 --- /dev/null +++ b/demos/embedded/anomaly/src/ControlStrip.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "ControlStrip.h" + +#include <QtCore> +#include <QtGui> + +ControlStrip::ControlStrip(QWidget *parent) + : QWidget(parent) +{ + menuPixmap.load(":/images/edit-find.png"); + backPixmap.load(":/images/go-previous.png"); + forwardPixmap.load(":/images/go-next.png"); +} + +QSize ControlStrip::sizeHint() const +{ + return minimumSizeHint(); +} + +QSize ControlStrip::minimumSizeHint() const +{ + return QSize(320, 48); +} + +void ControlStrip::mousePressEvent(QMouseEvent *event) +{ + int h = height(); + int x = event->pos().x(); + + if (x < h) { + emit menuClicked(); + event->accept(); + return; + } + + if (x > width() - h) { + emit forwardClicked(); + event->accept(); + return; + } + + if ((x < width() - 2 * h) && (x > width() - 3 * h)) { + emit backClicked(); + event->accept(); + return; + } +} + +void ControlStrip::paintEvent(QPaintEvent *event) +{ + int h = height(); + int s = (h - menuPixmap.height()) / 2; + + QPainter p(this); + p.fillRect(event->rect(), QColor(32, 32, 32, 192)); + p.setCompositionMode(QPainter::CompositionMode_SourceOver); + p.drawPixmap(s, s, menuPixmap); + p.drawPixmap(width() - 3 * h + s, s, backPixmap); + p.drawPixmap(width() - h + s, s, forwardPixmap); + p.end(); +} diff --git a/demos/embedded/anomaly/src/ControlStrip.h b/demos/embedded/anomaly/src/ControlStrip.h new file mode 100644 index 0000000..99fc58d --- /dev/null +++ b/demos/embedded/anomaly/src/ControlStrip.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef CONTROLSTRIP_H +#define CONTROLSTRIP_H + +#include <QWidget> + +class ControlStrip : public QWidget +{ + Q_OBJECT + +public: + ControlStrip(QWidget *parent = 0); + + QSize sizeHint() const; + QSize minimumSizeHint() const; + +signals: + void menuClicked(); + void backClicked(); + void forwardClicked(); + +protected: + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + QPixmap menuPixmap; + QPixmap backPixmap; + QPixmap forwardPixmap; +}; + +#endif // CONTROLSTRIP_H diff --git a/demos/embedded/anomaly/src/HomeView.cpp b/demos/embedded/anomaly/src/HomeView.cpp new file mode 100644 index 0000000..0f59d54 --- /dev/null +++ b/demos/embedded/anomaly/src/HomeView.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "HomeView.h" + +#include <QtCore> +#include <QtGui> + +#include "AddressBar.h" +#include "BookmarksView.h" + +HomeView::HomeView(QWidget *parent) + : QWidget(parent) + , m_addressBar(0) +{ + m_addressBar = new AddressBar(parent); + connect(m_addressBar, SIGNAL(addressEntered(QString)), SLOT(gotoAddress(QString))); + + m_bookmarks = new BookmarksView(parent); + connect(m_bookmarks, SIGNAL(urlSelected(QUrl)), SIGNAL(urlActivated(QUrl))); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->setMargin(4); + layout->setSpacing(4); + layout->addWidget(m_addressBar); + layout->addWidget(m_bookmarks); +} + +void HomeView::gotoAddress(const QString &address) +{ + emit addressEntered(address); +} + +void HomeView::focusInEvent(QFocusEvent *event) +{ + m_addressBar->setFocus(); + QWidget::focusInEvent(event); +} diff --git a/demos/embedded/anomaly/src/HomeView.h b/demos/embedded/anomaly/src/HomeView.h new file mode 100644 index 0000000..b54f07e --- /dev/null +++ b/demos/embedded/anomaly/src/HomeView.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef HOMEVIEW_H +#define HOMEVIEW_H + +#include <QWidget> + +class QUrl; + +class AddressBar; +class BookmarksView; + +class HomeView : public QWidget +{ + Q_OBJECT + +public: + HomeView(QWidget *parent); + +signals: + void urlActivated(const QUrl &url); + void addressEntered(const QString &address); + +private slots: + void gotoAddress(const QString &address); + +protected: + void focusInEvent(QFocusEvent *event); + +private: + AddressBar *m_addressBar; + BookmarksView *m_bookmarks; +}; + +#endif // HOMEVIEW_H diff --git a/demos/embedded/anomaly/src/Main.cpp b/demos/embedded/anomaly/src/Main.cpp new file mode 100644 index 0000000..2be6143 --- /dev/null +++ b/demos/embedded/anomaly/src/Main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include <QtCore> +#include <QtGui> +#include <QtWebKit> + +#include "BrowserWindow.h" + +#if defined (Q_OS_SYMBIAN) +#include "sym_iap_util.h" +#endif + +int main(int argc, char *argv[]) +{ +#if !defined(Q_WS_S60) + QApplication::setGraphicsSystem("raster"); +#endif + + QApplication app(argc, argv); + + app.setApplicationName("Anomaly"); + app.setApplicationVersion("0.0.0"); + + BrowserWindow window; +#ifdef Q_OS_SYMBIAN + window.showFullScreen(); + QWebSettings::globalSettings()->setObjectCacheCapacities(128*1024, 1024*1024, 1024*1024); + QWebSettings::globalSettings()->setMaximumPagesInCache(3); + qt_SetDefaultIap(); +#else + window.resize(360, 640); + window.show(); + app.setStyle("windows"); +#endif + + return app.exec(); +} + diff --git a/demos/embedded/anomaly/src/TitleBar.cpp b/demos/embedded/anomaly/src/TitleBar.cpp new file mode 100644 index 0000000..ff7837c --- /dev/null +++ b/demos/embedded/anomaly/src/TitleBar.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "TitleBar.h" + +#include <QtCore> +#include <QtGui> + +TitleBar::TitleBar(QWidget *parent) + : QWidget(parent) + , m_progress(0) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); +} + +void TitleBar::setHost(const QString &host) +{ + m_host = host; + update(); +} + +void TitleBar::setTitle(const QString &title) +{ + m_title = title; + update(); +} + +void TitleBar::setProgress(int percent) +{ + m_progress = percent; + update(); +} + +QSize TitleBar::sizeHint() const +{ + return minimumSizeHint(); +} + +QSize TitleBar::minimumSizeHint() const +{ + QFontMetrics fm = fontMetrics(); + return QSize(100, fm.height()); +} + +void TitleBar::paintEvent(QPaintEvent *event) +{ + QString title = m_host; + if (!m_title.isEmpty()) + title.append(": ").append(m_title); + + QPalette pal = palette(); + QPainter p(this); + p.fillRect(event->rect(), pal.color(QPalette::Highlight)); + + if (m_progress > 0) { + + QRect box = rect(); + box.setLeft(16); + box.setWidth(width() - box.left() - 110); + + p.setPen(pal.color(QPalette::HighlightedText)); + p.setOpacity(0.8); + p.drawText(box, Qt::AlignLeft + Qt::AlignVCenter, title); + + int x = width() - 100 - 5; + int y = 1; + int h = height() - 4; + + p.setOpacity(1.0); + p.setBrush(Qt::NoBrush); + p.setPen(pal.color(QPalette::HighlightedText)); + p.drawRect(x, y, 100, h); + p.setPen(Qt::NoPen); + p.setBrush(pal.color(QPalette::HighlightedText)); + p.drawRect(x, y, m_progress, h); + } else { + + QRect box = rect(); + box.setLeft(16); + box.setWidth(width() - box.left() - 5); + p.setPen(pal.color(QPalette::HighlightedText)); + p.drawText(box, Qt::AlignLeft + Qt::AlignVCenter, title); + } + + p.end(); +} diff --git a/demos/embedded/anomaly/src/TitleBar.h b/demos/embedded/anomaly/src/TitleBar.h new file mode 100644 index 0000000..10ef2a8 --- /dev/null +++ b/demos/embedded/anomaly/src/TitleBar.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef TITLEBAR_H +#define TITLEBAR_H + +#include <QWidget> + +class TitleBar : public QWidget +{ + Q_OBJECT + +public: + TitleBar(QWidget *parent = 0); + + void setHost(const QString &host); + void setTitle(const QString &title); + void setProgress(int percent); + + QSize sizeHint() const; + QSize minimumSizeHint() const; + +protected: + void paintEvent(QPaintEvent *event); + +private: + QString m_host; + QString m_title; + int m_progress; +}; + +#endif // TITLEBAR_H diff --git a/demos/embedded/anomaly/src/ZoomStrip.cpp b/demos/embedded/anomaly/src/ZoomStrip.cpp new file mode 100644 index 0000000..80bfdea --- /dev/null +++ b/demos/embedded/anomaly/src/ZoomStrip.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "ZoomStrip.h" + +#include <QtCore> +#include <QtGui> + +ZoomStrip::ZoomStrip(QWidget *parent) + : QWidget(parent) +{ + zoomInPixmap.load(":/images/list-add.png"); + zoomOutPixmap.load(":/images/list-remove.png"); +} + +QSize ZoomStrip::sizeHint() const +{ + return minimumSizeHint(); +} + +QSize ZoomStrip::minimumSizeHint() const +{ + return QSize(48, 96); +} + +void ZoomStrip::mousePressEvent(QMouseEvent *event) +{ + if (event->pos().y() < height() / 2) + emit zoomInClicked(); + else + emit zoomOutClicked(); +} + +void ZoomStrip::paintEvent(QPaintEvent *event) +{ + int w = width(); + int s = (w - zoomInPixmap.width()) / 2; + + QPainter p(this); + p.fillRect(event->rect(), QColor(128, 128, 128, 128)); + p.drawPixmap(s, s, zoomInPixmap); + p.drawPixmap(s, s + w, zoomOutPixmap); + p.end(); +} diff --git a/demos/embedded/anomaly/src/ZoomStrip.h b/demos/embedded/anomaly/src/ZoomStrip.h new file mode 100644 index 0000000..fdf0328 --- /dev/null +++ b/demos/embedded/anomaly/src/ZoomStrip.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Anomaly project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef ZOOMSTRIP_H +#define ZOOMSTRIP_H + +#include <QWidget> + +class ZoomStrip : public QWidget +{ + Q_OBJECT + +public: + ZoomStrip(QWidget *parent = 0); + + QSize sizeHint() const; + QSize minimumSizeHint() const; + +signals: + void zoomInClicked(); + void zoomOutClicked(); + +protected: + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + QPixmap zoomInPixmap; + QPixmap zoomOutPixmap; +}; + +#endif // ZOOMSTRIP_H diff --git a/demos/embedded/anomaly/src/anomaly.qrc b/demos/embedded/anomaly/src/anomaly.qrc new file mode 100644 index 0000000..601a34e --- /dev/null +++ b/demos/embedded/anomaly/src/anomaly.qrc @@ -0,0 +1,9 @@ +<RCC> + <qresource prefix="/" > + <file>images/go-next.png</file> + <file>images/go-previous.png</file> + <file>images/edit-find.png</file> + <file>images/list-add.png</file> + <file>images/list-remove.png</file> + </qresource> +</RCC> diff --git a/demos/embedded/anomaly/src/flickcharm.cpp b/demos/embedded/anomaly/src/flickcharm.cpp new file mode 100644 index 0000000..620ef88 --- /dev/null +++ b/demos/embedded/anomaly/src/flickcharm.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Graphics Dojo project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "flickcharm.h" + +#include <QAbstractScrollArea> +#include <QApplication> +#include <QBasicTimer> +#include <QEvent> +#include <QHash> +#include <QList> +#include <QMouseEvent> +#include <QScrollBar> +#include <QWebFrame> +#include <QWebView> + +#include <QDebug> + +struct FlickData { + typedef enum { Steady, Pressed, ManualScroll, AutoScroll, Stop } State; + State state; + QWidget *widget; + QPoint pressPos; + QPoint offset; + QPoint dragPos; + QPoint speed; + QList<QEvent*> ignored; +}; + +class FlickCharmPrivate +{ +public: + QHash<QWidget*, FlickData*> flickData; + QBasicTimer ticker; +}; + +FlickCharm::FlickCharm(QObject *parent): QObject(parent) +{ + d = new FlickCharmPrivate; +} + +FlickCharm::~FlickCharm() +{ + delete d; +} + +void FlickCharm::activateOn(QWidget *widget) +{ + QAbstractScrollArea *scrollArea = dynamic_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 = dynamic_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)"; +} + +void FlickCharm::deactivateFrom(QWidget *widget) +{ + QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(widget); + if (scrollArea) { + QWidget *viewport = scrollArea->viewport(); + + viewport->removeEventFilter(this); + scrollArea->removeEventFilter(this); + + delete d->flickData[viewport]; + d->flickData.remove(viewport); + + return; + } + + QWebView *webView = dynamic_cast<QWebView*>(widget); + if (webView) { + webView->removeEventFilter(this); + + delete d->flickData[webView]; + d->flickData.remove(webView); + + return; + } +} + +static QPoint scrollOffset(QWidget *widget) +{ + int x = 0, y = 0; + + QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(widget); + if (scrollArea) { + x = scrollArea->horizontalScrollBar()->value(); + y = scrollArea->verticalScrollBar()->value(); + } + + QWebView *webView = dynamic_cast<QWebView*>(widget); + if (webView) { + QWebFrame *frame = webView->page()->mainFrame(); + x = frame->evaluateJavaScript("window.scrollX").toInt(); + y = frame->evaluateJavaScript("window.scrollY").toInt(); + } + + return QPoint(x, y); +} + +static void setScrollOffset(QWidget *widget, const QPoint &p) +{ + QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(widget); + if (scrollArea) { + scrollArea->horizontalScrollBar()->setValue(p.x()); + scrollArea->verticalScrollBar()->setValue(p.y()); + } + + QWebView *webView = dynamic_cast<QWebView*>(widget); + QWebFrame *frame = webView ? webView->page()->mainFrame() : 0; + if (frame) + frame->evaluateJavaScript(QString("window.scrollTo(%1,%2);").arg(p.x()).arg(p.y())); +} + +static QPoint deaccelerate(const QPoint &speed, int a = 1, int max = 64) +{ + int x = qBound(-max, speed.x(), max); + int y = qBound(-max, speed.y(), max); + x = (x == 0) ? x : (x > 0) ? qMax(0, x - a) : qMin(0, x + a); + y = (y == 0) ? y : (y > 0) ? qMax(0, y - a) : qMin(0, y + a); + return QPoint(x, y); +} + +bool FlickCharm::eventFilter(QObject *object, QEvent *event) +{ + if (!object->isWidgetType()) + return false; + + QEvent::Type type = event->type(); + if (type != QEvent::MouseButtonPress && + type != QEvent::MouseButtonRelease && + type != QEvent::MouseMove) + return false; + + QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event); + if (!mouseEvent || mouseEvent->modifiers() != Qt::NoModifier) + return false; + + QWidget *viewport = dynamic_cast<QWidget*>(object); + FlickData *data = d->flickData.value(viewport); + if (!viewport || !data || data->ignored.removeAll(event)) + return false; + + bool consumed = false; + switch (data->state) { + + case FlickData::Steady: + if (mouseEvent->type() == QEvent::MouseButtonPress) + if (mouseEvent->buttons() == Qt::LeftButton) { + consumed = true; + data->state = FlickData::Pressed; + data->pressPos = mouseEvent->pos(); + data->offset = scrollOffset(data->widget); + } + break; + + case FlickData::Pressed: + if (mouseEvent->type() == QEvent::MouseButtonRelease) { + consumed = true; + data->state = FlickData::Steady; + + QMouseEvent *event1 = new QMouseEvent(QEvent::MouseButtonPress, + data->pressPos, Qt::LeftButton, + Qt::LeftButton, Qt::NoModifier); + QMouseEvent *event2 = new QMouseEvent(*mouseEvent); + + data->ignored << event1; + data->ignored << event2; + QApplication::postEvent(object, event1); + QApplication::postEvent(object, event2); + } + if (mouseEvent->type() == QEvent::MouseMove) { + consumed = true; + data->state = FlickData::ManualScroll; + data->dragPos = QCursor::pos(); + if (!d->ticker.isActive()) + d->ticker.start(20, this); + } + break; + + case FlickData::ManualScroll: + if (mouseEvent->type() == QEvent::MouseMove) { + consumed = true; + QPoint delta = mouseEvent->pos() - data->pressPos; + setScrollOffset(data->widget, data->offset - delta); + } + if (mouseEvent->type() == QEvent::MouseButtonRelease) { + consumed = true; + data->state = FlickData::AutoScroll; + } + break; + + case FlickData::AutoScroll: + if (mouseEvent->type() == QEvent::MouseButtonPress) { + consumed = true; + data->state = FlickData::Stop; + data->speed = QPoint(0, 0); + data->pressPos = mouseEvent->pos(); + data->offset = scrollOffset(data->widget); + } + if (mouseEvent->type() == QEvent::MouseButtonRelease) { + consumed = true; + data->state = FlickData::Steady; + data->speed = QPoint(0, 0); + } + break; + + case FlickData::Stop: + if (mouseEvent->type() == QEvent::MouseButtonRelease) { + consumed = true; + data->state = FlickData::Steady; + } + if (mouseEvent->type() == QEvent::MouseMove) { + consumed = true; + data->state = FlickData::ManualScroll; + data->dragPos = QCursor::pos(); + if (!d->ticker.isActive()) + d->ticker.start(20, this); + } + break; + + default: + break; + } + + return consumed; +} + +void FlickCharm::timerEvent(QTimerEvent *event) +{ + int count = 0; + QHashIterator<QWidget*, FlickData*> item(d->flickData); + while (item.hasNext()) { + item.next(); + FlickData *data = item.value(); + + if (data->state == FlickData::ManualScroll) { + count++; + data->speed = QCursor::pos() - data->dragPos; + data->dragPos = QCursor::pos(); + } + + if (data->state == FlickData::AutoScroll) { + count++; + data->speed = deaccelerate(data->speed); + QPoint p = scrollOffset(data->widget); + setScrollOffset(data->widget, p - data->speed); + if (data->speed == QPoint(0, 0)) + data->state = FlickData::Steady; + } + } + + if (!count) + d->ticker.stop(); + + QObject::timerEvent(event); +} diff --git a/demos/embedded/anomaly/src/flickcharm.h b/demos/embedded/anomaly/src/flickcharm.h new file mode 100644 index 0000000..3b3831f --- /dev/null +++ b/demos/embedded/anomaly/src/flickcharm.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Graphics Dojo project on Qt Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 or 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef FLICKCHARM_H +#define FLICKCHARM_H + +#include <QObject> + +class FlickCharmPrivate; +class QWidget; + +class FlickCharm: public QObject +{ + Q_OBJECT +public: + FlickCharm(QObject *parent = 0); + ~FlickCharm(); + void activateOn(QWidget *widget); + void deactivateFrom(QWidget *widget); + bool eventFilter(QObject *object, QEvent *event); + +protected: + void timerEvent(QTimerEvent *event); + +private: + FlickCharmPrivate *d; +}; + +#endif // FLICKCHARM_H diff --git a/demos/embedded/anomaly/src/images/edit-find.png b/demos/embedded/anomaly/src/images/edit-find.png Binary files differnew file mode 100644 index 0000000..5594785 --- /dev/null +++ b/demos/embedded/anomaly/src/images/edit-find.png diff --git a/demos/embedded/anomaly/src/images/go-next.png b/demos/embedded/anomaly/src/images/go-next.png Binary files differnew file mode 100644 index 0000000..a68e2db --- /dev/null +++ b/demos/embedded/anomaly/src/images/go-next.png diff --git a/demos/embedded/anomaly/src/images/go-previous.png b/demos/embedded/anomaly/src/images/go-previous.png Binary files differnew file mode 100644 index 0000000..c37bc04 --- /dev/null +++ b/demos/embedded/anomaly/src/images/go-previous.png diff --git a/demos/embedded/anomaly/src/images/list-add.png b/demos/embedded/anomaly/src/images/list-add.png Binary files differnew file mode 100644 index 0000000..2acdd8f --- /dev/null +++ b/demos/embedded/anomaly/src/images/list-add.png diff --git a/demos/embedded/anomaly/src/images/list-remove.png b/demos/embedded/anomaly/src/images/list-remove.png Binary files differnew file mode 100644 index 0000000..c5524f7 --- /dev/null +++ b/demos/embedded/anomaly/src/images/list-remove.png diff --git a/demos/embedded/embedded.pro b/demos/embedded/embedded.pro index 8214dd3..8a79298 100644 --- a/demos/embedded/embedded.pro +++ b/demos/embedded/embedded.pro @@ -7,6 +7,8 @@ contains(QT_CONFIG, svg) { desktopservices } +SUBDIRS += anomaly + # install sources.files = README *.pro sources.path = $$[QT_INSTALL_DEMOS]/embedded |