This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
65 lines (51 loc) · 2.09 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2011 Stefan A. van der Meer
// See "LICENSE" file included with source code for terms and conditions.
#include "mainwindow.h"
#include "ui_mainwindow.h" // Generated from .ui by qmake
#include <QKeyEvent>
#include <QUrl>
#include <QApplication>
MainWindow::MainWindow(const QUrl &url, QWebPage *custom_page, QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
// Set up the interface compiled from the .ui file
ui->setupUi(this);
// Remove title bar and edges: we are a fullscreen/kiosk app
setWindowFlags(Qt::FramelessWindowHint);
// Setup the webkit browser frame
QWebView *webview = findChild<QWebView *>("webView");
if (webview) {
// We can specify a custom page class for additional functionality.
if (custom_page) {
// Make child of webview, so it will dealloc the page on exit
custom_page->setParent(webview);
webview->setPage(custom_page);
}
qDebug("Loading URL: %s", qPrintable(url.toString()));
webview->load(url);
webview->show();
} else {
qFatal("Failed to find required 'webView' element in ui.");
}
QProgressBar *progress = findChild<QProgressBar *>("progressBar");
if (progress) {
// Progress bar should not show until we are loading something.
progress->hide();
// All the progress bar functions we need to use are slots,
// so we can hook them up directly to the webview's loading signals.
// Show progress percentage in bar
connect(webview, SIGNAL(loadProgress(int)), progress, SLOT(setValue(int)));
// Reset bar percentage and show
connect(webview, SIGNAL(loadStarted()), progress, SLOT(reset()));
connect(webview, SIGNAL(loadStarted()), progress, SLOT(show()));
// Hide when page load is finished
connect(webview, SIGNAL(loadFinished(bool)),progress, SLOT(hide()));
} else {
// Technically we can do without.
qWarning("Failed to find 'progressBar' element in ui.");
}
}
MainWindow::~MainWindow()
{
delete ui;
}