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