~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/widgets/common/previewwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
};
108
108
 
109
109
PreviewWidget::PreviewWidget(QWidget* parent)
110
 
             : Q3ScrollView(parent), d(new PreviewWidgetPriv)
 
110
    : Q3ScrollView(parent), d(new PreviewWidgetPriv)
111
111
{
112
112
    m_movingInProgress = false;
113
113
    setAttribute(Qt::WA_DeleteOnClose);
225
225
    snapValues.append(fit);
226
226
 
227
227
    if (d->zoom < zoom)
 
228
    {
228
229
        qStableSort(snapValues);
 
230
    }
229
231
    else
 
232
    {
230
233
        qStableSort(snapValues.begin(), snapValues.end(), qGreater<double>());
 
234
    }
231
235
 
232
 
    for(QList<double>::const_iterator it = snapValues.constBegin(); it != snapValues.constEnd(); ++it)
 
236
    for (QList<double>::const_iterator it = snapValues.constBegin(); it != snapValues.constEnd(); ++it)
233
237
    {
234
238
        double z = *it;
 
239
 
235
240
        if ((d->zoom < z) && (zoom > z))
236
241
        {
237
242
            zoom = z;
259
264
void PreviewWidget::setZoomFactorSnapped(double zoom)
260
265
{
261
266
    double fit = calcAutoZoomFactor(ZoomInOrOut);
 
267
 
262
268
    if (fabs(zoom-1.0) < 0.05)
263
269
    {
264
270
        zoom = 1.0;
265
271
    }
 
272
 
266
273
    if (fabs(zoom-0.5) < 0.05)
267
274
    {
268
275
        zoom = 0.5;
269
276
    }
 
277
 
270
278
    if (fabs(zoom-fit) < 0.05)
271
279
    {
272
280
        zoom = fit;
326
334
    verticalScrollBar()->setPageStep( step * 10 );
327
335
 
328
336
    viewport()->setUpdatesEnabled(false);
 
337
 
329
338
    if (d->centerZoomPoint.isNull())
330
339
    {
331
340
        cpx = ( cpx * d->tileSize ) / floor(d->tileSize / d->zoom);
346
355
 
347
356
        setContentsPos((int)cpx, (int)(cpy));
348
357
    }
 
358
 
349
359
    viewport()->setUpdatesEnabled(true);
350
360
    viewport()->update();
351
361
 
384
394
        d->zoomWidth  = (int)(previewWidth());
385
395
        d->zoomHeight = (int)(previewHeight());
386
396
    }
 
397
 
387
398
    updateContentsSize();
388
399
    zoomFactorChanged(d->zoom);
389
400
    viewport()->update();
433
444
 
434
445
double PreviewWidget::calcAutoZoomFactor(AutoZoomMode mode)
435
446
{
436
 
    if (previewIsNull()) return d->zoom;
 
447
    if (previewIsNull())
 
448
    {
 
449
        return d->zoom;
 
450
    }
437
451
 
438
452
    double srcWidth  = previewWidth();
439
453
    double srcHeight = previewHeight();
443
457
    double zoom = qMin(dstWidth/srcWidth, dstHeight/srcHeight);
444
458
    // limit precision as above
445
459
    zoom = round(zoom * 10000.0) / 10000.0;
 
460
 
446
461
    if (mode == ZoomInOrOut)
447
462
        // fit to available space, scale up or down
 
463
    {
448
464
        return zoom;
 
465
    }
449
466
    else
450
467
        // ZoomInOnly: accept that an image is smaller than available space, don't scale up
 
468
    {
451
469
        return qMin(1.0, zoom);
 
470
    }
452
471
}
453
472
 
454
473
void PreviewWidget::updateContentsSize()
484
503
 
485
504
void PreviewWidget::resizeEvent(QResizeEvent* e)
486
505
{
487
 
    if (!e) return;
 
506
    if (!e)
 
507
    {
 
508
        return;
 
509
    }
488
510
 
489
511
    Q3ScrollView::resizeEvent(e);
490
512
 
491
513
    if (d->autoZoom)
 
514
    {
492
515
        updateAutoZoom();
 
516
    }
493
517
 
494
518
    updateContentsSize();
495
519
 
543
567
            for (int i = x1 ; i < x2 ; i += d->tileSize)
544
568
            {
545
569
                QString key  = QString("%1,%2").arg(i).arg(j);
546
 
                QPixmap *pix = d->tileCache.object(key);
 
570
                QPixmap* pix = d->tileCache.object(key);
547
571
 
548
572
                if (!pix)
549
573
                {
617
641
void PreviewWidget::contentsMouseDoubleClickEvent(QMouseEvent* e)
618
642
{
619
643
    if (!e || e->button() == Qt::RightButton)
 
644
    {
620
645
        return;
 
646
    }
621
647
 
622
648
    if (e->button() == Qt::LeftButton)
623
649
    {
624
650
        emit signalLeftButtonDoubleClicked();
 
651
 
625
652
        if (!KGlobalSettings::singleClick())
 
653
        {
626
654
            emit signalActivated();
 
655
        }
627
656
    }
628
657
}
629
658
 
654
683
void PreviewWidget::contentsMousePressEvent(QMouseEvent* e)
655
684
{
656
685
    if (!e || e->button() == Qt::RightButton)
 
686
    {
657
687
        return;
 
688
    }
658
689
 
659
690
    m_movingInProgress = false;
660
691
 
661
692
    if (e->button() == Qt::LeftButton || e->button() == Qt::MidButton)
662
693
    {
663
694
        d->mousePressPos = e->pos();
 
695
 
664
696
        if (!KGlobalSettings::singleClick() || e->button() == Qt::MidButton)
 
697
        {
665
698
            startPanning(e->pos());
 
699
        }
666
700
 
667
701
        return;
668
702
    }
672
706
 
673
707
void PreviewWidget::contentsMouseMoveEvent(QMouseEvent* e)
674
708
{
675
 
    if (!e) return;
 
709
    if (!e)
 
710
    {
 
711
        return;
 
712
    }
676
713
 
677
714
    if (((e->buttons() & Qt::LeftButton) || (e->buttons() & Qt::MidButton)) && !d->mousePressPos.isNull())
678
715
    {
679
716
        if (!m_movingInProgress && (e->buttons() & Qt::LeftButton))
680
717
        {
681
718
            if ((d->mousePressPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
 
719
            {
682
720
                startPanning(d->mousePressPos);
 
721
            }
683
722
        }
684
723
 
685
724
        if (m_movingInProgress)
691
730
 
692
731
void PreviewWidget::contentsMouseReleaseEvent(QMouseEvent* e)
693
732
{
694
 
    if (!e) return;
 
733
    if (!e)
 
734
    {
 
735
        return;
 
736
    }
695
737
 
696
738
    if ((e->button() == Qt::LeftButton || e->button() == Qt::MidButton) && !d->mousePressPos.isNull())
697
739
    {
698
740
        if (!m_movingInProgress && e->button() == Qt::LeftButton)
699
741
        {
700
742
            emit signalLeftButtonClicked();
 
743
 
701
744
            if (KGlobalSettings::singleClick())
 
745
            {
702
746
                emit signalActivated();
 
747
            }
703
748
        }
704
749
        else
705
750
        {
723
768
    if (e->modifiers() & Qt::ShiftModifier)
724
769
    {
725
770
        if (e->delta() < 0)
 
771
        {
726
772
            emit signalShowNextImage();
 
773
        }
727
774
        else if (e->delta() > 0)
 
775
        {
728
776
            emit signalShowPrevImage();
 
777
        }
 
778
 
729
779
        return;
730
780
    }
731
781
    else if (e->modifiers() & Qt::ControlModifier)
732
782
    {
733
783
        // When zooming with the mouse-wheel, the image center is kept fixed.
734
784
        d->centerZoomPoint = e->pos();
 
785
 
735
786
        if (e->delta() < 0 && !minZoom())
 
787
        {
736
788
            slotDecreaseZoom();
 
789
        }
737
790
        else if (e->delta() > 0 && !maxZoom())
 
791
        {
738
792
            slotIncreaseZoom();
 
793
        }
 
794
 
739
795
        d->centerZoomPoint = QPoint();
740
796
        return;
741
797
    }
758
814
    }
759
815
 
760
816
    d->panIconPopup    = new KPopupFrame(this);
761
 
    PanIconWidget *pan = new PanIconWidget(d->panIconPopup);
 
817
    PanIconWidget* pan = new PanIconWidget(d->panIconPopup);
762
818
 
763
819
    connect(pan, SIGNAL(signalSelectionTakeFocus()),
764
820
            this, SIGNAL(signalContentTakeFocus()));
821
877
 
822
878
void PreviewWidget::keyPressEvent(QKeyEvent* e)
823
879
{
824
 
    if (!e) return;
 
880
    if (!e)
 
881
    {
 
882
        return;
 
883
    }
825
884
 
826
885
    int mult = 1;
 
886
 
827
887
    if ( (e->modifiers() & Qt::ControlModifier))
 
888
    {
828
889
        mult = 10;
 
890
    }
829
891
 
830
892
    switch ( e->key() )
831
893
    {
867
929
 
868
930
void PreviewWidget::keyReleaseEvent(QKeyEvent* e)
869
931
{
870
 
    if (!e) return;
 
932
    if (!e)
 
933
    {
 
934
        return;
 
935
    }
871
936
 
872
937
    switch ( e->key() )
873
938
    {