@@ -51,8 +51,8 @@ ImageView::ImageView(QWidget* parent):
51
51
autoZoomFit_ (false ),
52
52
smoothOnZoom_ (true ),
53
53
isSVG (false ),
54
- currentTool (ToolNone),
55
- nextNumber (1 ),
54
+ currentTool_ (ToolNone),
55
+ nextNumber_ (1 ),
56
56
showOutline_ (false ) {
57
57
58
58
setViewportMargins (0 , 0 , 0 , 0 );
@@ -125,19 +125,19 @@ void ImageView::mouseDoubleClickEvent(QMouseEvent* event) {
125
125
}
126
126
127
127
void ImageView::mousePressEvent (QMouseEvent * event) {
128
- if (currentTool == ToolNone) {
128
+ if (currentTool_ == ToolNone) {
129
129
QGraphicsView::mousePressEvent (event);
130
130
if (cursorTimer_) {
131
131
cursorTimer_->stop ();
132
132
}
133
133
}
134
134
else {
135
- startPoint = mapToScene (event->position ().toPoint ()).toPoint ();
135
+ startPoint_ = mapToScene (event->position ().toPoint ()).toPoint ();
136
136
}
137
137
}
138
138
139
139
void ImageView::mouseReleaseEvent (QMouseEvent* event) {
140
- if (currentTool == ToolNone) {
140
+ if (currentTool_ == ToolNone) {
141
141
QGraphicsView::mouseReleaseEvent (event);
142
142
if (cursorTimer_) {
143
143
cursorTimer_->start (CURSOR_HIDE_DELY);
@@ -150,29 +150,32 @@ void ImageView::mouseReleaseEvent(QMouseEvent* event) {
150
150
painter.setRenderHint (QPainter::Antialiasing, true );
151
151
painter.setPen (QPen (Qt::red, 5 ));
152
152
153
- switch (currentTool ) {
153
+ switch (currentTool_ ) {
154
154
case ToolArrow:
155
- drawArrow (painter, startPoint , endPoint, M_PI / 8 , 25 );
155
+ drawArrow (painter, startPoint_ , endPoint, M_PI / 8 , 25 );
156
156
break ;
157
- case ToolRectangle:
157
+ case ToolRectangle: {
158
158
// Draw the rectangle in the image and scene at the same time
159
- painter.drawRect (QRect (startPoint, endPoint));
160
- annotations.append (scene_->addRect (QRect (startPoint, endPoint), painter.pen ()));
159
+ QRect r = QRect (startPoint_, endPoint).normalized ();
160
+ painter.drawRect (r);
161
+ annotations_.append (scene_->addRect (r, painter.pen ()));
161
162
break ;
162
- case ToolCircle:
163
+ }
164
+ case ToolCircle: {
163
165
// Draw the circle in the image and scene at the same time
164
- painter.drawEllipse (QRect (startPoint, endPoint));
165
- annotations.append (scene_->addEllipse (QRect (startPoint, endPoint), painter.pen ()));
166
+ QRect r = QRect (startPoint_, endPoint).normalized ();
167
+ painter.drawEllipse (r);
168
+ annotations_.append (scene_->addEllipse (r, painter.pen ()));
166
169
break ;
167
- case ToolNumber:
168
- {
170
+ }
171
+ case ToolNumber: {
169
172
// Set the font
170
173
QFont font;
171
174
font.setPixelSize (32 );
172
175
painter.setFont (font);
173
176
174
177
// Calculate the dimensions of the text
175
- QString text = QStringLiteral (" %1" ).arg (nextNumber ++);
178
+ QString text = QStringLiteral (" %1" ).arg (nextNumber_ ++);
176
179
QRectF textRect = painter.boundingRect (image_.rect (), 0 , text);
177
180
textRect.moveTo (endPoint);
178
181
@@ -190,7 +193,7 @@ void ImageView::mouseReleaseEvent(QMouseEvent* event) {
190
193
painter.drawPath (path);
191
194
// Draw the circle in the sence
192
195
auto item = scene_->addPath (path, painter.pen (), QBrush (Qt::red));
193
- annotations .append (item);
196
+ annotations_ .append (item);
194
197
195
198
// Draw the text in the image
196
199
painter.setPen (Qt::white);
@@ -308,7 +311,7 @@ void ImageView::rotateImage(bool clockwise) {
308
311
// Since, in the case of SVG and GIF, annotations are not parts of the QImage and
309
312
// because they might have been added at any time, they need to be transformed
310
313
// by considering their previous transformations separately.
311
- for (const auto & annotation : std::as_const (annotations )) {
314
+ for (const auto & annotation : std::as_const (annotations_ )) {
312
315
prevTrans = annotation->transform ();
313
316
annotation->setTransform (transform, false );
314
317
annotation->setTransform (prevTrans, true );
@@ -319,11 +322,11 @@ void ImageView::rotateImage(bool clockwise) {
319
322
QTransform transform;
320
323
transform.rotate (clockwise ? 90.0 : -90.0 );
321
324
image_ = image_.transformed (transform, Qt::SmoothTransformation);
322
- int tmp = nextNumber ; // restore it (may be restet by setImage())
325
+ int tmp = nextNumber_ ; // restore it (may be reset by setImage())
323
326
/* when this is GIF or SVG, we need to transform its corresponding QImage
324
327
without showing it to have right measures for auto-zooming and other things */
325
328
setImage (image_, !gifMovie_ && !isSVG);
326
- nextNumber = tmp;
329
+ nextNumber_ = tmp;
327
330
}
328
331
}
329
332
@@ -346,7 +349,7 @@ void ImageView::flipImage(bool horizontal) {
346
349
outlineItem_->setTransform (transform, false );
347
350
outlineItem_->setTransform (prevTrans, true );
348
351
}
349
- for (const auto & annotation : std::as_const (annotations )) {
352
+ for (const auto & annotation : std::as_const (annotations_ )) {
350
353
prevTrans = annotation->transform ();
351
354
annotation->setTransform (transform, false );
352
355
annotation->setTransform (prevTrans, true );
@@ -360,9 +363,9 @@ void ImageView::flipImage(bool horizontal) {
360
363
else {
361
364
image_ = image_.mirrored (false , true );
362
365
}
363
- int tmp = nextNumber ;
366
+ int tmp = nextNumber_ ;
364
367
setImage (image_, !gifMovie_ && !isSVG);
365
- nextNumber = tmp;
368
+ nextNumber_ = tmp;
366
369
}
367
370
}
368
371
@@ -371,7 +374,7 @@ bool ImageView::resizeImage(const QSize& newSize) {
371
374
if (newSize == imgSize) {
372
375
return false ;
373
376
}
374
- int tmp = nextNumber ;
377
+ int tmp = nextNumber_ ;
375
378
if (!isSVG) { // with SVG, we get a sharp image below
376
379
image_ = image_.scaled (newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
377
380
setImage (image_, !gifMovie_);
@@ -389,7 +392,7 @@ bool ImageView::resizeImage(const QSize& newSize) {
389
392
outlineItem_->setTransform (transform, false );
390
393
outlineItem_->setTransform (prevTrans, true );
391
394
}
392
- for (const auto & annotation : std::as_const (annotations )) {
395
+ for (const auto & annotation : std::as_const (annotations_ )) {
393
396
prevTrans = annotation->transform ();
394
397
annotation->setTransform (transform, false );
395
398
annotation->setTransform (prevTrans, true );
@@ -406,7 +409,7 @@ bool ImageView::resizeImage(const QSize& newSize) {
406
409
imageItem->paint (&painter, &opt);
407
410
painter.restore ();
408
411
// draw annotations
409
- for (const auto & annotation : std::as_const (annotations )) {
412
+ for (const auto & annotation : std::as_const (annotations_ )) {
410
413
painter.save ();
411
414
painter.setTransform (annotation->transform ());
412
415
annotation->paint (&painter, &opt);
@@ -425,7 +428,7 @@ bool ImageView::resizeImage(const QSize& newSize) {
425
428
}
426
429
}
427
430
}
428
- nextNumber = tmp;
431
+ nextNumber_ = tmp;
429
432
return true ;
430
433
}
431
434
@@ -759,7 +762,7 @@ void ImageView::hideCursor(bool enable) {
759
762
}
760
763
761
764
void ImageView::activateTool (Tool tool) {
762
- currentTool = tool;
765
+ currentTool_ = tool;
763
766
viewport ()->setCursor (tool == ToolNone ?
764
767
Qt::OpenHandCursor :
765
768
Qt::CrossCursor);
@@ -774,7 +777,7 @@ void ImageView::drawArrow(QPainter &painter,
774
777
// Draw the line in the inmage
775
778
painter.drawLine (start, end);
776
779
// Draw the line in the scene
777
- annotations .append (scene_->addLine (QLine (start, end), painter.pen ()));
780
+ annotations_ .append (scene_->addLine (QLine (start, end), painter.pen ()));
778
781
779
782
// Calculate the angle of the line
780
783
QPoint delta = end - start;
@@ -794,8 +797,8 @@ void ImageView::drawArrow(QPainter &painter,
794
797
painter.drawLine (end, end + tip1);
795
798
painter.drawLine (end, end + tip2);
796
799
// Draw the two lines in the scene
797
- annotations .append (scene_->addLine (QLine (end, end+tip1), painter.pen ()));
798
- annotations .append (scene_->addLine (QLine (end, end+tip2), painter.pen ()));
800
+ annotations_ .append (scene_->addLine (QLine (end, end+tip1), painter.pen ()));
801
+ annotations_ .append (scene_->addLine (QLine (end, end+tip2), painter.pen ()));
799
802
}
800
803
801
804
void ImageView::resetView () {
@@ -807,17 +810,17 @@ void ImageView::resetView() {
807
810
}
808
811
}
809
812
// remove annotations
810
- if (!annotations .isEmpty ()) {
813
+ if (!annotations_ .isEmpty ()) {
811
814
if (!scene_->items ().isEmpty ()) { // WARNING: This is not enough to guard against dangling pointers.
812
- for (const auto & annotation : std::as_const (annotations )) {
815
+ for (const auto & annotation : std::as_const (annotations_ )) {
813
816
scene_->removeItem (annotation);
814
817
}
815
- qDeleteAll (annotations .begin (), annotations .end ());
818
+ qDeleteAll (annotations_ .begin (), annotations_ .end ());
816
819
}
817
- annotations .clear ();
820
+ annotations_ .clear ();
818
821
}
819
822
// reset numbering
820
- nextNumber = 1 ;
823
+ nextNumber_ = 1 ;
821
824
}
822
825
823
826
} // namespace LxImage
0 commit comments