]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
Warn about missing images and fonts in title clips when opening a document:
[kdenlive] / src / titlewidget.h
1 /***************************************************************************
2                           titlewidget.h  -  description
3                              -------------------
4     begin                : Feb 28 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef TITLEWIDGET_H
19 #define TITLEWIDGET_H
20
21
22 #include "ui_titlewidget_ui.h"
23 #include "titledocument.h"
24 #include "renderer.h"
25 #include "graphicsscenerectmove.h"
26 #include "unicodedialog.h"
27 #include "timecode.h"
28
29 #include <QMap>
30 #include <QSignalMapper>
31
32
33 class Transform
34 {
35 public:
36     Transform() {
37         scalex = 1.0;
38         scaley = 1.0;
39         rotatex = 0.0;
40         rotatey = 0.0;
41         rotatez = 0.0;
42     }
43     double scalex, scaley;
44     double rotatex, rotatey, rotatez;
45 };
46
47 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
48 {
49     Q_OBJECT
50
51 public:
52     /** \brief Constructor
53      * \param projectPath Path to use when user requests loading or saving of titles as .kdenlivetitle documents */
54     TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent = 0);
55     virtual ~TitleWidget();
56     QDomDocument xml();
57     void setXml(QDomDocument doc);
58
59     /** \brief Find first available filename of the form titleXXX.png in projectUrl + "/titles/" directory
60     * \param projectUrl Url to directory of project.
61      * \returns A list, with the name in the form of "/path/to/titles/titleXXX" as the first element, the extension
62      * ".png" as the second element.
63      *
64      * The path "/titles/" is appended to projectUrl to locate the actual directory that contains the title pngs. */
65     static QStringList getFreeTitleInfo(const KUrl &projectUrl, bool isClone = false);
66
67     /** \brief Return a list af all images included in a title
68      * \param xml The xml data for title
69     */
70     static QStringList extractImageList(QString xml);
71
72     /** \brief Return a list af all fonts included in a title
73      * \param xml The xml data for title
74     */
75     static QStringList extractFontList(QString xml);
76
77     /** \brief Build a filename from a projectUrl and a titleName
78      * \param projectUrl Url to directory of project.
79      * \param titleName Name of title, on the form "titleXXX"
80      *
81      * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
82      * get the filename. It is not checked that the title png actually exists, only the name is build and
83      * returned. */
84     static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
85
86     /** \brief Get clip duration. */
87     int duration() const;
88
89 protected:
90     virtual void resizeEvent(QResizeEvent * event);
91
92 private:
93     /** \brief Rectangle describing animation start viewport */
94     QGraphicsRectItem *m_startViewport;
95     /** \brief Rectangle describing animation end viewport */
96     QGraphicsRectItem *m_endViewport;
97     /** \brief Scene for the titler */
98     GraphicsSceneRectMove *m_scene;
99     /** \brief Initialize the animation properties (viewport size,...) */
100     void initAnimation();
101     QMap<QGraphicsItem*, Transform > m_transformations;
102     TitleDocument m_titledocument;
103     QGraphicsRectItem *m_frameBorder;
104     QGraphicsPixmapItem *m_frameImage;
105     int m_frameWidth;
106     int m_frameHeight;
107     Render *m_render;
108     int m_count;
109     QAction *m_buttonRect;
110     QAction *m_buttonText;
111     QAction *m_buttonImage;
112     QAction *m_buttonCursor;
113     QAction *m_buttonSave;
114     QAction *m_buttonLoad;
115
116     QAction *m_unicodeAction;
117     QAction *m_zUp;
118     QAction *m_zDown;
119     QAction *m_zTop;
120     QAction *m_zBottom;
121
122     /** \brief Dialog for entering unicode in text fields */
123     UnicodeDialog *m_unicodeDialog;
124     /** project path for storing title clips */
125     QString m_projectTitlePath;
126     Timecode m_tc;
127
128     /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
129     QSignalMapper *m_signalMapper;
130
131     enum ValueType { ValueWidth = 0, ValueHeight = 1 };
132
133     /** \brief Sets the font weight value in the combo box. (#909) */
134     void setFontBoxWeight(int weight);
135
136     /** \brief Store the current choices of font, background and rect values */
137     void writeChoices();
138     /** \brief Read the last stored choices into the dialog */
139     void readChoices();
140     /** \brief Update the displayed X/Y coordinate values */
141     void updateCoordinates(QGraphicsItem *i);
142     /** \brief Update displayed width/height values */
143     void updateDimension(QGraphicsItem *i);
144     /** \brief Update displayed rotation/zoom values */
145     void updateRotZoom(QGraphicsItem *i);
146
147     /** \brief Update the item's position */
148     void updatePosition(QGraphicsItem *i);
149
150     void textChanged(QGraphicsTextItem *i);
151     void updateAxisButtons(QGraphicsItem *i);
152
153     void updateTextOriginX();
154     void updateTextOriginY();
155
156     /** \brief Enables the toolbars suiting to toolType */
157     void enableToolbars(TITLETOOL toolType);
158     /** \brief Shows the toolbars suiting to toolType */
159     void showToolbars(TITLETOOL toolType);
160     /** \brief Check a tool button. */
161     void checkButton(TITLETOOL toolType);
162
163     void adjustFrameSize();
164     /** \brief Add a "start" and "end" info text to the animation viewports */
165     void addAnimInfoText();
166     /** \brief Update font for the "start" and "end" info text */
167     void updateInfoText();
168     /** \brief Remove the "start" and "end" info text from animation viewports */
169     void deleteAnimInfoText();
170
171     qreal maxZIndex();
172     qreal zIndexBounds(bool maxBound);
173
174     void itemRotate(qreal val, int axis);
175
176 public slots:
177     void slotNewText(QGraphicsTextItem *tt);
178     void slotNewRect(QGraphicsRectItem *rect);
179     void slotChangeBackground();
180     void selectionChanged();
181     void rectChanged();
182     void setupViewports();
183     void zIndexChanged(int);
184     void itemScaled(int);
185     void itemRotateX(qreal);
186     void itemRotateY(qreal);
187     void itemRotateZ(qreal);
188     void saveTitle(KUrl url = KUrl());
189     void loadTitle(KUrl url = KUrl());
190
191 private slots:
192     void slotAdjustSelectedItem();
193
194     /**
195      * \brief Switches the origin of the x axis between left and right
196      * border of the frame (offset from left/right frame border)
197      * \param originLeft Take left border?
198      *
199      * Called when the origin of the x coorinate has been changed. The
200      * x origin will either be at the left or at the right side of the frame.
201      *
202      * When the origin of the x axis is at the left side, the user can
203      * enter the distance between an element's left border and the left
204      * side of the frame.
205      *
206      * When on the right, the distance from the right border of the
207      * frame to the right border of the element can be entered. This
208      * would result in negative values as long as the element's right
209      * border is at the left of the frame's right border. As that is
210      * usually the case, I additionally invert the x axis.
211      *
212      * Default value is left.
213      *
214      * |----l----->|#######|----r--->|
215      * |           |---w-->|         |
216      * |           |#######|         |
217      * |                             |
218      * |----------m_frameWidth------>|
219      * |                             |
220      *
221      * Left selected: Value = l
222      * Right selected: Value = r
223      *
224      * To calculate between the two coorindate systems:
225      * l = m_frameWidth - w - r
226      * r = m_frameWidth - w - l
227      *
228      */
229     void slotOriginXClicked();
230     /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
231      *  \param originTop Take top border? */
232     void slotOriginYClicked();
233
234     /** \brief Update coorinates of text fields if necessary and text has changed */
235     void slotChanged();
236
237     /** \param valueType Of type ValueType */
238     void slotValueChanged(int valueType);
239
240     void slotZoom(bool up);
241     void slotUpdateZoom(int pos);
242     void slotAdjustZoom();
243     void slotZoomOneToOne();
244
245     void slotUpdateText();
246     void slotInsertUnicode();
247     void slotInsertUnicodeString(QString);
248
249     void displayBackgroundFrame();
250
251     void setCurrentItem(QGraphicsItem *item);
252
253     void slotTextTool();
254     void slotRectTool();
255     void slotSelectTool();
256     void slotImageTool();
257
258     void slotAnimStart(bool);
259     void slotAnimEnd(bool);
260     void slotKeepAspect(bool keep);
261
262     void itemHCenter();
263     void itemVCenter();
264     void itemTop();
265     void itemBottom();
266     void itemLeft();
267     void itemRight();
268     void slotResize50();
269     void slotResize100();
270     void slotResize200();
271
272     /** \brief Called when accepted, stores the user selections for next time use */
273     void slotAccepted();
274
275     void slotFontText(const QString& s);
276
277     void slotAddEffect(int ix);
278     void slotEditBlur(int ix);
279     void slotEditShadow();
280     void slotEditTypewriter(int ix);
281
282     /** \brief Changes the z index of objects. */
283     void slotZIndexUp();
284     void slotZIndexDown();
285     void slotZIndexTop();
286     void slotZIndexBottom();
287 };
288
289
290 #endif