diff --git a/Demos/src/QtWidgetsDemoApp.cpp b/Demos/src/QtWidgetsDemoApp.cpp index 25d15eb47..33977a6d4 100644 --- a/Demos/src/QtWidgetsDemoApp.cpp +++ b/Demos/src/QtWidgetsDemoApp.cpp @@ -8,10 +8,22 @@ const auto MIN_ZOOM = 0; const auto MAP_DPI = 96; namespace { +// used with QWheelEvent template auto pos(EventType* event) { -#if QT_VERSION < 0x051400 +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + return event->pos(); +#else + return event->position().toPoint(); +#endif +} + +// used with QMouseEvent +template +auto pos2(EventType* event) +{ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return event->pos(); #else return event->position().toPoint(); @@ -58,15 +70,15 @@ class MapFrame : public QWidget { void mousePressEvent(QMouseEvent* ev) override { - m_lastMousePos = ::pos(ev); + m_lastMousePos = ::pos2(ev); } void mouseMoveEvent(QMouseEvent* ev) override { - auto x_delta = ::pos(ev).x() - m_lastMousePos.x(); - auto y_delta = ::pos(ev).y() - m_lastMousePos.y(); + auto x_delta = ::pos2(ev).x() - m_lastMousePos.x(); + auto y_delta = ::pos2(ev).y() - m_lastMousePos.y(); m_currentProjection.Move(-x_delta, y_delta); - m_lastMousePos = ::pos(ev); + m_lastMousePos = ::pos2(ev); update(); } diff --git a/Tests/src/DrawTextQt.cpp b/Tests/src/DrawTextQt.cpp index 35bcdd459..148383019 100644 --- a/Tests/src/DrawTextQt.cpp +++ b/Tests/src/DrawTextQt.cpp @@ -100,7 +100,7 @@ void DrawWindow::drawText1(QPainter *painter, QString string, const osmscout::La painter->drawText(point.GetX(), point.GetY(), QString(string[i])); -#if QT_VERSION < 0x051100 +#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) offset+=metrics.width(string[i]); #else offset+=metrics.horizontalAdvance(string[i]); diff --git a/libosmscout-client-qt/include/osmscoutclientqt/InstalledVoicesModel.h b/libosmscout-client-qt/include/osmscoutclientqt/InstalledVoicesModel.h index 313ab69b9..19bc0a48d 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/InstalledVoicesModel.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/InstalledVoicesModel.h @@ -29,7 +29,7 @@ #include #include #include -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include #endif @@ -89,7 +89,7 @@ public slots: SettingsRef settings; // we setup QObject parents, objects are cleaned after Module destruction -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QMediaPlaylist *currentPlaylist{nullptr}; #endif QMediaPlayer *mediaPlayer{nullptr}; diff --git a/libosmscout-client-qt/include/osmscoutclientqt/NavigationModule.h b/libosmscout-client-qt/include/osmscoutclientqt/NavigationModule.h index 3f0492901..3241a9337 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/NavigationModule.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/NavigationModule.h @@ -45,7 +45,7 @@ #include #include -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include #endif @@ -53,7 +53,7 @@ namespace osmscout { -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) using QtMediaPlayerState = QMediaPlayer::State; #else using QtMediaPlayerState = QMediaPlayer::PlaybackState; @@ -142,7 +142,7 @@ public slots: QString voiceDir; // player and playlist should be created in module thread, not in UI thread (constructor) // we setup QObject parents, objects are cleaned after Module destruction -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QMediaPlaylist *currentPlaylist{nullptr}; #endif QMediaPlayer *mediaPlayer{nullptr}; diff --git a/libosmscout-client-qt/src/osmscoutclientqt/InstalledVoicesModel.cpp b/libosmscout-client-qt/src/osmscoutclientqt/InstalledVoicesModel.cpp index 56976f876..dd67326a3 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/InstalledVoicesModel.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/InstalledVoicesModel.cpp @@ -136,7 +136,7 @@ void InstalledVoicesModel::playSample(const QModelIndex &index, const QStringLis return; } -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (mediaPlayer==nullptr){ assert(currentPlaylist==nullptr); mediaPlayer = new QMediaPlayer(this); diff --git a/libosmscout-client-qt/src/osmscoutclientqt/NavigationModule.cpp b/libosmscout-client-qt/src/osmscoutclientqt/NavigationModule.cpp index e9cbe991e..2abfac1c5 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/NavigationModule.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/NavigationModule.cpp @@ -56,19 +56,19 @@ void NavigationModule::InitPlayer() } if (mediaPlayer==nullptr){ -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) assert(currentPlaylist==nullptr); #endif mediaPlayer = new QMediaPlayer(this); -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) currentPlaylist = new QMediaPlaylist(mediaPlayer); #endif -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) connect(mediaPlayer, &QMediaPlayer::stateChanged, this, &NavigationModule::playerStateChanged); #else connect(mediaPlayer, &QMediaPlayer::playbackStateChanged, this, &NavigationModule::playerStateChanged); #endif -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) mediaPlayer->setPlaylist(currentPlaylist); #endif } @@ -138,7 +138,7 @@ void NavigationModule::ProcessMessages(const std::listmessage; InitPlayer(); assert(mediaPlayer); -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) playerStateChanged(mediaPlayer->state()); #else playerStateChanged(mediaPlayer->playbackState()); @@ -329,7 +329,7 @@ QString NavigationModule::sampleFile(osmscout::VoiceInstructionMessage::VoiceSam } } -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void NavigationModule::playerStateChanged(QMediaPlayer::State state) #else void NavigationModule::playerStateChanged(QMediaPlayer::PlaybackState state) @@ -339,26 +339,26 @@ QString NavigationModule::sampleFile(osmscout::VoiceInstructionMessage::VoiceSam qWarning() << "Player state changed from incorrect thread;" << thread << "!=" << QThread::currentThread(); } -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) qDebug() << "Voice player state:" << mediaPlayer->state() << "(" << currentPlaylist->currentIndex() << "/" << currentPlaylist->mediaCount() << ")"; #endif if (!voiceDir.isEmpty() && !nextMessage.empty() && state == QMediaPlayer::StoppedState) { -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) currentPlaylist->clear(); #endif for (const auto& sample : nextMessage){ auto sampleUrl = QUrl::fromLocalFile(voiceDir + QDir::separator() + sampleFile(sample)); -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) qDebug() << "Adding to playlist:" << sampleUrl; currentPlaylist->addMedia(sampleUrl); #endif } nextMessage.clear(); -#if QT_VERSION < 0x060000 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) currentPlaylist->setCurrentIndex(0); #endif mediaPlayer->play();