From d46456b07df11bf774c3a7dcbcd843bb97efbe38 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 7 Oct 2019 13:36:56 +0100 Subject: weld ScreenshotAnnotationDlg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I94e42c1d10922170f53af917bba6848c9f006a11 Reviewed-on: https://gerrit.libreoffice.org/80383 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- cui/source/dialogs/screenshotannotationdlg.cxx | 299 ++++++++++++------------- cui/source/factory/dlgfact.cxx | 10 +- cui/source/factory/dlgfact.hxx | 13 +- cui/source/inc/screenshotannotationdlg.hxx | 5 +- cui/uiconfig/ui/screenshotannotationdialog.ui | 14 +- 5 files changed, 178 insertions(+), 163 deletions(-) (limited to 'cui') diff --git a/cui/source/dialogs/screenshotannotationdlg.cxx b/cui/source/dialogs/screenshotannotationdlg.cxx index fb1f41d29525..f9ed955f2afa 100644 --- a/cui/source/dialogs/screenshotannotationdlg.cxx +++ b/cui/source/dialogs/screenshotannotationdlg.cxx @@ -29,17 +29,16 @@ #include #include -#include #include #include #include +#include #include -#include +#include #include #include #include -#include -#include +#include #include #include #include @@ -128,20 +127,39 @@ private: typedef std::vector< ControlDataEntry > ControlDataCollection; +class Picture : public weld::CustomWidgetController +{ +private: + ScreenshotAnnotationDlg_Impl *m_pDialog; + bool m_bMouseOver; +private: + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override; + virtual bool MouseMove(const MouseEvent& rMouseEvent) override; + virtual bool MouseButtonUp(const MouseEvent& rMouseEvent) override; +public: + Picture(ScreenshotAnnotationDlg_Impl* pDialog) + : m_pDialog(pDialog) + , m_bMouseOver(false) + { + } + + bool IsMouseOver() const + { + return m_bMouseOver; + } +}; + class ScreenshotAnnotationDlg_Impl { public: ScreenshotAnnotationDlg_Impl( - ScreenshotAnnotationDlg& rParent, + weld::Builder& rParent, Dialog& rParentDialog); ~ScreenshotAnnotationDlg_Impl(); private: // Handler for click on save - DECL_LINK(saveButtonHandler, Button*, void); - - // Handler for clicks on picture frame - DECL_LINK(pictureFrameListener, VclWindowEvent&, void); + DECL_LINK(saveButtonHandler, weld::Button&, void); // helper methods void CollectChildren( @@ -167,7 +185,7 @@ private: Size maParentDialogSize; // VirtualDevice for buffered interaction paints - VclPtr mpVirtualBufferDevice; + VclPtr mxVirtualBufferDevice; // all detected children ControlDataCollection maAllChildren; @@ -178,9 +196,10 @@ private: maSelected; // list of detected controls - VclPtr mpPicture; - VclPtr mpText; - VclPtr mpSave; + Picture maPicture; + std::unique_ptr mxPicture; + std::unique_ptr mxText; + std::unique_ptr mxSave; // save as text OUString maSaveAsText; @@ -188,24 +207,26 @@ private: // folder URL static OUString maLastFolderURL; +public: + void Paint(vcl::RenderContext& rRenderContext); + bool MouseMove(const MouseEvent& rMouseEvent); + bool MouseButtonUp(); }; OUString ScreenshotAnnotationDlg_Impl::maLastFolderURL = OUString(); ScreenshotAnnotationDlg_Impl::ScreenshotAnnotationDlg_Impl( - ScreenshotAnnotationDlg& rParent, + weld::Builder& rParent, Dialog& rParentDialog) : mrParentDialog(rParentDialog), maParentDialogBitmap(rParentDialog.createScreenshot()), maDimmedDialogBitmap(maParentDialogBitmap), maParentDialogSize(maParentDialogBitmap.GetSizePixel()), - mpVirtualBufferDevice(nullptr), + mxVirtualBufferDevice(nullptr), maAllChildren(), mpHilighted(nullptr), maSelected(), - mpPicture(nullptr), - mpText(nullptr), - mpSave(nullptr), + maPicture(this), maSaveAsText(CuiResId(RID_SVXSTR_SAVE_SCREENSHOT_AS)) { // image ain't empty @@ -214,15 +235,15 @@ ScreenshotAnnotationDlg_Impl::ScreenshotAnnotationDlg_Impl( assert(0 != maParentDialogBitmap.GetSizePixel().Height()); // get needed widgets - rParent.get(mpPicture, "picture"); - assert(mpPicture.get()); - rParent.get(mpText, "text"); - assert(mpText.get()); - rParent.get(mpSave, "save"); - assert(mpSave.get()); + mxPicture.reset(new weld::CustomWeld(rParent, "picture", maPicture)); + assert(mxPicture.get()); + mxText = rParent.weld_text_view("text"); + assert(mxText.get()); + mxSave = rParent.weld_button("save"); + assert(mxSave.get()); // set screenshot image at FixedImage, resize, set event listener - if (mpPicture) + if (mxPicture) { // collect all children. Choose start pos to be negative // of target dialog's position to get all positions relative to (0,0) @@ -239,44 +260,37 @@ ScreenshotAnnotationDlg_Impl::ScreenshotAnnotationDlg_Impl( maDimmedDialogBitmap.Adjust(-15, 0, 0, 0, 0); // init paint buffering VirtualDevice - mpVirtualBufferDevice = VclPtr::Create(*Application::GetDefaultDevice(), DeviceFormat::DEFAULT, DeviceFormat::BITMASK); - mpVirtualBufferDevice->SetOutputSizePixel(maParentDialogSize); - mpVirtualBufferDevice->SetFillColor(COL_TRANSPARENT); + mxVirtualBufferDevice = VclPtr::Create(*Application::GetDefaultDevice(), DeviceFormat::DEFAULT, DeviceFormat::BITMASK); + mxVirtualBufferDevice->SetOutputSizePixel(maParentDialogSize); + mxVirtualBufferDevice->SetFillColor(COL_TRANSPARENT); // initially set image for picture control - mpPicture->SetImage(Image(maDimmedDialogBitmap)); + mxVirtualBufferDevice->DrawBitmapEx(Point(0, 0), maDimmedDialogBitmap); // set size for picture control, this will re-layout so that // the picture control shows the whole dialog - mpPicture->set_width_request(maParentDialogSize.Width()); - mpPicture->set_height_request(maParentDialogSize.Height()); - - // add local event listener to allow interactions with mouse - mpPicture->AddEventListener(LINK(this, ScreenshotAnnotationDlg_Impl, pictureFrameListener)); + maPicture.SetOutputSizePixel(maParentDialogSize); + mxPicture->set_size_request(maParentDialogSize.Width(), maParentDialogSize.Height()); - // avoid image scaling, this is needed for images smaller than the - // minimal dialog size - const WinBits aWinBits(mpPicture->GetStyle()); - mpPicture->SetStyle(aWinBits & ~WB_SCALE); + mxPicture->queue_draw(); } // set some test text at VclMultiLineEdit and make read-only - only // copying content to clipboard is allowed - if (mpText) + if (mxText) { - mpText->set_width_request(400); - mpText->set_height_request( mpText->GetTextHeight() * 10 ); + mxText->set_size_request(400, mxText->get_height_rows(10)); OUString aHelpId = OStringToOUString( mrParentDialog.GetHelpId(), RTL_TEXTENCODING_UTF8 ); Size aSizeCm = mrParentDialog.PixelToLogic(maParentDialogSize, MapMode(MapUnit::MapCM)); maMainMarkupText = lcl_ParagraphWithImage( aHelpId, aSizeCm ); - mpText->SetText( maMainMarkupText ); - mpText->SetReadOnly(); + mxText->set_text( maMainMarkupText ); + mxText->set_editable(false); } // set click handler for save button - if (mpSave) + if (mxSave) { - mpSave->SetClickHdl(LINK(this, ScreenshotAnnotationDlg_Impl, saveButtonHandler)); + mxSave->connect_clicked(LINK(this, ScreenshotAnnotationDlg_Impl, saveButtonHandler)); } } @@ -311,10 +325,10 @@ void ScreenshotAnnotationDlg_Impl::CollectChildren( ScreenshotAnnotationDlg_Impl::~ScreenshotAnnotationDlg_Impl() { - mpVirtualBufferDevice.disposeAndClear(); + mxVirtualBufferDevice.disposeAndClear(); } -IMPL_LINK_NOARG(ScreenshotAnnotationDlg_Impl, saveButtonHandler, Button*, void) +IMPL_LINK_NOARG(ScreenshotAnnotationDlg_Impl, saveButtonHandler, weld::Button&, void) { // 'save screenshot...' pressed, offer to save maParentDialogBitmap // as PNG image, use *.id file name as screenshot file name offering @@ -388,9 +402,9 @@ IMPL_LINK_NOARG(ScreenshotAnnotationDlg_Impl, saveButtonHandler, Button*, void) // extract Bitmap const BitmapEx aTargetBitmap( - mpVirtualBufferDevice->GetBitmapEx( + mxVirtualBufferDevice->GetBitmapEx( Point(0, 0), - mpVirtualBufferDevice->GetOutputSizePixel())); + mxVirtualBufferDevice->GetOutputSizePixel())); // write as PNG vcl::PNGWriter aPNGWriter(aTargetBitmap); @@ -433,7 +447,7 @@ void ScreenshotAnnotationDlg_Impl::PaintControlDataEntry( double fLineWidth, double fTransparency) { - if (mpPicture && mpVirtualBufferDevice) + if (mxPicture && mxVirtualBufferDevice) { basegfx::B2DRange aB2DRange(rEntry.getB2IRange()); @@ -453,10 +467,10 @@ void ScreenshotAnnotationDlg_Impl::PaintControlDataEntry( fEdgeRoundPixel / aB2DRange.getWidth(), fEdgeRoundPixel / aB2DRange.getHeight())); - mpVirtualBufferDevice->SetLineColor(rColor); + mxVirtualBufferDevice->SetLineColor(rColor); // try to use transparency - if (!mpVirtualBufferDevice->DrawPolyLineDirect( + if (!mxVirtualBufferDevice->DrawPolyLineDirect( basegfx::B2DHomMatrix(), aPolygon, fLineWidth, @@ -464,7 +478,7 @@ void ScreenshotAnnotationDlg_Impl::PaintControlDataEntry( basegfx::B2DLineJoin::Round)) { // no transparency, draw without - mpVirtualBufferDevice->DrawPolyLine( + mxVirtualBufferDevice->DrawPolyLine( aPolygon, fLineWidth); } @@ -473,12 +487,7 @@ void ScreenshotAnnotationDlg_Impl::PaintControlDataEntry( Point ScreenshotAnnotationDlg_Impl::GetOffsetInPicture() const { - if (!mpPicture) - { - return Point(0, 0); - } - - const Size aPixelSizeTarget(mpPicture->GetOutputSizePixel()); + const Size aPixelSizeTarget(maPicture.GetOutputSizePixel()); return Point( aPixelSizeTarget.Width() > maParentDialogSize.Width() ? (aPixelSizeTarget.Width() - maParentDialogSize.Width()) >> 1 : 0, @@ -489,10 +498,10 @@ void ScreenshotAnnotationDlg_Impl::RepaintToBuffer( bool bUseDimmed, bool bPaintHilight) { - if (mpVirtualBufferDevice) + if (mxVirtualBufferDevice) { // reset with original screenshot bitmap - mpVirtualBufferDevice->DrawBitmapEx( + mxVirtualBufferDevice->DrawBitmapEx( Point(0, 0), bUseDimmed ? maDimmedDialogBitmap : maParentDialogBitmap); @@ -501,11 +510,11 @@ void ScreenshotAnnotationDlg_Impl::RepaintToBuffer( const Color aHilightColor(aSvtOptionsDrawinglayer.getHilightColor()); const double fTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01); const bool bIsAntiAliasing(aSvtOptionsDrawinglayer.IsAntiAliasing()); - const AntialiasingFlags nOldAA(mpVirtualBufferDevice->GetAntialiasing()); + const AntialiasingFlags nOldAA(mxVirtualBufferDevice->GetAntialiasing()); if (bIsAntiAliasing) { - mpVirtualBufferDevice->SetAntialiasing(AntialiasingFlags::EnableB2dDraw); + mxVirtualBufferDevice->SetAntialiasing(AntialiasingFlags::EnableB2dDraw); } // paint selected entries @@ -524,129 +533,119 @@ void ScreenshotAnnotationDlg_Impl::RepaintToBuffer( if (bIsAntiAliasing) { - mpVirtualBufferDevice->SetAntialiasing(nOldAA); + mxVirtualBufferDevice->SetAntialiasing(nOldAA); } } } void ScreenshotAnnotationDlg_Impl::RepaintPictureElement() { - if (mpPicture && mpVirtualBufferDevice) + if (mxPicture && mxVirtualBufferDevice) { // reset image in buffer, use dimmed version and allow highlight RepaintToBuffer(true, true); + mxPicture->queue_draw(); + } +} - // copy new content to picture control (hard paint) - mpPicture->DrawOutDev( - GetOffsetInPicture(), - maParentDialogSize, - Point(0, 0), - maParentDialogSize, - *mpVirtualBufferDevice); +void ScreenshotAnnotationDlg_Impl::Paint(vcl::RenderContext& rRenderContext) +{ + Point aPos(GetOffsetInPicture()); + Size aSize(mxVirtualBufferDevice->GetOutputSizePixel()); + rRenderContext.DrawOutDev(aPos, aSize, Point(), aSize, *mxVirtualBufferDevice); +} - // also set image to get repaints right, but trigger no repaint - mpPicture->SetImage( - Image( - mpVirtualBufferDevice->GetBitmapEx( - Point(0, 0), - mpVirtualBufferDevice->GetOutputSizePixel()))); - mpPicture->Validate(); - } +void Picture::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) +{ + m_pDialog->Paint(rRenderContext); } -IMPL_LINK(ScreenshotAnnotationDlg_Impl, pictureFrameListener, VclWindowEvent&, rEvent, void) +bool ScreenshotAnnotationDlg_Impl::MouseMove(const MouseEvent& rMouseEvent) { - // event in picture frame bool bRepaint(false); - switch (rEvent.GetId()) - { - case VclEventId::WindowMouseMove: - case VclEventId::WindowMouseButtonUp: + if (maPicture.IsMouseOver()) { - MouseEvent* pMouseEvent = static_cast< MouseEvent* >(rEvent.GetData()); - - if (pMouseEvent) + const ControlDataEntry* pOldHit = mpHilighted; + const Point aOffset(GetOffsetInPicture()); + const basegfx::B2IPoint aMousePos( + rMouseEvent.GetPosPixel().X() - aOffset.X(), + rMouseEvent.GetPosPixel().Y() - aOffset.Y()); + const ControlDataEntry* pHit = CheckHit(aMousePos); + + if (pHit && pOldHit != pHit) { - switch (rEvent.GetId()) - { - case VclEventId::WindowMouseMove: - { - if (mpPicture->IsMouseOver()) - { - const ControlDataEntry* pOldHit = mpHilighted; - const Point aOffset(GetOffsetInPicture()); - const basegfx::B2IPoint aMousePos( - pMouseEvent->GetPosPixel().X() - aOffset.X(), - pMouseEvent->GetPosPixel().Y() - aOffset.Y()); - const ControlDataEntry* pHit = CheckHit(aMousePos); - - if (pHit && pOldHit != pHit) - { - mpHilighted = const_cast< ControlDataEntry* >(pHit); - bRepaint = true; - } - } - else if (mpHilighted) - { - mpHilighted = nullptr; - bRepaint = true; - } - break; - } - case VclEventId::WindowMouseButtonUp: - { - if (mpPicture->IsMouseOver() && mpHilighted) - { - if (maSelected.erase(mpHilighted) == 0) - { - maSelected.insert(mpHilighted); - } - - OUStringBuffer aBookmarks(maMainMarkupText); - for (auto&& rCandidate : maSelected) - { - OUString aHelpId = OStringToOUString( rCandidate->GetHelpId(), RTL_TEXTENCODING_UTF8 ); - aBookmarks.append(lcl_Bookmark( aHelpId )); - } - - mpText->SetText( aBookmarks.makeStringAndClear() ); - bRepaint = true; - } - break; - } - default: - { - break; - } - } + mpHilighted = const_cast(pHit); + bRepaint = true; } - break; } - default: + else if (mpHilighted) { - break; + mpHilighted = nullptr; + bRepaint = true; } + + if (bRepaint) + { + RepaintPictureElement(); + } + + return true; +} + +bool Picture::MouseMove(const MouseEvent& rMouseEvent) +{ + if (rMouseEvent.IsEnterWindow()) + m_bMouseOver = true; + if (rMouseEvent.IsLeaveWindow()) + m_bMouseOver = false; + return m_pDialog->MouseMove(rMouseEvent); +} + +bool ScreenshotAnnotationDlg_Impl::MouseButtonUp() +{ + // event in picture frame + bool bRepaint(false); + + if (maPicture.IsMouseOver() && mpHilighted) + { + if (maSelected.erase(mpHilighted) == 0) + { + maSelected.insert(mpHilighted); + } + + OUStringBuffer aBookmarks(maMainMarkupText); + for (auto&& rCandidate : maSelected) + { + OUString aHelpId = OStringToOUString( rCandidate->GetHelpId(), RTL_TEXTENCODING_UTF8 ); + aBookmarks.append(lcl_Bookmark( aHelpId )); + } + + mxText->set_text( aBookmarks.makeStringAndClear() ); + bRepaint = true; } if (bRepaint) { RepaintPictureElement(); } + + return true; } -ScreenshotAnnotationDlg::ScreenshotAnnotationDlg( - vcl::Window* pParent, - Dialog& rParentDialog) -: ModalDialog(pParent, "ScreenshotAnnotationDialog", "cui/ui/screenshotannotationdialog.ui") +bool Picture::MouseButtonUp(const MouseEvent&) { - m_pImpl.reset(new ScreenshotAnnotationDlg_Impl(*this, rParentDialog)); + return m_pDialog->MouseButtonUp(); } +ScreenshotAnnotationDlg::ScreenshotAnnotationDlg(weld::Window* pParent, Dialog& rParentDialog) + : GenericDialogController(pParent, "cui/ui/screenshotannotationdialog.ui", "ScreenshotAnnotationDialog") +{ + m_pImpl.reset(new ScreenshotAnnotationDlg_Impl(*m_xBuilder, rParentDialog)); +} ScreenshotAnnotationDlg::~ScreenshotAnnotationDlg() { - disposeOnce(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index 7608d9f8cd3e..0a81690478ca 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -324,7 +324,10 @@ short AbstractQrCodeGenDialog_Impl::Execute() return m_xDlg->run(); } -IMPL_ABSTDLG_BASE(AbstractScreenshotAnnotationDlg_Impl); +short AbstractScreenshotAnnotationDlg_Impl::Execute() +{ + return m_xDlg->run(); +} short CuiAbstractTabController_Impl::Execute() { @@ -1606,11 +1609,10 @@ VclPtr AbstractDialogFactory_Impl::CreatePas } VclPtr AbstractDialogFactory_Impl::CreateScreenshotAnnotationDlg( - vcl::Window * pParent, + weld::Window* pParent, Dialog& rParentDialog) { - VclPtrInstance pDlg(pParent, rParentDialog); - return VclPtr::Create(pDlg); + return VclPtr::Create(std::make_unique(pParent, rParentDialog)); } VclPtr AbstractDialogFactory_Impl::CreateSignatureLineDialog( diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx index dab0e9ae43d0..b3ada6ca80e9 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -679,7 +679,14 @@ public: class ScreenshotAnnotationDlg; class AbstractScreenshotAnnotationDlg_Impl : public AbstractScreenshotAnnotationDlg { - DECL_ABSTDLG_BASE(AbstractScreenshotAnnotationDlg_Impl, ScreenshotAnnotationDlg) + std::unique_ptr m_xDlg; + +public: + explicit AbstractScreenshotAnnotationDlg_Impl(std::unique_ptr p) + : m_xDlg(std::move(p)) + { + } + virtual short Execute() override; }; class SignatureLineDialog; @@ -921,9 +928,9 @@ public: virtual VclPtr CreateSvxInsRowColDlg(weld::Window* pParent, bool bCol, const OString& rHelpId) override; - virtual VclPtr CreatePasswordToOpenModifyDialog(weld::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) override; + virtual VclPtr CreatePasswordToOpenModifyDialog(weld::Window* pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) override; - virtual VclPtr CreateScreenshotAnnotationDlg(vcl::Window * pParent, Dialog& rParentDialog) override; + virtual VclPtr CreateScreenshotAnnotationDlg(weld::Window* pParent, Dialog& rParentDialog) override; virtual VclPtr CreateSignatureLineDialog(weld::Window* pParent, diff --git a/cui/source/inc/screenshotannotationdlg.hxx b/cui/source/inc/screenshotannotationdlg.hxx index ac9e0edc564f..53df8d4f7ea5 100644 --- a/cui/source/inc/screenshotannotationdlg.hxx +++ b/cui/source/inc/screenshotannotationdlg.hxx @@ -20,11 +20,12 @@ #define INCLUDED_CUI_SOURCE_INC_SCREENSHANNDLG_HXX #include +#include #include class ScreenshotAnnotationDlg_Impl; -class ScreenshotAnnotationDlg : public ModalDialog +class ScreenshotAnnotationDlg : public weld::GenericDialogController { private: std::unique_ptr< ScreenshotAnnotationDlg_Impl > m_pImpl; @@ -34,7 +35,7 @@ private: public: ScreenshotAnnotationDlg( - vcl::Window* pParent, + weld::Window* pParent, Dialog& rParentDialog); virtual ~ScreenshotAnnotationDlg() override; }; diff --git a/cui/uiconfig/ui/screenshotannotationdialog.ui b/cui/uiconfig/ui/screenshotannotationdialog.ui index b20a8edbf943..e7e3e78fa3d0 100644 --- a/cui/uiconfig/ui/screenshotannotationdialog.ui +++ b/cui/uiconfig/ui/screenshotannotationdialog.ui @@ -1,5 +1,5 @@ - + @@ -10,6 +10,9 @@ 600 460 normal + + + False @@ -73,11 +76,10 @@ - + image True False - gtk-missing-image True @@ -107,7 +109,7 @@ True in - + True True True @@ -123,5 +125,9 @@ + + cancel + save + -- cgit