]> git.sesse.net Git - kdenlive/blob - src/widgets/titlewidget.h
Moving choosecolorwidget and colorpickerwidget in the widget folder.
[kdenlive] / src / widgets / 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     explicit TitleWidget(const KUrl &url, const Timecode &tc, const QString &projectTitlePath, Render *render, QWidget *parent = 0);
67     virtual ~TitleWidget();
68     QDomDocument xml();
69     void setXml(const 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(const 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(const 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 duration. */
101     int duration() const;
102
103     /** @brief Retrieves a list of all available title templates. */
104     static void refreshTitleTemplates();
105
106 protected:
107     void resizeEvent(QResizeEvent * event);
108     void keyPressEvent(QKeyEvent *e);
109     QSize sizeHint() const;
110
111 private:
112
113     /** @brief Rectangle describing the animation start viewport. */
114     QGraphicsRectItem *m_startViewport;
115
116     /** @brief Rectangle describing the animation end viewport. */
117     QGraphicsRectItem *m_endViewport;
118
119     /** @brief Scene for the titler. */
120     GraphicsSceneRectMove *m_scene;
121
122     /** @brief Initialises the animation properties (viewport size, etc.). */
123     void initAnimation();
124     QMap<QGraphicsItem*, Transform > m_transformations;
125     TitleDocument m_titledocument;
126     QGraphicsRectItem *m_frameBorder;
127     QGraphicsPixmapItem *m_frameImage;
128     int m_frameWidth;
129     int m_frameHeight;
130     Render *m_render;   // TODO Is NOT destroyed in the destructor. Deliberately?
131     int m_count;
132     QAction *m_buttonRect;
133     QAction *m_buttonText;
134     QAction *m_buttonImage;
135     QAction *m_buttonCursor;
136     QAction *m_buttonSave;
137     QAction *m_buttonLoad;
138
139     QAction *m_unicodeAction;
140     QAction *m_zUp;
141     QAction *m_zDown;
142     QAction *m_zTop;
143     QAction *m_zBottom;
144     QAction *m_selectAll;
145     QAction *m_selectText;
146     QAction *m_selectRects;
147     QAction *m_selectImages;
148     QAction *m_unselectAll;
149
150     /** @brief Dialog for entering Unicode characters in text fields. */
151     UnicodeDialog *m_unicodeDialog;
152
153     /** @brief Project path for storing title documents. */
154     QString m_projectTitlePath;
155     Timecode m_tc;
156     QString lastDocumentHash;
157
158     // See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage.
159     QSignalMapper *m_signalMapper;
160
161     enum ValueType { ValueWidth = 1, ValueHeight = 2, ValueX = 4, ValueY = 8 };
162
163     /** @brief Sets the font weight value in the combo box. (#909) */
164     void setFontBoxWeight(int weight);
165
166     /** @brief Stores the choices of font, background and rectangle values. */
167     void writeChoices();
168
169     /** @brief Reads the last stored choices into the dialog. */
170     void readChoices();
171
172     /** @brief Updates the displayed X/Y coordinates. */
173     void updateCoordinates(QGraphicsItem *i);
174
175     /** @brief Updates the displayed width/height/zindex values. */
176     void updateDimension(QGraphicsItem *i);
177
178     /** @brief Updates the displayed rotation/zoom values. Changes values of rotation/zoom GUI elements. */
179     void updateRotZoom(QGraphicsItem *i);
180
181     /** @brief Updates the item position (position read directly from the GUI). Does not change GUI elements. */
182     void updatePosition(QGraphicsItem *i);
183     /** @brief Updates the item position. Does not change GUI elements. */
184     void updatePosition(QGraphicsItem *i, int x, int y);
185
186     void textChanged(QGraphicsTextItem *i);
187     void updateAxisButtons(QGraphicsItem *i);
188
189     void updateTextOriginX();
190     void updateTextOriginY();
191
192     /** @brief Enables the toolbars suiting to toolType. */
193     void enableToolbars(TITLETOOL toolType);
194
195     /** @brief Shows the toolbars suiting to toolType. */
196     void showToolbars(TITLETOOL toolType);
197     
198     /** @brief Set up the tools suiting referenceItem */
199     void prepareTools(QGraphicsItem *referenceItem);
200
201     /** @brief Checks a tool button. */
202     void checkButton(TITLETOOL toolType);
203
204     void adjustFrameSize();
205
206     /** @brief Adds a "start" and "end" info text to the animation viewports. */
207     void addAnimInfoText();
208
209     /** @brief Updates the font for the "start" and "end" info text. */
210     void updateInfoText();
211
212     /** @brief Removes the "start" and "end" info text from animation viewports. */
213     void deleteAnimInfoText();
214
215     qreal maxZIndex();
216
217     /** @brief Gets the minimum/maximum Z index of items.
218      * @param maxBound true: use maximum Z index; false: use minimum
219      * @param intersectingOnly if true, consider only the items intersecting
220      *     with the currently selected item
221      */
222     qreal zIndexBounds(bool maxBound, bool intersectingOnly);
223
224     void itemRotate(qreal val, int axis);
225
226     void selectItems(int itemType);
227
228     /** @brief Appends the shortcut of a QAction to a tooltip text */
229     QString getTooltipWithShortcut(const QString& text, QAction *button);
230
231 public slots:
232     void slotNewText(QGraphicsTextItem *tt);
233     void slotNewRect(QGraphicsRectItem *rect);
234     void slotChangeBackground();
235
236     /** @brief Sets up the tools (toolbars etc.) according to the selected item. */
237     void selectionChanged();
238     void rectChanged();
239     void setupViewports();
240     void zIndexChanged(int);
241     void itemScaled(int);
242     void itemRotateX(qreal);
243     void itemRotateY(qreal);
244     void itemRotateZ(qreal);
245     /** Save a title to a title file */
246     void saveTitle(KUrl url = KUrl());
247     /** Load a title from a title file */
248     void loadTitle(KUrl url = KUrl());
249
250 private slots:
251
252     /** @brief Switches the origin of the X axis between left and right border.
253      *
254      * It's called when the origin of the X coordinate has been changed. The X
255      * origin will either be at the left or at the right side of the frame.
256      *
257      * When the origin of the X axis is at the left side, the user can enter the
258      * distance between an element's left border and the left side of the frame.
259      *
260      * When on the right, the distance from the right border of the frame to the
261      * right border of the element can be entered. This would result in negative
262      * values as long as the element's right border is at the left of the
263      * frame's right border. As that is usually the case, I additionally invert
264      * the X axis.
265      *
266      * Default value is left.
267      *
268      * |----l----->|#######|----r--->|
269      * |           |---w-->|         |
270      * |           |#######|         |
271      * |                             |
272      * |----------m_frameWidth------>|
273      * |                             |
274      *
275      * Left selected: Value = l
276      * Right selected: Value = r
277      *
278      * To calculate between the two coorindate systems:
279      * l = m_frameWidth - w - r
280      * r = m_frameWidth - w - l
281      */
282     void slotOriginXClicked();
283
284     /** @brief Same as slotOriginXClicked(), but for the Y axis; default is top.
285      * @ref slotOriginXClicked */
286     void slotOriginYClicked();
287
288     /** @brief Updates coordinates of text fields if necessary.
289      *
290      * It's called when something changes in the QGraphicsScene. */
291     void slotChanged();
292
293     /** 
294      * Reacts to changes of widht/height/x/y QSpinBox values.
295      * @brief Updates width, height, and position of the selected items.
296      * @param valueType of type ValueType
297      */
298     void slotValueChanged(int valueType);
299
300     void slotZoom(bool up);
301     void slotUpdateZoom(int pos);
302     void slotAdjustZoom();
303     void slotZoomOneToOne();
304
305     void slotSelectAll();
306     void slotSelectText();
307     void slotSelectRects();
308     void slotSelectImages();
309     void slotSelectNone();
310
311
312     /** Called whenever text properties change (font e.g.) */
313     void slotUpdateText();
314     void slotInsertUnicode();
315     void slotInsertUnicodeString(const QString&);
316
317     void displayBackgroundFrame();
318
319     void setCurrentItem(QGraphicsItem *item);
320
321     void slotTextTool();
322     void slotRectTool();
323     void slotSelectTool();
324     void slotImageTool();
325
326     void slotAnimStart(bool);
327     void slotAnimEnd(bool);
328     void slotKeepAspect(bool keep);
329
330     void itemHCenter();
331     void itemVCenter();
332     void itemTop();
333     void itemBottom();
334     void itemLeft();
335     void itemRight();
336     void slotResize50();
337     void slotResize100();
338     void slotResize200();
339
340     /** @brief Called when accepted, stores user selections for next time use.
341      * @ref writeChoices */
342     void slotAccepted();
343
344     void slotFontText(const QString& s);
345
346     /** @brief Adds an effect to an element.
347      * @param ix index of the effect in the effects menu
348      *
349      * The current implementation allows for one QGraphicsEffect to be added
350      * along with the typewriter effect. This is not clear to the user: the
351      * stack would help, and would permit us to make more QGraphicsEffects
352      * coexist (with different layers of QGraphicsItems). */
353     void slotAddEffect(int ix);
354     void slotEditBlur(int ix);
355     void slotEditShadow();
356     void slotEditTypewriter(int ix);
357
358     /** @brief Changes the Z index of objects. */
359     void slotZIndexUp();
360     void slotZIndexDown();
361     void slotZIndexTop();
362     void slotZIndexBottom();
363     /** Called when the user wants to apply a different template to the title */
364     void templateIndexChanged(int);
365 };
366
367 #endif