~ubuntu-branches/debian/sid/qpdfview/sid

« back to all changes in this revision

Viewing changes to sources/presentationview.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2014-10-22 21:49:15 UTC
  • mfrom: (1.2.15)
  • Revision ID: package-import@ubuntu.com-20141022214915-agqeoe318lzs2s4d
Tags: 0.4.12-1
* New upstream release.
* Fixed option to zoom to selection and implemented tiled rendering
  (Closes: #739554)
* Enable support for qt5 and poppler-qt5.
* Explicit dependence on hicolor-icon-theme.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
    m_prefetchTimer->setSingleShot(true);
76
76
 
77
77
    connect(this, SIGNAL(currentPageChanged(int)), m_prefetchTimer, SLOT(start()));
 
78
    connect(this, SIGNAL(scaleModeChanged(ScaleMode)), m_prefetchTimer, SLOT(start()));
 
79
    connect(this, SIGNAL(scaleFactorChanged(qreal)), m_prefetchTimer, SLOT(start()));
78
80
    connect(this, SIGNAL(rotationChanged(Rotation)), m_prefetchTimer, SLOT(start()));
 
81
    connect(this, SIGNAL(invertColorsChanged(bool)), m_prefetchTimer, SLOT(start()));
79
82
 
80
83
    connect(m_prefetchTimer, SIGNAL(timeout()), SLOT(on_prefetch_timeout()));
81
84
 
134
137
 
135
138
void PresentationView::setScaleFactor(qreal scaleFactor)
136
139
{
137
 
    if(!qFuzzyCompare(m_scaleFactor, scaleFactor) && scaleFactor >= Defaults::DocumentView::minimumScaleFactor() && scaleFactor <= Defaults::DocumentView::maximumScaleFactor())
 
140
    if(!qFuzzyCompare(m_scaleFactor, scaleFactor)
 
141
            && scaleFactor >= s_settings->documentView().minimumScaleFactor()
 
142
            && scaleFactor <= s_settings->documentView().maximumScaleFactor())
138
143
    {
139
144
        m_scaleFactor = scaleFactor;
140
145
 
256
261
{
257
262
    if(scaleMode() != ScaleFactorMode)
258
263
    {
259
 
        setScaleFactor(qMin(m_pageItems.at(m_currentPage - 1)->scaleFactor() + Defaults::DocumentView::zoomBy(), Defaults::DocumentView::maximumScaleFactor()));
 
264
        setScaleFactor(qMin(m_pageItems.at(m_currentPage - 1)->scaleFactor() * s_settings->documentView().zoomFactor(),
 
265
                            s_settings->documentView().maximumScaleFactor()));
 
266
 
260
267
        setScaleMode(ScaleFactorMode);
261
268
    }
262
269
    else
263
270
    {
264
 
        setScaleFactor(qMin(m_scaleFactor + Defaults::DocumentView::zoomBy(), Defaults::DocumentView::maximumScaleFactor()));
 
271
        setScaleFactor(qMin(m_scaleFactor * s_settings->documentView().zoomFactor(),
 
272
                            s_settings->documentView().maximumScaleFactor()));
265
273
    }
266
274
}
267
275
 
269
277
{
270
278
    if(scaleMode() != ScaleFactorMode)
271
279
    {
272
 
        setScaleFactor(qMax(m_pageItems.at(m_currentPage - 1)->scaleFactor() - Defaults::DocumentView::zoomBy(), Defaults::DocumentView::minimumScaleFactor()));
 
280
        setScaleFactor(qMax(m_pageItems.at(m_currentPage - 1)->scaleFactor() / s_settings->documentView().zoomFactor(),
 
281
                            s_settings->documentView().minimumScaleFactor()));
 
282
 
273
283
        setScaleMode(ScaleFactorMode);
274
284
    }
275
285
    else
276
286
    {
277
 
        setScaleFactor(qMax(m_scaleFactor - Defaults::DocumentView::zoomBy(), Defaults::DocumentView::minimumScaleFactor()));
 
287
        setScaleFactor(qMax(m_scaleFactor / s_settings->documentView().zoomFactor(),
 
288
                            s_settings->documentView().minimumScaleFactor()));
278
289
    }
279
290
}
280
291
 
334
345
    fromPage = qMax(fromPage, 1);
335
346
    toPage = qMin(toPage, m_pages.count());
336
347
 
337
 
    for(int index = fromPage - 1; index <= toPage - 1; ++index)
338
 
    {
339
 
        m_pageItems.at(index)->startRender(true);
340
 
    }
341
 
}
342
 
 
343
 
void PresentationView::on_pages_linkClicked(int page, qreal left, qreal top)
344
 
{
 
348
    const int maxCost = toPage - fromPage + 1;
 
349
    int cost = 0;
 
350
 
 
351
    for(int index = m_currentPage - 1; index <= toPage - 1; ++index)
 
352
    {
 
353
        cost += m_pageItems.at(index)->startRender(true);
 
354
 
 
355
        if(cost >= maxCost)
 
356
        {
 
357
            return;
 
358
        }
 
359
    }
 
360
 
 
361
    for(int index = m_currentPage - 1; index >= fromPage - 1; --index)
 
362
    {
 
363
        cost += m_pageItems.at(index)->startRender(true);
 
364
 
 
365
        if(cost >= maxCost)
 
366
        {
 
367
            return;
 
368
        }
 
369
    }
 
370
}
 
371
 
 
372
void PresentationView::on_pages_cropRectChanged()
 
373
{
 
374
    prepareScene();
 
375
    prepareView();
 
376
}
 
377
 
 
378
void PresentationView::on_pages_linkClicked(bool newTab, int page, qreal left, qreal top)
 
379
{
 
380
    Q_UNUSED(newTab);
345
381
    Q_UNUSED(left);
346
382
    Q_UNUSED(top);
347
383
 
512
548
        scene()->addItem(page);
513
549
        m_pageItems.append(page);
514
550
 
515
 
        connect(page, SIGNAL(linkClicked(int,qreal,qreal)), SLOT(on_pages_linkClicked(int,qreal,qreal)));
 
551
        connect(page, SIGNAL(cropRectChanged()), SLOT(on_pages_cropRectChanged()));
 
552
 
 
553
        connect(page, SIGNAL(linkClicked(bool,int,qreal,qreal)), SLOT(on_pages_linkClicked(bool,int,qreal,qreal)));
516
554
    }
517
555
}
518
556
 
535
573
 
536
574
void PresentationView::prepareScene()
537
575
{
538
 
    for(int index = 0; index < m_pageItems.count(); ++index)
 
576
    const qreal visibleWidth = viewport()->width();
 
577
    const qreal visibleHeight = viewport()->height();
 
578
 
 
579
    foreach(PageItem* page, m_pageItems)
539
580
    {
540
 
        PageItem* page = m_pageItems.at(index);
541
 
 
542
581
#if QT_VERSION >= QT_VERSION_CHECK(5,1,0)
543
582
 
544
583
        page->setDevicePixelRatio(devicePixelRatio());
547
586
 
548
587
        page->setResolution(logicalDpiX(), logicalDpiY());
549
588
 
550
 
        const qreal visibleWidth = viewport()->width();
551
 
        const qreal visibleHeight = viewport()->height();
552
 
 
553
 
        qreal pageWidth = 0.0;
554
 
        qreal pageHeight = 0.0;
555
 
 
556
 
        switch(m_rotation)
557
 
        {
558
 
        default:
559
 
        case RotateBy0:
560
 
        case RotateBy180:
561
 
            pageWidth = logicalDpiX() / 72.0 * page->size().width();
562
 
            pageHeight = logicalDpiY() / 72.0 * page->size().height();
563
 
            break;
564
 
        case RotateBy90:
565
 
        case RotateBy270:
566
 
            pageWidth = logicalDpiX() / 72.0 * page->size().height();
567
 
            pageHeight = logicalDpiY() / 72.0 * page->size().width();
568
 
            break;
569
 
        }
 
589
        page->setRotation(m_rotation);
 
590
 
 
591
        const qreal displayedWidth = page->displayedWidth();
 
592
        const qreal displayedHeight = page->displayedHeight();
570
593
 
571
594
        switch(m_scaleMode)
572
595
        {
575
598
            page->setScaleFactor(m_scaleFactor);
576
599
            break;
577
600
        case FitToPageWidthMode:
578
 
            page->setScaleFactor(visibleWidth / pageWidth);
 
601
            page->setScaleFactor(visibleWidth / displayedWidth);
579
602
            break;
580
603
        case FitToPageSizeMode:
581
 
            page->setScaleFactor(qMin(visibleWidth / pageWidth, visibleHeight / pageHeight));
 
604
            page->setScaleFactor(qMin(visibleWidth / displayedWidth, visibleHeight / displayedHeight));
582
605
            break;
583
606
        }
584
 
 
585
 
        page->setRotation(m_rotation);
586
607
    }
587
608
}
588
609