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 .
20 #ifndef INCLUDED_CUI_SOURCE_INC_CUIGRFFLT_HXX
21 #define INCLUDED_CUI_SOURCE_INC_CUIGRFFLT_HXX
23 #include <tools/helpers.hxx>
24 #include <vcl/GraphicObject.hxx>
25 #include <vcl/timer.hxx>
26 #include <svx/graphctl.hxx>
27 #include <svx/dlgctrl.hxx>
28 #include <svx/rectenum.hxx>
30 class CuiGraphicPreviewWindow
: public weld::CustomWidgetController
33 const Graphic
* mpOrigGraphic
;
34 Size maOrigGraphicSizePixel
;
35 Size maOutputSizePixel
;
36 Link
<LinkParamNone
*,void> maModifyHdl
;
42 virtual void Paint(vcl::RenderContext
& rRenderContext
, const ::tools::Rectangle
& rRect
) override
;
43 virtual void Resize() override
;
45 void ScaleImageToFit();
48 CuiGraphicPreviewWindow();
49 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
50 void init(const Graphic
* pOrigGraphic
, const Link
<LinkParamNone
*,void>& rLink
)
52 mpOrigGraphic
= pOrigGraphic
;
54 maOrigGraphicSizePixel
= GetDrawingArea()->get_ref_device().LogicToPixel(mpOrigGraphic
->GetPrefSize(),
55 mpOrigGraphic
->GetPrefMapMode());
59 void SetPreview(const Graphic
& rGraphic
);
60 const Graphic
& GetScaledOriginal() const { return maScaledOrig
; }
61 double GetScaleX() const { return mfScaleX
; }
62 double GetScaleY() const { return mfScaleY
; }
63 const Size
& GetGraphicSizePixel() const { return maOrigGraphicSizePixel
; }
66 class GraphicFilterDialog
: public weld::GenericDialogController
71 Link
<LinkParamNone
*,void> maModifyHdl
;
74 DECL_LINK( ImplPreviewTimeoutHdl
, Timer
*, void );
75 DECL_LINK( ImplModifyHdl
, LinkParamNone
*, void);
77 CuiGraphicPreviewWindow maPreview
;
78 std::unique_ptr
<weld::CustomWeld
> mxPreview
;
81 const Link
<LinkParamNone
*,void>& GetModifyHdl() const { return maModifyHdl
; }
82 const Size
& GetGraphicSizePixel() const { return maPreview
.GetGraphicSizePixel(); }
86 GraphicFilterDialog(weld::Window
* pParent
, const OUString
& rUIXMLDescription
, const OString
& rID
, const Graphic
& rGraphic
);
87 virtual Graphic
GetFilteredGraphic(const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) = 0;
90 class GraphicFilterSmooth
: public GraphicFilterDialog
93 std::unique_ptr
<weld::SpinButton
> mxMtrRadius
;
94 DECL_LINK(EditModifyHdl
, weld::SpinButton
&, void);
98 GraphicFilterSmooth(weld::Window
* pParent
, const Graphic
& rGraphic
, double nRadius
);
99 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
102 class GraphicFilterMosaic
: public GraphicFilterDialog
105 std::unique_ptr
<weld::MetricSpinButton
> mxMtrWidth
;
106 std::unique_ptr
<weld::MetricSpinButton
> mxMtrHeight
;
107 std::unique_ptr
<weld::CheckButton
> mxCbxEdges
;
108 DECL_LINK(CheckBoxModifyHdl
, weld::ToggleButton
&, void);
109 DECL_LINK(EditModifyHdl
, weld::MetricSpinButton
&, void);
112 GraphicFilterMosaic(weld::Window
* pParent
, const Graphic
& rGraphic
,
113 sal_uInt16 nTileWidth
, sal_uInt16 nTileHeight
, bool bEnhanceEdges
);
115 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
116 bool IsEnhanceEdges() const { return mxCbxEdges
->get_active(); }
119 class GraphicFilterSolarize
: public GraphicFilterDialog
122 std::unique_ptr
<weld::MetricSpinButton
> mxMtrThreshold
;
123 std::unique_ptr
<weld::CheckButton
> mxCbxInvert
;
124 DECL_LINK(CheckBoxModifyHdl
, weld::ToggleButton
&, void);
125 DECL_LINK(EditModifyHdl
, weld::MetricSpinButton
&, void);
128 GraphicFilterSolarize(weld::Window
* pParent
, const Graphic
& rGraphic
,
129 sal_uInt8 nGreyThreshold
, bool bInvert
);
130 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
131 bool IsInvert() const { return mxCbxInvert
->get_active(); }
134 class GraphicFilterSepia
: public GraphicFilterDialog
137 std::unique_ptr
<weld::MetricSpinButton
> mxMtrSepia
;
138 DECL_LINK(EditModifyHdl
, weld::MetricSpinButton
&, void);
140 GraphicFilterSepia(weld::Window
* pParent
, const Graphic
& rGraphic
,
141 sal_uInt16 nSepiaPercent
);
142 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
145 class GraphicFilterPoster
: public GraphicFilterDialog
148 std::unique_ptr
<weld::SpinButton
> mxNumPoster
;
149 DECL_LINK(EditModifyHdl
, weld::SpinButton
&, void);
151 GraphicFilterPoster(weld::Window
* pParent
, const Graphic
& rGraphic
,
152 sal_uInt16 nPosterColorCount
);
153 virtual Graphic
GetFilteredGraphic( const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
156 class EmbossControl
: public SvxRectCtl
159 Link
<LinkParamNone
*, void> maModifyHdl
;
160 virtual bool MouseButtonDown( const MouseEvent
& rEvt
) override
;
161 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
164 : SvxRectCtl(nullptr)
168 void SetModifyHdl( const Link
<LinkParamNone
*,void>& rHdl
) { maModifyHdl
= rHdl
; }
171 class GraphicFilterEmboss
: public GraphicFilterDialog
174 EmbossControl maCtlLight
;
175 std::unique_ptr
<weld::CustomWeld
> mxCtlLight
;
177 GraphicFilterEmboss(weld::Window
* pParent
, const Graphic
& rGraphic
,
178 RectPoint eLightSource
);
179 virtual ~GraphicFilterEmboss() override
;
181 virtual Graphic
GetFilteredGraphic(const Graphic
& rGraphic
, double fScaleX
, double fScaleY
) override
;
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */