LibreOffice Module svx (master)  1
MediaPlaybackPanel.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #include "MediaPlaybackPanel.hxx"
20 #include <avmedia/mediaitem.hxx>
21 #include <sfx2/sfxsids.hrc>
22 #include <sfx2/dispatch.hxx>
24 
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 
27 using namespace avmedia;
28 
29 namespace svx::sidebar {
30 
31 MediaPlaybackPanel::MediaPlaybackPanel (
32  weld::Widget* pParent,
33  SfxBindings* pBindings)
34  : PanelLayout(pParent, "MediaPlaybackPanel", "svx/ui/mediaplayback.ui"),
35  MediaControlBase(),
36  maMediaController(SID_AVMEDIA_TOOLBOX, *pBindings, *this),
37  maIdle("MediaPlaybackPanel"),
38  mpBindings(pBindings)
39 {
40  mxTimeEdit = m_xBuilder->weld_entry("timeedit");
41  mxPlayToolBox = m_xBuilder->weld_toolbar("playtoolbox");
42  mxMuteToolBox = m_xBuilder->weld_toolbar("mutetoolbox");
43  mxTimeSlider = m_xBuilder->weld_scale("timeslider");
44  mxVolumeSlider = m_xBuilder->weld_scale("volumeslider");
45  mxZoomListBox = m_xBuilder->weld_combo_box("zoombox");
46 
47  Initialize();
48 }
49 
50 std::unique_ptr<PanelLayout> MediaPlaybackPanel::Create(
51  weld::Widget* pParent,
52  SfxBindings* pBindings)
53 {
54  if (pParent == nullptr)
55  throw lang::IllegalArgumentException("no parent Window given to MediaPlaybackPanel::Create", nullptr, 0);
56  if (pBindings == nullptr)
57  throw lang::IllegalArgumentException("no SfxBindings given to MediaPlaybackPanel::Create", nullptr, 2);
58 
59  return std::make_unique<MediaPlaybackPanel>(pParent, pBindings);
60 }
61 
63 {
64  InitializeWidgets();
65  mxVolumeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, VolumeSlideHdl));
66  mxPlayToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl));
67  mxMuteToolBox->connect_clicked(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl));
68  mxTimeSlider->connect_value_changed(LINK(this, MediaPlaybackPanel, SeekHdl));
69 
70  maIdle.SetPriority( TaskPriority::HIGHEST );
71  maIdle.SetInvokeHandler( LINK( this, MediaPlaybackPanel, TimeoutHdl ) );
72  maIdle.Start();
73  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
74 }
75 
77 {
78  disposeWidgets();
79 }
80 
82  const sal_uInt16 nSID,
83  const SfxItemState eState,
84  const SfxPoolItem* pState)
85 {
86  if( nSID == SID_AVMEDIA_TOOLBOX )
87  {
88  if(eState >= SfxItemState::DEFAULT)
89  {
90  mpMediaItem.reset(pState ? static_cast< MediaItem* >(pState->Clone()) : nullptr);
91  Update();
92  }
93  }
94 }
95 
97 {
98  mxPlayToolBox->set_sensitive(false);
99  avmedia::MediaControlBase::UpdateToolBoxes(rMediaItem);
100 }
101 
103 {
104  if (mpMediaItem)
105  {
107  UpdateTimeSlider( *mpMediaItem );
108  UpdateVolumeSlider( *mpMediaItem );
109  UpdateTimeField( *mpMediaItem, mpMediaItem->getTime() );
110  }
111 }
112 
114 {
115  MediaItem aItem(SID_AVMEDIA_TOOLBOX);
116  aItem.setVolumeDB(mxVolumeSlider->get_value());
117  mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem });
118 }
119 
121 {
122  MediaItem aItem(SID_AVMEDIA_TOOLBOX);
123  double nTime = 0;
124  if (mpMediaItem)
125  nTime = mxTimeSlider->get_value() * mpMediaItem->getDuration() / AVMEDIA_TIME_RANGE;
126  aItem.setTime(nTime);
127  mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem });
128  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
129 }
130 
132 {
133  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
134 }
135 
136 IMPL_LINK( MediaPlaybackPanel, PlayToolBoxSelectHdl, const OString&, rId, void)
137 {
138  MediaItem aItem(SID_AVMEDIA_TOOLBOX);
139 
140  if (rId == "play")
141  {
142  aItem.setState( MediaState::Play );
143 
144  if( !mpMediaItem || (mpMediaItem->getTime() == mpMediaItem->getDuration() ))
145  aItem.setTime( 0.0 );
146  else
147  aItem.setTime( mpMediaItem->getTime());
148  }
149  else if (rId == "pause")
150  {
151  aItem.setState( MediaState::Pause );
152  }
153  else if (rId == "stop")
154  {
155  aItem.setState( MediaState::Stop );
156  aItem.setTime( 0.0 );
157  }
158  else if (rId == "mute")
159  {
160  aItem.setMute( mxMuteToolBox->get_item_active("mute") );
161  }
162  else if (rId == "loop")
163  {
164  aItem.setLoop( mxPlayToolBox->get_item_active("loop") );
165  }
166 
167  if(aItem.getMaskSet() != AVMediaSetMask::NONE)
168  {
169  mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem } );
170  mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX);
171  }
172 }
173 
174 } // end of namespace svx::sidebar
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void setLoop(bool bLoop)
void Invalidate(sal_uInt16 nId)
std::unique_ptr< weld::Builder > m_xBuilder
void setState(MediaState eState)
void setTime(double fTime)
virtual void Start() override
virtual void NotifyItemUpdate(const sal_uInt16 nSID, const SfxItemState eState, const SfxPoolItem *pState) override
#define AVMEDIA_TIME_RANGE
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
IMPL_LINK(MediaPlaybackPanel, PlayToolBoxSelectHdl, const OString &, rId, void)
AVMediaSetMask getMaskSet() const
void setVolumeDB(sal_Int16 nDB)
void setMute(bool bMute)
virtual void UpdateToolBoxes(const avmedia::MediaItem &rMediaItem) override
SfxItemState
void SetInvokeHandler(const Link< Timer *, void > &rLink)
std::unique_ptr< ::avmedia::MediaItem > mpMediaItem
void SetPriority(TaskPriority ePriority)
This panel provides media playback control in document.