]> git.sesse.net Git - kdenlive/blob - src/titlewidget.cpp
Title clips now really usable (only transparency & duration change still missing)
[kdenlive] / src / titlewidget.cpp
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
19
20 #include <QGraphicsView>
21 #include <QDomDocument>
22 #include <QGraphicsItem>
23 #include <QGraphicsSvgItem>
24 #include <QTimer>
25
26 #include <QToolBar>
27 #include <QMenu>
28
29 #include <KDebug>
30 #include <KGlobalSettings>
31 #include <KFileDialog>
32
33 #include "titlewidget.h"
34 #include "kdenlivesettings.h"
35
36 int settingUp = false;
37
38 TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget *parent): QDialog(parent), m_render(render), m_count(0), m_projectPath(projectPath) {
39     setupUi(this);
40     //frame_properties->
41     setFont(KGlobalSettings::toolBarFont());
42     //toolBox->setFont(KGlobalSettings::toolBarFont());
43     frame_properties->setEnabled(false);
44     m_frameWidth = render->renderWidth();
45     m_frameHeight = render->renderHeight();
46     //connect(newTextButton, SIGNAL(clicked()), this, SLOT(slotNewText()));
47     //connect(newRectButton, SIGNAL(clicked()), this, SLOT(slotNewRect()));
48     connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
49     connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
50     //connect(ktextedit, SIGNAL(textChanged()), this , SLOT(textChanged()));
51     //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ;
52
53
54     //ktextedit->setHidden(true);
55     connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
56     connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
57     connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
58     connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
59     //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged()));
60
61     connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
62     connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
63     connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
64     connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
65     connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
66
67     connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
68     connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
69     connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
70     connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
71     connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
72     connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
73
74     connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
75     connect(svgfilename, SIGNAL(urlSelected(const KUrl&)), this, SLOT(svgSelected(const KUrl &)));
76     connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
77     connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
78
79     connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
80     connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
81     connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
82     connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
83     connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
84     connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
85     connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
86     connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
87     connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
88     connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
89
90     buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
91     buttonRealSize->setIcon(KIcon("zoom-original"));
92     buttonBold->setIcon(KIcon("format-text-bold"));
93     buttonItalic->setIcon(KIcon("format-text-italic"));
94     buttonUnder->setIcon(KIcon("format-text-underline"));
95
96     QHBoxLayout *layout = new QHBoxLayout;
97     frame_toolbar->setLayout(layout);
98
99     QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
100
101     m_buttonRect = m_toolbar->addAction(KIcon("insert-rect"), i18n("Add Rectangle"));
102     m_buttonRect->setCheckable(true);
103     connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
104
105     m_buttonText = m_toolbar->addAction(KIcon("insert-text"), i18n("Add Text"));
106     m_buttonText->setCheckable(true);
107     connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
108
109     m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image"));
110     m_buttonImage->setCheckable(true);
111     connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
112
113     m_buttonCursor = m_toolbar->addAction(KIcon("select-rectangular"), i18n("Selection Tool"));
114     m_buttonCursor->setCheckable(true);
115     connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
116
117     m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
118     m_buttonLoad->setCheckable(false);
119     connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
120
121     m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
122     m_buttonSave->setCheckable(false);
123     connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
124
125     layout->addWidget(m_toolbar);
126     text_properties->setHidden(true);
127
128     // initialize graphic scene
129     m_scene = new GraphicsSceneRectMove(this);
130     graphicsView->setScene(m_scene);
131     m_titledocument.setScene(m_scene);
132
133     // a gradient background
134     QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
135     gradient->setSpread(QGradient::ReflectSpread);
136     //scene->setBackgroundBrush(*gradient);
137
138     m_frameImage = new QGraphicsPixmapItem();
139     QTransform qtrans;
140     qtrans.scale(2.0, 2.0);
141     m_frameImage->setTransform(qtrans);
142     m_frameImage->setZValue(-1200);
143     m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
144     displayBackgroundFrame();
145     graphicsView->scene()->addItem(m_frameImage);
146
147     connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
148     connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
149     connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
150     connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
151     connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
152     connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
153     connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
154     connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
155
156     QPen framepen(Qt::DotLine);
157     framepen.setColor(Qt::red);
158
159     m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
160     m_frameBorder->setPen(framepen);
161     m_frameBorder->setZValue(-1100);
162     m_frameBorder->setBrush(QColor(0, 0, 0, 0));
163     m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
164     graphicsView->scene()->addItem(m_frameBorder);
165
166     initViewports();
167
168     graphicsView->show();
169     graphicsView->setRenderHint(QPainter::Antialiasing);
170     graphicsView->setInteractive(true);
171     QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
172     //graphicsView->resize(400, 300);
173     kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
174     toolBox->setItemEnabled(2, false);
175     toolBox->setItemEnabled(3, false);
176     if (!url.isEmpty()) {
177         m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
178         slotSelectTool();
179     } else slotRectTool();
180 }
181
182
183 //virtual
184 void TitleWidget::resizeEvent(QResizeEvent * event) {
185     //slotAdjustZoom();
186 }
187
188 void TitleWidget::slotTextTool() {
189     rect_properties->setHidden(true);
190     text_properties->setHidden(false);
191     m_scene->setTool(TITLE_TEXT);
192     m_buttonRect->setChecked(false);
193     m_buttonCursor->setChecked(false);
194     m_buttonImage->setChecked(false);
195 }
196
197 void TitleWidget::slotRectTool() {
198     text_properties->setHidden(true);
199     rect_properties->setHidden(false);
200     m_scene->setTool(TITLE_RECTANGLE);
201     m_buttonText->setChecked(false);
202     m_buttonCursor->setChecked(false);
203     m_buttonImage->setChecked(false);
204 }
205
206 void TitleWidget::slotSelectTool() {
207     m_scene->setTool(TITLE_SELECT);
208     m_buttonCursor->setChecked(true);
209     m_buttonText->setChecked(false);
210     m_buttonRect->setChecked(false);
211     m_buttonImage->setChecked(false);
212 }
213
214 void TitleWidget::displayBackgroundFrame() {
215     if (!displayBg->isChecked()) {
216         QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
217         QPixmap pattern(20, 20);
218         pattern.fill();
219         QPainter p;
220         p.begin(&pattern);
221         p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
222         p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
223         p.end();
224         QBrush br(pattern);
225
226         p.begin(&bg);
227         p.fillRect(bg.rect(), br);
228         p.end();
229         m_frameImage->setPixmap(bg);
230     } else {
231         m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
232     }
233 }
234
235 void TitleWidget::initViewports() {
236     startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
237     endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
238
239     QPen startpen(Qt::DotLine);
240     QPen endpen(Qt::DashDotLine);
241     startpen.setColor(QColor(100, 200, 100, 140));
242     endpen.setColor(QColor(200, 100, 100, 140));
243
244     startViewport->setPen(startpen);
245     endViewport->setPen(endpen);
246
247     startViewportSize->setValue(40);
248     endViewportSize->setValue(40);
249
250     startViewport->setZValue(-1000);
251     endViewport->setZValue(-1000);
252
253     startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
254     endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
255
256     graphicsView->scene()->addItem(startViewport);
257     graphicsView->scene()->addItem(endViewport);
258 }
259
260 void TitleWidget::slotUpdateZoom(int pos) {
261     m_scene->setZoom((double) pos / 7);
262     zoom_label->setText("x" + QString::number((double) pos / 7, 'g', 2));
263 }
264
265 void TitleWidget::slotZoom(bool up) {
266     int pos = zoom_slider->value();
267     if (up) pos++;
268     else pos--;
269     zoom_slider->setValue(pos);
270 }
271
272 void TitleWidget::slotAdjustZoom() {
273     double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
274     double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
275     if (scalex > scaley) scalex = scaley;
276     int zoompos = (int)(scalex * 7 + 0.5);
277     zoom_slider->setValue(zoompos);
278     graphicsView->centerOn(m_frameBorder);
279 }
280
281 void TitleWidget::slotZoomOneToOne() {
282     zoom_slider->setValue(7);
283     graphicsView->centerOn(m_frameBorder);
284 }
285
286 void TitleWidget::slotNewRect(QGraphicsRectItem * rect) {
287     QColor f = rectFColor->color();
288     f.setAlpha(rectFAlpha->value());
289     QPen penf(f);
290     penf.setWidth(rectLineWidth->value());
291     rect->setPen(penf);
292     QColor b = rectBColor->color();
293     b.setAlpha(rectBAlpha->value());
294     rect->setBrush(QBrush(b));
295     rect->setZValue(m_count++);
296     //setCurrentItem(rect);
297     //graphicsView->setFocus();
298 }
299
300 void TitleWidget::slotNewText(QGraphicsTextItem *tt) {
301     QFont font = font_family->currentFont();
302     font.setPointSize(font_size->value());
303     tt->setFont(font);
304     QColor color = fontColorButton->color();
305     color.setAlpha(textAlpha->value());
306     tt->setDefaultTextColor(color);
307     tt->setZValue(m_count++);
308     setCurrentItem(tt);
309 }
310
311 void TitleWidget::setCurrentItem(QGraphicsItem *item) {
312     m_scene->setSelectedItem(item);
313 }
314
315 void TitleWidget::zIndexChanged(int v) {
316     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
317     if (l.size() >= 1) {
318         l[0]->setZValue(v);
319     }
320 }
321
322 void TitleWidget::selectionChanged() {
323     if (m_scene->tool() != TITLE_SELECT) return;
324     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
325     //toolBox->setItemEnabled(2, false);
326     //toolBox->setItemEnabled(3, false);
327     value_x->blockSignals(true);
328     value_y->blockSignals(true);
329     value_w->blockSignals(true);
330     value_h->blockSignals(true);
331     kDebug() << "////////  SELECTION CHANGED; ITEMS: " << l.size();
332     if (l.size() == 1) {
333         if ((l[0])->type() == 8) {
334             rect_properties->setHidden(true);
335             text_properties->setHidden(false);
336             QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]);
337             //if (l[0]->hasFocus())
338             //ktextedit->setHtml(i->toHtml());
339             toolBox->setCurrentIndex(0);
340             //toolBox->setItemEnabled(2, true);
341             font_size->blockSignals(true);
342             font_family->blockSignals(true);
343             buttonBold->blockSignals(true);
344             buttonItalic->blockSignals(true);
345             buttonUnder->blockSignals(true);
346             fontColorButton->blockSignals(true);
347             textAlpha->blockSignals(true);
348
349             QFont font = i->font();
350             font_family->setCurrentFont(font);
351             font_size->setValue(font.pointSize());
352             buttonBold->setChecked(font.bold());
353             buttonItalic->setChecked(font.italic());
354             buttonUnder->setChecked(font.underline());
355
356             QColor color = i->defaultTextColor();
357             fontColorButton->setColor(color);
358             textAlpha->setValue(color.alpha());
359
360             font_size->blockSignals(false);
361             font_family->blockSignals(false);
362             buttonBold->blockSignals(false);
363             buttonItalic->blockSignals(false);
364             buttonUnder->blockSignals(false);
365             fontColorButton->blockSignals(false);
366             textAlpha->blockSignals(false);
367
368             value_x->setValue((int) i->pos().x());
369             value_y->setValue((int) i->pos().y());
370             value_w->setValue((int) i->boundingRect().width());
371             value_h->setValue((int) i->boundingRect().height());
372             frame_properties->setEnabled(true);
373             value_w->setEnabled(false);
374             value_h->setEnabled(false);
375         } else if ((l[0])->type() == 3) {
376             rect_properties->setHidden(false);
377             text_properties->setHidden(true);
378             settingUp = true;
379             QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
380             toolBox->setCurrentIndex(0);
381             //toolBox->setItemEnabled(3, true);
382             rectFAlpha->setValue(rec->pen().color().alpha());
383             rectBAlpha->setValue(rec->brush().color().alpha());
384             kDebug() << rec->brush().color().alpha();
385             QColor fcol = rec->pen().color();
386             QColor bcol = rec->brush().color();
387             //fcol.setAlpha(255);
388             //bcol.setAlpha(255);
389             rectFColor->setColor(fcol);
390             rectBColor->setColor(bcol);
391             settingUp = false;
392             rectLineWidth->setValue(rec->pen().width());
393             value_x->setValue((int) rec->pos().x());
394             value_y->setValue((int) rec->pos().y());
395             value_w->setValue((int) rec->rect().width());
396             value_h->setValue((int) rec->rect().height());
397             frame_properties->setEnabled(true);
398             value_w->setEnabled(true);
399             value_h->setEnabled(true);
400         } else {
401             //toolBox->setCurrentIndex(0);
402             frame_properties->setEnabled(false);
403         }
404         zValue->setValue((int)l[0]->zValue());
405         itemzoom->setValue((int)transformations[l[0]].scalex*100);
406         itemrotate->setValue((int)transformations[l[0]].rotate);
407         value_x->blockSignals(false);
408         value_y->blockSignals(false);
409         value_w->blockSignals(false);
410         value_h->blockSignals(false);
411     } else frame_properties->setEnabled(false);
412 }
413
414 void TitleWidget::slotAdjustSelectedItem() {
415     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
416     if (l.size() >= 1) {
417         if (l[0]->type() == 3) {
418             //rect item
419             QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
420             rec->setPos(value_x->value(), value_y->value());
421             rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
422         } else if (l[0]->type() == 8) {
423             //text item
424             QGraphicsTextItem *rec = ((QGraphicsTextItem*)l[0]);
425             rec->setPos(value_x->value(), value_y->value());
426         }
427     }
428 }
429
430 void TitleWidget::slotChangeBackground() {
431     QColor color = kcolorbutton->color();
432     color.setAlpha(horizontalSlider->value());
433     m_frameBorder->setBrush(QBrush(color));
434 }
435
436 void TitleWidget::textChanged() {
437     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
438     if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
439         //kDebug() << ktextedit->document()->toHtml();
440         //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
441     }
442 }
443
444 void TitleWidget::slotUpdateText() {
445     QFont font = font_family->currentFont();
446     font.setPointSize(font_size->value());
447     font.setBold(buttonBold->isChecked());
448     font.setItalic(buttonItalic->isChecked());
449     font.setUnderline(buttonUnder->isChecked());
450     QColor color = fontColorButton->color();
451     color.setAlpha(textAlpha->value());
452
453     QGraphicsTextItem* item = NULL;
454     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
455     if (l.size() == 1 && (l[0])->type() == 8) {
456         item = (QGraphicsTextItem*)l[0];
457     }
458     if (!item) return;
459     //if (item->textCursor().selection ().isEmpty())
460     {
461         item->setFont(font);
462         item->setDefaultTextColor(color);
463     }
464     /*else {
465     QTextDocumentFragment selec = item->textCursor().selection ();
466     selec.set
467     }*/
468     //if (ktextedit->textCursor().selectedText().isEmpty()) ktextedit->selectAll();
469
470     //ktextedit->setCurrentFont(font);
471     //ktextedit->setTextColor(color);
472     /*QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
473     if (l.size() == 1 && (l[0])->type() == 8 && l[0]->hasFocus()) {
474     QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
475     //item-
476     }*/
477 }
478
479 void TitleWidget::rectChanged() {
480     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
481     if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) {
482         QGraphicsRectItem *rec = (QGraphicsRectItem*)l[0];
483         QColor f = rectFColor->color();
484         f.setAlpha(rectFAlpha->value());
485         QPen penf(f);
486         penf.setWidth(rectLineWidth->value());
487         rec->setPen(penf);
488         QColor b = rectBColor->color();
489         b.setAlpha(rectBAlpha->value());
490         rec->setBrush(QBrush(b));
491     }
492 }
493
494 void TitleWidget::fontBold() {
495     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
496     if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
497         //ktextedit->document()->setTextOption();
498     }
499 }
500
501 void TitleWidget::svgSelected(const KUrl& u) {
502     QGraphicsSvgItem *svg = new QGraphicsSvgItem(u.toLocalFile());
503     svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
504     graphicsView->scene()->addItem(svg);
505 }
506
507 void TitleWidget::itemScaled(int val) {
508     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
509     if (l.size() == 1) {
510         Transform x = transformations[l[0]];
511         x.scalex = (double)val / 100.0;
512         x.scaley = (double)val / 100.0;
513         QTransform qtrans;
514         qtrans.scale(x.scalex, x.scaley);
515         qtrans.rotate(x.rotate);
516         l[0]->setTransform(qtrans);
517         transformations[l[0]] = x;
518     }
519 }
520
521 void TitleWidget::itemRotate(int val) {
522     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
523     if (l.size() == 1) {
524         Transform x = transformations[l[0]];
525         x.rotate = (double)val;
526         QTransform qtrans;
527         qtrans.scale(x.scalex, x.scaley);
528         qtrans.rotate(x.rotate);
529         l[0]->setTransform(qtrans);
530         transformations[l[0]] = x;
531     }
532 }
533
534
535 void TitleWidget::setupViewports() {
536     double aspect_ratio = 4.0 / 3.0;//read from project
537
538     QRectF sp(0, 0, 0, 0);
539     QRectF ep(0, 0, 0, 0);
540
541     double sv_size = startViewportSize->value();
542     double ev_size = endViewportSize->value();
543     sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio);
544     ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio);
545
546     startViewport->setPos(startViewportX->value(), startViewportY->value());
547     endViewport->setPos(endViewportX->value(), endViewportY->value());
548
549     startViewport->setPolygon(QPolygonF(sp));
550     endViewport->setPolygon(QPolygonF(ep));
551
552 }
553
554 void TitleWidget::loadTitle() {
555     KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, tr("Save Title"));
556     if (!url.isEmpty()) {
557         QList<QGraphicsItem *> items = m_scene->items();
558         for (int i = 0; i < items.size(); i++) {
559             if (items.at(i)->zValue() > -1000) delete items.at(i);
560         }
561         m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
562         slotSelectTool();
563     }
564 }
565
566 void TitleWidget::saveTitle(KUrl url) {
567     if (url.isEmpty()) KUrl url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, tr("Save Title"));
568     if (!url.isEmpty()) m_titledocument.saveDocument(url, startViewport, endViewport);
569 }
570
571 QPixmap TitleWidget::renderedPixmap() {
572     QPixmap pix(m_frameWidth, m_frameHeight);
573     pix.fill(Qt::transparent);
574     QPainter painter(&pix);
575
576     m_scene->clearSelection();
577     QPen framepen = m_frameBorder->pen();
578     m_frameBorder->setPen(Qt::NoPen);
579     startViewport->setVisible(false);
580     endViewport->setVisible(false);
581     m_frameImage->setVisible(false);
582
583     m_scene->render(&painter, QRectF(), QRectF(0, 0, m_frameWidth, m_frameHeight));
584     m_frameBorder->setPen(framepen);
585     startViewport->setVisible(true);
586     endViewport->setVisible(true);
587     m_frameImage->setVisible(true);
588     return pix;
589 }
590
591 #include "moc_titlewidget.cpp"
592