Changeset 561 for trunk/demos/shared/hoverpoints.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/demos/shared/hoverpoints.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 54 54 m_widget = widget; 55 55 widget->installEventFilter(this); 56 widget->setAttribute(Qt::WA_AcceptTouchEvents); 56 57 57 58 m_connectionType = CurveConnection; … … 66 67 m_enabled = true; 67 68 68 connect(this, SIGNAL(pointsChanged( const QPolygonF &)),69 connect(this, SIGNAL(pointsChanged(QPolygonF)), 69 70 m_widget, SLOT(update())); 70 71 } … … 87 88 case QEvent::MouseButtonPress: 88 89 { 90 if (!m_fingerPointMapping.isEmpty()) 91 return true; 89 92 QMouseEvent *me = (QMouseEvent *) event; 90 93 … … 148 151 149 152 case QEvent::MouseButtonRelease: 153 if (!m_fingerPointMapping.isEmpty()) 154 return true; 150 155 m_currentIndex = -1; 151 156 break; 152 157 153 158 case QEvent::MouseMove: 159 if (!m_fingerPointMapping.isEmpty()) 160 return true; 154 161 if (m_currentIndex >= 0) 155 162 movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); 163 break; 164 case QEvent::TouchBegin: 165 case QEvent::TouchUpdate: 166 { 167 const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event); 168 const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); 169 const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height()); 170 foreach (const QTouchEvent::TouchPoint &touchPoint, points) { 171 const int id = touchPoint.id(); 172 switch (touchPoint.state()) { 173 case Qt::TouchPointPressed: 174 { 175 // find the point, move it 176 QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values()); 177 int activePoint = -1; 178 qreal distance = -1; 179 const int pointsCount = m_points.size(); 180 const int activePointCount = activePoints.size(); 181 if (pointsCount == 2 && activePointCount == 1) { // only two points 182 activePoint = activePoints.contains(0) ? 1 : 0; 183 } else { 184 for (int i=0; i<pointsCount; ++i) { 185 if (activePoints.contains(i)) 186 continue; 187 188 qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length(); 189 if ((distance < 0 && d < 12 * pointSize) || d < distance) { 190 distance = d; 191 activePoint = i; 192 } 193 194 } 195 } 196 if (activePoint != -1) { 197 m_fingerPointMapping.insert(touchPoint.id(), activePoint); 198 movePoint(activePoint, touchPoint.pos()); 199 } 200 } 201 break; 202 case Qt::TouchPointReleased: 203 { 204 // move the point and release 205 QHash<int,int>::iterator it = m_fingerPointMapping.find(id); 206 movePoint(it.value(), touchPoint.pos()); 207 m_fingerPointMapping.erase(it); 208 } 209 break; 210 case Qt::TouchPointMoved: 211 { 212 // move the point 213 const int pointIdx = m_fingerPointMapping.value(id, -1); 214 if (pointIdx >= 0) // do we track this point? 215 movePoint(pointIdx, touchPoint.pos()); 216 } 217 break; 218 default: 219 break; 220 } 221 } 222 if (m_fingerPointMapping.isEmpty()) { 223 event->ignore(); 224 return false; 225 } else { 226 return true; 227 } 228 } 229 break; 230 case QEvent::TouchEnd: 231 if (m_fingerPointMapping.isEmpty()) { 232 event->ignore(); 233 return false; 234 } 235 return true; 156 236 break; 157 237 … … 263 343 void HoverPoints::setPoints(const QPolygonF &points) 264 344 { 345 if (points.size() != m_points.size()) 346 m_fingerPointMapping.clear(); 265 347 m_points.clear(); 266 348 for (int i=0; i<points.size(); ++i)
Note:
See TracChangeset
for help on using the changeset viewer.