~ubuntu-branches/debian/wheezy/qpdfview/wheezy

« back to all changes in this revision

Viewing changes to sources/documentview.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2012-07-01 18:16:12 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120701181612-lk31wf664hvjoj63
Tags: 0.3.1-1
* Upstream resolved license incompatibility issues.
* Added German translation.
* Changed hotkeys for scaling. (Closes: #677448)
  Thanks to jidanni@jidanni.org
* Fixed several bugs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    m_index(-1),
47
47
    m_scale(1.0),
48
48
    m_links(),
49
 
    m_highlight(),
50
49
    m_rubberBand(),
51
50
    m_size(),
52
51
    m_linkTransform(),
89
88
 
90
89
    parent->m_documentMutex.unlock();
91
90
 
92
 
    painter->drawImage(boundingRect(), image);
 
91
    painter->drawImage(0.0, 0.0, image);
93
92
 
94
93
#else
95
94
 
102
101
        DocumentView::PageCacheValue& value = parent->m_pageCache[key];
103
102
 
104
103
        value.time = QTime::currentTime();
105
 
        painter->drawImage(boundingRect(), value.image);
 
104
        painter->drawImage(0.0, 0.0, value.image);
106
105
    }
107
106
    else
108
107
    {
109
108
        if(!m_render.isRunning())
110
109
        {
111
 
            m_render = QtConcurrent::run(this, &DocumentView::PageItem::render, false);
 
110
            m_render = QtConcurrent::run(this, &DocumentView::PageItem::render, m_scale, false);
112
111
        }
113
112
    }
114
113
 
136
135
        painter->restore();
137
136
    }
138
137
 
139
 
    // selections
 
138
    // highlights
140
139
 
141
140
    painter->save();
142
141
 
143
142
    painter->setTransform(m_highlightTransform, true);
144
 
    painter->setPen(QPen(QColor(0, 0, 255)));
145
 
 
146
 
    if(!m_highlight.isNull())
147
 
    {
148
 
        painter->drawRect(m_highlight);
149
 
        painter->fillRect(m_highlight, QBrush(QColor(0, 0, 255, 127)));
150
 
    }
151
143
 
152
144
    if(parent->m_highlightAll)
153
145
    {
159
151
 
160
152
    painter->restore();
161
153
 
 
154
    // rubber band
 
155
 
162
156
    if(!m_rubberBand.isNull())
163
157
    {
164
158
        painter->setPen(QPen(Qt::DashLine));
166
160
    }
167
161
}
168
162
 
 
163
void DocumentView::PageItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
 
164
{
 
165
    Q_UNUSED(event);
 
166
}
 
167
 
169
168
void DocumentView::PageItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
170
169
{
171
170
    DocumentView* parent = qobject_cast< DocumentView* >(scene()->parent()); Q_ASSERT(parent);
194
193
    QToolTip::hideText();
195
194
}
196
195
 
 
196
void DocumentView::PageItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
 
197
{
 
198
    Q_UNUSED(event);
 
199
}
 
200
 
197
201
void DocumentView::PageItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
198
202
{
199
203
    DocumentView* parent = qobject_cast< DocumentView* >(scene()->parent()); Q_ASSERT(parent);
237
241
            event->ignore();
238
242
        }
239
243
    }
240
 
    else if(event->button() == Qt::MidButton)
241
 
    {
242
 
        m_highlight = QRectF();
243
 
 
244
 
        update(boundingRect());
245
 
 
246
 
        event->accept();
247
 
    }
248
244
    else
249
245
    {
250
246
        event->ignore();
275
271
    {
276
272
        m_rubberBand.setBottomRight(event->pos());
277
273
 
278
 
        m_highlight = m_highlightTransform.inverted().mapRect(m_rubberBand.normalized()).adjusted(-1.0, -1.0, 1.0, 1.0);
 
274
        m_rubberBand = m_rubberBand.normalized();
279
275
 
280
276
        // copy text or image
281
277
 
290
286
        {
291
287
            parent->m_documentMutex.lock();
292
288
 
293
 
            QString text = m_page->text(m_highlight);
 
289
            QString text = m_page->text(m_highlightTransform.inverted().mapRect(m_rubberBand));
294
290
 
295
291
            parent->m_documentMutex.unlock();
296
292
 
325
321
    }
326
322
}
327
323
 
328
 
void DocumentView::PageItem::render(bool prefetch)
 
324
void DocumentView::PageItem::render(qreal scale, bool prefetch)
329
325
{
330
326
    DocumentView* parent = qobject_cast< DocumentView* >(scene()->parent()); Q_ASSERT(parent);
331
327
 
361
357
    document->setRenderHint(Poppler::Document::TextAntialiasing, renderHints.testFlag(Poppler::Document::TextAntialiasing));
362
358
    document->setRenderHint(Poppler::Document::TextHinting, renderHints.testFlag(Poppler::Document::TextHinting));
363
359
 
364
 
    QImage image = page->renderToImage(m_scale * parent->m_resolutionX, m_scale * parent->m_resolutionY);
 
360
    QImage image = page->renderToImage(scale * parent->m_resolutionX, scale * parent->m_resolutionY);
365
361
 
366
362
    delete page;
367
363
    delete document;
370
366
 
371
367
    parent->m_documentMutex.lock();
372
368
 
373
 
    QImage image = m_page->renderToImage(m_scale * parent->m_resolutionX, m_scale * parent->m_resolutionY);
 
369
    QImage image = m_page->renderToImage(scale * parent->m_resolutionX, scale * parent->m_resolutionY);
374
370
 
375
371
    parent->m_documentMutex.unlock();
376
372
 
377
373
#endif
378
374
 
379
 
    DocumentView::PageCacheKey key(m_index, m_scale * parent->m_resolutionX, m_scale * parent->m_resolutionY);
 
375
    DocumentView::PageCacheKey key(m_index, scale * parent->m_resolutionX, scale * parent->m_resolutionY);
380
376
    DocumentView::PageCacheValue value(image);
381
377
 
382
378
    parent->updatePageCache(key, value);
383
379
 
384
 
    emit parent->pageItemChanged(this);
 
380
    emit parent->pageItemChanged(m_index);
385
381
}
386
382
 
387
383
// thumbnail item
428
424
 
429
425
    parent->m_documentMutex.unlock();
430
426
 
431
 
    painter->drawImage(boundingRect(), image);
 
427
    painter->drawImage(0.0, 0.0, image);
432
428
 
433
429
#else
434
430
 
441
437
        DocumentView::PageCacheValue& value = parent->m_pageCache[key];
442
438
 
443
439
        value.time = QTime::currentTime();
444
 
        painter->drawImage(boundingRect(), value.image);
 
440
        painter->drawImage(0.0, 0.0, value.image);
445
441
    }
446
442
    else
447
443
    {
448
444
        if(!m_render.isRunning())
449
445
        {
450
 
            m_render = QtConcurrent::run(this, &DocumentView::ThumbnailItem::render);
 
446
            m_render = QtConcurrent::run(this, &DocumentView::ThumbnailItem::render, m_scale);
451
447
        }
452
448
    }
453
449
 
466
462
    parent->setCurrentPage(m_index + 1);
467
463
}
468
464
 
469
 
void DocumentView::ThumbnailItem::render()
 
465
void DocumentView::ThumbnailItem::render(qreal scale)
470
466
{
471
467
    DocumentView* parent = qobject_cast< DocumentView* >(scene()->parent()); Q_ASSERT(parent);
472
468
 
502
498
    document->setRenderHint(Poppler::Document::TextAntialiasing, renderHints.testFlag(Poppler::Document::TextAntialiasing));
503
499
    document->setRenderHint(Poppler::Document::TextHinting, renderHints.testFlag(Poppler::Document::TextHinting));
504
500
 
505
 
    QImage image = page->renderToImage(m_scale * parent->physicalDpiX(), m_scale * parent->physicalDpiY());
 
501
    QImage image = page->renderToImage(scale * parent->physicalDpiX(), scale * parent->physicalDpiY());
506
502
 
507
503
    delete page;
508
504
    delete document;
511
507
 
512
508
    parent->m_documentMutex.lock();
513
509
 
514
 
    QImage image = m_page->renderToImage(m_scale * parent->physicalDpiX(), m_scale * parent->physicalDpiY());
 
510
    QImage image = m_page->renderToImage(scale * parent->physicalDpiX(), scale * parent->physicalDpiY());
515
511
 
516
512
    parent->m_documentMutex.unlock();
517
513
 
518
514
#endif
519
515
 
520
 
    DocumentView::PageCacheKey key(m_index, m_scale * parent->physicalDpiX(), m_scale * parent->physicalDpiY());
 
516
    DocumentView::PageCacheKey key(m_index, scale * parent->physicalDpiX(), scale * parent->physicalDpiY());
521
517
    DocumentView::PageCacheValue value(image);
522
518
 
523
519
    parent->updatePageCache(key, value);
524
520
 
525
 
    emit parent->thumbnailItemChanged(this);
 
521
    emit parent->thumbnailItemChanged(m_index);
526
522
}
527
523
 
528
524
// document view
544
540
    m_highlightAll(false),
545
541
    m_pagesByIndex(),
546
542
    m_pagesByHeight(),
 
543
    m_thumbnailsByIndex(),
547
544
    m_resolutionX(72.0),
548
545
    m_resolutionY(72.0),
549
546
    m_pageTransform(),
554
551
    m_search(),
555
552
    m_print()
556
553
{
557
 
    connect(this, SIGNAL(pageItemChanged(PageItem*)), SLOT(slotUpdatePageItem(PageItem*)));
558
 
    connect(this, SIGNAL(thumbnailItemChanged(ThumbnailItem*)), SLOT(slotUpdateThumbnailItem(ThumbnailItem*)));
 
554
    connect(this, SIGNAL(pageItemChanged(int)), SLOT(slotUpdatePageItem(int)));
 
555
    connect(this, SIGNAL(thumbnailItemChanged(int)), SLOT(slotUpdateThumbnailItem(int)));
 
556
 
 
557
    connect(this, SIGNAL(currentPageChanged(int)), SLOT(slotThumbnailsEnsureVisible(int)));
559
558
 
560
559
    connect(this, SIGNAL(firstResultFound()), SLOT(findNext()));
561
560
 
576
575
    m_view = new QGraphicsView(m_scene, this);
577
576
    m_view->setDragMode(QGraphicsView::ScrollHandDrag);
578
577
 
 
578
    m_view->setAcceptDrops(false);
 
579
 
579
580
    setFocusProxy(m_view);
580
581
 
581
582
    // highlight
664
665
 
665
666
DocumentView::~DocumentView()
666
667
{
667
 
    m_scene->clear();
668
 
    m_thumbnailsGraphicsView->scene()->clear();
 
668
    clearScene();
669
669
 
670
670
    m_search.cancel();
671
671
    m_search.waitForFinished();
869
869
    return fontsTableWidget;
870
870
}
871
871
 
 
872
void DocumentView::clearBookmarks()
 
873
{
 
874
    m_bookmarksMenu->clearList();
 
875
}
 
876
 
872
877
bool DocumentView::open(const QString& filePath)
873
878
{
 
879
    m_prefetchTimer->blockSignals(true);
 
880
 
874
881
    Poppler::Document* document = Poppler::Document::load(filePath);
875
882
 
876
883
    if(document != 0)
877
884
    {
878
885
        if(document->isLocked())
879
886
        {
880
 
            QString password = QInputDialog::getText(0, tr("Password"), tr("Please enter the password required to unlock the document file \"%1\".").arg(QFileInfo(filePath).completeBaseName()), QLineEdit::Password);
 
887
            QString password = QInputDialog::getText(0, tr("Password"), tr("Please enter the password required to unlock the document file \"%1\".").arg(filePath), QLineEdit::Password);
881
888
 
882
889
            if(document->unlock(password.toLatin1(), password.toLatin1()))
883
890
            {
932
939
        prepareOutline();
933
940
        prepareMetaInformation();
934
941
        prepareThumbnails();
935
 
    }
936
942
 
937
 
    if(m_document != 0)
938
 
    {
939
943
        m_document->setRenderHint(Poppler::Document::Antialiasing, m_settings.value("documentView/antialiasing", true).toBool());
940
944
        m_document->setRenderHint(Poppler::Document::TextAntialiasing, m_settings.value("documentView/textAntialiasing", true).toBool());
941
945
        m_document->setRenderHint(Poppler::Document::TextHinting, m_settings.value("documentView/textHinting", false).toBool());
942
 
    }
943
 
 
944
 
    clearPageCache();
945
 
 
946
 
    prepareScene();
947
 
    prepareView();
948
 
 
949
 
    if(m_settings.value("documentView/prefetch").toBool())
950
 
    {
951
 
        m_prefetchTimer->blockSignals(false);
952
 
        m_prefetchTimer->start();
953
 
    }
954
 
    else
955
 
    {
956
 
        m_prefetchTimer->blockSignals(true);
 
946
 
 
947
        clearPageCache();
 
948
 
 
949
        prepareScene();
 
950
        prepareView();
 
951
 
 
952
        if(m_settings.value("documentView/prefetch").toBool())
 
953
        {
 
954
            m_prefetchTimer->blockSignals(false);
 
955
            m_prefetchTimer->start();
 
956
        }
957
957
    }
958
958
 
959
959
    return document != 0;
961
961
 
962
962
bool DocumentView::refresh()
963
963
{
 
964
    m_prefetchTimer->blockSignals(true);
 
965
 
964
966
    Poppler::Document* document = Poppler::Document::load(m_filePath);
965
967
 
966
968
    if(document != 0)
967
969
    {
968
970
        if(document->isLocked())
969
971
        {
970
 
            QString password = QInputDialog::getText(0, tr("Password"), tr("Please enter the password required to unlock the document file \"%1\".").arg(QFileInfo(m_filePath).completeBaseName()), QLineEdit::Password);
 
972
            QString password = QInputDialog::getText(0, tr("Password"), tr("Please enter the password required to unlock the document file \"%1\".").arg(m_filePath), QLineEdit::Password);
971
973
 
972
974
            if(document->unlock(password.toLatin1(), password.toLatin1()))
973
975
            {
1011
1013
        prepareOutline();
1012
1014
        prepareMetaInformation();
1013
1015
        prepareThumbnails();
1014
 
    }
1015
1016
 
1016
 
    if(m_document != 0)
1017
 
    {
1018
1017
        m_document->setRenderHint(Poppler::Document::Antialiasing, m_settings.value("documentView/antialiasing", true).toBool());
1019
1018
        m_document->setRenderHint(Poppler::Document::TextAntialiasing, m_settings.value("documentView/textAntialiasing", true).toBool());
1020
1019
        m_document->setRenderHint(Poppler::Document::TextHinting, m_settings.value("documentView/textHinting", false).toBool());
1021
 
    }
1022
 
 
1023
 
    clearPageCache();
1024
 
 
1025
 
    prepareScene();
1026
 
    prepareView();
1027
 
 
1028
 
    if(m_settings.value("documentView/prefetch").toBool())
1029
 
    {
1030
 
        m_prefetchTimer->blockSignals(false);
1031
 
        m_prefetchTimer->start();
1032
 
    }
1033
 
    else
1034
 
    {
1035
 
        m_prefetchTimer->blockSignals(true);
 
1020
 
 
1021
        clearPageCache();
 
1022
 
 
1023
        prepareScene();
 
1024
        prepareView();
 
1025
 
 
1026
        if(m_settings.value("documentView/prefetch").toBool())
 
1027
        {
 
1028
            m_prefetchTimer->blockSignals(false);
 
1029
            m_prefetchTimer->start();
 
1030
        }
1036
1031
    }
1037
1032
 
1038
1033
    return document != 0;
1042
1037
{
1043
1038
    if(m_document != 0)
1044
1039
    {
1045
 
            Poppler::PDFConverter* converter = m_document->pdfConverter();
1046
 
 
1047
 
            converter->setOutputFileName(filePath);
1048
 
 
1049
 
            bool success = converter->convert();
1050
 
 
1051
 
            delete converter;
1052
 
 
1053
 
            return success;
 
1040
        m_documentMutex.lock();
 
1041
 
 
1042
        Poppler::PDFConverter* converter = m_document->pdfConverter();
 
1043
 
 
1044
        converter->setOutputFileName(filePath);
 
1045
 
 
1046
        bool success = converter->convert();
 
1047
 
 
1048
        delete converter;
 
1049
 
 
1050
        m_documentMutex.unlock();
 
1051
 
 
1052
        return success;
1054
1053
    }
1055
1054
 
1056
1055
    return false;
1072
1071
            case OneColumn:
1073
1072
                if(m_currentPage != currentPage)
1074
1073
                {
 
1074
                    m_bookmarksMenu->setReturnPosition(m_currentPage, m_view->verticalScrollBar()->value());
 
1075
 
1075
1076
                    m_currentPage = currentPage;
1076
1077
 
1077
1078
                    prepareView(top);
1088
1089
            case TwoColumns:
1089
1090
                if(m_currentPage != (currentPage % 2 != 0 ? currentPage : currentPage - 1))
1090
1091
                {
 
1092
                    m_bookmarksMenu->setReturnPosition(m_currentPage, m_view->verticalScrollBar()->value());
 
1093
 
1091
1094
                    m_currentPage = currentPage % 2 != 0 ? currentPage : currentPage - 1;
1092
1095
 
1093
1096
                    prepareView(top);
1521
1524
    {
1522
1525
        QKeyEvent* keyEvent = static_cast< QKeyEvent* >(event);
1523
1526
 
1524
 
        if(keyEvent->key() == Qt::Key_PageUp || keyEvent->key() == Qt::Key_PageDown)
 
1527
        if(keyEvent->modifiers() == Qt::NoModifier && (keyEvent->key() == Qt::Key_PageUp || keyEvent->key() == Qt::Key_PageDown))
1525
1528
        {
1526
1529
            keyPressEvent(keyEvent);
1527
1530
 
1567
1570
 
1568
1571
void DocumentView::keyPressEvent(QKeyEvent* event)
1569
1572
{
1570
 
    if(event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Backspace)
 
1573
    if(event->modifiers() == Qt::NoModifier && (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Backspace))
1571
1574
    {
1572
1575
        switch(m_pageLayout)
1573
1576
        {
1574
1577
        case OnePage:
1575
1578
        case TwoPages:
1576
 
            if(m_view->verticalScrollBar()->value() - m_view->verticalScrollBar()->pageStep() < m_view->verticalScrollBar()->minimum() && m_currentPage > 1)
 
1579
            if(m_view->verticalScrollBar()->value() == m_view->verticalScrollBar()->minimum() && m_currentPage > 1)
1577
1580
            {
1578
1581
                previousPage();
1579
1582
 
1580
1583
                m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->maximum());
1581
1584
            }
 
1585
            else if(m_view->verticalScrollBar()->value() - m_view->verticalScrollBar()->pageStep() < m_view->verticalScrollBar()->minimum())
 
1586
            {
 
1587
                m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->minimum());
 
1588
            }
1582
1589
            else
1583
1590
            {
1584
1591
                m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->value() - m_view->verticalScrollBar()->pageStep());
1592
1599
            break;
1593
1600
        }
1594
1601
    }
1595
 
    else if(event->key() == Qt::Key_PageDown || event->key() == Qt::Key_Space)
 
1602
    else if(event->modifiers() == Qt::NoModifier && (event->key() == Qt::Key_PageDown || event->key() == Qt::Key_Space))
1596
1603
    {
1597
1604
        int lastPage = -1;
1598
1605
 
1610
1617
        {
1611
1618
        case OnePage:
1612
1619
        case TwoPages:
1613
 
            if(m_view->verticalScrollBar()->value() + m_view->verticalScrollBar()->pageStep() > m_view->verticalScrollBar()->maximum() && m_currentPage < lastPage)
 
1620
            if(m_view->verticalScrollBar()->value() == m_view->verticalScrollBar()->maximum() && m_currentPage < lastPage)
1614
1621
            {
1615
1622
                nextPage();
1616
1623
 
1617
1624
                m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->minimum());
1618
1625
            }
 
1626
            else if(m_view->verticalScrollBar()->value() + m_view->verticalScrollBar()->pageStep() > m_view->verticalScrollBar()->maximum())
 
1627
            {
 
1628
                m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->maximum());
 
1629
            }
1619
1630
            else
1620
1631
            {
1621
1632
                m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->value() + m_view->verticalScrollBar()->pageStep());
1715
1726
    }
1716
1727
}
1717
1728
 
1718
 
void DocumentView::slotUpdatePageItem(PageItem* pageItem)
 
1729
void DocumentView::slotUpdatePageItem(int index)
1719
1730
{
 
1731
    PageItem* pageItem = m_pagesByIndex.value(index, 0);
 
1732
 
1720
1733
    if(pageItem != 0)
1721
1734
    {
1722
1735
        pageItem->update(pageItem->boundingRect());
1723
1736
    }
1724
1737
}
1725
1738
 
1726
 
void DocumentView::slotUpdateThumbnailItem(ThumbnailItem* thumbnailItem)
 
1739
void DocumentView::slotUpdateThumbnailItem(int index)
1727
1740
{
 
1741
    ThumbnailItem* thumbnailItem = m_thumbnailsByIndex.value(index, 0);
 
1742
 
1728
1743
    if(thumbnailItem != 0)
1729
1744
    {
1730
1745
        thumbnailItem->update(thumbnailItem->boundingRect());
1749
1764
    }
1750
1765
}
1751
1766
 
 
1767
void DocumentView::slotThumbnailsEnsureVisible(int currentPage)
 
1768
{
 
1769
    ThumbnailItem* thumbnailItem = m_thumbnailsByIndex.value(currentPage - 1, 0);
 
1770
 
 
1771
    if(thumbnailItem != 0)
 
1772
    {
 
1773
        m_thumbnailsGraphicsView->ensureVisible(thumbnailItem);
 
1774
    }
 
1775
}
 
1776
 
1752
1777
void DocumentView::slotPrefetchTimerTimeout()
1753
1778
{
1754
1779
#ifndef RENDER_IN_PAINT
1788
1813
            {
1789
1814
                if(!pageItem->m_render.isRunning())
1790
1815
                {
1791
 
                    pageItem->m_render = QtConcurrent::run(pageItem, &DocumentView::PageItem::render, true);
 
1816
                    pageItem->m_render = QtConcurrent::run(pageItem, &DocumentView::PageItem::render, pageItem->m_scale, true);
1792
1817
                }
1793
1818
            }
1794
1819
 
1849
1874
 
1850
1875
        Poppler::Page* page = m_document->page(index);
1851
1876
 
1852
 
        QList<QRectF> results;
 
1877
        QList< QRectF > results;
1853
1878
 
1854
1879
#ifdef HAS_POPPLER_14
1855
1880
        double rectLeft = 0.0, rectTop = 0.0, rectRight = 0.0, rectBottom = 0.0;
1895
1920
 
1896
1921
        if(m_highlightAll)
1897
1922
        {
1898
 
            emit pageItemChanged(m_pagesByIndex.value(index, 0));
 
1923
            emit pageItemChanged(index);
1899
1924
        }
1900
1925
 
1901
1926
        emit searchProgressed((100 * (indices.indexOf(index) + 1)) / indices.count());
2006
2031
        qDebug() << "CUPS:" << cupsLastErrorString();
2007
2032
    }
2008
2033
 
 
2034
    delete printer;
 
2035
 
2009
2036
    emit printProgressed(100);
2010
2037
 
2011
2038
    emit printFinished();
2064
2091
 
2065
2092
void DocumentView::clearScene()
2066
2093
{
2067
 
    disconnect(this, SIGNAL(pageItemChanged(PageItem*)), this, SLOT(slotUpdatePageItem(PageItem*)));
2068
 
    disconnect(this, SIGNAL(thumbnailItemChanged(ThumbnailItem*)), this, SLOT(slotUpdateThumbnailItem(ThumbnailItem*)));
 
2094
    m_pagesByIndex.clear();
 
2095
    m_thumbnailsByIndex.clear();
2069
2096
 
2070
2097
    m_scene->removeItem(m_highlight);
2071
2098
    m_scene->clear();
2072
2099
    m_scene->addItem(m_highlight);
2073
2100
 
2074
2101
    m_thumbnailsGraphicsView->scene()->clear();
2075
 
 
2076
 
    connect(this, SIGNAL(pageItemChanged(PageItem*)), this, SLOT(slotUpdatePageItem(PageItem*)));
2077
 
    connect(this, SIGNAL(thumbnailItemChanged(ThumbnailItem*)), this, SLOT(slotUpdateThumbnailItem(ThumbnailItem*)));
2078
2102
}
2079
2103
 
2080
2104
void DocumentView::clearPageCache()
2213
2237
    {
2214
2238
        Poppler::LinkDestination linkDestination(element.attribute("Destination"));
2215
2239
 
2216
 
        item->setData(0, Qt::UserRole, linkDestination.pageNumber());
2217
 
        item->setData(0, Qt::UserRole+1, linkDestination.isChangeTop() ? linkDestination.top() : 0.0);
 
2240
        int page = linkDestination.pageNumber();
 
2241
        qreal top = linkDestination.isChangeTop() ? linkDestination.top() : 0.0;
 
2242
 
 
2243
        page = qMax(page, 1);
 
2244
        page = qMin(page, m_numberOfPages);
 
2245
 
 
2246
        top = qMax(top, static_cast< qreal >(0.0));
 
2247
        top = qMin(top, static_cast< qreal >(1.0));
 
2248
 
 
2249
        item->setData(0, Qt::UserRole, page);
 
2250
        item->setData(0, Qt::UserRole+1, top);
2218
2251
    }
2219
2252
    else if(element.hasAttribute("DestinationName"))
2220
2253
    {
2221
2254
        Poppler::LinkDestination* linkDestination = m_document->linkDestination(element.attribute("DestinationName"));
2222
2255
 
2223
 
        item->setData(0, Qt::UserRole, linkDestination ? linkDestination->pageNumber() : 1);
2224
 
        item->setData(0, Qt::UserRole+1, linkDestination ? (linkDestination->isChangeTop() ? linkDestination->top() : 0.0) : 0.0);
 
2256
        int page = linkDestination != 0 ? linkDestination->pageNumber() : 1;
 
2257
        qreal top = linkDestination != 0 ? (linkDestination->isChangeTop() ? linkDestination->top() : 0.0) : 0.0;
 
2258
 
 
2259
        page = qMax(page, 1);
 
2260
        page = qMin(page, m_numberOfPages);
 
2261
 
 
2262
        top = qMax(top, static_cast< qreal >(0.0));
 
2263
        top = qMin(top, static_cast< qreal >(1.0));
 
2264
 
 
2265
        item->setData(0, Qt::UserRole, page);
 
2266
        item->setData(0, Qt::UserRole+1, top);
2225
2267
 
2226
2268
        delete linkDestination;
2227
2269
    }
 
2270
    else
 
2271
    {
 
2272
        item->setData(0, Qt::UserRole, -1);
 
2273
    }
2228
2274
 
2229
2275
    if(QVariant(element.attribute("Open", "false")).toBool())
2230
2276
    {
2272
2318
{
2273
2319
    m_thumbnailsGraphicsView->scene()->clear();
2274
2320
 
 
2321
    m_thumbnailsByIndex.clear();
 
2322
    m_thumbnailsByIndex.reserve(m_numberOfPages);
 
2323
 
2275
2324
    qreal sceneWidth = 0.0, sceneHeight = thumbnailSpacing;
2276
2325
 
2277
2326
    for(int index = 0; index < m_numberOfPages; index++)
2290
2339
 
2291
2340
        m_thumbnailsGraphicsView->scene()->addItem(thumbnailItem);
2292
2341
 
 
2342
        m_thumbnailsByIndex.append(thumbnailItem);
 
2343
 
2293
2344
        sceneWidth = qMax(sceneWidth, thumbnailItem->boundingRect().width() + 2 * thumbnailSpacing);
2294
2345
        sceneHeight += thumbnailItem->boundingRect().height() + thumbnailSpacing;
2295
2346
 
2332
2383
    if(m_scaleMode == FitToPage || m_scaleMode == FitToPageWidth)
2333
2384
    {
2334
2385
        qreal pageWidth = 0.0, pageHeight = 0.0;
2335
 
        qreal visibleWidth = m_view->viewport()->width() - m_view->verticalScrollBar()->width() - 2;
2336
 
        qreal visibleHeight = m_view->viewport()->height() - 2;
 
2386
        qreal visibleWidth = m_view->viewport()->width() - 5;
 
2387
        qreal visibleHeight = m_view->viewport()->height() - 5;
2337
2388
 
2338
2389
        switch(m_pageLayout)
2339
2390
        {