diff --git a/src/Charts/BingMap.cpp b/src/Charts/BingMap.cpp index 14a2a1d60..de064816c 100644 --- a/src/Charts/BingMap.cpp +++ b/src/Charts/BingMap.cpp @@ -30,6 +30,10 @@ #include "TimeUtils.h" #include "HelpWhatsThis.h" +#ifdef NOWEBKIT +#include +#endif + #include BingMap::BingMap(Context *context) : GcChartWindow(context), context(context), range(-1), current(NULL) @@ -42,7 +46,12 @@ BingMap::BingMap(Context *context) : GcChartWindow(context), context(context), r layout->setContentsMargins(2,0,2,2); setChartLayout(layout); +#ifdef NOWEBKIT + view = new QWebEngineView(this); +#else view = new QWebView(); +#endif + view->setContentsMargins(0,0,0,0); view->page()->view()->setContentsMargins(0,0,0,0); view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -53,9 +62,26 @@ BingMap::BingMap(Context *context) : GcChartWindow(context), context(context), r view->setWhatsThis(help->getWhatsThisText(HelpWhatsThis::ChartRides_Map)); webBridge = new BWebBridge(context, this); +#ifdef NOWEBKIT + // file: MyWebEngineView.cpp, MyWebEngineView extends QWebEngineView + QWebChannel *channel = new QWebChannel(view->page()); + + // set the web channel to be used by the page + // see http://doc.qt.io/qt-5/qwebenginepage.html#setWebChannel + view->page()->setWebChannel(channel); + + // register QObjects to be exposed to JavaScript + channel->registerObject(QStringLiteral("webBridge"), webBridge); + + // now you can call page()->runJavaScript(...) etc + // you DON'T need to call runJavaScript with qwebchannel.js, see the html file below + +#endif connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); +#ifndef NOWEBKIT connect(view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(updateFrame())); +#endif connect(context, SIGNAL(intervalsChanged()), webBridge, SLOT(intervalsChanged())); connect(context, SIGNAL(intervalSelected()), webBridge, SLOT(intervalsChanged())); connect(context, SIGNAL(intervalZoom(IntervalItem*)), this, SLOT(zoomInterval(IntervalItem*))); @@ -67,6 +93,11 @@ BingMap::BingMap(Context *context) : GcChartWindow(context), context(context), r configChanged(CONFIG_APPEARANCE); } +BingMap::~BingMap() +{ + delete webBridge; +} + void BingMap::configChanged(qint32) { @@ -102,7 +133,12 @@ BingMap::rideSelected() void BingMap::loadRide() { createHtml(); + +#ifdef NOWEBKIT + view->page()->setHtml(currentPage); +#else view->page()->mainFrame()->setHtml(currentPage); +#endif } void BingMap::updateFrame() @@ -114,7 +150,9 @@ void BingMap::updateFrame() connect(context, SIGNAL(intervalsChanged()), webBridge, SLOT(intervalsChanged())); connect(context, SIGNAL(intervalSelected()), webBridge, SLOT(intervalsChanged())); +#ifndef NOWEBKIT view->page()->mainFrame()->addToJavaScriptWindowObject("webBridge", webBridge); +#endif } void BingMap::createHtml() @@ -157,6 +195,25 @@ void BingMap::createHtml() "\n" "\n"); +#ifdef NOWEBKIT + currentPage += QString("\n"); +#endif + + currentPage += QString(""); + // colors currentPage += QString("") .arg(bgColor.name()).arg(fgColor.name()); @@ -173,6 +230,17 @@ void BingMap::createHtml() // b) allow local manipulation. This makes the UI // considerably more 'snappy' "function drawRoute() {\n" +#ifdef NOWEBKIT + // load the GPS co-ordinates + " webBridge.getLatLons(0, drawRouteForLatLons);\n" +#else + // load the GPS co-ordinates + " var latlons = webBridge.getLatLons(0);\n" // interval "0" is the entire route + " drawRouteForLatLons(latlons);\n" +#endif + "}\n" + "\n" + "function drawRouteForLatLons(latlons) {\n" // route will be drawn with these options " var routeOptionsYellow = {\n" @@ -182,9 +250,6 @@ void BingMap::createHtml() " zIndex: -2\n" " };\n" - // load the GPS co-ordinates - " var latlons = webBridge.getLatLons(0);\n" // interval "0" is the entire route - // create the route path " var route = new Array();\n" " var j=0;\n" @@ -200,13 +265,15 @@ void BingMap::createHtml() "}\n" "function drawIntervals() { \n" - // intervals will be drawn with these options - " var polyOptions = {\n" - " strokeColor: new Microsoft.Maps.Color(100, 0, 0, 255),\n" - " strokeThickness: 5,\n" - " strokeDashArray: '5 0',\n" - " zIndex: -1\n" - " };\n" + // how many to draw? +#ifdef NOWEBKIT + " webBridge.intervalCount(drawIntervalsCount);\n" +#else + " drawIntervalsCount(webBridge.intervalCount());\n" +#endif + "}\n" + + "function drawIntervalsCount(intervals) { \n" // remove previous intervals highlighted " j= intervalList.length;\n" @@ -217,28 +284,38 @@ void BingMap::createHtml() " }\n" // how many to draw? - " var intervals = webBridge.intervalCount();\n" - " while (intervals > 0) {\n" - " var latlons = webBridge.getLatLons(intervals);\n" - - // create the route path - " var route = new Array();\n" - " var j=0;\n" - " while (j < latlons.length) { \n" - " route.push(new Microsoft.Maps.Location(latlons[j],latlons[j+1]));\n" - " j += 2;\n" - " }\n" - - // create the route Polyline - " var intervalHighlighter = new Microsoft.Maps.Polyline(route, polyOptions);\n" - " map.entities.push(intervalHighlighter);\n" - " intervalList.push(intervalHighlighter);\n" - - " intervals--;\n" - " }\n" + " while (intervals > 0) {\n" +#ifdef NOWEBKIT + " webBridge.getLatLons(intervals, drawInterval);\n" +#else + " drawInterval(webBridge.getLatLons(intervals));\n" +#endif + " intervals--;\n" + " }\n" "}\n" + "function drawInterval(latlons) { \n" + // intervals will be drawn with these options + " var polyOptions = {\n" + " strokeColor: new Microsoft.Maps.Color(100, 0, 0, 255),\n" + " strokeThickness: 5,\n" + " strokeDashArray: '5 0',\n" + " zIndex: -1\n" + " };\n" + // create the route path + " var route = new Array();\n" + " var j=0;\n" + " while (j < latlons.length) { \n" + " route.push(new Microsoft.Maps.Location(latlons[j],latlons[j+1]));\n" + " j += 2;\n" + " }\n" + + // create the route Polyline + " var intervalHighlighter = new Microsoft.Maps.Polyline(route, polyOptions);\n" + " map.entities.push(intervalHighlighter);\n" + " intervalList.push(intervalHighlighter);\n" + "}\n" // initialise function called when map loaded "function initialize() {\n" @@ -282,7 +359,7 @@ void BingMap::createHtml() // the main page is rather trivial currentPage += QString("\n" - "\n" + "\n" "
\n" "\n" "\n"); @@ -344,7 +421,12 @@ BingMap::drawShadedRoute() "}\n").arg(color.red()) .arg(color.green()) .arg(color.blue()); + + #ifdef NOWEBKIT + view->page()->runJavaScript(code); + #else view->page()->mainFrame()->evaluateJavaScript(code); + #endif } } } @@ -394,7 +476,11 @@ BingMap::createMarkers() "map.entities.push(pushpin); }" ).arg(points[0]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[0]->lon,0,'g',GPS_COORD_TO_STRING); + #ifdef NOWEBKIT + view->page()->runJavaScript(code); + #else view->page()->mainFrame()->evaluateJavaScript(code); + #endif } else { // start / finish markers @@ -403,14 +489,24 @@ BingMap::createMarkers() "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);" "map.entities.push(pushpin); }" ).arg(points[0]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[0]->lon,0,'g',GPS_COORD_TO_STRING); + + #ifdef NOWEBKIT + view->page()->runJavaScript(code); + #else view->page()->mainFrame()->evaluateJavaScript(code); + #endif code = QString("{ var latlng = new Microsoft.Maps.Location(%1,%2); " "var pushpinOptions = { icon: 'qrc:images/maps/finish.png', height: 37, width: 32 };" "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);" "map.entities.push(pushpin); }" ).arg(points[points.count()-1]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[points.count()-1]->lon,0,'g',GPS_COORD_TO_STRING); + + #ifdef NOWEBKIT + view->page()->runJavaScript(code); + #else view->page()->mainFrame()->evaluateJavaScript(code); + #endif } // @@ -455,7 +551,12 @@ BingMap::createMarkers() "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);" "map.entities.push(pushpin); }" ).arg(rfp->lat,0,'g',GPS_COORD_TO_STRING).arg(rfp->lon,0,'g',GPS_COORD_TO_STRING); + + #ifdef NOWEBKIT + view->page()->runJavaScript(code); + #else view->page()->mainFrame()->evaluateJavaScript(code); + #endif stoptime=0; } stoplat=stoplon=stoptime=0; @@ -476,7 +577,8 @@ BingMap::createMarkers() "var pushpinOptions = { };\n" "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);\n" "map.entities.push(pushpin);\n" - "pushpin.cm1001_er_etr.dom.setAttribute('title', '%3');\n" + "if (pushpin.cm1001_er_etr) pushpin.cm1001_er_etr.dom.setAttribute('title', '%3');\n" + "if (pushpin.cm1002_er_etr) pushpin.cm1002_er_etr.dom.setAttribute('title', '%3');\n" "pushpinClick= Microsoft.Maps.Events.addHandler(pushpin, 'click', function(event) { webBridge.toggleInterval(%4); });\n" " }") .arg(myRideItem->ride()->dataPoints()[offset]->lat,0,'g',GPS_COORD_TO_STRING) @@ -484,7 +586,11 @@ BingMap::createMarkers() .arg(x->name) .arg(interval); + #ifdef NOWEBKIT + view->page()->runJavaScript(code); + #else view->page()->mainFrame()->evaluateJavaScript(code); + #endif interval++; } @@ -531,7 +637,12 @@ void BingMap::zoomInterval(IntervalItem *which) .arg(minLon,0,'g',GPS_COORD_TO_STRING) .arg(maxLat,0,'g',GPS_COORD_TO_STRING) .arg(maxLon,0,'g',GPS_COORD_TO_STRING); + +#ifdef NOWEBKIT + view->page()->runJavaScript(code); +#else view->page()->mainFrame()->evaluateJavaScript(code); +#endif } // quick diag, used to debug code only @@ -605,11 +716,11 @@ void BWebBridge::toggleInterval(int x) { RideItem *rideItem = gm->property("ride").value(); - if (x < 0 || rideItem->intervals().count() >= x) return; + if (x < 0 || rideItem->intervals().count() <= x) return; -//XXX WHEN DECIDED HOW TO SELECT/UNSELECT INTERVALS -#if 0 - IntervalItem *current = dynamic_cast(context->athlete->allIntervalItems()->child(x)); - if (current) current->setSelected(!current->isSelected()); -#endif + IntervalItem *current = rideItem->intervals().at(x); + if (current) { + current->selected = !current->selected; + context->notifyIntervalItemSelectionChanged(current); + } } diff --git a/src/Charts/BingMap.h b/src/Charts/BingMap.h index 9241420fd..a09870871 100644 --- a/src/Charts/BingMap.h +++ b/src/Charts/BingMap.h @@ -21,8 +21,15 @@ #include "GoldenCheetah.h" #include + +#ifdef NOWEBKIT +#include +#include +#else #include #include +#endif + #include #include #include @@ -77,7 +84,7 @@ class BingMap : public GcChartWindow public: BingMap(Context *); - virtual ~BingMap() {} + ~BingMap(); bool first; public slots: @@ -91,7 +98,13 @@ class BingMap : public GcChartWindow private: Context *context; QVBoxLayout *layout; + +#ifdef NOWEBKIT + QWebEngineView *view; +#else QWebView *view; +#endif + BWebBridge *webBridge; BingMap(); // default ctor int range; diff --git a/src/Gui/GcWindowRegistry.cpp b/src/Gui/GcWindowRegistry.cpp index 9604ee12f..a2e867856 100644 --- a/src/Gui/GcWindowRegistry.cpp +++ b/src/Gui/GcWindowRegistry.cpp @@ -52,9 +52,9 @@ #include "WorkoutPlotWindow.h" #include "WorkoutWindow.h" #ifndef NOWEBKIT -#include "BingMap.h" #include "RideWindow.h" #endif +#include "BingMap.h" #include "GoogleMapControl.h" // Not until v4.0 //#include "RouteWindow.h" @@ -203,17 +203,17 @@ GcWindowRegistry::newGcWindow(GcWinID id, Context *context) case GcWindowTypes::SpinScanPlot: returning = new SpinScanPlotWindow(context); break; case GcWindowTypes::WorkoutPlot: returning = new WorkoutPlotWindow(context); break; #ifdef NOWEBKIT - case GcWindowTypes::BingMap: case GcWindowTypes::MapWindow: case GcWindowTypes::StreetViewWindow: returning = new GcWindow(); break; break; #else - case GcWindowTypes::BingMap: returning = new BingMap(context); break; case GcWindowTypes::MapWindow: returning = new MapWindow(context); break; case GcWindowTypes::StreetViewWindow: returning = new StreetViewWindow(context); break; #endif case GcWindowTypes::GoogleMap: returning = new GoogleMapControl(context); break; + case GcWindowTypes::BingMap: returning = new BingMap(context); break; + case GcWindowTypes::ActivityNavigator: returning = new RideNavigator(context); break; case GcWindowTypes::WorkoutWindow: returning = new WorkoutWindow(context); break; #if 0 // not till v4.0 diff --git a/src/src.pro b/src/src.pro index 9f60e4982..ac34d1a66 100644 --- a/src/src.pro +++ b/src/src.pro @@ -569,7 +569,7 @@ HEADERS += ANT/ANTChannel.h ANT/ANT.h ANT/ANTlocalController.h ANT/ANTLogger.h # Charts and associated widgets HEADERS += Charts/Aerolab.h Charts/AerolabWindow.h Charts/AllPlot.h Charts/AllPlotInterval.h Charts/AllPlotSlopeCurve.h \ - Charts/AllPlotWindow.h Charts/BlankState.h Charts/ChartBar.h Charts/ChartSettings.h \ + Charts/AllPlotWindow.h Charts/BingMap.h Charts/BlankState.h Charts/ChartBar.h Charts/ChartSettings.h \ Charts/CpPlotCurve.h Charts/CPPlot.h Charts/CriticalPowerWindow.h Charts/DaysScaleDraw.h Charts/ExhaustionDialog.h Charts/GcOverlayWidget.h \ Charts/GcPane.h Charts/GoldenCheetah.h Charts/GoogleMapControl.h Charts/HistogramWindow.h Charts/HomeWindow.h \ Charts/HrPwPlot.h Charts/HrPwWindow.h Charts/IndendPlotMarker.h Charts/IntervalSummaryWindow.h Charts/LogTimeScaleDraw.h \ @@ -580,10 +580,9 @@ HEADERS += Charts/Aerolab.h Charts/AerolabWindow.h Charts/AllPlot.h Charts/AllPl Charts/ScatterPlot.h Charts/ScatterWindow.h Charts/SmallPlot.h Charts/SummaryWindow.h Charts/TreeMapPlot.h \ Charts/TreeMapWindow.h Charts/ZoneScaleDraw.h -# Bing/Google Map temporarily disabled if we don't have WebKit -# This will be resolved shortly +# RideWindow temporarily disabled if we don't have WebKit !contains(DEFINES, NOWEBKIT) { - HEADERS += Charts/BingMap.h Charts/RideWindow.h + HEADERS += Charts/RideWindow.h } # cloud services @@ -648,7 +647,7 @@ SOURCES += ANT/ANTChannel.cpp ANT/ANT.cpp ANT/ANTlocalController.cpp ANT/ANTLogg ## Charts and related SOURCES += Charts/Aerolab.cpp Charts/AerolabWindow.cpp Charts/AllPlot.cpp Charts/AllPlotInterval.cpp Charts/AllPlotSlopeCurve.cpp \ - Charts/AllPlotWindow.cpp Charts/BlankState.cpp Charts/ChartBar.cpp Charts/ChartSettings.cpp \ + Charts/AllPlotWindow.cpp Charts/BingMap.cpp Charts/BlankState.cpp Charts/ChartBar.cpp Charts/ChartSettings.cpp \ Charts/CPPlot.cpp Charts/CpPlotCurve.cpp Charts/CriticalPowerWindow.cpp Charts/ExhaustionDialog.cpp Charts/GcOverlayWidget.cpp Charts/GcPane.cpp \ Charts/GoldenCheetah.cpp Charts/GoogleMapControl.cpp Charts/HistogramWindow.cpp Charts/HomeWindow.cpp Charts/HrPwPlot.cpp \ Charts/HrPwWindow.cpp Charts/IndendPlotMarker.cpp Charts/IntervalSummaryWindow.cpp Charts/LogTimeScaleDraw.cpp \ @@ -659,10 +658,9 @@ SOURCES += Charts/Aerolab.cpp Charts/AerolabWindow.cpp Charts/AllPlot.cpp Charts Charts/ScatterPlot.cpp Charts/ScatterWindow.cpp Charts/SmallPlot.cpp Charts/SummaryWindow.cpp Charts/TreeMapPlot.cpp \ Charts/TreeMapWindow.cpp -# Bing/Google Map temporarily disabled if we don't have WebKit -# This will be resolved shortly +# RideWindow temporarily disabled if we don't have WebKit !contains(DEFINES, NOWEBKIT) { - SOURCES += Charts/BingMap.cpp Charts/RideWindow.cpp + SOURCES += Charts/RideWindow.cpp } ## Cloud Services / Web resources