1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <vcl/timer.hxx>
23 #include <svx/dlgctrl.hxx>
24 #include <svx/rectenum.hxx>
26 class CuiGraphicPreviewWindow
: public weld::CustomWidgetController
29 const Graphic
* mpOrigGraphic
;
30 Size maOrigGraphicSizePixel
;
31 Size maOutputSizePixel
;
32 Link
<LinkParamNone
*,void> maModifyHdl
;
38 virtual void Paint(vcl::RenderContext
& rRenderContext
, const ::tools::Rectangle
& rRect
) override
;
39 virtual void Resize() override
;
41 void ScaleImageToFit();
44 CuiGraphicPreviewWindow();
45 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
46 void init(const Graphic
* pOrigGraphic
, const Link
<LinkParamNone
*,void>& rLink
)
48 mpOrigGraphic
= pOrigGraphic
;
50 maOrigGraphicSizePixel
= GetDrawingArea()->get_ref_device().LogicToPixel(mpOrigGraphic
->GetPrefSize(),
51 mpOrigGraphic
->GetPrefMapMode());
55 void SetPreview(const Graphic
& rGraphic
);
56 const Graphic
& GetScaledOriginal() const { return maScaledOrig
; }
57 double GetScaleX() const { return mfScaleX
; }
58 double GetScaleY() const { return mfScaleY
; }
59 const Size
& GetGraphicSizePixel() const { return maOrigGraphicSizePixel
; }
62 class GraphicFilterDialog
: public weld::GenericDialogController
67 Link
<LinkParamNone
*,void> maModifyHdl
;
70 DECL_LINK( ImplPreviewTimeoutHdl
, Timer
*, void );
71 DECL_LINK( ImplModifyHdl
, LinkParamNone
*, void);
73 CuiGraphicPreviewWindow maPreview
;
74 std::unique_ptr
<weld::CustomWeld
> mxPreview
;
77 const Link
<LinkParamNone
*,void>& GetModifyHdl() const { return maModifyHdl
; }
78 const Size
& GetGraphicSizePixel() const { return maPreview
.GetGraphicSizePixel(); }
82 GraphicFilterDialog(weld::Window
* pParent
, const OUString
& rUIXMLDescription
, const OUString
& rID
, const Graphic
& rGraphic
);
83 virtual Graphic
GetFilteredGraphic(const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) = 0;
86 class GraphicFilterSmooth
: public GraphicFilterDialog
89 std::unique_ptr
<weld::SpinButton
> mxMtrRadius
;
90 DECL_LINK(EditModifyHdl
, weld::SpinButton
&, void);
94 GraphicFilterSmooth(weld::Window
* pParent
, const Graphic
& rGraphic
, double nRadius
);
95 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
98 class GraphicFilterMosaic
: public GraphicFilterDialog
101 std::unique_ptr
<weld::MetricSpinButton
> mxMtrWidth
;
102 std::unique_ptr
<weld::MetricSpinButton
> mxMtrHeight
;
103 std::unique_ptr
<weld::CheckButton
> mxCbxEdges
;
104 DECL_LINK(CheckBoxModifyHdl
, weld::Toggleable
&, void);
105 DECL_LINK(EditModifyHdl
, weld::MetricSpinButton
&, void);
108 GraphicFilterMosaic(weld::Window
* pParent
, const Graphic
& rGraphic
,
109 sal_uInt16 nTileWidth
, sal_uInt16 nTileHeight
, bool bEnhanceEdges
);
111 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
112 bool IsEnhanceEdges() const { return mxCbxEdges
->get_active(); }
115 class GraphicFilterSolarize
: public GraphicFilterDialog
118 std::unique_ptr
<weld::MetricSpinButton
> mxMtrThreshold
;
119 std::unique_ptr
<weld::CheckButton
> mxCbxInvert
;
120 DECL_LINK(CheckBoxModifyHdl
, weld::Toggleable
&, void);
121 DECL_LINK(EditModifyHdl
, weld::MetricSpinButton
&, void);
124 GraphicFilterSolarize(weld::Window
* pParent
, const Graphic
& rGraphic
,
125 sal_uInt8 nGreyThreshold
, bool bInvert
);
126 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
127 bool IsInvert() const { return mxCbxInvert
->get_active(); }
130 class GraphicFilterSepia
: public GraphicFilterDialog
133 std::unique_ptr
<weld::MetricSpinButton
> mxMtrSepia
;
134 DECL_LINK(EditModifyHdl
, weld::MetricSpinButton
&, void);
136 GraphicFilterSepia(weld::Window
* pParent
, const Graphic
& rGraphic
,
137 sal_uInt16 nSepiaPercent
);
138 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
141 class GraphicFilterPoster
: public GraphicFilterDialog
144 std::unique_ptr
<weld::SpinButton
> mxNumPoster
;
145 DECL_LINK(EditModifyHdl
, weld::SpinButton
&, void);
147 GraphicFilterPoster(weld::Window
* pParent
, const Graphic
& rGraphic
,
148 sal_uInt16 nPosterColorCount
);
149 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
152 class EmbossControl
: public SvxRectCtl
155 Link
<LinkParamNone
*, void> maModifyHdl
;
156 virtual bool MouseButtonDown( const MouseEvent
& rEvt
) override
;
157 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
160 : SvxRectCtl(nullptr)
164 void SetModifyHdl( const Link
<LinkParamNone
*,void>& rHdl
) { maModifyHdl
= rHdl
; }
167 class GraphicFilterEmboss
: public GraphicFilterDialog
170 EmbossControl maCtlLight
;
171 std::unique_ptr
<weld::CustomWeld
> mxCtlLight
;
173 GraphicFilterEmboss(weld::Window
* pParent
, const Graphic
& rGraphic
,
174 RectPoint eLightSource
);
175 virtual ~GraphicFilterEmboss() override
;
177 virtual Graphic
GetFilteredGraphic(const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */