File indexing completed on 2024-06-23 04:26:35

0001 /*
0002  *  SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef _STORYBOARDDOCKER_DOCK_H_
0008 #define _STORYBOARDDOCKER_DOCK_H_
0009 
0010 #include <QDockWidget>
0011 #include <QButtonGroup>
0012 #include <QItemSelection>
0013 
0014 #include <kis_mainwindow_observer.h>
0015 #include <kis_canvas2.h>
0016 #include <kis_action.h>
0017 #include <boost/optional.hpp>
0018 #include "DlgExportStoryboard.h"
0019 #include <QDomElement>
0020 
0021 class Ui_WdgStoryboardDock;
0022 class CommentMenu;
0023 class ArrangeMenu;
0024 class StoryboardCommentModel;
0025 class StoryboardModel;
0026 class StoryboardDelegate;
0027 class KisNodeManager;
0028 class QPrinter;
0029 
0030 class StoryboardDockerDock : public QDockWidget, public KisMainwindowObserver{
0031     Q_OBJECT
0032 public:
0033     StoryboardDockerDock();
0034     ~StoryboardDockerDock() override;
0035     QString observerName() override { return "StoryboardDockerDock"; }
0036     void setCanvas(KoCanvasBase *canvas) override;
0037     void unsetCanvas() override;
0038     void setViewManager(KisViewManager* kisview) override;
0039 
0040     struct ExportPageShot {
0041         boost::optional<QRectF> cutNameRect;
0042         boost::optional<QRectF> cutNumberRect;
0043         boost::optional<QRectF> cutDurationRect;
0044         boost::optional<QRectF> cutImageRect;
0045         QMap<QString, QRectF> commentRects;
0046 
0047         ExportPageShot()
0048             : commentRects() {
0049         }
0050     };
0051 
0052     struct ExportPage {
0053         QVector<ExportPageShot> elements;
0054         boost::optional<QRectF> pageTimeRect;
0055         boost::optional<QRectF> pageNumberRect;
0056         boost::optional<QDomDocument> svg;
0057 
0058         ExportPage()
0059             : elements()
0060         {}
0061     };
0062 
0063 private Q_SLOTS:
0064     /**
0065      * @brief sets the image in Model to nullptr if there is no canvas set or no KisImage
0066      */
0067     void notifyImageDeleted();
0068     /**
0069      * @brief sets the KisDocument's storyboardItemList to be the same as StoryboardModel's storyboardItemList
0070      * and KisDocument's storyboardCommentList to be the same as CommentModel's commentList
0071      */
0072     void slotUpdateDocumentList();
0073     /**
0074      * @brief sets the StoryboardModel's storyboardItemList to be the same as KisDocument's storyboardItemList
0075      */
0076     void slotUpdateStoryboardModelList();
0077     /**
0078      * @brief sets the CommentModel's comment list to be the same as KisDocument's storyboardCommentList
0079      */
0080     void slotUpdateCommentModelList();
0081 
0082 
0083     /**
0084      * @brief calls @c slotExport(ExportFormat) with PDF parameter.
0085      */
0086     void slotExportAsPdf();
0087 
0088     /**
0089      * @brief calls @c slotExport(ExportFormat) with SVG parameter.
0090      */
0091     void slotExportAsSvg();
0092 
0093     /**
0094      * @brief Creates the @c DlgExportStoryboard and performs the actual export.
0095      * @sa DlgExportStoryboard
0096      */
0097     void slotExport(ExportFormat format);
0098 
0099     /**
0100      * @brief called when lock toggle button is clicked.
0101      * @param value The new lock toggle value.
0102      */
0103     void slotLockClicked(bool);
0104 
0105     /**
0106      * @brief called when a mode option is selected in @c Arrange menu.
0107      * @param button The button selected.
0108      */
0109     void slotModeChanged(QAbstractButton*);
0110 
0111     /**
0112      * @brief called when a view option is selected in @c Arrange menu.
0113      * @param button The button selected.
0114      */
0115     void slotViewChanged(QAbstractButton*);
0116 
0117     /**
0118      * @brief called to update minimum width on reaction to model changes.
0119      * Should change based on available content.
0120      */
0121     void slotUpdateMinimumWidth();
0122 
0123     /**
0124      * @brief called to reflect changes to the model.
0125      */
0126     void slotModelChanged();
0127 
0128 private:
0129     ExportPage getPageLayout(int rows, int columns, const QRect& imageSize, const QRect& pageRect, const QFontMetrics& painter);
0130     ExportPage getPageLayout(QString layoutSvgFileName, QPrinter *printer);
0131 
0132     QString buildDurationString(int seconds, int frames);
0133 
0134 private:
0135     KisCanvas2* m_canvas;
0136     KisNodeManager* m_nodeManager;
0137     QScopedPointer<Ui_WdgStoryboardDock> m_ui;
0138 
0139     QMenu *m_exportMenu;
0140     KisAction *m_exportAsPdfAction;
0141     KisAction *m_exportAsSvgAction;
0142 
0143     QPointer<StoryboardCommentModel> m_commentModel;
0144     CommentMenu *m_commentMenu;
0145 
0146     KisAction *m_lockAction;
0147 
0148     ArrangeMenu *m_arrangeMenu;
0149 
0150     QButtonGroup *m_modeGroup;
0151     QButtonGroup *m_viewGroup;
0152 
0153     QSharedPointer<StoryboardModel> m_storyboardModel;
0154     QPointer<StoryboardDelegate> m_storyboardDelegate;
0155 };
0156 
0157 #endif