diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-01-22 16:01:03 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-01-23 13:38:40 +0100 |
commit | 07b26af18d45ad7ecacc30c2c4cb2c23033e9f2d (patch) | |
tree | 3b5c8aec2e07225524b70d15ce28c1564ffbd48d /svx | |
parent | 6cece4bf4147fb1cedd7011b3487fd64ff6dbeba (diff) |
make the graphic filter dialogs async
Change-Id: I49a1ff800c6b5fcee69e160158a089659d288bdc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162422
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/dialog/grfflt.cxx | 383 |
1 files changed, 203 insertions, 180 deletions
diff --git a/svx/source/dialog/grfflt.cxx b/svx/source/dialog/grfflt.cxx index 81b9289009dd..562e0d52c990 100644 --- a/svx/source/dialog/grfflt.cxx +++ b/svx/source/dialog/grfflt.cxx @@ -33,224 +33,247 @@ #include <svx/svxdlg.hxx> -SvxGraphicFilterResult SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest const & rReq, GraphicObject& rFilterObject ) +static void handleGraphicFilterDialog(const VclPtr<AbstractGraphicFilterDialog>& pDlg, + const Graphic& aInputGraphic, + std::function<void(GraphicObject)> f); + +void SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest const & rReq, + const GraphicObject& rInputObject, + std::function<void(GraphicObject)> f) { - const Graphic& rGraphic = rFilterObject.GetGraphic(); - SvxGraphicFilterResult nRet = SvxGraphicFilterResult::UnsupportedGraphicType; + Graphic aInputGraphic = rInputObject.GetGraphic(); - if( rGraphic.GetType() == GraphicType::Bitmap ) - { - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : nullptr; - weld::Window* pFrameWeld = (pViewFrame && pViewFrame->GetViewShell()) ? pViewFrame->GetViewShell()->GetFrameWeld() : nullptr; - Graphic aGraphic; + if( aInputGraphic.GetType() != GraphicType::Bitmap ) + return; + + SfxViewFrame* pViewFrame = SfxViewFrame::Current(); + SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : nullptr; + weld::Window* pFrameWeld = (pViewFrame && pViewFrame->GetViewShell()) ? pViewFrame->GetViewShell()->GetFrameWeld() : nullptr; - switch( rReq.GetSlot() ) + switch( rReq.GetSlot() ) + { + case SID_GRFFILTER_INVERT: { - case SID_GRFFILTER_INVERT: - { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if( aAnimation.Invert() ) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if( aBmpEx.Invert() ) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); - } - break; + Graphic aOutputGraphic; - case SID_GRFFILTER_SMOOTH: - { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSmooth(pFrameWeld, rGraphic, 0.7)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + if( pShell ) + pShell->SetWaitCursor( true ); - case SID_GRFFILTER_SHARPEN: + if( aInputGraphic.IsAnimated() ) { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapSharpenFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapSharpenFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_REMOVENOISE: - { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapMedianFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapMedianFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); + if( aAnimation.Invert() ) + aOutputGraphic = aAnimation; } - break; - - case SID_GRFFILTER_SOBEL: + else { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapSobelGreyFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapSobelGreyFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if( aBmpEx.Invert() ) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER_MOSAIC: + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_SMOOTH: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterSmooth(pFrameWeld, aInputGraphic, 0.7), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_SHARPEN: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterMosaic(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_EMBOSS: + if (BitmapFilter::Filter(aAnimation, BitmapSharpenFilter())) + aOutputGraphic = aAnimation; + } + else { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterEmboss(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapSharpenFilter())) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER_POSTER: + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_REMOVENOISE: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterPoster(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_POPART: + if (BitmapFilter::Filter(aAnimation, BitmapMedianFilter())) + aOutputGraphic = aAnimation; + } + else { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapPopArtFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapPopArtFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapMedianFilter())) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER_SEPIA: + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_SOBEL: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSepia(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_SOLARIZE: + if (BitmapFilter::Filter(aAnimation, BitmapSobelGreyFilter())) + aOutputGraphic = aAnimation; + } + else { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSolarize(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapSobelGreyFilter())) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER : + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_MOSAIC: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterMosaic(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_EMBOSS: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterEmboss(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_POSTER: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterPoster(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_POPART: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - // do nothing; no error - nRet = SvxGraphicFilterResult::NONE; - break; - } + Animation aAnimation( aInputGraphic.GetAnimation() ); - default: + if (BitmapFilter::Filter(aAnimation, BitmapPopArtFilter())) + aOutputGraphic = aAnimation; + } + else { - OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" ); - nRet = SvxGraphicFilterResult::UnsupportedSlot; + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapPopArtFilter())) + aOutputGraphic = aBmpEx; } - break; + + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); } + break; - if( aGraphic.GetType() != GraphicType::NONE ) + case SID_GRFFILTER_SEPIA: { - rFilterObject.SetGraphic( aGraphic ); - nRet = SvxGraphicFilterResult::NONE; + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterSepia(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_SOLARIZE: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterSolarize(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER : + { + // do nothing; no error + return; } - } - return nRet; + default: + { + OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" ); + return; + } + } } +static void handleGraphicFilterDialog(const VclPtr<AbstractGraphicFilterDialog>& pDlg, + const Graphic& aInputGraphic, + std::function<void(GraphicObject)> f) +{ + pDlg->StartExecuteAsync( + [pDlg, aInputGraphic, f] (sal_Int32 nResult)->void + { + if (nResult == RET_OK) + { + Graphic aOutputGraphic = pDlg->GetFilteredGraphic( aInputGraphic, 1.0, 1.0 ); + f(aOutputGraphic); + } + pDlg->disposeOnce(); + } + ); +} void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet ) { |