Murder the last of webkit and break Statistics/help a little bit

This commit is contained in:
Mark Watkins 2018-05-29 08:35:48 +10:00
parent f11f5fe284
commit 3e73860351
6 changed files with 113 additions and 132 deletions

View File

@ -22,7 +22,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -111,17 +120,20 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
<widget class="QTextBrowser" name="webView"/>
</item>
</layout>
</widget>
@ -133,7 +145,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -205,7 +226,16 @@
<property name="spacing">
<number>4</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
@ -237,7 +267,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -292,7 +331,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -308,7 +356,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -349,13 +406,6 @@
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
</customwidgets>
<resources>
<include location="Resources.qrc"/>
</resources>

View File

@ -11,11 +11,6 @@
#include <QMessageBox>
#include <QResource>
#include <QProgressBar>
#include <QWebHistory>
#include <QWebFrame>
#include <QNetworkRequest>
#include <QDesktopServices>
#include <QNetworkReply>
#include <QTimer>
#include <QSettings>
#include <QPixmap>
@ -32,6 +27,8 @@
#include <QCalendarWidget>
#include <QDialogButtonBox>
#include <QTextBrowser>
#include <QStandardPaths>
#include <QDesktopServices>
#include <cmath>
#include "common_gui.h"
@ -214,8 +211,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui->action_Sidebar_Toggle->setChecked(b);
ui->toolBox->setVisible(b);
ui->statisticsView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
// ui->statisticsView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
// ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
QString loadingtxt =
"<HTML><body style='text-align: center; vertical-align: center'><table width='100%' height='100%'>"
@ -324,29 +321,6 @@ void MainWindow::Notify(QString s, QString title, int ms)
}
}
class MyStatsPage: public QWebPage
{
public:
MyStatsPage(QObject *parent);
virtual ~MyStatsPage();
protected:
//virtual void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
virtual void javaScriptAlert(QWebFrame *frame, const QString &msg);
};
MyStatsPage::MyStatsPage(QObject *parent)
: QWebPage(parent)
{
}
MyStatsPage::~MyStatsPage()
{
}
void MyStatsPage::javaScriptAlert(QWebFrame *frame, const QString &msg)
{
Q_UNUSED(frame);
mainwin->sendStatsUrl(msg);
}
QString getCPAPPixmap(QString mach_class)
{
QString cpapimage;
@ -1197,12 +1171,12 @@ void MainWindow::updateFavourites()
void MainWindow::on_backButton_clicked()
{
ui->webView->back();
ui->helpBrowser->backward();
}
void MainWindow::on_forwardButton_clicked()
{
ui->webView->forward();
ui->helpBrowser->forward();
}
void MainWindow::on_webView_urlChanged(const QUrl &arg1)
@ -1212,8 +1186,9 @@ void MainWindow::on_webView_urlChanged(const QUrl &arg1)
void MainWindow::on_urlBar_activated(const QString &arg1)
{
QUrl url(arg1);
ui->webView->setUrl(url);
Q_UNUSED(arg1);
//QUrl url(arg1);
//ui->webView->setUrl(url);
}
void MainWindow::on_dailyButton_clicked()
@ -1242,17 +1217,15 @@ void MainWindow::on_webView_loadFinished(bool arg1)
qstatus->setText("");
}
ui->backButton->setEnabled(ui->webView->history()->canGoBack());
ui->forwardButton->setEnabled(ui->webView->history()->canGoForward());
ui->backButton->setEnabled(ui->helpBrowser->backwardHistoryCount()>0);
ui->forwardButton->setEnabled(ui->helpBrowser->forwardHistoryCount()>0);
connect(ui->webView->page(), SIGNAL(linkHovered(QString, QString, QString)), this,
SLOT(LinkHovered(QString, QString, QString)));
//connect(ui->webView->page(), SIGNAL(linkHovered(QString, QString, QString)), this, SLOT(LinkHovered(QString, QString, QString)));
}
void MainWindow::on_webView_loadStarted()
{
disconnect(ui->webView->page(), SIGNAL(linkHovered(QString, QString, QString)), this,
SLOT(LinkHovered(QString, QString, QString)));
//disconnect(ui->webView->page(), SIGNAL(linkHovered(QString, QString, QString)), this, SLOT(LinkHovered(QString, QString, QString)));
if (!first_load) {
qstatus->setText(tr("Loading"));
@ -1455,7 +1428,7 @@ void MainWindow::on_actionPrint_Report_triggered()
if (ui->tabWidget->currentWidget() == ui->statisticsTab) {
ui->statisticsView->print(&printer);
} else if (ui->tabWidget->currentWidget() == ui->helpTab) {
ui->webView->print(&printer);
ui->helpBrowser->print(&printer);
}
}
@ -1489,14 +1462,12 @@ void MainWindow::on_action_CycleTabs_triggered()
void MainWindow::on_actionOnline_Users_Guide_triggered()
{
ui->webView->load(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=SleepyHead_Users_Guide"));
ui->tabWidget->setCurrentWidget(ui->helpTab);
QDesktopServices::openUrl(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=SleepyHead_Users_Guide"));
}
void MainWindow::on_action_Frequently_Asked_Questions_triggered()
{
ui->webView->load(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Frequently_Asked_Questions"));
ui->tabWidget->setCurrentWidget(ui->helpTab);
QDesktopServices::openUrl(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Frequently_Asked_Questions"));
}
void packEventList(EventList *el, EventDataType minval = 0)
@ -2053,7 +2024,7 @@ void MainWindow::on_webView_linkClicked(const QUrl &url)
if (s.toLower().startsWith("https:")) {
QDesktopServices().openUrl(url);
} else {
ui->webView->setUrl(url);
//ui->helpBrowser->setUrl(url);
}
}
@ -2363,14 +2334,12 @@ void MainWindow::on_actionImport_RemStar_MSeries_Data_triggered()
void MainWindow::on_actionSleep_Disorder_Terms_Glossary_triggered()
{
ui->webView->load(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Glossary"));
ui->tabWidget->setCurrentWidget(ui->helpTab);
QDesktopServices::openUrl(QUrl("http://sleepyhead.sourceforge.net/wiki/index.php?title=Glossary"));
}
void MainWindow::on_actionHelp_Support_SleepyHead_Development_triggered()
{
QUrl url = QUrl("https://sleepyhead.jedimark.net/donate.php");
QDesktopServices().openUrl(url);
QDesktopServices().openUrl(QUrl("https://sleepyhead.jedimark.net/donate.php"));
}
void MainWindow::on_actionChange_Language_triggered()
@ -2440,9 +2409,7 @@ void MainWindow::GenerateStatistics()
//QWebFrame *frame=ui->statisticsView->page()->currentFrame();
//frame->addToJavaScriptWindowObject("mainwin",this);
//ui->statisticsView->setHtml(html);
MyStatsPage *page = new MyStatsPage(this);
page->currentFrame()->setHtml(html);
ui->statisticsView->setPage(page);
ui->statisticsView->setHtml(html);
}

View File

@ -11,8 +11,6 @@
#include <QMainWindow>
#include <QGLContext>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QSystemTrayIcon>
#include <QTimer>

View File

@ -926,7 +926,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="documentMode">
<bool>false</bool>
@ -958,19 +958,7 @@
<number>0</number>
</property>
<item>
<widget class="QWebView" name="statisticsView" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="url" stdset="0">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
<widget class="QTextBrowser" name="statisticsView"/>
</item>
<item>
<widget class="QFrame" name="frame_3">
@ -1228,31 +1216,7 @@
<number>0</number>
</property>
<item>
<widget class="QWebView" name="webView" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="url" stdset="0">
<url>
<string>qrc:/docs/index.html</string>
</url>
</property>
</widget>
<widget class="QTextBrowser" name="helpBrowser"/>
</item>
</layout>
</widget>
@ -1417,7 +1381,7 @@ QToolBox::tab:selected {
<rect>
<x>0</x>
<y>0</y>
<width>158</width>
<width>310</width>
<height>676</height>
</rect>
</property>
@ -1875,7 +1839,7 @@ border: 2px solid #56789a; border-radius: 30px;
<rect>
<x>0</x>
<y>0</y>
<width>175</width>
<width>327</width>
<height>667</height>
</rect>
</property>
@ -2931,7 +2895,7 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>175</width>
<width>327</width>
<height>667</height>
</rect>
</property>
@ -3417,13 +3381,6 @@ p, li { white-space: pre-wrap; }
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKitWidgets/QWebView</header>
</customwidget>
</customwidgets>
<resources>
<include location="Resources.qrc"/>
</resources>

View File

@ -4,13 +4,11 @@
#
#-------------------------------------------------
QT += core gui network xml printsupport serialport
QT += core gui network xml printsupport serialport widgets
greaterThan(QT_MAJOR_VERSION,4) {
QT += widgets webkitwidgets
} else { # qt4
QT += webkit
lessThan(QT_MAJOR_VERSION,5) {
error("Sorry, need Qt 5 to build SleepyHead");
}
#SleepyHead requires OpenGL 2.0 support to run smoothly

View File

@ -1,4 +1,4 @@
/* Statistics Report Generator Implementation
/* Statistics Report Generator Implementation
*
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
*
@ -9,6 +9,7 @@
#include <QApplication>
#include <QFile>
#include <QDataStream>
#include <QBuffer>
#include <cmath>
#include "mainwindow.h"
@ -16,6 +17,14 @@
extern MainWindow *mainwin;
QString resizeHTMLPixmap(QPixmap &pixmap, int width, int height) {
QByteArray byteArray;
QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray
buffer.open(QIODevice::WriteOnly);
pixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(&buffer, "PNG");
return QString("<img src=\"data:image/png;base64,"+byteArray.toBase64()+"\">");
}
QString formatTime(float time)
{
int hours = time;
@ -623,6 +632,8 @@ QString htmlHeader(bool showheader)
"</script>"
"</head>"
"<body leftmargin=0 topmargin=5 rightmargin=0>";
QPixmap bobPixmap(":/icons/bob-v3.0.png");
if (showheader) {
html += "<div align=center><table class=curved "+table_width+">"
"<td>"+userinfo+"</td>"
@ -630,7 +641,7 @@ QString htmlHeader(bool showheader)
"<font size='+2'>" + STR_TR_SleepyHead + "</font><br/>"
"<font size='+1'>" + QObject::tr("Usage Statistics") + "</font>"
"</td>"
"<td align='right' width=170px><img src='qrc:/icons/bob-v3.0.png' height=140px><br/>"
"<td align='right' width=170px>" +resizeHTMLPixmap(bobPixmap,140,140)+"<br/>"
"</td></tr></table>"
"</div><br/>";
}