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 itemzoom->setSuffix(i18n("%"));
95 m_frameWidth = render->renderWidth();
96 m_frameHeight = render->renderHeight();
97 showToolbars(TITLE_SELECT);
99 //TODO: get default title duration instead of hardcoded one
100 title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0)));
102 connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
103 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
105 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
106 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
107 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
108 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
109 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
110 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
111 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
112 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
114 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
116 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
117 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
118 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
119 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
120 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
122 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
123 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
124 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
125 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
126 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
127 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
130 effect_list->addItem(i18n("None"), NOEFFECT);
131 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
132 effect_list->addItem(i18n("Blur"), BLUREFFECT);
135 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
136 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
137 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
138 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
139 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
140 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
141 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
142 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
143 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
144 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
145 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
146 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
147 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
148 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
149 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
150 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
151 effect_stack->setHidden(true);
152 effect_frame->setEnabled(false);
154 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
155 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
157 m_signalMapper = new QSignalMapper(this);
158 m_signalMapper->setMapping(value_w, ValueWidth);
159 m_signalMapper->setMapping(value_h, ValueHeight);
160 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
161 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
162 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
164 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
165 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
166 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
167 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
168 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
169 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
170 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
171 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
172 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
173 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
174 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
175 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
176 //connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
177 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
179 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
182 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
184 font_weight_box->blockSignals(true);
185 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
186 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
187 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
188 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
189 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
190 font_weight_box->setToolTip(i18n("Font weight"));
191 font_weight_box->setCurrentIndex(1);
192 font_weight_box->blockSignals(false);
194 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
195 buttonRealSize->setIcon(KIcon("zoom-original"));
196 buttonItalic->setIcon(KIcon("format-text-italic"));
197 buttonUnder->setIcon(KIcon("format-text-underline"));
198 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
199 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
200 buttonAlignRight->setIcon(KIcon("format-justify-right"));
201 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
203 buttonAlignNone->setToolTip(i18n("No alignment"));
204 buttonAlignRight->setToolTip(i18n("Align right"));
205 buttonAlignLeft->setToolTip(i18n("Align left"));
206 buttonAlignCenter->setToolTip(i18n("Align center"));
208 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
209 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
210 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
211 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
212 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
214 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
215 m_zUp->setShortcut(Qt::Key_PageUp);
216 m_zUp->setToolTip(i18n("Raise object"));
217 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
218 zUp->setDefaultAction(m_zUp);
220 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
221 m_zDown->setShortcut(Qt::Key_PageDown);
222 m_zDown->setToolTip(i18n("Lower object"));
223 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
224 zDown->setDefaultAction(m_zDown);
226 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
227 m_zTop->setShortcut(Qt::Key_Home);
228 m_zTop->setToolTip(i18n("Raise object to top"));
229 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
230 zTop->setDefaultAction(m_zTop);
232 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
233 m_zBottom->setShortcut(Qt::Key_End);
234 m_zBottom->setToolTip(i18n("Lower object to bottom"));
235 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
236 zBottom->setDefaultAction(m_zBottom);
238 zDown->setIcon(KIcon("kdenlive-zindex-down"));
239 zTop->setIcon(KIcon("kdenlive-zindex-top"));
240 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
241 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
242 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
243 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
245 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
246 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
247 rectBColor->setToolTip(i18n("Select fill color"));
248 rectFColor->setToolTip(i18n("Select border color"));
249 rectBAlpha->setToolTip(i18n("Fill transparency"));
250 rectFAlpha->setToolTip(i18n("Border transparency"));
251 zoom_slider->setToolTip(i18n("Zoom"));
252 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
253 buttonFitZoom->setToolTip(i18n("Fit zoom"));
254 kcolorbutton->setToolTip(i18n("Select background color"));
255 horizontalSlider->setToolTip(i18n("Background Transparency"));
257 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
258 itemhcenter->setToolTip(i18n("Align item horizontally"));
259 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
260 itemvcenter->setToolTip(i18n("Align item vertically"));
261 itemtop->setIcon(KIcon("kdenlive-align-top"));
262 itemtop->setToolTip(i18n("Align item to top"));
263 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
264 itembottom->setToolTip(i18n("Align item to bottom"));
265 itemright->setIcon(KIcon("kdenlive-align-right"));
266 itemright->setToolTip(i18n("Align item to right"));
267 itemleft->setIcon(KIcon("kdenlive-align-left"));
268 itemleft->setToolTip(i18n("Align item to left"));
271 QHBoxLayout *layout = new QHBoxLayout;
272 frame_toolbar->setLayout(layout);
273 layout->setContentsMargins(0, 0, 0, 0);
274 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
275 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
276 m_toolbar->setIconSize(QSize(s, s));
278 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
279 m_buttonCursor->setCheckable(true);
280 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
281 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
282 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
284 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
285 m_buttonText->setCheckable(true);
286 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
287 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
288 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
290 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
291 m_buttonRect->setCheckable(true);
292 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
293 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
294 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
296 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
297 m_buttonImage->setCheckable(false);
298 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
299 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
300 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
302 m_toolbar->addSeparator();
304 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
305 m_buttonLoad->setCheckable(false);
306 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
307 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
309 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
310 m_buttonSave->setCheckable(false);
311 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
312 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
314 layout->addWidget(m_toolbar);
316 // initialize graphic scene
317 m_scene = new GraphicsSceneRectMove(this);
318 graphicsView->setScene(m_scene);
319 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
320 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
321 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
323 // a gradient background
324 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
325 gradient->setSpread(QGradient::ReflectSpread);
326 scene->setBackgroundBrush(*gradient);*/
328 m_frameImage = new QGraphicsPixmapItem();
330 qtrans.scale(2.0, 2.0);
331 m_frameImage->setTransform(qtrans);
332 m_frameImage->setZValue(-1200);
333 m_frameImage->setFlags(0);
334 displayBackgroundFrame();
335 graphicsView->scene()->addItem(m_frameImage);
337 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
338 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
339 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
340 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
341 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
342 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
343 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
344 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
346 QPen framepen(Qt::DotLine);
347 framepen.setColor(Qt::red);
349 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
350 m_frameBorder->setPen(framepen);
351 m_frameBorder->setZValue(-1100);
352 m_frameBorder->setBrush(Qt::transparent);
353 m_frameBorder->setFlags(0);
354 graphicsView->scene()->addItem(m_frameBorder);
356 // mbd: load saved settings
359 graphicsView->show();
360 //graphicsView->setRenderHint(QPainter::Antialiasing);
361 graphicsView->setInteractive(true);
362 //graphicsView->resize(400, 300);
363 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
364 //toolBox->setItemEnabled(2, false);
365 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
366 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
367 m_startViewport->setData(0, m_frameWidth);
368 m_startViewport->setData(1, m_frameHeight);
369 m_endViewport->setData(0, m_frameWidth);
370 m_endViewport->setData(1, m_frameHeight);
372 if (!url.isEmpty()) loadTitle(url);
375 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
378 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
379 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
381 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
384 TitleWidget::~TitleWidget()
388 delete m_buttonImage;
389 delete m_buttonCursor;
392 delete m_unicodeAction;
398 delete m_unicodeDialog;
399 delete m_frameBorder;
401 delete m_startViewport;
402 delete m_endViewport;
404 delete m_signalMapper;
408 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
411 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
412 KStandardDirs::makeDir(titlePath);
413 titlePath.append((isClone == false) ? "title" : "clone");
416 while (path.isEmpty() || QFile::exists(path)) {
418 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
420 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
426 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
429 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
430 KStandardDirs::makeDir(titlePath);
431 return titlePath + titleName + ".png";
435 QStringList TitleWidget::extractImageList(QString xml)
438 if (xml.isEmpty()) return result;
441 QDomNodeList images = doc.elementsByTagName("content");
442 for (int i = 0; i < images.count(); i++) {
443 if (images.at(i).toElement().hasAttribute("url"))
444 result.append(images.at(i).toElement().attribute("url"));
451 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
456 void TitleWidget::slotTextTool()
458 m_scene->setTool(TITLE_TEXT);
459 showToolbars(TITLE_TEXT);
460 checkButton(TITLE_TEXT);
463 void TitleWidget::slotRectTool()
465 m_scene->setTool(TITLE_RECTANGLE);
466 showToolbars(TITLE_RECTANGLE);
467 checkButton(TITLE_RECTANGLE);
470 void TitleWidget::slotSelectTool()
472 m_scene->setTool(TITLE_SELECT);
474 // Find out which toolbars need to be shown, depending on selected item
475 TITLETOOL t = TITLE_SELECT;
476 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
478 switch (l.at(0)->type()) {
492 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
493 //graphicsView->centerOn(l.at(0));
499 updateCoordinates(l.at(0));
500 updateDimension(l.at(0));
501 updateRotZoom(l.at(0));
504 checkButton(TITLE_SELECT);
507 void TitleWidget::slotImageTool()
509 // TODO: find a way to get a list of all supported image types...
510 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";
511 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
512 if (!url.isEmpty()) {
513 if (url.path().endsWith(".svg")) {
514 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
515 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
516 svg->setZValue(m_count++);
517 svg->setData(Qt::UserRole, url.path());
518 graphicsView->scene()->addItem(svg);
520 QPixmap pix(url.path());
521 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
522 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
523 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
524 image->setData(Qt::UserRole, url.path());
525 image->setZValue(m_count++);
526 graphicsView->scene()->addItem(image);
529 m_scene->setTool(TITLE_SELECT);
530 showToolbars(TITLE_SELECT);
531 checkButton(TITLE_SELECT);
534 void TitleWidget::showToolbars(TITLETOOL toolType)
536 toolbar_stack->setCurrentIndex((int) toolType);
539 void TitleWidget::enableToolbars(TITLETOOL toolType)
541 // TITLETOOL is defined in graphicsscenerectmove.h
543 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
544 value_w->setEnabled(enable);
545 value_h->setEnabled(enable);
548 void TitleWidget::checkButton(TITLETOOL toolType)
550 bool bSelect = false;
562 case TITLE_RECTANGLE:
572 m_buttonCursor->setChecked(bSelect);
573 m_buttonText->setChecked(bText);
574 m_buttonRect->setChecked(bRect);
575 m_buttonImage->setChecked(bImage);
578 void TitleWidget::displayBackgroundFrame()
580 if (!displayBg->isChecked()) {
581 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
582 QPixmap pattern(20, 20);
584 QColor bgcolor(210, 210, 210);
587 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
588 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
593 p.fillRect(bg.rect(), br);
595 m_frameImage->setPixmap(bg);
597 m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
601 void TitleWidget::initAnimation()
603 align_box->setEnabled(false);
604 QPen startpen(Qt::DotLine);
605 QPen endpen(Qt::DashDotLine);
606 startpen.setColor(QColor(100, 200, 100, 140));
607 endpen.setColor(QColor(200, 100, 100, 140));
609 m_startViewport->setPen(startpen);
610 m_endViewport->setPen(endpen);
612 m_startViewport->setZValue(-1000);
613 m_endViewport->setZValue(-1000);
615 m_startViewport->setFlags(0);
616 m_endViewport->setFlags(0);
618 graphicsView->scene()->addItem(m_startViewport);
619 graphicsView->scene()->addItem(m_endViewport);
621 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
622 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
623 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
624 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
627 void TitleWidget::slotUpdateZoom(int pos)
629 m_scene->setZoom((double) pos / 100);
630 zoom_label->setText(QString::number(pos) + '%');
633 void TitleWidget::slotZoom(bool up)
635 int pos = zoom_slider->value();
638 zoom_slider->setValue(pos);
641 void TitleWidget::slotAdjustZoom()
643 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
644 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
645 if (scalex > scaley) scalex = scaley;
646 int zoompos = (int)(scalex * 7 + 0.5);*/
647 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
648 int zoompos = graphicsView->matrix().m11() * 100;
649 zoom_slider->setValue(zoompos);
650 graphicsView->centerOn(m_frameBorder);
653 void TitleWidget::slotZoomOneToOne()
655 zoom_slider->setValue(100);
656 graphicsView->centerOn(m_frameBorder);
659 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
661 updateAxisButtons(rect); // back to default
663 QColor f = rectFColor->color();
664 f.setAlpha(rectFAlpha->value());
666 penf.setWidth(rectLineWidth->value());
668 QColor b = rectBColor->color();
669 b.setAlpha(rectBAlpha->value());
670 rect->setBrush(QBrush(b));
671 rect->setZValue(m_count++);
672 //setCurrentItem(rect);
673 //graphicsView->setFocus();
676 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
678 updateAxisButtons(tt); // back to default
680 QFont font = font_family->currentFont();
681 font.setPixelSize(font_size->value());
683 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
684 font.setItalic(buttonItalic->isChecked());
685 font.setUnderline(buttonUnder->isChecked());
688 QColor color = fontColorButton->color();
689 color.setAlpha(textAlpha->value());
690 tt->setDefaultTextColor(color);
692 QTextCursor cur(tt->document());
693 cur.select(QTextCursor::Document);
694 QTextBlockFormat format = cur.blockFormat();
695 QTextCharFormat cformat = cur.charFormat();
696 QColor outlineColor = textOutlineColor->color();
697 outlineColor.setAlpha(textOutlineAlpha->value());
698 double outlineWidth = textOutline->value() / 10.0;
700 tt->setData(101, outlineWidth);
701 tt->setData(102, outlineColor);
702 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
704 cformat.setForeground(QBrush(color));
705 cur.setCharFormat(cformat);
706 cur.setBlockFormat(format);
707 tt->setTextCursor(cur);
708 tt->setZValue(m_count++);
712 void TitleWidget::setFontBoxWeight(int weight)
714 int index = font_weight_box->findData(weight);
716 index = font_weight_box->findData(QFont::Normal);
718 font_weight_box->setCurrentIndex(index);
721 void TitleWidget::setCurrentItem(QGraphicsItem *item)
723 m_scene->setSelectedItem(item);
726 void TitleWidget::zIndexChanged(int v)
728 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
734 void TitleWidget::selectionChanged()
736 if (m_scene->tool() != TITLE_SELECT) return;
737 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
738 //toolBox->setItemEnabled(2, false);
739 //toolBox->setItemEnabled(3, false);
740 value_x->blockSignals(true);
741 value_y->blockSignals(true);
742 value_w->blockSignals(true);
743 value_h->blockSignals(true);
744 itemzoom->blockSignals(true);
745 itemrotate->blockSignals(true);
747 effect_stack->setHidden(true);
748 effect_frame->setEnabled(false);
749 effect_list->setCurrentIndex(0);
750 bool blockX = !origin_x_left->signalsBlocked();
751 bool blockY = !origin_y_top->signalsBlocked();
752 if (blockX) origin_x_left->blockSignals(true);
753 if (blockY) origin_y_top->blockSignals(true);
754 origin_x_left->setChecked(false);
755 origin_y_top->setChecked(false);
758 enableToolbars(TITLE_SELECT);
759 if (blockX) origin_x_left->blockSignals(false);
760 if (blockY) origin_y_top->blockSignals(false);
761 itemzoom->setEnabled(false);
762 itemrotate->setEnabled(false);
763 frame_properties->setEnabled(false);
764 } else if (l.size() == 1) {
765 effect_frame->setEnabled(true);
766 frame_properties->setEnabled(true);
767 if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
768 itemzoom->setEnabled(true);
769 itemrotate->setEnabled(true);
771 itemzoom->setEnabled(false);
772 itemrotate->setEnabled(false);
775 if (l.at(0)->type() == TEXTITEM) {
776 showToolbars(TITLE_TEXT);
777 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
778 if (!i->data(100).isNull()) {
779 // Item has an effect
780 QStringList effdata = i->data(100).toStringList();
781 QString effectName = effdata.takeFirst();
782 if (effectName == "typewriter") {
783 QStringList params = effdata.at(0).split(';');
784 typewriter_delay->setValue(params.at(0).toInt());
785 typewriter_start->setValue(params.at(1).toInt());
786 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
787 effect_stack->setHidden(false);
790 #if QT_VERSION >= 0x040600
791 if (i->graphicsEffect()) {
792 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
794 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
795 int rad = (int) blur->blurRadius();
796 blur_radius->setValue(rad);
797 effect_stack->setHidden(false);
799 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
801 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
802 shadow_radius->setValue(shad->blurRadius());
803 shadow_x->setValue(shad->xOffset());
804 shadow_y->setValue(shad->yOffset());
805 effect_stack->setHidden(false);
809 effect_list->blockSignals(true);
810 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
811 effect_list->blockSignals(false);
812 effect_stack->setHidden(true);
815 effect_list->blockSignals(true);
816 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
817 effect_list->blockSignals(false);
818 effect_stack->setHidden(true);
821 //if (l[0]->hasFocus())
822 //toolBox->setCurrentIndex(0);
823 //toolBox->setItemEnabled(2, true);
824 font_size->blockSignals(true);
825 font_family->blockSignals(true);
826 font_weight_box->blockSignals(true);
827 buttonItalic->blockSignals(true);
828 buttonUnder->blockSignals(true);
829 fontColorButton->blockSignals(true);
830 textAlpha->blockSignals(true);
831 buttonAlignLeft->blockSignals(true);
832 buttonAlignRight->blockSignals(true);
833 buttonAlignNone->blockSignals(true);
834 buttonAlignCenter->blockSignals(true);
836 QFont font = i->font();
837 font_family->setCurrentFont(font);
838 font_size->setValue(font.pixelSize());
839 m_scene->slotUpdateFontSize(font.pixelSize());
840 buttonItalic->setChecked(font.italic());
841 buttonUnder->setChecked(font.underline());
842 setFontBoxWeight(font.weight());
844 QTextCursor cursor(i->document());
845 cursor.select(QTextCursor::Document);
846 QColor color = cursor.charFormat().foreground().color();
847 textAlpha->setValue(color.alpha());
849 fontColorButton->setColor(color);
851 if (!i->data(101).isNull()) {
852 textOutline->blockSignals(true);
853 textOutline->setValue(i->data(101).toDouble()*10);
854 textOutline->blockSignals(false);
856 if (!i->data(102).isNull()) {
857 textOutlineColor->blockSignals(true);
858 textOutlineAlpha->blockSignals(true);
859 color = QColor(i->data(102).toString());
860 textOutlineAlpha->setValue(color.alpha());
862 textOutlineColor->setColor(color);
863 textOutlineColor->blockSignals(false);
864 textOutlineAlpha->blockSignals(false);
866 QTextCursor cur = i->textCursor();
867 QTextBlockFormat format = cur.blockFormat();
868 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
869 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
870 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
871 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
873 font_size->blockSignals(false);
874 font_family->blockSignals(false);
875 font_weight_box->blockSignals(false);
876 buttonItalic->blockSignals(false);
877 buttonUnder->blockSignals(false);
878 fontColorButton->blockSignals(false);
879 textAlpha->blockSignals(false);
880 buttonAlignLeft->blockSignals(false);
881 buttonAlignRight->blockSignals(false);
882 buttonAlignNone->blockSignals(false);
883 buttonAlignCenter->blockSignals(false);
885 updateAxisButtons(i);
886 updateCoordinates(i);
888 enableToolbars(TITLE_TEXT);
890 } else if ((l.at(0))->type() == RECTITEM) {
891 showToolbars(TITLE_RECTANGLE);
893 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
894 if (rec == m_startViewport || rec == m_endViewport) {
895 /*toolBox->setCurrentIndex(3);
896 toolBox->widget(0)->setEnabled(false);
897 toolBox->widget(1)->setEnabled(false);*/
898 enableToolbars(TITLE_SELECT);
900 /*toolBox->widget(0)->setEnabled(true);
901 toolBox->widget(1)->setEnabled(true);
902 toolBox->setCurrentIndex(0);*/
903 //toolBox->setItemEnabled(3, true);
904 rectFAlpha->setValue(rec->pen().color().alpha());
905 rectBAlpha->setValue(rec->brush().color().alpha());
906 //kDebug() << rec->brush().color().alpha();
907 QColor fcol = rec->pen().color();
908 QColor bcol = rec->brush().color();
909 //fcol.setAlpha(255);
910 //bcol.setAlpha(255);
911 rectFColor->setColor(fcol);
912 rectBColor->setColor(bcol);
914 rectLineWidth->setValue(rec->pen().width());
915 enableToolbars(TITLE_RECTANGLE);
918 updateAxisButtons(l.at(0));
919 updateCoordinates(rec);
920 updateDimension(rec);
922 } else if (l.at(0)->type() == IMAGEITEM) {
923 showToolbars(TITLE_IMAGE);
925 updateCoordinates(l.at(0));
926 updateDimension(l.at(0));
928 enableToolbars(TITLE_IMAGE);
931 //toolBox->setCurrentIndex(0);
932 showToolbars(TITLE_SELECT);
933 enableToolbars(TITLE_SELECT);
934 frame_properties->setEnabled(false);
936 zValue->setValue((int)l.at(0)->zValue());
937 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
938 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
939 value_x->blockSignals(false);
940 value_y->blockSignals(false);
941 value_w->blockSignals(false);
942 value_h->blockSignals(false);
943 itemzoom->blockSignals(false);
944 itemrotate->blockSignals(false);
948 void TitleWidget::slotValueChanged(int type)
950 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
951 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
956 val = value_w->value();
959 val = value_h->value();
963 QGraphicsItem *i = l.at(0);
964 Transform t = m_transformations.value(i);
966 // Ratio width:height
967 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
968 double alpha = (double) t.rotate / 180.0 * M_PI;
978 // Add 0.5 because otherwise incrementing by 1 might have no effect
979 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
980 scale = length / i->boundingRect().width();
983 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
984 scale = length / i->boundingRect().height();
991 qtrans.scale(scale, scale);
992 qtrans.rotate(t.rotate);
993 i->setTransform(qtrans);
994 m_transformations[i] = t;
1001 /** \brief Updates position/size of the selected item when a value
1002 * of an item (coordinates, size) has changed */
1003 void TitleWidget::slotAdjustSelectedItem()
1005 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1006 if (l.size() >= 1) {
1007 if (l.at(0)->type() == RECTITEM) {
1009 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1010 updatePosition(rec);
1011 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1012 } else if (l.at(0)->type() == TEXTITEM) {
1014 updatePosition(l.at(0));
1015 } else if (l.at(0)->type() == IMAGEITEM) {
1017 updatePosition(l.at(0));
1022 /** \brief Updates width/height int the text fields, regarding transformation matrix */
1023 void TitleWidget::updateDimension(QGraphicsItem *i)
1025 value_w->blockSignals(true);
1026 value_h->blockSignals(true);
1027 zValue->blockSignals(true);
1029 zValue->setValue((int) i->zValue());
1030 if (i->type() == IMAGEITEM) {
1031 // Get multipliers for rotation/scaling
1033 /*Transform t = m_transformations.value(i);
1034 QRectF r = i->boundingRect();
1035 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1036 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1037 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1038 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1040 value_w->setValue(i->sceneBoundingRect().width());
1041 value_h->setValue(i->sceneBoundingRect().height());
1042 } else if (i->type() == RECTITEM) {
1043 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1044 value_w->setValue((int) r->rect().width());
1045 value_h->setValue((int) r->rect().height());
1046 } else if (i->type() == TEXTITEM) {
1047 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1048 value_w->setValue((int) t->boundingRect().width());
1049 value_h->setValue((int) t->boundingRect().height());
1052 zValue->blockSignals(false);
1053 value_w->blockSignals(false);
1054 value_h->blockSignals(false);
1057 /** \brief Updates the coordinates in the text fields from the item */
1058 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1060 // Block signals emitted by this method
1061 value_x->blockSignals(true);
1062 value_y->blockSignals(true);
1064 if (i->type() == TEXTITEM) {
1066 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1068 // Set the correct x coordinate value
1069 if (origin_x_left->isChecked()) {
1070 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1071 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1073 // Origin is at 0 (default)
1074 value_x->setValue((int) rec->pos().x());
1078 if (origin_y_top->isChecked()) {
1079 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1081 value_y->setValue((int) rec->pos().y());
1084 } else if (i->type() == RECTITEM) {
1086 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1088 if (origin_x_left->isChecked()) {
1089 // Origin (0 point) is at m_frameWidth
1090 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1092 // Origin is at 0 (default)
1093 value_x->setValue((int) rec->pos().x());
1096 if (origin_y_top->isChecked()) {
1097 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1099 value_y->setValue((int) rec->pos().y());
1102 } else if (i->type() == IMAGEITEM) {
1104 if (origin_x_left->isChecked()) {
1105 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1107 value_x->setValue((int) i->pos().x());
1110 if (origin_y_top->isChecked()) {
1111 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1113 value_y->setValue((int) i->pos().y());
1118 // Stop blocking signals now
1119 value_x->blockSignals(false);
1120 value_y->blockSignals(false);
1123 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1125 itemzoom->blockSignals(true);
1126 itemrotate->blockSignals(false);
1128 Transform t = m_transformations.value(i);
1129 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1130 itemrotate->setValue((int)(t.rotate));
1132 itemzoom->blockSignals(false);
1133 itemrotate->blockSignals(false);
1136 /** \brief Updates the position of an item by reading coordinates from the text fields */
1137 void TitleWidget::updatePosition(QGraphicsItem *i)
1139 if (i->type() == TEXTITEM) {
1140 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1143 if (origin_x_left->isChecked()) {
1144 /* Origin of the x axis is at m_frameWidth,
1145 * and distance from right border of the item to the right
1146 * border of the frame is taken.
1147 * See comment to slotOriginXClicked().
1149 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1151 posX = value_x->value();
1155 if (origin_y_top->isChecked()) {
1156 /* Same for y axis */
1157 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1159 posY = value_y->value();
1162 rec->setPos(posX, posY);
1164 } else if (i->type() == RECTITEM) {
1166 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1169 if (origin_x_left->isChecked()) {
1170 posX = m_frameWidth - value_x->value() - rec->rect().width();
1172 posX = value_x->value();
1176 if (origin_y_top->isChecked()) {
1177 posY = m_frameHeight - value_y->value() - rec->rect().height();
1179 posY = value_y->value();
1182 rec->setPos(posX, posY);
1184 } else if (i->type() == IMAGEITEM) {
1186 if (origin_x_left->isChecked()) {
1187 // Use the sceneBoundingRect because this also regards transformations like zoom
1188 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1190 posX = value_x->value();
1194 if (origin_y_top->isChecked()) {
1195 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1197 posY = value_y->value();
1200 i->setPos(posX, posY);
1206 void TitleWidget::updateTextOriginX()
1208 if (origin_x_left->isChecked()) {
1209 origin_x_left->setText(i18n("\u2212X"));
1211 origin_x_left->setText(i18n("+X"));
1215 void TitleWidget::slotOriginXClicked()
1217 // Update the text displayed on the button.
1218 updateTextOriginX();
1220 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1221 if (l.size() >= 1) {
1222 updateCoordinates(l.at(0));
1224 // Remember x axis setting
1225 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1226 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1228 graphicsView->setFocus();
1231 void TitleWidget::updateTextOriginY()
1233 if (origin_y_top->isChecked()) {
1234 origin_y_top->setText(i18n("\u2212Y"));
1236 origin_y_top->setText(i18n("+Y"));
1240 void TitleWidget::slotOriginYClicked()
1242 // Update the text displayed on the button.
1243 updateTextOriginY();
1245 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1246 if (l.size() >= 1) {
1247 updateCoordinates(l.at(0));
1249 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1250 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1253 graphicsView->setFocus();
1256 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1258 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1259 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1260 origin_x_left->blockSignals(true);
1261 origin_y_top->blockSignals(true);
1263 if (xAxis == TitleDocument::AxisInverted) {
1264 origin_x_left->setChecked(true);
1266 origin_x_left->setChecked(false);
1268 updateTextOriginX();
1270 if (yAxis == TitleDocument::AxisInverted) {
1271 origin_y_top->setChecked(true);
1273 origin_y_top->setChecked(false);
1275 updateTextOriginY();
1277 origin_x_left->blockSignals(false);
1278 origin_y_top->blockSignals(false);
1281 void TitleWidget::slotChangeBackground()
1283 QColor color = kcolorbutton->color();
1284 color.setAlpha(horizontalSlider->value());
1285 m_frameBorder->setBrush(QBrush(color));
1289 * Something (yeah) has changed in our QGraphicsScene.
1291 void TitleWidget::slotChanged()
1293 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1294 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1295 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1300 * If the user has set origin_x_left (everything also for y),
1301 * we need to look whether a text element has been selected. If yes,
1302 * we need to ensure that the right border of the text field
1303 * remains fixed also when some text has been entered.
1305 * This is also known as right-justified, with the difference that
1306 * it is not valid for text but for its boundingRect. Text may still
1307 * be left-justified.
1309 void TitleWidget::textChanged(QGraphicsTextItem *i)
1314 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1316 if (!i->toPlainText().isEmpty()) {
1320 * Don't do anything if the string is empty. If the position
1321 * would be updated here, a newly created text field would
1322 * be set to the position of the last selected text field.
1328 void TitleWidget::slotInsertUnicode()
1330 m_unicodeDialog->exec();
1333 void TitleWidget::slotInsertUnicodeString(QString text)
1335 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1337 if (l.at(0)->type() == TEXTITEM) {
1338 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1339 t->textCursor().insertText(text);
1344 void TitleWidget::slotUpdateText()
1346 QFont font = font_family->currentFont();
1347 font.setPixelSize(font_size->value());
1348 font.setItalic(buttonItalic->isChecked());
1349 font.setUnderline(buttonUnder->isChecked());
1350 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1351 QColor color = fontColorButton->color();
1352 color.setAlpha(textAlpha->value());
1354 QColor outlineColor = textOutlineColor->color();
1355 outlineColor.setAlpha(textOutlineAlpha->value());
1356 double outlineWidth = textOutline->value() / 10.0;
1357 QGraphicsTextItem* item = NULL;
1358 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1359 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1360 item = static_cast <QGraphicsTextItem *>(l.at(0));
1363 //if (item->textCursor().selection ().isEmpty())
1364 QTextCursor cur(item->document());
1365 cur.select(QTextCursor::Document);
1366 QTextBlockFormat format = cur.blockFormat();
1367 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1368 item->setTextWidth(item->boundingRect().width());
1369 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1370 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1371 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1373 format.setAlignment(Qt::AlignLeft);
1374 item->setTextWidth(-1);
1377 item->setFont(font);
1378 QTextCharFormat cformat = cur.charFormat();
1380 item->setData(101, outlineWidth);
1381 item->setData(102, outlineColor);
1382 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
1384 cformat.setForeground(QBrush(color));
1385 cur.setCharFormat(cformat);
1386 cur.setBlockFormat(format);
1387 item->setTextCursor(cur);
1388 cur.clearSelection();
1389 item->setTextCursor(cur);
1392 void TitleWidget::rectChanged()
1394 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1395 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1396 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1397 QColor f = rectFColor->color();
1398 f.setAlpha(rectFAlpha->value());
1400 penf.setWidth(rectLineWidth->value());
1402 QColor b = rectBColor->color();
1403 b.setAlpha(rectBAlpha->value());
1404 rec->setBrush(QBrush(b));
1408 void TitleWidget::itemScaled(int val)
1410 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1411 if (l.size() == 1) {
1412 Transform x = m_transformations.value(l.at(0));
1413 x.scalex = (double)val / 100.0;
1414 x.scaley = (double)val / 100.0;
1416 qtrans.scale(x.scalex, x.scaley);
1417 qtrans.rotate(x.rotate);
1418 l[0]->setTransform(qtrans);
1419 m_transformations[l.at(0)] = x;
1420 updateDimension(l.at(0));
1424 void TitleWidget::itemRotate(int val)
1426 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1427 if (l.size() == 1) {
1428 Transform x = m_transformations[l.at(0)];
1429 x.rotate = (double)val;
1431 qtrans.scale(x.scalex, x.scaley);
1432 qtrans.rotate(x.rotate);
1433 l[0]->setTransform(qtrans);
1434 m_transformations[l.at(0)] = x;
1435 updateDimension(l.at(0));
1439 void TitleWidget::itemHCenter()
1441 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1442 if (l.size() == 1) {
1443 QGraphicsItem *item = l.at(0);
1444 QRectF br = item->sceneBoundingRect();
1445 int width = (int)br.width();
1446 int newPos = (int)((m_frameWidth - width) / 2);
1447 newPos += item->pos().x() - br.left(); // Check item transformation
1448 item->setPos(newPos, item->pos().y());
1449 updateCoordinates(item);
1453 void TitleWidget::itemVCenter()
1455 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1456 if (l.size() == 1) {
1457 QGraphicsItem *item = l.at(0);
1458 QRectF br = item->sceneBoundingRect();
1459 int height = (int)br.height();
1460 int newPos = (int)((m_frameHeight - height) / 2);
1461 newPos += item->pos().y() - br.top(); // Check item transformation
1462 item->setPos(item->pos().x(), newPos);
1463 updateCoordinates(item);
1467 void TitleWidget::itemTop()
1469 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1470 if (l.size() == 1) {
1471 QGraphicsItem *item = l.at(0);
1472 QRectF br = item->sceneBoundingRect();
1474 if (br.top() > 0) diff = -br.top();
1475 else diff = -br.bottom();
1476 item->moveBy(0, diff);
1477 updateCoordinates(item);
1481 void TitleWidget::itemBottom()
1483 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1484 if (l.size() == 1) {
1485 QGraphicsItem *item = l.at(0);
1486 QRectF br = item->sceneBoundingRect();
1488 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1489 else diff = m_frameHeight - br.bottom();
1490 item->moveBy(0, diff);
1491 updateCoordinates(item);
1495 void TitleWidget::itemLeft()
1497 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1498 if (l.size() == 1) {
1499 QGraphicsItem *item = l.at(0);
1500 QRectF br = item->sceneBoundingRect();
1502 if (br.left() > 0) diff = -br.left();
1503 else diff = -br.right();
1504 item->moveBy(diff, 0);
1505 updateCoordinates(item);
1509 void TitleWidget::itemRight()
1511 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1512 if (l.size() == 1) {
1513 QGraphicsItem *item = l.at(0);
1514 QRectF br = item->sceneBoundingRect();
1516 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1517 else diff = m_frameWidth - br.left();
1518 item->moveBy(diff, 0);
1519 updateCoordinates(item);
1523 void TitleWidget::setupViewports()
1525 //double aspect_ratio = 4.0 / 3.0;//read from project
1526 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1527 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1528 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1529 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1530 QPolygonF spoly(sp);
1531 QPolygonF epoly(ep);
1532 spoly.translate(startViewportX->value(), startViewportY->value());
1533 epoly.translate(endViewportX->value(), endViewportY->value());
1534 m_startViewport->setPolygon(spoly);
1535 m_endViewport->setPolygon(epoly);
1536 if (! insertingValues) {
1537 m_startViewport->setData(0, startViewportX->value());
1538 m_startViewport->setData(1, startViewportY->value());
1539 m_startViewport->setData(2, startViewportSize->value());
1541 m_endViewport->setData(0, endViewportX->value());
1542 m_endViewport->setData(1, endViewportY->value());
1543 m_endViewport->setData(2, endViewportSize->value());
1547 void TitleWidget::loadTitle(KUrl url)
1549 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1550 if (!url.isEmpty()) {
1551 QList<QGraphicsItem *> items = m_scene->items();
1552 for (int i = 0; i < items.size(); i++) {
1553 if (items.at(i)->zValue() > -1000) delete items.at(i);
1555 m_scene->clearTextSelection();
1559 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1560 QFile file(tmpfile);
1561 if (file.open(QIODevice::ReadOnly)) {
1562 doc.setContent(&file, false);
1565 KIO::NetAccess::removeTempFile(tmpfile);
1570 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1572 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1573 insertingValues = true;
1574 startViewportX->setValue(m_startViewport->data(0).toInt());
1575 startViewportY->setValue(m_startViewport->data(1).toInt());
1576 startViewportSize->setValue(m_startViewport->data(2).toInt());
1577 endViewportX->setValue(m_endViewport->data(0).toInt());
1578 endViewportY->setValue(m_endViewport->data(1).toInt());
1579 endViewportSize->setValue(m_endViewport->data(2).toInt());
1581 insertingValues = false;
1587 void TitleWidget::saveTitle(KUrl url)
1589 if (anim_start->isChecked()) slotAnimStart(false);
1590 if (anim_end->isChecked()) slotAnimEnd(false);
1591 if (url.isEmpty()) {
1592 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1593 fs->setOperationMode(KFileDialog::Saving);
1594 fs->setMode(KFile::File);
1595 #if KDE_IS_VERSION(4,2,0)
1596 fs->setConfirmOverwrite(true);
1598 fs->setKeepLocation(true);
1600 url = fs->selectedUrl();
1603 if (!url.isEmpty()) {
1604 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1605 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1609 QDomDocument TitleWidget::xml()
1611 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1612 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1616 int TitleWidget::duration() const
1618 return m_tc.getFrameCount(title_duration->text());
1621 void TitleWidget::setXml(QDomDocument doc)
1624 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1626 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1627 /*if (doc.documentElement().hasAttribute("out")) {
1628 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1629 title_duration->setText(m_tc.getTimecode(duration));
1631 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1633 QDomElement e = doc.documentElement();
1634 m_transformations.clear();
1635 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1636 const double PI = 4.0 * atan(1.0);
1637 for (int i = 0; i < items.count(); i++) {
1638 QTransform t = items.at(i)->transform();
1642 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1643 m_transformations[items.at(i)] = x;
1645 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1646 QColor background_color = m_titledocument.getBackgroundColor();
1647 horizontalSlider->blockSignals(true);
1648 kcolorbutton->blockSignals(true);
1649 horizontalSlider->setValue(background_color.alpha());
1650 background_color.setAlpha(255);
1651 kcolorbutton->setColor(background_color);
1652 horizontalSlider->blockSignals(false);
1653 kcolorbutton->blockSignals(false);
1655 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1656 startViewportY->setValue(m_startViewport->data(1).toInt());
1657 startViewportSize->setValue(m_startViewport->data(2).toInt());
1658 endViewportX->setValue(m_endViewport->data(0).toInt());
1659 endViewportY->setValue(m_endViewport->data(1).toInt());
1660 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1662 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1666 /** \brief Connected to the accepted signal - calls writeChoices */
1667 void TitleWidget::slotAccepted()
1669 if (anim_start->isChecked()) slotAnimStart(false);
1670 if (anim_end->isChecked()) slotAnimEnd(false);
1674 /** \brief Store the current choices of font, background and rect values */
1675 void TitleWidget::writeChoices()
1677 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1678 KSharedConfigPtr config = KGlobal::config();
1679 KConfigGroup titleConfig(config, "TitleWidget");
1680 // Write the entries
1681 titleConfig.writeEntry("font_family", font_family->currentFont());
1682 //titleConfig.writeEntry("font_size", font_size->value());
1683 titleConfig.writeEntry("font_pixel_size", font_size->value());
1684 titleConfig.writeEntry("font_color", fontColorButton->color());
1685 titleConfig.writeEntry("font_alpha", textAlpha->value());
1686 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1687 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1688 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1690 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1691 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1692 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1693 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1694 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1696 titleConfig.writeEntry("background_color", kcolorbutton->color());
1697 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1699 //! \todo Not sure if I should sync - it is probably safe to do it
1704 /** \brief Read the last stored choices into the dialog */
1705 void TitleWidget::readChoices()
1707 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1708 KSharedConfigPtr config = KGlobal::config();
1709 KConfigGroup titleConfig(config, "TitleWidget");
1711 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1712 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1713 m_scene->slotUpdateFontSize(font_size->value());
1714 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1715 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1717 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1718 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1719 setFontBoxWeight(weight);
1720 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1721 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1723 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1724 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1725 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1726 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1727 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1729 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1730 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1733 void TitleWidget::adjustFrameSize()
1735 m_frameWidth = m_titledocument.frameWidth();
1736 m_frameHeight = m_titledocument.frameHeight();
1737 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1738 displayBackgroundFrame();
1741 void TitleWidget::slotAnimStart(bool anim)
1743 if (anim && anim_end->isChecked()) {
1744 anim_end->setChecked(false);
1745 m_endViewport->setZValue(-1000);
1746 m_endViewport->setBrush(QBrush());
1749 QList<QGraphicsItem *> list = m_scene->items();
1750 for (int i = 0; i < list.count(); i++) {
1751 if (list.at(i)->zValue() > -1000) {
1752 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1753 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1756 align_box->setEnabled(anim);
1757 itemzoom->setEnabled(!anim);
1758 itemrotate->setEnabled(!anim);
1759 frame_toolbar->setEnabled(!anim);
1760 toolbar_stack->setEnabled(!anim);
1762 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1763 m_startViewport->setZValue(1100);
1764 QColor col = m_startViewport->pen().color();
1766 m_startViewport->setBrush(col);
1767 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1768 m_startViewport->setSelected(true);
1771 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1773 m_startViewport->setZValue(-1000);
1774 m_startViewport->setBrush(QBrush());
1775 m_startViewport->setFlags(0);
1776 if (!anim_end->isChecked()) deleteAnimInfoText();
1781 void TitleWidget::slotAnimEnd(bool anim)
1783 if (anim && anim_start->isChecked()) {
1784 anim_start->setChecked(false);
1785 m_startViewport->setZValue(-1000);
1786 m_startViewport->setBrush(QBrush());
1789 QList<QGraphicsItem *> list = m_scene->items();
1790 for (int i = 0; i < list.count(); i++) {
1791 if (list.at(i)->zValue() > -1000) {
1792 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1793 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1796 align_box->setEnabled(anim);
1797 itemzoom->setEnabled(!anim);
1798 itemrotate->setEnabled(!anim);
1799 frame_toolbar->setEnabled(!anim);
1800 toolbar_stack->setEnabled(!anim);
1802 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1803 m_endViewport->setZValue(1100);
1804 QColor col = m_endViewport->pen().color();
1806 m_endViewport->setBrush(col);
1807 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1808 m_endViewport->setSelected(true);
1811 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
1813 m_endViewport->setZValue(-1000);
1814 m_endViewport->setBrush(QBrush());
1815 m_endViewport->setFlags(0);
1816 if (!anim_start->isChecked()) deleteAnimInfoText();
1820 void TitleWidget::addAnimInfoText()
1822 // add text to anim viewport
1823 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
1824 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
1825 QFont font = t->font();
1826 font.setPixelSize(m_startViewport->rect().width() / 10);
1827 QColor col = m_startViewport->pen().color();
1829 t->setDefaultTextColor(col);
1831 font.setPixelSize(m_endViewport->rect().width() / 10);
1832 col = m_endViewport->pen().color();
1834 t2->setDefaultTextColor(col);
1838 void TitleWidget::updateInfoText()
1840 // update info text font
1841 if (!m_startViewport->childItems().isEmpty()) {
1842 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
1844 QFont font = item->font();
1845 font.setPixelSize(m_startViewport->rect().width() / 10);
1846 item->setFont(font);
1849 if (!m_endViewport->childItems().isEmpty()) {
1850 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
1852 QFont font = item->font();
1853 font.setPixelSize(m_endViewport->rect().width() / 10);
1854 item->setFont(font);
1859 void TitleWidget::deleteAnimInfoText()
1861 // end animation editing, remove info text
1862 while (!m_startViewport->childItems().isEmpty()) {
1863 QGraphicsItem *item = m_startViewport->childItems().at(0);
1864 m_scene->removeItem(item);
1867 while (!m_endViewport->childItems().isEmpty()) {
1868 QGraphicsItem *item = m_endViewport->childItems().at(0);
1869 m_scene->removeItem(item);
1875 void TitleWidget::slotKeepAspect(bool keep)
1877 if (m_endViewport->zValue() == 1100) {
1878 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1879 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1881 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1882 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1886 void TitleWidget::slotResize50()
1888 if (m_endViewport->zValue() == 1100) {
1889 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1890 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1893 void TitleWidget::slotResize100()
1895 if (m_endViewport->zValue() == 1100) {
1896 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1897 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1900 void TitleWidget::slotResize200()
1902 if (m_endViewport->zValue() == 1100) {
1903 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1904 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1907 void TitleWidget::slotAddEffect(int ix)
1909 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1910 int effect = effect_list->itemData(ix).toInt();
1911 if (effect == NOEFFECT) {
1912 if (l.size() == 1) l[0]->setData(100, QVariant());
1913 effect_stack->setHidden(true);
1916 effect_stack->setCurrentIndex(effect - 1);
1917 effect_stack->setHidden(false);
1918 if (effect == TYPEWRITEREFFECT) {
1919 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1920 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1921 l[0]->setData(100, effdata);
1924 #if QT_VERSION < 0x040600
1927 if (effect == BLUREFFECT) {
1929 if (l.size() == 1) {
1930 QGraphicsEffect *eff = new QGraphicsBlurEffect();
1931 l[0]->setGraphicsEffect(eff);
1933 } else if (effect == SHADOWEFFECT) {
1934 if (l.size() == 1) {
1935 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
1936 l[0]->setGraphicsEffect(eff);
1944 void TitleWidget::slotFontText(const QString& s)
1947 if (f.exactMatch()) {
1948 // Font really exists (could also just be a «d» if the user
1949 // starts typing «dejavu» for example).
1950 font_family->setCurrentFont(f);
1952 // Note: Typing dejavu serif does not recognize the font (takes sans)
1953 // in older Qt versions.
1956 void TitleWidget::slotEditTypewriter(int ix)
1958 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1959 if (l.size() == 1) {
1960 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1961 l[0]->setData(100, effdata);
1965 void TitleWidget::slotEditBlur(int ix)
1967 #if QT_VERSION < 0x040600
1970 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1971 if (l.size() == 1) {
1972 QGraphicsEffect *eff = l[0]->graphicsEffect();
1973 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
1974 if (blur) blur->setBlurRadius(ix);
1979 void TitleWidget::slotEditShadow()
1981 #if QT_VERSION < 0x040600
1984 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1985 if (l.size() == 1) {
1986 QGraphicsEffect *eff = l[0]->graphicsEffect();
1987 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
1989 shadow->setBlurRadius(shadow_radius->value());
1990 shadow->setOffset(shadow_x->value(), shadow_y->value());
1996 qreal TitleWidget::zIndexBounds(bool maxBound)
1998 qreal bound = maxBound ? -99 : 99;
1999 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2001 QList<QGraphicsItem*> lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2002 if (lItems.size() > 0) {
2003 int n = lItems.size();
2006 for (int i = 0; i < n; i++) {
2007 z = lItems[i]->zValue();
2008 if (z > bound && !lItems[i]->isSelected()) {
2013 // Get minimum z index.
2014 for (int i = 0; i < n; i++) {
2015 z = lItems[i]->zValue();
2016 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2017 // There are items at the very bottom (background e.g.) with z-index < -1000.
2027 void TitleWidget::slotZIndexUp()
2029 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2030 if (l.size() >= 1) {
2031 qreal currentZ = l[0]->zValue();
2032 qreal max = zIndexBounds(true);
2033 if (currentZ <= max) {
2034 l[0]->setZValue(currentZ + 1);
2035 updateDimension(l[0]);
2040 void TitleWidget::slotZIndexTop()
2042 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2043 if (l.size() >= 1) {
2044 qreal currentZ = l[0]->zValue();
2045 qreal max = zIndexBounds(true);
2046 if (currentZ <= max) {
2047 l[0]->setZValue(max + 1);
2048 updateDimension(l[0]);
2053 void TitleWidget::slotZIndexDown()
2055 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2056 if (l.size() >= 1) {
2057 qreal currentZ = l[0]->zValue();
2058 qreal min = zIndexBounds(false);
2059 if (currentZ >= min) {
2060 l[0]->setZValue(currentZ - 1);
2061 updateDimension(l[0]);
2066 void TitleWidget::slotZIndexBottom()
2068 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2069 if (l.size() >= 1) {
2070 qreal currentZ = l[0]->zValue();
2071 qreal min = zIndexBounds(false);
2072 if (currentZ >= min) {
2073 l[0]->setZValue(min - 1);
2074 updateDimension(l[0]);