31 mLayout =
new QVBoxLayout();
32 mLayout->setContentsMargins( 0, 0, 0, 0 );
34 mVideoWidget =
new QVideoWidget(
this );
35 const int vHeight = QFontMetrics( font() ).height() * 12;
36 mVideoWidget->setMinimumHeight( vHeight );
37 mVideoWidget->setMaximumHeight( vHeight );
38 mLayout->addWidget( mVideoWidget );
40 QHBoxLayout *controlsLayout =
new QHBoxLayout();
41 controlsLayout->setContentsMargins( 0, 0, 0, 0 );
43 mPlayButton =
new QPushButton(
this );
44 mPlayButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
46 mPlayButton->setCheckable(
true );
47 controlsLayout->addWidget( mPlayButton );
49 mPositionSlider =
new QSlider(
this );
50 mPositionSlider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
51 mPositionSlider->setOrientation( Qt::Horizontal );
52 controlsLayout->addWidget( mPositionSlider );
54 mDurationLabel =
new QLabel(
this );
55 mDurationLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
56 mDurationLabel->setAlignment( Qt::AlignHCenter );
57 mDurationLabel->setText( QStringLiteral(
"-" ) );
58 QFontMetrics fm( mDurationLabel->font() );
59 mDurationLabel->setMinimumWidth( fm.boundingRect( QStringLiteral(
"00:00:00" ) ).width() );
60 controlsLayout->addWidget( mDurationLabel );
62 QWidget *controls =
new QWidget();
63 controls->setLayout( controlsLayout );
65 mLayout->addWidget( controls );
69 setControlsEnabled(
false );
71 mMediaPlayer.setVideoOutput( mVideoWidget );
73 connect( &mMediaPlayer, &QMediaPlayer::mediaStatusChanged,
this, &QgsMediaWidget::mediaStatusChanged );
74 connect( &mMediaPlayer, &QMediaPlayer::positionChanged,
this, [ = ]()
76 mPositionSlider->setValue(
static_cast<int>( mMediaPlayer.position() / 1000 ) );
79 connect( mPlayButton, &QAbstractButton::clicked,
this, [ = ]()
81#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
82 if ( mMediaPlayer.playbackState() == QMediaPlayer::PlayingState )
84 if ( mMediaPlayer.state() == QMediaPlayer::PlayingState )
94 connect( mPositionSlider, &QAbstractSlider::sliderReleased,
this, [ = ]()
96 mMediaPlayer.setPosition(
static_cast<qint64
>( mPositionSlider->value() ) * 1000 );
172 mDurationLabel->setText( QStringLiteral(
"%1:%2:%3" ).arg( QString::number( hours ), 2,
'0' )