]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
53d2dc6dd3314314332771f0b423c5b1eec64f5b
[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 protected:
73     virtual void resizeEvent(QResizeEvent * event);
74
75 private:
76     QGraphicsPolygonItem *m_startViewport, *m_endViewport;
77     GraphicsSceneRectMove *m_scene;
78     void initViewports();
79     QMap<QGraphicsItem*, Transform > m_transformations;
80     TitleDocument m_titledocument;
81     QGraphicsRectItem *m_frameBorder;
82     QGraphicsPixmapItem *m_frameImage;
83     int m_frameWidth;
84     int m_frameHeight;
85     Render *m_render;
86     int m_count;
87     QAction *m_buttonRect;
88     QAction *m_buttonText;
89     QAction *m_buttonImage;
90     QAction *m_buttonCursor;
91     QAction *m_buttonSave;
92     QAction *m_buttonLoad;
93     /** \brief Dialog for entering unicode in text fields */
94     UnicodeDialog *m_unicodeDialog;
95     /** project path for storing title clips */
96     QString m_projectPath;
97     /** \brief Store the current choices of font, background and rect values */
98     void writeChoices();
99     /** \brief Read the last stored choices into the dialog */
100     void readChoices();
101     /** \brief Update the displayed X/Y coordinates */
102     void updateCoordinates(QGraphicsItem *i);
103     void updateDimension(QGraphicsItem *i);
104     /** \brief Update the item's position */
105     void updatePosition(QGraphicsItem *i);
106
107     void textChanged(QGraphicsTextItem *i);
108     void updateAxisButtons(QGraphicsItem *i);
109
110     void updateTextOriginX();
111     void updateTextOriginY();
112
113 public slots:
114     void slotNewText(QGraphicsTextItem *tt);
115     void slotNewRect(QGraphicsRectItem *rect);
116     void slotChangeBackground();
117     void selectionChanged();
118     void rectChanged();
119     void setupViewports();
120     void zIndexChanged(int);
121     void itemScaled(int);
122     void itemRotate(int);
123     void itemHCenter();
124     void itemVCenter();
125     void saveTitle(KUrl url = KUrl());
126     void loadTitle();
127     QImage renderedPixmap();
128
129 private slots:
130     void slotAdjustSelectedItem();
131
132     /**
133      * \brief Switches the origin of the x axis between left and right
134      * border of the frame (offset from left/right frame border)
135      * \param originLeft Take left border?
136      *
137      * Called when the origin of the x coorinate has been changed. The
138      * x origin will either be at the left or at the right side of the frame.
139      *
140      * When the origin of the x axis is at the left side, the user can
141      * enter the distance between an element's left border and the left
142      * side of the frame.
143      *
144      * When on the right, the distance from the right border of the
145      * frame to the right border of the element can be entered. This
146      * would result in negative values as long as the element's right
147      * border is at the left of the frame's right border. As that is
148      * usually the case, I additionally invert the x axis.
149      *
150      * Default value is left.
151      *
152      * |----l----->|#######|----r--->|
153      * |           |---w-->|         |
154      * |           |#######|         |
155      * |                             |
156      * |----------m_frameWidth------>|
157      * |                             |
158      *
159      * Left selected: Value = l
160      * Right selected: Value = r
161      *
162      * To calculate between the two coorindate systems:
163      * l = m_frameWidth - w - r
164      * r = m_frameWidth - w - l
165      *
166      */
167     void slotOriginXClicked();
168     /** \brief Same as slotOriginYChanged, but for the Y axis; default is top.
169      *  \param originTop Take top border? */
170     void slotOriginYClicked();
171
172     /** \brief Update coorinates of text fields if necessary and text has changed */
173     void slotChanged();
174
175     void slotZoom(bool up);
176     void slotUpdateZoom(int pos);
177     void slotAdjustZoom();
178     void slotZoomOneToOne();
179
180     void slotUpdateText();
181     void slotInsertUnicode();
182     void slotInsertUnicodeString(QString);
183
184     void displayBackgroundFrame();
185
186     void setCurrentItem(QGraphicsItem *item);
187
188     void slotTextTool();
189     void slotRectTool();
190     void slotSelectTool();
191     void slotImageTool();
192
193     /** \brief Called when accepted, stores the user selections for next time use */
194     void slotAccepted();
195 };
196
197
198 #endif