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 // kcolorbutton == The color of the background
51 connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
52 // horizontalslider == The alpha of the background
53 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
54 //connect(ktextedit, SIGNAL(textChanged()), this , SLOT(textChanged()));
55 //connect (fontBold, SIGNAL ( clicked()), this, SLOT( setBold()) ) ;
58 //ktextedit->setHidden(true);
59 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
60 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
61 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
62 connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
63 //connect (ktextedit, SIGNAL(selectionChanged()), this , SLOT (textChanged()));
65 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
66 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
67 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
68 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
69 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
71 connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
72 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
73 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
74 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
75 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
76 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
78 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
79 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
80 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
81 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
82 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
84 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
85 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
86 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
87 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
88 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
89 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
90 connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
91 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
92 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
93 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
96 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
98 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
99 buttonRealSize->setIcon(KIcon("zoom-original"));
100 buttonBold->setIcon(KIcon("format-text-bold"));
101 buttonItalic->setIcon(KIcon("format-text-italic"));
102 buttonUnder->setIcon(KIcon("format-text-underline"));
104 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
105 itemhcenter->setToolTip(i18n("Align item horizontally"));
106 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
107 itemvcenter->setToolTip(i18n("Align item vertically"));
109 QHBoxLayout *layout = new QHBoxLayout;
110 frame_toolbar->setLayout(layout);
111 layout->setContentsMargins(2, 2, 2, 2);
112 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
114 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), i18n("Add Rectangle"));
115 m_buttonRect->setCheckable(true);
116 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
118 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), i18n("Add Text"));
119 m_buttonText->setCheckable(true);
120 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
122 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image"));
123 m_buttonImage->setCheckable(false);
124 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
126 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), i18n("Selection Tool"));
127 m_buttonCursor->setCheckable(true);
128 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
130 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
131 m_buttonLoad->setCheckable(false);
132 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
134 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
135 m_buttonSave->setCheckable(false);
136 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
138 layout->addWidget(m_toolbar);
139 text_properties->setHidden(true);
141 // initialize graphic scene
142 m_scene = new GraphicsSceneRectMove(this);
143 graphicsView->setScene(m_scene);
144 m_titledocument.setScene(m_scene);
146 // a gradient background
147 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
148 gradient->setSpread(QGradient::ReflectSpread);
149 scene->setBackgroundBrush(*gradient);*/
151 m_frameImage = new QGraphicsPixmapItem();
153 qtrans.scale(2.0, 2.0);
154 m_frameImage->setTransform(qtrans);
155 m_frameImage->setZValue(-1200);
156 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
157 displayBackgroundFrame();
158 graphicsView->scene()->addItem(m_frameImage);
160 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
161 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
162 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
163 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
164 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
165 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
166 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
167 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
169 QPen framepen(Qt::DotLine);
170 framepen.setColor(Qt::red);
172 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
173 m_frameBorder->setPen(framepen);
174 m_frameBorder->setZValue(-1100);
175 m_frameBorder->setBrush(Qt::transparent);
176 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
177 graphicsView->scene()->addItem(m_frameBorder);
179 // mbd: load saved settings
183 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
184 graphicsView->show();
185 //graphicsView->setRenderHint(QPainter::Antialiasing);
186 graphicsView->setInteractive(true);
187 //graphicsView->resize(400, 300);
188 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
189 toolBox->setItemEnabled(2, false);
190 if (!url.isEmpty()) {
191 m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
199 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl) {
201 QString titlePath = projectUrl.path() + "/titles/";
202 KStandardDirs::makeDir(titlePath);
203 QString titleName = "title";
205 QString path = titlePath + titleName + QString::number(counter).rightJustified(3, '0', false);
206 while (QFile::exists(path + ".png")) {
208 path = titlePath + titleName + QString::number(counter).rightJustified(3, '0', false);
210 result.append(titleName + QString::number(counter).rightJustified(3, '0', false));
211 result.append(path + ".png");
215 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName) {
217 QString titlePath = projectUrl.path() + "/titles/";
218 KStandardDirs::makeDir(titlePath);
219 return titlePath + titleName + ".png";
223 void TitleWidget::resizeEvent(QResizeEvent * event) {
227 void TitleWidget::slotTextTool() {
228 rect_properties->setHidden(true);
229 text_properties->setHidden(false);
230 m_scene->setTool(TITLE_TEXT);
231 m_buttonRect->setChecked(false);
232 m_buttonCursor->setChecked(false);
235 void TitleWidget::slotRectTool() {
236 text_properties->setHidden(true);
237 rect_properties->setHidden(false);
238 m_scene->setTool(TITLE_RECTANGLE);
239 m_buttonText->setChecked(false);
240 m_buttonCursor->setChecked(false);
241 m_buttonRect->setChecked(true);
244 void TitleWidget::slotSelectTool() {
245 m_scene->setTool(TITLE_SELECT);
246 m_buttonCursor->setChecked(true);
247 m_buttonText->setChecked(false);
248 m_buttonRect->setChecked(false);
251 void TitleWidget::slotImageTool() {
252 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
253 if (!url.isEmpty()) {
254 if (url.path().endsWith(".svg")) {
255 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
256 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
257 svg->setZValue(m_count++);
258 svg->setData(Qt::UserRole, url.path());
259 graphicsView->scene()->addItem(svg);
261 QPixmap pix(url.path());
262 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
263 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
264 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
265 image->setData(Qt::UserRole, url.path());
266 image->setZValue(m_count++);
267 graphicsView->scene()->addItem(image);
270 m_scene->setTool(TITLE_SELECT);
271 m_buttonRect->setChecked(false);
272 m_buttonCursor->setChecked(true);
273 m_buttonText->setChecked(false);
276 void TitleWidget::displayBackgroundFrame() {
277 if (!displayBg->isChecked()) {
278 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
279 QPixmap pattern(20, 20);
283 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
284 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
289 p.fillRect(bg.rect(), br);
291 m_frameImage->setPixmap(bg);
293 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
297 void TitleWidget::initViewports() {
298 startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
299 endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
301 QPen startpen(Qt::DotLine);
302 QPen endpen(Qt::DashDotLine);
303 startpen.setColor(QColor(100, 200, 100, 140));
304 endpen.setColor(QColor(200, 100, 100, 140));
306 startViewport->setPen(startpen);
307 endViewport->setPen(endpen);
309 startViewportSize->setValue(40);
310 endViewportSize->setValue(40);
312 startViewport->setZValue(-1000);
313 endViewport->setZValue(-1000);
315 startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
316 endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
318 graphicsView->scene()->addItem(startViewport);
319 graphicsView->scene()->addItem(endViewport);
322 void TitleWidget::slotUpdateZoom(int pos) {
323 m_scene->setZoom((double) pos / 100);
324 zoom_label->setText(QString::number(pos) + "%");
327 void TitleWidget::slotZoom(bool up) {
328 int pos = zoom_slider->value();
331 zoom_slider->setValue(pos);
334 void TitleWidget::slotAdjustZoom() {
335 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
336 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
337 if (scalex > scaley) scalex = scaley;
338 int zoompos = (int)(scalex * 7 + 0.5);*/
339 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
340 int zoompos = graphicsView->matrix().m11() * 100;
341 zoom_slider->setValue(zoompos);
342 graphicsView->centerOn(m_frameBorder);
345 void TitleWidget::slotZoomOneToOne() {
346 zoom_slider->setValue(100);
347 graphicsView->centerOn(m_frameBorder);
350 void TitleWidget::slotNewRect(QGraphicsRectItem * rect) {
351 QColor f = rectFColor->color();
352 f.setAlpha(rectFAlpha->value());
354 penf.setWidth(rectLineWidth->value());
356 QColor b = rectBColor->color();
357 b.setAlpha(rectBAlpha->value());
358 rect->setBrush(QBrush(b));
359 rect->setZValue(m_count++);
360 //setCurrentItem(rect);
361 //graphicsView->setFocus();
364 void TitleWidget::slotNewText(QGraphicsTextItem *tt) {
365 QFont font = font_family->currentFont();
366 font.setPointSize(font_size->value());
368 font.setBold(buttonBold->isChecked());
369 font.setItalic(buttonItalic->isChecked());
370 font.setUnderline(buttonUnder->isChecked());
373 QColor color = fontColorButton->color();
374 color.setAlpha(textAlpha->value());
375 tt->setDefaultTextColor(color);
376 tt->setZValue(m_count++);
380 void TitleWidget::setCurrentItem(QGraphicsItem *item) {
381 m_scene->setSelectedItem(item);
384 void TitleWidget::zIndexChanged(int v) {
385 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
391 void TitleWidget::selectionChanged() {
392 if (m_scene->tool() != TITLE_SELECT) return;
393 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
394 //toolBox->setItemEnabled(2, false);
395 //toolBox->setItemEnabled(3, false);
396 value_x->blockSignals(true);
397 value_y->blockSignals(true);
398 value_w->blockSignals(true);
399 value_h->blockSignals(true);
400 //kDebug() << "//////// SELECTION CHANGED; ITEMS: " << l.size();
402 if ((l[0])->type() == 8) {
403 rect_properties->setHidden(true);
404 text_properties->setHidden(false);
405 QGraphicsTextItem* i = ((QGraphicsTextItem*)l[0]);
406 //if (l[0]->hasFocus())
407 //ktextedit->setHtml(i->toHtml());
408 toolBox->setCurrentIndex(0);
409 //toolBox->setItemEnabled(2, true);
410 font_size->blockSignals(true);
411 font_family->blockSignals(true);
412 buttonBold->blockSignals(true);
413 buttonItalic->blockSignals(true);
414 buttonUnder->blockSignals(true);
415 fontColorButton->blockSignals(true);
416 textAlpha->blockSignals(true);
418 QFont font = i->font();
419 font_family->setCurrentFont(font);
420 font_size->setValue(font.pointSize());
421 buttonBold->setChecked(font.bold());
422 buttonItalic->setChecked(font.italic());
423 buttonUnder->setChecked(font.underline());
425 QColor color = i->defaultTextColor();
426 fontColorButton->setColor(color);
427 textAlpha->setValue(color.alpha());
429 font_size->blockSignals(false);
430 font_family->blockSignals(false);
431 buttonBold->blockSignals(false);
432 buttonItalic->blockSignals(false);
433 buttonUnder->blockSignals(false);
434 fontColorButton->blockSignals(false);
435 textAlpha->blockSignals(false);
437 value_x->setValue((int) i->pos().x());
438 value_y->setValue((int) i->pos().y());
439 value_w->setValue((int) i->boundingRect().width());
440 value_h->setValue((int) i->boundingRect().height());
441 frame_properties->setEnabled(true);
442 value_w->setEnabled(false);
443 value_h->setEnabled(false);
444 } else if ((l[0])->type() == 3) {
445 rect_properties->setHidden(false);
446 text_properties->setHidden(true);
448 QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
449 toolBox->setCurrentIndex(0);
450 //toolBox->setItemEnabled(3, true);
451 rectFAlpha->setValue(rec->pen().color().alpha());
452 rectBAlpha->setValue(rec->brush().color().alpha());
453 //kDebug() << rec->brush().color().alpha();
454 QColor fcol = rec->pen().color();
455 QColor bcol = rec->brush().color();
456 //fcol.setAlpha(255);
457 //bcol.setAlpha(255);
458 rectFColor->setColor(fcol);
459 rectBColor->setColor(bcol);
461 rectLineWidth->setValue(rec->pen().width());
462 value_x->setValue((int) rec->pos().x());
463 value_y->setValue((int) rec->pos().y());
464 value_w->setValue((int) rec->rect().width());
465 value_h->setValue((int) rec->rect().height());
466 frame_properties->setEnabled(true);
467 value_w->setEnabled(true);
468 value_h->setEnabled(true);
470 //toolBox->setCurrentIndex(0);
471 frame_properties->setEnabled(false);
473 zValue->setValue((int)l[0]->zValue());
474 itemzoom->setValue((int)(transformations[l[0]].scalex * 100));
475 itemrotate->setValue((int)(transformations[l[0]].rotate));
476 value_x->blockSignals(false);
477 value_y->blockSignals(false);
478 value_w->blockSignals(false);
479 value_h->blockSignals(false);
480 } else frame_properties->setEnabled(false);
483 void TitleWidget::slotAdjustSelectedItem() {
484 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
486 if (l[0]->type() == 3) {
488 QGraphicsRectItem *rec = ((QGraphicsRectItem*)l[0]);
489 rec->setPos(value_x->value(), value_y->value());
490 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
491 } else if (l[0]->type() == 8) {
493 QGraphicsTextItem *rec = ((QGraphicsTextItem*)l[0]);
494 rec->setPos(value_x->value(), value_y->value());
499 void TitleWidget::slotChangeBackground() {
500 QColor color = kcolorbutton->color();
501 color.setAlpha(horizontalSlider->value());
502 m_frameBorder->setBrush(QBrush(color));
505 void TitleWidget::textChanged() {
506 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
507 if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
508 //kDebug() << ktextedit->document()->toHtml();
509 //((QGraphicsTextItem*)l[0])->setHtml(ktextedit->toHtml());
513 void TitleWidget::slotUpdateText() {
514 QFont font = font_family->currentFont();
515 font.setPointSize(font_size->value());
516 font.setBold(buttonBold->isChecked());
517 font.setItalic(buttonItalic->isChecked());
518 font.setUnderline(buttonUnder->isChecked());
519 QColor color = fontColorButton->color();
520 color.setAlpha(textAlpha->value());
522 QGraphicsTextItem* item = NULL;
523 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
524 if (l.size() == 1 && (l[0])->type() == 8) {
525 item = (QGraphicsTextItem*)l[0];
528 //if (item->textCursor().selection ().isEmpty())
531 item->setDefaultTextColor(color);
534 QTextDocumentFragment selec = item->textCursor().selection ();
537 //if (ktextedit->textCursor().selectedText().isEmpty()) ktextedit->selectAll();
539 //ktextedit->setCurrentFont(font);
540 //ktextedit->setTextColor(color);
541 /*QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
542 if (l.size() == 1 && (l[0])->type() == 8 && l[0]->hasFocus()) {
543 QGraphicsTextItem* item = static_cast <QGraphicsTextItem*> (l[0]);
548 void TitleWidget::rectChanged() {
549 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
550 if (l.size() == 1 && (l[0])->type() == 3 && !settingUp) {
551 QGraphicsRectItem *rec = (QGraphicsRectItem*)l[0];
552 QColor f = rectFColor->color();
553 f.setAlpha(rectFAlpha->value());
555 penf.setWidth(rectLineWidth->value());
557 QColor b = rectBColor->color();
558 b.setAlpha(rectBAlpha->value());
559 rec->setBrush(QBrush(b));
563 void TitleWidget::fontBold() {
564 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
565 if (l.size() == 1 && (l[0])->type() == 8 && !l[0]->hasFocus()) {
566 //ktextedit->document()->setTextOption();
570 void TitleWidget::itemScaled(int val) {
571 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
573 Transform x = transformations[l[0]];
574 x.scalex = (double)val / 100.0;
575 x.scaley = (double)val / 100.0;
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::itemRotate(int val) {
585 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
587 Transform x = transformations[l[0]];
588 x.rotate = (double)val;
590 qtrans.scale(x.scalex, x.scaley);
591 qtrans.rotate(x.rotate);
592 l[0]->setTransform(qtrans);
593 transformations[l[0]] = x;
597 void TitleWidget::itemHCenter() {
598 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
600 QGraphicsItem *item = l[0];
602 if (item->type() == 3) {
603 br = ((QGraphicsRectItem*)item)->rect();
604 } else br = item->boundingRect();
605 int width = (int) br.width();
606 int newPos = (int)((m_frameWidth - width) / 2);
607 item->setPos(newPos, item->pos().y());
611 void TitleWidget::itemVCenter() {
612 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
614 QGraphicsItem *item = l[0];
616 if (item->type() == 3) {
617 br = ((QGraphicsRectItem*)item)->rect();
618 } else br = item->boundingRect();
619 int height = (int) br.height();
620 int newPos = (int)((m_frameHeight - height) / 2);
621 item->setPos(item->pos().x(), newPos);
625 void TitleWidget::setupViewports() {
626 double aspect_ratio = 4.0 / 3.0;//read from project
628 QRectF sp(0, 0, 0, 0);
629 QRectF ep(0, 0, 0, 0);
631 double sv_size = startViewportSize->value();
632 double ev_size = endViewportSize->value();
633 sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio);
634 ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio);
636 startViewport->setPos(startViewportX->value(), startViewportY->value());
637 endViewport->setPos(endViewportX->value(), endViewportY->value());
639 startViewport->setPolygon(QPolygonF(sp));
640 endViewport->setPolygon(QPolygonF(ep));
644 void TitleWidget::loadTitle() {
645 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Load Title"));
646 if (!url.isEmpty()) {
647 QList<QGraphicsItem *> items = m_scene->items();
648 for (int i = 0; i < items.size(); i++) {
649 if (items.at(i)->zValue() > -1000) delete items.at(i);
651 m_count = m_titledocument.loadDocument(url, startViewport, endViewport) + 1;
656 void TitleWidget::saveTitle(KUrl url) {
657 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Save Title"));
658 if (!url.isEmpty()) m_titledocument.saveDocument(url, startViewport, endViewport);
661 QDomDocument TitleWidget::xml() {
662 return m_titledocument.xml(startViewport, endViewport);
665 void TitleWidget::setXml(QDomDocument doc) {
666 m_count = m_titledocument.loadFromXml(doc, startViewport, endViewport);
667 // mbd: Update the GUI color selectors to match the stuff from the loaded document
668 QColor background_color = m_titledocument.getBackgroundColor();
669 horizontalSlider->blockSignals(true);
670 kcolorbutton->blockSignals(true);
671 horizontalSlider->setValue(background_color.alpha());
672 background_color.setAlpha(255);
673 kcolorbutton->setColor(background_color);
674 horizontalSlider->blockSignals(false);
675 kcolorbutton->blockSignals(false);
680 QPixmap TitleWidget::renderedPixmap() {
681 QPixmap pix(m_frameWidth, m_frameHeight);
682 pix.fill(Qt::transparent);
683 QPainter painter(&pix);
684 painter.setRenderHint(QPainter::Antialiasing);
685 m_scene->clearTextSelection();
686 QPen framepen = m_frameBorder->pen();
687 m_frameBorder->setPen(Qt::NoPen);
688 startViewport->setVisible(false);
689 endViewport->setVisible(false);
690 m_frameImage->setVisible(false);
692 m_scene->render(&painter, QRectF(), QRectF(0, 0, m_frameWidth, m_frameHeight));
693 m_frameBorder->setPen(framepen);
694 startViewport->setVisible(true);
695 endViewport->setVisible(true);
696 m_frameImage->setVisible(true);
700 /** \brief Connected to the accepted signal - calls writeChoices */
701 void TitleWidget::slotAccepted() {
705 /** \brief Store the current choices of font, background and rect values */
706 void TitleWidget::writeChoices() {
707 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
708 KSharedConfigPtr config = KGlobal::config();
709 KConfigGroup titleConfig(config, "TitleWidget");
711 titleConfig.writeEntry("font_family", font_family->currentFont());
712 titleConfig.writeEntry("font_size", font_size->value());
713 titleConfig.writeEntry("font_color", fontColorButton->color());
714 titleConfig.writeEntry("font_alpha", textAlpha->value());
715 titleConfig.writeEntry("font_bold", buttonBold->isChecked());
716 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
717 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
719 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
720 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
721 titleConfig.writeEntry("rect_background_color", rectBColor->color());
722 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
723 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
725 titleConfig.writeEntry("background_color", kcolorbutton->color());
726 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
727 //! \todo Not sure if I should sync - it is probably safe to do it
732 /** \brief Read the last stored choices into the dialog */
733 void TitleWidget::readChoices() {
734 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
735 KSharedConfigPtr config = KGlobal::config();
736 KConfigGroup titleConfig(config, "TitleWidget");
738 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
739 font_size->setValue(titleConfig.readEntry("font_size", font_size->value()));
740 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
741 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
742 buttonBold->setChecked(titleConfig.readEntry("font_bold", buttonBold->isChecked()));
743 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
744 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
746 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
747 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
748 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
749 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
750 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
752 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
753 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
755 #include "moc_titlewidget.cpp"