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(m_tc.inputMask());
147 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
149 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
150 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
152 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
153 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
154 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
155 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
156 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
157 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
158 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
159 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
161 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
163 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
164 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
165 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
166 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
167 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
169 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
170 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
171 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
172 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
173 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
174 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
177 effect_list->addItem(i18n("None"), NOEFFECT);
178 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
179 effect_list->addItem(i18n("Blur"), BLUREFFECT);
182 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
183 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
184 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
185 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
186 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
187 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
188 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
189 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
190 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
191 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
192 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
193 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
194 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
195 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
196 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
197 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
198 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
199 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
200 effect_stack->setHidden(true);
201 effect_frame->setEnabled(false);
203 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
204 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
206 m_signalMapper = new QSignalMapper(this);
207 m_signalMapper->setMapping(value_w, ValueWidth);
208 m_signalMapper->setMapping(value_h, ValueHeight);
209 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
210 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
211 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
213 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
214 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
215 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
216 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
217 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
218 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
219 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
220 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
221 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
222 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
223 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
224 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
225 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
227 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
230 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
232 font_weight_box->blockSignals(true);
233 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
234 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
235 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
236 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
237 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
238 font_weight_box->setToolTip(i18n("Font weight"));
239 font_weight_box->setCurrentIndex(1);
240 font_weight_box->blockSignals(false);
242 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
243 buttonRealSize->setIcon(KIcon("zoom-original"));
244 buttonItalic->setIcon(KIcon("format-text-italic"));
245 buttonUnder->setIcon(KIcon("format-text-underline"));
246 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
247 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
248 buttonAlignRight->setIcon(KIcon("format-justify-right"));
249 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
251 buttonAlignNone->setToolTip(i18n("No alignment"));
252 buttonAlignRight->setToolTip(i18n("Align right"));
253 buttonAlignLeft->setToolTip(i18n("Align left"));
254 buttonAlignCenter->setToolTip(i18n("Align center"));
256 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
257 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
258 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
259 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
260 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
262 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
263 m_zUp->setShortcut(Qt::Key_PageUp);
264 m_zUp->setToolTip(i18n("Raise object"));
265 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
266 zUp->setDefaultAction(m_zUp);
268 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
269 m_zDown->setShortcut(Qt::Key_PageDown);
270 m_zDown->setToolTip(i18n("Lower object"));
271 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
272 zDown->setDefaultAction(m_zDown);
274 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
275 // TODO mbt 1414: Shortcut should change z index only if
276 // cursor is NOT in a text field ...
277 //m_zTop->setShortcut(Qt::Key_Home);
278 m_zTop->setToolTip(i18n("Raise object to top"));
279 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
280 zTop->setDefaultAction(m_zTop);
282 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
284 //m_zBottom->setShortcut(Qt::Key_End);
285 m_zBottom->setToolTip(i18n("Lower object to bottom"));
286 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
287 zBottom->setDefaultAction(m_zBottom);
289 zDown->setIcon(KIcon("kdenlive-zindex-down"));
290 zTop->setIcon(KIcon("kdenlive-zindex-top"));
291 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
292 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
293 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
294 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
296 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
297 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
298 rectBColor->setToolTip(i18n("Select fill color"));
299 rectFColor->setToolTip(i18n("Select border color"));
300 rectBAlpha->setToolTip(i18n("Fill opacity"));
301 rectFAlpha->setToolTip(i18n("Border opacity"));
302 zoom_slider->setToolTip(i18n("Zoom"));
303 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
304 buttonFitZoom->setToolTip(i18n("Fit zoom"));
305 backgroundColor->setToolTip(i18n("Select background color"));
306 backgroundAlpha->setToolTip(i18n("Background opacity"));
308 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
309 itemhcenter->setToolTip(i18n("Align item horizontally"));
310 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
311 itemvcenter->setToolTip(i18n("Align item vertically"));
312 itemtop->setIcon(KIcon("kdenlive-align-top"));
313 itemtop->setToolTip(i18n("Align item to top"));
314 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
315 itembottom->setToolTip(i18n("Align item to bottom"));
316 itemright->setIcon(KIcon("kdenlive-align-right"));
317 itemright->setToolTip(i18n("Align item to right"));
318 itemleft->setIcon(KIcon("kdenlive-align-left"));
319 itemleft->setToolTip(i18n("Align item to left"));
322 QHBoxLayout *layout = new QHBoxLayout;
323 frame_toolbar->setLayout(layout);
324 layout->setContentsMargins(0, 0, 0, 0);
325 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
326 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
327 m_toolbar->setIconSize(QSize(s, s));
329 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
330 m_buttonCursor->setCheckable(true);
331 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
332 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
333 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
335 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
336 m_buttonText->setCheckable(true);
337 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
338 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
339 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
341 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
342 m_buttonRect->setCheckable(true);
343 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
344 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
345 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
347 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
348 m_buttonImage->setCheckable(false);
349 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
350 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
351 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
353 m_toolbar->addSeparator();
355 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
356 m_buttonLoad->setCheckable(false);
357 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
358 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
360 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
361 m_buttonSave->setCheckable(false);
362 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
363 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
365 layout->addWidget(m_toolbar);
367 // initialize graphic scene
368 m_scene = new GraphicsSceneRectMove(this);
369 graphicsView->setScene(m_scene);
370 graphicsView->setMouseTracking(true);
371 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
372 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
373 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
375 // a gradient background
376 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
377 gradient->setSpread(QGradient::ReflectSpread);
378 scene->setBackgroundBrush(*gradient);*/
380 m_frameImage = new QGraphicsPixmapItem();
382 qtrans.scale(2.0, 2.0);
383 m_frameImage->setTransform(qtrans);
384 m_frameImage->setZValue(-1200);
385 m_frameImage->setFlags(0);
386 displayBackgroundFrame();
387 graphicsView->scene()->addItem(m_frameImage);
389 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
390 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
391 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
392 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
393 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
394 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
395 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
396 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
398 QPen framepen(Qt::DotLine);
399 framepen.setColor(Qt::red);
401 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
402 m_frameBorder->setPen(framepen);
403 m_frameBorder->setZValue(-1100);
404 m_frameBorder->setBrush(Qt::transparent);
405 m_frameBorder->setFlags(0);
406 graphicsView->scene()->addItem(m_frameBorder);
408 // mbd: load saved settings
411 graphicsView->show();
412 //graphicsView->setRenderHint(QPainter::Antialiasing);
413 graphicsView->setInteractive(true);
414 //graphicsView->resize(400, 300);
415 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
416 //toolBox->setItemEnabled(2, false);
417 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
418 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
419 m_startViewport->setData(0, m_frameWidth);
420 m_startViewport->setData(1, m_frameHeight);
421 m_endViewport->setData(0, m_frameWidth);
422 m_endViewport->setData(1, m_frameHeight);
424 if (!url.isEmpty()) loadTitle(url);
427 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
430 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
431 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
432 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
434 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
435 refreshTitleTemplates();
436 //templateBox->setIconSize(QSize(60,60));
437 templateBox->clear();
438 templateBox->addItem("");
439 foreach(TitleTemplate t, titletemplates) {
440 templateBox->addItem(t.icon, t.name, t.file);
442 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
445 TitleWidget::~TitleWidget()
449 delete m_buttonImage;
450 delete m_buttonCursor;
453 delete m_unicodeAction;
459 delete m_unicodeDialog;
460 delete m_frameBorder;
462 delete m_startViewport;
463 delete m_endViewport;
465 delete m_signalMapper;
469 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
472 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
473 KStandardDirs::makeDir(titlePath);
474 titlePath.append((isClone == false) ? "title" : "clone");
477 while (path.isEmpty() || QFile::exists(path)) {
479 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
481 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
487 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
490 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
491 KStandardDirs::makeDir(titlePath);
492 return titlePath + titleName + ".png";
496 QStringList TitleWidget::extractImageList(QString xml)
499 if (xml.isEmpty()) return result;
502 QDomNodeList images = doc.elementsByTagName("content");
503 for (int i = 0; i < images.count(); i++) {
504 if (images.at(i).toElement().hasAttribute("url"))
505 result.append(images.at(i).toElement().attribute("url"));
511 QStringList TitleWidget::extractFontList(QString xml)
514 if (xml.isEmpty()) return result;
517 QDomNodeList images = doc.elementsByTagName("content");
518 for (int i = 0; i < images.count(); i++) {
519 if (images.at(i).toElement().hasAttribute("font"))
520 result.append(images.at(i).toElement().attribute("font"));
525 void TitleWidget::refreshTitleTemplates()
527 QStringList titlenamelist = QStringList() << i18n("None");
528 QStringList titlefiles = QStringList() << QString();
530 filters << "*.kdenlivetitle" ;
531 titletemplates.clear();
532 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
533 foreach(const QString &folder, titleTemplates) {
534 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
535 foreach(const QString &fname, filesnames) {
536 //titlenamelist.append(fname);
537 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
540 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
541 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
542 titletemplates.append(t);
545 kDebug() << titlenamelist << titlefiles;
547 void TitleWidget::templateIndexChanged(int index)
549 QString item = templateBox->itemData(index).toString();
551 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
552 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;
555 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
559 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
564 void TitleWidget::slotTextTool()
566 m_scene->setTool(TITLE_TEXT);
567 showToolbars(TITLE_TEXT);
568 checkButton(TITLE_TEXT);
571 void TitleWidget::slotRectTool()
573 m_scene->setTool(TITLE_RECTANGLE);
574 showToolbars(TITLE_RECTANGLE);
575 checkButton(TITLE_RECTANGLE);
578 void TitleWidget::slotSelectTool()
580 m_scene->setTool(TITLE_SELECT);
582 // Find out which toolbars need to be shown, depending on selected item
583 TITLETOOL t = TITLE_SELECT;
584 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
586 switch (l.at(0)->type()) {
600 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
601 //graphicsView->centerOn(l.at(0));
607 updateCoordinates(l.at(0));
608 updateDimension(l.at(0));
609 updateRotZoom(l.at(0));
612 checkButton(TITLE_SELECT);
615 void TitleWidget::slotImageTool()
617 // TODO: find a way to get a list of all supported image types...
618 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";
619 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
620 if (!url.isEmpty()) {
621 if (url.path().endsWith(".svg")) {
622 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
623 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
624 svg->setZValue(m_count++);
625 svg->setData(Qt::UserRole, url.path());
626 graphicsView->scene()->addItem(svg);
628 QPixmap pix(url.path());
629 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
630 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
631 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
632 image->setData(Qt::UserRole, url.path());
633 image->setZValue(m_count++);
634 graphicsView->scene()->addItem(image);
637 m_scene->setTool(TITLE_SELECT);
638 showToolbars(TITLE_SELECT);
639 checkButton(TITLE_SELECT);
642 void TitleWidget::showToolbars(TITLETOOL toolType)
644 toolbar_stack->setCurrentIndex((int) toolType);
647 void TitleWidget::enableToolbars(TITLETOOL toolType)
649 // TITLETOOL is defined in graphicsscenerectmove.h
651 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
652 value_w->setEnabled(enable);
653 value_h->setEnabled(enable);
656 void TitleWidget::checkButton(TITLETOOL toolType)
658 bool bSelect = false;
670 case TITLE_RECTANGLE:
680 m_buttonCursor->setChecked(bSelect);
681 m_buttonText->setChecked(bText);
682 m_buttonRect->setChecked(bRect);
683 m_buttonImage->setChecked(bImage);
686 void TitleWidget::displayBackgroundFrame()
688 if (!displayBg->isChecked()) {
689 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
690 QPixmap pattern(20, 20);
692 QColor bgcolor(210, 210, 210);
695 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
696 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
701 p.fillRect(bg.rect(), br);
703 m_frameImage->setPixmap(bg);
705 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
709 void TitleWidget::initAnimation()
711 align_box->setEnabled(false);
712 QPen startpen(Qt::DotLine);
713 QPen endpen(Qt::DashDotLine);
714 startpen.setColor(QColor(100, 200, 100, 140));
715 endpen.setColor(QColor(200, 100, 100, 140));
717 m_startViewport->setPen(startpen);
718 m_endViewport->setPen(endpen);
720 m_startViewport->setZValue(-1000);
721 m_endViewport->setZValue(-1000);
723 m_startViewport->setFlags(0);
724 m_endViewport->setFlags(0);
726 graphicsView->scene()->addItem(m_startViewport);
727 graphicsView->scene()->addItem(m_endViewport);
729 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
730 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
731 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
732 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
735 void TitleWidget::slotUpdateZoom(int pos)
737 m_scene->setZoom((double) pos / 100);
738 zoom_label->setText(QString::number(pos) + '%');
741 void TitleWidget::slotZoom(bool up)
743 int pos = zoom_slider->value();
746 zoom_slider->setValue(pos);
749 void TitleWidget::slotAdjustZoom()
751 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
752 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
753 if (scalex > scaley) scalex = scaley;
754 int zoompos = (int)(scalex * 7 + 0.5);*/
755 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
756 int zoompos = graphicsView->matrix().m11() * 100;
757 zoom_slider->setValue(zoompos);
758 graphicsView->centerOn(m_frameBorder);
761 void TitleWidget::slotZoomOneToOne()
763 zoom_slider->setValue(100);
764 graphicsView->centerOn(m_frameBorder);
767 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
769 updateAxisButtons(rect); // back to default
771 QColor f = rectFColor->color();
772 f.setAlpha(rectFAlpha->value());
774 penf.setWidth(rectLineWidth->value());
775 penf.setJoinStyle(Qt::RoundJoin);
777 QColor b = rectBColor->color();
778 b.setAlpha(rectBAlpha->value());
779 rect->setBrush(QBrush(b));
780 rect->setZValue(m_count++);
781 rect->setData(ZOOMFACTOR, 100);
782 //setCurrentItem(rect);
783 //graphicsView->setFocus();
786 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
788 updateAxisButtons(tt); // back to default
790 QFont font = font_family->currentFont();
791 font.setPixelSize(font_size->value());
793 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
794 font.setItalic(buttonItalic->isChecked());
795 font.setUnderline(buttonUnder->isChecked());
798 QColor color = fontColorButton->color();
799 color.setAlpha(textAlpha->value());
800 tt->setDefaultTextColor(color);
802 QTextCursor cur(tt->document());
803 cur.select(QTextCursor::Document);
804 QTextBlockFormat format = cur.blockFormat();
805 QTextCharFormat cformat = cur.charFormat();
806 QColor outlineColor = textOutlineColor->color();
807 outlineColor.setAlpha(textOutlineAlpha->value());
808 double outlineWidth = textOutline->value() / 10.0;
810 tt->setData(101, outlineWidth);
811 tt->setData(102, outlineColor);
812 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
814 cformat.setForeground(QBrush(color));
815 cur.setCharFormat(cformat);
816 cur.setBlockFormat(format);
817 tt->setTextCursor(cur);
818 tt->setZValue(m_count++);
822 void TitleWidget::setFontBoxWeight(int weight)
824 int index = font_weight_box->findData(weight);
826 index = font_weight_box->findData(QFont::Normal);
828 font_weight_box->setCurrentIndex(index);
831 void TitleWidget::setCurrentItem(QGraphicsItem *item)
833 m_scene->setSelectedItem(item);
836 void TitleWidget::zIndexChanged(int v)
838 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
844 void TitleWidget::selectionChanged()
846 if (m_scene->tool() != TITLE_SELECT) return;
847 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
848 //toolBox->setItemEnabled(2, false);
849 //toolBox->setItemEnabled(3, false);
850 value_x->blockSignals(true);
851 value_y->blockSignals(true);
852 value_w->blockSignals(true);
853 value_h->blockSignals(true);
854 itemzoom->blockSignals(true);
855 itemrotatex->blockSignals(true);
856 itemrotatey->blockSignals(true);
857 itemrotatez->blockSignals(true);
859 effect_stack->setHidden(true);
860 effect_frame->setEnabled(false);
861 effect_list->setCurrentIndex(0);
862 bool blockX = !origin_x_left->signalsBlocked();
863 bool blockY = !origin_y_top->signalsBlocked();
864 if (blockX) origin_x_left->blockSignals(true);
865 if (blockY) origin_y_top->blockSignals(true);
866 origin_x_left->setChecked(false);
867 origin_y_top->setChecked(false);
870 enableToolbars(TITLE_SELECT);
871 if (blockX) origin_x_left->blockSignals(false);
872 if (blockY) origin_y_top->blockSignals(false);
873 itemzoom->setEnabled(false);
874 itemrotatex->setEnabled(false);
875 itemrotatey->setEnabled(false);
876 itemrotatez->setEnabled(false);
877 frame_properties->setEnabled(false);
878 } else if (l.size() == 1) {
879 effect_frame->setEnabled(true);
880 frame_properties->setEnabled(true);
881 if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
882 itemzoom->setEnabled(true);
883 itemrotatex->setEnabled(true);
884 itemrotatey->setEnabled(true);
885 itemrotatez->setEnabled(true);
887 itemzoom->setEnabled(false);
888 itemrotatex->setEnabled(false);
889 itemrotatey->setEnabled(false);
890 itemrotatez->setEnabled(false);
893 if (l.at(0)->type() == TEXTITEM) {
894 showToolbars(TITLE_TEXT);
895 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
896 if (!i->data(100).isNull()) {
897 // Item has an effect
898 QStringList effdata = i->data(100).toStringList();
899 QString effectName = effdata.takeFirst();
900 if (effectName == "typewriter") {
901 QStringList params = effdata.at(0).split(';');
902 typewriter_delay->setValue(params.at(0).toInt());
903 typewriter_start->setValue(params.at(1).toInt());
904 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
905 effect_stack->setHidden(false);
908 #if QT_VERSION >= 0x040600
909 if (i->graphicsEffect()) {
910 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
912 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
913 int rad = (int) blur->blurRadius();
914 blur_radius->setValue(rad);
915 effect_stack->setHidden(false);
917 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
919 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
920 shadow_radius->setValue(shad->blurRadius());
921 shadow_x->setValue(shad->xOffset());
922 shadow_y->setValue(shad->yOffset());
923 effect_stack->setHidden(false);
927 effect_list->blockSignals(true);
928 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
929 effect_list->blockSignals(false);
930 effect_stack->setHidden(true);
933 effect_list->blockSignals(true);
934 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
935 effect_list->blockSignals(false);
936 effect_stack->setHidden(true);
939 //if (l[0]->hasFocus())
940 //toolBox->setCurrentIndex(0);
941 //toolBox->setItemEnabled(2, true);
942 font_size->blockSignals(true);
943 font_family->blockSignals(true);
944 font_weight_box->blockSignals(true);
945 buttonItalic->blockSignals(true);
946 buttonUnder->blockSignals(true);
947 fontColorButton->blockSignals(true);
948 textAlpha->blockSignals(true);
949 buttonAlignLeft->blockSignals(true);
950 buttonAlignRight->blockSignals(true);
951 buttonAlignNone->blockSignals(true);
952 buttonAlignCenter->blockSignals(true);
954 QFont font = i->font();
955 font_family->setCurrentFont(font);
956 font_size->setValue(font.pixelSize());
957 m_scene->slotUpdateFontSize(font.pixelSize());
958 buttonItalic->setChecked(font.italic());
959 buttonUnder->setChecked(font.underline());
960 setFontBoxWeight(font.weight());
962 QTextCursor cursor(i->document());
963 cursor.select(QTextCursor::Document);
964 QColor color = cursor.charFormat().foreground().color();
965 textAlpha->setValue(color.alpha());
967 fontColorButton->setColor(color);
969 if (!i->data(101).isNull()) {
970 textOutline->blockSignals(true);
971 textOutline->setValue(i->data(101).toDouble()*10);
972 textOutline->blockSignals(false);
974 if (!i->data(102).isNull()) {
975 textOutlineColor->blockSignals(true);
976 textOutlineAlpha->blockSignals(true);
977 color = QColor(i->data(102).toString());
978 textOutlineAlpha->setValue(color.alpha());
980 textOutlineColor->setColor(color);
981 textOutlineColor->blockSignals(false);
982 textOutlineAlpha->blockSignals(false);
984 QTextCursor cur = i->textCursor();
985 QTextBlockFormat format = cur.blockFormat();
986 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
987 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
988 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
989 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
991 font_size->blockSignals(false);
992 font_family->blockSignals(false);
993 font_weight_box->blockSignals(false);
994 buttonItalic->blockSignals(false);
995 buttonUnder->blockSignals(false);
996 fontColorButton->blockSignals(false);
997 textAlpha->blockSignals(false);
998 buttonAlignLeft->blockSignals(false);
999 buttonAlignRight->blockSignals(false);
1000 buttonAlignNone->blockSignals(false);
1001 buttonAlignCenter->blockSignals(false);
1003 updateAxisButtons(i);
1004 updateCoordinates(i);
1006 enableToolbars(TITLE_TEXT);
1008 } else if ((l.at(0))->type() == RECTITEM) {
1009 showToolbars(TITLE_RECTANGLE);
1011 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1012 if (rec == m_startViewport || rec == m_endViewport) {
1013 /*toolBox->setCurrentIndex(3);
1014 toolBox->widget(0)->setEnabled(false);
1015 toolBox->widget(1)->setEnabled(false);*/
1016 enableToolbars(TITLE_SELECT);
1018 /*toolBox->widget(0)->setEnabled(true);
1019 toolBox->widget(1)->setEnabled(true);
1020 toolBox->setCurrentIndex(0);*/
1021 //toolBox->setItemEnabled(3, true);
1022 rectFAlpha->setValue(rec->pen().color().alpha());
1023 rectBAlpha->setValue(rec->brush().color().alpha());
1024 //kDebug() << rec->brush().color().alpha();
1025 QColor fcol = rec->pen().color();
1026 QColor bcol = rec->brush().color();
1027 //fcol.setAlpha(255);
1028 //bcol.setAlpha(255);
1029 rectFColor->setColor(fcol);
1030 rectBColor->setColor(bcol);
1032 rectLineWidth->setValue(rec->pen().width());
1033 enableToolbars(TITLE_RECTANGLE);
1036 updateAxisButtons(l.at(0));
1037 updateCoordinates(rec);
1038 updateDimension(rec);
1040 } else if (l.at(0)->type() == IMAGEITEM) {
1041 showToolbars(TITLE_IMAGE);
1043 updateCoordinates(l.at(0));
1044 updateDimension(l.at(0));
1046 enableToolbars(TITLE_IMAGE);
1049 //toolBox->setCurrentIndex(0);
1050 showToolbars(TITLE_SELECT);
1051 enableToolbars(TITLE_SELECT);
1052 frame_properties->setEnabled(false);
1054 zValue->setValue((int)l.at(0)->zValue());
1055 if (!l.at(0)->data(ZOOMFACTOR).isNull()) itemzoom->setValue(l.at(0)->data(ZOOMFACTOR).toInt());
1056 else itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
1057 itemrotatex->setValue((int)(m_transformations.value(l.at(0)).rotatex));
1058 itemrotatey->setValue((int)(m_transformations.value(l.at(0)).rotatey));
1059 itemrotatez->setValue((int)(m_transformations.value(l.at(0)).rotatez));
1060 value_x->blockSignals(false);
1061 value_y->blockSignals(false);
1062 value_w->blockSignals(false);
1063 value_h->blockSignals(false);
1064 itemzoom->blockSignals(false);
1065 itemrotatex->blockSignals(false);
1066 itemrotatey->blockSignals(false);
1067 itemrotatez->blockSignals(false);
1071 void TitleWidget::slotValueChanged(int type)
1073 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1074 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
1079 val = value_w->value();
1082 val = value_h->value();
1086 QGraphicsItem *i = l.at(0);
1087 Transform t = m_transformations.value(i);
1089 // Ratio width:height
1090 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1091 // TODO: proper calculation for rotation around 3 axes
1092 double alpha = (double) t.rotatez / 180.0 * M_PI;
1095 double length = val;
1102 // Add 0.5 because otherwise incrementing by 1 might have no effect
1103 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1104 scale = length / i->boundingRect().width();
1107 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1108 scale = length / i->boundingRect().height();
1115 qtrans.scale(scale, scale);
1116 qtrans.rotate(t.rotatex, Qt::XAxis);
1117 qtrans.rotate(t.rotatey, Qt::YAxis);
1118 qtrans.rotate(t.rotatez, Qt::ZAxis);
1119 i->setTransform(qtrans);
1120 m_transformations[i] = t;
1127 /** \brief Updates position/size of the selected item when a value
1128 * of an item (coordinates, size) has changed */
1129 void TitleWidget::slotAdjustSelectedItem()
1131 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1132 if (l.size() >= 1) {
1133 if (l.at(0)->type() == RECTITEM) {
1135 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1136 updatePosition(rec);
1137 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1138 } else if (l.at(0)->type() == TEXTITEM) {
1140 updatePosition(l.at(0));
1141 } else if (l.at(0)->type() == IMAGEITEM) {
1143 updatePosition(l.at(0));
1148 /** \brief Updates width/height int the text fields, regarding transformation matrix */
1149 void TitleWidget::updateDimension(QGraphicsItem *i)
1151 value_w->blockSignals(true);
1152 value_h->blockSignals(true);
1153 zValue->blockSignals(true);
1155 zValue->setValue((int) i->zValue());
1156 if (i->type() == IMAGEITEM) {
1157 // Get multipliers for rotation/scaling
1159 /*Transform t = m_transformations.value(i);
1160 QRectF r = i->boundingRect();
1161 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1162 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1163 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1164 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1166 value_w->setValue(i->sceneBoundingRect().width());
1167 value_h->setValue(i->sceneBoundingRect().height());
1168 } else if (i->type() == RECTITEM) {
1169 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1170 value_w->setValue((int) r->rect().width());
1171 value_h->setValue((int) r->rect().height());
1172 } else if (i->type() == TEXTITEM) {
1173 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1174 value_w->setValue((int) t->boundingRect().width());
1175 value_h->setValue((int) t->boundingRect().height());
1178 zValue->blockSignals(false);
1179 value_w->blockSignals(false);
1180 value_h->blockSignals(false);
1183 /** \brief Updates the coordinates in the text fields from the item */
1184 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1186 // Block signals emitted by this method
1187 value_x->blockSignals(true);
1188 value_y->blockSignals(true);
1190 if (i->type() == TEXTITEM) {
1192 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1194 // Set the correct x coordinate value
1195 if (origin_x_left->isChecked()) {
1196 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1197 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1199 // Origin is at 0 (default)
1200 value_x->setValue((int) rec->pos().x());
1204 if (origin_y_top->isChecked()) {
1205 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1207 value_y->setValue((int) rec->pos().y());
1210 } else if (i->type() == RECTITEM) {
1212 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1214 if (origin_x_left->isChecked()) {
1215 // Origin (0 point) is at m_frameWidth
1216 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1218 // Origin is at 0 (default)
1219 value_x->setValue((int) rec->pos().x());
1222 if (origin_y_top->isChecked()) {
1223 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1225 value_y->setValue((int) rec->pos().y());
1228 } else if (i->type() == IMAGEITEM) {
1230 if (origin_x_left->isChecked()) {
1231 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1233 value_x->setValue((int) i->pos().x());
1236 if (origin_y_top->isChecked()) {
1237 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1239 value_y->setValue((int) i->pos().y());
1244 // Stop blocking signals now
1245 value_x->blockSignals(false);
1246 value_y->blockSignals(false);
1249 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1251 itemzoom->blockSignals(true);
1252 itemrotatex->blockSignals(true);
1253 itemrotatey->blockSignals(true);
1254 itemrotatez->blockSignals(true);
1256 Transform t = m_transformations.value(i);
1258 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1259 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1261 itemrotatex->setValue((int)(t.rotatex));
1262 itemrotatey->setValue((int)(t.rotatey));
1263 itemrotatez->setValue((int)(t.rotatez));
1265 itemzoom->blockSignals(false);
1266 itemrotatex->blockSignals(false);
1267 itemrotatey->blockSignals(false);
1268 itemrotatez->blockSignals(false);
1271 /** \brief Updates the position of an item by reading coordinates from the text fields */
1272 void TitleWidget::updatePosition(QGraphicsItem *i)
1274 if (i->type() == TEXTITEM) {
1275 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1278 if (origin_x_left->isChecked()) {
1279 /* Origin of the x axis is at m_frameWidth,
1280 * and distance from right border of the item to the right
1281 * border of the frame is taken.
1282 * See comment to slotOriginXClicked().
1284 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1286 posX = value_x->value();
1290 if (origin_y_top->isChecked()) {
1291 /* Same for y axis */
1292 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1294 posY = value_y->value();
1297 rec->setPos(posX, posY);
1299 } else if (i->type() == RECTITEM) {
1301 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1304 if (origin_x_left->isChecked()) {
1305 posX = m_frameWidth - value_x->value() - rec->rect().width();
1307 posX = value_x->value();
1311 if (origin_y_top->isChecked()) {
1312 posY = m_frameHeight - value_y->value() - rec->rect().height();
1314 posY = value_y->value();
1317 rec->setPos(posX, posY);
1319 } else if (i->type() == IMAGEITEM) {
1321 if (origin_x_left->isChecked()) {
1322 // Use the sceneBoundingRect because this also regards transformations like zoom
1323 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1325 posX = value_x->value();
1329 if (origin_y_top->isChecked()) {
1330 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1332 posY = value_y->value();
1335 i->setPos(posX, posY);
1341 void TitleWidget::updateTextOriginX()
1343 if (origin_x_left->isChecked()) {
1344 origin_x_left->setText(i18n("\u2212X"));
1346 origin_x_left->setText(i18n("+X"));
1350 void TitleWidget::slotOriginXClicked()
1352 // Update the text displayed on the button.
1353 updateTextOriginX();
1355 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1356 if (l.size() >= 1) {
1357 updateCoordinates(l.at(0));
1359 // Remember x axis setting
1360 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1361 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1363 graphicsView->setFocus();
1366 void TitleWidget::updateTextOriginY()
1368 if (origin_y_top->isChecked()) {
1369 origin_y_top->setText(i18n("\u2212Y"));
1371 origin_y_top->setText(i18n("+Y"));
1375 void TitleWidget::slotOriginYClicked()
1377 // Update the text displayed on the button.
1378 updateTextOriginY();
1380 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1381 if (l.size() >= 1) {
1382 updateCoordinates(l.at(0));
1384 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1385 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1388 graphicsView->setFocus();
1391 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1393 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1394 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1395 origin_x_left->blockSignals(true);
1396 origin_y_top->blockSignals(true);
1398 if (xAxis == TitleDocument::AxisInverted) {
1399 origin_x_left->setChecked(true);
1401 origin_x_left->setChecked(false);
1403 updateTextOriginX();
1405 if (yAxis == TitleDocument::AxisInverted) {
1406 origin_y_top->setChecked(true);
1408 origin_y_top->setChecked(false);
1410 updateTextOriginY();
1412 origin_x_left->blockSignals(false);
1413 origin_y_top->blockSignals(false);
1416 void TitleWidget::slotChangeBackground()
1418 QColor color = backgroundColor->color();
1419 color.setAlpha(backgroundAlpha->value());
1420 m_frameBorder->setBrush(QBrush(color));
1424 * Something (yeah) has changed in our QGraphicsScene.
1426 void TitleWidget::slotChanged()
1428 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1429 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1430 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1435 * If the user has set origin_x_left (everything also for y),
1436 * we need to look whether a text element has been selected. If yes,
1437 * we need to ensure that the right border of the text field
1438 * remains fixed also when some text has been entered.
1440 * This is also known as right-justified, with the difference that
1441 * it is not valid for text but for its boundingRect. Text may still
1442 * be left-justified.
1444 void TitleWidget::textChanged(QGraphicsTextItem *i)
1449 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1451 if (!i->toPlainText().isEmpty()) {
1455 * Don't do anything if the string is empty. If the position
1456 * would be updated here, a newly created text field would
1457 * be set to the position of the last selected text field.
1463 void TitleWidget::slotInsertUnicode()
1465 m_unicodeDialog->exec();
1468 void TitleWidget::slotInsertUnicodeString(QString text)
1470 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1472 if (l.at(0)->type() == TEXTITEM) {
1473 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1474 t->textCursor().insertText(text);
1479 void TitleWidget::slotUpdateText()
1481 QFont font = font_family->currentFont();
1482 font.setPixelSize(font_size->value());
1483 font.setItalic(buttonItalic->isChecked());
1484 font.setUnderline(buttonUnder->isChecked());
1485 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1486 QColor color = fontColorButton->color();
1487 color.setAlpha(textAlpha->value());
1489 QColor outlineColor = textOutlineColor->color();
1490 outlineColor.setAlpha(textOutlineAlpha->value());
1491 double outlineWidth = textOutline->value() / 10.0;
1492 QGraphicsTextItem* item = NULL;
1493 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1494 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1495 item = static_cast <QGraphicsTextItem *>(l.at(0));
1498 //if (item->textCursor().selection ().isEmpty())
1499 QTextCursor cur(item->document());
1500 cur.select(QTextCursor::Document);
1501 QTextBlockFormat format = cur.blockFormat();
1502 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1503 item->setTextWidth(item->boundingRect().width());
1504 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1505 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1506 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1508 format.setAlignment(Qt::AlignLeft);
1509 item->setTextWidth(-1);
1512 item->setFont(font);
1513 QTextCharFormat cformat = cur.charFormat();
1515 item->setData(101, outlineWidth);
1516 item->setData(102, outlineColor);
1517 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1519 cformat.setForeground(QBrush(color));
1520 cur.setCharFormat(cformat);
1521 cur.setBlockFormat(format);
1522 item->setTextCursor(cur);
1523 cur.clearSelection();
1524 item->setTextCursor(cur);
1527 void TitleWidget::rectChanged()
1529 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1530 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1531 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1532 QColor f = rectFColor->color();
1533 f.setAlpha(rectFAlpha->value());
1535 penf.setWidth(rectLineWidth->value());
1536 penf.setJoinStyle(Qt::RoundJoin);
1538 QColor b = rectBColor->color();
1539 b.setAlpha(rectBAlpha->value());
1540 rec->setBrush(QBrush(b));
1544 void TitleWidget::itemScaled(int val)
1546 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1547 if (l.size() == 1) {
1548 Transform x = m_transformations.value(l.at(0));
1549 x.scalex = (double)val / 100.0;
1550 x.scaley = (double)val / 100.0;
1552 qtrans.scale(x.scalex, x.scaley);
1553 qtrans.rotate(x.rotatex, Qt::XAxis);
1554 qtrans.rotate(x.rotatey, Qt::YAxis);
1555 qtrans.rotate(x.rotatez, Qt::ZAxis);
1556 l[0]->setTransform(qtrans);
1557 l[0]->setData(ZOOMFACTOR, val);
1558 m_transformations[l.at(0)] = x;
1559 updateDimension(l.at(0));
1563 void TitleWidget::itemRotateX(qreal val)
1568 void TitleWidget::itemRotateY(qreal val)
1573 void TitleWidget::itemRotateZ(qreal val)
1578 void TitleWidget::itemRotate(qreal val, int axis)
1580 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1581 if (l.size() == 1) {
1582 Transform x = m_transformations[l.at(0)];
1595 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1598 qtrans.scale(x.scalex, x.scaley);
1599 qtrans.rotate(x.rotatex, Qt::XAxis);
1600 qtrans.rotate(x.rotatey, Qt::YAxis);
1601 qtrans.rotate(x.rotatez, Qt::ZAxis);
1602 l[0]->setTransform(qtrans);
1603 m_transformations[l.at(0)] = x;
1604 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1605 updateDimension(l.at(0));
1609 void TitleWidget::itemHCenter()
1611 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1612 if (l.size() == 1) {
1613 QGraphicsItem *item = l.at(0);
1614 QRectF br = item->sceneBoundingRect();
1615 int width = (int)br.width();
1616 int newPos = (int)((m_frameWidth - width) / 2);
1617 newPos += item->pos().x() - br.left(); // Check item transformation
1618 item->setPos(newPos, item->pos().y());
1619 updateCoordinates(item);
1623 void TitleWidget::itemVCenter()
1625 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1626 if (l.size() == 1) {
1627 QGraphicsItem *item = l.at(0);
1628 QRectF br = item->sceneBoundingRect();
1629 int height = (int)br.height();
1630 int newPos = (int)((m_frameHeight - height) / 2);
1631 newPos += item->pos().y() - br.top(); // Check item transformation
1632 item->setPos(item->pos().x(), newPos);
1633 updateCoordinates(item);
1637 void TitleWidget::itemTop()
1639 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1640 if (l.size() == 1) {
1641 QGraphicsItem *item = l.at(0);
1642 QRectF br = item->sceneBoundingRect();
1644 if (br.top() > 0) diff = -br.top();
1645 else diff = -br.bottom();
1646 item->moveBy(0, diff);
1647 updateCoordinates(item);
1651 void TitleWidget::itemBottom()
1653 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1654 if (l.size() == 1) {
1655 QGraphicsItem *item = l.at(0);
1656 QRectF br = item->sceneBoundingRect();
1658 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1659 else diff = m_frameHeight - br.bottom();
1660 item->moveBy(0, diff);
1661 updateCoordinates(item);
1665 void TitleWidget::itemLeft()
1667 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1668 if (l.size() == 1) {
1669 QGraphicsItem *item = l.at(0);
1670 QRectF br = item->sceneBoundingRect();
1672 if (br.left() > 0) diff = -br.left();
1673 else diff = -br.right();
1674 item->moveBy(diff, 0);
1675 updateCoordinates(item);
1679 void TitleWidget::itemRight()
1681 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1682 if (l.size() == 1) {
1683 QGraphicsItem *item = l.at(0);
1684 QRectF br = item->sceneBoundingRect();
1686 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1687 else diff = m_frameWidth - br.left();
1688 item->moveBy(diff, 0);
1689 updateCoordinates(item);
1693 void TitleWidget::setupViewports()
1695 //double aspect_ratio = 4.0 / 3.0;//read from project
1696 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1697 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1698 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1699 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1700 QPolygonF spoly(sp);
1701 QPolygonF epoly(ep);
1702 spoly.translate(startViewportX->value(), startViewportY->value());
1703 epoly.translate(endViewportX->value(), endViewportY->value());
1704 m_startViewport->setPolygon(spoly);
1705 m_endViewport->setPolygon(epoly);
1706 if (! insertingValues) {
1707 m_startViewport->setData(0, startViewportX->value());
1708 m_startViewport->setData(1, startViewportY->value());
1709 m_startViewport->setData(2, startViewportSize->value());
1711 m_endViewport->setData(0, endViewportX->value());
1712 m_endViewport->setData(1, endViewportY->value());
1713 m_endViewport->setData(2, endViewportSize->value());
1717 void TitleWidget::loadTitle(KUrl url)
1719 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1720 if (!url.isEmpty()) {
1721 QList<QGraphicsItem *> items = m_scene->items();
1722 for (int i = 0; i < items.size(); i++) {
1723 if (items.at(i)->zValue() > -1000) delete items.at(i);
1725 m_scene->clearTextSelection();
1729 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1730 QFile file(tmpfile);
1731 if (file.open(QIODevice::ReadOnly)) {
1732 doc.setContent(&file, false);
1735 KIO::NetAccess::removeTempFile(tmpfile);
1740 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1742 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1743 insertingValues = true;
1744 startViewportX->setValue(m_startViewport->data(0).toInt());
1745 startViewportY->setValue(m_startViewport->data(1).toInt());
1746 startViewportSize->setValue(m_startViewport->data(2).toInt());
1747 endViewportX->setValue(m_endViewport->data(0).toInt());
1748 endViewportY->setValue(m_endViewport->data(1).toInt());
1749 endViewportSize->setValue(m_endViewport->data(2).toInt());
1751 insertingValues = false;
1757 void TitleWidget::saveTitle(KUrl url)
1759 if (anim_start->isChecked()) slotAnimStart(false);
1760 if (anim_end->isChecked()) slotAnimEnd(false);
1761 if (url.isEmpty()) {
1762 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1763 fs->setOperationMode(KFileDialog::Saving);
1764 fs->setMode(KFile::File);
1765 #if KDE_IS_VERSION(4,2,0)
1766 fs->setConfirmOverwrite(true);
1768 fs->setKeepLocation(true);
1770 url = fs->selectedUrl();
1773 if (!url.isEmpty()) {
1774 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()) - 1) == false)
1775 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1779 QDomDocument TitleWidget::xml()
1781 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1782 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()) - 1);
1786 int TitleWidget::outPoint() const
1788 return m_tc.getFrameCount(title_duration->text()) - 1;
1791 void TitleWidget::setXml(QDomDocument doc)
1794 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1796 title_duration->setText(m_tc.getTimecode(GenTime(out + 1, m_render->fps())));
1797 /*if (doc.documentElement().hasAttribute("out")) {
1798 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1799 title_duration->setText(m_tc.getTimecode(duration));
1801 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1803 QDomElement e = doc.documentElement();
1804 m_transformations.clear();
1805 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1806 const double PI = 4.0 * atan(1.0);
1807 for (int i = 0; i < items.count(); i++) {
1808 QTransform t = items.at(i)->transform();
1812 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1813 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1814 if (rotlist.count() >= 3) {
1815 x.rotatex = rotlist[0].toDouble();
1816 x.rotatey = rotlist[1].toDouble();
1817 x.rotatez = rotlist[2].toDouble();
1819 // Try to adjust zoom
1820 t.rotate(x.rotatex *(-1), Qt::XAxis);
1821 t.rotate(x.rotatey *(-1), Qt::YAxis);
1822 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1833 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1835 m_transformations[items.at(i)] = x;
1837 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1838 QColor background_color = m_titledocument.getBackgroundColor();
1839 backgroundAlpha->blockSignals(true);
1840 backgroundColor->blockSignals(true);
1841 backgroundAlpha->setValue(background_color.alpha());
1842 background_color.setAlpha(255);
1843 backgroundColor->setColor(background_color);
1844 backgroundAlpha->blockSignals(false);
1845 backgroundColor->blockSignals(false);
1847 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1848 startViewportY->setValue(m_startViewport->data(1).toInt());
1849 startViewportSize->setValue(m_startViewport->data(2).toInt());
1850 endViewportX->setValue(m_endViewport->data(0).toInt());
1851 endViewportY->setValue(m_endViewport->data(1).toInt());
1852 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1854 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1859 /** \brief Connected to the accepted signal - calls writeChoices */
1860 void TitleWidget::slotAccepted()
1862 if (anim_start->isChecked()) slotAnimStart(false);
1863 if (anim_end->isChecked()) slotAnimEnd(false);
1867 /** \brief Store the current choices of font, background and rect values */
1868 void TitleWidget::writeChoices()
1870 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1871 KSharedConfigPtr config = KGlobal::config();
1872 KConfigGroup titleConfig(config, "TitleWidget");
1873 // Write the entries
1874 titleConfig.writeEntry("font_family", font_family->currentFont());
1875 //titleConfig.writeEntry("font_size", font_size->value());
1876 titleConfig.writeEntry("font_pixel_size", font_size->value());
1877 titleConfig.writeEntry("font_color", fontColorButton->color());
1878 titleConfig.writeEntry("font_alpha", textAlpha->value());
1879 titleConfig.writeEntry("font_outline", textOutline->value());
1880 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1881 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1882 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1883 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1884 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1886 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1887 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1888 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1889 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1890 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1892 titleConfig.writeEntry("background_color", backgroundColor->color());
1893 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1895 //! \todo Not sure if I should sync - it is probably safe to do it
1900 /** \brief Read the last stored choices into the dialog */
1901 void TitleWidget::readChoices()
1903 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1904 KSharedConfigPtr config = KGlobal::config();
1905 KConfigGroup titleConfig(config, "TitleWidget");
1907 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1908 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1909 m_scene->slotUpdateFontSize(font_size->value());
1910 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1911 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1913 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
1914 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
1915 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
1918 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1919 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1920 setFontBoxWeight(weight);
1921 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1922 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1924 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1925 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1926 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1927 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1928 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1930 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
1931 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
1934 void TitleWidget::adjustFrameSize()
1936 m_frameWidth = m_titledocument.frameWidth();
1937 m_frameHeight = m_titledocument.frameHeight();
1938 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1939 displayBackgroundFrame();
1942 void TitleWidget::slotAnimStart(bool anim)
1944 if (anim && anim_end->isChecked()) {
1945 anim_end->setChecked(false);
1946 m_endViewport->setZValue(-1000);
1947 m_endViewport->setBrush(QBrush());
1950 QList<QGraphicsItem *> list = m_scene->items();
1951 for (int i = 0; i < list.count(); i++) {
1952 if (list.at(i)->zValue() > -1000) {
1953 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1954 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1957 align_box->setEnabled(anim);
1958 itemzoom->setEnabled(!anim);
1959 itemrotatex->setEnabled(!anim);
1960 itemrotatey->setEnabled(!anim);
1961 itemrotatez->setEnabled(!anim);
1962 frame_toolbar->setEnabled(!anim);
1963 toolbar_stack->setEnabled(!anim);
1965 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1966 m_startViewport->setZValue(1100);
1967 QColor col = m_startViewport->pen().color();
1969 m_startViewport->setBrush(col);
1970 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1971 m_startViewport->setSelected(true);
1974 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1976 m_startViewport->setZValue(-1000);
1977 m_startViewport->setBrush(QBrush());
1978 m_startViewport->setFlags(0);
1979 if (!anim_end->isChecked()) deleteAnimInfoText();
1984 void TitleWidget::slotAnimEnd(bool anim)
1986 if (anim && anim_start->isChecked()) {
1987 anim_start->setChecked(false);
1988 m_startViewport->setZValue(-1000);
1989 m_startViewport->setBrush(QBrush());
1992 QList<QGraphicsItem *> list = m_scene->items();
1993 for (int i = 0; i < list.count(); i++) {
1994 if (list.at(i)->zValue() > -1000) {
1995 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1996 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1999 align_box->setEnabled(anim);
2000 itemzoom->setEnabled(!anim);
2001 itemrotatex->setEnabled(!anim);
2002 itemrotatey->setEnabled(!anim);
2003 itemrotatez->setEnabled(!anim);
2004 frame_toolbar->setEnabled(!anim);
2005 toolbar_stack->setEnabled(!anim);
2007 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2008 m_endViewport->setZValue(1100);
2009 QColor col = m_endViewport->pen().color();
2011 m_endViewport->setBrush(col);
2012 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2013 m_endViewport->setSelected(true);
2016 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2018 m_endViewport->setZValue(-1000);
2019 m_endViewport->setBrush(QBrush());
2020 m_endViewport->setFlags(0);
2021 if (!anim_start->isChecked()) deleteAnimInfoText();
2025 void TitleWidget::addAnimInfoText()
2027 // add text to anim viewport
2028 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2029 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2030 QFont font = t->font();
2031 font.setPixelSize(m_startViewport->rect().width() / 10);
2032 QColor col = m_startViewport->pen().color();
2034 t->setDefaultTextColor(col);
2036 font.setPixelSize(m_endViewport->rect().width() / 10);
2037 col = m_endViewport->pen().color();
2039 t2->setDefaultTextColor(col);
2043 void TitleWidget::updateInfoText()
2045 // update info text font
2046 if (!m_startViewport->childItems().isEmpty()) {
2047 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2049 QFont font = item->font();
2050 font.setPixelSize(m_startViewport->rect().width() / 10);
2051 item->setFont(font);
2054 if (!m_endViewport->childItems().isEmpty()) {
2055 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2057 QFont font = item->font();
2058 font.setPixelSize(m_endViewport->rect().width() / 10);
2059 item->setFont(font);
2064 void TitleWidget::deleteAnimInfoText()
2066 // end animation editing, remove info text
2067 while (!m_startViewport->childItems().isEmpty()) {
2068 QGraphicsItem *item = m_startViewport->childItems().at(0);
2069 m_scene->removeItem(item);
2072 while (!m_endViewport->childItems().isEmpty()) {
2073 QGraphicsItem *item = m_endViewport->childItems().at(0);
2074 m_scene->removeItem(item);
2080 void TitleWidget::slotKeepAspect(bool keep)
2082 if (m_endViewport->zValue() == 1100) {
2083 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2084 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2086 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2087 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2091 void TitleWidget::slotResize50()
2093 if (m_endViewport->zValue() == 1100) {
2094 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2095 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2098 void TitleWidget::slotResize100()
2100 if (m_endViewport->zValue() == 1100) {
2101 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2102 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2105 void TitleWidget::slotResize200()
2107 if (m_endViewport->zValue() == 1100) {
2108 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2109 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2112 void TitleWidget::slotAddEffect(int ix)
2114 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2115 int effect = effect_list->itemData(ix).toInt();
2116 if (effect == NOEFFECT) {
2117 if (l.size() == 1) l[0]->setData(100, QVariant());
2118 effect_stack->setHidden(true);
2121 effect_stack->setCurrentIndex(effect - 1);
2122 effect_stack->setHidden(false);
2123 if (effect == TYPEWRITEREFFECT) {
2124 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
2125 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2126 l[0]->setData(100, effdata);
2129 #if QT_VERSION < 0x040600
2132 if (effect == BLUREFFECT) {
2134 if (l.size() == 1) {
2135 QGraphicsEffect *eff = new QGraphicsBlurEffect();
2136 l[0]->setGraphicsEffect(eff);
2138 } else if (effect == SHADOWEFFECT) {
2139 if (l.size() == 1) {
2140 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
2141 l[0]->setGraphicsEffect(eff);
2149 void TitleWidget::slotFontText(const QString& s)
2152 if (f.exactMatch()) {
2153 // Font really exists (could also just be a «d» if the user
2154 // starts typing «dejavu» for example).
2155 font_family->setCurrentFont(f);
2157 // Note: Typing dejavu serif does not recognize the font (takes sans)
2158 // in older Qt versions.
2161 void TitleWidget::slotEditTypewriter(int /*ix*/)
2163 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2164 if (l.size() == 1) {
2165 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2166 l[0]->setData(100, effdata);
2170 void TitleWidget::slotEditBlur(int ix)
2172 #if QT_VERSION < 0x040600
2175 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2176 if (l.size() == 1) {
2177 QGraphicsEffect *eff = l[0]->graphicsEffect();
2178 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2179 if (blur) blur->setBlurRadius(ix);
2184 void TitleWidget::slotEditShadow()
2186 #if QT_VERSION < 0x040600
2189 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2190 if (l.size() == 1) {
2191 QGraphicsEffect *eff = l[0]->graphicsEffect();
2192 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2194 shadow->setBlurRadius(shadow_radius->value());
2195 shadow->setOffset(shadow_x->value(), shadow_y->value());
2201 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2203 qreal bound = maxBound ? -99 : 99;
2204 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2206 QList<QGraphicsItem*> lItems;
2207 // Get items (all or intersecting only)
2208 if (intersectingOnly) {
2209 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2211 lItems = graphicsView->scene()->items();
2213 if (lItems.size() > 0) {
2214 int n = lItems.size();
2217 for (int i = 0; i < n; i++) {
2218 z = lItems[i]->zValue();
2219 if (z > bound && !lItems[i]->isSelected()) {
2224 // Get minimum z index.
2225 for (int i = 0; i < n; i++) {
2226 z = lItems[i]->zValue();
2227 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2228 // There are items at the very bottom (background e.g.) with z-index < -1000.
2238 void TitleWidget::slotZIndexUp()
2240 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2241 if (l.size() >= 1) {
2242 qreal currentZ = l[0]->zValue();
2243 qreal max = zIndexBounds(true, true);
2244 if (currentZ <= max) {
2245 l[0]->setZValue(currentZ + 1);
2246 updateDimension(l[0]);
2251 void TitleWidget::slotZIndexTop()
2253 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2254 if (l.size() >= 1) {
2255 qreal currentZ = l[0]->zValue();
2256 qreal max = zIndexBounds(true, false);
2257 if (currentZ <= max) {
2258 l[0]->setZValue(max + 1);
2259 updateDimension(l[0]);
2264 void TitleWidget::slotZIndexDown()
2266 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2267 if (l.size() >= 1) {
2268 qreal currentZ = l[0]->zValue();
2269 qreal min = zIndexBounds(false, true);
2270 if (currentZ >= min) {
2271 l[0]->setZValue(currentZ - 1);
2272 updateDimension(l[0]);
2277 void TitleWidget::slotZIndexBottom()
2279 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2280 if (l.size() >= 1) {
2281 qreal currentZ = l[0]->zValue();
2282 qreal min = zIndexBounds(false, false);
2283 if (currentZ >= min) {
2284 l[0]->setZValue(min - 1);
2285 updateDimension(l[0]);