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"
38 double scalex, scaley;
42 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
47 /** \brief Constructor
48 * \param projectPath Path to use when user requests loading or saving of titles as .kdenlivetitle documents */
49 TitleWidget(KUrl url, QString projectPath, Render *render, QWidget *parent = 0);
50 virtual ~TitleWidget();
52 void setXml(QDomDocument doc);
54 /** \brief Find first available filename of the form titleXXX.png in projectUrl + "/titles/" directory
55 * \param projectUrl Url to directory of project.
56 * \returns A list, with the name in the form of "/path/to/titles/titleXXX" as the first element, the extension
57 * ".png" as the second element.
59 * The path "/titles/" is appended to projectUrl to locate the actual directory that contains the title pngs. */
60 static QStringList getFreeTitleInfo(const KUrl &projectUrl);
62 /** \brief Build a filename from a projectUrl and a titleName
63 * \param projectUrl Url to directory of project.
64 * \param titleName Name of title, on the form "titleXXX"
66 * The path "/titles/" is appended to projectUrl to build the directoryname, then .pgn is appended to
67 * get the filename. It is not checked that the title png actually exists, only the name is build and
69 static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
72 virtual void resizeEvent(QResizeEvent * event);
75 QGraphicsPolygonItem *m_startViewport, *m_endViewport;
76 GraphicsSceneRectMove *m_scene;
78 QMap<QGraphicsItem*, Transform > m_transformations;
79 TitleDocument m_titledocument;
80 QGraphicsRectItem *m_frameBorder;
81 QGraphicsPixmapItem *m_frameImage;
86 QAction *m_buttonRect;
87 QAction *m_buttonText;
88 QAction *m_buttonImage;
89 QAction *m_buttonCursor;
90 QAction *m_buttonSave;
91 QAction *m_buttonLoad;
92 /** project path for storing title clips */
93 QString m_projectPath;
94 /** \brief Store the current choices of font, background and rect values */
96 /** \brief Read the last stored choices into the dialog */
98 /** \brief Update the displayed X/Y coordinates */
99 void updateCoordinates(QGraphicsItem *i);
100 void updateDimension(QGraphicsItem *i);
101 /** \brief Update the item's position */
102 void updatePosition(QGraphicsItem *i);
104 void textChanged(QGraphicsTextItem *i);
105 void updateAxisButtons(QGraphicsItem *i);
107 void updateTextOriginX();
108 void updateTextOriginY();
111 void slotNewText(QGraphicsTextItem *tt);
112 void slotNewRect(QGraphicsRectItem *rect);
113 void slotChangeBackground();
114 void selectionChanged();
116 void setupViewports();
117 void zIndexChanged(int);
118 void itemScaled(int);
119 void itemRotate(int);
122 void saveTitle(KUrl url = KUrl());
124 QImage renderedPixmap();
127 void slotAdjustSelectedItem();
130 * \brief Switches the origin of the x axis between left and right
131 * border of the frame (offset from left/right frame border)
132 * \param originLeft Take left border?
134 * Called when the origin of the x coorinate has been changed. The
135 * x origin will either be at the left or at the right side of the frame.
137 * When the origin of the x axis is at the left side, the user can
138 * enter the distance between an element's left border and the left
141 * When on the right, the distance from the right border of the
142 * frame to the right border of the element can be entered. This
143 * would result in negative values as long as the element's right
144 * border is at the left of the frame's right border. As that is
145 * usually the case, I additionally invert the x axis.
147 * Default value is left.
149 * |----l----->|#######|----r--->|
153 * |----------m_frameWidth------>|
156 * Left selected: Value = l
157 * Right selected: Value = r
159 * To calculate between the two coorindate systems:
160 * l = m_frameWidth - w - r
161 * r = m_frameWidth - w - l
164 void slotOriginXClicked();
165 /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
166 * \param originTop Take top border? */
167 void slotOriginYClicked();
169 /** \brief Update coorinates of text fields if necessary and text has changed */
172 void slotZoom(bool up);
173 void slotUpdateZoom(int pos);
174 void slotAdjustZoom();
175 void slotZoomOneToOne();
177 void slotUpdateText();
179 void displayBackgroundFrame();
181 void setCurrentItem(QGraphicsItem *item);
185 void slotSelectTool();
186 void slotImageTool();
188 /** \brief Called when accepted, stores the user selections for next time use */