Changeset View
Changeset View
Standalone View
Standalone View
lib/documentview/abstractimageview.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 43 | enum Verbosity { | |||
---|---|---|---|---|---|
45 | Notify | 45 | Notify | ||
46 | }; | 46 | }; | ||
47 | AbstractImageView* q; | 47 | AbstractImageView* q; | ||
48 | QCursor mZoomCursor; | 48 | QCursor mZoomCursor; | ||
49 | Document::Ptr mDocument; | 49 | Document::Ptr mDocument; | ||
50 | 50 | | |||
51 | bool mControlKeyIsDown; | 51 | bool mControlKeyIsDown; | ||
52 | bool mEnlargeSmallerImages; | 52 | bool mEnlargeSmallerImages; | ||
53 | bool mToolActive; | ||||
53 | 54 | | |||
54 | qreal mZoom; | 55 | qreal mZoom; | ||
55 | bool mZoomToFit; | 56 | bool mZoomToFit; | ||
56 | bool mZoomToFill; | 57 | bool mZoomToFill; | ||
57 | QPointF mImageOffset; | 58 | QPointF mImageOffset; | ||
58 | QPointF mScrollPos; | 59 | QPointF mScrollPos; | ||
59 | QPointF mLastDragPos; | 60 | QPointF mLastDragPos; | ||
60 | QSizeF mDocumentSize; | 61 | QSizeF mDocumentSize; | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 120 | { | |||
121 | QPainter painter(&pix); | 122 | QPainter painter(&pix); | ||
122 | painter.fillRect(pix.rect(), QColor(128, 128, 128)); | 123 | painter.fillRect(pix.rect(), QColor(128, 128, 128)); | ||
123 | const QColor light = QColor(192, 192, 192); | 124 | const QColor light = QColor(192, 192, 192); | ||
124 | painter.fillRect(0, 0, 16, 16, light); | 125 | painter.fillRect(0, 0, 16, 16, light); | ||
125 | painter.fillRect(16, 16, 16, 16, light); | 126 | painter.fillRect(16, 16, 16, 16, light); | ||
126 | return pix; | 127 | return pix; | ||
127 | } | 128 | } | ||
128 | 129 | | |||
129 | void checkAndRequestZoomAction(const QGraphicsSceneMouseEvent* event) | 130 | bool checkAndRequestZoomAction(const QGraphicsSceneMouseEvent* event) | ||
130 | { | 131 | { | ||
131 | if (event->modifiers() & Qt::ControlModifier) { | 132 | if (event->modifiers() & Qt::ControlModifier) { | ||
132 | if (event->button() == Qt::LeftButton) { | 133 | if (event->button() == Qt::LeftButton) { | ||
133 | q->zoomInRequested(event->pos()); | 134 | q->zoomInRequested(event->pos()); | ||
134 | } else if (event->button() == Qt::RightButton) { | 135 | } else if (event->button() == Qt::RightButton) { | ||
135 | q->zoomOutRequested(event->pos()); | 136 | q->zoomOutRequested(event->pos()); | ||
136 | } | 137 | } | ||
138 | return true; | ||||
rkflx: Hiding that in the function can be a bit unexpected. Maybe we should return a `bool`, and… | |||||
137 | } | 139 | } | ||
140 | return false; | ||||
138 | } | 141 | } | ||
139 | }; | 142 | }; | ||
140 | 143 | | |||
141 | AbstractImageView::AbstractImageView(QGraphicsItem* parent) | 144 | AbstractImageView::AbstractImageView(QGraphicsItem* parent) | ||
142 | : QGraphicsWidget(parent) | 145 | : QGraphicsWidget(parent) | ||
143 | , d(new AbstractImageViewPrivate) | 146 | , d(new AbstractImageViewPrivate) | ||
144 | { | 147 | { | ||
145 | d->q = this; | 148 | d->q = this; | ||
146 | d->mControlKeyIsDown = false; | 149 | d->mControlKeyIsDown = false; | ||
147 | d->mEnlargeSmallerImages = false; | 150 | d->mEnlargeSmallerImages = false; | ||
151 | d->mToolActive = false; | ||||
148 | d->mZoom = 1; | 152 | d->mZoom = 1; | ||
149 | d->mZoomToFit = true; | 153 | d->mZoomToFit = true; | ||
150 | d->mZoomToFill = false; | 154 | d->mZoomToFill = false; | ||
151 | d->mImageOffset = QPointF(0, 0); | 155 | d->mImageOffset = QPointF(0, 0); | ||
152 | d->mScrollPos = QPointF(0, 0); | 156 | d->mScrollPos = QPointF(0, 0); | ||
153 | setFocusPolicy(Qt::WheelFocus); | 157 | setFocusPolicy(Qt::WheelFocus); | ||
154 | setFlag(ItemIsSelectable); | 158 | setFlag(ItemIsSelectable); | ||
155 | setFlag(ItemClipsChildrenToShape); | 159 | setFlag(ItemClipsChildrenToShape); | ||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Line(s) | 357 | { | |||
364 | } | 368 | } | ||
365 | return fill; | 369 | return fill; | ||
366 | } | 370 | } | ||
367 | 371 | | |||
368 | void AbstractImageView::mousePressEvent(QGraphicsSceneMouseEvent* event) | 372 | void AbstractImageView::mousePressEvent(QGraphicsSceneMouseEvent* event) | ||
369 | { | 373 | { | ||
370 | QGraphicsItem::mousePressEvent(event); | 374 | QGraphicsItem::mousePressEvent(event); | ||
371 | 375 | | |||
372 | d->checkAndRequestZoomAction(event); | 376 | if (d->checkAndRequestZoomAction(event)) { | ||
377 | event->accept(); | ||||
378 | } | ||||
373 | 379 | | |||
374 | // Prepare for panning or dragging | 380 | // Prepare for panning or dragging | ||
375 | if (event->button() == Qt::LeftButton) { | 381 | if (event->button() == Qt::LeftButton) { | ||
376 | d->mLastDragPos = event->pos(); | 382 | d->mLastDragPos = event->pos(); | ||
377 | updateCursor(); | 383 | updateCursor(); | ||
378 | } | 384 | } | ||
379 | } | 385 | } | ||
380 | 386 | | |||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | |||||
500 | } | 506 | } | ||
501 | 507 | | |||
502 | void AbstractImageView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) | 508 | void AbstractImageView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) | ||
503 | { | 509 | { | ||
504 | if (event->modifiers() == Qt::NoModifier && event->button() == Qt::LeftButton) { | 510 | if (event->modifiers() == Qt::NoModifier && event->button() == Qt::LeftButton) { | ||
505 | toggleFullScreenRequested(); | 511 | toggleFullScreenRequested(); | ||
506 | } | 512 | } | ||
507 | 513 | | |||
508 | d->checkAndRequestZoomAction(event); | 514 | if (d->checkAndRequestZoomAction(event)) { | ||
515 | event->accept(); | ||||
516 | } | ||||
509 | } | 517 | } | ||
510 | 518 | | |||
511 | QPointF AbstractImageView::imageOffset() const | 519 | QPointF AbstractImageView::imageOffset() const | ||
512 | { | 520 | { | ||
513 | return d->mImageOffset; | 521 | return d->mImageOffset; | ||
514 | } | 522 | } | ||
515 | 523 | | |||
516 | QPointF AbstractImageView::scrollPos() const | 524 | QPointF AbstractImageView::scrollPos() const | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 587 | { | |||
580 | d->mEnlargeSmallerImages = value; | 588 | d->mEnlargeSmallerImages = value; | ||
581 | if (zoomToFit()) { | 589 | if (zoomToFit()) { | ||
582 | setZoom(computeZoomToFit()); | 590 | setZoom(computeZoomToFit()); | ||
583 | } | 591 | } | ||
584 | } | 592 | } | ||
585 | 593 | | |||
586 | void AbstractImageView::updateCursor() | 594 | void AbstractImageView::updateCursor() | ||
587 | { | 595 | { | ||
596 | if (d->mToolActive) { | ||||
597 | return; | ||||
598 | } | ||||
599 | | ||||
588 | if (d->mControlKeyIsDown) { | 600 | if (d->mControlKeyIsDown) { | ||
589 | setCursor(d->mZoomCursor); | 601 | setCursor(d->mZoomCursor); | ||
590 | } else { | 602 | } else { | ||
591 | if (d->mLastDragPos.isNull()) { | 603 | if (d->mLastDragPos.isNull()) { | ||
592 | setCursor(Qt::OpenHandCursor); | 604 | setCursor(Qt::OpenHandCursor); | ||
593 | } else { | 605 | } else { | ||
594 | setCursor(Qt::ClosedHandCursor); | 606 | setCursor(Qt::ClosedHandCursor); | ||
595 | } | 607 | } | ||
Show All 16 Lines | |||||
612 | } | 624 | } | ||
613 | 625 | | |||
614 | void AbstractImageView::resetDragCursor() | 626 | void AbstractImageView::resetDragCursor() | ||
615 | { | 627 | { | ||
616 | d->mLastDragPos = QPointF(); | 628 | d->mLastDragPos = QPointF(); | ||
617 | updateCursor(); | 629 | updateCursor(); | ||
618 | } | 630 | } | ||
619 | 631 | | |||
632 | void AbstractImageView::setToolActive(bool active) | ||||
633 | { | ||||
634 | d->mToolActive = active; | ||||
635 | } | ||||
636 | | ||||
620 | } // namespace | 637 | } // namespace |
Hiding that in the function can be a bit unexpected. Maybe we should return a bool, and depending on that accept or do something else in the caller?