Qt 4.8
colorpickertool.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 "colorpickertool.h"
43 
44 #include "../qdeclarativeviewinspector.h"
45 
46 #include <QtGui/QMouseEvent>
47 #include <QtGui/QKeyEvent>
48 #include <QtCore/QRectF>
49 #include <QtGui/QRgb>
50 #include <QtGui/QImage>
51 #include <QtGui/QApplication>
52 #include <QtGui/QPalette>
53 
54 namespace QmlJSDebugger {
55 
58 {
59  m_selectedColor.setRgb(0,0,0);
60 }
61 
63 {
64 }
65 
67 {
68  pickColor(event->pos());
69 }
70 
72 {
73  pickColor(event->pos());
74 }
75 
77 {
78 #ifndef QT_NO_CURSOR
80 #endif
81 }
82 
84 {
85  QRgb fillColor = view()->backgroundBrush().color().rgb();
86  if (view()->backgroundBrush().style() == Qt::NoBrush)
87  fillColor = view()->palette().color(QPalette::Base).rgb();
88 
89  QRectF target(0,0, 1, 1);
90  QRect source(pos.x(), pos.y(), 1, 1);
91  QImage img(1, 1, QImage::Format_ARGB32);
92  img.fill(fillColor);
93  QPainter painter(&img);
94  view()->render(&painter, target, source);
95  m_selectedColor = QColor::fromRgb(img.pixel(0, 0));
96 
98 }
99 
100 } // namespace QmlJSDebugger
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
unsigned int QRgb
Definition: qrgb.h:53
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
void mouseMoveEvent(QMouseEvent *event)
void render(QPainter *painter, const QRectF &target=QRectF(), const QRect &source=QRect(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio)
Renders the source rect, which is in view coordinates, from the scene into target, which is in paint device coordinates, using painter.
QBrush backgroundBrush() const
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
void mousePressEvent(QMouseEvent *event)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define emit
Definition: qobjectdefs.h:76
const QPalette & palette() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void selectedColorChanged(const QColor &color)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
static QColor fromRgb(QRgb rgb)
Static convenience function that returns a QColor constructed from the given QRgb value rgb...
Definition: qcolor.cpp:1958
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
ColorPickerTool(QDeclarativeViewInspector *view)
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051
void pickColor(const QPoint &pos)