]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
Add 3d rotation to objects in titler, based on patch from Till Theato
[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 Build a filename from a projectUrl and a titleName
73      * \param projectUrl Url to directory of project.
74      * \param titleName Name of title, on the form "titleXXX"
75      *
76      * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
77      * get the filename. It is not checked that the title png actually exists, only the name is build and
78      * returned. */
79     static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
80
81     /** \brief Get clip duration. */
82     int duration() const;
83
84 protected:
85     virtual void resizeEvent(QResizeEvent * event);
86
87 private:
88     /** \brief Rectangle describing animation start viewport */
89     QGraphicsRectItem *m_startViewport;
90     /** \brief Rectangle describing animation end viewport */
91     QGraphicsRectItem *m_endViewport;
92     /** \brief Scene for the titler */
93     GraphicsSceneRectMove *m_scene;
94     /** \brief Initialize the animation properties (viewport size,...) */
95     void initAnimation();
96     QMap<QGraphicsItem*, Transform > m_transformations;
97     TitleDocument m_titledocument;
98     QGraphicsRectItem *m_frameBorder;
99     QGraphicsPixmapItem *m_frameImage;
100     int m_frameWidth;
101     int m_frameHeight;
102     Render *m_render;
103     int m_count;
104     QAction *m_buttonRect;
105     QAction *m_buttonText;
106     QAction *m_buttonImage;
107     QAction *m_buttonCursor;
108     QAction *m_buttonSave;
109     QAction *m_buttonLoad;
110
111     QAction *m_unicodeAction;
112     QAction *m_zUp;
113     QAction *m_zDown;
114     QAction *m_zTop;
115     QAction *m_zBottom;
116
117     /** \brief Dialog for entering unicode in text fields */
118     UnicodeDialog *m_unicodeDialog;
119     /** project path for storing title clips */
120     QString m_projectTitlePath;
121     Timecode m_tc;
122
123     /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
124     QSignalMapper *m_signalMapper;
125
126     enum ValueType { ValueWidth = 0, ValueHeight = 1 };
127
128     /** \brief Sets the font weight value in the combo box. (#909) */
129     void setFontBoxWeight(int weight);
130
131     /** \brief Store the current choices of font, background and rect values */
132     void writeChoices();
133     /** \brief Read the last stored choices into the dialog */
134     void readChoices();
135     /** \brief Update the displayed X/Y coordinate values */
136     void updateCoordinates(QGraphicsItem *i);
137     /** \brief Update displayed width/height values */
138     void updateDimension(QGraphicsItem *i);
139     /** \brief Update displayed rotation/zoom values */
140     void updateRotZoom(QGraphicsItem *i);
141
142     /** \brief Update the item's position */
143     void updatePosition(QGraphicsItem *i);
144
145     void textChanged(QGraphicsTextItem *i);
146     void updateAxisButtons(QGraphicsItem *i);
147
148     void updateTextOriginX();
149     void updateTextOriginY();
150
151     /** \brief Enables the toolbars suiting to toolType */
152     void enableToolbars(TITLETOOL toolType);
153     /** \brief Shows the toolbars suiting to toolType */
154     void showToolbars(TITLETOOL toolType);
155     /** \brief Check a tool button. */
156     void checkButton(TITLETOOL toolType);
157
158     void adjustFrameSize();
159     /** \brief Add a "start" and "end" info text to the animation viewports */
160     void addAnimInfoText();
161     /** \brief Update font for the "start" and "end" info text */
162     void updateInfoText();
163     /** \brief Remove the "start" and "end" info text from animation viewports */
164     void deleteAnimInfoText();
165
166     qreal maxZIndex();
167     qreal zIndexBounds(bool maxBound);
168
169     void itemRotate(qreal val, int axis);
170
171 public slots:
172     void slotNewText(QGraphicsTextItem *tt);
173     void slotNewRect(QGraphicsRectItem *rect);
174     void slotChangeBackground();
175     void selectionChanged();
176     void rectChanged();
177     void setupViewports();
178     void zIndexChanged(int);
179     void itemScaled(int);
180     void itemRotateX(qreal);
181     void itemRotateY(qreal);
182     void itemRotateZ(qreal);
183     void saveTitle(KUrl url = KUrl());
184     void loadTitle(KUrl url = KUrl());
185
186 private slots:
187     void slotAdjustSelectedItem();
188
189     /**
190      * \brief Switches the origin of the x axis between left and right
191      * border of the frame (offset from left/right frame border)
192      * \param originLeft Take left border?
193      *
194      * Called when the origin of the x coorinate has been changed. The
195      * x origin will either be at the left or at the right side of the frame.
196      *
197      * When the origin of the x axis is at the left side, the user can
198      * enter the distance between an element's left border and the left
199      * side of the frame.
200      *
201      * When on the right, the distance from the right border of the
202      * frame to the right border of the element can be entered. This
203      * would result in negative values as long as the element's right
204      * border is at the left of the frame's right border. As that is
205      * usually the case, I additionally invert the x axis.
206      *
207      * Default value is left.
208      *
209      * |----l----->|#######|----r--->|
210      * |           |---w-->|         |
211      * |           |#######|         |
212      * |                             |
213      * |----------m_frameWidth------>|
214      * |                             |
215      *
216      * Left selected: Value = l
217      * Right selected: Value = r
218      *
219      * To calculate between the two coorindate systems:
220      * l = m_frameWidth - w - r
221      * r = m_frameWidth - w - l
222      *
223      */
224     void slotOriginXClicked();
225     /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
226      *  \param originTop Take top border? */
227     void slotOriginYClicked();
228
229     /** \brief Update coorinates of text fields if necessary and text has changed */
230     void slotChanged();
231
232     /** \param valueType Of type ValueType */
233     void slotValueChanged(int valueType);
234
235     void slotZoom(bool up);
236     void slotUpdateZoom(int pos);
237     void slotAdjustZoom();
238     void slotZoomOneToOne();
239
240     void slotUpdateText();
241     void slotInsertUnicode();
242     void slotInsertUnicodeString(QString);
243
244     void displayBackgroundFrame();
245
246     void setCurrentItem(QGraphicsItem *item);
247
248     void slotTextTool();
249     void slotRectTool();
250     void slotSelectTool();
251     void slotImageTool();
252
253     void slotAnimStart(bool);
254     void slotAnimEnd(bool);
255     void slotKeepAspect(bool keep);
256
257     void itemHCenter();
258     void itemVCenter();
259     void itemTop();
260     void itemBottom();
261     void itemLeft();
262     void itemRight();
263     void slotResize50();
264     void slotResize100();
265     void slotResize200();
266
267     /** \brief Called when accepted, stores the user selections for next time use */
268     void slotAccepted();
269
270     void slotFontText(const QString& s);
271
272     void slotAddEffect(int ix);
273     void slotEditBlur(int ix);
274     void slotEditShadow();
275     void slotEditTypewriter(int ix);
276
277     /** \brief Changes the z index of objects. */
278     void slotZIndexUp();
279     void slotZIndexDown();
280     void slotZIndexTop();
281     void slotZIndexBottom();
282 };
283
284
285 #endif