Skip to content

Commit

Permalink
ui: Implement interactive welcome page (fixes #323)
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Feb 18, 2018
1 parent ab1c1a2 commit f85b902
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/app/resources/browser/assets/css/welcome.min.css

Large diffs are not rendered by default.

70 changes: 36 additions & 34 deletions src/app/resources/browser/welcome-noad.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,55 @@

<body class="is-unselectable">
<section class="hero is-fullheight">
<div class="hero-head">
<header class="navbar is-transparent" role="navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://zealdocs.org/">zealdocs.org</a>
</div>
<div class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item" href="https://go.zealdocs.org/l/gitter">
<span class="icon">
<i class="fab fa-gitter"></i>
</span>
<span>Gitter</span>
</a>
<a class="navbar-item" href="https://go.zealdocs.org/l/github">
<span class="icon">
<i class="fab fa-github"></i>
</span>
<span>GitHub</span>
</a>
<div class="hero-body">
<div class="container">
<div class="columns is-vcentered">
<div class="column has-text-centered">
<p class="title">Zeal
<span id="version" class="has-text-weight-light is-size-5"></span>
</p>
<p class="subtitle">Docs for everyone</p>
</div>
<div class="column">
<p class="subtitle is-5">Customize</p>
<div class="command-block" onclick="zAppBridge.triggerAction('openDocsetManager')">
<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>
</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 class="hero-foot">
<div class="container">
<div class="content has-text-centered">
<p>
<a class="icon" href="https://go.zealdocs.org/l/github">
<a class="icon" onclick="zAppBridge.openShortUrl('github')">
<i class="fab fa-github"></i>
</a>
<a class="icon" href="https://go.zealdocs.org/l/gitter">
<a class="icon" onclick="zAppBridge.openShortUrl('gitter')">
<i class="fab fa-gitter"></i>
</a>
<a class="icon" href="https://go.zealdocs.org/l/twitter">
<a class="icon" onclick="zAppBridge.openShortUrl('twiter')">
<i class="fab fa-twitter"></i>
</a>
</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">
<i class="fas fa-bug"></i>
</span>
Expand All @@ -74,6 +72,10 @@ <h2 class="subtitle">
</div>
</div>
</section>

<script>
document.getElementById("version").textContent = zAppBridge.AppVersion;
</script>
</body>

</html>
82 changes: 42 additions & 40 deletions src/app/resources/browser/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,61 @@

<body class="is-unselectable">
<section class="hero is-fullheight">
<div class="hero-head">
<header class="navbar is-transparent" role="navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://zealdocs.org/">zealdocs.org</a>
</div>
<div class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item" href="https://go.zealdocs.org/l/gitter">
<span class="icon">
<i class="fab fa-gitter"></i>
</span>
<span>Gitter</span>
</a>
<a class="navbar-item" href="https://go.zealdocs.org/l/github">
<span class="icon">
<i class="fab fa-github"></i>
</span>
<span>GitHub</span>
</a>
<div class="hero-body">
<div class="container">
<div class="columns is-vcentered">
<div class="column has-text-centered">
<p class="title">Zeal
<span id="version" class="has-text-weight-light is-size-5"></span>
</p>
<p class="subtitle">Docs for everyone</p>
<div id="carboncontainer" style="margin-top: 75px;">
<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>
</div>
<div class="column">
<p class="subtitle is-5">Customize</p>
<div class="command-block" onclick="zAppBridge.triggerAction('openDocsetManager')">
<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>
</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 class="hero-foot">
<div class="container">
<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>
<a class="icon" href="https://go.zealdocs.org/l/github">
<a class="icon" onclick="zAppBridge.openShortUrl('github')">
<i class="fab fa-github"></i>
</a>
<a class="icon" href="https://go.zealdocs.org/l/gitter">
<a class="icon" onclick="zAppBridge.openShortUrl('gitter')">
<i class="fab fa-gitter"></i>
</a>
<a class="icon" href="https://go.zealdocs.org/l/twitter">
<a class="icon" onclick="zAppBridge.openShortUrl('twiter')">
<i class="fab fa-twitter"></i>
</a>
</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">
<i class="fas fa-bug"></i>
</span>
Expand All @@ -80,6 +78,10 @@ <h2 class="subtitle">
</div>
</div>
</section>

<script>
document.getElementById("version").textContent = zAppBridge.AppVersion;
</script>
</body>

</html>
1 change: 1 addition & 0 deletions src/libs/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_library(Ui
progressitemdelegate.cpp
searchitemdelegate.cpp
settingsdialog.cpp
webbridge.cpp
${Widgets_SOURCES}
${Ui_FORMS} # For Qt Creator.
)
Expand Down
14 changes: 14 additions & 0 deletions src/libs/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "docsetsdialog.h"
#include "searchitemdelegate.h"
#include "settingsdialog.h"
#include "webbridge.h"
#include "qxtglobalshortcut/qxtglobalshortcut.h"
#include "widgets/webviewtab.h"

Expand Down Expand Up @@ -312,6 +313,17 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) :
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();

connect(ui->treeView, &QTreeView::clicked, this, &MainWindow::openDocset);
Expand Down Expand Up @@ -520,6 +532,7 @@ WebViewTab *MainWindow::createTab(int index)
index = m_tabStates.size();

TabState *newState = new TabState();
newState->widget->setWebBridgeObject("zAppBridge", m_webBridge);
newState->goToStartPage();

m_tabStates.insert(index, newState);
Expand All @@ -541,6 +554,7 @@ void MainWindow::duplicateTab(int index)
syncTabState(tabState);

TabState *newState = new TabState(*tabState);
newState->widget->setWebBridgeObject("zAppBridge", m_webBridge);

++index;
m_tabStates.insert(index, newState);
Expand Down
3 changes: 3 additions & 0 deletions src/libs/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace Ui {
class MainWindow;
} // namespace Ui

class WebBridge;
class WebViewTab;

struct TabState;
Expand Down Expand Up @@ -110,6 +111,8 @@ private slots:
Core::Settings *m_settings = nullptr;
Registry::ListModel *m_zealListModel = nullptr;

WebBridge *m_webBridge = nullptr;

QMenu *m_backMenu = nullptr;
QMenu *m_forwardMenu = nullptr;

Expand Down
49 changes: 49 additions & 0 deletions src/libs/ui/webbridge.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 52 additions & 0 deletions src/libs/ui/webbridge.h
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions src/libs/ui/widgets/webviewtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ void WebViewTab::setZoomLevel(int 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)
{
m_webView->load(url);
Expand Down
Loading

0 comments on commit f85b902

Please sign in to comment.