diff options
author | Stefan Wildemann <metalstrolch@users.noreply.github.com> | 2017-04-05 20:06:28 +0200 |
---|---|---|
committer | Pierre GRANDIN <pgrandin@users.noreply.github.com> | 2017-04-05 11:06:28 -0700 |
commit | f466ed624c282e30869fa1cc04f191812e0b4888 (patch) | |
tree | 0537f6a34b41b767507da5ef3161bcaba8064ada | |
parent | 480200b03e4f887ef82a62a950dad19dd609ec9c (diff) | |
download | navit-R7378.tar.gz |
Qt5 Graphics: Add QML support (#213)R7378
* Qt5: Add navit callbacks to private
Add navit callbacks to private data, to prepare qt5 graphics
transition to QML 2.0 instead of QWidget.
* Qt5: use only one widget
Refactor qt5 code to use only one widget. Overlays won't have their own
widgets anymore. This is in peparation for converting qt4 graphics to
QML 2.0
* initial addition of QML to qt5 graphics.
* Add first (bogus) qml file.
This commit adds the qml file for the qt5 qml graphics if used with
internal gui. And it alters the cmake scripts to istall it.
* Add inital Quick component
Now this has it's own c++ Quick component included. Additionally the
qml file gets embedded into the plugin.
* Small cleanup, qml package name correction.
* Convert to QGuiApplication to remove QWidget dep.
* First time working QQuick Navit
* Lower qml import versions, as sailfish uses old ones.
* Add header to QtQuick item.
* Add new attr qt5_widget to qt5
* Add qt5 variants to test
* Correct mistake in running test for qt5
* Fix: Tomtom libpng version bump to 1.6.29
The libpng version 1.6.28 was removed from
ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/
* Fix: Make window as big as possible if w and h are not given
* Fix navit config for run_linux_test, complete test separation.
* Fix xdotools use separatelog dir
* Fix: correct mess generated with last commit
* Convert from CMAKE_AUTORRC to old macros
We want to support old cmake, that doesn't have AUTORRC
* Fix: Add qml modules to build in order to allow QML graphics to run
* Fix: Use trusty packages instead.
-rwxr-xr-x | CMakeLists.txt | 41 | ||||
-rw-r--r-- | ci/build_linux.sh | 2 | ||||
-rw-r--r-- | ci/build_tomtom_minimal.sh | 8 | ||||
-rw-r--r-- | ci/build_tomtom_plugin.sh | 8 | ||||
-rw-r--r-- | ci/run_linux_tests.sh | 20 | ||||
-rw-r--r-- | ci/setup_tomtom_requirements.sh | 8 | ||||
-rw-r--r-- | ci/xdotools.sh | 15 | ||||
-rw-r--r-- | navit/attr_def.h | 2 | ||||
-rw-r--r-- | navit/graphics/qt5/CMakeLists.txt | 28 | ||||
-rw-r--r-- | navit/graphics/qt5/QNavitQuick.cpp | 201 | ||||
-rw-r--r-- | navit/graphics/qt5/QNavitQuick.h | 34 | ||||
-rw-r--r-- | navit/graphics/qt5/QNavitWidget.cpp | 61 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.cpp | 256 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.h | 52 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.qml | 14 | ||||
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.qrc | 5 |
16 files changed, 648 insertions, 107 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 819e7d450..fe9457e23 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,18 +158,24 @@ libfind_pkg_check_modules(FONTCONFIG fontconfig) #Qt detection if (NOT DISABLE_QT) find_package(Qt5Widgets) - find_package(Qt5Svg) - find_package(Qt5DBus) + find_package(Qt5Quick) find_package(Qt5Positioning) - find_package(Qt5Sensors) - #find_package(Qt5Declarative) - if (Qt5Widgets_FOUND) - else (Qt5Widgets_FOUND) + if (Qt5Widgets_FOUND OR Qt5Quick_FOUND OR Qt5Sensors_FOUND) + add_feature (USE_QWIDGET "Qt5 Qt5Widget not found" FALSE) + add_feature (USE_QML "Qt5 Qt5Quick not found" FALSE) + if (Qt5Widgets_FOUND OR Qt5Quick_FOUND) + find_package(Qt5Svg REQUIRED) + find_package(Qt5DBus REQUIRED) + endif (Qt5Widgets_FOUND OR Qt5Quick_FOUND) + if (Qt5Positioning_FOUND) + find_package(Qt5Sensors REQUIRED) + endif (Qt5Positioning_FOUND) + else (Qt5Widgets_FOUND OR Qt5Quick_FOUND OR Qt5Sensors_FOUND) # Unfortunately, CMake seems to ignore the "OPTIONAL_COMPONENTS" flag, # and actually requires all components to be installed. Maybe this can # be fixed later... find_package(Qt4 4.7 COMPONENTS QtCore OPTIONAL_COMPONENTS QtGui QtXml QtDeclarative QtSvg) - endif (Qt5Widgets_FOUND) + endif (Qt5Widgets_FOUND OR Qt5Quick_FOUND OR Qt5Sensors_FOUND) endif (NOT DISABLE_QT) #pkg-config based detection @@ -313,14 +319,27 @@ if (QT_FOUND) endif() endif() endif(QT_FOUND) -if (Qt5Widgets_FOUND) - set_with_reason(graphics/qt5 "Qt5 found" TRUE ${Qt5Widgets_LIBRARIES} - ${Qt5Declarative_LIBRARIES} +if (Qt5Widgets_FOUND OR Qt5Quick_FOUND) + set(Qt5_ADDITIONAL_LIBRARIES "") + if(Qt5Widgets_FOUND) + set_with_reason(USE_QWIDGET "Qt5Widgets found" TRUE) + if(USE_QWIDGET) + set(Qt5_ADDITIONAL_LIBRARIES ${Qt5_ADDITIONAL_LIBRARIES} ${Qt5Widgets_LIBRARIES}) + endif() + endif() + if(Qt5Quick_FOUND) + set_with_reason(USE_QML "Qt5Quick found" TRUE) + if(USE_QML) + set(Qt5_ADDITIONAL_LIBRARIES ${Qt5_ADDITIONAL_LIBRARIES} ${Qt5Quick_LIBRARIES}) + endif() + endif() + set_with_reason(graphics/qt5 "Qt5 found" TRUE + ${Qt5_ADDITIONAL_LIBRARIES} ${Qt5Svg_LIBRARIES} ${Qt5DBus_LIBRARIES}) endif () if (Qt5Positioning_FOUND) - set_with_reason(vehicle/qt5 "Qt5 Positioning found" TRUE + set_with_reason(vehicle/qt5 "Qt5 Positioning found" TRUE ${Qt5Positioning_LIBRARIES} ${Qt5Sensors_LIBRARIES}) endif () diff --git a/ci/build_linux.sh b/ci/build_linux.sh index 7e26d0685..096651453 100644 --- a/ci/build_linux.sh +++ b/ci/build_linux.sh @@ -1,4 +1,4 @@ -sudo apt-get install cmake libpng12-dev librsvg2-bin libfreetype6-dev libdbus-glib-1-dev g++ libgtk2.0-dev libqt5svg5-dev +sudo apt-get install cmake libpng12-dev librsvg2-bin libfreetype6-dev libdbus-glib-1-dev g++ libgtk2.0-dev libqt5svg5-dev qtdeclarative5-qtquick2-plugin qtdeclarative5-window-plugin cmake_opts="-Dgraphics/qt_qpainter:BOOL=FALSE -Dgui/qml:BOOL=FALSE -DSVG2PNG:BOOL=FALSE -DSAMPLE_MAP=n -Dgraphics/gtk_drawing_area:BOOL=TRUE" diff --git a/ci/build_tomtom_minimal.sh b/ci/build_tomtom_minimal.sh index 8cf0c735a..585f79316 100644 --- a/ci/build_tomtom_minimal.sh +++ b/ci/build_tomtom_minimal.sh @@ -40,9 +40,9 @@ if ! [ -e "~/tomtom_assets/toolchain_redhat_gcc-3.3.4_glibc-2.3.2-20060131a.tar. wget -nv -c https://github.com/navit-gps/dependencies/raw/master/tomtom/toolchain_redhat_gcc-3.3.4_glibc-2.3.2-20060131a.tar.gz -P ~/tomtom_assets fi -if ! test -f "~/tomtom_assets/libpng-1.6.28.tar.gz" +if ! test -f "~/tomtom_assets/libpng-1.6.29.tar.gz" then - wget -nv -c ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.28.tar.gz -P ~/tomtom_assets + wget -nv -c ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.29.tar.gz -P ~/tomtom_assets fi # toolchain @@ -71,8 +71,8 @@ make install # libpng cd /tmp/ -tar xzf ~/tomtom_assets/libpng-1.6.28.tar.gz -cd libpng-1.6.28/ +tar xzf ~/tomtom_assets/libpng-1.6.29.tar.gz +cd libpng-1.6.29/ ./configure --prefix=$PREFIX --host=$ARCH make -j$JOBS make install diff --git a/ci/build_tomtom_plugin.sh b/ci/build_tomtom_plugin.sh index 548109877..6acf3b376 100644 --- a/ci/build_tomtom_plugin.sh +++ b/ci/build_tomtom_plugin.sh @@ -39,9 +39,9 @@ if ! [ -e "~/tomtom_assets/toolchain_redhat_gcc-3.3.4_glibc-2.3.2-20060131a.tar. wget -nv -c https://github.com/navit-gps/dependencies/raw/master/tomtom/toolchain_redhat_gcc-3.3.4_glibc-2.3.2-20060131a.tar.gz -P ~/tomtom_assets fi -if ! test -f "~/tomtom_assets/libpng-1.6.28.tar.gz" +if ! test -f "~/tomtom_assets/libpng-1.6.29.tar.gz" then - wget -nv -c ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.28.tar.gz -P ~/tomtom_assets + wget -nv -c ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.29.tar.gz -P ~/tomtom_assets fi # toolchain @@ -195,8 +195,8 @@ make install # libpng cd /tmp/ -tar xzf ~/tomtom_assets/libpng-1.6.28.tar.gz -cd libpng-1.6.28/ +tar xzf ~/tomtom_assets/libpng-1.6.29.tar.gz +cd libpng-1.6.29/ ./configure --prefix=$PREFIX --host=$ARCH make -j$JOBS make install diff --git a/ci/run_linux_tests.sh b/ci/run_linux_tests.sh index 3f87161ed..4c937dc7d 100644 --- a/ci/run_linux_tests.sh +++ b/ci/run_linux_tests.sh @@ -12,10 +12,10 @@ linux_test () { sleep 5 # screen shot root window - import -window root $CIRCLE_ARTIFACTS/default.png + import -window root $CIRCLE_ARTIFACTS/logs_${1}/default.png # run tests on X11 - bash ~/navit/ci/xdotools.sh + bash ~/navit/ci/xdotools.sh ${1} # python ~/navit/ci/dbus_tests.py $CIRCLE_TEST_REPORTS/ # dbus-send --print-reply --session --dest=org.navit_project.navit /org/navit_project/navit/default_navit org.navit_project.navit.navit.quit @@ -46,11 +46,21 @@ linux_test gtk_drawing_area # restore config cp navit.xml.bak navit.xml -# run qt5 test -sed -i -e 's@graphics type="gtk_drawing_area"@graphics type="qt5" v="792" h="547"@' navit.xml +# run qt5 qwidget test +sed -i -e 's@graphics type="gtk_drawing_area"@graphics type="qt5" w="792" h="547" qt5_widget="qwidget"@' navit.xml sed -i -e 's@name="Local GPS" profilename="car" enabled="yes" active="1"@name="Local GPS" profilename="car" enabled="no" active="0"@' navit.xml sed -i -e 's@name="Demo" profilename="car" enabled="no" @name="Demo" profilename="car" enabled="yes" follow="1" refresh="1"@' navit.xml sed -i -e 's@type="internal" enabled@type="internal" fullscreen="1" font_size="350" enabled@' navit.xml sed -i -e 's@libbinding_dbus.so" active="no"@libbinding_dbus.so" active="yes"@' navit.xml -linux_test qt5 +linux_test qt5_widget + +# restore config +cp navit.xml.bak navit.xml +# run qt5 qml test +sed -i -e 's@graphics type="gtk_drawing_area"@graphics type="qt5" w="792" h="547" qt5_widget="qml"@' navit.xml +sed -i -e 's@name="Local GPS" profilename="car" enabled="yes" active="1"@name="Local GPS" profilename="car" enabled="no" active="0"@' navit.xml +sed -i -e 's@name="Demo" profilename="car" enabled="no" @name="Demo" profilename="car" enabled="yes" follow="1" refresh="1"@' navit.xml +sed -i -e 's@type="internal" enabled@type="internal" fullscreen="1" font_size="350" enabled@' navit.xml +sed -i -e 's@libbinding_dbus.so" active="no"@libbinding_dbus.so" active="yes"@' navit.xml +linux_test qt5_qml diff --git a/ci/setup_tomtom_requirements.sh b/ci/setup_tomtom_requirements.sh index bf07211c6..8ed1c158f 100644 --- a/ci/setup_tomtom_requirements.sh +++ b/ci/setup_tomtom_requirements.sh @@ -40,9 +40,9 @@ if ! [ -e "~/assets/tomtom/toolchain_redhat_gcc-3.3.4_glibc-2.3.2-20060131a.tar. wget -nv -c http://www.tomtom.com/gpl/toolchain_redhat_gcc-3.3.4_glibc-2.3.2-20060131a.tar.gz -P ~/assets/tomtom fi -if ! test -f "~/assets/tomtom/libpng-1.6.27.tar.gz" +if ! test -f "~/assets/tomtom/libpng-1.6.29.tar.gz" then - wget -nv -c ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.27.tar.gz -P ~/assets/tomtom + wget -nv -c ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.29.tar.gz -P ~/assets/tomtom fi # toolchain @@ -70,8 +70,8 @@ make install # libpng cd /tmp/ -tar xzf ~/assets/tomtom/libpng-1.6.27.tar.gz -cd libpng-1.6.27/ +tar xzf ~/assets/tomtom/libpng-1.6.29.tar.gz +cd libpng-1.6.29/ ./configure --prefix=$PREFIX --host=$ARCH make -j$JOBS make install diff --git a/ci/xdotools.sh b/ci/xdotools.sh index 36331fd9b..b745d9f39 100644 --- a/ci/xdotools.sh +++ b/ci/xdotools.sh @@ -1,18 +1,21 @@ sudo apt-get install xdotool # Use xinput test 4 when running x11vnc on the circleci server to find mouse coordinates -[ -d $CIRCLE_ARTIFACTS/frames/ ] || mkdir $CIRCLE_ARTIFACTS/frames/ +FRAME_DIR=$CIRCLE_ARTIFACTS/logs_${1}/frames +LOGS_DIR=$CIRCLE_ARTIFACTS/logs_${1} + +[ -d $FRAME_DIR/ ] || mkdir $FRAME_DIR/ event=0 send_event (){ file=`printf "%05d\n" $event` - import -window root $CIRCLE_ARTIFACTS/frames/tmp.png + import -window root $FRAME_DIR/tmp.png if [[ "$1" == "mousemove" ]]; then - composite -gravity NorthWest -geometry +$2+$3 ~/navit/ci/pointer-64.png $CIRCLE_ARTIFACTS/frames/tmp.png $CIRCLE_ARTIFACTS/frames/${file}.png + composite -gravity NorthWest -geometry +$2+$3 ~/navit/ci/pointer-64.png $FRAME_DIR/tmp.png $FRAME_DIR/${file}.png else - mv $CIRCLE_ARTIFACTS/frames/tmp.png $CIRCLE_ARTIFACTS/frames/${file}.png + mv $FRAME_DIR/tmp.png $FRAME_DIR/${file}.png fi event=$((event+1)) xdotool $@ @@ -78,7 +81,7 @@ send_event key KP_Enter # Validate # capture 5 seconds of usage for i in `seq 99994 99999`; do - import -window root $CIRCLE_ARTIFACTS/frames/${i}.png + import -window root $FRAME_DIR/${i}.png sleep 1 done @@ -91,4 +94,4 @@ send_event key Right # Select 'Quit' send_event key KP_Enter # Validate # Assemble the gif -convert -delay 100 -loop 0 $CIRCLE_ARTIFACTS/frames/*.png $CIRCLE_ARTIFACTS/town_search.gif +convert -delay 100 -loop 0 $FRAME_DIR/*.png $LOGS_DIR/town_search.gif diff --git a/navit/attr_def.h b/navit/attr_def.h index fdb973f47..7e66ac3d2 100644 --- a/navit/attr_def.h +++ b/navit/attr_def.h @@ -282,7 +282,7 @@ ATTR_UNUSED ATTR_UNUSED ATTR(window_title) ATTR(qt5_platform) -ATTR_UNUSED +ATTR(qt5_widget) /* poi */ ATTR_UNUSED ATTR(info_html) diff --git a/navit/graphics/qt5/CMakeLists.txt b/navit/graphics/qt5/CMakeLists.txt index 9c2574e8b..0f5e19c6c 100644 --- a/navit/graphics/qt5/CMakeLists.txt +++ b/navit/graphics/qt5/CMakeLists.txt @@ -2,8 +2,30 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) +# Instruct CMake to build QRC if needed +#set(CMAKE_AUTORCC ON) -> unfortunate cmake used in CI doesnt have this -# Find the QtWidgets library -find_package(Qt5Widgets) +# collect additional source files in this variable +set (GRAPHICS_QT5_ADDITIONAL "") + +# initialize QML and QWIDGET usage to not use +set(QML 0) +set(QWIDGET 0) + +# check if we have QML +if(USE_QML) + set(QML 1) + qt5_add_resources(QT5_QRC "graphics_qt5.qrc") + set(GRAPHICS_QT5_ADDITIONAL ${GRAPHICS_QT5_ADDITIONAL} "QNavitQuick.cpp" ${QT5_QRC}) +endif () + +#check if we have QWIDGET +if(USE_QWIDGET) + set(QWIDGET 1) + set(GRAPHICS_QT5_ADDITIONAL ${GRAPHICS_QT5_ADDITIONAL} "QNavitWidget.cpp") +endif () + +module_add_library(graphics_qt5 graphics_qt5.cpp event_qt5.cpp ${GRAPHICS_QT5_ADDITIONAL}) +# pass QML and QWIDGET preference to source +target_compile_definitions(graphics_qt5 PRIVATE USE_QML=${QML} USE_QWIDGET=${QWIDGET}) -module_add_library(graphics_qt5 graphics_qt5.cpp event_qt5.cpp QNavitWidget.cpp) diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp new file mode 100644 index 000000000..127ea2113 --- /dev/null +++ b/navit/graphics/qt5/QNavitQuick.cpp @@ -0,0 +1,201 @@ +/** + * Navit, a modular navigation system. + * Copyright (C) 2005-2008 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program 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 this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <glib.h> +#include "config.h" +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#include "item.h" +#include "point.h" +#include "graphics.h" +#include "color.h" +#include "plugin.h" +#include "event.h" +#include "debug.h" +#include "window.h" +#include "callback.h" +#if defined(WINDOWS) || defined(WIN32) || defined (HAVE_API_WIN32_CE) +#include <windows.h> +#endif +#include <QPainter> +#include "QNavitQuick.h" +#include "graphics_qt5.h" + +QNavitQuick::QNavitQuick(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ + setAcceptedMouseButtons(Qt::AllButtons); + graphics_priv = NULL; +} + +void QNavitQuick::setGraphicContext(GraphicsPriv *gp) +{ + dbg(lvl_debug,"enter\n"); + graphics_priv = gp->gp; + QObject::connect(gp, SIGNAL(update()), this, SLOT(update())); +} + +static void paintOverlays(QPainter * painter, struct graphics_priv * gp, QPaintEvent * event) +{ + GHashTableIter iter; + struct graphics_priv * key, * value; + g_hash_table_iter_init (&iter, gp->overlays); + while (g_hash_table_iter_next (&iter, (void **)&key, (void **)&value)) + { + if(! value->disable) + { + QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height()); + if(event->rect().intersects(rr)) + { + dbg(lvl_debug,"draw overlay (%d, %d, %d, %d)\n",value->x, value->y, value->pixmap->width(), value->pixmap->height()); + painter->drawPixmap(value->x, value->y, *value->pixmap); + /* draw overlays of overlay if any by recursive calling */ + paintOverlays(painter, value, event); + } + } + } +} + +void QNavitQuick::paint(QPainter *painter) +{ + QPaintEvent event = QPaintEvent(QRect(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height())); + + dbg(lvl_debug,"enter (%f, %f, %f, %f)\n",boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height()); + + /* color background if any */ + if (graphics_priv->background_graphics_gc_priv != NULL) + { + painter->setPen(*graphics_priv->background_graphics_gc_priv->pen); + painter->fillRect(boundingRect(),*graphics_priv->background_graphics_gc_priv->brush); + } + /* draw base */ + painter->drawPixmap(0,0,*graphics_priv->pixmap, + boundingRect().x(), boundingRect().y(), + boundingRect().width(), boundingRect().height()); + paintOverlays(painter, graphics_priv, &event); +} + + +void QNavitQuick::keyPressEvent(QKeyEvent *event) +{ + dbg(lvl_debug,"enter\n"); +} + +void QNavitQuick::keyReleaseEvent(QKeyEvent *event) +{ + dbg(lvl_debug,"enter\n"); +} + +void QNavitQuick::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + dbg(lvl_debug,"enter\n"); + QQuickPaintedItem::geometryChanged(newGeometry,oldGeometry); + QPainter * painter = NULL; + if(graphics_priv == NULL) + { + dbg(lvl_debug,"Context not set, aborting\n"); + return; + } + if(graphics_priv->pixmap != NULL) + { + delete graphics_priv->pixmap; + graphics_priv->pixmap = NULL; + } + + graphics_priv->pixmap=new QPixmap(width(), height()); + painter = new QPainter(graphics_priv->pixmap); + if(painter != NULL) + { + QBrush brush; + painter->fillRect(0, 0, width(), height(), brush); + delete painter; + } + dbg(lvl_debug,"size %fx%f\n", width(), height()); + dbg(lvl_debug,"pixmap %p %dx%d\n", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height()); + /* if the root window got resized, tell navit about it */ + if(graphics_priv->root) + resize_callback(graphics_priv,width(),height()); +} + +void QNavitQuick::mouseEvent(int pressed, QMouseEvent *event) +{ + struct point p; + dbg(lvl_debug,"enter\n"); + p.x=event->x(); + p.y=event->y(); + switch (event->button()) { + case Qt::LeftButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p)); + break; + case Qt::MidButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p)); + break; + case Qt::RightButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p)); + break; + default: + break; + } +} + +void QNavitQuick::mousePressEvent(QMouseEvent *event) +{ + dbg(lvl_debug,"enter\n"); + mouseEvent(1, event); +} + +void QNavitQuick::mouseReleaseEvent(QMouseEvent *event) +{ + dbg(lvl_debug,"enter\n"); + mouseEvent(0, event); +} + +void QNavitQuick::mouseMoveEvent(QMouseEvent *event) +{ + dbg(lvl_debug,"enter\n"); + struct point p; + p.x=event->x(); + p.y=event->y(); + callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void *)&p); +} + +void QNavitQuick::wheelEvent(QWheelEvent *event) +{ + struct point p; + int button; + dbg(lvl_debug,"enter\n"); + p.x=event->x(); // xy-coordinates of the mouse pointer + p.y=event->y(); + + if (event->delta() > 0) // wheel movement away from the person + button=4; + else if (event->delta() < 0) // wheel movement towards the person + button=5; + else + button=-1; + + if (button != -1) { + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); + } + + event->accept(); +} + diff --git a/navit/graphics/qt5/QNavitQuick.h b/navit/graphics/qt5/QNavitQuick.h new file mode 100644 index 000000000..d213bdac5 --- /dev/null +++ b/navit/graphics/qt5/QNavitQuick.h @@ -0,0 +1,34 @@ +#ifndef QNAVITQUICK_H +#define QNAVITQUICK_H +class QNavitQuick; +#include <QtQuick/QQuickPaintedItem> +#include <QColor> + +#include "graphics_qt5.h" + +class QNavitQuick : public QQuickPaintedItem +{ + Q_OBJECT +public: + QNavitQuick(QQuickItem *parent = 0); + + void paint(QPainter *painter); + + Q_INVOKABLE void setGraphicContext(GraphicsPriv *gp); + +protected: + virtual void keyPressEvent(QKeyEvent *event); + virtual void keyReleaseEvent(QKeyEvent *event); + virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + virtual void mouseEvent(int pressed, QMouseEvent *event); + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseReleaseEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); + virtual void wheelEvent(QWheelEvent *event); + + +private: + struct graphics_priv* graphics_priv; +}; + +#endif diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp index fe3a618e2..ad32c2cb7 100644 --- a/navit/graphics/qt5/QNavitWidget.cpp +++ b/navit/graphics/qt5/QNavitWidget.cpp @@ -53,20 +53,42 @@ bool QNavitWidget::event(QEvent *event) return QWidget::event(event); } +static void paintOverlays(QPainter * painter, struct graphics_priv * gp, QPaintEvent * event) +{ + GHashTableIter iter; + struct graphics_priv * key, * value; + g_hash_table_iter_init (&iter, gp->overlays); + while (g_hash_table_iter_next (&iter, (void **)&key, (void **)&value)) + { + if(! value->disable) + { + QRect rr(value->x, value->y, value->pixmap->width(), value->pixmap->height()); + if(event->rect().intersects(rr)) + { + dbg(lvl_debug,"draw overlay (%d, %d, %d, %d)\n",value->x, value->y, value->pixmap->width(), value->pixmap->height()); + painter->drawPixmap(value->x, value->y, *value->pixmap); + /* draw overlays of overlay if any by recursive calling */ + paintOverlays(painter, value, event); + } + } + } + +} + void QNavitWidget :: paintEvent(QPaintEvent * event) { -// dbg(lvl_debug,"enter\n"); + dbg(lvl_debug,"enter (%d, %d, %d, %d)\n",event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height()); QPainter painter(this); /* color background if any */ - if (graphics_priv->background_graphics_gc_priv != NULL) + if (graphics_priv->background_graphics_gc_priv != NULL) { painter.setPen(*graphics_priv->background_graphics_gc_priv->pen); - painter.fillRect(0, 0, graphics_priv->pixmap->width(), - graphics_priv->pixmap->height(), - *graphics_priv->background_graphics_gc_priv->brush); + painter.fillRect(event->rect(),*graphics_priv->background_graphics_gc_priv->brush); } - painter.drawPixmap(0,0,*graphics_priv->pixmap); - + painter.drawPixmap(0,0,*graphics_priv->pixmap, + event->rect().x(), event->rect().y(), + event->rect().width(), event->rect().height()); + paintOverlays(&painter, graphics_priv, event); } void QNavitWidget::resizeEvent(QResizeEvent * event) @@ -79,17 +101,18 @@ void QNavitWidget::resizeEvent(QResizeEvent * event) } graphics_priv->pixmap=new QPixmap(size()); - graphics_priv->pixmap->fill(); painter = new QPainter(graphics_priv->pixmap); - QBrush brush; - painter->fillRect(0, 0, width(), height(), brush); if(painter != NULL) - delete painter; + { + QBrush brush; + painter->fillRect(0, 0, width(), height(), brush); + delete painter; + } dbg(lvl_debug,"size %dx%d\n", width(), height()); dbg(lvl_debug,"pixmap %p %dx%d\n", graphics_priv->pixmap, graphics_priv->pixmap->width(), graphics_priv->pixmap->height()); /* if the root window got resized, tell navit about it */ if(graphics_priv->root) - resize_callback(width(),height()); + resize_callback(graphics_priv,width(),height()); } void QNavitWidget::mouseEvent(int pressed, QMouseEvent *event) @@ -100,13 +123,13 @@ void QNavitWidget::mouseEvent(int pressed, QMouseEvent *event) p.y=event->y(); switch (event->button()) { case Qt::LeftButton: - callback_list_call_attr_3(callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), GINT_TO_POINTER(&p)); break; case Qt::MidButton: - callback_list_call_attr_3(callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), GINT_TO_POINTER(&p)); break; case Qt::RightButton: - callback_list_call_attr_3(callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), GINT_TO_POINTER(&p)); break; default: break; @@ -131,14 +154,14 @@ void QNavitWidget::mouseMoveEvent(QMouseEvent *event) // dbg(lvl_debug,"enter\n"); p.x=event->x(); p.y=event->y(); - callback_list_call_attr_1(callbacks, attr_motion, (void *)&p); + callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void *)&p); } void QNavitWidget::wheelEvent(QWheelEvent *event) { struct point p; int button; - dbg(lvl_debug,"enter"); + dbg(lvl_debug,"enter\n"); p.x=event->x(); // xy-coordinates of the mouse pointer p.y=event->y(); @@ -150,8 +173,8 @@ void QNavitWidget::wheelEvent(QWheelEvent *event) button=-1; if (button != -1) { - callback_list_call_attr_3(callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); - callback_list_call_attr_3(callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), GINT_TO_POINTER(&p)); } event->accept(); diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index 81fec32c2..c7408690d 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -36,19 +36,43 @@ #endif #include "graphics_qt5.h" #include "event_qt5.h" -#include "QNavitWidget.h" -#include <QApplication> -#include <QDesktopWidget> +#include <QGuiApplication> #include <QPixmap> #include <QPainter> #include <QFont> #include <QSvgRenderer> -#include <QPixmapCache> #include <QDBusConnection> #include <QDBusInterface> +#include <QFile> +#include <QScreen> +#if USE_QML +#include <QQuickWindow> +#include <QQmlApplicationEngine> +#include <QQmlContext> +#include "QNavitQuick.h" +#endif +#if USE_QWIDGET +#include <QApplication> +#include "QNavitWidget.h" +#endif + +#if USE_QML +GraphicsPriv::GraphicsPriv(struct graphics_priv * gp) +{ + this->gp = gp; +} + +GraphicsPriv::~GraphicsPriv() +{ +} + +void GraphicsPriv::emit_update() +{ + emit update(); +} +#endif -struct callback_list* callbacks; -QApplication * navit_app = NULL; +QGuiApplication * navit_app = NULL; struct graphics_font_priv { QFont * font; @@ -71,8 +95,18 @@ graphics_destroy(struct graphics_priv *gr) /* destroy pixmap */ if(gr->pixmap != NULL) delete(gr->pixmap); - /* destroy widget */ - delete(gr->widget); + /* destroy widget if root window*/ + if(gr->root) + { +#if USE_QWIDGET + if(gr->widget != NULL) + delete(gr->widget); +#endif +#if USE_QML + if(gr->GPriv != NULL) + delete(gr->GPriv); +#endif + } /* unregister from parent, if any */ if(gr->parent != NULL) { @@ -393,7 +427,7 @@ draw_circle(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point static void draw_text(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct graphics_font_priv *font, char *text, struct point *p, int dx, int dy) { -// dbg(lvl_debug,"enter gc=%p, fg=%p, bg=%p pos(%d,%d) %s\n", gr, fg, bg, p->x, p->y, text); + dbg(lvl_debug,"enter gc=%p, fg=%p, bg=%p pos(%d,%d) %s\n", gr, fg, bg, p->x, p->y, text); QPainter *painter=gr->painter; if(painter == NULL) return; @@ -490,7 +524,8 @@ static void draw_drag(struct graphics_priv *gr, struct point *p) if(p != NULL) { // dbg(lvl_debug,"enter %p (%d,%d)\n", gr, p->x, p->y); - gr->widget->move(p->x, p->y); + gr->x = p->x; + gr->y = p->y; } else { @@ -530,8 +565,16 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) gr->painter->end(); delete(gr->painter); gr->painter = NULL; +#if USE_QWIDGET /* call repaint on widget */ - gr->widget->repaint(); + if(gr->widget != NULL) + gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height()); +#endif +#if USE_QML + if(gr->GPriv != NULL) + gr->GPriv->emit_update(); + +#endif } else dbg(lvl_debug, "Context %p not active!\n", gr) @@ -546,10 +589,10 @@ draw_mode(struct graphics_priv *gr, enum draw_mode_num mode) static struct graphics_priv * overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct point *p, int w, int h, int wraparound); void -resize_callback(int w, int h) +resize_callback(struct graphics_priv * gr, int w, int h) { // dbg(lvl_debug,"enter (%d, %d)\n", w, h); - callback_list_call_attr_2(callbacks, attr_resize, + callback_list_call_attr_2(gr->callbacks, attr_resize, GINT_TO_POINTER(w), GINT_TO_POINTER(h)); } @@ -559,10 +602,24 @@ graphics_qt5_fullscreen(struct window *w, int on) struct graphics_priv * gr; // dbg(lvl_debug,"enter\n"); gr = (struct graphics_priv *) w->priv; - if(on) - gr->widget->setWindowState(Qt::WindowFullScreen); - else - gr->widget->setWindowState(Qt::WindowMaximized); +#if USE_QML + if(gr->window != NULL) + { + if(on) + gr->window->setWindowState(Qt::WindowFullScreen); + else + gr->window->setWindowState(Qt::WindowMaximized); + } +#endif +#if USE_QWIDGET + if(gr->widget != NULL) + { + if(on) + gr->widget->setWindowState(Qt::WindowFullScreen); + else + gr->widget->setWindowState(Qt::WindowMaximized); + } +#endif return 1; } @@ -605,7 +662,7 @@ get_data(struct graphics_priv *this_priv, char const *type) win->priv = this_priv; win->fullscreen = graphics_qt5_fullscreen; win->disable_suspend = graphics_qt5_disable_suspend; - resize_callback(this_priv->widget->width(),this_priv->widget->height()); + resize_callback(this_priv, this_priv->pixmap->width(),this_priv->pixmap->height()); return win; } return NULL; @@ -653,21 +710,22 @@ static void overlay_disable(struct graphics_priv *gr, int disable) while (g_hash_table_iter_next (&iter, (void **)&key, (void **)&value)) { /* disable or enable all overlays of this pane */ - value->widget->setVisible(!disable); + value->disable = disable; } } static void overlay_resize(struct graphics_priv *gr, struct point *p, int w, int h, int wraparound) { // dbg(lvl_debug,"enter\n"); - gr->widget->move(p->x, p->y); - gr->widget->resize(w, h); + gr->x = p->x; + gr->y = p->y; if(gr->painter != NULL) { delete(gr->painter); } delete(gr->pixmap); - gr->pixmap = new QPixmap(gr->widget->size()); + gr->pixmap = new QPixmap(w, h); + gr->pixmap->fill(Qt::transparent); if(gr->painter != NULL) gr->painter = new QPainter (gr->pixmap); } @@ -710,11 +768,19 @@ overlay_new(struct graphics_priv *gr, struct graphics_methods *meth, struct poin meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox; } #endif - graphics_priv->widget = new QNavitWidget(graphics_priv, gr->widget, Qt::Widget); - graphics_priv->widget->move(p->x, p->y); - graphics_priv->widget->resize(w, h); - graphics_priv->widget->setVisible(true); - graphics_priv->pixmap = new QPixmap(graphics_priv->widget->size()); +#if USE_QML + graphics_priv->window = gr->window; + graphics_priv->GPriv = gr->GPriv; +#endif +#if USE_QWIDGET + graphics_priv->widget = gr->widget; +#endif + graphics_priv->x = p->x; + graphics_priv->y = p->y; + graphics_priv->disable = false; + graphics_priv->callbacks = gr->callbacks; + graphics_priv->pixmap = new QPixmap(w, h); + graphics_priv->pixmap->fill(Qt::transparent); graphics_priv->painter = NULL; graphics_priv->use_count = 0; graphics_priv->parent = gr; @@ -737,8 +803,32 @@ graphics_qt5_new(struct navit *nav, struct graphics_methods *meth, struct attr * struct attr * event_loop_system = NULL; struct attr * platform = NULL; struct attr * fullscreen = NULL; - //dbg(lvl_debug,"enter\n"); + struct attr * attr_widget = NULL; + bool use_qml = USE_QML; + bool use_qwidget = USE_QWIDGET; + //dbg(lvl_debug,"enter\n"); + + /* get qt widget attr */ + if((attr_widget=attr_search(attrs, NULL, attr_qt5_widget))) + { + /* check if we shall use qml */ + if(strcmp (attr_widget->u.str, "qwidget") == 0) + { + use_qml = false; + } + /* check if we shall use qwidget */ + if(strcmp (attr_widget->u.str, "qml") == 0) + { + use_qwidget = false; + } + } + if(use_qml && use_qwidget) + { + /* both are possible, default to QML */ + use_qwidget = false; + } + /*register graphic methods by copying in our predefined ones */ *meth=graphics_methods; @@ -780,7 +870,12 @@ graphics_qt5_new(struct navit *nav, struct graphics_methods *meth, struct attr * graphics_priv->argc ++; } /* create surrounding application */ - navit_app = new QApplication(graphics_priv->argc, graphics_priv->argv); +#if USE_QWIDGET + QApplication * internal_app = new QApplication(graphics_priv->argc, graphics_priv->argv); + navit_app = internal_app; +#else + navit_app = new QGuiApplication(graphics_priv->argc, graphics_priv->argv); +#endif #ifdef QT_QPAINTER_USE_FREETYPE graphics_priv->font_freetype_new=font_freetype_new; @@ -788,17 +883,54 @@ graphics_qt5_new(struct navit *nav, struct graphics_methods *meth, struct attr * meth->font_new=(struct graphics_font_priv *(*)(struct graphics_priv *, struct graphics_font_methods *, char *, int, int))graphics_priv->freetype_methods.font_new; meth->get_text_bbox=(void (*)(struct graphics_priv*, struct graphics_font_priv*, char*, int, int, struct point*, int))graphics_priv->freetype_methods.get_text_bbox; #endif - callbacks = cbl; + graphics_priv->callbacks = cbl; graphics_priv->pixmap = NULL; graphics_priv->use_count = 0; graphics_priv->painter = NULL; graphics_priv->parent = NULL; graphics_priv->overlays=g_hash_table_new(NULL, NULL); - - graphics_priv->widget = new QNavitWidget(graphics_priv,NULL,Qt::Window); + graphics_priv->x = 0; + graphics_priv->y = 0; + graphics_priv->disable = 0; +#if USE_QML + graphics_priv->window = NULL; + graphics_priv->GPriv = NULL; + if(use_qml) + { + /* register our QtQuick widget to allow it's usage within QML */ + qmlRegisterType<QNavitQuick>("com.navit.graphics_qt5", 1, 0, "QNavitQuick"); + /* get our qml application from embedded resources. May be replaced by the + * QtQuick gui component if enabled */ + QQmlApplicationEngine * engine = new QQmlApplicationEngine(); + if(engine != NULL) + { + graphics_priv->GPriv = new GraphicsPriv(graphics_priv); + QQmlContext *context = engine->rootContext(); + context->setContextProperty("graphics_qt5_context", graphics_priv->GPriv); + engine->load(QUrl("qrc:///graphics_qt5.qml")); + /* Get the engine's root window (for resizing) */ + QObject *toplevel = engine->rootObjects().value(0); + graphics_priv->window = qobject_cast<QQuickWindow *> (toplevel); + } + } +#endif +#if USE_QWIDGET + graphics_priv->widget = NULL; + if(use_qwidget) + { + graphics_priv->widget = new QNavitWidget(graphics_priv,NULL,Qt::Window); + } +#endif if ((fullscreen=attr_search(attrs, NULL, attr_fullscreen)) && (fullscreen->u.num)) { /* show this maximized */ - graphics_priv->widget->setWindowState(Qt::WindowFullScreen); +#if USE_QML + if(graphics_priv->window != NULL) + graphics_priv->window->setWindowState(Qt::WindowFullScreen); +#endif +#if USE_QWIDGET + if(graphics_priv->widget != NULL) + graphics_priv->widget->setWindowState(Qt::WindowFullScreen); +#endif } else { @@ -806,25 +938,65 @@ graphics_qt5_new(struct navit *nav, struct graphics_methods *meth, struct attr * struct attr * w = NULL; struct attr * h = NULL; /* default to desktop size if nothing else is given */ - QRect geomet = navit_app->desktop()->screenGeometry(graphics_priv->widget); + QRect geomet; + geomet.setHeight(100); + geomet.setWidth(100); + /* get desktop size */ + QScreen *primary = navit_app->primaryScreen(); + if(primary != NULL) + { + geomet = primary->availableGeometry(); + } /* check for height */ if ((h = attr_search(attrs, NULL, attr_h)) && (h->u.num > 100)) - geomet.setHeight(h->u.num); + geomet.setHeight(h->u.num); /* check for width */ if ((w = attr_search(attrs, NULL, attr_w)) && (w->u.num > 100)) - geomet.setWidth(w->u.num); - graphics_priv->widget->resize(geomet.width(), geomet.height()); - //graphics_priv->widget->setFixedSize(geomet.width(), geomet.height()); - } + geomet.setWidth(w->u.num); +#if USE_QML + if(graphics_priv->window != NULL) + { + graphics_priv->window->resize(geomet.width(), geomet.height()); + //graphics_priv->window->setFixedSize(geomet.width(), geomet.height()); + } +#endif +#if USE_QWIDGET + if(graphics_priv->widget != NULL) + { + graphics_priv->widget->resize(geomet.width(), geomet.height()); + //graphics_priv->widget->setFixedSize(geomet.width(), geomet.height()); + } +#endif + } /* generate initial pixmap same size as window */ if(graphics_priv->pixmap == NULL) - graphics_priv->pixmap = new QPixmap(graphics_priv->widget->size()); + { +#if USE_QML + if(graphics_priv->window != NULL) + graphics_priv->pixmap = new QPixmap(graphics_priv->window->size()); +#endif +#if USE_QWIDGET + if(graphics_priv->widget != NULL) + graphics_priv->pixmap = new QPixmap(graphics_priv->widget->size()); +#endif + if(graphics_priv->pixmap == NULL) + graphics_priv->pixmap = new QPixmap(100,100); + graphics_priv->pixmap->fill(Qt::black); + } /* tell Navit our geometry */ - resize_callback(graphics_priv->widget->width(),graphics_priv->widget->height()); + resize_callback(graphics_priv, graphics_priv->pixmap->width(),graphics_priv->pixmap->height()); /* show our window */ - graphics_priv->widget->show(); +#if USE_QML + if(graphics_priv->window != NULL) + graphics_priv->window->show(); +#endif +#if USE_QWIDGET + if(graphics_priv->widget != NULL) + graphics_priv->widget->show(); +#endif + return graphics_priv; } diff --git a/navit/graphics/qt5/graphics_qt5.h b/navit/graphics/qt5/graphics_qt5.h index 2f19390c4..2e3f7b85e 100644 --- a/navit/graphics/qt5/graphics_qt5.h +++ b/navit/graphics/qt5/graphics_qt5.h @@ -1,12 +1,27 @@ #ifndef __graphics_qt_h #define __graphics_qt_h + +#ifndef USE_QWIDGET +#define USE_QWIDGET 1 +#endif + +#ifndef USE_QML +#define USE_QML 0 +#endif + #include <glib.h> -#include <QApplication> +#include <QGuiApplication> #include <QPixmap> #include <QPainter> #include <QPen> #include <QBrush> +#if USE_QML +#include <QQuickWindow> +#include <QObject> +#endif +#if USE_QWIDGET #include "QNavitWidget.h" +#endif #ifndef QT_QPAINTER_USE_FREETYPE #define QT_QPAINTER_USE_FREETYPE 1 @@ -24,11 +39,36 @@ struct graphics_gc_priv; struct graphics_priv; +#if USE_QML +class GraphicsPriv : public QObject +{ + Q_OBJECT +public: + GraphicsPriv(struct graphics_priv * gp); + ~GraphicsPriv(); + void emit_update(); + + struct graphics_priv * gp; + +signals: + void update(); +}; +#endif + struct graphics_priv { +#if USE_QML + GraphicsPriv * GPriv; + QQuickWindow * window; +#endif +#if USE_QWIDGET QNavitWidget * widget; +#endif QPixmap * pixmap; QPainter * painter; int use_count; + int disable; + int x; + int y; struct graphics_gc_priv * background_graphics_gc_priv; #ifdef QT_QPAINTER_USE_FREETYPE struct font_priv * (*font_freetype_new)(void *meth); @@ -38,6 +78,7 @@ struct graphics_priv { struct callback *display_on_cb; struct event_timeout *display_on_ev; #endif + struct callback_list* callbacks; GHashTable *overlays; struct graphics_priv * parent; bool root; @@ -45,19 +86,16 @@ struct graphics_priv { char * argv[4]; }; + struct graphics_gc_priv { struct graphics_priv * graphics_priv; QPen * pen; QBrush * brush; }; /* central exported application info */ -extern QApplication * navit_app; - -/* navit callback list */ -extern struct callback_list* callbacks; +extern QGuiApplication * navit_app; -void -resize_callback(int w, int h); +void resize_callback(struct graphics_priv * gr, int w, int h); #endif diff --git a/navit/graphics/qt5/graphics_qt5.qml b/navit/graphics/qt5/graphics_qt5.qml new file mode 100644 index 000000000..3748fe520 --- /dev/null +++ b/navit/graphics/qt5/graphics_qt5.qml @@ -0,0 +1,14 @@ +import com.navit.graphics_qt5 1.0 +import QtQuick 2.2 +import QtQuick.Window 2.0 + +Window { + width: 200; height: 200 + QNavitQuick { + id: navit1 + anchors.fill: parent + Component.onCompleted: { + navit1.setGraphicContext(graphics_qt5_context) + } + } +} diff --git a/navit/graphics/qt5/graphics_qt5.qrc b/navit/graphics/qt5/graphics_qt5.qrc new file mode 100644 index 000000000..4c82492ee --- /dev/null +++ b/navit/graphics/qt5/graphics_qt5.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>graphics_qt5.qml</file> + </qresource> +</RCC> |