Last active
November 11, 2017 18:54
-
-
Save slarosa/b7c2e2f5a140834e4691fa6299a3d02b to your computer and use it in GitHub Desktop.
An audio joke.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index c3401123e8..fe09479d7f 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -303,6 +303,8 @@ IF(WITH_CORE) | |
FIND_PACKAGE(Qt5UiTools REQUIRED) | |
FIND_PACKAGE(Qt5Script REQUIRED) | |
FIND_PACKAGE(Qt5Sql REQUIRED) | |
+ FIND_PACKAGE(Qt5Multimedia REQUIRED) | |
+ FIND_PACKAGE(Qt5MultimediaWidgets REQUIRED) | |
IF (WITH_3D) | |
FIND_PACKAGE(Qt53DCore REQUIRED) | |
FIND_PACKAGE(Qt53DRender REQUIRED) | |
diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt | |
index 39455668d8..73427b7c41 100644 | |
--- a/src/app/CMakeLists.txt | |
+++ b/src/app/CMakeLists.txt | |
@@ -731,6 +731,7 @@ TARGET_LINK_LIBRARIES(qgis_app | |
qgis_native | |
libdxfrw | |
) | |
+QT5_USE_MODULES(qgis_app Multimedia MultimediaWidgets) | |
IF (WITH_3D) | |
TARGET_LINK_LIBRARIES(qgis_app | |
diff --git a/src/app/qgsstatusbarcoordinateswidget.cpp b/src/app/qgsstatusbarcoordinateswidget.cpp | |
index 20937fd9e1..6dc29d73d6 100644 | |
--- a/src/app/qgsstatusbarcoordinateswidget.cpp | |
+++ b/src/app/qgsstatusbarcoordinateswidget.cpp | |
@@ -21,6 +21,8 @@ | |
#include <QSpacerItem> | |
#include <QTimer> | |
#include <QToolButton> | |
+#include <QtMultimedia/QMediaPlayer> | |
+#include <QtMultimedia/QMediaPlaylist> | |
#include "qgsstatusbarcoordinateswidget.h" | |
#include "qgsapplication.h" | |
@@ -81,6 +83,8 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent ) | |
// When you feel dizzy | |
mDizzyTimer = new QTimer( this ); | |
connect( mDizzyTimer, &QTimer::timeout, this, &QgsStatusBarCoordinatesWidget::dizzy ); | |
+ | |
+ mMusic = new QMediaPlayer( this ); | |
} | |
void QgsStatusBarCoordinatesWidget::setMapCanvas( QgsMapCanvas *mapCanvas ) | |
@@ -135,6 +139,37 @@ void QgsStatusBarCoordinatesWidget::validateCoordinates() | |
refreshMapCanvas(); | |
return; | |
} | |
+ else if ( mLineEdit->text().startsWith( QLatin1String( "music" ) ) ) | |
+ { | |
+ if ( mMusic->state() == QMediaPlayer::StoppedState ) | |
+ { | |
+ QStringList mTrack = mLineEdit->text().split( QStringLiteral( "," ) ); | |
+ QString mAudioFile = QString(); | |
+ bool exists = mTrack.size() > 1 && QFileInfo( mTrack[1] ).exists() && QFileInfo( mTrack[1] ).isFile(); | |
+ if ( !exists ) | |
+ { | |
+ mAudioFile = QString("/Users/slarosa/sound.mp3"); | |
+ } | |
+ else | |
+ { | |
+ mAudioFile = mTrack[1]; | |
+ } | |
+ mPlaylist = new QMediaPlaylist( this ); | |
+ mPlaylist->addMedia( QMediaContent( QUrl::fromLocalFile( mAudioFile ) ) ); | |
+ mPlaylist->setPlaybackMode( QMediaPlaylist::Loop ); | |
+ | |
+ mMusic->setPlaylist(mPlaylist); | |
+ mMusic->setVolume( 100 ); | |
+ mMusic->play(); | |
+ } | |
+ else | |
+ { | |
+ mMusic->stop(); | |
+ } | |
+ return; | |
+ } | |
bool xOk = false; | |
bool yOk = false; | |
diff --git a/src/app/qgsstatusbarcoordinateswidget.h b/src/app/qgsstatusbarcoordinateswidget.h | |
index 988087d922..e248a94cef 100644 | |
--- a/src/app/qgsstatusbarcoordinateswidget.h | |
+++ b/src/app/qgsstatusbarcoordinateswidget.h | |
@@ -27,6 +27,9 @@ class QValidator; | |
class QgsMapCanvas; | |
class QgsPointXY; | |
+class QMediaPlayer; | |
+class QMediaPlaylist; | |
+ | |
#include <QWidget> | |
#include "qgis_app.h" | |
@@ -68,6 +71,9 @@ class APP_EXPORT QgsStatusBarCoordinatesWidget : public QWidget | |
//! Widget that will live on the statusbar to display "Coordinate / Extent" | |
QLabel *mLabel = nullptr; | |
+ QMediaPlaylist *mPlaylist = nullptr; | |
+ QMediaPlayer *mMusic = nullptr; | |
+ | |
QValidator *mCoordsEditValidator = nullptr; | |
QTimer *mDizzyTimer = nullptr; | |
QgsMapCanvas *mMapCanvas = nullptr; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment