]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
Update for new titler module, turn clip speed into an effect, mem leaks and more
[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 Build a filename from a projectUrl and a titleName
66      * \param projectUrl Url to directory of project.
67      * \param titleName Name of title, on the form "titleXXX"
68      *
69      * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
70      * get the filename. It is not checked that the title png actually exists, only the name is build and
71      * returned. */
72     static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
73
74     /** \brief returns the size of the rendered pixmap
75     *
76     */
77     const QRect renderedRect();
78
79     /** \brief Get clip duration. */
80     int duration() const;
81
82 protected:
83     virtual void resizeEvent(QResizeEvent * event);
84
85 private:
86     QGraphicsPolygonItem *m_startViewport, *m_endViewport;
87     GraphicsSceneRectMove *m_scene;
88     void initViewports();
89     QMap<QGraphicsItem*, Transform > m_transformations;
90     TitleDocument m_titledocument;
91     QGraphicsRectItem *m_frameBorder;
92     QGraphicsPixmapItem *m_frameImage;
93     int m_frameWidth;
94     int m_frameHeight;
95     Render *m_render;
96     int m_count;
97     QAction *m_buttonRect;
98     QAction *m_buttonText;
99     QAction *m_buttonImage;
100     QAction *m_buttonCursor;
101     QAction *m_buttonSave;
102     QAction *m_buttonLoad;
103
104     QAction *m_unicodeAction;
105
106     /** \brief Dialog for entering unicode in text fields */
107     UnicodeDialog *m_unicodeDialog;
108     /** project path for storing title clips */
109     QString m_projectTitlePath;
110     Timecode m_tc;
111
112     /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
113     QSignalMapper *m_signalMapper;
114
115     enum ValueType { ValueWidth = 0, ValueHeight = 1 };
116
117     /** \brief Sets the font weight value in the combo box. (#909) */
118     void setFontBoxWeight(int weight);
119
120     /** \brief Store the current choices of font, background and rect values */
121     void writeChoices();
122     /** \brief Read the last stored choices into the dialog */
123     void readChoices();
124     /** \brief Update the displayed X/Y coordinate values */
125     void updateCoordinates(QGraphicsItem *i);
126     /** \brief Update displayed width/height values */
127     void updateDimension(QGraphicsItem *i);
128     /** \brief Update displayed rotation/zoom values */
129     void updateRotZoom(QGraphicsItem *i);
130
131     /** \brief Update the item's position */
132     void updatePosition(QGraphicsItem *i);
133
134     void textChanged(QGraphicsTextItem *i);
135     void updateAxisButtons(QGraphicsItem *i);
136
137     void updateTextOriginX();
138     void updateTextOriginY();
139
140     /** \brief Enables the toolbars suiting to toolType */
141     void enableToolbars(TITLETOOL toolType);
142     /** \brief Shows the toolbars suiting to toolType */
143     void showToolbars(TITLETOOL toolType);
144     /** \brief Check a tool button. */
145     void checkButton(TITLETOOL toolType);
146
147 public slots:
148     void slotNewText(QGraphicsTextItem *tt);
149     void slotNewRect(QGraphicsRectItem *rect);
150     void slotChangeBackground();
151     void selectionChanged();
152     void rectChanged();
153     void setupViewports();
154     void zIndexChanged(int);
155     void itemScaled(int);
156     void itemRotate(int);
157     void itemHCenter();
158     void itemVCenter();
159     void saveTitle(KUrl url = KUrl());
160     void loadTitle();
161     QImage renderedPixmap();
162
163 private slots:
164     void slotAdjustSelectedItem();
165
166     /**
167      * \brief Switches the origin of the x axis between left and right
168      * border of the frame (offset from left/right frame border)
169      * \param originLeft Take left border?
170      *
171      * Called when the origin of the x coorinate has been changed. The
172      * x origin will either be at the left or at the right side of the frame.
173      *
174      * When the origin of the x axis is at the left side, the user can
175      * enter the distance between an element's left border and the left
176      * side of the frame.
177      *
178      * When on the right, the distance from the right border of the
179      * frame to the right border of the element can be entered. This
180      * would result in negative values as long as the element's right
181      * border is at the left of the frame's right border. As that is
182      * usually the case, I additionally invert the x axis.
183      *
184      * Default value is left.
185      *
186      * |----l----->|#######|----r--->|
187      * |           |---w-->|         |
188      * |           |#######|         |
189      * |                             |
190      * |----------m_frameWidth------>|
191      * |                             |
192      *
193      * Left selected: Value = l
194      * Right selected: Value = r
195      *
196      * To calculate between the two coorindate systems:
197      * l = m_frameWidth - w - r
198      * r = m_frameWidth - w - l
199      *
200      */
201     void slotOriginXClicked();
202     /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
203      *  \param originTop Take top border? */
204     void slotOriginYClicked();
205
206     /** \brief Update coorinates of text fields if necessary and text has changed */
207     void slotChanged();
208
209     /** \param valueType Of type ValueType */
210     void slotValueChanged(int valueType);
211
212     void slotZoom(bool up);
213     void slotUpdateZoom(int pos);
214     void slotAdjustZoom();
215     void slotZoomOneToOne();
216
217     void slotUpdateText();
218     void slotInsertUnicode();
219     void slotInsertUnicodeString(QString);
220
221     void displayBackgroundFrame();
222
223     void setCurrentItem(QGraphicsItem *item);
224
225     void slotTextTool();
226     void slotRectTool();
227     void slotSelectTool();
228     void slotImageTool();
229
230
231     /** \brief Called when accepted, stores the user selections for next time use */
232     void slotAccepted();
233 };
234
235
236 #endif