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();
173 * \brief Get the minimum/maximum z index value of items.
174 * \param maxBound true: Use maximum z index. false: Use minimum
175 * \param intersectingOnly Only considers the items intersecting with
176 * the currently selected item if true.
178 qreal zIndexBounds(bool maxBound, bool intersectingOnly);
180 void itemRotate(qreal val, int axis);
183 void slotNewText(QGraphicsTextItem *tt);
184 void slotNewRect(QGraphicsRectItem *rect);
185 void slotChangeBackground();
186 void selectionChanged();
188 void setupViewports();
189 void zIndexChanged(int);
190 void itemScaled(int);
191 void itemRotateX(qreal);
192 void itemRotateY(qreal);
193 void itemRotateZ(qreal);
194 void saveTitle(KUrl url = KUrl());
195 void loadTitle(KUrl url = KUrl());
198 void slotAdjustSelectedItem();
201 * \brief Switches the origin of the x axis between left and right
202 * border of the frame (offset from left/right frame border)
203 * \param originLeft Take left border?
205 * Called when the origin of the x coorinate has been changed. The
206 * x origin will either be at the left or at the right side of the frame.
208 * When the origin of the x axis is at the left side, the user can
209 * enter the distance between an element's left border and the left
212 * When on the right, the distance from the right border of the
213 * frame to the right border of the element can be entered. This
214 * would result in negative values as long as the element's right
215 * border is at the left of the frame's right border. As that is
216 * usually the case, I additionally invert the x axis.
218 * Default value is left.
220 * |----l----->|#######|----r--->|
224 * |----------m_frameWidth------>|
227 * Left selected: Value = l
228 * Right selected: Value = r
230 * To calculate between the two coorindate systems:
231 * l = m_frameWidth - w - r
232 * r = m_frameWidth - w - l
235 void slotOriginXClicked();
236 /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
237 * \param originTop Take top border? */
238 void slotOriginYClicked();
240 /** \brief Update coorinates of text fields if necessary and text has changed */
243 /** \param valueType Of type ValueType */
244 void slotValueChanged(int valueType);
246 void slotZoom(bool up);
247 void slotUpdateZoom(int pos);
248 void slotAdjustZoom();
249 void slotZoomOneToOne();
251 void slotUpdateText();
252 void slotInsertUnicode();
253 void slotInsertUnicodeString(QString);
255 void displayBackgroundFrame();
257 void setCurrentItem(QGraphicsItem *item);
261 void slotSelectTool();
262 void slotImageTool();
264 void slotAnimStart(bool);
265 void slotAnimEnd(bool);
266 void slotKeepAspect(bool keep);
275 void slotResize100();
276 void slotResize200();
278 /** \brief Called when accepted, stores the user selections for next time use */
281 void slotFontText(const QString& s);
283 void slotAddEffect(int ix);
284 void slotEditBlur(int ix);
285 void slotEditShadow();
286 void slotEditTypewriter(int ix);
288 /** \brief Changes the z index of objects. */
290 void slotZIndexDown();
291 void slotZIndexTop();
292 void slotZIndexBottom();