]> git.sesse.net Git - kdenlive/blob - src/titlewidget.h
Fixed 9/11 ... eh, #911. X/Y now also displaying positive values.~
[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
27 #include <QMap>
28
29
30 class Transform
31 {
32 public:
33     Transform() {
34         scalex = 1.0;
35         scaley = 1.0;
36         rotate = 0.0;
37     }
38     double scalex, scaley;
39     double rotate;
40 };
41
42 class TitleWidget : public QDialog , public Ui::TitleWidget_UI
43 {
44     Q_OBJECT
45
46 public:
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();
51     QDomDocument xml();
52     void setXml(QDomDocument doc);
53
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.
58      *
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);
61
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"
65      *
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
68      * returned. */
69     static QString getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName);
70
71 protected:
72     virtual void resizeEvent(QResizeEvent * event);
73
74 private:
75     QGraphicsPolygonItem *m_startViewport, *m_endViewport;
76     GraphicsSceneRectMove *m_scene;
77     void initViewports();
78     QMap<QGraphicsItem*, Transform > m_transformations;
79     TitleDocument m_titledocument;
80     QGraphicsRectItem *m_frameBorder;
81     QGraphicsPixmapItem *m_frameImage;
82     int m_frameWidth;
83     int m_frameHeight;
84     Render *m_render;
85     int m_count;
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 */
95     void writeChoices();
96     /** \brief Read the last stored choices into the dialog */
97     void readChoices();
98         /** \brief Update the displayed X/Y coordinates */
99         void updateCoordinates(QGraphicsItem *i);
100         /** \brief Update the item's position */
101         void updatePosition(QGraphicsItem *i);
102
103 public slots:
104     void slotNewText(QGraphicsTextItem *tt);
105     void slotNewRect(QGraphicsRectItem *rect);
106     void slotChangeBackground();
107     void selectionChanged();
108     void rectChanged();
109     void setupViewports();
110     void zIndexChanged(int);
111     void itemScaled(int);
112     void itemRotate(int);
113     void itemHCenter();
114     void itemVCenter();
115     void saveTitle(KUrl url = KUrl());
116     void loadTitle();
117     QImage renderedPixmap();
118
119 private slots:
120     void slotAdjustSelectedItem();
121         
122         /** 
123          * \brief Switches the origin of the x axis between left and right 
124          * border of the frame (offset from left/right frame border)
125          * \param originLeft Take left border?
126          * 
127          * Called when the origin of the x coorinate has been changed. The 
128          * x origin will either be at the left or at the right side of the frame.
129          * 
130          * When the origin of the x axis is at the left side, the user can 
131          * enter the distance between an element's left border and the left
132          * side of the frame.
133          * 
134          * When on the right, the distance from the right border of the 
135          * frame to the right border of the element can be entered. This 
136          * would result in negative values as long as the element's right 
137          * border is at the left of the frame's right border. As that is
138          * usually the case, I additionally invert the x axis.
139          * 
140          * Default value is left.
141          * 
142          * |----l----->|#######|----r--->|              
143          * |           |---w-->|         |
144          * |           |#######|         |
145          * |                             |
146          * |----------m_frameWidth------>|
147          * |                             |
148          * 
149          * Left selected: Value = l
150          * Right selected: Value = r
151          * 
152          * To calculate between the two coorindate systems:
153          * l = m_frameWidth - w - r
154          * r = m_frameWidth - w - l
155          * 
156          */
157         void slotOriginXClicked();
158         /** \brief Same as slotOriginYChanged, but for the Y axis; default is top. 
159          *  \param originTop Take top border? */
160         void slotOriginYClicked();
161         
162         /** \brief Update coorinates of text fields if necessary and text has changed */
163         void slotChanged();
164         
165     void slotZoom(bool up);
166     void slotUpdateZoom(int pos);
167     void slotAdjustZoom();
168     void slotZoomOneToOne();
169         
170     void slotUpdateText();
171         
172     void displayBackgroundFrame();
173         
174     void setCurrentItem(QGraphicsItem *item);
175         
176     void slotTextTool();
177     void slotRectTool();
178     void slotSelectTool();
179     void slotImageTool();
180         
181     /** \brief Called when accepted, stores the user selections for next time use */
182     void slotAccepted();
183 };
184
185
186 #endif