From 83adf1e49d25a86aa0a53d0f33c0454884526487 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Fri, 5 Apr 2024 16:51:49 +0200 Subject: [PATCH] Editor - continuation --- Pdf4QtLibWidgets/CMakeLists.txt | 1 + ...pdfpagecontenteditorediteditemsettings.cpp | 63 ++++++++++ .../pdfpagecontenteditorediteditemsettings.h | 47 ++++++++ .../pdfpagecontenteditorediteditemsettings.ui | 84 +++++++++++++ .../pdfpagecontenteditorstylesettings.cpp | 113 +++++++++++------- .../sources/pdfpagecontentelements.cpp | 5 + .../sources/pdfpagecontentelements.h | 2 + 7 files changed, 273 insertions(+), 42 deletions(-) create mode 100644 Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.cpp create mode 100644 Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.h create mode 100644 Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.ui diff --git a/Pdf4QtLibWidgets/CMakeLists.txt b/Pdf4QtLibWidgets/CMakeLists.txt index 591ce20..db2fcdd 100644 --- a/Pdf4QtLibWidgets/CMakeLists.txt +++ b/Pdf4QtLibWidgets/CMakeLists.txt @@ -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) diff --git a/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.cpp b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.cpp new file mode 100644 index 0000000..7ea370e --- /dev/null +++ b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.cpp @@ -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 . + +#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 diff --git a/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.h b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.h new file mode 100644 index 0000000..6923993 --- /dev/null +++ b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.h @@ -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 . + +#ifndef PDFPAGECONTENTEDITOREDITEDITEMSETTINGS_H +#define PDFPAGECONTENTEDITOREDITEDITEMSETTINGS_H + +#include + +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 diff --git a/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.ui b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.ui new file mode 100644 index 0000000..b3a263a --- /dev/null +++ b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorediteditemsettings.ui @@ -0,0 +1,84 @@ + + + PDFPageContentEditorEditedItemSettings + + + + 0 + 0 + 571 + 461 + + + + Dialog + + + + + + 0 + + + + Text + + + + + + Text Content + + + + + + + + + + + + + Image + + + + + + Image Content + + + + + + + + + + + + + + + + + Style + + + + + Transformation + + + + + + + + + + accept() + reject() + + diff --git a/Pdf4QtLibWidgets/sources/pdfpagecontenteditorstylesettings.cpp b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorstylesettings.cpp index 8b88ee2..4db6b9d 100644 --- a/Pdf4QtLibWidgets/sources/pdfpagecontenteditorstylesettings.cpp +++ b/Pdf4QtLibWidgets/sources/pdfpagecontenteditorstylesettings.cpp @@ -20,6 +20,7 @@ #include "pdfwidgetutils.h" #include "pdfpagecontentelements.h" +#include "pdfpagecontenteditorediteditemsettings.h" #include #include @@ -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(element); - PDFPageContentElementTextBox* textElement = dynamic_cast(element); - if (textElement) + PDFPageContentEditorStyleSettings* appearanceWidget = nullptr; + PDFPageContentElementEdited* editedElement = dynamic_cast(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(element); + PDFPageContentElementTextBox* textElement = dynamic_cast(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; diff --git a/Pdf4QtLibWidgets/sources/pdfpagecontentelements.cpp b/Pdf4QtLibWidgets/sources/pdfpagecontentelements.cpp index 0108082..1f069c2 100644 --- a/Pdf4QtLibWidgets/sources/pdfpagecontentelements.cpp +++ b/Pdf4QtLibWidgets/sources/pdfpagecontentelements.cpp @@ -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; } diff --git a/Pdf4QtLibWidgets/sources/pdfpagecontentelements.h b/Pdf4QtLibWidgets/sources/pdfpagecontentelements.h index 219eaa5..6716afb 100644 --- a/Pdf4QtLibWidgets/sources/pdfpagecontentelements.h +++ b/Pdf4QtLibWidgets/sources/pdfpagecontentelements.h @@ -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 m_element; };