mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-24 23:47:49 +01:00
Signature plugin: edit item via double click
This commit is contained in:
parent
4fae8a7405
commit
a08d49e8d6
@ -24,6 +24,10 @@
|
|||||||
#include <QFontDialog>
|
#include <QFontDialog>
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QTextEdit>
|
||||||
|
|
||||||
namespace pdf
|
namespace pdf
|
||||||
{
|
{
|
||||||
@ -252,6 +256,71 @@ void PDFPageContentEditorStyleSettings::setTextAngle(PDFReal angle, bool forceUp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PDFPageContentEditorStyleSettings::showEditElementStyleDialog(QWidget* parent,
|
||||||
|
PDFPageContentElement* element)
|
||||||
|
{
|
||||||
|
QDialog dialog(parent);
|
||||||
|
dialog.setWindowTitle(tr("Edit Item"));
|
||||||
|
dialog.setLayout(new QVBoxLayout());
|
||||||
|
|
||||||
|
QTextEdit* textEdit = nullptr;
|
||||||
|
PDFPageContentStyledElement* styledElement = dynamic_cast<PDFPageContentStyledElement*>(element);
|
||||||
|
PDFPageContentElementTextBox* textElement = dynamic_cast<PDFPageContentElementTextBox*>(element);
|
||||||
|
if (textElement)
|
||||||
|
{
|
||||||
|
QGroupBox* contentGroupBox = new QGroupBox(&dialog);
|
||||||
|
textEdit = new QTextEdit(textElement->getText(), contentGroupBox);
|
||||||
|
textEdit->setFont(textElement->getFont());
|
||||||
|
textEdit->setAlignment(textElement->getAlignment());
|
||||||
|
textEdit->setTextColor(textElement->getPen().color());
|
||||||
|
contentGroupBox->setTitle(tr("Content"));
|
||||||
|
contentGroupBox->setLayout(new QVBoxLayout());
|
||||||
|
contentGroupBox->layout()->addWidget(textEdit);
|
||||||
|
dialog.layout()->addWidget(contentGroupBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFPageContentEditorStyleSettings* appearanceWidget = new PDFPageContentEditorStyleSettings(&dialog);
|
||||||
|
appearanceWidget->loadFromElement(element, true);
|
||||||
|
if (textEdit)
|
||||||
|
{
|
||||||
|
connect(appearanceWidget, &PDFPageContentEditorStyleSettings::alignmentChanged, textEdit, &QTextEdit::setAlignment);
|
||||||
|
connect(appearanceWidget, &PDFPageContentEditorStyleSettings::fontChanged, textEdit, &QTextEdit::setFont);
|
||||||
|
connect(appearanceWidget, &PDFPageContentEditorStyleSettings::penChanged, textEdit, [textEdit](const QPen& pen) { textEdit->setTextColor(pen.color()); });
|
||||||
|
}
|
||||||
|
|
||||||
|
QGroupBox* appearanceGroupBox = new QGroupBox(&dialog);
|
||||||
|
appearanceGroupBox->setTitle(tr("Appearance"));
|
||||||
|
appearanceGroupBox->setLayout(new QVBoxLayout());
|
||||||
|
appearanceGroupBox->layout()->addWidget(appearanceWidget);
|
||||||
|
dialog.layout()->addWidget(appearanceGroupBox);
|
||||||
|
|
||||||
|
QDialogButtonBox* dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
|
||||||
|
connect(dialogButtonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
||||||
|
connect(dialogButtonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
||||||
|
dialog.layout()->addWidget(dialogButtonBox);
|
||||||
|
|
||||||
|
if (dialog.exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
if (styledElement)
|
||||||
|
{
|
||||||
|
styledElement->setPen(appearanceWidget->getPen());
|
||||||
|
styledElement->setBrush(appearanceWidget->getBrush());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textElement)
|
||||||
|
{
|
||||||
|
textElement->setText(textEdit->toPlainText());
|
||||||
|
textElement->setFont(appearanceWidget->getFont());
|
||||||
|
textElement->setAlignment(appearanceWidget->getAlignment());
|
||||||
|
textElement->setAngle(appearanceWidget->getTextAngle());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QIcon PDFPageContentEditorStyleSettings::getIconForColor(QColor color) const
|
QIcon PDFPageContentEditorStyleSettings::getIconForColor(QColor color) const
|
||||||
{
|
{
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
@ -332,6 +401,31 @@ void PDFPageContentEditorStyleSettings::setBrushColor(QColor color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::Alignment PDFPageContentEditorStyleSettings::getAlignment() const
|
||||||
|
{
|
||||||
|
return m_alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFReal PDFPageContentEditorStyleSettings::getTextAngle() const
|
||||||
|
{
|
||||||
|
return ui->textAngleEdit->value();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QFont& PDFPageContentEditorStyleSettings::getFont() const
|
||||||
|
{
|
||||||
|
return m_font;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QBrush& PDFPageContentEditorStyleSettings::getBrush() const
|
||||||
|
{
|
||||||
|
return m_brush;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QPen& PDFPageContentEditorStyleSettings::getPen() const
|
||||||
|
{
|
||||||
|
return m_pen;
|
||||||
|
}
|
||||||
|
|
||||||
void PDFPageContentEditorStyleSettings::onSelectBrushColorButtonClicked()
|
void PDFPageContentEditorStyleSettings::onSelectBrushColorButtonClicked()
|
||||||
{
|
{
|
||||||
QColor color = QColorDialog::getColor(m_pen.color(), this, tr("Select Color for Brush"), QColorDialog::ShowAlphaChannel);
|
QColor color = QColorDialog::getColor(m_pen.color(), this, tr("Select Color for Brush"), QColorDialog::ShowAlphaChannel);
|
||||||
|
@ -38,7 +38,7 @@ namespace pdf
|
|||||||
{
|
{
|
||||||
class PDFPageContentElement;
|
class PDFPageContentElement;
|
||||||
|
|
||||||
class PDFPageContentEditorStyleSettings : public QWidget
|
class PDF4QTLIBSHARED_EXPORT PDFPageContentEditorStyleSettings : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -67,6 +67,14 @@ public:
|
|||||||
void setFontAlignment(Qt::Alignment alignment, bool forceUpdate);
|
void setFontAlignment(Qt::Alignment alignment, bool forceUpdate);
|
||||||
void setTextAngle(PDFReal angle, bool forceUpdate);
|
void setTextAngle(PDFReal angle, bool forceUpdate);
|
||||||
|
|
||||||
|
static bool showEditElementStyleDialog(QWidget* parent, PDFPageContentElement* element);
|
||||||
|
|
||||||
|
const QPen& getPen() const;
|
||||||
|
const QBrush& getBrush() const;
|
||||||
|
const QFont& getFont() const;
|
||||||
|
Qt::Alignment getAlignment() const;
|
||||||
|
PDFReal getTextAngle() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void penChanged(const QPen& pen);
|
void penChanged(const QPen& pen);
|
||||||
void brushChanged(const QBrush& brush);
|
void brushChanged(const QBrush& brush);
|
||||||
|
@ -504,6 +504,12 @@ void PDFPageContentScene::mouseDoubleClickEvent(QWidget* widget, QMouseEvent* ev
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MouseEventInfo info = getMouseEventInfo(widget, event->pos());
|
||||||
|
if (info.isValid())
|
||||||
|
{
|
||||||
|
emit editElementRequest(info.hoveredElementIds);
|
||||||
|
}
|
||||||
|
|
||||||
// If mouse is grabbed, then event is accepted always (because
|
// If mouse is grabbed, then event is accepted always (because
|
||||||
// we get Press event, when we grabbed the mouse, then we will
|
// we get Press event, when we grabbed the mouse, then we will
|
||||||
// wait for corresponding release event while all mouse move events
|
// wait for corresponding release event while all mouse move events
|
||||||
|
@ -548,6 +548,9 @@ signals:
|
|||||||
|
|
||||||
void selectionChanged();
|
void selectionChanged();
|
||||||
|
|
||||||
|
/// Request to edit the elements
|
||||||
|
void editElementRequest(const std::set<PDFInteger>& elements);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct MouseEventInfo
|
struct MouseEventInfo
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "pdfdrawwidget.h"
|
#include "pdfdrawwidget.h"
|
||||||
#include "pdfutils.h"
|
#include "pdfutils.h"
|
||||||
#include "pdfpagecontenteditorwidget.h"
|
#include "pdfpagecontenteditorwidget.h"
|
||||||
|
#include "pdfpagecontenteditorstylesettings.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@ -148,6 +149,7 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget)
|
|||||||
m_scene.setWidget(m_widget);
|
m_scene.setWidget(m_widget);
|
||||||
connect(&m_scene, &pdf::PDFPageContentScene::sceneChanged, this, &SignaturePlugin::onSceneChanged);
|
connect(&m_scene, &pdf::PDFPageContentScene::sceneChanged, this, &SignaturePlugin::onSceneChanged);
|
||||||
connect(&m_scene, &pdf::PDFPageContentScene::selectionChanged, this, &SignaturePlugin::onSceneSelectionChanged);
|
connect(&m_scene, &pdf::PDFPageContentScene::selectionChanged, this, &SignaturePlugin::onSceneSelectionChanged);
|
||||||
|
connect(&m_scene, &pdf::PDFPageContentScene::editElementRequest, this, &SignaturePlugin::onSceneEditElement);
|
||||||
connect(clearAction, &QAction::triggered, &m_scene, &pdf::PDFPageContentScene::clear);
|
connect(clearAction, &QAction::triggered, &m_scene, &pdf::PDFPageContentScene::clear);
|
||||||
connect(activateAction, &QAction::triggered, this, &SignaturePlugin::setActive);
|
connect(activateAction, &QAction::triggered, this, &SignaturePlugin::setActive);
|
||||||
|
|
||||||
@ -238,6 +240,34 @@ void SignaturePlugin::onToolActivityChanged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SignaturePlugin::onSceneEditElement(const std::set<pdf::PDFInteger>& elements)
|
||||||
|
{
|
||||||
|
if (elements.empty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdf::PDFPageContentElement* element = nullptr;
|
||||||
|
for (pdf::PDFInteger id : elements)
|
||||||
|
{
|
||||||
|
element = m_scene.getElementById(id);
|
||||||
|
if (element)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!element)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdf::PDFPageContentEditorStyleSettings::showEditElementStyleDialog(m_dataExchangeInterface->getMainWindow(), element))
|
||||||
|
{
|
||||||
|
updateGraphics();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SignaturePlugin::onPenChanged(const QPen& pen)
|
void SignaturePlugin::onPenChanged(const QPen& pen)
|
||||||
{
|
{
|
||||||
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
|
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
|
||||||
|
@ -52,6 +52,7 @@ private:
|
|||||||
void onSceneSelectionChanged();
|
void onSceneSelectionChanged();
|
||||||
void onWidgetSelectionChanged();
|
void onWidgetSelectionChanged();
|
||||||
void onToolActivityChanged();
|
void onToolActivityChanged();
|
||||||
|
void onSceneEditElement(const std::set<pdf::PDFInteger>& elements);
|
||||||
|
|
||||||
void onPenChanged(const QPen& pen);
|
void onPenChanged(const QPen& pen);
|
||||||
void onBrushChanged(const QBrush& brush);
|
void onBrushChanged(const QBrush& brush);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user