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"
39 double scalex, scaley;
43 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
48 /** \brief Constructor
49 * \param projectPath Path to use when user requests loading or saving of titles as .kdenlivetitle documents */
50 TitleWidget(KUrl url, QString projectTitlePath, Render *render, QWidget *parent = 0);
51 virtual ~TitleWidget();
53 void setXml(QDomDocument doc);
55 /** \brief Find first available filename of the form titleXXX.png in projectUrl + "/titles/" directory
56 * \param projectUrl Url to directory of project.
57 * \returns A list, with the name in the form of "/path/to/titles/titleXXX" as the first element, the extension
58 * ".png" as the second element.
60 * The path "/titles/" is appended to projectUrl to locate the actual directory that contains the title pngs. */
61 static QStringList getFreeTitleInfo(const KUrl &projectUrl, bool isClone = false);
63 /** \brief Build a filename from a projectUrl and a titleName
64 * \param projectUrl Url to directory of project.
65 * \param titleName Name of title, on the form "titleXXX"
67 * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
68 * get the filename. It is not checked that the title png actually exists, only the name is build and
70 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
72 /** \brief returns the size of the rendered pixmap
75 const QRect renderedRect();
78 virtual void resizeEvent(QResizeEvent * event);
81 QGraphicsPolygonItem *m_startViewport, *m_endViewport;
82 GraphicsSceneRectMove *m_scene;
84 QMap<QGraphicsItem*, Transform > m_transformations;
85 TitleDocument m_titledocument;
86 QGraphicsRectItem *m_frameBorder;
87 QGraphicsPixmapItem *m_frameImage;
92 QAction *m_buttonRect;
93 QAction *m_buttonText;
94 QAction *m_buttonImage;
95 QAction *m_buttonCursor;
96 QAction *m_buttonSave;
97 QAction *m_buttonLoad;
98 /** \brief Dialog for entering unicode in text fields */
99 UnicodeDialog *m_unicodeDialog;
100 /** project path for storing title clips */
101 QString m_projectTitlePath;
103 enum ValueType { ValueWidth, ValueHeight };
105 /** \brief Store the current choices of font, background and rect values */
107 /** \brief Read the last stored choices into the dialog */
109 /** \brief Update the displayed X/Y coordinate values */
110 void updateCoordinates(QGraphicsItem *i);
111 /** \brief Update displayed width/height values */
112 void updateDimension(QGraphicsItem *i);
113 /** \brief Update displayed rotation/zoom values */
114 void updateRotZoom(QGraphicsItem *i);
116 /** \brief Update the item's position */
117 void updatePosition(QGraphicsItem *i);
119 void textChanged(QGraphicsTextItem *i);
120 void updateAxisButtons(QGraphicsItem *i);
122 void updateTextOriginX();
123 void updateTextOriginY();
125 /** \brief Enables the toolbars suiting to toolType */
126 void enableToolbars(TITLETOOL toolType);
127 /** \brief Shows the toolbars suiting to toolType */
128 void showToolbars(TITLETOOL toolType);
131 void slotNewText(QGraphicsTextItem *tt);
132 void slotNewRect(QGraphicsRectItem *rect);
133 void slotChangeBackground();
134 void selectionChanged();
136 void setupViewports();
137 void zIndexChanged(int);
138 void itemScaled(int);
139 void itemRotate(int);
142 void saveTitle(KUrl url = KUrl());
144 QImage renderedPixmap();
147 void slotAdjustSelectedItem();
150 * \brief Switches the origin of the x axis between left and right
151 * border of the frame (offset from left/right frame border)
152 * \param originLeft Take left border?
154 * Called when the origin of the x coorinate has been changed. The
155 * x origin will either be at the left or at the right side of the frame.
157 * When the origin of the x axis is at the left side, the user can
158 * enter the distance between an element's left border and the left
161 * When on the right, the distance from the right border of the
162 * frame to the right border of the element can be entered. This
163 * would result in negative values as long as the element's right
164 * border is at the left of the frame's right border. As that is
165 * usually the case, I additionally invert the x axis.
167 * Default value is left.
169 * |----l----->|#######|----r--->|
173 * |----------m_frameWidth------>|
176 * Left selected: Value = l
177 * Right selected: Value = r
179 * To calculate between the two coorindate systems:
180 * l = m_frameWidth - w - r
181 * r = m_frameWidth - w - l
184 void slotOriginXClicked();
185 /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
186 * \param originTop Take top border? */
187 void slotOriginYClicked();
189 /** \brief Update coorinates of text fields if necessary and text has changed */
192 void slotValueChanged(ValueType type, int val);
194 void slotZoom(bool up);
195 void slotUpdateZoom(int pos);
196 void slotAdjustZoom();
197 void slotZoomOneToOne();
199 void slotUpdateText();
200 void slotInsertUnicode();
201 void slotInsertUnicodeString(QString);
203 void displayBackgroundFrame();
205 void setCurrentItem(QGraphicsItem *item);
209 void slotSelectTool();
210 void slotImageTool();
213 /** \brief Called when accepted, stores the user selections for next time use */