7
7
* Description : a widget to display an image preview
9
* Copyright (C) 2006-2007 Gilles Caulier <caulier dot gilles at gmail dot com>
9
* Copyright (C) 2006-2008 Gilles Caulier <caulier dot gilles at gmail dot com>
11
11
* This program is free software; you can redistribute it
12
12
* and/or modify it under the terms of the GNU General
103
103
d = new PreviewWidgetPriv;
104
104
d->bgColor.setRgb(0, 0, 0);
105
105
m_movingInProgress = false;
107
107
viewport()->setBackgroundMode(Qt::NoBackground);
108
108
viewport()->setMouseTracking(false);
188
188
return (d->zoom <= d->minZoom);
191
double PreviewWidget::snapZoom(double zoom)
193
// If the zoom value gets changed from d->zoom to zoom
194
// across 50%, 100% or fit-to-window, then return the
195
// the corresponding special value. Otherwise zoom is returned unchanged.
196
double fit = calcAutoZoomFactor(ZoomInOrOut);
197
QValueList<double> snapValues;
198
snapValues.append(0.5);
199
snapValues.append(1.0);
200
snapValues.append(fit);
201
qHeapSort(snapValues);
202
QValueList<double>::const_iterator it;
206
for(it = snapValues.constBegin(); it != snapValues.constEnd(); ++it)
209
if ((d->zoom < z) && (zoom > z))
218
for(it = snapValues.constEnd(); it != snapValues.constBegin(); --it)
221
if ((d->zoom > z) && (zoom < z))
191
232
void PreviewWidget::slotIncreaseZoom()
193
234
double zoom = d->zoom * d->zoomMultiplier;
194
setZoomFactor(zoom > zoomMax() ? zoomMax() : zoom);
235
zoom = snapZoom(zoom > zoomMax() ? zoomMax() : zoom);
197
239
void PreviewWidget::slotDecreaseZoom()
199
241
double zoom = d->zoom / d->zoomMultiplier;
200
setZoomFactor(zoom < zoomMin() ? zoomMin() : zoom);
242
zoom = snapZoom(zoom < zoomMin() ? zoomMin() : zoom);
246
void PreviewWidget::setZoomFactorSnapped(double zoom)
248
double fit = calcAutoZoomFactor(ZoomInOrOut);
249
if (fabs(zoom-1.0) < 0.05)
253
if (fabs(zoom-0.5) < 0.05)
257
if (fabs(zoom-fit) < 0.05)
203
265
void PreviewWidget::setZoomFactor(double zoom)
267
setZoomFactor(zoom, false);
270
void PreviewWidget::setZoomFactor(double zoom, bool centerView)
205
272
// Zoom using center of canvas and given zoom factor.
207
274
double oldZoom = d->zoom;
209
277
if (d->centerZoomPoint.isNull())
211
279
// center on current center
293
369
viewport()->update();
372
void PreviewWidget::toggleFitToWindowOr100()
374
// If the current zoom is 100%, then fit to window.
381
setZoomFactor(1.0, true);
296
385
void PreviewWidget::updateAutoZoom(AutoZoomMode mode)
298
387
d->zoom = calcAutoZoomFactor(mode);
531
620
else if (e->state() & Qt::ControlButton)
622
// When zooming with the mouse-wheel, the image center is kept fixed.
533
623
d->centerZoomPoint = e->pos();
534
624
if (e->delta() < 0 && !minZoom())
535
625
slotDecreaseZoom();