Qt 4.8
liveselectionrectangle.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "liveselectionrectangle.h"
43 
44 #include "../qmlinspectorconstants.h"
45 
46 #include <QtGui/QPen>
47 #include <QtGui/QGraphicsRectItem>
48 #include <QtGui/QGraphicsObject>
49 #include <QtGui/QGraphicsScene>
50 
51 #include <QtCore/QtDebug>
52 
53 #include <cmath>
54 
55 #ifdef Q_OS_WINCE
56 # include <qfunctions_wince.h>
57 #endif
58 
59 namespace QmlJSDebugger {
60 
62 {
63 public:
65  int type() const { return Constants::EditorItemType; }
66 };
67 
69  : m_controlShape(new SelectionRectShape(layerItem)),
70  m_layerItem(layerItem)
71 {
73  m_controlShape->setBrush(QColor(128, 128, 128, 50));
74 }
75 
77 {
78  if (m_layerItem)
80 }
81 
83 {
84  hide();
85 }
87 {
89 }
90 
92 {
94 }
95 
97 {
99 }
100 
102  const QPointF &secondPoint)
103 {
104  double firstX = std::floor(firstPoint.x()) + 0.5;
105  double firstY = std::floor(firstPoint.y()) + 0.5;
106  double secondX = std::floor(secondPoint.x()) + 0.5;
107  double secondY = std::floor(secondPoint.y()) + 0.5;
108  QPointF topLeftPoint(firstX < secondX ? firstX : secondX,
109  firstY < secondY ? firstY : secondY);
110  QPointF bottomRightPoint(firstX > secondX ? firstX : secondX,
111  firstY > secondY ? firstY : secondY);
112 
113  QRectF rect(topLeftPoint, bottomRightPoint);
114  m_controlShape->setRect(rect);
115 }
116 
117 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
void setRect(const QPointF &firstPoint, const QPointF &secondPoint)
int type() const
Reimplemented Function
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QRectF rect() const
Returns the item&#39;s rectangle.
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
T * data() const
QWeakPointer< QGraphicsObject > m_layerItem
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
SelectionRectShape(QGraphicsItem *parent=0)
static const QRectF boundingRect(const QPointF *points, int pointCount)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
void setPen(const QPen &pen)
Sets the pen for this item to pen.
LiveSelectionRectangle(QGraphicsObject *layerItem)
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
void hide()
Hides the item.
void setRect(const QRectF &rect)
Sets the item&#39;s rectangle to be the given rectangle.
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
The QGraphicsObject class provides a base class for all graphics items that require signals...
void setBrush(const QBrush &brush)
Sets the item&#39;s brush to brush.
void show()
Shows the item.