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 ***************************************************************************/
21 #include "ui_titlewidget_ui.h"
22 #include "titledocument.h"
24 #include "graphicsscenerectmove.h"
25 #include "unicodedialog.h"
29 #include <QSignalMapper>
49 double scalex, scaley;
50 double rotatex, rotatey, rotatez;
54 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
60 /** @brief Draws the dialog and loads a title document (if any).
61 * @param url title document to load
62 * @param tc timecode of the project
63 * @param projectPath default path to save to or load from title documents
64 * @param render project renderer
65 * @param parent (optional) parent widget */
66 TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent = 0);
67 virtual ~TitleWidget();
69 void setXml(QDomDocument doc);
71 /** @brief Finds the first available file name for a title document.
72 * @deprecated With the titler module there's no need to save titles as images.
73 * @param projectUrl project directory
74 * @param isClone (optional) if true, the file name will be cloneXXX.png
75 * @return list with title name (Title XXX or Clone XXX) and file name
77 * The path "/titles/" is appended to projectUrl, and the format of the file name is (title|clone)XXX.png. */
78 static QStringList getFreeTitleInfo(const KUrl &projectUrl, bool isClone = false);
80 /** @brief Checks for the images referenced by a title clip.
81 * @param xml XML data representing the title
82 * @return list of the image files */
83 static QStringList extractImageList(QString xml);
85 /** @brief Checks for the fonts referenced by a title clip.
86 * @param xml XML data representing the title
87 * @return list of the fonts */
88 static QStringList extractFontList(QString xml);
90 /** @brief Builds a file name for a title document.
91 * @deprecated With the titler module there's no need to save titles as images.
92 * @param projectUrl project directory
93 * @param titleName name of title, in the form titleXXX
94 * @return file name composed with the given arguments
96 * The path "/titles/" is appended to projectUrl, and .png is appended to
97 * get the file name. There is no check for the existence of the file. */
98 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
100 /** @brief Returns clip out position. */
101 int outPoint() const;
103 /** @brief Retrieves a list of all available title templates. */
104 static void refreshTitleTemplates();
107 virtual void resizeEvent(QResizeEvent * event);
111 /** @brief Rectangle describing the animation start viewport. */
112 QGraphicsRectItem *m_startViewport;
114 /** @brief Rectangle describing the animation end viewport. */
115 QGraphicsRectItem *m_endViewport;
117 /** @brief Scene for the titler. */
118 GraphicsSceneRectMove *m_scene;
120 /** @brief Initialises the animation properties (viewport size, etc.). */
121 void initAnimation();
122 QMap<QGraphicsItem*, Transform > m_transformations;
123 TitleDocument m_titledocument;
124 QGraphicsRectItem *m_frameBorder;
125 QGraphicsPixmapItem *m_frameImage;
128 Render *m_render; // TODO Is NOT destroyed in the destructor. Deliberately?
130 QAction *m_buttonRect;
131 QAction *m_buttonText;
132 QAction *m_buttonImage;
133 QAction *m_buttonCursor;
134 QAction *m_buttonSave;
135 QAction *m_buttonLoad;
137 QAction *m_unicodeAction;
142 QAction *m_selectAll;
143 QAction *m_selectText;
144 QAction *m_selectRects;
145 QAction *m_selectImages;
146 QAction *m_unselectAll;
148 /** @brief Dialog for entering Unicode characters in text fields. */
149 UnicodeDialog *m_unicodeDialog;
151 /** @brief Project path for storing title documents. */
152 QString m_projectTitlePath;
154 QString lastDocumentHash;
156 // See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage.
157 QSignalMapper *m_signalMapper;
159 enum ValueType { ValueWidth = 1, ValueHeight = 2, ValueX = 4, ValueY = 8 };
161 /** @brief Sets the font weight value in the combo box. (#909) */
162 void setFontBoxWeight(int weight);
164 /** @brief Stores the choices of font, background and rectangle values. */
167 /** @brief Reads the last stored choices into the dialog. */
170 /** @brief Updates the displayed X/Y coordinates. */
171 void updateCoordinates(QGraphicsItem *i);
173 /** @brief Updates the displayed width/height/zindex values. */
174 void updateDimension(QGraphicsItem *i);
176 /** @brief Updates the displayed rotation/zoom values. Changes values of rotation/zoom GUI elements. */
177 void updateRotZoom(QGraphicsItem *i);
179 /** @brief Updates the item position (position read directly from the GUI). Does not change GUI elements. */
180 void updatePosition(QGraphicsItem *i);
181 /** @brief Updates the item position. Does not change GUI elements. */
182 void updatePosition(QGraphicsItem *i, int x, int y);
184 void textChanged(QGraphicsTextItem *i);
185 void updateAxisButtons(QGraphicsItem *i);
187 void updateTextOriginX();
188 void updateTextOriginY();
190 /** @brief Enables the toolbars suiting to toolType. */
191 void enableToolbars(TITLETOOL toolType);
193 /** @brief Shows the toolbars suiting to toolType. */
194 void showToolbars(TITLETOOL toolType);
196 /** @brief Set up the tools suiting referenceItem */
197 void prepareTools(QGraphicsItem *referenceItem);
199 /** @brief Checks a tool button. */
200 void checkButton(TITLETOOL toolType);
202 void adjustFrameSize();
204 /** @brief Adds a "start" and "end" info text to the animation viewports. */
205 void addAnimInfoText();
207 /** @brief Updates the font for the "start" and "end" info text. */
208 void updateInfoText();
210 /** @brief Removes the "start" and "end" info text from animation viewports. */
211 void deleteAnimInfoText();
215 /** @brief Gets the minimum/maximum Z index of items.
216 * @param maxBound true: use maximum Z index; false: use minimum
217 * @param intersectingOnly if true, consider only the items intersecting
218 * with the currently selected item
220 qreal zIndexBounds(bool maxBound, bool intersectingOnly);
222 void itemRotate(qreal val, int axis);
224 void selectItems(int itemType);
226 /** @brief Appends the shortcut of a QAction to a tooltip text */
227 QString getTooltipWithShortcut(const QString& text, QAction *button);
230 void slotNewText(QGraphicsTextItem *tt);
231 void slotNewRect(QGraphicsRectItem *rect);
232 void slotChangeBackground();
234 /** @brief Sets up the tools (toolbars etc.) according to the selected item. */
235 void selectionChanged();
237 void setupViewports();
238 void zIndexChanged(int);
239 void itemScaled(int);
240 void itemRotateX(qreal);
241 void itemRotateY(qreal);
242 void itemRotateZ(qreal);
243 /** Save a title to a title file */
244 void saveTitle(KUrl url = KUrl());
245 /** Load a title from a title file */
246 void loadTitle(KUrl url = KUrl());
250 /** @brief Switches the origin of the X axis between left and right border.
252 * It's called when the origin of the X coordinate has been changed. The X
253 * origin will either be at the left or at the right side of the frame.
255 * When the origin of the X axis is at the left side, the user can enter the
256 * distance between an element's left border and the left side of the frame.
258 * When on the right, the distance from the right border of the frame to the
259 * right border of the element can be entered. This would result in negative
260 * values as long as the element's right border is at the left of the
261 * frame's right border. As that is usually the case, I additionally invert
264 * Default value is left.
266 * |----l----->|#######|----r--->|
270 * |----------m_frameWidth------>|
273 * Left selected: Value = l
274 * Right selected: Value = r
276 * To calculate between the two coorindate systems:
277 * l = m_frameWidth - w - r
278 * r = m_frameWidth - w - l
280 void slotOriginXClicked();
282 /** @brief Same as slotOriginXClicked(), but for the Y axis; default is top.
283 * @ref slotOriginXClicked */
284 void slotOriginYClicked();
286 /** @brief Updates coordinates of text fields if necessary.
288 * It's called when something changes in the QGraphicsScene. */
292 * Reacts to changes of widht/height/x/y QSpinBox values.
293 * @brief Updates width, height, and position of the selected items.
294 * @param valueType of type ValueType
296 void slotValueChanged(int valueType);
298 void slotZoom(bool up);
299 void slotUpdateZoom(int pos);
300 void slotAdjustZoom();
301 void slotZoomOneToOne();
303 void slotSelectAll();
304 void slotSelectText();
305 void slotSelectRects();
306 void slotSelectImages();
307 void slotSelectNone();
310 /** Called whenever text properties change (font e.g.) */
311 void slotUpdateText();
312 void slotInsertUnicode();
313 void slotInsertUnicodeString(QString);
315 void displayBackgroundFrame();
317 void setCurrentItem(QGraphicsItem *item);
321 void slotSelectTool();
322 void slotImageTool();
324 void slotAnimStart(bool);
325 void slotAnimEnd(bool);
326 void slotKeepAspect(bool keep);
335 void slotResize100();
336 void slotResize200();
338 /** @brief Called when accepted, stores user selections for next time use.
339 * @ref writeChoices */
342 void slotFontText(const QString& s);
344 /** @brief Adds an effect to an element.
345 * @param ix index of the effect in the effects menu
347 * The current implementation allows for one QGraphicsEffect to be added
348 * along with the typewriter effect. This is not clear to the user: the
349 * stack would help, and would permit us to make more QGraphicsEffects
350 * coexist (with different layers of QGraphicsItems). */
351 void slotAddEffect(int ix);
352 void slotEditBlur(int ix);
353 void slotEditShadow();
354 void slotEditTypewriter(int ix);
356 /** @brief Changes the Z index of objects. */
358 void slotZIndexDown();
359 void slotZIndexTop();
360 void slotZIndexBottom();
361 /** Called when the user wants to apply a different template to the title */
362 void templateIndexChanged(int);