QtBase  v6.3.1
src_corelib_tools_qpoint.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
53 
54 p.setX(p.x() + 1);
55 p += QPoint(1, 0);
56 p.rx()++;
58 
59 
61 QPoint p(1, 2);
62 p.rx()--; // p becomes (0, 2)
64 
65 
67 QPoint p(1, 2);
68 p.ry()++; // p becomes (1, 3)
70 
71 
73 QPoint p( 3, 7);
74 QPoint q(-1, 4);
75 p += q; // p becomes (2, 11)
77 
78 
80 QPoint p( 3, 7);
81 QPoint q(-1, 4);
82 p -= q; // p becomes (4, 3)
84 
85 
87 QPoint p(-1, 4);
88 p *= 2.5; // p becomes (-3, 10)
90 
91 
93 QPoint p( 3, 7);
94 QPoint q(-1, 4);
95 int dotProduct = QPoint::dotProduct(p, q); // dotProduct becomes 25
97 
98 
100 QPoint p(-3, 10);
101 p /= 2.5; // p becomes (-1, 4)
103 
104 
107 
109 {
110  QPoint point = event->pos() - oldPosition;
111  if (point.manhattanLength() > 3)
112  // the mouse has moved more than 3 pixels since the oldPosition
113 }
115 
116 
118 double trueLength = std::sqrt(std::pow(x(), 2) + std::pow(y(), 2));
120 
121 
123 QPointF p;
124 
125 p.setX(p.x() + 1.0);
126 p += QPointF(1.0, 0.0);
127 p.rx()++;
129 
130 
132  QPointF p(1.1, 2.5);
133  p.rx()--; // p becomes (0.1, 2.5)
135 
136 
138 QPointF p(1.1, 2.5);
139 p.ry()++; // p becomes (1.1, 3.5)
141 
142 
144 QPointF p( 3.1, 7.1);
145 QPointF q(-1.0, 4.1);
146 p += q; // p becomes (2.1, 11.2)
148 
149 
151 QPointF p( 3.1, 7.1);
152 QPointF q(-1.0, 4.1);
153 p -= q; // p becomes (4.1, 3.0)
155 
156 
158 QPointF p(-1.1, 4.1);
159 p *= 2.5; // p becomes (-2.75, 10.25)
161 
162 
164 QPointF p(-2.75, 10.25);
165 p /= 2.5; // p becomes (-1.1, 4.1)
167 
168 
170 QPointF p( 3.1, 7.1);
171 QPointF q(-1.0, 4.1);
172 qreal dotProduct = QPointF::dotProduct(p, q); // dotProduct becomes 26.01
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:231
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
constexpr static qreal dotProduct(const QPointF &p1, const QPointF &p2)
Definition: qpoint.h:267
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
constexpr int manhattanLength() const
Definition: qpoint.h:175
constexpr static int dotProduct(const QPoint &p1, const QPoint &p2)
Definition: qpoint.h:80
constexpr void setX(int x) noexcept
Definition: qpoint.h:165
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: qwidget.cpp:9362
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
GLint GLint GLint GLint GLint x
[0]
GLint y
struct _cl_event * event
Definition: qopenglext.h:2998
GLdouble GLdouble GLdouble GLdouble q
Definition: qopenglext.h:259
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
QPoint q(-1, 4)
QPoint oldPosition
[6]
QPoint p
[0]
double trueLength
[7]