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>
50 double scalex, scaley;
51 double rotatex, rotatey, rotatez;
55 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
60 /** \brief Constructor
61 * \param projectPath Path to use when user requests loading or saving of titles as .kdenlivetitle documents */
62 TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent = 0);
63 virtual ~TitleWidget();
65 void setXml(QDomDocument doc);
67 /** \brief Find first available filename of the form titleXXX.png in projectUrl + "/titles/" directory
68 * \param projectUrl Url to directory of project.
69 * \returns A list, with the name in the form of "/path/to/titles/titleXXX" as the first element, the extension
70 * ".png" as the second element.
72 * The path "/titles/" is appended to projectUrl to locate the actual directory that contains the title pngs. */
73 static QStringList getFreeTitleInfo(const KUrl &projectUrl, bool isClone = false);
75 /** \brief Return a list af all images included in a title
76 * \param xml The xml data for title
78 static QStringList extractImageList(QString xml);
80 /** \brief Return a list af all fonts included in a title
81 * \param xml The xml data for title
83 static QStringList extractFontList(QString xml);
85 /** \brief Build a filename from a projectUrl and a titleName
86 * \param projectUrl Url to directory of project.
87 * \param titleName Name of title, on the form "titleXXX"
89 * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
90 * get the filename. It is not checked that the title png actually exists, only the name is build and
92 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
94 /** \brief Get clip out position. */
96 /** load Title Templates*/
97 static void refreshTitleTemplates();
100 virtual void resizeEvent(QResizeEvent * event);
103 /** \brief Rectangle describing animation start viewport */
104 QGraphicsRectItem *m_startViewport;
105 /** \brief Rectangle describing animation end viewport */
106 QGraphicsRectItem *m_endViewport;
107 /** \brief Scene for the titler */
108 GraphicsSceneRectMove *m_scene;
109 /** \brief Initialize the animation properties (viewport size,...) */
110 void initAnimation();
111 QMap<QGraphicsItem*, Transform > m_transformations;
112 TitleDocument m_titledocument;
113 QGraphicsRectItem *m_frameBorder;
114 QGraphicsPixmapItem *m_frameImage;
119 QAction *m_buttonRect;
120 QAction *m_buttonText;
121 QAction *m_buttonImage;
122 QAction *m_buttonCursor;
123 QAction *m_buttonSave;
124 QAction *m_buttonLoad;
126 QAction *m_unicodeAction;
132 /** \brief Dialog for entering unicode in text fields */
133 UnicodeDialog *m_unicodeDialog;
134 /** project path for storing title clips */
135 QString m_projectTitlePath;
137 QString lastDocumentHash;
139 /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
140 QSignalMapper *m_signalMapper;
142 enum ValueType { ValueWidth = 0, ValueHeight = 1 };
144 /** \brief Sets the font weight value in the combo box. (#909) */
145 void setFontBoxWeight(int weight);
147 /** \brief Store the current choices of font, background and rect values */
149 /** \brief Read the last stored choices into the dialog */
151 /** \brief Update the displayed X/Y coordinate values */
152 void updateCoordinates(QGraphicsItem *i);
153 /** \brief Update displayed width/height values */
154 void updateDimension(QGraphicsItem *i);
155 /** \brief Update displayed rotation/zoom values */
156 void updateRotZoom(QGraphicsItem *i);
158 /** \brief Update the item's position */
159 void updatePosition(QGraphicsItem *i);
161 void textChanged(QGraphicsTextItem *i);
162 void updateAxisButtons(QGraphicsItem *i);
164 void updateTextOriginX();
165 void updateTextOriginY();
167 /** \brief Enables the toolbars suiting to toolType */
168 void enableToolbars(TITLETOOL toolType);
169 /** \brief Shows the toolbars suiting to toolType */
170 void showToolbars(TITLETOOL toolType);
171 /** \brief Check a tool button. */
172 void checkButton(TITLETOOL toolType);
174 void adjustFrameSize();
175 /** \brief Add a "start" and "end" info text to the animation viewports */
176 void addAnimInfoText();
177 /** \brief Update font for the "start" and "end" info text */
178 void updateInfoText();
179 /** \brief Remove the "start" and "end" info text from animation viewports */
180 void deleteAnimInfoText();
184 * \brief Get the minimum/maximum z index value of items.
185 * \param maxBound true: Use maximum z index. false: Use minimum
186 * \param intersectingOnly Only considers the items intersecting with
187 * the currently selected item if true.
189 qreal zIndexBounds(bool maxBound, bool intersectingOnly);
191 void itemRotate(qreal val, int axis);
194 void slotNewText(QGraphicsTextItem *tt);
195 void slotNewRect(QGraphicsRectItem *rect);
196 void slotChangeBackground();
197 void selectionChanged();
199 void setupViewports();
200 void zIndexChanged(int);
201 void itemScaled(int);
202 void itemRotateX(qreal);
203 void itemRotateY(qreal);
204 void itemRotateZ(qreal);
205 void saveTitle(KUrl url = KUrl());
206 void loadTitle(KUrl url = KUrl());
209 void slotAdjustSelectedItem();
212 * \brief Switches the origin of the x axis between left and right
213 * border of the frame (offset from left/right frame border)
214 * \param originLeft Take left border?
216 * Called when the origin of the x coorinate has been changed. The
217 * x origin will either be at the left or at the right side of the frame.
219 * When the origin of the x axis is at the left side, the user can
220 * enter the distance between an element's left border and the left
223 * When on the right, the distance from the right border of the
224 * frame to the right border of the element can be entered. This
225 * would result in negative values as long as the element's right
226 * border is at the left of the frame's right border. As that is
227 * usually the case, I additionally invert the x axis.
229 * Default value is left.
231 * |----l----->|#######|----r--->|
235 * |----------m_frameWidth------>|
238 * Left selected: Value = l
239 * Right selected: Value = r
241 * To calculate between the two coorindate systems:
242 * l = m_frameWidth - w - r
243 * r = m_frameWidth - w - l
246 void slotOriginXClicked();
247 /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
248 * \param originTop Take top border? */
249 void slotOriginYClicked();
251 /** \brief Update coorinates of text fields if necessary and text has changed */
254 /** \param valueType Of type ValueType */
255 void slotValueChanged(int valueType);
257 void slotZoom(bool up);
258 void slotUpdateZoom(int pos);
259 void slotAdjustZoom();
260 void slotZoomOneToOne();
262 void slotUpdateText();
263 void slotInsertUnicode();
264 void slotInsertUnicodeString(QString);
266 void displayBackgroundFrame();
268 void setCurrentItem(QGraphicsItem *item);
272 void slotSelectTool();
273 void slotImageTool();
275 void slotAnimStart(bool);
276 void slotAnimEnd(bool);
277 void slotKeepAspect(bool keep);
286 void slotResize100();
287 void slotResize200();
289 /** \brief Called when accepted, stores the user selections for next time use */
292 void slotFontText(const QString& s);
294 void slotAddEffect(int ix);
295 void slotEditBlur(int ix);
296 void slotEditShadow();
297 void slotEditTypewriter(int ix);
299 /** \brief Changes the z index of objects. */
301 void slotZIndexDown();
302 void slotZIndexTop();
303 void slotZIndexBottom();
304 void templateIndexChanged(int);