当前位置: 首页 > news >正文

3.The Graphics View Coordinate System(图形视图坐标系)

The Graphics View Coordinate System(图形视图坐标系)

--Item Coordinates(对象坐标)

--Scene Coordinates(场景坐标)

--View Coordinates(视图坐标)

--Coordinate Mapping(坐标映射)

3.The Graphics View Coordinate System(图形视图坐标系)

Graphics View is based on the Cartesian coordinate system; items' position and geometry on the scene are represented by sets of two numbers: the x-coordinate, and the y-coordinate. When observing a scene using an untransformed view, one unit on the scene is represented by one pixel on the screen.
图形视图建立在直角坐标系基础上,图形对象的位置和几何形状由两组数据来表示: x坐标和 y坐标。如果使用未变换的视图来观察场景,场景中的一个单元将会表现为屏幕上的一个像素。

Note: The inverted Y-axis coordinate system (where y grows upwards) is unsupported as Graphics Views uses Qt's coordinate system.
注意 :图形视图使用了 Qt的坐标系,不支持反转的 y轴坐标系统(即 y向上为正方向)。

There are three effective coordinate systems in play in Graphics View: Item coordinates, scene coordinates, and view coordinates. To simplify your implementation, Graphics View provides convenience functions that allow you to map between the three coordinate systems.
图形视图使用了三种有效的坐标系:对象坐标,场景坐标和视图坐标。为了简化你的实现工作,图形视图提供了一系列非常方便的函数来进行三个坐标系下的坐标变换。

When rendering, Graphics View's scene coordinates correspond to QPainter's logical coordinates, and view coordinates are the same as device coordinates. In the Coordinate System documentation, you can read about the relationship between logical coordinates and device coordinates.

    绘制的时候,图形视图的场景坐标对应于 QPainter的逻辑坐标,视图坐标与设备坐标保持一致。在 The Coordinate System 文中你可以关于逻辑坐标和设备坐标关系的内容。

3.1Item Coordinates(对象坐标)

Items live in their own local coordinate system. Their coordinates are usually centered around its center point (0, 0), and this is also the center for all transformations. Geometric primitives in the item coordinate system are often referred to as item points, item lines, or item rectangles.
图形对象建立其自身的局部坐标系下。该坐标系通常以中心点(0,0)为中心,同时该中心点也是各种矩阵你变换的中心。对象坐标系下的几何元素通常用点、线或者矩形来表示。

When creating a custom item, item coordinates are all you need to worry about; QGraphicsScene and QGraphicsView will perform all transformations for you. This makes it very easy to implement custom items. For example, if you receive a mouse press or a drag enter event, the event position is given in item coordinates. The QGraphicsItem::contains() virtual function, which returns true if a certain point is inside your item, and false otherwise, takes a point argument in item coordinates. Similarly, an item's bounding rect and shape are in item coordinates.
当创建自定义图形对象的时候,你只需关注对象坐标系即可。 QGraphicsScene 和 QGraphicsView 会执行所有相关的变换,这样一来我们实现自定义对象就容易多了。比如说,当你接受鼠标按下或者拖拽事件的时候,事件位置已经被传递到了对象坐标系下。这个QGraphicsItem::contains()虚函数,当返回只为true的时候,某一点在你的图形对象中,当返回为false时候,把一个点的参数放到对象坐标系中。类似的,对象的包围盒和形状都是基于对象坐标系的。

At item's position is the coordinate of the item's center point in its parent's coordinate system; sometimes referred to as parent coordinates. The scene is in this sense regarded as all parent-less items' "parent". Top level items' position are in scene coordinates.
对象的位置是对象坐标系下的中心点在其父对象坐标系下的位置;有时候被称为父坐标。对于所有没有父对象的对象来说,场景就是其父对象。因此最顶层对象的位置就是其在场景中的位置。

Child coordinates are relative to the parent's coordinates. If the child is untransformed, the difference between a child coordinate and a parent coordinate is the same as the distance between the items in parent coordinates. For example: If an untransformed child item is positioned precisely in its parent's center point, then the two items' coordinate systems will be identical. If the child's position is (10, 0), however, the child's (0, 10) point will correspond to its parent's (10, 10) point.
子对象坐标系是相对于父对象坐标系来说的。如果子节点没有进行矩阵变换,那么在子对象坐标系和父对象坐标系的差异就和这些对象在父对象中的偏移距离一样。比如说,如果一个未经变换的子对象精确的位于父对象的中心点,那么这两个对象的坐标系就是一致的。如果子对象的位置是(10,0),那么子对象的(0,10)点就位于父对象的(10,10)点的位置。

Because items' position and transformation are relative to the parent, child items' coordinates are unaffected by the parent's transformation, although the parent's transformation implicitly transforms the child. In the above example, even if the parent is rotated and scaled, the child's (0, 10) point will still correspond to the parent's (10, 10) point. Relative to the scene, however, the child will follow the parent's transformation and position. If the parent is scaled (2x, 2x), the child's position will be at scene coordinate (20, 0), and its (10, 0) point will correspond to the point (40, 0) on the scene.
由于对象的位置和变换是相对于父对象来说的,因此虽然父对象的变换隐式地变换了子对象,子对象的坐标系不受父对象坐标系改变的影响。在上面的例子中,即使父对象经过了旋转和缩放,子对象的(0,10)点依然相对于父对象是(10,10)点。不过相对于场景来说,子对象将随着父对象进行变换和 偏移 。如果父对象缩放了(2x,2x),那么子对象在场景坐标系下将会位于(20,0)的位置,同时其(10,0)点将会对应于场景中的(40,0)点。

With QGraphicsItem::pos() being one of the few exceptions, QGraphicsItem's functions operate in item coordinates, regardless of the item, or any of its parents' transformation. For example, an item's bounding rect (i.e. QGraphicsItem::boundingRect()) is always given in item coordinates.

不管对象自身或者父对象进行了什么样的变化, QGraphicsItem的函数一般总是表示在对象坐标系下的位置,其操作也作用于对象坐标系内。比如,一个对象的包围盒( QGraphicsItem::boundingRect ())总是在对象坐标系下给出的。但是 QGraphicsItem::pos 是例外之一,该函数表示其在父对象中的位置 。

3.2Scene Coordinates(场景坐标)

The scene represents the base coordinate system for all its items. The scene coordinate system describes the position of each top-level item, and also forms the basis for all scene events delivered to the scene from the view. Each item on the scene has a scene position and bounding rectangle (QGraphicsItem::scenePos(), QGraphicsItem::sceneBoundingRect()), in addition to its local item pos and bounding rectangle. The scene position describes the item's position in scene coordinates, and its scene bounding rect forms the basis for how QGraphicsScene determines what areas of the scene have changed. Changes in the scene are communicated through the QGraphicsScene::changed() signal, and the argument is a list of scene rectangles.
场景表示了其中所有对象的基础坐标系。场景坐标系描述了每一个顶层对象的位置,同时也是所有从视图传递到场景的事件的变化基础。场景中的每一个对象都有其在场景中的位置和包围盒( QGraphicsItem::scenePos (), QGraphicsItem::sceneBoundingRect ()),另外,也有其自身的位置和包围盒。场景位置描述了对象在场景坐标系下的位置,场景包围盒则提供给 QGraphicsScene来决定场景中的哪一块区域已经被改变了。场景中的变化通过 QGraphicsScene::changed ()信号发出,参数是场景坐标系下的矩形列表。

3.3View Coordinates(视图坐标)

View coordinates are the coordinates of the widget. Each unit in view coordinates corresponds to one pixel. What's special about this coordinate system is that it is relative to the widget, or viewport, and unaffected by the observed scene. The top left corner of QGraphicsView's viewport is always (0, 0), and the bottom right corner is always (viewport width, viewport height). All mouse events and drag and drop events are originally received as view coordinates, and you need to map these coordinates to the scene in order to interact with items.
视图坐标系是 组件的坐标系。视图坐标系下的每个单位对应于一个像素。对于该坐标系来说比较特殊的一点是,它是相对于 widget 或者 viewport 的坐标系,不会受到被显示的场景的影响。 QGraphicsView 的 viewport 左上角坐标总是( 0 , 0 ),右下角坐标总是( viewport 宽度, viewport 高度)。所有的鼠标事件和拖拽事件都在视图坐标系下接收,你需要将这些坐标映射到场景中后才能与场景中的图形对象进行交互。

3.4Coordinate Mapping(坐标映射)

Often when dealing with items in a scene, it can be useful to map coordinates and arbitrary shapes from the scene to an item, from item to item, or from the view to the scene. For example, when you click your mouse in QGraphicsView's viewport, you can ask the scene what item is under the cursor by calling QGraphicsView::mapToScene(), followed by QGraphicsScene::itemAt(). If you want to know where in the viewport an item is located, you can call QGraphicsItem::mapToScene() on the item, then QGraphicsView::mapFromScene() on the view. Finally, if you use want to find what items are inside a view ellipse, you can pass a QPainterPath to mapToScene(), and then pass the mapped path to QGraphicsScene::items().
常当我们处理场景中的对象的时候,坐标变换将会非常有用,我们可以把坐标或者任意形状从场景变换到对象坐标系下,从一个对象坐标系变换到另一个对象坐标系,或者从视图变换到场景。例如当你用鼠标点击了 QGraphicsView的 viewport,你可以向场景管理器查询当前鼠标下方的对象(调用 QGraphicsView::mapToScene ()变换坐标,然后通过 QGraphicsScene::itemAt ()查询对象)。如果你想知道一个对象处于 viewport中的位置,你可以调用对象的函数 QGraphicsItem::mapToScene () ,然后在调用视图的函数 QGraphicsView::mapFromScene () 。最后,如果你想查找位于一个椭圆区域内的对象,你可以把一个 QPainterPath 对象传递给 mapToScene()然后将变换之后的 path传递给 QGraphicsScene::items ()。

You can map coordinates and shapes to and from an item's scene by calling QGraphicsItem::mapToScene() and QGraphicsItem::mapFromScene(). You can also map to an item's parent item by calling QGraphicsItem::mapToParent() and QGraphicsItem::mapFromParent(), or between items by calling QGraphicsItem::mapToItem() and QGraphicsItem::mapFromItem(). All mapping functions can map both points, rectangles, polygons and paths.
你可以通过调用 QGraphicsItem::mapToScene () 将坐标或者任意形状 映射到对象的场景中去,同样也可以通过调用 QGraphicsItem::mapFromScene ()将其映射回来。你也可以调用 QGraphicsItem::mapToParent ()将对象映射到其父对象的坐标系下,同样也可以通过调用 QGraphicsItem::mapFromParent ()将其映射回来。甚至可以用过调用 QGraphicsItem::mapToItem () 和 QGraphicsItem::mapFromItem ()在不同的对象的坐标系之间进行映射。所有的映射函数均支持点、举行、多边形和路径。

The same mapping functions are available in the view, for mapping to and from the scene. QGraphicsView::mapFromScene() and QGraphicsView::mapToScene(). To map from a view to an item, you first map to the scene, and then map from the scene to the item.
在视图和场景之间也存在着同样的映射函数: QGraphicsView::mapFromScene () 和 QGraphicsView::mapToScene ()。要从视图映射到对象,第一步是映射到场景,然后才能从场景映射到对象坐标系下。


相关文章:

  • 2.Classes in the Graphics View Framework(图形视图框架中的类)
  • 4.Key Features(主要特征)
  • 5.Performance(性能)
  • linux解决wifi问题
  • 比较C++中数组,vector,array
  • 一、opencv的图像基本读写
  • 二、opencv的滑块使用
  • 三、Mat类的使用
  • 四、常用数据结构和函数
  • 五、颜色空间缩减
  • 2017.5.5
  • ubuntu安装QT5.7
  • QT 语法知识
  • Qt Creator 使用tips
  • C++使用tips
  • 实现windows 窗体的自己画,网上摘抄的,学习了
  • Angular Elements 及其运作原理
  • Angular4 模板式表单用法以及验证
  •  D - 粉碎叛乱F - 其他起义
  • Docker容器管理
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Java教程_软件开发基础
  • JSDuck 与 AngularJS 融合技巧
  • Js基础知识(一) - 变量
  • Python学习之路13-记分
  • spring-boot List转Page
  • Terraform入门 - 3. 变更基础设施
  • zookeeper系列(七)实战分布式命名服务
  • 记一次删除Git记录中的大文件的过程
  • 开源中国专访:Chameleon原理首发,其它跨多端统一框架都是假的?
  • 聊聊directory traversal attack
  • 如何优雅地使用 Sublime Text
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 数据仓库的几种建模方法
  • 思否第一天
  • [Shell 脚本] 备份网站文件至OSS服务(纯shell脚本无sdk) ...
  • ​DB-Engines 12月数据库排名: PostgreSQL有望获得「2020年度数据库」荣誉?
  • #pragma once
  • $Django python中使用redis, django中使用(封装了),redis开启事务(管道)
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (4.10~4.16)
  • (AtCoder Beginner Contest 340) -- F - S = 1 -- 题解
  • (C语言)二分查找 超详细
  • (ibm)Java 语言的 XPath API
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (黑马出品_高级篇_01)SpringCloud+RabbitMQ+Docker+Redis+搜索+分布式
  • (免费分享)基于springboot,vue疗养中心管理系统
  • ..回顾17,展望18
  • .bat批处理(七):PC端从手机内复制文件到本地
  • .jks文件(JAVA KeyStore)
  • .net framwork4.6操作MySQL报错Character set ‘utf8mb3‘ is not supported 解决方法
  • .NET 材料检测系统崩溃分析
  • .NET版Word处理控件Aspose.words功能演示:在ASP.NET MVC中创建MS Word编辑器
  • /dev/VolGroup00/LogVol00:unexpected inconsistency;run fsck manually
  • @GlobalLock注解作用与原理解析