Editor - continuation

This commit is contained in:
Jakub Melka 2024-04-05 16:51:49 +02:00
parent 36b7a99deb
commit 83adf1e49d
7 changed files with 273 additions and 42 deletions

View File

@ -65,6 +65,7 @@ add_library(Pdf4QtLibWidgets SHARED
sources/pdfwidgetsglobal.h
sources/pdfcertificatelisthelper.h
sources/pdfcertificatelisthelper.cpp
sources/pdfpagecontenteditorediteditemsettings.h sources/pdfpagecontenteditorediteditemsettings.cpp sources/pdfpagecontenteditorediteditemsettings.ui
)
include(GenerateExportHeader)

View File

@ -0,0 +1,63 @@
// Copyright (C) 2024 Jakub Melka
//
// This file is part of PDF4QT.
//
// PDF4QT is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// with the written consent of the copyright owner, any later version.
//
// PDF4QT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
#include "pdfpagecontenteditorediteditemsettings.h"
#include "ui_pdfpagecontenteditorediteditemsettings.h"
#include "pdfpagecontentelements.h"
#include "pdfpagecontenteditorprocessor.h"
#include "pdfwidgetutils.h"
namespace pdf
{
PDFPageContentEditorEditedItemSettings::PDFPageContentEditorEditedItemSettings(QWidget* parent) :
QWidget(parent),
ui(new Ui::PDFPageContentEditorEditedItemSettings)
{
ui->setupUi(this);
}
PDFPageContentEditorEditedItemSettings::~PDFPageContentEditorEditedItemSettings()
{
delete ui;
}
void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentElementEdited* editedElement)
{
const PDFEditedPageContentElement* contentElement = editedElement->getElement();
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->imageTab));
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->textTab));
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->styleTab));
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->transformationTab));
if (const PDFEditedPageContentElementImage* imageElement = contentElement->asImage())
{
QSize imageSize = QSize(200, 200);
QImage image = imageElement->getImage();
image.setDevicePixelRatio(this->devicePixelRatioF());
image = image.scaled(imageSize * this->devicePixelRatioF(), Qt::KeepAspectRatio);
ui->tabWidget->addTab(ui->imageTab, tr("Image"));
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
ui->imageLabel->setFixedSize(PDFWidgetUtils::scaleDPI(this, imageSize));
}
}
} // namespace pdf

View File

@ -0,0 +1,47 @@
// Copyright (C) 2024 Jakub Melka
//
// This file is part of PDF4QT.
//
// PDF4QT is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// with the written consent of the copyright owner, any later version.
//
// PDF4QT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFPAGECONTENTEDITOREDITEDITEMSETTINGS_H
#define PDFPAGECONTENTEDITOREDITEDITEMSETTINGS_H
#include <QDialog>
namespace Ui {
class PDFPageContentEditorEditedItemSettings;
}
namespace pdf
{
class PDFPageContentElementEdited;
class PDFPageContentEditorEditedItemSettings : public QWidget
{
Q_OBJECT
public:
explicit PDFPageContentEditorEditedItemSettings(QWidget* parent);
virtual ~PDFPageContentEditorEditedItemSettings() override;
void loadFromElement(PDFPageContentElementEdited* editedElement);
private:
Ui::PDFPageContentEditorEditedItemSettings* ui;
};
} // namespace pdf
#endif // PDFPAGECONTENTEDITOREDITEDITEMSETTINGS_H

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PDFPageContentEditorEditedItemSettings</class>
<widget class="QWidget" name="PDFPageContentEditorEditedItemSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>571</width>
<height>461</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="textTab">
<attribute name="title">
<string>Text</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="textGroupBox">
<property name="title">
<string>Text Content</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPlainTextEdit" name="plainTextEdit"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="imageTab">
<attribute name="title">
<string>Image</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Image Content</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="imageLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="styleTab">
<attribute name="title">
<string>Style</string>
</attribute>
</widget>
<widget class="QWidget" name="transformationTab">
<attribute name="title">
<string>Transformation</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<slots>
<slot>accept()</slot>
<slot>reject()</slot>
</slots>
</ui>

View File

@ -20,6 +20,7 @@
#include "pdfwidgetutils.h"
#include "pdfpagecontentelements.h"
#include "pdfpagecontenteditorediteditemsettings.h"
#include <QFontDialog>
#include <QColorDialog>
@ -38,7 +39,7 @@ PDFPageContentEditorStyleSettings::PDFPageContentEditorStyleSettings(QWidget* pa
{
ui->setupUi(this);
for (QString colorName : QColor::colorNames())
for (const QString& colorName : QColor::colorNames())
{
QColor color(colorName);
QIcon icon = getIconForColor(color);
@ -263,59 +264,87 @@ bool PDFPageContentEditorStyleSettings::showEditElementStyleDialog(QWidget* pare
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)
PDFPageContentEditorStyleSettings* appearanceWidget = nullptr;
PDFPageContentElementEdited* editedElement = dynamic_cast<PDFPageContentElementEdited*>(element);
if (editedElement)
{
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);
}
PDFPageContentEditorEditedItemSettings* widget = new PDFPageContentEditorEditedItemSettings(&dialog);
dialog.layout()->addWidget(widget);
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()); });
}
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);
QGroupBox* appearanceGroupBox = new QGroupBox(&dialog);
appearanceGroupBox->setTitle(tr("Appearance"));
appearanceGroupBox->setLayout(new QVBoxLayout());
appearanceGroupBox->layout()->addWidget(appearanceWidget);
dialog.layout()->addWidget(appearanceGroupBox);
pdf::PDFWidgetUtils::style(&dialog);
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);
widget->loadFromElement(editedElement);
if (dialog.exec() == QDialog::Accepted)
{
if (styledElement)
if (dialog.exec() == QDialog::Accepted)
{
styledElement->setPen(appearanceWidget->getPen());
styledElement->setBrush(appearanceWidget->getBrush());
}
}
else
{
QTextEdit* textEdit = nullptr;
PDFPageContentStyledElement* styledElement = dynamic_cast<PDFPageContentStyledElement*>(element);
PDFPageContentElementTextBox* textElement = dynamic_cast<PDFPageContentElementTextBox*>(element);
if (textElement)
{
textElement->setText(textEdit->toPlainText());
textElement->setFont(appearanceWidget->getFont());
textElement->setAlignment(appearanceWidget->getAlignment());
textElement->setAngle(appearanceWidget->getTextAngle());
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);
}
return true;
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);
pdf::PDFWidgetUtils::style(&dialog);
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;

View File

@ -2605,6 +2605,11 @@ uint PDFPageContentElementEdited::getManipulationMode(const QPointF& point, PDFR
Q_UNUSED(point);
Q_UNUSED(snapPointDistanceThreshold);
if (getBoundingBox().contains(point))
{
return Select;
}
return None;
}

View File

@ -369,6 +369,8 @@ public:
virtual void setSize(QSizeF size) override;
virtual QString getDescription() const override;
const PDFEditedPageContentElement* getElement() const { return m_element.get(); }
private:
std::unique_ptr<PDFEditedPageContentElement> m_element;
};