]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
331 fixed: Naming of tracks now Audio 1, Video 1, etc. http://www.kdenlive.org/mantis...
[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 #include "ui_titlewidget_ui.h"
22 #include "titledocument.h"
23 #include "renderer.h"
24 #include "graphicsscenerectmove.h"
25 #include "unicodedialog.h"
26 #include "timecode.h"
27
28 #include <QMap>
29 #include <QSignalMapper>
30
31 class TitleTemplate
32 {
33 public:
34     QString file;
35     QString name;
36     QIcon icon;
37 };
38
39 class Transform
40 {
41 public:
42     Transform() {
43         scalex = 1.0;
44         scaley = 1.0;
45         rotatex = 0.0;
46         rotatey = 0.0;
47         rotatez = 0.0;
48     }
49     double scalex, scaley;
50     double rotatex, rotatey, rotatez;
51 };
52
53
54 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
55 {
56     Q_OBJECT
57
58 public:
59
60     /** @brief Draws the dialog and loads a title document (if any).
61      * @param url title document to load
62      * @param tc timecode of the project
63      * @param projectPath default path to save to or load from title documents
64      * @param render project renderer
65      * @param parent (optional) parent widget */
66     TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent = 0);
67     virtual ~TitleWidget();
68     QDomDocument xml();
69     void setXml(QDomDocument doc);
70
71     /** @brief Finds the first available file name for a title document.
72      * @deprecated With the titler module there's no need to save titles as images.
73      * @param projectUrl project directory
74      * @param isClone (optional) if true, the file name will be cloneXXX.png
75      * @return list with title name (Title XXX or Clone XXX) and file name
76      *
77      * The path "/titles/" is appended to projectUrl, and the format of the file name is (title|clone)XXX.png. */
78     static QStringList getFreeTitleInfo(const KUrl &projectUrl, bool isClone = false);
79
80     /** @brief Checks for the images referenced by a title clip.
81      * @param xml XML data representing the title
82      * @return list of the image files */
83     static QStringList extractImageList(QString xml);
84
85     /** @brief Checks for the fonts referenced by a title clip.
86      * @param xml XML data representing the title
87      * @return list of the fonts */
88     static QStringList extractFontList(QString xml);
89
90     /** @brief Builds a file name for a title document.
91      * @deprecated With the titler module there's no need to save titles as images.
92      * @param projectUrl project directory
93      * @param titleName name of title, in the form titleXXX
94      * @return file name composed with the given arguments
95      *
96      * The path "/titles/" is appended to projectUrl, and .png is appended to
97      * get the file name. There is no check for the existence of the file. */
98     static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
99
100     /** @brief Returns clip out position. */
101     int outPoint() const;
102
103     /** @brief Retrieves a list of all available title templates. */
104     static void refreshTitleTemplates();
105
106 protected:
107     virtual void resizeEvent(QResizeEvent * event);
108
109 private:
110
111     /** @brief Rectangle describing the animation start viewport. */
112     QGraphicsRectItem *m_startViewport;
113
114     /** @brief Rectangle describing the animation end viewport. */
115     QGraphicsRectItem *m_endViewport;
116
117     /** @brief Scene for the titler. */
118     GraphicsSceneRectMove *m_scene;
119
120     /** @brief Initialises the animation properties (viewport size, etc.). */
121     void initAnimation();
122     QMap<QGraphicsItem*, Transform > m_transformations;
123     TitleDocument m_titledocument;
124     QGraphicsRectItem *m_frameBorder;
125     QGraphicsPixmapItem *m_frameImage;
126     int m_frameWidth;
127     int m_frameHeight;
128     Render *m_render;
129     int m_count;
130     QAction *m_buttonRect;
131     QAction *m_buttonText;
132     QAction *m_buttonImage;
133     QAction *m_buttonCursor;
134     QAction *m_buttonSave;
135     QAction *m_buttonLoad;
136
137     QAction *m_unicodeAction;
138     QAction *m_zUp;
139     QAction *m_zDown;
140     QAction *m_zTop;
141     QAction *m_zBottom;
142
143     /** @brief Dialog for entering Unicode characters in text fields. */
144     UnicodeDialog *m_unicodeDialog;
145
146     /** @brief Project path for storing title documents. */
147     QString m_projectTitlePath;
148     Timecode m_tc;
149     QString lastDocumentHash;
150
151     // See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage.
152     QSignalMapper *m_signalMapper;
153
154     enum ValueType { ValueWidth = 0, ValueHeight = 1 };
155
156     /** @brief Sets the font weight value in the combo box. (#909) */
157     void setFontBoxWeight(int weight);
158
159     /** @brief Stores the choices of font, background and rectangle values. */
160     void writeChoices();
161
162     /** @brief Reads the last stored choices into the dialog. */
163     void readChoices();
164
165     /** @brief Updates the displayed X/Y coordinates. */
166     void updateCoordinates(QGraphicsItem *i);
167
168     /** @brief Updates the displayed width/height values. */
169     void updateDimension(QGraphicsItem *i);
170
171     /** @brief Updates the displayed rotation/zoom values. */
172     void updateRotZoom(QGraphicsItem *i);
173
174     /** @brief Updates the item position. */
175     void updatePosition(QGraphicsItem *i);
176
177     void textChanged(QGraphicsTextItem *i);
178     void updateAxisButtons(QGraphicsItem *i);
179
180     void updateTextOriginX();
181     void updateTextOriginY();
182
183     /** @brief Enables the toolbars suiting to toolType. */
184     void enableToolbars(TITLETOOL toolType);
185
186     /** @brief Shows the toolbars suiting to toolType. */
187     void showToolbars(TITLETOOL toolType);
188
189     /** @brief Checks a tool button. */
190     void checkButton(TITLETOOL toolType);
191
192     void adjustFrameSize();
193
194     /** @brief Adds a "start" and "end" info text to the animation viewports. */
195     void addAnimInfoText();
196
197     /** @brief Updates the font for the "start" and "end" info text. */
198     void updateInfoText();
199
200     /** @brief Removes the "start" and "end" info text from animation viewports. */
201     void deleteAnimInfoText();
202
203     qreal maxZIndex();
204
205     /** @brief Gets the minimum/maximum Z index of items.
206      * @param maxBound true: use maximum Z index; false: use minimum
207      * @param intersectingOnly if true, consider only the items intersecting
208      *     with the currently selected item
209      */
210     qreal zIndexBounds(bool maxBound, bool intersectingOnly);
211
212     void itemRotate(qreal val, int axis);
213
214 public slots:
215     void slotNewText(QGraphicsTextItem *tt);
216     void slotNewRect(QGraphicsRectItem *rect);
217     void slotChangeBackground();
218
219     /** @brief Sets up the tools (toolbars etc.) according to the selected item. */
220     void selectionChanged();
221     void rectChanged();
222     void setupViewports();
223     void zIndexChanged(int);
224     void itemScaled(int);
225     void itemRotateX(qreal);
226     void itemRotateY(qreal);
227     void itemRotateZ(qreal);
228     void saveTitle(KUrl url = KUrl());
229     void loadTitle(KUrl url = KUrl());
230
231 private slots:
232
233     /** @brief Updates position/size of the selected item when a value changes. */
234     void slotAdjustSelectedItem();
235
236     /** @brief Switches the origin of the X axis between left and right border.
237      *
238      * It's called when the origin of the X coordinate has been changed. The X
239      * origin will either be at the left or at the right side of the frame.
240      *
241      * When the origin of the X axis is at the left side, the user can enter the
242      * distance between an element's left border and the left side of the frame.
243      *
244      * When on the right, the distance from the right border of the frame to the
245      * right border of the element can be entered. This would result in negative
246      * values as long as the element's right border is at the left of the
247      * frame's right border. As that is usually the case, I additionally invert
248      * the X axis.
249      *
250      * Default value is left.
251      *
252      * |----l----->|#######|----r--->|
253      * |           |---w-->|         |
254      * |           |#######|         |
255      * |                             |
256      * |----------m_frameWidth------>|
257      * |                             |
258      *
259      * Left selected: Value = l
260      * Right selected: Value = r
261      *
262      * To calculate between the two coorindate systems:
263      * l = m_frameWidth - w - r
264      * r = m_frameWidth - w - l
265      */
266     void slotOriginXClicked();
267
268     /** @brief Same as slotOriginXClicked(), but for the Y axis; default is top.
269      * @ref slotOriginXClicked */
270     void slotOriginYClicked();
271
272     /** @brief Updates coordinates of text fields if necessary.
273      *
274      * It's called when something changes in the QGraphicsScene. */
275     void slotChanged();
276
277     /** @param valueType of type ValueType */
278     void slotValueChanged(int valueType);
279
280     void slotZoom(bool up);
281     void slotUpdateZoom(int pos);
282     void slotAdjustZoom();
283     void slotZoomOneToOne();
284
285     /** Called whenever text properties change (font e.g.) */
286     void slotUpdateText();
287     void slotInsertUnicode();
288     void slotInsertUnicodeString(QString);
289
290     void displayBackgroundFrame();
291
292     void setCurrentItem(QGraphicsItem *item);
293
294     void slotTextTool();
295     void slotRectTool();
296     void slotSelectTool();
297     void slotImageTool();
298
299     void slotAnimStart(bool);
300     void slotAnimEnd(bool);
301     void slotKeepAspect(bool keep);
302
303     void itemHCenter();
304     void itemVCenter();
305     void itemTop();
306     void itemBottom();
307     void itemLeft();
308     void itemRight();
309     void slotResize50();
310     void slotResize100();
311     void slotResize200();
312
313     /** @brief Called when accepted, stores user selections for next time use.
314      * @ref writeChoices */
315     void slotAccepted();
316
317     void slotFontText(const QString& s);
318
319     /** @brief Adds an effect to an element.
320      * @param ix index of the effect in the effects menu
321      *
322      * The current implementation allows for one QGraphicsEffect to be added
323      * along with the typewriter effect. This is not clear to the user: the
324      * stack would help, and would permit us to make more QGraphicsEffects
325      * coexist (with different layers of QGraphicsItems). */
326     void slotAddEffect(int ix);
327     void slotEditBlur(int ix);
328     void slotEditShadow();
329     void slotEditTypewriter(int ix);
330
331     /** @brief Changes the Z index of objects. */
332     void slotZIndexUp();
333     void slotZIndexDown();
334     void slotZIndexTop();
335     void slotZIndexBottom();
336     /** Called when the user wants to apply a different template to the title */
337     void templateIndexChanged(int);
338 };
339
340 #endif