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 fontColorButton->setColor(color);
848 textAlpha->setValue(color.alpha());
850 if (!i->data(101).isNull()) {
851 textOutline->blockSignals(true);
852 textOutline->setValue(i->data(101).toDouble()*10);
853 textOutline->blockSignals(false);
855 if (!i->data(102).isNull()) {
856 textOutlineColor->blockSignals(true);
857 textOutlineAlpha->blockSignals(true);
858 textOutlineColor->setColor(i->data(102).toString());
859 textOutlineAlpha->setValue(QColor(i->data(102).toString()).alpha());
860 textOutlineColor->blockSignals(false);
861 textOutlineAlpha->blockSignals(false);
863 QTextCursor cur = i->textCursor();
864 QTextBlockFormat format = cur.blockFormat();
865 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
866 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
867 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
868 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
870 font_size->blockSignals(false);
871 font_family->blockSignals(false);
872 font_weight_box->blockSignals(false);
873 buttonItalic->blockSignals(false);
874 buttonUnder->blockSignals(false);
875 fontColorButton->blockSignals(false);
876 textAlpha->blockSignals(false);
877 buttonAlignLeft->blockSignals(false);
878 buttonAlignRight->blockSignals(false);
879 buttonAlignNone->blockSignals(false);
880 buttonAlignCenter->blockSignals(false);
882 updateAxisButtons(i);
883 updateCoordinates(i);
885 enableToolbars(TITLE_TEXT);
887 } else if ((l.at(0))->type() == RECTITEM) {
888 showToolbars(TITLE_RECTANGLE);
890 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
891 if (rec == m_startViewport || rec == m_endViewport) {
892 /*toolBox->setCurrentIndex(3);
893 toolBox->widget(0)->setEnabled(false);
894 toolBox->widget(1)->setEnabled(false);*/
895 enableToolbars(TITLE_SELECT);
897 /*toolBox->widget(0)->setEnabled(true);
898 toolBox->widget(1)->setEnabled(true);
899 toolBox->setCurrentIndex(0);*/
900 //toolBox->setItemEnabled(3, true);
901 rectFAlpha->setValue(rec->pen().color().alpha());
902 rectBAlpha->setValue(rec->brush().color().alpha());
903 //kDebug() << rec->brush().color().alpha();
904 QColor fcol = rec->pen().color();
905 QColor bcol = rec->brush().color();
906 //fcol.setAlpha(255);
907 //bcol.setAlpha(255);
908 rectFColor->setColor(fcol);
909 rectBColor->setColor(bcol);
911 rectLineWidth->setValue(rec->pen().width());
912 enableToolbars(TITLE_RECTANGLE);
915 updateAxisButtons(l.at(0));
916 updateCoordinates(rec);
917 updateDimension(rec);
919 } else if (l.at(0)->type() == IMAGEITEM) {
920 showToolbars(TITLE_IMAGE);
922 updateCoordinates(l.at(0));
923 updateDimension(l.at(0));
925 enableToolbars(TITLE_IMAGE);
928 //toolBox->setCurrentIndex(0);
929 showToolbars(TITLE_SELECT);
930 enableToolbars(TITLE_SELECT);
931 frame_properties->setEnabled(false);
933 zValue->setValue((int)l.at(0)->zValue());
934 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
935 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
936 value_x->blockSignals(false);
937 value_y->blockSignals(false);
938 value_w->blockSignals(false);
939 value_h->blockSignals(false);
940 itemzoom->blockSignals(false);
941 itemrotate->blockSignals(false);
945 void TitleWidget::slotValueChanged(int type)
947 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
948 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
953 val = value_w->value();
956 val = value_h->value();
960 QGraphicsItem *i = l.at(0);
961 Transform t = m_transformations.value(i);
963 // Ratio width:height
964 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
965 double alpha = (double) t.rotate / 180.0 * M_PI;
975 // Add 0.5 because otherwise incrementing by 1 might have no effect
976 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
977 scale = length / i->boundingRect().width();
980 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
981 scale = length / i->boundingRect().height();
988 qtrans.scale(scale, scale);
989 qtrans.rotate(t.rotate);
990 i->setTransform(qtrans);
991 m_transformations[i] = t;
998 /** \brief Updates position/size of the selected item when a value
999 * of an item (coordinates, size) has changed */
1000 void TitleWidget::slotAdjustSelectedItem()
1002 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1003 if (l.size() >= 1) {
1004 if (l.at(0)->type() == RECTITEM) {
1006 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
1007 updatePosition(rec);
1008 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
1009 } else if (l.at(0)->type() == TEXTITEM) {
1011 updatePosition(l.at(0));
1012 } else if (l.at(0)->type() == IMAGEITEM) {
1014 updatePosition(l.at(0));
1019 /** \brief Updates width/height int the text fields, regarding transformation matrix */
1020 void TitleWidget::updateDimension(QGraphicsItem *i)
1022 value_w->blockSignals(true);
1023 value_h->blockSignals(true);
1024 zValue->blockSignals(true);
1026 zValue->setValue((int) i->zValue());
1027 if (i->type() == IMAGEITEM) {
1028 // Get multipliers for rotation/scaling
1030 /*Transform t = m_transformations.value(i);
1031 QRectF r = i->boundingRect();
1032 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1033 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1034 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1035 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1037 value_w->setValue(i->sceneBoundingRect().width());
1038 value_h->setValue(i->sceneBoundingRect().height());
1039 } else if (i->type() == RECTITEM) {
1040 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1041 value_w->setValue((int) r->rect().width());
1042 value_h->setValue((int) r->rect().height());
1043 } else if (i->type() == TEXTITEM) {
1044 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1045 value_w->setValue((int) t->boundingRect().width());
1046 value_h->setValue((int) t->boundingRect().height());
1049 zValue->blockSignals(false);
1050 value_w->blockSignals(false);
1051 value_h->blockSignals(false);
1054 /** \brief Updates the coordinates in the text fields from the item */
1055 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1057 // Block signals emitted by this method
1058 value_x->blockSignals(true);
1059 value_y->blockSignals(true);
1061 if (i->type() == TEXTITEM) {
1063 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1065 // Set the correct x coordinate value
1066 if (origin_x_left->isChecked()) {
1067 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1068 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1070 // Origin is at 0 (default)
1071 value_x->setValue((int) rec->pos().x());
1075 if (origin_y_top->isChecked()) {
1076 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1078 value_y->setValue((int) rec->pos().y());
1081 } else if (i->type() == RECTITEM) {
1083 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1085 if (origin_x_left->isChecked()) {
1086 // Origin (0 point) is at m_frameWidth
1087 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1089 // Origin is at 0 (default)
1090 value_x->setValue((int) rec->pos().x());
1093 if (origin_y_top->isChecked()) {
1094 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1096 value_y->setValue((int) rec->pos().y());
1099 } else if (i->type() == IMAGEITEM) {
1101 if (origin_x_left->isChecked()) {
1102 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1104 value_x->setValue((int) i->pos().x());
1107 if (origin_y_top->isChecked()) {
1108 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1110 value_y->setValue((int) i->pos().y());
1115 // Stop blocking signals now
1116 value_x->blockSignals(false);
1117 value_y->blockSignals(false);
1120 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1122 itemzoom->blockSignals(true);
1123 itemrotate->blockSignals(false);
1125 Transform t = m_transformations.value(i);
1126 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1127 itemrotate->setValue((int)(t.rotate));
1129 itemzoom->blockSignals(false);
1130 itemrotate->blockSignals(false);
1133 /** \brief Updates the position of an item by reading coordinates from the text fields */
1134 void TitleWidget::updatePosition(QGraphicsItem *i)
1136 if (i->type() == TEXTITEM) {
1137 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1140 if (origin_x_left->isChecked()) {
1141 /* Origin of the x axis is at m_frameWidth,
1142 * and distance from right border of the item to the right
1143 * border of the frame is taken.
1144 * See comment to slotOriginXClicked().
1146 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1148 posX = value_x->value();
1152 if (origin_y_top->isChecked()) {
1153 /* Same for y axis */
1154 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1156 posY = value_y->value();
1159 rec->setPos(posX, posY);
1161 } else if (i->type() == RECTITEM) {
1163 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1166 if (origin_x_left->isChecked()) {
1167 posX = m_frameWidth - value_x->value() - rec->rect().width();
1169 posX = value_x->value();
1173 if (origin_y_top->isChecked()) {
1174 posY = m_frameHeight - value_y->value() - rec->rect().height();
1176 posY = value_y->value();
1179 rec->setPos(posX, posY);
1181 } else if (i->type() == IMAGEITEM) {
1183 if (origin_x_left->isChecked()) {
1184 // Use the sceneBoundingRect because this also regards transformations like zoom
1185 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1187 posX = value_x->value();
1191 if (origin_y_top->isChecked()) {
1192 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1194 posY = value_y->value();
1197 i->setPos(posX, posY);
1203 void TitleWidget::updateTextOriginX()
1205 if (origin_x_left->isChecked()) {
1206 origin_x_left->setText(i18n("\u2212X"));
1208 origin_x_left->setText(i18n("+X"));
1212 void TitleWidget::slotOriginXClicked()
1214 // Update the text displayed on the button.
1215 updateTextOriginX();
1217 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1218 if (l.size() >= 1) {
1219 updateCoordinates(l.at(0));
1221 // Remember x axis setting
1222 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1223 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1225 graphicsView->setFocus();
1228 void TitleWidget::updateTextOriginY()
1230 if (origin_y_top->isChecked()) {
1231 origin_y_top->setText(i18n("\u2212Y"));
1233 origin_y_top->setText(i18n("+Y"));
1237 void TitleWidget::slotOriginYClicked()
1239 // Update the text displayed on the button.
1240 updateTextOriginY();
1242 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1243 if (l.size() >= 1) {
1244 updateCoordinates(l.at(0));
1246 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1247 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1250 graphicsView->setFocus();
1253 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1255 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1256 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1257 origin_x_left->blockSignals(true);
1258 origin_y_top->blockSignals(true);
1260 if (xAxis == TitleDocument::AxisInverted) {
1261 origin_x_left->setChecked(true);
1263 origin_x_left->setChecked(false);
1265 updateTextOriginX();
1267 if (yAxis == TitleDocument::AxisInverted) {
1268 origin_y_top->setChecked(true);
1270 origin_y_top->setChecked(false);
1272 updateTextOriginY();
1274 origin_x_left->blockSignals(false);
1275 origin_y_top->blockSignals(false);
1278 void TitleWidget::slotChangeBackground()
1280 QColor color = kcolorbutton->color();
1281 color.setAlpha(horizontalSlider->value());
1282 m_frameBorder->setBrush(QBrush(color));
1286 * Something (yeah) has changed in our QGraphicsScene.
1288 void TitleWidget::slotChanged()
1290 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1291 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1292 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1297 * If the user has set origin_x_left (everything also for y),
1298 * we need to look whether a text element has been selected. If yes,
1299 * we need to ensure that the right border of the text field
1300 * remains fixed also when some text has been entered.
1302 * This is also known as right-justified, with the difference that
1303 * it is not valid for text but for its boundingRect. Text may still
1304 * be left-justified.
1306 void TitleWidget::textChanged(QGraphicsTextItem *i)
1311 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1313 if (!i->toPlainText().isEmpty()) {
1317 * Don't do anything if the string is empty. If the position
1318 * would be updated here, a newly created text field would
1319 * be set to the position of the last selected text field.
1325 void TitleWidget::slotInsertUnicode()
1327 m_unicodeDialog->exec();
1330 void TitleWidget::slotInsertUnicodeString(QString text)
1332 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1334 if (l.at(0)->type() == TEXTITEM) {
1335 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1336 t->textCursor().insertText(text);
1341 void TitleWidget::slotUpdateText()
1343 QFont font = font_family->currentFont();
1344 font.setPixelSize(font_size->value());
1345 font.setItalic(buttonItalic->isChecked());
1346 font.setUnderline(buttonUnder->isChecked());
1347 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1348 QColor color = fontColorButton->color();
1349 color.setAlpha(textAlpha->value());
1351 QColor outlineColor = textOutlineColor->color();
1352 outlineColor.setAlpha(textOutlineAlpha->value());
1353 double outlineWidth = textOutline->value() / 10.0;
1354 QGraphicsTextItem* item = NULL;
1355 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1356 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1357 item = static_cast <QGraphicsTextItem *>(l.at(0));
1360 //if (item->textCursor().selection ().isEmpty())
1361 QTextCursor cur(item->document());
1362 cur.select(QTextCursor::Document);
1363 QTextBlockFormat format = cur.blockFormat();
1364 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1365 item->setTextWidth(item->boundingRect().width());
1366 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1367 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1368 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1370 format.setAlignment(Qt::AlignLeft);
1371 item->setTextWidth(-1);
1374 item->setFont(font);
1375 QTextCharFormat cformat = cur.charFormat();
1377 item->setData(101, outlineWidth);
1378 item->setData(102, outlineColor);
1379 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
1381 cformat.setForeground(QBrush(color));
1382 cur.setCharFormat(cformat);
1383 cur.setBlockFormat(format);
1384 item->setTextCursor(cur);
1385 cur.clearSelection();
1386 item->setTextCursor(cur);
1389 void TitleWidget::rectChanged()
1391 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1392 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1393 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1394 QColor f = rectFColor->color();
1395 f.setAlpha(rectFAlpha->value());
1397 penf.setWidth(rectLineWidth->value());
1399 QColor b = rectBColor->color();
1400 b.setAlpha(rectBAlpha->value());
1401 rec->setBrush(QBrush(b));
1405 void TitleWidget::itemScaled(int val)
1407 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1408 if (l.size() == 1) {
1409 Transform x = m_transformations.value(l.at(0));
1410 x.scalex = (double)val / 100.0;
1411 x.scaley = (double)val / 100.0;
1413 qtrans.scale(x.scalex, x.scaley);
1414 qtrans.rotate(x.rotate);
1415 l[0]->setTransform(qtrans);
1416 m_transformations[l.at(0)] = x;
1417 updateDimension(l.at(0));
1421 void TitleWidget::itemRotate(int val)
1423 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1424 if (l.size() == 1) {
1425 Transform x = m_transformations[l.at(0)];
1426 x.rotate = (double)val;
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::itemHCenter()
1438 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1439 if (l.size() == 1) {
1440 QGraphicsItem *item = l.at(0);
1441 QRectF br = item->sceneBoundingRect();
1442 int width = (int)br.width();
1443 int newPos = (int)((m_frameWidth - width) / 2);
1444 newPos += item->pos().x() - br.left(); // Check item transformation
1445 item->setPos(newPos, item->pos().y());
1446 updateCoordinates(item);
1450 void TitleWidget::itemVCenter()
1452 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1453 if (l.size() == 1) {
1454 QGraphicsItem *item = l.at(0);
1455 QRectF br = item->sceneBoundingRect();
1456 int height = (int)br.height();
1457 int newPos = (int)((m_frameHeight - height) / 2);
1458 newPos += item->pos().y() - br.top(); // Check item transformation
1459 item->setPos(item->pos().x(), newPos);
1460 updateCoordinates(item);
1464 void TitleWidget::itemTop()
1466 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1467 if (l.size() == 1) {
1468 QGraphicsItem *item = l.at(0);
1469 QRectF br = item->sceneBoundingRect();
1471 if (br.top() > 0) diff = -br.top();
1472 else diff = -br.bottom();
1473 item->moveBy(0, diff);
1474 updateCoordinates(item);
1478 void TitleWidget::itemBottom()
1480 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1481 if (l.size() == 1) {
1482 QGraphicsItem *item = l.at(0);
1483 QRectF br = item->sceneBoundingRect();
1485 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1486 else diff = m_frameHeight - br.bottom();
1487 item->moveBy(0, diff);
1488 updateCoordinates(item);
1492 void TitleWidget::itemLeft()
1494 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1495 if (l.size() == 1) {
1496 QGraphicsItem *item = l.at(0);
1497 QRectF br = item->sceneBoundingRect();
1499 if (br.left() > 0) diff = -br.left();
1500 else diff = -br.right();
1501 item->moveBy(diff, 0);
1502 updateCoordinates(item);
1506 void TitleWidget::itemRight()
1508 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1509 if (l.size() == 1) {
1510 QGraphicsItem *item = l.at(0);
1511 QRectF br = item->sceneBoundingRect();
1513 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1514 else diff = m_frameWidth - br.left();
1515 item->moveBy(diff, 0);
1516 updateCoordinates(item);
1520 void TitleWidget::setupViewports()
1522 //double aspect_ratio = 4.0 / 3.0;//read from project
1523 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1524 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1525 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1526 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1527 QPolygonF spoly(sp);
1528 QPolygonF epoly(ep);
1529 spoly.translate(startViewportX->value(), startViewportY->value());
1530 epoly.translate(endViewportX->value(), endViewportY->value());
1531 m_startViewport->setPolygon(spoly);
1532 m_endViewport->setPolygon(epoly);
1533 if (! insertingValues) {
1534 m_startViewport->setData(0, startViewportX->value());
1535 m_startViewport->setData(1, startViewportY->value());
1536 m_startViewport->setData(2, startViewportSize->value());
1538 m_endViewport->setData(0, endViewportX->value());
1539 m_endViewport->setData(1, endViewportY->value());
1540 m_endViewport->setData(2, endViewportSize->value());
1544 void TitleWidget::loadTitle(KUrl url)
1546 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1547 if (!url.isEmpty()) {
1548 QList<QGraphicsItem *> items = m_scene->items();
1549 for (int i = 0; i < items.size(); i++) {
1550 if (items.at(i)->zValue() > -1000) delete items.at(i);
1552 m_scene->clearTextSelection();
1556 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1557 QFile file(tmpfile);
1558 if (file.open(QIODevice::ReadOnly)) {
1559 doc.setContent(&file, false);
1562 KIO::NetAccess::removeTempFile(tmpfile);
1567 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1569 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1570 insertingValues = true;
1571 startViewportX->setValue(m_startViewport->data(0).toInt());
1572 startViewportY->setValue(m_startViewport->data(1).toInt());
1573 startViewportSize->setValue(m_startViewport->data(2).toInt());
1574 endViewportX->setValue(m_endViewport->data(0).toInt());
1575 endViewportY->setValue(m_endViewport->data(1).toInt());
1576 endViewportSize->setValue(m_endViewport->data(2).toInt());
1578 insertingValues = false;
1584 void TitleWidget::saveTitle(KUrl url)
1586 if (anim_start->isChecked()) slotAnimStart(false);
1587 if (anim_end->isChecked()) slotAnimEnd(false);
1588 if (url.isEmpty()) {
1589 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1590 fs->setOperationMode(KFileDialog::Saving);
1591 fs->setMode(KFile::File);
1592 #if KDE_IS_VERSION(4,2,0)
1593 fs->setConfirmOverwrite(true);
1595 fs->setKeepLocation(true);
1597 url = fs->selectedUrl();
1600 if (!url.isEmpty()) {
1601 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1602 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1606 QDomDocument TitleWidget::xml()
1608 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1609 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1613 int TitleWidget::duration() const
1615 return m_tc.getFrameCount(title_duration->text());
1618 void TitleWidget::setXml(QDomDocument doc)
1621 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1623 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1624 /*if (doc.documentElement().hasAttribute("out")) {
1625 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1626 title_duration->setText(m_tc.getTimecode(duration));
1628 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1630 QDomElement e = doc.documentElement();
1631 m_transformations.clear();
1632 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1633 const double PI = 4.0 * atan(1.0);
1634 for (int i = 0; i < items.count(); i++) {
1635 QTransform t = items.at(i)->transform();
1639 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1640 m_transformations[items.at(i)] = x;
1642 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1643 QColor background_color = m_titledocument.getBackgroundColor();
1644 horizontalSlider->blockSignals(true);
1645 kcolorbutton->blockSignals(true);
1646 horizontalSlider->setValue(background_color.alpha());
1647 background_color.setAlpha(255);
1648 kcolorbutton->setColor(background_color);
1649 horizontalSlider->blockSignals(false);
1650 kcolorbutton->blockSignals(false);
1652 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1653 startViewportY->setValue(m_startViewport->data(1).toInt());
1654 startViewportSize->setValue(m_startViewport->data(2).toInt());
1655 endViewportX->setValue(m_endViewport->data(0).toInt());
1656 endViewportY->setValue(m_endViewport->data(1).toInt());
1657 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1659 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1663 /** \brief Connected to the accepted signal - calls writeChoices */
1664 void TitleWidget::slotAccepted()
1666 if (anim_start->isChecked()) slotAnimStart(false);
1667 if (anim_end->isChecked()) slotAnimEnd(false);
1671 /** \brief Store the current choices of font, background and rect values */
1672 void TitleWidget::writeChoices()
1674 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1675 KSharedConfigPtr config = KGlobal::config();
1676 KConfigGroup titleConfig(config, "TitleWidget");
1677 // Write the entries
1678 titleConfig.writeEntry("font_family", font_family->currentFont());
1679 //titleConfig.writeEntry("font_size", font_size->value());
1680 titleConfig.writeEntry("font_pixel_size", font_size->value());
1681 titleConfig.writeEntry("font_color", fontColorButton->color());
1682 titleConfig.writeEntry("font_alpha", textAlpha->value());
1683 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1684 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1685 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1687 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1688 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1689 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1690 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1691 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1693 titleConfig.writeEntry("background_color", kcolorbutton->color());
1694 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1696 //! \todo Not sure if I should sync - it is probably safe to do it
1701 /** \brief Read the last stored choices into the dialog */
1702 void TitleWidget::readChoices()
1704 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1705 KSharedConfigPtr config = KGlobal::config();
1706 KConfigGroup titleConfig(config, "TitleWidget");
1708 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1709 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1710 m_scene->slotUpdateFontSize(font_size->value());
1711 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1712 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1714 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1715 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1716 setFontBoxWeight(weight);
1717 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1718 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1720 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1721 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1722 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1723 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1724 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1726 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1727 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1730 void TitleWidget::adjustFrameSize()
1732 m_frameWidth = m_titledocument.frameWidth();
1733 m_frameHeight = m_titledocument.frameHeight();
1734 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1735 displayBackgroundFrame();
1738 void TitleWidget::slotAnimStart(bool anim)
1740 if (anim && anim_end->isChecked()) {
1741 anim_end->setChecked(false);
1742 m_endViewport->setZValue(-1000);
1743 m_endViewport->setBrush(QBrush());
1746 QList<QGraphicsItem *> list = m_scene->items();
1747 for (int i = 0; i < list.count(); i++) {
1748 if (list.at(i)->zValue() > -1000) {
1749 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1750 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1753 align_box->setEnabled(anim);
1754 itemzoom->setEnabled(!anim);
1755 itemrotate->setEnabled(!anim);
1756 frame_toolbar->setEnabled(!anim);
1757 toolbar_stack->setEnabled(!anim);
1759 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1760 m_startViewport->setZValue(1100);
1761 QColor col = m_startViewport->pen().color();
1763 m_startViewport->setBrush(col);
1764 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1765 m_startViewport->setSelected(true);
1768 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1770 m_startViewport->setZValue(-1000);
1771 m_startViewport->setBrush(QBrush());
1772 m_startViewport->setFlags(0);
1773 if (!anim_end->isChecked()) deleteAnimInfoText();
1778 void TitleWidget::slotAnimEnd(bool anim)
1780 if (anim && anim_start->isChecked()) {
1781 anim_start->setChecked(false);
1782 m_startViewport->setZValue(-1000);
1783 m_startViewport->setBrush(QBrush());
1786 QList<QGraphicsItem *> list = m_scene->items();
1787 for (int i = 0; i < list.count(); i++) {
1788 if (list.at(i)->zValue() > -1000) {
1789 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1790 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1793 align_box->setEnabled(anim);
1794 itemzoom->setEnabled(!anim);
1795 itemrotate->setEnabled(!anim);
1796 frame_toolbar->setEnabled(!anim);
1797 toolbar_stack->setEnabled(!anim);
1799 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1800 m_endViewport->setZValue(1100);
1801 QColor col = m_endViewport->pen().color();
1803 m_endViewport->setBrush(col);
1804 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1805 m_endViewport->setSelected(true);
1808 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
1810 m_endViewport->setZValue(-1000);
1811 m_endViewport->setBrush(QBrush());
1812 m_endViewport->setFlags(0);
1813 if (!anim_start->isChecked()) deleteAnimInfoText();
1817 void TitleWidget::addAnimInfoText()
1819 // add text to anim viewport
1820 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
1821 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
1822 QFont font = t->font();
1823 font.setPixelSize(m_startViewport->rect().width() / 10);
1824 QColor col = m_startViewport->pen().color();
1826 t->setDefaultTextColor(col);
1828 font.setPixelSize(m_endViewport->rect().width() / 10);
1829 col = m_endViewport->pen().color();
1831 t2->setDefaultTextColor(col);
1835 void TitleWidget::updateInfoText()
1837 // update info text font
1838 if (!m_startViewport->childItems().isEmpty()) {
1839 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
1841 QFont font = item->font();
1842 font.setPixelSize(m_startViewport->rect().width() / 10);
1843 item->setFont(font);
1846 if (!m_endViewport->childItems().isEmpty()) {
1847 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
1849 QFont font = item->font();
1850 font.setPixelSize(m_endViewport->rect().width() / 10);
1851 item->setFont(font);
1856 void TitleWidget::deleteAnimInfoText()
1858 // end animation editing, remove info text
1859 while (!m_startViewport->childItems().isEmpty()) {
1860 QGraphicsItem *item = m_startViewport->childItems().at(0);
1861 m_scene->removeItem(item);
1864 while (!m_endViewport->childItems().isEmpty()) {
1865 QGraphicsItem *item = m_endViewport->childItems().at(0);
1866 m_scene->removeItem(item);
1872 void TitleWidget::slotKeepAspect(bool keep)
1874 if (m_endViewport->zValue() == 1100) {
1875 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1876 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1878 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1879 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1883 void TitleWidget::slotResize50()
1885 if (m_endViewport->zValue() == 1100) {
1886 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1887 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1890 void TitleWidget::slotResize100()
1892 if (m_endViewport->zValue() == 1100) {
1893 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1894 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1897 void TitleWidget::slotResize200()
1899 if (m_endViewport->zValue() == 1100) {
1900 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1901 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1904 void TitleWidget::slotAddEffect(int ix)
1906 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1907 int effect = effect_list->itemData(ix).toInt();
1908 if (effect == NOEFFECT) {
1909 if (l.size() == 1) l[0]->setData(100, QVariant());
1910 effect_stack->setHidden(true);
1913 effect_stack->setCurrentIndex(effect - 1);
1914 effect_stack->setHidden(false);
1915 if (effect == TYPEWRITEREFFECT) {
1916 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1917 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1918 l[0]->setData(100, effdata);
1921 #if QT_VERSION < 0x040600
1924 if (effect == BLUREFFECT) {
1926 if (l.size() == 1) {
1927 QGraphicsEffect *eff = new QGraphicsBlurEffect();
1928 l[0]->setGraphicsEffect(eff);
1930 } else if (effect == SHADOWEFFECT) {
1931 if (l.size() == 1) {
1932 QGraphicsEffect *eff = new QGraphicsDropShadowEffect();
1933 l[0]->setGraphicsEffect(eff);
1941 void TitleWidget::slotFontText(const QString& s)
1944 if (f.exactMatch()) {
1945 // Font really exists (could also just be a «d» if the user
1946 // starts typing «dejavu» for example).
1947 font_family->setCurrentFont(f);
1949 // Note: Typing dejavu serif does not recognize the font (takes sans)
1950 // in older Qt versions.
1953 void TitleWidget::slotEditTypewriter(int ix)
1955 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1956 if (l.size() == 1) {
1957 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
1958 l[0]->setData(100, effdata);
1962 void TitleWidget::slotEditBlur(int ix)
1964 #if QT_VERSION < 0x040600
1967 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1968 if (l.size() == 1) {
1969 QGraphicsEffect *eff = l[0]->graphicsEffect();
1970 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
1971 if (blur) blur->setBlurRadius(ix);
1976 void TitleWidget::slotEditShadow()
1978 #if QT_VERSION < 0x040600
1981 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1982 if (l.size() == 1) {
1983 QGraphicsEffect *eff = l[0]->graphicsEffect();
1984 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
1986 shadow->setBlurRadius(shadow_radius->value());
1987 shadow->setOffset(shadow_x->value(), shadow_y->value());
1993 qreal TitleWidget::zIndexBounds(bool maxBound)
1995 qreal bound = maxBound ? -99 : 99;
1996 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1998 QList<QGraphicsItem*> lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
1999 if (lItems.size() > 0) {
2000 int n = lItems.size();
2003 for (int i = 0; i < n; i++) {
2004 z = lItems[i]->zValue();
2005 if (z > bound && !lItems[i]->isSelected()) {
2010 // Get minimum z index.
2011 for (int i = 0; i < n; i++) {
2012 z = lItems[i]->zValue();
2013 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2014 // There are items at the very bottom (background e.g.) with z-index < -1000.
2024 void TitleWidget::slotZIndexUp()
2026 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2027 if (l.size() >= 1) {
2028 qreal currentZ = l[0]->zValue();
2029 qreal max = zIndexBounds(true);
2030 if (currentZ <= max) {
2031 l[0]->setZValue(currentZ + 1);
2032 updateDimension(l[0]);
2037 void TitleWidget::slotZIndexTop()
2039 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2040 if (l.size() >= 1) {
2041 qreal currentZ = l[0]->zValue();
2042 qreal max = zIndexBounds(true);
2043 if (currentZ <= max) {
2044 l[0]->setZValue(max + 1);
2045 updateDimension(l[0]);
2050 void TitleWidget::slotZIndexDown()
2052 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2053 if (l.size() >= 1) {
2054 qreal currentZ = l[0]->zValue();
2055 qreal min = zIndexBounds(false);
2056 if (currentZ >= min) {
2057 l[0]->setZValue(currentZ - 1);
2058 updateDimension(l[0]);
2063 void TitleWidget::slotZIndexBottom()
2065 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2066 if (l.size() >= 1) {
2067 qreal currentZ = l[0]->zValue();
2068 qreal min = zIndexBounds(false);
2069 if (currentZ >= min) {
2070 l[0]->setZValue(min - 1);
2071 updateDimension(l[0]);