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 Return a list af all fonts included in a title
73 * \param xml The xml data for title
75 static QStringList extractFontList(QString xml);
77 /** \brief Build a filename from a projectUrl and a titleName
78 * \param projectUrl Url to directory of project.
79 * \param titleName Name of title, on the form "titleXXX"
81 * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
82 * get the filename. It is not checked that the title png actually exists, only the name is build and
84 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
86 /** \brief Get clip duration. */
90 virtual void resizeEvent(QResizeEvent * event);
93 /** \brief Rectangle describing animation start viewport */
94 QGraphicsRectItem *m_startViewport;
95 /** \brief Rectangle describing animation end viewport */
96 QGraphicsRectItem *m_endViewport;
97 /** \brief Scene for the titler */
98 GraphicsSceneRectMove *m_scene;
99 /** \brief Initialize the animation properties (viewport size,...) */
100 void initAnimation();
101 QMap<QGraphicsItem*, Transform > m_transformations;
102 TitleDocument m_titledocument;
103 QGraphicsRectItem *m_frameBorder;
104 QGraphicsPixmapItem *m_frameImage;
109 QAction *m_buttonRect;
110 QAction *m_buttonText;
111 QAction *m_buttonImage;
112 QAction *m_buttonCursor;
113 QAction *m_buttonSave;
114 QAction *m_buttonLoad;
116 QAction *m_unicodeAction;
122 /** \brief Dialog for entering unicode in text fields */
123 UnicodeDialog *m_unicodeDialog;
124 /** project path for storing title clips */
125 QString m_projectTitlePath;
128 /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
129 QSignalMapper *m_signalMapper;
131 enum ValueType { ValueWidth = 0, ValueHeight = 1 };
133 /** \brief Sets the font weight value in the combo box. (#909) */
134 void setFontBoxWeight(int weight);
136 /** \brief Store the current choices of font, background and rect values */
138 /** \brief Read the last stored choices into the dialog */
140 /** \brief Update the displayed X/Y coordinate values */
141 void updateCoordinates(QGraphicsItem *i);
142 /** \brief Update displayed width/height values */
143 void updateDimension(QGraphicsItem *i);
144 /** \brief Update displayed rotation/zoom values */
145 void updateRotZoom(QGraphicsItem *i);
147 /** \brief Update the item's position */
148 void updatePosition(QGraphicsItem *i);
150 void textChanged(QGraphicsTextItem *i);
151 void updateAxisButtons(QGraphicsItem *i);
153 void updateTextOriginX();
154 void updateTextOriginY();
156 /** \brief Enables the toolbars suiting to toolType */
157 void enableToolbars(TITLETOOL toolType);
158 /** \brief Shows the toolbars suiting to toolType */
159 void showToolbars(TITLETOOL toolType);
160 /** \brief Check a tool button. */
161 void checkButton(TITLETOOL toolType);
163 void adjustFrameSize();
164 /** \brief Add a "start" and "end" info text to the animation viewports */
165 void addAnimInfoText();
166 /** \brief Update font for the "start" and "end" info text */
167 void updateInfoText();
168 /** \brief Remove the "start" and "end" info text from animation viewports */
169 void deleteAnimInfoText();
172 qreal zIndexBounds(bool maxBound);
174 void itemRotate(qreal val, int axis);
177 void slotNewText(QGraphicsTextItem *tt);
178 void slotNewRect(QGraphicsRectItem *rect);
179 void slotChangeBackground();
180 void selectionChanged();
182 void setupViewports();
183 void zIndexChanged(int);
184 void itemScaled(int);
185 void itemRotateX(qreal);
186 void itemRotateY(qreal);
187 void itemRotateZ(qreal);
188 void saveTitle(KUrl url = KUrl());
189 void loadTitle(KUrl url = KUrl());
192 void slotAdjustSelectedItem();
195 * \brief Switches the origin of the x axis between left and right
196 * border of the frame (offset from left/right frame border)
197 * \param originLeft Take left border?
199 * Called when the origin of the x coorinate has been changed. The
200 * x origin will either be at the left or at the right side of the frame.
202 * When the origin of the x axis is at the left side, the user can
203 * enter the distance between an element's left border and the left
206 * When on the right, the distance from the right border of the
207 * frame to the right border of the element can be entered. This
208 * would result in negative values as long as the element's right
209 * border is at the left of the frame's right border. As that is
210 * usually the case, I additionally invert the x axis.
212 * Default value is left.
214 * |----l----->|#######|----r--->|
218 * |----------m_frameWidth------>|
221 * Left selected: Value = l
222 * Right selected: Value = r
224 * To calculate between the two coorindate systems:
225 * l = m_frameWidth - w - r
226 * r = m_frameWidth - w - l
229 void slotOriginXClicked();
230 /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
231 * \param originTop Take top border? */
232 void slotOriginYClicked();
234 /** \brief Update coorinates of text fields if necessary and text has changed */
237 /** \param valueType Of type ValueType */
238 void slotValueChanged(int valueType);
240 void slotZoom(bool up);
241 void slotUpdateZoom(int pos);
242 void slotAdjustZoom();
243 void slotZoomOneToOne();
245 void slotUpdateText();
246 void slotInsertUnicode();
247 void slotInsertUnicodeString(QString);
249 void displayBackgroundFrame();
251 void setCurrentItem(QGraphicsItem *item);
255 void slotSelectTool();
256 void slotImageTool();
258 void slotAnimStart(bool);
259 void slotAnimEnd(bool);
260 void slotKeepAspect(bool keep);
269 void slotResize100();
270 void slotResize200();
272 /** \brief Called when accepted, stores the user selections for next time use */
275 void slotFontText(const QString& s);
277 void slotAddEffect(int ix);
278 void slotEditBlur(int ix);
279 void slotEditShadow();
280 void slotEditTypewriter(int ix);
282 /** \brief Changes the z index of objects. */
284 void slotZIndexDown();
285 void slotZIndexTop();
286 void slotZIndexBottom();