sd/source/ui/animations/SlideTransitionPane.cxx | 221 +++++++++-------------- sd/source/ui/inc/SlideTransitionPane.hxx | 22 +- sd/uiconfig/simpress/ui/slidetransitionspanel.ui | 56 ++--- 3 files changed, 132 insertions(+), 167 deletions(-)
New commits: commit 7d34d4944c962ad69e7d05a57c1548ef5ac7be42 Author: Javiya Vivekkumar Dineshbhai <vivek.jav...@collabora.com> AuthorDate: Tue Jul 30 20:27:10 2024 +0200 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Thu Aug 8 13:23:38 2024 +0200 slideshow: change transition drawing view to icon view Signed-off-by: Javiya Vivekkumar Dineshbhai <vivek.jav...@collabora.com> Change-Id: I109d2268824d3be233c5c7b560c1777b95aa4276 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171180 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/sd/source/ui/animations/SlideTransitionPane.cxx b/sd/source/ui/animations/SlideTransitionPane.cxx index e2c954623eaa..2671b3aa0f86 100644 --- a/sd/source/ui/animations/SlideTransitionPane.cxx +++ b/sd/source/ui/animations/SlideTransitionPane.cxx @@ -210,6 +210,9 @@ struct TransitionEffect } // namespace sd::impl +namespace sd +{ + // Local Helper Functions namespace { @@ -341,53 +344,20 @@ void lcl_FillSoundListBox( } /// Returns an offset into the list of transition presets -size_t getPresetOffset( const sd::impl::TransitionEffect &rEffect ) +sd::TransitionPresetPtr getPreset(const sd::impl::TransitionEffect &rEffect) { - const sd::TransitionPresetList& rPresetList = - sd::TransitionPreset::getTransitionPresetList(); + const sd::TransitionPresetList& rPresetList = sd::TransitionPreset::getTransitionPresetList(); - size_t nIdx = 0; - for( const auto& aIt: rPresetList ) + for (const auto& pPreset: rPresetList) { - if( rEffect.operator==( *aIt )) - break; - nIdx++; + if (rEffect.operator==(*pPreset)) + return pPreset; } - return nIdx; + return sd::TransitionPresetPtr(); } } // anonymous namespace -namespace sd -{ - -class TransitionPane : public ValueSet -{ -public: - explicit TransitionPane(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow) - : ValueSet(std::move(pScrolledWindow)) - { - } - - void Recalculate() - { - GetScrollBar()->set_vpolicy(VclPolicyType::AUTOMATIC); - RecalculateItemSizes(); - } - - virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override - { - Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont)); - pDrawingArea->set_size_request(aSize.Width(), aSize.Height()); - ValueSet::SetDrawingArea(pDrawingArea); - SetOutputSizePixel(aSize); - - SetStyle(GetStyle() | WB_ITEMBORDER | WB_FLATVALUESET | WB_VSCROLL); - EnableFullItemMode( false ); - SetColCount(3); - } -}; - // SlideTransitionPane SlideTransitionPane::SlideTransitionPane( weld::Widget* pParent, @@ -395,6 +365,8 @@ SlideTransitionPane::SlideTransitionPane( PanelLayout( pParent, "SlideTransitionsPanel", "modules/simpress/ui/slidetransitionspanel.ui" ), mrBase( rBase ), mpDrawDoc( rBase.GetDocShell() ? rBase.GetDocShell()->GetDoc() : nullptr ), + mxTransitionsIconView(m_xBuilder->weld_icon_view("transitions_icons")), + mxTransitionsScrollWindow(m_xBuilder->weld_scrolled_window("transitions_icons_scrolled_window")), mbHasSelection( false ), mbUpdatingControls( false ), mbIsMainViewChangePending( false ), @@ -409,8 +381,6 @@ css::ui::LayoutSize SlideTransitionPane::GetHeightForWidth(const sal_Int32 /*nWi return css::ui::LayoutSize(nMinimumHeight, -1, nMinimumHeight); } -constexpr sal_uInt16 nNoneId = std::numeric_limits<sal_uInt16>::max(); - void SlideTransitionPane::Initialize(SdDrawDocument* pDoc) { mxLB_VARIANT = m_xBuilder->weld_combo_box("variant_list"); @@ -432,22 +402,12 @@ void SlideTransitionPane::Initialize(SdDrawDocument* pDoc) mxMF_ADVANCE_AUTO_AFTER->set_width_chars(nWidthChars); mxCBX_duration->set_width_chars(nWidthChars); - mxVS_TRANSITION_ICONS.reset(new TransitionPane(m_xBuilder->weld_scrolled_window("transitions_iconswin", true))); - mxVS_TRANSITION_ICONSWin.reset(new weld::CustomWeld(*m_xBuilder, "transitions_icons", *mxVS_TRANSITION_ICONS)); - if( pDoc ) mxModel = pDoc->getUnoModel(); // TODO: get correct view if( mxModel.is()) mxView.set( mxModel->getCurrentController(), uno::UNO_QUERY ); - // dummy list box of slide transitions for startup. - mxVS_TRANSITION_ICONS->InsertItem( - nNoneId, Image( StockImage::Yes, "sd/cmd/transition-none.png" ), - SdResId( STR_SLIDETRANSITION_NONE ), - VALUESET_APPEND, /* show legend */ true ); - mxVS_TRANSITION_ICONS->Recalculate(); - // set defaults mxCB_AUTO_PREVIEW->set_active(true); // automatic preview on @@ -458,7 +418,7 @@ void SlideTransitionPane::Initialize(SdDrawDocument* pDoc) mxPB_APPLY_TO_ALL->connect_clicked( LINK( this, SlideTransitionPane, ApplyToAllButtonClicked )); mxPB_PLAY->connect_clicked( LINK( this, SlideTransitionPane, PlayButtonClicked )); - mxVS_TRANSITION_ICONS->SetSelectHdl( LINK( this, SlideTransitionPane, TransitionSelected )); + mxTransitionsIconView->connect_item_activated(LINK(this, SlideTransitionPane, TransitionSelected)); mxLB_VARIANT->connect_changed( LINK( this, SlideTransitionPane, VariantListBoxSelected )); mxCBX_duration->connect_value_changed(LINK( this, SlideTransitionPane, DurationModifiedHdl)); @@ -481,8 +441,8 @@ SlideTransitionPane::~SlideTransitionPane() { maLateInitTimer.Stop(); removeListener(); - mxVS_TRANSITION_ICONSWin.reset(); - mxVS_TRANSITION_ICONS.reset(); + mxTransitionsScrollWindow.reset(); + mxTransitionsIconView.reset(); mxLB_VARIANT.reset(); mxCBX_duration.reset(); mxFT_SOUND.reset(); @@ -562,16 +522,16 @@ void SlideTransitionPane::updateControls() if( aEffect.mbEffectAmbiguous ) { SAL_WARN( "sd.transitions", "Unusual, ambiguous transition effect" ); - mxVS_TRANSITION_ICONS->SelectItem(nNoneId); + mxTransitionsIconView->select(0); } else { - // ToDo: That 0 is "no transition" is documented nowhere except in the + // ToDo: That 0 is "no transition" is documented nowhere except in the // CTOR of sdpage if( aEffect.mnType == 0 ) - mxVS_TRANSITION_ICONS->SelectItem(nNoneId); + mxTransitionsIconView->select(0); else - updateVariants( getPresetOffset( aEffect ) ); + updateVariants(getPreset(aEffect)); } if( aEffect.mbDurationAmbiguous ) @@ -654,7 +614,8 @@ void SlideTransitionPane::updateControls() void SlideTransitionPane::updateControlState() { - mxVS_TRANSITION_ICONSWin->set_sensitive( mbHasSelection ); + if (mxTransitionsScrollWindow) + mxTransitionsScrollWindow->set_sensitive(mbHasSelection); mxLB_VARIANT->set_sensitive( mbHasSelection && mxLB_VARIANT->get_count() > 0 ); mxCBX_duration->set_sensitive( mbHasSelection ); mxLB_SOUND->set_sensitive( mbHasSelection ); @@ -754,34 +715,34 @@ impl::TransitionEffect SlideTransitionPane::getTransitionEffectFromControls() co impl::TransitionEffect aResult; aResult.setAllAmbiguous(); - bool bNoneSelected = mxVS_TRANSITION_ICONS->IsNoSelection() || mxVS_TRANSITION_ICONS->GetSelectedItemId() == nNoneId; + OUString sSelectedId = mxTransitionsIconView->get_selected_id(); + auto* pTransitionEntry = weld::fromId<TransitionEntry*>(sSelectedId); + if (!pTransitionEntry) + return aResult; + + const sd::TransitionPresetList& rPresetList = sd::TransitionPreset::getTransitionPresetList(); - // check first (aResult might be overwritten) - if( mxVS_TRANSITION_ICONSWin->get_sensitive() && - !bNoneSelected && - mxVS_TRANSITION_ICONS->GetSelectedItemId() > 0 ) + if (pTransitionEntry->mpPreset) { - const sd::TransitionPresetList& rPresetList = sd::TransitionPreset::getTransitionPresetList(); - auto aSelected = rPresetList.begin(); - std::advance( aSelected, mxVS_TRANSITION_ICONS->GetSelectedItemId() - 1); + auto pSelectedPreset = pTransitionEntry->mpPreset; if (mxLB_VARIANT->get_active() == -1) { // Transition with just one effect. - aResult = impl::TransitionEffect( **aSelected ); + aResult = impl::TransitionEffect(*pSelectedPreset); aResult.setAllAmbiguous(); } else { int nVariant = 0; bool bFound = false; - for( const auto& aIter: rPresetList ) + for(const auto& rPreset: rPresetList) { - if( aIter->getSetId() == (*aSelected)->getSetId() ) + if (rPreset->getSetId() == pSelectedPreset->getSetId() ) { if( mxLB_VARIANT->get_active() == nVariant) { - aResult = impl::TransitionEffect( *aIter ); + aResult = impl::TransitionEffect(*rPreset); aResult.setAllAmbiguous(); bFound = true; break; @@ -799,7 +760,7 @@ impl::TransitionEffect SlideTransitionPane::getTransitionEffectFromControls() co } aResult.mbEffectAmbiguous = false; } - else if (bNoneSelected) + else { aResult.mbEffectAmbiguous = false; } @@ -995,53 +956,45 @@ IMPL_LINK_NOARG(SlideTransitionPane, PlayButtonClicked, weld::Button&, void) playCurrentEffect(); } -IMPL_LINK_NOARG(SlideTransitionPane, TransitionSelected, ValueSet*, void) +IMPL_LINK_NOARG(SlideTransitionPane, TransitionSelected, weld::IconView&, bool) { - updateVariants( mxVS_TRANSITION_ICONS->GetSelectedItemId() - 1 ); + OUString sSelectedId = mxTransitionsIconView->get_selected_id(); + auto* pTransitionEntry = weld::fromId<TransitionEntry*>(sSelectedId); + updateVariants(pTransitionEntry->mpPreset); applyToSelectedPages(); + return true; } /// we use an integer offset into the list of transition presets -void SlideTransitionPane::updateVariants( size_t nPresetOffset ) +void SlideTransitionPane::updateVariants(TransitionPresetPtr const& pPreset) { - const sd::TransitionPresetList& rPresetList = sd::TransitionPreset::getTransitionPresetList(); mxLB_VARIANT->clear(); - mxVS_TRANSITION_ICONS->SelectItem(nNoneId); + mxLB_VARIANT->set_sensitive(false); + mxLB_VARIANT->set_active(0); - if( nPresetOffset >= rPresetList.size() ) + if (!pPreset) { - mxLB_VARIANT->set_sensitive( false ); + mxTransitionsIconView->select(0); } else { - auto pFound = rPresetList.begin(); - std::advance( pFound, nPresetOffset ); - - // Fill in the variant listbox - size_t nFirstItem = 0, nItem = 1; - for( const auto& aIt: rPresetList ) + auto iterator = maTranstionMap.find(pPreset->getSetId()); + if (iterator != maTranstionMap.end()) { - if( aIt->getSetId() == (*pFound)->getSetId() ) + auto& pTransitionEntry = iterator->second; + if (!pTransitionEntry->mnVariants.empty()) { - if (!nFirstItem) - nFirstItem = nItem; - if( !aIt->getVariantLabel().isEmpty() ) + for (OUString const& rCurrentVariant : pTransitionEntry->mnVariants) { - mxLB_VARIANT->append_text( aIt->getVariantLabel() ); - if( *pFound == aIt ) - mxLB_VARIANT->set_active( mxLB_VARIANT->get_count()-1 ); + mxLB_VARIANT->append_text(rCurrentVariant); + if (pPreset->getVariantLabel() == rCurrentVariant) + mxLB_VARIANT->set_active(mxLB_VARIANT->get_count() - 1); } + mxLB_VARIANT->set_sensitive(true); } - nItem++; - } - - if( mxLB_VARIANT->get_count() == 0 ) - mxLB_VARIANT->set_sensitive( false ); - else - mxLB_VARIANT->set_sensitive(true); - // item has the id of the first transition from this set. - mxVS_TRANSITION_ICONS->SelectItem( nFirstItem ); + mxTransitionsIconView->select(pTransitionEntry->mnIndex); + } } } @@ -1102,47 +1055,51 @@ IMPL_LINK_NOARG(SlideTransitionPane, AutoPreviewClicked, weld::Toggleable&, void IMPL_LINK_NOARG(SlideTransitionPane, LateInitCallback, Timer *, void) { - const TransitionPresetList& rPresetList = TransitionPreset::getTransitionPresetList(); + mxTransitionsIconView->freeze(); - size_t nPresetOffset = 0; - for( const TransitionPresetPtr& pPreset: rPresetList ) { - const OUString sLabel( pPreset->getSetLabel() ); - if( !sLabel.isEmpty() ) + auto pTransition = std::make_unique<TransitionEntry>(); + const OUString aId = weld::toId(pTransition.get()); + pTransition->msIcon = u"sd/cmd/transition-none.png"_ustr; + pTransition->msLabel = SdResId(STR_SLIDETRANSITION_NONE); + pTransition->mnIndex = 0; + mxTransitionsIconView->append(aId, pTransition->msLabel, pTransition->msIcon); + maTranstionMap.emplace(u"None"_ustr, std::move(pTransition)); + } + + const TransitionPresetList& rPresetList = TransitionPreset::getTransitionPresetList(); + size_t nIndex = 1; + for (TransitionPresetPtr const& pPreset: rPresetList) + { + const OUString aLabel = pPreset->getSetLabel(); + if (!aLabel.isEmpty()) { - if( m_aNumVariants.find( pPreset->getSetId() ) == m_aNumVariants.end() ) + auto aIterator = maTranstionMap.find(pPreset->getSetId()); + if (aIterator == maTranstionMap.end()) { - OUString sImageName("sd/cmd/transition-" + pPreset->getSetId() + ".png"); - BitmapEx aIcon( sImageName ); - if ( aIcon.IsEmpty() ) // need a fallback - sImageName = "sd/cmd/transition-none.png"; - - mxVS_TRANSITION_ICONS->InsertItem( - nPresetOffset + 1, Image(StockImage::Yes, sImageName), sLabel, - VALUESET_APPEND, /* show legend */ true ); - - m_aNumVariants[ pPreset->getSetId() ] = 1; + auto pTransition = std::make_unique<TransitionEntry>(); + const OUString aId = weld::toId(pTransition.get()); + + pTransition->msIcon = u"sd/cmd/transition-"_ustr + pPreset->getSetId() + u".png"_ustr; + pTransition->msLabel = aLabel; + pTransition->mpPreset = pPreset; + if (!pPreset->getVariantLabel().isEmpty()) + pTransition->mnVariants.push_back(pPreset->getVariantLabel()); + pTransition->mnIndex = nIndex; + nIndex++; + + mxTransitionsIconView->append(aId, pTransition->msLabel, pTransition->msIcon); + maTranstionMap.emplace(pPreset->getSetId(), std::move(pTransition)); } else { - m_aNumVariants[ pPreset->getSetId() ]++; + auto& pTransition = aIterator->second; + pTransition->mnVariants.push_back(pPreset->getVariantLabel()); } } - nPresetOffset++; - } - mxVS_TRANSITION_ICONS->Recalculate(); - - SAL_INFO( "sd.transitions", "Item transition offsets in ValueSet:"); - for( size_t i = 0; i < mxVS_TRANSITION_ICONS->GetItemCount(); ++i ) - SAL_INFO( "sd.transitions", i << ":" << mxVS_TRANSITION_ICONS->GetItemId( i ) ); - - nPresetOffset = 0; - SAL_INFO( "sd.transitions", "Transition presets by offsets:"); - for( const auto& aIter: rPresetList ) - { - SAL_INFO( "sd.transitions", nPresetOffset++ << " " << - aIter->getPresetId() << ": " << aIter->getSetId() ); } + mxTransitionsIconView->set_size_request(0, 0); + mxTransitionsIconView->thaw(); updateSoundList(); updateControls(); diff --git a/sd/source/ui/inc/SlideTransitionPane.hxx b/sd/source/ui/inc/SlideTransitionPane.hxx index 2672bfa630ef..ed5c84486486 100644 --- a/sd/source/ui/inc/SlideTransitionPane.hxx +++ b/sd/source/ui/inc/SlideTransitionPane.hxx @@ -36,8 +36,7 @@ namespace sd::tools { class EventMultiplexerEvent; } namespace sd { - -class TransitionPane; +class TransitionPreset; class ViewShellBase; namespace impl @@ -45,6 +44,15 @@ namespace impl struct TransitionEffect; } +struct TransitionEntry +{ + OUString msIcon; + OUString msLabel; + size_t mnIndex = 0; + std::vector<OUString> mnVariants; + std::shared_ptr<TransitionPreset> mpPreset; +}; + class SlideTransitionPane final : public PanelLayout , public sfx2::sidebar::ILayoutableWindow { @@ -63,7 +71,7 @@ public: private: void updateControls(); void updateControlState(); - void updateVariants(size_t nPresetOffset); + void updateVariants(std::shared_ptr<TransitionPreset> const& pPreset); void updateSoundList(); void openSoundFileDialog(); @@ -84,7 +92,7 @@ private: DECL_LINK( PlayButtonClicked, weld::Button&, void ); DECL_LINK( AutoPreviewClicked, weld::Toggleable&, void ); - DECL_LINK( TransitionSelected, ValueSet*, void ); + DECL_LINK( TransitionSelected, weld::IconView&, bool ); DECL_LINK( AdvanceSlideRadioButtonToggled, weld::Toggleable&, void ); DECL_LINK( AdvanceTimeModified, weld::MetricSpinButton&, void ); DECL_LINK( VariantListBoxSelected, weld::ComboBox&, void ); @@ -98,8 +106,8 @@ private: ViewShellBase & mrBase; SdDrawDocument * mpDrawDoc; - std::unique_ptr<TransitionPane> mxVS_TRANSITION_ICONS; - std::unique_ptr<weld::CustomWeld> mxVS_TRANSITION_ICONSWin; + std::unique_ptr<weld::IconView> mxTransitionsIconView; + std::unique_ptr<weld::ScrolledWindow> mxTransitionsScrollWindow; std::unique_ptr<weld::ComboBox> mxLB_VARIANT; std::unique_ptr<weld::MetricSpinButton> mxCBX_duration; std::unique_ptr<weld::Label> mxFT_SOUND; @@ -115,6 +123,8 @@ private: css::uno::Reference< css::drawing::XDrawView > mxView; css::uno::Reference< css::frame::XModel > mxModel; + std::unordered_map<OUString, std::unique_ptr<TransitionEntry>> maTranstionMap; + bool mbHasSelection; bool mbUpdatingControls; bool mbIsMainViewChangePending; diff --git a/sd/uiconfig/simpress/ui/slidetransitionspanel.ui b/sd/uiconfig/simpress/ui/slidetransitionspanel.ui index 6f0c01465637..73916f1fb947 100644 --- a/sd/uiconfig/simpress/ui/slidetransitionspanel.ui +++ b/sd/uiconfig/simpress/ui/slidetransitionspanel.ui @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.38.2 --> +<!-- Generated with glade 3.40.0 --> <interface domain="sd"> <requires lib="gtk+" version="3.20"/> <object class="GtkAdjustment" id="adjustment1"> @@ -17,6 +17,16 @@ <property name="can-focus">False</property> <property name="icon-name">sd/res/playblue_16.png</property> </object> + <object class="GtkTreeStore" id="liststore1"> + <columns> + <!-- column-name expander --> + <column type="GdkPixbuf"/> + <!-- column-name text --> + <column type="gchararray"/> + <!-- column-name id --> + <column type="gchararray"/> + </columns> + </object> <object class="GtkBox" id="SlideTransitionsPanel"> <property name="visible">True</property> <property name="can-focus">False</property> @@ -31,44 +41,32 @@ <property name="orientation">vertical</property> <property name="spacing">12</property> <child> - <object class="GtkBox" id="box4"> + <object class="GtkScrolledWindow" id="transitions_icons_scrolled_window"> <property name="visible">True</property> - <property name="can-focus">False</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> <property name="vexpand">True</property> + <property name="hscrollbar-policy">never</property> + <property name="shadow-type">in</property> <child> - <object class="GtkScrolledWindow" id="transitions_iconswin"> + <object class="GtkIconView" id="transitions_icons"> <property name="visible">True</property> <property name="can-focus">True</property> + <property name="margin">6</property> <property name="hexpand">True</property> <property name="vexpand">True</property> - <property name="hscrollbar-policy">never</property> - <property name="shadow-type">in</property> - <child> - <object class="GtkViewport"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <child> - <object class="GtkDrawingArea" id="transitions_icons"> - <property name="visible">True</property> - <property name="can-focus">True</property> - <property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK</property> - <property name="hexpand">True</property> - <property name="vexpand">True</property> - <child internal-child="accessible"> - <object class="AtkObject" id="transitions_icons-atkobject"> - <property name="AtkObject::accessible-description" translatable="yes" context="slidetransitionspanel|extended_tip|transitions_icons">Select the slide transition you want to use for the selected slides.</property> - </object> - </child> - </object> - </child> + <property name="model">liststore1</property> + <property name="pixbuf-column">0</property> + <property name="text-column">1</property> + <property name="item-width">55</property> + <property name="tooltip-column">1</property> + <property name="activate-on-single-click">True</property> + <child internal-child="accessible"> + <object class="AtkObject" id="transitions_icons-atkobject"> + <property name="AtkObject::accessible-description" translatable="yes" context="slidetransitionspanel|extended_tip|transitions_icons">Select the slide transition you want to use for the selected slides.</property> </object> </child> </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> </child> </object> <packing>