48 TabletCanvas::TabletCanvas() |
48 TabletCanvas::TabletCanvas() |
49 { |
49 { |
50 resize(500, 500); |
50 resize(500, 500); |
51 myBrush = QBrush(); |
51 myBrush = QBrush(); |
52 myPen = QPen(); |
52 myPen = QPen(); |
53 initImage(); |
53 initPixmap(); |
54 setAutoFillBackground(true); |
54 setAutoFillBackground(true); |
55 deviceDown = false; |
55 deviceDown = false; |
56 myColor = Qt::red; |
56 myColor = Qt::red; |
57 myTabletDevice = QTabletEvent::Stylus; |
57 myTabletDevice = QTabletEvent::Stylus; |
58 alphaChannelType = NoAlpha; |
58 alphaChannelType = NoAlpha; |
59 colorSaturationType = NoSaturation; |
59 colorSaturationType = NoSaturation; |
60 lineWidthType = LineWidthPressure; |
60 lineWidthType = LineWidthPressure; |
61 } |
61 } |
62 |
62 |
63 void TabletCanvas::initImage() |
63 void TabletCanvas::initPixmap() |
64 { |
64 { |
65 QImage newImage = QImage(width(), height(), QImage::Format_ARGB32); |
65 QPixmap newPixmap = QPixmap(width(), height()); |
66 QPainter painter(&newImage); |
66 newPixmap.fill(Qt::white); |
67 painter.fillRect(0, 0, newImage.width(), newImage.height(), Qt::white); |
67 QPainter painter(&newPixmap); |
68 if (!image.isNull()) |
68 if (!pixmap.isNull()) |
69 painter.drawImage(0, 0, image); |
69 painter.drawPixmap(0, 0, pixmap); |
70 painter.end(); |
70 painter.end(); |
71 image = newImage; |
71 pixmap = newPixmap; |
72 } |
72 } |
73 //! [0] |
73 //! [0] |
74 |
74 |
75 //! [1] |
75 //! [1] |
76 bool TabletCanvas::saveImage(const QString &file) |
76 bool TabletCanvas::saveImage(const QString &file) |
77 { |
77 { |
78 return image.save(file); |
78 return pixmap.save(file); |
79 } |
79 } |
80 //! [1] |
80 //! [1] |
81 |
81 |
82 //! [2] |
82 //! [2] |
83 bool TabletCanvas::loadImage(const QString &file) |
83 bool TabletCanvas::loadImage(const QString &file) |
84 { |
84 { |
85 bool success = image.load(file); |
85 bool success = pixmap.load(file); |
86 |
86 |
87 if (success) { |
87 if (success) { |
88 update(); |
88 update(); |
89 return true; |
89 return true; |
90 } |
90 } |
127 |
127 |
128 //! [4] |
128 //! [4] |
129 void TabletCanvas::paintEvent(QPaintEvent *) |
129 void TabletCanvas::paintEvent(QPaintEvent *) |
130 { |
130 { |
131 QPainter painter(this); |
131 QPainter painter(this); |
132 painter.drawImage(QPoint(0, 0), image); |
132 painter.drawPixmap(0, 0, pixmap); |
133 } |
133 } |
134 //! [4] |
134 //! [4] |
135 |
135 |
136 //! [5] |
136 //! [5] |
137 void TabletCanvas::paintImage(QPainter &painter, QTabletEvent *event) |
137 void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event) |
138 { |
138 { |
139 QPoint brushAdjust(10, 10); |
139 QPoint brushAdjust(10, 10); |
140 |
140 |
141 switch (myTabletDevice) { |
141 switch (myTabletDevice) { |
142 case QTabletEvent::Airbrush: |
142 case QTabletEvent::Airbrush: |