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>
32 #include <KStandardDirs>
34 #include "titlewidget.h"
35 #include "kdenlivesettings.h"
37 int settingUp = false;
39 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 rect_properties->setFixedHeight(frame_properties->height() + 4);
45 text_properties->setFixedHeight(frame_properties->height() + 4);
46 m_frameWidth = render->renderWidth();
47 m_frameHeight = render->renderHeight();
48 //connect(newTextButton, SIGNAL(clicked()), this, SLOT(slotNewText()));
49 //connect(newRectButton, SIGNAL(clicked()), this, SLOT(slotNewRect()));
50 connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
51 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
52 //connect(ktextedit, SIGNAL(textChanged()), this , SLOT(textChanged()));
53 //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ;
56 //ktextedit->setHidden(true);
57 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
58 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
59 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
60 connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
61 //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged()));
63 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
64 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
65 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
66 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
67 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
69 connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
70 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
71 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
72 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
73 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
74 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
76 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
77 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
78 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
79 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
80 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
82 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
83 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
84 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
85 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
86 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
87 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
88 connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
89 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
90 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
91 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
93 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
94 buttonRealSize->setIcon(KIcon("zoom-original"));
95 buttonBold->setIcon(KIcon("format-text-bold"));
96 buttonItalic->setIcon(KIcon("format-text-italic"));
97 buttonUnder->setIcon(KIcon("format-text-underline"));
99 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
100 itemhcenter->setToolTip(i18n("Align item horizontally"));
101 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
102 itemvcenter->setToolTip(i18n("Align item vertically"));
104 QHBoxLayout *layout = new QHBoxLayout;
105 frame_toolbar->setLayout(layout);
106 layout->setContentsMargins(2, 2, 2, 2);
107 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
109 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), i18n("Add Rectangle"));
110 m_buttonRect->setCheckable(true);
111 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
113 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), i18n("Add Text"));
114 m_buttonText->setCheckable(true);
115 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
117 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image"));
118 m_buttonImage->setCheckable(false);
119 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
121 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), i18n("Selection Tool"));
122 m_buttonCursor->setCheckable(true);
123 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
125 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
126 m_buttonLoad->setCheckable(false);
127 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
129 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
130 m_buttonSave->setCheckable(false);
131 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
133 layout->addWidget(m_toolbar);
134 text_properties->setHidden(true);
136 // initialize graphic scene
137 m_scene = new GraphicsSceneRectMove(this);
138 graphicsView->setScene(m_scene);
139 m_titledocument.setScene(m_scene);
141 // a gradient background
142 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
143 gradient->setSpread(QGradient::ReflectSpread);
144 scene->setBackgroundBrush(*gradient);*/
146 m_frameImage = new QGraphicsPixmapItem();
148 qtrans.scale(2.0, 2.0);
149 m_frameImage->setTransform(qtrans);
150 m_frameImage->setZValue(-1200);
151 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
152 displayBackgroundFrame();
153 graphicsView->scene()->addItem(m_frameImage);
155 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
156 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
157 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
158 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
159 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
160 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
161 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
162 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
164 QPen framepen(Qt::DotLine);
165 framepen.setColor(Qt::red);
167 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
168 m_frameBorder->setPen(framepen);
169 m_frameBorder->setZValue(-1100);
170 m_frameBorder->setBrush(Qt::transparent);
171 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
172 graphicsView->scene()->addItem(m_frameBorder);
175 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
176 graphicsView->show();
177 //graphicsView->setRenderHint(QPainter::Antialiasing);
178 graphicsView->setInteractive(true);
179 //graphicsView->resize(400, 300);
180 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
181 toolBox->setItemEnabled(2, false);
182 if (!url.isEmpty()) {
183 m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
191 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl) {
193 QString titlePath = projectUrl.path() + "/titles/";
194 KStandardDirs::makeDir(titlePath);
195 QString titleName = "title";
197 QString path = titlePath + titleName + QString::number(counter).rightJustified(3, '0', false);
198 while (QFile::exists(path + ".png")) {
200 path = titlePath + titleName + QString::number(counter).rightJustified(3, '0', false);
202 result.append(titleName + QString::number(counter).rightJustified(3, '0', false));
203 result.append(path + ".png");
207 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName) {
209 QString titlePath = projectUrl.path() + "/titles/";
210 KStandardDirs::makeDir(titlePath);
211 return titlePath + titleName + ".png";
215 void TitleWidget::resizeEvent(QResizeEvent * event) {
219 void TitleWidget::slotTextTool() {
220 rect_properties->setHidden(true);
221 text_properties->setHidden(false);
222 m_scene->setTool(TITLE_TEXT);
223 m_buttonRect->setChecked(false);
224 m_buttonCursor->setChecked(false);
227 void TitleWidget::slotRectTool() {
228 text_properties->setHidden(true);
229 rect_properties->setHidden(false);
230 m_scene->setTool(TITLE_RECTANGLE);
231 m_buttonText->setChecked(false);
232 m_buttonCursor->setChecked(false);
233 m_buttonRect->setChecked(true);
236 void TitleWidget::slotSelectTool() {
237 m_scene->setTool(TITLE_SELECT);
238 m_buttonCursor->setChecked(true);
239 m_buttonText->setChecked(false);
240 m_buttonRect->setChecked(false);
243 void TitleWidget::slotImageTool() {
244 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
245 if (!url.isEmpty()) {
246 if (url.path().endsWith(".svg")) {
247 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
248 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
249 svg->setZValue(m_count++);
250 svg->setData(Qt::UserRole, url.path());
251 graphicsView->scene()->addItem(svg);
253 QPixmap pix(url.path());
254 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
255 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
256 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
257 image->setData(Qt::UserRole, url.path());
258 image->setZValue(m_count++);
259 graphicsView->scene()->addItem(image);
262 m_scene->setTool(TITLE_SELECT);
263 m_buttonRect->setChecked(false);
264 m_buttonCursor->setChecked(true);
265 m_buttonText->setChecked(false);
268 void TitleWidget::displayBackgroundFrame() {
269 if (!displayBg->isChecked()) {
270 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
271 QPixmap pattern(20, 20);
275 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
276 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
281 p.fillRect(bg.rect(), br);
283 m_frameImage->setPixmap(bg);
285 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
289 void TitleWidget::initViewports() {
290 startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
291 endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
293 QPen startpen(Qt::DotLine);
294 QPen endpen(Qt::DashDotLine);
295 startpen.setColor(QColor(100, 200, 100, 140));
296 endpen.setColor(QColor(200, 100, 100, 140));
298 startViewport->setPen(startpen);
299 endViewport->setPen(endpen);
301 startViewportSize->setValue(40);
302 endViewportSize->setValue(40);
304 startViewport->setZValue(-1000);
305 endViewport->setZValue(-1000);
307 startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
308 endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
310 graphicsView->scene()->addItem(startViewport);
311 graphicsView->scene()->addItem(endViewport);
314 void TitleWidget::slotUpdateZoom(int pos) {
315 m_scene->setZoom((double) pos / 100);
316 zoom_label->setText(QString::number(pos) + "%");
319 void TitleWidget::slotZoom(bool up) {
320 int pos = zoom_slider->value();
323 zoom_slider->setValue(pos);
326 void TitleWidget::slotAdjustZoom() {
327 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
328 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
329 if (scalex > scaley) scalex = scaley;
330 int zoompos = (int)(scalex * 7 + 0.5);*/
331 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
332 int zoompos = graphicsView->matrix().m11() * 100;
333 zoom_slider->setValue(zoompos);
334 graphicsView->centerOn(m_frameBorder);
337 void TitleWidget::slotZoomOneToOne() {
338 zoom_slider->setValue(100);
339 graphicsView->centerOn(m_frameBorder);
342 void TitleWidget::slotNewRect(QGraphicsRectItem * rect) {
343 QColor f = rectFColor->color();
344 f.setAlpha(rectFAlpha->value());
346 penf.setWidth(rectLineWidth->value());
348 QColor b = rectBColor->color();
349 b.setAlpha(rectBAlpha->value());
350 rect->setBrush(QBrush(b));
351 rect->setZValue(m_count++);
352 //setCurrentItem(rect);
353 //graphicsView->setFocus();
356 void TitleWidget::slotNewText(QGraphicsTextItem *tt) {
357 QFont font = font_family->currentFont();
358 font.setPointSize(font_size->value());
360 QColor color = fontColorButton->color();
361 color.setAlpha(textAlpha->value());
362 tt->setDefaultTextColor(color);
363 tt->setZValue(m_count++);
367 void TitleWidget::setCurrentItem(QGraphicsItem *item) {
368 m_scene->setSelectedItem(item);
371 void TitleWidget::zIndexChanged(int v) {
372 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
378 void TitleWidget::selectionChanged() {
379 if (m_scene->tool() != TITLE_SELECT) return;
380 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
381 //toolBox->setItemEnabled(2, false);
382 //toolBox->setItemEnabled(3, false);
383 value_x->blockSignals(true);
384 value_y->blockSignals(true);
385 value_w->blockSignals(true);
386 value_h->blockSignals(true);
387 //kDebug() << "//////// SELECTION CHANGED; ITEMS: " << l.size();
389 if ((l[0])->type() == 8) {
390 rect_properties->setHidden(true);
391 text_properties->setHidden(false);
392 QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]);
393 //if (l[0]->hasFocus())
394 //ktextedit->setHtml(i->toHtml());
395 toolBox->setCurrentIndex(0);
396 //toolBox->setItemEnabled(2, true);
397 font_size->blockSignals(true);
398 font_family->blockSignals(true);
399 buttonBold->blockSignals(true);
400 buttonItalic->blockSignals(true);
401 buttonUnder->blockSignals(true);
402 fontColorButton->blockSignals(true);
403 textAlpha->blockSignals(true);
405 QFont font = i->font();
406 font_family->setCurrentFont(font);
407 font_size->setValue(font.pointSize());
408 buttonBold->setChecked(font.bold());
409 buttonItalic->setChecked(font.italic());
410 buttonUnder->setChecked(font.underline());
412 QColor color = i->defaultTextColor();
413 fontColorButton->setColor(color);
414 textAlpha->setValue(color.alpha());
416 font_size->blockSignals(false);
417 font_family->blockSignals(false);
418 buttonBold->blockSignals(false);
419 buttonItalic->blockSignals(false);
420 buttonUnder->blockSignals(false);
421 fontColorButton->blockSignals(false);
422 textAlpha->blockSignals(false);
424 value_x->setValue((int) i->pos().x());
425 value_y->setValue((int) i->pos().y());
426 value_w->setValue((int) i->boundingRect().width());
427 value_h->setValue((int) i->boundingRect().height());
428 frame_properties->setEnabled(true);
429 value_w->setEnabled(false);
430 value_h->setEnabled(false);
431 } else if ((l[0])->type() == 3) {
432 rect_properties->setHidden(false);
433 text_properties->setHidden(true);
435 QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
436 toolBox->setCurrentIndex(0);
437 //toolBox->setItemEnabled(3, true);
438 rectFAlpha->setValue(rec->pen().color().alpha());
439 rectBAlpha->setValue(rec->brush().color().alpha());
440 //kDebug() << rec->brush().color().alpha();
441 QColor fcol = rec->pen().color();
442 QColor bcol = rec->brush().color();
443 //fcol.setAlpha(255);
444 //bcol.setAlpha(255);
445 rectFColor->setColor(fcol);
446 rectBColor->setColor(bcol);
448 rectLineWidth->setValue(rec->pen().width());
449 value_x->setValue((int) rec->pos().x());
450 value_y->setValue((int) rec->pos().y());
451 value_w->setValue((int) rec->rect().width());
452 value_h->setValue((int) rec->rect().height());
453 frame_properties->setEnabled(true);
454 value_w->setEnabled(true);
455 value_h->setEnabled(true);
457 //toolBox->setCurrentIndex(0);
458 frame_properties->setEnabled(false);
460 zValue->setValue((int)l[0]->zValue());
461 itemzoom->setValue((int)(transformations[l[0]].scalex * 100));
462 itemrotate->setValue((int)(transformations[l[0]].rotate));
463 value_x->blockSignals(false);
464 value_y->blockSignals(false);
465 value_w->blockSignals(false);
466 value_h->blockSignals(false);
467 } else frame_properties->setEnabled(false);
470 void TitleWidget::slotAdjustSelectedItem() {
471 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
473 if (l[0]->type() == 3) {
475 QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
476 rec->setPos(value_x->value(), value_y->value());
477 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
478 } else if (l[0]->type() == 8) {
480 QGraphicsTextItem *rec = ((QGraphicsTextItem*)l[0]);
481 rec->setPos(value_x->value(), value_y->value());
486 void TitleWidget::slotChangeBackground() {
487 QColor color = kcolorbutton->color();
488 color.setAlpha(horizontalSlider->value());
489 m_frameBorder->setBrush(QBrush(color));
492 void TitleWidget::textChanged() {
493 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
494 if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
495 //kDebug() << ktextedit->document()->toHtml();
496 //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
500 void TitleWidget::slotUpdateText() {
501 QFont font = font_family->currentFont();
502 font.setPointSize(font_size->value());
503 font.setBold(buttonBold->isChecked());
504 font.setItalic(buttonItalic->isChecked());
505 font.setUnderline(buttonUnder->isChecked());
506 QColor color = fontColorButton->color();
507 color.setAlpha(textAlpha->value());
509 QGraphicsTextItem* item = NULL;
510 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
511 if (l.size() == 1 && (l[0])->type() == 8) {
512 item = (QGraphicsTextItem*)l[0];
515 //if (item->textCursor().selection ().isEmpty())
518 item->setDefaultTextColor(color);
521 QTextDocumentFragment selec = item->textCursor().selection ();
524 //if (ktextedit->textCursor().selectedText().isEmpty()) ktextedit->selectAll();
526 //ktextedit->setCurrentFont(font);
527 //ktextedit->setTextColor(color);
528 /*QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
529 if (l.size() == 1 && (l[0])->type() == 8 && l[0]->hasFocus()) {
530 QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
535 void TitleWidget::rectChanged() {
536 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
537 if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) {
538 QGraphicsRectItem *rec = (QGraphicsRectItem*)l[0];
539 QColor f = rectFColor->color();
540 f.setAlpha(rectFAlpha->value());
542 penf.setWidth(rectLineWidth->value());
544 QColor b = rectBColor->color();
545 b.setAlpha(rectBAlpha->value());
546 rec->setBrush(QBrush(b));
550 void TitleWidget::fontBold() {
551 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
552 if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
553 //ktextedit->document()->setTextOption();
557 void TitleWidget::itemScaled(int val) {
558 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
560 Transform x = transformations[l[0]];
561 x.scalex = (double)val / 100.0;
562 x.scaley = (double)val / 100.0;
564 qtrans.scale(x.scalex, x.scaley);
565 qtrans.rotate(x.rotate);
566 l[0]->setTransform(qtrans);
567 transformations[l[0]] = x;
571 void TitleWidget::itemRotate(int val) {
572 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
574 Transform x = transformations[l[0]];
575 x.rotate = (double)val;
577 qtrans.scale(x.scalex, x.scaley);
578 qtrans.rotate(x.rotate);
579 l[0]->setTransform(qtrans);
580 transformations[l[0]] = x;
584 void TitleWidget::itemHCenter() {
585 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
587 QGraphicsItem *item = l[0];
589 if (item->type() == 3) {
590 br = ((QGraphicsRectItem*)item)->rect();
591 } else br = item->boundingRect();
592 int width = (int) br.width();
593 int newPos = (int)((m_frameWidth - width) / 2);
594 item->setPos(newPos, item->pos().y());
598 void TitleWidget::itemVCenter() {
599 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
601 QGraphicsItem *item = l[0];
603 if (item->type() == 3) {
604 br = ((QGraphicsRectItem*)item)->rect();
605 } else br = item->boundingRect();
606 int height = (int) br.height();
607 int newPos = (int)((m_frameHeight - height) / 2);
608 item->setPos(item->pos().x(), newPos);
612 void TitleWidget::setupViewports() {
613 double aspect_ratio = 4.0 / 3.0;//read from project
615 QRectF sp(0, 0, 0, 0);
616 QRectF ep(0, 0, 0, 0);
618 double sv_size = startViewportSize->value();
619 double ev_size = endViewportSize->value();
620 sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio);
621 ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio);
623 startViewport->setPos(startViewportX->value(), startViewportY->value());
624 endViewport->setPos(endViewportX->value(), endViewportY->value());
626 startViewport->setPolygon(QPolygonF(sp));
627 endViewport->setPolygon(QPolygonF(ep));
631 void TitleWidget::loadTitle() {
632 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Load Title"));
633 if (!url.isEmpty()) {
634 QList<QGraphicsItem *> items = m_scene->items();
635 for (int i = 0; i < items.size(); i++) {
636 if (items.at(i)->zValue() > -1000) delete items.at(i);
638 m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
643 void TitleWidget::saveTitle(KUrl url) {
644 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Save Title"));
645 if (!url.isEmpty()) m_titledocument.saveDocument(url, startViewport, endViewport);
648 QDomDocument TitleWidget::xml() {
649 return m_titledocument.xml(startViewport, endViewport);
652 void TitleWidget::setXml(QDomDocument doc) {
653 m_count = m_titledocument.loadFromXml(doc, startViewport, endViewport);
657 QPixmap TitleWidget::renderedPixmap() {
658 QPixmap pix(m_frameWidth, m_frameHeight);
659 pix.fill(Qt::transparent);
660 QPainter painter(&pix);
661 painter.setRenderHint(QPainter::Antialiasing);
662 m_scene->clearTextSelection();
663 QPen framepen = m_frameBorder->pen();
664 m_frameBorder->setPen(Qt::NoPen);
665 startViewport->setVisible(false);
666 endViewport->setVisible(false);
667 m_frameImage->setVisible(false);
669 m_scene->render(&painter, QRectF(), QRectF(0, 0, m_frameWidth, m_frameHeight));
670 m_frameBorder->setPen(framepen);
671 startViewport->setVisible(true);
672 endViewport->setVisible(true);
673 m_frameImage->setVisible(true);
677 #include "moc_titlewidget.cpp"