mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Issue #236: Highligting - Allow color selection and intensity [Enhancement]
This commit is contained in:
@ -22,9 +22,11 @@
|
|||||||
#include "pdfcompiler.h"
|
#include "pdfcompiler.h"
|
||||||
#include "pdfwidgetformmanager.h"
|
#include "pdfwidgetformmanager.h"
|
||||||
#include "pdfwidgetannotation.h"
|
#include "pdfwidgetannotation.h"
|
||||||
|
#include "pdfwidgetutils.h"
|
||||||
|
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QColorDialog>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include "pdfdbgheap.h"
|
#include "pdfdbgheap.h"
|
||||||
@ -924,12 +926,14 @@ PDFCreateHighlightTextTool::PDFCreateHighlightTextTool(PDFDrawWidgetProxy* proxy
|
|||||||
BaseClass(proxy, parent),
|
BaseClass(proxy, parent),
|
||||||
m_toolManager(toolManager),
|
m_toolManager(toolManager),
|
||||||
m_actionGroup(actionGroup),
|
m_actionGroup(actionGroup),
|
||||||
|
m_colorDialog(nullptr),
|
||||||
m_type(AnnotationType::Highlight),
|
m_type(AnnotationType::Highlight),
|
||||||
m_isCursorOverText(false)
|
m_isCursorOverText(false)
|
||||||
{
|
{
|
||||||
connect(m_actionGroup, &QActionGroup::triggered, this, &PDFCreateHighlightTextTool::onActionTriggered);
|
connect(m_actionGroup, &QActionGroup::triggered, this, &PDFCreateHighlightTextTool::onActionTriggered);
|
||||||
|
|
||||||
updateActions();
|
updateActions();
|
||||||
|
updateInitialColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFCreateHighlightTextTool::drawPage(QPainter* painter,
|
void PDFCreateHighlightTextTool::drawPage(QPainter* painter,
|
||||||
@ -988,7 +992,7 @@ void PDFCreateHighlightTextTool::mouseReleaseEvent(QWidget* widget, QMouseEvent*
|
|||||||
// Jakub Melka: handle the selection
|
// Jakub Melka: handle the selection
|
||||||
PDFTextLayoutGetter textLayoutGetter = getProxy()->getTextLayoutCompiler()->getTextLayoutLazy(pageIndex);
|
PDFTextLayoutGetter textLayoutGetter = getProxy()->getTextLayoutCompiler()->getTextLayoutLazy(pageIndex);
|
||||||
PDFTextLayout textLayout = textLayoutGetter;
|
PDFTextLayout textLayout = textLayoutGetter;
|
||||||
setSelection(textLayout.createTextSelection(pageIndex, m_selectionInfo.selectionStartPoint, pagePoint));
|
setSelection(textLayout.createTextSelection(pageIndex, m_selectionInfo.selectionStartPoint, pagePoint, m_color));
|
||||||
|
|
||||||
QPolygonF quadrilaterals;
|
QPolygonF quadrilaterals;
|
||||||
PDFTextSelectionPainter textSelectionPainter(&m_textSelection);
|
PDFTextSelectionPainter textSelectionPainter(&m_textSelection);
|
||||||
@ -1003,21 +1007,21 @@ void PDFCreateHighlightTextTool::mouseReleaseEvent(QWidget* widget, QMouseEvent*
|
|||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
case AnnotationType::Highlight:
|
case AnnotationType::Highlight:
|
||||||
annotationReference = modifier.getBuilder()->createAnnotationHighlight(page, quadrilaterals, Qt::yellow);
|
annotationReference = modifier.getBuilder()->createAnnotationHighlight(page, quadrilaterals, m_color);
|
||||||
modifier.getBuilder()->setAnnotationOpacity(annotationReference, 0.2);
|
modifier.getBuilder()->setAnnotationOpacity(annotationReference, 0.2);
|
||||||
modifier.getBuilder()->updateAnnotationAppearanceStreams(annotationReference);
|
modifier.getBuilder()->updateAnnotationAppearanceStreams(annotationReference);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AnnotationType::Underline:
|
case AnnotationType::Underline:
|
||||||
annotationReference = modifier.getBuilder()->createAnnotationUnderline(page, quadrilaterals, Qt::black);
|
annotationReference = modifier.getBuilder()->createAnnotationUnderline(page, quadrilaterals, m_color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AnnotationType::Squiggly:
|
case AnnotationType::Squiggly:
|
||||||
annotationReference = modifier.getBuilder()->createAnnotationSquiggly(page, quadrilaterals, Qt::red);
|
annotationReference = modifier.getBuilder()->createAnnotationSquiggly(page, quadrilaterals, m_color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AnnotationType::StrikeOut:
|
case AnnotationType::StrikeOut:
|
||||||
annotationReference = modifier.getBuilder()->createAnnotationStrikeout(page, quadrilaterals, Qt::red);
|
annotationReference = modifier.getBuilder()->createAnnotationStrikeout(page, quadrilaterals, m_color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1057,7 +1061,7 @@ void PDFCreateHighlightTextTool::mouseMoveEvent(QWidget* widget, QMouseEvent* ev
|
|||||||
if (m_selectionInfo.pageIndex == pageIndex)
|
if (m_selectionInfo.pageIndex == pageIndex)
|
||||||
{
|
{
|
||||||
// Jakub Melka: handle the selection
|
// Jakub Melka: handle the selection
|
||||||
setSelection(textLayout.createTextSelection(pageIndex, m_selectionInfo.selectionStartPoint, pagePoint));
|
setSelection(textLayout.createTextSelection(pageIndex, m_selectionInfo.selectionStartPoint, pagePoint, m_color));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1094,17 +1098,44 @@ void PDFCreateHighlightTextTool::setActiveImpl(bool active)
|
|||||||
{
|
{
|
||||||
// Just clear the text selection
|
// Just clear the text selection
|
||||||
setSelection(PDFTextSelection());
|
setSelection(PDFTextSelection());
|
||||||
|
|
||||||
|
delete m_colorDialog;
|
||||||
|
m_colorDialog = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_colorDialog = new QColorDialog(m_color, getProxy()->getWidget());
|
||||||
|
m_colorDialog->setWindowTitle(tr("Select Color"));
|
||||||
|
m_colorDialog->setOption(QColorDialog::ShowAlphaChannel, false);
|
||||||
|
m_colorDialog->setOption(QColorDialog::NoButtons, true);
|
||||||
|
m_colorDialog->setOption(QColorDialog::DontUseNativeDialog, true);
|
||||||
|
m_colorDialog->setOption(QColorDialog::NoEyeDropperButton, true);
|
||||||
|
m_colorDialog->setWindowFlag(Qt::Tool);
|
||||||
|
m_colorDialog->move(pdf::PDFWidgetUtils::scaleDPI_x(m_colorDialog, 50), pdf::PDFWidgetUtils::scaleDPI_y(m_colorDialog, 50));
|
||||||
|
connect(m_colorDialog, &QColorDialog::currentColorChanged, this, &PDFCreateHighlightTextTool::onColorChanged);
|
||||||
|
m_colorDialog->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFCreateHighlightTextTool::onActionTriggered(QAction* action)
|
void PDFCreateHighlightTextTool::onActionTriggered(QAction* action)
|
||||||
{
|
{
|
||||||
setActive(action && action->isChecked());
|
|
||||||
|
|
||||||
if (action)
|
if (action)
|
||||||
{
|
{
|
||||||
m_type = static_cast<AnnotationType>(action->data().toInt());
|
AnnotationType type = static_cast<AnnotationType>(action->data().toInt());
|
||||||
|
|
||||||
|
if (m_type != type)
|
||||||
|
{
|
||||||
|
m_type = type;
|
||||||
|
updateInitialColor();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setActive(action && action->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFCreateHighlightTextTool::onColorChanged(const QColor& color)
|
||||||
|
{
|
||||||
|
m_color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFCreateHighlightTextTool::updateCursor()
|
void PDFCreateHighlightTextTool::updateCursor()
|
||||||
@ -1131,6 +1162,33 @@ void PDFCreateHighlightTextTool::setSelection(PDFTextSelection&& textSelection)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFCreateHighlightTextTool::updateInitialColor()
|
||||||
|
{
|
||||||
|
switch (m_type)
|
||||||
|
{
|
||||||
|
case AnnotationType::Highlight:
|
||||||
|
m_color = Qt::yellow;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AnnotationType::Underline:
|
||||||
|
m_color = Qt::black;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AnnotationType::Squiggly:
|
||||||
|
m_color = Qt::red;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AnnotationType::StrikeOut:
|
||||||
|
m_color = Qt::red;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_colorDialog)
|
||||||
|
{
|
||||||
|
m_colorDialog->setCurrentColor(m_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PDFCreateRedactRectangleTool::PDFCreateRedactRectangleTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent) :
|
PDFCreateRedactRectangleTool::PDFCreateRedactRectangleTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent) :
|
||||||
BaseClass(proxy, action, parent),
|
BaseClass(proxy, action, parent),
|
||||||
m_toolManager(toolManager),
|
m_toolManager(toolManager),
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "pdfannotation.h"
|
#include "pdfannotation.h"
|
||||||
|
|
||||||
class QActionGroup;
|
class QActionGroup;
|
||||||
|
class QColorDialog;
|
||||||
|
|
||||||
namespace pdf
|
namespace pdf
|
||||||
{
|
{
|
||||||
@ -307,8 +308,10 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void onActionTriggered(QAction* action);
|
void onActionTriggered(QAction* action);
|
||||||
|
void onColorChanged(const QColor& color);
|
||||||
void updateCursor();
|
void updateCursor();
|
||||||
void setSelection(pdf::PDFTextSelection&& textSelection);
|
void setSelection(pdf::PDFTextSelection&& textSelection);
|
||||||
|
void updateInitialColor();
|
||||||
|
|
||||||
struct SelectionInfo
|
struct SelectionInfo
|
||||||
{
|
{
|
||||||
@ -318,9 +321,11 @@ private:
|
|||||||
|
|
||||||
PDFToolManager* m_toolManager;
|
PDFToolManager* m_toolManager;
|
||||||
QActionGroup* m_actionGroup;
|
QActionGroup* m_actionGroup;
|
||||||
|
QColorDialog* m_colorDialog;
|
||||||
AnnotationType m_type;
|
AnnotationType m_type;
|
||||||
pdf::PDFTextSelection m_textSelection;
|
pdf::PDFTextSelection m_textSelection;
|
||||||
SelectionInfo m_selectionInfo;
|
SelectionInfo m_selectionInfo;
|
||||||
|
QColor m_color;
|
||||||
bool m_isCursorOverText;
|
bool m_isCursorOverText;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
CURRENT:
|
CURRENT:
|
||||||
|
- Issue #236: Highligting - Allow color selection and intensity [Enhancement]
|
||||||
- Issue #229: Can't add picture to PDF
|
- Issue #229: Can't add picture to PDF
|
||||||
- Issue #228: [feature] reverse pages order
|
- Issue #228: [feature] reverse pages order
|
||||||
- Issue #222: UnitTests fails several tests
|
- Issue #222: UnitTests fails several tests
|
||||||
|
Reference in New Issue
Block a user