ui: Implement interactive welcome page (fixes #323)

This commit is contained in:
Oleg Shparber 2018-02-18 02:00:48 +02:00
parent ab1c1a2bae
commit f85b902fc7
10 changed files with 208 additions and 75 deletions

File diff suppressed because one or more lines are too long

View File

@ -12,38 +12,36 @@
<body class="is-unselectable"> <body class="is-unselectable">
<section class="hero is-fullheight"> <section class="hero is-fullheight">
<div class="hero-head"> <div class="hero-body">
<header class="navbar is-transparent" role="navigation"> <div class="container">
<div class="navbar-brand"> <div class="columns is-vcentered">
<a class="navbar-item" href="https://zealdocs.org/">zealdocs.org</a> <div class="column has-text-centered">
</div> <p class="title">Zeal
<div class="navbar-menu"> <span id="version" class="has-text-weight-light is-size-5"></span>
<div class="navbar-end"> </p>
<a class="navbar-item" href="https://go.zealdocs.org/l/gitter"> <p class="subtitle">Docs for everyone</p>
<span class="icon"> </div>
<i class="fab fa-gitter"></i> <div class="column">
</span> <p class="subtitle is-5">Customize</p>
<span>Gitter</span> <div class="command-block" onclick="zAppBridge.triggerAction('openDocsetManager')">
</a> <p class="title is-6">Docsets</p>
<a class="navbar-item" href="https://go.zealdocs.org/l/github"> <p class="subtitle is-6">Install and update docsets</p>
<span class="icon"> </div>
<i class="fab fa-github"></i> <div class="command-block" onclick="zAppBridge.triggerAction('openPreferences')">
</span> <p class="title is-6">Preferences</p>
<span>GitHub</span> <p class="subtitle is-6">Adjust application settings</p>
</a> </div>
<p class="subtitle is-5">Get in touch</p>
<div class="command-block" onclick="zAppBridge.openShortUrl('gitter')">
<p class="title is-6">Gitter</p>
<p class="subtitle is-6">Chat with developers and other users</p>
</div>
<div class="command-block" onclick="zAppBridge.openShortUrl('github')">
<p class="title is-6">GitHub</p>
<p class="subtitle is-6">Contribute to the project</p>
</div>
</div> </div>
</div> </div>
</header>
</div>
<div class="hero-body">
<div class="container has-text-centered">
<h1 class="title">
Zeal
</h1>
<h2 class="subtitle">
Docs for everyone
</h2>
</div> </div>
</div> </div>
@ -51,18 +49,18 @@
<div class="container"> <div class="container">
<div class="content has-text-centered"> <div class="content has-text-centered">
<p> <p>
<a class="icon" href="https://go.zealdocs.org/l/github"> <a class="icon" onclick="zAppBridge.openShortUrl('github')">
<i class="fab fa-github"></i> <i class="fab fa-github"></i>
</a> </a>
<a class="icon" href="https://go.zealdocs.org/l/gitter"> <a class="icon" onclick="zAppBridge.openShortUrl('gitter')">
<i class="fab fa-gitter"></i> <i class="fab fa-gitter"></i>
</a> </a>
<a class="icon" href="https://go.zealdocs.org/l/twitter"> <a class="icon" onclick="zAppBridge.openShortUrl('twiter')">
<i class="fab fa-twitter"></i> <i class="fab fa-twitter"></i>
</a> </a>
</p> </p>
<p> <p>
<a class="is-size-7" href="https://go.zealdocs.org/l/report-bug"> <a class="is-size-7" onclick="zAppBridge.openShortUrl('report-bug')">
<span class="icon"> <span class="icon">
<i class="fas fa-bug"></i> <i class="fas fa-bug"></i>
</span> </span>
@ -74,6 +72,10 @@
</div> </div>
</div> </div>
</section> </section>
<script>
document.getElementById("version").textContent = zAppBridge.AppVersion;
</script>
</body> </body>
</html> </html>

View File

@ -12,63 +12,61 @@
<body class="is-unselectable"> <body class="is-unselectable">
<section class="hero is-fullheight"> <section class="hero is-fullheight">
<div class="hero-head"> <div class="hero-body">
<header class="navbar is-transparent" role="navigation"> <div class="container">
<div class="navbar-brand"> <div class="columns is-vcentered">
<a class="navbar-item" href="https://zealdocs.org/">zealdocs.org</a> <div class="column has-text-centered">
</div> <p class="title">Zeal
<div class="navbar-menu"> <span id="version" class="has-text-weight-light is-size-5"></span>
<div class="navbar-end"> </p>
<a class="navbar-item" href="https://go.zealdocs.org/l/gitter"> <p class="subtitle">Docs for everyone</p>
<span class="icon"> <div id="carboncontainer" style="margin-top: 75px;">
<i class="fab fa-gitter"></i> <div id="carbon" class="box">
</span> <script async type="text/javascript" src="https://cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=zealdocsforwindowsorg"
<span>Gitter</span> onerror="document.getElementById('carboncontainer').style.display = 'none';" id="_carbonads_js"></script>
</a> </div>
<a class="navbar-item" href="https://go.zealdocs.org/l/github"> </div>
<span class="icon"> </div>
<i class="fab fa-github"></i> <div class="column">
</span> <p class="subtitle is-5">Customize</p>
<span>GitHub</span> <div class="command-block" onclick="zAppBridge.triggerAction('openDocsetManager')">
</a> <p class="title is-6">Docsets</p>
<p class="subtitle is-6">Install and update docsets</p>
</div>
<div class="command-block" onclick="zAppBridge.triggerAction('openPreferences')">
<p class="title is-6">Preferences</p>
<p class="subtitle is-6">Adjust application settings</p>
</div>
<p class="subtitle is-5">Get in touch</p>
<div class="command-block" onclick="zAppBridge.openShortUrl('gitter')">
<p class="title is-6">Gitter</p>
<p class="subtitle is-6">Chat with developers and other users</p>
</div>
<div class="command-block" onclick="zAppBridge.openShortUrl('github')">
<p class="title is-6">GitHub</p>
<p class="subtitle is-6">Contribute to the project</p>
</div>
</div> </div>
</div> </div>
</header>
</div>
<div class="hero-body">
<div class="container has-text-centered">
<h1 class="title">
Zeal
</h1>
<h2 class="subtitle">
Docs for everyone
</h2>
</div> </div>
</div> </div>
<div class="hero-foot"> <div class="hero-foot">
<div class="container"> <div class="container">
<div class="content has-text-centered"> <div class="content has-text-centered">
<div id="carboncontainer">
<div id="carbon" class="box">
<script async type="text/javascript" src="https://cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=zealdocsforwindowsorg"
onerror="document.getElementById('carboncontainer').style.display = 'none';" id="_carbonads_js"></script>
</div>
</div>
<p> <p>
<a class="icon" href="https://go.zealdocs.org/l/github"> <a class="icon" onclick="zAppBridge.openShortUrl('github')">
<i class="fab fa-github"></i> <i class="fab fa-github"></i>
</a> </a>
<a class="icon" href="https://go.zealdocs.org/l/gitter"> <a class="icon" onclick="zAppBridge.openShortUrl('gitter')">
<i class="fab fa-gitter"></i> <i class="fab fa-gitter"></i>
</a> </a>
<a class="icon" href="https://go.zealdocs.org/l/twitter"> <a class="icon" onclick="zAppBridge.openShortUrl('twiter')">
<i class="fab fa-twitter"></i> <i class="fab fa-twitter"></i>
</a> </a>
</p> </p>
<p> <p>
<a class="is-size-7" href="https://go.zealdocs.org/l/report-bug"> <a class="is-size-7" onclick="zAppBridge.openShortUrl('report-bug')">
<span class="icon"> <span class="icon">
<i class="fas fa-bug"></i> <i class="fas fa-bug"></i>
</span> </span>
@ -80,6 +78,10 @@
</div> </div>
</div> </div>
</section> </section>
<script>
document.getElementById("version").textContent = zAppBridge.AppVersion;
</script>
</body> </body>
</html> </html>

View File

@ -24,6 +24,7 @@ add_library(Ui
progressitemdelegate.cpp progressitemdelegate.cpp
searchitemdelegate.cpp searchitemdelegate.cpp
settingsdialog.cpp settingsdialog.cpp
webbridge.cpp
${Widgets_SOURCES} ${Widgets_SOURCES}
${Ui_FORMS} # For Qt Creator. ${Ui_FORMS} # For Qt Creator.
) )

View File

@ -28,6 +28,7 @@
#include "docsetsdialog.h" #include "docsetsdialog.h"
#include "searchitemdelegate.h" #include "searchitemdelegate.h"
#include "settingsdialog.h" #include "settingsdialog.h"
#include "webbridge.h"
#include "qxtglobalshortcut/qxtglobalshortcut.h" #include "qxtglobalshortcut/qxtglobalshortcut.h"
#include "widgets/webviewtab.h" #include "widgets/webviewtab.h"
@ -312,6 +313,17 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) :
m_settings->tocSplitterState = ui->tocSplitter->saveState(); m_settings->tocSplitterState = ui->tocSplitter->saveState();
}); });
m_webBridge = new WebBridge(this);
connect(m_webBridge, &WebBridge::actionTriggered, this, [this](const QString &action) {
// TODO: In the future connect directly to the ActionManager.
if (action == "openDocsetManager") {
ui->actionDocsets->trigger();
} else if (action == "openPreferences") {
ui->actionPreferences->trigger();
}
});
createTab(); createTab();
connect(ui->treeView, &QTreeView::clicked, this, &MainWindow::openDocset); connect(ui->treeView, &QTreeView::clicked, this, &MainWindow::openDocset);
@ -520,6 +532,7 @@ WebViewTab *MainWindow::createTab(int index)
index = m_tabStates.size(); index = m_tabStates.size();
TabState *newState = new TabState(); TabState *newState = new TabState();
newState->widget->setWebBridgeObject("zAppBridge", m_webBridge);
newState->goToStartPage(); newState->goToStartPage();
m_tabStates.insert(index, newState); m_tabStates.insert(index, newState);
@ -541,6 +554,7 @@ void MainWindow::duplicateTab(int index)
syncTabState(tabState); syncTabState(tabState);
TabState *newState = new TabState(*tabState); TabState *newState = new TabState(*tabState);
newState->widget->setWebBridgeObject("zAppBridge", m_webBridge);
++index; ++index;
m_tabStates.insert(index, newState); m_tabStates.insert(index, newState);

View File

@ -51,6 +51,7 @@ namespace Ui {
class MainWindow; class MainWindow;
} // namespace Ui } // namespace Ui
class WebBridge;
class WebViewTab; class WebViewTab;
struct TabState; struct TabState;
@ -110,6 +111,8 @@ private:
Core::Settings *m_settings = nullptr; Core::Settings *m_settings = nullptr;
Registry::ListModel *m_zealListModel = nullptr; Registry::ListModel *m_zealListModel = nullptr;
WebBridge *m_webBridge = nullptr;
QMenu *m_backMenu = nullptr; QMenu *m_backMenu = nullptr;
QMenu *m_forwardMenu = nullptr; QMenu *m_forwardMenu = nullptr;

49
src/libs/ui/webbridge.cpp Normal file
View File

@ -0,0 +1,49 @@
/****************************************************************************
**
** Copyright (C) 2018 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal 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 3 of the License, or
** (at your option) any later version.
**
** Zeal 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 Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "webbridge.h"
#include <QCoreApplication>
#include <QDesktopServices>
#include <QUrl>
using namespace Zeal::WidgetUi;
WebBridge::WebBridge(QObject *parent)
: QObject(parent)
{
}
void WebBridge::openShortUrl(const QString &key)
{
QDesktopServices::openUrl(QUrl(QStringLiteral("https://go.zealdocs.org/l/") + key));
}
void WebBridge::triggerAction(const QString &action)
{
emit actionTriggered(action);
}
QString WebBridge::appVersion() const
{
return QCoreApplication::applicationVersion();
}

52
src/libs/ui/webbridge.h Normal file
View File

@ -0,0 +1,52 @@
/****************************************************************************
**
** Copyright (C) 2018 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal 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 3 of the License, or
** (at your option) any later version.
**
** Zeal 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 Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef ZEAL_WIDGETUI_WEBBRIDGE_H
#define ZEAL_WIDGETUI_WEBBRIDGE_H
#include <QObject>
namespace Zeal {
namespace WidgetUi {
class WebBridge : public QObject
{
Q_OBJECT
Q_PROPERTY(QString AppVersion READ appVersion CONSTANT)
public:
explicit WebBridge(QObject *parent = nullptr);
signals:
void actionTriggered(const QString &action);
public slots:
Q_INVOKABLE void openShortUrl(const QString &key);
Q_INVOKABLE void triggerAction(const QString &action);
private:
QString appVersion() const;
};
} // namespace WidgetUi
} // namespace Zeal
#endif // ZEAL_WIDGETUI_WEBBRIDGE_H

View File

@ -70,6 +70,14 @@ void WebViewTab::setZoomLevel(int level)
m_webView->setZoomLevel(level); m_webView->setZoomLevel(level);
} }
void WebViewTab::setWebBridgeObject(const QString &name, QObject *object)
{
connect(m_webView->page()->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared,
this, [=]() {
m_webView->page()->mainFrame()->addToJavaScriptWindowObject(name, object);
});
}
void WebViewTab::load(const QUrl &url) void WebViewTab::load(const QUrl &url)
{ {
m_webView->load(url); m_webView->load(url);

View File

@ -53,6 +53,8 @@ public:
int zoomLevel() const; int zoomLevel() const;
void setZoomLevel(int level); void setZoomLevel(int level);
void setWebBridgeObject(const QString &name, QObject *object);
signals: signals:
void titleChanged(const QString &title); void titleChanged(const QString &title);
void urlChanged(const QUrl &url); void urlChanged(const QUrl &url);