@@ -45,6 +45,10 @@ void MovableWidget::mouseReleaseEvent(QMouseEvent *event) {
4545
4646static bool hasSelection = false ;
4747
48+ static QPointF last_end = QPointF(0 ,0 );
49+ static QPointF last_begin = QPointF(0 ,0 );
50+ static int rad = 0 ;
51+
4852void DrawingWidget::createSelection () {
4953 hasSelection = true ;
5054 // printf("%f %f %f %f\n", startPoint.x(), endPoint.x(), startPoint.y(), endPoint.y());
@@ -69,7 +73,29 @@ void DrawingWidget::createSelection() {
6973 cropWidget->move (topLeft);
7074 cropWidget->raise ();
7175 cropWidget->show ();
72- update ();
76+
77+ rad = penSize[penType];
78+ update (QRectF (
79+ last_begin, last_end
80+ ).toRect ().normalized ().adjusted (-rad, -rad, +rad, +rad));
81+ update (QRectF (
82+ startPoint, endPoint
83+ ).toRect ().normalized ().adjusted (-rad, -rad, +rad, +rad));
84+ last_begin = startPoint;
85+ last_end = endPoint;
86+ }
87+
88+ void DrawingWidget::clearSelection () {
89+ if (!hasSelection){
90+ return ;
91+ }
92+ hasSelection = false ;
93+ cropWidget->setFixedSize (0 ,0 );
94+ cropWidget->move (QPoint (-1 ,-1 ));
95+ cropWidget->image = QImage (QSize (0 ,0 ), QImage::Format_ARGB32);
96+ cropWidget->image .fill (QColor (" transparent" ));
97+ addImage (image);
98+
7399}
74100
75101void DrawingWidget::mergeSelection () {
@@ -80,9 +106,7 @@ void DrawingWidget::mergeSelection() {
80106 painter.begin (&image);
81107 painter.setPen (Qt::NoPen);
82108 painter.drawImage (QPoint (cropWidget->x (), cropWidget->y ()), cropWidget->image .scaled (cropWidget->width (), cropWidget->height ()));
83- cropWidget->setFixedSize (0 ,0 );
84- cropWidget->move (QPoint (-1 ,-1 ));
85109 update ();
86110 painter.end ();
87- addImage (image );
111+ clearSelection ( );
88112}
0 commit comments