1 /***************************************************************************
2 titlewidget.h - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
20 #include <QGraphicsView>
21 #include <QDomDocument>
22 #include <QGraphicsItem>
23 #include <QGraphicsSvgItem>
30 #include <KGlobalSettings>
31 #include <KFileDialog>
33 #include "titlewidget.h"
34 #include "kdenlivesettings.h"
36 int settingUp = false;
38 TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget *parent): QDialog(parent), m_render(render), m_count(0), m_projectPath(projectPath) {
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()) ) ;
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()));
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()));
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()));
74 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
75 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
76 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
77 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
78 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
80 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
81 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
82 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
83 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
84 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
85 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
86 connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
87 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
88 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
89 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
91 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
92 buttonRealSize->setIcon(KIcon("zoom-original"));
93 buttonBold->setIcon(KIcon("format-text-bold"));
94 buttonItalic->setIcon(KIcon("format-text-italic"));
95 buttonUnder->setIcon(KIcon("format-text-underline"));
97 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
98 itemhcenter->setToolTip(i18n("Align item horizontally"));
99 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
100 itemvcenter->setToolTip(i18n("Align item vertically"));
102 QHBoxLayout *layout = new QHBoxLayout;
103 frame_toolbar->setLayout(layout);
105 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
107 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), i18n("Add Rectangle"));
108 m_buttonRect->setCheckable(true);
109 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
111 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), i18n("Add Text"));
112 m_buttonText->setCheckable(true);
113 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
115 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image"));
116 m_buttonImage->setCheckable(false);
117 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
119 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), i18n("Selection Tool"));
120 m_buttonCursor->setCheckable(true);
121 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
123 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
124 m_buttonLoad->setCheckable(false);
125 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
127 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
128 m_buttonSave->setCheckable(false);
129 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
131 layout->addWidget(m_toolbar);
132 text_properties->setHidden(true);
134 // initialize graphic scene
135 m_scene = new GraphicsSceneRectMove(this);
136 graphicsView->setScene(m_scene);
137 m_titledocument.setScene(m_scene);
139 // a gradient background
140 QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
141 gradient->setSpread(QGradient::ReflectSpread);
142 //scene->setBackgroundBrush(*gradient);
144 m_frameImage = new QGraphicsPixmapItem();
146 qtrans.scale(2.0, 2.0);
147 m_frameImage->setTransform(qtrans);
148 m_frameImage->setZValue(-1200);
149 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
150 displayBackgroundFrame();
151 graphicsView->scene()->addItem(m_frameImage);
153 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
154 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
155 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
156 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
157 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
158 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
159 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
160 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
162 QPen framepen(Qt::DotLine);
163 framepen.setColor(Qt::red);
165 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
166 m_frameBorder->setPen(framepen);
167 m_frameBorder->setZValue(-1100);
168 m_frameBorder->setBrush(QColor(0, 0, 0, 0));
169 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
170 graphicsView->scene()->addItem(m_frameBorder);
174 graphicsView->show();
175 graphicsView->setRenderHint(QPainter::Antialiasing);
176 graphicsView->setInteractive(true);
177 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
178 //graphicsView->resize(400, 300);
179 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
180 toolBox->setItemEnabled(2, false);
181 if (!url.isEmpty()) {
182 m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
184 } else slotRectTool();
189 void TitleWidget::resizeEvent(QResizeEvent * event) {
193 void TitleWidget::slotTextTool() {
194 rect_properties->setHidden(true);
195 text_properties->setHidden(false);
196 m_scene->setTool(TITLE_TEXT);
197 m_buttonRect->setChecked(false);
198 m_buttonCursor->setChecked(false);
201 void TitleWidget::slotRectTool() {
202 text_properties->setHidden(true);
203 rect_properties->setHidden(false);
204 m_scene->setTool(TITLE_RECTANGLE);
205 m_buttonText->setChecked(false);
206 m_buttonCursor->setChecked(false);
207 m_buttonRect->setChecked(true);
210 void TitleWidget::slotSelectTool() {
211 m_scene->setTool(TITLE_SELECT);
212 m_buttonCursor->setChecked(true);
213 m_buttonText->setChecked(false);
214 m_buttonRect->setChecked(false);
217 void TitleWidget::slotImageTool() {
218 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
219 if (!url.isEmpty()) {
220 if (url.path().endsWith(".svg")) {
221 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
222 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
223 svg->setZValue(m_count++);
224 svg->setData(Qt::UserRole, url.path());
225 graphicsView->scene()->addItem(svg);
227 QPixmap pix(url.path());
228 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
229 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
230 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
231 image->setData(Qt::UserRole, url.path());
232 image->setZValue(m_count++);
233 graphicsView->scene()->addItem(image);
236 m_scene->setTool(TITLE_SELECT);
237 m_buttonRect->setChecked(false);
238 m_buttonCursor->setChecked(true);
239 m_buttonText->setChecked(false);
242 void TitleWidget::displayBackgroundFrame() {
243 if (!displayBg->isChecked()) {
244 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
245 QPixmap pattern(20, 20);
249 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
250 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
255 p.fillRect(bg.rect(), br);
257 m_frameImage->setPixmap(bg);
259 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
263 void TitleWidget::initViewports() {
264 startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
265 endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
267 QPen startpen(Qt::DotLine);
268 QPen endpen(Qt::DashDotLine);
269 startpen.setColor(QColor(100, 200, 100, 140));
270 endpen.setColor(QColor(200, 100, 100, 140));
272 startViewport->setPen(startpen);
273 endViewport->setPen(endpen);
275 startViewportSize->setValue(40);
276 endViewportSize->setValue(40);
278 startViewport->setZValue(-1000);
279 endViewport->setZValue(-1000);
281 startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
282 endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
284 graphicsView->scene()->addItem(startViewport);
285 graphicsView->scene()->addItem(endViewport);
288 void TitleWidget::slotUpdateZoom(int pos) {
289 m_scene->setZoom((double) pos / 7);
290 zoom_label->setText("x" + QString::number((double) pos / 7, 'g', 2));
293 void TitleWidget::slotZoom(bool up) {
294 int pos = zoom_slider->value();
297 zoom_slider->setValue(pos);
300 void TitleWidget::slotAdjustZoom() {
301 double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
302 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
303 if (scalex > scaley) scalex = scaley;
304 int zoompos = (int)(scalex * 7 + 0.5);
305 zoom_slider->setValue(zoompos);
306 graphicsView->centerOn(m_frameBorder);
309 void TitleWidget::slotZoomOneToOne() {
310 zoom_slider->setValue(7);
311 graphicsView->centerOn(m_frameBorder);
314 void TitleWidget::slotNewRect(QGraphicsRectItem * rect) {
315 QColor f = rectFColor->color();
316 f.setAlpha(rectFAlpha->value());
318 penf.setWidth(rectLineWidth->value());
320 QColor b = rectBColor->color();
321 b.setAlpha(rectBAlpha->value());
322 rect->setBrush(QBrush(b));
323 rect->setZValue(m_count++);
324 //setCurrentItem(rect);
325 //graphicsView->setFocus();
328 void TitleWidget::slotNewText(QGraphicsTextItem *tt) {
329 QFont font = font_family->currentFont();
330 font.setPointSize(font_size->value());
332 QColor color = fontColorButton->color();
333 color.setAlpha(textAlpha->value());
334 tt->setDefaultTextColor(color);
335 tt->setZValue(m_count++);
339 void TitleWidget::setCurrentItem(QGraphicsItem *item) {
340 m_scene->setSelectedItem(item);
343 void TitleWidget::zIndexChanged(int v) {
344 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
350 void TitleWidget::selectionChanged() {
351 if (m_scene->tool() != TITLE_SELECT) return;
352 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
353 //toolBox->setItemEnabled(2, false);
354 //toolBox->setItemEnabled(3, false);
355 value_x->blockSignals(true);
356 value_y->blockSignals(true);
357 value_w->blockSignals(true);
358 value_h->blockSignals(true);
359 kDebug() << "//////// SELECTION CHANGED; ITEMS: " << l.size();
361 if ((l[0])->type() == 8) {
362 rect_properties->setHidden(true);
363 text_properties->setHidden(false);
364 QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]);
365 //if (l[0]->hasFocus())
366 //ktextedit->setHtml(i->toHtml());
367 toolBox->setCurrentIndex(0);
368 //toolBox->setItemEnabled(2, true);
369 font_size->blockSignals(true);
370 font_family->blockSignals(true);
371 buttonBold->blockSignals(true);
372 buttonItalic->blockSignals(true);
373 buttonUnder->blockSignals(true);
374 fontColorButton->blockSignals(true);
375 textAlpha->blockSignals(true);
377 QFont font = i->font();
378 font_family->setCurrentFont(font);
379 font_size->setValue(font.pointSize());
380 buttonBold->setChecked(font.bold());
381 buttonItalic->setChecked(font.italic());
382 buttonUnder->setChecked(font.underline());
384 QColor color = i->defaultTextColor();
385 fontColorButton->setColor(color);
386 textAlpha->setValue(color.alpha());
388 font_size->blockSignals(false);
389 font_family->blockSignals(false);
390 buttonBold->blockSignals(false);
391 buttonItalic->blockSignals(false);
392 buttonUnder->blockSignals(false);
393 fontColorButton->blockSignals(false);
394 textAlpha->blockSignals(false);
396 value_x->setValue((int) i->pos().x());
397 value_y->setValue((int) i->pos().y());
398 value_w->setValue((int) i->boundingRect().width());
399 value_h->setValue((int) i->boundingRect().height());
400 frame_properties->setEnabled(true);
401 value_w->setEnabled(false);
402 value_h->setEnabled(false);
403 } else if ((l[0])->type() == 3) {
404 rect_properties->setHidden(false);
405 text_properties->setHidden(true);
407 QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
408 toolBox->setCurrentIndex(0);
409 //toolBox->setItemEnabled(3, true);
410 rectFAlpha->setValue(rec->pen().color().alpha());
411 rectBAlpha->setValue(rec->brush().color().alpha());
412 kDebug() << rec->brush().color().alpha();
413 QColor fcol = rec->pen().color();
414 QColor bcol = rec->brush().color();
415 //fcol.setAlpha(255);
416 //bcol.setAlpha(255);
417 rectFColor->setColor(fcol);
418 rectBColor->setColor(bcol);
420 rectLineWidth->setValue(rec->pen().width());
421 value_x->setValue((int) rec->pos().x());
422 value_y->setValue((int) rec->pos().y());
423 value_w->setValue((int) rec->rect().width());
424 value_h->setValue((int) rec->rect().height());
425 frame_properties->setEnabled(true);
426 value_w->setEnabled(true);
427 value_h->setEnabled(true);
429 //toolBox->setCurrentIndex(0);
430 frame_properties->setEnabled(false);
432 zValue->setValue((int)l[0]->zValue());
433 itemzoom->setValue((int)(transformations[l[0]].scalex * 100));
434 itemrotate->setValue((int)(transformations[l[0]].rotate));
435 value_x->blockSignals(false);
436 value_y->blockSignals(false);
437 value_w->blockSignals(false);
438 value_h->blockSignals(false);
439 } else frame_properties->setEnabled(false);
442 void TitleWidget::slotAdjustSelectedItem() {
443 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
445 if (l[0]->type() == 3) {
447 QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
448 rec->setPos(value_x->value(), value_y->value());
449 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
450 } else if (l[0]->type() == 8) {
452 QGraphicsTextItem *rec = ((QGraphicsTextItem*)l[0]);
453 rec->setPos(value_x->value(), value_y->value());
458 void TitleWidget::slotChangeBackground() {
459 QColor color = kcolorbutton->color();
460 color.setAlpha(horizontalSlider->value());
461 m_frameBorder->setBrush(QBrush(color));
464 void TitleWidget::textChanged() {
465 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
466 if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
467 //kDebug() << ktextedit->document()->toHtml();
468 //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
472 void TitleWidget::slotUpdateText() {
473 QFont font = font_family->currentFont();
474 font.setPointSize(font_size->value());
475 font.setBold(buttonBold->isChecked());
476 font.setItalic(buttonItalic->isChecked());
477 font.setUnderline(buttonUnder->isChecked());
478 QColor color = fontColorButton->color();
479 color.setAlpha(textAlpha->value());
481 QGraphicsTextItem* item = NULL;
482 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
483 if (l.size() == 1 && (l[0])->type() == 8) {
484 item = (QGraphicsTextItem*)l[0];
487 //if (item->textCursor().selection ().isEmpty())
490 item->setDefaultTextColor(color);
493 QTextDocumentFragment selec = item->textCursor().selection ();
496 //if (ktextedit->textCursor().selectedText().isEmpty()) ktextedit->selectAll();
498 //ktextedit->setCurrentFont(font);
499 //ktextedit->setTextColor(color);
500 /*QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
501 if (l.size() == 1 && (l[0])->type() == 8 && l[0]->hasFocus()) {
502 QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
507 void TitleWidget::rectChanged() {
508 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
509 if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) {
510 QGraphicsRectItem *rec = (QGraphicsRectItem*)l[0];
511 QColor f = rectFColor->color();
512 f.setAlpha(rectFAlpha->value());
514 penf.setWidth(rectLineWidth->value());
516 QColor b = rectBColor->color();
517 b.setAlpha(rectBAlpha->value());
518 rec->setBrush(QBrush(b));
522 void TitleWidget::fontBold() {
523 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
524 if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
525 //ktextedit->document()->setTextOption();
529 void TitleWidget::itemScaled(int val) {
530 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
532 Transform x = transformations[l[0]];
533 x.scalex = (double)val / 100.0;
534 x.scaley = (double)val / 100.0;
536 qtrans.scale(x.scalex, x.scaley);
537 qtrans.rotate(x.rotate);
538 l[0]->setTransform(qtrans);
539 transformations[l[0]] = x;
543 void TitleWidget::itemRotate(int val) {
544 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
546 Transform x = transformations[l[0]];
547 x.rotate = (double)val;
549 qtrans.scale(x.scalex, x.scaley);
550 qtrans.rotate(x.rotate);
551 l[0]->setTransform(qtrans);
552 transformations[l[0]] = x;
556 void TitleWidget::itemHCenter() {
557 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
559 QGraphicsItem *item = l[0];
561 if (item->type() == 3) {
562 br = ((QGraphicsRectItem*)item)->rect();
563 } else br = item->boundingRect();
564 int width = (int) br.width();
565 int newPos = (int)((m_frameWidth - width) / 2);
566 item->setPos(newPos, item->pos().y());
570 void TitleWidget::itemVCenter() {
571 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
573 QGraphicsItem *item = l[0];
575 if (item->type() == 3) {
576 br = ((QGraphicsRectItem*)item)->rect();
577 } else br = item->boundingRect();
578 int height = (int) br.height();
579 int newPos = (int)((m_frameHeight - height) / 2);
580 item->setPos(item->pos().x(), newPos);
584 void TitleWidget::setupViewports() {
585 double aspect_ratio = 4.0 / 3.0;//read from project
587 QRectF sp(0, 0, 0, 0);
588 QRectF ep(0, 0, 0, 0);
590 double sv_size = startViewportSize->value();
591 double ev_size = endViewportSize->value();
592 sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio);
593 ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio);
595 startViewport->setPos(startViewportX->value(), startViewportY->value());
596 endViewport->setPos(endViewportX->value(), endViewportY->value());
598 startViewport->setPolygon(QPolygonF(sp));
599 endViewport->setPolygon(QPolygonF(ep));
603 void TitleWidget::loadTitle() {
604 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Load Title"));
605 if (!url.isEmpty()) {
606 QList<QGraphicsItem *> items = m_scene->items();
607 for (int i = 0; i < items.size(); i++) {
608 if (items.at(i)->zValue() > -1000) delete items.at(i);
610 m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
615 void TitleWidget::saveTitle(KUrl url) {
616 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Save Title"));
617 if (!url.isEmpty()) m_titledocument.saveDocument(url, startViewport, endViewport);
620 QDomDocument TitleWidget::xml() {
621 return m_titledocument.xml(startViewport, endViewport);
624 void TitleWidget::setXml(QDomDocument doc) {
625 m_titledocument.loadFromXml(doc, startViewport, endViewport);
629 QPixmap TitleWidget::renderedPixmap() {
630 QPixmap pix(m_frameWidth, m_frameHeight);
631 pix.fill(Qt::transparent);
632 QPainter painter(&pix);
633 //painter.setRenderHint( QPainter::Antialiasing );
634 m_scene->clearSelection();
635 QPen framepen = m_frameBorder->pen();
636 m_frameBorder->setPen(Qt::NoPen);
637 startViewport->setVisible(false);
638 endViewport->setVisible(false);
639 m_frameImage->setVisible(false);
641 m_scene->render(&painter, QRectF(), QRectF(0, 0, m_frameWidth, m_frameHeight));
642 m_frameBorder->setPen(framepen);
643 startViewport->setVisible(true);
644 endViewport->setVisible(true);
645 m_frameImage->setVisible(true);
649 #include "moc_titlewidget.cpp"