source: trunk/demos/shared/hoverpoints.cpp@ 106

Last change on this file since 106 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the demonstration applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifdef QT_OPENGL_SUPPORT
43#include <QGLWidget>
44#endif
45
46#include "arthurwidgets.h"
47#include "hoverpoints.h"
48
49#define printf
50
51HoverPoints::HoverPoints(QWidget *widget, PointShape shape)
52 : QObject(widget)
53{
54 m_widget = widget;
55 widget->installEventFilter(this);
56
57 m_connectionType = CurveConnection;
58 m_sortType = NoSort;
59 m_shape = shape;
60 m_pointPen = QPen(QColor(255, 255, 255, 191), 1);
61 m_connectionPen = QPen(QColor(255, 255, 255, 127), 2);
62 m_pointBrush = QBrush(QColor(191, 191, 191, 127));
63 m_pointSize = QSize(11, 11);
64 m_currentIndex = -1;
65 m_editable = true;
66 m_enabled = true;
67
68 connect(this, SIGNAL(pointsChanged(const QPolygonF &)),
69 m_widget, SLOT(update()));
70}
71
72
73void HoverPoints::setEnabled(bool enabled)
74{
75 if (m_enabled != enabled) {
76 m_enabled = enabled;
77 m_widget->update();
78 }
79}
80
81
82bool HoverPoints::eventFilter(QObject *object, QEvent *event)
83{
84 if (object == m_widget && m_enabled) {
85 switch (event->type()) {
86
87 case QEvent::MouseButtonPress:
88 {
89 QMouseEvent *me = (QMouseEvent *) event;
90
91 QPointF clickPos = me->pos();
92 int index = -1;
93 for (int i=0; i<m_points.size(); ++i) {
94 QPainterPath path;
95 if (m_shape == CircleShape)
96 path.addEllipse(pointBoundingRect(i));
97 else
98 path.addRect(pointBoundingRect(i));
99
100 if (path.contains(clickPos)) {
101 index = i;
102 break;
103 }
104 }
105
106 if (me->button() == Qt::LeftButton) {
107 if (index == -1) {
108 if (!m_editable)