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>
41 double scalex, scaley;
45 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
50 /** \brief Constructor
51 * \param projectPath Path to use when user requests loading or saving of titles as .kdenlivetitle documents */
52 TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent = 0);
53 virtual ~TitleWidget();
55 void setXml(QDomDocument doc);
57 /** \brief Find first available filename of the form titleXXX.png in projectUrl + "/titles/" directory
58 * \param projectUrl Url to directory of project.
59 * \returns A list, with the name in the form of "/path/to/titles/titleXXX" as the first element, the extension
60 * ".png" as the second element.
62 * The path "/titles/" is appended to projectUrl to locate the actual directory that contains the title pngs. */
63 static QStringList getFreeTitleInfo(const KUrl &projectUrl, bool isClone = false);
65 /** \brief Build a filename from a projectUrl and a titleName
66 * \param projectUrl Url to directory of project.
67 * \param titleName Name of title, on the form "titleXXX"
69 * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
70 * get the filename. It is not checked that the title png actually exists, only the name is build and
72 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
74 /** \brief Get clip duration. */
78 virtual void resizeEvent(QResizeEvent * event);
81 /** \brief Rectangle describing animation start viewport */
82 QGraphicsRectItem *m_startViewport;
83 /** \brief Rectangle describing animation end viewport */
84 QGraphicsRectItem *m_endViewport;
85 /** \brief Scene for the titler */
86 GraphicsSceneRectMove *m_scene;
87 /** \brief Initialize the animation properties (viewport size,...) */
89 QMap<QGraphicsItem*, Transform > m_transformations;
90 TitleDocument m_titledocument;
91 QGraphicsRectItem *m_frameBorder;
92 QGraphicsPixmapItem *m_frameImage;
97 QAction *m_buttonRect;
98 QAction *m_buttonText;
99 QAction *m_buttonImage;
100 QAction *m_buttonCursor;
101 QAction *m_buttonSave;
102 QAction *m_buttonLoad;
104 QAction *m_unicodeAction;
106 /** \brief Dialog for entering unicode in text fields */
107 UnicodeDialog *m_unicodeDialog;
108 /** project path for storing title clips */
109 QString m_projectTitlePath;
112 /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
113 QSignalMapper *m_signalMapper;
115 enum ValueType { ValueWidth = 0, ValueHeight = 1 };
117 /** \brief Sets the font weight value in the combo box. (#909) */
118 void setFontBoxWeight(int weight);
120 /** \brief Store the current choices of font, background and rect values */
122 /** \brief Read the last stored choices into the dialog */
124 /** \brief Update the displayed X/Y coordinate values */
125 void updateCoordinates(QGraphicsItem *i);
126 /** \brief Update displayed width/height values */
127 void updateDimension(QGraphicsItem *i);
128 /** \brief Update displayed rotation/zoom values */
129 void updateRotZoom(QGraphicsItem *i);
131 /** \brief Update the item's position */
132 void updatePosition(QGraphicsItem *i);
134 void textChanged(QGraphicsTextItem *i);
135 void updateAxisButtons(QGraphicsItem *i);
137 void updateTextOriginX();
138 void updateTextOriginY();
140 /** \brief Enables the toolbars suiting to toolType */
141 void enableToolbars(TITLETOOL toolType);
142 /** \brief Shows the toolbars suiting to toolType */
143 void showToolbars(TITLETOOL toolType);
144 /** \brief Check a tool button. */
145 void checkButton(TITLETOOL toolType);
147 void adjustFrameSize();
148 /** \brief Add a "start" and "end" info text to the animation viewports */
149 void addAnimInfoText();
150 /** \brief Update font for the "start" and "end" info text */
151 void updateInfoText();
152 /** \brief Remove the "start" and "end" info text from animation viewports */
153 void deleteAnimInfoText();
156 void slotNewText(QGraphicsTextItem *tt);
157 void slotNewRect(QGraphicsRectItem *rect);
158 void slotChangeBackground();
159 void selectionChanged();
161 void setupViewports();
162 void zIndexChanged(int);
163 void itemScaled(int);
164 void itemRotate(int);
165 void saveTitle(KUrl url = KUrl());
166 void loadTitle(KUrl url = KUrl());
169 void slotAdjustSelectedItem();
172 * \brief Switches the origin of the x axis between left and right
173 * border of the frame (offset from left/right frame border)
174 * \param originLeft Take left border?
176 * Called when the origin of the x coorinate has been changed. The
177 * x origin will either be at the left or at the right side of the frame.
179 * When the origin of the x axis is at the left side, the user can
180 * enter the distance between an element's left border and the left
183 * When on the right, the distance from the right border of the
184 * frame to the right border of the element can be entered. This
185 * would result in negative values as long as the element's right
186 * border is at the left of the frame's right border. As that is
187 * usually the case, I additionally invert the x axis.
189 * Default value is left.
191 * |----l----->|#######|----r--->|
195 * |----------m_frameWidth------>|
198 * Left selected: Value = l
199 * Right selected: Value = r
201 * To calculate between the two coorindate systems:
202 * l = m_frameWidth - w - r
203 * r = m_frameWidth - w - l
206 void slotOriginXClicked();
207 /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
208 * \param originTop Take top border? */
209 void slotOriginYClicked();
211 /** \brief Update coorinates of text fields if necessary and text has changed */
214 /** \param valueType Of type ValueType */
215 void slotValueChanged(int valueType);
217 void slotZoom(bool up);
218 void slotUpdateZoom(int pos);
219 void slotAdjustZoom();
220 void slotZoomOneToOne();
222 void slotUpdateText();
223 void slotInsertUnicode();
224 void slotInsertUnicodeString(QString);
226 void displayBackgroundFrame();
228 void setCurrentItem(QGraphicsItem *item);
232 void slotSelectTool();
233 void slotImageTool();
235 void slotAnimStart(bool);
236 void slotAnimEnd(bool);
237 void slotKeepAspect(bool keep);
246 void slotResize100();
247 void slotResize200();
249 /** \brief Called when accepted, stores the user selections for next time use */