diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-10-07 13:36:56 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-10-07 20:24:04 +0200 |
commit | d46456b07df11bf774c3a7dcbcd843bb97efbe38 (patch) | |
tree | df5be0a3ea649a44aa2e28a4e7d6a2870343380e /cui/source/dialogs | |
parent | 76681af6d846f9b285b4034826722766e47415e2 (diff) |
weld ScreenshotAnnotationDlg
Change-Id: I94e42c1d10922170f53af917bba6848c9f006a11
Reviewed-on: https://gerrit.libreoffice.org/80383
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cui/source/dialogs')
-rw-r--r-- | cui/source/dialogs/screenshotannotationdlg.cxx | 299 |
1 files changed, 149 insertions, 150 deletions
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 <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> #include <comphelper/random.hxx> -#include <vcl/pngwrite.hxx> #include <basegfx/polygon/b2dpolygontools.hxx> #include <tools/stream.hxx> #include <tools/urlobj.hxx> +#include <vcl/customweld.hxx> #include <vcl/event.hxx> -#include <vcl/fixed.hxx> +#include <vcl/pngwrite.hxx> #include <vcl/svapp.hxx> #include <vcl/salgtype.hxx> #include <vcl/virdev.hxx> -#include <vcl/vclmedit.hxx> -#include <vcl/button.hxx> +#include <vcl/weld.hxx> #include <svtools/optionsdrawinglayer.hxx> #include <basegfx/matrix/b2dhommatrix.hxx> #include <set> @@ -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<VirtualDevice> mpVirtualBufferDevice; + VclPtr<VirtualDevice> mxVirtualBufferDevice; // all detected children ControlDataCollection maAllChildren; @@ -178,9 +196,10 @@ private: maSelected; // list of detected controls - VclPtr<FixedImage> mpPicture; - VclPtr<VclMultiLineEdit> mpText; - VclPtr<PushButton> mpSave; + Picture maPicture; + std::unique_ptr<weld::CustomWeld> mxPicture; + std::unique_ptr<weld::TextView> mxText; + std::unique_ptr<weld::Button> 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<VirtualDevice>::Create(*Application::GetDefaultDevice(), DeviceFormat::DEFAULT, DeviceFormat::BITMASK); - mpVirtualBufferDevice->SetOutputSizePixel(maParentDialogSize); - mpVirtualBufferDevice->SetFillColor(COL_TRANSPARENT); + mxVirtualBufferDevice = VclPtr<VirtualDevice>::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<ControlDataEntry*>(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: */ |