PDF4QT/Pdf4QtLib/sources/pdfobjecteditorwidget_impl.h

297 lines
8.6 KiB
C
Raw Normal View History

2021-04-30 20:12:10 +02:00
// Copyright (C) 2020-2021 Jakub Melka
2020-11-28 17:50:14 +01:00
//
2021-08-10 19:22:56 +02:00
// This file is part of PDF4QT.
2020-11-28 17:50:14 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is free software: you can redistribute it and/or modify
2020-11-28 17:50:14 +01:00
// 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
2021-04-30 20:12:10 +02:00
// with the written consent of the copyright owner, any later version.
2020-11-28 17:50:14 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is distributed in the hope that it will be useful,
2020-11-28 17:50:14 +01:00
// 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
2021-08-10 19:22:56 +02:00
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
2020-11-28 17:50:14 +01:00
#ifndef PDFOBJECTEDITORWIDGET_IMPL_H
#define PDFOBJECTEDITORWIDGET_IMPL_H
#include "pdfobjecteditormodel.h"
class QLabel;
class QGroupBox;
class QComboBox;
class QTabWidget;
class QGridLayout;
class QLineEdit;
class QTextBrowser;
class QPushButton;
2020-11-29 18:36:59 +01:00
class QDateTimeEdit;
class QCheckBox;
2020-12-22 18:29:40 +01:00
class QDoubleSpinBox;
2020-11-28 17:50:14 +01:00
namespace pdf
{
class PDFObjectEditorMappedWidgetAdapter : public QObject
{
Q_OBJECT
private:
using BaseClass = QObject;
public:
explicit PDFObjectEditorMappedWidgetAdapter(PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
/// Returns PDFObject value currently present in the widget
virtual PDFObject getValue() const = 0;
2020-11-28 17:50:14 +01:00
/// Sets PDFObject value to the widget. If data are incompatible,
/// then no data are set to the widget.
/// \param object Value to be set to the widget
2020-11-28 17:50:14 +01:00
virtual void setValue(PDFObject object) = 0;
/// Updates widget state (for example, visibility, enabledness and readonly mode)
virtual void update() = 0;
2020-11-28 17:50:14 +01:00
signals:
void commitRequested(size_t attribute);
protected:
// Initializes label text with attributes name
void initLabel(QLabel* label);
PDFObjectEditorAbstractModel* m_model;
size_t m_attribute;
};
2020-11-29 18:36:59 +01:00
class PDFObjectEditorWidgetMapper : public QObject
{
Q_OBJECT
private:
using BaseClass = QObject;
public:
explicit PDFObjectEditorWidgetMapper(PDFObjectEditorAbstractModel* model, QObject* parent);
void initialize(QTabWidget* tabWidget);
2020-12-22 18:29:40 +01:00
void setObject(PDFObject object);
PDFObject getObject();
2020-11-29 18:36:59 +01:00
private:
struct Subcategory
{
QString name;
std::vector<size_t> attributes;
};
struct Category
{
QString name;
std::vector<Subcategory> subcategories;
QWidget* page = nullptr;
Subcategory* getOrCreateSubcategory(QString name);
};
void loadWidgets();
void onEditedObjectChanged();
void onCommitRequested(size_t attribute);
void createMappedAdapter(QGroupBox* groupBox, QGridLayout* layout, size_t attribute);
Category* getOrCreateCategory(QString categoryName);
/// Returns true, if category is visible
/// \param category Category
bool isCategoryVisible(const Category& category) const;
2020-11-29 18:36:59 +01:00
PDFObjectEditorAbstractModel* m_model;
QTabWidget* m_tabWidget;
2020-11-29 18:36:59 +01:00
std::vector<Category> m_categories;
std::map<size_t, PDFObjectEditorMappedWidgetAdapter*> m_adapters;
bool m_isCommitingDisabled;
};
2020-11-28 17:50:14 +01:00
class PDFObjectEditorMappedComboBoxAdapter : public PDFObjectEditorMappedWidgetAdapter
{
Q_OBJECT
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
public:
explicit PDFObjectEditorMappedComboBoxAdapter(QLabel* label, QComboBox* comboBox, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-28 17:50:14 +01:00
private:
QLabel* m_label;
QComboBox* m_comboBox;
};
class PDFObjectEditorMappedLineEditAdapter : public PDFObjectEditorMappedWidgetAdapter
{
Q_OBJECT
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
public:
explicit PDFObjectEditorMappedLineEditAdapter(QLabel* label, QLineEdit* lineEdit, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-28 17:50:14 +01:00
private:
QLabel* m_label;
QLineEdit* m_lineEdit;
};
class PDFObjectEditorMappedTextBrowserAdapter : public PDFObjectEditorMappedWidgetAdapter
{
Q_OBJECT
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
public:
explicit PDFObjectEditorMappedTextBrowserAdapter(QLabel* label, QTextBrowser* textBrowser, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-28 17:50:14 +01:00
private:
QLabel* m_label;
QTextBrowser* m_textBrowser;
};
2020-11-29 18:36:59 +01:00
class PDFObjectEditorMappedRectangleAdapter : public PDFObjectEditorMappedWidgetAdapter
2020-11-28 17:50:14 +01:00
{
Q_OBJECT
private:
2020-11-29 18:36:59 +01:00
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
2020-11-28 17:50:14 +01:00
public:
2020-11-29 18:36:59 +01:00
explicit PDFObjectEditorMappedRectangleAdapter(QLabel* label, QPushButton* pushButton, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
2020-11-28 17:50:14 +01:00
2020-11-29 18:36:59 +01:00
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-28 17:50:14 +01:00
private:
2020-11-29 18:36:59 +01:00
QLabel* m_label;
QPushButton* m_pushButton;
PDFObject m_rectangle;
};
2020-11-28 17:50:14 +01:00
2020-11-29 18:36:59 +01:00
class PDFObjectEditorMappedDateTimeAdapter : public PDFObjectEditorMappedWidgetAdapter
{
Q_OBJECT
2020-11-28 17:50:14 +01:00
2020-11-29 18:36:59 +01:00
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
2020-11-28 17:50:14 +01:00
2020-11-29 18:36:59 +01:00
public:
explicit PDFObjectEditorMappedDateTimeAdapter(QLabel* label, QDateTimeEdit* dateTimeEdit, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
2020-11-28 17:50:14 +01:00
2020-11-29 18:36:59 +01:00
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-29 18:36:59 +01:00
private:
QLabel* m_label;
QDateTimeEdit* m_dateTimeEdit;
2020-11-28 17:50:14 +01:00
};
2020-11-29 18:36:59 +01:00
class PDFObjectEditorMappedFlagsAdapter : public PDFObjectEditorMappedWidgetAdapter
2020-11-28 17:50:14 +01:00
{
Q_OBJECT
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
public:
2020-11-29 18:36:59 +01:00
explicit PDFObjectEditorMappedFlagsAdapter(std::vector<std::pair<uint32_t, QCheckBox*>> flagCheckBoxes,
PDFObjectEditorAbstractModel* model,
size_t attribute,
QObject* parent);
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-29 18:36:59 +01:00
private:
std::vector<std::pair<uint32_t, QCheckBox*>> m_flagCheckBoxes;
};
class PDFObjectEditorMappedCheckBoxAdapter : public PDFObjectEditorMappedWidgetAdapter
{
Q_OBJECT
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
public:
explicit PDFObjectEditorMappedCheckBoxAdapter(QLabel* label, QCheckBox* checkBox, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-29 18:36:59 +01:00
private:
QLabel* m_label;
QCheckBox* m_checkBox;
};
class PDFObjectEditorMappedColorAdapter : public PDFObjectEditorMappedWidgetAdapter
{
Q_OBJECT
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
public:
2020-12-23 18:33:09 +01:00
explicit PDFObjectEditorMappedColorAdapter(QLabel* label, QComboBox* comboBox, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
2020-11-28 17:50:14 +01:00
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-11-28 17:50:14 +01:00
private:
2020-12-23 18:33:09 +01:00
QIcon getIconForColor(QColor color) const;
2020-11-28 17:50:14 +01:00
QLabel* m_label;
2020-12-23 18:33:09 +01:00
QComboBox* m_comboBox;
2020-11-28 17:50:14 +01:00
};
2020-12-22 18:29:40 +01:00
class PDFObjectEditorMappedDoubleAdapter : public PDFObjectEditorMappedWidgetAdapter
{
Q_OBJECT
private:
using BaseClass = PDFObjectEditorMappedWidgetAdapter;
public:
explicit PDFObjectEditorMappedDoubleAdapter(QLabel* label, QDoubleSpinBox* spinBox, PDFObjectEditorAbstractModel* model, size_t attribute, QObject* parent);
virtual PDFObject getValue() const override;
virtual void setValue(PDFObject object) override;
virtual void update() override;
2020-12-22 18:29:40 +01:00
private:
QLabel* m_label;
QDoubleSpinBox* m_spinBox;
};
2020-11-28 17:50:14 +01:00
} // namespace pdf
#endif // PDFOBJECTEDITORWIDGET_IMPL_H