~adamreichold/qpdfview/trunk

« back to all changes in this revision

Viewing changes to sources/pageitem.cpp

  • Committer: Adam Reichold
  • Date: 2020-07-29 07:15:12 UTC
  • Revision ID: adam.reichold@t-online.de-20200729071512-4ljoi4b4rhj3i2ya
Fix build of Fitz plug-in using MuPDF v1.17.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
Copyright 2021 S. Razi Alavizadeh
4
 
Copyright 2020 Johan Björklund
5
 
Copyright 2012-2015, 2021 Adam Reichold
 
3
Copyright 2012-2015 Adam Reichold
6
4
 
7
5
This file is part of qpdfview.
8
6
 
69
67
    return ((settings->pageItem().copyToClipboardModifiers() | settings->pageItem().addAnnotationModifiers()) & mouseButton) != 0;
70
68
}
71
69
 
72
 
inline void showToolTip(Settings* settings, const QGraphicsSceneHoverEvent* event, const QString& text)
73
 
{
74
 
#if QT_VERSION >= QT_VERSION_CHECK(5,2,0)
75
 
 
76
 
    QToolTip::showText(event->screenPos(), text, 0, QRect(), settings->documentView().highlightDuration());
77
 
 
78
 
#else
79
 
 
80
 
    QToolTip::showText(event->screenPos(), text);
81
 
 
82
 
#endif // QT_VERSION
83
 
}
84
 
 
85
70
} // anonymous
86
71
 
87
72
Settings* PageItem::s_settings = 0;
101
86
    m_rubberBand(),
102
87
    m_annotationOverlay(),
103
88
    m_formFieldOverlay(),
104
 
    m_renderParam(RenderParam::defaultInstance),
 
89
    m_renderParam(),
105
90
    m_transform(),
106
91
    m_normalizedTransform(),
107
92
    m_boundingRect(),
391
376
 
392
377
                    if(link->urlOrFileName.isNull())
393
378
                    {
394
 
                        showToolTip(s_settings, event, tr("Go to page %1.").arg(link->page));
 
379
                        QToolTip::showText(event->screenPos(), tr("Go to page %1.").arg(link->page));
395
380
                    }
396
381
                    else
397
382
                    {
398
 
                        showToolTip(s_settings, event, tr("Go to page %1 of file '%2'.").arg(link->page).arg(link->urlOrFileName));
 
383
                        QToolTip::showText(event->screenPos(), tr("Go to page %1 of file '%2'.").arg(link->page).arg(link->urlOrFileName));
399
384
                    }
400
385
 
401
386
                    return;
403
388
                else if(!link->urlOrFileName.isNull() && !presentationMode())
404
389
                {
405
390
                    setCursor(Qt::PointingHandCursor);
406
 
                    showToolTip(s_settings, event, tr("Open '%1'.").arg(link->urlOrFileName));
 
391
                    QToolTip::showText(event->screenPos(), tr("Open '%1'.").arg(link->urlOrFileName));
407
392
 
408
393
                    return;
409
394
                }
425
410
            if(m_normalizedTransform.mapRect(annotation->boundary()).contains(event->pos()))
426
411
            {
427
412
                setCursor(Qt::PointingHandCursor);
428
 
                showToolTip(s_settings, event, annotation->contents());
 
413
                QToolTip::showText(event->screenPos(), annotation->contents());
429
414
 
430
415
                return;
431
416
            }
438
423
            if(m_normalizedTransform.mapRect(formField->boundary()).contains(event->pos()))
439
424
            {
440
425
                setCursor(Qt::PointingHandCursor);
441
 
                showToolTip(s_settings, event, tr("Edit form field '%1'.").arg(formField->name()));
 
426
                QToolTip::showText(event->screenPos(), tr("Edit form field '%1'.").arg(formField->name()));
442
427
 
443
428
                return;
444
429
            }
456
441
void PageItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
457
442
{
458
443
    const bool leftButtonActive = event->button() == Qt::LeftButton;
459
 
    const bool middleButtonActive = event->button() == Qt::MiddleButton;
 
444
    const bool middleButtonActive = event->button() == Qt::MidButton;
460
445
    const bool anyButtonActive = leftButtonActive || middleButtonActive;
461
446
 
462
447
    const bool noModifiersActive = event->modifiers() == Qt::NoModifier;
757
742
 
758
743
    m_loadInteractiveElements = new QFutureWatcher< void >(this);
759
744
    connect(m_loadInteractiveElements, SIGNAL(finished()), SLOT(on_loadInteractiveElements_finished()));
760
 
 
761
 
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
762
 
 
763
 
    m_loadInteractiveElements->setFuture(QtConcurrent::run(std::bind(&PageItem::loadInteractiveElements, this)));
764
 
 
765
 
#else
766
 
 
767
745
    m_loadInteractiveElements->setFuture(QtConcurrent::run(this, &PageItem::loadInteractiveElements));
768
 
 
769
 
#endif // QT_VERSION
770
746
}
771
747
 
772
748
void PageItem::loadInteractiveElements()
808
784
 
809
785
    QAction* copyTextAction = menu.addAction(tr("Copy &text"));
810
786
    QAction* selectTextAction = menu.addAction(tr("&Select text"));
811
 
    QAction* appendTextToBookmarkCommentAction = menu.addAction(tr("&Append text to bookmark comment..."));
812
787
    const QAction* copyImageAction = menu.addAction(tr("Copy &image"));
813
788
    const QAction* saveImageToFileAction = menu.addAction(tr("Save image to &file..."));
814
789
 
816
791
 
817
792
    copyTextAction->setVisible(!text.isEmpty());
818
793
    selectTextAction->setVisible(!text.isEmpty() && QApplication::clipboard()->supportsSelection());
819
 
    appendTextToBookmarkCommentAction->setVisible(!text.isEmpty());
820
794
 
821
795
    const QAction* action = menu.exec(screenPos);
822
796
 
831
805
            QApplication::clipboard()->setText(text, QClipboard::Selection);
832
806
        }
833
807
    }
834
 
    else if(action == appendTextToBookmarkCommentAction)
835
 
    {
836
 
        emit appendTextToBookmarkComment(m_index + 1, text);
837
 
    }
838
808
    else if(action == copyImageAction || action == saveImageToFileAction)
839
809
    {
840
 
        QTransform transform;
841
 
        transform.scale(m_renderParam.devicePixelRatio(), m_renderParam.devicePixelRatio());
842
 
        transform.translate(-m_boundingRect.topLeft().x(), -m_boundingRect.topLeft().y());
843
 
 
844
 
        const QRect rect = transform.mapRect(m_rubberBand).toRect();
845
 
        const QImage image = m_page->render(m_renderParam.devicePixelRatio() * m_renderParam.resolutionX() * m_renderParam.scaleFactor(),
846
 
                                            m_renderParam.devicePixelRatio() * m_renderParam.resolutionY() * m_renderParam.scaleFactor(),
 
810
        const QRect rect = m_rubberBand.translated(-m_boundingRect.topLeft()).toRect();
 
811
        const QImage image = m_page->render(m_renderParam.resolutionX() * m_renderParam.scaleFactor(),
 
812
                                            m_renderParam.resolutionY() * m_renderParam.scaleFactor(),
847
813
                                            m_renderParam.rotation(), rect);
848
814
 
849
815
        if(!image.isNull())
1221
1187
            paperColor.setRgb(~paperColor.rgb());
1222
1188
        }
1223
1189
 
1224
 
        if(m_renderParam.invertLightness())
1225
 
        {
1226
 
            paperColor.setRgb(~paperColor.rgb());
1227
 
        }
1228
 
 
1229
1190
        painter->fillRect(m_boundingRect, QBrush(paperColor));
1230
1191
    }
1231
1192