]> git.sesse.net Git - kdenlive/blob - src/geometrywidget.h
Fix color of warning message in render widget
[kdenlive] / src / geometrywidget.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #ifndef GEOMETRYWIDGET_H
22 #define GEOMETRYWIDGET_H
23
24 #include "ui_geometrywidget_ui.h"
25 #include "timecode.h"
26 #include <mlt++/Mlt.h>
27
28 #include <QWidget>
29 #include <QGraphicsRectItem>
30 #include <QPainter>
31
32 class QDomElement;
33 class QGraphicsRectItem;
34 class Monitor;
35 class MonitorScene;
36 class KeyframeHelper;
37 class TimecodeDisplay;
38
39
40 class QGraphicsRectHandleItem: public QGraphicsRectItem
41 {
42 public:
43
44     QGraphicsRectHandleItem(const QRectF & rect, QGraphicsItem * parent = 0):
45             QGraphicsRectItem(rect, parent),
46             drawHandles(false) {
47     }
48
49     bool drawHandles;
50
51
52     virtual void paint(QPainter *painter,
53                        const QStyleOptionGraphicsItem * option,
54                        QWidget* widget = 0) {
55         QGraphicsRectItem::paint(painter, option, widget);
56         if (!drawHandles) return;
57         double handleSize = 6 / painter->matrix().m11();
58         painter->fillRect(0, 0, handleSize, handleSize, QColor(Qt::yellow));
59         painter->fillRect(option->rect.width() - handleSize, 0, handleSize, handleSize, QColor(Qt::yellow));
60         painter->fillRect(option->rect.width() - handleSize, option->rect.height() - handleSize, handleSize, handleSize, QColor(Qt::yellow));
61         painter->fillRect(0, option->rect.height() - handleSize, handleSize, handleSize, QColor(Qt::yellow));
62     }
63 };
64
65 class GeometryWidget : public QWidget
66 {
67     Q_OBJECT
68 public:
69     /** @brief Sets up the UI and connects it.
70     * @param monitor Project monitor
71     * @param clipPos Position of the clip in timeline
72     * @param parent (optional) Parent widget */
73     GeometryWidget(Monitor *monitor, Timecode timecode, int clipPos, bool isEffect, QWidget* parent = 0);
74     virtual ~GeometryWidget();
75     /** @brief Gets the geometry as a serialized string. */
76     QString getValue() const;
77     /** @brief Updates the timecode display according to settings (frame number or hh:mm:ss:ff) */
78     void updateTimecodeFormat();
79
80 public slots:
81     /** @brief Sets up the rect and the geometry object.
82     * @param elem DomElement representing this effect parameter
83     * @param minframe In point of the clip
84     * @param maxframe Out point of the clip */
85     void setupParam(const QDomElement elem, int minframe, int maxframe);
86     /** @brief Updates position of the local timeline to @param relTimelinePos.  */
87     void slotSyncPosition(int relTimelinePos);
88
89 private:
90     Ui::GeometryWidget_UI m_ui;
91     Monitor *m_monitor;
92     TimecodeDisplay *m_timePos;
93     /** Position of the clip in timeline. */
94     int m_clipPos;
95     /** In point of the clip (crop from start). */
96     int m_inPoint;
97     /** Out point of the clip (crop from end). */
98     int m_outPoint;
99     bool m_isEffect;
100     MonitorScene *m_scene;
101     QGraphicsRectHandleItem *m_rect;
102     KeyframeHelper *m_timeline;
103     /** Stores the different settings in the MLT geometry format. */
104     Mlt::Geometry *m_geometry;
105     bool m_showScene;
106
107 private slots:
108     /** @brief Updates controls according to position.
109     * @param pos (optional) Position to update to
110     * @param seek (optional, default = true) Whether to seek timleine & project monitor to pos
111     * If pos = -1 (default) the value of m_timePos is used. */
112     void slotPositionChanged(int pos = -1, bool seek = true);
113     /** @brief Updates settings after a keyframe was moved to @param pos. */
114     void slotKeyframeMoved(int pos);
115     /** @brief Adds a keyframe.
116     * @param pos (optional) Position where the keyframe should be added
117     * If pos = -1 (default) the value of m_timePos is used. */
118     void slotAddKeyframe(int pos = -1);
119     /** @brief Deletes a keyframe.
120     * @param pos (optional) Position of the keyframe which should be deleted
121     * If pos = -1 (default) the value of m_timePos is used. */
122     void slotDeleteKeyframe(int pos = -1);
123     /** @brief Goes to the next keyframe or to the end if none is available. */
124     void slotNextKeyframe();
125     /** @brief Goes to the previous keyframe or to the beginning if none is available. */
126     void slotPreviousKeyframe();
127     /** @brief Adds or deletes a keyframe depending on whether there is already a keyframe at the current position. */
128     void slotAddDeleteKeyframe();
129
130     /** @brief Makes sure the monitor effect scene is only visible if the clip this geometry belongs to is visible.
131     * @param renderPos Postion of the Monitor / Timeline cursor */
132     void slotCheckMonitorPosition(int renderPos);
133
134     /** @brief Updates the Mlt::Geometry object. */
135     void slotUpdateGeometry();
136     /** @brief Updates the spinBoxes according to the rect. */
137     void slotUpdateProperties();
138
139     /** @brief Sets the rect's x position to @param value. */
140     void slotSetX(int value);
141     /** @brief Sets the rect's y position to @param value. */
142     void slotSetY(int value);
143     /** @brief Sets the rect's width to @param value. */
144     void slotSetWidth(int value);
145     /** @brief Sets the rect's height to @param value. */
146     void slotSetHeight(int value);
147
148     /** @brief Resizes the rect by @param value (in perecent) compared to the frame size. */
149     void slotResize(int value);
150
151     /** @brief Sets the opacity to @param value. */
152     void slotSetOpacity(int value);
153
154     /** @brief Moves the rect to the left frame border (x position = 0). */
155     void slotMoveLeft();
156     /** @brief Centers the rect horizontally. */
157     void slotCenterH();
158     /** @brief Moves the rect to the right frame border (x position = frame width - rect width). */
159     void slotMoveRight();
160     /** @brief Moves the rect to the top frame border (y position = 0). */
161     void slotMoveTop();
162     /** @brief Centers the rect vertically. */
163     void slotCenterV();
164     /** @brief Moves the rect to the bottom frame border (y position = frame height - rect height). */
165     void slotMoveBottom();
166
167     /** @brief Enables/Disables syncing with the timeline according to @param sync. */
168     void slotSetSynchronize(bool sync);
169     /** @brief Switches from normal monitor to monitor scene according to @param show. */
170     void slotShowScene(bool show = true);
171
172 signals:
173     void parameterChanged();
174     void checkMonitorPosition(int);
175     void seekToPos(int);
176 };
177
178 #endif