/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// helper to create the geometry for a rounded polygon, maybe // containing a Lap positioned inside top-left for some text
basegfx::B2DPolygon createRoundedPolygon( const basegfx::B2DRange& rRange, double fDistance, bool bCreateLap, double fTextWidth)
{
basegfx::B2DPolygon aRetval;
// helper primitive to create/show the overlay geometry for a DynamicDiagram class OverlayDiagramPrimitive final : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
{ private:
basegfx::B2DHomMatrix maTransformation; // object dimensions double mfDiscreteDistance; // distance from object in pixels double mfDiscreteGap; // gap/width of visualization in pixels
Color maColor; // base color (made lighter/darker as needed, should be system selection color)
drawinglayer::primitive2d::Primitive2DReference OverlayDiagramPrimitive::create2DDecomposition( const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
{ // get the dimensions. Do *not* take rotation/shear into account, // this is intended to be a pure expanded/frame visualization as // needed in UI for simplified visualization
basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0);
aRange.transform(maTransformation);
// initially try to create lap if(bCreateLap)
{ // take a resource text (for now existing one that fits) const OUString aName(SvxResId(RID_STR_DATANAV_EDIT_ELEMENT));
drawinglayer::primitive2d::TextLayouterDevice aTextLayouter;
basegfx::B2DPolyPolygonVector aTarget;
std::vector<double> aDXArray;
// to simplify things for now, do not create a TextSimplePortionPrimitive2D // and needed FontAttribute, just get the TextOutlines as geometry
aTextLayouter.getTextOutlines(
aTarget,
aName,
0,
aName.getLength(),
aDXArray,
{});
// put into one PolyPolygon (also simplification - overlapping chars // may create XOR gaps, so these exist for a reason, but low probability) for (autoconst& elem : aTarget)
{
aTextAsPolyPolygon.append(elem);
}
// get text dimensions & transform to destination const basegfx::B2DRange aTextRange(aTextAsPolyPolygon.getB2DRange());
basegfx::B2DHomMatrix aTextTransform;
// if text is too big, do not create a Lap at all // to avoid trouble. It is expected that the user keeps // the object he works with big enough to do useful actions if(fTextWidth + (4.0 * getDiscreteUnit()) > fLapRight - fLapLeft)
bCreateLap = false;
}
// filled polygon as BG (may get transparence for better look ?)
aContainer.push_back( new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
aPolyPolygon,
aFillColor.getBColor()));
// outline polygon for visibility (may be accentuated shaded // top/left, would require alternative creation)
aContainer.push_back( new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(
std::move(aPolyPolygon),
aLineAttribute));
// top-left line pattern (as grep-here-sign to signal // that this construct may be also dragged by the user) constdouble fLapLeft(aRange.getMinX() + fInnerDistance); constdouble fLapRight(aRange.getMinX() + (aRange.getWidth() * 0.5) - fInnerDistance); constdouble fLapUp(aRange.getMinY() - ((mfDiscreteDistance + mfDiscreteDistance * 0.666) * getDiscreteUnit())); constdouble fLapDown(aRange.getMinY() - ((mfDiscreteDistance + mfDiscreteDistance * 0.333) * getDiscreteUnit()));
basegfx::B2DPolygon aPolygonLapUp;
aPolygonLapUp.append(basegfx::B2DPoint(fLapLeft, fLapUp));
aPolygonLapUp.append(basegfx::B2DPoint(fLapRight, fLapUp));
basegfx::B2DPolygon aPolygonLapDown;
aPolygonLapDown.append(basegfx::B2DPoint(fLapLeft, fLapDown));
aPolygonLapDown.append(basegfx::B2DPoint(fLapRight, fLapDown));
drawinglayer::attribute::StrokeAttribute aStrokeAttribute({ 2.0 * getDiscreteUnit(), 2.0 * getDiscreteUnit() });
aContainer.push_back( new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
std::move(aPolygonLapUp),
aLineAttribute,
aStrokeAttribute));
aContainer.push_back( new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
std::move(aPolygonLapDown),
aLineAttribute,
std::move(aStrokeAttribute)));
// add text last. May use darker text color, go for same color // as accentuation line for now if(bCreateLap && 0 != aTextAsPolyPolygon.count())
{
aContainer.push_back( new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
std::move(aTextAsPolyPolygon),
aLineColor.getBColor()));
} returnnew drawinglayer::primitive2d::GroupPrimitive2D(std::move(aContainer));
}
// helper object for DiagramOverlay class OverlayDiagramFrame final : public sdr::overlay::OverlayObject
{ private:
basegfx::B2DHomMatrix maTransformation; // object dimensions
Color maColor; // base color
if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() ) return aReturnContainer;
if (getOverlayManager())
{
aReturnContainer = drawinglayer::primitive2d::Primitive2DContainer { new OverlayDiagramPrimitive(
maTransformation,
8.0, // distance from geometry in pixels
8.0, // gap/width of visualization in pixels
maColor) };
}
return aReturnContainer;
}
} // end of anonymous namespace
namespace svx { namespace diagram {
void DiagramFrameHdl::clicked(const Point& /*rPnt*/)
{ // this may check for a direct hit at the text later // and only then take action. That would require // to evaluate & keep that (maybe during creation). // For now, just trigger to open the Dialog
comphelper::dispatchCommand(u".uno:EditDiagram"_ustr, {});
}
void DiagramFrameHdl::CreateB2dIAObject()
{ // first throw away old one
GetRidOfIAObject();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.