32 mLayout =
new QVBoxLayout();
33 mLayout->setContentsMargins( 0, 0, 0, 0 );
35 mVideoWidget =
new QVideoWidget(
this );
36 const int vHeight = QFontMetrics( font() ).height() * 12;
37 mVideoWidget->setMinimumHeight( vHeight );
38 mVideoWidget->setMaximumHeight( vHeight );
39 mLayout->addWidget( mVideoWidget );
41 QHBoxLayout *controlsLayout =
new QHBoxLayout();
42 controlsLayout->setContentsMargins( 0, 0, 0, 0 );
44 mPlayButton =
new QPushButton(
this );
45 mPlayButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
47 mPlayButton->setCheckable(
true );
48 controlsLayout->addWidget( mPlayButton );
50 mPositionSlider =
new QSlider(
this );
51 mPositionSlider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
52 mPositionSlider->setOrientation( Qt::Horizontal );
53 controlsLayout->addWidget( mPositionSlider );
55 mDurationLabel =
new QLabel(
this );
56 mDurationLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
57 mDurationLabel->setAlignment( Qt::AlignHCenter );
58 mDurationLabel->setText( QStringLiteral(
"-" ) );
59 QFontMetrics fm( mDurationLabel->font() );
60 mDurationLabel->setMinimumWidth( fm.boundingRect( QStringLiteral(
"00:00:00" ) ).width() );
61 controlsLayout->addWidget( mDurationLabel );
63 QWidget *controls =
new QWidget();
64 controls->setLayout( controlsLayout );
66 mLayout->addWidget( controls );
70 setControlsEnabled(
false );
72 mMediaPlayer.setVideoOutput( mVideoWidget );
74 connect( &mMediaPlayer, &QMediaPlayer::mediaStatusChanged,
this, &QgsMediaWidget::mediaStatusChanged );
75 connect( &mMediaPlayer, &QMediaPlayer::positionChanged,
this, [=]() {
76 mPositionSlider->setValue(
static_cast<int>( mMediaPlayer.position() / 1000 ) );
79 connect( mPlayButton, &QAbstractButton::clicked,
this, [=]() {
80#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
81 if ( mMediaPlayer.playbackState() == QMediaPlayer::PlayingState )
83 if ( mMediaPlayer.state() == QMediaPlayer::PlayingState )
93 connect( mPositionSlider, &QAbstractSlider::sliderReleased,
this, [=]() {
94 mMediaPlayer.setPosition(
static_cast<qint64
>( mPositionSlider->value() ) * 1000 );
170 mDurationLabel->setText( QStringLiteral(
"%1:%2:%3" ).arg( QString::number( hours ), 2,
'0' ).arg( QString::number( minutes ), 2,
'0' ).arg( QString::number( seconds ), 2,
'0' ) );