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>
50 static QList<TitleTemplate> titletemplates;
52 int settingUp = false;
54 const int IMAGEITEM = 7;
55 const int RECTITEM = 3;
56 const int TEXTITEM = 8;
58 const int NOEFFECT = 0;
59 const int BLUREFFECT = 1;
60 const int SHADOWEFFECT = 2;
61 const int TYPEWRITEREFFECT = 3;
63 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
66 m_startViewport(NULL),
70 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
71 m_projectTitlePath(projectTitlePath),
75 setFont(KGlobalSettings::toolBarFont());
76 frame_properties->setEnabled(false);
77 frame_properties->setFixedHeight(frame_toolbar->height());
79 // Set combo sliders values
80 textAlpha->setMinimum(0);
81 textAlpha->setMaximum(255);
82 textAlpha->setDecimals(0);
83 textAlpha->setValue(255);
84 textAlpha->setToolTip(i18n("Font color opacity"));
86 textOutlineAlpha->setMinimum(0);
87 textOutlineAlpha->setMaximum(255);
88 textOutlineAlpha->setDecimals(0);
89 textOutlineAlpha->setValue(255);
90 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
92 textOutline->setMinimum(0);
93 textOutline->setMaximum(200);
94 textOutline->setDecimals(0);
95 textOutline->setValue(0);
96 textOutline->setToolTip(i18n("Outline width"));
98 backgroundAlpha->setMinimum(0);
99 backgroundAlpha->setMaximum(255);
100 backgroundAlpha->setDecimals(0);
101 backgroundAlpha->setValue(0);
102 backgroundAlpha->setToolTip(i18n("Background color opacity"));
104 itemrotatex->setMinimum(-360);
105 itemrotatex->setMaximum(360);
106 itemrotatex->setDecimals(0);
107 itemrotatex->setValue(0);
108 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
110 itemrotatey->setMinimum(-360);
111 itemrotatey->setMaximum(360);
112 itemrotatey->setDecimals(0);
113 itemrotatey->setValue(0);
114 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
116 itemrotatez->setMinimum(-360);
117 itemrotatez->setMaximum(360);
118 itemrotatez->setDecimals(0);
119 itemrotatez->setValue(0);
120 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
122 rectBAlpha->setMinimum(0);
123 rectBAlpha->setMaximum(255);
124 rectBAlpha->setDecimals(0);
125 rectBAlpha->setValue(255);
126 rectBAlpha->setToolTip(i18n("Color opacity"));
128 rectFAlpha->setMinimum(0);
129 rectFAlpha->setMaximum(255);
130 rectFAlpha->setDecimals(0);
131 rectFAlpha->setValue(255);
132 rectFAlpha->setToolTip(i18n("Border opacity"));
134 rectLineWidth->setMinimum(0);
135 rectLineWidth->setMaximum(100);
136 rectLineWidth->setDecimals(0);
137 rectLineWidth->setValue(0);
138 rectLineWidth->setToolTip(i18n("Border width"));
140 itemzoom->setSuffix(i18n("%"));
141 m_frameWidth = render->renderWidth();
142 m_frameHeight = render->renderHeight();
143 showToolbars(TITLE_SELECT);
145 //If project is drop frame, set the input mask as such.
146 title_duration->setInputMask("");
147 title_duration->setValidator(m_tc.validator());
148 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
150 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
151 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
153 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
154 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
155 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
156 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
157 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
158 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
159 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
160 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
162 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
164 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
165 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
166 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
167 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
168 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
170 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
171 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
172 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
173 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
174 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
175 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
178 effect_list->addItem(i18n("None"), NOEFFECT);
179 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
180 effect_list->addItem(i18n("Blur"), BLUREFFECT);
183 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
184 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
185 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
186 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
187 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
188 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
189 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
190 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
191 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
192 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
193 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
194 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
195 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
196 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
197 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
198 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
199 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
200 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
201 effect_stack->setHidden(true);
202 effect_frame->setEnabled(false);
204 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
205 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
207 m_signalMapper = new QSignalMapper(this);
208 m_signalMapper->setMapping(value_w, ValueWidth);
209 m_signalMapper->setMapping(value_h, ValueHeight);
210 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
211 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
212 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
214 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
215 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
216 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
217 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
218 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
219 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
220 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
221 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
222 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
223 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
224 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
225 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
226 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
228 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
231 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
233 font_weight_box->blockSignals(true);
234 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
235 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
236 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
237 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
238 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
239 font_weight_box->setToolTip(i18n("Font weight"));
240 font_weight_box->setCurrentIndex(1);
241 font_weight_box->blockSignals(false);
243 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
244 buttonRealSize->setIcon(KIcon("zoom-original"));
245 buttonItalic->setIcon(KIcon("format-text-italic"));
246 buttonUnder->setIcon(KIcon("format-text-underline"));
247 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
248 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
249 buttonAlignRight->setIcon(KIcon("format-justify-right"));
250 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
252 buttonAlignNone->setToolTip(i18n("No alignment"));
253 buttonAlignRight->setToolTip(i18n("Align right"));
254 buttonAlignLeft->setToolTip(i18n("Align left"));
255 buttonAlignCenter->setToolTip(i18n("Align center"));
257 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
258 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
259 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
260 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
261 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
263 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
264 m_zUp->setShortcut(Qt::Key_PageUp);
265 m_zUp->setToolTip(i18n("Raise object"));
266 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
267 zUp->setDefaultAction(m_zUp);
269 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
270 m_zDown->setShortcut(Qt::Key_PageDown);
271 m_zDown->setToolTip(i18n("Lower object"));
272 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
273 zDown->setDefaultAction(m_zDown);
275 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
276 // TODO mbt 1414: Shortcut should change z index only if
277 // cursor is NOT in a text field ...
278 //m_zTop->setShortcut(Qt::Key_Home);
279 m_zTop->setToolTip(i18n("Raise object to top"));
280 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
281 zTop->setDefaultAction(m_zTop);
283 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
285 //m_zBottom->setShortcut(Qt::Key_End);
286 m_zBottom->setToolTip(i18n("Lower object to bottom"));
287 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
288 zBottom->setDefaultAction(m_zBottom);
290 zDown->setIcon(KIcon("kdenlive-zindex-down"));
291 zTop->setIcon(KIcon("kdenlive-zindex-top"));
292 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
293 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
294 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
295 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
297 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
298 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
299 rectBColor->setToolTip(i18n("Select fill color"));
300 rectFColor->setToolTip(i18n("Select border color"));
301 rectBAlpha->setToolTip(i18n("Fill opacity"));
302 rectFAlpha->setToolTip(i18n("Border opacity"));
303 zoom_slider->setToolTip(i18n("Zoom"));
304 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
305 buttonFitZoom->setToolTip(i18n("Fit zoom"));
306 backgroundColor->setToolTip(i18n("Select background color"));
307 backgroundAlpha->setToolTip(i18n("Background opacity"));
309 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
310 itemhcenter->setToolTip(i18n("Align item horizontally"));
311 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
312 itemvcenter->setToolTip(i18n("Align item vertically"));
313 itemtop->setIcon(KIcon("kdenlive-align-top"));
314 itemtop->setToolTip(i18n("Align item to top"));
315 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
316 itembottom->setToolTip(i18n("Align item to bottom"));
317 itemright->setIcon(KIcon("kdenlive-align-right"));
318 itemright->setToolTip(i18n("Align item to right"));
319 itemleft->setIcon(KIcon("kdenlive-align-left"));
320 itemleft->setToolTip(i18n("Align item to left"));
323 QHBoxLayout *layout = new QHBoxLayout;
324 frame_toolbar->setLayout(layout);
325 layout->setContentsMargins(0, 0, 0, 0);
326 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
327 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
328 m_toolbar->setIconSize(QSize(s, s));
330 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
331 m_buttonCursor->setCheckable(true);
332 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
333 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
334 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
336 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
337 m_buttonText->setCheckable(true);
338 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
339 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
340 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
342 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
343 m_buttonRect->setCheckable(true);
344 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
345 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
346 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
348 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
349 m_buttonImage->setCheckable(false);
350 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
351 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
352 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
354 m_toolbar->addSeparator();
356 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
357 m_buttonLoad->setCheckable(false);
358 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
359 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
361 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
362 m_buttonSave->setCheckable(false);
363 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
364 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
366 layout->addWidget(m_toolbar);
368 // initialize graphic scene
369 m_scene = new GraphicsSceneRectMove(this);
370 graphicsView->setScene(m_scene);
371 graphicsView->setMouseTracking(true);
372 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
373 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
374 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
376 // a gradient background
377 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
378 gradient->setSpread(QGradient::ReflectSpread);
379 scene->setBackgroundBrush(*gradient);*/
381 m_frameImage = new QGraphicsPixmapItem();
383 qtrans.scale(2.0, 2.0);
384 m_frameImage->setTransform(qtrans);
385 m_frameImage->setZValue(-1200);
386 m_frameImage->setFlags(0);
387 displayBackgroundFrame();
388 graphicsView->scene()->addItem(m_frameImage);
390 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
391 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
392 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
393 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
394 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
395 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
396 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
397 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
399 QPen framepen(Qt::DotLine);
400 framepen.setColor(Qt::red);
402 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
403 m_frameBorder->setPen(framepen);
404 m_frameBorder->setZValue(-1100);
405 m_frameBorder->setBrush(Qt::transparent);
406 m_frameBorder->setFlags(0);
407 graphicsView->scene()->addItem(m_frameBorder);
409 // mbd: load saved settings
412 graphicsView->show();
413 //graphicsView->setRenderHint(QPainter::Antialiasing);
414 graphicsView->setInteractive(true);
415 //graphicsView->resize(400, 300);
416 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
417 //toolBox->setItemEnabled(2, false);
418 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
419 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
420 m_startViewport->setData(0, m_frameWidth);
421 m_startViewport->setData(1, m_frameHeight);
422 m_endViewport->setData(0, m_frameWidth);
423 m_endViewport->setData(1, m_frameHeight);
425 if (!url.isEmpty()) loadTitle(url);
428 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
431 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
432 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
433 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
435 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
436 refreshTitleTemplates();
437 //templateBox->setIconSize(QSize(60,60));
438 templateBox->clear();
439 templateBox->addItem("");
440 foreach(TitleTemplate t, titletemplates) {
441 templateBox->addItem(t.icon, t.name, t.file);
443 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
446 TitleWidget::~TitleWidget()
450 delete m_buttonImage;
451 delete m_buttonCursor;
454 delete m_unicodeAction;
460 delete m_unicodeDialog;
461 delete m_frameBorder;
463 delete m_startViewport;
464 delete m_endViewport;
466 delete m_signalMapper;
470 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
473 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
474 KStandardDirs::makeDir(titlePath);
475 titlePath.append((isClone == false) ? "title" : "clone");
478 while (path.isEmpty() || QFile::exists(path)) {
480 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
482 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
488 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
491 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
492 KStandardDirs::makeDir(titlePath);
493 return titlePath + titleName + ".png";
497 QStringList TitleWidget::extractImageList(QString xml)
500 if (xml.isEmpty()) return result;
503 QDomNodeList images = doc.elementsByTagName("content");
504 for (int i = 0; i < images.count(); i++) {
505 if (images.at(i).toElement().hasAttribute("url"))
506 result.append(images.at(i).toElement().attribute("url"));
512 QStringList TitleWidget::extractFontList(QString xml)
515 if (xml.isEmpty()) return result;
518 QDomNodeList images = doc.elementsByTagName("content");
519 for (int i = 0; i < images.count(); i++) {
520 if (images.at(i).toElement().hasAttribute("font"))
521 result.append(images.at(i).toElement().attribute("font"));
526 void TitleWidget::refreshTitleTemplates()
528 QStringList titlenamelist = QStringList() << i18n("None");
529 QStringList titlefiles = QStringList() << QString();
531 filters << "*.kdenlivetitle" ;
532 titletemplates.clear();
533 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
534 foreach(const QString &folder, titleTemplates) {
535 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
536 foreach(const QString &fname, filesnames) {
537 //titlenamelist.append(fname);
538 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
541 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
542 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
543 titletemplates.append(t);
546 kDebug() << titlenamelist << titlefiles;
548 void TitleWidget::templateIndexChanged(int index)
550 QString item = templateBox->itemData(index).toString();
552 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
553 if (KMessageBox::questionYesNo(this, i18n("Title was changed !\nDo you really want to load a new template?\nAll changes in this document are lost !!")) == KMessageBox::No) return;
556 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
560 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
565 void TitleWidget::slotTextTool()
567 m_scene->setTool(TITLE_TEXT);
568 showToolbars(TITLE_TEXT);
569 checkButton(TITLE_TEXT);
572 void TitleWidget::slotRectTool()
574 m_scene->setTool(TITLE_RECTANGLE);
575 showToolbars(TITLE_RECTANGLE);
576 checkButton(TITLE_RECTANGLE);
579 void TitleWidget::slotSelectTool()
581 m_scene->setTool(TITLE_SELECT);
583 // Find out which toolbars need to be shown, depending on selected item
584 TITLETOOL t = TITLE_SELECT;
585 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
587 switch (l.at(0)->type()) {
601 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
602 //graphicsView->centerOn(l.at(0));
608 updateCoordinates(l.at(0));
609 updateDimension(l.at(0));
610 updateRotZoom(l.at(0));
613 checkButton(TITLE_SELECT);
616 void TitleWidget::slotImageTool()
618 // TODO: find a way to get a list of all supported image types...
619 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";
620 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
621 if (!url.isEmpty()) {
622 if (url.path().endsWith(".svg")) {
623 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
624 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
625 svg->setZValue(m_count++);
626 svg->setData(Qt::UserRole, url.path());
627 graphicsView->scene()->addItem(svg);
629 QPixmap pix(url.path());
630 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
631 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
632 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
633 image->setData(Qt::UserRole, url.path());
634 image->setZValue(m_count++);
635 graphicsView->scene()->addItem(image);
638 m_scene->setTool(TITLE_SELECT);
639 showToolbars(TITLE_SELECT);
640 checkButton(TITLE_SELECT);
643 void TitleWidget::showToolbars(TITLETOOL toolType)
645 toolbar_stack->setCurrentIndex((int) toolType);
648 void TitleWidget::enableToolbars(TITLETOOL toolType)
650 // TITLETOOL is defined in graphicsscenerectmove.h
652 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
653 value_w->setEnabled(enable);
654 value_h->setEnabled(enable);
657 void TitleWidget::checkButton(TITLETOOL toolType)
659 bool bSelect = false;
671 case TITLE_RECTANGLE:
681 m_buttonCursor->setChecked(bSelect);
682 m_buttonText->setChecked(bText);
683 m_buttonRect->setChecked(bRect);
684 m_buttonImage->setChecked(bImage);
687 void TitleWidget::displayBackgroundFrame()
689 if (!displayBg->isChecked()) {
690 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
691 QPixmap pattern(20, 20);
693 QColor bgcolor(210, 210, 210);
696 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
697 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
702 p.fillRect(bg.rect(), br);
704 m_frameImage->setPixmap(bg);
706 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
710 void TitleWidget::initAnimation()
712 align_box->setEnabled(false);
713 QPen startpen(Qt::DotLine);
714 QPen endpen(Qt::DashDotLine);
715 startpen.setColor(QColor(100, 200, 100, 140));
716 endpen.setColor(QColor(200, 100, 100, 140));
718 m_startViewport->setPen(startpen);
719 m_endViewport->setPen(endpen);
721 m_startViewport->setZValue(-1000);
722 m_endViewport->setZValue(-1000);
724 m_startViewport->setFlags(0);
725 m_endViewport->setFlags(0);
727 graphicsView->scene()->addItem(m_startViewport);
728 graphicsView->scene()->addItem(m_endViewport);
730 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
731 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
732 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
733 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
736 void TitleWidget::slotUpdateZoom(int pos)
738 m_scene->setZoom((double) pos / 100);
739 zoom_label->setText(QString::number(pos) + '%');
742 void TitleWidget::slotZoom(bool up)
744 int pos = zoom_slider->value();
747 zoom_slider->setValue(pos);
750 void TitleWidget::slotAdjustZoom()
752 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
753 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
754 if (scalex > scaley) scalex = scaley;
755 int zoompos = (int)(scalex * 7 + 0.5);*/
756 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
757 int zoompos = graphicsView->matrix().m11() * 100;
758 zoom_slider->setValue(zoompos);
759 graphicsView->centerOn(m_frameBorder);
762 void TitleWidget::slotZoomOneToOne()
764 zoom_slider->setValue(100);
765 graphicsView->centerOn(m_frameBorder);
768 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
770 updateAxisButtons(rect); // back to default
772 QColor f = rectFColor->color();
773 f.setAlpha(rectFAlpha->value());
775 penf.setWidth(rectLineWidth->value());
776 penf.setJoinStyle(Qt::RoundJoin);
778 QColor b = rectBColor->color();
779 b.setAlpha(rectBAlpha->value());
780 rect->setBrush(QBrush(b));
781 rect->setZValue(m_count++);
782 rect->setData(ZOOMFACTOR, 100);
783 //setCurrentItem(rect);
784 //graphicsView->setFocus();
787 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
789 updateAxisButtons(tt); // back to default
791 QFont font = font_family->currentFont();
792 font.setPixelSize(font_size->value());
794 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
795 font.setItalic(buttonItalic->isChecked());
796 font.setUnderline(buttonUnder->isChecked());
799 QColor color = fontColorButton->color();
800 color.setAlpha(textAlpha->value());
801 tt->setDefaultTextColor(color);
803 QTextCursor cur(tt->document());
804 cur.select(QTextCursor::Document);
805 QTextBlockFormat format = cur.blockFormat();
806 QTextCharFormat cformat = cur.charFormat();
807 QColor outlineColor = textOutlineColor->color();
808 outlineColor.setAlpha(textOutlineAlpha->value());
809 double outlineWidth = textOutline->value() / 10.0;
811 tt->setData(101, outlineWidth);
812 tt->setData(102, outlineColor);
813 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
815 cformat.setForeground(QBrush(color));
816 cur.setCharFormat(cformat);
817 cur.setBlockFormat(format);
818 tt->setTextCursor(cur);
819 tt->setZValue(m_count++);
823 void TitleWidget::setFontBoxWeight(int weight)
825 int index = font_weight_box->findData(weight);
827 index = font_weight_box->findData(QFont::Normal);
829 font_weight_box->setCurrentIndex(index);
832 void TitleWidget::setCurrentItem(QGraphicsItem *item)
834 m_scene->setSelectedItem(item);
837 void TitleWidget::zIndexChanged(int v)
839 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
845 void TitleWidget::selectionChanged()
847 if (m_scene->tool() != TITLE_SELECT) return;
848 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
849 //toolBox->setItemEnabled(2, false);
850 //toolBox->setItemEnabled(3, false);
851 effect_list->blockSignals(true);
852 value_x->blockSignals(true);
853 value_y->blockSignals(true);
854 value_w->blockSignals(true);
855 value_h->blockSignals(true);
856 itemzoom->blockSignals(true);
857 itemrotatex->blockSignals(true);
858 itemrotatey->blockSignals(true);
859 itemrotatez->blockSignals(true);
861 effect_stack->setHidden(true);
862 effect_frame->setEnabled(false);
863 effect_list->setCurrentIndex(0);
864 bool blockX = !origin_x_left->signalsBlocked();
865 bool blockY = !origin_y_top->signalsBlocked();
866 if (blockX) origin_x_left->blockSignals(true);
867 if (blockY) origin_y_top->blockSignals(true);
868 origin_x_left->setChecked(false);
869 origin_y_top->setChecked(false);
872 enableToolbars(TITLE_SELECT);
873 if (blockX) origin_x_left->blockSignals(false);
874 if (blockY) origin_y_top->blockSignals(false);
875 itemzoom->setEnabled(false);
876 itemrotatex->setEnabled(false);
877 itemrotatey->setEnabled(false);
878 itemrotatez->setEnabled(false);
879 frame_properties->setEnabled(false);
880 } else if (l.size() == 1) {
881 effect_frame->setEnabled(true);
882 frame_properties->setEnabled(true);
883 if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
884 itemzoom->setEnabled(true);
885 itemrotatex->setEnabled(true);
886 itemrotatey->setEnabled(true);
887 itemrotatez->setEnabled(true);
889 itemzoom->setEnabled(false);
890 itemrotatex->setEnabled(false);
891 itemrotatey->setEnabled(false);
892 itemrotatez->setEnabled(false);
895 if (l.at(0)->type() == TEXTITEM) {
896 showToolbars(TITLE_TEXT);
897 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
898 if (!i->data(100).isNull()) {
899 // Item has an effect
900 QStringList effdata = i->data(100).toStringList();
901 QString effectName = effdata.takeFirst();
902 if (effectName == "typewriter") {
903 QStringList params = effdata.at(0).split(';');
904 typewriter_delay->setValue(params.at(0).toInt());
905 typewriter_start->setValue(params.at(1).toInt());
906 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
907 effect_stack->setHidden(false);
910 #if QT_VERSION >= 0x040600
911 if (i->graphicsEffect()) {
912 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
914 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
915 int rad = (int) blur->blurRadius();
916 blur_radius->setValue(rad);
917 effect_stack->setHidden(false);
919 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
921 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
922 shadow_radius->setValue(shad->blurRadius());
923 shadow_x->setValue(shad->xOffset());
924 shadow_y->setValue(shad->yOffset());
925 effect_stack->setHidden(false);
929 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
930 effect_stack->setHidden(true);
933 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
934 effect_stack->setHidden(true);
937 //if (l[0]->hasFocus())
938 //toolBox->setCurrentIndex(0);
939 //toolBox->setItemEnabled(2, true);
940 font_size->blockSignals(true);
941 font_family->blockSignals(true);
942 font_weight_box->blockSignals(true);
943 buttonItalic->blockSignals(true);
944 buttonUnder->blockSignals(true);
945 fontColorButton->blockSignals(true);
946 textAlpha->blockSignals(true);
947 buttonAlignLeft->blockSignals(true);
948 buttonAlignRight->blockSignals(true);
949 buttonAlignNone->blockSignals(true);
950 buttonAlignCenter->blockSignals(true);
952 QFont font = i->font();
953 font_family->setCurrentFont(font);
954 font_size->setValue(font.pixelSize());
955 m_scene->slotUpdateFontSize(font.pixelSize());
956 buttonItalic->setChecked(font.italic());
957 buttonUnder->setChecked(font.underline());
958 setFontBoxWeight(font.weight());
960 QTextCursor cursor(i->document());
961 cursor.select(QTextCursor::Document);
962 QColor color = cursor.charFormat().foreground().color();
963 textAlpha->setValue(color.alpha());
965 fontColorButton->setColor(color);
967 if (!i->data(101).isNull()) {
968 textOutline->blockSignals(true);
969 textOutline->setValue(i->data(101).toDouble()*10);
970 textOutline->blockSignals(false);
972 if (!i->data(102).isNull()) {
973 textOutlineColor->blockSignals(true);
974 textOutlineAlpha->blockSignals(true);
975 color = QColor(i->data(102).toString());
976 textOutlineAlpha->setValue(color.alpha());
978 textOutlineColor->setColor(color);
979 textOutlineColor->blockSignals(false);
980 textOutlineAlpha->blockSignals(false);
982 QTextCursor cur = i->textCursor();
983 QTextBlockFormat format = cur.blockFormat();
984 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
985 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
986 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
987 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
989 font_size->blockSignals(false);
990 font_family->blockSignals(false);
991 font_weight_box->blockSignals(false);
992 buttonItalic->blockSignals(false);
993 buttonUnder->blockSignals(false);
994 fontColorButton->blockSignals(false);
995 textAlpha->blockSignals(false);
996 buttonAlignLeft->blockSignals(false);
997 buttonAlignRight->blockSignals(false);
998 buttonAlignNone->blockSignals(false);
999 buttonAlignCenter->blockSignals(false);
1001 updateAxisButtons(i);
1002 updateCoordinates(i);
1004 enableToolbars(TITLE_TEXT);
1006 } else if ((l.at(0))->type() == RECTITEM) {
1007 showToolbars(TITLE_RECTANGLE);
1009 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1010 if (rec == m_startViewport || rec == m_endViewport) {
1011 /*toolBox->setCurrentIndex(3);
1012 toolBox->widget(0)->setEnabled(false);
1013 toolBox->widget(1)->setEnabled(false);*/
1014 enableToolbars(TITLE_SELECT);
1016 /*toolBox->widget(0)->setEnabled(true);
1017 toolBox->widget(1)->setEnabled(true);
1018 toolBox->setCurrentIndex(0);*/
1019 //toolBox->setItemEnabled(3, true);
1020 rectFAlpha->setValue(rec->pen().color().alpha());
1021 rectBAlpha->setValue(rec->brush().color().alpha());
1022 //kDebug() << rec->brush().color().alpha();
1023 QColor fcol = rec->pen().color();
1024 QColor bcol = rec->brush().color();
1025 //fcol.setAlpha(255);
1026 //bcol.setAlpha(255);
1027 rectFColor->setColor(fcol);
1028 rectBColor->setColor(bcol);
1030 rectLineWidth->setValue(rec->pen().width());
1031 enableToolbars(TITLE_RECTANGLE);
1034 updateAxisButtons(l.at(0));
1035 updateCoordinates(rec);
1036 updateDimension(rec);
1038 } else if (l.at(0)->type() == IMAGEITEM) {
1039 showToolbars(TITLE_IMAGE);
1041 updateCoordinates(l.at(0));
1042 updateDimension(l.at(0));
1044 enableToolbars(TITLE_IMAGE);
1047 //toolBox->setCurrentIndex(0);
1048 showToolbars(TITLE_SELECT);
1049 enableToolbars(TITLE_SELECT);
1050 frame_properties->setEnabled(false);
1052 zValue->setValue((int)l.at(0)->zValue());
1053 if (!l.at(0)->data(ZOOMFACTOR).isNull()) itemzoom->setValue(l.at(0)->data(ZOOMFACTOR).toInt());
1054 else itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
1055 itemrotatex->setValue((int)(m_transformations.value(l.at(0)).rotatex));
1056 itemrotatey->setValue((int)(m_transformations.value(l.at(0)).rotatey));
1057 itemrotatez->setValue((int)(m_transformations.value(l.at(0)).rotatez));
1058 value_x->blockSignals(false);
1059 value_y->blockSignals(false);
1060 value_w->blockSignals(false);
1061 value_h->blockSignals(false);
1062 itemzoom->blockSignals(false);
1063 itemrotatex->blockSignals(false);
1064 itemrotatey->blockSignals(false);
1065 itemrotatez->blockSignals(false);
1067 // Tools working on more than one element.
1069 effect_list->blockSignals(false);
1072 void TitleWidget::slotValueChanged(int type)
1074 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1075 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
1080 val = value_w->value();
1083 val = value_h->value();
1087 QGraphicsItem *i = l.at(0);
1088 Transform t = m_transformations.value(i);
1090 // Ratio width:height
1091 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1092 // TODO: proper calculation for rotation around 3 axes
1093 double alpha = (double) t.rotatez / 180.0 * M_PI;
1096 double length = val;
1103 // Add 0.5 because otherwise incrementing by 1 might have no effect
1104 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1105 scale = length / i->boundingRect().width();
1108 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1109 scale = length / i->boundingRect().height();
1116 qtrans.scale(scale, scale);
1117 qtrans.rotate(t.rotatex, Qt::XAxis);
1118 qtrans.rotate(t.rotatey, Qt::YAxis);
1119 qtrans.rotate(t.rotatez, Qt::ZAxis);
1120 i->setTransform(qtrans);
1121 m_transformations[i] = t;
1128 void TitleWidget::slotAdjustSelectedItem()
1130 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1131 if (l.size() >= 1) {
1132 if (l.at(0)->type() == RECTITEM) {
1134 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1135 updatePosition(rec);
1136 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1137 } else if (l.at(0)->type() == TEXTITEM) {
1139 updatePosition(l.at(0));
1140 } else if (l.at(0)->type() == IMAGEITEM) {
1142 updatePosition(l.at(0));
1147 void TitleWidget::updateDimension(QGraphicsItem *i)
1149 value_w->blockSignals(true);
1150 value_h->blockSignals(true);
1151 zValue->blockSignals(true);
1153 zValue->setValue((int) i->zValue());
1154 if (i->type() == IMAGEITEM) {
1155 // Get multipliers for rotation/scaling
1157 /*Transform t = m_transformations.value(i);
1158 QRectF r = i->boundingRect();
1159 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1160 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1161 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1162 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1164 value_w->setValue(i->sceneBoundingRect().width());
1165 value_h->setValue(i->sceneBoundingRect().height());
1166 } else if (i->type() == RECTITEM) {
1167 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1168 value_w->setValue((int) r->rect().width());
1169 value_h->setValue((int) r->rect().height());
1170 } else if (i->type() == TEXTITEM) {
1171 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1172 value_w->setValue((int) t->boundingRect().width());
1173 value_h->setValue((int) t->boundingRect().height());
1176 zValue->blockSignals(false);
1177 value_w->blockSignals(false);
1178 value_h->blockSignals(false);
1181 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1183 // Block signals emitted by this method
1184 value_x->blockSignals(true);
1185 value_y->blockSignals(true);
1187 if (i->type() == TEXTITEM) {
1189 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1191 // Set the correct x coordinate value
1192 if (origin_x_left->isChecked()) {
1193 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1194 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1196 // Origin is at 0 (default)
1197 value_x->setValue((int) rec->pos().x());
1201 if (origin_y_top->isChecked()) {
1202 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1204 value_y->setValue((int) rec->pos().y());
1207 } else if (i->type() == RECTITEM) {
1209 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1211 if (origin_x_left->isChecked()) {
1212 // Origin (0 point) is at m_frameWidth
1213 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1215 // Origin is at 0 (default)
1216 value_x->setValue((int) rec->pos().x());
1219 if (origin_y_top->isChecked()) {
1220 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1222 value_y->setValue((int) rec->pos().y());
1225 } else if (i->type() == IMAGEITEM) {
1227 if (origin_x_left->isChecked()) {
1228 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1230 value_x->setValue((int) i->pos().x());
1233 if (origin_y_top->isChecked()) {
1234 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1236 value_y->setValue((int) i->pos().y());
1241 // Stop blocking signals now
1242 value_x->blockSignals(false);
1243 value_y->blockSignals(false);
1246 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1248 itemzoom->blockSignals(true);
1249 itemrotatex->blockSignals(true);
1250 itemrotatey->blockSignals(true);
1251 itemrotatez->blockSignals(true);
1253 Transform t = m_transformations.value(i);
1255 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1256 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1258 itemrotatex->setValue((int)(t.rotatex));
1259 itemrotatey->setValue((int)(t.rotatey));
1260 itemrotatez->setValue((int)(t.rotatez));
1262 itemzoom->blockSignals(false);
1263 itemrotatex->blockSignals(false);
1264 itemrotatey->blockSignals(false);
1265 itemrotatez->blockSignals(false);
1268 void TitleWidget::updatePosition(QGraphicsItem *i)
1270 if (i->type() == TEXTITEM) {
1271 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1274 if (origin_x_left->isChecked()) {
1276 * Origin of the X axis is at m_frameWidth, and distance from right
1277 * border of the item to the right border of the frame is taken. See
1278 * comment to slotOriginXClicked().
1280 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1282 posX = value_x->value();
1286 if (origin_y_top->isChecked()) {
1287 /* Same for y axis */
1288 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1290 posY = value_y->value();
1293 rec->setPos(posX, posY);
1295 } else if (i->type() == RECTITEM) {
1297 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1300 if (origin_x_left->isChecked()) {
1301 posX = m_frameWidth - value_x->value() - rec->rect().width();
1303 posX = value_x->value();
1307 if (origin_y_top->isChecked()) {
1308 posY = m_frameHeight - value_y->value() - rec->rect().height();
1310 posY = value_y->value();
1313 rec->setPos(posX, posY);
1315 } else if (i->type() == IMAGEITEM) {
1317 if (origin_x_left->isChecked()) {
1318 // Use the sceneBoundingRect because this also regards transformations like zoom
1319 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1321 posX = value_x->value();
1325 if (origin_y_top->isChecked()) {
1326 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1328 posY = value_y->value();
1331 i->setPos(posX, posY);
1337 void TitleWidget::updateTextOriginX()
1339 if (origin_x_left->isChecked()) {
1340 origin_x_left->setText(i18n("\u2212X"));
1342 origin_x_left->setText(i18n("+X"));
1346 void TitleWidget::slotOriginXClicked()
1348 // Update the text displayed on the button.
1349 updateTextOriginX();
1351 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1352 if (l.size() >= 1) {
1353 updateCoordinates(l.at(0));
1355 // Remember x axis setting
1356 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1357 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1359 graphicsView->setFocus();
1362 void TitleWidget::updateTextOriginY()
1364 if (origin_y_top->isChecked()) {
1365 origin_y_top->setText(i18n("\u2212Y"));
1367 origin_y_top->setText(i18n("+Y"));
1371 void TitleWidget::slotOriginYClicked()
1373 // Update the text displayed on the button.
1374 updateTextOriginY();
1376 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1377 if (l.size() >= 1) {
1378 updateCoordinates(l.at(0));
1380 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1381 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1384 graphicsView->setFocus();
1387 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1389 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1390 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1391 origin_x_left->blockSignals(true);
1392 origin_y_top->blockSignals(true);
1394 if (xAxis == TitleDocument::AxisInverted) {
1395 origin_x_left->setChecked(true);
1397 origin_x_left->setChecked(false);
1399 updateTextOriginX();
1401 if (yAxis == TitleDocument::AxisInverted) {
1402 origin_y_top->setChecked(true);
1404 origin_y_top->setChecked(false);
1406 updateTextOriginY();
1408 origin_x_left->blockSignals(false);
1409 origin_y_top->blockSignals(false);
1412 void TitleWidget::slotChangeBackground()
1414 QColor color = backgroundColor->color();
1415 color.setAlpha(backgroundAlpha->value());
1416 m_frameBorder->setBrush(QBrush(color));
1419 void TitleWidget::slotChanged()
1421 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1422 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1423 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1427 void TitleWidget::textChanged(QGraphicsTextItem *i)
1430 * If the user has set origin_x_left (the same for y), we need to look
1431 * whether a text element has been selected. If yes, we need to ensure that
1432 * the right border of the text field remains fixed also when some text has
1435 * This is also known as right-justified, with the difference that it is not
1436 * valid for text but for its boundingRect. Text may still be
1441 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1442 if (!i->toPlainText().isEmpty())
1446 * Don't do anything if the string is empty. If the position were
1447 * updated here, a newly created text field would be set to the
1448 * position of the last selected text field.
1454 void TitleWidget::slotInsertUnicode()
1456 m_unicodeDialog->exec();
1459 void TitleWidget::slotInsertUnicodeString(QString text)
1461 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1463 if (l.at(0)->type() == TEXTITEM) {
1464 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1465 t->textCursor().insertText(text);
1470 void TitleWidget::slotUpdateText()
1472 QFont font = font_family->currentFont();
1473 font.setPixelSize(font_size->value());
1474 font.setItalic(buttonItalic->isChecked());
1475 font.setUnderline(buttonUnder->isChecked());
1476 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1477 QColor color = fontColorButton->color();
1478 color.setAlpha(textAlpha->value());
1480 QColor outlineColor = textOutlineColor->color();
1481 outlineColor.setAlpha(textOutlineAlpha->value());
1482 double outlineWidth = textOutline->value() / 10.0;
1483 QGraphicsTextItem* item = NULL;
1484 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1485 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1486 item = static_cast <QGraphicsTextItem *>(l.at(0));
1489 //if (item->textCursor().selection ().isEmpty())
1490 QTextCursor cur(item->document());
1491 cur.select(QTextCursor::Document);
1492 QTextBlockFormat format = cur.blockFormat();
1493 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1494 item->setTextWidth(item->boundingRect().width());
1495 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1496 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1497 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1499 format.setAlignment(Qt::AlignLeft);
1500 item->setTextWidth(-1);
1503 item->setFont(font);
1504 QTextCharFormat cformat = cur.charFormat();
1506 item->setData(101, outlineWidth);
1507 item->setData(102, outlineColor);
1508 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1510 cformat.setForeground(QBrush(color));
1511 cur.setCharFormat(cformat);
1512 cur.setBlockFormat(format);
1513 item->setTextCursor(cur);
1514 cur.clearSelection();
1515 item->setTextCursor(cur);
1518 void TitleWidget::rectChanged()
1520 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1521 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1522 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1523 QColor f = rectFColor->color();
1524 f.setAlpha(rectFAlpha->value());
1526 penf.setWidth(rectLineWidth->value());
1527 penf.setJoinStyle(Qt::RoundJoin);
1529 QColor b = rectBColor->color();
1530 b.setAlpha(rectBAlpha->value());
1531 rec->setBrush(QBrush(b));
1535 void TitleWidget::itemScaled(int val)
1537 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1538 if (l.size() == 1) {
1539 Transform x = m_transformations.value(l.at(0));
1540 x.scalex = (double)val / 100.0;
1541 x.scaley = (double)val / 100.0;
1543 qtrans.scale(x.scalex, x.scaley);
1544 qtrans.rotate(x.rotatex, Qt::XAxis);
1545 qtrans.rotate(x.rotatey, Qt::YAxis);
1546 qtrans.rotate(x.rotatez, Qt::ZAxis);
1547 l[0]->setTransform(qtrans);
1548 l[0]->setData(ZOOMFACTOR, val);
1549 m_transformations[l.at(0)] = x;
1550 updateDimension(l.at(0));
1554 void TitleWidget::itemRotateX(qreal val)
1559 void TitleWidget::itemRotateY(qreal val)
1564 void TitleWidget::itemRotateZ(qreal val)
1569 void TitleWidget::itemRotate(qreal val, int axis)
1571 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1572 if (l.size() == 1) {
1573 Transform x = m_transformations[l.at(0)];
1586 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1589 qtrans.scale(x.scalex, x.scaley);
1590 qtrans.rotate(x.rotatex, Qt::XAxis);
1591 qtrans.rotate(x.rotatey, Qt::YAxis);
1592 qtrans.rotate(x.rotatez, Qt::ZAxis);
1593 l[0]->setTransform(qtrans);
1594 m_transformations[l.at(0)] = x;
1595 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1596 updateDimension(l.at(0));
1600 void TitleWidget::itemHCenter()
1602 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1603 if (l.size() == 1) {
1604 QGraphicsItem *item = l.at(0);
1605 QRectF br = item->sceneBoundingRect();
1606 int width = (int)br.width();
1607 int newPos = (int)((m_frameWidth - width) / 2);
1608 newPos += item->pos().x() - br.left(); // Check item transformation
1609 item->setPos(newPos, item->pos().y());
1610 updateCoordinates(item);
1614 void TitleWidget::itemVCenter()
1616 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1617 if (l.size() == 1) {
1618 QGraphicsItem *item = l.at(0);
1619 QRectF br = item->sceneBoundingRect();
1620 int height = (int)br.height();
1621 int newPos = (int)((m_frameHeight - height) / 2);
1622 newPos += item->pos().y() - br.top(); // Check item transformation
1623 item->setPos(item->pos().x(), newPos);
1624 updateCoordinates(item);
1628 void TitleWidget::itemTop()
1630 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1631 if (l.size() == 1) {
1632 QGraphicsItem *item = l.at(0);
1633 QRectF br = item->sceneBoundingRect();
1635 if (br.top() > 0) diff = -br.top();
1636 else diff = -br.bottom();
1637 item->moveBy(0, diff);
1638 updateCoordinates(item);
1642 void TitleWidget::itemBottom()
1644 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1645 if (l.size() == 1) {
1646 QGraphicsItem *item = l.at(0);
1647 QRectF br = item->sceneBoundingRect();
1649 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1650 else diff = m_frameHeight - br.bottom();
1651 item->moveBy(0, diff);
1652 updateCoordinates(item);
1656 void TitleWidget::itemLeft()
1658 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1659 if (l.size() == 1) {
1660 QGraphicsItem *item = l.at(0);
1661 QRectF br = item->sceneBoundingRect();
1663 if (br.left() > 0) diff = -br.left();
1664 else diff = -br.right();
1665 item->moveBy(diff, 0);
1666 updateCoordinates(item);
1670 void TitleWidget::itemRight()
1672 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1673 if (l.size() == 1) {
1674 QGraphicsItem *item = l.at(0);
1675 QRectF br = item->sceneBoundingRect();
1677 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1678 else diff = m_frameWidth - br.left();
1679 item->moveBy(diff, 0);
1680 updateCoordinates(item);
1684 void TitleWidget::setupViewports()
1686 //double aspect_ratio = 4.0 / 3.0;//read from project
1687 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1688 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1689 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1690 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1691 QPolygonF spoly(sp);
1692 QPolygonF epoly(ep);
1693 spoly.translate(startViewportX->value(), startViewportY->value());
1694 epoly.translate(endViewportX->value(), endViewportY->value());
1695 m_startViewport->setPolygon(spoly);
1696 m_endViewport->setPolygon(epoly);
1697 if (! insertingValues) {
1698 m_startViewport->setData(0, startViewportX->value());
1699 m_startViewport->setData(1, startViewportY->value());
1700 m_startViewport->setData(2, startViewportSize->value());
1702 m_endViewport->setData(0, endViewportX->value());
1703 m_endViewport->setData(1, endViewportY->value());
1704 m_endViewport->setData(2, endViewportSize->value());
1708 void TitleWidget::loadTitle(KUrl url)
1710 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1711 if (!url.isEmpty()) {
1712 QList<QGraphicsItem *> items = m_scene->items();
1713 for (int i = 0; i < items.size(); i++) {
1714 if (items.at(i)->zValue() > -1000) delete items.at(i);
1716 m_scene->clearTextSelection();
1720 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1721 QFile file(tmpfile);
1722 if (file.open(QIODevice::ReadOnly)) {
1723 doc.setContent(&file, false);
1726 KIO::NetAccess::removeTempFile(tmpfile);
1731 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1733 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1734 insertingValues = true;
1735 startViewportX->setValue(m_startViewport->data(0).toInt());
1736 startViewportY->setValue(m_startViewport->data(1).toInt());
1737 startViewportSize->setValue(m_startViewport->data(2).toInt());
1738 endViewportX->setValue(m_endViewport->data(0).toInt());
1739 endViewportY->setValue(m_endViewport->data(1).toInt());
1740 endViewportSize->setValue(m_endViewport->data(2).toInt());
1742 insertingValues = false;
1748 void TitleWidget::saveTitle(KUrl url)
1750 if (anim_start->isChecked()) slotAnimStart(false);
1751 if (anim_end->isChecked()) slotAnimEnd(false);
1752 if (url.isEmpty()) {
1753 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1754 fs->setOperationMode(KFileDialog::Saving);
1755 fs->setMode(KFile::File);
1756 #if KDE_IS_VERSION(4,2,0)
1757 fs->setConfirmOverwrite(true);
1759 fs->setKeepLocation(true);
1761 url = fs->selectedUrl();
1764 if (!url.isEmpty()) {
1765 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()) - 1) == false)
1766 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1770 QDomDocument TitleWidget::xml()
1772 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1773 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()) - 1);
1777 int TitleWidget::outPoint() const
1779 return m_tc.getFrameCount(title_duration->text()) - 1;
1782 void TitleWidget::setXml(QDomDocument doc)
1785 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1787 title_duration->setText(m_tc.getTimecode(GenTime(out + 1, m_render->fps())));
1788 /*if (doc.documentElement().hasAttribute("out")) {
1789 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1790 title_duration->setText(m_tc.getTimecode(duration));
1792 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1794 QDomElement e = doc.documentElement();
1795 m_transformations.clear();
1796 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1797 const double PI = 4.0 * atan(1.0);
1798 for (int i = 0; i < items.count(); i++) {
1799 QTransform t = items.at(i)->transform();
1803 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1804 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1805 if (rotlist.count() >= 3) {
1806 x.rotatex = rotlist[0].toDouble();
1807 x.rotatey = rotlist[1].toDouble();
1808 x.rotatez = rotlist[2].toDouble();
1810 // Try to adjust zoom
1811 t.rotate(x.rotatex *(-1), Qt::XAxis);
1812 t.rotate(x.rotatey *(-1), Qt::YAxis);
1813 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1824 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1826 m_transformations[items.at(i)] = x;
1828 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1829 QColor background_color = m_titledocument.getBackgroundColor();
1830 backgroundAlpha->blockSignals(true);
1831 backgroundColor->blockSignals(true);
1832 backgroundAlpha->setValue(background_color.alpha());
1833 background_color.setAlpha(255);
1834 backgroundColor->setColor(background_color);
1835 backgroundAlpha->blockSignals(false);
1836 backgroundColor->blockSignals(false);
1838 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1839 startViewportY->setValue(m_startViewport->data(1).toInt());
1840 startViewportSize->setValue(m_startViewport->data(2).toInt());
1841 endViewportX->setValue(m_endViewport->data(0).toInt());
1842 endViewportY->setValue(m_endViewport->data(1).toInt());
1843 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1845 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1850 void TitleWidget::slotAccepted()
1852 if (anim_start->isChecked()) slotAnimStart(false);
1853 if (anim_end->isChecked()) slotAnimEnd(false);
1857 void TitleWidget::writeChoices()
1859 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1860 KSharedConfigPtr config = KGlobal::config();
1861 KConfigGroup titleConfig(config, "TitleWidget");
1862 // Write the entries
1863 titleConfig.writeEntry("font_family", font_family->currentFont());
1864 //titleConfig.writeEntry("font_size", font_size->value());
1865 titleConfig.writeEntry("font_pixel_size", font_size->value());
1866 titleConfig.writeEntry("font_color", fontColorButton->color());
1867 titleConfig.writeEntry("font_alpha", textAlpha->value());
1868 titleConfig.writeEntry("font_outline", textOutline->value());
1869 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1870 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1871 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1872 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1873 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1875 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1876 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1877 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1878 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1879 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1881 titleConfig.writeEntry("background_color", backgroundColor->color());
1882 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1884 //! \todo Not sure if I should sync - it is probably safe to do it
1889 void TitleWidget::readChoices()
1891 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1892 KSharedConfigPtr config = KGlobal::config();
1893 KConfigGroup titleConfig(config, "TitleWidget");
1895 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1896 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1897 m_scene->slotUpdateFontSize(font_size->value());
1898 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1899 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1901 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
1902 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
1903 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
1906 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1907 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1908 setFontBoxWeight(weight);
1909 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1910 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1912 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1913 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1914 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1915 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1916 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1918 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
1919 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
1922 void TitleWidget::adjustFrameSize()
1924 m_frameWidth = m_titledocument.frameWidth();
1925 m_frameHeight = m_titledocument.frameHeight();
1926 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1927 displayBackgroundFrame();
1930 void TitleWidget::slotAnimStart(bool anim)
1932 if (anim && anim_end->isChecked()) {
1933 anim_end->setChecked(false);
1934 m_endViewport->setZValue(-1000);
1935 m_endViewport->setBrush(QBrush());
1938 QList<QGraphicsItem *> list = m_scene->items();
1939 for (int i = 0; i < list.count(); i++) {
1940 if (list.at(i)->zValue() > -1000) {
1941 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1942 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1945 align_box->setEnabled(anim);
1946 itemzoom->setEnabled(!anim);
1947 itemrotatex->setEnabled(!anim);
1948 itemrotatey->setEnabled(!anim);
1949 itemrotatez->setEnabled(!anim);
1950 frame_toolbar->setEnabled(!anim);
1951 toolbar_stack->setEnabled(!anim);
1953 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1954 m_startViewport->setZValue(1100);
1955 QColor col = m_startViewport->pen().color();
1957 m_startViewport->setBrush(col);
1958 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1959 m_startViewport->setSelected(true);
1962 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1964 m_startViewport->setZValue(-1000);
1965 m_startViewport->setBrush(QBrush());
1966 m_startViewport->setFlags(0);
1967 if (!anim_end->isChecked()) deleteAnimInfoText();
1972 void TitleWidget::slotAnimEnd(bool anim)
1974 if (anim && anim_start->isChecked()) {
1975 anim_start->setChecked(false);
1976 m_startViewport->setZValue(-1000);
1977 m_startViewport->setBrush(QBrush());
1980 QList<QGraphicsItem *> list = m_scene->items();
1981 for (int i = 0; i < list.count(); i++) {
1982 if (list.at(i)->zValue() > -1000) {
1983 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1984 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1987 align_box->setEnabled(anim);
1988 itemzoom->setEnabled(!anim);
1989 itemrotatex->setEnabled(!anim);
1990 itemrotatey->setEnabled(!anim);
1991 itemrotatez->setEnabled(!anim);
1992 frame_toolbar->setEnabled(!anim);
1993 toolbar_stack->setEnabled(!anim);
1995 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1996 m_endViewport->setZValue(1100);
1997 QColor col = m_endViewport->pen().color();
1999 m_endViewport->setBrush(col);
2000 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2001 m_endViewport->setSelected(true);
2004 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2006 m_endViewport->setZValue(-1000);
2007 m_endViewport->setBrush(QBrush());
2008 m_endViewport->setFlags(0);
2009 if (!anim_start->isChecked()) deleteAnimInfoText();
2013 void TitleWidget::addAnimInfoText()
2015 // add text to anim viewport
2016 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2017 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2018 QFont font = t->font();
2019 font.setPixelSize(m_startViewport->rect().width() / 10);
2020 QColor col = m_startViewport->pen().color();
2022 t->setDefaultTextColor(col);
2024 font.setPixelSize(m_endViewport->rect().width() / 10);
2025 col = m_endViewport->pen().color();
2027 t2->setDefaultTextColor(col);
2031 void TitleWidget::updateInfoText()
2033 // update info text font
2034 if (!m_startViewport->childItems().isEmpty()) {
2035 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2037 QFont font = item->font();
2038 font.setPixelSize(m_startViewport->rect().width() / 10);
2039 item->setFont(font);
2042 if (!m_endViewport->childItems().isEmpty()) {
2043 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2045 QFont font = item->font();
2046 font.setPixelSize(m_endViewport->rect().width() / 10);
2047 item->setFont(font);
2052 void TitleWidget::deleteAnimInfoText()
2054 // end animation editing, remove info text
2055 while (!m_startViewport->childItems().isEmpty()) {
2056 QGraphicsItem *item = m_startViewport->childItems().at(0);
2057 m_scene->removeItem(item);
2060 while (!m_endViewport->childItems().isEmpty()) {
2061 QGraphicsItem *item = m_endViewport->childItems().at(0);
2062 m_scene->removeItem(item);
2067 void TitleWidget::slotKeepAspect(bool keep)
2069 if (m_endViewport->zValue() == 1100) {
2070 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2071 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2073 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2074 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2078 void TitleWidget::slotResize50()
2080 if (m_endViewport->zValue() == 1100) {
2081 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2082 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2085 void TitleWidget::slotResize100()
2087 if (m_endViewport->zValue() == 1100) {
2088 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2089 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2092 void TitleWidget::slotResize200()
2094 if (m_endViewport->zValue() == 1100) {
2095 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2096 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2099 void TitleWidget::slotAddEffect(int ix)
2101 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2102 int effect = effect_list->itemData(ix).toInt();
2104 if (list.size() == 1) {
2105 if (effect == NOEFFECT)
2106 effect_stack->setHidden(true);
2108 effect_stack->setCurrentIndex(effect - 1);
2109 effect_stack->setHidden(false);
2111 } else // Hide the effects stack when more than one element is selected.
2112 effect_stack->setHidden(true);
2114 foreach(QGraphicsItem *item, list) {
2117 item->setData(100, QVariant());
2118 #if QT_VERSION >= 0x040600
2119 item->setGraphicsEffect(0);
2122 case TYPEWRITEREFFECT:
2124 * Allow the user to set the typewriter effect to more than one
2125 * element, but do not add it to non-text elements.
2127 if (item->type() == TEXTITEM) {
2128 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2129 item->setData(100, effdata);
2132 #if QT_VERSION >= 0x040600
2133 // Do not remove the non-QGraphicsEffects.
2135 item->setGraphicsEffect(new QGraphicsBlurEffect());
2138 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2145 void TitleWidget::slotFontText(const QString& s)
2148 if (f.exactMatch()) {
2149 // Font really exists (could also just be a «d» if the user
2150 // starts typing «dejavu» for example).
2151 font_family->setCurrentFont(f);
2153 // Note: Typing dejavu serif does not recognize the font (takes sans)
2154 // in older Qt versions.
2157 void TitleWidget::slotEditTypewriter(int /*ix*/)
2159 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2160 if (l.size() == 1) {
2161 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2162 l[0]->setData(100, effdata);
2166 void TitleWidget::slotEditBlur(int ix)
2168 #if QT_VERSION < 0x040600
2171 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2172 if (l.size() == 1) {
2173 QGraphicsEffect *eff = l[0]->graphicsEffect();
2174 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2175 if (blur) blur->setBlurRadius(ix);
2180 void TitleWidget::slotEditShadow()
2182 #if QT_VERSION < 0x040600
2185 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2186 if (l.size() == 1) {
2187 QGraphicsEffect *eff = l[0]->graphicsEffect();
2188 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2190 shadow->setBlurRadius(shadow_radius->value());
2191 shadow->setOffset(shadow_x->value(), shadow_y->value());
2197 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2199 qreal bound = maxBound ? -99 : 99;
2200 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2202 QList<QGraphicsItem*> lItems;
2203 // Get items (all or intersecting only)
2204 if (intersectingOnly) {
2205 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2207 lItems = graphicsView->scene()->items();
2209 if (lItems.size() > 0) {
2210 int n = lItems.size();
2213 for (int i = 0; i < n; i++) {
2214 z = lItems[i]->zValue();
2215 if (z > bound && !lItems[i]->isSelected()) {
2220 // Get minimum z index.
2221 for (int i = 0; i < n; i++) {
2222 z = lItems[i]->zValue();
2223 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2224 // There are items at the very bottom (background e.g.) with z-index < -1000.
2234 void TitleWidget::slotZIndexUp()
2236 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2237 if (l.size() >= 1) {
2238 qreal currentZ = l[0]->zValue();
2239 qreal max = zIndexBounds(true, true);
2240 if (currentZ <= max) {
2241 l[0]->setZValue(currentZ + 1);
2242 updateDimension(l[0]);
2247 void TitleWidget::slotZIndexTop()
2249 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2250 if (l.size() >= 1) {
2251 qreal currentZ = l[0]->zValue();
2252 qreal max = zIndexBounds(true, false);
2253 if (currentZ <= max) {
2254 l[0]->setZValue(max + 1);
2255 updateDimension(l[0]);
2260 void TitleWidget::slotZIndexDown()
2262 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2263 if (l.size() >= 1) {
2264 qreal currentZ = l[0]->zValue();
2265 qreal min = zIndexBounds(false, true);
2266 if (currentZ >= min) {
2267 l[0]->setZValue(currentZ - 1);
2268 updateDimension(l[0]);
2273 void TitleWidget::slotZIndexBottom()
2275 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2276 if (l.size() >= 1) {
2277 qreal currentZ = l[0]->zValue();
2278 qreal min = zIndexBounds(false, false);
2279 if (currentZ >= min) {
2280 l[0]->setZValue(min - 1);
2281 updateDimension(l[0]);