mirror of https://github.com/JakubMelka/PDF4QT.git
Text field bugfixing
This commit is contained in:
parent
29372b6cd0
commit
691eaff6db
|
@ -1012,6 +1012,13 @@ void PDFAnnotationManager::drawWidgetAnnotationHighlight(QRectF annotationRectan
|
|||
return;
|
||||
}
|
||||
|
||||
// Nekreslíme zvýraznění push buttonů
|
||||
if (formField->getFieldType() == PDFFormField::FieldType::Button &&
|
||||
formField->getFlags().testFlag(PDFFormField::PushButton))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QColor color;
|
||||
if (flags.testFlag(PDFFormManager::HighlightFields))
|
||||
{
|
||||
|
@ -1083,8 +1090,16 @@ void PDFAnnotationManager::drawPage(QPainter* painter,
|
|||
continue;
|
||||
}
|
||||
|
||||
const PDFFormFieldWidgetEditor* editor = nullptr;
|
||||
const bool isWidget = annotation.annotation->getType() == AnnotationType::Widget;
|
||||
if (isWidget && m_formManager)
|
||||
{
|
||||
editor = m_formManager->getEditor(m_formManager->getFormFieldForWidget(annotation.annotation->getSelfReference()));
|
||||
}
|
||||
const bool isEditorDrawEnabled = editor && editor->isEditorDrawEnabled();
|
||||
|
||||
PDFObject appearanceStreamObject = m_document->getObject(getAppearanceStream(annotation));
|
||||
if (!appearanceStreamObject.isStream())
|
||||
if (!appearanceStreamObject.isStream() || isEditorDrawEnabled)
|
||||
{
|
||||
// Object is not valid appearance stream. We will try to draw default
|
||||
// annotation appearance, but we must consider also optional content.
|
||||
|
@ -1104,6 +1119,8 @@ void PDFAnnotationManager::drawPage(QPainter* painter,
|
|||
painter->setWorldMatrix(pagePointToDevicePointMatrix, true);
|
||||
AnnotationDrawParameters parameters;
|
||||
parameters.painter = painter;
|
||||
parameters.annotation = annotation.annotation.data();
|
||||
parameters.formManager = m_formManager;
|
||||
parameters.key = std::make_pair(annotation.appearance, annotation.annotation->getAppearanceState());
|
||||
annotation.annotation->draw(parameters);
|
||||
|
||||
|
@ -1116,7 +1133,7 @@ void PDFAnnotationManager::drawPage(QPainter* painter,
|
|||
// Draw highlighting of fields, but only, if target is View,
|
||||
// we do not want to render form field highlight, when we are
|
||||
// printing to the printer.
|
||||
if (m_target == Target::View)
|
||||
if (m_target == Target::View && !isEditorDrawEnabled)
|
||||
{
|
||||
PDFPainterStateGuard guard(painter);
|
||||
drawWidgetAnnotationHighlight(annotationRectangle, annotation.annotation.get(), painter, pagePointToDevicePointMatrix);
|
||||
|
@ -1356,6 +1373,12 @@ PDFWidgetAnnotationManager::~PDFWidgetAnnotationManager()
|
|||
m_proxy->unregisterDrawInterface(this);
|
||||
}
|
||||
|
||||
void PDFWidgetAnnotationManager::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(event);
|
||||
}
|
||||
|
||||
void PDFWidgetAnnotationManager::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
|
@ -2857,4 +2880,55 @@ std::vector<const PDFAnnotationManager::PageAnnotation*> PDFAnnotationManager::P
|
|||
return result;
|
||||
}
|
||||
|
||||
void PDFWidgetAnnotation::draw(AnnotationDrawParameters& parameters) const
|
||||
{
|
||||
// Do not draw without form manager
|
||||
if (!parameters.formManager)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not draw without form field
|
||||
const PDFFormField* formField = parameters.formManager->getFormFieldForWidget(getSelfReference());
|
||||
if (!formField)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const PDFFormFieldWidgetEditor* editor = parameters.formManager->getEditor(formField);
|
||||
if (editor && editor->isEditorDrawEnabled())
|
||||
{
|
||||
editor->draw(parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (formField->getFieldType())
|
||||
{
|
||||
case PDFFormField::FieldType::Text:
|
||||
{
|
||||
if (const PDFFormFieldTextBoxEditor* textBoxEditor = qobject_cast<const PDFFormFieldTextBoxEditor*>(editor))
|
||||
{
|
||||
PDFTextEditPseudowidget pseudowidget(formField->getFlags());
|
||||
textBoxEditor->initializeTextEdit(&pseudowidget);
|
||||
pseudowidget.draw(parameters, false);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PDFFormField::FieldType::Button:
|
||||
case PDFFormField::FieldType::Invalid:
|
||||
case PDFFormField::FieldType::Choice:
|
||||
case PDFFormField::FieldType::Signature:
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
|
|
@ -46,6 +46,7 @@ class PDFFontCache;
|
|||
class PDFFormManager;
|
||||
class PDFModifiedDocument;
|
||||
class PDFOptionalContentActivity;
|
||||
class PDFFormFieldWidgetEditor;
|
||||
|
||||
using TextAlignment = Qt::Alignment;
|
||||
using Polygons = std::vector<QPolygonF>;
|
||||
|
@ -440,6 +441,14 @@ struct AnnotationDrawParameters
|
|||
/// Painter, onto which is annotation graphics drawn
|
||||
QPainter* painter = nullptr;
|
||||
|
||||
/// Pointer to annotation (if draw is delegated to other objects,
|
||||
/// for example, form manager, then maybe pointer to annotation
|
||||
/// is needed).
|
||||
PDFAnnotation* annotation = nullptr;
|
||||
|
||||
/// Pointer to form manager (if forms are drawn)
|
||||
const PDFFormManager* formManager = nullptr;
|
||||
|
||||
/// Output parameter. Marks annotation's graphics bounding
|
||||
/// rectangle (it can be different/adjusted from original
|
||||
/// annotation bounding rectangle, in that case, it must be adjusted).
|
||||
|
@ -1155,6 +1164,7 @@ public:
|
|||
};
|
||||
|
||||
virtual AnnotationType getType() const override { return AnnotationType::Widget; }
|
||||
virtual void draw(AnnotationDrawParameters& parameters) const override;
|
||||
|
||||
HighlightMode getHighlightMode() const { return m_highlightMode; }
|
||||
const PDFAnnotationAppearanceCharacteristics& getAppearanceCharacteristics() const { return m_appearanceCharacteristics; }
|
||||
|
@ -1410,34 +1420,12 @@ public:
|
|||
explicit PDFWidgetAnnotationManager(PDFDrawWidgetProxy* proxy, QObject* parent);
|
||||
virtual ~PDFWidgetAnnotationManager() override;
|
||||
|
||||
/// Handles key press event from widget, over which tool operates
|
||||
/// \param widget Widget, over which tool operates
|
||||
/// \param event Event
|
||||
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
|
||||
/// Handles key release event from widget
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void keyReleaseEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
|
||||
/// Handles mouse press event from widget, over which tool operates
|
||||
/// \param widget Widget, over which tool operates
|
||||
/// \param event Event
|
||||
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) override;
|
||||
|
||||
/// Handles mouse release event from widget, over which tool operates
|
||||
/// \param widget Widget, over which tool operates
|
||||
/// \param event Event
|
||||
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
|
||||
|
||||
/// Handles mouse move event from widget, over which tool operates
|
||||
/// \param widget Widget, over which tool operates
|
||||
/// \param event Event
|
||||
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
|
||||
|
||||
/// Handles mouse wheel event from widget, over which tool operates
|
||||
/// \param widget Widget, over which tool operates
|
||||
/// \param event Event
|
||||
virtual void wheelEvent(QWidget* widget, QWheelEvent* event) override;
|
||||
|
||||
/// Returns tooltip generated from annotation
|
||||
|
|
|
@ -74,6 +74,12 @@ public:
|
|||
AnnotationPriority = 30
|
||||
};
|
||||
|
||||
/// Handles shortcut override event. Accept this event, when you want given
|
||||
/// key sequence to be propagated to keyPressEvent.
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) = 0;
|
||||
|
||||
/// Handles key press event from widget
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
|
|
|
@ -253,6 +253,17 @@ QSize PDFDrawWidgetBase<BaseWidget>::minimumSizeHint() const
|
|||
return QSize(200, 200);
|
||||
}
|
||||
|
||||
template<typename BaseWidget>
|
||||
bool PDFDrawWidgetBase<BaseWidget>::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::ShortcutOverride)
|
||||
{
|
||||
return processEvent<QKeyEvent, &IDrawWidgetInputInterface::shortcutOverrideEvent>(static_cast<QKeyEvent*>(event));
|
||||
}
|
||||
|
||||
return BaseWidget::event(event);
|
||||
}
|
||||
|
||||
template<typename BaseWidget>
|
||||
void PDFDrawWidgetBase<BaseWidget>::performMouseOperation(QPoint currentMousePosition)
|
||||
{
|
||||
|
|
|
@ -138,6 +138,7 @@ public:
|
|||
virtual QWidget* getWidget() override { return this; }
|
||||
|
||||
protected:
|
||||
virtual bool event(QEvent* event) override;
|
||||
virtual void keyPressEvent(QKeyEvent* event) override;
|
||||
virtual void keyReleaseEvent(QKeyEvent* event) override;
|
||||
virtual void mousePressEvent(QMouseEvent* event) override;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "pdfdrawspacecontroller.h"
|
||||
#include "pdfdrawwidget.h"
|
||||
#include "pdfdocumentbuilder.h"
|
||||
#include "pdfpainterutils.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
|
@ -822,6 +823,15 @@ QRectF PDFFormManager::getWidgetRectangle(const PDFFormWidget& widget) const
|
|||
return QRectF();
|
||||
}
|
||||
|
||||
|
||||
void PDFFormManager::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
if (m_focusedEditor)
|
||||
{
|
||||
m_focusedEditor->shortcutOverrideEvent(widget, event);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFFormManager::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
if (m_focusedEditor)
|
||||
|
@ -1144,6 +1154,12 @@ PDFFormFieldWidgetEditor::PDFFormFieldWidgetEditor(PDFFormManager* formManager,
|
|||
Q_ASSERT(m_formManager);
|
||||
}
|
||||
|
||||
void PDFFormFieldWidgetEditor::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(event);
|
||||
}
|
||||
|
||||
void PDFFormFieldWidgetEditor::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
|
@ -1176,7 +1192,16 @@ void PDFFormFieldWidgetEditor::mouseMoveEvent(QWidget* widget, QMouseEvent* even
|
|||
|
||||
void PDFFormFieldWidgetEditor::setFocus(bool hasFocus)
|
||||
{
|
||||
m_hasFocus = hasFocus;
|
||||
if (m_hasFocus != hasFocus)
|
||||
{
|
||||
m_hasFocus = hasFocus;
|
||||
setFocusImpl(m_hasFocus);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFFormFieldWidgetEditor::draw(AnnotationDrawParameters& parameters) const
|
||||
{
|
||||
Q_UNUSED(parameters);
|
||||
}
|
||||
|
||||
void PDFFormFieldWidgetEditor::performKeypadNavigation(QWidget* widget, QKeyEvent* event)
|
||||
|
@ -1369,24 +1394,22 @@ PDFFormFieldListBoxEditor::PDFFormFieldListBoxEditor(PDFFormManager* formManager
|
|||
|
||||
}
|
||||
|
||||
PDFFormFieldTextBoxEditor::PDFFormFieldTextBoxEditor(PDFFormManager* formManager, PDFFormWidget formWidget, QObject* parent) :
|
||||
BaseClass(formManager, formWidget, parent),
|
||||
m_textEdit(formWidget.getParent()->getFlags())
|
||||
void PDFFormFieldTextBoxEditor::initializeTextEdit(PDFTextEditPseudowidget* textEdit) const
|
||||
{
|
||||
const PDFFormFieldText* parentField = dynamic_cast<const PDFFormFieldText*>(formWidget.getParent());
|
||||
const PDFFormFieldText* parentField = dynamic_cast<const PDFFormFieldText*>(m_formWidget.getParent());
|
||||
Q_ASSERT(parentField);
|
||||
|
||||
PDFDocumentDataLoaderDecorator loader(formManager->getDocument());
|
||||
PDFDocumentDataLoaderDecorator loader(m_formManager->getDocument());
|
||||
|
||||
QByteArray defaultAppearance = parentField->getDefaultAppearance();
|
||||
if (defaultAppearance.isEmpty())
|
||||
{
|
||||
defaultAppearance = formManager->getForm()->getDefaultAppearance().value_or(QByteArray());
|
||||
defaultAppearance = m_formManager->getForm()->getDefaultAppearance().value_or(QByteArray());
|
||||
}
|
||||
Qt::Alignment alignment = parentField->getAlignment();
|
||||
if (!(alignment & Qt::AlignHorizontal_Mask))
|
||||
{
|
||||
switch (formManager->getForm()->getQuadding().value_or(0))
|
||||
switch (m_formManager->getForm()->getQuadding().value_or(0))
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
|
@ -1404,8 +1427,46 @@ PDFFormFieldTextBoxEditor::PDFFormFieldTextBoxEditor(PDFFormManager* formManager
|
|||
}
|
||||
|
||||
// Initialize text edit
|
||||
m_textEdit.setAppearance(PDFAnnotationDefaultAppearance::parse(defaultAppearance), alignment, m_formManager->getWidgetRectangle(formWidget), parentField->getTextMaximalLength());
|
||||
m_textEdit.setText(loader.readTextString(parentField->getValue(), QString()));
|
||||
textEdit->setAppearance(PDFAnnotationDefaultAppearance::parse(defaultAppearance), alignment, m_formManager->getWidgetRectangle(m_formWidget), parentField->getTextMaximalLength());
|
||||
textEdit->setText(loader.readTextString(parentField->getValue(), QString()));
|
||||
}
|
||||
|
||||
void PDFFormFieldTextBoxEditor::setFocusImpl(bool focused)
|
||||
{
|
||||
if (focused)
|
||||
{
|
||||
m_textEdit.setCursorPosition(m_textEdit.getPositionEnd(), false);
|
||||
m_textEdit.performSelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
PDFFormFieldTextBoxEditor::PDFFormFieldTextBoxEditor(PDFFormManager* formManager, PDFFormWidget formWidget, QObject* parent) :
|
||||
BaseClass(formManager, formWidget, parent),
|
||||
m_textEdit(formWidget.getParent()->getFlags())
|
||||
{
|
||||
initializeTextEdit(&m_textEdit);
|
||||
}
|
||||
|
||||
void PDFFormFieldTextBoxEditor::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
|
||||
m_textEdit.shortcutOverrideEvent(widget, event);
|
||||
}
|
||||
|
||||
void PDFFormFieldTextBoxEditor::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
m_textEdit.keyPressEvent(widget, event);
|
||||
|
||||
if (event->isAccepted())
|
||||
{
|
||||
widget->update();
|
||||
}
|
||||
}
|
||||
|
||||
void PDFFormFieldTextBoxEditor::draw(AnnotationDrawParameters& parameters) const
|
||||
{
|
||||
m_textEdit.draw(parameters, true);
|
||||
}
|
||||
|
||||
PDFTextEditPseudowidget::PDFTextEditPseudowidget(PDFFormField::FieldFlags flags) :
|
||||
|
@ -1419,6 +1480,43 @@ PDFTextEditPseudowidget::PDFTextEditPseudowidget(PDFFormField::FieldFlags flags)
|
|||
m_passwordReplacementCharacter = QApplication::style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter);
|
||||
}
|
||||
|
||||
void PDFTextEditPseudowidget::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
constexpr QKeySequence::StandardKey acceptedKeys[] = { QKeySequence::Delete, QKeySequence::Cut, QKeySequence::Copy, QKeySequence::Paste,
|
||||
QKeySequence::SelectAll, QKeySequence::MoveToNextChar, QKeySequence::MoveToPreviousChar,
|
||||
QKeySequence::MoveToNextWord, QKeySequence::MoveToPreviousWord, QKeySequence::MoveToNextLine,
|
||||
QKeySequence::MoveToPreviousLine, QKeySequence::MoveToStartOfLine, QKeySequence::MoveToEndOfLine,
|
||||
QKeySequence::MoveToStartOfBlock, QKeySequence::MoveToEndOfBlock, QKeySequence::MoveToStartOfDocument,
|
||||
QKeySequence::MoveToEndOfDocument, QKeySequence::SelectNextChar, QKeySequence::SelectPreviousChar,
|
||||
QKeySequence::SelectNextWord, QKeySequence::SelectPreviousWord, QKeySequence::SelectNextLine,
|
||||
QKeySequence::SelectPreviousLine, QKeySequence::SelectStartOfLine, QKeySequence::SelectEndOfLine,
|
||||
QKeySequence::SelectStartOfBlock, QKeySequence::SelectEndOfBlock, QKeySequence::SelectStartOfDocument,
|
||||
QKeySequence::SelectEndOfDocument, QKeySequence::DeleteStartOfWord, QKeySequence::DeleteEndOfWord,
|
||||
QKeySequence::DeleteEndOfLine, QKeySequence::Deselect, QKeySequence::DeleteCompleteLine, QKeySequence::Backspace };
|
||||
|
||||
if (std::any_of(std::begin(acceptedKeys), std::end(acceptedKeys), [event](QKeySequence::StandardKey standardKey) { return event == standardKey; }))
|
||||
{
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event->key())
|
||||
{
|
||||
case Qt::Key_Direction_L:
|
||||
case Qt::Key_Direction_R:
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Down:
|
||||
case Qt::Key_Left:
|
||||
case Qt::Key_Right:
|
||||
event->accept();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PDFTextEditPseudowidget::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
|
@ -1502,11 +1600,11 @@ void PDFTextEditPseudowidget::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
|||
}
|
||||
else if (event == QKeySequence::MoveToNextLine)
|
||||
{
|
||||
setCursorPosition(getCursorNextLine(), false);
|
||||
setCursorPosition(getCursorLineDown(), false);
|
||||
}
|
||||
else if (event == QKeySequence::MoveToPreviousLine)
|
||||
{
|
||||
setCursorPosition(getCursorPreviousLine(), false);
|
||||
setCursorPosition(getCursorLineUp(), false);
|
||||
}
|
||||
else if (event == QKeySequence::MoveToStartOfLine || event == QKeySequence::MoveToStartOfBlock)
|
||||
{
|
||||
|
@ -1542,11 +1640,11 @@ void PDFTextEditPseudowidget::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
|||
}
|
||||
else if (event == QKeySequence::SelectNextLine)
|
||||
{
|
||||
setCursorPosition(getCursorNextLine(), true);
|
||||
setCursorPosition(getCursorLineDown(), true);
|
||||
}
|
||||
else if (event == QKeySequence::SelectPreviousLine)
|
||||
{
|
||||
setCursorPosition(getCursorPreviousLine(), true);
|
||||
setCursorPosition(getCursorLineUp(), true);
|
||||
}
|
||||
else if (event == QKeySequence::SelectStartOfLine || event == QKeySequence::SelectStartOfBlock)
|
||||
{
|
||||
|
@ -1601,7 +1699,7 @@ void PDFTextEditPseudowidget::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
|||
performRemoveSelectedText();
|
||||
}
|
||||
}
|
||||
else if (event == QKeySequence::Backspace)
|
||||
else if (event == QKeySequence::Backspace || event->key() == Qt::Key_Backspace)
|
||||
{
|
||||
performBackspace();
|
||||
}
|
||||
|
@ -1741,7 +1839,7 @@ void PDFTextEditPseudowidget::setAppearance(const PDFAnnotationDefaultAppearance
|
|||
m_textLayout.setFont(font);
|
||||
|
||||
QTextOption option = m_textLayout.textOption();
|
||||
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||
option.setWrapMode(isMultiline() ? QTextOption::WrapAtWordBoundaryOrAnywhere : QTextOption::NoWrap);
|
||||
option.setAlignment(textAlignment);
|
||||
option.setUseDesignMetrics(true);
|
||||
m_textLayout.setTextOption(option);
|
||||
|
@ -1835,10 +1933,13 @@ void PDFTextEditPseudowidget::performDelete()
|
|||
|
||||
void PDFTextEditPseudowidget::performRemoveSelectedText()
|
||||
{
|
||||
m_editText.remove(m_selectionStart, getSelectionLength());
|
||||
setCursorPosition(m_selectionStart, false);
|
||||
clearSelection();
|
||||
updateTextLayout();
|
||||
if (isTextSelected())
|
||||
{
|
||||
m_editText.remove(m_selectionStart, getSelectionLength());
|
||||
setCursorPosition(m_selectionStart, false);
|
||||
clearSelection();
|
||||
updateTextLayout();
|
||||
}
|
||||
}
|
||||
|
||||
void PDFTextEditPseudowidget::performInsertText(const QString& text)
|
||||
|
@ -1855,6 +1956,58 @@ void PDFTextEditPseudowidget::performInsertText(const QString& text)
|
|||
updateTextLayout();
|
||||
}
|
||||
|
||||
void PDFTextEditPseudowidget::draw(AnnotationDrawParameters& parameters, bool edit) const
|
||||
{
|
||||
pdf::PDFPainterStateGuard guard(parameters.painter);
|
||||
parameters.boundingRectangle = parameters.annotation->getRectangle();
|
||||
|
||||
QPainter* painter = parameters.painter;
|
||||
painter->translate(parameters.boundingRectangle.bottomLeft());
|
||||
painter->scale(1.0, -1.0);
|
||||
|
||||
QVector<QTextLayout::FormatRange> selections;
|
||||
|
||||
QTextLayout::FormatRange defaultFormat;
|
||||
defaultFormat.start = getPositionStart();
|
||||
defaultFormat.length = getTextLength();
|
||||
defaultFormat.format.clearBackground();
|
||||
defaultFormat.format.setForeground(QBrush(m_textColor, Qt::SolidPattern));
|
||||
|
||||
// If we are editing, draw selections
|
||||
if (edit && isTextSelected())
|
||||
{
|
||||
QTextLayout::FormatRange before = defaultFormat;
|
||||
QTextLayout::FormatRange after = defaultFormat;
|
||||
|
||||
before.start = getPositionStart();
|
||||
before.length = m_selectionStart;
|
||||
after.start = m_selectionEnd;
|
||||
after.length = getTextLength() - m_selectionEnd;
|
||||
|
||||
QPalette palette = QApplication::palette();
|
||||
QTextLayout::FormatRange selectedFormat = defaultFormat;
|
||||
selectedFormat.start = m_selectionStart;
|
||||
selectedFormat.length = getSelectionLength();
|
||||
selectedFormat.format.setForeground(palette.brush(QPalette::HighlightedText));
|
||||
selectedFormat.format.setBackground(palette.brush(QPalette::Highlight));
|
||||
|
||||
selections = { before, selectedFormat, after};
|
||||
}
|
||||
else
|
||||
{
|
||||
selections.push_back(defaultFormat);
|
||||
}
|
||||
|
||||
// Draw text
|
||||
m_textLayout.draw(painter, QPointF(0.0, 0.0), selections, QRectF(0, 0, parameters.boundingRectangle.width(), parameters.boundingRectangle.height()));
|
||||
|
||||
// If we are editing, also draw text
|
||||
if (edit)
|
||||
{
|
||||
m_textLayout.drawCursor(painter, QPointF(0.0, 0.0), m_positionCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFTextEditPseudowidget::updateTextLayout()
|
||||
{
|
||||
// Prepare display text
|
||||
|
@ -1872,7 +2025,7 @@ void PDFTextEditPseudowidget::updateTextLayout()
|
|||
m_textLayout.setText(m_displayText);
|
||||
m_textLayout.beginLayout();
|
||||
|
||||
QPointF textLinePosition = m_widgetRect.topLeft();
|
||||
QPointF textLinePosition(0.0, 0.0);
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
@ -1936,7 +2089,7 @@ int PDFTextEditPseudowidget::getNextPrevCursorPosition(int referencePosition, in
|
|||
}
|
||||
else if (steps < 0)
|
||||
{
|
||||
for (int i = 0; i < steps; ++i)
|
||||
for (int i = 0; i < -steps; ++i)
|
||||
{
|
||||
cursor = m_textLayout.previousCursorPosition(cursor, mode);
|
||||
}
|
||||
|
|
|
@ -451,6 +451,7 @@ class PDFTextEditPseudowidget
|
|||
public:
|
||||
explicit inline PDFTextEditPseudowidget(PDFFormField::FieldFlags flags);
|
||||
|
||||
void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event);
|
||||
void keyPressEvent(QWidget* widget, QKeyEvent* event);
|
||||
|
||||
inline bool isReadonly() const { return m_flags.testFlag(PDFFormField::ReadOnly); }
|
||||
|
@ -512,6 +513,10 @@ public:
|
|||
void performRemoveSelectedText();
|
||||
void performInsertText(const QString& text);
|
||||
|
||||
/// Draw text edit using given parameters
|
||||
/// \param parameters Parameters
|
||||
void draw(AnnotationDrawParameters& parameters, bool edit) const;
|
||||
|
||||
private:
|
||||
/// This function does following things:
|
||||
/// 1) Clamps edit text to fit maximum length
|
||||
|
@ -599,19 +604,30 @@ public:
|
|||
explicit PDFFormFieldWidgetEditor(PDFFormManager* formManager, PDFFormWidget formWidget, QObject* parent);
|
||||
virtual ~PDFFormFieldWidgetEditor() = default;
|
||||
|
||||
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event);
|
||||
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event);
|
||||
virtual void keyReleaseEvent(QWidget* widget, QKeyEvent* event);
|
||||
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event);
|
||||
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event);
|
||||
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event);
|
||||
|
||||
virtual bool isEditorDrawEnabled() const { return false; }
|
||||
|
||||
const PDFFormWidget* getFormWidget() const { return &m_formWidget; }
|
||||
PDFFormField* getFormField() const { return m_formWidget.getParent(); }
|
||||
PDFObjectReference getWidgetAnnotation() const { return m_formWidget.getWidget(); }
|
||||
|
||||
void setFocus(bool hasFocus);
|
||||
|
||||
/// Draw form field widget using given parameters
|
||||
/// \param parameters Parameters
|
||||
virtual void draw(AnnotationDrawParameters& parameters) const;
|
||||
|
||||
protected:
|
||||
/// This function is called every time, the focus state changes
|
||||
/// \param focused If editor was focused, or not
|
||||
virtual void setFocusImpl(bool focused) { Q_UNUSED(focused); }
|
||||
|
||||
void performKeypadNavigation(QWidget* widget, QKeyEvent* event);
|
||||
|
||||
PDFFormManager* m_formManager;
|
||||
|
@ -683,6 +699,20 @@ public:
|
|||
explicit PDFFormFieldTextBoxEditor(PDFFormManager* formManager, PDFFormWidget formWidget, QObject* parent);
|
||||
virtual ~PDFFormFieldTextBoxEditor() = default;
|
||||
|
||||
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event);
|
||||
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
|
||||
virtual bool isEditorDrawEnabled() const override { return m_hasFocus; }
|
||||
virtual void draw(AnnotationDrawParameters& parameters) const override;
|
||||
|
||||
/// Initializes text edit using actual form field value,
|
||||
/// font, color for text edit appearance.
|
||||
/// \param textEdit Text editor
|
||||
void initializeTextEdit(PDFTextEditPseudowidget* textEdit) const;
|
||||
|
||||
protected:
|
||||
virtual void setFocusImpl(bool focused);
|
||||
|
||||
private:
|
||||
PDFTextEditPseudowidget m_textEdit;
|
||||
};
|
||||
|
@ -831,36 +861,17 @@ public:
|
|||
/// Get widget rectangle (from annotation)
|
||||
QRectF getWidgetRectangle(const PDFFormWidget& widget) const;
|
||||
|
||||
/// Returns editor for form field
|
||||
PDFFormFieldWidgetEditor* getEditor(const PDFFormField* formField) const;
|
||||
|
||||
// interface IDrawWidgetInputInterface
|
||||
|
||||
/// Handles key press event from widget
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
|
||||
/// Handles key release event from widget
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void keyReleaseEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
|
||||
/// Handles mouse press event from widget
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) override;
|
||||
|
||||
/// Handles mouse release event from widget
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
|
||||
|
||||
/// Handles mouse move event from widge
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
|
||||
|
||||
/// Handles mouse wheel event from widget
|
||||
/// \param widget Widget
|
||||
/// \param event Event
|
||||
virtual void wheelEvent(QWidget* widget, QWheelEvent* event) override;
|
||||
|
||||
/// Returns tooltip generated from annotation
|
||||
|
@ -879,7 +890,6 @@ private:
|
|||
void updateFormWidgetEditors();
|
||||
void updateFieldValues();
|
||||
|
||||
PDFFormFieldWidgetEditor* getEditor(const PDFFormField* formField) const;
|
||||
MouseEventInfo getMouseEventInfo(QWidget* widget, QPoint point);
|
||||
|
||||
struct MouseGrabInfo
|
||||
|
|
|
@ -788,6 +788,12 @@ PDFMagnifierTool* PDFToolManager::getMagnifierTool() const
|
|||
return qobject_cast<PDFMagnifierTool*>(m_predefinedTools[MagnifierTool]);
|
||||
}
|
||||
|
||||
void PDFToolManager::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(event);
|
||||
}
|
||||
|
||||
void PDFToolManager::keyPressEvent(QWidget* widget, QKeyEvent* event)
|
||||
{
|
||||
event->ignore();
|
||||
|
|
|
@ -446,6 +446,9 @@ public:
|
|||
/// Returns magnifier tool
|
||||
PDFMagnifierTool* getMagnifierTool() const;
|
||||
|
||||
/// Handles shortcut override event
|
||||
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) override;
|
||||
|
||||
/// Handles key press event from widget, over which tool operates
|
||||
/// \param widget Widget, over which tool operates
|
||||
/// \param event Event
|
||||
|
|
Loading…
Reference in New Issue