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 //TODO: get default title duration instead of hardcoded one
146 title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0)));
148 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
149 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
151 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
152 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
153 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
154 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
155 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
156 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
157 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
158 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
160 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
162 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
163 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
164 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
165 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
166 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
168 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
169 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
170 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
171 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
172 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
173 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
176 effect_list->addItem(i18n("None"), NOEFFECT);
177 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
178 effect_list->addItem(i18n("Blur"), BLUREFFECT);
181 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
182 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
183 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
184 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
185 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
186 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
187 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
188 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
189 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
190 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
191 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
192 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
193 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
194 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
195 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
196 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
197 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
198 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
199 effect_stack->setHidden(true);
200 effect_frame->setEnabled(false);
202 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
203 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
205 m_signalMapper = new QSignalMapper(this);
206 m_signalMapper->setMapping(value_w, ValueWidth);
207 m_signalMapper->setMapping(value_h, ValueHeight);
208 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
209 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
210 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
212 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
213 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
214 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
215 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
216 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
217 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
218 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
219 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
220 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
221 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
222 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
223 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
224 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
226 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
229 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
231 font_weight_box->blockSignals(true);
232 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
233 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
234 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
235 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
236 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
237 font_weight_box->setToolTip(i18n("Font weight"));
238 font_weight_box->setCurrentIndex(1);
239 font_weight_box->blockSignals(false);
241 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
242 buttonRealSize->setIcon(KIcon("zoom-original"));
243 buttonItalic->setIcon(KIcon("format-text-italic"));
244 buttonUnder->setIcon(KIcon("format-text-underline"));
245 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
246 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
247 buttonAlignRight->setIcon(KIcon("format-justify-right"));
248 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
250 buttonAlignNone->setToolTip(i18n("No alignment"));
251 buttonAlignRight->setToolTip(i18n("Align right"));
252 buttonAlignLeft->setToolTip(i18n("Align left"));
253 buttonAlignCenter->setToolTip(i18n("Align center"));
255 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
256 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
257 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
258 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
259 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
261 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
262 m_zUp->setShortcut(Qt::Key_PageUp);
263 m_zUp->setToolTip(i18n("Raise object"));
264 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
265 zUp->setDefaultAction(m_zUp);
267 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
268 m_zDown->setShortcut(Qt::Key_PageDown);
269 m_zDown->setToolTip(i18n("Lower object"));
270 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
271 zDown->setDefaultAction(m_zDown);
273 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
274 // TODO mbt 1414: Shortcut should change z index only if
275 // cursor is NOT in a text field ...
276 //m_zTop->setShortcut(Qt::Key_Home);
277 m_zTop->setToolTip(i18n("Raise object to top"));
278 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
279 zTop->setDefaultAction(m_zTop);
281 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
283 //m_zBottom->setShortcut(Qt::Key_End);
284 m_zBottom->setToolTip(i18n("Lower object to bottom"));
285 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
286 zBottom->setDefaultAction(m_zBottom);
288 zDown->setIcon(KIcon("kdenlive-zindex-down"));
289 zTop->setIcon(KIcon("kdenlive-zindex-top"));
290 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
291 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
292 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
293 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
295 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
296 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
297 rectBColor->setToolTip(i18n("Select fill color"));
298 rectFColor->setToolTip(i18n("Select border color"));
299 rectBAlpha->setToolTip(i18n("Fill opacity"));
300 rectFAlpha->setToolTip(i18n("Border opacity"));
301 zoom_slider->setToolTip(i18n("Zoom"));
302 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
303 buttonFitZoom->setToolTip(i18n("Fit zoom"));
304 backgroundColor->setToolTip(i18n("Select background color"));
305 backgroundAlpha->setToolTip(i18n("Background opacity"));
307 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
308 itemhcenter->setToolTip(i18n("Align item horizontally"));
309 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
310 itemvcenter->setToolTip(i18n("Align item vertically"));
311 itemtop->setIcon(KIcon("kdenlive-align-top"));
312 itemtop->setToolTip(i18n("Align item to top"));
313 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
314 itembottom->setToolTip(i18n("Align item to bottom"));
315 itemright->setIcon(KIcon("kdenlive-align-right"));
316 itemright->setToolTip(i18n("Align item to right"));
317 itemleft->setIcon(KIcon("kdenlive-align-left"));
318 itemleft->setToolTip(i18n("Align item to left"));
321 QHBoxLayout *layout = new QHBoxLayout;
322 frame_toolbar->setLayout(layout);
323 layout->setContentsMargins(0, 0, 0, 0);
324 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
325 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
326 m_toolbar->setIconSize(QSize(s, s));
328 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
329 m_buttonCursor->setCheckable(true);
330 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
331 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
332 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
334 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
335 m_buttonText->setCheckable(true);
336 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
337 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
338 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
340 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
341 m_buttonRect->setCheckable(true);
342 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
343 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
344 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
346 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
347 m_buttonImage->setCheckable(false);
348 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
349 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
350 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
352 m_toolbar->addSeparator();
354 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
355 m_buttonLoad->setCheckable(false);
356 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
357 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
359 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
360 m_buttonSave->setCheckable(false);
361 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
362 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
364 layout->addWidget(m_toolbar);
366 // initialize graphic scene
367 m_scene = new GraphicsSceneRectMove(this);
368 graphicsView->setScene(m_scene);
369 graphicsView->setMouseTracking(true);
370 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
371 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
372 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
374 // a gradient background
375 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
376 gradient->setSpread(QGradient::ReflectSpread);
377 scene->setBackgroundBrush(*gradient);*/
379 m_frameImage = new QGraphicsPixmapItem();
381 qtrans.scale(2.0, 2.0);
382 m_frameImage->setTransform(qtrans);
383 m_frameImage->setZValue(-1200);
384 m_frameImage->setFlags(0);
385 displayBackgroundFrame();
386 graphicsView->scene()->addItem(m_frameImage);
388 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
389 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
390 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
391 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
392 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
393 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
394 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
395 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
397 QPen framepen(Qt::DotLine);
398 framepen.setColor(Qt::red);
400 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
401 m_frameBorder->setPen(framepen);
402 m_frameBorder->setZValue(-1100);
403 m_frameBorder->setBrush(Qt::transparent);
404 m_frameBorder->setFlags(0);
405 graphicsView->scene()->addItem(m_frameBorder);
407 // mbd: load saved settings
410 graphicsView->show();
411 //graphicsView->setRenderHint(QPainter::Antialiasing);
412 graphicsView->setInteractive(true);
413 //graphicsView->resize(400, 300);
414 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
415 //toolBox->setItemEnabled(2, false);
416 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
417 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
418 m_startViewport->setData(0, m_frameWidth);
419 m_startViewport->setData(1, m_frameHeight);
420 m_endViewport->setData(0, m_frameWidth);
421 m_endViewport->setData(1, m_frameHeight);
423 if (!url.isEmpty()) loadTitle(url);
426 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
429 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
430 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
431 connect(templateBox,SIGNAL(currentIndexChanged(int)),this,SLOT(templateIndexChanged(int)));
433 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
434 refreshTitleTemplates();
435 //templateBox->setIconSize(QSize(60,60));
436 templateBox->clear();
437 templateBox->addItem("");
438 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();
552 if (lastDocumentHash!=QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex())
554 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;
557 lastDocumentHash=QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
561 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
566 void TitleWidget::slotTextTool()
568 m_scene->setTool(TITLE_TEXT);
569 showToolbars(TITLE_TEXT);
570 checkButton(TITLE_TEXT);
573 void TitleWidget::slotRectTool()
575 m_scene->setTool(TITLE_RECTANGLE);
576 showToolbars(TITLE_RECTANGLE);
577 checkButton(TITLE_RECTANGLE);
580 void TitleWidget::slotSelectTool()
582 m_scene->setTool(TITLE_SELECT);
584 // Find out which toolbars need to be shown, depending on selected item
585 TITLETOOL t = TITLE_SELECT;
586 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
588 switch (l.at(0)->type()) {
602 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
603 //graphicsView->centerOn(l.at(0));
609 updateCoordinates(l.at(0));
610 updateDimension(l.at(0));
611 updateRotZoom(l.at(0));
614 checkButton(TITLE_SELECT);
617 void TitleWidget::slotImageTool()
619 // TODO: find a way to get a list of all supported image types...
620 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";
621 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
622 if (!url.isEmpty()) {
623 if (url.path().endsWith(".svg")) {
624 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
625 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
626 svg->setZValue(m_count++);
627 svg->setData(Qt::UserRole, url.path());
628 graphicsView->scene()->addItem(svg);
630 QPixmap pix(url.path());
631 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
632 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
633 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
634 image->setData(Qt::UserRole, url.path());
635 image->setZValue(m_count++);
636 graphicsView->scene()->addItem(image);
639 m_scene->setTool(TITLE_SELECT);
640 showToolbars(TITLE_SELECT);
641 checkButton(TITLE_SELECT);
644 void TitleWidget::showToolbars(TITLETOOL toolType)
646 toolbar_stack->setCurrentIndex((int) toolType);
649 void TitleWidget::enableToolbars(TITLETOOL toolType)
651 // TITLETOOL is defined in graphicsscenerectmove.h
653 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
654 value_w->setEnabled(enable);
655 value_h->setEnabled(enable);
658 void TitleWidget::checkButton(TITLETOOL toolType)
660 bool bSelect = false;
672 case TITLE_RECTANGLE:
682 m_buttonCursor->setChecked(bSelect);
683 m_buttonText->setChecked(bText);
684 m_buttonRect->setChecked(bRect);
685 m_buttonImage->setChecked(bImage);
688 void TitleWidget::displayBackgroundFrame()
690 if (!displayBg->isChecked()) {
691 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
692 QPixmap pattern(20, 20);
694 QColor bgcolor(210, 210, 210);
697 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
698 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
703 p.fillRect(bg.rect(), br);
705 m_frameImage->setPixmap(bg);
707 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
711 void TitleWidget::initAnimation()
713 align_box->setEnabled(false);
714 QPen startpen(Qt::DotLine);
715 QPen endpen(Qt::DashDotLine);
716 startpen.setColor(QColor(100, 200, 100, 140));
717 endpen.setColor(QColor(200, 100, 100, 140));
719 m_startViewport->setPen(startpen);
720 m_endViewport->setPen(endpen);
722 m_startViewport->setZValue(-1000);
723 m_endViewport->setZValue(-1000);
725 m_startViewport->setFlags(0);
726 m_endViewport->setFlags(0);
728 graphicsView->scene()->addItem(m_startViewport);
729 graphicsView->scene()->addItem(m_endViewport);
731 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
732 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
733 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
734 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
737 void TitleWidget::slotUpdateZoom(int pos)
739 m_scene->setZoom((double) pos / 100);
740 zoom_label->setText(QString::number(pos) + '%');
743 void TitleWidget::slotZoom(bool up)
745 int pos = zoom_slider->value();
748 zoom_slider->setValue(pos);
751 void TitleWidget::slotAdjustZoom()
753 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
754 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
755 if (scalex > scaley) scalex = scaley;
756 int zoompos = (int)(scalex * 7 + 0.5);*/
757 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
758 int zoompos = graphicsView->matrix().m11() * 100;
759 zoom_slider->setValue(zoompos);
760 graphicsView->centerOn(m_frameBorder);
763 void TitleWidget::slotZoomOneToOne()
765 zoom_slider->setValue(100);
766 graphicsView->centerOn(m_frameBorder);
769 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
771 updateAxisButtons(rect); // back to default
773 QColor f = rectFColor->color();
774 f.setAlpha(rectFAlpha->value());
776 penf.setWidth(rectLineWidth->value());
777 penf.setJoinStyle(Qt::RoundJoin);
779 QColor b = rectBColor->color();
780 b.setAlpha(rectBAlpha->value());
781 rect->setBrush(QBrush(b));
782 rect->setZValue(m_count++);
783 rect->setData(ZOOMFACTOR, 100);
784 //setCurrentItem(rect);
785 //graphicsView->setFocus();
788 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
790 updateAxisButtons(tt); // back to default
792 QFont font = font_family->currentFont();
793 font.setPixelSize(font_size->value());
795 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
796 font.setItalic(buttonItalic->isChecked());
797 font.setUnderline(buttonUnder->isChecked());
800 QColor color = fontColorButton->color();
801 color.setAlpha(textAlpha->value());
802 tt->setDefaultTextColor(color);
804 QTextCursor cur(tt->document());
805 cur.select(QTextCursor::Document);
806 QTextBlockFormat format = cur.blockFormat();
807 QTextCharFormat cformat = cur.charFormat();
808 QColor outlineColor = textOutlineColor->color();
809 outlineColor.setAlpha(textOutlineAlpha->value());
810 double outlineWidth = textOutline->value() / 10.0;
812 tt->setData(101, outlineWidth);
813 tt->setData(102, outlineColor);
814 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
816 cformat.setForeground(QBrush(color));
817 cur.setCharFormat(cformat);
818 cur.setBlockFormat(format);
819 tt->setTextCursor(cur);
820 tt->setZValue(m_count++);
824 void TitleWidget::setFontBoxWeight(int weight)
826 int index = font_weight_box->findData(weight);
828 index = font_weight_box->findData(QFont::Normal);
830 font_weight_box->setCurrentIndex(index);
833 void TitleWidget::setCurrentItem(QGraphicsItem *item)
835 m_scene->setSelectedItem(item);
838 void TitleWidget::zIndexChanged(int v)
840 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
846 void TitleWidget::selectionChanged()
848 if (m_scene->tool() != TITLE_SELECT) return;
849 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
850 //toolBox->setItemEnabled(2, false);
851 //toolBox->setItemEnabled(3, false);
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->blockSignals(true);
930 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
931 effect_list->blockSignals(false);
932 effect_stack->setHidden(true);
935 effect_list->blockSignals(true);
936 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
937 effect_list->blockSignals(false);
938 effect_stack->setHidden(true);
941 //if (l[0]->hasFocus())
942 //toolBox->setCurrentIndex(0);
943 //toolBox->setItemEnabled(2, true);
944 font_size->blockSignals(true);
945 font_family->blockSignals(true);
946 font_weight_box->blockSignals(true);
947 buttonItalic->blockSignals(true);
948 buttonUnder->blockSignals(true);
949 fontColorButton->blockSignals(true);
950 textAlpha->blockSignals(true);
951 buttonAlignLeft->blockSignals(true);
952 buttonAlignRight->blockSignals(true);
953 buttonAlignNone->blockSignals(true);
954 buttonAlignCenter->blockSignals(true);
956 QFont font = i->font();
957 font_family->setCurrentFont(font);
958 font_size->setValue(font.pixelSize());
959 m_scene->slotUpdateFontSize(font.pixelSize());
960 buttonItalic->setChecked(font.italic());
961 buttonUnder->setChecked(font.underline());
962 setFontBoxWeight(font.weight());
964 QTextCursor cursor(i->document());
965 cursor.select(QTextCursor::Document);
966 QColor color = cursor.charFormat().foreground().color();
967 textAlpha->setValue(color.alpha());
969 fontColorButton->setColor(color);
971 if (!i->data(101).isNull()) {
972 textOutline->blockSignals(true);
973 textOutline->setValue(i->data(101).toDouble()*10);
974 textOutline->blockSignals(false);
976 if (!i->data(102).isNull()) {
977 textOutlineColor->blockSignals(true);
978 textOutlineAlpha->blockSignals(true);
979 color = QColor(i->data(102).toString());
980 textOutlineAlpha->setValue(color.alpha());
982 textOutlineColor->setColor(color);
983 textOutlineColor->blockSignals(false);
984 textOutlineAlpha->blockSignals(false);
986 QTextCursor cur = i->textCursor();
987 QTextBlockFormat format = cur.blockFormat();
988 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
989 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
990 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
991 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
993 font_size->blockSignals(false);
994 font_family->blockSignals(false);
995 font_weight_box->blockSignals(false);
996 buttonItalic->blockSignals(false);
997 buttonUnder->blockSignals(false);
998 fontColorButton->blockSignals(false);
999 textAlpha->blockSignals(false);
1000 buttonAlignLeft->blockSignals(false);
1001 buttonAlignRight->blockSignals(false);
1002 buttonAlignNone->blockSignals(false);
1003 buttonAlignCenter->blockSignals(false);
1005 updateAxisButtons(i);
1006 updateCoordinates(i);
1008 enableToolbars(TITLE_TEXT);
1010 } else if ((l.at(0))->type() == RECTITEM) {
1011 showToolbars(TITLE_RECTANGLE);
1013 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1014 if (rec == m_startViewport || rec == m_endViewport) {
1015 /*toolBox->setCurrentIndex(3);
1016 toolBox->widget(0)->setEnabled(false);
1017 toolBox->widget(1)->setEnabled(false);*/
1018 enableToolbars(TITLE_SELECT);
1020 /*toolBox->widget(0)->setEnabled(true);
1021 toolBox->widget(1)->setEnabled(true);
1022 toolBox->setCurrentIndex(0);*/
1023 //toolBox->setItemEnabled(3, true);
1024 rectFAlpha->setValue(rec->pen().color().alpha());
1025 rectBAlpha->setValue(rec->brush().color().alpha());
1026 //kDebug() << rec->brush().color().alpha();
1027 QColor fcol = rec->pen().color();
1028 QColor bcol = rec->brush().color();
1029 //fcol.setAlpha(255);
1030 //bcol.setAlpha(255);
1031 rectFColor->setColor(fcol);
1032 rectBColor->setColor(bcol);
1034 rectLineWidth->setValue(rec->pen().width());
1035 enableToolbars(TITLE_RECTANGLE);
1038 updateAxisButtons(l.at(0));
1039 updateCoordinates(rec);
1040 updateDimension(rec);
1042 } else if (l.at(0)->type() == IMAGEITEM) {
1043 showToolbars(TITLE_IMAGE);
1045 updateCoordinates(l.at(0));
1046 updateDimension(l.at(0));
1048 enableToolbars(TITLE_IMAGE);
1051 //toolBox->setCurrentIndex(0);
1052 showToolbars(TITLE_SELECT);
1053 enableToolbars(TITLE_SELECT);
1054 frame_properties->setEnabled(false);
1056 zValue->setValue((int)l.at(0)->zValue());
1057 if (!l.at(0)->data(ZOOMFACTOR).isNull()) itemzoom->setValue(l.at(0)->data(ZOOMFACTOR).toInt());
1058 else itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
1059 itemrotatex->setValue((int)(m_transformations.value(l.at(0)).rotatex));
1060 itemrotatey->setValue((int)(m_transformations.value(l.at(0)).rotatey));
1061 itemrotatez->setValue((int)(m_transformations.value(l.at(0)).rotatez));
1062 value_x->blockSignals(false);
1063 value_y->blockSignals(false);
1064 value_w->blockSignals(false);
1065 value_h->blockSignals(false);
1066 itemzoom->blockSignals(false);
1067 itemrotatex->blockSignals(false);
1068 itemrotatey->blockSignals(false);
1069 itemrotatez->blockSignals(false);
1073 void TitleWidget::slotValueChanged(int type)
1075 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1076 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
1081 val = value_w->value();
1084 val = value_h->value();
1088 QGraphicsItem *i = l.at(0);
1089 Transform t = m_transformations.value(i);
1091 // Ratio width:height
1092 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1093 // TODO: proper calculation for rotation around 3 axes
1094 double alpha = (double) t.rotatez / 180.0 * M_PI;
1097 double length = val;
1104 // Add 0.5 because otherwise incrementing by 1 might have no effect
1105 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1106 scale = length / i->boundingRect().width();
1109 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1110 scale = length / i->boundingRect().height();
1117 qtrans.scale(scale, scale);
1118 qtrans.rotate(t.rotatex, Qt::XAxis);
1119 qtrans.rotate(t.rotatey, Qt::YAxis);
1120 qtrans.rotate(t.rotatez, Qt::ZAxis);
1121 i->setTransform(qtrans);
1122 m_transformations[i] = t;
1129 /** \brief Updates position/size of the selected item when a value
1130 * of an item (coordinates, size) has changed */
1131 void TitleWidget::slotAdjustSelectedItem()
1133 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1134 if (l.size() >= 1) {
1135 if (l.at(0)->type() == RECTITEM) {
1137 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1138 updatePosition(rec);
1139 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1140 } else if (l.at(0)->type() == TEXTITEM) {
1142 updatePosition(l.at(0));
1143 } else if (l.at(0)->type() == IMAGEITEM) {
1145 updatePosition(l.at(0));
1150 /** \brief Updates width/height int the text fields, regarding transformation matrix */
1151 void TitleWidget::updateDimension(QGraphicsItem *i)
1153 value_w->blockSignals(true);
1154 value_h->blockSignals(true);
1155 zValue->blockSignals(true);
1157 zValue->setValue((int) i->zValue());
1158 if (i->type() == IMAGEITEM) {
1159 // Get multipliers for rotation/scaling
1161 /*Transform t = m_transformations.value(i);
1162 QRectF r = i->boundingRect();
1163 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1164 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1165 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1166 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1168 value_w->setValue(i->sceneBoundingRect().width());
1169 value_h->setValue(i->sceneBoundingRect().height());
1170 } else if (i->type() == RECTITEM) {
1171 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1172 value_w->setValue((int) r->rect().width());
1173 value_h->setValue((int) r->rect().height());
1174 } else if (i->type() == TEXTITEM) {
1175 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1176 value_w->setValue((int) t->boundingRect().width());
1177 value_h->setValue((int) t->boundingRect().height());
1180 zValue->blockSignals(false);
1181 value_w->blockSignals(false);
1182 value_h->blockSignals(false);
1185 /** \brief Updates the coordinates in the text fields from the item */
1186 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1188 // Block signals emitted by this method
1189 value_x->blockSignals(true);
1190 value_y->blockSignals(true);
1192 if (i->type() == TEXTITEM) {
1194 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1196 // Set the correct x coordinate value
1197 if (origin_x_left->isChecked()) {
1198 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1199 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1201 // Origin is at 0 (default)
1202 value_x->setValue((int) rec->pos().x());
1206 if (origin_y_top->isChecked()) {
1207 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1209 value_y->setValue((int) rec->pos().y());
1212 } else if (i->type() == RECTITEM) {
1214 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1216 if (origin_x_left->isChecked()) {
1217 // Origin (0 point) is at m_frameWidth
1218 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1220 // Origin is at 0 (default)
1221 value_x->setValue((int) rec->pos().x());
1224 if (origin_y_top->isChecked()) {
1225 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1227 value_y->setValue((int) rec->pos().y());
1230 } else if (i->type() == IMAGEITEM) {
1232 if (origin_x_left->isChecked()) {
1233 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1235 value_x->setValue((int) i->pos().x());
1238 if (origin_y_top->isChecked()) {
1239 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1241 value_y->setValue((int) i->pos().y());
1246 // Stop blocking signals now
1247 value_x->blockSignals(false);
1248 value_y->blockSignals(false);
1251 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1253 itemzoom->blockSignals(true);
1254 itemrotatex->blockSignals(true);
1255 itemrotatey->blockSignals(true);
1256 itemrotatez->blockSignals(true);
1258 Transform t = m_transformations.value(i);
1260 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1261 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1263 itemrotatex->setValue((int)(t.rotatex));
1264 itemrotatey->setValue((int)(t.rotatey));
1265 itemrotatez->setValue((int)(t.rotatez));
1267 itemzoom->blockSignals(false);
1268 itemrotatex->blockSignals(false);
1269 itemrotatey->blockSignals(false);
1270 itemrotatez->blockSignals(false);
1273 /** \brief Updates the position of an item by reading coordinates from the text fields */
1274 void TitleWidget::updatePosition(QGraphicsItem *i)
1276 if (i->type() == TEXTITEM) {
1277 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1280 if (origin_x_left->isChecked()) {
1281 /* Origin of the x axis is at m_frameWidth,
1282 * and distance from right border of the item to the right
1283 * border of the frame is taken.
1284 * See comment to slotOriginXClicked().
1286 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1288 posX = value_x->value();
1292 if (origin_y_top->isChecked()) {
1293 /* Same for y axis */
1294 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1296 posY = value_y->value();
1299 rec->setPos(posX, posY);
1301 } else if (i->type() == RECTITEM) {
1303 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1306 if (origin_x_left->isChecked()) {
1307 posX = m_frameWidth - value_x->value() - rec->rect().width();
1309 posX = value_x->value();
1313 if (origin_y_top->isChecked()) {
1314 posY = m_frameHeight - value_y->value() - rec->rect().height();
1316 posY = value_y->value();
1319 rec->setPos(posX, posY);
1321 } else if (i->type() == IMAGEITEM) {
1323 if (origin_x_left->isChecked()) {
1324 // Use the sceneBoundingRect because this also regards transformations like zoom
1325 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1327 posX = value_x->value();
1331 if (origin_y_top->isChecked()) {
1332 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1334 posY = value_y->value();
1337 i->setPos(posX, posY);
1343 void TitleWidget::updateTextOriginX()
1345 if (origin_x_left->isChecked()) {
1346 origin_x_left->setText(i18n("\u2212X"));
1348 origin_x_left->setText(i18n("+X"));
1352 void TitleWidget::slotOriginXClicked()
1354 // Update the text displayed on the button.
1355 updateTextOriginX();
1357 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1358 if (l.size() >= 1) {
1359 updateCoordinates(l.at(0));
1361 // Remember x axis setting
1362 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1363 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1365 graphicsView->setFocus();
1368 void TitleWidget::updateTextOriginY()
1370 if (origin_y_top->isChecked()) {
1371 origin_y_top->setText(i18n("\u2212Y"));
1373 origin_y_top->setText(i18n("+Y"));
1377 void TitleWidget::slotOriginYClicked()
1379 // Update the text displayed on the button.
1380 updateTextOriginY();
1382 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1383 if (l.size() >= 1) {
1384 updateCoordinates(l.at(0));
1386 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1387 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1390 graphicsView->setFocus();
1393 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1395 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1396 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1397 origin_x_left->blockSignals(true);
1398 origin_y_top->blockSignals(true);
1400 if (xAxis == TitleDocument::AxisInverted) {
1401 origin_x_left->setChecked(true);
1403 origin_x_left->setChecked(false);
1405 updateTextOriginX();
1407 if (yAxis == TitleDocument::AxisInverted) {
1408 origin_y_top->setChecked(true);
1410 origin_y_top->setChecked(false);
1412 updateTextOriginY();
1414 origin_x_left->blockSignals(false);
1415 origin_y_top->blockSignals(false);
1418 void TitleWidget::slotChangeBackground()
1420 QColor color = backgroundColor->color();
1421 color.setAlpha(backgroundAlpha->value());
1422 m_frameBorder->setBrush(QBrush(color));
1426 * Something (yeah) has changed in our QGraphicsScene.
1428 void TitleWidget::slotChanged()
1430 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1431 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1432 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1437 * If the user has set origin_x_left (everything also for y),
1438 * we need to look whether a text element has been selected. If yes,
1439 * we need to ensure that the right border of the text field
1440 * remains fixed also when some text has been entered.
1442 * This is also known as right-justified, with the difference that
1443 * it is not valid for text but for its boundingRect. Text may still
1444 * be left-justified.
1446 void TitleWidget::textChanged(QGraphicsTextItem *i)
1451 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1453 if (!i->toPlainText().isEmpty()) {
1457 * Don't do anything if the string is empty. If the position
1458 * would be updated here, a newly created text field would
1459 * be set to the position of the last selected text field.
1465 void TitleWidget::slotInsertUnicode()
1467 m_unicodeDialog->exec();
1470 void TitleWidget::slotInsertUnicodeString(QString text)
1472 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1474 if (l.at(0)->type() == TEXTITEM) {
1475 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1476 t->textCursor().insertText(text);
1481 void TitleWidget::slotUpdateText()
1483 QFont font = font_family->currentFont();
1484 font.setPixelSize(font_size->value());
1485 font.setItalic(buttonItalic->isChecked());
1486 font.setUnderline(buttonUnder->isChecked());
1487 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1488 QColor color = fontColorButton->color();
1489 color.setAlpha(textAlpha->value());
1491 QColor outlineColor = textOutlineColor->color();
1492 outlineColor.setAlpha(textOutlineAlpha->value());
1493 double outlineWidth = textOutline->value() / 10.0;
1494 QGraphicsTextItem* item = NULL;
1495 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1496 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1497 item = static_cast <QGraphicsTextItem *>(l.at(0));
1500 //if (item->textCursor().selection ().isEmpty())
1501 QTextCursor cur(item->document());
1502 cur.select(QTextCursor::Document);
1503 QTextBlockFormat format = cur.blockFormat();
1504 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1505 item->setTextWidth(item->boundingRect().width());
1506 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1507 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1508 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1510 format.setAlignment(Qt::AlignLeft);
1511 item->setTextWidth(-1);
1514 item->setFont(font);
1515 QTextCharFormat cformat = cur.charFormat();
1517 item->setData(101, outlineWidth);
1518 item->setData(102, outlineColor);
1519 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1521 cformat.setForeground(QBrush(color));
1522 cur.setCharFormat(cformat);
1523 cur.setBlockFormat(format);
1524 item->setTextCursor(cur);
1525 cur.clearSelection();
1526 item->setTextCursor(cur);
1529 void TitleWidget::rectChanged()
1531 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1532 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1533 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1534 QColor f = rectFColor->color();
1535 f.setAlpha(rectFAlpha->value());
1537 penf.setWidth(rectLineWidth->value());
1538 penf.setJoinStyle(Qt::RoundJoin);
1540 QColor b = rectBColor->color();
1541 b.setAlpha(rectBAlpha->value());
1542 rec->setBrush(QBrush(b));
1546 void TitleWidget::itemScaled(int val)
1548 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1549 if (l.size() == 1) {
1550 Transform x = m_transformations.value(l.at(0));
1551 x.scalex = (double)val / 100.0;
1552 x.scaley = (double)val / 100.0;
1554 qtrans.scale(x.scalex, x.scaley);
1555 qtrans.rotate(x.rotatex, Qt::XAxis);
1556 qtrans.rotate(x.rotatey, Qt::YAxis);
1557 qtrans.rotate(x.rotatez, Qt::ZAxis);
1558 l[0]->setTransform(qtrans);
1559 l[0]->setData(ZOOMFACTOR, val);
1560 m_transformations[l.at(0)] = x;
1561 updateDimension(l.at(0));
1565 void TitleWidget::itemRotateX(qreal val)
1570 void TitleWidget::itemRotateY(qreal val)
1575 void TitleWidget::itemRotateZ(qreal val)
1580 void TitleWidget::itemRotate(qreal val, int axis)
1582 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1583 if (l.size() == 1) {
1584 Transform x = m_transformations[l.at(0)];
1597 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1600 qtrans.scale(x.scalex, x.scaley);
1601 qtrans.rotate(x.rotatex, Qt::XAxis);
1602 qtrans.rotate(x.rotatey, Qt::YAxis);
1603 qtrans.rotate(x.rotatez, Qt::ZAxis);
1604 l[0]->setTransform(qtrans);
1605 m_transformations[l.at(0)] = x;
1606 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1607 updateDimension(l.at(0));
1611 void TitleWidget::itemHCenter()
1613 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1614 if (l.size() == 1) {
1615 QGraphicsItem *item = l.at(0);
1616 QRectF br = item->sceneBoundingRect();
1617 int width = (int)br.width();
1618 int newPos = (int)((m_frameWidth - width) / 2);
1619 newPos += item->pos().x() - br.left(); // Check item transformation
1620 item->setPos(newPos, item->pos().y());
1621 updateCoordinates(item);
1625 void TitleWidget::itemVCenter()
1627 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1628 if (l.size() == 1) {
1629 QGraphicsItem *item = l.at(0);
1630 QRectF br = item->sceneBoundingRect();
1631 int height = (int)br.height();
1632 int newPos = (int)((m_frameHeight - height) / 2);
1633 newPos += item->pos().y() - br.top(); // Check item transformation
1634 item->setPos(item->pos().x(), newPos);
1635 updateCoordinates(item);
1639 void TitleWidget::itemTop()
1641 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1642 if (l.size() == 1) {
1643 QGraphicsItem *item = l.at(0);
1644 QRectF br = item->sceneBoundingRect();
1646 if (br.top() > 0) diff = -br.top();
1647 else diff = -br.bottom();
1648 item->moveBy(0, diff);
1649 updateCoordinates(item);
1653 void TitleWidget::itemBottom()
1655 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1656 if (l.size() == 1) {
1657 QGraphicsItem *item = l.at(0);
1658 QRectF br = item->sceneBoundingRect();
1660 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1661 else diff = m_frameHeight - br.bottom();
1662 item->moveBy(0, diff);
1663 updateCoordinates(item);
1667 void TitleWidget::itemLeft()
1669 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1670 if (l.size() == 1) {
1671 QGraphicsItem *item = l.at(0);
1672 QRectF br = item->sceneBoundingRect();
1674 if (br.left() > 0) diff = -br.left();
1675 else diff = -br.right();
1676 item->moveBy(diff, 0);
1677 updateCoordinates(item);
1681 void TitleWidget::itemRight()
1683 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1684 if (l.size() == 1) {
1685 QGraphicsItem *item = l.at(0);
1686 QRectF br = item->sceneBoundingRect();
1688 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1689 else diff = m_frameWidth - br.left();
1690 item->moveBy(diff, 0);
1691 updateCoordinates(item);
1695 void TitleWidget::setupViewports()
1697 //double aspect_ratio = 4.0 / 3.0;//read from project
1698 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1699 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1700 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1701 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1702 QPolygonF spoly(sp);
1703 QPolygonF epoly(ep);
1704 spoly.translate(startViewportX->value(), startViewportY->value());
1705 epoly.translate(endViewportX->value(), endViewportY->value());
1706 m_startViewport->setPolygon(spoly);
1707 m_endViewport->setPolygon(epoly);
1708 if (! insertingValues) {
1709 m_startViewport->setData(0, startViewportX->value());
1710 m_startViewport->setData(1, startViewportY->value());
1711 m_startViewport->setData(2, startViewportSize->value());
1713 m_endViewport->setData(0, endViewportX->value());
1714 m_endViewport->setData(1, endViewportY->value());
1715 m_endViewport->setData(2, endViewportSize->value());
1719 void TitleWidget::loadTitle(KUrl url)
1721 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1722 if (!url.isEmpty()) {
1723 QList<QGraphicsItem *> items = m_scene->items();
1724 for (int i = 0; i < items.size(); i++) {
1725 if (items.at(i)->zValue() > -1000) delete items.at(i);
1727 m_scene->clearTextSelection();
1731 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1732 QFile file(tmpfile);
1733 if (file.open(QIODevice::ReadOnly)) {
1734 doc.setContent(&file, false);
1737 KIO::NetAccess::removeTempFile(tmpfile);
1742 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1744 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1745 insertingValues = true;
1746 startViewportX->setValue(m_startViewport->data(0).toInt());
1747 startViewportY->setValue(m_startViewport->data(1).toInt());
1748 startViewportSize->setValue(m_startViewport->data(2).toInt());
1749 endViewportX->setValue(m_endViewport->data(0).toInt());
1750 endViewportY->setValue(m_endViewport->data(1).toInt());
1751 endViewportSize->setValue(m_endViewport->data(2).toInt());
1753 insertingValues = false;
1759 void TitleWidget::saveTitle(KUrl url)
1761 if (anim_start->isChecked()) slotAnimStart(false);
1762 if (anim_end->isChecked()) slotAnimEnd(false);
1763 if (url.isEmpty()) {
1764 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1765 fs->setOperationMode(KFileDialog::Saving);
1766 fs->setMode(KFile::File);
1767 #if KDE_IS_VERSION(4,2,0)
1768 fs->setConfirmOverwrite(true);
1770 fs->setKeepLocation(true);
1772 url = fs->selectedUrl();
1775 if (!url.isEmpty()) {
1776 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1777 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1781 QDomDocument TitleWidget::xml()
1783 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1784 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1788 int TitleWidget::duration() const
1790 return m_tc.getFrameCount(title_duration->text());
1793 void TitleWidget::setXml(QDomDocument doc)
1796 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1798 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1799 /*if (doc.documentElement().hasAttribute("out")) {
1800 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1801 title_duration->setText(m_tc.getTimecode(duration));
1803 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1805 QDomElement e = doc.documentElement();
1806 m_transformations.clear();
1807 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1808 const double PI = 4.0 * atan(1.0);
1809 for (int i = 0; i < items.count(); i++) {
1810 QTransform t = items.at(i)->transform();
1814 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1815 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1816 if (rotlist.count() >= 3) {
1817 x.rotatex = rotlist[0].toDouble();
1818 x.rotatey = rotlist[1].toDouble();
1819 x.rotatez = rotlist[2].toDouble();
1821 // Try to adjust zoom
1822 t.rotate(x.rotatex *(-1), Qt::XAxis);
1823 t.rotate(x.rotatey *(-1), Qt::YAxis);
1824 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1835 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1837 m_transformations[items.at(i)] = x;
1839 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1840 QColor background_color = m_titledocument.getBackgroundColor();
1841 backgroundAlpha->blockSignals(true);
1842 backgroundColor->blockSignals(true);
1843 backgroundAlpha->setValue(background_color.alpha());
1844 background_color.setAlpha(255);
1845 backgroundColor->setColor(background_color);
1846 backgroundAlpha->blockSignals(false);
1847 backgroundColor->blockSignals(false);
1849 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1850 startViewportY->setValue(m_startViewport->data(1).toInt());
1851 startViewportSize->setValue(m_startViewport->data(2).toInt());
1852 endViewportX->setValue(m_endViewport->data(0).toInt());
1853 endViewportY->setValue(m_endViewport->data(1).toInt());
1854 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1856 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1861 /** \brief Connected to the accepted signal - calls writeChoices */
1862 void TitleWidget::slotAccepted()
1864 if (anim_start->isChecked()) slotAnimStart(false);
1865 if (anim_end->isChecked()) slotAnimEnd(false);
1869 /** \brief Store the current choices of font, background and rect values */
1870 void TitleWidget::writeChoices()
1872 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1873 KSharedConfigPtr config = KGlobal::config();
1874 KConfigGroup titleConfig(config, "TitleWidget");
1875 // Write the entries
1876 titleConfig.writeEntry("font_family", font_family->currentFont());
1877 //titleConfig.writeEntry("font_size", font_size->value());
1878 titleConfig.writeEntry("font_pixel_size", font_size->value());
1879 titleConfig.writeEntry("font_color", fontColorButton->color());
1880 titleConfig.writeEntry("font_alpha", textAlpha->value());
1881 titleConfig.writeEntry("font_outline", textOutline->value());
1882 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1883 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1884 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1885 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1886 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1888 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1889 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1890 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1891 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1892 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1894 titleConfig.writeEntry("background_color", backgroundColor->color());
1895 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1897 //! \todo Not sure if I should sync - it is probably safe to do it
1902 /** \brief Read the last stored choices into the dialog */
1903 void TitleWidget::readChoices()
1905 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1906 KSharedConfigPtr config = KGlobal::config();
1907 KConfigGroup titleConfig(config, "TitleWidget");
1909 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1910 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1911 m_scene->slotUpdateFontSize(font_size->value());
1912 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1913 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1915 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
1916 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
1917 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
1920 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1921 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1922 setFontBoxWeight(weight);
1923 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1924 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1926 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1927 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1928 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1929 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1930 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1932 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
1933 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
1936 void TitleWidget::adjustFrameSize()
1938 m_frameWidth = m_titledocument.frameWidth();
1939 m_frameHeight = m_titledocument.frameHeight();
1940 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1941 displayBackgroundFrame();
1944 void TitleWidget::slotAnimStart(bool anim)
1946 if (anim && anim_end->isChecked()) {
1947 anim_end->setChecked(false);
1948 m_endViewport->setZValue(-1000);
1949 m_endViewport->setBrush(QBrush());
1952 QList<QGraphicsItem *> list = m_scene->items();
1953 for (int i = 0; i < list.count(); i++) {
1954 if (list.at(i)->zValue() > -1000) {
1955 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1956 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1959 align_box->setEnabled(anim);
1960 itemzoom->setEnabled(!anim);
1961 itemrotatex->setEnabled(!anim);
1962 itemrotatey->setEnabled(!anim);
1963 itemrotatez->setEnabled(!anim);
1964 frame_toolbar->setEnabled(!anim);
1965 toolbar_stack->setEnabled(!anim);
1967 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1968 m_startViewport->setZValue(1100);
1969 QColor col = m_startViewport->pen().color();
1971 m_startViewport->setBrush(col);
1972 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1973 m_startViewport->setSelected(true);
1976 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1978 m_startViewport->setZValue(-1000);
1979 m_startViewport->setBrush(QBrush());
1980 m_startViewport->setFlags(0);
1981 if (!anim_end->isChecked()) deleteAnimInfoText();
1986 void TitleWidget::slotAnimEnd(bool anim)
1988 if (anim && anim_start->isChecked()) {
1989 anim_start->setChecked(false);
1990 m_startViewport->setZValue(-1000);
1991 m_startViewport->setBrush(QBrush());
1994 QList<QGraphicsItem *> list = m_scene->items();
1995 for (int i = 0; i < list.count(); i++) {
1996 if (list.at(i)->zValue() > -1000) {
1997 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1998 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2001 align_box->setEnabled(anim);
2002 itemzoom->setEnabled(!anim);
2003 itemrotatex->setEnabled(!anim);
2004 itemrotatey->setEnabled(!anim);
2005 itemrotatez->setEnabled(!anim);
2006 frame_toolbar->setEnabled(!anim);
2007 toolbar_stack->setEnabled(!anim);
2009 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2010 m_endViewport->setZValue(1100);
2011 QColor col = m_endViewport->pen().color();
2013 m_endViewport->setBrush(col);
2014 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2015 m_endViewport->setSelected(true);
2018 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2020 m_endViewport->setZValue(-1000);
2021 m_endViewport->setBrush(QBrush());
2022 m_endViewport->setFlags(0);
2023 if (!anim_start->isChecked()) deleteAnimInfoText();
2027 void TitleWidget::addAnimInfoText()
2029 // add text to anim viewport
2030 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2031 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2032 QFont font = t->font();
2033 font.setPixelSize(m_startViewport->rect().width() / 10);
2034 QColor col = m_startViewport->pen().color();
2036 t->setDefaultTextColor(col);
2038 font.setPixelSize(m_endViewport->rect().width() / 10);
2039 col = m_endViewport->pen().color();
2041 t2->setDefaultTextColor(col);
2045 void TitleWidget::updateInfoText()
2047 // update info text font
2048 if (!m_startViewport->childItems().isEmpty()) {
2049 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2051 QFont font = item->font();
2052 font.setPixelSize(m_startViewport->rect().width() / 10);
2053 item->setFont(font);
2056 if (!m_endViewport->childItems().isEmpty()) {
2057 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2059 QFont font = item->font();
2060 font.setPixelSize(m_endViewport->rect().width() / 10);
2061 item->setFont(font);
2066 void TitleWidget::deleteAnimInfoText()
2068 // end animation editing, remove info text
2069 while (!m_startViewport->childItems().isEmpty()) {
2070 QGraphicsItem *item = m_startViewport->childItems().at(0);
2071 m_scene->removeItem(item);
2074 while (!m_endViewport->childItems().isEmpty()) {
2075 QGraphicsItem *item = m_endViewport->childItems().at(0);
2076 m_scene->removeItem(item);
2082 void TitleWidget::slotKeepAspect(bool keep)
2084 if (m_endViewport->zValue() == 1100) {
2085 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2086 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2088 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2089 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2093 void TitleWidget::slotResize50()
2095 if (m_endViewport->zValue() == 1100) {
2096 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2097 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2100 void TitleWidget::slotResize100()
2102 if (m_endViewport->zValue() == 1100) {
2103 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2104 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2107 void TitleWidget::slotResize200()
2109 if (m_endViewport->zValue() == 1100) {
2110 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2111 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2114 void TitleWidget::slotAddEffect(int ix)
2116 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2117 int effect = effect_list->itemData(ix).toInt();
2118 if (effect == NOEFFECT) {
2119 if (l.size() == 1) l[0]->setData(100, QVariant());
2120 effect_stack->setHidden(true);
2123 effect_stack->setCurrentIndex(effect - 1);
2124 effect_stack->setHidden(false);
2125 if (effect == TYPEWRITEREFFECT) {
2126 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
2127 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2128 l[0]->setData(100, effdata);
2131 #if QT_VERSION < 0x040600
2134 if (effect == BLUREFFECT) {
2136 if (l.size() == 1) {
2137 QGraphicsEffect *eff = new QGraphicsBlurEffect();
2138 l[0]->setGraphicsEffect(eff);
2140 } else if (effect == SHADOWEFFECT) {
2141 if (l.size() == 1) {
2142 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
2143 l[0]->setGraphicsEffect(eff);
2151 void TitleWidget::slotFontText(const QString& s)
2154 if (f.exactMatch()) {
2155 // Font really exists (could also just be a «d» if the user
2156 // starts typing «dejavu» for example).
2157 font_family->setCurrentFont(f);
2159 // Note: Typing dejavu serif does not recognize the font (takes sans)
2160 // in older Qt versions.
2163 void TitleWidget::slotEditTypewriter(int /*ix*/)
2165 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2166 if (l.size() == 1) {
2167 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2168 l[0]->setData(100, effdata);
2172 void TitleWidget::slotEditBlur(int ix)
2174 #if QT_VERSION < 0x040600
2177 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2178 if (l.size() == 1) {
2179 QGraphicsEffect *eff = l[0]->graphicsEffect();
2180 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2181 if (blur) blur->setBlurRadius(ix);
2186 void TitleWidget::slotEditShadow()
2188 #if QT_VERSION < 0x040600
2191 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2192 if (l.size() == 1) {
2193 QGraphicsEffect *eff = l[0]->graphicsEffect();
2194 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2196 shadow->setBlurRadius(shadow_radius->value());
2197 shadow->setOffset(shadow_x->value(), shadow_y->value());
2203 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2205 qreal bound = maxBound ? -99 : 99;
2206 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2208 QList<QGraphicsItem*> lItems;
2209 // Get items (all or intersecting only)
2210 if (intersectingOnly) {
2211 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2213 lItems = graphicsView->scene()->items();
2215 if (lItems.size() > 0) {
2216 int n = lItems.size();
2219 for (int i = 0; i < n; i++) {
2220 z = lItems[i]->zValue();
2221 if (z > bound && !lItems[i]->isSelected()) {
2226 // Get minimum z index.
2227 for (int i = 0; i < n; i++) {
2228 z = lItems[i]->zValue();
2229 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2230 // There are items at the very bottom (background e.g.) with z-index < -1000.
2240 void TitleWidget::slotZIndexUp()
2242 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2243 if (l.size() >= 1) {
2244 qreal currentZ = l[0]->zValue();
2245 qreal max = zIndexBounds(true, true);
2246 if (currentZ <= max) {
2247 l[0]->setZValue(currentZ + 1);
2248 updateDimension(l[0]);
2253 void TitleWidget::slotZIndexTop()
2255 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2256 if (l.size() >= 1) {
2257 qreal currentZ = l[0]->zValue();
2258 qreal max = zIndexBounds(true, false);
2259 if (currentZ <= max) {
2260 l[0]->setZValue(max + 1);
2261 updateDimension(l[0]);
2266 void TitleWidget::slotZIndexDown()
2268 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2269 if (l.size() >= 1) {
2270 qreal currentZ = l[0]->zValue();
2271 qreal min = zIndexBounds(false, true);
2272 if (currentZ >= min) {
2273 l[0]->setZValue(currentZ - 1);
2274 updateDimension(l[0]);
2279 void TitleWidget::slotZIndexBottom()
2281 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2282 if (l.size() >= 1) {
2283 qreal currentZ = l[0]->zValue();
2284 qreal min = zIndexBounds(false, false);
2285 if (currentZ >= min) {
2286 l[0]->setZValue(min - 1);
2287 updateDimension(l[0]);