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