diff options
-rw-r--r-- | DeclarativeDesktopWebView.cpp | 77 | ||||
-rw-r--r-- | DeclarativeDesktopWebView.h | 54 | ||||
-rw-r--r-- | MainView.cpp | 54 | ||||
-rw-r--r-- | MainView.h | 49 | ||||
-rw-r--r-- | PageGraphicsView.cpp | 85 | ||||
-rw-r--r-- | PageGraphicsView.h | 56 | ||||
-rw-r--r-- | PageWidget.cpp | 4 | ||||
-rw-r--r-- | PageWidget.h | 4 | ||||
-rw-r--r-- | main.cpp | 4 | ||||
-rw-r--r-- | qml/main.qml | 22 | ||||
-rw-r--r-- | snowshoe.pro | 11 | ||||
-rw-r--r-- | snowshoe.qrc | 9 |
12 files changed, 278 insertions, 151 deletions
diff --git a/DeclarativeDesktopWebView.cpp b/DeclarativeDesktopWebView.cpp new file mode 100644 index 0000000..bb9e225 --- /dev/null +++ b/DeclarativeDesktopWebView.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** + * Copyright (C) 2011 Instituto Nokia de Tecnologia (INdT) * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + ****************************************************************************/ + +#include "DeclarativeDesktopWebView.h" + +#include "qdesktopwebview.h" + +class DeclarativeDesktopWebViewPrivate { +public: + DeclarativeDesktopWebViewPrivate(DeclarativeDesktopWebView* v) + : q(v) + , view(new QDesktopWebView()) + { + view->setParentItem(q); + view->setPos(0, 0); + + QObject::connect(view, SIGNAL(titleChanged(QString)), q, SIGNAL(titleChanged(QString))); + QObject::connect(view, SIGNAL(statusBarMessageChanged(QString)), q, SIGNAL(statusBarMessageChanged(QString))); + QObject::connect(view, SIGNAL(loadStarted()), q, SIGNAL(loadStarted())); + QObject::connect(view, SIGNAL(loadSucceeded()), q, SIGNAL(loadSucceeded())); + QObject::connect(view, SIGNAL(loadProgress(int)), q, SIGNAL(loadProgress(int))); + QObject::connect(view, SIGNAL(urlChanged(QUrl)), q, SIGNAL(urlChanged(QUrl))); + } + + ~DeclarativeDesktopWebViewPrivate() + { + delete view; + } + + DeclarativeDesktopWebView* q; + QDesktopWebView* view; +}; + +DeclarativeDesktopWebView::DeclarativeDesktopWebView(QDeclarativeItem *parent) + : QDeclarativeItem(parent) + , d(new DeclarativeDesktopWebViewPrivate(this)) +{ +} + +DeclarativeDesktopWebView::~DeclarativeDesktopWebView() +{ + delete d; +} + +QString DeclarativeDesktopWebView::title() const +{ + return d->view->title(); +} + +QUrl DeclarativeDesktopWebView::url() const +{ + return d->view->url(); +} + +void DeclarativeDesktopWebView::setUrl(const QUrl& url) +{ + d->view->load(url); +} + +void DeclarativeDesktopWebView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); + d->view->setGeometry(0, 0, newGeometry.width(), newGeometry.height()); +} diff --git a/DeclarativeDesktopWebView.h b/DeclarativeDesktopWebView.h new file mode 100644 index 0000000..69fa6a0 --- /dev/null +++ b/DeclarativeDesktopWebView.h @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (C) 2011 Instituto Nokia de Tecnologia (INdT) * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + ****************************************************************************/ + +#ifndef DeclarativeDesktopWebView_h +#define DeclarativeDesktopWebView_h + +#include <QtDeclarative/QDeclarativeItem> + +class DeclarativeDesktopWebViewPrivate; + +class DeclarativeDesktopWebView : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QString title READ title NOTIFY titleChanged) + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) +public: + DeclarativeDesktopWebView(QDeclarativeItem *parent = 0); + ~DeclarativeDesktopWebView(); + + QUrl url() const; + QString title() const; + +public Q_SLOTS: + void setUrl(const QUrl&); + +protected: + virtual void geometryChanged(const QRectF&, const QRectF&); + +Q_SIGNALS: + void titleChanged(const QString&); + void statusBarMessageChanged(const QString&); + void loadStarted(); + void loadSucceeded(); + void loadProgress(int progress); + void urlChanged(const QUrl&); + +private: + DeclarativeDesktopWebViewPrivate* d; +}; + +#endif // DeclarativeDesktopWebView_h diff --git a/MainView.cpp b/MainView.cpp new file mode 100644 index 0000000..043f29b --- /dev/null +++ b/MainView.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** + * Copyright (c) 2011 Andreas Kling <awesomekling@gmail.com> * + * Copyright (C) 2011 Instituto Nokia de Tecnologia (INdT) * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + ****************************************************************************/ + +#include "MainView.h" + +#include <QtDeclarative/QDeclarativeItem> + +MainView::MainView(QWidget* parent) + : QDeclarativeView(parent) +{ + setAlignment(Qt::AlignLeft | Qt::AlignTop); + setSource(QUrl("qrc:/qml/main.qml")); + + m_view = qobject_cast<QDeclarativeItem*>(rootObject()); + Q_ASSERT(m_view); + + connect(m_view, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); + connect(m_view, SIGNAL(statusBarMessageChanged(QString)), this, SIGNAL(statusBarMessageChanged(QString))); + connect(m_view, SIGNAL(loadStarted()), this, SIGNAL(loadStarted())); + connect(m_view, SIGNAL(loadSucceeded()), this, SIGNAL(loadSucceeded())); + connect(m_view, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); + connect(m_view, SIGNAL(urlChanged(QUrl)), this, SIGNAL(urlChanged(QUrl))); +} + +MainView::~MainView() +{ +} + +void MainView::resizeEvent(QResizeEvent* event) +{ + QDeclarativeView::resizeEvent(event); + + m_view->setWidth(width()); + m_view->setHeight(height()); +} + +void MainView::load(const QUrl& url) +{ + QMetaObject::invokeMethod(m_view, "setUrl", Qt::AutoConnection, Q_ARG(QUrl, url)); +} diff --git a/MainView.h b/MainView.h new file mode 100644 index 0000000..29ae0db --- /dev/null +++ b/MainView.h @@ -0,0 +1,49 @@ +/**************************************************************************** + * Copyright (c) 2011 Andreas Kling <awesomekling@gmail.com> * + * Copyright (C) 2011 Instituto Nokia de Tecnologia (INdT) * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + ****************************************************************************/ + +#ifndef MainView_h +#define MainView_h + +#include <QtDeclarative/QDeclarativeView> + +class QDeclarativeItem; + +class MainView : public QDeclarativeView { + Q_OBJECT + +public: + MainView(QWidget* parent = 0); + virtual ~MainView(); + + void load(const QUrl&); + +Q_SIGNALS: + void titleChanged(const QString&); + void statusBarMessageChanged(const QString&); + void loadStarted(); + void loadSucceeded(); + void loadProgress(int progress); + void urlChanged(const QUrl&); + +protected: + virtual void resizeEvent(QResizeEvent*); + +private: + QDeclarativeItem* m_view; +}; + +#endif diff --git a/PageGraphicsView.cpp b/PageGraphicsView.cpp deleted file mode 100644 index 54203ee..0000000 --- a/PageGraphicsView.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2011 Andreas Kling <awesomekling@gmail.com> * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -#include "PageGraphicsView.h" - -#include "CrashGraphicsItem.h" -#include <QtGui/QGraphicsScene> - -#include "qdesktopwebview.h" - -PageGraphicsView::PageGraphicsView(QWidget* parent) - : QGraphicsView(parent) - , m_crashItem(0) -{ - m_webViewItem = new QDesktopWebView(); - setScene(new QGraphicsScene(this)); - scene()->addItem(m_webViewItem); - m_webViewItem->setFocus(); - - setFrameShape(QFrame::NoFrame); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - connect(m_webViewItem, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); - connect(m_webViewItem, SIGNAL(statusBarMessageChanged(QString)), this, SIGNAL(statusBarMessageChanged(QString))); - connect(m_webViewItem, SIGNAL(loadStarted()), this, SIGNAL(loadStarted())); - connect(m_webViewItem, SIGNAL(loadSucceeded()), this, SIGNAL(loadSucceeded())); - connect(m_webViewItem, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); - connect(m_webViewItem, SIGNAL(urlChanged(QUrl)), this, SIGNAL(urlChanged(QUrl))); - - // Keeping this feature commented out until we have support for it in the new API. -// connect(page(), SIGNAL(engineConnectionChanged(bool)), SLOT(onEngineConnectionChanged(bool))); -} - -PageGraphicsView::~PageGraphicsView() -{ - delete m_webViewItem; - m_webViewItem = 0; -} - -void PageGraphicsView::resizeEvent(QResizeEvent* event) -{ - QGraphicsView::resizeEvent(event); - QRectF rect(QPoint(0, 0), event->size()); - m_webViewItem->setGeometry(rect); - if (m_crashItem) - m_crashItem->setGeometry(rect); - scene()->setSceneRect(rect); -} - -void PageGraphicsView::load(const QUrl& url) -{ - return m_webViewItem->load(url); -} - -void PageGraphicsView::onEngineConnectionChanged(bool connected) -{ - if (connected) { - delete m_crashItem; - m_crashItem = 0; - return; - } - - m_crashItem = new CrashGraphicsItem; - m_crashItem->setZValue(1); - m_crashItem->setGeometry(scene()->sceneRect()); - scene()->addItem(m_crashItem); - m_crashItem->setVisible(true); -} diff --git a/PageGraphicsView.h b/PageGraphicsView.h deleted file mode 100644 index eaf63fa..0000000 --- a/PageGraphicsView.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2011 Andreas Kling <awesomekling@gmail.com> * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * - ***************************************************************************/ - -#ifndef PageGraphicsView_h -#define PageGraphicsView_h - -#include <QGraphicsView> - -class CrashGraphicsItem; -class QDesktopWebView; - -class PageGraphicsView : public QGraphicsView { - Q_OBJECT - -public: - PageGraphicsView(QWidget* parent = 0); - virtual ~PageGraphicsView(); - - void load(const QUrl&); - -Q_SIGNALS: - void titleChanged(const QString&); - void statusBarMessageChanged(const QString&); - void loadStarted(); - void loadSucceeded(); - void loadProgress(int progress); - void urlChanged(const QUrl&); - -protected: - virtual void resizeEvent(QResizeEvent*); - -private slots: - void onEngineConnectionChanged(bool); - -private: - CrashGraphicsItem* m_crashItem; - QDesktopWebView* m_webViewItem; -}; - -#endif diff --git a/PageWidget.cpp b/PageWidget.cpp index 5daa271..36e1958 100644 --- a/PageWidget.cpp +++ b/PageWidget.cpp @@ -20,7 +20,7 @@ #include "PageWidget.h" #include "BrowserWindow.h" -#include "PageGraphicsView.h" +#include "MainView.h" #include <QtGui/QAction> #include <QtGui/QApplication> #include <QtGui/QLineEdit> @@ -49,7 +49,7 @@ PageWidget::PageWidget(QWidget* parent) layout->setSpacing(0); QToolBar* toolBar = new QToolBar; - m_view = new PageGraphicsView(); + m_view = new MainView(); layout->addWidget(toolBar); layout->addWidget(m_view); diff --git a/PageWidget.h b/PageWidget.h index 19ec103..0905f48 100644 --- a/PageWidget.h +++ b/PageWidget.h @@ -22,7 +22,7 @@ #include <QtGui/QWidget> -class PageGraphicsView; +class MainView; class QLineEdit; class QUrl; @@ -58,7 +58,7 @@ private slots: private: QLineEdit* m_urlEdit; - PageGraphicsView* m_view; + MainView* m_view; bool m_loading; }; @@ -22,12 +22,16 @@ #include <QtCore/QLatin1String> #include <QtGui/QApplication> +#include "DeclarativeDesktopWebView.h" + int main(int argc, char** argv) { QApplication app(argc, argv); app.setQuitOnLastWindowClosed(true); app.setApplicationName(QLatin1String("Snowshoe")); + qmlRegisterType<DeclarativeDesktopWebView>("Snowshoe", 1, 0, "DeclarativeDesktopWebView"); + QStringList arguments = app.arguments(); arguments.removeAt(0); diff --git a/qml/main.qml b/qml/main.qml new file mode 100644 index 0000000..c1cbc64 --- /dev/null +++ b/qml/main.qml @@ -0,0 +1,22 @@ +/**************************************************************************** + * Copyright (C) 2011 Instituto Nokia de Tecnologia (INdT) * + * * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Lesser General Public License for more details. * + ****************************************************************************/ + +import QtQuick 1.0 +import Snowshoe 1.0 + +DeclarativeDesktopWebView { + id: desktopview +} diff --git a/snowshoe.pro b/snowshoe.pro index d3311e2..7cf7bef 100644 --- a/snowshoe.pro +++ b/snowshoe.pro @@ -1,18 +1,22 @@ TEMPLATE = app TARGET = snowshoe +QT += declarative + SOURCES += \ main.cpp \ BrowserWindow.cpp \ CrashGraphicsItem.cpp \ - PageGraphicsView.cpp \ + MainView.cpp \ PageWidget.cpp \ + DeclarativeDesktopWebView.cpp \ HEADERS += \ BrowserWindow.h \ CrashGraphicsItem.h \ - PageGraphicsView.h \ + MainView.h \ PageWidget.h \ + DeclarativeDesktopWebView.h \ RESOURCES += \ snowshoe.qrc @@ -54,3 +58,6 @@ macx { unix : QMAKE_RPATHDIR = $$WEBKIT_BUILD_DIR/lib $$QMAKE_RPATHDIR LIBS += -lQtWebKit } + +OTHER_FILES += \ + qml/main.qml diff --git a/snowshoe.qrc b/snowshoe.qrc index c5292e3..ecf2fae 100644 --- a/snowshoe.qrc +++ b/snowshoe.qrc @@ -1,5 +1,6 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource> - <file>images/spinner.gif</file> -</qresource> +<RCC> + <qresource prefix="/"> + <file>images/spinner.gif</file> + <file>qml/main.qml</file> + </qresource> </RCC> |