]> git.sesse.net Git - kdenlive/blob - src/titlewidget.cpp
01719d8ce39c82eac01daa2c9c5f6f3646945b72
[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(Render *render, QWidget *parent): QDialog(parent), m_render(render), m_count(0) {
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     slotRectTool();
159
160     m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
161     m_frameBorder->setPen(framepen);
162     m_frameBorder->setZValue(-1100);
163     m_frameBorder->setBrush(QColor(0, 0, 0, 0));
164     m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
165     graphicsView->scene()->addItem(m_frameBorder);
166
167     initViewports();
168
169     graphicsView->show();
170     graphicsView->setRenderHint(QPainter::Antialiasing);
171     graphicsView->setInteractive(true);
172     QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
173     //graphicsView->resize(400, 300);
174     kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
175     toolBox->setItemEnabled(2, false);
176     toolBox->setItemEnabled(3, false);
177 }
178
179
180 //virtual
181 void TitleWidget::resizeEvent(QResizeEvent * event) {
182     //slotAdjustZoom();
183 }
184
185 void TitleWidget::slotTextTool() {
186     rect_properties->setHidden(true);
187     text_properties->setHidden(false);
188     m_scene->setTool(TITLE_TEXT);
189     m_buttonRect->setChecked(false);
190     m_buttonCursor->setChecked(false);
191     m_buttonImage->setChecked(false);
192 }
193
194 void TitleWidget::slotRectTool() {
195     text_properties->setHidden(true);
196     rect_properties->setHidden(false);
197     m_scene->setTool(TITLE_RECTANGLE);
198     m_buttonText->setChecked(false);
199     m_buttonCursor->setChecked(false);
200     m_buttonImage->setChecked(false);
201 }
202
203 void TitleWidget::slotSelectTool() {
204     m_scene->setTool(TITLE_SELECT);
205     m_buttonCursor->setChecked(true);
206     m_buttonText->setChecked(false);
207     m_buttonRect->setChecked(false);
208     m_buttonImage->setChecked(false);
209 }
210
211 void TitleWidget::displayBackgroundFrame() {
212     if (!displayBg->isChecked()) {
213         QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
214         QPixmap pattern(20, 20);
215         pattern.fill();
216         QPainter p;
217         p.begin(&pattern);
218         p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
219         p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
220         p.end();
221         QBrush br(pattern);
222
223         p.begin(&bg);
224         p.fillRect(bg.rect(), br);
225         p.end();
226         m_frameImage->setPixmap(bg);
227     } else {
228         m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
229     }
230 }
231
232 void TitleWidget::initViewports() {
233     startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
234     endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
235
236     QPen startpen(Qt::DotLine);
237     QPen endpen(Qt::DashDotLine);
238     startpen.setColor(QColor(100, 200, 100, 140));
239     endpen.setColor(QColor(200, 100, 100, 140));
240
241     startViewport->setPen(startpen);
242     endViewport->setPen(endpen);
243
244     startViewportSize->setValue(40);
245     endViewportSize->setValue(40);
246
247     startViewport->setZValue(-1000);
248     endViewport->setZValue(-1000);
249
250     startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
251     endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
252
253     graphicsView->scene()->addItem(startViewport);
254     graphicsView->scene()->addItem(endViewport);
255 }
256
257 void TitleWidget::slotUpdateZoom(int pos) {
258     m_scene->setZoom((double) pos / 7);
259     zoom_label->setText("x" + QString::number((double) pos / 7, 'g', 2));
260 }
261
262 void TitleWidget::slotZoom(bool up) {
263     int pos = zoom_slider->value();
264     if (up) pos++;
265     else pos--;
266     zoom_slider->setValue(pos);
267 }
268
269 void TitleWidget::slotAdjustZoom() {
270     double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
271     double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
272     if (scalex > scaley) scalex = scaley;
273     int zoompos = (int)(scalex * 7 + 0.5);
274     zoom_slider->setValue(zoompos);
275     graphicsView->centerOn(m_frameBorder);
276 }
277
278 void TitleWidget::slotZoomOneToOne() {
279     zoom_slider->setValue(7);
280     graphicsView->centerOn(m_frameBorder);
281 }
282
283 void TitleWidget::slotNewRect(QGraphicsRectItem * rect) {
284     QColor f = rectFColor->color();
285     f.setAlpha(rectFAlpha->value());
286     QPen penf(f);
287     penf.setWidth(rectLineWidth->value());
288     rect->setPen(penf);
289     QColor b = rectBColor->color();
290     b.setAlpha(rectBAlpha->value());
291     rect->setBrush(QBrush(b));
292     rect->setZValue(m_count++);
293     //setCurrentItem(rect);
294     //graphicsView->setFocus();
295 }
296
297 void TitleWidget::slotNewText(QGraphicsTextItem *tt) {
298     QFont font = font_family->currentFont();
299     font.setPointSize(font_size->value());
300     tt->setFont(font);
301     QColor color = fontColorButton->color();
302     color.setAlpha(textAlpha->value());
303     tt->setDefaultTextColor(color);
304     tt->setZValue(m_count++);
305     setCurrentItem(tt);
306 }
307
308 void TitleWidget::setCurrentItem(QGraphicsItem *item) {
309     m_scene->setSelectedItem(item);
310 }
311
312 void TitleWidget::zIndexChanged(int v) {
313     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
314     if (l.size() >= 1) {
315         l[0]->setZValue(v);
316     }
317 }
318
319 void TitleWidget::selectionChanged() {
320     if (m_scene->tool() != TITLE_SELECT) return;
321     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
322     //toolBox->setItemEnabled(2, false);
323     //toolBox->setItemEnabled(3, false);
324     value_x->blockSignals(true);
325     value_y->blockSignals(true);
326     value_w->blockSignals(true);
327     value_h->blockSignals(true);
328     kDebug() << "////////  SELECTION CHANGED; ITEMS: " << l.size();
329     if (l.size() == 1) {
330         if ((l[0])->type() == 8) {
331             rect_properties->setHidden(true);
332             text_properties->setHidden(false);
333             QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]);
334             //if (l[0]->hasFocus())
335             //ktextedit->setHtml(i->toHtml());
336             toolBox->setCurrentIndex(0);
337             //toolBox->setItemEnabled(2, true);
338             font_size->blockSignals(true);
339             font_family->blockSignals(true);
340             buttonBold->blockSignals(true);
341             buttonItalic->blockSignals(true);
342             buttonUnder->blockSignals(true);
343             fontColorButton->blockSignals(true);
344             textAlpha->blockSignals(true);
345
346             QFont font = i->font();
347             font_family->setCurrentFont(font);
348             font_size->setValue(font.pointSize());
349             buttonBold->setChecked(font.bold());
350             buttonItalic->setChecked(font.italic());
351             buttonUnder->setChecked(font.underline());
352
353             QColor color = i->defaultTextColor();
354             fontColorButton->setColor(color);
355             textAlpha->setValue(color.alpha());
356
357             font_size->blockSignals(false);
358             font_family->blockSignals(false);
359             buttonBold->blockSignals(false);
360             buttonItalic->blockSignals(false);
361             buttonUnder->blockSignals(false);
362             fontColorButton->blockSignals(false);
363             textAlpha->blockSignals(false);
364
365             value_x->setValue((int) i->pos().x());
366             value_y->setValue((int) i->pos().y());
367             value_w->setValue((int) i->boundingRect().width());
368             value_h->setValue((int) i->boundingRect().height());
369             frame_properties->setEnabled(true);
370             value_w->setEnabled(false);
371             value_h->setEnabled(false);
372         } else if ((l[0])->type() == 3) {
373             rect_properties->setHidden(false);
374             text_properties->setHidden(true);
375             settingUp = true;
376             QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
377             toolBox->setCurrentIndex(0);
378             //toolBox->setItemEnabled(3, true);
379             rectFAlpha->setValue(rec->pen().color().alpha());
380             rectBAlpha->setValue(rec->brush().color().alpha());
381             kDebug() << rec->brush().color().alpha();
382             QColor fcol = rec->pen().color();
383             QColor bcol = rec->brush().color();
384             //fcol.setAlpha(255);
385             //bcol.setAlpha(255);
386             rectFColor->setColor(fcol);
387             rectBColor->setColor(bcol);
388             settingUp = false;
389             rectLineWidth->setValue(rec->pen().width());
390             value_x->setValue((int) rec->pos().x());
391             value_y->setValue((int) rec->pos().y());
392             value_w->setValue((int) rec->rect().width());
393             value_h->setValue((int) rec->rect().height());
394             frame_properties->setEnabled(true);
395             value_w->setEnabled(true);
396             value_h->setEnabled(true);
397         } else {
398             //toolBox->setCurrentIndex(0);
399             frame_properties->setEnabled(false);
400         }
401         zValue->setValue((int)l[0]->zValue());
402         itemzoom->setValue((int)transformations[l[0]].scalex*100);
403         itemrotate->setValue((int)transformations[l[0]].rotate);
404         value_x->blockSignals(false);
405         value_y->blockSignals(false);
406         value_w->blockSignals(false);
407         value_h->blockSignals(false);
408     } else frame_properties->setEnabled(false);
409 }
410
411 void TitleWidget::slotAdjustSelectedItem() {
412     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
413     if (l.size() >= 1) {
414         if (l[0]->type() == 3) {
415             //rect item
416             QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
417             rec->setPos(value_x->value(), value_y->value());
418             rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
419         } else if (l[0]->type() == 8) {
420             //text item
421             QGraphicsTextItem *rec = ((QGraphicsTextItem*)l[0]);
422             rec->setPos(value_x->value(), value_y->value());
423         }
424     }
425 }
426
427 void TitleWidget::slotChangeBackground() {
428     QColor color = kcolorbutton->color();
429     color.setAlpha(horizontalSlider->value());
430     m_frameBorder->setBrush(QBrush(color));
431 }
432
433 void TitleWidget::textChanged() {
434     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
435     if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
436         //kDebug() << ktextedit->document()->toHtml();
437         //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
438     }
439 }
440
441 void TitleWidget::slotUpdateText() {
442     QFont font = font_family->currentFont();
443     font.setPointSize(font_size->value());
444     font.setBold(buttonBold->isChecked());
445     font.setItalic(buttonItalic->isChecked());
446     font.setUnderline(buttonUnder->isChecked());
447     QColor color = fontColorButton->color();
448     color.setAlpha(textAlpha->value());
449
450     QGraphicsTextItem* item = NULL;
451     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
452     if (l.size() == 1 && (l[0])->type() == 8) {
453         item = (QGraphicsTextItem*)l[0];
454     }
455     if (!item) return;
456     //if (item->textCursor().selection ().isEmpty())
457     {
458         item->setFont(font);
459         item->setDefaultTextColor(color);
460     }
461     /*else {
462     QTextDocumentFragment selec = item->textCursor().selection ();
463     selec.set
464     }*/
465     //if (ktextedit->textCursor().selectedText().isEmpty()) ktextedit->selectAll();
466
467     //ktextedit->setCurrentFont(font);
468     //ktextedit->setTextColor(color);
469     /*QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
470     if (l.size() == 1 && (l[0])->type() == 8 && l[0]->hasFocus()) {
471     QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
472     //item-
473     }*/
474 }
475
476 void TitleWidget::rectChanged() {
477     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
478     if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) {
479         QGraphicsRectItem *rec = (QGraphicsRectItem*)l[0];
480         QColor f = rectFColor->color();
481         f.setAlpha(rectFAlpha->value());
482         QPen penf(f);
483         penf.setWidth(rectLineWidth->value());
484         rec->setPen(penf);
485         QColor b = rectBColor->color();
486         b.setAlpha(rectBAlpha->value());
487         rec->setBrush(QBrush(b));
488     }
489 }
490
491 void TitleWidget::fontBold() {
492     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
493     if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
494         //ktextedit->document()->setTextOption();
495     }
496 }
497
498 void TitleWidget::svgSelected(const KUrl& u) {
499     QGraphicsSvgItem *svg = new QGraphicsSvgItem(u.toLocalFile());
500     svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
501     graphicsView->scene()->addItem(svg);
502 }
503
504 void TitleWidget::itemScaled(int val) {
505     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
506     if (l.size() == 1) {
507         Transform x = transformations[l[0]];
508         x.scalex = (double)val / 100.0;
509         x.scaley = (double)val / 100.0;
510         QTransform qtrans;
511         qtrans.scale(x.scalex, x.scaley);
512         qtrans.rotate(x.rotate);
513         l[0]->setTransform(qtrans);
514         transformations[l[0]] = x;
515     }
516 }
517
518 void TitleWidget::itemRotate(int val) {
519     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
520     if (l.size() == 1) {
521         Transform x = transformations[l[0]];
522         x.rotate = (double)val;
523         QTransform qtrans;
524         qtrans.scale(x.scalex, x.scaley);
525         qtrans.rotate(x.rotate);
526         l[0]->setTransform(qtrans);
527         transformations[l[0]] = x;
528     }
529 }
530
531
532 void TitleWidget::setupViewports() {
533     double aspect_ratio = 4.0 / 3.0;//read from project
534
535     QRectF sp(0, 0, 0, 0);
536     QRectF ep(0, 0, 0, 0);
537
538     double sv_size = startViewportSize->value();
539     double ev_size = endViewportSize->value();
540     sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio);
541     ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio);
542
543     startViewport->setPos(startViewportX->value(), startViewportY->value());
544     endViewport->setPos(endViewportX->value(), endViewportY->value());
545
546     startViewport->setPolygon(QPolygonF(sp));
547     endViewport->setPolygon(QPolygonF(ep));
548
549 }
550
551 void TitleWidget::loadTitle() {
552     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlivetitle", this, tr("Save Title"));
553     if (!url.isEmpty()) {
554         QList<QGraphicsItem *> items = m_scene->items();
555         for (int i = 0; i < items.size(); i++) {
556             if (items.at(i)->zValue() > -1000) delete items.at(i);
557         }
558         m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
559         slotSelectTool();
560     }
561 }
562
563 void TitleWidget::saveTitle() {
564     KUrl url = KFileDialog::getSaveUrl(KUrl(), "*.kdenlivetitle", this, tr("Save Title"));
565     m_titledocument.saveDocument(url, startViewport, endViewport);
566 }
567
568 QPixmap TitleWidget::renderedPixmap() {
569     QPixmap pix(m_frameWidth, m_frameHeight);
570     pix.fill(Qt::transparent);
571     QPainter painter(&pix);
572
573     m_scene->clearSelection();
574     QPen framepen = m_frameBorder->pen();
575     m_frameBorder->setPen(Qt::NoPen);
576     startViewport->setVisible(false);
577     endViewport->setVisible(false);
578     m_frameImage->setVisible(false);
579
580     m_scene->render(&painter, QRectF(), QRectF(0, 0, m_frameWidth, m_frameHeight));
581     m_frameBorder->setPen(framepen);
582     startViewport->setVisible(true);
583     endViewport->setVisible(true);
584     m_frameImage->setVisible(true);
585     return pix;
586 }
587
588 #include "moc_titlewidget.cpp"
589