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(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
87 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
88 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
89 connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
90 connect(textOutline, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
91 connect(textOutlineAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
92 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
94 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
96 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
97 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
98 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
99 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
100 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
102 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
103 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
104 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
105 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
106 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
107 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
110 effect_list->addItem(i18n("None"), NOEFFECT);
111 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
112 effect_list->addItem(i18n("Blur"), BLUREFFECT);
115 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
116 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
117 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
118 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
119 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
120 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
121 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
122 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
123 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
124 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
125 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
126 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
127 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
128 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
129 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
130 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
131 effect_stack->setHidden(true);
132 effect_frame->setEnabled(false);
134 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
135 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
137 m_signalMapper = new QSignalMapper(this);
138 m_signalMapper->setMapping(value_w, ValueWidth);
139 m_signalMapper->setMapping(value_h, ValueHeight);
140 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
141 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
142 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
144 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
145 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
146 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
147 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
148 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
149 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
150 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
151 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
152 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
153 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
154 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
155 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
156 //connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
157 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
159 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
162 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
164 font_weight_box->blockSignals(true);
165 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
166 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
167 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
168 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
169 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
170 font_weight_box->setToolTip(i18n("Font weight"));
171 font_weight_box->setCurrentIndex(1);
172 font_weight_box->blockSignals(false);
174 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
175 buttonRealSize->setIcon(KIcon("zoom-original"));
176 buttonItalic->setIcon(KIcon("format-text-italic"));
177 buttonUnder->setIcon(KIcon("format-text-underline"));
178 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
179 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
180 buttonAlignRight->setIcon(KIcon("format-justify-right"));
181 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
183 buttonAlignNone->setToolTip(i18n("No alignment"));
184 buttonAlignRight->setToolTip(i18n("Align right"));
185 buttonAlignLeft->setToolTip(i18n("Align left"));
186 buttonAlignCenter->setToolTip(i18n("Align center"));
188 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
189 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
190 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
191 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
192 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
194 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
195 m_zUp->setShortcut(Qt::Key_PageUp);
196 m_zUp->setToolTip(i18n("Raise object"));
197 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
198 zUp->setDefaultAction(m_zUp);
200 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
201 m_zDown->setShortcut(Qt::Key_PageDown);
202 m_zDown->setToolTip(i18n("Lower object"));
203 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
204 zDown->setDefaultAction(m_zDown);
206 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
207 m_zTop->setShortcut(Qt::Key_Home);
208 m_zTop->setToolTip(i18n("Raise object to top"));
209 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
210 zTop->setDefaultAction(m_zTop);
212 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
213 m_zBottom->setShortcut(Qt::Key_End);
214 m_zBottom->setToolTip(i18n("Lower object to bottom"));
215 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
216 zBottom->setDefaultAction(m_zBottom);
218 zDown->setIcon(KIcon("kdenlive-zindex-down"));
219 zTop->setIcon(KIcon("kdenlive-zindex-top"));
220 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
221 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
222 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
223 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
225 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
226 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
227 rectBColor->setToolTip(i18n("Select fill color"));
228 rectFColor->setToolTip(i18n("Select border color"));
229 rectBAlpha->setToolTip(i18n("Fill transparency"));
230 rectFAlpha->setToolTip(i18n("Border transparency"));
231 zoom_slider->setToolTip(i18n("Zoom"));
232 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
233 buttonFitZoom->setToolTip(i18n("Fit zoom"));
234 kcolorbutton->setToolTip(i18n("Select background color"));
235 horizontalSlider->setToolTip(i18n("Background Transparency"));
237 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
238 itemhcenter->setToolTip(i18n("Align item horizontally"));
239 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
240 itemvcenter->setToolTip(i18n("Align item vertically"));
241 itemtop->setIcon(KIcon("kdenlive-align-top"));
242 itemtop->setToolTip(i18n("Align item to top"));
243 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
244 itembottom->setToolTip(i18n("Align item to bottom"));
245 itemright->setIcon(KIcon("kdenlive-align-right"));
246 itemright->setToolTip(i18n("Align item to right"));
247 itemleft->setIcon(KIcon("kdenlive-align-left"));
248 itemleft->setToolTip(i18n("Align item to left"));
251 QHBoxLayout *layout = new QHBoxLayout;
252 frame_toolbar->setLayout(layout);
253 layout->setContentsMargins(0, 0, 0, 0);
254 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
255 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
256 m_toolbar->setIconSize(QSize(s, s));
258 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
259 m_buttonCursor->setCheckable(true);
260 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
261 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
262 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
264 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
265 m_buttonText->setCheckable(true);
266 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
267 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
268 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
270 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
271 m_buttonRect->setCheckable(true);
272 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
273 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
274 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
276 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
277 m_buttonImage->setCheckable(false);
278 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
279 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
280 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
282 m_toolbar->addSeparator();
284 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
285 m_buttonLoad->setCheckable(false);
286 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
287 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
289 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
290 m_buttonSave->setCheckable(false);
291 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
292 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
294 layout->addWidget(m_toolbar);
296 // initialize graphic scene
297 m_scene = new GraphicsSceneRectMove(this);
298 graphicsView->setScene(m_scene);
299 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
300 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
301 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
303 // a gradient background
304 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
305 gradient->setSpread(QGradient::ReflectSpread);
306 scene->setBackgroundBrush(*gradient);*/
308 m_frameImage = new QGraphicsPixmapItem();
310 qtrans.scale(2.0, 2.0);
311 m_frameImage->setTransform(qtrans);
312 m_frameImage->setZValue(-1200);
313 m_frameImage->setFlags(0);
314 displayBackgroundFrame();
315 graphicsView->scene()->addItem(m_frameImage);
317 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
318 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
319 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
320 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
321 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
322 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
323 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
324 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
326 QPen framepen(Qt::DotLine);
327 framepen.setColor(Qt::red);
329 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
330 m_frameBorder->setPen(framepen);
331 m_frameBorder->setZValue(-1100);
332 m_frameBorder->setBrush(Qt::transparent);
333 m_frameBorder->setFlags(0);
334 graphicsView->scene()->addItem(m_frameBorder);
336 // mbd: load saved settings
339 graphicsView->show();
340 //graphicsView->setRenderHint(QPainter::Antialiasing);
341 graphicsView->setInteractive(true);
342 //graphicsView->resize(400, 300);
343 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
344 //toolBox->setItemEnabled(2, false);
345 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
346 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
347 m_startViewport->setData(0, m_frameWidth);
348 m_startViewport->setData(1, m_frameHeight);
349 m_endViewport->setData(0, m_frameWidth);
350 m_endViewport->setData(1, m_frameHeight);
352 if (!url.isEmpty()) loadTitle(url);
355 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
358 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
359 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
361 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
364 TitleWidget::~TitleWidget()
368 delete m_buttonImage;
369 delete m_buttonCursor;
372 delete m_unicodeAction;
378 delete m_unicodeDialog;
379 delete m_frameBorder;
381 delete m_startViewport;
382 delete m_endViewport;
384 delete m_signalMapper;
388 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
391 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
392 KStandardDirs::makeDir(titlePath);
393 titlePath.append((isClone == false) ? "title" : "clone");
396 while (path.isEmpty() || QFile::exists(path)) {
398 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
400 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
406 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
409 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
410 KStandardDirs::makeDir(titlePath);
411 return titlePath + titleName + ".png";
415 QStringList TitleWidget::extractImageList(QString xml)
418 if (xml.isEmpty()) return result;
421 QDomNodeList images = doc.elementsByTagName("content");
422 for (int i = 0; i < images.count(); i++) {
423 if (images.at(i).toElement().hasAttribute("url"))
424 result.append(images.at(i).toElement().attribute("url"));
431 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
436 void TitleWidget::slotTextTool()
438 m_scene->setTool(TITLE_TEXT);
439 showToolbars(TITLE_TEXT);
440 checkButton(TITLE_TEXT);
443 void TitleWidget::slotRectTool()
445 m_scene->setTool(TITLE_RECTANGLE);
446 showToolbars(TITLE_RECTANGLE);
447 checkButton(TITLE_RECTANGLE);
450 void TitleWidget::slotSelectTool()
452 m_scene->setTool(TITLE_SELECT);
454 // Find out which toolbars need to be shown, depending on selected item
455 TITLETOOL t = TITLE_SELECT;
456 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
458 switch (l.at(0)->type()) {
472 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
473 //graphicsView->centerOn(l.at(0));
479 updateCoordinates(l.at(0));
480 updateDimension(l.at(0));
481 updateRotZoom(l.at(0));
484 checkButton(TITLE_SELECT);
487 void TitleWidget::slotImageTool()
489 // TODO: find a way to get a list of all supported image types...
490 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";
491 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
492 if (!url.isEmpty()) {
493 if (url.path().endsWith(".svg")) {
494 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
495 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
496 svg->setZValue(m_count++);
497 svg->setData(Qt::UserRole, url.path());
498 graphicsView->scene()->addItem(svg);
500 QPixmap pix(url.path());
501 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
502 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
503 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
504 image->setData(Qt::UserRole, url.path());
505 image->setZValue(m_count++);
506 graphicsView->scene()->addItem(image);
509 m_scene->setTool(TITLE_SELECT);
510 showToolbars(TITLE_SELECT);
511 checkButton(TITLE_SELECT);
514 void TitleWidget::showToolbars(TITLETOOL toolType)
516 toolbar_stack->setCurrentIndex((int) toolType);
519 void TitleWidget::enableToolbars(TITLETOOL toolType)
521 // TITLETOOL is defined in graphicsscenerectmove.h
523 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
524 value_w->setEnabled(enable);
525 value_h->setEnabled(enable);
528 void TitleWidget::checkButton(TITLETOOL toolType)
530 bool bSelect = false;
542 case TITLE_RECTANGLE:
552 m_buttonCursor->setChecked(bSelect);
553 m_buttonText->setChecked(bText);
554 m_buttonRect->setChecked(bRect);
555 m_buttonImage->setChecked(bImage);
558 void TitleWidget::displayBackgroundFrame()
560 if (!displayBg->isChecked()) {
561 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
562 QPixmap pattern(20, 20);
564 QColor bgcolor(210, 210, 210);
567 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
568 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
573 p.fillRect(bg.rect(), br);
575 m_frameImage->setPixmap(bg);
577 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
581 void TitleWidget::initAnimation()
583 align_box->setEnabled(false);
584 QPen startpen(Qt::DotLine);
585 QPen endpen(Qt::DashDotLine);
586 startpen.setColor(QColor(100, 200, 100, 140));
587 endpen.setColor(QColor(200, 100, 100, 140));
589 m_startViewport->setPen(startpen);
590 m_endViewport->setPen(endpen);
592 m_startViewport->setZValue(-1000);
593 m_endViewport->setZValue(-1000);
595 m_startViewport->setFlags(0);
596 m_endViewport->setFlags(0);
598 graphicsView->scene()->addItem(m_startViewport);
599 graphicsView->scene()->addItem(m_endViewport);
601 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
602 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
603 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
604 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
607 void TitleWidget::slotUpdateZoom(int pos)
609 m_scene->setZoom((double) pos / 100);
610 zoom_label->setText(QString::number(pos) + '%');
613 void TitleWidget::slotZoom(bool up)
615 int pos = zoom_slider->value();
618 zoom_slider->setValue(pos);
621 void TitleWidget::slotAdjustZoom()
623 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
624 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
625 if (scalex > scaley) scalex = scaley;
626 int zoompos = (int)(scalex * 7 + 0.5);*/
627 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
628 int zoompos = graphicsView->matrix().m11() * 100;
629 zoom_slider->setValue(zoompos);
630 graphicsView->centerOn(m_frameBorder);
633 void TitleWidget::slotZoomOneToOne()
635 zoom_slider->setValue(100);
636 graphicsView->centerOn(m_frameBorder);
639 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
641 updateAxisButtons(rect); // back to default
643 QColor f = rectFColor->color();
644 f.setAlpha(rectFAlpha->value());
646 penf.setWidth(rectLineWidth->value());
648 QColor b = rectBColor->color();
649 b.setAlpha(rectBAlpha->value());
650 rect->setBrush(QBrush(b));
651 rect->setZValue(m_count++);
652 //setCurrentItem(rect);
653 //graphicsView->setFocus();
656 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
658 updateAxisButtons(tt); // back to default
660 QFont font = font_family->currentFont();
661 font.setPixelSize(font_size->value());
663 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
664 font.setItalic(buttonItalic->isChecked());
665 font.setUnderline(buttonUnder->isChecked());
668 QColor color = fontColorButton->color();
669 color.setAlpha(textAlpha->value());
670 tt->setDefaultTextColor(color);
672 QTextCursor cur(tt->document());
673 cur.select(QTextCursor::Document);
674 QTextBlockFormat format = cur.blockFormat();
675 QTextCharFormat cformat = cur.charFormat();
676 QColor outlineColor = textOutlineColor->color();
677 outlineColor.setAlpha(textOutlineAlpha->value());
678 double outlineWidth = textOutline->value() / 10.0;
680 if (outlineWidth > 0.0) {
681 tt->setData(101, outlineWidth);
682 tt->setData(102, outlineColor);
683 cformat.setTextOutline(QPen(outlineColor, outlineWidth));
685 cformat.setForeground(QBrush(color));
686 cur.setCharFormat(cformat);
687 cur.setBlockFormat(format);
688 tt->setTextCursor(cur);
689 tt->setZValue(m_count++);
693 void TitleWidget::setFontBoxWeight(int weight)
695 int index = font_weight_box->findData(weight);
697 index = font_weight_box->findData(QFont::Normal);
699 font_weight_box->setCurrentIndex(index);
702 void TitleWidget::setCurrentItem(QGraphicsItem *item)
704 m_scene->setSelectedItem(item);
707 void TitleWidget::zIndexChanged(int v)
709 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
715 void TitleWidget::selectionChanged()
717 if (m_scene->tool() != TITLE_SELECT) return;
718 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
719 //toolBox->setItemEnabled(2, false);
720 //toolBox->setItemEnabled(3, false);
721 value_x->blockSignals(true);
722 value_y->blockSignals(true);
723 value_w->blockSignals(true);
724 value_h->blockSignals(true);
725 itemzoom->blockSignals(true);
726 itemrotate->blockSignals(true);
728 effect_stack->setHidden(true);
729 effect_frame->setEnabled(false);
730 effect_list->setCurrentIndex(0);
731 bool blockX = !origin_x_left->signalsBlocked();
732 bool blockY = !origin_y_top->signalsBlocked();
733 if (blockX) origin_x_left->blockSignals(true);
734 if (blockY) origin_y_top->blockSignals(true);
735 origin_x_left->setChecked(false);
736 origin_y_top->setChecked(false);
739 enableToolbars(TITLE_SELECT);
740 if (blockX) origin_x_left->blockSignals(false);
741 if (blockY) origin_y_top->blockSignals(false);
742 itemzoom->setEnabled(false);
743 itemrotate->setEnabled(false);
744 frame_properties->setEnabled(false);
745 } else if (l.size() == 1) {
746 effect_frame->setEnabled(true);
747 frame_properties->setEnabled(true);
748 if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
749 itemzoom->setEnabled(true);
750 itemrotate->setEnabled(true);
752 itemzoom->setEnabled(false);
753 itemrotate->setEnabled(false);
756 if (l.at(0)->type() == TEXTITEM) {
757 showToolbars(TITLE_TEXT);
758 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
759 if (!i->data(100).isNull()) {
760 // Item has an effect
761 QStringList effdata = i->data(100).toStringList();
762 QString effectName = effdata.takeFirst();
763 if (effectName == "typewriter") {
764 QStringList params = effdata.at(0).split(';');
765 typewriter_delay->setValue(params.at(0).toInt());
766 typewriter_start->setValue(params.at(1).toInt());
767 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
768 effect_stack->setHidden(false);
771 #if QT_VERSION >= 0x040600
772 if (i->graphicsEffect()) {
773 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
775 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
776 int rad = (int) blur->blurRadius();
777 blur_radius->setValue(rad);
778 effect_stack->setHidden(false);
780 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
782 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
783 shadow_radius->setValue(shad->blurRadius());
784 shadow_x->setValue(shad->xOffset());
785 shadow_y->setValue(shad->yOffset());
786 effect_stack->setHidden(false);
790 effect_list->blockSignals(true);
791 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
792 effect_list->blockSignals(false);
793 effect_stack->setHidden(true);
796 effect_list->blockSignals(true);
797 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
798 effect_list->blockSignals(false);
799 effect_stack->setHidden(true);
802 //if (l[0]->hasFocus())
803 //toolBox->setCurrentIndex(0);
804 //toolBox->setItemEnabled(2, true);
805 font_size->blockSignals(true);
806 font_family->blockSignals(true);
807 font_weight_box->blockSignals(true);
808 buttonItalic->blockSignals(true);
809 buttonUnder->blockSignals(true);
810 fontColorButton->blockSignals(true);
811 textAlpha->blockSignals(true);
812 buttonAlignLeft->blockSignals(true);
813 buttonAlignRight->blockSignals(true);
814 buttonAlignNone->blockSignals(true);
815 buttonAlignCenter->blockSignals(true);
817 QFont font = i->font();
818 font_family->setCurrentFont(font);
819 font_size->setValue(font.pixelSize());
820 m_scene->slotUpdateFontSize(font.pixelSize());
821 buttonItalic->setChecked(font.italic());
822 buttonUnder->setChecked(font.underline());
823 setFontBoxWeight(font.weight());
825 QTextCursor cursor(i->document());
826 cursor.select(QTextCursor::Document);
827 QColor color = cursor.charFormat().foreground().color();
828 fontColorButton->setColor(color);
829 textAlpha->setValue(color.alpha());
831 if (!i->data(101).isNull()) {
832 textOutline->blockSignals(true);
833 textOutline->setValue(i->data(101).toDouble()*10);
834 textOutline->blockSignals(false);
836 if (!i->data(102).isNull()) {
837 textOutlineColor->blockSignals(true);
838 textOutlineAlpha->blockSignals(true);
839 textOutlineColor->setColor(i->data(102).toString());
840 textOutlineAlpha->setValue(QColor(i->data(102).toString()).alpha());
841 textOutlineColor->blockSignals(false);
842 textOutlineAlpha->blockSignals(false);
844 QTextCursor cur = i->textCursor();
845 QTextBlockFormat format = cur.blockFormat();
846 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
847 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
848 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
849 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
851 font_size->blockSignals(false);
852 font_family->blockSignals(false);
853 font_weight_box->blockSignals(false);
854 buttonItalic->blockSignals(false);
855 buttonUnder->blockSignals(false);
856 fontColorButton->blockSignals(false);
857 textAlpha->blockSignals(false);
858 buttonAlignLeft->blockSignals(false);
859 buttonAlignRight->blockSignals(false);
860 buttonAlignNone->blockSignals(false);
861 buttonAlignCenter->blockSignals(false);
863 updateAxisButtons(i);
864 updateCoordinates(i);
866 enableToolbars(TITLE_TEXT);
868 } else if ((l.at(0))->type() == RECTITEM) {
869 showToolbars(TITLE_RECTANGLE);
871 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
872 if (rec == m_startViewport || rec == m_endViewport) {
873 /*toolBox->setCurrentIndex(3);
874 toolBox->widget(0)->setEnabled(false);
875 toolBox->widget(1)->setEnabled(false);*/
876 enableToolbars(TITLE_SELECT);
878 /*toolBox->widget(0)->setEnabled(true);
879 toolBox->widget(1)->setEnabled(true);
880 toolBox->setCurrentIndex(0);*/
881 //toolBox->setItemEnabled(3, true);
882 rectFAlpha->setValue(rec->pen().color().alpha());
883 rectBAlpha->setValue(rec->brush().color().alpha());
884 //kDebug() << rec->brush().color().alpha();
885 QColor fcol = rec->pen().color();
886 QColor bcol = rec->brush().color();
887 //fcol.setAlpha(255);
888 //bcol.setAlpha(255);
889 rectFColor->setColor(fcol);
890 rectBColor->setColor(bcol);
892 rectLineWidth->setValue(rec->pen().width());
893 enableToolbars(TITLE_RECTANGLE);
896 updateAxisButtons(l.at(0));
897 updateCoordinates(rec);
898 updateDimension(rec);
900 } else if (l.at(0)->type() == IMAGEITEM) {
901 showToolbars(TITLE_IMAGE);
903 updateCoordinates(l.at(0));
904 updateDimension(l.at(0));
906 enableToolbars(TITLE_IMAGE);
909 //toolBox->setCurrentIndex(0);
910 showToolbars(TITLE_SELECT);
911 enableToolbars(TITLE_SELECT);
912 frame_properties->setEnabled(false);
914 zValue->setValue((int)l.at(0)->zValue());
915 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
916 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
917 value_x->blockSignals(false);
918 value_y->blockSignals(false);
919 value_w->blockSignals(false);
920 value_h->blockSignals(false);
921 itemzoom->blockSignals(false);
922 itemrotate->blockSignals(false);
926 void TitleWidget::slotValueChanged(int type)
928 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
929 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
934 val = value_w->value();
937 val = value_h->value();
941 QGraphicsItem *i = l.at(0);
942 Transform t = m_transformations.value(i);
944 // Ratio width:height
945 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
946 double alpha = (double) t.rotate / 180.0 * M_PI;
956 // Add 0.5 because otherwise incrementing by 1 might have no effect
957 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
958 scale = length / i->boundingRect().width();
961 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
962 scale = length / i->boundingRect().height();
969 qtrans.scale(scale, scale);
970 qtrans.rotate(t.rotate);
971 i->setTransform(qtrans);
972 m_transformations[i] = t;
979 /** \brief Updates position/size of the selected item when a value
980 * of an item (coordinates, size) has changed */
981 void TitleWidget::slotAdjustSelectedItem()
983 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
985 if (l.at(0)->type() == RECTITEM) {
987 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
989 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
990 } else if (l.at(0)->type() == TEXTITEM) {
992 updatePosition(l.at(0));
993 } else if (l.at(0)->type() == IMAGEITEM) {
995 updatePosition(l.at(0));
1000 /** \brief Updates width/height int the text fields, regarding transformation matrix */
1001 void TitleWidget::updateDimension(QGraphicsItem *i)
1003 value_w->blockSignals(true);
1004 value_h->blockSignals(true);
1005 zValue->blockSignals(true);
1007 zValue->setValue((int) i->zValue());
1008 if (i->type() == IMAGEITEM) {
1009 // Get multipliers for rotation/scaling
1011 /*Transform t = m_transformations.value(i);
1012 QRectF r = i->boundingRect();
1013 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1014 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1015 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1016 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1018 value_w->setValue(i->sceneBoundingRect().width());
1019 value_h->setValue(i->sceneBoundingRect().height());
1020 } else if (i->type() == RECTITEM) {
1021 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1022 value_w->setValue((int) r->rect().width());
1023 value_h->setValue((int) r->rect().height());
1024 } else if (i->type() == TEXTITEM) {
1025 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1026 value_w->setValue((int) t->boundingRect().width());
1027 value_h->setValue((int) t->boundingRect().height());
1030 zValue->blockSignals(false);
1031 value_w->blockSignals(false);
1032 value_h->blockSignals(false);
1035 /** \brief Updates the coordinates in the text fields from the item */
1036 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1038 // Block signals emitted by this method
1039 value_x->blockSignals(true);
1040 value_y->blockSignals(true);
1042 if (i->type() == TEXTITEM) {
1044 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1046 // Set the correct x coordinate value
1047 if (origin_x_left->isChecked()) {
1048 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1049 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1051 // Origin is at 0 (default)
1052 value_x->setValue((int) rec->pos().x());
1056 if (origin_y_top->isChecked()) {
1057 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1059 value_y->setValue((int) rec->pos().y());
1062 } else if (i->type() == RECTITEM) {
1064 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1066 if (origin_x_left->isChecked()) {
1067 // Origin (0 point) is at m_frameWidth
1068 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1070 // Origin is at 0 (default)
1071 value_x->setValue((int) rec->pos().x());
1074 if (origin_y_top->isChecked()) {
1075 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1077 value_y->setValue((int) rec->pos().y());
1080 } else if (i->type() == IMAGEITEM) {
1082 if (origin_x_left->isChecked()) {
1083 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1085 value_x->setValue((int) i->pos().x());
1088 if (origin_y_top->isChecked()) {
1089 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1091 value_y->setValue((int) i->pos().y());
1096 // Stop blocking signals now
1097 value_x->blockSignals(false);
1098 value_y->blockSignals(false);
1101 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1103 itemzoom->blockSignals(true);
1104 itemrotate->blockSignals(false);
1106 Transform t = m_transformations.value(i);
1107 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1108 itemrotate->setValue((int)(t.rotate));
1110 itemzoom->blockSignals(false);
1111 itemrotate->blockSignals(false);
1114 /** \brief Updates the position of an item by reading coordinates from the text fields */
1115 void TitleWidget::updatePosition(QGraphicsItem *i)
1117 if (i->type() == TEXTITEM) {
1118 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1121 if (origin_x_left->isChecked()) {
1122 /* Origin of the x axis is at m_frameWidth,
1123 * and distance from right border of the item to the right
1124 * border of the frame is taken.
1125 * See comment to slotOriginXClicked().
1127 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1129 posX = value_x->value();
1133 if (origin_y_top->isChecked()) {
1134 /* Same for y axis */
1135 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1137 posY = value_y->value();
1140 rec->setPos(posX, posY);
1142 } else if (i->type() == RECTITEM) {
1144 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1147 if (origin_x_left->isChecked()) {
1148 posX = m_frameWidth - value_x->value() - rec->rect().width();
1150 posX = value_x->value();
1154 if (origin_y_top->isChecked()) {
1155 posY = m_frameHeight - value_y->value() - rec->rect().height();
1157 posY = value_y->value();
1160 rec->setPos(posX, posY);
1162 } else if (i->type() == IMAGEITEM) {
1164 if (origin_x_left->isChecked()) {
1165 // Use the sceneBoundingRect because this also regards transformations like zoom
1166 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1168 posX = value_x->value();
1172 if (origin_y_top->isChecked()) {
1173 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1175 posY = value_y->value();
1178 i->setPos(posX, posY);
1184 void TitleWidget::updateTextOriginX()
1186 if (origin_x_left->isChecked()) {
1187 origin_x_left->setText(i18n("\u2212X"));
1189 origin_x_left->setText(i18n("+X"));
1193 void TitleWidget::slotOriginXClicked()
1195 // Update the text displayed on the button.
1196 updateTextOriginX();
1198 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1199 if (l.size() >= 1) {
1200 updateCoordinates(l.at(0));
1202 // Remember x axis setting
1203 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1204 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1206 graphicsView->setFocus();
1209 void TitleWidget::updateTextOriginY()
1211 if (origin_y_top->isChecked()) {
1212 origin_y_top->setText(i18n("\u2212Y"));
1214 origin_y_top->setText(i18n("+Y"));
1218 void TitleWidget::slotOriginYClicked()
1220 // Update the text displayed on the button.
1221 updateTextOriginY();
1223 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1224 if (l.size() >= 1) {
1225 updateCoordinates(l.at(0));
1227 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1228 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1231 graphicsView->setFocus();
1234 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1236 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1237 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1238 origin_x_left->blockSignals(true);
1239 origin_y_top->blockSignals(true);
1241 if (xAxis == TitleDocument::AxisInverted) {
1242 origin_x_left->setChecked(true);
1244 origin_x_left->setChecked(false);
1246 updateTextOriginX();
1248 if (yAxis == TitleDocument::AxisInverted) {
1249 origin_y_top->setChecked(true);
1251 origin_y_top->setChecked(false);
1253 updateTextOriginY();
1255 origin_x_left->blockSignals(false);
1256 origin_y_top->blockSignals(false);
1259 void TitleWidget::slotChangeBackground()
1261 QColor color = kcolorbutton->color();
1262 color.setAlpha(horizontalSlider->value());
1263 m_frameBorder->setBrush(QBrush(color));
1267 * Something (yeah) has changed in our QGraphicsScene.
1269 void TitleWidget::slotChanged()
1271 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1272 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1273 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1278 * If the user has set origin_x_left (everything also for y),
1279 * we need to look whether a text element has been selected. If yes,
1280 * we need to ensure that the right border of the text field
1281 * remains fixed also when some text has been entered.
1283 * This is also known as right-justified, with the difference that
1284 * it is not valid for text but for its boundingRect. Text may still
1285 * be left-justified.
1287 void TitleWidget::textChanged(QGraphicsTextItem *i)
1292 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1294 if (!i->toPlainText().isEmpty()) {
1298 * Don't do anything if the string is empty. If the position
1299 * would be updated here, a newly created text field would
1300 * be set to the position of the last selected text field.
1306 void TitleWidget::slotInsertUnicode()
1308 m_unicodeDialog->exec();
1311 void TitleWidget::slotInsertUnicodeString(QString text)
1313 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1315 if (l.at(0)->type() == TEXTITEM) {
1316 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1317 t->textCursor().insertText(text);
1322 void TitleWidget::slotUpdateText()
1324 QFont font = font_family->currentFont();
1325 font.setPixelSize(font_size->value());
1326 font.setItalic(buttonItalic->isChecked());
1327 font.setUnderline(buttonUnder->isChecked());
1328 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1329 QColor color = fontColorButton->color();
1330 color.setAlpha(textAlpha->value());
1332 QColor outlineColor = textOutlineColor->color();
1333 outlineColor.setAlpha(textOutlineAlpha->value());
1334 double outlineWidth = textOutline->value() / 10.0;
1335 QGraphicsTextItem* item = NULL;
1336 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1337 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1338 item = static_cast <QGraphicsTextItem *>(l.at(0));
1341 //if (item->textCursor().selection ().isEmpty())
1342 QTextCursor cur(item->document());
1343 cur.select(QTextCursor::Document);
1344 QTextBlockFormat format = cur.blockFormat();
1345 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1346 item->setTextWidth(item->boundingRect().width());
1347 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1348 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1349 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1351 format.setAlignment(Qt::AlignLeft);
1352 item->setTextWidth(-1);
1355 item->setFont(font);
1356 QTextCharFormat cformat = cur.charFormat();
1357 if (outlineWidth > 0.0) {
1358 item->setData(101, outlineWidth);
1359 item->setData(102, outlineColor);
1360 cformat.setTextOutline(QPen(outlineColor, outlineWidth));
1362 cformat.setForeground(QBrush(color));
1363 cur.setCharFormat(cformat);
1364 cur.setBlockFormat(format);
1365 item->setTextCursor(cur);
1366 cur.clearSelection();
1367 item->setTextCursor(cur);
1370 void TitleWidget::rectChanged()
1372 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1373 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1374 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1375 QColor f = rectFColor->color();
1376 f.setAlpha(rectFAlpha->value());
1378 penf.setWidth(rectLineWidth->value());
1380 QColor b = rectBColor->color();
1381 b.setAlpha(rectBAlpha->value());
1382 rec->setBrush(QBrush(b));
1386 void TitleWidget::itemScaled(int val)
1388 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1389 if (l.size() == 1) {
1390 Transform x = m_transformations.value(l.at(0));
1391 x.scalex = (double)val / 100.0;
1392 x.scaley = (double)val / 100.0;
1394 qtrans.scale(x.scalex, x.scaley);
1395 qtrans.rotate(x.rotate);
1396 l[0]->setTransform(qtrans);
1397 m_transformations[l.at(0)] = x;
1398 updateDimension(l.at(0));
1402 void TitleWidget::itemRotate(int val)
1404 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1405 if (l.size() == 1) {
1406 Transform x = m_transformations[l.at(0)];
1407 x.rotate = (double)val;
1409 qtrans.scale(x.scalex, x.scaley);
1410 qtrans.rotate(x.rotate);
1411 l[0]->setTransform(qtrans);
1412 m_transformations[l.at(0)] = x;
1413 updateDimension(l.at(0));
1417 void TitleWidget::itemHCenter()
1419 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1420 if (l.size() == 1) {
1421 QGraphicsItem *item = l.at(0);
1422 QRectF br = item->sceneBoundingRect();
1423 int width = (int)br.width();
1424 int newPos = (int)((m_frameWidth - width) / 2);
1425 newPos += item->pos().x() - br.left(); // Check item transformation
1426 item->setPos(newPos, item->pos().y());
1427 updateCoordinates(item);
1431 void TitleWidget::itemVCenter()
1433 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1434 if (l.size() == 1) {
1435 QGraphicsItem *item = l.at(0);
1436 QRectF br = item->sceneBoundingRect();
1437 int height = (int)br.height();
1438 int newPos = (int)((m_frameHeight - height) / 2);
1439 newPos += item->pos().y() - br.top(); // Check item transformation
1440 item->setPos(item->pos().x(), newPos);
1441 updateCoordinates(item);
1445 void TitleWidget::itemTop()
1447 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1448 if (l.size() == 1) {
1449 QGraphicsItem *item = l.at(0);
1450 QRectF br = item->sceneBoundingRect();
1452 if (br.top() > 0) diff = -br.top();
1453 else diff = -br.bottom();
1454 item->moveBy(0, diff);
1455 updateCoordinates(item);
1459 void TitleWidget::itemBottom()
1461 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1462 if (l.size() == 1) {
1463 QGraphicsItem *item = l.at(0);
1464 QRectF br = item->sceneBoundingRect();
1466 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1467 else diff = m_frameHeight - br.bottom();
1468 item->moveBy(0, diff);
1469 updateCoordinates(item);
1473 void TitleWidget::itemLeft()
1475 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1476 if (l.size() == 1) {
1477 QGraphicsItem *item = l.at(0);
1478 QRectF br = item->sceneBoundingRect();
1480 if (br.left() > 0) diff = -br.left();
1481 else diff = -br.right();
1482 item->moveBy(diff, 0);
1483 updateCoordinates(item);
1487 void TitleWidget::itemRight()
1489 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1490 if (l.size() == 1) {
1491 QGraphicsItem *item = l.at(0);
1492 QRectF br = item->sceneBoundingRect();
1494 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1495 else diff = m_frameWidth - br.left();
1496 item->moveBy(diff, 0);
1497 updateCoordinates(item);
1501 void TitleWidget::setupViewports()
1503 //double aspect_ratio = 4.0 / 3.0;//read from project
1504 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1505 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1506 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1507 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1508 QPolygonF spoly(sp);
1509 QPolygonF epoly(ep);
1510 spoly.translate(startViewportX->value(), startViewportY->value());
1511 epoly.translate(endViewportX->value(), endViewportY->value());
1512 m_startViewport->setPolygon(spoly);
1513 m_endViewport->setPolygon(epoly);
1514 if (! insertingValues) {
1515 m_startViewport->setData(0, startViewportX->value());
1516 m_startViewport->setData(1, startViewportY->value());
1517 m_startViewport->setData(2, startViewportSize->value());
1519 m_endViewport->setData(0, endViewportX->value());
1520 m_endViewport->setData(1, endViewportY->value());
1521 m_endViewport->setData(2, endViewportSize->value());
1525 void TitleWidget::loadTitle(KUrl url)
1527 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1528 if (!url.isEmpty()) {
1529 QList<QGraphicsItem *> items = m_scene->items();
1530 for (int i = 0; i < items.size(); i++) {
1531 if (items.at(i)->zValue() > -1000) delete items.at(i);
1533 m_scene->clearTextSelection();
1537 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1538 QFile file(tmpfile);
1539 if (file.open(QIODevice::ReadOnly)) {
1540 doc.setContent(&file, false);
1543 KIO::NetAccess::removeTempFile(tmpfile);
1548 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1550 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1551 insertingValues = true;
1552 startViewportX->setValue(m_startViewport->data(0).toInt());
1553 startViewportY->setValue(m_startViewport->data(1).toInt());
1554 startViewportSize->setValue(m_startViewport->data(2).toInt());
1555 endViewportX->setValue(m_endViewport->data(0).toInt());
1556 endViewportY->setValue(m_endViewport->data(1).toInt());
1557 endViewportSize->setValue(m_endViewport->data(2).toInt());
1559 insertingValues = false;
1565 void TitleWidget::saveTitle(KUrl url)
1567 if (anim_start->isChecked()) slotAnimStart(false);
1568 if (anim_end->isChecked()) slotAnimEnd(false);
1569 if (url.isEmpty()) {
1570 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1571 fs->setOperationMode(KFileDialog::Saving);
1572 fs->setMode(KFile::File);
1573 #if KDE_IS_VERSION(4,2,0)
1574 fs->setConfirmOverwrite(true);
1576 fs->setKeepLocation(true);
1578 url = fs->selectedUrl();
1581 if (!url.isEmpty()) {
1582 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1583 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1587 QDomDocument TitleWidget::xml()
1589 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1590 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1594 int TitleWidget::duration() const
1596 return m_tc.getFrameCount(title_duration->text());
1599 void TitleWidget::setXml(QDomDocument doc)
1602 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1604 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1605 /*if (doc.documentElement().hasAttribute("out")) {
1606 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1607 title_duration->setText(m_tc.getTimecode(duration));
1609 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1611 QDomElement e = doc.documentElement();
1612 m_transformations.clear();
1613 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1614 const double PI = 4.0 * atan(1.0);
1615 for (int i = 0; i < items.count(); i++) {
1616 QTransform t = items.at(i)->transform();
1620 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1621 m_transformations[items.at(i)] = x;
1623 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1624 QColor background_color = m_titledocument.getBackgroundColor();
1625 horizontalSlider->blockSignals(true);
1626 kcolorbutton->blockSignals(true);
1627 horizontalSlider->setValue(background_color.alpha());
1628 background_color.setAlpha(255);
1629 kcolorbutton->setColor(background_color);
1630 horizontalSlider->blockSignals(false);
1631 kcolorbutton->blockSignals(false);
1633 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1634 startViewportY->setValue(m_startViewport->data(1).toInt());
1635 startViewportSize->setValue(m_startViewport->data(2).toInt());
1636 endViewportX->setValue(m_endViewport->data(0).toInt());
1637 endViewportY->setValue(m_endViewport->data(1).toInt());
1638 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1640 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1644 /** \brief Connected to the accepted signal - calls writeChoices */
1645 void TitleWidget::slotAccepted()
1647 if (anim_start->isChecked()) slotAnimStart(false);
1648 if (anim_end->isChecked()) slotAnimEnd(false);
1652 /** \brief Store the current choices of font, background and rect values */
1653 void TitleWidget::writeChoices()
1655 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1656 KSharedConfigPtr config = KGlobal::config();
1657 KConfigGroup titleConfig(config, "TitleWidget");
1658 // Write the entries
1659 titleConfig.writeEntry("font_family", font_family->currentFont());
1660 //titleConfig.writeEntry("font_size", font_size->value());
1661 titleConfig.writeEntry("font_pixel_size", font_size->value());
1662 titleConfig.writeEntry("font_color", fontColorButton->color());
1663 titleConfig.writeEntry("font_alpha", textAlpha->value());
1664 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1665 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1666 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1668 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1669 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1670 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1671 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1672 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1674 titleConfig.writeEntry("background_color", kcolorbutton->color());
1675 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1677 //! \todo Not sure if I should sync - it is probably safe to do it
1682 /** \brief Read the last stored choices into the dialog */
1683 void TitleWidget::readChoices()
1685 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1686 KSharedConfigPtr config = KGlobal::config();
1687 KConfigGroup titleConfig(config, "TitleWidget");
1689 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1690 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1691 m_scene->slotUpdateFontSize(font_size->value());
1692 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1693 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1695 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1696 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1697 setFontBoxWeight(weight);
1698 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1699 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1701 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1702 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1703 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1704 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1705 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1707 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1708 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1711 void TitleWidget::adjustFrameSize()
1713 m_frameWidth = m_titledocument.frameWidth();
1714 m_frameHeight = m_titledocument.frameHeight();
1715 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1716 displayBackgroundFrame();
1719 void TitleWidget::slotAnimStart(bool anim)
1721 if (anim && anim_end->isChecked()) {
1722 anim_end->setChecked(false);
1723 m_endViewport->setZValue(-1000);
1724 m_endViewport->setBrush(QBrush());
1727 QList<QGraphicsItem *> list = m_scene->items();
1728 for (int i = 0; i < list.count(); i++) {
1729 if (list.at(i)->zValue() > -1000) {
1730 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1731 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1734 align_box->setEnabled(anim);
1735 itemzoom->setEnabled(!anim);
1736 itemrotate->setEnabled(!anim);
1737 frame_toolbar->setEnabled(!anim);
1738 toolbar_stack->setEnabled(!anim);
1740 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1741 m_startViewport->setZValue(1100);
1742 QColor col = m_startViewport->pen().color();
1744 m_startViewport->setBrush(col);
1745 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1746 m_startViewport->setSelected(true);
1749 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1751 m_startViewport->setZValue(-1000);
1752 m_startViewport->setBrush(QBrush());
1753 m_startViewport->setFlags(0);
1754 if (!anim_end->isChecked()) deleteAnimInfoText();
1759 void TitleWidget::slotAnimEnd(bool anim)
1761 if (anim && anim_start->isChecked()) {
1762 anim_start->setChecked(false);
1763 m_startViewport->setZValue(-1000);
1764 m_startViewport->setBrush(QBrush());
1767 QList<QGraphicsItem *> list = m_scene->items();
1768 for (int i = 0; i < list.count(); i++) {
1769 if (list.at(i)->zValue() > -1000) {
1770 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1771 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1774 align_box->setEnabled(anim);
1775 itemzoom->setEnabled(!anim);
1776 itemrotate->setEnabled(!anim);
1777 frame_toolbar->setEnabled(!anim);
1778 toolbar_stack->setEnabled(!anim);
1780 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1781 m_endViewport->setZValue(1100);
1782 QColor col = m_endViewport->pen().color();
1784 m_endViewport->setBrush(col);
1785 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1786 m_endViewport->setSelected(true);
1789 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
1791 m_endViewport->setZValue(-1000);
1792 m_endViewport->setBrush(QBrush());
1793 m_endViewport->setFlags(0);
1794 if (!anim_start->isChecked()) deleteAnimInfoText();
1798 void TitleWidget::addAnimInfoText()
1800 // add text to anim viewport
1801 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
1802 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
1803 QFont font = t->font();
1804 font.setPixelSize(m_startViewport->rect().width() / 10);
1805 QColor col = m_startViewport->pen().color();
1807 t->setDefaultTextColor(col);
1809 font.setPixelSize(m_endViewport->rect().width() / 10);
1810 col = m_endViewport->pen().color();
1812 t2->setDefaultTextColor(col);
1816 void TitleWidget::updateInfoText()
1818 // update info text font
1819 if (!m_startViewport->childItems().isEmpty()) {
1820 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
1822 QFont font = item->font();
1823 font.setPixelSize(m_startViewport->rect().width() / 10);
1824 item->setFont(font);
1827 if (!m_endViewport->childItems().isEmpty()) {
1828 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
1830 QFont font = item->font();
1831 font.setPixelSize(m_endViewport->rect().width() / 10);
1832 item->setFont(font);
1837 void TitleWidget::deleteAnimInfoText()
1839 // end animation editing, remove info text
1840 while (!m_startViewport->childItems().isEmpty()) {
1841 QGraphicsItem *item = m_startViewport->childItems().at(0);
1842 m_scene->removeItem(item);
1845 while (!m_endViewport->childItems().isEmpty()) {
1846 QGraphicsItem *item = m_endViewport->childItems().at(0);
1847 m_scene->removeItem(item);
1853 void TitleWidget::slotKeepAspect(bool keep)
1855 if (m_endViewport->zValue() == 1100) {
1856 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1857 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1859 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1860 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1864 void TitleWidget::slotResize50()
1866 if (m_endViewport->zValue() == 1100) {
1867 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1868 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1871 void TitleWidget::slotResize100()
1873 if (m_endViewport->zValue() == 1100) {
1874 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1875 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1878 void TitleWidget::slotResize200()
1880 if (m_endViewport->zValue() == 1100) {
1881 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1882 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1885 void TitleWidget::slotAddEffect(int ix)
1887 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1888 int effect = effect_list->itemData(ix).toInt();
1889 if (effect == NOEFFECT) {
1890 if (l.size() == 1) l[0]->setData(100, QVariant());
1891 effect_stack->setHidden(true);
1894 effect_stack->setCurrentIndex(effect - 1);
1895 effect_stack->setHidden(false);
1896 if (effect == TYPEWRITEREFFECT) {
1897 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1898 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1899 l[0]->setData(100, effdata);
1902 #if QT_VERSION < 0x040600
1905 if (effect == BLUREFFECT) {
1907 if (l.size() == 1) {
1908 QGraphicsEffect *eff = new QGraphicsBlurEffect();
1909 l[0]->setGraphicsEffect(eff);
1911 } else if (effect == SHADOWEFFECT) {
1912 if (l.size() == 1) {
1913 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
1914 l[0]->setGraphicsEffect(eff);
1922 void TitleWidget::slotFontText(const QString& s)
1925 if (f.exactMatch()) {
1926 // Font really exists (could also just be a «d» if the user
1927 // starts typing «dejavu» for example).
1928 font_family->setCurrentFont(f);
1930 // Note: Typing dejavu serif does not recognize the font (takes sans)
1931 // in older Qt versions.
1934 void TitleWidget::slotEditTypewriter(int ix)
1936 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1937 if (l.size() == 1) {
1938 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1939 l[0]->setData(100, effdata);
1943 void TitleWidget::slotEditBlur(int ix)
1945 #if QT_VERSION < 0x040600
1948 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1949 if (l.size() == 1) {
1950 QGraphicsEffect *eff = l[0]->graphicsEffect();
1951 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
1952 if (blur) blur->setBlurRadius(ix);
1957 void TitleWidget::slotEditShadow()
1959 #if QT_VERSION < 0x040600
1962 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1963 if (l.size() == 1) {
1964 QGraphicsEffect *eff = l[0]->graphicsEffect();
1965 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
1967 shadow->setBlurRadius(shadow_radius->value());
1968 shadow->setOffset(shadow_x->value(), shadow_y->value());
1974 qreal TitleWidget::zIndexBounds(bool maxBound)
1976 qreal bound = maxBound ? -99 : 99;
1977 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1979 QList<QGraphicsItem*> lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
1980 if (lItems.size() > 0) {
1981 int n = lItems.size();
1984 for (int i = 0; i < n; i++) {
1985 z = lItems[i]->zValue();
1986 if (z > bound && !lItems[i]->isSelected()) {
1991 // Get minimum z index.
1992 for (int i = 0; i < n; i++) {
1993 z = lItems[i]->zValue();
1994 if (z < bound && !lItems[i]->isSelected() && z > -999) {
1995 // There are items at the very bottom (background e.g.) with z-index < -1000.
2005 void TitleWidget::slotZIndexUp()
2007 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2008 if (l.size() >= 1) {
2009 qreal currentZ = l[0]->zValue();
2010 qreal max = zIndexBounds(true);
2011 if (currentZ <= max) {
2012 l[0]->setZValue(currentZ + 1);
2013 updateDimension(l[0]);
2018 void TitleWidget::slotZIndexTop()
2020 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2021 if (l.size() >= 1) {
2022 qreal currentZ = l[0]->zValue();
2023 qreal max = zIndexBounds(true);
2024 if (currentZ <= max) {
2025 l[0]->setZValue(max + 1);
2026 updateDimension(l[0]);
2031 void TitleWidget::slotZIndexDown()
2033 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2034 if (l.size() >= 1) {
2035 qreal currentZ = l[0]->zValue();
2036 qreal min = zIndexBounds(false);
2037 if (currentZ >= min) {
2038 l[0]->setZValue(currentZ - 1);
2039 updateDimension(l[0]);
2044 void TitleWidget::slotZIndexBottom()
2046 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2047 if (l.size() >= 1) {
2048 qreal currentZ = l[0]->zValue();
2049 qreal min = zIndexBounds(false);
2050 if (currentZ >= min) {
2051 l[0]->setZValue(min - 1);
2052 updateDimension(l[0]);