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