LibreOffice Module svx (master)  1
measctrl.cxx
Go to the documentation of this file.
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 #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>
29 
31  : m_aMapMode(MapUnit::Map100thMM)
32 {
33  // Scale: 1:2
36 }
37 
39 {
40  CustomWidgetController::SetDrawingArea(pDrawingArea);
41  Size aSize(getPreviewStripSize(pDrawingArea->get_ref_device()));
42  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
43 
44  pModel.reset(new SdrModel(nullptr, nullptr, true));
45  pMeasureObj.reset(new SdrMeasureObj(*pModel, Point(), Point()));
46 
47  ResizeImpl(aSize);
48  Invalidate();
49 }
50 
52 {
53  OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
54  rRefDevice.Push(PushFlags::MAPMODE);
55 
56  rRefDevice.SetMapMode(m_aMapMode);
57 
58  Size aSize = rRefDevice.PixelToLogic(rSize);
59  Point aPt1(aSize.Width() / 5, static_cast<long>(aSize.Height() / 2));
60  pMeasureObj->SetPoint(aPt1, 0);
61  Point aPt2(aSize.Width() * 4 / 5, static_cast<long>(aSize.Height() / 2));
62  pMeasureObj->SetPoint(aPt2, 1);
63 
64  rRefDevice.Pop();
65 }
66 
68 {
69  CustomWidgetController::Resize();
71  Invalidate();
72 }
73 
75 {
76 }
77 
79 {
80  rRenderContext.SetBackground(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
81  rRenderContext.Erase();
82 
83  rRenderContext.Push(PushFlags::MAPMODE);
84  rRenderContext.SetMapMode(m_aMapMode);
85 
87  rRenderContext.SetDrawMode(bHighContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
88  pMeasureObj->SingleObjectPainter(rRenderContext);
89 
90  rRenderContext.Pop();
91 }
92 
94 {
95  pMeasureObj->SetMergedItemSetAndBroadcast(rInAttrs);
96 
97  Invalidate();
98 }
99 
101 {
102  bool bZoomIn = rMEvt.IsLeft() && !rMEvt.IsShift();
103  bool bZoomOut = rMEvt.IsRight() || rMEvt.IsShift();
104  bool bCtrl = rMEvt.IsMod1();
105 
106  if (bZoomIn || bZoomOut)
107  {
108  Fraction aXFrac = m_aMapMode.GetScaleX();
109  Fraction aYFrac = m_aMapMode.GetScaleY();
110  std::unique_ptr<Fraction> pMultFrac;
111 
112  if (bZoomIn)
113  {
114  if (bCtrl)
115  pMultFrac.reset(new Fraction(3, 2));
116  else
117  pMultFrac.reset(new Fraction(11, 10));
118  }
119  else
120  {
121  if (bCtrl)
122  pMultFrac.reset(new Fraction(2, 3));
123  else
124  pMultFrac.reset(new Fraction(10, 11));
125  }
126 
127  aXFrac *= *pMultFrac;
128  aYFrac *= *pMultFrac;
129 
130  if (double(aXFrac) > 0.001 && double(aXFrac) < 1000.0 &&
131  double(aYFrac) > 0.001 && double(aYFrac) < 1000.0)
132  {
133  m_aMapMode.SetScaleX(aXFrac);
134  m_aMapMode.SetScaleY(aYFrac);
135 
136  OutputDevice& rRefDevice = GetDrawingArea()->get_ref_device();
137  rRefDevice.Push(PushFlags::MAPMODE);
138  rRefDevice.SetMapMode(m_aMapMode);
139  Size aOutSize(rRefDevice.PixelToLogic(GetOutputSizePixel()));
140  rRefDevice.Pop();
141 
142  Point aPt(m_aMapMode.GetOrigin());
143  long nX = long((double(aOutSize.Width()) - (double(aOutSize.Width()) * double(*pMultFrac))) / 2.0 + 0.5);
144  long nY = long((double(aOutSize.Height()) - (double(aOutSize.Height()) * double(*pMultFrac))) / 2.0 + 0.5);
145  aPt.AdjustX(nX );
146  aPt.AdjustY(nY );
147 
148  m_aMapMode.SetOrigin(aPt);
149 
150  Invalidate();
151  }
152  }
153 
154  return true;
155 }
156 
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Fraction & GetScaleX() const
long Width() const
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: measctrl.cxx:78
virtual ~SvxXMeasurePreview() override
Definition: measctrl.cxx:74
long Height() const
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: measctrl.cxx:100
bool IsShift() const
constexpr DrawModeFlags OUTPUT_DRAWMODE_COLOR
Definition: dlgutil.hxx:33
std::unique_ptr< SdrMeasureObj, SdrObjectFreeOp > pMeasureObj
Definition: measctrl.hxx:38
void SetMapMode()
Size const & GetOutputSizePixel() const
void SetDrawMode(DrawModeFlags nDrawMode)
void SetBackground()
const Fraction & GetScaleY() const
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: measctrl.cxx:38
Size getPreviewStripSize(const OutputDevice &rReference)
bool GetHighContrastMode() const
std::unique_ptr< SdrModel > pModel
Definition: measctrl.hxx:37
virtual OutputDevice & get_ref_device()=0
void SetScaleX(const Fraction &rScaleX)
void SetOrigin(const Point &rOrigin)
void SetScaleY(const Fraction &rScaleY)
const AllSettings & GetSettings() const
Point PixelToLogic(const Point &rDevicePt) const
weld::DrawingArea * GetDrawingArea() const
bool IsLeft() const
void ResizeImpl(const Size &rSize)
Definition: measctrl.cxx:51
const Color & GetWindowColor() const
const Point & GetOrigin() const
MapUnit
bool IsRight() const
virtual void Resize() override
Definition: measctrl.cxx:67
void SetAttributes(const SfxItemSet &rInAttrs)
Definition: measctrl.cxx:93
virtual void set_size_request(int nWidth, int nHeight)=0
void Push(PushFlags nFlags=PushFlags::ALL)
MapMode m_aMapMode
Definition: measctrl.hxx:36
constexpr DrawModeFlags OUTPUT_DRAWMODE_CONTRAST
Definition: dlgutil.hxx:34
bool IsMod1() const