]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
reindent
[kdenlive] / src / titlewidget.h
1 /***************************************************************************
2                           titlewidget.h  -  description
3                              -------------------
4     begin                : Feb 28 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef TITLEWIDGET_H
19 #define TITLEWIDGET_H
20
21
22 #include "ui_titlewidget_ui.h"
23 #include "titledocument.h"
24 #include "renderer.h"
25 #include "graphicsscenerectmove.h"
26 #include "unicodedialog.h"
27
28 #include <QMap>
29 #include <QSignalMapper>
30
31
32 class Transform
33 {
34 public:
35     Transform() {
36         scalex = 1.0;
37         scaley = 1.0;
38         rotate = 0.0;
39     }
40     double scalex, scaley;
41     double rotate;
42 };
43
44 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
45 {
46     Q_OBJECT
47
48 public:
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();
53     QDomDocument xml();
54     void setXml(QDomDocument doc);
55
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.
60      *
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);
63
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"
67      *
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
70      * returned. */
71     static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
72
73     /** \brief returns the size of the rendered pixmap
74     *
75     */
76     const QRect renderedRect();
77
78 protected:
79     virtual void resizeEvent(QResizeEvent * event);
80
81 private:
82     QGraphicsPolygonItem *m_startViewport, *m_endViewport;
83     GraphicsSceneRectMove *m_scene;
84     void initViewports();
85     QMap<QGraphicsItem*, Transform > m_transformations;
86     TitleDocument m_titledocument;
87     QGraphicsRectItem *m_frameBorder;
88     QGraphicsPixmapItem *m_frameImage;
89     int m_frameWidth;
90     int m_frameHeight;
91     Render *m_render;
92     int m_count;
93     QAction *m_buttonRect;
94     QAction *m_buttonText;
95     QAction *m_buttonImage;
96     QAction *m_buttonCursor;
97     QAction *m_buttonSave;
98     QAction *m_buttonLoad;
99
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;
105
106     /** See http://doc.trolltech.com/4.5/signalsandslots.html#advanced-signals-and-slots-usage */
107     QSignalMapper *m_signalMapper;
108
109     enum ValueType { ValueWidth = 0, ValueHeight = 1 };
110
111     /** \brief Store the current choices of font, background and rect values */
112     void writeChoices();
113     /** \brief Read the last stored choices into the dialog */
114     void readChoices();
115     /** \brief Update the displayed X/Y coordinate values */
116     void updateCoordinates(QGraphicsItem *i);
117     /** \brief Update displayed width/height values */
118     void updateDimension(QGraphicsItem *i);
119     /** \brief Update displayed rotation/zoom values */
120     void updateRotZoom(QGraphicsItem *i);
121
122     /** \brief Update the item's position */
123     void updatePosition(QGraphicsItem *i);
124
125     void textChanged(QGraphicsTextItem *i);
126     void updateAxisButtons(QGraphicsItem *i);
127
128     void updateTextOriginX();
129     void updateTextOriginY();
130
131     /** \brief Enables the toolbars suiting to toolType */
132     void enableToolbars(TITLETOOL toolType);
133     /** \brief Shows the toolbars suiting to toolType */
134     void showToolbars(TITLETOOL toolType);
135     /** \brief Check a tool button. */
136     void checkButton(TITLETOOL toolType);
137
138 public slots:
139     void slotNewText(QGraphicsTextItem *tt);
140     void slotNewRect(QGraphicsRectItem *rect);
141     void slotChangeBackground();
142     void selectionChanged();
143     void rectChanged();
144     void setupViewports();
145     void zIndexChanged(int);
146     void itemScaled(int);
147     void itemRotate(int);
148     void itemHCenter();
149     void itemVCenter();
150     void saveTitle(KUrl url = KUrl());
151     void loadTitle();
152     QImage renderedPixmap();
153
154 private slots:
155     void slotAdjustSelectedItem();
156
157     /**
158      * \brief Switches the origin of the x axis between left and right
159      * border of the frame (offset from left/right frame border)
160      * \param originLeft Take left border?
161      *
162      * Called when the origin of the x coorinate has been changed. The
163      * x origin will either be at the left or at the right side of the frame.
164      *
165      * When the origin of the x axis is at the left side, the user can
166      * enter the distance between an element's left border and the left
167      * side of the frame.
168      *
169      * When on the right, the distance from the right border of the
170      * frame to the right border of the element can be entered. This
171      * would result in negative values as long as the element's right
172      * border is at the left of the frame's right border. As that is
173      * usually the case, I additionally invert the x axis.
174      *
175      * Default value is left.
176      *
177      * |----l----->|#######|----r--->|
178      * |           |---w-->|         |
179      * |           |#######|         |
180      * |                             |
181      * |----------m_frameWidth------>|
182      * |                             |
183      *
184      * Left selected: Value = l
185      * Right selected: Value = r
186      *
187      * To calculate between the two coorindate systems:
188      * l = m_frameWidth - w - r
189      * r = m_frameWidth - w - l
190      *
191      */
192     void slotOriginXClicked();
193     /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
194      *  \param originTop Take top border? */
195     void slotOriginYClicked();
196
197     /** \brief Update coorinates of text fields if necessary and text has changed */
198     void slotChanged();
199
200     /** \param valueType Of type ValueType */
201     void slotValueChanged(int valueType);
202
203     void slotZoom(bool up);
204     void slotUpdateZoom(int pos);
205     void slotAdjustZoom();
206     void slotZoomOneToOne();
207
208     void slotUpdateText();
209     void slotInsertUnicode();
210     void slotInsertUnicodeString(QString);
211
212     void displayBackgroundFrame();
213
214     void setCurrentItem(QGraphicsItem *item);
215
216     void slotTextTool();
217     void slotRectTool();
218     void slotSelectTool();
219     void slotImageTool();
220
221
222     /** \brief Called when accepted, stores the user selections for next time use */
223     void slotAccepted();
224 };
225
226
227 #endif