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"
24 #include <KGlobalSettings>
25 #include <KFileDialog>
26 #include <KStandardDirs>
27 #include <KMessageBox>
28 #include <kio/netaccess.h>
29 #include <kdeversion.h>
31 #include <QDomDocument>
32 #include <QGraphicsItem>
33 #include <QGraphicsSvgItem>
37 #include <QSignalMapper>
38 #include <QTextBlockFormat>
39 #include <QTextCursor>
41 #if QT_VERSION >= 0x040600
42 #include <QGraphicsEffect>
43 #include <QGraphicsBlurEffect>
44 #include <QGraphicsDropShadowEffect>
47 int settingUp = false;
49 const int IMAGEITEM = 7;
50 const int RECTITEM = 3;
51 const int TEXTITEM = 8;
53 const int NOEFFECT = 0;
54 const int BLUREFFECT = 1;
55 const int SHADOWEFFECT = 2;
56 const int TYPEWRITEREFFECT = 3;
58 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
61 m_startViewport(NULL),
65 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
66 m_projectTitlePath(projectTitlePath),
70 setFont(KGlobalSettings::toolBarFont());
71 frame_properties->setEnabled(false);
72 frame_properties->setFixedHeight(frame_toolbar->height());
74 itemzoom->setSuffix(i18n("%"));
75 m_frameWidth = render->renderWidth();
76 m_frameHeight = render->renderHeight();
77 showToolbars(TITLE_SELECT);
79 //TODO: get default title duration instead of hardcoded one
80 title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0)));
82 connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
83 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
85 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
86 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
87 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
88 connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
89 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
91 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
93 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
94 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
95 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
96 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
97 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
99 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
100 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
101 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
102 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
103 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
104 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
107 effect_list->addItem(i18n("None"), NOEFFECT);
108 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
109 effect_list->addItem(i18n("Blur"), BLUREFFECT);
112 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
113 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
114 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
115 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
116 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
117 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
118 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
119 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
120 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
121 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
122 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
123 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
124 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
125 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
126 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
127 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
128 effect_stack->setHidden(true);
129 effect_frame->setEnabled(false);
131 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
132 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
134 m_signalMapper = new QSignalMapper(this);
135 m_signalMapper->setMapping(value_w, ValueWidth);
136 m_signalMapper->setMapping(value_h, ValueHeight);
137 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
138 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
139 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
141 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
142 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
143 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
144 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
145 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
146 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
147 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
148 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
149 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
150 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
151 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
152 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
153 //connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
154 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
156 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
159 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
161 font_weight_box->blockSignals(true);
162 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
163 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
164 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
165 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
166 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
167 font_weight_box->setToolTip(i18n("Font weight"));
168 font_weight_box->setCurrentIndex(1);
169 font_weight_box->blockSignals(false);
171 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
172 buttonRealSize->setIcon(KIcon("zoom-original"));
173 buttonItalic->setIcon(KIcon("format-text-italic"));
174 buttonUnder->setIcon(KIcon("format-text-underline"));
175 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
176 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
177 buttonAlignRight->setIcon(KIcon("format-justify-right"));
178 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
180 buttonAlignNone->setToolTip(i18n("No alignment"));
181 buttonAlignRight->setToolTip(i18n("Align right"));
182 buttonAlignLeft->setToolTip(i18n("Align left"));
183 buttonAlignCenter->setToolTip(i18n("Align center"));
185 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
186 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
187 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
188 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
189 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
191 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
192 m_zUp->setShortcut(Qt::Key_PageUp);
193 m_zUp->setToolTip(i18n("Raise object"));
194 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
195 zUp->setDefaultAction(m_zUp);
197 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
198 m_zDown->setShortcut(Qt::Key_PageDown);
199 m_zDown->setToolTip(i18n("Lower object"));
200 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
201 zDown->setDefaultAction(m_zDown);
203 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
204 m_zTop->setShortcut(Qt::Key_Home);
205 m_zTop->setToolTip(i18n("Raise object to top"));
206 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
207 zTop->setDefaultAction(m_zTop);
209 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
210 m_zBottom->setShortcut(Qt::Key_End);
211 m_zBottom->setToolTip(i18n("Lower object to bottom"));
212 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
213 zBottom->setDefaultAction(m_zBottom);
215 zDown->setIcon(KIcon("kdenlive-zindex-down"));
216 zTop->setIcon(KIcon("kdenlive-zindex-top"));
217 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
218 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
219 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
220 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
222 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
223 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
224 rectBColor->setToolTip(i18n("Select fill color"));
225 rectFColor->setToolTip(i18n("Select border color"));
226 rectBAlpha->setToolTip(i18n("Fill transparency"));
227 rectFAlpha->setToolTip(i18n("Border transparency"));
228 zoom_slider->setToolTip(i18n("Zoom"));
229 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
230 buttonFitZoom->setToolTip(i18n("Fit zoom"));
231 kcolorbutton->setToolTip(i18n("Select background color"));
232 horizontalSlider->setToolTip(i18n("Background Transparency"));
234 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
235 itemhcenter->setToolTip(i18n("Align item horizontally"));
236 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
237 itemvcenter->setToolTip(i18n("Align item vertically"));
238 itemtop->setIcon(KIcon("kdenlive-align-top"));
239 itemtop->setToolTip(i18n("Align item to top"));
240 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
241 itembottom->setToolTip(i18n("Align item to bottom"));
242 itemright->setIcon(KIcon("kdenlive-align-right"));
243 itemright->setToolTip(i18n("Align item to right"));
244 itemleft->setIcon(KIcon("kdenlive-align-left"));
245 itemleft->setToolTip(i18n("Align item to left"));
248 QHBoxLayout *layout = new QHBoxLayout;
249 frame_toolbar->setLayout(layout);
250 layout->setContentsMargins(0, 0, 0, 0);
251 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
252 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
253 m_toolbar->setIconSize(QSize(s, s));
255 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
256 m_buttonCursor->setCheckable(true);
257 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
258 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
259 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
261 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
262 m_buttonText->setCheckable(true);
263 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
264 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
265 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
267 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
268 m_buttonRect->setCheckable(true);
269 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
270 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
271 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
273 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
274 m_buttonImage->setCheckable(false);
275 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
276 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
277 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
279 m_toolbar->addSeparator();
281 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
282 m_buttonLoad->setCheckable(false);
283 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
284 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
286 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
287 m_buttonSave->setCheckable(false);
288 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
289 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
291 layout->addWidget(m_toolbar);
293 // initialize graphic scene
294 m_scene = new GraphicsSceneRectMove(this);
295 graphicsView->setScene(m_scene);
296 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
297 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
298 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
300 // a gradient background
301 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
302 gradient->setSpread(QGradient::ReflectSpread);
303 scene->setBackgroundBrush(*gradient);*/
305 m_frameImage = new QGraphicsPixmapItem();
307 qtrans.scale(2.0, 2.0);
308 m_frameImage->setTransform(qtrans);
309 m_frameImage->setZValue(-1200);
310 m_frameImage->setFlags(0);
311 displayBackgroundFrame();
312 graphicsView->scene()->addItem(m_frameImage);
314 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
315 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
316 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
317 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
318 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
319 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
320 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
321 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
323 QPen framepen(Qt::DotLine);
324 framepen.setColor(Qt::red);
326 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
327 m_frameBorder->setPen(framepen);
328 m_frameBorder->setZValue(-1100);
329 m_frameBorder->setBrush(Qt::transparent);
330 m_frameBorder->setFlags(0);
331 graphicsView->scene()->addItem(m_frameBorder);
333 // mbd: load saved settings
336 graphicsView->show();
337 //graphicsView->setRenderHint(QPainter::Antialiasing);
338 graphicsView->setInteractive(true);
339 //graphicsView->resize(400, 300);
340 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
341 //toolBox->setItemEnabled(2, false);
342 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
343 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
344 m_startViewport->setData(0, m_frameWidth);
345 m_startViewport->setData(1, m_frameHeight);
346 m_endViewport->setData(0, m_frameWidth);
347 m_endViewport->setData(1, m_frameHeight);
349 if (!url.isEmpty()) loadTitle(url);
352 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
355 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
356 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
358 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
361 TitleWidget::~TitleWidget()
365 delete m_buttonImage;
366 delete m_buttonCursor;
369 delete m_unicodeAction;
375 delete m_unicodeDialog;
376 delete m_frameBorder;
378 delete m_startViewport;
379 delete m_endViewport;
381 delete m_signalMapper;
385 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
388 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
389 KStandardDirs::makeDir(titlePath);
390 titlePath.append((isClone == false) ? "title" : "clone");
393 while (path.isEmpty() || QFile::exists(path)) {
395 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
397 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
403 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
406 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
407 KStandardDirs::makeDir(titlePath);
408 return titlePath + titleName + ".png";
412 QStringList TitleWidget::extractImageList(QString xml)
415 if (xml.isEmpty()) return result;
418 QDomNodeList images = doc.elementsByTagName("content");
419 for (int i = 0; i < images.count(); i++) {
420 if (images.at(i).toElement().hasAttribute("url"))
421 result.append(images.at(i).toElement().attribute("url"));
428 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
433 void TitleWidget::slotTextTool()
435 m_scene->setTool(TITLE_TEXT);
436 showToolbars(TITLE_TEXT);
437 checkButton(TITLE_TEXT);
440 void TitleWidget::slotRectTool()
442 m_scene->setTool(TITLE_RECTANGLE);
443 showToolbars(TITLE_RECTANGLE);
444 checkButton(TITLE_RECTANGLE);
447 void TitleWidget::slotSelectTool()
449 m_scene->setTool(TITLE_SELECT);
451 // Find out which toolbars need to be shown, depending on selected item
452 TITLETOOL t = TITLE_SELECT;
453 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
455 switch (l.at(0)->type()) {
469 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
470 //graphicsView->centerOn(l.at(0));
476 updateCoordinates(l.at(0));
477 updateDimension(l.at(0));
478 updateRotZoom(l.at(0));
481 checkButton(TITLE_SELECT);
484 void TitleWidget::slotImageTool()
486 // TODO: find a way to get a list of all supported image types...
487 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";
488 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
489 if (!url.isEmpty()) {
490 if (url.path().endsWith(".svg")) {
491 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
492 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
493 svg->setZValue(m_count++);
494 svg->setData(Qt::UserRole, url.path());
495 graphicsView->scene()->addItem(svg);
497 QPixmap pix(url.path());
498 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
499 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
500 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
501 image->setData(Qt::UserRole, url.path());
502 image->setZValue(m_count++);
503 graphicsView->scene()->addItem(image);
506 m_scene->setTool(TITLE_SELECT);
507 showToolbars(TITLE_SELECT);
508 checkButton(TITLE_SELECT);
511 void TitleWidget::showToolbars(TITLETOOL toolType)
513 toolbar_stack->setCurrentIndex((int) toolType);
516 void TitleWidget::enableToolbars(TITLETOOL toolType)
518 // TITLETOOL is defined in graphicsscenerectmove.h
520 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
521 value_w->setEnabled(enable);
522 value_h->setEnabled(enable);
525 void TitleWidget::checkButton(TITLETOOL toolType)
527 bool bSelect = false;
539 case TITLE_RECTANGLE:
549 m_buttonCursor->setChecked(bSelect);
550 m_buttonText->setChecked(bText);
551 m_buttonRect->setChecked(bRect);
552 m_buttonImage->setChecked(bImage);
555 void TitleWidget::displayBackgroundFrame()
557 if (!displayBg->isChecked()) {
558 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
559 QPixmap pattern(20, 20);
561 QColor bgcolor(210, 210, 210);
564 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
565 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
570 p.fillRect(bg.rect(), br);
572 m_frameImage->setPixmap(bg);
574 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
578 void TitleWidget::initAnimation()
580 align_box->setEnabled(false);
581 QPen startpen(Qt::DotLine);
582 QPen endpen(Qt::DashDotLine);
583 startpen.setColor(QColor(100, 200, 100, 140));
584 endpen.setColor(QColor(200, 100, 100, 140));
586 m_startViewport->setPen(startpen);
587 m_endViewport->setPen(endpen);
589 m_startViewport->setZValue(-1000);
590 m_endViewport->setZValue(-1000);
592 m_startViewport->setFlags(0);
593 m_endViewport->setFlags(0);
595 graphicsView->scene()->addItem(m_startViewport);
596 graphicsView->scene()->addItem(m_endViewport);
598 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
599 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
600 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
601 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
604 void TitleWidget::slotUpdateZoom(int pos)
606 m_scene->setZoom((double) pos / 100);
607 zoom_label->setText(QString::number(pos) + '%');
610 void TitleWidget::slotZoom(bool up)
612 int pos = zoom_slider->value();
615 zoom_slider->setValue(pos);
618 void TitleWidget::slotAdjustZoom()
620 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
621 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
622 if (scalex > scaley) scalex = scaley;
623 int zoompos = (int)(scalex * 7 + 0.5);*/
624 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
625 int zoompos = graphicsView->matrix().m11() * 100;
626 zoom_slider->setValue(zoompos);
627 graphicsView->centerOn(m_frameBorder);
630 void TitleWidget::slotZoomOneToOne()
632 zoom_slider->setValue(100);
633 graphicsView->centerOn(m_frameBorder);
636 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
638 updateAxisButtons(rect); // back to default
640 QColor f = rectFColor->color();
641 f.setAlpha(rectFAlpha->value());
643 penf.setWidth(rectLineWidth->value());
645 QColor b = rectBColor->color();
646 b.setAlpha(rectBAlpha->value());
647 rect->setBrush(QBrush(b));
648 rect->setZValue(m_count++);
649 //setCurrentItem(rect);
650 //graphicsView->setFocus();
653 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
655 updateAxisButtons(tt); // back to default
657 QFont font = font_family->currentFont();
658 font.setPixelSize(font_size->value());
660 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
661 font.setItalic(buttonItalic->isChecked());
662 font.setUnderline(buttonUnder->isChecked());
665 QColor color = fontColorButton->color();
666 color.setAlpha(textAlpha->value());
667 tt->setDefaultTextColor(color);
668 tt->setZValue(m_count++);
672 void TitleWidget::setFontBoxWeight(int weight)
674 int index = font_weight_box->findData(weight);
676 index = font_weight_box->findData(QFont::Normal);
678 font_weight_box->setCurrentIndex(index);
681 void TitleWidget::setCurrentItem(QGraphicsItem *item)
683 m_scene->setSelectedItem(item);
686 void TitleWidget::zIndexChanged(int v)
688 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
694 void TitleWidget::selectionChanged()
696 if (m_scene->tool() != TITLE_SELECT) return;
697 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
698 //toolBox->setItemEnabled(2, false);
699 //toolBox->setItemEnabled(3, false);
700 value_x->blockSignals(true);
701 value_y->blockSignals(true);
702 value_w->blockSignals(true);
703 value_h->blockSignals(true);
704 itemzoom->blockSignals(true);
705 itemrotate->blockSignals(true);
707 effect_stack->setHidden(true);
708 effect_frame->setEnabled(false);
709 effect_list->setCurrentIndex(0);
710 bool blockX = !origin_x_left->signalsBlocked();
711 bool blockY = !origin_y_top->signalsBlocked();
712 if (blockX) origin_x_left->blockSignals(true);
713 if (blockY) origin_y_top->blockSignals(true);
714 origin_x_left->setChecked(false);
715 origin_y_top->setChecked(false);
718 enableToolbars(TITLE_SELECT);
719 if (blockX) origin_x_left->blockSignals(false);
720 if (blockY) origin_y_top->blockSignals(false);
721 itemzoom->setEnabled(false);
722 itemrotate->setEnabled(false);
723 frame_properties->setEnabled(false);
724 } else if (l.size() == 1) {
725 effect_frame->setEnabled(true);
726 frame_properties->setEnabled(true);
727 if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
728 itemzoom->setEnabled(true);
729 itemrotate->setEnabled(true);
731 itemzoom->setEnabled(false);
732 itemrotate->setEnabled(false);
735 if (l.at(0)->type() == TEXTITEM) {
736 showToolbars(TITLE_TEXT);
737 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
738 if (!i->data(100).isNull()) {
739 // Item has an effect
740 QStringList effdata = i->data(100).toStringList();
741 QString effectName = effdata.takeFirst();
742 if (effectName == "typewriter") {
743 QStringList params = effdata.at(0).split(';');
744 typewriter_delay->setValue(params.at(0).toInt());
745 typewriter_start->setValue(params.at(1).toInt());
746 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
747 effect_stack->setHidden(false);
750 #if QT_VERSION >= 0x040600
751 if (i->graphicsEffect()) {
752 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
754 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
755 int rad = (int) blur->blurRadius();
756 blur_radius->setValue(rad);
757 effect_stack->setHidden(false);
759 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
761 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
762 shadow_radius->setValue(shad->blurRadius());
763 shadow_x->setValue(shad->xOffset());
764 shadow_y->setValue(shad->yOffset());
765 effect_stack->setHidden(false);
769 effect_list->blockSignals(true);
770 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
771 effect_list->blockSignals(false);
772 effect_stack->setHidden(true);
775 effect_list->blockSignals(true);
776 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
777 effect_list->blockSignals(false);
778 effect_stack->setHidden(true);
781 //if (l[0]->hasFocus())
782 //toolBox->setCurrentIndex(0);
783 //toolBox->setItemEnabled(2, true);
784 font_size->blockSignals(true);
785 font_family->blockSignals(true);
786 font_weight_box->blockSignals(true);
787 buttonItalic->blockSignals(true);
788 buttonUnder->blockSignals(true);
789 fontColorButton->blockSignals(true);
790 textAlpha->blockSignals(true);
791 buttonAlignLeft->blockSignals(true);
792 buttonAlignRight->blockSignals(true);
793 buttonAlignNone->blockSignals(true);
794 buttonAlignCenter->blockSignals(true);
796 QFont font = i->font();
797 font_family->setCurrentFont(font);
798 font_size->setValue(font.pixelSize());
799 m_scene->slotUpdateFontSize(font.pixelSize());
800 buttonItalic->setChecked(font.italic());
801 buttonUnder->setChecked(font.underline());
802 setFontBoxWeight(font.weight());
804 QColor color = i->defaultTextColor();
805 fontColorButton->setColor(color);
806 textAlpha->setValue(color.alpha());
808 QTextCursor cur = i->textCursor();
809 QTextBlockFormat format = cur.blockFormat();
810 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
811 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
812 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
813 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
815 font_size->blockSignals(false);
816 font_family->blockSignals(false);
817 font_weight_box->blockSignals(false);
818 buttonItalic->blockSignals(false);
819 buttonUnder->blockSignals(false);
820 fontColorButton->blockSignals(false);
821 textAlpha->blockSignals(false);
822 buttonAlignLeft->blockSignals(false);
823 buttonAlignRight->blockSignals(false);
824 buttonAlignNone->blockSignals(false);
825 buttonAlignCenter->blockSignals(false);
827 updateAxisButtons(i);
828 updateCoordinates(i);
830 enableToolbars(TITLE_TEXT);
832 } else if ((l.at(0))->type() == RECTITEM) {
833 showToolbars(TITLE_RECTANGLE);
835 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
836 if (rec == m_startViewport || rec == m_endViewport) {
837 /*toolBox->setCurrentIndex(3);
838 toolBox->widget(0)->setEnabled(false);
839 toolBox->widget(1)->setEnabled(false);*/
840 enableToolbars(TITLE_SELECT);
842 /*toolBox->widget(0)->setEnabled(true);
843 toolBox->widget(1)->setEnabled(true);
844 toolBox->setCurrentIndex(0);*/
845 //toolBox->setItemEnabled(3, true);
846 rectFAlpha->setValue(rec->pen().color().alpha());
847 rectBAlpha->setValue(rec->brush().color().alpha());
848 //kDebug() << rec->brush().color().alpha();
849 QColor fcol = rec->pen().color();
850 QColor bcol = rec->brush().color();
851 //fcol.setAlpha(255);
852 //bcol.setAlpha(255);
853 rectFColor->setColor(fcol);
854 rectBColor->setColor(bcol);
856 rectLineWidth->setValue(rec->pen().width());
857 enableToolbars(TITLE_RECTANGLE);
860 updateAxisButtons(l.at(0));
861 updateCoordinates(rec);
862 updateDimension(rec);
864 } else if (l.at(0)->type() == IMAGEITEM) {
865 showToolbars(TITLE_IMAGE);
867 updateCoordinates(l.at(0));
868 updateDimension(l.at(0));
870 enableToolbars(TITLE_IMAGE);
873 //toolBox->setCurrentIndex(0);
874 showToolbars(TITLE_SELECT);
875 enableToolbars(TITLE_SELECT);
876 frame_properties->setEnabled(false);
878 zValue->setValue((int)l.at(0)->zValue());
879 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
880 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
881 value_x->blockSignals(false);
882 value_y->blockSignals(false);
883 value_w->blockSignals(false);
884 value_h->blockSignals(false);
885 itemzoom->blockSignals(false);
886 itemrotate->blockSignals(false);
890 void TitleWidget::slotValueChanged(int type)
892 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
893 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
898 val = value_w->value();
901 val = value_h->value();
905 QGraphicsItem *i = l.at(0);
906 Transform t = m_transformations.value(i);
908 // Ratio width:height
909 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
910 double alpha = (double) t.rotate / 180.0 * M_PI;
920 // Add 0.5 because otherwise incrementing by 1 might have no effect
921 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
922 scale = length / i->boundingRect().width();
925 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
926 scale = length / i->boundingRect().height();
933 qtrans.scale(scale, scale);
934 qtrans.rotate(t.rotate);
935 i->setTransform(qtrans);
936 m_transformations[i] = t;
943 /** \brief Updates position/size of the selected item when a value
944 * of an item (coordinates, size) has changed */
945 void TitleWidget::slotAdjustSelectedItem()
947 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
949 if (l.at(0)->type() == RECTITEM) {
951 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
953 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
954 } else if (l.at(0)->type() == TEXTITEM) {
956 updatePosition(l.at(0));
957 } else if (l.at(0)->type() == IMAGEITEM) {
959 updatePosition(l.at(0));
964 /** \brief Updates width/height int the text fields, regarding transformation matrix */
965 void TitleWidget::updateDimension(QGraphicsItem *i)
967 value_w->blockSignals(true);
968 value_h->blockSignals(true);
969 zValue->blockSignals(true);
971 zValue->setValue((int) i->zValue());
972 if (i->type() == IMAGEITEM) {
973 // Get multipliers for rotation/scaling
975 /*Transform t = m_transformations.value(i);
976 QRectF r = i->boundingRect();
977 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
978 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
979 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
980 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
982 value_w->setValue(i->sceneBoundingRect().width());
983 value_h->setValue(i->sceneBoundingRect().height());
984 } else if (i->type() == RECTITEM) {
985 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
986 value_w->setValue((int) r->rect().width());
987 value_h->setValue((int) r->rect().height());
988 } else if (i->type() == TEXTITEM) {
989 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
990 value_w->setValue((int) t->boundingRect().width());
991 value_h->setValue((int) t->boundingRect().height());
994 zValue->blockSignals(false);
995 value_w->blockSignals(false);
996 value_h->blockSignals(false);
999 /** \brief Updates the coordinates in the text fields from the item */
1000 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1002 // Block signals emitted by this method
1003 value_x->blockSignals(true);
1004 value_y->blockSignals(true);
1006 if (i->type() == TEXTITEM) {
1008 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1010 // Set the correct x coordinate value
1011 if (origin_x_left->isChecked()) {
1012 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1013 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1015 // Origin is at 0 (default)
1016 value_x->setValue((int) rec->pos().x());
1020 if (origin_y_top->isChecked()) {
1021 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1023 value_y->setValue((int) rec->pos().y());
1026 } else if (i->type() == RECTITEM) {
1028 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1030 if (origin_x_left->isChecked()) {
1031 // Origin (0 point) is at m_frameWidth
1032 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1034 // Origin is at 0 (default)
1035 value_x->setValue((int) rec->pos().x());
1038 if (origin_y_top->isChecked()) {
1039 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1041 value_y->setValue((int) rec->pos().y());
1044 } else if (i->type() == IMAGEITEM) {
1046 if (origin_x_left->isChecked()) {
1047 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1049 value_x->setValue((int) i->pos().x());
1052 if (origin_y_top->isChecked()) {
1053 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1055 value_y->setValue((int) i->pos().y());
1060 // Stop blocking signals now
1061 value_x->blockSignals(false);
1062 value_y->blockSignals(false);
1065 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1067 itemzoom->blockSignals(true);
1068 itemrotate->blockSignals(false);
1070 Transform t = m_transformations.value(i);
1071 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1072 itemrotate->setValue((int)(t.rotate));
1074 itemzoom->blockSignals(false);
1075 itemrotate->blockSignals(false);
1078 /** \brief Updates the position of an item by reading coordinates from the text fields */
1079 void TitleWidget::updatePosition(QGraphicsItem *i)
1081 if (i->type() == TEXTITEM) {
1082 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1085 if (origin_x_left->isChecked()) {
1086 /* Origin of the x axis is at m_frameWidth,
1087 * and distance from right border of the item to the right
1088 * border of the frame is taken.
1089 * See comment to slotOriginXClicked().
1091 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1093 posX = value_x->value();
1097 if (origin_y_top->isChecked()) {
1098 /* Same for y axis */
1099 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1101 posY = value_y->value();
1104 rec->setPos(posX, posY);
1106 } else if (i->type() == RECTITEM) {
1108 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1111 if (origin_x_left->isChecked()) {
1112 posX = m_frameWidth - value_x->value() - rec->rect().width();
1114 posX = value_x->value();
1118 if (origin_y_top->isChecked()) {
1119 posY = m_frameHeight - value_y->value() - rec->rect().height();
1121 posY = value_y->value();
1124 rec->setPos(posX, posY);
1126 } else if (i->type() == IMAGEITEM) {
1128 if (origin_x_left->isChecked()) {
1129 // Use the sceneBoundingRect because this also regards transformations like zoom
1130 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1132 posX = value_x->value();
1136 if (origin_y_top->isChecked()) {
1137 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1139 posY = value_y->value();
1142 i->setPos(posX, posY);
1148 void TitleWidget::updateTextOriginX()
1150 if (origin_x_left->isChecked()) {
1151 origin_x_left->setText(i18n("\u2212X"));
1153 origin_x_left->setText(i18n("+X"));
1157 void TitleWidget::slotOriginXClicked()
1159 // Update the text displayed on the button.
1160 updateTextOriginX();
1162 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1163 if (l.size() >= 1) {
1164 updateCoordinates(l.at(0));
1166 // Remember x axis setting
1167 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1168 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1170 graphicsView->setFocus();
1173 void TitleWidget::updateTextOriginY()
1175 if (origin_y_top->isChecked()) {
1176 origin_y_top->setText(i18n("\u2212Y"));
1178 origin_y_top->setText(i18n("+Y"));
1182 void TitleWidget::slotOriginYClicked()
1184 // Update the text displayed on the button.
1185 updateTextOriginY();
1187 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1188 if (l.size() >= 1) {
1189 updateCoordinates(l.at(0));
1191 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1192 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1195 graphicsView->setFocus();
1198 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1200 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1201 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1202 origin_x_left->blockSignals(true);
1203 origin_y_top->blockSignals(true);
1205 if (xAxis == TitleDocument::AxisInverted) {
1206 origin_x_left->setChecked(true);
1208 origin_x_left->setChecked(false);
1210 updateTextOriginX();
1212 if (yAxis == TitleDocument::AxisInverted) {
1213 origin_y_top->setChecked(true);
1215 origin_y_top->setChecked(false);
1217 updateTextOriginY();
1219 origin_x_left->blockSignals(false);
1220 origin_y_top->blockSignals(false);
1223 void TitleWidget::slotChangeBackground()
1225 QColor color = kcolorbutton->color();
1226 color.setAlpha(horizontalSlider->value());
1227 m_frameBorder->setBrush(QBrush(color));
1231 * Something (yeah) has changed in our QGraphicsScene.
1233 void TitleWidget::slotChanged()
1235 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1236 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1237 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1242 * If the user has set origin_x_left (everything also for y),
1243 * we need to look whether a text element has been selected. If yes,
1244 * we need to ensure that the right border of the text field
1245 * remains fixed also when some text has been entered.
1247 * This is also known as right-justified, with the difference that
1248 * it is not valid for text but for its boundingRect. Text may still
1249 * be left-justified.
1251 void TitleWidget::textChanged(QGraphicsTextItem *i)
1256 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1258 if (!i->toPlainText().isEmpty()) {
1262 * Don't do anything if the string is empty. If the position
1263 * would be updated here, a newly created text field would
1264 * be set to the position of the last selected text field.
1270 void TitleWidget::slotInsertUnicode()
1272 m_unicodeDialog->exec();
1275 void TitleWidget::slotInsertUnicodeString(QString text)
1277 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1279 if (l.at(0)->type() == TEXTITEM) {
1280 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1281 t->textCursor().insertText(text);
1286 void TitleWidget::slotUpdateText()
1288 QFont font = font_family->currentFont();
1289 font.setPixelSize(font_size->value());
1290 font.setItalic(buttonItalic->isChecked());
1291 font.setUnderline(buttonUnder->isChecked());
1292 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1293 QColor color = fontColorButton->color();
1294 color.setAlpha(textAlpha->value());
1296 QGraphicsTextItem* item = NULL;
1297 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1298 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1299 item = static_cast <QGraphicsTextItem *>(l.at(0));
1302 //if (item->textCursor().selection ().isEmpty())
1303 QTextCursor cur = item->textCursor();
1304 QTextBlockFormat format = cur.blockFormat();
1305 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1306 item->setTextWidth(item->boundingRect().width());
1307 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1308 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1309 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1311 format.setAlignment(Qt::AlignLeft);
1312 item->setTextWidth(-1);
1316 item->setFont(font);
1317 item->setDefaultTextColor(color);
1318 cur.select(QTextCursor::Document);
1319 cur.setBlockFormat(format);
1320 item->setTextCursor(cur);
1321 cur.clearSelection();
1322 item->setTextCursor(cur);
1327 void TitleWidget::rectChanged()
1329 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1330 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1331 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1332 QColor f = rectFColor->color();
1333 f.setAlpha(rectFAlpha->value());
1335 penf.setWidth(rectLineWidth->value());
1337 QColor b = rectBColor->color();
1338 b.setAlpha(rectBAlpha->value());
1339 rec->setBrush(QBrush(b));
1343 void TitleWidget::itemScaled(int val)
1345 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1346 if (l.size() == 1) {
1347 Transform x = m_transformations.value(l.at(0));
1348 x.scalex = (double)val / 100.0;
1349 x.scaley = (double)val / 100.0;
1351 qtrans.scale(x.scalex, x.scaley);
1352 qtrans.rotate(x.rotate);
1353 l[0]->setTransform(qtrans);
1354 m_transformations[l.at(0)] = x;
1355 updateDimension(l.at(0));
1359 void TitleWidget::itemRotate(int val)
1361 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1362 if (l.size() == 1) {
1363 Transform x = m_transformations[l.at(0)];
1364 x.rotate = (double)val;
1366 qtrans.scale(x.scalex, x.scaley);
1367 qtrans.rotate(x.rotate);
1368 l[0]->setTransform(qtrans);
1369 m_transformations[l.at(0)] = x;
1370 updateDimension(l.at(0));
1374 void TitleWidget::itemHCenter()
1376 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1377 if (l.size() == 1) {
1378 QGraphicsItem *item = l.at(0);
1379 QRectF br = item->sceneBoundingRect();
1380 int width = (int)br.width();
1381 int newPos = (int)((m_frameWidth - width) / 2);
1382 newPos += item->pos().x() - br.left(); // Check item transformation
1383 item->setPos(newPos, item->pos().y());
1384 updateCoordinates(item);
1388 void TitleWidget::itemVCenter()
1390 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1391 if (l.size() == 1) {
1392 QGraphicsItem *item = l.at(0);
1393 QRectF br = item->sceneBoundingRect();
1394 int height = (int)br.height();
1395 int newPos = (int)((m_frameHeight - height) / 2);
1396 newPos += item->pos().y() - br.top(); // Check item transformation
1397 item->setPos(item->pos().x(), newPos);
1398 updateCoordinates(item);
1402 void TitleWidget::itemTop()
1404 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1405 if (l.size() == 1) {
1406 QGraphicsItem *item = l.at(0);
1407 QRectF br = item->sceneBoundingRect();
1409 if (br.top() > 0) diff = -br.top();
1410 else diff = -br.bottom();
1411 item->moveBy(0, diff);
1412 updateCoordinates(item);
1416 void TitleWidget::itemBottom()
1418 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1419 if (l.size() == 1) {
1420 QGraphicsItem *item = l.at(0);
1421 QRectF br = item->sceneBoundingRect();
1423 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1424 else diff = m_frameHeight - br.bottom();
1425 item->moveBy(0, diff);
1426 updateCoordinates(item);
1430 void TitleWidget::itemLeft()
1432 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1433 if (l.size() == 1) {
1434 QGraphicsItem *item = l.at(0);
1435 QRectF br = item->sceneBoundingRect();
1437 if (br.left() > 0) diff = -br.left();
1438 else diff = -br.right();
1439 item->moveBy(diff, 0);
1440 updateCoordinates(item);
1444 void TitleWidget::itemRight()
1446 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1447 if (l.size() == 1) {
1448 QGraphicsItem *item = l.at(0);
1449 QRectF br = item->sceneBoundingRect();
1451 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1452 else diff = m_frameWidth - br.left();
1453 item->moveBy(diff, 0);
1454 updateCoordinates(item);
1458 void TitleWidget::setupViewports()
1460 //double aspect_ratio = 4.0 / 3.0;//read from project
1461 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1462 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1463 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1464 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1465 QPolygonF spoly(sp);
1466 QPolygonF epoly(ep);
1467 spoly.translate(startViewportX->value(), startViewportY->value());
1468 epoly.translate(endViewportX->value(), endViewportY->value());
1469 m_startViewport->setPolygon(spoly);
1470 m_endViewport->setPolygon(epoly);
1471 if (! insertingValues) {
1472 m_startViewport->setData(0, startViewportX->value());
1473 m_startViewport->setData(1, startViewportY->value());
1474 m_startViewport->setData(2, startViewportSize->value());
1476 m_endViewport->setData(0, endViewportX->value());
1477 m_endViewport->setData(1, endViewportY->value());
1478 m_endViewport->setData(2, endViewportSize->value());
1482 void TitleWidget::loadTitle(KUrl url)
1484 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1485 if (!url.isEmpty()) {
1486 QList<QGraphicsItem *> items = m_scene->items();
1487 for (int i = 0; i < items.size(); i++) {
1488 if (items.at(i)->zValue() > -1000) delete items.at(i);
1490 m_scene->clearTextSelection();
1494 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1495 QFile file(tmpfile);
1496 if (file.open(QIODevice::ReadOnly)) {
1497 doc.setContent(&file, false);
1500 KIO::NetAccess::removeTempFile(tmpfile);
1505 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1507 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1508 insertingValues = true;
1509 startViewportX->setValue(m_startViewport->data(0).toInt());
1510 startViewportY->setValue(m_startViewport->data(1).toInt());
1511 startViewportSize->setValue(m_startViewport->data(2).toInt());
1512 endViewportX->setValue(m_endViewport->data(0).toInt());
1513 endViewportY->setValue(m_endViewport->data(1).toInt());
1514 endViewportSize->setValue(m_endViewport->data(2).toInt());
1516 insertingValues = false;
1522 void TitleWidget::saveTitle(KUrl url)
1524 if (anim_start->isChecked()) slotAnimStart(false);
1525 if (anim_end->isChecked()) slotAnimEnd(false);
1526 if (url.isEmpty()) {
1527 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1528 fs->setOperationMode(KFileDialog::Saving);
1529 fs->setMode(KFile::File);
1530 #if KDE_IS_VERSION(4,2,0)
1531 fs->setConfirmOverwrite(true);
1533 fs->setKeepLocation(true);
1535 url = fs->selectedUrl();
1538 if (!url.isEmpty()) {
1539 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1540 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1544 QDomDocument TitleWidget::xml()
1546 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1547 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1551 int TitleWidget::duration() const
1553 return m_tc.getFrameCount(title_duration->text());
1556 void TitleWidget::setXml(QDomDocument doc)
1559 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1561 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1562 /*if (doc.documentElement().hasAttribute("out")) {
1563 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1564 title_duration->setText(m_tc.getTimecode(duration));
1566 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1568 QDomElement e = doc.documentElement();
1569 m_transformations.clear();
1570 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1571 const double PI = 4.0 * atan(1.0);
1572 for (int i = 0; i < items.count(); i++) {
1573 QTransform t = items.at(i)->transform();
1577 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1578 m_transformations[items.at(i)] = x;
1580 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1581 QColor background_color = m_titledocument.getBackgroundColor();
1582 horizontalSlider->blockSignals(true);
1583 kcolorbutton->blockSignals(true);
1584 horizontalSlider->setValue(background_color.alpha());
1585 background_color.setAlpha(255);
1586 kcolorbutton->setColor(background_color);
1587 horizontalSlider->blockSignals(false);
1588 kcolorbutton->blockSignals(false);
1590 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1591 startViewportY->setValue(m_startViewport->data(1).toInt());
1592 startViewportSize->setValue(m_startViewport->data(2).toInt());
1593 endViewportX->setValue(m_endViewport->data(0).toInt());
1594 endViewportY->setValue(m_endViewport->data(1).toInt());
1595 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1597 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1601 /** \brief Connected to the accepted signal - calls writeChoices */
1602 void TitleWidget::slotAccepted()
1604 if (anim_start->isChecked()) slotAnimStart(false);
1605 if (anim_end->isChecked()) slotAnimEnd(false);
1609 /** \brief Store the current choices of font, background and rect values */
1610 void TitleWidget::writeChoices()
1612 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1613 KSharedConfigPtr config = KGlobal::config();
1614 KConfigGroup titleConfig(config, "TitleWidget");
1615 // Write the entries
1616 titleConfig.writeEntry("font_family", font_family->currentFont());
1617 //titleConfig.writeEntry("font_size", font_size->value());
1618 titleConfig.writeEntry("font_pixel_size", font_size->value());
1619 titleConfig.writeEntry("font_color", fontColorButton->color());
1620 titleConfig.writeEntry("font_alpha", textAlpha->value());
1621 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1622 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1623 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1625 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1626 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1627 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1628 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1629 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1631 titleConfig.writeEntry("background_color", kcolorbutton->color());
1632 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1634 //! \todo Not sure if I should sync - it is probably safe to do it
1639 /** \brief Read the last stored choices into the dialog */
1640 void TitleWidget::readChoices()
1642 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1643 KSharedConfigPtr config = KGlobal::config();
1644 KConfigGroup titleConfig(config, "TitleWidget");
1646 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1647 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1648 m_scene->slotUpdateFontSize(font_size->value());
1649 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1650 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1652 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1653 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1654 setFontBoxWeight(weight);
1655 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1656 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1658 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1659 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1660 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1661 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1662 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1664 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1665 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1668 void TitleWidget::adjustFrameSize()
1670 m_frameWidth = m_titledocument.frameWidth();
1671 m_frameHeight = m_titledocument.frameHeight();
1672 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1673 displayBackgroundFrame();
1676 void TitleWidget::slotAnimStart(bool anim)
1678 if (anim && anim_end->isChecked()) {
1679 anim_end->setChecked(false);
1680 m_endViewport->setZValue(-1000);
1681 m_endViewport->setBrush(QBrush());
1684 QList<QGraphicsItem *> list = m_scene->items();
1685 for (int i = 0; i < list.count(); i++) {
1686 if (list.at(i)->zValue() > -1000) {
1687 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1688 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1691 align_box->setEnabled(anim);
1692 itemzoom->setEnabled(!anim);
1693 itemrotate->setEnabled(!anim);
1694 frame_toolbar->setEnabled(!anim);
1695 toolbar_stack->setEnabled(!anim);
1697 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1698 m_startViewport->setZValue(1100);
1699 QColor col = m_startViewport->pen().color();
1701 m_startViewport->setBrush(col);
1702 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1703 m_startViewport->setSelected(true);
1706 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1708 m_startViewport->setZValue(-1000);
1709 m_startViewport->setBrush(QBrush());
1710 m_startViewport->setFlags(0);
1711 if (!anim_end->isChecked()) deleteAnimInfoText();
1716 void TitleWidget::slotAnimEnd(bool anim)
1718 if (anim && anim_start->isChecked()) {
1719 anim_start->setChecked(false);
1720 m_startViewport->setZValue(-1000);
1721 m_startViewport->setBrush(QBrush());
1724 QList<QGraphicsItem *> list = m_scene->items();
1725 for (int i = 0; i < list.count(); i++) {
1726 if (list.at(i)->zValue() > -1000) {
1727 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1728 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1731 align_box->setEnabled(anim);
1732 itemzoom->setEnabled(!anim);
1733 itemrotate->setEnabled(!anim);
1734 frame_toolbar->setEnabled(!anim);
1735 toolbar_stack->setEnabled(!anim);
1737 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1738 m_endViewport->setZValue(1100);
1739 QColor col = m_endViewport->pen().color();
1741 m_endViewport->setBrush(col);
1742 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1743 m_endViewport->setSelected(true);
1746 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
1748 m_endViewport->setZValue(-1000);
1749 m_endViewport->setBrush(QBrush());
1750 m_endViewport->setFlags(0);
1751 if (!anim_start->isChecked()) deleteAnimInfoText();
1755 void TitleWidget::addAnimInfoText()
1757 // add text to anim viewport
1758 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
1759 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
1760 QFont font = t->font();
1761 font.setPixelSize(m_startViewport->rect().width() / 10);
1762 QColor col = m_startViewport->pen().color();
1764 t->setDefaultTextColor(col);
1766 font.setPixelSize(m_endViewport->rect().width() / 10);
1767 col = m_endViewport->pen().color();
1769 t2->setDefaultTextColor(col);
1773 void TitleWidget::updateInfoText()
1775 // update info text font
1776 if (!m_startViewport->childItems().isEmpty()) {
1777 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
1779 QFont font = item->font();
1780 font.setPixelSize(m_startViewport->rect().width() / 10);
1781 item->setFont(font);
1784 if (!m_endViewport->childItems().isEmpty()) {
1785 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
1787 QFont font = item->font();
1788 font.setPixelSize(m_endViewport->rect().width() / 10);
1789 item->setFont(font);
1794 void TitleWidget::deleteAnimInfoText()
1796 // end animation editing, remove info text
1797 while (!m_startViewport->childItems().isEmpty()) {
1798 QGraphicsItem *item = m_startViewport->childItems().at(0);
1799 m_scene->removeItem(item);
1802 while (!m_endViewport->childItems().isEmpty()) {
1803 QGraphicsItem *item = m_endViewport->childItems().at(0);
1804 m_scene->removeItem(item);
1810 void TitleWidget::slotKeepAspect(bool keep)
1812 if (m_endViewport->zValue() == 1100) {
1813 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1814 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1816 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1817 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1821 void TitleWidget::slotResize50()
1823 if (m_endViewport->zValue() == 1100) {
1824 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1825 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1828 void TitleWidget::slotResize100()
1830 if (m_endViewport->zValue() == 1100) {
1831 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1832 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1835 void TitleWidget::slotResize200()
1837 if (m_endViewport->zValue() == 1100) {
1838 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1839 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1842 void TitleWidget::slotAddEffect(int ix)
1844 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1845 int effect = effect_list->itemData(ix).toInt();
1846 if (effect == NOEFFECT) {
1847 if (l.size() == 1) l[0]->setData(100, QVariant());
1848 effect_stack->setHidden(true);
1851 effect_stack->setCurrentIndex(effect - 1);
1852 effect_stack->setHidden(false);
1853 if (effect == TYPEWRITEREFFECT) {
1854 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1855 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1856 l[0]->setData(100, effdata);
1859 #if QT_VERSION < 0x040600
1862 if (effect == BLUREFFECT) {
1864 if (l.size() == 1) {
1865 QGraphicsEffect *eff = new QGraphicsBlurEffect();
1866 l[0]->setGraphicsEffect(eff);
1868 } else if (effect == SHADOWEFFECT) {
1869 if (l.size() == 1) {
1870 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
1871 l[0]->setGraphicsEffect(eff);
1879 void TitleWidget::slotFontText(const QString& s)
1882 if (f.exactMatch()) {
1883 // Font really exists (could also just be a «d» if the user
1884 // starts typing «dejavu» for example).
1885 font_family->setCurrentFont(f);
1887 // Note: Typing dejavu serif does not recognize the font (takes sans)
1888 // in older Qt versions.
1891 void TitleWidget::slotEditTypewriter(int ix)
1893 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1894 if (l.size() == 1) {
1895 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1896 l[0]->setData(100, effdata);
1900 void TitleWidget::slotEditBlur(int ix)
1902 #if QT_VERSION < 0x040600
1905 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1906 if (l.size() == 1) {
1907 QGraphicsEffect *eff = l[0]->graphicsEffect();
1908 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
1909 if (blur) blur->setBlurRadius(ix);
1914 void TitleWidget::slotEditShadow()
1916 #if QT_VERSION < 0x040600
1919 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1920 if (l.size() == 1) {
1921 QGraphicsEffect *eff = l[0]->graphicsEffect();
1922 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
1924 shadow->setBlurRadius(shadow_radius->value());
1925 shadow->setOffset(shadow_x->value(), shadow_y->value());
1931 qreal TitleWidget::zIndexBounds(bool maxBound)
1933 qreal bound = maxBound ? -99 : 99;
1934 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1936 QList<QGraphicsItem*> lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
1937 if (lItems.size() > 0) {
1938 int n = lItems.size();
1941 for (int i = 0; i < n; i++) {
1942 z = lItems[i]->zValue();
1943 if (z > bound && !lItems[i]->isSelected()) {
1948 // Get minimum z index.
1949 for (int i = 0; i < n; i++) {
1950 z = lItems[i]->zValue();
1951 if (z < bound && !lItems[i]->isSelected() && z > -999) {
1952 // There are items at the very bottom (background e.g.) with z-index < -1000.
1962 void TitleWidget::slotZIndexUp()
1964 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1965 if (l.size() >= 1) {
1966 qreal currentZ = l[0]->zValue();
1967 qreal max = zIndexBounds(true);
1968 if (currentZ <= max) {
1969 l[0]->setZValue(currentZ + 1);
1970 updateDimension(l[0]);
1975 void TitleWidget::slotZIndexTop()
1977 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1978 if (l.size() >= 1) {
1979 qreal currentZ = l[0]->zValue();
1980 qreal max = zIndexBounds(true);
1981 if (currentZ <= max) {
1982 l[0]->setZValue(max + 1);
1983 updateDimension(l[0]);
1988 void TitleWidget::slotZIndexDown()
1990 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1991 if (l.size() >= 1) {
1992 qreal currentZ = l[0]->zValue();
1993 qreal min = zIndexBounds(false);
1994 if (currentZ >= min) {
1995 l[0]->setZValue(currentZ - 1);
1996 updateDimension(l[0]);
2001 void TitleWidget::slotZIndexBottom()
2003 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2004 if (l.size() >= 1) {
2005 qreal currentZ = l[0]->zValue();
2006 qreal min = zIndexBounds(false);
2007 if (currentZ >= min) {
2008 l[0]->setZValue(min - 1);
2009 updateDimension(l[0]);