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(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
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-select-all"), 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-select-texts"), 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);
302 buttonSelectText->setEnabled(false);
304 m_selectRects = new QAction(KIcon("kdenlive-select-rects"), QString(), this);
305 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
306 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
307 buttonSelectRects->setDefaultAction(m_selectRects);
308 buttonSelectRects->setEnabled(false);
310 m_selectImages = new QAction(KIcon("kdenlive-select-images"), QString(), this);
311 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
312 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
313 buttonSelectImages->setDefaultAction(m_selectImages);
314 buttonSelectImages->setEnabled(false);
316 m_unselectAll = new QAction(KIcon("kdenlive-unselect-all"), QString(), this);
317 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
318 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
319 buttonUnselectAll->setDefaultAction(m_unselectAll);
320 buttonUnselectAll->setEnabled(false);
322 zDown->setIcon(KIcon("kdenlive-zindex-down"));
323 zTop->setIcon(KIcon("kdenlive-zindex-top"));
324 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
325 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
326 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
327 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
329 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
330 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
331 rectBColor->setToolTip(i18n("Select fill color"));
332 rectFColor->setToolTip(i18n("Select border color"));
333 rectBAlpha->setToolTip(i18n("Fill opacity"));
334 rectFAlpha->setToolTip(i18n("Border opacity"));
335 zoom_slider->setToolTip(i18n("Zoom"));
336 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
337 buttonFitZoom->setToolTip(i18n("Fit zoom"));
338 backgroundColor->setToolTip(i18n("Select background color"));
339 backgroundAlpha->setToolTip(i18n("Background opacity"));
340 buttonSelectAll->setToolTip(getTooltipWithShortcut(i18n("Select all"), m_selectAll));
341 buttonSelectText->setToolTip(getTooltipWithShortcut(i18n("Select text items in current selection"), m_selectText));
342 buttonSelectRects->setToolTip(getTooltipWithShortcut(i18n("Select rect items in current selection"), m_selectRects));
343 buttonSelectImages->setToolTip(getTooltipWithShortcut(i18n("Select image items in current selection"), m_selectImages));
344 buttonUnselectAll->setToolTip(getTooltipWithShortcut(i18n("Unselect all"), m_unselectAll));
346 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
347 itemhcenter->setToolTip(i18n("Align item horizontally"));
348 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
349 itemvcenter->setToolTip(i18n("Align item vertically"));
350 itemtop->setIcon(KIcon("kdenlive-align-top"));
351 itemtop->setToolTip(i18n("Align item to top"));
352 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
353 itembottom->setToolTip(i18n("Align item to bottom"));
354 itemright->setIcon(KIcon("kdenlive-align-right"));
355 itemright->setToolTip(i18n("Align item to right"));
356 itemleft->setIcon(KIcon("kdenlive-align-left"));
357 itemleft->setToolTip(i18n("Align item to left"));
360 QHBoxLayout *layout = new QHBoxLayout;
361 frame_toolbar->setLayout(layout);
362 layout->setContentsMargins(0, 0, 0, 0);
363 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
364 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
365 m_toolbar->setIconSize(QSize(s, s));
367 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
368 m_buttonCursor->setCheckable(true);
369 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
370 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
371 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
373 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
374 m_buttonText->setCheckable(true);
375 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
376 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
377 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
379 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
380 m_buttonRect->setCheckable(true);
381 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
382 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
383 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
385 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
386 m_buttonImage->setCheckable(false);
387 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
388 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
389 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
391 m_toolbar->addSeparator();
393 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
394 m_buttonLoad->setCheckable(false);
395 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
396 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
398 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
399 m_buttonSave->setCheckable(false);
400 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
401 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
403 layout->addWidget(m_toolbar);
405 // initialize graphic scene
406 m_scene = new GraphicsSceneRectMove(this);
407 graphicsView->setScene(m_scene);
408 graphicsView->setMouseTracking(true);
409 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
410 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
411 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
413 // a gradient background
414 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
415 gradient->setSpread(QGradient::ReflectSpread);
416 scene->setBackgroundBrush(*gradient);*/
418 m_frameImage = new QGraphicsPixmapItem();
420 qtrans.scale(2.0, 2.0);
421 m_frameImage->setTransform(qtrans);
422 m_frameImage->setZValue(-1200);
423 m_frameImage->setFlags(0);
424 displayBackgroundFrame();
425 graphicsView->scene()->addItem(m_frameImage);
427 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
428 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
429 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
430 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
431 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
432 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
433 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
434 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
436 QPen framepen(Qt::DotLine);
437 framepen.setColor(Qt::red);
439 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
440 m_frameBorder->setPen(framepen);
441 m_frameBorder->setZValue(-1100);
442 m_frameBorder->setBrush(Qt::transparent);
443 m_frameBorder->setFlags(0);
444 graphicsView->scene()->addItem(m_frameBorder);
446 // mbd: load saved settings
449 graphicsView->show();
450 //graphicsView->setRenderHint(QPainter::Antialiasing);
451 graphicsView->setInteractive(true);
452 //graphicsView->resize(400, 300);
453 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
454 //toolBox->setItemEnabled(2, false);
455 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
456 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
457 m_startViewport->setData(0, m_frameWidth);
458 m_startViewport->setData(1, m_frameHeight);
459 m_endViewport->setData(0, m_frameWidth);
460 m_endViewport->setData(1, m_frameHeight);
462 if(!url.isEmpty()) loadTitle(url);
465 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
468 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
469 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
470 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
472 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
473 refreshTitleTemplates();
474 //templateBox->setIconSize(QSize(60,60));
475 templateBox->clear();
476 templateBox->addItem("");
477 foreach(TitleTemplate t, titletemplates) {
478 templateBox->addItem(t.icon, t.name, t.file);
480 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
483 TitleWidget::~TitleWidget()
487 delete m_buttonImage;
488 delete m_buttonCursor;
491 delete m_unicodeAction;
498 delete m_selectRects;
499 delete m_selectImages;
500 delete m_unselectAll;
502 delete m_unicodeDialog;
503 delete m_frameBorder;
505 delete m_startViewport;
506 delete m_endViewport;
508 delete m_signalMapper;
512 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
515 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
516 KStandardDirs::makeDir(titlePath);
517 titlePath.append((isClone == false) ? "title" : "clone");
520 while(path.isEmpty() || QFile::exists(path)) {
522 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
524 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
530 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
533 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
534 KStandardDirs::makeDir(titlePath);
535 return titlePath + titleName + ".png";
539 QStringList TitleWidget::extractImageList(QString xml)
542 if(xml.isEmpty()) return result;
545 QDomNodeList images = doc.elementsByTagName("content");
546 for(int i = 0; i < images.count(); i++) {
547 if(images.at(i).toElement().hasAttribute("url"))
548 result.append(images.at(i).toElement().attribute("url"));
554 QStringList TitleWidget::extractFontList(QString xml)
557 if(xml.isEmpty()) return result;
560 QDomNodeList images = doc.elementsByTagName("content");
561 for(int i = 0; i < images.count(); i++) {
562 if(images.at(i).toElement().hasAttribute("font"))
563 result.append(images.at(i).toElement().attribute("font"));
568 void TitleWidget::refreshTitleTemplates()
570 QStringList titlenamelist = QStringList() << i18n("None");
571 QStringList titlefiles = QStringList() << QString();
573 filters << "*.kdenlivetitle" ;
574 titletemplates.clear();
575 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
576 foreach(const QString & folder, titleTemplates) {
577 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
578 foreach(const QString & fname, filesnames) {
579 //titlenamelist.append(fname);
580 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
583 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
584 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
585 titletemplates.append(t);
588 kDebug() << titlenamelist << titlefiles;
590 void TitleWidget::templateIndexChanged(int index)
592 QString item = templateBox->itemData(index).toString();
594 if(lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
595 if(KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
599 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
600 // Text of unchanged template titles should be selected when clicked.
601 QList<QGraphicsItem *> list = graphicsView->scene()->items();
602 foreach(QGraphicsItem * qgItem, list) {
603 if(qgItem->type() == TEXTITEM) {
604 QGraphicsTextItem *i;
605 i = static_cast<QGraphicsTextItem *>(qgItem);
606 i->setProperty("isTemplate", "true");
607 i->setProperty("templateText", i->toHtml());
611 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
615 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
620 void TitleWidget::slotTextTool()
622 m_scene->setTool(TITLE_TEXT);
623 showToolbars(TITLE_TEXT);
624 checkButton(TITLE_TEXT);
627 void TitleWidget::slotRectTool()
629 m_scene->setTool(TITLE_RECTANGLE);
630 showToolbars(TITLE_RECTANGLE);
631 checkButton(TITLE_RECTANGLE);
634 void TitleWidget::slotSelectTool()
636 m_scene->setTool(TITLE_SELECT);
638 // Find out which toolbars need to be shown, depending on selected item
639 TITLETOOL t = TITLE_SELECT;
640 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
642 switch(l.at(0)->type()) {
656 if(t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
657 //graphicsView->centerOn(l.at(0));
663 updateCoordinates(l.at(0));
664 updateDimension(l.at(0));
665 updateRotZoom(l.at(0));
668 checkButton(TITLE_SELECT);
671 void TitleWidget::slotImageTool()
673 // TODO: find a way to get a list of all supported image types...
674 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";
675 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
677 if(url.path().endsWith(".svg")) {
678 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
679 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
680 svg->setZValue(m_count++);
681 svg->setData(Qt::UserRole, url.path());
682 graphicsView->scene()->addItem(svg);
684 QPixmap pix(url.path());
685 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
686 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
687 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
688 image->setData(Qt::UserRole, url.path());
689 image->setZValue(m_count++);
690 graphicsView->scene()->addItem(image);
693 m_scene->setTool(TITLE_SELECT);
694 showToolbars(TITLE_SELECT);
695 checkButton(TITLE_SELECT);
698 void TitleWidget::showToolbars(TITLETOOL toolType)
700 toolbar_stack->setCurrentIndex((int) toolType);
703 void TitleWidget::enableToolbars(TITLETOOL toolType)
705 // TITLETOOL is defined in graphicsscenerectmove.h
707 if(toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
708 value_w->setEnabled(enable);
709 value_h->setEnabled(enable);
712 void TitleWidget::checkButton(TITLETOOL toolType)
714 bool bSelect = false;
726 case TITLE_RECTANGLE:
736 m_buttonCursor->setChecked(bSelect);
737 m_buttonText->setChecked(bText);
738 m_buttonRect->setChecked(bRect);
739 m_buttonImage->setChecked(bImage);
742 void TitleWidget::displayBackgroundFrame()
744 if(!displayBg->isChecked()) {
745 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
746 QPixmap pattern(20, 20);
748 QColor bgcolor(210, 210, 210);
751 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
752 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
757 p.fillRect(bg.rect(), br);
759 m_frameImage->setPixmap(bg);
761 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
765 void TitleWidget::initAnimation()
767 align_box->setEnabled(false);
768 QPen startpen(Qt::DotLine);
769 QPen endpen(Qt::DashDotLine);
770 startpen.setColor(QColor(100, 200, 100, 140));
771 endpen.setColor(QColor(200, 100, 100, 140));
773 m_startViewport->setPen(startpen);
774 m_endViewport->setPen(endpen);
776 m_startViewport->setZValue(-1000);
777 m_endViewport->setZValue(-1000);
779 m_startViewport->setFlags(0);
780 m_endViewport->setFlags(0);
782 graphicsView->scene()->addItem(m_startViewport);
783 graphicsView->scene()->addItem(m_endViewport);
785 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
786 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
787 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
788 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
791 void TitleWidget::slotUpdateZoom(int pos)
793 m_scene->setZoom((double) pos / 100);
794 zoom_label->setText(QString::number(pos) + '%');
797 void TitleWidget::slotZoom(bool up)
799 int pos = zoom_slider->value();
802 zoom_slider->setValue(pos);
805 void TitleWidget::slotAdjustZoom()
807 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
808 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
809 if (scalex > scaley) scalex = scaley;
810 int zoompos = (int)(scalex * 7 + 0.5);*/
811 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
812 int zoompos = graphicsView->matrix().m11() * 100;
813 zoom_slider->setValue(zoompos);
814 graphicsView->centerOn(m_frameBorder);
817 void TitleWidget::slotZoomOneToOne()
819 zoom_slider->setValue(100);
820 graphicsView->centerOn(m_frameBorder);
823 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
825 updateAxisButtons(rect); // back to default
827 QColor f = rectFColor->color();
828 f.setAlpha(rectFAlpha->value());
830 penf.setWidth(rectLineWidth->value());
831 penf.setJoinStyle(Qt::RoundJoin);
833 QColor b = rectBColor->color();
834 b.setAlpha(rectBAlpha->value());
835 rect->setBrush(QBrush(b));
836 rect->setZValue(m_count++);
837 rect->setData(ZOOMFACTOR, 100);
838 //setCurrentItem(rect);
839 //graphicsView->setFocus();
842 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
844 updateAxisButtons(tt); // back to default
846 QFont font = font_family->currentFont();
847 font.setPixelSize(font_size->value());
849 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
850 font.setItalic(buttonItalic->isChecked());
851 font.setUnderline(buttonUnder->isChecked());
854 QColor color = fontColorButton->color();
855 color.setAlpha(textAlpha->value());
856 tt->setDefaultTextColor(color);
858 QTextCursor cur(tt->document());
859 cur.select(QTextCursor::Document);
860 QTextBlockFormat format = cur.blockFormat();
861 QTextCharFormat cformat = cur.charFormat();
862 QColor outlineColor = textOutlineColor->color();
863 outlineColor.setAlpha(textOutlineAlpha->value());
864 double outlineWidth = textOutline->value() / 10.0;
866 tt->setData(101, outlineWidth);
867 tt->setData(102, outlineColor);
868 if(outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
870 cformat.setForeground(QBrush(color));
871 cur.setCharFormat(cformat);
872 cur.setBlockFormat(format);
873 tt->setTextCursor(cur);
874 tt->setZValue(m_count++);
878 void TitleWidget::setFontBoxWeight(int weight)
880 int index = font_weight_box->findData(weight);
882 index = font_weight_box->findData(QFont::Normal);
884 font_weight_box->setCurrentIndex(index);
887 void TitleWidget::setCurrentItem(QGraphicsItem *item)
889 m_scene->setSelectedItem(item);
892 void TitleWidget::zIndexChanged(int v)
894 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
900 void TitleWidget::selectionChanged()
902 if(m_scene->tool() != TITLE_SELECT) return;
904 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
906 QList<QGraphicsItem *> l;
908 // mbt 1607: One text item might have grabbed the keyboard.
909 // Ungrab it for all items that are not selected, otherwise
910 // text input would only work for the text item that grabbed
911 // the keyboard last.
912 l = graphicsView->scene()->items();
913 foreach(QGraphicsItem * item, l) {
914 if(item->type() == TEXTITEM && !item->isSelected()) {
915 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
920 l = graphicsView->scene()->selectedItems();
923 buttonUnselectAll->setEnabled(true);
925 buttonUnselectAll->setEnabled(false);
928 buttonSelectText->setEnabled(true);
929 buttonSelectRects->setEnabled(true);
930 buttonSelectImages->setEnabled(true);
932 buttonSelectText->setEnabled(false);
933 buttonSelectRects->setEnabled(false);
934 buttonSelectImages->setEnabled(false);
938 //toolBox->setItemEnabled(2, false);
939 //toolBox->setItemEnabled(3, false);
940 effect_list->blockSignals(true);
941 value_x->blockSignals(true);
942 value_y->blockSignals(true);
943 value_w->blockSignals(true);
944 value_h->blockSignals(true);
945 itemzoom->blockSignals(true);
946 itemrotatex->blockSignals(true);
947 itemrotatey->blockSignals(true);
948 itemrotatez->blockSignals(true);
950 effect_stack->setHidden(true);
951 effect_frame->setEnabled(false);
952 effect_list->setCurrentIndex(0);
953 bool blockX = !origin_x_left->signalsBlocked();
954 bool blockY = !origin_y_top->signalsBlocked();
955 if(blockX) origin_x_left->blockSignals(true);
956 if(blockY) origin_y_top->blockSignals(true);
957 origin_x_left->setChecked(false);
958 origin_y_top->setChecked(false);
961 enableToolbars(TITLE_SELECT);
962 if(blockX) origin_x_left->blockSignals(false);
963 if(blockY) origin_y_top->blockSignals(false);
964 itemzoom->setEnabled(false);
965 itemrotatex->setEnabled(false);
966 itemrotatey->setEnabled(false);
967 itemrotatez->setEnabled(false);
968 frame_properties->setEnabled(false);
969 } else if(l.size() == 1) {
970 effect_frame->setEnabled(true);
971 frame_properties->setEnabled(true);
972 if(l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
973 itemzoom->setEnabled(true);
974 itemrotatex->setEnabled(true);
975 itemrotatey->setEnabled(true);
976 itemrotatez->setEnabled(true);
978 itemzoom->setEnabled(false);
979 itemrotatex->setEnabled(false);
980 itemrotatey->setEnabled(false);
981 itemrotatez->setEnabled(false);
984 if(l.at(0)->type() == TEXTITEM) {
985 showToolbars(TITLE_TEXT);
986 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
987 if(!i->data(100).isNull()) {
988 // Item has an effect
989 QStringList effdata = i->data(100).toStringList();
990 QString effectName = effdata.takeFirst();
991 if(effectName == "typewriter") {
992 QStringList params = effdata.at(0).split(';');
993 typewriter_delay->setValue(params.at(0).toInt());
994 typewriter_start->setValue(params.at(1).toInt());
995 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
996 effect_stack->setHidden(false);
999 #if QT_VERSION >= 0x040600
1000 if(i->graphicsEffect()) {
1001 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
1003 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
1004 int rad = (int) blur->blurRadius();
1005 blur_radius->setValue(rad);
1006 effect_stack->setHidden(false);
1008 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
1010 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
1011 shadow_radius->setValue(shad->blurRadius());
1012 shadow_x->setValue(shad->xOffset());
1013 shadow_y->setValue(shad->yOffset());
1014 effect_stack->setHidden(false);
1018 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
1019 effect_stack->setHidden(true);
1022 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
1023 effect_stack->setHidden(true);
1026 //if (l[0]->hasFocus())
1027 //toolBox->setCurrentIndex(0);
1028 //toolBox->setItemEnabled(2, true);
1029 font_size->blockSignals(true);
1030 font_family->blockSignals(true);
1031 font_weight_box->blockSignals(true);
1032 buttonItalic->blockSignals(true);
1033 buttonUnder->blockSignals(true);
1034 fontColorButton->blockSignals(true);
1035 textAlpha->blockSignals(true);
1036 buttonAlignLeft->blockSignals(true);
1037 buttonAlignRight->blockSignals(true);
1038 buttonAlignNone->blockSignals(true);
1039 buttonAlignCenter->blockSignals(true);
1041 QFont font = i->font();
1042 font_family->setCurrentFont(font);
1043 font_size->setValue(font.pixelSize());
1044 m_scene->slotUpdateFontSize(font.pixelSize());
1045 buttonItalic->setChecked(font.italic());
1046 buttonUnder->setChecked(font.underline());
1047 setFontBoxWeight(font.weight());
1049 QTextCursor cursor(i->document());
1050 cursor.select(QTextCursor::Document);
1051 QColor color = cursor.charFormat().foreground().color();
1052 textAlpha->setValue(color.alpha());
1053 color.setAlpha(255);
1054 fontColorButton->setColor(color);
1056 if(!i->data(101).isNull()) {
1057 textOutline->blockSignals(true);
1058 textOutline->setValue(i->data(101).toDouble() * 10);
1059 textOutline->blockSignals(false);
1061 if(!i->data(102).isNull()) {
1062 textOutlineColor->blockSignals(true);
1063 textOutlineAlpha->blockSignals(true);
1064 color = QColor(i->data(102).toString());
1065 textOutlineAlpha->setValue(color.alpha());
1066 color.setAlpha(255);
1067 textOutlineColor->setColor(color);
1068 textOutlineColor->blockSignals(false);
1069 textOutlineAlpha->blockSignals(false);
1071 QTextCursor cur = i->textCursor();
1072 QTextBlockFormat format = cur.blockFormat();
1073 if(i->textWidth() == -1) buttonAlignNone->setChecked(true);
1074 else if(format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
1075 else if(format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
1076 else if(format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
1078 font_size->blockSignals(false);
1079 font_family->blockSignals(false);
1080 font_weight_box->blockSignals(false);
1081 buttonItalic->blockSignals(false);
1082 buttonUnder->blockSignals(false);
1083 fontColorButton->blockSignals(false);
1084 textAlpha->blockSignals(false);
1085 buttonAlignLeft->blockSignals(false);
1086 buttonAlignRight->blockSignals(false);
1087 buttonAlignNone->blockSignals(false);
1088 buttonAlignCenter->blockSignals(false);
1090 // mbt 1607: Select text if the text item is an unchanged template item.
1091 if(i->property("isTemplate").isValid()) {
1092 cur.setPosition(0, QTextCursor::MoveAnchor);
1093 cur.select(QTextCursor::Document);
1094 i->setTextCursor(cur);
1095 // Make text editable now.
1097 i->setTextInteractionFlags(Qt::TextEditorInteraction);
1100 updateAxisButtons(i);
1101 updateCoordinates(i);
1103 enableToolbars(TITLE_TEXT);
1105 } else if((l.at(0))->type() == RECTITEM) {
1106 showToolbars(TITLE_RECTANGLE);
1108 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1109 if(rec == m_startViewport || rec == m_endViewport) {
1110 /*toolBox->setCurrentIndex(3);
1111 toolBox->widget(0)->setEnabled(false);
1112 toolBox->widget(1)->setEnabled(false);*/
1113 enableToolbars(TITLE_SELECT);
1115 /*toolBox->widget(0)->setEnabled(true);
1116 toolBox->widget(1)->setEnabled(true);
1117 toolBox->setCurrentIndex(0);*/
1118 //toolBox->setItemEnabled(3, true);
1119 rectFAlpha->setValue(rec->pen().color().alpha());
1120 rectBAlpha->setValue(rec->brush().color().alpha());
1121 //kDebug() << rec->brush().color().alpha();
1122 QColor fcol = rec->pen().color();
1123 QColor bcol = rec->brush().color();
1124 //fcol.setAlpha(255);
1125 //bcol.setAlpha(255);
1126 rectFColor->setColor(fcol);
1127 rectBColor->setColor(bcol);
1129 rectLineWidth->setValue(rec->pen().width());
1130 enableToolbars(TITLE_RECTANGLE);
1133 updateAxisButtons(l.at(0));
1134 updateCoordinates(rec);
1135 updateDimension(rec);
1137 } else if(l.at(0)->type() == IMAGEITEM) {
1138 showToolbars(TITLE_IMAGE);
1140 updateCoordinates(l.at(0));
1141 updateDimension(l.at(0));
1143 enableToolbars(TITLE_IMAGE);
1146 //toolBox->setCurrentIndex(0);
1147 showToolbars(TITLE_SELECT);
1148 enableToolbars(TITLE_SELECT);
1149 frame_properties->setEnabled(false);
1151 zValue->setValue((int)l.at(0)->zValue());
1152 if(!l.at(0)->data(ZOOMFACTOR).isNull()) itemzoom->setValue(l.at(0)->data(ZOOMFACTOR).toInt());
1153 else itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
1154 itemrotatex->setValue((int)(m_transformations.value(l.at(0)).rotatex));
1155 itemrotatey->setValue((int)(m_transformations.value(l.at(0)).rotatey));
1156 itemrotatez->setValue((int)(m_transformations.value(l.at(0)).rotatez));
1157 value_x->blockSignals(false);
1158 value_y->blockSignals(false);
1159 value_w->blockSignals(false);
1160 value_h->blockSignals(false);
1161 itemzoom->blockSignals(false);
1162 itemrotatex->blockSignals(false);
1163 itemrotatey->blockSignals(false);
1164 itemrotatez->blockSignals(false);
1166 // More than one item selected
1169 // Tools working on more than one element.
1171 effect_list->blockSignals(false);
1175 void TitleWidget::slotValueChanged(int type)
1177 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1178 if(l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
1183 val = value_w->value();
1186 val = value_h->value();
1190 QGraphicsItem *i = l.at(0);
1191 Transform t = m_transformations.value(i);
1193 // Ratio width:height
1194 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1195 // TODO: proper calculation for rotation around 3 axes
1196 double alpha = (double) t.rotatez / 180.0 * M_PI;
1199 double length = val;
1206 // Add 0.5 because otherwise incrementing by 1 might have no effect
1207 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1208 scale = length / i->boundingRect().width();
1211 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1212 scale = length / i->boundingRect().height();
1219 qtrans.scale(scale, scale);
1220 qtrans.rotate(t.rotatex, Qt::XAxis);
1221 qtrans.rotate(t.rotatey, Qt::YAxis);
1222 qtrans.rotate(t.rotatez, Qt::ZAxis);
1223 i->setTransform(qtrans);
1224 m_transformations[i] = t;
1231 void TitleWidget::slotAdjustSelectedItem()
1233 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1235 if(l.at(0)->type() == RECTITEM) {
1237 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1238 updatePosition(rec);
1239 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1240 } else if(l.at(0)->type() == TEXTITEM) {
1242 updatePosition(l.at(0));
1243 } else if(l.at(0)->type() == IMAGEITEM) {
1245 updatePosition(l.at(0));
1250 void TitleWidget::updateDimension(QGraphicsItem *i)
1252 value_w->blockSignals(true);
1253 value_h->blockSignals(true);
1254 zValue->blockSignals(true);
1256 zValue->setValue((int) i->zValue());
1257 if(i->type() == IMAGEITEM) {
1258 // Get multipliers for rotation/scaling
1260 /*Transform t = m_transformations.value(i);
1261 QRectF r = i->boundingRect();
1262 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1263 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1264 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1265 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1267 value_w->setValue(i->sceneBoundingRect().width());
1268 value_h->setValue(i->sceneBoundingRect().height());
1269 } else if(i->type() == RECTITEM) {
1270 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1271 value_w->setValue((int) r->rect().width());
1272 value_h->setValue((int) r->rect().height());
1273 } else if(i->type() == TEXTITEM) {
1274 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1275 value_w->setValue((int) t->boundingRect().width());
1276 value_h->setValue((int) t->boundingRect().height());
1279 zValue->blockSignals(false);
1280 value_w->blockSignals(false);
1281 value_h->blockSignals(false);
1284 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1286 // Block signals emitted by this method
1287 value_x->blockSignals(true);
1288 value_y->blockSignals(true);
1290 if(i->type() == TEXTITEM) {
1292 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1294 // Set the correct x coordinate value
1295 if(origin_x_left->isChecked()) {
1296 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1297 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1299 // Origin is at 0 (default)
1300 value_x->setValue((int) rec->pos().x());
1304 if(origin_y_top->isChecked()) {
1305 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1307 value_y->setValue((int) rec->pos().y());
1310 } else if(i->type() == RECTITEM) {
1312 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1314 if(origin_x_left->isChecked()) {
1315 // Origin (0 point) is at m_frameWidth
1316 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1318 // Origin is at 0 (default)
1319 value_x->setValue((int) rec->pos().x());
1322 if(origin_y_top->isChecked()) {
1323 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1325 value_y->setValue((int) rec->pos().y());
1328 } else if(i->type() == IMAGEITEM) {
1330 if(origin_x_left->isChecked()) {
1331 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1333 value_x->setValue((int) i->pos().x());
1336 if(origin_y_top->isChecked()) {
1337 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1339 value_y->setValue((int) i->pos().y());
1344 // Stop blocking signals now
1345 value_x->blockSignals(false);
1346 value_y->blockSignals(false);
1349 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1351 itemzoom->blockSignals(true);
1352 itemrotatex->blockSignals(true);
1353 itemrotatey->blockSignals(true);
1354 itemrotatez->blockSignals(true);
1356 Transform t = m_transformations.value(i);
1358 if(!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1359 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1361 itemrotatex->setValue((int)(t.rotatex));
1362 itemrotatey->setValue((int)(t.rotatey));
1363 itemrotatez->setValue((int)(t.rotatez));
1365 itemzoom->blockSignals(false);
1366 itemrotatex->blockSignals(false);
1367 itemrotatey->blockSignals(false);
1368 itemrotatez->blockSignals(false);
1371 void TitleWidget::updatePosition(QGraphicsItem *i)
1373 if(i->type() == TEXTITEM) {
1374 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1377 if(origin_x_left->isChecked()) {
1379 * Origin of the X axis is at m_frameWidth, and distance from right
1380 * border of the item to the right border of the frame is taken. See
1381 * comment to slotOriginXClicked().
1383 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1385 posX = value_x->value();
1389 if(origin_y_top->isChecked()) {
1390 /* Same for y axis */
1391 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1393 posY = value_y->value();
1396 rec->setPos(posX, posY);
1398 } else if(i->type() == RECTITEM) {
1400 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1403 if(origin_x_left->isChecked()) {
1404 posX = m_frameWidth - value_x->value() - rec->rect().width();
1406 posX = value_x->value();
1410 if(origin_y_top->isChecked()) {
1411 posY = m_frameHeight - value_y->value() - rec->rect().height();
1413 posY = value_y->value();
1416 rec->setPos(posX, posY);
1418 } else if(i->type() == IMAGEITEM) {
1420 if(origin_x_left->isChecked()) {
1421 // Use the sceneBoundingRect because this also regards transformations like zoom
1422 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1424 posX = value_x->value();
1428 if(origin_y_top->isChecked()) {
1429 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1431 posY = value_y->value();
1434 i->setPos(posX, posY);
1440 void TitleWidget::updateTextOriginX()
1442 if(origin_x_left->isChecked()) {
1443 origin_x_left->setText(i18n("\u2212X"));
1445 origin_x_left->setText(i18n("+X"));
1449 void TitleWidget::slotOriginXClicked()
1451 // Update the text displayed on the button.
1452 updateTextOriginX();
1454 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1456 updateCoordinates(l.at(0));
1458 // Remember x axis setting
1459 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1460 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1462 graphicsView->setFocus();
1465 void TitleWidget::updateTextOriginY()
1467 if(origin_y_top->isChecked()) {
1468 origin_y_top->setText(i18n("\u2212Y"));
1470 origin_y_top->setText(i18n("+Y"));
1474 void TitleWidget::slotOriginYClicked()
1476 // Update the text displayed on the button.
1477 updateTextOriginY();
1479 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1481 updateCoordinates(l.at(0));
1483 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1484 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1487 graphicsView->setFocus();
1490 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1492 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1493 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1494 origin_x_left->blockSignals(true);
1495 origin_y_top->blockSignals(true);
1497 if(xAxis == TitleDocument::AxisInverted) {
1498 origin_x_left->setChecked(true);
1500 origin_x_left->setChecked(false);
1502 updateTextOriginX();
1504 if(yAxis == TitleDocument::AxisInverted) {
1505 origin_y_top->setChecked(true);
1507 origin_y_top->setChecked(false);
1509 updateTextOriginY();
1511 origin_x_left->blockSignals(false);
1512 origin_y_top->blockSignals(false);
1515 void TitleWidget::slotChangeBackground()
1517 QColor color = backgroundColor->color();
1518 color.setAlpha(backgroundAlpha->value());
1519 m_frameBorder->setBrush(QBrush(color));
1522 void TitleWidget::slotChanged()
1524 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1525 if(l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1526 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1530 void TitleWidget::textChanged(QGraphicsTextItem *i)
1533 * If the user has set origin_x_left (the same for y), we need to look
1534 * whether a text element has been selected. If yes, we need to ensure that
1535 * the right border of the text field remains fixed also when some text has
1538 * This is also known as right-justified, with the difference that it is not
1539 * valid for text but for its boundingRect. Text may still be
1544 if(origin_x_left->isChecked() || origin_y_top->isChecked()) {
1545 if(!i->toPlainText().isEmpty())
1549 * Don't do anything if the string is empty. If the position were
1550 * updated here, a newly created text field would be set to the
1551 * position of the last selected text field.
1556 // mbt 1607: Template text has changed; don't auto-select content anymore.
1557 if(i->property("isTemplate").isValid()) {
1558 if(i->property("templateText").isValid()) {
1559 if(i->property("templateText") == i->toHtml()) {
1560 // Unchanged, do nothing.
1562 i->setProperty("isTemplate", QVariant::Invalid);
1563 i->setProperty("templateText", QVariant::Invalid);
1569 void TitleWidget::slotInsertUnicode()
1571 m_unicodeDialog->exec();
1574 void TitleWidget::slotInsertUnicodeString(QString text)
1576 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1578 if(l.at(0)->type() == TEXTITEM) {
1579 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1580 t->textCursor().insertText(text);
1585 void TitleWidget::slotUpdateText()
1587 QFont font = font_family->currentFont();
1588 font.setPixelSize(font_size->value());
1589 font.setItalic(buttonItalic->isChecked());
1590 font.setUnderline(buttonUnder->isChecked());
1591 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1592 QColor color = fontColorButton->color();
1593 color.setAlpha(textAlpha->value());
1595 QColor outlineColor = textOutlineColor->color();
1596 outlineColor.setAlpha(textOutlineAlpha->value());
1597 double outlineWidth = textOutline->value() / 10.0;
1600 for(i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1601 QGraphicsTextItem* item = NULL;
1602 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1603 if(l.at(i)->type() == TEXTITEM) {
1604 item = static_cast <QGraphicsTextItem *>(l.at(i));
1607 // No text item, try next one.
1611 // Set alignment of all text in the text item
1612 QTextCursor cur(item->document());
1613 cur.select(QTextCursor::Document);
1614 QTextBlockFormat format = cur.blockFormat();
1615 if(buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1616 item->setTextWidth(item->boundingRect().width());
1617 if(buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1618 else if(buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1619 else if(buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1621 format.setAlignment(Qt::AlignLeft);
1622 item->setTextWidth(-1);
1625 // Set font properties
1626 item->setFont(font);
1627 QTextCharFormat cformat = cur.charFormat();
1629 item->setData(101, outlineWidth);
1630 item->setData(102, outlineColor);
1631 if(outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1633 cformat.setForeground(QBrush(color));
1634 cur.setCharFormat(cformat);
1635 cur.setBlockFormat(format);
1636 // item->setTextCursor(cur);
1637 cur.clearSelection();
1638 item->setTextCursor(cur);
1642 void TitleWidget::rectChanged()
1644 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1646 for(i = 0; i < l.length(); i++) {
1647 if(l.at(i)->type() == RECTITEM && !settingUp) {
1648 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1649 QColor f = rectFColor->color();
1650 f.setAlpha(rectFAlpha->value());
1652 penf.setWidth(rectLineWidth->value());
1653 penf.setJoinStyle(Qt::RoundJoin);
1655 QColor b = rectBColor->color();
1656 b.setAlpha(rectBAlpha->value());
1657 rec->setBrush(QBrush(b));
1662 void TitleWidget::itemScaled(int val)
1664 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1666 Transform x = m_transformations.value(l.at(0));
1667 x.scalex = (double)val / 100.0;
1668 x.scaley = (double)val / 100.0;
1670 qtrans.scale(x.scalex, x.scaley);
1671 qtrans.rotate(x.rotatex, Qt::XAxis);
1672 qtrans.rotate(x.rotatey, Qt::YAxis);
1673 qtrans.rotate(x.rotatez, Qt::ZAxis);
1674 l[0]->setTransform(qtrans);
1675 l[0]->setData(ZOOMFACTOR, val);
1676 m_transformations[l.at(0)] = x;
1677 updateDimension(l.at(0));
1681 void TitleWidget::itemRotateX(qreal val)
1686 void TitleWidget::itemRotateY(qreal val)
1691 void TitleWidget::itemRotateZ(qreal val)
1696 void TitleWidget::itemRotate(qreal val, int axis)
1698 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1700 Transform x = m_transformations[l.at(0)];
1713 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1716 qtrans.scale(x.scalex, x.scaley);
1717 qtrans.rotate(x.rotatex, Qt::XAxis);
1718 qtrans.rotate(x.rotatey, Qt::YAxis);
1719 qtrans.rotate(x.rotatez, Qt::ZAxis);
1720 l[0]->setTransform(qtrans);
1721 m_transformations[l.at(0)] = x;
1722 if(l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1723 updateDimension(l.at(0));
1727 void TitleWidget::itemHCenter()
1729 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1731 QGraphicsItem *item = l.at(0);
1732 QRectF br = item->sceneBoundingRect();
1733 int width = (int)br.width();
1734 int newPos = (int)((m_frameWidth - width) / 2);
1735 newPos += item->pos().x() - br.left(); // Check item transformation
1736 item->setPos(newPos, item->pos().y());
1737 updateCoordinates(item);
1741 void TitleWidget::itemVCenter()
1743 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1745 QGraphicsItem *item = l.at(0);
1746 QRectF br = item->sceneBoundingRect();
1747 int height = (int)br.height();
1748 int newPos = (int)((m_frameHeight - height) / 2);
1749 newPos += item->pos().y() - br.top(); // Check item transformation
1750 item->setPos(item->pos().x(), newPos);
1751 updateCoordinates(item);
1755 void TitleWidget::itemTop()
1757 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1759 QGraphicsItem *item = l.at(0);
1760 QRectF br = item->sceneBoundingRect();
1762 if(br.top() > 0) diff = -br.top();
1763 else diff = -br.bottom();
1764 item->moveBy(0, diff);
1765 updateCoordinates(item);
1769 void TitleWidget::itemBottom()
1771 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1773 QGraphicsItem *item = l.at(0);
1774 QRectF br = item->sceneBoundingRect();
1776 if(br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1777 else diff = m_frameHeight - br.bottom();
1778 item->moveBy(0, diff);
1779 updateCoordinates(item);
1783 void TitleWidget::itemLeft()
1785 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1787 QGraphicsItem *item = l.at(0);
1788 QRectF br = item->sceneBoundingRect();
1790 if(br.left() > 0) diff = -br.left();
1791 else diff = -br.right();
1792 item->moveBy(diff, 0);
1793 updateCoordinates(item);
1797 void TitleWidget::itemRight()
1799 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1801 QGraphicsItem *item = l.at(0);
1802 QRectF br = item->sceneBoundingRect();
1804 if(br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1805 else diff = m_frameWidth - br.left();
1806 item->moveBy(diff, 0);
1807 updateCoordinates(item);
1811 void TitleWidget::setupViewports()
1813 //double aspect_ratio = 4.0 / 3.0;//read from project
1814 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1815 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1816 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1817 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1818 QPolygonF spoly(sp);
1819 QPolygonF epoly(ep);
1820 spoly.translate(startViewportX->value(), startViewportY->value());
1821 epoly.translate(endViewportX->value(), endViewportY->value());
1822 m_startViewport->setPolygon(spoly);
1823 m_endViewport->setPolygon(epoly);
1824 if (! insertingValues) {
1825 m_startViewport->setData(0, startViewportX->value());
1826 m_startViewport->setData(1, startViewportY->value());
1827 m_startViewport->setData(2, startViewportSize->value());
1829 m_endViewport->setData(0, endViewportX->value());
1830 m_endViewport->setData(1, endViewportY->value());
1831 m_endViewport->setData(2, endViewportSize->value());
1835 void TitleWidget::loadTitle(KUrl url)
1837 if(url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1838 if(!url.isEmpty()) {
1839 QList<QGraphicsItem *> items = m_scene->items();
1840 for(int i = 0; i < items.size(); i++) {
1841 if(items.at(i)->zValue() > -1000) delete items.at(i);
1843 m_scene->clearTextSelection();
1847 if(KIO::NetAccess::download(url, tmpfile, 0)) {
1848 QFile file(tmpfile);
1849 if(file.open(QIODevice::ReadOnly)) {
1850 doc.setContent(&file, false);
1853 KIO::NetAccess::removeTempFile(tmpfile);
1858 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1860 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1861 insertingValues = true;
1862 startViewportX->setValue(m_startViewport->data(0).toInt());
1863 startViewportY->setValue(m_startViewport->data(1).toInt());
1864 startViewportSize->setValue(m_startViewport->data(2).toInt());
1865 endViewportX->setValue(m_endViewport->data(0).toInt());
1866 endViewportY->setValue(m_endViewport->data(1).toInt());
1867 endViewportSize->setValue(m_endViewport->data(2).toInt());
1869 insertingValues = false;
1875 void TitleWidget::saveTitle(KUrl url)
1877 if(anim_start->isChecked()) slotAnimStart(false);
1878 if(anim_end->isChecked()) slotAnimEnd(false);
1880 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1881 fs->setOperationMode(KFileDialog::Saving);
1882 fs->setMode(KFile::File);
1883 #if KDE_IS_VERSION(4,2,0)
1884 fs->setConfirmOverwrite(true);
1886 fs->setKeepLocation(true);
1888 url = fs->selectedUrl();
1891 if(!url.isEmpty()) {
1892 if(m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()) - 1) == false)
1893 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1897 QDomDocument TitleWidget::xml()
1899 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1900 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()) - 1);
1904 int TitleWidget::outPoint() const
1906 return m_tc.getFrameCount(title_duration->text()) - 1;
1909 void TitleWidget::setXml(QDomDocument doc)
1912 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1914 title_duration->setText(m_tc.getTimecode(GenTime(out + 1, m_render->fps())));
1915 /*if (doc.documentElement().hasAttribute("out")) {
1916 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1917 title_duration->setText(m_tc.getTimecode(duration));
1919 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1921 QDomElement e = doc.documentElement();
1922 m_transformations.clear();
1923 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1924 const double PI = 4.0 * atan(1.0);
1925 for(int i = 0; i < items.count(); i++) {
1926 QTransform t = items.at(i)->transform();
1930 if(!items.at(i)->data(ROTATEFACTOR).isNull()) {
1931 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1932 if(rotlist.count() >= 3) {
1933 x.rotatex = rotlist[0].toDouble();
1934 x.rotatey = rotlist[1].toDouble();
1935 x.rotatez = rotlist[2].toDouble();
1937 // Try to adjust zoom
1938 t.rotate(x.rotatex *(-1), Qt::XAxis);
1939 t.rotate(x.rotatey *(-1), Qt::YAxis);
1940 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1951 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1953 m_transformations[items.at(i)] = x;
1955 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1956 QColor background_color = m_titledocument.getBackgroundColor();
1957 backgroundAlpha->blockSignals(true);
1958 backgroundColor->blockSignals(true);
1959 backgroundAlpha->setValue(background_color.alpha());
1960 background_color.setAlpha(255);
1961 backgroundColor->setColor(background_color);
1962 backgroundAlpha->blockSignals(false);
1963 backgroundColor->blockSignals(false);
1965 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1966 startViewportY->setValue(m_startViewport->data(1).toInt());
1967 startViewportSize->setValue(m_startViewport->data(2).toInt());
1968 endViewportX->setValue(m_endViewport->data(0).toInt());
1969 endViewportY->setValue(m_endViewport->data(1).toInt());
1970 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1972 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1977 void TitleWidget::slotAccepted()
1979 if(anim_start->isChecked()) slotAnimStart(false);
1980 if(anim_end->isChecked()) slotAnimEnd(false);
1984 void TitleWidget::writeChoices()
1986 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1987 KSharedConfigPtr config = KGlobal::config();
1988 KConfigGroup titleConfig(config, "TitleWidget");
1989 // Write the entries
1990 titleConfig.writeEntry("font_family", font_family->currentFont());
1991 //titleConfig.writeEntry("font_size", font_size->value());
1992 titleConfig.writeEntry("font_pixel_size", font_size->value());
1993 titleConfig.writeEntry("font_color", fontColorButton->color());
1994 titleConfig.writeEntry("font_alpha", textAlpha->value());
1995 titleConfig.writeEntry("font_outline", textOutline->value());
1996 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1997 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1998 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1999 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
2000 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
2002 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
2003 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
2004 titleConfig.writeEntry("rect_background_color", rectBColor->color());
2005 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
2006 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
2008 titleConfig.writeEntry("background_color", backgroundColor->color());
2009 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
2011 //! \todo Not sure if I should sync - it is probably safe to do it
2016 void TitleWidget::readChoices()
2018 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
2019 KSharedConfigPtr config = KGlobal::config();
2020 KConfigGroup titleConfig(config, "TitleWidget");
2022 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
2023 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
2024 m_scene->slotUpdateFontSize(font_size->value());
2025 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
2026 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
2028 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
2029 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
2030 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
2033 if(titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
2034 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
2035 setFontBoxWeight(weight);
2036 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
2037 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
2039 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
2040 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
2041 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
2042 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
2043 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
2045 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
2046 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
2049 void TitleWidget::adjustFrameSize()
2051 m_frameWidth = m_titledocument.frameWidth();
2052 m_frameHeight = m_titledocument.frameHeight();
2053 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
2054 displayBackgroundFrame();
2057 void TitleWidget::slotAnimStart(bool anim)
2059 if(anim && anim_end->isChecked()) {
2060 anim_end->setChecked(false);
2061 m_endViewport->setZValue(-1000);
2062 m_endViewport->setBrush(QBrush());
2065 QList<QGraphicsItem *> list = m_scene->items();
2066 for(int i = 0; i < list.count(); i++) {
2067 if(list.at(i)->zValue() > -1000) {
2068 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2069 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2072 align_box->setEnabled(anim);
2073 itemzoom->setEnabled(!anim);
2074 itemrotatex->setEnabled(!anim);
2075 itemrotatey->setEnabled(!anim);
2076 itemrotatez->setEnabled(!anim);
2077 frame_toolbar->setEnabled(!anim);
2078 toolbar_stack->setEnabled(!anim);
2080 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
2081 m_startViewport->setZValue(1100);
2082 QColor col = m_startViewport->pen().color();
2084 m_startViewport->setBrush(col);
2085 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2086 m_startViewport->setSelected(true);
2089 if(m_startViewport->childItems().isEmpty()) addAnimInfoText();
2091 m_startViewport->setZValue(-1000);
2092 m_startViewport->setBrush(QBrush());
2093 m_startViewport->setFlags(0);
2094 if(!anim_end->isChecked()) deleteAnimInfoText();
2099 void TitleWidget::slotAnimEnd(bool anim)
2101 if(anim && anim_start->isChecked()) {
2102 anim_start->setChecked(false);
2103 m_startViewport->setZValue(-1000);
2104 m_startViewport->setBrush(QBrush());
2107 QList<QGraphicsItem *> list = m_scene->items();
2108 for(int i = 0; i < list.count(); i++) {
2109 if(list.at(i)->zValue() > -1000) {
2110 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2111 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2114 align_box->setEnabled(anim);
2115 itemzoom->setEnabled(!anim);
2116 itemrotatex->setEnabled(!anim);
2117 itemrotatey->setEnabled(!anim);
2118 itemrotatez->setEnabled(!anim);
2119 frame_toolbar->setEnabled(!anim);
2120 toolbar_stack->setEnabled(!anim);
2122 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2123 m_endViewport->setZValue(1100);
2124 QColor col = m_endViewport->pen().color();
2126 m_endViewport->setBrush(col);
2127 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2128 m_endViewport->setSelected(true);
2131 if(m_endViewport->childItems().isEmpty()) addAnimInfoText();
2133 m_endViewport->setZValue(-1000);
2134 m_endViewport->setBrush(QBrush());
2135 m_endViewport->setFlags(0);
2136 if(!anim_start->isChecked()) deleteAnimInfoText();
2140 void TitleWidget::addAnimInfoText()
2142 // add text to anim viewport
2143 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2144 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2145 QFont font = t->font();
2146 font.setPixelSize(m_startViewport->rect().width() / 10);
2147 QColor col = m_startViewport->pen().color();
2149 t->setDefaultTextColor(col);
2151 font.setPixelSize(m_endViewport->rect().width() / 10);
2152 col = m_endViewport->pen().color();
2154 t2->setDefaultTextColor(col);
2158 void TitleWidget::updateInfoText()
2160 // update info text font
2161 if(!m_startViewport->childItems().isEmpty()) {
2162 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2164 QFont font = item->font();
2165 font.setPixelSize(m_startViewport->rect().width() / 10);
2166 item->setFont(font);
2169 if(!m_endViewport->childItems().isEmpty()) {
2170 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2172 QFont font = item->font();
2173 font.setPixelSize(m_endViewport->rect().width() / 10);
2174 item->setFont(font);
2179 void TitleWidget::deleteAnimInfoText()
2181 // end animation editing, remove info text
2182 while(!m_startViewport->childItems().isEmpty()) {
2183 QGraphicsItem *item = m_startViewport->childItems().at(0);
2184 m_scene->removeItem(item);
2187 while(!m_endViewport->childItems().isEmpty()) {
2188 QGraphicsItem *item = m_endViewport->childItems().at(0);
2189 m_scene->removeItem(item);
2194 void TitleWidget::slotKeepAspect(bool keep)
2196 if(m_endViewport->zValue() == 1100) {
2197 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2198 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2200 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2201 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2205 void TitleWidget::slotResize50()
2207 if(m_endViewport->zValue() == 1100) {
2208 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2209 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2212 void TitleWidget::slotResize100()
2214 if(m_endViewport->zValue() == 1100) {
2215 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2216 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2219 void TitleWidget::slotResize200()
2221 if(m_endViewport->zValue() == 1100) {
2222 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2223 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2226 void TitleWidget::slotAddEffect(int ix)
2228 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2229 int effect = effect_list->itemData(ix).toInt();
2231 if(list.size() == 1) {
2232 if(effect == NOEFFECT)
2233 effect_stack->setHidden(true);
2235 effect_stack->setCurrentIndex(effect - 1);
2236 effect_stack->setHidden(false);
2238 } else // Hide the effects stack when more than one element is selected.
2239 effect_stack->setHidden(true);
2241 foreach(QGraphicsItem * item, list) {
2244 item->setData(100, QVariant());
2245 #if QT_VERSION >= 0x040600
2246 item->setGraphicsEffect(0);
2249 case TYPEWRITEREFFECT:
2251 * Allow the user to set the typewriter effect to more than one
2252 * element, but do not add it to non-text elements.
2254 if(item->type() == TEXTITEM) {
2255 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2256 item->setData(100, effdata);
2259 #if QT_VERSION >= 0x040600
2260 // Do not remove the non-QGraphicsEffects.
2262 item->setGraphicsEffect(new QGraphicsBlurEffect());
2265 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2272 void TitleWidget::slotFontText(const QString& s)
2275 if(f.exactMatch()) {
2276 // Font really exists (could also just be a «d» if the user
2277 // starts typing «dejavu» for example).
2278 font_family->setCurrentFont(f);
2280 // Note: Typing dejavu serif does not recognize the font (takes sans)
2281 // in older Qt versions. Case must match there (except for first letter)
2284 void TitleWidget::slotEditTypewriter(int /*ix*/)
2286 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2288 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2289 l[0]->setData(100, effdata);
2293 void TitleWidget::slotEditBlur(int ix)
2295 #if QT_VERSION < 0x040600
2298 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2300 QGraphicsEffect *eff = l[0]->graphicsEffect();
2301 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2302 if(blur) blur->setBlurRadius(ix);
2307 void TitleWidget::slotEditShadow()
2309 #if QT_VERSION < 0x040600
2312 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2314 QGraphicsEffect *eff = l[0]->graphicsEffect();
2315 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2317 shadow->setBlurRadius(shadow_radius->value());
2318 shadow->setOffset(shadow_x->value(), shadow_y->value());
2324 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2326 qreal bound = maxBound ? -99 : 99;
2327 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2329 QList<QGraphicsItem*> lItems;
2330 // Get items (all or intersecting only)
2331 if(intersectingOnly) {
2332 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2334 lItems = graphicsView->scene()->items();
2336 if(lItems.size() > 0) {
2337 int n = lItems.size();
2340 for(int i = 0; i < n; i++) {
2341 z = lItems[i]->zValue();
2342 if(z > bound && !lItems[i]->isSelected()) {
2347 // Get minimum z index.
2348 for(int i = 0; i < n; i++) {
2349 z = lItems[i]->zValue();
2350 if(z < bound && !lItems[i]->isSelected() && z > -999) {
2351 // There are items at the very bottom (background e.g.) with z-index < -1000.
2361 void TitleWidget::slotZIndexUp()
2363 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2365 qreal currentZ = l[0]->zValue();
2366 qreal max = zIndexBounds(true, true);
2367 if(currentZ <= max) {
2368 l[0]->setZValue(currentZ + 1);
2369 updateDimension(l[0]);
2374 void TitleWidget::slotZIndexTop()
2376 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2378 qreal currentZ = l[0]->zValue();
2379 qreal max = zIndexBounds(true, false);
2380 if(currentZ <= max) {
2381 l[0]->setZValue(max + 1);
2382 updateDimension(l[0]);
2387 void TitleWidget::slotZIndexDown()
2389 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2391 qreal currentZ = l[0]->zValue();
2392 qreal min = zIndexBounds(false, true);
2393 if(currentZ >= min) {
2394 l[0]->setZValue(currentZ - 1);
2395 updateDimension(l[0]);
2400 void TitleWidget::slotZIndexBottom()
2402 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2404 qreal currentZ = l[0]->zValue();
2405 qreal min = zIndexBounds(false, false);
2406 if(currentZ >= min) {
2407 l[0]->setZValue(min - 1);
2408 updateDimension(l[0]);
2413 void TitleWidget::slotSelectAll()
2415 graphicsView->blockSignals(true);
2416 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2417 for(int i = 0; i < l.size(); i++) {
2418 l.at(i)->setSelected(true);
2420 graphicsView->blockSignals(false);
2421 // Notify the GUI of the selection change
2425 void TitleWidget::selectItems(int itemType)
2427 graphicsView->blockSignals(true);
2428 QList<QGraphicsItem*> l;
2429 if(graphicsView->scene()->selectedItems().size() > 0) {
2430 l = graphicsView->scene()->selectedItems();
2431 for(int i = 0; i < l.size(); i++) {
2432 if(l.at(i)->type() != itemType) {
2433 l.at(i)->setSelected(false);
2437 l = graphicsView->scene()->items();
2438 for(int i = 0; i < l.size(); i++) {
2439 if(l.at(i)->type() == itemType) {
2440 l.at(i)->setSelected(true);
2444 graphicsView->blockSignals(false);
2448 void TitleWidget::slotSelectText()
2450 selectItems(TEXTITEM);
2453 void TitleWidget::slotSelectRects()
2455 selectItems(RECTITEM);
2458 void TitleWidget::slotSelectImages()
2460 selectItems(IMAGEITEM);
2463 void TitleWidget::slotSelectNone()
2465 graphicsView->blockSignals(true);
2466 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2467 for(int i = 0; i < l.size(); i++) {
2468 l.at(i)->setSelected(false);
2470 graphicsView->blockSignals(false);
2474 QString TitleWidget::getTooltipWithShortcut(const QString text, QAction *button)
2476 return text + " <b>" + button->shortcut().toString() + "</b>";