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 #if QT_VERSION >= 0x040600
43 #include <QGraphicsEffect>
44 #include <QGraphicsBlurEffect>
45 #include <QGraphicsDropShadowEffect>
48 int settingUp = false;
50 const int IMAGEITEM = 7;
51 const int RECTITEM = 3;
52 const int TEXTITEM = 8;
54 const int NOEFFECT = 0;
55 const int BLUREFFECT = 1;
56 const int SHADOWEFFECT = 2;
57 const int TYPEWRITEREFFECT = 3;
59 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
62 m_startViewport(NULL),
66 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
67 m_projectTitlePath(projectTitlePath),
71 setFont(KGlobalSettings::toolBarFont());
72 frame_properties->setEnabled(false);
73 frame_properties->setFixedHeight(frame_toolbar->height());
75 // Set combo sliders values
76 textAlpha->setMinimum(0);
77 textAlpha->setMaximum(255);
78 textAlpha->setDecimals(0);
79 textAlpha->setValue(255);
80 textAlpha->setToolTip(i18n("Font color opacity"));
82 textOutlineAlpha->setMinimum(0);
83 textOutlineAlpha->setMaximum(255);
84 textOutlineAlpha->setDecimals(0);
85 textOutlineAlpha->setValue(255);
86 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
88 textOutline->setMinimum(0);
89 textOutline->setMaximum(200);
90 textOutline->setDecimals(0);
91 textOutline->setValue(0);
92 textOutline->setToolTip(i18n("Outline width"));
94 backgroundAlpha->setMinimum(0);
95 backgroundAlpha->setMaximum(255);
96 backgroundAlpha->setDecimals(0);
97 backgroundAlpha->setValue(0);
98 backgroundAlpha->setToolTip(i18n("Background color opacity"));
100 itemrotatex->setMinimum(-360);
101 itemrotatex->setMaximum(360);
102 itemrotatex->setDecimals(0);
103 itemrotatex->setValue(0);
104 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
106 itemrotatey->setMinimum(-360);
107 itemrotatey->setMaximum(360);
108 itemrotatey->setDecimals(0);
109 itemrotatey->setValue(0);
110 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
112 itemrotatez->setMinimum(-360);
113 itemrotatez->setMaximum(360);
114 itemrotatez->setDecimals(0);
115 itemrotatez->setValue(0);
116 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
118 rectBAlpha->setMinimum(0);
119 rectBAlpha->setMaximum(255);
120 rectBAlpha->setDecimals(0);
121 rectBAlpha->setValue(255);
122 rectBAlpha->setToolTip(i18n("Color opacity"));
124 rectFAlpha->setMinimum(0);
125 rectFAlpha->setMaximum(255);
126 rectFAlpha->setDecimals(0);
127 rectFAlpha->setValue(255);
128 rectFAlpha->setToolTip(i18n("Border opacity"));
130 rectLineWidth->setMinimum(0);
131 rectLineWidth->setMaximum(100);
132 rectLineWidth->setDecimals(0);
133 rectLineWidth->setValue(0);
134 rectLineWidth->setToolTip(i18n("Border width"));
136 itemzoom->setSuffix(i18n("%"));
137 m_frameWidth = render->renderWidth();
138 m_frameHeight = render->renderHeight();
139 showToolbars(TITLE_SELECT);
141 //TODO: get default title duration instead of hardcoded one
142 title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0)));
144 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
145 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
147 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
148 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
149 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
150 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
151 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
152 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
153 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
154 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
156 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
158 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
159 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
160 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
161 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
162 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
164 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
165 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
166 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
167 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
168 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
169 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
172 effect_list->addItem(i18n("None"), NOEFFECT);
173 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
174 effect_list->addItem(i18n("Blur"), BLUREFFECT);
177 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
178 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
179 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
180 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
181 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
182 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
183 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
184 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
185 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
186 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
187 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
188 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
189 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
190 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
191 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
192 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
193 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
194 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
195 effect_stack->setHidden(true);
196 effect_frame->setEnabled(false);
198 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
199 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
201 m_signalMapper = new QSignalMapper(this);
202 m_signalMapper->setMapping(value_w, ValueWidth);
203 m_signalMapper->setMapping(value_h, ValueHeight);
204 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
205 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
206 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
208 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
209 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
210 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
211 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
212 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
213 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
214 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
215 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
216 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
217 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
218 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
219 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
220 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
222 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
225 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
227 font_weight_box->blockSignals(true);
228 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
229 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
230 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
231 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
232 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
233 font_weight_box->setToolTip(i18n("Font weight"));
234 font_weight_box->setCurrentIndex(1);
235 font_weight_box->blockSignals(false);
237 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
238 buttonRealSize->setIcon(KIcon("zoom-original"));
239 buttonItalic->setIcon(KIcon("format-text-italic"));
240 buttonUnder->setIcon(KIcon("format-text-underline"));
241 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
242 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
243 buttonAlignRight->setIcon(KIcon("format-justify-right"));
244 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
246 buttonAlignNone->setToolTip(i18n("No alignment"));
247 buttonAlignRight->setToolTip(i18n("Align right"));
248 buttonAlignLeft->setToolTip(i18n("Align left"));
249 buttonAlignCenter->setToolTip(i18n("Align center"));
251 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
252 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
253 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
254 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
255 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
257 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
258 m_zUp->setShortcut(Qt::Key_PageUp);
259 m_zUp->setToolTip(i18n("Raise object"));
260 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
261 zUp->setDefaultAction(m_zUp);
263 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
264 m_zDown->setShortcut(Qt::Key_PageDown);
265 m_zDown->setToolTip(i18n("Lower object"));
266 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
267 zDown->setDefaultAction(m_zDown);
269 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
270 // TODO mbt 1414: Shortcut should change z index only if
271 // cursor is NOT in a text field ...
272 //m_zTop->setShortcut(Qt::Key_Home);
273 m_zTop->setToolTip(i18n("Raise object to top"));
274 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
275 zTop->setDefaultAction(m_zTop);
277 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
279 //m_zBottom->setShortcut(Qt::Key_End);
280 m_zBottom->setToolTip(i18n("Lower object to bottom"));
281 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
282 zBottom->setDefaultAction(m_zBottom);
284 zDown->setIcon(KIcon("kdenlive-zindex-down"));
285 zTop->setIcon(KIcon("kdenlive-zindex-top"));
286 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
287 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
288 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
289 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
291 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
292 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
293 rectBColor->setToolTip(i18n("Select fill color"));
294 rectFColor->setToolTip(i18n("Select border color"));
295 rectBAlpha->setToolTip(i18n("Fill opacity"));
296 rectFAlpha->setToolTip(i18n("Border opacity"));
297 zoom_slider->setToolTip(i18n("Zoom"));
298 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
299 buttonFitZoom->setToolTip(i18n("Fit zoom"));
300 backgroundColor->setToolTip(i18n("Select background color"));
301 backgroundAlpha->setToolTip(i18n("Background opacity"));
303 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
304 itemhcenter->setToolTip(i18n("Align item horizontally"));
305 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
306 itemvcenter->setToolTip(i18n("Align item vertically"));
307 itemtop->setIcon(KIcon("kdenlive-align-top"));
308 itemtop->setToolTip(i18n("Align item to top"));
309 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
310 itembottom->setToolTip(i18n("Align item to bottom"));
311 itemright->setIcon(KIcon("kdenlive-align-right"));
312 itemright->setToolTip(i18n("Align item to right"));
313 itemleft->setIcon(KIcon("kdenlive-align-left"));
314 itemleft->setToolTip(i18n("Align item to left"));
317 QHBoxLayout *layout = new QHBoxLayout;
318 frame_toolbar->setLayout(layout);
319 layout->setContentsMargins(0, 0, 0, 0);
320 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
321 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
322 m_toolbar->setIconSize(QSize(s, s));
324 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
325 m_buttonCursor->setCheckable(true);
326 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
327 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
328 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
330 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
331 m_buttonText->setCheckable(true);
332 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
333 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
334 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
336 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
337 m_buttonRect->setCheckable(true);
338 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
339 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
340 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
342 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
343 m_buttonImage->setCheckable(false);
344 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
345 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
346 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
348 m_toolbar->addSeparator();
350 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
351 m_buttonLoad->setCheckable(false);
352 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
353 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
355 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
356 m_buttonSave->setCheckable(false);
357 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
358 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
360 layout->addWidget(m_toolbar);
362 // initialize graphic scene
363 m_scene = new GraphicsSceneRectMove(this);
364 graphicsView->setScene(m_scene);
365 graphicsView->setMouseTracking(true);
366 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
367 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
368 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
370 // a gradient background
371 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
372 gradient->setSpread(QGradient::ReflectSpread);
373 scene->setBackgroundBrush(*gradient);*/
375 m_frameImage = new QGraphicsPixmapItem();
377 qtrans.scale(2.0, 2.0);
378 m_frameImage->setTransform(qtrans);
379 m_frameImage->setZValue(-1200);
380 m_frameImage->setFlags(0);
381 displayBackgroundFrame();
382 graphicsView->scene()->addItem(m_frameImage);
384 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
385 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
386 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
387 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
388 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
389 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
390 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
391 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
393 QPen framepen(Qt::DotLine);
394 framepen.setColor(Qt::red);
396 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
397 m_frameBorder->setPen(framepen);
398 m_frameBorder->setZValue(-1100);
399 m_frameBorder->setBrush(Qt::transparent);
400 m_frameBorder->setFlags(0);
401 graphicsView->scene()->addItem(m_frameBorder);
403 // mbd: load saved settings
406 graphicsView->show();
407 //graphicsView->setRenderHint(QPainter::Antialiasing);
408 graphicsView->setInteractive(true);
409 //graphicsView->resize(400, 300);
410 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
411 //toolBox->setItemEnabled(2, false);
412 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
413 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
414 m_startViewport->setData(0, m_frameWidth);
415 m_startViewport->setData(1, m_frameHeight);
416 m_endViewport->setData(0, m_frameWidth);
417 m_endViewport->setData(1, m_frameHeight);
419 if (!url.isEmpty()) loadTitle(url);
422 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
425 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
426 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
428 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
431 TitleWidget::~TitleWidget()
435 delete m_buttonImage;
436 delete m_buttonCursor;
439 delete m_unicodeAction;
445 delete m_unicodeDialog;
446 delete m_frameBorder;
448 delete m_startViewport;
449 delete m_endViewport;
451 delete m_signalMapper;
455 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
458 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
459 KStandardDirs::makeDir(titlePath);
460 titlePath.append((isClone == false) ? "title" : "clone");
463 while (path.isEmpty() || QFile::exists(path)) {
465 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
467 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
473 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
476 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
477 KStandardDirs::makeDir(titlePath);
478 return titlePath + titleName + ".png";
482 QStringList TitleWidget::extractImageList(QString xml)
485 if (xml.isEmpty()) return result;
488 QDomNodeList images = doc.elementsByTagName("content");
489 for (int i = 0; i < images.count(); i++) {
490 if (images.at(i).toElement().hasAttribute("url"))
491 result.append(images.at(i).toElement().attribute("url"));
497 QStringList TitleWidget::extractFontList(QString xml)
500 if (xml.isEmpty()) return result;
503 QDomNodeList images = doc.elementsByTagName("content");
504 for (int i = 0; i < images.count(); i++) {
505 if (images.at(i).toElement().hasAttribute("font"))
506 result.append(images.at(i).toElement().attribute("font"));
513 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
518 void TitleWidget::slotTextTool()
520 m_scene->setTool(TITLE_TEXT);
521 showToolbars(TITLE_TEXT);
522 checkButton(TITLE_TEXT);
525 void TitleWidget::slotRectTool()
527 m_scene->setTool(TITLE_RECTANGLE);
528 showToolbars(TITLE_RECTANGLE);
529 checkButton(TITLE_RECTANGLE);
532 void TitleWidget::slotSelectTool()
534 m_scene->setTool(TITLE_SELECT);
536 // Find out which toolbars need to be shown, depending on selected item
537 TITLETOOL t = TITLE_SELECT;
538 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
540 switch (l.at(0)->type()) {
554 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
555 //graphicsView->centerOn(l.at(0));
561 updateCoordinates(l.at(0));
562 updateDimension(l.at(0));
563 updateRotZoom(l.at(0));
566 checkButton(TITLE_SELECT);
569 void TitleWidget::slotImageTool()
571 // TODO: find a way to get a list of all supported image types...
572 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";
573 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
574 if (!url.isEmpty()) {
575 if (url.path().endsWith(".svg")) {
576 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
577 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
578 svg->setZValue(m_count++);
579 svg->setData(Qt::UserRole, url.path());
580 graphicsView->scene()->addItem(svg);
582 QPixmap pix(url.path());
583 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
584 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
585 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
586 image->setData(Qt::UserRole, url.path());
587 image->setZValue(m_count++);
588 graphicsView->scene()->addItem(image);
591 m_scene->setTool(TITLE_SELECT);
592 showToolbars(TITLE_SELECT);
593 checkButton(TITLE_SELECT);
596 void TitleWidget::showToolbars(TITLETOOL toolType)
598 toolbar_stack->setCurrentIndex((int) toolType);
601 void TitleWidget::enableToolbars(TITLETOOL toolType)
603 // TITLETOOL is defined in graphicsscenerectmove.h
605 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
606 value_w->setEnabled(enable);
607 value_h->setEnabled(enable);
610 void TitleWidget::checkButton(TITLETOOL toolType)
612 bool bSelect = false;
624 case TITLE_RECTANGLE:
634 m_buttonCursor->setChecked(bSelect);
635 m_buttonText->setChecked(bText);
636 m_buttonRect->setChecked(bRect);
637 m_buttonImage->setChecked(bImage);
640 void TitleWidget::displayBackgroundFrame()
642 if (!displayBg->isChecked()) {
643 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
644 QPixmap pattern(20, 20);
646 QColor bgcolor(210, 210, 210);
649 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
650 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
655 p.fillRect(bg.rect(), br);
657 m_frameImage->setPixmap(bg);
659 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
663 void TitleWidget::initAnimation()
665 align_box->setEnabled(false);
666 QPen startpen(Qt::DotLine);
667 QPen endpen(Qt::DashDotLine);
668 startpen.setColor(QColor(100, 200, 100, 140));
669 endpen.setColor(QColor(200, 100, 100, 140));
671 m_startViewport->setPen(startpen);
672 m_endViewport->setPen(endpen);
674 m_startViewport->setZValue(-1000);
675 m_endViewport->setZValue(-1000);
677 m_startViewport->setFlags(0);
678 m_endViewport->setFlags(0);
680 graphicsView->scene()->addItem(m_startViewport);
681 graphicsView->scene()->addItem(m_endViewport);
683 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
684 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
685 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
686 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
689 void TitleWidget::slotUpdateZoom(int pos)
691 m_scene->setZoom((double) pos / 100);
692 zoom_label->setText(QString::number(pos) + '%');
695 void TitleWidget::slotZoom(bool up)
697 int pos = zoom_slider->value();
700 zoom_slider->setValue(pos);
703 void TitleWidget::slotAdjustZoom()
705 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
706 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
707 if (scalex > scaley) scalex = scaley;
708 int zoompos = (int)(scalex * 7 + 0.5);*/
709 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
710 int zoompos = graphicsView->matrix().m11() * 100;
711 zoom_slider->setValue(zoompos);
712 graphicsView->centerOn(m_frameBorder);
715 void TitleWidget::slotZoomOneToOne()
717 zoom_slider->setValue(100);
718 graphicsView->centerOn(m_frameBorder);
721 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
723 updateAxisButtons(rect); // back to default
725 QColor f = rectFColor->color();
726 f.setAlpha(rectFAlpha->value());
728 penf.setWidth(rectLineWidth->value());
729 penf.setJoinStyle(Qt::RoundJoin);
731 QColor b = rectBColor->color();
732 b.setAlpha(rectBAlpha->value());
733 rect->setBrush(QBrush(b));
734 rect->setZValue(m_count++);
735 rect->setData(ZOOMFACTOR, 100);
736 //setCurrentItem(rect);
737 //graphicsView->setFocus();
740 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
742 updateAxisButtons(tt); // back to default
744 QFont font = font_family->currentFont();
745 font.setPixelSize(font_size->value());
747 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
748 font.setItalic(buttonItalic->isChecked());
749 font.setUnderline(buttonUnder->isChecked());
752 QColor color = fontColorButton->color();
753 color.setAlpha(textAlpha->value());
754 tt->setDefaultTextColor(color);
756 QTextCursor cur(tt->document());
757 cur.select(QTextCursor::Document);
758 QTextBlockFormat format = cur.blockFormat();
759 QTextCharFormat cformat = cur.charFormat();
760 QColor outlineColor = textOutlineColor->color();
761 outlineColor.setAlpha(textOutlineAlpha->value());
762 double outlineWidth = textOutline->value() / 10.0;
764 tt->setData(101, outlineWidth);
765 tt->setData(102, outlineColor);
766 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
768 cformat.setForeground(QBrush(color));
769 cur.setCharFormat(cformat);
770 cur.setBlockFormat(format);
771 tt->setTextCursor(cur);
772 tt->setZValue(m_count++);
776 void TitleWidget::setFontBoxWeight(int weight)
778 int index = font_weight_box->findData(weight);
780 index = font_weight_box->findData(QFont::Normal);
782 font_weight_box->setCurrentIndex(index);
785 void TitleWidget::setCurrentItem(QGraphicsItem *item)
787 m_scene->setSelectedItem(item);
790 void TitleWidget::zIndexChanged(int v)
792 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
798 void TitleWidget::selectionChanged()
800 if (m_scene->tool() != TITLE_SELECT) return;
801 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
802 //toolBox->setItemEnabled(2, false);
803 //toolBox->setItemEnabled(3, false);
804 value_x->blockSignals(true);
805 value_y->blockSignals(true);
806 value_w->blockSignals(true);
807 value_h->blockSignals(true);
808 itemzoom->blockSignals(true);
809 itemrotatex->blockSignals(true);
810 itemrotatey->blockSignals(true);
811 itemrotatez->blockSignals(true);
813 effect_stack->setHidden(true);
814 effect_frame->setEnabled(false);
815 effect_list->setCurrentIndex(0);
816 bool blockX = !origin_x_left->signalsBlocked();
817 bool blockY = !origin_y_top->signalsBlocked();
818 if (blockX) origin_x_left->blockSignals(true);
819 if (blockY) origin_y_top->blockSignals(true);
820 origin_x_left->setChecked(false);
821 origin_y_top->setChecked(false);
824 enableToolbars(TITLE_SELECT);
825 if (blockX) origin_x_left->blockSignals(false);
826 if (blockY) origin_y_top->blockSignals(false);
827 itemzoom->setEnabled(false);
828 itemrotatex->setEnabled(false);
829 itemrotatey->setEnabled(false);
830 itemrotatez->setEnabled(false);
831 frame_properties->setEnabled(false);
832 } else if (l.size() == 1) {
833 effect_frame->setEnabled(true);
834 frame_properties->setEnabled(true);
835 if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
836 itemzoom->setEnabled(true);
837 itemrotatex->setEnabled(true);
838 itemrotatey->setEnabled(true);
839 itemrotatez->setEnabled(true);
841 itemzoom->setEnabled(false);
842 itemrotatex->setEnabled(false);
843 itemrotatey->setEnabled(false);
844 itemrotatez->setEnabled(false);
847 if (l.at(0)->type() == TEXTITEM) {
848 showToolbars(TITLE_TEXT);
849 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
850 if (!i->data(100).isNull()) {
851 // Item has an effect
852 QStringList effdata = i->data(100).toStringList();
853 QString effectName = effdata.takeFirst();
854 if (effectName == "typewriter") {
855 QStringList params = effdata.at(0).split(';');
856 typewriter_delay->setValue(params.at(0).toInt());
857 typewriter_start->setValue(params.at(1).toInt());
858 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
859 effect_stack->setHidden(false);
862 #if QT_VERSION >= 0x040600
863 if (i->graphicsEffect()) {
864 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
866 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
867 int rad = (int) blur->blurRadius();
868 blur_radius->setValue(rad);
869 effect_stack->setHidden(false);
871 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
873 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
874 shadow_radius->setValue(shad->blurRadius());
875 shadow_x->setValue(shad->xOffset());
876 shadow_y->setValue(shad->yOffset());
877 effect_stack->setHidden(false);
881 effect_list->blockSignals(true);
882 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
883 effect_list->blockSignals(false);
884 effect_stack->setHidden(true);
887 effect_list->blockSignals(true);
888 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
889 effect_list->blockSignals(false);
890 effect_stack->setHidden(true);
893 //if (l[0]->hasFocus())
894 //toolBox->setCurrentIndex(0);
895 //toolBox->setItemEnabled(2, true);
896 font_size->blockSignals(true);
897 font_family->blockSignals(true);
898 font_weight_box->blockSignals(true);
899 buttonItalic->blockSignals(true);
900 buttonUnder->blockSignals(true);
901 fontColorButton->blockSignals(true);
902 textAlpha->blockSignals(true);
903 buttonAlignLeft->blockSignals(true);
904 buttonAlignRight->blockSignals(true);
905 buttonAlignNone->blockSignals(true);
906 buttonAlignCenter->blockSignals(true);
908 QFont font = i->font();
909 font_family->setCurrentFont(font);
910 font_size->setValue(font.pixelSize());
911 m_scene->slotUpdateFontSize(font.pixelSize());
912 buttonItalic->setChecked(font.italic());
913 buttonUnder->setChecked(font.underline());
914 setFontBoxWeight(font.weight());
916 QTextCursor cursor(i->document());
917 cursor.select(QTextCursor::Document);
918 QColor color = cursor.charFormat().foreground().color();
919 textAlpha->setValue(color.alpha());
921 fontColorButton->setColor(color);
923 if (!i->data(101).isNull()) {
924 textOutline->blockSignals(true);
925 textOutline->setValue(i->data(101).toDouble()*10);
926 textOutline->blockSignals(false);
928 if (!i->data(102).isNull()) {
929 textOutlineColor->blockSignals(true);
930 textOutlineAlpha->blockSignals(true);
931 color = QColor(i->data(102).toString());
932 textOutlineAlpha->setValue(color.alpha());
934 textOutlineColor->setColor(color);
935 textOutlineColor->blockSignals(false);
936 textOutlineAlpha->blockSignals(false);
938 QTextCursor cur = i->textCursor();
939 QTextBlockFormat format = cur.blockFormat();
940 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
941 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
942 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
943 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
945 font_size->blockSignals(false);
946 font_family->blockSignals(false);
947 font_weight_box->blockSignals(false);
948 buttonItalic->blockSignals(false);
949 buttonUnder->blockSignals(false);
950 fontColorButton->blockSignals(false);
951 textAlpha->blockSignals(false);
952 buttonAlignLeft->blockSignals(false);
953 buttonAlignRight->blockSignals(false);
954 buttonAlignNone->blockSignals(false);
955 buttonAlignCenter->blockSignals(false);
957 updateAxisButtons(i);
958 updateCoordinates(i);
960 enableToolbars(TITLE_TEXT);
962 } else if ((l.at(0))->type() == RECTITEM) {
963 showToolbars(TITLE_RECTANGLE);
965 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
966 if (rec == m_startViewport || rec == m_endViewport) {
967 /*toolBox->setCurrentIndex(3);
968 toolBox->widget(0)->setEnabled(false);
969 toolBox->widget(1)->setEnabled(false);*/
970 enableToolbars(TITLE_SELECT);
972 /*toolBox->widget(0)->setEnabled(true);
973 toolBox->widget(1)->setEnabled(true);
974 toolBox->setCurrentIndex(0);*/
975 //toolBox->setItemEnabled(3, true);
976 rectFAlpha->setValue(rec->pen().color().alpha());
977 rectBAlpha->setValue(rec->brush().color().alpha());
978 //kDebug() << rec->brush().color().alpha();
979 QColor fcol = rec->pen().color();
980 QColor bcol = rec->brush().color();
981 //fcol.setAlpha(255);
982 //bcol.setAlpha(255);
983 rectFColor->setColor(fcol);
984 rectBColor->setColor(bcol);
986 rectLineWidth->setValue(rec->pen().width());
987 enableToolbars(TITLE_RECTANGLE);
990 updateAxisButtons(l.at(0));
991 updateCoordinates(rec);
992 updateDimension(rec);
994 } else if (l.at(0)->type() == IMAGEITEM) {
995 showToolbars(TITLE_IMAGE);
997 updateCoordinates(l.at(0));
998 updateDimension(l.at(0));
1000 enableToolbars(TITLE_IMAGE);
1003 //toolBox->setCurrentIndex(0);
1004 showToolbars(TITLE_SELECT);
1005 enableToolbars(TITLE_SELECT);
1006 frame_properties->setEnabled(false);
1008 zValue->setValue((int)l.at(0)->zValue());
1009 if (!l.at(0)->data(ZOOMFACTOR).isNull()) itemzoom->setValue(l.at(0)->data(ZOOMFACTOR).toInt());
1010 else itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
1011 itemrotatex->setValue((int)(m_transformations.value(l.at(0)).rotatex));
1012 itemrotatey->setValue((int)(m_transformations.value(l.at(0)).rotatey));
1013 itemrotatez->setValue((int)(m_transformations.value(l.at(0)).rotatez));
1014 value_x->blockSignals(false);
1015 value_y->blockSignals(false);
1016 value_w->blockSignals(false);
1017 value_h->blockSignals(false);
1018 itemzoom->blockSignals(false);
1019 itemrotatex->blockSignals(false);
1020 itemrotatey->blockSignals(false);
1021 itemrotatez->blockSignals(false);
1025 void TitleWidget::slotValueChanged(int type)
1027 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1028 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
1033 val = value_w->value();
1036 val = value_h->value();
1040 QGraphicsItem *i = l.at(0);
1041 Transform t = m_transformations.value(i);
1043 // Ratio width:height
1044 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1045 // TODO: proper calculation for rotation around 3 axes
1046 double alpha = (double) t.rotatez / 180.0 * M_PI;
1049 double length = val;
1056 // Add 0.5 because otherwise incrementing by 1 might have no effect
1057 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1058 scale = length / i->boundingRect().width();
1061 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1062 scale = length / i->boundingRect().height();
1069 qtrans.scale(scale, scale);
1070 qtrans.rotate(t.rotatex, Qt::XAxis);
1071 qtrans.rotate(t.rotatey, Qt::YAxis);
1072 qtrans.rotate(t.rotatez, Qt::ZAxis);
1073 i->setTransform(qtrans);
1074 m_transformations[i] = t;
1081 /** \brief Updates position/size of the selected item when a value
1082 * of an item (coordinates, size) has changed */
1083 void TitleWidget::slotAdjustSelectedItem()
1085 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1086 if (l.size() >= 1) {
1087 if (l.at(0)->type() == RECTITEM) {
1089 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1090 updatePosition(rec);
1091 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1092 } else if (l.at(0)->type() == TEXTITEM) {
1094 updatePosition(l.at(0));
1095 } else if (l.at(0)->type() == IMAGEITEM) {
1097 updatePosition(l.at(0));
1102 /** \brief Updates width/height int the text fields, regarding transformation matrix */
1103 void TitleWidget::updateDimension(QGraphicsItem *i)
1105 value_w->blockSignals(true);
1106 value_h->blockSignals(true);
1107 zValue->blockSignals(true);
1109 zValue->setValue((int) i->zValue());
1110 if (i->type() == IMAGEITEM) {
1111 // Get multipliers for rotation/scaling
1113 /*Transform t = m_transformations.value(i);
1114 QRectF r = i->boundingRect();
1115 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1116 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1117 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1118 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1120 value_w->setValue(i->sceneBoundingRect().width());
1121 value_h->setValue(i->sceneBoundingRect().height());
1122 } else if (i->type() == RECTITEM) {
1123 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1124 value_w->setValue((int) r->rect().width());
1125 value_h->setValue((int) r->rect().height());
1126 } else if (i->type() == TEXTITEM) {
1127 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1128 value_w->setValue((int) t->boundingRect().width());
1129 value_h->setValue((int) t->boundingRect().height());
1132 zValue->blockSignals(false);
1133 value_w->blockSignals(false);
1134 value_h->blockSignals(false);
1137 /** \brief Updates the coordinates in the text fields from the item */
1138 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1140 // Block signals emitted by this method
1141 value_x->blockSignals(true);
1142 value_y->blockSignals(true);
1144 if (i->type() == TEXTITEM) {
1146 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1148 // Set the correct x coordinate value
1149 if (origin_x_left->isChecked()) {
1150 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1151 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1153 // Origin is at 0 (default)
1154 value_x->setValue((int) rec->pos().x());
1158 if (origin_y_top->isChecked()) {
1159 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1161 value_y->setValue((int) rec->pos().y());
1164 } else if (i->type() == RECTITEM) {
1166 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1168 if (origin_x_left->isChecked()) {
1169 // Origin (0 point) is at m_frameWidth
1170 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1172 // Origin is at 0 (default)
1173 value_x->setValue((int) rec->pos().x());
1176 if (origin_y_top->isChecked()) {
1177 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1179 value_y->setValue((int) rec->pos().y());
1182 } else if (i->type() == IMAGEITEM) {
1184 if (origin_x_left->isChecked()) {
1185 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1187 value_x->setValue((int) i->pos().x());
1190 if (origin_y_top->isChecked()) {
1191 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1193 value_y->setValue((int) i->pos().y());
1198 // Stop blocking signals now
1199 value_x->blockSignals(false);
1200 value_y->blockSignals(false);
1203 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1205 itemzoom->blockSignals(true);
1206 itemrotatex->blockSignals(true);
1207 itemrotatey->blockSignals(true);
1208 itemrotatez->blockSignals(true);
1210 Transform t = m_transformations.value(i);
1212 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1213 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1215 itemrotatex->setValue((int)(t.rotatex));
1216 itemrotatey->setValue((int)(t.rotatey));
1217 itemrotatez->setValue((int)(t.rotatez));
1219 itemzoom->blockSignals(false);
1220 itemrotatex->blockSignals(false);
1221 itemrotatey->blockSignals(false);
1222 itemrotatez->blockSignals(false);
1225 /** \brief Updates the position of an item by reading coordinates from the text fields */
1226 void TitleWidget::updatePosition(QGraphicsItem *i)
1228 if (i->type() == TEXTITEM) {
1229 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1232 if (origin_x_left->isChecked()) {
1233 /* Origin of the x axis is at m_frameWidth,
1234 * and distance from right border of the item to the right
1235 * border of the frame is taken.
1236 * See comment to slotOriginXClicked().
1238 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1240 posX = value_x->value();
1244 if (origin_y_top->isChecked()) {
1245 /* Same for y axis */
1246 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1248 posY = value_y->value();
1251 rec->setPos(posX, posY);
1253 } else if (i->type() == RECTITEM) {
1255 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1258 if (origin_x_left->isChecked()) {
1259 posX = m_frameWidth - value_x->value() - rec->rect().width();
1261 posX = value_x->value();
1265 if (origin_y_top->isChecked()) {
1266 posY = m_frameHeight - value_y->value() - rec->rect().height();
1268 posY = value_y->value();
1271 rec->setPos(posX, posY);
1273 } else if (i->type() == IMAGEITEM) {
1275 if (origin_x_left->isChecked()) {
1276 // Use the sceneBoundingRect because this also regards transformations like zoom
1277 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1279 posX = value_x->value();
1283 if (origin_y_top->isChecked()) {
1284 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1286 posY = value_y->value();
1289 i->setPos(posX, posY);
1295 void TitleWidget::updateTextOriginX()
1297 if (origin_x_left->isChecked()) {
1298 origin_x_left->setText(i18n("\u2212X"));
1300 origin_x_left->setText(i18n("+X"));
1304 void TitleWidget::slotOriginXClicked()
1306 // Update the text displayed on the button.
1307 updateTextOriginX();
1309 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1310 if (l.size() >= 1) {
1311 updateCoordinates(l.at(0));
1313 // Remember x axis setting
1314 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1315 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1317 graphicsView->setFocus();
1320 void TitleWidget::updateTextOriginY()
1322 if (origin_y_top->isChecked()) {
1323 origin_y_top->setText(i18n("\u2212Y"));
1325 origin_y_top->setText(i18n("+Y"));
1329 void TitleWidget::slotOriginYClicked()
1331 // Update the text displayed on the button.
1332 updateTextOriginY();
1334 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1335 if (l.size() >= 1) {
1336 updateCoordinates(l.at(0));
1338 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1339 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1342 graphicsView->setFocus();
1345 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1347 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1348 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1349 origin_x_left->blockSignals(true);
1350 origin_y_top->blockSignals(true);
1352 if (xAxis == TitleDocument::AxisInverted) {
1353 origin_x_left->setChecked(true);
1355 origin_x_left->setChecked(false);
1357 updateTextOriginX();
1359 if (yAxis == TitleDocument::AxisInverted) {
1360 origin_y_top->setChecked(true);
1362 origin_y_top->setChecked(false);
1364 updateTextOriginY();
1366 origin_x_left->blockSignals(false);
1367 origin_y_top->blockSignals(false);
1370 void TitleWidget::slotChangeBackground()
1372 QColor color = backgroundColor->color();
1373 color.setAlpha(backgroundAlpha->value());
1374 m_frameBorder->setBrush(QBrush(color));
1378 * Something (yeah) has changed in our QGraphicsScene.
1380 void TitleWidget::slotChanged()
1382 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1383 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1384 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1389 * If the user has set origin_x_left (everything also for y),
1390 * we need to look whether a text element has been selected. If yes,
1391 * we need to ensure that the right border of the text field
1392 * remains fixed also when some text has been entered.
1394 * This is also known as right-justified, with the difference that
1395 * it is not valid for text but for its boundingRect. Text may still
1396 * be left-justified.
1398 void TitleWidget::textChanged(QGraphicsTextItem *i)
1403 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1405 if (!i->toPlainText().isEmpty()) {
1409 * Don't do anything if the string is empty. If the position
1410 * would be updated here, a newly created text field would
1411 * be set to the position of the last selected text field.
1417 void TitleWidget::slotInsertUnicode()
1419 m_unicodeDialog->exec();
1422 void TitleWidget::slotInsertUnicodeString(QString text)
1424 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1426 if (l.at(0)->type() == TEXTITEM) {
1427 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1428 t->textCursor().insertText(text);
1433 void TitleWidget::slotUpdateText()
1435 QFont font = font_family->currentFont();
1436 font.setPixelSize(font_size->value());
1437 font.setItalic(buttonItalic->isChecked());
1438 font.setUnderline(buttonUnder->isChecked());
1439 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1440 QColor color = fontColorButton->color();
1441 color.setAlpha(textAlpha->value());
1443 QColor outlineColor = textOutlineColor->color();
1444 outlineColor.setAlpha(textOutlineAlpha->value());
1445 double outlineWidth = textOutline->value() / 10.0;
1446 QGraphicsTextItem* item = NULL;
1447 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1448 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1449 item = static_cast <QGraphicsTextItem *>(l.at(0));
1452 //if (item->textCursor().selection ().isEmpty())
1453 QTextCursor cur(item->document());
1454 cur.select(QTextCursor::Document);
1455 QTextBlockFormat format = cur.blockFormat();
1456 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1457 item->setTextWidth(item->boundingRect().width());
1458 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1459 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1460 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1462 format.setAlignment(Qt::AlignLeft);
1463 item->setTextWidth(-1);
1466 item->setFont(font);
1467 QTextCharFormat cformat = cur.charFormat();
1469 item->setData(101, outlineWidth);
1470 item->setData(102, outlineColor);
1471 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1473 cformat.setForeground(QBrush(color));
1474 cur.setCharFormat(cformat);
1475 cur.setBlockFormat(format);
1476 item->setTextCursor(cur);
1477 cur.clearSelection();
1478 item->setTextCursor(cur);
1481 void TitleWidget::rectChanged()
1483 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1484 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1485 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1486 QColor f = rectFColor->color();
1487 f.setAlpha(rectFAlpha->value());
1489 penf.setWidth(rectLineWidth->value());
1490 penf.setJoinStyle(Qt::RoundJoin);
1492 QColor b = rectBColor->color();
1493 b.setAlpha(rectBAlpha->value());
1494 rec->setBrush(QBrush(b));
1498 void TitleWidget::itemScaled(int val)
1500 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1501 if (l.size() == 1) {
1502 Transform x = m_transformations.value(l.at(0));
1503 x.scalex = (double)val / 100.0;
1504 x.scaley = (double)val / 100.0;
1506 qtrans.scale(x.scalex, x.scaley);
1507 qtrans.rotate(x.rotatex, Qt::XAxis);
1508 qtrans.rotate(x.rotatey, Qt::YAxis);
1509 qtrans.rotate(x.rotatez, Qt::ZAxis);
1510 l[0]->setTransform(qtrans);
1511 l[0]->setData(ZOOMFACTOR, val);
1512 m_transformations[l.at(0)] = x;
1513 updateDimension(l.at(0));
1517 void TitleWidget::itemRotateX(qreal val)
1522 void TitleWidget::itemRotateY(qreal val)
1527 void TitleWidget::itemRotateZ(qreal val)
1532 void TitleWidget::itemRotate(qreal val, int axis)
1534 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1535 if (l.size() == 1) {
1536 Transform x = m_transformations[l.at(0)];
1549 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
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 m_transformations[l.at(0)] = x;
1558 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1559 updateDimension(l.at(0));
1563 void TitleWidget::itemHCenter()
1565 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1566 if (l.size() == 1) {
1567 QGraphicsItem *item = l.at(0);
1568 QRectF br = item->sceneBoundingRect();
1569 int width = (int)br.width();
1570 int newPos = (int)((m_frameWidth - width) / 2);
1571 newPos += item->pos().x() - br.left(); // Check item transformation
1572 item->setPos(newPos, item->pos().y());
1573 updateCoordinates(item);
1577 void TitleWidget::itemVCenter()
1579 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1580 if (l.size() == 1) {
1581 QGraphicsItem *item = l.at(0);
1582 QRectF br = item->sceneBoundingRect();
1583 int height = (int)br.height();
1584 int newPos = (int)((m_frameHeight - height) / 2);
1585 newPos += item->pos().y() - br.top(); // Check item transformation
1586 item->setPos(item->pos().x(), newPos);
1587 updateCoordinates(item);
1591 void TitleWidget::itemTop()
1593 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1594 if (l.size() == 1) {
1595 QGraphicsItem *item = l.at(0);
1596 QRectF br = item->sceneBoundingRect();
1598 if (br.top() > 0) diff = -br.top();
1599 else diff = -br.bottom();
1600 item->moveBy(0, diff);
1601 updateCoordinates(item);
1605 void TitleWidget::itemBottom()
1607 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1608 if (l.size() == 1) {
1609 QGraphicsItem *item = l.at(0);
1610 QRectF br = item->sceneBoundingRect();
1612 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1613 else diff = m_frameHeight - br.bottom();
1614 item->moveBy(0, diff);
1615 updateCoordinates(item);
1619 void TitleWidget::itemLeft()
1621 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1622 if (l.size() == 1) {
1623 QGraphicsItem *item = l.at(0);
1624 QRectF br = item->sceneBoundingRect();
1626 if (br.left() > 0) diff = -br.left();
1627 else diff = -br.right();
1628 item->moveBy(diff, 0);
1629 updateCoordinates(item);
1633 void TitleWidget::itemRight()
1635 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1636 if (l.size() == 1) {
1637 QGraphicsItem *item = l.at(0);
1638 QRectF br = item->sceneBoundingRect();
1640 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1641 else diff = m_frameWidth - br.left();
1642 item->moveBy(diff, 0);
1643 updateCoordinates(item);
1647 void TitleWidget::setupViewports()
1649 //double aspect_ratio = 4.0 / 3.0;//read from project
1650 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1651 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1652 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1653 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1654 QPolygonF spoly(sp);
1655 QPolygonF epoly(ep);
1656 spoly.translate(startViewportX->value(), startViewportY->value());
1657 epoly.translate(endViewportX->value(), endViewportY->value());
1658 m_startViewport->setPolygon(spoly);
1659 m_endViewport->setPolygon(epoly);
1660 if (! insertingValues) {
1661 m_startViewport->setData(0, startViewportX->value());
1662 m_startViewport->setData(1, startViewportY->value());
1663 m_startViewport->setData(2, startViewportSize->value());
1665 m_endViewport->setData(0, endViewportX->value());
1666 m_endViewport->setData(1, endViewportY->value());
1667 m_endViewport->setData(2, endViewportSize->value());
1671 void TitleWidget::loadTitle(KUrl url)
1673 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1674 if (!url.isEmpty()) {
1675 QList<QGraphicsItem *> items = m_scene->items();
1676 for (int i = 0; i < items.size(); i++) {
1677 if (items.at(i)->zValue() > -1000) delete items.at(i);
1679 m_scene->clearTextSelection();
1683 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1684 QFile file(tmpfile);
1685 if (file.open(QIODevice::ReadOnly)) {
1686 doc.setContent(&file, false);
1689 KIO::NetAccess::removeTempFile(tmpfile);
1694 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1696 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1697 insertingValues = true;
1698 startViewportX->setValue(m_startViewport->data(0).toInt());
1699 startViewportY->setValue(m_startViewport->data(1).toInt());
1700 startViewportSize->setValue(m_startViewport->data(2).toInt());
1701 endViewportX->setValue(m_endViewport->data(0).toInt());
1702 endViewportY->setValue(m_endViewport->data(1).toInt());
1703 endViewportSize->setValue(m_endViewport->data(2).toInt());
1705 insertingValues = false;
1711 void TitleWidget::saveTitle(KUrl url)
1713 if (anim_start->isChecked()) slotAnimStart(false);
1714 if (anim_end->isChecked()) slotAnimEnd(false);
1715 if (url.isEmpty()) {
1716 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1717 fs->setOperationMode(KFileDialog::Saving);
1718 fs->setMode(KFile::File);
1719 #if KDE_IS_VERSION(4,2,0)
1720 fs->setConfirmOverwrite(true);
1722 fs->setKeepLocation(true);
1724 url = fs->selectedUrl();
1727 if (!url.isEmpty()) {
1728 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1729 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1733 QDomDocument TitleWidget::xml()
1735 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1736 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1740 int TitleWidget::duration() const
1742 return m_tc.getFrameCount(title_duration->text());
1745 void TitleWidget::setXml(QDomDocument doc)
1748 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1750 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1751 /*if (doc.documentElement().hasAttribute("out")) {
1752 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1753 title_duration->setText(m_tc.getTimecode(duration));
1755 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1757 QDomElement e = doc.documentElement();
1758 m_transformations.clear();
1759 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1760 const double PI = 4.0 * atan(1.0);
1761 for (int i = 0; i < items.count(); i++) {
1762 QTransform t = items.at(i)->transform();
1766 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1767 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1768 if (rotlist.count() >= 3) {
1769 x.rotatex = rotlist[0].toDouble();
1770 x.rotatey = rotlist[1].toDouble();
1771 x.rotatez = rotlist[2].toDouble();
1773 // Try to adjust zoom
1774 t.rotate(x.rotatex * (-1), Qt::XAxis);
1775 t.rotate(x.rotatey * (-1), Qt::YAxis);
1776 t.rotate(x.rotatez * (-1), Qt::ZAxis);
1787 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1789 m_transformations[items.at(i)] = x;
1791 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1792 QColor background_color = m_titledocument.getBackgroundColor();
1793 backgroundAlpha->blockSignals(true);
1794 backgroundColor->blockSignals(true);
1795 backgroundAlpha->setValue(background_color.alpha());
1796 background_color.setAlpha(255);
1797 backgroundColor->setColor(background_color);
1798 backgroundAlpha->blockSignals(false);
1799 backgroundColor->blockSignals(false);
1801 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1802 startViewportY->setValue(m_startViewport->data(1).toInt());
1803 startViewportSize->setValue(m_startViewport->data(2).toInt());
1804 endViewportX->setValue(m_endViewport->data(0).toInt());
1805 endViewportY->setValue(m_endViewport->data(1).toInt());
1806 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1808 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1813 /** \brief Connected to the accepted signal - calls writeChoices */
1814 void TitleWidget::slotAccepted()
1816 if (anim_start->isChecked()) slotAnimStart(false);
1817 if (anim_end->isChecked()) slotAnimEnd(false);
1821 /** \brief Store the current choices of font, background and rect values */
1822 void TitleWidget::writeChoices()
1824 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1825 KSharedConfigPtr config = KGlobal::config();
1826 KConfigGroup titleConfig(config, "TitleWidget");
1827 // Write the entries
1828 titleConfig.writeEntry("font_family", font_family->currentFont());
1829 //titleConfig.writeEntry("font_size", font_size->value());
1830 titleConfig.writeEntry("font_pixel_size", font_size->value());
1831 titleConfig.writeEntry("font_color", fontColorButton->color());
1832 titleConfig.writeEntry("font_alpha", textAlpha->value());
1833 titleConfig.writeEntry("font_outline", textOutline->value());
1834 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1835 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1836 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1837 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1838 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1840 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1841 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1842 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1843 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1844 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1846 titleConfig.writeEntry("background_color", backgroundColor->color());
1847 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1849 //! \todo Not sure if I should sync - it is probably safe to do it
1854 /** \brief Read the last stored choices into the dialog */
1855 void TitleWidget::readChoices()
1857 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1858 KSharedConfigPtr config = KGlobal::config();
1859 KConfigGroup titleConfig(config, "TitleWidget");
1861 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1862 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1863 m_scene->slotUpdateFontSize(font_size->value());
1864 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1865 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1867 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
1868 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
1869 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
1872 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1873 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1874 setFontBoxWeight(weight);
1875 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1876 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1878 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1879 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1880 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1881 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1882 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1884 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
1885 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
1888 void TitleWidget::adjustFrameSize()
1890 m_frameWidth = m_titledocument.frameWidth();
1891 m_frameHeight = m_titledocument.frameHeight();
1892 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1893 displayBackgroundFrame();
1896 void TitleWidget::slotAnimStart(bool anim)
1898 if (anim && anim_end->isChecked()) {
1899 anim_end->setChecked(false);
1900 m_endViewport->setZValue(-1000);
1901 m_endViewport->setBrush(QBrush());
1904 QList<QGraphicsItem *> list = m_scene->items();
1905 for (int i = 0; i < list.count(); i++) {
1906 if (list.at(i)->zValue() > -1000) {
1907 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1908 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1911 align_box->setEnabled(anim);
1912 itemzoom->setEnabled(!anim);
1913 itemrotatex->setEnabled(!anim);
1914 itemrotatey->setEnabled(!anim);
1915 itemrotatez->setEnabled(!anim);
1916 frame_toolbar->setEnabled(!anim);
1917 toolbar_stack->setEnabled(!anim);
1919 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1920 m_startViewport->setZValue(1100);
1921 QColor col = m_startViewport->pen().color();
1923 m_startViewport->setBrush(col);
1924 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1925 m_startViewport->setSelected(true);
1928 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1930 m_startViewport->setZValue(-1000);
1931 m_startViewport->setBrush(QBrush());
1932 m_startViewport->setFlags(0);
1933 if (!anim_end->isChecked()) deleteAnimInfoText();
1938 void TitleWidget::slotAnimEnd(bool anim)
1940 if (anim && anim_start->isChecked()) {
1941 anim_start->setChecked(false);
1942 m_startViewport->setZValue(-1000);
1943 m_startViewport->setBrush(QBrush());
1946 QList<QGraphicsItem *> list = m_scene->items();
1947 for (int i = 0; i < list.count(); i++) {
1948 if (list.at(i)->zValue() > -1000) {
1949 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1950 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1953 align_box->setEnabled(anim);
1954 itemzoom->setEnabled(!anim);
1955 itemrotatex->setEnabled(!anim);
1956 itemrotatey->setEnabled(!anim);
1957 itemrotatez->setEnabled(!anim);
1958 frame_toolbar->setEnabled(!anim);
1959 toolbar_stack->setEnabled(!anim);
1961 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1962 m_endViewport->setZValue(1100);
1963 QColor col = m_endViewport->pen().color();
1965 m_endViewport->setBrush(col);
1966 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1967 m_endViewport->setSelected(true);
1970 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
1972 m_endViewport->setZValue(-1000);
1973 m_endViewport->setBrush(QBrush());
1974 m_endViewport->setFlags(0);
1975 if (!anim_start->isChecked()) deleteAnimInfoText();
1979 void TitleWidget::addAnimInfoText()
1981 // add text to anim viewport
1982 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
1983 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
1984 QFont font = t->font();
1985 font.setPixelSize(m_startViewport->rect().width() / 10);
1986 QColor col = m_startViewport->pen().color();
1988 t->setDefaultTextColor(col);
1990 font.setPixelSize(m_endViewport->rect().width() / 10);
1991 col = m_endViewport->pen().color();
1993 t2->setDefaultTextColor(col);
1997 void TitleWidget::updateInfoText()
1999 // update info text font
2000 if (!m_startViewport->childItems().isEmpty()) {
2001 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2003 QFont font = item->font();
2004 font.setPixelSize(m_startViewport->rect().width() / 10);
2005 item->setFont(font);
2008 if (!m_endViewport->childItems().isEmpty()) {
2009 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2011 QFont font = item->font();
2012 font.setPixelSize(m_endViewport->rect().width() / 10);
2013 item->setFont(font);
2018 void TitleWidget::deleteAnimInfoText()
2020 // end animation editing, remove info text
2021 while (!m_startViewport->childItems().isEmpty()) {
2022 QGraphicsItem *item = m_startViewport->childItems().at(0);
2023 m_scene->removeItem(item);
2026 while (!m_endViewport->childItems().isEmpty()) {
2027 QGraphicsItem *item = m_endViewport->childItems().at(0);
2028 m_scene->removeItem(item);
2034 void TitleWidget::slotKeepAspect(bool keep)
2036 if (m_endViewport->zValue() == 1100) {
2037 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2038 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2040 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2041 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2045 void TitleWidget::slotResize50()
2047 if (m_endViewport->zValue() == 1100) {
2048 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2049 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2052 void TitleWidget::slotResize100()
2054 if (m_endViewport->zValue() == 1100) {
2055 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2056 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2059 void TitleWidget::slotResize200()
2061 if (m_endViewport->zValue() == 1100) {
2062 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2063 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2066 void TitleWidget::slotAddEffect(int ix)
2068 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2069 int effect = effect_list->itemData(ix).toInt();
2070 if (effect == NOEFFECT) {
2071 if (l.size() == 1) l[0]->setData(100, QVariant());
2072 effect_stack->setHidden(true);
2075 effect_stack->setCurrentIndex(effect - 1);
2076 effect_stack->setHidden(false);
2077 if (effect == TYPEWRITEREFFECT) {
2078 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
2079 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2080 l[0]->setData(100, effdata);
2083 #if QT_VERSION < 0x040600
2086 if (effect == BLUREFFECT) {
2088 if (l.size() == 1) {
2089 QGraphicsEffect *eff = new QGraphicsBlurEffect();
2090 l[0]->setGraphicsEffect(eff);
2092 } else if (effect == SHADOWEFFECT) {
2093 if (l.size() == 1) {
2094 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
2095 l[0]->setGraphicsEffect(eff);
2103 void TitleWidget::slotFontText(const QString& s)
2106 if (f.exactMatch()) {
2107 // Font really exists (could also just be a «d» if the user
2108 // starts typing «dejavu» for example).
2109 font_family->setCurrentFont(f);
2111 // Note: Typing dejavu serif does not recognize the font (takes sans)
2112 // in older Qt versions.
2115 void TitleWidget::slotEditTypewriter(int ix)
2117 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2118 if (l.size() == 1) {
2119 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2120 l[0]->setData(100, effdata);
2124 void TitleWidget::slotEditBlur(int ix)
2126 #if QT_VERSION < 0x040600
2129 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2130 if (l.size() == 1) {
2131 QGraphicsEffect *eff = l[0]->graphicsEffect();
2132 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2133 if (blur) blur->setBlurRadius(ix);
2138 void TitleWidget::slotEditShadow()
2140 #if QT_VERSION < 0x040600
2143 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2144 if (l.size() == 1) {
2145 QGraphicsEffect *eff = l[0]->graphicsEffect();
2146 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2148 shadow->setBlurRadius(shadow_radius->value());
2149 shadow->setOffset(shadow_x->value(), shadow_y->value());
2155 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2157 qreal bound = maxBound ? -99 : 99;
2158 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2160 QList<QGraphicsItem*> lItems;
2161 // Get items (all or intersecting only)
2162 if (intersectingOnly) {
2163 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2165 lItems = graphicsView->scene()->items();
2167 if (lItems.size() > 0) {
2168 int n = lItems.size();
2171 for (int i = 0; i < n; i++) {
2172 z = lItems[i]->zValue();
2173 if (z > bound && !lItems[i]->isSelected()) {
2178 // Get minimum z index.
2179 for (int i = 0; i < n; i++) {
2180 z = lItems[i]->zValue();
2181 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2182 // There are items at the very bottom (background e.g.) with z-index < -1000.
2192 void TitleWidget::slotZIndexUp()
2194 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2195 if (l.size() >= 1) {
2196 qreal currentZ = l[0]->zValue();
2197 qreal max = zIndexBounds(true, true);
2198 if (currentZ <= max) {
2199 l[0]->setZValue(currentZ + 1);
2200 updateDimension(l[0]);
2205 void TitleWidget::slotZIndexTop()
2207 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2208 if (l.size() >= 1) {
2209 qreal currentZ = l[0]->zValue();
2210 qreal max = zIndexBounds(true, false);
2211 if (currentZ <= max) {
2212 l[0]->setZValue(max + 1);
2213 updateDimension(l[0]);
2218 void TitleWidget::slotZIndexDown()
2220 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2221 if (l.size() >= 1) {
2222 qreal currentZ = l[0]->zValue();
2223 qreal min = zIndexBounds(false, true);
2224 if (currentZ >= min) {
2225 l[0]->setZValue(currentZ - 1);
2226 updateDimension(l[0]);
2231 void TitleWidget::slotZIndexBottom()
2233 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2234 if (l.size() >= 1) {
2235 qreal currentZ = l[0]->zValue();
2236 qreal min = zIndexBounds(false, false);
2237 if (currentZ >= min) {
2238 l[0]->setZValue(min - 1);
2239 updateDimension(l[0]);