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 | void checkAndRequestZoomAction(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 | event->accept(); | ||||
rkflx: Hiding that in the function can be a bit unexpected. Maybe we should return a `bool`, and… | |||||
137 | } | 139 | } | ||
138 | } | 140 | } | ||
139 | }; | 141 | }; | ||
140 | 142 | | |||
141 | AbstractImageView::AbstractImageView(QGraphicsItem* parent) | 143 | AbstractImageView::AbstractImageView(QGraphicsItem* parent) | ||
142 | : QGraphicsWidget(parent) | 144 | : QGraphicsWidget(parent) | ||
143 | , d(new AbstractImageViewPrivate) | 145 | , d(new AbstractImageViewPrivate) | ||
144 | { | 146 | { | ||
145 | d->q = this; | 147 | d->q = this; | ||
146 | d->mControlKeyIsDown = false; | 148 | d->mControlKeyIsDown = false; | ||
147 | d->mEnlargeSmallerImages = false; | 149 | d->mEnlargeSmallerImages = false; | ||
150 | d->mToolActive = false; | ||||
148 | d->mZoom = 1; | 151 | d->mZoom = 1; | ||
149 | d->mZoomToFit = true; | 152 | d->mZoomToFit = true; | ||
150 | d->mZoomToFill = false; | 153 | d->mZoomToFill = false; | ||
151 | d->mImageOffset = QPointF(0, 0); | 154 | d->mImageOffset = QPointF(0, 0); | ||
152 | d->mScrollPos = QPointF(0, 0); | 155 | d->mScrollPos = QPointF(0, 0); | ||
153 | setFocusPolicy(Qt::WheelFocus); | 156 | setFocusPolicy(Qt::WheelFocus); | ||
154 | setFlag(ItemIsSelectable); | 157 | setFlag(ItemIsSelectable); | ||
155 | setFlag(ItemClipsChildrenToShape); | 158 | setFlag(ItemClipsChildrenToShape); | ||
▲ Show 20 Lines • Show All 424 Lines • ▼ Show 20 Line(s) | 582 | { | |||
580 | d->mEnlargeSmallerImages = value; | 583 | d->mEnlargeSmallerImages = value; | ||
581 | if (zoomToFit()) { | 584 | if (zoomToFit()) { | ||
582 | setZoom(computeZoomToFit()); | 585 | setZoom(computeZoomToFit()); | ||
583 | } | 586 | } | ||
584 | } | 587 | } | ||
585 | 588 | | |||
586 | void AbstractImageView::updateCursor() | 589 | void AbstractImageView::updateCursor() | ||
587 | { | 590 | { | ||
591 | if (d->mToolActive) { | ||||
592 | return; | ||||
593 | } | ||||
594 | | ||||
588 | if (d->mControlKeyIsDown) { | 595 | if (d->mControlKeyIsDown) { | ||
589 | setCursor(d->mZoomCursor); | 596 | setCursor(d->mZoomCursor); | ||
590 | } else { | 597 | } else { | ||
591 | if (d->mLastDragPos.isNull()) { | 598 | if (d->mLastDragPos.isNull()) { | ||
592 | setCursor(Qt::OpenHandCursor); | 599 | setCursor(Qt::OpenHandCursor); | ||
593 | } else { | 600 | } else { | ||
594 | setCursor(Qt::ClosedHandCursor); | 601 | setCursor(Qt::ClosedHandCursor); | ||
595 | } | 602 | } | ||
Show All 16 Lines | |||||
612 | } | 619 | } | ||
613 | 620 | | |||
614 | void AbstractImageView::resetDragCursor() | 621 | void AbstractImageView::resetDragCursor() | ||
615 | { | 622 | { | ||
616 | d->mLastDragPos = QPointF(); | 623 | d->mLastDragPos = QPointF(); | ||
617 | updateCursor(); | 624 | updateCursor(); | ||
618 | } | 625 | } | ||
619 | 626 | | |||
627 | void AbstractImageView::setToolActive(bool active) | ||||
628 | { | ||||
629 | d->mToolActive = active; | ||||
630 | } | ||||
631 | | ||||
620 | } // namespace | 632 | } // 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?