From c2f95e69684948aa2db75b95afbf7a5eb77be953 Mon Sep 17 00:00:00 2001 From: Yousuf Philips Date: Sun, 14 Aug 2016 23:53:31 +0400 Subject: tdf#87794: Media Playback Panel Change-Id: I2ad02ea031c2a1f558f76bd4c5dd816e400c5269 Reviewed-on: https://gerrit.libreoffice.org/27363 Reviewed-by: Yousuf Philips Tested-by: Yousuf Philips Reviewed-by: Katarina Behrens --- svx/Library_svx.mk | 2 + svx/UIConfig_svx.mk | 1 + svx/source/sidebar/PanelFactory.cxx | 5 + svx/source/sidebar/media/MediaPlaybackPanel.cxx | 199 ++++++++++++++++++++++++ svx/source/sidebar/media/MediaPlaybackPanel.hxx | 84 ++++++++++ svx/uiconfig/ui/mediaplayback.ui | 170 ++++++++++++++++++++ 6 files changed, 461 insertions(+) create mode 100644 svx/source/sidebar/media/MediaPlaybackPanel.cxx create mode 100644 svx/source/sidebar/media/MediaPlaybackPanel.hxx create mode 100644 svx/uiconfig/ui/mediaplayback.ui (limited to 'svx') diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index 919f721c480e..9c09ed0624c0 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -41,6 +41,7 @@ $(eval $(call gb_Library_add_defs,svx,\ $(eval $(call gb_Library_set_precompiled_header,svx,$(SRCDIR)/svx/inc/pch/precompiled_svx)) $(eval $(call gb_Library_use_libraries,svx,\ + avmedia\ basegfx \ sb \ comphelper \ @@ -200,6 +201,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/sidebar/line/LinePropertyPanelBase \ svx/source/sidebar/line/LineWidthValueSet \ svx/source/sidebar/line/LineWidthPopup \ + svx/source/sidebar/media/MediaPlaybackPanel \ svx/source/sidebar/possize/PosSizePropertyPanel \ svx/source/sidebar/possize/SidebarDialControl \ svx/source/sidebar/shapes/DefaultShapesPanel \ diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk index bb1bda38d500..502e8801881a 100644 --- a/svx/UIConfig_svx.mk +++ b/svx/UIConfig_svx.mk @@ -45,6 +45,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\ svx/uiconfig/ui/headfootformatpage \ svx/uiconfig/ui/imapdialog \ svx/uiconfig/ui/linkwarndialog \ + svx/uiconfig/ui/mediaplayback \ svx/uiconfig/ui/namespacedialog \ svx/uiconfig/ui/optgridpage \ svx/uiconfig/ui/paralinespacingcontrol \ diff --git a/svx/source/sidebar/PanelFactory.cxx b/svx/source/sidebar/PanelFactory.cxx index d64ee5c4c9f0..97817e0283fb 100644 --- a/svx/source/sidebar/PanelFactory.cxx +++ b/svx/source/sidebar/PanelFactory.cxx @@ -26,6 +26,7 @@ #include "line/LinePropertyPanel.hxx" #include "possize/PosSizePropertyPanel.hxx" #include "shapes/DefaultShapesPanel.hxx" +#include "media/MediaPlaybackPanel.hxx" #include "GalleryControl.hxx" #include "EmptyPanel.hxx" #include @@ -172,6 +173,10 @@ Reference SAL_CALL PanelFactory::createUIElement ( { pControl = DefaultShapesPanel::Create(pParentWindow, xFrame); } + else if (rsResourceURL.endsWith("/MediaPlaybackPanel")) + { + pControl = MediaPlaybackPanel::Create(pParentWindow, xFrame, pBindings); + } else if (rsResourceURL.endsWith("/GalleryPanel")) { pControl.reset(VclPtr::Create(pBindings, pParentWindow)); diff --git a/svx/source/sidebar/media/MediaPlaybackPanel.cxx b/svx/source/sidebar/media/MediaPlaybackPanel.cxx new file mode 100644 index 000000000000..f35304c40d75 --- /dev/null +++ b/svx/source/sidebar/media/MediaPlaybackPanel.cxx @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "MediaPlaybackPanel.hxx" +#include +#include +#include +#include +#include +#include +#include +#include + +using ::rtl::OUString; +using namespace avmedia; + +namespace svx { namespace sidebar { + +MediaPlaybackPanel::MediaPlaybackPanel ( + vcl::Window* pParent, + const css::uno::Reference& rxFrame, + SfxBindings* pBindings) + : PanelLayout(pParent, "MediaPlaybackPanel", "svx/ui/mediaplayback.ui", rxFrame), + MediaControlBase(), + maMediaController(SID_AVMEDIA_TOOLBOX, *pBindings, *this), + maIdle("MediaPlaybackPanel"), + mpBindings(pBindings) +{ + get(mpTimeEdit, "timeedit"); + get(mpPlayToolBox, "playtoolbox"); + get(mpMuteToolBox, "mutetoolbox"); + get(mpTimeSlider, "timeslider"); + get(mpVolumeSlider, "volumeslider"); + get(mpZoomListBox, "zoombox"); + Initialize(); +} + +VclPtr< vcl::Window > MediaPlaybackPanel::Create( + vcl::Window* pParent, + const Reference< XFrame >& rxFrame, + SfxBindings* pBindings) +{ + if (pParent == nullptr) + throw lang::IllegalArgumentException("no parent Window given to MediaPlaybackPanel::Create", nullptr, 0); + if ( ! rxFrame.is()) + throw lang::IllegalArgumentException("no XFrame given to MediaPlaybackPanel::Create", nullptr, 1); + if (pBindings == nullptr) + throw lang::IllegalArgumentException("no SfxBindings given to MediaPlaybackPanel::Create", nullptr, 2); + + return VclPtr::Create( + pParent, + rxFrame, + pBindings); +} + +MediaPlaybackPanel::~MediaPlaybackPanel() +{ + disposeOnce(); +} + +void MediaPlaybackPanel::Initialize() +{ + InitializeWidgets(); + mpVolumeSlider->SetSlideHdl(LINK(this, MediaPlaybackPanel, VolumeSlideHdl)); + mpPlayToolBox->SetSelectHdl(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl)); + mpMuteToolBox->SetSelectHdl(LINK(this, MediaPlaybackPanel, PlayToolBoxSelectHdl)); + mpTimeSlider->SetSlideHdl(LINK(this, MediaPlaybackPanel, SeekHdl)); + + maIdle.SetPriority( SchedulerPriority::HIGHEST ); + maIdle.SetIdleHdl( LINK( this, MediaPlaybackPanel, TimeoutHdl ) ); + maIdle.Start(); + mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); +} + +void MediaPlaybackPanel::dispose() +{ + mpTimeEdit.disposeAndClear(); + PanelLayout::dispose(); +} + +void MediaPlaybackPanel::NotifyItemUpdate( + const sal_uInt16 nSID, + const SfxItemState eState, + const SfxPoolItem* pState, + const bool bIsEnabled) +{ + (void)bIsEnabled; + if( nSID == SID_AVMEDIA_TOOLBOX ) + { + if(eState >= SfxItemState::DEFAULT) + { + mpMediaItem.reset(pState ? static_cast< MediaItem* >(pState->Clone()) : nullptr); + Update(); + } + } +} + +void MediaPlaybackPanel::UpdateToolBoxes(MediaItem aMediaItem) +{ + mpPlayToolBox->Disable(); + avmedia::MediaControlBase::UpdateToolBoxes(aMediaItem); +} + +void MediaPlaybackPanel::Update() +{ + UpdateToolBoxes( *mpMediaItem ); + UpdateTimeSlider( *mpMediaItem ); + UpdateVolumeSlider( *mpMediaItem ); + UpdateTimeField( *mpMediaItem, mpMediaItem->getTime() ); +} + +IMPL_LINK_NOARG_TYPED( MediaPlaybackPanel, VolumeSlideHdl, Slider*, void) +{ + MediaItem aItem(SID_AVMEDIA_TOOLBOX); + aItem.setVolumeDB( static_cast< sal_Int16 > (mpVolumeSlider->GetThumbPos())); + mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem }); +} + +IMPL_LINK_NOARG_TYPED( MediaPlaybackPanel, SeekHdl, Slider*, void) +{ + MediaItem aItem(SID_AVMEDIA_TOOLBOX); + aItem.setState( MediaState::Pause ); + aItem.setTime( mpTimeSlider->GetThumbPos() * mpMediaItem->getDuration() / AVMEDIA_TIME_RANGE); + mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem }); + mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); +} + +IMPL_LINK_NOARG_TYPED( MediaPlaybackPanel, TimeoutHdl, Idle*, void) +{ + mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); +} + +IMPL_LINK_TYPED( MediaPlaybackPanel, PlayToolBoxSelectHdl, ToolBox*, pControl, void) +{ + MediaItem aItem(SID_AVMEDIA_TOOLBOX); + switch(pControl->GetCurItemId()) + { + case AVMEDIA_TOOLBOXITEM_PLAY: + { + aItem.setState( MediaState::Play ); + + if( mpMediaItem->getTime() == mpMediaItem->getDuration() ) + aItem.setTime( 0.0 ); + else + aItem.setTime( mpMediaItem->getTime()); + } + break; + + case AVMEDIA_TOOLBOXITEM_PAUSE: + { + aItem.setState( MediaState::Pause ); + } + break; + + case AVMEDIA_TOOLBOXITEM_STOP: + { + aItem.setState( MediaState::Stop ); + aItem.setTime( 0.0 ); + } + break; + + case AVMEDIA_TOOLBOXITEM_MUTE: + { + aItem.setMute( !mpMuteToolBox->IsItemChecked( AVMEDIA_TOOLBOXITEM_MUTE ) ); + } + break; + + case AVMEDIA_TOOLBOXITEM_LOOP: + { + aItem.setLoop( !mpPlayToolBox->IsItemChecked( AVMEDIA_TOOLBOXITEM_LOOP ) ); + } + break; + default: break; + } + if(aItem.getMaskSet() != AVMediaSetMask::NONE) + { + mpBindings->GetDispatcher()->ExecuteList(SID_AVMEDIA_TOOLBOX, SfxCallMode::RECORD, { &aItem } ); + mpBindings->Invalidate(SID_AVMEDIA_TOOLBOX); + } +} + +} } // end of namespace svx::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/media/MediaPlaybackPanel.hxx b/svx/source/sidebar/media/MediaPlaybackPanel.hxx new file mode 100644 index 000000000000..0a4bd5ebf441 --- /dev/null +++ b/svx/source/sidebar/media/MediaPlaybackPanel.hxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_SD_SOURCE_SIDEBAR_MEDIAPLAYBACKPANEL_HXX +#define INCLUDED_SD_SOURCE_SIDEBAR_MEDIAPLAYBACKPANEL_HXX + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace css; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::frame; + +namespace svx { namespace sidebar { + +/** This panel provides media playback control in document +*/ +class MediaPlaybackPanel + : public PanelLayout, + public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface, + public ::avmedia::MediaControlBase +{ +public: + MediaPlaybackPanel ( + vcl::Window* pParent, + const css::uno::Reference& rxFrame, + SfxBindings* pBindings); + static VclPtr Create( + vcl::Window* pParent, + const css::uno::Reference& rxFrame, + SfxBindings* pBindings); + virtual ~MediaPlaybackPanel(); + virtual void dispose() override; + +protected: + virtual void UpdateToolBoxes(avmedia::MediaItem aMediaItem) override; + +private: + std::unique_ptr< ::avmedia::MediaItem > mpMediaItem; + ::sfx2::sidebar::ControllerItem maMediaController; + Idle maIdle; + SfxBindings* mpBindings; + void Initialize(); + void Update(); + virtual void NotifyItemUpdate( const sal_uInt16 nSID, + const SfxItemState eState, + const SfxPoolItem* pState, + const bool bIsEnabled) override; + DECL_LINK_TYPED(PlayToolBoxSelectHdl, ToolBox*, void); + DECL_LINK_TYPED(VolumeSlideHdl, Slider*, void); + DECL_LINK_TYPED(SeekHdl, Slider*, void); + DECL_LINK_TYPED(TimeoutHdl, Idle*, void); +}; + + +} } // end of namespace svx::sidebar + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file diff --git a/svx/uiconfig/ui/mediaplayback.ui b/svx/uiconfig/ui/mediaplayback.ui new file mode 100644 index 000000000000..2209bb24333a --- /dev/null +++ b/svx/uiconfig/ui/mediaplayback.ui @@ -0,0 +1,170 @@ + + + + + + True + False + 6 + + + True + False + center + 6 + 7 + True + + + True + False + end + Playback: + + + 0 + 0 + 1 + 1 + + + + + True + False + end + Seek: + + + 0 + 1 + 1 + 1 + + + + + True + False + end + Volume: + + + 0 + 3 + 1 + 1 + + + + + 150 + True + True + 1 + 2 + False + + + 1 + 1 + 1 + 1 + + + + + 150 + False + View + + + 1 + 4 + 1 + 1 + + + + + 150 + True + False + False + 0.5 + + + 1 + 2 + 1 + 1 + + + + + True + False + center + + + 1 + 0 + 1 + 1 + + + + + True + False + + + 2 + 3 + 1 + 1 + + + + + 150 + True + True + 0.98999999999999999 + False + + + 1 + 3 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 1 + 1 + + + + -- cgit