Signature plugin: style settings

This commit is contained in:
Jakub Melka 2022-04-10 19:30:12 +02:00
parent e5dd010609
commit 1325f87a10
11 changed files with 527 additions and 77 deletions

View File

@ -23,6 +23,7 @@
#include <QFontDialog>
#include <QColorDialog>
#include <QLineEdit>
namespace pdf
{
@ -53,6 +54,13 @@ PDFPageContentEditorStyleSettings::PDFPageContentEditorStyleSettings(QWidget* pa
connect(ui->selectPenColorButton, &QToolButton::clicked, this, &PDFPageContentEditorStyleSettings::onSelectPenColorButtonClicked);
connect(ui->selectBrushColorButton, &QToolButton::clicked, this, &PDFPageContentEditorStyleSettings::onSelectBrushColorButtonClicked);
connect(ui->selectFontButton, &QToolButton::clicked, this, &PDFPageContentEditorStyleSettings::onSelectFontButtonClicked);
connect(ui->penWidthEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &PDFPageContentEditorStyleSettings::onPenWidthChanged);
connect(ui->penStyleCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PDFPageContentEditorStyleSettings::onPenStyleChanged);
connect(ui->textAngleEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &PDFPageContentEditorStyleSettings::onTextAngleChanged);
connect(ui->penColorCombo->lineEdit(), &QLineEdit::editingFinished, this, &PDFPageContentEditorStyleSettings::onPenColorComboTextChanged);
connect(ui->penColorCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PDFPageContentEditorStyleSettings::onPenColorComboIndexChanged);
connect(ui->brushColorCombo->lineEdit(), &QLineEdit::editingFinished, this, &PDFPageContentEditorStyleSettings::onBrushColorComboTextChanged);
connect(ui->brushColorCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PDFPageContentEditorStyleSettings::onBrushColorComboIndexChanged);
m_alignmentMapper.setMapping(ui->al11Button, int(Qt::AlignLeft | Qt::AlignTop));
m_alignmentMapper.setMapping(ui->al12Button, int(Qt::AlignHCenter | Qt::AlignTop));
@ -64,6 +72,12 @@ PDFPageContentEditorStyleSettings::PDFPageContentEditorStyleSettings(QWidget* pa
m_alignmentMapper.setMapping(ui->al32Button, int(Qt::AlignHCenter | Qt::AlignBottom));
m_alignmentMapper.setMapping(ui->al33Button, int(Qt::AlignRight | Qt::AlignBottom));
for (QRadioButton* radioButton : findChildren<QRadioButton*>())
{
connect(radioButton, &QRadioButton::clicked, &m_alignmentMapper, QOverload<>::of(&QSignalMapper::map));
}
connect(&m_alignmentMapper, &QSignalMapper::mappedInt, this, &PDFPageContentEditorStyleSettings::onAlignmentRadioButtonClicked);
loadFromElement(nullptr, true);
}
@ -121,10 +135,14 @@ void PDFPageContentEditorStyleSettings::loadFromElement(const PDFPageContentElem
}
ui->textAlignmentLabel->setEnabled(hasText);
ui->textAngleLabel->setEnabled(hasText);
ui->textAngleEdit->setEnabled(hasText);
QPen pen(Qt::SolidLine);
QBrush brush(Qt::transparent);
QFont font = QGuiApplication::font();
Qt::Alignment alignment = Qt::AlignCenter;
PDFReal textAngle = 0.0;
if (styledElement)
{
@ -136,12 +154,14 @@ void PDFPageContentEditorStyleSettings::loadFromElement(const PDFPageContentElem
{
font = textElement->getFont();
alignment = textElement->getAlignment();
textAngle = textElement->getAngle();
}
setPen(pen, forceUpdate);
setBrush(brush, forceUpdate);
setFont(font, forceUpdate);
setFontAlignment(alignment, forceUpdate);
setTextAngle(textAngle, forceUpdate);
}
void PDFPageContentEditorStyleSettings::setPen(const QPen& pen, bool forceUpdate)
@ -207,6 +227,17 @@ void PDFPageContentEditorStyleSettings::setFontAlignment(Qt::Alignment alignment
}
}
void PDFPageContentEditorStyleSettings::setTextAngle(PDFReal angle, bool forceUpdate)
{
if (ui->textAngleEdit->value() != angle || forceUpdate)
{
const bool oldBlockSignals = blockSignals(true);
ui->textAngleEdit->setValue(angle);
blockSignals(oldBlockSignals);
emit textAngleChanged(ui->textAngleEdit->value());
}
}
QIcon PDFPageContentEditorStyleSettings::getIconForColor(QColor color) const
{
QIcon icon;
@ -229,7 +260,14 @@ void PDFPageContentEditorStyleSettings::setColorToComboBox(QComboBox* comboBox,
QString name = color.name(QColor::HexArgb);
const int index = comboBox->findText(name);
int index = comboBox->findData(color, Qt::UserRole, Qt::MatchExactly);
if (index == -1)
{
// Jakub Melka: try to find text (color name)
index = comboBox->findText(name);
}
if (index != -1)
{
comboBox->setCurrentIndex(index);
@ -286,6 +324,100 @@ void PDFPageContentEditorStyleSettings::onSelectBrushColorButtonClicked()
setBrushColor(color);
}
void PDFPageContentEditorStyleSettings::onPenWidthChanged(double value)
{
if (m_pen.widthF() != value)
{
m_pen.setWidthF(value);
emit penChanged(m_pen);
}
}
void PDFPageContentEditorStyleSettings::onTextAngleChanged(double value)
{
emit textAngleChanged(value);
}
void PDFPageContentEditorStyleSettings::onAlignmentRadioButtonClicked(int alignment)
{
Qt::Alignment alignmentValue = static_cast<Qt::Alignment>(alignment);
if (m_alignment != alignmentValue)
{
m_alignment = alignmentValue;
emit alignmentChanged(m_alignment);
}
}
void PDFPageContentEditorStyleSettings::onPenStyleChanged()
{
Qt::PenStyle penStyle = static_cast<Qt::PenStyle>(ui->penStyleCombo->currentData().toInt());
if (m_pen.style() != penStyle)
{
m_pen.setStyle(penStyle);
emit penChanged(m_pen);
}
}
void PDFPageContentEditorStyleSettings::onPenColorComboTextChanged()
{
QColor color(ui->penColorCombo->currentText());
if (color.isValid())
{
setColorToComboBox(ui->penColorCombo, color);
if (m_pen.color() != color)
{
m_pen.setColor(color);
emit penChanged(m_pen);
}
}
else if (ui->penColorCombo->currentIndex() != -1)
{
ui->penColorCombo->setEditText(ui->penColorCombo->itemText(ui->penColorCombo->currentIndex()));
}
}
void PDFPageContentEditorStyleSettings::onPenColorComboIndexChanged()
{
const int index = ui->penColorCombo->currentIndex();
QColor color = ui->penColorCombo->itemData(index, Qt::UserRole).value<QColor>();
if (color.isValid() && m_pen.color() != color)
{
m_pen.setColor(color);
emit penChanged(m_pen);
}
}
void PDFPageContentEditorStyleSettings::onBrushColorComboTextChanged()
{
QColor color(ui->brushColorCombo->currentText());
if (color.isValid())
{
setColorToComboBox(ui->brushColorCombo, color);
if (m_brush.color() != color)
{
m_brush.setColor(color);
emit brushChanged(m_brush);
}
}
else if (ui->brushColorCombo->currentIndex() != -1)
{
ui->brushColorCombo->setEditText(ui->brushColorCombo->itemText(ui->brushColorCombo->currentIndex()));
}
}
void PDFPageContentEditorStyleSettings::onBrushColorComboIndexChanged()
{
const int index = ui->brushColorCombo->currentIndex();
QColor color = ui->brushColorCombo->itemData(index, Qt::UserRole).value<QColor>();
if (color.isValid() && m_brush.color() != color)
{
m_brush.setColor(color);
emit brushChanged(m_brush);
}
}
void PDFPageContentEditorStyleSettings::onFontChanged(const QFont& font)
{
if (m_font != font)

View File

@ -65,17 +65,27 @@ public:
void setBrush(const QBrush& brush, bool forceUpdate);
void setFont(const QFont& font, bool forceUpdate);
void setFontAlignment(Qt::Alignment alignment, bool forceUpdate);
void setTextAngle(PDFReal angle, bool forceUpdate);
signals:
void penChanged(const QPen& pen);
void brushChanged(const QBrush& brush);
void fontChanged(const QFont& font);
void alignmentChanged(Qt::Alignment alignment);
void textAngleChanged(pdf::PDFReal angle);
private slots:
void onSelectFontButtonClicked();
void onSelectPenColorButtonClicked();
void onSelectBrushColorButtonClicked();
void onPenWidthChanged(double value);
void onTextAngleChanged(double value);
void onAlignmentRadioButtonClicked(int alignment);
void onPenStyleChanged();
void onPenColorComboTextChanged();
void onPenColorComboIndexChanged();
void onBrushColorComboTextChanged();
void onBrushColorComboIndexChanged();
private:
Ui::PDFPageContentEditorStyleSettings* ui;

View File

@ -28,67 +28,9 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="brushColorCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="brushColorLabel">
<property name="text">
<string>Brush Color</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="fontLabel">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QFontComboBox" name="fontComboBox"/>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0">
<widget class="QLabel" name="textAlignmentLabel">
<property name="text">
<string>Text Alignment</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="penColorCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="penColorLabel">
<property name="text">
<string>Pen Color</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QToolButton" name="selectFontButton">
<property name="text">
@ -96,27 +38,20 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QToolButton" name="selectBrushColorButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="selectPenColorButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="penWidthEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="brushColorLabel">
<property name="text">
<string>Brush Color</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="penStyleCombo"/>
</item>
<item row="5" column="1" colspan="2">
<item row="6" column="1" colspan="2">
<layout class="QGridLayout" name="textAlignmentLayout">
<item row="1" column="0">
<widget class="QRadioButton" name="al21Button">
@ -196,6 +131,88 @@
</item>
</layout>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="brushColorCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="fontLabel">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="selectPenColorButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="penColorLabel">
<property name="text">
<string>Pen Color</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QToolButton" name="selectBrushColorButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="textAlignmentLabel">
<property name="text">
<string>Text Alignment</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="penColorCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="textAngleLabel">
<property name="text">
<string>Text Angle</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="textAngleEdit">
<property name="minimum">
<double>-90.000000000000000</double>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@ -38,6 +38,51 @@ PDFCreatePCElementTool::PDFCreatePCElementTool(PDFDrawWidgetProxy* proxy,
}
void PDFCreatePCElementTool::setPen(const QPen& pen)
{
if (PDFPageContentStyledElement* styledElement = dynamic_cast<PDFPageContentStyledElement*>(getElement()))
{
styledElement->setPen(pen);
emit getProxy()->repaintNeeded();
}
}
void PDFCreatePCElementTool::setBrush(const QBrush& brush)
{
if (PDFPageContentStyledElement* styledElement = dynamic_cast<PDFPageContentStyledElement*>(getElement()))
{
styledElement->setBrush(brush);
emit getProxy()->repaintNeeded();
}
}
void PDFCreatePCElementTool::setFont(const QFont& font)
{
if (PDFPageContentElementTextBox* textBoxElement = dynamic_cast<PDFPageContentElementTextBox*>(getElement()))
{
textBoxElement->setFont(font);
emit getProxy()->repaintNeeded();
}
}
void PDFCreatePCElementTool::setAlignment(Qt::Alignment alignment)
{
if (PDFPageContentElementTextBox* textBoxElement = dynamic_cast<PDFPageContentElementTextBox*>(getElement()))
{
textBoxElement->setAlignment(alignment);
emit getProxy()->repaintNeeded();
}
}
void PDFCreatePCElementTool::setTextAngle(PDFReal angle)
{
if (PDFPageContentElementTextBox* textBoxElement = dynamic_cast<PDFPageContentElementTextBox*>(getElement()))
{
textBoxElement->setAngle(angle);
emit getProxy()->repaintNeeded();
}
}
QRectF PDFCreatePCElementTool::getRectangleFromPickTool(PDFPickTool* pickTool,
const QMatrix& pagePointToDevicePointMatrix)
{
@ -120,6 +165,16 @@ void PDFCreatePCElementRectangleTool::drawPage(QPainter* painter,
m_element->drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
}
const PDFPageContentElement* PDFCreatePCElementRectangleTool::getElement() const
{
return m_element;
}
PDFPageContentElement* PDFCreatePCElementRectangleTool::getElement()
{
return m_element;
}
void PDFCreatePCElementRectangleTool::onRectanglePicked(PDFInteger pageIndex, QRectF pageRectangle)
{
if (pageRectangle.isEmpty())
@ -206,6 +261,16 @@ void PDFCreatePCElementLineTool::drawPage(QPainter* painter,
m_element->drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
}
const PDFPageContentElement* PDFCreatePCElementLineTool::getElement() const
{
return m_element;
}
PDFPageContentElement* PDFCreatePCElementLineTool::getElement()
{
return m_element;
}
void PDFCreatePCElementLineTool::clear()
{
m_startPoint = std::nullopt;
@ -298,6 +363,16 @@ void PDFCreatePCElementSvgTool::drawPage(QPainter* painter,
m_element->drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
}
const PDFPageContentElement* PDFCreatePCElementSvgTool::getElement() const
{
return m_element;
}
PDFPageContentElement* PDFCreatePCElementSvgTool::getElement()
{
return m_element;
}
void PDFCreatePCElementSvgTool::onRectanglePicked(PDFInteger pageIndex, QRectF pageRectangle)
{
if (pageRectangle.isEmpty())
@ -360,6 +435,16 @@ void PDFCreatePCElementDotTool::drawPage(QPainter* painter,
painter->drawPoint(point);
}
const PDFPageContentElement* PDFCreatePCElementDotTool::getElement() const
{
return m_element;
}
PDFPageContentElement* PDFCreatePCElementDotTool::getElement()
{
return m_element;
}
void PDFCreatePCElementDotTool::onPointPicked(PDFInteger pageIndex, QPointF pagePoint)
{
m_element->setPageIndex(pageIndex);
@ -409,6 +494,16 @@ void PDFCreatePCElementFreehandCurveTool::drawPage(QPainter* painter,
m_element->drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
}
const PDFPageContentElement* PDFCreatePCElementFreehandCurveTool::getElement() const
{
return m_element;
}
PDFPageContentElement* PDFCreatePCElementFreehandCurveTool::getElement()
{
return m_element;
}
void PDFCreatePCElementFreehandCurveTool::mousePressEvent(QWidget* widget, QMouseEvent* event)
{
Q_UNUSED(widget);
@ -554,6 +649,16 @@ void PDFCreatePCElementTextTool::drawPage(QPainter* painter,
}
}
const PDFPageContentElement* PDFCreatePCElementTextTool::getElement() const
{
return m_element;
}
PDFPageContentElement* PDFCreatePCElementTextTool::getElement()
{
return m_element;
}
void PDFCreatePCElementTextTool::resetTool()
{
m_textEditWidget->setText(QString());
@ -767,4 +872,25 @@ void PDFCreatePCElementTextTool::wheelEvent(QWidget* widget, QWheelEvent* event)
}
}
void PDFCreatePCElementTextTool::setFont(const QFont& font)
{
BaseClass::setFont(font);
m_textEditWidget->setAppearance(font, m_element->getAlignment(), m_element->getRectangle(), std::numeric_limits<int>::max(), m_element->getPen().color());
emit getProxy()->repaintNeeded();
}
void PDFCreatePCElementTextTool::setAlignment(Qt::Alignment alignment)
{
BaseClass::setAlignment(alignment);
m_textEditWidget->setAppearance(m_element->getFont(), alignment, m_element->getRectangle(), std::numeric_limits<int>::max(), m_element->getPen().color());
emit getProxy()->repaintNeeded();
}
void PDFCreatePCElementTextTool::setPen(const QPen& pen)
{
BaseClass::setPen(pen);
m_textEditWidget->setAppearance(m_element->getFont(), m_element->getAlignment(), m_element->getRectangle(), std::numeric_limits<int>::max(), pen.color());
emit getProxy()->repaintNeeded();
}
} // namespace pdf

View File

@ -24,6 +24,7 @@ namespace pdf
{
class PDFPageContentScene;
class PDFPageContentElement;
class PDFPageContentSvgElement;
class PDFPageContentElementDot;
class PDFPageContentElementLine;
@ -32,14 +33,24 @@ class PDFPageContentElementRectangle;
class PDFPageContentElementFreehandCurve;
class PDFTextEditPseudowidget;
class PDFCreatePCElementTool : public PDFWidgetTool
class PDF4QTLIBSHARED_EXPORT PDFCreatePCElementTool : public PDFWidgetTool
{
Q_OBJECT
public:
PDFCreatePCElementTool(PDFDrawWidgetProxy* proxy,
PDFPageContentScene* scene,
QAction* action,
QObject* parent);
virtual const PDFPageContentElement* getElement() const = 0;
virtual PDFPageContentElement* getElement() = 0;
virtual void setPen(const QPen& pen);
virtual void setBrush(const QBrush& brush);
virtual void setFont(const QFont& font);
virtual void setAlignment(Qt::Alignment alignment);
virtual void setTextAngle(pdf::PDFReal angle);
protected:
static QRectF getRectangleFromPickTool(PDFPickTool* pickTool, const QMatrix& pagePointToDevicePointMatrix);
@ -69,6 +80,9 @@ public:
const QMatrix& pagePointToDevicePointMatrix,
QList<PDFRenderError>& errors) const override;
virtual const PDFPageContentElement* getElement() const override;
virtual PDFPageContentElement* getElement() override;
private:
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
@ -99,6 +113,9 @@ public:
const QMatrix& pagePointToDevicePointMatrix,
QList<PDFRenderError>& errors) const override;
virtual const PDFPageContentElement* getElement() const override;
virtual PDFPageContentElement* getElement() override;
private:
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
@ -130,6 +147,9 @@ public:
const QMatrix& pagePointToDevicePointMatrix,
QList<PDFRenderError>& errors) const override;
virtual const PDFPageContentElement* getElement() const override;
virtual PDFPageContentElement* getElement() override;
private:
void clear();
void onPointPicked(pdf::PDFInteger pageIndex, QPointF pagePoint);
@ -161,6 +181,9 @@ public:
const QMatrix& pagePointToDevicePointMatrix,
QList<PDFRenderError>& errors) const override;
virtual const PDFPageContentElement* getElement() const override;
virtual PDFPageContentElement* getElement() override;
private:
void onPointPicked(pdf::PDFInteger pageIndex, QPointF pagePoint);
@ -190,6 +213,9 @@ public:
const QMatrix& pagePointToDevicePointMatrix,
QList<PDFRenderError>& errors) const override;
virtual const PDFPageContentElement* getElement() const override;
virtual PDFPageContentElement* getElement() override;
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) override;
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
@ -225,6 +251,13 @@ public:
const QMatrix& pagePointToDevicePointMatrix,
QList<PDFRenderError>& errors) const override;
virtual const PDFPageContentElement* getElement() const override;
virtual PDFPageContentElement* getElement() override;
virtual void setPen(const QPen& pen);
virtual void setFont(const QFont& font) override;
virtual void setAlignment(Qt::Alignment alignment) override;
virtual void setActiveImpl(bool active) override;
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) override;
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event) override;

View File

@ -33,7 +33,8 @@ PDFPageContentEditorWidget::PDFPageContentEditorWidget(QWidget* parent) :
ui(new Ui::PDFPageContentEditorWidget),
m_toolBoxColumnCount(6),
m_scene(nullptr),
m_selectionChangeEnabled(true)
m_selectionChangeEnabled(true),
m_updatesEnabled(true)
{
ui->setupUi(this);
@ -81,6 +82,12 @@ PDFPageContentEditorWidget::PDFPageContentEditorWidget(QWidget* parent) :
connect(&m_actionMapper, &QSignalMapper::mappedObject, this, &PDFPageContentEditorWidget::onActionTriggerRequest);
connect(&m_operationMapper, &QSignalMapper::mappedInt, this, &PDFPageContentEditorWidget::operationTriggered);
connect(ui->itemsListWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &PDFPageContentEditorWidget::onItemSelectionChanged);
connect(ui->appearanceSettingsWidget, &PDFPageContentEditorStyleSettings::penChanged, this, &PDFPageContentEditorWidget::penChanged);
connect(ui->appearanceSettingsWidget, &PDFPageContentEditorStyleSettings::brushChanged, this, &PDFPageContentEditorWidget::brushChanged);
connect(ui->appearanceSettingsWidget, &PDFPageContentEditorStyleSettings::fontChanged, this, &PDFPageContentEditorWidget::fontChanged);
connect(ui->appearanceSettingsWidget, &PDFPageContentEditorStyleSettings::alignmentChanged, this, &PDFPageContentEditorWidget::alignmentChanged);
connect(ui->appearanceSettingsWidget, &PDFPageContentEditorStyleSettings::textAngleChanged, this, &PDFPageContentEditorWidget::textAngleChanged);
}
PDFPageContentEditorWidget::~PDFPageContentEditorWidget()
@ -133,6 +140,12 @@ QToolButton* PDFPageContentEditorWidget::getToolButtonForOperation(int operation
void PDFPageContentEditorWidget::updateItemsInListWidget()
{
if (!m_updatesEnabled)
{
return;
}
pdf::PDFTemporaryValueChange guard(&m_updatesEnabled, false);
ui->itemsListWidget->setUpdatesEnabled(false);
if (m_scene)
@ -252,4 +265,9 @@ void PDFPageContentEditorWidget::setSelection(const std::set<PDFInteger>& select
}
}
void PDFPageContentEditorWidget::loadStyleFromElement(const PDFPageContentElement* element)
{
ui->appearanceSettingsWidget->loadFromElement(element, false);
}
} // namespace pdf

View File

@ -35,6 +35,7 @@ class PDFPageContentEditorWidget;
namespace pdf
{
class PDFPageContentScene;
class PDFPageContentElement;
class PDF4QTLIBSHARED_EXPORT PDFPageContentEditorWidget : public QDockWidget
{
@ -58,10 +59,20 @@ public:
std::set<PDFInteger> getSelection() const;
void setSelection(const std::set<PDFInteger>& selection);
/// Loads style from element, element can be nullptr
/// \param element Element
void loadStyleFromElement(const PDFPageContentElement* element);
signals:
void operationTriggered(int operation);
void itemSelectionChangedByUser();
void penChanged(const QPen& pen);
void brushChanged(const QBrush& brush);
void fontChanged(const QFont& font);
void alignmentChanged(Qt::Alignment alignment);
void textAngleChanged(pdf::PDFReal angle);
private:
void onActionTriggerRequest(QObject* actionObject);
void onActionChanged();
@ -74,6 +85,7 @@ private:
QSize m_toolButtonIconSize;
PDFPageContentScene* m_scene;
bool m_selectionChangeEnabled;
bool m_updatesEnabled;
};
} // namespace pdf

View File

@ -162,8 +162,23 @@
<string>Appearance</string>
</property>
<layout class="QVBoxLayout" name="appearanceLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="pdf::PDFPageContentEditorStyleSettings" name="widget" native="true"/>
<widget class="pdf::PDFPageContentEditorStyleSettings" name="appearanceSettingsWidget" native="true"/>
</item>
</layout>
</widget>

View File

@ -428,6 +428,7 @@ void PDFTextEditPseudowidget::setAppearance(const PDFAnnotationDefaultAppearance
m_maxTextLength = maxTextLength;
m_widgetRect = rect;
updateTextLayout();
}
void PDFTextEditPseudowidget::setAppearance(const QFont& font,
@ -453,6 +454,7 @@ void PDFTextEditPseudowidget::setAppearance(const QFont& font,
m_maxTextLength = maxTextLength;
m_widgetRect = rect;
updateTextLayout();
}
void PDFTextEditPseudowidget::performCut()

View File

@ -139,6 +139,7 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget)
for (pdf::PDFWidgetTool* tool : m_tools)
{
toolManager->addTool(tool);
connect(tool, &pdf::PDFWidgetTool::toolActivityChanged, this, &SignaturePlugin::onToolActivityChanged);
}
m_widget->addInputInterface(&m_scene);
@ -206,6 +207,76 @@ void SignaturePlugin::onWidgetSelectionChanged()
m_scene.setSelectedElementIds(m_editorWidget->getSelection());
}
pdf::PDFWidgetTool* SignaturePlugin::getActiveTool()
{
for (pdf::PDFWidgetTool* currentTool : m_tools)
{
if (currentTool->isActive())
{
return currentTool;
}
}
return nullptr;
}
void SignaturePlugin::onToolActivityChanged()
{
if (m_editorWidget)
{
pdf::PDFWidgetTool* activeTool = getActiveTool();
const pdf::PDFPageContentElement* element = nullptr;
pdf::PDFCreatePCElementTool* tool = qobject_cast<pdf::PDFCreatePCElementTool*>(activeTool);
if (tool)
{
element = tool->getElement();
}
m_editorWidget->loadStyleFromElement(element);
}
}
void SignaturePlugin::onPenChanged(const QPen& pen)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setPen(pen);
}
}
void SignaturePlugin::onBrushChanged(const QBrush& brush)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setBrush(brush);
}
}
void SignaturePlugin::onFontChanged(const QFont& font)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setFont(font);
}
}
void SignaturePlugin::onAlignmentChanged(Qt::Alignment alignment)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setAlignment(alignment);
}
}
void SignaturePlugin::onTextAngleChanged(pdf::PDFReal angle)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setTextAngle(angle);
}
}
void SignaturePlugin::setActive(bool active)
{
if (m_scene.isActive() != active)
@ -325,6 +396,12 @@ void SignaturePlugin::updateDockWidget()
{
m_editorWidget->addAction(action);
}
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::penChanged, this, &SignaturePlugin::onPenChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::brushChanged, this, &SignaturePlugin::onBrushChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::fontChanged, this, &SignaturePlugin::onFontChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::alignmentChanged, this, &SignaturePlugin::onAlignmentChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::textAngleChanged, this, &SignaturePlugin::onTextAngleChanged);
}
}

View File

@ -51,6 +51,13 @@ private:
void onSceneChanged(bool graphicsOnly);
void onSceneSelectionChanged();
void onWidgetSelectionChanged();
void onToolActivityChanged();
void onPenChanged(const QPen& pen);
void onBrushChanged(const QBrush& brush);
void onFontChanged(const QFont& font);
void onAlignmentChanged(Qt::Alignment alignment);
void onTextAngleChanged(pdf::PDFReal angle);
enum Action
{
@ -106,6 +113,7 @@ private:
pdf::PDFPageContentScene m_scene;
bool m_sceneSelectionChangeEnabled;
pdf::PDFWidgetTool* getActiveTool();
};
} // namespace pdfplugin