]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
b6ecc7c99b6c8804040b560d80b6956f4342c29a
[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     /** 
173      * \brief Get the minimum/maximum z index value of items.
174      * \param maxBound true: Use maximum z index. false: Use minimum
175      * \param intersectingOnly Only considers the items intersecting with
176      * the currently selected item if true.
177      */
178     qreal zIndexBounds(bool maxBound, bool intersectingOnly);
179
180     void itemRotate(qreal val, int axis);
181
182 public slots:
183     void slotNewText(QGraphicsTextItem *tt);
184     void slotNewRect(QGraphicsRectItem *rect);
185     void slotChangeBackground();
186     void selectionChanged();
187     void rectChanged();
188     void setupViewports();
189     void zIndexChanged(int);
190     void itemScaled(int);
191     void itemRotateX(qreal);
192     void itemRotateY(qreal);
193     void itemRotateZ(qreal);
194     void saveTitle(KUrl url = KUrl());
195     void loadTitle(KUrl url = KUrl());
196
197 private slots:
198     void slotAdjustSelectedItem();
199
200     /**
201      * \brief Switches the origin of the x axis between left and right
202      * border of the frame (offset from left/right frame border)
203      * \param originLeft Take left border?
204      *
205      * Called when the origin of the x coorinate has been changed. The
206      * x origin will either be at the left or at the right side of the frame.
207      *
208      * When the origin of the x axis is at the left side, the user can
209      * enter the distance between an element's left border and the left
210      * side of the frame.
211      *
212      * When on the right, the distance from the right border of the
213      * frame to the right border of the element can be entered. This
214      * would result in negative values as long as the element's right
215      * border is at the left of the frame's right border. As that is
216      * usually the case, I additionally invert the x axis.
217      *
218      * Default value is left.
219      *
220      * |----l----->|#######|----r--->|
221      * |           |---w-->|         |
222      * |           |#######|         |
223      * |                             |
224      * |----------m_frameWidth------>|
225      * |                             |
226      *
227      * Left selected: Value = l
228      * Right selected: Value = r
229      *
230      * To calculate between the two coorindate systems:
231      * l = m_frameWidth - w - r
232      * r = m_frameWidth - w - l
233      *
234      */
235     void slotOriginXClicked();
236     /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
237      *  \param originTop Take top border? */
238     void slotOriginYClicked();
239
240     /** \brief Update coorinates of text fields if necessary and text has changed */
241     void slotChanged();
242
243     /** \param valueType Of type ValueType */
244     void slotValueChanged(int valueType);
245
246     void slotZoom(bool up);
247     void slotUpdateZoom(int pos);
248     void slotAdjustZoom();
249     void slotZoomOneToOne();
250
251     void slotUpdateText();
252     void slotInsertUnicode();
253     void slotInsertUnicodeString(QString);
254
255     void displayBackgroundFrame();
256
257     void setCurrentItem(QGraphicsItem *item);
258
259     void slotTextTool();
260     void slotRectTool();
261     void slotSelectTool();
262     void slotImageTool();
263
264     void slotAnimStart(bool);
265     void slotAnimEnd(bool);
266     void slotKeepAspect(bool keep);
267
268     void itemHCenter();
269     void itemVCenter();
270     void itemTop();
271     void itemBottom();
272     void itemLeft();
273     void itemRight();
274     void slotResize50();
275     void slotResize100();
276     void slotResize200();
277
278     /** \brief Called when accepted, stores the user selections for next time use */
279     void slotAccepted();
280
281     void slotFontText(const QString& s);
282
283     void slotAddEffect(int ix);
284     void slotEditBlur(int ix);
285     void slotEditShadow();
286     void slotEditTypewriter(int ix);
287
288     /** \brief Changes the z index of objects. */
289     void slotZIndexUp();
290     void slotZIndexDown();
291     void slotZIndexTop();
292     void slotZIndexBottom();
293 };
294
295
296 #endif