import * as React from "react"; import {ReportItemBaseDesigner} from "./ReportItemBaseDesigner"; import {ReportItem} from "../../items/ReportItem"; import {RectF, RectUnit, Unit} from "../../drawing/Unit"; import {SelectionRules, ItemSelectionType} from "../behavior/Enums"; import {SnapLine, SnapLineType, SnapLinePriority} from "../behavior/SnapLine"; import {Glyph} from "../behavior/Glyph"; import {ItemLocationGlyph} from "../behavior/ItemLocationGlyph"; const Konva = require('konva'); export abstract class ReportItemDesigner extends ReportItemBaseDesigner { get reportItem(): ReportItem { return this.item as ReportItem; } get bounds():RectUnit { return this.reportItem.bounds; } get selectionRules():SelectionRules { let rules = super['selectionRules']; rules |= (SelectionRules.Moveable | SelectionRules.AllSizeable); return rules; } protected getSnapLines(): Array { const snapLines:Array = super.getSnapLines(); if (! this.isTableCell()) { const bounds = this.getBounds(); // MarginsU margins = this.Item.Margins; const zoom = this.behaviorService.zoom; const margins = { Left: Unit.Zero, Top: Unit.Zero, Right: Unit.Zero, Bottom: Unit.Zero, }; snapLines.push(new SnapLine(SnapLineType.Top, bounds.top, SnapLinePriority.Low)); snapLines.push(new SnapLine(SnapLineType.Bottom, bounds.bottom, SnapLinePriority.Low)); snapLines.push(new SnapLine(SnapLineType.HorizontalMiddle, bounds.top + bounds.height / 2.0, SnapLinePriority.Low, SnapLine.MiddleHorizontal)); snapLines.push(new SnapLine(SnapLineType.Left, bounds.left, SnapLinePriority.Low)); snapLines.push(new SnapLine(SnapLineType.Right, bounds.right, SnapLinePriority.Low)); snapLines.push(new SnapLine(SnapLineType.VerticalMiddle, bounds.left + bounds.width / 2.0, SnapLinePriority.Low, SnapLine.MiddleVertical)); snapLines.push(new SnapLine(SnapLineType.Horizontal, bounds.top - zoom * margins.Top.fPixels, SnapLinePriority.Always, "Margin.Top")); snapLines.push(new SnapLine(SnapLineType.Horizontal, bounds.bottom + zoom * margins.Bottom.fPixels, SnapLinePriority.Always, "Margin.Bottom")); snapLines.push(new SnapLine(SnapLineType.Vertical, bounds.left - zoom * margins.Left.fPixels, SnapLinePriority.Always, "Margin.Left")); snapLines.push(new SnapLine(SnapLineType.Vertical, bounds.right + zoom * margins.Right.fPixels, SnapLinePriority.Always, "Margin.Right")); } return snapLines; } getItemDimensionGlyphs(selType:ItemSelectionType):Array { const baseGlyphs = super.getItemDimensionGlyphs(selType); if (selType == ItemSelectionType.PrimarySelection) { const glyphs = []; if (! this.isTableCell() && this.behaviorService.showDimensions) { this.addDimensionGlyphs(glyphs); } if (baseGlyphs) { baseGlyphs.forEach(g => glyphs.push(g)); } return glyphs; } return baseGlyphs; } private addDimensionGlyphs(glyphs:Array):void { const parentDesigner = this.host.getDesigner(this.item.parent) as ReportItemBaseDesigner; const parentBounds = parentDesigner.getBounds(); const bounds = this.getBounds(); const itemBounds = this.bounds; if (bounds.left - parentBounds.left < parentBounds.width / 2) { const y1 = bounds.top + bounds.height / 2; glyphs.push(new ItemLocationGlyph(parentBounds.left , y1 , bounds.left , y1 , itemBounds.left , SnapLineType.Left)); } if (parentBounds.right - bounds.right < parentBounds.width / 2) { const rc = parentDesigner.bounds; const parentRight = rc.width; const itemRight = itemBounds.left.add(itemBounds.width); const y1 = bounds.top + bounds.height / 2; glyphs.push(new ItemLocationGlyph(parentBounds.right , y1 , bounds.right , y1 , (parentRight.subtract(itemRight)).changeType(itemBounds.left.type) , SnapLineType.Right)); } if (bounds.top - parentBounds.top < parentBounds.height / 2) { const x1 = bounds.left + bounds.width / 2; glyphs.push(new ItemLocationGlyph(x1 , parentBounds.top , x1 , bounds.top , itemBounds.top , SnapLineType.Top)); } if (parentBounds.bottom - bounds.bottom < parentBounds.height / 2) { const rc = parentDesigner.bounds; const parentBottom = rc.height; const itemBottom = itemBounds.top.add(itemBounds.height); const x1 = bounds.left + bounds.width / 2; glyphs.push(new ItemLocationGlyph(x1 , parentBounds.bottom , x1 , bounds.bottom , (parentBottom.subtract(itemBottom)).changeType(itemBounds.top.type) , SnapLineType.Bottom)); } } renderBackground(bounds: RectF):any { // let props = { // x: bounds.x, // y: bounds.y, // width: bounds.width, // height: bounds.height, // fill: null, // listening: false, // }; let color = null; const style = this.reportItem.style; if (style.opaque && style.backgroundColor) { color = this.reportItem.style.backgroundColor; } return ReportItemBaseDesigner.drawBackground(bounds, color); } render(bounds:RectF):any{ // const paddingTop = 8; // const paddingLeft = 8; // const paddingRight = 8; // const paddingBottom = 8; // // const clipWidth = bounds.width - paddingLeft - paddingRight; // const clipHeight = bounds.height - paddingTop - paddingBottom; // // const props = { // x: bounds.x, // y: bounds.y, // width: bounds.width, // height: bounds.height, // clipX: paddingLeft, // clipY: paddingTop, // clipWidth: clipWidth, // clipHeight: clipHeight, // listening: false, // }; // // // //更新bounds信息,将自己占用的区域去掉 // bounds.x = bounds.x + paddingLeft; // bounds.y = bounds.y + paddingTop; // bounds.width = bounds.width - paddingLeft - paddingRight; // bounds.height = bounds.height - paddingTop - paddingBottom; // // // const groupNode = new Konva.Group(props); // // return groupNode; } }