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

View File

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

View File

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

View File

@ -926,7 +926,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<property name="documentMode"> <property name="documentMode">
<bool>false</bool> <bool>false</bool>
@ -958,19 +958,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QWebView" name="statisticsView" native="true"> <widget class="QTextBrowser" name="statisticsView"/>
<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>
</item> </item>
<item> <item>
<widget class="QFrame" name="frame_3"> <widget class="QFrame" name="frame_3">
@ -1228,31 +1216,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QWebView" name="webView" native="true"> <widget class="QTextBrowser" name="helpBrowser"/>
<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>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -1417,7 +1381,7 @@ QToolBox::tab:selected {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>158</width> <width>310</width>
<height>676</height> <height>676</height>
</rect> </rect>
</property> </property>
@ -1875,7 +1839,7 @@ border: 2px solid #56789a; border-radius: 30px;
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>175</width> <width>327</width>
<height>667</height> <height>667</height>
</rect> </rect>
</property> </property>
@ -2931,7 +2895,7 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>175</width> <width>327</width>
<height>667</height> <height>667</height>
</rect> </rect>
</property> </property>
@ -3417,13 +3381,6 @@ p, li { white-space: pre-wrap; }
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKitWidgets/QWebView</header>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="Resources.qrc"/> <include location="Resources.qrc"/>
</resources> </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) { lessThan(QT_MAJOR_VERSION,5) {
QT += widgets webkitwidgets error("Sorry, need Qt 5 to build SleepyHead");
} else { # qt4
QT += webkit
} }
#SleepyHead requires OpenGL 2.0 support to run smoothly #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> * Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
* *
@ -9,6 +9,7 @@
#include <QApplication> #include <QApplication>
#include <QFile> #include <QFile>
#include <QDataStream> #include <QDataStream>
#include <QBuffer>
#include <cmath> #include <cmath>
#include "mainwindow.h" #include "mainwindow.h"
@ -16,6 +17,14 @@
extern MainWindow *mainwin; 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) QString formatTime(float time)
{ {
int hours = time; int hours = time;
@ -623,6 +632,8 @@ QString htmlHeader(bool showheader)
"</script>" "</script>"
"</head>" "</head>"
"<body leftmargin=0 topmargin=5 rightmargin=0>"; "<body leftmargin=0 topmargin=5 rightmargin=0>";
QPixmap bobPixmap(":/icons/bob-v3.0.png");
if (showheader) { if (showheader) {
html += "<div align=center><table class=curved "+table_width+">" html += "<div align=center><table class=curved "+table_width+">"
"<td>"+userinfo+"</td>" "<td>"+userinfo+"</td>"
@ -630,7 +641,7 @@ QString htmlHeader(bool showheader)
"<font size='+2'>" + STR_TR_SleepyHead + "</font><br/>" "<font size='+2'>" + STR_TR_SleepyHead + "</font><br/>"
"<font size='+1'>" + QObject::tr("Usage Statistics") + "</font>" "<font size='+1'>" + QObject::tr("Usage Statistics") + "</font>"
"</td>" "</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>" "</td></tr></table>"
"</div><br/>"; "</div><br/>";
} }