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