MythTV master
mythuieditbar.cpp
Go to the documentation of this file.
1
2#include "mythuieditbar.h"
3
4// C++
5#include <cmath>
6
7// MythUI
8#include "mythuishape.h"
9#include "mythuiimage.h"
10
12{
14}
15
16void MythUIEditBar::SetTotal(double total)
17{
18 if (total < 1.0)
19 return;
20
21 bool changed = m_total != total;
22 m_total = total;
23
24 if (changed)
25 Display();
26}
27
28void MythUIEditBar::SetEditPosition(double position)
29{
30 float newpos = position / m_total;
31
32 if (newpos < 0.0F || newpos > 1.0F)
33 return;
34
35 bool changed = m_editPosition != newpos;
36 m_editPosition = newpos;
37
38 if (changed)
39 Display();
40}
41
42void MythUIEditBar::AddRegion(double start, double end)
43{
44 if (m_total >= end && end >= start && start >= 0.0)
45 m_regions.append(qMakePair((float)(start / m_total),
46 (float)(end / m_total)));
47}
48
49void MythUIEditBar::SetTotal(long long total)
50{
51 SetTotal((double)total);
52}
53
54void MythUIEditBar::SetEditPosition(long long position)
55{
56 SetEditPosition((double)position);
57}
58
59void MythUIEditBar::AddRegion(long long start, long long end)
60{
61 AddRegion((double)start, (double)end);
62}
63
65{
66 m_regions.clear();
67}
68
70{
71 QRect keeparea = QRect();
72 QRect cutarea = QRect();
73 MythUIType *position = GetChild("position");
74 MythUIType *keep = GetChild("keep");
75 MythUIType *cut = GetChild("cut");
76 MythUIType *cuttoleft = GetChild("cuttoleft");
77 MythUIType *cuttoright = GetChild("cuttoright");
78 MythUIType *keeptoleft = GetChild("keeptoleft");
79 MythUIType *keeptoright = GetChild("keeptoright");
80
81 if (position)
82 position->SetVisible(false);
83
84 if (keep)
85 {
86 keep->SetVisible(false);
87 keeparea = keep->GetArea();
88 }
89
90 if (cut)
91 {
92 cut->SetVisible(false);
93 cutarea = cut->GetArea();
94 }
95
96 if (cuttoleft)
97 cuttoleft->SetVisible(false);
98
99 if (cuttoright)
100 cuttoright->SetVisible(false);
101
102 if (keeptoleft)
103 keeptoleft->SetVisible(false);
104
105 if (keeptoright)
106 keeptoright->SetVisible(false);
107
108 if (position && keeparea.isValid())
109 {
110 int offset = position->GetArea().width() / 2;
111 int newx = lroundf((float)keeparea.width() * m_editPosition);
112 int newy = position->GetArea().top();
113 position->SetPosition(newx - offset, newy);
114 position->SetVisible(true);
115 }
116
117 ClearImages();
118
119 if (m_regions.isEmpty())
120 {
121 if (keep)
122 keep->SetVisible(true);
123
124 return;
125 }
126
127 auto *barshape = dynamic_cast<MythUIShape *>(cut);
128 auto *barimage = dynamic_cast<MythUIImage *>(cut);
129 auto *leftshape = dynamic_cast<MythUIShape *>(cuttoleft);
130 auto *leftimage = dynamic_cast<MythUIImage *>(cuttoleft);
131 auto *rightshape = dynamic_cast<MythUIShape *>(cuttoright);
132 auto *rightimage = dynamic_cast<MythUIImage *>(cuttoright);
133
134 QListIterator<QPair<float, float> > regions(m_regions);
135
136 while (regions.hasNext() && cutarea.isValid())
137 {
138 QPair<float, float> region = regions.next();
139 int left = lroundf(region.first * cutarea.width());
140 int right = lroundf(region.second * cutarea.width());
141
142 if (left >= right)
143 right = left + 1;
144
145 if (cut)
146 {
147 AddBar(barshape, barimage, QRect(left, cutarea.top(), right - left,
148 cutarea.height()));
149 }
150
151 if (cuttoleft && (region.second < 1.0F))
152 AddMark(leftshape, leftimage, right, true);
153
154 if (cuttoright && (region.first > 0.0F))
155 AddMark(rightshape, rightimage, left, false);
156 }
157
159
160 barshape = dynamic_cast<MythUIShape *>(keep);
161 barimage = dynamic_cast<MythUIImage *>(keep);
162 leftshape = dynamic_cast<MythUIShape *>(keeptoleft);
163 leftimage = dynamic_cast<MythUIImage *>(keeptoleft);
164 rightshape = dynamic_cast<MythUIShape *>(keeptoright);
165 rightimage = dynamic_cast<MythUIImage *>(keeptoright);
166
167 QListIterator<QPair<float, float> > regions2(m_invregions);
168
169 while (regions2.hasNext() && keeparea.isValid())
170 {
171 QPair<float, float> region = regions2.next();
172 int left = lroundf(region.first * keeparea.width());
173 int right = lroundf(region.second * keeparea.width());
174
175 if (left >= right)
176 right = left + 1;
177
178 if (keep)
179 {
180 AddBar(barshape, barimage, QRect(left, keeparea.top(), right - left,
181 keeparea.height()));
182 }
183
184 if (keeptoleft && (region.second < 1.0F))
185 AddMark(leftshape, leftimage, right, true);
186
187 if (keeptoright && (region.first > 0.0F))
188 AddMark(rightshape, rightimage, left, false);
189 }
190
191 if (position)
192 position->MoveToTop();
193}
194
196 const QRect area)
197{
198 MythUIType *add = GetNew(_shape, _image);
199
200 if (add)
201 {
202 auto *shape = dynamic_cast<MythUIShape *>(add);
203 auto *image = dynamic_cast<MythUIImage *>(add);
204
205 if (shape)
206 shape->SetCropRect(area.left(), area.top(), area.width(), area.height());
207
208 if (image)
209 image->SetCropRect(area.left(), area.top(), area.width(), area.height());
210
211 add->SetPosition(area.left(), area.top());
212 }
213}
214
216 int start, bool left)
217{
218 MythUIType *add = GetNew(shape, image);
219
220 if (add)
221 {
222 if (left)
223 start -= add->GetArea().width();
224
225 add->SetPosition(start, add->GetArea().top());
226 }
227}
228
230{
231 QString name = QString("editbarimage_%1").arg(m_images.size());
232
233 if (shape)
234 {
235 auto *newshape = new MythUIShape(this, name);
236
237 if (newshape)
238 {
239 newshape->CopyFrom(shape);
240 newshape->SetVisible(true);
241 m_images.append(newshape);
242 return newshape;
243 }
244 }
245 else if (image)
246 {
247 auto *newimage = new MythUIImage(this, name);
248
249 if (newimage)
250 {
251 newimage->CopyFrom(image);
252 newimage->SetVisible(true);
253 m_images.append(newimage);
254 return newimage;
255 }
256 }
257
258 return nullptr;
259}
260
262{
263 m_invregions.clear();
264
265 bool first = true;
266 float start = 0.0F;
267 QListIterator<QPair<float, float> > regions(m_regions);
268
269 while (regions.hasNext())
270 {
271 QPair<float, float> region = regions.next();
272
273 if (first)
274 {
275 if (region.first > 0.0F)
276 m_invregions.append(qMakePair(start, region.first));
277
278 start = region.second;
279 first = false;
280 }
281 else
282 {
283 m_invregions.append(qMakePair(start, region.first));
284 start = region.second;
285 }
286 }
287
288 if (start < 1.0F)
289 m_invregions.append(qMakePair(start, 1.0F));
290}
291
293{
294 while (!m_images.empty())
295 DeleteChild(m_images.takeFirst());
296 SetRedraw();
297}
298
303{
304 auto *editbar = dynamic_cast<MythUIEditBar *>(base);
305
306 if (!editbar)
307 return;
308
309 m_editPosition = editbar->m_editPosition;
310
311 QListIterator<QPair<float, float> > it(m_regions);
312
313 while (it.hasNext())
314 editbar->m_regions.append(it.next());
315
317}
318
323{
324 auto *editbar = new MythUIEditBar(parent, objectName());
325 editbar->CopyFrom(this);
326}
327
332{
333 MythUIType *position = GetChild("position");
334
335 if (position)
336 position->MoveToTop();
337}
A narrow purpose widget used to represent cut positions and regions when editing a video.
Definition: mythuieditbar.h:17
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
void AddBar(MythUIShape *shape, MythUIImage *image, QRect area)
QList< QPair< float, float > > m_invregions
Definition: mythuieditbar.h:49
void ClearRegions(void)
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
void ReleaseImages(void)
void SetEditPosition(double position)
float m_editPosition
Definition: mythuieditbar.h:46
MythUIType * GetNew(MythUIShape *shape, MythUIImage *image)
void AddRegion(double start, double end)
MythUIEditBar(MythUIType *parent, const QString &name)
Definition: mythuieditbar.h:19
void ClearImages(void)
void CalcInverseRegions(void)
void AddMark(MythUIShape *shape, MythUIImage *image, int start, bool left)
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
void Display(void)
void SetTotal(double total)
QList< MythUIType * > m_images
Definition: mythuieditbar.h:50
QList< QPair< float, float > > m_regions
Definition: mythuieditbar.h:48
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
void SetCropRect(int x, int y, int width, int height)
Crop the image using the given rectangle, useful for removing unsightly edges from imported images or...
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:22
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
virtual void SetVisible(bool visible)
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void SetRedraw(void)
Definition: mythuitype.cpp:313
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
Definition: mythuitype.cpp:885
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:533
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
bool MoveToTop(void)
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:153