1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #pragma once 21 22 #include <vcl/timer.hxx> 23 #include <svx/dlgctrl.hxx> 24 #include <svx/rectenum.hxx> 25 26 class CuiGraphicPreviewWindow : public weld::CustomWidgetController 27 { 28 private: 29 const Graphic* mpOrigGraphic; 30 Size maOrigGraphicSizePixel; 31 Size maOutputSizePixel; 32 Link<LinkParamNone*,void> maModifyHdl; 33 Graphic maScaledOrig; 34 Graphic maPreview; 35 double mfScaleX; 36 double mfScaleY; 37 38 virtual void Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) override; 39 virtual void Resize() override; 40 41 void ScaleImageToFit(); 42 43 public: 44 CuiGraphicPreviewWindow(); 45 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; init(const Graphic * pOrigGraphic,const Link<LinkParamNone *,void> & rLink)46 void init(const Graphic* pOrigGraphic, const Link<LinkParamNone*,void>& rLink) 47 { 48 mpOrigGraphic = pOrigGraphic; 49 maModifyHdl = rLink; 50 maOrigGraphicSizePixel = GetDrawingArea()->get_ref_device().LogicToPixel(mpOrigGraphic->GetPrefSize(), 51 mpOrigGraphic->GetPrefMapMode()); 52 ScaleImageToFit(); 53 } 54 55 void SetPreview(const Graphic& rGraphic); GetScaledOriginal() const56 const Graphic& GetScaledOriginal() const { return maScaledOrig; } GetScaleX() const57 double GetScaleX() const { return mfScaleX; } GetScaleY() const58 double GetScaleY() const { return mfScaleY; } GetGraphicSizePixel() const59 const Size& GetGraphicSizePixel() const { return maOrigGraphicSizePixel; } 60 }; 61 62 class GraphicFilterDialog : public weld::GenericDialogController 63 { 64 private: 65 66 Timer maTimer; 67 Link<LinkParamNone*,void> maModifyHdl; 68 bool bIsBitmap; 69 70 DECL_LINK( ImplPreviewTimeoutHdl, Timer *, void ); 71 DECL_LINK( ImplModifyHdl, LinkParamNone*, void); 72 73 CuiGraphicPreviewWindow maPreview; 74 std::unique_ptr<weld::CustomWeld> mxPreview; 75 76 protected: GetModifyHdl() const77 const Link<LinkParamNone*,void>& GetModifyHdl() const { return maModifyHdl; } GetGraphicSizePixel() const78 const Size& GetGraphicSizePixel() const { return maPreview.GetGraphicSizePixel(); } 79 80 public: 81 82 GraphicFilterDialog(weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID, const Graphic& rGraphic); 83 virtual Graphic GetFilteredGraphic(const Graphic& rGraphic, double fScaleX, double fScaleY) = 0; 84 }; 85 86 class GraphicFilterSmooth : public GraphicFilterDialog 87 { 88 private: 89 std::unique_ptr<weld::SpinButton> mxMtrRadius; 90 DECL_LINK(EditModifyHdl, weld::SpinButton&, void); 91 92 public: 93 94 GraphicFilterSmooth(weld::Window* pParent, const Graphic& rGraphic, double nRadius); 95 virtual Graphic GetFilteredGraphic( const Graphic& rGraphic, double fScaleX, double fScaleY ) override; 96 }; 97 98 class GraphicFilterMosaic : public GraphicFilterDialog 99 { 100 private: 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); 106 public: 107 108 GraphicFilterMosaic(weld::Window* pParent, const Graphic& rGraphic, 109 sal_uInt16 nTileWidth, sal_uInt16 nTileHeight, bool bEnhanceEdges); 110 111 virtual Graphic GetFilteredGraphic( const Graphic& rGraphic, double fScaleX, double fScaleY ) override; IsEnhanceEdges() const112 bool IsEnhanceEdges() const { return mxCbxEdges->get_active(); } 113 }; 114 115 class GraphicFilterSolarize : public GraphicFilterDialog 116 { 117 private: 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); 122 123 public: 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; IsInvert() const127 bool IsInvert() const { return mxCbxInvert->get_active(); } 128 }; 129 130 class GraphicFilterSepia : public GraphicFilterDialog 131 { 132 private: 133 std::unique_ptr<weld::MetricSpinButton> mxMtrSepia; 134 DECL_LINK(EditModifyHdl, weld::MetricSpinButton&, void); 135 public: 136 GraphicFilterSepia(weld::Window* pParent, const Graphic& rGraphic, 137 sal_uInt16 nSepiaPercent); 138 virtual Graphic GetFilteredGraphic( const Graphic& rGraphic, double fScaleX, double fScaleY ) override; 139 }; 140 141 class GraphicFilterPoster : public GraphicFilterDialog 142 { 143 private: 144 std::unique_ptr<weld::SpinButton> mxNumPoster; 145 DECL_LINK(EditModifyHdl, weld::SpinButton&, void); 146 public: 147 GraphicFilterPoster(weld::Window* pParent, const Graphic& rGraphic, 148 sal_uInt16 nPosterColorCount); 149 virtual Graphic GetFilteredGraphic( const Graphic& rGraphic, double fScaleX, double fScaleY ) override; 150 }; 151 152 class EmbossControl : public SvxRectCtl 153 { 154 private: 155 Link<LinkParamNone*, void> maModifyHdl; 156 virtual bool MouseButtonDown( const MouseEvent& rEvt ) override; 157 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; 158 public: EmbossControl()159 EmbossControl() 160 : SvxRectCtl(nullptr) 161 { 162 } 163 SetModifyHdl(const Link<LinkParamNone *,void> & rHdl)164 void SetModifyHdl( const Link<LinkParamNone*,void>& rHdl ) { maModifyHdl = rHdl; } 165 }; 166 167 class GraphicFilterEmboss : public GraphicFilterDialog 168 { 169 private: 170 EmbossControl maCtlLight; 171 std::unique_ptr<weld::CustomWeld> mxCtlLight; 172 public: 173 GraphicFilterEmboss(weld::Window* pParent, const Graphic& rGraphic, 174 RectPoint eLightSource); 175 virtual ~GraphicFilterEmboss() override; 176 177 virtual Graphic GetFilteredGraphic(const Graphic& rGraphic, double fScaleX, double fScaleY) override; 178 }; 179 180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 181