diff options
author | hjk <qthjk@ovi.com> | 2012-12-10 17:21:29 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-10 18:37:29 +0100 |
commit | 129bcf57471d09f15cbfe6dc3ab397689e6eb245 (patch) | |
tree | b4901c52b1f75212303be606e6c40530c2afcd53 /examples/webkitwidgets/embedded | |
parent | 539c47c9c93335196dbde56f7ba98de0e6600a38 (diff) | |
download | qtwebkit-examples-129bcf57471d09f15cbfe6dc3ab397689e6eb245.tar.gz |
Adjust webkit example project install targets.
This follows suit with aeb036e in qtbase.
Change-Id: Ifc85b327df81d15f3579b911e07c95a3b7a3bb9d
Reviewed-by: Michael Bruning <michael.bruning@digia.com>
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'examples/webkitwidgets/embedded')
31 files changed, 2249 insertions, 0 deletions
diff --git a/examples/webkitwidgets/embedded/anomaly/README.TXT b/examples/webkitwidgets/embedded/anomaly/README.TXT new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/README.TXT diff --git a/examples/webkitwidgets/embedded/anomaly/anomaly.pro b/examples/webkitwidgets/embedded/anomaly/anomaly.pro new file mode 100644 index 0000000..ddb20f2 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/anomaly.pro @@ -0,0 +1,28 @@ +QT += network \ + webkitwidgets \ + widgets +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 \ + src/webview.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 \ + src/webview.cpp +RESOURCES += src/anomaly.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/webkitwidgets/embedded/anomaly +INSTALLS += target diff --git a/examples/webkitwidgets/embedded/anomaly/src/AddressBar.cpp b/examples/webkitwidgets/embedded/anomaly/src/AddressBar.cpp new file mode 100644 index 0000000..dfb4043 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/AddressBar.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "AddressBar.h" + +#include <QtCore> +#include <QtWidgets> + +AddressBar::AddressBar(QWidget *parent) + : QWidget(parent) +{ + m_lineEdit = new QLineEdit(parent); + m_lineEdit->setPlaceholderText("Enter address or search terms"); + 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/examples/webkitwidgets/embedded/anomaly/src/AddressBar.h b/examples/webkitwidgets/embedded/anomaly/src/AddressBar.h new file mode 100644 index 0000000..ae9010d --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/AddressBar.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ADDRESSBAR_H +#define ADDRESSBAR_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QLineEdit; +class QToolButton; +QT_END_NAMESPACE + +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/examples/webkitwidgets/embedded/anomaly/src/BookmarksView.cpp b/examples/webkitwidgets/embedded/anomaly/src/BookmarksView.cpp new file mode 100644 index 0000000..63e48e2 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/BookmarksView.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "BookmarksView.h" + +#include <QtWidgets> + +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("qt-project.org/doc/qt-5.0"); + m_iconView->addItem("news.bbc.co.uk/2/mobile/default.stm"); + m_iconView->addItem("mobile.wikipedia.org"); + m_iconView->addItem("qt.digia.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/examples/webkitwidgets/embedded/anomaly/src/BookmarksView.h b/examples/webkitwidgets/embedded/anomaly/src/BookmarksView.h new file mode 100644 index 0000000..4d68a6c --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/BookmarksView.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BOOKMARKSVIEW_H +#define BOOKMARKSVIEW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QListWidgetItem; +class QUrl; +QT_END_NAMESPACE + +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/examples/webkitwidgets/embedded/anomaly/src/BrowserView.cpp b/examples/webkitwidgets/embedded/anomaly/src/BrowserView.cpp new file mode 100644 index 0000000..46f898d --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/BrowserView.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "BrowserView.h" + +#include <QtWidgets> +#include <QtNetwork> +#include <QtWebKitWidgets> + +#include "ControlStrip.h" +#include "TitleBar.h" +#include "flickcharm.h" +#include "webview.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 WebView(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; + + QNetworkConfigurationManager manager; + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { + // Get saved network configuration + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + const QString id = + settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); + settings.endGroup(); + + // If the saved network configuration is not currently discovered use the system + // default + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if ((config.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + config = manager.defaultConfiguration(); + } + + m_webView->page()->networkAccessManager()->setConfiguration(config); + } + + 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())); + connect(m_controlStrip, SIGNAL(closeClicked()), qApp, SLOT(quit())); + + 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->setHtml("about:blank"); + 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/examples/webkitwidgets/embedded/anomaly/src/BrowserView.h b/examples/webkitwidgets/embedded/anomaly/src/BrowserView.h new file mode 100644 index 0000000..51f5897 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/BrowserView.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BROWSERVIEW_H +#define BROWSERVIEW_H + +#include <QWidget> +#include <QVector> + +QT_BEGIN_NAMESPACE +class QUrl; +QT_END_NAMESPACE + +class QWebView; +class TitleBar; +class ControlStrip; +class WebView; +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; + WebView *m_webView; + ZoomStrip *m_zoomStrip; + ControlStrip *m_controlStrip; + int m_progress; + int m_currentZoom; + QVector<int> m_zoomLevels; +}; + +#endif // BROWSERVIEW_H + diff --git a/examples/webkitwidgets/embedded/anomaly/src/BrowserWindow.cpp b/examples/webkitwidgets/embedded/anomaly/src/BrowserWindow.cpp new file mode 100644 index 0000000..c380766 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/BrowserWindow.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "BrowserWindow.h" + +#include <QtCore> +#include <QtWidgets> +#include <QPropertyAnimation> +#include <QResizeEvent> + +#include "BrowserView.h" +#include "HomeView.h" + +BrowserWindow::BrowserWindow() + : m_slidingSurface(new QWidget(this)) + , m_homeView(new HomeView(m_slidingSurface)) + , m_browserView(new BrowserView(m_slidingSurface)) + , m_animation(new QPropertyAnimation(this, "slideValue")) +{ + m_slidingSurface->setAutoFillBackground(true); + + m_homeView->resize(size()); + + m_browserView->resize(size()); + + 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_animation->setDuration(200); + connect(m_animation, SIGNAL(finished()), SLOT(animationFinished())); + + setSlideValue(0.0f); +} + +void BrowserWindow::gotoAddress(const QString &address) +{ + m_browserView->navigate(QUrl::fromUserInput(address)); + showBrowserView(); +} + +void BrowserWindow::animationFinished() +{ + m_animation->setDirection(QAbstractAnimation::Forward); +} + +void BrowserWindow::navigate(const QUrl &url) +{ + m_browserView->navigate(url); + showBrowserView(); +} + +void BrowserWindow::setSlideValue(qreal slideRatio) +{ + // we use a ratio to handle resize corectly + const int pos = -qRound(slideRatio * width()); + m_slidingSurface->scroll(pos - m_homeView->x(), 0); + + if (qFuzzyCompare(slideRatio, static_cast<qreal>(1.0f))) { + m_browserView->show(); + m_homeView->hide(); + } else if (qFuzzyCompare(slideRatio, static_cast<qreal>(0.0f))) { + m_homeView->show(); + m_browserView->hide(); + } else { + m_browserView->show(); + m_homeView->show(); + } +} + +qreal BrowserWindow::slideValue() const +{ + Q_ASSERT(m_slidingSurface->x() < width()); + return static_cast<qreal>(qAbs(m_homeView->x())) / width(); +} + +void BrowserWindow::showHomeView() +{ + m_animation->setStartValue(slideValue()); + m_animation->setEndValue(0.0f); + m_animation->start(); + m_homeView->setFocus(); +} + +void BrowserWindow::showBrowserView() +{ + m_animation->setStartValue(slideValue()); + m_animation->setEndValue(1.0f); + m_animation->start(); + + m_browserView->setFocus(); +} + +void BrowserWindow::keyReleaseEvent(QKeyEvent *event) +{ + QWidget::keyReleaseEvent(event); + + if (event->key() == Qt::Key_F3) { + if (m_animation->state() == QAbstractAnimation::Running) { + const QAbstractAnimation::Direction direction = m_animation->direction() == QAbstractAnimation::Forward + ? QAbstractAnimation::Forward + : QAbstractAnimation::Backward; + m_animation->setDirection(direction); + } else if (qFuzzyCompare(slideValue(), static_cast<qreal>(1.0f))) + showHomeView(); + else + showBrowserView(); + event->accept(); + } +} + +void BrowserWindow::resizeEvent(QResizeEvent *event) +{ + const QSize oldSize = event->oldSize(); + const qreal oldSlidingRatio = static_cast<qreal>(qAbs(m_homeView->x())) / oldSize.width(); + + const QSize newSize = event->size(); + m_slidingSurface->resize(newSize.width() * 2, newSize.height()); + + m_homeView->resize(newSize); + m_homeView->move(0, 0); + + m_browserView->resize(newSize); + m_browserView->move(newSize.width(), 0); + + setSlideValue(oldSlidingRatio); +} diff --git a/examples/webkitwidgets/embedded/anomaly/src/BrowserWindow.h b/examples/webkitwidgets/embedded/anomaly/src/BrowserWindow.h new file mode 100644 index 0000000..eb97f77 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/BrowserWindow.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BROWSERWINDOW_H +#define BROWSERWINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QPropertyAnimation; +class QUrl; +QT_END_NAMESPACE + +class BrowserView; +class HomeView; + +class BrowserWindow : public QWidget +{ + Q_OBJECT + Q_PROPERTY(qreal slideValue READ slideValue WRITE setSlideValue) + +public: + BrowserWindow(); + +private slots: + void navigate(const QUrl &url); + void gotoAddress(const QString &address); + void animationFinished(); + +public slots: + void showBrowserView(); + void showHomeView(); + +protected: + void keyReleaseEvent(QKeyEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + void setSlideValue(qreal); + qreal slideValue() const; + + QWidget *m_slidingSurface; + HomeView *m_homeView; + BrowserView *m_browserView; + QPropertyAnimation *m_animation; +}; + +#endif // BROWSERWINDOW_H diff --git a/examples/webkitwidgets/embedded/anomaly/src/ControlStrip.cpp b/examples/webkitwidgets/embedded/anomaly/src/ControlStrip.cpp new file mode 100644 index 0000000..c5f2aee --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/ControlStrip.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ControlStrip.h" + +#include <QtCore> +#include <QtWidgets> + +ControlStrip::ControlStrip(QWidget *parent) + : QWidget(parent) +{ + menuPixmap.load(":/images/edit-find.png"); + backPixmap.load(":/images/go-previous.png"); + forwardPixmap.load(":/images/go-next.png"); + closePixmap.load(":/images/button-close.png"); +} + +QSize ControlStrip::sizeHint() const +{ + return minimumSizeHint(); +} + +QSize ControlStrip::minimumSizeHint() const +{ + return QSize(320, 48); +} + +void ControlStrip::mousePressEvent(QMouseEvent *event) +{ + int h = height(); + int spacing = qMin(h, (width() - h * 4) / 3); + int x = event->pos().x(); + + if (x < h) { + emit menuClicked(); + event->accept(); + return; + } + + if (x > width() - h) { + emit closeClicked(); + event->accept(); + return; + } + + if ((x < width() - (h + spacing)) && (x > width() - (h * 2 + spacing))) { + emit forwardClicked(); + event->accept(); + return; + } + + if ((x < width() - (h * 2 + spacing * 2)) && (x > width() - (h * 3 + spacing * 2))) { + emit backClicked(); + event->accept(); + return; + } +} + +void ControlStrip::paintEvent(QPaintEvent *event) +{ + int h = height(); + int spacing = qMin(h, (width() - h * 4) / 3); + int s = (height() - 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() - h + s, s, closePixmap); + p.drawPixmap(width() - (h * 2 + spacing) + s, s, forwardPixmap); + p.drawPixmap(width() - (h * 3 + spacing * 2) + s, s, backPixmap); + + p.end(); +} diff --git a/examples/webkitwidgets/embedded/anomaly/src/ControlStrip.h b/examples/webkitwidgets/embedded/anomaly/src/ControlStrip.h new file mode 100644 index 0000000..8c37036 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/ControlStrip.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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(); + void closeClicked(); + +protected: + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + QPixmap menuPixmap; + QPixmap backPixmap; + QPixmap forwardPixmap; + QPixmap closePixmap; +}; + +#endif // CONTROLSTRIP_H diff --git a/examples/webkitwidgets/embedded/anomaly/src/HomeView.cpp b/examples/webkitwidgets/embedded/anomaly/src/HomeView.cpp new file mode 100644 index 0000000..9bc0fee --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/HomeView.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "HomeView.h" + +#include <QtCore> +#include <QtWidgets> + +#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/examples/webkitwidgets/embedded/anomaly/src/HomeView.h b/examples/webkitwidgets/embedded/anomaly/src/HomeView.h new file mode 100644 index 0000000..bac25ae --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/HomeView.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HOMEVIEW_H +#define HOMEVIEW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +class QUrl; +QT_END_NAMESPACE + +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/examples/webkitwidgets/embedded/anomaly/src/Main.cpp b/examples/webkitwidgets/embedded/anomaly/src/Main.cpp new file mode 100644 index 0000000..958738d --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/Main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtWidgets> +#include <QtWebKitWidgets> + +#include "BrowserWindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + app.setApplicationName("Anomaly"); + app.setApplicationVersion("0.0.0"); + + BrowserWindow window; + window.resize(360, 640); + window.show(); + app.setStyle("windows"); + +#ifdef QT_KEYPAD_NAVIGATION + QApplication::setNavigationMode(Qt::NavigationModeCursorAuto); +#endif + return app.exec(); +} diff --git a/examples/webkitwidgets/embedded/anomaly/src/TitleBar.cpp b/examples/webkitwidgets/embedded/anomaly/src/TitleBar.cpp new file mode 100644 index 0000000..c6a67e8 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/TitleBar.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "TitleBar.h" + +#include <QtCore> +#include <QtWidgets> + +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/examples/webkitwidgets/embedded/anomaly/src/TitleBar.h b/examples/webkitwidgets/embedded/anomaly/src/TitleBar.h new file mode 100644 index 0000000..9747f97 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/TitleBar.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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/examples/webkitwidgets/embedded/anomaly/src/ZoomStrip.cpp b/examples/webkitwidgets/embedded/anomaly/src/ZoomStrip.cpp new file mode 100644 index 0000000..5b0b15e --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/ZoomStrip.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "ZoomStrip.h" + +#include <QtCore> +#include <QtWidgets> + +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/examples/webkitwidgets/embedded/anomaly/src/ZoomStrip.h b/examples/webkitwidgets/embedded/anomaly/src/ZoomStrip.h new file mode 100644 index 0000000..a30b6a3 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/ZoomStrip.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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/examples/webkitwidgets/embedded/anomaly/src/anomaly.qrc b/examples/webkitwidgets/embedded/anomaly/src/anomaly.qrc new file mode 100644 index 0000000..d8ea630 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/anomaly.qrc @@ -0,0 +1,10 @@ +<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> + <file>images/button-close.png</file> + </qresource> +</RCC> diff --git a/examples/webkitwidgets/embedded/anomaly/src/flickcharm.cpp b/examples/webkitwidgets/embedded/anomaly/src/flickcharm.cpp new file mode 100644 index 0000000..4e30ee8 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/flickcharm.cpp @@ -0,0 +1,402 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "flickcharm.h" + +#include <QAbstractScrollArea> +#include <QApplication> +#include <QBasicTimer> +#include <QEvent> +#include <QHash> +#include <QList> +#include <QMouseEvent> +#include <QScrollBar> +#include <QTime> +#include <QWebFrame> +#include <QWebView> + +#include <QDebug> + +const int fingerAccuracyThreshold = 3; + +struct FlickData { + typedef enum { + Steady, // Interaction without scrolling + ManualScroll, // Scrolling manually with the finger on the screen + AutoScroll, // Scrolling automatically + AutoScrollAcceleration // Scrolling automatically but a finger is on the screen + } State; + State state; + QWidget *widget; + QPoint pressPos; + QPoint lastPos; + QPoint speed; + QTime speedTimer; + QList<QEvent*> ignored; + QTime accelerationTimer; + bool lastPosValid:1; + bool waitingAcceleration:1; + + FlickData() + : lastPosValid(false) + , waitingAcceleration(false) + {} + + void resetSpeed() + { + speed = QPoint(); + lastPosValid = false; + } + void updateSpeed(const QPoint &newPosition) + { + if (lastPosValid) { + const int timeElapsed = speedTimer.elapsed(); + if (timeElapsed) { + const QPoint newPixelDiff = (newPosition - lastPos); + const QPoint pixelsPerSecond = newPixelDiff * (1000 / timeElapsed); + // fingers are inacurates, we ignore small changes to avoid stopping the autoscroll because + // of a small horizontal offset when scrolling vertically + const int newSpeedY = (qAbs(pixelsPerSecond.y()) > fingerAccuracyThreshold) ? pixelsPerSecond.y() : 0; + const int newSpeedX = (qAbs(pixelsPerSecond.x()) > fingerAccuracyThreshold) ? pixelsPerSecond.x() : 0; + if (state == AutoScrollAcceleration) { + const int max = 4000; // px by seconds + const int oldSpeedY = speed.y(); + const int oldSpeedX = speed.x(); + if ((oldSpeedY <= 0 && newSpeedY <= 0) || (oldSpeedY >= 0 && newSpeedY >= 0) + && (oldSpeedX <= 0 && newSpeedX <= 0) || (oldSpeedX >= 0 && newSpeedX >= 0)) { + speed.setY(qBound(-max, (oldSpeedY + (newSpeedY / 4)), max)); + speed.setX(qBound(-max, (oldSpeedX + (newSpeedX / 4)), max)); + } else { + speed = QPoint(); + } + } else { + const int max = 2500; // px by seconds + // we average the speed to avoid strange effects with the last delta + if (!speed.isNull()) { + speed.setX(qBound(-max, (speed.x() / 4) + (newSpeedX * 3 / 4), max)); + speed.setY(qBound(-max, (speed.y() / 4) + (newSpeedY * 3 / 4), max)); + } else { + speed = QPoint(newSpeedX, newSpeedY); + } + } + } + } else { + lastPosValid = true; + } + speedTimer.start(); + lastPos = newPosition; + } + + // scroll by dx, dy + // return true if the widget was scrolled + bool scrollWidget(const int dx, const int dy) + { + QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget); + if (scrollArea) { + const int x = scrollArea->horizontalScrollBar()->value(); + const int y = scrollArea->verticalScrollBar()->value(); + scrollArea->horizontalScrollBar()->setValue(x - dx); + scrollArea->verticalScrollBar()->setValue(y - dy); + return (scrollArea->horizontalScrollBar()->value() != x + || scrollArea->verticalScrollBar()->value() != y); + } + + QWebView *webView = qobject_cast<QWebView*>(widget); + if (webView) { + QWebFrame *frame = webView->page()->mainFrame(); + const QPoint position = frame->scrollPosition(); + frame->setScrollPosition(position - QPoint(dx, dy)); + return frame->scrollPosition() != position; + } + return false; + } + + bool scrollTo(const QPoint &newPosition) + { + const QPoint delta = newPosition - lastPos; + updateSpeed(newPosition); + return scrollWidget(delta.x(), delta.y()); + } +}; + +class FlickCharmPrivate +{ +public: + QHash<QWidget*, FlickData*> flickData; + QBasicTimer ticker; + QTime timeCounter; + void startTicker(QObject *object) + { + if (!ticker.isActive()) + ticker.start(15, object); + timeCounter.start(); + } +}; + +FlickCharm::FlickCharm(QObject *parent): QObject(parent) +{ + d = new FlickCharmPrivate; +} + +FlickCharm::~FlickCharm() +{ + delete d; +} + +void FlickCharm::activateOn(QWidget *widget) +{ + QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget); + if (scrollArea) { + scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + QWidget *viewport = scrollArea->viewport(); + + viewport->installEventFilter(this); + scrollArea->installEventFilter(this); + + d->flickData.remove(viewport); + d->flickData[viewport] = new FlickData; + d->flickData[viewport]->widget = widget; + d->flickData[viewport]->state = FlickData::Steady; + + return; + } + + QWebView *webView = qobject_cast<QWebView*>(widget); + if (webView) { + QWebFrame *frame = webView->page()->mainFrame(); + frame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); + frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); + + webView->installEventFilter(this); + + d->flickData.remove(webView); + d->flickData[webView] = new FlickData; + d->flickData[webView]->widget = webView; + d->flickData[webView]->state = FlickData::Steady; + + return; + } + + qWarning() << "FlickCharm only works on QAbstractScrollArea (and derived classes)"; + qWarning() << "or QWebView (and derived classes)"; +} + +void FlickCharm::deactivateFrom(QWidget *widget) +{ + QAbstractScrollArea *scrollArea = qobject_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 = qobject_cast<QWebView*>(widget); + if (webView) { + webView->removeEventFilter(this); + + delete d->flickData[webView]; + d->flickData.remove(webView); + + return; + } +} + +static QPoint deaccelerate(const QPoint &speed, const int deltatime) +{ + const int deltaSpeed = deltatime; + + int x = speed.x(); + int y = speed.y(); + x = (x == 0) ? x : (x > 0) ? qMax(0, x - deltaSpeed) : qMin(0, x + deltaSpeed); + y = (y == 0) ? y : (y > 0) ? qMax(0, y - deltaSpeed) : qMin(0, y + deltaSpeed); + return QPoint(x, y); +} + +bool FlickCharm::eventFilter(QObject *object, QEvent *event) +{ + if (!object->isWidgetType()) + return false; + + const QEvent::Type type = event->type(); + + switch (type) { + case QEvent::MouseButtonPress: + case QEvent::MouseMove: + case QEvent::MouseButtonRelease: + break; + case QEvent::MouseButtonDblClick: // skip double click + return true; + default: + return false; + } + + QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); + if (type == QEvent::MouseMove && mouseEvent->buttons() != Qt::LeftButton) + return false; + + if (mouseEvent->modifiers() != Qt::NoModifier) + return false; + + QWidget *viewport = qobject_cast<QWidget*>(object); + FlickData *data = d->flickData.value(viewport); + if (!viewport || !data || data->ignored.removeAll(event)) + return false; + + const QPoint mousePos = mouseEvent->pos(); + bool consumed = false; + switch (data->state) { + + case FlickData::Steady: + if (type == QEvent::MouseButtonPress) { + consumed = true; + data->pressPos = mousePos; + } else if (type == QEvent::MouseButtonRelease) { + consumed = true; + QMouseEvent *event1 = new QMouseEvent(QEvent::MouseButtonPress, + data->pressPos, Qt::LeftButton, + Qt::LeftButton, Qt::NoModifier); + QMouseEvent *event2 = new QMouseEvent(QEvent::MouseButtonRelease, + data->pressPos, Qt::LeftButton, + Qt::LeftButton, Qt::NoModifier); + + data->ignored << event1; + data->ignored << event2; + QApplication::postEvent(object, event1); + QApplication::postEvent(object, event2); + } else if (type == QEvent::MouseMove) { + consumed = true; + data->scrollTo(mousePos); + + const QPoint delta = mousePos - data->pressPos; + if (delta.x() > fingerAccuracyThreshold || delta.y() > fingerAccuracyThreshold) + data->state = FlickData::ManualScroll; + } + break; + + case FlickData::ManualScroll: + if (type == QEvent::MouseMove) { + consumed = true; + data->scrollTo(mousePos); + } else if (type == QEvent::MouseButtonRelease) { + consumed = true; + data->state = FlickData::AutoScroll; + data->lastPosValid = false; + d->startTicker(this); + } + break; + + case FlickData::AutoScroll: + if (type == QEvent::MouseButtonPress) { + consumed = true; + data->state = FlickData::AutoScrollAcceleration; + data->waitingAcceleration = true; + data->accelerationTimer.start(); + data->updateSpeed(mousePos); + data->pressPos = mousePos; + } else if (type == QEvent::MouseButtonRelease) { + consumed = true; + data->state = FlickData::Steady; + data->resetSpeed(); + } + break; + + case FlickData::AutoScrollAcceleration: + if (type == QEvent::MouseMove) { + consumed = true; + data->updateSpeed(mousePos); + data->accelerationTimer.start(); + if (data->speed.isNull()) + data->state = FlickData::ManualScroll; + } else if (type == QEvent::MouseButtonRelease) { + consumed = true; + data->state = FlickData::AutoScroll; + data->waitingAcceleration = false; + data->lastPosValid = false; + } + break; + default: + break; + } + data->lastPos = mousePos; + return true; +} + +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::AutoScrollAcceleration + && data->waitingAcceleration + && data->accelerationTimer.elapsed() > 40) { + data->state = FlickData::ManualScroll; + data->resetSpeed(); + } + if (data->state == FlickData::AutoScroll || data->state == FlickData::AutoScrollAcceleration) { + const int timeElapsed = d->timeCounter.elapsed(); + const QPoint delta = (data->speed) * timeElapsed / 1000; + bool hasScrolled = data->scrollWidget(delta.x(), delta.y()); + + if (data->speed.isNull() || !hasScrolled) + data->state = FlickData::Steady; + else + count++; + data->speed = deaccelerate(data->speed, timeElapsed); + } + } + + if (!count) + d->ticker.stop(); + else + d->timeCounter.start(); + + QObject::timerEvent(event); +} diff --git a/examples/webkitwidgets/embedded/anomaly/src/flickcharm.h b/examples/webkitwidgets/embedded/anomaly/src/flickcharm.h new file mode 100644 index 0000000..8042ecd --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/flickcharm.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FLICKCHARM_H +#define FLICKCHARM_H + +#include <QObject> + +QT_BEGIN_NAMESPACE +class QWidget; +QT_END_NAMESPACE + +class FlickCharmPrivate; + +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/examples/webkitwidgets/embedded/anomaly/src/images/button-close.png b/examples/webkitwidgets/embedded/anomaly/src/images/button-close.png Binary files differnew file mode 100644 index 0000000..7a7b048 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/images/button-close.png diff --git a/examples/webkitwidgets/embedded/anomaly/src/images/edit-find.png b/examples/webkitwidgets/embedded/anomaly/src/images/edit-find.png Binary files differnew file mode 100644 index 0000000..b84b1e2 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/images/edit-find.png diff --git a/examples/webkitwidgets/embedded/anomaly/src/images/go-next.png b/examples/webkitwidgets/embedded/anomaly/src/images/go-next.png Binary files differnew file mode 100644 index 0000000..ed89a36 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/images/go-next.png diff --git a/examples/webkitwidgets/embedded/anomaly/src/images/go-previous.png b/examples/webkitwidgets/embedded/anomaly/src/images/go-previous.png Binary files differnew file mode 100644 index 0000000..44e803d --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/images/go-previous.png diff --git a/examples/webkitwidgets/embedded/anomaly/src/images/list-add.png b/examples/webkitwidgets/embedded/anomaly/src/images/list-add.png Binary files differnew file mode 100644 index 0000000..2acdd8f --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/images/list-add.png diff --git a/examples/webkitwidgets/embedded/anomaly/src/images/list-remove.png b/examples/webkitwidgets/embedded/anomaly/src/images/list-remove.png Binary files differnew file mode 100644 index 0000000..c5524f7 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/images/list-remove.png diff --git a/examples/webkitwidgets/embedded/anomaly/src/webview.cpp b/examples/webkitwidgets/embedded/anomaly/src/webview.cpp new file mode 100644 index 0000000..03d9ced --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/webview.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "webview.h" + +#include <QPaintEvent> +#include <QWebFrame> + +WebView::WebView(QWidget *parent) + : QWebView(parent) + , inLoading(false) +{ + connect(this, SIGNAL(loadStarted()), this, SLOT(newPageLoading())); + connect(this, SIGNAL(loadFinished(bool)), this, SLOT(pageLoaded(bool))); + page()->setPreferredContentsSize(QSize(1024, 768)); +} + +void WebView::paintEvent(QPaintEvent *event) +{ + if (inLoading && loadingTime.elapsed() < 750) { + QPainter painter(this); + painter.setBrush(Qt::white); + painter.setPen(Qt::NoPen); + foreach (const QRect &rect, event->region().rects()) { + painter.drawRect(rect); + } + } else { + QWebView::paintEvent(event); + } +} + +void WebView::newPageLoading() +{ + inLoading = true; + loadingTime.start(); +} + +void WebView::pageLoaded(bool) +{ + inLoading = false; + update(); +} diff --git a/examples/webkitwidgets/embedded/anomaly/src/webview.h b/examples/webkitwidgets/embedded/anomaly/src/webview.h new file mode 100644 index 0000000..d7d4193 --- /dev/null +++ b/examples/webkitwidgets/embedded/anomaly/src/webview.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 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 the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WEBVIEW_H +#define WEBVIEW_H + +#include <QWebView> +#include <QTime> + +class WebView : public QWebView +{ + Q_OBJECT +public: + WebView(QWidget *parent = 0); + +protected: + void paintEvent(QPaintEvent *event); + +private slots: + void newPageLoading(); + void pageLoaded(bool ok); + +private: + QTime loadingTime; + bool inLoading; +}; + +#endif // WEBVIEW_H diff --git a/examples/webkitwidgets/embedded/embedded.pro b/examples/webkitwidgets/embedded/embedded.pro new file mode 100644 index 0000000..9c61eec --- /dev/null +++ b/examples/webkitwidgets/embedded/embedded.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += anomaly |