Changeset View
Changeset View
Standalone View
Standalone View
lib/documentview/abstractimageview.cpp
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | 119 | { | |||
---|---|---|---|---|---|
125 | painter.fillRect(16, 16, 16, 16, light); | 125 | painter.fillRect(16, 16, 16, 16, light); | ||
126 | return pix; | 126 | return pix; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | void checkAndRequestZoomAction(const QGraphicsSceneMouseEvent* event) | 129 | void checkAndRequestZoomAction(const QGraphicsSceneMouseEvent* event) | ||
130 | { | 130 | { | ||
131 | if (event->modifiers() & Qt::ControlModifier) { | 131 | if (event->modifiers() & Qt::ControlModifier) { | ||
132 | if (event->button() == Qt::LeftButton) { | 132 | if (event->button() == Qt::LeftButton) { | ||
133 | q->zoomInRequested(event->pos()); | 133 | emit q->zoomInRequested(event->pos()); | ||
134 | } else if (event->button() == Qt::RightButton) { | 134 | } else if (event->button() == Qt::RightButton) { | ||
135 | q->zoomOutRequested(event->pos()); | 135 | emit q->zoomOutRequested(event->pos()); | ||
136 | } | 136 | } | ||
137 | } | 137 | } | ||
138 | } | 138 | } | ||
139 | }; | 139 | }; | ||
140 | 140 | | |||
141 | AbstractImageView::AbstractImageView(QGraphicsItem* parent) | 141 | AbstractImageView::AbstractImageView(QGraphicsItem* parent) | ||
142 | : QGraphicsWidget(parent) | 142 | : QGraphicsWidget(parent) | ||
143 | , d(new AbstractImageViewPrivate) | 143 | , d(new AbstractImageViewPrivate) | ||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 194 | { | |||
246 | */ | 246 | */ | ||
247 | QPointF oldScroll = scrollPos() - imageOffset(); | 247 | QPointF oldScroll = scrollPos() - imageOffset(); | ||
248 | 248 | | |||
249 | QPointF scroll = (zoom / oldZoom) * (oldScroll + center) - center; | 249 | QPointF scroll = (zoom / oldZoom) * (oldScroll + center) - center; | ||
250 | 250 | | |||
251 | d->adjustImageOffset(AbstractImageViewPrivate::Silent); | 251 | d->adjustImageOffset(AbstractImageViewPrivate::Silent); | ||
252 | d->setScrollPos(scroll, AbstractImageViewPrivate::Silent); | 252 | d->setScrollPos(scroll, AbstractImageViewPrivate::Silent); | ||
253 | onZoomChanged(); | 253 | onZoomChanged(); | ||
254 | zoomChanged(d->mZoom); | 254 | emit zoomChanged(d->mZoom); | ||
255 | } | 255 | } | ||
256 | 256 | | |||
257 | bool AbstractImageView::zoomToFit() const | 257 | bool AbstractImageView::zoomToFit() const | ||
258 | { | 258 | { | ||
259 | return d->mZoomToFit; | 259 | return d->mZoomToFit; | ||
260 | } | 260 | } | ||
261 | 261 | | |||
262 | bool AbstractImageView::zoomToFill() const | 262 | bool AbstractImageView::zoomToFill() const | ||
263 | { | 263 | { | ||
264 | return d->mZoomToFill; | 264 | return d->mZoomToFill; | ||
265 | } | 265 | } | ||
266 | 266 | | |||
267 | void AbstractImageView::setZoomToFit(bool on) | 267 | void AbstractImageView::setZoomToFit(bool on) | ||
268 | { | 268 | { | ||
269 | d->mZoomToFit = on; | 269 | d->mZoomToFit = on; | ||
270 | if (on) { | 270 | if (on) { | ||
271 | d->mZoomToFill = false; | 271 | d->mZoomToFill = false; | ||
272 | setZoom(computeZoomToFit()); | 272 | setZoom(computeZoomToFit()); | ||
273 | } | 273 | } | ||
274 | // We do not set zoom to 1 if zoomToFit is off, this is up to the code | 274 | // We do not set zoom to 1 if zoomToFit is off, this is up to the code | ||
275 | // calling us. It may went to zoom to some other level and/or to zoom on | 275 | // calling us. It may went to zoom to some other level and/or to zoom on | ||
276 | // a particular position | 276 | // a particular position | ||
277 | zoomToFitChanged(d->mZoomToFit); | 277 | emit zoomToFitChanged(d->mZoomToFit); | ||
278 | } | 278 | } | ||
279 | 279 | | |||
280 | void AbstractImageView::setZoomToFill(bool on, const QPointF& center) | 280 | void AbstractImageView::setZoomToFill(bool on, const QPointF& center) | ||
281 | { | 281 | { | ||
282 | d->mZoomToFill = on; | 282 | d->mZoomToFill = on; | ||
283 | if (on) { | 283 | if (on) { | ||
284 | d->mZoomToFit = false; | 284 | d->mZoomToFit = false; | ||
285 | setZoom(computeZoomToFill(), center); | 285 | setZoom(computeZoomToFill(), center); | ||
286 | } | 286 | } | ||
287 | // We do not set zoom to 1 if zoomToFit is off, this is up to the code | 287 | // We do not set zoom to 1 if zoomToFit is off, this is up to the code | ||
288 | // calling us. It may went to zoom to some other level and/or to zoom on | 288 | // calling us. It may went to zoom to some other level and/or to zoom on | ||
289 | // a particular position | 289 | // a particular position | ||
290 | zoomToFillChanged(d->mZoomToFill); | 290 | emit zoomToFillChanged(d->mZoomToFill); | ||
291 | } | 291 | } | ||
292 | 292 | | |||
293 | const QPixmap& AbstractImageView::alphaBackgroundTexture() const | 293 | const QPixmap& AbstractImageView::alphaBackgroundTexture() const | ||
294 | { | 294 | { | ||
295 | return d->mAlphaBackgroundTexture; | 295 | return d->mAlphaBackgroundTexture; | ||
296 | } | 296 | } | ||
297 | 297 | | |||
298 | void AbstractImageView::resizeEvent(QGraphicsSceneResizeEvent* event) | 298 | void AbstractImageView::resizeEvent(QGraphicsSceneResizeEvent* event) | ||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | 428 | { | |||
434 | if (zoomToFit() || qFuzzyCompare(computeZoomToFit(), zoom())) { | 434 | if (zoomToFit() || qFuzzyCompare(computeZoomToFit(), zoom())) { | ||
435 | if (event->modifiers() != Qt::NoModifier) { | 435 | if (event->modifiers() != Qt::NoModifier) { | ||
436 | return; | 436 | return; | ||
437 | } | 437 | } | ||
438 | 438 | | |||
439 | switch (event->key()) { | 439 | switch (event->key()) { | ||
440 | case Qt::Key_Left: | 440 | case Qt::Key_Left: | ||
441 | case Qt::Key_Up: | 441 | case Qt::Key_Up: | ||
442 | previousImageRequested(); | 442 | emit previousImageRequested(); | ||
443 | break; | 443 | break; | ||
444 | case Qt::Key_Right: | 444 | case Qt::Key_Right: | ||
445 | case Qt::Key_Down: | 445 | case Qt::Key_Down: | ||
446 | nextImageRequested(); | 446 | emit nextImageRequested(); | ||
447 | break; | 447 | break; | ||
448 | default: | 448 | default: | ||
449 | break; | 449 | break; | ||
450 | } | 450 | } | ||
451 | return; | 451 | return; | ||
452 | } | 452 | } | ||
453 | 453 | | |||
454 | QPointF delta(0, 0); | 454 | QPointF delta(0, 0); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 496 | if (event->key() == Qt::Key_Control) { | |||
497 | d->mControlKeyIsDown = false; | 497 | d->mControlKeyIsDown = false; | ||
498 | updateCursor(); | 498 | updateCursor(); | ||
499 | } | 499 | } | ||
500 | } | 500 | } | ||
501 | 501 | | |||
502 | void AbstractImageView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) | 502 | void AbstractImageView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) | ||
503 | { | 503 | { | ||
504 | if (event->modifiers() == Qt::NoModifier && event->button() == Qt::LeftButton) { | 504 | if (event->modifiers() == Qt::NoModifier && event->button() == Qt::LeftButton) { | ||
505 | toggleFullScreenRequested(); | 505 | emit toggleFullScreenRequested(); | ||
506 | } | 506 | } | ||
507 | 507 | | |||
508 | d->checkAndRequestZoomAction(event); | 508 | d->checkAndRequestZoomAction(event); | ||
509 | } | 509 | } | ||
510 | 510 | | |||
511 | QPointF AbstractImageView::imageOffset() const | 511 | QPointF AbstractImageView::imageOffset() const | ||
512 | { | 512 | { | ||
513 | return d->mImageOffset; | 513 | return d->mImageOffset; | ||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |