File indexing completed on 2024-04-21 04:52:25

0001 /*
0002     SPDX-FileCopyrightText: 2008 Marco Gittler <g.marco@freenet.de>
0003     SPDX-FileCopyrightText: Rafał Lalik
0004 
0005     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 
0009 /*
0010  *                                                                         *
0011  *   Modifications by Rafał Lalik to implement Patterns mechanism          *
0012  *                                                                         *
0013  ***************************************************************************/
0014 
0015 #pragma once
0016 
0017 #include <QColor>
0018 #include <QDomDocument>
0019 #include <QRectF>
0020 #include <QTransform>
0021 #include <QUrl>
0022 #include <QVariant>
0023 
0024 class QGraphicsScene;
0025 class QGraphicsRectItem;
0026 class QGraphicsItem;
0027 class GraphicsSceneRectMove;
0028 
0029 class TitleDocument
0030 {
0031 
0032 public:
0033     TitleDocument();
0034     enum TitleProperties { OutlineWidth = 101, OutlineColor, LineSpacing, Gradient, RotateFactor, ZoomFactor };
0035     void setScene(QGraphicsScene *scene, int width, int height);
0036     bool saveDocument(const QUrl &url, QGraphicsRectItem *startv, QGraphicsRectItem *endv, int duration, bool embed_images = false);
0037     /** @brief Save XML for this title. It calls static version for the function.
0038      */
0039     QDomDocument xml(QGraphicsRectItem *startv, QGraphicsRectItem *endv, bool embed_images = false);
0040     /** @brief Load XML for this title. It calls static version for the function.
0041      */
0042     int loadFromXml(const QDomDocument &doc, GraphicsSceneRectMove *scene, QGraphicsRectItem *startv, QGraphicsRectItem *endv, int *duration, const QString &projectpath = QString());
0043     /** \brief Get the background color (incl. alpha) from the document, if possibly
0044      * \returns The background color of the document, inclusive alpha. If none found, returns (0,0,0,0) */
0045     QColor getBackgroundColor() const;
0046     static QColor getBackgroundColor(const QList<QGraphicsItem *> & items);
0047     int frameWidth() const;
0048     int frameHeight() const;
0049     /** \brief Extract embedded images in project titles folder. */
0050     static const QString extractBase64Image(const QString &titlePath, const QString &data);
0051     /** \brief The number of missing elements in this title. */
0052     int invalidCount() const;
0053 
0054     enum ItemOrigin { OriginXLeft = 0, OriginYTop = 1 };
0055     enum AxisPosition { AxisDefault = 0, AxisInverted = 1 };
0056 
0057     /**
0058      * @brief General static function to store items in xml format.
0059      */
0060     static QDomDocument xml(const QList<QGraphicsItem *> & items, int width, int height, QGraphicsRectItem *startv, QGraphicsRectItem *endv, bool embed_images = false, const QString & projectPath = QString());
0061 
0062     /**
0063      * @brief General static function to load items into list from a xml file.
0064      */
0065     static int loadFromXml(const QDomDocument &doc, QList<QGraphicsItem *> & gitems, int & width, int & height, GraphicsSceneRectMove * scene, QGraphicsRectItem *startv, QGraphicsRectItem *endv, int *duration, int & missingElements);
0066 
0067 private:
0068     QGraphicsScene *m_scene;
0069     QString m_projectPath;
0070     int m_missingElements;
0071     int m_width;
0072     int m_height;
0073     static QString colorToString(const QColor &);
0074     static QString rectFToString(const QRectF &);
0075     static QRectF stringToRect(const QString &);
0076     static QColor stringToColor(const QString &);
0077     static QTransform stringToTransform(const QString &);
0078     static QList<QVariant> stringToList(const QString &);
0079     static int base64ToUrl(QGraphicsItem *item, QDomElement &content, bool embed, const QString & pojectPath);
0080     static QPixmap createInvalidPixmap(const QString &url, int height);
0081 };