Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/examples/widgets/tablet/tabletcanvas.cpp

    r2 r561  
    22**
    33** 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])
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5151    myBrush = QBrush();
    5252    myPen = QPen();
    53     initImage();
     53    init();
    5454    setAutoFillBackground(true);
    5555    deviceDown = false;
     
    6161}
    6262
    63 void TabletCanvas::initImage()
    64 {
    65     QImage 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.drawImage(0, 0, image);
     63void TabletCanvas::init()
     64{
     65    Q);
     66    e);
     67    );
     68    if (!.isNull())
     69        painter.draw);
    7070    painter.end();
    71     image = newImage;
     71    ;
    7272}
    7373//! [0]
     
    7676bool TabletCanvas::saveImage(const QString &file)
    7777{
    78     return image.save(file);
     78    return .save(file);
    7979}
    8080//! [1]
     
    8383bool TabletCanvas::loadImage(const QString &file)
    8484{
    85     bool success = image.load(file);
     85    bool success = .load(file);
    8686
    8787    if (success) {
     
    9999    switch (event->type()) {
    100100        case QEvent::TabletPress:
    101             if (!deviceDown)
     101            if (!deviceDown)
    102102                deviceDown = true;
     103
     104
    103105            break;
    104106        case QEvent::TabletRelease:
     
    113115            if (deviceDown) {
    114116                updateBrush(event);
    115                 QPainter painter(&image);
    116                 paintImage(painter, event);
     117                QPainter painter(&);
     118                paint(painter, event);
    117119            }
    118120            break;
     
    128130{
    129131    QPainter painter(this);
    130     painter.drawImage(QPoint(0, 0), image);
     132    painter.draw);
    131133}
    132134//! [4]
    133135
    134136//! [5]
    135 void TabletCanvas::paintImage(QPainter &painter, QTabletEvent *event)
     137void TabletCanvas::paint(QPainter &painter, QTabletEvent *event)
    136138{
    137139    QPoint brushAdjust(10, 10);
    138140
    139141    switch (myTabletDevice) {
    140         case QTabletEvent::Stylus:
    141             painter.setBrush(myBrush);
    142             painter.setPen(myPen);
    143             painter.drawLine(polyLine[1], event->pos());
    144             break;
    145142        case QTabletEvent::Airbrush:
    146143            myBrush.setColor(myColor);
     
    157154        case QTabletEvent::FourDMouse:
    158155        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;
    163182    }
    164183}
     
    251270//! [11]
    252271
    253 void TabletCanvas::resizeEvent(QResizeEvent *event)
    254 {
    255     initImage();
     272void TabletCanvas::resizeEvent(QResizeEvent *)
     273{
     274    init();
    256275    polyLine[0] = polyLine[1] = polyLine[2] = QPoint();
    257276}
Note: See TracChangeset for help on using the changeset viewer.