summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@openbossa.org>2011-07-28 11:33:30 -0300
committerAlexis Menard <alexis.menard@openbossa.org>2011-08-03 14:35:50 -0300
commitb4505dbe6ee11f598c88718b005be1aca37fa729 (patch)
treef047d03e075d7e1bddcb483c0d95356a58178163
parent9d0842f51bec4f61f387b8ed3244be0b21bbef2b (diff)
Port Snowshoe to Qt5 and QtQuick 2.0.
It mostly work again with the exception of text rendering a bit ugly and the triple click which is not working. Reviewed-by: Caio Oliveira
-rw-r--r--BrowserObject.cpp5
-rw-r--r--BrowserObject.h1
-rw-r--r--DeclarativeDesktopWebView.cpp123
-rw-r--r--DeclarativeDesktopWebView.h71
-rw-r--r--MainView.cpp18
-rw-r--r--MainView.h12
-rw-r--r--TripleClickMonitor.cpp4
-rw-r--r--TripleClickMonitor.h10
-rw-r--r--main.cpp6
-rw-r--r--qml/PageWidget.qml15
-rw-r--r--qml/Tab.qml13
-rw-r--r--qml/TabWidget.js2
-rw-r--r--qml/TabWidget.qml2
-rw-r--r--qml/UrlBar.qml9
-rw-r--r--qml/UrlEdit.qml2
-rw-r--r--qml/main.qml2
-rw-r--r--snowshoe.pro2
17 files changed, 57 insertions, 240 deletions
diff --git a/BrowserObject.cpp b/BrowserObject.cpp
index 29621ab..d5271ac 100644
--- a/BrowserObject.cpp
+++ b/BrowserObject.cpp
@@ -44,3 +44,8 @@ bool BrowserObject::isUrlValid(const QUrl& url)
{
return url.isValid();
}
+
+bool BrowserObject::isUrlEmpty(const QUrl& url)
+{
+ return url.isEmpty();
+}
diff --git a/BrowserObject.h b/BrowserObject.h
index d52bf1d..329bdb6 100644
--- a/BrowserObject.h
+++ b/BrowserObject.h
@@ -32,6 +32,7 @@ public:
Q_INVOKABLE QUrl urlFromUserInput(const QString&);
Q_INVOKABLE bool isUrlValid(const QUrl&);
+ Q_INVOKABLE bool isUrlEmpty(const QUrl& url);
signals:
void windowTitleChanged();
diff --git a/DeclarativeDesktopWebView.cpp b/DeclarativeDesktopWebView.cpp
deleted file mode 100644
index 636d2db..0000000
--- a/DeclarativeDesktopWebView.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/****************************************************************************
- * 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)
- , loadProgress(0)
- , 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(loadFailed(QWebError)), q, SIGNAL(loadFailed(QWebError)));
- QObject::connect(view, SIGNAL(loadProgress(int)), q, SLOT(_q_loadProgressChanged(int)));
- QObject::connect(view, SIGNAL(urlChanged(QUrl)), q, SIGNAL(urlChanged(QUrl)));
- }
-
- ~DeclarativeDesktopWebViewPrivate()
- {
- delete view;
- }
-
- void _q_loadProgressChanged(int progress)
- {
- loadProgress = progress;
- emit q->loadProgressChanged();
- }
-
- DeclarativeDesktopWebView* q;
- int loadProgress;
- 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::back()
-{
- d->view->navigationAction(QtWebKit::Back)->trigger();
-}
-
-void DeclarativeDesktopWebView::forward()
-{
- d->view->navigationAction(QtWebKit::Forward)->trigger();
-}
-
-void DeclarativeDesktopWebView::reload()
-{
- d->view->navigationAction(QtWebKit::Reload)->trigger();
-}
-
-void DeclarativeDesktopWebView::stop()
-{
- d->view->navigationAction(QtWebKit::Stop)->trigger();
-}
-
-int DeclarativeDesktopWebView::loadProgress()
-{
- return d->loadProgress;
-}
-
-void DeclarativeDesktopWebView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
-{
- QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
- d->view->setGeometry(0, 0, newGeometry.width(), newGeometry.height());
-}
-
-void DeclarativeDesktopWebView::setFocusOnView()
-{
- d->view->setFocus();
-}
-
-bool DeclarativeDesktopWebView::hasViewFocus()
-{
- return d->view->hasFocus();
-}
-
-#include "moc_DeclarativeDesktopWebView.cpp"
diff --git a/DeclarativeDesktopWebView.h b/DeclarativeDesktopWebView.h
deleted file mode 100644
index 9f71896..0000000
--- a/DeclarativeDesktopWebView.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
- * 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 QWebError;
-
-class DeclarativeDesktopWebView : public QDeclarativeItem
-{
- Q_OBJECT
- Q_PROPERTY(QString title READ title NOTIFY titleChanged)
- Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
- Q_PROPERTY(int loadProgress READ loadProgress NOTIFY loadProgressChanged)
-public:
- DeclarativeDesktopWebView(QDeclarativeItem *parent = 0);
- ~DeclarativeDesktopWebView();
-
- QUrl url() const;
- QString title() const;
-
- int loadProgress();
-
- Q_INVOKABLE bool isUrlEmpty() { return url().isEmpty(); }
- Q_INVOKABLE bool hasViewFocus();
- Q_INVOKABLE void setFocusOnView();
-
-public Q_SLOTS:
- void setUrl(const QUrl&);
- void back();
- void forward();
- void reload();
- void stop();
-
-protected:
- virtual void geometryChanged(const QRectF&, const QRectF&);
-
-Q_SIGNALS:
- void titleChanged(const QString&);
- void statusBarMessageChanged(const QString&);
- void loadStarted();
- void loadSucceeded();
- void loadFailed(const QWebError&);
- void loadProgressChanged();
- void urlChanged(const QUrl&);
-
-private:
- DeclarativeDesktopWebViewPrivate* d;
-
- friend class DeclarativeDesktopWebViewPrivate;
-
- Q_PRIVATE_SLOT(d, void _q_loadProgressChanged(int))
-};
-
-#endif // DeclarativeDesktopWebView_h
diff --git a/MainView.cpp b/MainView.cpp
index a3dc465..b87a0c0 100644
--- a/MainView.cpp
+++ b/MainView.cpp
@@ -19,11 +19,11 @@
#include "BrowserObject.h"
#include "BrowserWindow.h"
-#include "DeclarativeDesktopWebView.h"
+#include "qdesktopwebview.h"
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeEngine>
-#include <QtDeclarative/QDeclarativeItem>
+#include <QtDeclarative/QSGItem>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QLineEdit>
@@ -33,16 +33,16 @@
#include <QUrl>
MainView::MainView(BrowserWindow* parent)
- : QDeclarativeView(parent)
+ : QSGView(parent)
, m_tabWidget(0)
{
rootContext()->setContextProperty("BrowserObject", parent->browserObject());
- setResizeMode(QDeclarativeView::SizeRootObjectToView);
+ setResizeMode(QSGView::SizeRootObjectToView);
setSource(QUrl("qrc:/qml/main.qml"));
connect(engine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
- m_tabWidget = qobject_cast<QDeclarativeItem*>(rootObject());
+ m_tabWidget = qobject_cast<QSGItem*>(rootObject());
Q_ASSERT(m_tabWidget);
setupActions();
@@ -58,16 +58,16 @@ void MainView::openInNewTab(const QString& urlFromUserInput)
if (!url.isEmpty()) {
QObject* currentActiveTab = m_tabWidget->property("currentActiveTab").value<QObject*>();
QObject* mainView = currentActiveTab->property("mainView").value<QObject*>();
- QObject* urlEdit = mainView->findChild<QDeclarativeItem*>("urlEdit");
+ QObject* urlEdit = mainView->findChild<QSGItem*>("urlEdit");
urlEdit->setProperty("text", url.toString());
- getWebViewForUrlEdit(urlEdit)->setUrl(url);
+ getWebViewForUrlEdit(urlEdit)->load(url);
}
}
-DeclarativeDesktopWebView* MainView::getWebViewForUrlEdit(QObject* urlEdit)
+QDesktopWebView* MainView::getWebViewForUrlEdit(QObject* urlEdit)
{
QObject* view = urlEdit->property("view").value<QObject*>();
- return qobject_cast<DeclarativeDesktopWebView* >(view);
+ return qobject_cast<QDesktopWebView* >(view);
}
QAction* MainView::createActionWithShortcut(const QKeySequence& shortcut)
diff --git a/MainView.h b/MainView.h
index ff74762..7e9364f 100644
--- a/MainView.h
+++ b/MainView.h
@@ -19,16 +19,16 @@
#define MainView_h
#include <QtCore/QVariant>
-#include <QtDeclarative/QDeclarativeView>
+#include <QtDeclarative/QSGView>
#include <QtGui/QKeySequence>
class BrowserWindow;
-class DeclarativeDesktopWebView;
-class QDeclarativeItem;
+class QDesktopWebView;
+class QSGItem;
class QUrl;
class QWebError;
-class MainView : public QDeclarativeView {
+class MainView : public QSGView {
Q_OBJECT
public:
@@ -46,9 +46,9 @@ private:
QAction* createActionWithShortcut(const QKeySequence&);
void setupActions();
- DeclarativeDesktopWebView* getWebViewForUrlEdit(QObject* urlEdit);
+ QDesktopWebView* getWebViewForUrlEdit(QObject* urlEdit);
- QDeclarativeItem* m_tabWidget;
+ QSGItem* m_tabWidget;
};
#endif
diff --git a/TripleClickMonitor.cpp b/TripleClickMonitor.cpp
index 42e257d..1a491c7 100644
--- a/TripleClickMonitor.cpp
+++ b/TripleClickMonitor.cpp
@@ -30,11 +30,11 @@ TripleClickMonitor::~TripleClickMonitor()
{
}
-void TripleClickMonitor::setTarget(QDeclarativeItem* target)
+void TripleClickMonitor::setTarget(QSGItem* target)
{
if (target == m_target)
return;
- QDeclarativeItem* oldTarget = m_target;
+ QSGItem* oldTarget = m_target;
if (oldTarget)
oldTarget->removeEventFilter(this);
m_target = target;
diff --git a/TripleClickMonitor.h b/TripleClickMonitor.h
index 108ccc5..38596c0 100644
--- a/TripleClickMonitor.h
+++ b/TripleClickMonitor.h
@@ -20,18 +20,18 @@
#include <QtCore/QEvent>
#include <QtCore/QObject>
#include <QtCore/QTimer>
-#include <QtDeclarative/QDeclarativeItem>
+#include <QtDeclarative/QSGItem>
class TripleClickMonitor : public QObject {
Q_OBJECT
- Q_PROPERTY(QDeclarativeItem* target READ target WRITE setTarget NOTIFY targetChanged)
+ Q_PROPERTY(QSGItem* target READ target WRITE setTarget NOTIFY targetChanged)
public:
TripleClickMonitor(QObject* parent = 0);
~TripleClickMonitor();
- QDeclarativeItem* target() const { return m_target; }
- void setTarget(QDeclarativeItem*);
+ QSGItem* target() const { return m_target; }
+ void setTarget(QSGItem*);
signals:
void targetChanged();
@@ -46,7 +46,7 @@ private:
void stopWatching();
QTimer m_timer;
- QDeclarativeItem* m_target;
+ QSGItem* m_target;
};
#endif // TripleClickMonitor_h
diff --git a/main.cpp b/main.cpp
index 44e675b..a574500 100644
--- a/main.cpp
+++ b/main.cpp
@@ -16,18 +16,20 @@
#include "BrowserWindow.h"
-#include "DeclarativeDesktopWebView.h"
+#include "qdesktopwebview.h"
#include "TripleClickMonitor.h"
#include <QtCore/QLatin1String>
#include <QtGui/QApplication>
int main(int argc, char** argv)
{
+ // FIXME: This need to be reverted when WebKit works with it.
+ qputenv("QML_NO_THREADED_RENDERER", QByteArray("1"));
+
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(true);
app.setApplicationName(QLatin1String("Snowshoe"));
- qmlRegisterType<DeclarativeDesktopWebView>("Snowshoe", 1, 0, "DeclarativeDesktopWebView");
qmlRegisterType<TripleClickMonitor>("Snowshoe", 1, 0, "TripleClickMonitor");
QStringList arguments = app.arguments();
diff --git a/qml/PageWidget.qml b/qml/PageWidget.qml
index e411dd4..186dbb5 100644
--- a/qml/PageWidget.qml
+++ b/qml/PageWidget.qml
@@ -14,7 +14,8 @@
* GNU Lesser General Public License for more details. *
****************************************************************************/
-import QtQuick 1.1
+import QtQuick 2.0
+import QtWebKit.experimental 5.0
import Snowshoe 1.0
Item {
@@ -31,13 +32,13 @@ Item {
onUrlEntered: {
var urlToBrowse = BrowserObject.urlFromUserInput(url);
if (BrowserObject.isUrlValid(urlToBrowse))
- desktopView.setUrl(urlToBrowse);
+ desktopView.load(urlToBrowse);
else
- desktopView.setUrl(fallbackUrl(url));
+ desktopView.load(fallbackUrl(url));
}
}
- DeclarativeDesktopWebView {
+ DesktopWebView {
id: desktopView
anchors.top: urlBar.bottom
anchors.topMargin: 5
@@ -51,15 +52,15 @@ Item {
onLoadSucceeded: {
root.isLoading = false
- if (tab.active && !hasViewFocus())
- setFocusOnView();
+ if (tab.active && !focus)
+ forceActiveFocus();
}
onUrlChanged: { urlBar.text = url.toString() }
onLoadFailed: {
root.isLoading = false
- url = fallbackUrl(urlBar.text)
+ load(fallbackUrl(urlBar.text))
}
onTitleChanged: { tab.text = title }
diff --git a/qml/Tab.qml b/qml/Tab.qml
index 45005c2..9b30736 100644
--- a/qml/Tab.qml
+++ b/qml/Tab.qml
@@ -14,7 +14,7 @@
* GNU Lesser General Public License for more details. *
****************************************************************************/
-import QtQuick 1.1
+import QtQuick 2.0
Item {
id: tab
@@ -36,7 +36,10 @@ Item {
property variant tabWidget: Item {}
- property variant mainView: Item {}
+ property variant mainView;
+
+ // Binding's target can't be changed on the fly let's affect it once.
+ onMainViewChanged: { heightBinding.target = widthBinding.target = mainView;}
function rightEdge() {
return content.x + content.width;
@@ -55,15 +58,15 @@ Item {
}
Binding {
+ id: heightBinding
property: "height"
value: tab.content.height - tab.headerHeight
- target: mainView
}
Binding {
+ id: widthBinding
property: "width"
value: tabWidget.width
- target: mainView
}
function syncHeader() {
@@ -151,7 +154,7 @@ Item {
anchors.topMargin: 10
anchors.leftMargin: 12
playing: visible
- visible: mainView.isLoading === true
+ visible: mainView != undefined && mainView.isLoading;
}
Text {
diff --git a/qml/TabWidget.js b/qml/TabWidget.js
index f9e5fc2..6d00569 100644
--- a/qml/TabWidget.js
+++ b/qml/TabWidget.js
@@ -28,7 +28,7 @@ function setActiveTab(newActiveTab) {
currentActiveTab = newActiveTab;
// FIXME: Do better it breaks the genericity of the tabwidget
- if (newActiveTab.mainView.desktopView.isUrlEmpty())
+ if (BrowserObject.isUrlEmpty(newActiveTab.mainView.desktopView.url))
newActiveTab.mainView.urlBar.textInput.forceActiveFocus();
else
newActiveTab.mainView.desktopView.forceActiveFocus();
diff --git a/qml/TabWidget.qml b/qml/TabWidget.qml
index 389de12..917d990 100644
--- a/qml/TabWidget.qml
+++ b/qml/TabWidget.qml
@@ -14,7 +14,7 @@
* GNU Lesser General Public License for more details. *
****************************************************************************/
-import QtQuick 1.1
+import QtQuick 2.0
import "TabWidget.js" as Core
Item {
diff --git a/qml/UrlBar.qml b/qml/UrlBar.qml
index 52eead0..dc55e34 100644
--- a/qml/UrlBar.qml
+++ b/qml/UrlBar.qml
@@ -14,7 +14,8 @@
* GNU Lesser General Public License for more details. *
****************************************************************************/
-import QtQuick 1.1
+import QtQuick 2.0
+import QtWebKit.experimental 5.0
Item {
id: root
@@ -46,7 +47,7 @@ Item {
MouseArea {
anchors.fill: parent
- onClicked: { desktopView.back(); }
+ onClicked: { desktopView.navigation.back(); }
}
}
@@ -63,7 +64,7 @@ Item {
MouseArea {
anchors.fill: parent
- onClicked: { desktopView.forward(); }
+ onClicked: { desktopView.navigation.forward(); }
}
}
@@ -80,7 +81,7 @@ Item {
MouseArea {
anchors.fill: parent
- onClicked: { desktopView.reload(); }
+ onClicked: { desktopView.navigation.reload(); }
}
}
}
diff --git a/qml/UrlEdit.qml b/qml/UrlEdit.qml
index e491244..40c7fea 100644
--- a/qml/UrlEdit.qml
+++ b/qml/UrlEdit.qml
@@ -14,7 +14,7 @@
* GNU Lesser General Public License for more details. *
****************************************************************************/
-import QtQuick 1.1
+import QtQuick 2.0
import Snowshoe 1.0
Item {
diff --git a/qml/main.qml b/qml/main.qml
index ebb50d9..c146e88 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -14,7 +14,7 @@
* GNU Lesser General Public License for more details. *
****************************************************************************/
-import QtQuick 1.1
+import QtQuick 2.0
TabWidget {
id: tabWidget
diff --git a/snowshoe.pro b/snowshoe.pro
index 70b928e..48aff3f 100644
--- a/snowshoe.pro
+++ b/snowshoe.pro
@@ -10,7 +10,6 @@ SOURCES += \
BrowserWindow.cpp \
DatabaseManager.cpp \
MainView.cpp \
- DeclarativeDesktopWebView.cpp \
TripleClickMonitor.cpp
HEADERS += \
@@ -19,7 +18,6 @@ HEADERS += \
BrowserWindow.h \
DatabaseManager.h \
MainView.h \
- DeclarativeDesktopWebView.h \
TripleClickMonitor.h
RESOURCES += \