]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
Unicode dialog remembering selected unicode, explanations added and extended
[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
30
31 class Transform
32 {
33 public:
34     Transform() {
35         scalex = 1.0;
36         scaley = 1.0;
37         rotate = 0.0;
38     }
39     double scalex, scaley;
40     double rotate;
41 };
42
43 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
44 {
45     Q_OBJECT
46
47 public:
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 projectPath, Render *render, QWidget *parent = 0);
51     virtual ~TitleWidget();
52     QDomDocument xml();
53     void setXml(QDomDocument doc);
54
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.
59      *
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);
62
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"
66      *
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
69      * returned. */
70     static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
71
72     /** \brief returns the size of the rendered pixmap
73     *
74     */
75     const QRect renderedRect();
76
77 protected:
78     virtual void resizeEvent(QResizeEvent * event);
79
80 private:
81     QGraphicsPolygonItem *m_startViewport, *m_endViewport;
82     GraphicsSceneRectMove *m_scene;
83     void initViewports();
84     QMap<QGraphicsItem*, Transform > m_transformations;
85     TitleDocument m_titledocument;
86     QGraphicsRectItem *m_frameBorder;
87     QGraphicsPixmapItem *m_frameImage;
88     int m_frameWidth;
89     int m_frameHeight;
90     Render *m_render;
91     int m_count;
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         /** \brief Stores the last used unicode */
101         QString m_lastUnicodeNumber;
102     /** project path for storing title clips */
103     QString m_projectPath;
104     /** \brief Store the current choices of font, background and rect values */
105     void writeChoices();
106     /** \brief Read the last stored choices into the dialog */
107     void readChoices();
108     /** \brief Update the displayed X/Y coordinates */
109     void updateCoordinates(QGraphicsItem *i);
110     void updateDimension(QGraphicsItem *i);
111     /** \brief Update the item's position */
112     void updatePosition(QGraphicsItem *i);
113
114     void textChanged(QGraphicsTextItem *i);
115     void updateAxisButtons(QGraphicsItem *i);
116
117     void updateTextOriginX();
118     void updateTextOriginY();
119
120 public slots:
121     void slotNewText(QGraphicsTextItem *tt);
122     void slotNewRect(QGraphicsRectItem *rect);
123     void slotChangeBackground();
124     void selectionChanged();
125     void rectChanged();
126     void setupViewports();
127     void zIndexChanged(int);
128     void itemScaled(int);
129     void itemRotate(int);
130     void itemHCenter();
131     void itemVCenter();
132     void saveTitle(KUrl url = KUrl());
133     void loadTitle();
134     QImage renderedPixmap();
135
136 private slots:
137     void slotAdjustSelectedItem();
138
139     /**
140      * \brief Switches the origin of the x axis between left and right
141      * border of the frame (offset from left/right frame border)
142      * \param originLeft Take left border?
143      *
144      * Called when the origin of the x coorinate has been changed. The
145      * x origin will either be at the left or at the right side of the frame.
146      *
147      * When the origin of the x axis is at the left side, the user can
148      * enter the distance between an element's left border and the left
149      * side of the frame.
150      *
151      * When on the right, the distance from the right border of the
152      * frame to the right border of the element can be entered. This
153      * would result in negative values as long as the element's right
154      * border is at the left of the frame's right border. As that is
155      * usually the case, I additionally invert the x axis.
156      *
157      * Default value is left.
158      *
159      * |----l----->|#######|----r--->|
160      * |           |---w-->|         |
161      * |           |#######|         |
162      * |                             |
163      * |----------m_frameWidth------>|
164      * |                             |
165      *
166      * Left selected: Value = l
167      * Right selected: Value = r
168      *
169      * To calculate between the two coorindate systems:
170      * l = m_frameWidth - w - r
171      * r = m_frameWidth - w - l
172      *
173      */
174     void slotOriginXClicked();
175     /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
176      *  \param originTop Take top border? */
177     void slotOriginYClicked();
178
179     /** \brief Update coorinates of text fields if necessary and text has changed */
180     void slotChanged();
181
182     void slotZoom(bool up);
183     void slotUpdateZoom(int pos);
184     void slotAdjustZoom();
185     void slotZoomOneToOne();
186
187     void slotUpdateText();
188     void slotInsertUnicode();
189     void slotInsertUnicodeString(QString);
190         /** \brief Called when unicode dialog closed, updates the last selected unicode number */
191         void slotUnicodeNumber(QString);
192
193     void displayBackgroundFrame();
194
195     void setCurrentItem(QGraphicsItem *item);
196
197     void slotTextTool();
198     void slotRectTool();
199     void slotSelectTool();
200     void slotImageTool();
201         
202
203     /** \brief Called when accepted, stores the user selections for next time use */
204     void slotAccepted();
205 };
206
207
208 #endif