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