Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / dialog / measctrl.cxx
blob9539d2f68c4662ac1fc8c002f9c73184ad727475
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <sfx2/dialoghelper.hxx>
21 #include <svx/svdomeas.hxx>
22 #include <svx/svdmodel.hxx>
23 #include <svx/measctrl.hxx>
24 #include <svx/dlgutil.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/settings.hxx>
27 #include <vcl/svapp.hxx>
28 #include <memory>
30 SvxXMeasurePreview::SvxXMeasurePreview()
31 : m_aMapMode(MapUnit::Map100thMM)
33 // Scale: 1:2
34 m_aMapMode.SetScaleX(Fraction(1, 2));
35 m_aMapMode.SetScaleY(Fraction(1, 2));
38 void SvxXMeasurePreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
40 CustomWidgetController::SetDrawingArea(pDrawingArea);
41 Size aSize(getPreviewStripSize(pDrawingArea->get_ref_device()));
42 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
44 pModel.reset(new SdrModel(nullptr, nullptr, true));
45 pMeasureObj = new SdrMeasureObj(*pModel, Point(), Point());
47 ResizeImpl(aSize);
48 Invalidate();
51 void SvxXMeasurePreview::ResizeImpl(const Size& rSize)
53 OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
54 rRefDevice.Push(vcl::PushFlags::MAPMODE);
56 rRefDevice.SetMapMode(m_aMapMode);
58 Size aSize = rRefDevice.PixelToLogic(rSize);
59 Point aPt1(aSize.Width() / 5, static_cast<tools::Long>(aSize.Height() / 2));
60 pMeasureObj->SetPoint(aPt1, 0);
61 Point aPt2(aSize.Width() * 4 / 5, static_cast<tools::Long>(aSize.Height() / 2));
62 pMeasureObj->SetPoint(aPt2, 1);
64 rRefDevice.Pop();
67 void SvxXMeasurePreview::Resize()
69 CustomWidgetController::Resize();
70 ResizeImpl(GetOutputSizePixel());
71 Invalidate();
74 SvxXMeasurePreview::~SvxXMeasurePreview() {}
76 void SvxXMeasurePreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
78 rRenderContext.SetBackground(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
79 rRenderContext.Erase();
81 rRenderContext.Push(vcl::PushFlags::MAPMODE);
82 rRenderContext.SetMapMode(m_aMapMode);
84 bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
85 rRenderContext.SetDrawMode(bHighContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
86 pMeasureObj->SingleObjectPainter(rRenderContext);
88 rRenderContext.Pop();
91 void SvxXMeasurePreview::SetAttributes(const SfxItemSet& rInAttrs)
93 pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
95 Invalidate();
98 bool SvxXMeasurePreview::MouseButtonDown(const MouseEvent& rMEvt)
100 bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
101 bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
102 bool bCtrl = rMEvt.IsMod1();
104 if (bZoomIn || bZoomOut)
106 Fraction aXFrac = m_aMapMode.GetScaleX();
107 Fraction aYFrac = m_aMapMode.GetScaleY();
108 std::unique_ptr<Fraction> pMultFrac;
110 if (bZoomIn)
112 if (bCtrl)
113 pMultFrac.reset(new Fraction(3, 2));
114 else
115 pMultFrac.reset(new Fraction(11, 10));
117 else
119 if (bCtrl)
120 pMultFrac.reset(new Fraction(2, 3));
121 else
122 pMultFrac.reset(new Fraction(10, 11));
125 aXFrac *= *pMultFrac;
126 aYFrac *= *pMultFrac;
128 if (double(aXFrac) > 0.001 && double(aXFrac) < 1000.0 && double(aYFrac) > 0.001
129 && double(aYFrac) < 1000.0)
131 m_aMapMode.SetScaleX(aXFrac);
132 m_aMapMode.SetScaleY(aYFrac);
134 OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
135 rRefDevice.Push(vcl::PushFlags::MAPMODE);
136 rRefDevice.SetMapMode(m_aMapMode);
137 Size aOutSize(rRefDevice.PixelToLogic(GetOutputSizePixel()));
138 rRefDevice.Pop();
140 Point aPt(m_aMapMode.GetOrigin());
141 tools::Long nX = tools::Long(
142 (double(aOutSize.Width()) - (double(aOutSize.Width()) * double(*pMultFrac))) / 2.0
143 + 0.5);
144 tools::Long nY = tools::Long(
145 (double(aOutSize.Height()) - (double(aOutSize.Height()) * double(*pMultFrac))) / 2.0
146 + 0.5);
147 aPt.AdjustX(nX);
148 aPt.AdjustY(nY);
150 m_aMapMode.SetOrigin(aPt);
152 Invalidate();
156 return true;
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */