1 /***************************************************************************
2 titlewidget.cpp - 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 ***************************************************************************/
18 #include "titlewidget.h"
19 #include "kdenlivesettings.h"
20 #include "KoSliderCombo.h"
25 #include <KGlobalSettings>
26 #include <KFileDialog>
27 #include <KStandardDirs>
28 #include <KMessageBox>
29 #include <kio/netaccess.h>
30 #include <kdeversion.h>
32 #include <QDomDocument>
33 #include <QGraphicsItem>
34 #include <QGraphicsSvgItem>
38 #include <QSignalMapper>
39 #include <QTextBlockFormat>
40 #include <QTextCursor>
42 #include <QCryptographicHash>
44 #if QT_VERSION >= 0x040600
45 #include <QGraphicsEffect>
46 #include <QGraphicsBlurEffect>
47 #include <QGraphicsDropShadowEffect>
52 static QList<TitleTemplate> titletemplates;
54 // What exactly is this variable good for?
55 int settingUp = false;
57 const int IMAGEITEM = 7;
58 const int RECTITEM = 3;
59 const int TEXTITEM = 8;
61 const int NOEFFECT = 0;
62 const int BLUREFFECT = 1;
63 const int SHADOWEFFECT = 2;
64 const int TYPEWRITEREFFECT = 3;
66 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
69 m_startViewport(NULL),
73 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
74 m_projectTitlePath(projectTitlePath),
78 setFont(KGlobalSettings::toolBarFont());
79 frame_properties->setEnabled(false);
80 frame_properties->setFixedHeight(frame_toolbar->height());
82 // Set combo sliders values
83 textAlpha->setMinimum(0);
84 textAlpha->setMaximum(255);
85 textAlpha->setDecimals(0);
86 textAlpha->setValue(255);
87 textAlpha->setToolTip(i18n("Font color opacity"));
89 textOutlineAlpha->setMinimum(0);
90 textOutlineAlpha->setMaximum(255);
91 textOutlineAlpha->setDecimals(0);
92 textOutlineAlpha->setValue(255);
93 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
95 textOutline->setMinimum(0);
96 textOutline->setMaximum(200);
97 textOutline->setDecimals(0);
98 textOutline->setValue(0);
99 textOutline->setToolTip(i18n("Outline width"));
101 backgroundAlpha->setMinimum(0);
102 backgroundAlpha->setMaximum(255);
103 backgroundAlpha->setDecimals(0);
104 backgroundAlpha->setValue(0);
105 backgroundAlpha->setToolTip(i18n("Background color opacity"));
107 itemrotatex->setMinimum(-360);
108 itemrotatex->setMaximum(360);
109 itemrotatex->setDecimals(0);
110 itemrotatex->setValue(0);
111 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
113 itemrotatey->setMinimum(-360);
114 itemrotatey->setMaximum(360);
115 itemrotatey->setDecimals(0);
116 itemrotatey->setValue(0);
117 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
119 itemrotatez->setMinimum(-360);
120 itemrotatez->setMaximum(360);
121 itemrotatez->setDecimals(0);
122 itemrotatez->setValue(0);
123 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
125 rectBAlpha->setMinimum(0);
126 rectBAlpha->setMaximum(255);
127 rectBAlpha->setDecimals(0);
128 rectBAlpha->setValue(255);
129 rectBAlpha->setToolTip(i18n("Color opacity"));
131 rectFAlpha->setMinimum(0);
132 rectFAlpha->setMaximum(255);
133 rectFAlpha->setDecimals(0);
134 rectFAlpha->setValue(255);
135 rectFAlpha->setToolTip(i18n("Border opacity"));
137 rectLineWidth->setMinimum(0);
138 rectLineWidth->setMaximum(100);
139 rectLineWidth->setDecimals(0);
140 rectLineWidth->setValue(0);
141 rectLineWidth->setToolTip(i18n("Border width"));
143 itemzoom->setSuffix(i18n("%"));
144 m_frameWidth = render->renderWidth();
145 m_frameHeight = render->renderHeight();
146 showToolbars(TITLE_SELECT);
148 //If project is drop frame, set the input mask as such.
149 title_duration->setInputMask("");
150 title_duration->setValidator(m_tc.validator());
151 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
153 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
154 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
156 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
157 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
158 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
159 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
160 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
161 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
162 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
163 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
165 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
167 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
168 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
169 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
170 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
171 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
173 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
174 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
175 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
176 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
177 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
178 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
181 effect_list->addItem(i18n("None"), NOEFFECT);
182 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
183 effect_list->addItem(i18n("Blur"), BLUREFFECT);
186 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
187 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
188 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
189 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
190 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
191 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
192 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
193 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
194 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
195 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
196 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
197 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
198 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
199 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
200 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
201 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
202 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
203 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
204 effect_stack->setHidden(true);
205 effect_frame->setEnabled(false);
207 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
208 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
210 m_signalMapper = new QSignalMapper(this);
211 m_signalMapper->setMapping(value_w, ValueWidth);
212 m_signalMapper->setMapping(value_h, ValueHeight);
213 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
214 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
215 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
217 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
218 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
219 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
220 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
221 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
222 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
223 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
224 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
225 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
226 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
227 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
228 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
229 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
231 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
234 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
236 font_weight_box->blockSignals(true);
237 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
238 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
239 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
240 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
241 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
242 font_weight_box->setToolTip(i18n("Font weight"));
243 font_weight_box->setCurrentIndex(1);
244 font_weight_box->blockSignals(false);
246 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
247 buttonRealSize->setIcon(KIcon("zoom-original"));
248 buttonItalic->setIcon(KIcon("format-text-italic"));
249 buttonUnder->setIcon(KIcon("format-text-underline"));
250 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
251 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
252 buttonAlignRight->setIcon(KIcon("format-justify-right"));
253 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
255 buttonAlignNone->setToolTip(i18n("No alignment"));
256 buttonAlignRight->setToolTip(i18n("Align right"));
257 buttonAlignLeft->setToolTip(i18n("Align left"));
258 buttonAlignCenter->setToolTip(i18n("Align center"));
260 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
261 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
262 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
263 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
264 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
266 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
267 m_zUp->setShortcut(Qt::Key_PageUp);
268 m_zUp->setToolTip(i18n("Raise object"));
269 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
270 zUp->setDefaultAction(m_zUp);
272 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
273 m_zDown->setShortcut(Qt::Key_PageDown);
274 m_zDown->setToolTip(i18n("Lower object"));
275 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
276 zDown->setDefaultAction(m_zDown);
278 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
279 // TODO mbt 1414: Shortcut should change z index only if
280 // cursor is NOT in a text field ...
281 //m_zTop->setShortcut(Qt::Key_Home);
282 m_zTop->setToolTip(i18n("Raise object to top"));
283 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
284 zTop->setDefaultAction(m_zTop);
286 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
288 //m_zBottom->setShortcut(Qt::Key_End);
289 m_zBottom->setToolTip(i18n("Lower object to bottom"));
290 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
291 zBottom->setDefaultAction(m_zBottom);
293 m_selectAll = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
294 m_selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
295 connect(m_selectAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
296 buttonSelectAll->setDefaultAction(m_selectAll);
298 m_selectText = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
299 m_selectText->setShortcut(Qt::CTRL + Qt::Key_T);
300 connect(m_selectText, SIGNAL(triggered()), this, SLOT(slotSelectText()));
301 buttonSelectText->setDefaultAction(m_selectText);
303 m_selectRects = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
304 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
305 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
306 buttonSelectRects->setDefaultAction(m_selectRects);
308 m_selectImages = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
309 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
310 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
311 buttonSelectImages->setDefaultAction(m_selectImages);
313 m_unselectAll = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
314 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
315 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
316 buttonUnselectAll->setDefaultAction(m_unselectAll);
318 zDown->setIcon(KIcon("kdenlive-zindex-down"));
319 zTop->setIcon(KIcon("kdenlive-zindex-top"));
320 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
321 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
322 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
323 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
325 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
326 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
327 rectBColor->setToolTip(i18n("Select fill color"));
328 rectFColor->setToolTip(i18n("Select border color"));
329 rectBAlpha->setToolTip(i18n("Fill opacity"));
330 rectFAlpha->setToolTip(i18n("Border opacity"));
331 zoom_slider->setToolTip(i18n("Zoom"));
332 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
333 buttonFitZoom->setToolTip(i18n("Fit zoom"));
334 backgroundColor->setToolTip(i18n("Select background color"));
335 backgroundAlpha->setToolTip(i18n("Background opacity"));
336 buttonSelectAll->setToolTip(i18n("Select all"));
337 buttonSelectText->setToolTip(i18n("Select text items in current selection"));
338 buttonSelectRects->setToolTip(i18n("Select rect items in current selection"));
339 buttonSelectImages->setToolTip(i18n("Select image items in current selection"));
340 buttonUnselectAll->setToolTip(i18n("Unselect all"));
342 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
343 itemhcenter->setToolTip(i18n("Align item horizontally"));
344 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
345 itemvcenter->setToolTip(i18n("Align item vertically"));
346 itemtop->setIcon(KIcon("kdenlive-align-top"));
347 itemtop->setToolTip(i18n("Align item to top"));
348 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
349 itembottom->setToolTip(i18n("Align item to bottom"));
350 itemright->setIcon(KIcon("kdenlive-align-right"));
351 itemright->setToolTip(i18n("Align item to right"));
352 itemleft->setIcon(KIcon("kdenlive-align-left"));
353 itemleft->setToolTip(i18n("Align item to left"));
356 QHBoxLayout *layout = new QHBoxLayout;
357 frame_toolbar->setLayout(layout);
358 layout->setContentsMargins(0, 0, 0, 0);
359 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
360 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
361 m_toolbar->setIconSize(QSize(s, s));
363 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
364 m_buttonCursor->setCheckable(true);
365 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
366 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
367 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
369 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
370 m_buttonText->setCheckable(true);
371 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
372 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
373 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
375 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
376 m_buttonRect->setCheckable(true);
377 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
378 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
379 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
381 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
382 m_buttonImage->setCheckable(false);
383 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
384 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
385 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
387 m_toolbar->addSeparator();
389 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
390 m_buttonLoad->setCheckable(false);
391 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
392 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
394 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
395 m_buttonSave->setCheckable(false);
396 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
397 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
399 layout->addWidget(m_toolbar);
401 // initialize graphic scene
402 m_scene = new GraphicsSceneRectMove(this);
403 graphicsView->setScene(m_scene);
404 graphicsView->setMouseTracking(true);
405 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
406 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
407 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
409 // a gradient background
410 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
411 gradient->setSpread(QGradient::ReflectSpread);
412 scene->setBackgroundBrush(*gradient);*/
414 m_frameImage = new QGraphicsPixmapItem();
416 qtrans.scale(2.0, 2.0);
417 m_frameImage->setTransform(qtrans);
418 m_frameImage->setZValue(-1200);
419 m_frameImage->setFlags(0);
420 displayBackgroundFrame();
421 graphicsView->scene()->addItem(m_frameImage);
423 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
424 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
425 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
426 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
427 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
428 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
429 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
430 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
432 QPen framepen(Qt::DotLine);
433 framepen.setColor(Qt::red);
435 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
436 m_frameBorder->setPen(framepen);
437 m_frameBorder->setZValue(-1100);
438 m_frameBorder->setBrush(Qt::transparent);
439 m_frameBorder->setFlags(0);
440 graphicsView->scene()->addItem(m_frameBorder);
442 // mbd: load saved settings
445 graphicsView->show();
446 //graphicsView->setRenderHint(QPainter::Antialiasing);
447 graphicsView->setInteractive(true);
448 //graphicsView->resize(400, 300);
449 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
450 //toolBox->setItemEnabled(2, false);
451 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
452 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
453 m_startViewport->setData(0, m_frameWidth);
454 m_startViewport->setData(1, m_frameHeight);
455 m_endViewport->setData(0, m_frameWidth);
456 m_endViewport->setData(1, m_frameHeight);
458 if(!url.isEmpty()) loadTitle(url);
461 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
464 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
465 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
466 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
468 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
469 refreshTitleTemplates();
470 //templateBox->setIconSize(QSize(60,60));
471 templateBox->clear();
472 templateBox->addItem("");
473 foreach(TitleTemplate t, titletemplates) {
474 templateBox->addItem(t.icon, t.name, t.file);
476 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
479 TitleWidget::~TitleWidget()
483 delete m_buttonImage;
484 delete m_buttonCursor;
487 delete m_unicodeAction;
494 delete m_selectRects;
495 delete m_selectImages;
496 delete m_unselectAll;
498 delete m_unicodeDialog;
499 delete m_frameBorder;
501 delete m_startViewport;
502 delete m_endViewport;
504 delete m_signalMapper;
508 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
511 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
512 KStandardDirs::makeDir(titlePath);
513 titlePath.append((isClone == false) ? "title" : "clone");
516 while(path.isEmpty() || QFile::exists(path)) {
518 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
520 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
526 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
529 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
530 KStandardDirs::makeDir(titlePath);
531 return titlePath + titleName + ".png";
535 QStringList TitleWidget::extractImageList(QString xml)
538 if(xml.isEmpty()) return result;
541 QDomNodeList images = doc.elementsByTagName("content");
542 for(int i = 0; i < images.count(); i++) {
543 if(images.at(i).toElement().hasAttribute("url"))
544 result.append(images.at(i).toElement().attribute("url"));
550 QStringList TitleWidget::extractFontList(QString xml)
553 if(xml.isEmpty()) return result;
556 QDomNodeList images = doc.elementsByTagName("content");
557 for(int i = 0; i < images.count(); i++) {
558 if(images.at(i).toElement().hasAttribute("font"))
559 result.append(images.at(i).toElement().attribute("font"));
564 void TitleWidget::refreshTitleTemplates()
566 QStringList titlenamelist = QStringList() << i18n("None");
567 QStringList titlefiles = QStringList() << QString();
569 filters << "*.kdenlivetitle" ;
570 titletemplates.clear();
571 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
572 foreach(const QString & folder, titleTemplates) {
573 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
574 foreach(const QString & fname, filesnames) {
575 //titlenamelist.append(fname);
576 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
579 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
580 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
581 titletemplates.append(t);
584 kDebug() << titlenamelist << titlefiles;
586 void TitleWidget::templateIndexChanged(int index)
588 QString item = templateBox->itemData(index).toString();
590 if(lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
591 if(KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
595 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
596 // Text of unchanged template titles should be selected when clicked.
597 QList<QGraphicsItem *> list = graphicsView->scene()->items();
598 foreach(QGraphicsItem * qgItem, list) {
599 if(qgItem->type() == TEXTITEM) {
600 QGraphicsTextItem *i;
601 i = static_cast<QGraphicsTextItem *>(qgItem);
602 i->setProperty("isTemplate", "true");
603 i->setProperty("templateText", i->toHtml());
607 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
611 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
616 void TitleWidget::slotTextTool()
618 m_scene->setTool(TITLE_TEXT);
619 showToolbars(TITLE_TEXT);
620 checkButton(TITLE_TEXT);
623 void TitleWidget::slotRectTool()
625 m_scene->setTool(TITLE_RECTANGLE);
626 showToolbars(TITLE_RECTANGLE);
627 checkButton(TITLE_RECTANGLE);
630 void TitleWidget::slotSelectTool()
632 m_scene->setTool(TITLE_SELECT);
634 // Find out which toolbars need to be shown, depending on selected item
635 TITLETOOL t = TITLE_SELECT;
636 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
638 switch(l.at(0)->type()) {
652 if(t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
653 //graphicsView->centerOn(l.at(0));
659 updateCoordinates(l.at(0));
660 updateDimension(l.at(0));
661 updateRotZoom(l.at(0));
664 checkButton(TITLE_SELECT);
667 void TitleWidget::slotImageTool()
669 // TODO: find a way to get a list of all supported image types...
670 QString allExtensions = "image/gif image/jpeg image/png image/x-tga image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr";
671 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
673 if(url.path().endsWith(".svg")) {
674 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
675 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
676 svg->setZValue(m_count++);
677 svg->setData(Qt::UserRole, url.path());
678 graphicsView->scene()->addItem(svg);
680 QPixmap pix(url.path());
681 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
682 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
683 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
684 image->setData(Qt::UserRole, url.path());
685 image->setZValue(m_count++);
686 graphicsView->scene()->addItem(image);
689 m_scene->setTool(TITLE_SELECT);
690 showToolbars(TITLE_SELECT);
691 checkButton(TITLE_SELECT);
694 void TitleWidget::showToolbars(TITLETOOL toolType)
696 toolbar_stack->setCurrentIndex((int) toolType);
699 void TitleWidget::enableToolbars(TITLETOOL toolType)
701 // TITLETOOL is defined in graphicsscenerectmove.h
703 if(toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
704 value_w->setEnabled(enable);
705 value_h->setEnabled(enable);
708 void TitleWidget::checkButton(TITLETOOL toolType)
710 bool bSelect = false;
722 case TITLE_RECTANGLE:
732 m_buttonCursor->setChecked(bSelect);
733 m_buttonText->setChecked(bText);
734 m_buttonRect->setChecked(bRect);
735 m_buttonImage->setChecked(bImage);
738 void TitleWidget::displayBackgroundFrame()
740 if(!displayBg->isChecked()) {
741 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
742 QPixmap pattern(20, 20);
744 QColor bgcolor(210, 210, 210);
747 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
748 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
753 p.fillRect(bg.rect(), br);
755 m_frameImage->setPixmap(bg);
757 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
761 void TitleWidget::initAnimation()
763 align_box->setEnabled(false);
764 QPen startpen(Qt::DotLine);
765 QPen endpen(Qt::DashDotLine);
766 startpen.setColor(QColor(100, 200, 100, 140));
767 endpen.setColor(QColor(200, 100, 100, 140));
769 m_startViewport->setPen(startpen);
770 m_endViewport->setPen(endpen);
772 m_startViewport->setZValue(-1000);
773 m_endViewport->setZValue(-1000);
775 m_startViewport->setFlags(0);
776 m_endViewport->setFlags(0);
778 graphicsView->scene()->addItem(m_startViewport);
779 graphicsView->scene()->addItem(m_endViewport);
781 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
782 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
783 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
784 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
787 void TitleWidget::slotUpdateZoom(int pos)
789 m_scene->setZoom((double) pos / 100);
790 zoom_label->setText(QString::number(pos) + '%');
793 void TitleWidget::slotZoom(bool up)
795 int pos = zoom_slider->value();
798 zoom_slider->setValue(pos);
801 void TitleWidget::slotAdjustZoom()
803 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
804 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
805 if (scalex > scaley) scalex = scaley;
806 int zoompos = (int)(scalex * 7 + 0.5);*/
807 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
808 int zoompos = graphicsView->matrix().m11() * 100;
809 zoom_slider->setValue(zoompos);
810 graphicsView->centerOn(m_frameBorder);
813 void TitleWidget::slotZoomOneToOne()
815 zoom_slider->setValue(100);
816 graphicsView->centerOn(m_frameBorder);
819 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
821 updateAxisButtons(rect); // back to default
823 QColor f = rectFColor->color();
824 f.setAlpha(rectFAlpha->value());
826 penf.setWidth(rectLineWidth->value());
827 penf.setJoinStyle(Qt::RoundJoin);
829 QColor b = rectBColor->color();
830 b.setAlpha(rectBAlpha->value());
831 rect->setBrush(QBrush(b));
832 rect->setZValue(m_count++);
833 rect->setData(ZOOMFACTOR, 100);
834 //setCurrentItem(rect);
835 //graphicsView->setFocus();
838 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
840 updateAxisButtons(tt); // back to default
842 QFont font = font_family->currentFont();
843 font.setPixelSize(font_size->value());
845 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
846 font.setItalic(buttonItalic->isChecked());
847 font.setUnderline(buttonUnder->isChecked());
850 QColor color = fontColorButton->color();
851 color.setAlpha(textAlpha->value());
852 tt->setDefaultTextColor(color);
854 QTextCursor cur(tt->document());
855 cur.select(QTextCursor::Document);
856 QTextBlockFormat format = cur.blockFormat();
857 QTextCharFormat cformat = cur.charFormat();
858 QColor outlineColor = textOutlineColor->color();
859 outlineColor.setAlpha(textOutlineAlpha->value());
860 double outlineWidth = textOutline->value() / 10.0;
862 tt->setData(101, outlineWidth);
863 tt->setData(102, outlineColor);
864 if(outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
866 cformat.setForeground(QBrush(color));
867 cur.setCharFormat(cformat);
868 cur.setBlockFormat(format);
869 tt->setTextCursor(cur);
870 tt->setZValue(m_count++);
874 void TitleWidget::setFontBoxWeight(int weight)
876 int index = font_weight_box->findData(weight);
878 index = font_weight_box->findData(QFont::Normal);
880 font_weight_box->setCurrentIndex(index);
883 void TitleWidget::setCurrentItem(QGraphicsItem *item)
885 m_scene->setSelectedItem(item);
888 void TitleWidget::zIndexChanged(int v)
890 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
896 void TitleWidget::selectionChanged()
898 if(m_scene->tool() != TITLE_SELECT) return;
900 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
902 QList<QGraphicsItem *> l;
904 // mbt 1607: One text item might have grabbed the keyboard.
905 // Ungrab it for all items that are not selected, otherwise
906 // text input would only work for the text item that grabbed
907 // the keyboard last.
908 l = graphicsView->scene()->items();
909 foreach(QGraphicsItem * item, l) {
910 if(item->type() == TEXTITEM && !item->isSelected()) {
911 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
916 l = graphicsView->scene()->selectedItems();
919 buttonUnselectAll->setEnabled(true);
921 buttonUnselectAll->setEnabled(false);
924 buttonSelectText->setEnabled(true);
925 buttonSelectRects->setEnabled(true);
926 buttonSelectImages->setEnabled(true);
928 buttonSelectText->setEnabled(false);
929 buttonSelectRects->setEnabled(false);
930 buttonSelectImages->setEnabled(false);
934 //toolBox->setItemEnabled(2, false);
935 //toolBox->setItemEnabled(3, false);
936 effect_list->blockSignals(true);
937 value_x->blockSignals(true);
938 value_y->blockSignals(true);
939 value_w->blockSignals(true);
940 value_h->blockSignals(true);
941 itemzoom->blockSignals(true);
942 itemrotatex->blockSignals(true);
943 itemrotatey->blockSignals(true);
944 itemrotatez->blockSignals(true);
946 effect_stack->setHidden(true);
947 effect_frame->setEnabled(false);
948 effect_list->setCurrentIndex(0);
949 bool blockX = !origin_x_left->signalsBlocked();
950 bool blockY = !origin_y_top->signalsBlocked();
951 if(blockX) origin_x_left->blockSignals(true);
952 if(blockY) origin_y_top->blockSignals(true);
953 origin_x_left->setChecked(false);
954 origin_y_top->setChecked(false);
957 enableToolbars(TITLE_SELECT);
958 if(blockX) origin_x_left->blockSignals(false);
959 if(blockY) origin_y_top->blockSignals(false);
960 itemzoom->setEnabled(false);
961 itemrotatex->setEnabled(false);
962 itemrotatey->setEnabled(false);
963 itemrotatez->setEnabled(false);
964 frame_properties->setEnabled(false);
965 } else if(l.size() == 1) {
966 effect_frame->setEnabled(true);
967 frame_properties->setEnabled(true);
968 if(l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
969 itemzoom->setEnabled(true);
970 itemrotatex->setEnabled(true);
971 itemrotatey->setEnabled(true);
972 itemrotatez->setEnabled(true);
974 itemzoom->setEnabled(false);
975 itemrotatex->setEnabled(false);
976 itemrotatey->setEnabled(false);
977 itemrotatez->setEnabled(false);
980 if(l.at(0)->type() == TEXTITEM) {
981 showToolbars(TITLE_TEXT);
982 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
983 if(!i->data(100).isNull()) {
984 // Item has an effect
985 QStringList effdata = i->data(100).toStringList();
986 QString effectName = effdata.takeFirst();
987 if(effectName == "typewriter") {
988 QStringList params = effdata.at(0).split(';');
989 typewriter_delay->setValue(params.at(0).toInt());
990 typewriter_start->setValue(params.at(1).toInt());
991 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
992 effect_stack->setHidden(false);
995 #if QT_VERSION >= 0x040600
996 if(i->graphicsEffect()) {
997 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
999 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
1000 int rad = (int) blur->blurRadius();
1001 blur_radius->setValue(rad);
1002 effect_stack->setHidden(false);
1004 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
1006 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
1007 shadow_radius->setValue(shad->blurRadius());
1008 shadow_x->setValue(shad->xOffset());
1009 shadow_y->setValue(shad->yOffset());
1010 effect_stack->setHidden(false);
1014 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
1015 effect_stack->setHidden(true);
1018 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
1019 effect_stack->setHidden(true);
1022 //if (l[0]->hasFocus())
1023 //toolBox->setCurrentIndex(0);
1024 //toolBox->setItemEnabled(2, true);
1025 font_size->blockSignals(true);
1026 font_family->blockSignals(true);
1027 font_weight_box->blockSignals(true);
1028 buttonItalic->blockSignals(true);
1029 buttonUnder->blockSignals(true);
1030 fontColorButton->blockSignals(true);
1031 textAlpha->blockSignals(true);
1032 buttonAlignLeft->blockSignals(true);
1033 buttonAlignRight->blockSignals(true);
1034 buttonAlignNone->blockSignals(true);
1035 buttonAlignCenter->blockSignals(true);
1037 QFont font = i->font();
1038 font_family->setCurrentFont(font);
1039 font_size->setValue(font.pixelSize());
1040 m_scene->slotUpdateFontSize(font.pixelSize());
1041 buttonItalic->setChecked(font.italic());
1042 buttonUnder->setChecked(font.underline());
1043 setFontBoxWeight(font.weight());
1045 QTextCursor cursor(i->document());
1046 cursor.select(QTextCursor::Document);
1047 QColor color = cursor.charFormat().foreground().color();
1048 textAlpha->setValue(color.alpha());
1049 color.setAlpha(255);
1050 fontColorButton->setColor(color);
1052 if(!i->data(101).isNull()) {
1053 textOutline->blockSignals(true);
1054 textOutline->setValue(i->data(101).toDouble() * 10);
1055 textOutline->blockSignals(false);
1057 if(!i->data(102).isNull()) {
1058 textOutlineColor->blockSignals(true);
1059 textOutlineAlpha->blockSignals(true);
1060 color = QColor(i->data(102).toString());
1061 textOutlineAlpha->setValue(color.alpha());
1062 color.setAlpha(255);
1063 textOutlineColor->setColor(color);
1064 textOutlineColor->blockSignals(false);
1065 textOutlineAlpha->blockSignals(false);
1067 QTextCursor cur = i->textCursor();
1068 QTextBlockFormat format = cur.blockFormat();
1069 if(i->textWidth() == -1) buttonAlignNone->setChecked(true);
1070 else if(format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
1071 else if(format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
1072 else if(format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
1074 font_size->blockSignals(false);
1075 font_family->blockSignals(false);
1076 font_weight_box->blockSignals(false);
1077 buttonItalic->blockSignals(false);
1078 buttonUnder->blockSignals(false);
1079 fontColorButton->blockSignals(false);
1080 textAlpha->blockSignals(false);
1081 buttonAlignLeft->blockSignals(false);
1082 buttonAlignRight->blockSignals(false);
1083 buttonAlignNone->blockSignals(false);
1084 buttonAlignCenter->blockSignals(false);
1086 // mbt 1607: Select text if the text item is an unchanged template item.
1087 if(i->property("isTemplate").isValid()) {
1088 cur.setPosition(0, QTextCursor::MoveAnchor);
1089 cur.select(QTextCursor::Document);
1090 i->setTextCursor(cur);
1091 // Make text editable now.
1093 i->setTextInteractionFlags(Qt::TextEditorInteraction);
1096 updateAxisButtons(i);
1097 updateCoordinates(i);
1099 enableToolbars(TITLE_TEXT);
1101 } else if((l.at(0))->type() == RECTITEM) {
1102 showToolbars(TITLE_RECTANGLE);
1104 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1105 if(rec == m_startViewport || rec == m_endViewport) {
1106 /*toolBox->setCurrentIndex(3);
1107 toolBox->widget(0)->setEnabled(false);
1108 toolBox->widget(1)->setEnabled(false);*/
1109 enableToolbars(TITLE_SELECT);
1111 /*toolBox->widget(0)->setEnabled(true);
1112 toolBox->widget(1)->setEnabled(true);
1113 toolBox->setCurrentIndex(0);*/
1114 //toolBox->setItemEnabled(3, true);
1115 rectFAlpha->setValue(rec->pen().color().alpha());
1116 rectBAlpha->setValue(rec->brush().color().alpha());
1117 //kDebug() << rec->brush().color().alpha();
1118 QColor fcol = rec->pen().color();
1119 QColor bcol = rec->brush().color();
1120 //fcol.setAlpha(255);
1121 //bcol.setAlpha(255);
1122 rectFColor->setColor(fcol);
1123 rectBColor->setColor(bcol);
1125 rectLineWidth->setValue(rec->pen().width());
1126 enableToolbars(TITLE_RECTANGLE);
1129 updateAxisButtons(l.at(0));
1130 updateCoordinates(rec);
1131 updateDimension(rec);
1133 } else if(l.at(0)->type() == IMAGEITEM) {
1134 showToolbars(TITLE_IMAGE);
1136 updateCoordinates(l.at(0));
1137 updateDimension(l.at(0));
1139 enableToolbars(TITLE_IMAGE);
1142 //toolBox->setCurrentIndex(0);
1143 showToolbars(TITLE_SELECT);
1144 enableToolbars(TITLE_SELECT);
1145 frame_properties->setEnabled(false);
1147 zValue->setValue((int)l.at(0)->zValue());
1148 if(!l.at(0)->data(ZOOMFACTOR).isNull()) itemzoom->setValue(l.at(0)->data(ZOOMFACTOR).toInt());
1149 else itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
1150 itemrotatex->setValue((int)(m_transformations.value(l.at(0)).rotatex));
1151 itemrotatey->setValue((int)(m_transformations.value(l.at(0)).rotatey));
1152 itemrotatez->setValue((int)(m_transformations.value(l.at(0)).rotatez));
1153 value_x->blockSignals(false);
1154 value_y->blockSignals(false);
1155 value_w->blockSignals(false);
1156 value_h->blockSignals(false);
1157 itemzoom->blockSignals(false);
1158 itemrotatex->blockSignals(false);
1159 itemrotatey->blockSignals(false);
1160 itemrotatez->blockSignals(false);
1162 // More than one item selected
1165 // Tools working on more than one element.
1167 effect_list->blockSignals(false);
1171 void TitleWidget::slotValueChanged(int type)
1173 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1174 if(l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
1179 val = value_w->value();
1182 val = value_h->value();
1186 QGraphicsItem *i = l.at(0);
1187 Transform t = m_transformations.value(i);
1189 // Ratio width:height
1190 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1191 // TODO: proper calculation for rotation around 3 axes
1192 double alpha = (double) t.rotatez / 180.0 * M_PI;
1195 double length = val;
1202 // Add 0.5 because otherwise incrementing by 1 might have no effect
1203 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1204 scale = length / i->boundingRect().width();
1207 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1208 scale = length / i->boundingRect().height();
1215 qtrans.scale(scale, scale);
1216 qtrans.rotate(t.rotatex, Qt::XAxis);
1217 qtrans.rotate(t.rotatey, Qt::YAxis);
1218 qtrans.rotate(t.rotatez, Qt::ZAxis);
1219 i->setTransform(qtrans);
1220 m_transformations[i] = t;
1227 void TitleWidget::slotAdjustSelectedItem()
1229 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1231 if(l.at(0)->type() == RECTITEM) {
1233 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1234 updatePosition(rec);
1235 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1236 } else if(l.at(0)->type() == TEXTITEM) {
1238 updatePosition(l.at(0));
1239 } else if(l.at(0)->type() == IMAGEITEM) {
1241 updatePosition(l.at(0));
1246 void TitleWidget::updateDimension(QGraphicsItem *i)
1248 value_w->blockSignals(true);
1249 value_h->blockSignals(true);
1250 zValue->blockSignals(true);
1252 zValue->setValue((int) i->zValue());
1253 if(i->type() == IMAGEITEM) {
1254 // Get multipliers for rotation/scaling
1256 /*Transform t = m_transformations.value(i);
1257 QRectF r = i->boundingRect();
1258 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1259 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1260 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1261 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1263 value_w->setValue(i->sceneBoundingRect().width());
1264 value_h->setValue(i->sceneBoundingRect().height());
1265 } else if(i->type() == RECTITEM) {
1266 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1267 value_w->setValue((int) r->rect().width());
1268 value_h->setValue((int) r->rect().height());
1269 } else if(i->type() == TEXTITEM) {
1270 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1271 value_w->setValue((int) t->boundingRect().width());
1272 value_h->setValue((int) t->boundingRect().height());
1275 zValue->blockSignals(false);
1276 value_w->blockSignals(false);
1277 value_h->blockSignals(false);
1280 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1282 // Block signals emitted by this method
1283 value_x->blockSignals(true);
1284 value_y->blockSignals(true);
1286 if(i->type() == TEXTITEM) {
1288 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1290 // Set the correct x coordinate value
1291 if(origin_x_left->isChecked()) {
1292 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1293 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1295 // Origin is at 0 (default)
1296 value_x->setValue((int) rec->pos().x());
1300 if(origin_y_top->isChecked()) {
1301 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1303 value_y->setValue((int) rec->pos().y());
1306 } else if(i->type() == RECTITEM) {
1308 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1310 if(origin_x_left->isChecked()) {
1311 // Origin (0 point) is at m_frameWidth
1312 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1314 // Origin is at 0 (default)
1315 value_x->setValue((int) rec->pos().x());
1318 if(origin_y_top->isChecked()) {
1319 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1321 value_y->setValue((int) rec->pos().y());
1324 } else if(i->type() == IMAGEITEM) {
1326 if(origin_x_left->isChecked()) {
1327 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1329 value_x->setValue((int) i->pos().x());
1332 if(origin_y_top->isChecked()) {
1333 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1335 value_y->setValue((int) i->pos().y());
1340 // Stop blocking signals now
1341 value_x->blockSignals(false);
1342 value_y->blockSignals(false);
1345 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1347 itemzoom->blockSignals(true);
1348 itemrotatex->blockSignals(true);
1349 itemrotatey->blockSignals(true);
1350 itemrotatez->blockSignals(true);
1352 Transform t = m_transformations.value(i);
1354 if(!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1355 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1357 itemrotatex->setValue((int)(t.rotatex));
1358 itemrotatey->setValue((int)(t.rotatey));
1359 itemrotatez->setValue((int)(t.rotatez));
1361 itemzoom->blockSignals(false);
1362 itemrotatex->blockSignals(false);
1363 itemrotatey->blockSignals(false);
1364 itemrotatez->blockSignals(false);
1367 void TitleWidget::updatePosition(QGraphicsItem *i)
1369 if(i->type() == TEXTITEM) {
1370 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1373 if(origin_x_left->isChecked()) {
1375 * Origin of the X axis is at m_frameWidth, and distance from right
1376 * border of the item to the right border of the frame is taken. See
1377 * comment to slotOriginXClicked().
1379 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1381 posX = value_x->value();
1385 if(origin_y_top->isChecked()) {
1386 /* Same for y axis */
1387 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1389 posY = value_y->value();
1392 rec->setPos(posX, posY);
1394 } else if(i->type() == RECTITEM) {
1396 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1399 if(origin_x_left->isChecked()) {
1400 posX = m_frameWidth - value_x->value() - rec->rect().width();
1402 posX = value_x->value();
1406 if(origin_y_top->isChecked()) {
1407 posY = m_frameHeight - value_y->value() - rec->rect().height();
1409 posY = value_y->value();
1412 rec->setPos(posX, posY);
1414 } else if(i->type() == IMAGEITEM) {
1416 if(origin_x_left->isChecked()) {
1417 // Use the sceneBoundingRect because this also regards transformations like zoom
1418 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1420 posX = value_x->value();
1424 if(origin_y_top->isChecked()) {
1425 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1427 posY = value_y->value();
1430 i->setPos(posX, posY);
1436 void TitleWidget::updateTextOriginX()
1438 if(origin_x_left->isChecked()) {
1439 origin_x_left->setText(i18n("\u2212X"));
1441 origin_x_left->setText(i18n("+X"));
1445 void TitleWidget::slotOriginXClicked()
1447 // Update the text displayed on the button.
1448 updateTextOriginX();
1450 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1452 updateCoordinates(l.at(0));
1454 // Remember x axis setting
1455 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1456 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1458 graphicsView->setFocus();
1461 void TitleWidget::updateTextOriginY()
1463 if(origin_y_top->isChecked()) {
1464 origin_y_top->setText(i18n("\u2212Y"));
1466 origin_y_top->setText(i18n("+Y"));
1470 void TitleWidget::slotOriginYClicked()
1472 // Update the text displayed on the button.
1473 updateTextOriginY();
1475 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1477 updateCoordinates(l.at(0));
1479 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1480 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1483 graphicsView->setFocus();
1486 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1488 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1489 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1490 origin_x_left->blockSignals(true);
1491 origin_y_top->blockSignals(true);
1493 if(xAxis == TitleDocument::AxisInverted) {
1494 origin_x_left->setChecked(true);
1496 origin_x_left->setChecked(false);
1498 updateTextOriginX();
1500 if(yAxis == TitleDocument::AxisInverted) {
1501 origin_y_top->setChecked(true);
1503 origin_y_top->setChecked(false);
1505 updateTextOriginY();
1507 origin_x_left->blockSignals(false);
1508 origin_y_top->blockSignals(false);
1511 void TitleWidget::slotChangeBackground()
1513 QColor color = backgroundColor->color();
1514 color.setAlpha(backgroundAlpha->value());
1515 m_frameBorder->setBrush(QBrush(color));
1518 void TitleWidget::slotChanged()
1520 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1521 if(l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1522 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1526 void TitleWidget::textChanged(QGraphicsTextItem *i)
1529 * If the user has set origin_x_left (the same for y), we need to look
1530 * whether a text element has been selected. If yes, we need to ensure that
1531 * the right border of the text field remains fixed also when some text has
1534 * This is also known as right-justified, with the difference that it is not
1535 * valid for text but for its boundingRect. Text may still be
1540 if(origin_x_left->isChecked() || origin_y_top->isChecked()) {
1541 if(!i->toPlainText().isEmpty())
1545 * Don't do anything if the string is empty. If the position were
1546 * updated here, a newly created text field would be set to the
1547 * position of the last selected text field.
1552 // mbt 1607: Template text has changed; don't auto-select content anymore.
1553 if(i->property("isTemplate").isValid()) {
1554 if(i->property("templateText").isValid()) {
1555 if(i->property("templateText") == i->toHtml()) {
1556 // Unchanged, do nothing.
1558 i->setProperty("isTemplate", QVariant::Invalid);
1559 i->setProperty("templateText", QVariant::Invalid);
1565 void TitleWidget::slotInsertUnicode()
1567 m_unicodeDialog->exec();
1570 void TitleWidget::slotInsertUnicodeString(QString text)
1572 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1574 if(l.at(0)->type() == TEXTITEM) {
1575 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1576 t->textCursor().insertText(text);
1581 void TitleWidget::slotUpdateText()
1583 QFont font = font_family->currentFont();
1584 font.setPixelSize(font_size->value());
1585 font.setItalic(buttonItalic->isChecked());
1586 font.setUnderline(buttonUnder->isChecked());
1587 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1588 QColor color = fontColorButton->color();
1589 color.setAlpha(textAlpha->value());
1591 QColor outlineColor = textOutlineColor->color();
1592 outlineColor.setAlpha(textOutlineAlpha->value());
1593 double outlineWidth = textOutline->value() / 10.0;
1596 for(i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1597 QGraphicsTextItem* item = NULL;
1598 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1599 if(l.at(i)->type() == TEXTITEM) {
1600 item = static_cast <QGraphicsTextItem *>(l.at(i));
1603 // No text item, try next one.
1607 // Set alignment of all text in the text item
1608 QTextCursor cur(item->document());
1609 cur.select(QTextCursor::Document);
1610 QTextBlockFormat format = cur.blockFormat();
1611 if(buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1612 item->setTextWidth(item->boundingRect().width());
1613 if(buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1614 else if(buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1615 else if(buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1617 format.setAlignment(Qt::AlignLeft);
1618 item->setTextWidth(-1);
1621 // Set font properties
1622 item->setFont(font);
1623 QTextCharFormat cformat = cur.charFormat();
1625 item->setData(101, outlineWidth);
1626 item->setData(102, outlineColor);
1627 if(outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1629 cformat.setForeground(QBrush(color));
1630 cur.setCharFormat(cformat);
1631 cur.setBlockFormat(format);
1632 // item->setTextCursor(cur);
1633 cur.clearSelection();
1634 item->setTextCursor(cur);
1638 void TitleWidget::rectChanged()
1640 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1642 for(i = 0; i < l.length(); i++) {
1643 if(l.at(i)->type() == RECTITEM && !settingUp) {
1644 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1645 QColor f = rectFColor->color();
1646 f.setAlpha(rectFAlpha->value());
1648 penf.setWidth(rectLineWidth->value());
1649 penf.setJoinStyle(Qt::RoundJoin);
1651 QColor b = rectBColor->color();
1652 b.setAlpha(rectBAlpha->value());
1653 rec->setBrush(QBrush(b));
1658 void TitleWidget::itemScaled(int val)
1660 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1662 Transform x = m_transformations.value(l.at(0));
1663 x.scalex = (double)val / 100.0;
1664 x.scaley = (double)val / 100.0;
1666 qtrans.scale(x.scalex, x.scaley);
1667 qtrans.rotate(x.rotatex, Qt::XAxis);
1668 qtrans.rotate(x.rotatey, Qt::YAxis);
1669 qtrans.rotate(x.rotatez, Qt::ZAxis);
1670 l[0]->setTransform(qtrans);
1671 l[0]->setData(ZOOMFACTOR, val);
1672 m_transformations[l.at(0)] = x;
1673 updateDimension(l.at(0));
1677 void TitleWidget::itemRotateX(qreal val)
1682 void TitleWidget::itemRotateY(qreal val)
1687 void TitleWidget::itemRotateZ(qreal val)
1692 void TitleWidget::itemRotate(qreal val, int axis)
1694 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1696 Transform x = m_transformations[l.at(0)];
1709 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1712 qtrans.scale(x.scalex, x.scaley);
1713 qtrans.rotate(x.rotatex, Qt::XAxis);
1714 qtrans.rotate(x.rotatey, Qt::YAxis);
1715 qtrans.rotate(x.rotatez, Qt::ZAxis);
1716 l[0]->setTransform(qtrans);
1717 m_transformations[l.at(0)] = x;
1718 if(l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1719 updateDimension(l.at(0));
1723 void TitleWidget::itemHCenter()
1725 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1727 QGraphicsItem *item = l.at(0);
1728 QRectF br = item->sceneBoundingRect();
1729 int width = (int)br.width();
1730 int newPos = (int)((m_frameWidth - width) / 2);
1731 newPos += item->pos().x() - br.left(); // Check item transformation
1732 item->setPos(newPos, item->pos().y());
1733 updateCoordinates(item);
1737 void TitleWidget::itemVCenter()
1739 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1741 QGraphicsItem *item = l.at(0);
1742 QRectF br = item->sceneBoundingRect();
1743 int height = (int)br.height();
1744 int newPos = (int)((m_frameHeight - height) / 2);
1745 newPos += item->pos().y() - br.top(); // Check item transformation
1746 item->setPos(item->pos().x(), newPos);
1747 updateCoordinates(item);
1751 void TitleWidget::itemTop()
1753 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1755 QGraphicsItem *item = l.at(0);
1756 QRectF br = item->sceneBoundingRect();
1758 if(br.top() > 0) diff = -br.top();
1759 else diff = -br.bottom();
1760 item->moveBy(0, diff);
1761 updateCoordinates(item);
1765 void TitleWidget::itemBottom()
1767 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1769 QGraphicsItem *item = l.at(0);
1770 QRectF br = item->sceneBoundingRect();
1772 if(br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1773 else diff = m_frameHeight - br.bottom();
1774 item->moveBy(0, diff);
1775 updateCoordinates(item);
1779 void TitleWidget::itemLeft()
1781 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1783 QGraphicsItem *item = l.at(0);
1784 QRectF br = item->sceneBoundingRect();
1786 if(br.left() > 0) diff = -br.left();
1787 else diff = -br.right();
1788 item->moveBy(diff, 0);
1789 updateCoordinates(item);
1793 void TitleWidget::itemRight()
1795 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1797 QGraphicsItem *item = l.at(0);
1798 QRectF br = item->sceneBoundingRect();
1800 if(br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1801 else diff = m_frameWidth - br.left();
1802 item->moveBy(diff, 0);
1803 updateCoordinates(item);
1807 void TitleWidget::setupViewports()
1809 //double aspect_ratio = 4.0 / 3.0;//read from project
1810 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1811 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1812 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1813 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1814 QPolygonF spoly(sp);
1815 QPolygonF epoly(ep);
1816 spoly.translate(startViewportX->value(), startViewportY->value());
1817 epoly.translate(endViewportX->value(), endViewportY->value());
1818 m_startViewport->setPolygon(spoly);
1819 m_endViewport->setPolygon(epoly);
1820 if (! insertingValues) {
1821 m_startViewport->setData(0, startViewportX->value());
1822 m_startViewport->setData(1, startViewportY->value());
1823 m_startViewport->setData(2, startViewportSize->value());
1825 m_endViewport->setData(0, endViewportX->value());
1826 m_endViewport->setData(1, endViewportY->value());
1827 m_endViewport->setData(2, endViewportSize->value());
1831 void TitleWidget::loadTitle(KUrl url)
1833 if(url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1834 if(!url.isEmpty()) {
1835 QList<QGraphicsItem *> items = m_scene->items();
1836 for(int i = 0; i < items.size(); i++) {
1837 if(items.at(i)->zValue() > -1000) delete items.at(i);
1839 m_scene->clearTextSelection();
1843 if(KIO::NetAccess::download(url, tmpfile, 0)) {
1844 QFile file(tmpfile);
1845 if(file.open(QIODevice::ReadOnly)) {
1846 doc.setContent(&file, false);
1849 KIO::NetAccess::removeTempFile(tmpfile);
1854 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1856 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1857 insertingValues = true;
1858 startViewportX->setValue(m_startViewport->data(0).toInt());
1859 startViewportY->setValue(m_startViewport->data(1).toInt());
1860 startViewportSize->setValue(m_startViewport->data(2).toInt());
1861 endViewportX->setValue(m_endViewport->data(0).toInt());
1862 endViewportY->setValue(m_endViewport->data(1).toInt());
1863 endViewportSize->setValue(m_endViewport->data(2).toInt());
1865 insertingValues = false;
1871 void TitleWidget::saveTitle(KUrl url)
1873 if(anim_start->isChecked()) slotAnimStart(false);
1874 if(anim_end->isChecked()) slotAnimEnd(false);
1876 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1877 fs->setOperationMode(KFileDialog::Saving);
1878 fs->setMode(KFile::File);
1879 #if KDE_IS_VERSION(4,2,0)
1880 fs->setConfirmOverwrite(true);
1882 fs->setKeepLocation(true);
1884 url = fs->selectedUrl();
1887 if(!url.isEmpty()) {
1888 if(m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()) - 1) == false)
1889 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1893 QDomDocument TitleWidget::xml()
1895 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1896 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()) - 1);
1900 int TitleWidget::outPoint() const
1902 return m_tc.getFrameCount(title_duration->text()) - 1;
1905 void TitleWidget::setXml(QDomDocument doc)
1908 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1910 title_duration->setText(m_tc.getTimecode(GenTime(out + 1, m_render->fps())));
1911 /*if (doc.documentElement().hasAttribute("out")) {
1912 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1913 title_duration->setText(m_tc.getTimecode(duration));
1915 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1917 QDomElement e = doc.documentElement();
1918 m_transformations.clear();
1919 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1920 const double PI = 4.0 * atan(1.0);
1921 for(int i = 0; i < items.count(); i++) {
1922 QTransform t = items.at(i)->transform();
1926 if(!items.at(i)->data(ROTATEFACTOR).isNull()) {
1927 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1928 if(rotlist.count() >= 3) {
1929 x.rotatex = rotlist[0].toDouble();
1930 x.rotatey = rotlist[1].toDouble();
1931 x.rotatez = rotlist[2].toDouble();
1933 // Try to adjust zoom
1934 t.rotate(x.rotatex *(-1), Qt::XAxis);
1935 t.rotate(x.rotatey *(-1), Qt::YAxis);
1936 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1947 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1949 m_transformations[items.at(i)] = x;
1951 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1952 QColor background_color = m_titledocument.getBackgroundColor();
1953 backgroundAlpha->blockSignals(true);
1954 backgroundColor->blockSignals(true);
1955 backgroundAlpha->setValue(background_color.alpha());
1956 background_color.setAlpha(255);
1957 backgroundColor->setColor(background_color);
1958 backgroundAlpha->blockSignals(false);
1959 backgroundColor->blockSignals(false);
1961 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1962 startViewportY->setValue(m_startViewport->data(1).toInt());
1963 startViewportSize->setValue(m_startViewport->data(2).toInt());
1964 endViewportX->setValue(m_endViewport->data(0).toInt());
1965 endViewportY->setValue(m_endViewport->data(1).toInt());
1966 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1968 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1973 void TitleWidget::slotAccepted()
1975 if(anim_start->isChecked()) slotAnimStart(false);
1976 if(anim_end->isChecked()) slotAnimEnd(false);
1980 void TitleWidget::writeChoices()
1982 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1983 KSharedConfigPtr config = KGlobal::config();
1984 KConfigGroup titleConfig(config, "TitleWidget");
1985 // Write the entries
1986 titleConfig.writeEntry("font_family", font_family->currentFont());
1987 //titleConfig.writeEntry("font_size", font_size->value());
1988 titleConfig.writeEntry("font_pixel_size", font_size->value());
1989 titleConfig.writeEntry("font_color", fontColorButton->color());
1990 titleConfig.writeEntry("font_alpha", textAlpha->value());
1991 titleConfig.writeEntry("font_outline", textOutline->value());
1992 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1993 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1994 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1995 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1996 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1998 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1999 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
2000 titleConfig.writeEntry("rect_background_color", rectBColor->color());
2001 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
2002 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
2004 titleConfig.writeEntry("background_color", backgroundColor->color());
2005 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
2007 //! \todo Not sure if I should sync - it is probably safe to do it
2012 void TitleWidget::readChoices()
2014 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
2015 KSharedConfigPtr config = KGlobal::config();
2016 KConfigGroup titleConfig(config, "TitleWidget");
2018 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
2019 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
2020 m_scene->slotUpdateFontSize(font_size->value());
2021 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
2022 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
2024 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
2025 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
2026 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
2029 if(titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
2030 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
2031 setFontBoxWeight(weight);
2032 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
2033 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
2035 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
2036 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
2037 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
2038 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
2039 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
2041 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
2042 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
2045 void TitleWidget::adjustFrameSize()
2047 m_frameWidth = m_titledocument.frameWidth();
2048 m_frameHeight = m_titledocument.frameHeight();
2049 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
2050 displayBackgroundFrame();
2053 void TitleWidget::slotAnimStart(bool anim)
2055 if(anim && anim_end->isChecked()) {
2056 anim_end->setChecked(false);
2057 m_endViewport->setZValue(-1000);
2058 m_endViewport->setBrush(QBrush());
2061 QList<QGraphicsItem *> list = m_scene->items();
2062 for(int i = 0; i < list.count(); i++) {
2063 if(list.at(i)->zValue() > -1000) {
2064 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2065 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2068 align_box->setEnabled(anim);
2069 itemzoom->setEnabled(!anim);
2070 itemrotatex->setEnabled(!anim);
2071 itemrotatey->setEnabled(!anim);
2072 itemrotatez->setEnabled(!anim);
2073 frame_toolbar->setEnabled(!anim);
2074 toolbar_stack->setEnabled(!anim);
2076 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
2077 m_startViewport->setZValue(1100);
2078 QColor col = m_startViewport->pen().color();
2080 m_startViewport->setBrush(col);
2081 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2082 m_startViewport->setSelected(true);
2085 if(m_startViewport->childItems().isEmpty()) addAnimInfoText();
2087 m_startViewport->setZValue(-1000);
2088 m_startViewport->setBrush(QBrush());
2089 m_startViewport->setFlags(0);
2090 if(!anim_end->isChecked()) deleteAnimInfoText();
2095 void TitleWidget::slotAnimEnd(bool anim)
2097 if(anim && anim_start->isChecked()) {
2098 anim_start->setChecked(false);
2099 m_startViewport->setZValue(-1000);
2100 m_startViewport->setBrush(QBrush());
2103 QList<QGraphicsItem *> list = m_scene->items();
2104 for(int i = 0; i < list.count(); i++) {
2105 if(list.at(i)->zValue() > -1000) {
2106 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2107 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2110 align_box->setEnabled(anim);
2111 itemzoom->setEnabled(!anim);
2112 itemrotatex->setEnabled(!anim);
2113 itemrotatey->setEnabled(!anim);
2114 itemrotatez->setEnabled(!anim);
2115 frame_toolbar->setEnabled(!anim);
2116 toolbar_stack->setEnabled(!anim);
2118 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2119 m_endViewport->setZValue(1100);
2120 QColor col = m_endViewport->pen().color();
2122 m_endViewport->setBrush(col);
2123 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2124 m_endViewport->setSelected(true);
2127 if(m_endViewport->childItems().isEmpty()) addAnimInfoText();
2129 m_endViewport->setZValue(-1000);
2130 m_endViewport->setBrush(QBrush());
2131 m_endViewport->setFlags(0);
2132 if(!anim_start->isChecked()) deleteAnimInfoText();
2136 void TitleWidget::addAnimInfoText()
2138 // add text to anim viewport
2139 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2140 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2141 QFont font = t->font();
2142 font.setPixelSize(m_startViewport->rect().width() / 10);
2143 QColor col = m_startViewport->pen().color();
2145 t->setDefaultTextColor(col);
2147 font.setPixelSize(m_endViewport->rect().width() / 10);
2148 col = m_endViewport->pen().color();
2150 t2->setDefaultTextColor(col);
2154 void TitleWidget::updateInfoText()
2156 // update info text font
2157 if(!m_startViewport->childItems().isEmpty()) {
2158 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2160 QFont font = item->font();
2161 font.setPixelSize(m_startViewport->rect().width() / 10);
2162 item->setFont(font);
2165 if(!m_endViewport->childItems().isEmpty()) {
2166 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2168 QFont font = item->font();
2169 font.setPixelSize(m_endViewport->rect().width() / 10);
2170 item->setFont(font);
2175 void TitleWidget::deleteAnimInfoText()
2177 // end animation editing, remove info text
2178 while(!m_startViewport->childItems().isEmpty()) {
2179 QGraphicsItem *item = m_startViewport->childItems().at(0);
2180 m_scene->removeItem(item);
2183 while(!m_endViewport->childItems().isEmpty()) {
2184 QGraphicsItem *item = m_endViewport->childItems().at(0);
2185 m_scene->removeItem(item);
2190 void TitleWidget::slotKeepAspect(bool keep)
2192 if(m_endViewport->zValue() == 1100) {
2193 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2194 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2196 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2197 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2201 void TitleWidget::slotResize50()
2203 if(m_endViewport->zValue() == 1100) {
2204 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2205 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2208 void TitleWidget::slotResize100()
2210 if(m_endViewport->zValue() == 1100) {
2211 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2212 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2215 void TitleWidget::slotResize200()
2217 if(m_endViewport->zValue() == 1100) {
2218 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2219 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2222 void TitleWidget::slotAddEffect(int ix)
2224 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2225 int effect = effect_list->itemData(ix).toInt();
2227 if(list.size() == 1) {
2228 if(effect == NOEFFECT)
2229 effect_stack->setHidden(true);
2231 effect_stack->setCurrentIndex(effect - 1);
2232 effect_stack->setHidden(false);
2234 } else // Hide the effects stack when more than one element is selected.
2235 effect_stack->setHidden(true);
2237 foreach(QGraphicsItem * item, list) {
2240 item->setData(100, QVariant());
2241 #if QT_VERSION >= 0x040600
2242 item->setGraphicsEffect(0);
2245 case TYPEWRITEREFFECT:
2247 * Allow the user to set the typewriter effect to more than one
2248 * element, but do not add it to non-text elements.
2250 if(item->type() == TEXTITEM) {
2251 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2252 item->setData(100, effdata);
2255 #if QT_VERSION >= 0x040600
2256 // Do not remove the non-QGraphicsEffects.
2258 item->setGraphicsEffect(new QGraphicsBlurEffect());
2261 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2268 void TitleWidget::slotFontText(const QString& s)
2271 if(f.exactMatch()) {
2272 // Font really exists (could also just be a «d» if the user
2273 // starts typing «dejavu» for example).
2274 font_family->setCurrentFont(f);
2276 // Note: Typing dejavu serif does not recognize the font (takes sans)
2277 // in older Qt versions. Case must match there (except for first letter)
2280 void TitleWidget::slotEditTypewriter(int /*ix*/)
2282 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2284 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2285 l[0]->setData(100, effdata);
2289 void TitleWidget::slotEditBlur(int ix)
2291 #if QT_VERSION < 0x040600
2294 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2296 QGraphicsEffect *eff = l[0]->graphicsEffect();
2297 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2298 if(blur) blur->setBlurRadius(ix);
2303 void TitleWidget::slotEditShadow()
2305 #if QT_VERSION < 0x040600
2308 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2310 QGraphicsEffect *eff = l[0]->graphicsEffect();
2311 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2313 shadow->setBlurRadius(shadow_radius->value());
2314 shadow->setOffset(shadow_x->value(), shadow_y->value());
2320 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2322 qreal bound = maxBound ? -99 : 99;
2323 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2325 QList<QGraphicsItem*> lItems;
2326 // Get items (all or intersecting only)
2327 if(intersectingOnly) {
2328 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2330 lItems = graphicsView->scene()->items();
2332 if(lItems.size() > 0) {
2333 int n = lItems.size();
2336 for(int i = 0; i < n; i++) {
2337 z = lItems[i]->zValue();
2338 if(z > bound && !lItems[i]->isSelected()) {
2343 // Get minimum z index.
2344 for(int i = 0; i < n; i++) {
2345 z = lItems[i]->zValue();
2346 if(z < bound && !lItems[i]->isSelected() && z > -999) {
2347 // There are items at the very bottom (background e.g.) with z-index < -1000.
2357 void TitleWidget::slotZIndexUp()
2359 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2361 qreal currentZ = l[0]->zValue();
2362 qreal max = zIndexBounds(true, true);
2363 if(currentZ <= max) {
2364 l[0]->setZValue(currentZ + 1);
2365 updateDimension(l[0]);
2370 void TitleWidget::slotZIndexTop()
2372 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2374 qreal currentZ = l[0]->zValue();
2375 qreal max = zIndexBounds(true, false);
2376 if(currentZ <= max) {
2377 l[0]->setZValue(max + 1);
2378 updateDimension(l[0]);
2383 void TitleWidget::slotZIndexDown()
2385 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2387 qreal currentZ = l[0]->zValue();
2388 qreal min = zIndexBounds(false, true);
2389 if(currentZ >= min) {
2390 l[0]->setZValue(currentZ - 1);
2391 updateDimension(l[0]);
2396 void TitleWidget::slotZIndexBottom()
2398 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2400 qreal currentZ = l[0]->zValue();
2401 qreal min = zIndexBounds(false, false);
2402 if(currentZ >= min) {
2403 l[0]->setZValue(min - 1);
2404 updateDimension(l[0]);
2409 void TitleWidget::slotSelectAll()
2411 graphicsView->blockSignals(true);
2412 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2413 for (int i = 0; i < l.size(); i++) {
2414 l.at(i)->setSelected(true);
2416 graphicsView->blockSignals(false);
2417 // Notify the GUI of the selection change
2421 void TitleWidget::selectItems(int itemType)
2423 graphicsView->blockSignals(true);
2424 QList<QGraphicsItem*> l;
2425 if (graphicsView->scene()->selectedItems().size() > 0) {
2426 l = graphicsView->scene()->selectedItems();
2427 for (int i = 0; i < l.size(); i++) {
2428 if (l.at(i)->type() != itemType) {
2429 l.at(i)->setSelected(false);
2433 l = graphicsView->scene()->items();
2434 for (int i = 0; i < l.size(); i++) {
2435 if (l.at(i)->type() == itemType) {
2436 l.at(i)->setSelected(true);
2440 graphicsView->blockSignals(false);
2444 void TitleWidget::slotSelectText()
2446 selectItems(TEXTITEM);
2449 void TitleWidget::slotSelectRects()
2451 selectItems(RECTITEM);
2454 void TitleWidget::slotSelectImages()
2456 selectItems(IMAGEITEM);
2459 void TitleWidget::slotSelectNone()
2461 graphicsView->blockSignals(true);
2462 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2463 for (int i = 0; i < l.size(); i++) {
2464 l.at(i)->setSelected(false);
2466 graphicsView->blockSignals(false);