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/pdfwidgetsglobal.h
sources/pdfcertificatelisthelper.h sources/pdfcertificatelisthelper.h
sources/pdfcertificatelisthelper.cpp sources/pdfcertificatelisthelper.cpp
sources/pdfpagecontenteditorediteditemsettings.h sources/pdfpagecontenteditorediteditemsettings.cpp sources/pdfpagecontenteditorediteditemsettings.ui
) )
include(GenerateExportHeader) 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 "pdfwidgetutils.h"
#include "pdfpagecontentelements.h" #include "pdfpagecontentelements.h"
#include "pdfpagecontenteditorediteditemsettings.h"
#include <QFontDialog> #include <QFontDialog>
#include <QColorDialog> #include <QColorDialog>
@ -38,7 +39,7 @@ PDFPageContentEditorStyleSettings::PDFPageContentEditorStyleSettings(QWidget* pa
{ {
ui->setupUi(this); ui->setupUi(this);
for (QString colorName : QColor::colorNames()) for (const QString& colorName : QColor::colorNames())
{ {
QColor color(colorName); QColor color(colorName);
QIcon icon = getIconForColor(color); QIcon icon = getIconForColor(color);
@ -263,9 +264,33 @@ bool PDFPageContentEditorStyleSettings::showEditElementStyleDialog(QWidget* pare
dialog.setWindowTitle(tr("Edit Item")); dialog.setWindowTitle(tr("Edit Item"));
dialog.setLayout(new QVBoxLayout()); dialog.setLayout(new QVBoxLayout());
PDFPageContentEditorStyleSettings* appearanceWidget = nullptr;
PDFPageContentElementEdited* editedElement = dynamic_cast<PDFPageContentElementEdited*>(element);
if (editedElement)
{
PDFPageContentEditorEditedItemSettings* widget = new PDFPageContentEditorEditedItemSettings(&dialog);
dialog.layout()->addWidget(widget);
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);
widget->loadFromElement(editedElement);
if (dialog.exec() == QDialog::Accepted)
{
}
}
else
{
QTextEdit* textEdit = nullptr; QTextEdit* textEdit = nullptr;
PDFPageContentStyledElement* styledElement = dynamic_cast<PDFPageContentStyledElement*>(element); PDFPageContentStyledElement* styledElement = dynamic_cast<PDFPageContentStyledElement*>(element);
PDFPageContentElementTextBox* textElement = dynamic_cast<PDFPageContentElementTextBox*>(element); PDFPageContentElementTextBox* textElement = dynamic_cast<PDFPageContentElementTextBox*>(element);
if (textElement) if (textElement)
{ {
QGroupBox* contentGroupBox = new QGroupBox(&dialog); QGroupBox* contentGroupBox = new QGroupBox(&dialog);
@ -279,8 +304,9 @@ bool PDFPageContentEditorStyleSettings::showEditElementStyleDialog(QWidget* pare
dialog.layout()->addWidget(contentGroupBox); dialog.layout()->addWidget(contentGroupBox);
} }
PDFPageContentEditorStyleSettings* appearanceWidget = new PDFPageContentEditorStyleSettings(&dialog); appearanceWidget = new PDFPageContentEditorStyleSettings(&dialog);
appearanceWidget->loadFromElement(element, true); appearanceWidget->loadFromElement(element, true);
if (textEdit) if (textEdit)
{ {
connect(appearanceWidget, &PDFPageContentEditorStyleSettings::alignmentChanged, textEdit, &QTextEdit::setAlignment); connect(appearanceWidget, &PDFPageContentEditorStyleSettings::alignmentChanged, textEdit, &QTextEdit::setAlignment);
@ -299,6 +325,8 @@ bool PDFPageContentEditorStyleSettings::showEditElementStyleDialog(QWidget* pare
connect(dialogButtonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); connect(dialogButtonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
dialog.layout()->addWidget(dialogButtonBox); dialog.layout()->addWidget(dialogButtonBox);
pdf::PDFWidgetUtils::style(&dialog);
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
{ {
if (styledElement) if (styledElement)
@ -317,6 +345,7 @@ bool PDFPageContentEditorStyleSettings::showEditElementStyleDialog(QWidget* pare
return true; return true;
} }
}
return false; return false;
} }

View File

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

View File

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