90
89
parent->m_documentMutex.unlock();
92
painter->drawImage(boundingRect(), image);
91
painter->drawImage(0.0, 0.0, image);
102
101
DocumentView::PageCacheValue& value = parent->m_pageCache[key];
104
103
value.time = QTime::currentTime();
105
painter->drawImage(boundingRect(), value.image);
104
painter->drawImage(0.0, 0.0, value.image);
109
108
if(!m_render.isRunning())
111
m_render = QtConcurrent::run(this, &DocumentView::PageItem::render, false);
110
m_render = QtConcurrent::run(this, &DocumentView::PageItem::render, m_scale, false);
136
135
painter->restore();
143
142
painter->setTransform(m_highlightTransform, true);
144
painter->setPen(QPen(QColor(0, 0, 255)));
146
if(!m_highlight.isNull())
148
painter->drawRect(m_highlight);
149
painter->fillRect(m_highlight, QBrush(QColor(0, 0, 255, 127)));
152
144
if(parent->m_highlightAll)
276
272
m_rubberBand.setBottomRight(event->pos());
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();
280
276
// copy text or image
361
357
document->setRenderHint(Poppler::Document::TextAntialiasing, renderHints.testFlag(Poppler::Document::TextAntialiasing));
362
358
document->setRenderHint(Poppler::Document::TextHinting, renderHints.testFlag(Poppler::Document::TextHinting));
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);
371
367
parent->m_documentMutex.lock();
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);
375
371
parent->m_documentMutex.unlock();
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);
382
378
parent->updatePageCache(key, value);
384
emit parent->pageItemChanged(this);
380
emit parent->pageItemChanged(m_index);
387
383
// thumbnail item
429
425
parent->m_documentMutex.unlock();
431
painter->drawImage(boundingRect(), image);
427
painter->drawImage(0.0, 0.0, image);
441
437
DocumentView::PageCacheValue& value = parent->m_pageCache[key];
443
439
value.time = QTime::currentTime();
444
painter->drawImage(boundingRect(), value.image);
440
painter->drawImage(0.0, 0.0, value.image);
448
444
if(!m_render.isRunning())
450
m_render = QtConcurrent::run(this, &DocumentView::ThumbnailItem::render);
446
m_render = QtConcurrent::run(this, &DocumentView::ThumbnailItem::render, m_scale);
466
462
parent->setCurrentPage(m_index + 1);
469
void DocumentView::ThumbnailItem::render()
465
void DocumentView::ThumbnailItem::render(qreal scale)
471
467
DocumentView* parent = qobject_cast< DocumentView* >(scene()->parent()); Q_ASSERT(parent);
502
498
document->setRenderHint(Poppler::Document::TextAntialiasing, renderHints.testFlag(Poppler::Document::TextAntialiasing));
503
499
document->setRenderHint(Poppler::Document::TextHinting, renderHints.testFlag(Poppler::Document::TextHinting));
505
QImage image = page->renderToImage(m_scale * parent->physicalDpiX(), m_scale * parent->physicalDpiY());
501
QImage image = page->renderToImage(scale * parent->physicalDpiX(), scale * parent->physicalDpiY());
512
508
parent->m_documentMutex.lock();
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());
516
512
parent->m_documentMutex.unlock();
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);
523
519
parent->updatePageCache(key, value);
525
emit parent->thumbnailItemChanged(this);
521
emit parent->thumbnailItemChanged(m_index);
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)));
557
connect(this, SIGNAL(currentPageChanged(int)), SLOT(slotThumbnailsEnsureVisible(int)));
560
559
connect(this, SIGNAL(firstResultFound()), SLOT(findNext()));
869
869
return fontsTableWidget;
872
void DocumentView::clearBookmarks()
874
m_bookmarksMenu->clearList();
872
877
bool DocumentView::open(const QString& filePath)
879
m_prefetchTimer->blockSignals(true);
874
881
Poppler::Document* document = Poppler::Document::load(filePath);
876
883
if(document != 0)
878
885
if(document->isLocked())
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);
882
889
if(document->unlock(password.toLatin1(), password.toLatin1()))
932
939
prepareOutline();
933
940
prepareMetaInformation();
934
941
prepareThumbnails();
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());
949
if(m_settings.value("documentView/prefetch").toBool())
951
m_prefetchTimer->blockSignals(false);
952
m_prefetchTimer->start();
956
m_prefetchTimer->blockSignals(true);
952
if(m_settings.value("documentView/prefetch").toBool())
954
m_prefetchTimer->blockSignals(false);
955
m_prefetchTimer->start();
959
959
return document != 0;
962
962
bool DocumentView::refresh()
964
m_prefetchTimer->blockSignals(true);
964
966
Poppler::Document* document = Poppler::Document::load(m_filePath);
966
968
if(document != 0)
968
970
if(document->isLocked())
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);
972
974
if(document->unlock(password.toLatin1(), password.toLatin1()))
1011
1013
prepareOutline();
1012
1014
prepareMetaInformation();
1013
1015
prepareThumbnails();
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());
1028
if(m_settings.value("documentView/prefetch").toBool())
1030
m_prefetchTimer->blockSignals(false);
1031
m_prefetchTimer->start();
1035
m_prefetchTimer->blockSignals(true);
1026
if(m_settings.value("documentView/prefetch").toBool())
1028
m_prefetchTimer->blockSignals(false);
1029
m_prefetchTimer->start();
1038
1033
return document != 0;
1043
1038
if(m_document != 0)
1045
Poppler::PDFConverter* converter = m_document->pdfConverter();
1047
converter->setOutputFileName(filePath);
1049
bool success = converter->convert();
1040
m_documentMutex.lock();
1042
Poppler::PDFConverter* converter = m_document->pdfConverter();
1044
converter->setOutputFileName(filePath);
1046
bool success = converter->convert();
1050
m_documentMutex.unlock();
1568
1571
void DocumentView::keyPressEvent(QKeyEvent* event)
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))
1572
1575
switch(m_pageLayout)
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)
1578
1581
previousPage();
1580
1583
m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->maximum());
1585
else if(m_view->verticalScrollBar()->value() - m_view->verticalScrollBar()->pageStep() < m_view->verticalScrollBar()->minimum())
1587
m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->minimum());
1584
1591
m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->value() - m_view->verticalScrollBar()->pageStep());
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)
1617
1624
m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->minimum());
1626
else if(m_view->verticalScrollBar()->value() + m_view->verticalScrollBar()->pageStep() > m_view->verticalScrollBar()->maximum())
1628
m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->maximum());
1621
1632
m_view->verticalScrollBar()->setValue(m_view->verticalScrollBar()->value() + m_view->verticalScrollBar()->pageStep());
1718
void DocumentView::slotUpdatePageItem(PageItem* pageItem)
1729
void DocumentView::slotUpdatePageItem(int index)
1731
PageItem* pageItem = m_pagesByIndex.value(index, 0);
1720
1733
if(pageItem != 0)
1722
1735
pageItem->update(pageItem->boundingRect());
1726
void DocumentView::slotUpdateThumbnailItem(ThumbnailItem* thumbnailItem)
1739
void DocumentView::slotUpdateThumbnailItem(int index)
1741
ThumbnailItem* thumbnailItem = m_thumbnailsByIndex.value(index, 0);
1728
1743
if(thumbnailItem != 0)
1730
1745
thumbnailItem->update(thumbnailItem->boundingRect());
1767
void DocumentView::slotThumbnailsEnsureVisible(int currentPage)
1769
ThumbnailItem* thumbnailItem = m_thumbnailsByIndex.value(currentPage - 1, 0);
1771
if(thumbnailItem != 0)
1773
m_thumbnailsGraphicsView->ensureVisible(thumbnailItem);
1752
1777
void DocumentView::slotPrefetchTimerTimeout()
1754
1779
#ifndef RENDER_IN_PAINT
1789
1814
if(!pageItem->m_render.isRunning())
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);
2065
2092
void DocumentView::clearScene()
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();
2070
2097
m_scene->removeItem(m_highlight);
2071
2098
m_scene->clear();
2072
2099
m_scene->addItem(m_highlight);
2074
2101
m_thumbnailsGraphicsView->scene()->clear();
2076
connect(this, SIGNAL(pageItemChanged(PageItem*)), this, SLOT(slotUpdatePageItem(PageItem*)));
2077
connect(this, SIGNAL(thumbnailItemChanged(ThumbnailItem*)), this, SLOT(slotUpdateThumbnailItem(ThumbnailItem*)));
2080
2104
void DocumentView::clearPageCache()
2214
2238
Poppler::LinkDestination linkDestination(element.attribute("Destination"));
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;
2243
page = qMax(page, 1);
2244
page = qMin(page, m_numberOfPages);
2246
top = qMax(top, static_cast< qreal >(0.0));
2247
top = qMin(top, static_cast< qreal >(1.0));
2249
item->setData(0, Qt::UserRole, page);
2250
item->setData(0, Qt::UserRole+1, top);
2219
2252
else if(element.hasAttribute("DestinationName"))
2221
2254
Poppler::LinkDestination* linkDestination = m_document->linkDestination(element.attribute("DestinationName"));
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;
2259
page = qMax(page, 1);
2260
page = qMin(page, m_numberOfPages);
2262
top = qMax(top, static_cast< qreal >(0.0));
2263
top = qMin(top, static_cast< qreal >(1.0));
2265
item->setData(0, Qt::UserRole, page);
2266
item->setData(0, Qt::UserRole+1, top);
2226
2268
delete linkDestination;
2272
item->setData(0, Qt::UserRole, -1);
2229
2275
if(QVariant(element.attribute("Open", "false")).toBool())
2273
2319
m_thumbnailsGraphicsView->scene()->clear();
2321
m_thumbnailsByIndex.clear();
2322
m_thumbnailsByIndex.reserve(m_numberOfPages);
2275
2324
qreal sceneWidth = 0.0, sceneHeight = thumbnailSpacing;
2277
2326
for(int index = 0; index < m_numberOfPages; index++)
2291
2340
m_thumbnailsGraphicsView->scene()->addItem(thumbnailItem);
2342
m_thumbnailsByIndex.append(thumbnailItem);
2293
2344
sceneWidth = qMax(sceneWidth, thumbnailItem->boundingRect().width() + 2 * thumbnailSpacing);
2294
2345
sceneHeight += thumbnailItem->boundingRect().height() + thumbnailSpacing;
2332
2383
if(m_scaleMode == FitToPage || m_scaleMode == FitToPageWidth)
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;
2338
2389
switch(m_pageLayout)