Changeset 561 for trunk/examples/widgets/tablet/tabletcanvas.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/examples/widgets/tablet/tabletcanvas.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the examples 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 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 51 51 myBrush = QBrush(); 52 52 myPen = QPen(); 53 init Image();53 init(); 54 54 setAutoFillBackground(true); 55 55 deviceDown = false; … … 61 61 } 62 62 63 void TabletCanvas::init Image()64 { 65 Q Image newImage = QImage(width(), height(), QImage::Format_ARGB32);66 QPainter painter(&newImage);67 painter.fillRect(0, 0, newImage.width(), newImage.height(), Qt::white);68 if (! image.isNull())69 painter.draw Image(0, 0, image);63 void TabletCanvas::init() 64 { 65 Q); 66 e); 67 ); 68 if (!.isNull()) 69 painter.draw); 70 70 painter.end(); 71 image = newImage;71 ; 72 72 } 73 73 //! [0] … … 76 76 bool TabletCanvas::saveImage(const QString &file) 77 77 { 78 return image.save(file);78 return .save(file); 79 79 } 80 80 //! [1] … … 83 83 bool TabletCanvas::loadImage(const QString &file) 84 84 { 85 bool success = image.load(file);85 bool success = .load(file); 86 86 87 87 if (success) { … … 99 99 switch (event->type()) { 100 100 case QEvent::TabletPress: 101 if (!deviceDown) 101 if (!deviceDown) 102 102 deviceDown = true; 103 104 103 105 break; 104 106 case QEvent::TabletRelease: … … 113 115 if (deviceDown) { 114 116 updateBrush(event); 115 QPainter painter(& image);116 paint Image(painter, event);117 QPainter painter(&); 118 paint(painter, event); 117 119 } 118 120 break; … … 128 130 { 129 131 QPainter painter(this); 130 painter.draw Image(QPoint(0, 0), image);132 painter.draw); 131 133 } 132 134 //! [4] 133 135 134 136 //! [5] 135 void TabletCanvas::paint Image(QPainter &painter, QTabletEvent *event)137 void TabletCanvas::paint(QPainter &painter, QTabletEvent *event) 136 138 { 137 139 QPoint brushAdjust(10, 10); 138 140 139 141 switch (myTabletDevice) { 140 case QTabletEvent::Stylus:141 painter.setBrush(myBrush);142 painter.setPen(myPen);143 painter.drawLine(polyLine[1], event->pos());144 break;145 142 case QTabletEvent::Airbrush: 146 143 myBrush.setColor(myColor); … … 157 154 case QTabletEvent::FourDMouse: 158 155 case QTabletEvent::RotationStylus: 159 qWarning("This input device is not supported by the example."); 160 break; 161 default: 162 qWarning("Unknown tablet device."); 156 { 157 const QString error(tr("This input device is not supported by the example.")); 158 #ifndef QT_NO_STATUSTIP 159 QStatusTipEvent status(error); 160 QApplication::sendEvent(this, &status); 161 #else 162 qWarning() << error; 163 #endif 164 } 165 break; 166 default: 167 { 168 const QString error(tr("Unknown tablet device - treating as stylus")); 169 #ifndef QT_NO_STATUSTIP 170 QStatusTipEvent status(error); 171 QApplication::sendEvent(this, &status); 172 #else 173 qWarning() << error; 174 #endif 175 } 176 // FALL-THROUGH 177 case QTabletEvent::Stylus: 178 painter.setBrush(myBrush); 179 painter.setPen(myPen); 180 painter.drawLine(polyLine[1], event->pos()); 181 break; 163 182 } 164 183 } … … 251 270 //! [11] 252 271 253 void TabletCanvas::resizeEvent(QResizeEvent * event)254 { 255 init Image();272 void TabletCanvas::resizeEvent(QResizeEvent *) 273 { 274 init(); 256 275 polyLine[0] = polyLine[1] = polyLine[2] = QPoint(); 257 276 }
Note:
See TracChangeset
for help on using the changeset viewer.