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"
29 #include <QSignalMapper>
40 double scalex, scaley;
44 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
49 /** \brief Constructor
50 * \param projectPath Path to use when user requests loading or saving of titles as .kdenlivetitle documents */
51 TitleWidget(KUrl url, QString projectTitlePath, Render *render, QWidget *parent = 0);
52 virtual ~TitleWidget();
54 void setXml(QDomDocument doc);
56 /** \brief Find first available filename of the form titleXXX.png in projectUrl + "/titles/" directory
57 * \param projectUrl Url to directory of project.
58 * \returns A list, with the name in the form of "/path/to/titles/titleXXX" as the first element, the extension
59 * ".png" as the second element.
61 * The path "/titles/" is appended to projectUrl to locate the actual directory that contains the title pngs. */
62 static QStringList getFreeTitleInfo(const KUrl &projectUrl, bool isClone = false);
64 /** \brief Build a filename from a projectUrl and a titleName
65 * \param projectUrl Url to directory of project.
66 * \param titleName Name of title, on the form "titleXXX"
68 * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
69 * get the filename. It is not checked that the title png actually exists, only the name is build and
71 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
73 /** \brief returns the size of the rendered pixmap
76 const QRect renderedRect();
79 virtual void resizeEvent(QResizeEvent * event);
82 QGraphicsPolygonItem *m_startViewport, *m_endViewport;
83 GraphicsSceneRectMove *m_scene;
85 QMap<QGraphicsItem*, Transform > m_transformations;
86 TitleDocument m_titledocument;
87 QGraphicsRectItem *m_frameBorder;
88 QGraphicsPixmapItem *m_frameImage;
93 QAction *m_buttonRect;
94 QAction *m_buttonText;
95 QAction *m_buttonImage;
96 QAction *m_buttonCursor;
97 QAction *m_buttonSave;
98 QAction *m_buttonLoad;
100 QAction *m_unicodeAction;
101 /** \brief Dialog for entering unicode in text fields */
102 UnicodeDialog *m_unicodeDialog;
103 /** project path for storing title clips */
104 QString m_projectTitlePath;
106 /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
107 QSignalMapper *m_signalMapper;
109 enum ValueType { ValueWidth = 0, ValueHeight = 1 };
111 /** \brief Sets the font weight value in the combo box. (#909) */
112 void setFontBoxWeight(int weight);
114 /** \brief Store the current choices of font, background and rect values */
116 /** \brief Read the last stored choices into the dialog */
118 /** \brief Update the displayed X/Y coordinate values */
119 void updateCoordinates(QGraphicsItem *i);
120 /** \brief Update displayed width/height values */
121 void updateDimension(QGraphicsItem *i);
122 /** \brief Update displayed rotation/zoom values */
123 void updateRotZoom(QGraphicsItem *i);
125 /** \brief Update the item's position */
126 void updatePosition(QGraphicsItem *i);
128 void textChanged(QGraphicsTextItem *i);
129 void updateAxisButtons(QGraphicsItem *i);
131 void updateTextOriginX();
132 void updateTextOriginY();
134 /** \brief Enables the toolbars suiting to toolType */
135 void enableToolbars(TITLETOOL toolType);
136 /** \brief Shows the toolbars suiting to toolType */
137 void showToolbars(TITLETOOL toolType);
138 /** \brief Check a tool button. */
139 void checkButton(TITLETOOL toolType);
142 void slotNewText(QGraphicsTextItem *tt);
143 void slotNewRect(QGraphicsRectItem *rect);
144 void slotChangeBackground();
145 void selectionChanged();
147 void setupViewports();
148 void zIndexChanged(int);
149 void itemScaled(int);
150 void itemRotate(int);
153 void saveTitle(KUrl url = KUrl());
155 QImage renderedPixmap();
158 void slotAdjustSelectedItem();
161 * \brief Switches the origin of the x axis between left and right
162 * border of the frame (offset from left/right frame border)
163 * \param originLeft Take left border?
165 * Called when the origin of the x coorinate has been changed. The
166 * x origin will either be at the left or at the right side of the frame.
168 * When the origin of the x axis is at the left side, the user can
169 * enter the distance between an element's left border and the left
172 * When on the right, the distance from the right border of the
173 * frame to the right border of the element can be entered. This
174 * would result in negative values as long as the element's right
175 * border is at the left of the frame's right border. As that is
176 * usually the case, I additionally invert the x axis.
178 * Default value is left.
180 * |----l----->|#######|----r--->|
184 * |----------m_frameWidth------>|
187 * Left selected: Value = l
188 * Right selected: Value = r
190 * To calculate between the two coorindate systems:
191 * l = m_frameWidth - w - r
192 * r = m_frameWidth - w - l
195 void slotOriginXClicked();
196 /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
197 * \param originTop Take top border? */
198 void slotOriginYClicked();
200 /** \brief Update coorinates of text fields if necessary and text has changed */
203 /** \param valueType Of type ValueType */
204 void slotValueChanged(int valueType);
206 void slotZoom(bool up);
207 void slotUpdateZoom(int pos);
208 void slotAdjustZoom();
209 void slotZoomOneToOne();
211 void slotUpdateText();
212 void slotInsertUnicode();
213 void slotInsertUnicodeString(QString);
215 void displayBackgroundFrame();
217 void setCurrentItem(QGraphicsItem *item);
221 void slotSelectTool();
222 void slotImageTool();
225 /** \brief Called when accepted, stores the user selections for next time use */