1 /***************************************************************************
2 titlewidget.cpp - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "titlewidget.h"
19 #include "kdenlivesettings.h"
20 #include "KoSliderCombo.h"
25 #include <KGlobalSettings>
26 #include <KFileDialog>
27 #include <KStandardDirs>
28 #include <KMessageBox>
29 #include <kio/netaccess.h>
30 #include <kdeversion.h>
32 #include <QDomDocument>
33 #include <QGraphicsItem>
34 #include <QGraphicsSvgItem>
38 #include <QSignalMapper>
39 #include <QTextBlockFormat>
40 #include <QTextCursor>
42 #if QT_VERSION >= 0x040600
43 #include <QGraphicsEffect>
44 #include <QGraphicsBlurEffect>
45 #include <QGraphicsDropShadowEffect>
48 int settingUp = false;
50 const int IMAGEITEM = 7;
51 const int RECTITEM = 3;
52 const int TEXTITEM = 8;
54 const int NOEFFECT = 0;
55 const int BLUREFFECT = 1;
56 const int SHADOWEFFECT = 2;
57 const int TYPEWRITEREFFECT = 3;
59 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
62 m_startViewport(NULL),
66 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
67 m_projectTitlePath(projectTitlePath),
71 setFont(KGlobalSettings::toolBarFont());
72 frame_properties->setEnabled(false);
73 frame_properties->setFixedHeight(frame_toolbar->height());
75 // Set combo sliders values
76 textAlpha->setMinimum(0);
77 textAlpha->setMaximum(255);
78 textAlpha->setDecimals(0);
79 textAlpha->setValue(255);
80 textAlpha->setToolTip(i18n("Font color opacity"));
82 textOutlineAlpha->setMinimum(0);
83 textOutlineAlpha->setMaximum(255);
84 textOutlineAlpha->setDecimals(0);
85 textOutlineAlpha->setValue(255);
86 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
88 textOutline->setMinimum(0);
89 textOutline->setMaximum(200);
90 textOutline->setDecimals(0);
91 textOutline->setValue(0);
92 textOutline->setToolTip(i18n("Outline width"));
94 backgroundAlpha->setMinimum(0);
95 backgroundAlpha->setMaximum(255);
96 backgroundAlpha->setDecimals(0);
97 backgroundAlpha->setValue(0);
98 backgroundAlpha->setToolTip(i18n("Background color opacity"));
100 itemrotate->setMinimum(-360);
101 itemrotate->setMaximum(360);
102 itemrotate->setDecimals(0);
103 itemrotate->setValue(0);
104 itemrotate->setToolTip(i18n("Rotation"));
106 itemzoom->setSuffix(i18n("%"));
107 m_frameWidth = render->renderWidth();
108 m_frameHeight = render->renderHeight();
109 showToolbars(TITLE_SELECT);
111 //TODO: get default title duration instead of hardcoded one
112 title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0)));
114 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
115 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
117 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
118 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
119 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
120 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
121 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
122 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
123 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
124 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
126 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
128 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
129 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
130 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
131 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
132 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
134 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
135 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
136 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
137 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
138 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
139 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
142 effect_list->addItem(i18n("None"), NOEFFECT);
143 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
144 effect_list->addItem(i18n("Blur"), BLUREFFECT);
147 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
148 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
149 connect(itemrotate, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotate(qreal)));
150 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
151 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
152 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
153 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
154 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
155 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
156 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
157 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
158 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
159 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
160 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
161 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
162 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
163 effect_stack->setHidden(true);
164 effect_frame->setEnabled(false);
166 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
167 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
169 m_signalMapper = new QSignalMapper(this);
170 m_signalMapper->setMapping(value_w, ValueWidth);
171 m_signalMapper->setMapping(value_h, ValueHeight);
172 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
173 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
174 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
176 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
177 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
178 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
179 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
180 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
181 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
182 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
183 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
184 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
185 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
186 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
187 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
188 //connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
189 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
191 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
194 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
196 font_weight_box->blockSignals(true);
197 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
198 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
199 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
200 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
201 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
202 font_weight_box->setToolTip(i18n("Font weight"));
203 font_weight_box->setCurrentIndex(1);
204 font_weight_box->blockSignals(false);
206 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
207 buttonRealSize->setIcon(KIcon("zoom-original"));
208 buttonItalic->setIcon(KIcon("format-text-italic"));
209 buttonUnder->setIcon(KIcon("format-text-underline"));
210 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
211 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
212 buttonAlignRight->setIcon(KIcon("format-justify-right"));
213 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
215 buttonAlignNone->setToolTip(i18n("No alignment"));
216 buttonAlignRight->setToolTip(i18n("Align right"));
217 buttonAlignLeft->setToolTip(i18n("Align left"));
218 buttonAlignCenter->setToolTip(i18n("Align center"));
220 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
221 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
222 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
223 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
224 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
226 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
227 m_zUp->setShortcut(Qt::Key_PageUp);
228 m_zUp->setToolTip(i18n("Raise object"));
229 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
230 zUp->setDefaultAction(m_zUp);
232 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
233 m_zDown->setShortcut(Qt::Key_PageDown);
234 m_zDown->setToolTip(i18n("Lower object"));
235 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
236 zDown->setDefaultAction(m_zDown);
238 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
239 m_zTop->setShortcut(Qt::Key_Home);
240 m_zTop->setToolTip(i18n("Raise object to top"));
241 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
242 zTop->setDefaultAction(m_zTop);
244 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
245 m_zBottom->setShortcut(Qt::Key_End);
246 m_zBottom->setToolTip(i18n("Lower object to bottom"));
247 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
248 zBottom->setDefaultAction(m_zBottom);
250 zDown->setIcon(KIcon("kdenlive-zindex-down"));
251 zTop->setIcon(KIcon("kdenlive-zindex-top"));
252 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
253 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
254 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
255 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
257 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
258 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
259 rectBColor->setToolTip(i18n("Select fill color"));
260 rectFColor->setToolTip(i18n("Select border color"));
261 rectBAlpha->setToolTip(i18n("Fill transparency"));
262 rectFAlpha->setToolTip(i18n("Border transparency"));
263 zoom_slider->setToolTip(i18n("Zoom"));
264 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
265 buttonFitZoom->setToolTip(i18n("Fit zoom"));
266 backgroundColor->setToolTip(i18n("Select background color"));
267 backgroundAlpha->setToolTip(i18n("Background Transparency"));
269 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
270 itemhcenter->setToolTip(i18n("Align item horizontally"));
271 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
272 itemvcenter->setToolTip(i18n("Align item vertically"));
273 itemtop->setIcon(KIcon("kdenlive-align-top"));
274 itemtop->setToolTip(i18n("Align item to top"));
275 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
276 itembottom->setToolTip(i18n("Align item to bottom"));
277 itemright->setIcon(KIcon("kdenlive-align-right"));
278 itemright->setToolTip(i18n("Align item to right"));
279 itemleft->setIcon(KIcon("kdenlive-align-left"));
280 itemleft->setToolTip(i18n("Align item to left"));
283 QHBoxLayout *layout = new QHBoxLayout;
284 frame_toolbar->setLayout(layout);
285 layout->setContentsMargins(0, 0, 0, 0);
286 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
287 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
288 m_toolbar->setIconSize(QSize(s, s));
290 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
291 m_buttonCursor->setCheckable(true);
292 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
293 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
294 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
296 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
297 m_buttonText->setCheckable(true);
298 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
299 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
300 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
302 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
303 m_buttonRect->setCheckable(true);
304 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
305 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
306 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
308 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
309 m_buttonImage->setCheckable(false);
310 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
311 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
312 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
314 m_toolbar->addSeparator();
316 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
317 m_buttonLoad->setCheckable(false);
318 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
319 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
321 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
322 m_buttonSave->setCheckable(false);
323 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
324 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
326 layout->addWidget(m_toolbar);
328 // initialize graphic scene
329 m_scene = new GraphicsSceneRectMove(this);
330 graphicsView->setScene(m_scene);
331 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
332 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
333 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
335 // a gradient background
336 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
337 gradient->setSpread(QGradient::ReflectSpread);
338 scene->setBackgroundBrush(*gradient);*/
340 m_frameImage = new QGraphicsPixmapItem();
342 qtrans.scale(2.0, 2.0);
343 m_frameImage->setTransform(qtrans);
344 m_frameImage->setZValue(-1200);
345 m_frameImage->setFlags(0);
346 displayBackgroundFrame();
347 graphicsView->scene()->addItem(m_frameImage);
349 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
350 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
351 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
352 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
353 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
354 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
355 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
356 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
358 QPen framepen(Qt::DotLine);
359 framepen.setColor(Qt::red);
361 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
362 m_frameBorder->setPen(framepen);
363 m_frameBorder->setZValue(-1100);
364 m_frameBorder->setBrush(Qt::transparent);
365 m_frameBorder->setFlags(0);
366 graphicsView->scene()->addItem(m_frameBorder);
368 // mbd: load saved settings
371 graphicsView->show();
372 //graphicsView->setRenderHint(QPainter::Antialiasing);
373 graphicsView->setInteractive(true);
374 //graphicsView->resize(400, 300);
375 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
376 //toolBox->setItemEnabled(2, false);
377 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
378 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
379 m_startViewport->setData(0, m_frameWidth);
380 m_startViewport->setData(1, m_frameHeight);
381 m_endViewport->setData(0, m_frameWidth);
382 m_endViewport->setData(1, m_frameHeight);
384 if (!url.isEmpty()) loadTitle(url);
387 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
390 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
391 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
393 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
396 TitleWidget::~TitleWidget()
400 delete m_buttonImage;
401 delete m_buttonCursor;
404 delete m_unicodeAction;
410 delete m_unicodeDialog;
411 delete m_frameBorder;
413 delete m_startViewport;
414 delete m_endViewport;
416 delete m_signalMapper;
420 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
423 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
424 KStandardDirs::makeDir(titlePath);
425 titlePath.append((isClone == false) ? "title" : "clone");
428 while (path.isEmpty() || QFile::exists(path)) {
430 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
432 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
438 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
441 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
442 KStandardDirs::makeDir(titlePath);
443 return titlePath + titleName + ".png";
447 QStringList TitleWidget::extractImageList(QString xml)
450 if (xml.isEmpty()) return result;
453 QDomNodeList images = doc.elementsByTagName("content");
454 for (int i = 0; i < images.count(); i++) {
455 if (images.at(i).toElement().hasAttribute("url"))
456 result.append(images.at(i).toElement().attribute("url"));
463 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
468 void TitleWidget::slotTextTool()
470 m_scene->setTool(TITLE_TEXT);
471 showToolbars(TITLE_TEXT);
472 checkButton(TITLE_TEXT);
475 void TitleWidget::slotRectTool()
477 m_scene->setTool(TITLE_RECTANGLE);
478 showToolbars(TITLE_RECTANGLE);
479 checkButton(TITLE_RECTANGLE);
482 void TitleWidget::slotSelectTool()
484 m_scene->setTool(TITLE_SELECT);
486 // Find out which toolbars need to be shown, depending on selected item
487 TITLETOOL t = TITLE_SELECT;
488 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
490 switch (l.at(0)->type()) {
504 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
505 //graphicsView->centerOn(l.at(0));
511 updateCoordinates(l.at(0));
512 updateDimension(l.at(0));
513 updateRotZoom(l.at(0));
516 checkButton(TITLE_SELECT);
519 void TitleWidget::slotImageTool()
521 // TODO: find a way to get a list of all supported image types...
522 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";
523 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
524 if (!url.isEmpty()) {
525 if (url.path().endsWith(".svg")) {
526 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
527 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
528 svg->setZValue(m_count++);
529 svg->setData(Qt::UserRole, url.path());
530 graphicsView->scene()->addItem(svg);
532 QPixmap pix(url.path());
533 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
534 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
535 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
536 image->setData(Qt::UserRole, url.path());
537 image->setZValue(m_count++);
538 graphicsView->scene()->addItem(image);
541 m_scene->setTool(TITLE_SELECT);
542 showToolbars(TITLE_SELECT);
543 checkButton(TITLE_SELECT);
546 void TitleWidget::showToolbars(TITLETOOL toolType)
548 toolbar_stack->setCurrentIndex((int) toolType);
551 void TitleWidget::enableToolbars(TITLETOOL toolType)
553 // TITLETOOL is defined in graphicsscenerectmove.h
555 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
556 value_w->setEnabled(enable);
557 value_h->setEnabled(enable);
560 void TitleWidget::checkButton(TITLETOOL toolType)
562 bool bSelect = false;
574 case TITLE_RECTANGLE:
584 m_buttonCursor->setChecked(bSelect);
585 m_buttonText->setChecked(bText);
586 m_buttonRect->setChecked(bRect);
587 m_buttonImage->setChecked(bImage);
590 void TitleWidget::displayBackgroundFrame()
592 if (!displayBg->isChecked()) {
593 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
594 QPixmap pattern(20, 20);
596 QColor bgcolor(210, 210, 210);
599 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
600 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
605 p.fillRect(bg.rect(), br);
607 m_frameImage->setPixmap(bg);
609 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
613 void TitleWidget::initAnimation()
615 align_box->setEnabled(false);
616 QPen startpen(Qt::DotLine);
617 QPen endpen(Qt::DashDotLine);
618 startpen.setColor(QColor(100, 200, 100, 140));
619 endpen.setColor(QColor(200, 100, 100, 140));
621 m_startViewport->setPen(startpen);
622 m_endViewport->setPen(endpen);
624 m_startViewport->setZValue(-1000);
625 m_endViewport->setZValue(-1000);
627 m_startViewport->setFlags(0);
628 m_endViewport->setFlags(0);
630 graphicsView->scene()->addItem(m_startViewport);
631 graphicsView->scene()->addItem(m_endViewport);
633 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
634 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
635 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
636 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
639 void TitleWidget::slotUpdateZoom(int pos)
641 m_scene->setZoom((double) pos / 100);
642 zoom_label->setText(QString::number(pos) + '%');
645 void TitleWidget::slotZoom(bool up)
647 int pos = zoom_slider->value();
650 zoom_slider->setValue(pos);
653 void TitleWidget::slotAdjustZoom()
655 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
656 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
657 if (scalex > scaley) scalex = scaley;
658 int zoompos = (int)(scalex * 7 + 0.5);*/
659 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
660 int zoompos = graphicsView->matrix().m11() * 100;
661 zoom_slider->setValue(zoompos);
662 graphicsView->centerOn(m_frameBorder);
665 void TitleWidget::slotZoomOneToOne()
667 zoom_slider->setValue(100);
668 graphicsView->centerOn(m_frameBorder);
671 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
673 updateAxisButtons(rect); // back to default
675 QColor f = rectFColor->color();
676 f.setAlpha(rectFAlpha->value());
678 penf.setWidth(rectLineWidth->value());
680 QColor b = rectBColor->color();
681 b.setAlpha(rectBAlpha->value());
682 rect->setBrush(QBrush(b));
683 rect->setZValue(m_count++);
684 //setCurrentItem(rect);
685 //graphicsView->setFocus();
688 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
690 updateAxisButtons(tt); // back to default
692 QFont font = font_family->currentFont();
693 font.setPixelSize(font_size->value());
695 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
696 font.setItalic(buttonItalic->isChecked());
697 font.setUnderline(buttonUnder->isChecked());
700 QColor color = fontColorButton->color();
701 color.setAlpha(textAlpha->value());
702 tt->setDefaultTextColor(color);
704 QTextCursor cur(tt->document());
705 cur.select(QTextCursor::Document);
706 QTextBlockFormat format = cur.blockFormat();
707 QTextCharFormat cformat = cur.charFormat();
708 QColor outlineColor = textOutlineColor->color();
709 outlineColor.setAlpha(textOutlineAlpha->value());
710 double outlineWidth = textOutline->value() / 10.0;
712 tt->setData(101, outlineWidth);
713 tt->setData(102, outlineColor);
714 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
716 cformat.setForeground(QBrush(color));
717 cur.setCharFormat(cformat);
718 cur.setBlockFormat(format);
719 tt->setTextCursor(cur);
720 tt->setZValue(m_count++);
724 void TitleWidget::setFontBoxWeight(int weight)
726 int index = font_weight_box->findData(weight);
728 index = font_weight_box->findData(QFont::Normal);
730 font_weight_box->setCurrentIndex(index);
733 void TitleWidget::setCurrentItem(QGraphicsItem *item)
735 m_scene->setSelectedItem(item);
738 void TitleWidget::zIndexChanged(int v)
740 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
746 void TitleWidget::selectionChanged()
748 if (m_scene->tool() != TITLE_SELECT) return;
749 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
750 //toolBox->setItemEnabled(2, false);
751 //toolBox->setItemEnabled(3, false);
752 value_x->blockSignals(true);
753 value_y->blockSignals(true);
754 value_w->blockSignals(true);
755 value_h->blockSignals(true);
756 itemzoom->blockSignals(true);
757 itemrotate->blockSignals(true);
759 effect_stack->setHidden(true);
760 effect_frame->setEnabled(false);
761 effect_list->setCurrentIndex(0);
762 bool blockX = !origin_x_left->signalsBlocked();
763 bool blockY = !origin_y_top->signalsBlocked();
764 if (blockX) origin_x_left->blockSignals(true);
765 if (blockY) origin_y_top->blockSignals(true);
766 origin_x_left->setChecked(false);
767 origin_y_top->setChecked(false);
770 enableToolbars(TITLE_SELECT);
771 if (blockX) origin_x_left->blockSignals(false);
772 if (blockY) origin_y_top->blockSignals(false);
773 itemzoom->setEnabled(false);
774 itemrotate->setEnabled(false);
775 frame_properties->setEnabled(false);
776 } else if (l.size() == 1) {
777 effect_frame->setEnabled(true);
778 frame_properties->setEnabled(true);
779 if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
780 itemzoom->setEnabled(true);
781 itemrotate->setEnabled(true);
783 itemzoom->setEnabled(false);
784 itemrotate->setEnabled(false);
787 if (l.at(0)->type() == TEXTITEM) {
788 showToolbars(TITLE_TEXT);
789 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
790 if (!i->data(100).isNull()) {
791 // Item has an effect
792 QStringList effdata = i->data(100).toStringList();
793 QString effectName = effdata.takeFirst();
794 if (effectName == "typewriter") {
795 QStringList params = effdata.at(0).split(';');
796 typewriter_delay->setValue(params.at(0).toInt());
797 typewriter_start->setValue(params.at(1).toInt());
798 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
799 effect_stack->setHidden(false);
802 #if QT_VERSION >= 0x040600
803 if (i->graphicsEffect()) {
804 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
806 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
807 int rad = (int) blur->blurRadius();
808 blur_radius->setValue(rad);
809 effect_stack->setHidden(false);
811 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
813 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
814 shadow_radius->setValue(shad->blurRadius());
815 shadow_x->setValue(shad->xOffset());
816 shadow_y->setValue(shad->yOffset());
817 effect_stack->setHidden(false);
821 effect_list->blockSignals(true);
822 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
823 effect_list->blockSignals(false);
824 effect_stack->setHidden(true);
827 effect_list->blockSignals(true);
828 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
829 effect_list->blockSignals(false);
830 effect_stack->setHidden(true);
833 //if (l[0]->hasFocus())
834 //toolBox->setCurrentIndex(0);
835 //toolBox->setItemEnabled(2, true);
836 font_size->blockSignals(true);
837 font_family->blockSignals(true);
838 font_weight_box->blockSignals(true);
839 buttonItalic->blockSignals(true);
840 buttonUnder->blockSignals(true);
841 fontColorButton->blockSignals(true);
842 textAlpha->blockSignals(true);
843 buttonAlignLeft->blockSignals(true);
844 buttonAlignRight->blockSignals(true);
845 buttonAlignNone->blockSignals(true);
846 buttonAlignCenter->blockSignals(true);
848 QFont font = i->font();
849 font_family->setCurrentFont(font);
850 font_size->setValue(font.pixelSize());
851 m_scene->slotUpdateFontSize(font.pixelSize());
852 buttonItalic->setChecked(font.italic());
853 buttonUnder->setChecked(font.underline());
854 setFontBoxWeight(font.weight());
856 QTextCursor cursor(i->document());
857 cursor.select(QTextCursor::Document);
858 QColor color = cursor.charFormat().foreground().color();
859 textAlpha->setValue(color.alpha());
861 fontColorButton->setColor(color);
863 if (!i->data(101).isNull()) {
864 textOutline->blockSignals(true);
865 textOutline->setValue(i->data(101).toDouble()*10);
866 textOutline->blockSignals(false);
868 if (!i->data(102).isNull()) {
869 textOutlineColor->blockSignals(true);
870 textOutlineAlpha->blockSignals(true);
871 color = QColor(i->data(102).toString());
872 textOutlineAlpha->setValue(color.alpha());
874 textOutlineColor->setColor(color);
875 textOutlineColor->blockSignals(false);
876 textOutlineAlpha->blockSignals(false);
878 QTextCursor cur = i->textCursor();
879 QTextBlockFormat format = cur.blockFormat();
880 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
881 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
882 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
883 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
885 font_size->blockSignals(false);
886 font_family->blockSignals(false);
887 font_weight_box->blockSignals(false);
888 buttonItalic->blockSignals(false);
889 buttonUnder->blockSignals(false);
890 fontColorButton->blockSignals(false);
891 textAlpha->blockSignals(false);
892 buttonAlignLeft->blockSignals(false);
893 buttonAlignRight->blockSignals(false);
894 buttonAlignNone->blockSignals(false);
895 buttonAlignCenter->blockSignals(false);
897 updateAxisButtons(i);
898 updateCoordinates(i);
900 enableToolbars(TITLE_TEXT);
902 } else if ((l.at(0))->type() == RECTITEM) {
903 showToolbars(TITLE_RECTANGLE);
905 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
906 if (rec == m_startViewport || rec == m_endViewport) {
907 /*toolBox->setCurrentIndex(3);
908 toolBox->widget(0)->setEnabled(false);
909 toolBox->widget(1)->setEnabled(false);*/
910 enableToolbars(TITLE_SELECT);
912 /*toolBox->widget(0)->setEnabled(true);
913 toolBox->widget(1)->setEnabled(true);
914 toolBox->setCurrentIndex(0);*/
915 //toolBox->setItemEnabled(3, true);
916 rectFAlpha->setValue(rec->pen().color().alpha());
917 rectBAlpha->setValue(rec->brush().color().alpha());
918 //kDebug() << rec->brush().color().alpha();
919 QColor fcol = rec->pen().color();
920 QColor bcol = rec->brush().color();
921 //fcol.setAlpha(255);
922 //bcol.setAlpha(255);
923 rectFColor->setColor(fcol);
924 rectBColor->setColor(bcol);
926 rectLineWidth->setValue(rec->pen().width());
927 enableToolbars(TITLE_RECTANGLE);
930 updateAxisButtons(l.at(0));
931 updateCoordinates(rec);
932 updateDimension(rec);
934 } else if (l.at(0)->type() == IMAGEITEM) {
935 showToolbars(TITLE_IMAGE);
937 updateCoordinates(l.at(0));
938 updateDimension(l.at(0));
940 enableToolbars(TITLE_IMAGE);
943 //toolBox->setCurrentIndex(0);
944 showToolbars(TITLE_SELECT);
945 enableToolbars(TITLE_SELECT);
946 frame_properties->setEnabled(false);
948 zValue->setValue((int)l.at(0)->zValue());
949 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
950 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
951 value_x->blockSignals(false);
952 value_y->blockSignals(false);
953 value_w->blockSignals(false);
954 value_h->blockSignals(false);
955 itemzoom->blockSignals(false);
956 itemrotate->blockSignals(false);
960 void TitleWidget::slotValueChanged(int type)
962 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
963 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
968 val = value_w->value();
971 val = value_h->value();
975 QGraphicsItem *i = l.at(0);
976 Transform t = m_transformations.value(i);
978 // Ratio width:height
979 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
980 double alpha = (double) t.rotate / 180.0 * M_PI;
990 // Add 0.5 because otherwise incrementing by 1 might have no effect
991 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
992 scale = length / i->boundingRect().width();
995 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
996 scale = length / i->boundingRect().height();
1003 qtrans.scale(scale, scale);
1004 qtrans.rotate(t.rotate);
1005 i->setTransform(qtrans);
1006 m_transformations[i] = t;
1013 /** \brief Updates position/size of the selected item when a value
1014 * of an item (coordinates, size) has changed */
1015 void TitleWidget::slotAdjustSelectedItem()
1017 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1018 if (l.size() >= 1) {
1019 if (l.at(0)->type() == RECTITEM) {
1021 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1022 updatePosition(rec);
1023 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1024 } else if (l.at(0)->type() == TEXTITEM) {
1026 updatePosition(l.at(0));
1027 } else if (l.at(0)->type() == IMAGEITEM) {
1029 updatePosition(l.at(0));
1034 /** \brief Updates width/height int the text fields, regarding transformation matrix */
1035 void TitleWidget::updateDimension(QGraphicsItem *i)
1037 value_w->blockSignals(true);
1038 value_h->blockSignals(true);
1039 zValue->blockSignals(true);
1041 zValue->setValue((int) i->zValue());
1042 if (i->type() == IMAGEITEM) {
1043 // Get multipliers for rotation/scaling
1045 /*Transform t = m_transformations.value(i);
1046 QRectF r = i->boundingRect();
1047 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1048 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1049 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1050 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1052 value_w->setValue(i->sceneBoundingRect().width());
1053 value_h->setValue(i->sceneBoundingRect().height());
1054 } else if (i->type() == RECTITEM) {
1055 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1056 value_w->setValue((int) r->rect().width());
1057 value_h->setValue((int) r->rect().height());
1058 } else if (i->type() == TEXTITEM) {
1059 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1060 value_w->setValue((int) t->boundingRect().width());
1061 value_h->setValue((int) t->boundingRect().height());
1064 zValue->blockSignals(false);
1065 value_w->blockSignals(false);
1066 value_h->blockSignals(false);
1069 /** \brief Updates the coordinates in the text fields from the item */
1070 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1072 // Block signals emitted by this method
1073 value_x->blockSignals(true);
1074 value_y->blockSignals(true);
1076 if (i->type() == TEXTITEM) {
1078 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1080 // Set the correct x coordinate value
1081 if (origin_x_left->isChecked()) {
1082 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1083 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1085 // Origin is at 0 (default)
1086 value_x->setValue((int) rec->pos().x());
1090 if (origin_y_top->isChecked()) {
1091 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1093 value_y->setValue((int) rec->pos().y());
1096 } else if (i->type() == RECTITEM) {
1098 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1100 if (origin_x_left->isChecked()) {
1101 // Origin (0 point) is at m_frameWidth
1102 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1104 // Origin is at 0 (default)
1105 value_x->setValue((int) rec->pos().x());
1108 if (origin_y_top->isChecked()) {
1109 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1111 value_y->setValue((int) rec->pos().y());
1114 } else if (i->type() == IMAGEITEM) {
1116 if (origin_x_left->isChecked()) {
1117 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1119 value_x->setValue((int) i->pos().x());
1122 if (origin_y_top->isChecked()) {
1123 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1125 value_y->setValue((int) i->pos().y());
1130 // Stop blocking signals now
1131 value_x->blockSignals(false);
1132 value_y->blockSignals(false);
1135 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1137 itemzoom->blockSignals(true);
1138 itemrotate->blockSignals(false);
1140 Transform t = m_transformations.value(i);
1141 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1142 itemrotate->setValue((int)(t.rotate));
1144 itemzoom->blockSignals(false);
1145 itemrotate->blockSignals(false);
1148 /** \brief Updates the position of an item by reading coordinates from the text fields */
1149 void TitleWidget::updatePosition(QGraphicsItem *i)
1151 if (i->type() == TEXTITEM) {
1152 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1155 if (origin_x_left->isChecked()) {
1156 /* Origin of the x axis is at m_frameWidth,
1157 * and distance from right border of the item to the right
1158 * border of the frame is taken.
1159 * See comment to slotOriginXClicked().
1161 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1163 posX = value_x->value();
1167 if (origin_y_top->isChecked()) {
1168 /* Same for y axis */
1169 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1171 posY = value_y->value();
1174 rec->setPos(posX, posY);
1176 } else if (i->type() == RECTITEM) {
1178 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1181 if (origin_x_left->isChecked()) {
1182 posX = m_frameWidth - value_x->value() - rec->rect().width();
1184 posX = value_x->value();
1188 if (origin_y_top->isChecked()) {
1189 posY = m_frameHeight - value_y->value() - rec->rect().height();
1191 posY = value_y->value();
1194 rec->setPos(posX, posY);
1196 } else if (i->type() == IMAGEITEM) {
1198 if (origin_x_left->isChecked()) {
1199 // Use the sceneBoundingRect because this also regards transformations like zoom
1200 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1202 posX = value_x->value();
1206 if (origin_y_top->isChecked()) {
1207 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1209 posY = value_y->value();
1212 i->setPos(posX, posY);
1218 void TitleWidget::updateTextOriginX()
1220 if (origin_x_left->isChecked()) {
1221 origin_x_left->setText(i18n("\u2212X"));
1223 origin_x_left->setText(i18n("+X"));
1227 void TitleWidget::slotOriginXClicked()
1229 // Update the text displayed on the button.
1230 updateTextOriginX();
1232 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1233 if (l.size() >= 1) {
1234 updateCoordinates(l.at(0));
1236 // Remember x axis setting
1237 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1238 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1240 graphicsView->setFocus();
1243 void TitleWidget::updateTextOriginY()
1245 if (origin_y_top->isChecked()) {
1246 origin_y_top->setText(i18n("\u2212Y"));
1248 origin_y_top->setText(i18n("+Y"));
1252 void TitleWidget::slotOriginYClicked()
1254 // Update the text displayed on the button.
1255 updateTextOriginY();
1257 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1258 if (l.size() >= 1) {
1259 updateCoordinates(l.at(0));
1261 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1262 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1265 graphicsView->setFocus();
1268 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1270 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1271 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1272 origin_x_left->blockSignals(true);
1273 origin_y_top->blockSignals(true);
1275 if (xAxis == TitleDocument::AxisInverted) {
1276 origin_x_left->setChecked(true);
1278 origin_x_left->setChecked(false);
1280 updateTextOriginX();
1282 if (yAxis == TitleDocument::AxisInverted) {
1283 origin_y_top->setChecked(true);
1285 origin_y_top->setChecked(false);
1287 updateTextOriginY();
1289 origin_x_left->blockSignals(false);
1290 origin_y_top->blockSignals(false);
1293 void TitleWidget::slotChangeBackground()
1295 QColor color = backgroundColor->color();
1296 color.setAlpha(backgroundAlpha->value());
1297 m_frameBorder->setBrush(QBrush(color));
1301 * Something (yeah) has changed in our QGraphicsScene.
1303 void TitleWidget::slotChanged()
1305 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1306 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1307 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1312 * If the user has set origin_x_left (everything also for y),
1313 * we need to look whether a text element has been selected. If yes,
1314 * we need to ensure that the right border of the text field
1315 * remains fixed also when some text has been entered.
1317 * This is also known as right-justified, with the difference that
1318 * it is not valid for text but for its boundingRect. Text may still
1319 * be left-justified.
1321 void TitleWidget::textChanged(QGraphicsTextItem *i)
1326 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1328 if (!i->toPlainText().isEmpty()) {
1332 * Don't do anything if the string is empty. If the position
1333 * would be updated here, a newly created text field would
1334 * be set to the position of the last selected text field.
1340 void TitleWidget::slotInsertUnicode()
1342 m_unicodeDialog->exec();
1345 void TitleWidget::slotInsertUnicodeString(QString text)
1347 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1349 if (l.at(0)->type() == TEXTITEM) {
1350 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1351 t->textCursor().insertText(text);
1356 void TitleWidget::slotUpdateText()
1358 QFont font = font_family->currentFont();
1359 font.setPixelSize(font_size->value());
1360 font.setItalic(buttonItalic->isChecked());
1361 font.setUnderline(buttonUnder->isChecked());
1362 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1363 QColor color = fontColorButton->color();
1364 color.setAlpha(textAlpha->value());
1366 QColor outlineColor = textOutlineColor->color();
1367 outlineColor.setAlpha(textOutlineAlpha->value());
1368 double outlineWidth = textOutline->value() / 10.0;
1369 QGraphicsTextItem* item = NULL;
1370 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1371 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1372 item = static_cast <QGraphicsTextItem *>(l.at(0));
1375 //if (item->textCursor().selection ().isEmpty())
1376 QTextCursor cur(item->document());
1377 cur.select(QTextCursor::Document);
1378 QTextBlockFormat format = cur.blockFormat();
1379 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1380 item->setTextWidth(item->boundingRect().width());
1381 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1382 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1383 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1385 format.setAlignment(Qt::AlignLeft);
1386 item->setTextWidth(-1);
1389 item->setFont(font);
1390 QTextCharFormat cformat = cur.charFormat();
1392 item->setData(101, outlineWidth);
1393 item->setData(102, outlineColor);
1394 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
1396 cformat.setForeground(QBrush(color));
1397 cur.setCharFormat(cformat);
1398 cur.setBlockFormat(format);
1399 item->setTextCursor(cur);
1400 cur.clearSelection();
1401 item->setTextCursor(cur);
1404 void TitleWidget::rectChanged()
1406 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1407 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1408 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1409 QColor f = rectFColor->color();
1410 f.setAlpha(rectFAlpha->value());
1412 penf.setWidth(rectLineWidth->value());
1414 QColor b = rectBColor->color();
1415 b.setAlpha(rectBAlpha->value());
1416 rec->setBrush(QBrush(b));
1420 void TitleWidget::itemScaled(int val)
1422 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1423 if (l.size() == 1) {
1424 Transform x = m_transformations.value(l.at(0));
1425 x.scalex = (double)val / 100.0;
1426 x.scaley = (double)val / 100.0;
1428 qtrans.scale(x.scalex, x.scaley);
1429 qtrans.rotate(x.rotate);
1430 l[0]->setTransform(qtrans);
1431 m_transformations[l.at(0)] = x;
1432 updateDimension(l.at(0));
1436 void TitleWidget::itemRotate(qreal val)
1438 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1439 if (l.size() == 1) {
1440 Transform x = m_transformations[l.at(0)];
1443 qtrans.scale(x.scalex, x.scaley);
1444 qtrans.rotate(x.rotate);
1445 l[0]->setTransform(qtrans);
1446 m_transformations[l.at(0)] = x;
1447 updateDimension(l.at(0));
1451 void TitleWidget::itemHCenter()
1453 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1454 if (l.size() == 1) {
1455 QGraphicsItem *item = l.at(0);
1456 QRectF br = item->sceneBoundingRect();
1457 int width = (int)br.width();
1458 int newPos = (int)((m_frameWidth - width) / 2);
1459 newPos += item->pos().x() - br.left(); // Check item transformation
1460 item->setPos(newPos, item->pos().y());
1461 updateCoordinates(item);
1465 void TitleWidget::itemVCenter()
1467 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1468 if (l.size() == 1) {
1469 QGraphicsItem *item = l.at(0);
1470 QRectF br = item->sceneBoundingRect();
1471 int height = (int)br.height();
1472 int newPos = (int)((m_frameHeight - height) / 2);
1473 newPos += item->pos().y() - br.top(); // Check item transformation
1474 item->setPos(item->pos().x(), newPos);
1475 updateCoordinates(item);
1479 void TitleWidget::itemTop()
1481 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1482 if (l.size() == 1) {
1483 QGraphicsItem *item = l.at(0);
1484 QRectF br = item->sceneBoundingRect();
1486 if (br.top() > 0) diff = -br.top();
1487 else diff = -br.bottom();
1488 item->moveBy(0, diff);
1489 updateCoordinates(item);
1493 void TitleWidget::itemBottom()
1495 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1496 if (l.size() == 1) {
1497 QGraphicsItem *item = l.at(0);
1498 QRectF br = item->sceneBoundingRect();
1500 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1501 else diff = m_frameHeight - br.bottom();
1502 item->moveBy(0, diff);
1503 updateCoordinates(item);
1507 void TitleWidget::itemLeft()
1509 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1510 if (l.size() == 1) {
1511 QGraphicsItem *item = l.at(0);
1512 QRectF br = item->sceneBoundingRect();
1514 if (br.left() > 0) diff = -br.left();
1515 else diff = -br.right();
1516 item->moveBy(diff, 0);
1517 updateCoordinates(item);
1521 void TitleWidget::itemRight()
1523 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1524 if (l.size() == 1) {
1525 QGraphicsItem *item = l.at(0);
1526 QRectF br = item->sceneBoundingRect();
1528 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1529 else diff = m_frameWidth - br.left();
1530 item->moveBy(diff, 0);
1531 updateCoordinates(item);
1535 void TitleWidget::setupViewports()
1537 //double aspect_ratio = 4.0 / 3.0;//read from project
1538 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1539 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1540 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1541 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1542 QPolygonF spoly(sp);
1543 QPolygonF epoly(ep);
1544 spoly.translate(startViewportX->value(), startViewportY->value());
1545 epoly.translate(endViewportX->value(), endViewportY->value());
1546 m_startViewport->setPolygon(spoly);
1547 m_endViewport->setPolygon(epoly);
1548 if (! insertingValues) {
1549 m_startViewport->setData(0, startViewportX->value());
1550 m_startViewport->setData(1, startViewportY->value());
1551 m_startViewport->setData(2, startViewportSize->value());
1553 m_endViewport->setData(0, endViewportX->value());
1554 m_endViewport->setData(1, endViewportY->value());
1555 m_endViewport->setData(2, endViewportSize->value());
1559 void TitleWidget::loadTitle(KUrl url)
1561 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1562 if (!url.isEmpty()) {
1563 QList<QGraphicsItem *> items = m_scene->items();
1564 for (int i = 0; i < items.size(); i++) {
1565 if (items.at(i)->zValue() > -1000) delete items.at(i);
1567 m_scene->clearTextSelection();
1571 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1572 QFile file(tmpfile);
1573 if (file.open(QIODevice::ReadOnly)) {
1574 doc.setContent(&file, false);
1577 KIO::NetAccess::removeTempFile(tmpfile);
1582 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1584 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1585 insertingValues = true;
1586 startViewportX->setValue(m_startViewport->data(0).toInt());
1587 startViewportY->setValue(m_startViewport->data(1).toInt());
1588 startViewportSize->setValue(m_startViewport->data(2).toInt());
1589 endViewportX->setValue(m_endViewport->data(0).toInt());
1590 endViewportY->setValue(m_endViewport->data(1).toInt());
1591 endViewportSize->setValue(m_endViewport->data(2).toInt());
1593 insertingValues = false;
1599 void TitleWidget::saveTitle(KUrl url)
1601 if (anim_start->isChecked()) slotAnimStart(false);
1602 if (anim_end->isChecked()) slotAnimEnd(false);
1603 if (url.isEmpty()) {
1604 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1605 fs->setOperationMode(KFileDialog::Saving);
1606 fs->setMode(KFile::File);
1607 #if KDE_IS_VERSION(4,2,0)
1608 fs->setConfirmOverwrite(true);
1610 fs->setKeepLocation(true);
1612 url = fs->selectedUrl();
1615 if (!url.isEmpty()) {
1616 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1617 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1621 QDomDocument TitleWidget::xml()
1623 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1624 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1628 int TitleWidget::duration() const
1630 return m_tc.getFrameCount(title_duration->text());
1633 void TitleWidget::setXml(QDomDocument doc)
1636 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1638 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1639 /*if (doc.documentElement().hasAttribute("out")) {
1640 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1641 title_duration->setText(m_tc.getTimecode(duration));
1643 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1645 QDomElement e = doc.documentElement();
1646 m_transformations.clear();
1647 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1648 const double PI = 4.0 * atan(1.0);
1649 for (int i = 0; i < items.count(); i++) {
1650 QTransform t = items.at(i)->transform();
1654 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1655 m_transformations[items.at(i)] = x;
1657 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1658 QColor background_color = m_titledocument.getBackgroundColor();
1659 backgroundAlpha->blockSignals(true);
1660 backgroundColor->blockSignals(true);
1661 backgroundAlpha->setValue(background_color.alpha());
1662 background_color.setAlpha(255);
1663 backgroundColor->setColor(background_color);
1664 backgroundAlpha->blockSignals(false);
1665 backgroundColor->blockSignals(false);
1667 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1668 startViewportY->setValue(m_startViewport->data(1).toInt());
1669 startViewportSize->setValue(m_startViewport->data(2).toInt());
1670 endViewportX->setValue(m_endViewport->data(0).toInt());
1671 endViewportY->setValue(m_endViewport->data(1).toInt());
1672 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1674 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1678 /** \brief Connected to the accepted signal - calls writeChoices */
1679 void TitleWidget::slotAccepted()
1681 if (anim_start->isChecked()) slotAnimStart(false);
1682 if (anim_end->isChecked()) slotAnimEnd(false);
1686 /** \brief Store the current choices of font, background and rect values */
1687 void TitleWidget::writeChoices()
1689 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1690 KSharedConfigPtr config = KGlobal::config();
1691 KConfigGroup titleConfig(config, "TitleWidget");
1692 // Write the entries
1693 titleConfig.writeEntry("font_family", font_family->currentFont());
1694 //titleConfig.writeEntry("font_size", font_size->value());
1695 titleConfig.writeEntry("font_pixel_size", font_size->value());
1696 titleConfig.writeEntry("font_color", fontColorButton->color());
1697 titleConfig.writeEntry("font_alpha", textAlpha->value());
1698 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1699 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1700 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1702 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1703 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1704 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1705 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1706 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1708 titleConfig.writeEntry("background_color", backgroundColor->color());
1709 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1711 //! \todo Not sure if I should sync - it is probably safe to do it
1716 /** \brief Read the last stored choices into the dialog */
1717 void TitleWidget::readChoices()
1719 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1720 KSharedConfigPtr config = KGlobal::config();
1721 KConfigGroup titleConfig(config, "TitleWidget");
1723 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1724 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1725 m_scene->slotUpdateFontSize(font_size->value());
1726 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1727 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1729 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1730 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1731 setFontBoxWeight(weight);
1732 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1733 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1735 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1736 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1737 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1738 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1739 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1741 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
1742 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
1745 void TitleWidget::adjustFrameSize()
1747 m_frameWidth = m_titledocument.frameWidth();
1748 m_frameHeight = m_titledocument.frameHeight();
1749 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1750 displayBackgroundFrame();
1753 void TitleWidget::slotAnimStart(bool anim)
1755 if (anim && anim_end->isChecked()) {
1756 anim_end->setChecked(false);
1757 m_endViewport->setZValue(-1000);
1758 m_endViewport->setBrush(QBrush());
1761 QList<QGraphicsItem *> list = m_scene->items();
1762 for (int i = 0; i < list.count(); i++) {
1763 if (list.at(i)->zValue() > -1000) {
1764 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1765 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1768 align_box->setEnabled(anim);
1769 itemzoom->setEnabled(!anim);
1770 itemrotate->setEnabled(!anim);
1771 frame_toolbar->setEnabled(!anim);
1772 toolbar_stack->setEnabled(!anim);
1774 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1775 m_startViewport->setZValue(1100);
1776 QColor col = m_startViewport->pen().color();
1778 m_startViewport->setBrush(col);
1779 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1780 m_startViewport->setSelected(true);
1783 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1785 m_startViewport->setZValue(-1000);
1786 m_startViewport->setBrush(QBrush());
1787 m_startViewport->setFlags(0);
1788 if (!anim_end->isChecked()) deleteAnimInfoText();
1793 void TitleWidget::slotAnimEnd(bool anim)
1795 if (anim && anim_start->isChecked()) {
1796 anim_start->setChecked(false);
1797 m_startViewport->setZValue(-1000);
1798 m_startViewport->setBrush(QBrush());
1801 QList<QGraphicsItem *> list = m_scene->items();
1802 for (int i = 0; i < list.count(); i++) {
1803 if (list.at(i)->zValue() > -1000) {
1804 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1805 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1808 align_box->setEnabled(anim);
1809 itemzoom->setEnabled(!anim);
1810 itemrotate->setEnabled(!anim);
1811 frame_toolbar->setEnabled(!anim);
1812 toolbar_stack->setEnabled(!anim);
1814 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1815 m_endViewport->setZValue(1100);
1816 QColor col = m_endViewport->pen().color();
1818 m_endViewport->setBrush(col);
1819 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1820 m_endViewport->setSelected(true);
1823 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
1825 m_endViewport->setZValue(-1000);
1826 m_endViewport->setBrush(QBrush());
1827 m_endViewport->setFlags(0);
1828 if (!anim_start->isChecked()) deleteAnimInfoText();
1832 void TitleWidget::addAnimInfoText()
1834 // add text to anim viewport
1835 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
1836 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
1837 QFont font = t->font();
1838 font.setPixelSize(m_startViewport->rect().width() / 10);
1839 QColor col = m_startViewport->pen().color();
1841 t->setDefaultTextColor(col);
1843 font.setPixelSize(m_endViewport->rect().width() / 10);
1844 col = m_endViewport->pen().color();
1846 t2->setDefaultTextColor(col);
1850 void TitleWidget::updateInfoText()
1852 // update info text font
1853 if (!m_startViewport->childItems().isEmpty()) {
1854 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
1856 QFont font = item->font();
1857 font.setPixelSize(m_startViewport->rect().width() / 10);
1858 item->setFont(font);
1861 if (!m_endViewport->childItems().isEmpty()) {
1862 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
1864 QFont font = item->font();
1865 font.setPixelSize(m_endViewport->rect().width() / 10);
1866 item->setFont(font);
1871 void TitleWidget::deleteAnimInfoText()
1873 // end animation editing, remove info text
1874 while (!m_startViewport->childItems().isEmpty()) {
1875 QGraphicsItem *item = m_startViewport->childItems().at(0);
1876 m_scene->removeItem(item);
1879 while (!m_endViewport->childItems().isEmpty()) {
1880 QGraphicsItem *item = m_endViewport->childItems().at(0);
1881 m_scene->removeItem(item);
1887 void TitleWidget::slotKeepAspect(bool keep)
1889 if (m_endViewport->zValue() == 1100) {
1890 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1891 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1893 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1894 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1898 void TitleWidget::slotResize50()
1900 if (m_endViewport->zValue() == 1100) {
1901 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1902 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1905 void TitleWidget::slotResize100()
1907 if (m_endViewport->zValue() == 1100) {
1908 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1909 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1912 void TitleWidget::slotResize200()
1914 if (m_endViewport->zValue() == 1100) {
1915 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1916 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1919 void TitleWidget::slotAddEffect(int ix)
1921 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1922 int effect = effect_list->itemData(ix).toInt();
1923 if (effect == NOEFFECT) {
1924 if (l.size() == 1) l[0]->setData(100, QVariant());
1925 effect_stack->setHidden(true);
1928 effect_stack->setCurrentIndex(effect - 1);
1929 effect_stack->setHidden(false);
1930 if (effect == TYPEWRITEREFFECT) {
1931 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1932 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1933 l[0]->setData(100, effdata);
1936 #if QT_VERSION < 0x040600
1939 if (effect == BLUREFFECT) {
1941 if (l.size() == 1) {
1942 QGraphicsEffect *eff = new QGraphicsBlurEffect();
1943 l[0]->setGraphicsEffect(eff);
1945 } else if (effect == SHADOWEFFECT) {
1946 if (l.size() == 1) {
1947 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
1948 l[0]->setGraphicsEffect(eff);
1956 void TitleWidget::slotFontText(const QString& s)
1959 if (f.exactMatch()) {
1960 // Font really exists (could also just be a «d» if the user
1961 // starts typing «dejavu» for example).
1962 font_family->setCurrentFont(f);
1964 // Note: Typing dejavu serif does not recognize the font (takes sans)
1965 // in older Qt versions.
1968 void TitleWidget::slotEditTypewriter(int ix)
1970 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1971 if (l.size() == 1) {
1972 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1973 l[0]->setData(100, effdata);
1977 void TitleWidget::slotEditBlur(int ix)
1979 #if QT_VERSION < 0x040600
1982 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1983 if (l.size() == 1) {
1984 QGraphicsEffect *eff = l[0]->graphicsEffect();
1985 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
1986 if (blur) blur->setBlurRadius(ix);
1991 void TitleWidget::slotEditShadow()
1993 #if QT_VERSION < 0x040600
1996 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1997 if (l.size() == 1) {
1998 QGraphicsEffect *eff = l[0]->graphicsEffect();
1999 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2001 shadow->setBlurRadius(shadow_radius->value());
2002 shadow->setOffset(shadow_x->value(), shadow_y->value());
2008 qreal TitleWidget::zIndexBounds(bool maxBound)
2010 qreal bound = maxBound ? -99 : 99;
2011 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2013 QList<QGraphicsItem*> lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2014 if (lItems.size() > 0) {
2015 int n = lItems.size();
2018 for (int i = 0; i < n; i++) {
2019 z = lItems[i]->zValue();
2020 if (z > bound && !lItems[i]->isSelected()) {
2025 // Get minimum z index.
2026 for (int i = 0; i < n; i++) {
2027 z = lItems[i]->zValue();
2028 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2029 // There are items at the very bottom (background e.g.) with z-index < -1000.
2039 void TitleWidget::slotZIndexUp()
2041 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2042 if (l.size() >= 1) {
2043 qreal currentZ = l[0]->zValue();
2044 qreal max = zIndexBounds(true);
2045 if (currentZ <= max) {
2046 l[0]->setZValue(currentZ + 1);
2047 updateDimension(l[0]);
2052 void TitleWidget::slotZIndexTop()
2054 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2055 if (l.size() >= 1) {
2056 qreal currentZ = l[0]->zValue();
2057 qreal max = zIndexBounds(true);
2058 if (currentZ <= max) {
2059 l[0]->setZValue(max + 1);
2060 updateDimension(l[0]);
2065 void TitleWidget::slotZIndexDown()
2067 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2068 if (l.size() >= 1) {
2069 qreal currentZ = l[0]->zValue();
2070 qreal min = zIndexBounds(false);
2071 if (currentZ >= min) {
2072 l[0]->setZValue(currentZ - 1);
2073 updateDimension(l[0]);
2078 void TitleWidget::slotZIndexBottom()
2080 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2081 if (l.size() >= 1) {
2082 qreal currentZ = l[0]->zValue();
2083 qreal min = zIndexBounds(false);
2084 if (currentZ >= min) {
2085 l[0]->setZValue(min - 1);
2086 updateDimension(l[0]);