1 /***************************************************************************
2 titlewidget.h - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
22 #include "ui_titlewidget_ui.h"
23 #include "titledocument.h"
25 #include "graphicsscenerectmove.h"
26 #include "unicodedialog.h"
30 #include <QSignalMapper>
43 double scalex, scaley;
44 double rotatex, rotatey, rotatez;
47 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
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();
57 void setXml(QDomDocument doc);
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.
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);
67 /** \brief Return a list af all images included in a title
68 * \param xml The xml data for title
70 static QStringList extractImageList(QString xml);
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"
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
79 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
81 /** \brief Get clip duration. */
85 virtual void resizeEvent(QResizeEvent * event);
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,...) */
96 QMap<QGraphicsItem*, Transform > m_transformations;
97 TitleDocument m_titledocument;
98 QGraphicsRectItem *m_frameBorder;
99 QGraphicsPixmapItem *m_frameImage;
104 QAction *m_buttonRect;
105 QAction *m_buttonText;
106 QAction *m_buttonImage;
107 QAction *m_buttonCursor;
108 QAction *m_buttonSave;
109 QAction *m_buttonLoad;
111 QAction *m_unicodeAction;
117 /** \brief Dialog for entering unicode in text fields */
118 UnicodeDialog *m_unicodeDialog;
119 /** project path for storing title clips */
120 QString m_projectTitlePath;
123 /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
124 QSignalMapper *m_signalMapper;
126 enum ValueType { ValueWidth = 0, ValueHeight = 1 };
128 /** \brief Sets the font weight value in the combo box. (#909) */
129 void setFontBoxWeight(int weight);
131 /** \brief Store the current choices of font, background and rect values */
133 /** \brief Read the last stored choices into the dialog */
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);
142 /** \brief Update the item's position */
143 void updatePosition(QGraphicsItem *i);
145 void textChanged(QGraphicsTextItem *i);
146 void updateAxisButtons(QGraphicsItem *i);
148 void updateTextOriginX();
149 void updateTextOriginY();
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);
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();
167 qreal zIndexBounds(bool maxBound);
169 void itemRotate(qreal val, int axis);
172 void slotNewText(QGraphicsTextItem *tt);
173 void slotNewRect(QGraphicsRectItem *rect);
174 void slotChangeBackground();
175 void selectionChanged();
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());
187 void slotAdjustSelectedItem();
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?
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.
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
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.
207 * Default value is left.
209 * |----l----->|#######|----r--->|
213 * |----------m_frameWidth------>|
216 * Left selected: Value = l
217 * Right selected: Value = r
219 * To calculate between the two coorindate systems:
220 * l = m_frameWidth - w - r
221 * r = m_frameWidth - w - l
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();
229 /** \brief Update coorinates of text fields if necessary and text has changed */
232 /** \param valueType Of type ValueType */
233 void slotValueChanged(int valueType);
235 void slotZoom(bool up);
236 void slotUpdateZoom(int pos);
237 void slotAdjustZoom();
238 void slotZoomOneToOne();
240 void slotUpdateText();
241 void slotInsertUnicode();
242 void slotInsertUnicodeString(QString);
244 void displayBackgroundFrame();
246 void setCurrentItem(QGraphicsItem *item);
250 void slotSelectTool();
251 void slotImageTool();
253 void slotAnimStart(bool);
254 void slotAnimEnd(bool);
255 void slotKeepAspect(bool keep);
264 void slotResize100();
265 void slotResize200();
267 /** \brief Called when accepted, stores the user selections for next time use */
270 void slotFontText(const QString& s);
272 void slotAddEffect(int ix);
273 void slotEditBlur(int ix);
274 void slotEditShadow();
275 void slotEditTypewriter(int ix);
277 /** \brief Changes the z index of objects. */
279 void slotZIndexDown();
280 void slotZIndexTop();
281 void slotZIndexBottom();