Minor bugfixing

This commit is contained in:
Jakub Melka
2020-04-13 18:02:49 +02:00
parent 2ff04eb6b5
commit 9b71031ec3
4 changed files with 50 additions and 14 deletions

View File

@ -1003,7 +1003,7 @@ void PDFAnnotationManager::drawPage(QPainter* painter,
for (const PageAnnotation& annotation : annotations.annotations) for (const PageAnnotation& annotation : annotations.annotations)
{ {
const PDFAnnotation::Flags annotationFlags = annotation.annotation->getFlags(); const PDFAnnotation::Flags annotationFlags = annotation.annotation->getEffectiveFlags();
if (annotationFlags.testFlag(PDFAnnotation::Hidden) || // Annotation is completely hidden if (annotationFlags.testFlag(PDFAnnotation::Hidden) || // Annotation is completely hidden
(m_target == Target::Print && !annotationFlags.testFlag(PDFAnnotation::Print)) || // Target is print and annotation is marked as not printed (m_target == Target::Print && !annotationFlags.testFlag(PDFAnnotation::Print)) || // Target is print and annotation is marked as not printed
(m_target == Target::View && annotationFlags.testFlag(PDFAnnotation::NoView)) || // Target is view, and annotation is disabled for screen (m_target == Target::View && annotationFlags.testFlag(PDFAnnotation::NoView)) || // Target is view, and annotation is disabled for screen
@ -1265,6 +1265,7 @@ void PDFWidgetAnnotationManager::updateFromMouseEvent(QMouseEvent* event)
} }
m_tooltip = QString(); m_tooltip = QString();
m_cursor = std::nullopt;
bool appearanceChanged = false; bool appearanceChanged = false;
// We must update appearance states, and update tooltip // We must update appearance states, and update tooltip
@ -1285,7 +1286,7 @@ void PDFWidgetAnnotationManager::updateFromMouseEvent(QMouseEvent* event)
const PDFAppeareanceStreams::Appearance oldAppearance = pageAnnotation.appearance; const PDFAppeareanceStreams::Appearance oldAppearance = pageAnnotation.appearance;
QRectF annotationRect = pageAnnotation.annotation->getRectangle(); QRectF annotationRect = pageAnnotation.annotation->getRectangle();
QMatrix matrix = prepareTransformations(snapshotItem.pageToDeviceMatrix, widget, pageAnnotation.annotation->getFlags(), m_document->getCatalog()->getPage(snapshotItem.pageIndex), annotationRect); QMatrix matrix = prepareTransformations(snapshotItem.pageToDeviceMatrix, widget, pageAnnotation.annotation->getEffectiveFlags(), m_document->getCatalog()->getPage(snapshotItem.pageIndex), annotationRect);
QPainterPath path; QPainterPath path;
path.addRect(annotationRect); path.addRect(annotationRect);
path = matrix.map(path); path = matrix.map(path);
@ -1320,6 +1321,22 @@ void PDFWidgetAnnotationManager::updateFromMouseEvent(QMouseEvent* event)
} }
} }
const PDFAction* linkAction = nullptr;
if (pageAnnotation.annotation->getType() == AnnotationType::Link)
{
const PDFLinkAnnotation* linkAnnotation = dynamic_cast<const PDFLinkAnnotation*>(pageAnnotation.annotation.data());
Q_ASSERT(linkAnnotation);
// We must check, if user clicked to the link area
QPainterPath activationPath = linkAnnotation->getActivationRegion().getPath();
activationPath = snapshotItem.pageToDeviceMatrix.map(activationPath);
if (activationPath.contains(event->pos()) && linkAnnotation->getAction())
{
m_cursor = QCursor(Qt::PointingHandCursor);
linkAction = linkAnnotation->getAction();
}
}
// Generate popup window // Generate popup window
if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton) if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton)
{ {
@ -1346,18 +1363,9 @@ void PDFWidgetAnnotationManager::updateFromMouseEvent(QMouseEvent* event)
dialog->exec(); dialog->exec();
} }
if (pageAnnotation.annotation->getType() == AnnotationType::Link) if (linkAction)
{ {
const PDFLinkAnnotation* linkAnnotation = dynamic_cast<const PDFLinkAnnotation*>(pageAnnotation.annotation.data()); emit actionTriggered(linkAction);
Q_ASSERT(linkAnnotation);
// We must check, if user clicked to the link area
QPainterPath activationPath = linkAnnotation->getActivationRegion().getPath();
activationPath = snapshotItem.pageToDeviceMatrix.map(activationPath);
if (activationPath.contains(event->pos()) && linkAnnotation->getAction())
{
emit actionTriggered(linkAnnotation->getAction());
}
} }
} }
} }
@ -1634,6 +1642,11 @@ void PDFTextAnnotation::draw(AnnotationDrawParameters& parameters) const
parameters.boundingRectangle = rectangle; parameters.boundingRectangle = rectangle;
} }
PDFTextAnnotation::Flags PDFTextAnnotation::getEffectiveFlags() const
{
return getFlags() | NoZoom | NoRotate;
}
void PDFLineAnnotation::draw(AnnotationDrawParameters& parameters) const void PDFLineAnnotation::draw(AnnotationDrawParameters& parameters) const
{ {
QLineF line = getLine(); QLineF line = getLine();

View File

@ -28,6 +28,7 @@
#include "pdfdocumentdrawinterface.h" #include "pdfdocumentdrawinterface.h"
#include "pdfrenderer.h" #include "pdfrenderer.h"
#include <QCursor>
#include <QPainterPath> #include <QPainterPath>
#include <array> #include <array>
@ -485,6 +486,10 @@ public:
/// Returns a list of appearance states, which must be created for this annotation /// Returns a list of appearance states, which must be created for this annotation
virtual std::vector<PDFAppeareanceStreams::Key> getDrawKeys() const; virtual std::vector<PDFAppeareanceStreams::Key> getDrawKeys() const;
/// Returns effective flags (some annotations can behave as they have always
/// set some flags, such as NoZoom and NoRotate)
virtual Flags getEffectiveFlags() const { return getFlags(); }
PDFObjectReference getSelfReference() const { return m_selfReference; } PDFObjectReference getSelfReference() const { return m_selfReference; }
const QRectF& getRectangle() const { return m_rectangle; } const QRectF& getRectangle() const { return m_rectangle; }
const QString& getContents() const { return m_contents; } const QString& getContents() const { return m_contents; }
@ -672,6 +677,7 @@ public:
virtual AnnotationType getType() const override { return AnnotationType::Text; } virtual AnnotationType getType() const override { return AnnotationType::Text; }
virtual std::vector<PDFAppeareanceStreams::Key> getDrawKeys() const override; virtual std::vector<PDFAppeareanceStreams::Key> getDrawKeys() const override;
virtual void draw(AnnotationDrawParameters& parameters) const override; virtual void draw(AnnotationDrawParameters& parameters) const override;
virtual Flags getEffectiveFlags() const override;
bool isOpen() const { return m_open; } bool isOpen() const { return m_open; }
const QByteArray& getIconName() const { return m_iconName; } const QByteArray& getIconName() const { return m_iconName; }
@ -1245,7 +1251,8 @@ private:
/// Annotation manager manages annotations for document's pages. Each page /// Annotation manager manages annotations for document's pages. Each page
/// can have multiple annotations, and this object caches them. Also, /// can have multiple annotations, and this object caches them. Also,
/// this object builds annotation's appearance streams, if necessary. This /// this object builds annotation's appearance streams, if necessary. This
/// manager is intended to non-gui rendering. /// manager is intended to non-gui rendering. If widget annotation manager is used,
/// then this object is not thread safe.
class PDFFORQTLIBSHARED_EXPORT PDFAnnotationManager : public QObject, public IDocumentDrawInterface class PDFFORQTLIBSHARED_EXPORT PDFAnnotationManager : public QObject, public IDocumentDrawInterface
{ {
Q_OBJECT Q_OBJECT
@ -1409,6 +1416,9 @@ public:
/// Returns tooltip generated from annotation /// Returns tooltip generated from annotation
const QString& getTooltip() const { return m_tooltip; } const QString& getTooltip() const { return m_tooltip; }
/// Returns current cursor
const std::optional<QCursor>& getCursor() const { return m_cursor;}
signals: signals:
void actionTriggered(const pdf::PDFAction* action); void actionTriggered(const pdf::PDFAction* action);
@ -1435,6 +1445,7 @@ private:
PDFDrawWidgetProxy* m_proxy; PDFDrawWidgetProxy* m_proxy;
QString m_tooltip; QString m_tooltip;
std::optional<QCursor> m_cursor;
}; };
} // namespace pdf } // namespace pdf

View File

@ -397,6 +397,14 @@ void PDFDrawWidgetBase<BaseWidget>::updateCursor()
cursor = toolManager->getCursor(); cursor = toolManager->getCursor();
} }
if (!cursor)
{
if (PDFWidgetAnnotationManager* annotationManager = m_widget->getDrawWidgetProxy()->getAnnotationManager())
{
cursor = annotationManager->getCursor();
}
}
if (!cursor) if (!cursor)
{ {
switch (m_mouseOperation) switch (m_mouseOperation)
@ -436,6 +444,7 @@ void PDFDrawWidgetBase<BaseWidget>::wheelEvent(QWheelEvent* event)
toolManager->wheelEvent(this, event); toolManager->wheelEvent(this, event);
if (event->isAccepted()) if (event->isAccepted())
{ {
updateCursor();
return; return;
} }
} }

View File

@ -97,6 +97,9 @@ public:
m_object = T(); m_object = T();
} }
/// Returns true, if cache is dirty
inline bool isDirty() const { return m_dirty; }
private: private:
bool m_dirty; bool m_dirty;
T m_object; T m_object;