]> git.sesse.net Git - kdenlive/blob - src/titlewidget.cpp
progress in timeline overwrite mode
[kdenlive] / src / titlewidget.cpp
1 /***************************************************************************
2                           titlewidget.cpp  -  description
3                              -------------------
4     begin                : Feb 28 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "titlewidget.h"
19 #include "kdenlivesettings.h"
20
21 #include <cmath>
22
23 #include <KDebug>
24 #include <KGlobalSettings>
25 #include <KFileDialog>
26 #include <KStandardDirs>
27 #include <KMessageBox>
28 #include <kio/netaccess.h>
29 #include <kdeversion.h>
30
31 #include <QDomDocument>
32 #include <QGraphicsItem>
33 #include <QGraphicsSvgItem>
34 #include <QTimer>
35 #include <QToolBar>
36 #include <QMenu>
37 #include <QSignalMapper>
38 #include <QTextBlockFormat>
39 #include <QTextCursor>
40
41 int settingUp = false;
42
43 const int IMAGEITEM = 7;
44 const int RECTITEM = 3;
45 const int TEXTITEM = 8;
46
47 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
48         QDialog(parent),
49         Ui::TitleWidget_UI(),
50         m_startViewport(NULL),
51         m_endViewport(NULL),
52         m_render(render),
53         m_count(0),
54         m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
55         m_projectTitlePath(projectTitlePath),
56         m_tc(tc)
57 {
58     setupUi(this);
59     setFont(KGlobalSettings::toolBarFont());
60     frame_properties->setEnabled(false);
61     rect_properties->setFixedHeight(frame_properties->height() + 4);
62     no_properties->setFixedHeight(frame_properties->height() + 4);
63     image_properties->setFixedHeight(frame_properties->height() + 4);
64     text_properties->setFixedHeight(frame_properties->height() + 4);
65     frame_properties->setFixedHeight(frame_toolbar->height());
66
67     itemzoom->setSuffix(i18n("%"));
68     m_frameWidth = render->renderWidth();
69     m_frameHeight = render->renderHeight();
70     showToolbars(TITLE_NONE);
71
72     //TODO: get default title duration instead of hardcoded one
73     title_duration->setText(m_tc.getTimecode(GenTime(5000 / 1000.0)));
74
75     connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
76     connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
77
78     connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
79     connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
80     connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
81     connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
82     connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
83
84     connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
85     connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
86     connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
87     connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
88     connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
89
90     /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
91     connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
92     connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
93     connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
94     connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
95     connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
96
97     connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
98     connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
99     connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
100     connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
101     connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
102     connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
103     connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
104     connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
105     connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
106
107     connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
108     connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
109
110     m_signalMapper = new QSignalMapper(this);
111     m_signalMapper->setMapping(value_w, ValueWidth);
112     m_signalMapper->setMapping(value_h, ValueHeight);
113     connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
114     connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
115     connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
116
117     connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
118     connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
119     connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
120     connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
121     connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
122     connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
123     connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
124     connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
125     connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
126     connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
127     connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
128     connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
129     //connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
130     connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
131
132     connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
133
134     // mbd
135     connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
136
137     font_weight_box->blockSignals(true);
138     font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
139     font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
140     font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
141     font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
142     font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
143     font_weight_box->setToolTip(i18n("Font weight"));
144     font_weight_box->setCurrentIndex(1);
145     font_weight_box->blockSignals(false);
146
147     buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
148     buttonRealSize->setIcon(KIcon("zoom-original"));
149     buttonItalic->setIcon(KIcon("format-text-italic"));
150     buttonUnder->setIcon(KIcon("format-text-underline"));
151     buttonAlignCenter->setIcon(KIcon("format-justify-center"));
152     buttonAlignLeft->setIcon(KIcon("format-justify-left"));
153     buttonAlignRight->setIcon(KIcon("format-justify-right"));
154     buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
155
156     buttonAlignNone->setToolTip(i18n("No alignment"));
157     buttonAlignRight->setToolTip(i18n("Align right"));
158     buttonAlignLeft->setToolTip(i18n("Align left"));
159     buttonAlignCenter->setToolTip(i18n("Align center"));
160
161     m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
162     m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
163     m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
164     connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
165     buttonInsertUnicode->setDefaultAction(m_unicodeAction);
166
167     origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
168     origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
169     rectBColor->setToolTip(i18n("Select fill color"));
170     rectFColor->setToolTip(i18n("Select border color"));
171     rectBAlpha->setToolTip(i18n("Fill transparency"));
172     rectFAlpha->setToolTip(i18n("Border transparency"));
173     zoom_slider->setToolTip(i18n("Zoom"));
174     buttonRealSize->setToolTip(i18n("Original size (1:1)"));
175     buttonFitZoom->setToolTip(i18n("Fit zoom"));
176     kcolorbutton->setToolTip(i18n("Select background color"));
177     horizontalSlider->setToolTip(i18n("Background Transparency"));
178
179     itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
180     itemhcenter->setToolTip(i18n("Align item horizontally"));
181     itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
182     itemvcenter->setToolTip(i18n("Align item vertically"));
183     itemtop->setIcon(KIcon("kdenlive-align-top"));
184     itemtop->setToolTip(i18n("Align item to top"));
185     itembottom->setIcon(KIcon("kdenlive-align-bottom"));
186     itembottom->setToolTip(i18n("Align item to bottom"));
187     itemright->setIcon(KIcon("kdenlive-align-right"));
188     itemright->setToolTip(i18n("Align item to right"));
189     itemleft->setIcon(KIcon("kdenlive-align-left"));
190     itemleft->setToolTip(i18n("Align item to left"));
191
192
193     QHBoxLayout *layout = new QHBoxLayout;
194     frame_toolbar->setLayout(layout);
195     layout->setContentsMargins(2, 2, 2, 2);
196     QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
197
198     m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
199     m_buttonCursor->setCheckable(true);
200     m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
201     m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
202     connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
203
204     m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
205     m_buttonText->setCheckable(true);
206     m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
207     m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
208     connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
209
210     m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
211     m_buttonRect->setCheckable(true);
212     m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
213     m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
214     connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
215
216     m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
217     m_buttonImage->setCheckable(false);
218     m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
219     m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
220     connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
221
222     m_toolbar->addSeparator();
223
224     m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
225     m_buttonLoad->setCheckable(false);
226     m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
227     connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
228
229     m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
230     m_buttonSave->setCheckable(false);
231     m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
232     connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
233
234     layout->addWidget(m_toolbar);
235
236     // initialize graphic scene
237     m_scene = new GraphicsSceneRectMove(this);
238     graphicsView->setScene(m_scene);
239     m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
240     connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
241
242     // a gradient background
243     /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
244     gradient->setSpread(QGradient::ReflectSpread);
245     scene->setBackgroundBrush(*gradient);*/
246
247     m_frameImage = new QGraphicsPixmapItem();
248     QTransform qtrans;
249     qtrans.scale(2.0, 2.0);
250     m_frameImage->setTransform(qtrans);
251     m_frameImage->setZValue(-1200);
252     m_frameImage->setFlags(0);
253     displayBackgroundFrame();
254     graphicsView->scene()->addItem(m_frameImage);
255
256     connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
257     connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
258     connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
259     connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
260     //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
261     connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
262     connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
263     connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
264
265     QPen framepen(Qt::DotLine);
266     framepen.setColor(Qt::red);
267
268     m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
269     m_frameBorder->setPen(framepen);
270     m_frameBorder->setZValue(-1100);
271     m_frameBorder->setBrush(Qt::transparent);
272     m_frameBorder->setFlags(0);
273     graphicsView->scene()->addItem(m_frameBorder);
274
275     // mbd: load saved settings
276     readChoices();
277
278     graphicsView->show();
279     //graphicsView->setRenderHint(QPainter::Antialiasing);
280     graphicsView->setInteractive(true);
281     //graphicsView->resize(400, 300);
282     kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
283     //toolBox->setItemEnabled(2, false);
284     m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
285     m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
286     m_startViewport->setData(0, m_frameWidth);
287     m_startViewport->setData(1, m_frameHeight);
288     m_endViewport->setData(0, m_frameWidth);
289     m_endViewport->setData(1, m_frameHeight);
290
291     if (!url.isEmpty()) loadTitle(url);
292     else {
293         slotTextTool();
294         QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
295     }
296     initAnimation();
297     connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
298     connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
299 }
300
301 TitleWidget::~TitleWidget()
302 {
303     delete m_buttonRect;
304     delete m_buttonText;
305     delete m_buttonImage;
306     delete m_buttonCursor;
307     delete m_buttonSave;
308     delete m_buttonLoad;
309     delete m_unicodeAction;
310
311     delete m_unicodeDialog;
312     delete m_frameBorder;
313     delete m_frameImage;
314     delete m_startViewport;
315     delete m_endViewport;
316     delete m_scene;
317     delete m_signalMapper;
318 }
319
320 //static
321 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
322 {
323     QStringList result;
324     QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
325     KStandardDirs::makeDir(titlePath);
326     titlePath.append((isClone == false) ? "title" : "clone");
327     int counter = 0;
328     QString path;
329     while (path.isEmpty() || QFile::exists(path)) {
330         counter++;
331         path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
332     }
333     result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
334     result.append(path);
335     return result;
336 }
337
338 // static
339 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
340 {
341     QStringList result;
342     QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
343     KStandardDirs::makeDir(titlePath);
344     return titlePath + titleName + ".png";
345 }
346
347 // static
348 QStringList TitleWidget::extractImageList(QString xml)
349 {
350     QStringList result;
351     if (xml.isEmpty()) return result;
352     QDomDocument doc;
353     doc.setContent(xml);
354     QDomNodeList images = doc.elementsByTagName("content");
355     for (int i = 0; i < images.count(); i++) {
356         if (images.at(i).toElement().hasAttribute("url"))
357             result.append(images.at(i).toElement().attribute("url"));
358     }
359     return result;
360 }
361
362
363 //virtual
364 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
365 {
366     //slotAdjustZoom();
367 }
368
369 void TitleWidget::slotTextTool()
370 {
371     m_scene->setTool(TITLE_TEXT);
372     showToolbars(TITLE_TEXT);
373     checkButton(TITLE_TEXT);
374 }
375
376 void TitleWidget::slotRectTool()
377 {
378     m_scene->setTool(TITLE_RECTANGLE);
379     showToolbars(TITLE_RECTANGLE);
380     checkButton(TITLE_RECTANGLE);
381 }
382
383 void TitleWidget::slotSelectTool()
384 {
385     m_scene->setTool(TITLE_SELECT);
386
387     // Find out which toolbars need to be shown, depending on selected item
388     TITLETOOL t = TITLE_SELECT;
389     QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
390     if (l.size() > 0) {
391         switch (l.at(0)->type()) {
392         case TEXTITEM:
393             t = TITLE_TEXT;
394             break;
395         case RECTITEM:
396             t = TITLE_RECTANGLE;
397             break;
398         case IMAGEITEM:
399             t = TITLE_IMAGE;
400             break;
401         }
402     }
403
404     enableToolbars(t);
405     if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
406         //graphicsView->centerOn(l.at(0));
407         t = TITLE_NONE;
408     }
409     showToolbars(t);
410
411     if (l.size() > 0) {
412         updateCoordinates(l.at(0));
413         updateDimension(l.at(0));
414         updateRotZoom(l.at(0));
415     }
416
417     checkButton(TITLE_SELECT);
418 }
419
420 void TitleWidget::slotImageTool()
421 {
422     // TODO: find a way to get a list of all supported image types...
423     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";
424     KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
425     if (!url.isEmpty()) {
426         if (url.path().endsWith(".svg")) {
427             QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
428             svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
429             svg->setZValue(m_count++);
430             svg->setData(Qt::UserRole, url.path());
431             graphicsView->scene()->addItem(svg);
432         } else {
433             QPixmap pix(url.path());
434             QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
435             image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
436             image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
437             image->setData(Qt::UserRole, url.path());
438             image->setZValue(m_count++);
439             graphicsView->scene()->addItem(image);
440         }
441     }
442     m_scene->setTool(TITLE_SELECT);
443     showToolbars(TITLE_SELECT);
444     checkButton(TITLE_NONE);
445 }
446
447 void TitleWidget::showToolbars(TITLETOOL toolType)
448 {
449     switch (toolType) {
450     case TITLE_TEXT:
451         rect_properties->setHidden(true);
452         image_properties->setHidden(true);
453         no_properties->setHidden(true);
454         text_properties->setHidden(false);
455         break;
456     case TITLE_RECTANGLE:
457         image_properties->setHidden(true);
458         no_properties->setHidden(true);
459         text_properties->setHidden(true);
460         rect_properties->setHidden(false);
461         break;
462     case TITLE_IMAGE:
463         no_properties->setHidden(true);
464         text_properties->setHidden(true);
465         rect_properties->setHidden(true);
466         image_properties->setHidden(false);
467         break;
468     default:
469         text_properties->setHidden(true);
470         rect_properties->setHidden(true);
471         image_properties->setHidden(true);
472         no_properties->setHidden(false);
473         break;
474     }
475 }
476
477 void TitleWidget::enableToolbars(TITLETOOL toolType)
478 {
479     // TITLETOOL is defined in graphicsscenerectmove.h
480     bool bFrame = false;
481     bool bText = false;
482     bool bRect = false;
483     bool bImage = false;
484     bool bValue_w = false;
485     bool bValue_h = false;
486
487     switch (toolType) {
488     case TITLE_SELECT:
489         break;
490     case TITLE_TEXT:
491         bFrame = true;
492         bText = true;
493         break;
494     case TITLE_RECTANGLE:
495         bFrame = true;
496         bRect = true;
497         bValue_w = true;
498         bValue_h = true;
499         break;
500     case TITLE_IMAGE:
501         bFrame = true;
502         bValue_w = true;
503         bValue_h = true;
504         bImage = true;
505         break;
506     default:
507         break;
508     }
509     frame_properties->setEnabled(bFrame);
510     text_properties->setEnabled(bText);
511     rect_properties->setEnabled(bRect);
512     image_properties->setEnabled(bImage);
513     value_w->setEnabled(bValue_w);
514     value_h->setEnabled(bValue_h);
515 }
516
517 void TitleWidget::checkButton(TITLETOOL toolType)
518 {
519     bool bSelect = false;
520     bool bText = false;
521     bool bRect = false;
522     bool bImage = false;
523
524     switch (toolType) {
525     case TITLE_SELECT:
526         bSelect = true;
527         break;
528     case TITLE_TEXT:
529         bText = true;
530         break;
531     case TITLE_RECTANGLE:
532         bRect = true;
533         break;
534     case TITLE_IMAGE:
535         bImage = true;
536         break;
537     case TITLE_NONE:
538         break;
539     }
540
541     m_buttonCursor->setChecked(bSelect);
542     m_buttonText->setChecked(bText);
543     m_buttonRect->setChecked(bRect);
544     m_buttonImage->setChecked(bImage);
545 }
546
547 void TitleWidget::displayBackgroundFrame()
548 {
549     if (!displayBg->isChecked()) {
550         QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
551         QPixmap pattern(20, 20);
552         pattern.fill();
553         QColor bgcolor(210, 210, 210);
554         QPainter p;
555         p.begin(&pattern);
556         p.fillRect(QRect(0, 0, 10, 10), bgcolor);
557         p.fillRect(QRect(10, 10, 20, 20), bgcolor);
558         p.end();
559         QBrush br(pattern);
560
561         p.begin(&bg);
562         p.fillRect(bg.rect(), br);
563         p.end();
564         m_frameImage->setPixmap(bg);
565     } else {
566         m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
567     }
568 }
569
570 void TitleWidget::initAnimation()
571 {
572     align_box->setEnabled(false);
573     QPen startpen(Qt::DotLine);
574     QPen endpen(Qt::DashDotLine);
575     startpen.setColor(QColor(100, 200, 100, 140));
576     endpen.setColor(QColor(200, 100, 100, 140));
577
578     m_startViewport->setPen(startpen);
579     m_endViewport->setPen(endpen);
580
581     m_startViewport->setZValue(-1000);
582     m_endViewport->setZValue(-1000);
583
584     m_startViewport->setFlags(0);
585     m_endViewport->setFlags(0);
586
587     graphicsView->scene()->addItem(m_startViewport);
588     graphicsView->scene()->addItem(m_endViewport);
589
590     connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
591     connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
592     connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
593     connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
594 }
595
596 void TitleWidget::slotUpdateZoom(int pos)
597 {
598     m_scene->setZoom((double) pos / 100);
599     zoom_label->setText(QString::number(pos) + '%');
600 }
601
602 void TitleWidget::slotZoom(bool up)
603 {
604     int pos = zoom_slider->value();
605     if (up) pos++;
606     else pos--;
607     zoom_slider->setValue(pos);
608 }
609
610 void TitleWidget::slotAdjustZoom()
611 {
612     /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
613     double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
614     if (scalex > scaley) scalex = scaley;
615     int zoompos = (int)(scalex * 7 + 0.5);*/
616     graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
617     int zoompos = graphicsView->matrix().m11() * 100;
618     zoom_slider->setValue(zoompos);
619     graphicsView->centerOn(m_frameBorder);
620 }
621
622 void TitleWidget::slotZoomOneToOne()
623 {
624     zoom_slider->setValue(100);
625     graphicsView->centerOn(m_frameBorder);
626 }
627
628 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
629 {
630     updateAxisButtons(rect); // back to default
631
632     QColor f = rectFColor->color();
633     f.setAlpha(rectFAlpha->value());
634     QPen penf(f);
635     penf.setWidth(rectLineWidth->value());
636     rect->setPen(penf);
637     QColor b = rectBColor->color();
638     b.setAlpha(rectBAlpha->value());
639     rect->setBrush(QBrush(b));
640     rect->setZValue(m_count++);
641     //setCurrentItem(rect);
642     //graphicsView->setFocus();
643 }
644
645 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
646 {
647     updateAxisButtons(tt); // back to default
648
649     QFont font = font_family->currentFont();
650     font.setPixelSize(font_size->value());
651     // mbd: issue 551:
652     font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
653     font.setItalic(buttonItalic->isChecked());
654     font.setUnderline(buttonUnder->isChecked());
655
656     tt->setFont(font);
657     QColor color = fontColorButton->color();
658     color.setAlpha(textAlpha->value());
659     tt->setDefaultTextColor(color);
660     tt->setZValue(m_count++);
661     setCurrentItem(tt);
662 }
663
664 void TitleWidget::setFontBoxWeight(int weight)
665 {
666     int index = font_weight_box->findData(weight);
667     if (index < 0) {
668         index = font_weight_box->findData(QFont::Normal);
669     }
670     font_weight_box->setCurrentIndex(index);
671 }
672
673 void TitleWidget::setCurrentItem(QGraphicsItem *item)
674 {
675     m_scene->setSelectedItem(item);
676 }
677
678 void TitleWidget::zIndexChanged(int v)
679 {
680     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
681     if (l.size() >= 1) {
682         l[0]->setZValue(v);
683     }
684 }
685
686 void TitleWidget::selectionChanged()
687 {
688     if (m_scene->tool() != TITLE_SELECT) return;
689     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
690     //toolBox->setItemEnabled(2, false);
691     //toolBox->setItemEnabled(3, false);
692     value_x->blockSignals(true);
693     value_y->blockSignals(true);
694     value_w->blockSignals(true);
695     value_h->blockSignals(true);
696     itemzoom->blockSignals(true);
697     itemrotate->blockSignals(true);
698     if (l.size() == 0) {
699         bool blockX = !origin_x_left->signalsBlocked();
700         bool blockY = !origin_y_top->signalsBlocked();
701         if (blockX) origin_x_left->blockSignals(true);
702         if (blockY) origin_y_top->blockSignals(true);
703         origin_x_left->setChecked(false);
704         origin_y_top->setChecked(false);
705         updateTextOriginX();
706         updateTextOriginY();
707         enableToolbars(TITLE_NONE);
708         if (blockX) origin_x_left->blockSignals(false);
709         if (blockY) origin_y_top->blockSignals(false);
710         itemzoom->setEnabled(false);
711         itemrotate->setEnabled(false);
712     } else if (l.size() == 1) {
713         if (l.at(0) != m_startViewport && l.at(0) != m_endViewport) {
714             itemzoom->setEnabled(true);
715             itemrotate->setEnabled(true);
716         } else {
717             itemzoom->setEnabled(false);
718             itemrotate->setEnabled(false);
719             updateInfoText();
720         }
721         if (l.at(0)->type() == TEXTITEM) {
722             showToolbars(TITLE_TEXT);
723             QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
724             //if (l[0]->hasFocus())
725             //toolBox->setCurrentIndex(0);
726             //toolBox->setItemEnabled(2, true);
727             font_size->blockSignals(true);
728             font_family->blockSignals(true);
729             font_weight_box->blockSignals(true);
730             buttonItalic->blockSignals(true);
731             buttonUnder->blockSignals(true);
732             fontColorButton->blockSignals(true);
733             textAlpha->blockSignals(true);
734             buttonAlignLeft->blockSignals(true);
735             buttonAlignRight->blockSignals(true);
736             buttonAlignNone->blockSignals(true);
737             buttonAlignCenter->blockSignals(true);
738
739             QFont font = i->font();
740             font_family->setCurrentFont(font);
741             font_size->setValue(font.pixelSize());
742             buttonItalic->setChecked(font.italic());
743             buttonUnder->setChecked(font.underline());
744             setFontBoxWeight(font.weight());
745
746             QColor color = i->defaultTextColor();
747             fontColorButton->setColor(color);
748             textAlpha->setValue(color.alpha());
749
750             QTextCursor cur = i->textCursor();
751             QTextBlockFormat format = cur.blockFormat();
752             if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
753             else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
754             else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
755             else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
756
757             font_size->blockSignals(false);
758             font_family->blockSignals(false);
759             font_weight_box->blockSignals(false);
760             buttonItalic->blockSignals(false);
761             buttonUnder->blockSignals(false);
762             fontColorButton->blockSignals(false);
763             textAlpha->blockSignals(false);
764             buttonAlignLeft->blockSignals(false);
765             buttonAlignRight->blockSignals(false);
766             buttonAlignNone->blockSignals(false);
767             buttonAlignCenter->blockSignals(false);
768
769             updateAxisButtons(i);
770             updateCoordinates(i);
771             updateDimension(i);
772             enableToolbars(TITLE_TEXT);
773
774         } else if ((l.at(0))->type() == RECTITEM) {
775             showToolbars(TITLE_RECTANGLE);
776             settingUp = true;
777             QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
778             if (rec == m_startViewport || rec == m_endViewport) {
779                 /*toolBox->setCurrentIndex(3);
780                 toolBox->widget(0)->setEnabled(false);
781                 toolBox->widget(1)->setEnabled(false);*/
782                 enableToolbars(TITLE_NONE);
783             } else {
784                 /*toolBox->widget(0)->setEnabled(true);
785                 toolBox->widget(1)->setEnabled(true);
786                 toolBox->setCurrentIndex(0);*/
787                 //toolBox->setItemEnabled(3, true);
788                 rectFAlpha->setValue(rec->pen().color().alpha());
789                 rectBAlpha->setValue(rec->brush().color().alpha());
790                 //kDebug() << rec->brush().color().alpha();
791                 QColor fcol = rec->pen().color();
792                 QColor bcol = rec->brush().color();
793                 //fcol.setAlpha(255);
794                 //bcol.setAlpha(255);
795                 rectFColor->setColor(fcol);
796                 rectBColor->setColor(bcol);
797                 settingUp = false;
798                 rectLineWidth->setValue(rec->pen().width());
799                 enableToolbars(TITLE_RECTANGLE);
800             }
801
802             updateAxisButtons(l.at(0));
803             updateCoordinates(rec);
804             updateDimension(rec);
805
806         } else if (l.at(0)->type() == IMAGEITEM) {
807             showToolbars(TITLE_IMAGE);
808
809             updateCoordinates(l.at(0));
810             updateDimension(l.at(0));
811
812             enableToolbars(TITLE_IMAGE);
813
814         } else {
815             //toolBox->setCurrentIndex(0);
816             showToolbars(TITLE_NONE);
817             enableToolbars(TITLE_NONE);
818             /*frame_properties->setEnabled(false);
819             text_properties->setEnabled(false);
820             rect_properties->setEnabled(false);*/
821         }
822         zValue->setValue((int)l.at(0)->zValue());
823         itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
824         itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
825         value_x->blockSignals(false);
826         value_y->blockSignals(false);
827         value_w->blockSignals(false);
828         value_h->blockSignals(false);
829         itemzoom->blockSignals(false);
830         itemrotate->blockSignals(false);
831     }
832 }
833
834 void TitleWidget::slotValueChanged(int type)
835 {
836     QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
837     if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
838
839         int val = 0;
840         switch (type) {
841         case ValueWidth:
842             val = value_w->value();
843             break;
844         case ValueHeight:
845             val = value_h->value();
846             break;
847         }
848
849         QGraphicsItem *i = l.at(0);
850         Transform t = m_transformations.value(i);
851
852         // Ratio width:height
853         double phi = (double) i->boundingRect().width() / i->boundingRect().height();
854         double alpha = (double) t.rotate / 180.0 * M_PI;
855
856         // New length
857         double length = val;
858
859         // Scaling factor
860         double scale = 1;
861
862         switch (type) {
863         case ValueWidth:
864             // Add 0.5 because otherwise incrementing by 1 might have no effect
865             length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
866             scale = length / i->boundingRect().width();
867             break;
868         case ValueHeight:
869             length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
870             scale = length / i->boundingRect().height();
871             break;
872         }
873
874         t.scalex = scale;
875         t.scaley = scale;
876         QTransform qtrans;
877         qtrans.scale(scale, scale);
878         qtrans.rotate(t.rotate);
879         i->setTransform(qtrans);
880         m_transformations[i] = t;
881
882         updateDimension(i);
883         updateRotZoom(i);
884     }
885 }
886
887 /** \brief Updates position/size of the selected item when a value
888  * of an item (coordinates, size) has changed */
889 void TitleWidget::slotAdjustSelectedItem()
890 {
891     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
892     if (l.size() >= 1) {
893         if (l.at(0)->type() == RECTITEM) {
894             //rect item
895             QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
896             updatePosition(rec);
897             rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
898         } else if (l.at(0)->type() == TEXTITEM) {
899             //text item
900             updatePosition(l.at(0));
901         } else if (l.at(0)->type() == IMAGEITEM) {
902             //image item
903             updatePosition(l.at(0));
904         }
905     }
906 }
907
908 /** \brief Updates width/height int the text fields, regarding transformation matrix */
909 void TitleWidget::updateDimension(QGraphicsItem *i)
910 {
911     value_w->blockSignals(true);
912     value_h->blockSignals(true);
913
914
915     if (i->type() == IMAGEITEM) {
916         // Get multipliers for rotation/scaling
917
918         /*Transform t = m_transformations.value(i);
919         QRectF r = i->boundingRect();
920         int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
921                     + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
922         int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
923                     + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
924
925         value_w->setValue(i->sceneBoundingRect().width());
926         value_h->setValue(i->sceneBoundingRect().height());
927     } else if (i->type() == RECTITEM) {
928         QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
929         value_w->setValue((int) r->rect().width());
930         value_h->setValue((int) r->rect().height());
931     } else if (i->type() == TEXTITEM) {
932         QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
933         value_w->setValue((int) t->boundingRect().width());
934         value_h->setValue((int) t->boundingRect().height());
935     }
936
937     value_w->blockSignals(false);
938     value_h->blockSignals(false);
939 }
940
941 /** \brief Updates the coordinates in the text fields from the item */
942 void TitleWidget::updateCoordinates(QGraphicsItem *i)
943 {
944     // Block signals emitted by this method
945     value_x->blockSignals(true);
946     value_y->blockSignals(true);
947
948     if (i->type() == TEXTITEM) {
949
950         QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
951
952         // Set the correct x coordinate value
953         if (origin_x_left->isChecked()) {
954             // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
955             value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
956         } else {
957             // Origin is at 0 (default)
958             value_x->setValue((int) rec->pos().x());
959         }
960
961         // Same for y
962         if (origin_y_top->isChecked()) {
963             value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
964         } else {
965             value_y->setValue((int) rec->pos().y());
966         }
967
968     } else if (i->type() == RECTITEM) {
969
970         QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
971
972         if (origin_x_left->isChecked()) {
973             // Origin (0 point) is at m_frameWidth
974             value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
975         } else {
976             // Origin is at 0 (default)
977             value_x->setValue((int) rec->pos().x());
978         }
979
980         if (origin_y_top->isChecked()) {
981             value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
982         } else {
983             value_y->setValue((int) rec->pos().y());
984         }
985
986     } else if (i->type() == IMAGEITEM) {
987
988         if (origin_x_left->isChecked()) {
989             value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
990         } else {
991             value_x->setValue((int) i->pos().x());
992         }
993
994         if (origin_y_top->isChecked()) {
995             value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
996         } else {
997             value_y->setValue((int) i->pos().y());
998         }
999
1000     }
1001
1002     // Stop blocking signals now
1003     value_x->blockSignals(false);
1004     value_y->blockSignals(false);
1005 }
1006
1007 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1008 {
1009     itemzoom->blockSignals(true);
1010     itemrotate->blockSignals(false);
1011
1012     Transform t = m_transformations.value(i);
1013     itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1014     itemrotate->setValue((int)(t.rotate));
1015
1016     itemzoom->blockSignals(false);
1017     itemrotate->blockSignals(false);
1018 }
1019
1020 /** \brief Updates the position of an item by reading coordinates from the text fields */
1021 void TitleWidget::updatePosition(QGraphicsItem *i)
1022 {
1023     if (i->type() == TEXTITEM) {
1024         QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1025
1026         int posX;
1027         if (origin_x_left->isChecked()) {
1028             /* Origin of the x axis is at m_frameWidth,
1029              * and distance from right border of the item to the right
1030              * border of the frame is taken.
1031              * See comment to slotOriginXClicked().
1032              */
1033             posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
1034         } else {
1035             posX = value_x->value();
1036         }
1037
1038         int posY;
1039         if (origin_y_top->isChecked()) {
1040             /* Same for y axis */
1041             posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
1042         } else {
1043             posY = value_y->value();
1044         }
1045
1046         rec->setPos(posX, posY);
1047
1048     } else if (i->type() == RECTITEM) {
1049
1050         QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1051
1052         int posX;
1053         if (origin_x_left->isChecked()) {
1054             posX = m_frameWidth - value_x->value() - rec->rect().width();
1055         } else {
1056             posX = value_x->value();
1057         }
1058
1059         int posY;
1060         if (origin_y_top->isChecked()) {
1061             posY = m_frameHeight - value_y->value() - rec->rect().height();
1062         } else {
1063             posY = value_y->value();
1064         }
1065
1066         rec->setPos(posX, posY);
1067
1068     } else if (i->type() == IMAGEITEM) {
1069         int posX;
1070         if (origin_x_left->isChecked()) {
1071             // Use the sceneBoundingRect because this also regards transformations like zoom
1072             posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1073         } else {
1074             posX = value_x->value();
1075         }
1076
1077         int posY;
1078         if (origin_y_top->isChecked()) {
1079             posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1080         } else {
1081             posY = value_y->value();
1082         }
1083
1084         i->setPos(posX, posY);
1085
1086     }
1087
1088 }
1089
1090 void TitleWidget::updateTextOriginX()
1091 {
1092     if (origin_x_left->isChecked()) {
1093         origin_x_left->setText(i18n("\u2212X"));
1094     } else {
1095         origin_x_left->setText(i18n("+X"));
1096     }
1097 }
1098
1099 void TitleWidget::slotOriginXClicked()
1100 {
1101     // Update the text displayed on the button.
1102     updateTextOriginX();
1103
1104     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1105     if (l.size() >= 1) {
1106         updateCoordinates(l.at(0));
1107
1108         // Remember x axis setting
1109         l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1110                          TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1111     }
1112     graphicsView->setFocus();
1113 }
1114
1115 void TitleWidget::updateTextOriginY()
1116 {
1117     if (origin_y_top->isChecked()) {
1118         origin_y_top->setText(i18n("\u2212Y"));
1119     } else {
1120         origin_y_top->setText(i18n("+Y"));
1121     }
1122 }
1123
1124 void TitleWidget::slotOriginYClicked()
1125 {
1126     // Update the text displayed on the button.
1127     updateTextOriginY();
1128
1129     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1130     if (l.size() >= 1) {
1131         updateCoordinates(l.at(0));
1132
1133         l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1134                          TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1135
1136     }
1137     graphicsView->setFocus();
1138 }
1139
1140 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1141 {
1142     int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1143     int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1144     origin_x_left->blockSignals(true);
1145     origin_y_top->blockSignals(true);
1146
1147     if (xAxis == TitleDocument::AxisInverted) {
1148         origin_x_left->setChecked(true);
1149     } else {
1150         origin_x_left->setChecked(false);
1151     }
1152     updateTextOriginX();
1153
1154     if (yAxis == TitleDocument::AxisInverted) {
1155         origin_y_top->setChecked(true);
1156     } else {
1157         origin_y_top->setChecked(false);
1158     }
1159     updateTextOriginY();
1160
1161     origin_x_left->blockSignals(false);
1162     origin_y_top->blockSignals(false);
1163 }
1164
1165 void TitleWidget::slotChangeBackground()
1166 {
1167     QColor color = kcolorbutton->color();
1168     color.setAlpha(horizontalSlider->value());
1169     m_frameBorder->setBrush(QBrush(color));
1170 }
1171
1172 /**
1173  * Something (yeah) has changed in our QGraphicsScene.
1174  */
1175 void TitleWidget::slotChanged()
1176 {
1177     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1178     if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1179         textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1180     }
1181 }
1182
1183 /**
1184  * If the user has set origin_x_left (everything also for y),
1185  * we need to look whether a text element has been selected. If yes,
1186  * we need to ensure that the right border of the text field
1187  * remains fixed also when some text has been entered.
1188  *
1189  * This is also known as right-justified, with the difference that
1190  * it is not valid for text but for its boundingRect. Text may still
1191  * be left-justified.
1192  */
1193 void TitleWidget::textChanged(QGraphicsTextItem *i)
1194 {
1195
1196     updateDimension(i);
1197
1198     if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1199
1200         if (!i->toPlainText().isEmpty()) {
1201             updatePosition(i);
1202         } else {
1203             /*
1204              * Don't do anything if the string is empty. If the position
1205              * would be updated here, a newly created text field would
1206              * be set to the position of the last selected text field.
1207              */
1208         }
1209     }
1210 }
1211
1212 void TitleWidget::slotInsertUnicode()
1213 {
1214     m_unicodeDialog->exec();
1215 }
1216
1217 void TitleWidget::slotInsertUnicodeString(QString text)
1218 {
1219     QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1220     if (l.size() > 0) {
1221         if (l.at(0)->type() == TEXTITEM) {
1222             QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1223             t->textCursor().insertText(text);
1224         }
1225     }
1226 }
1227
1228 void TitleWidget::slotUpdateText()
1229 {
1230     QFont font = font_family->currentFont();
1231     font.setPixelSize(font_size->value());
1232     font.setItalic(buttonItalic->isChecked());
1233     font.setUnderline(buttonUnder->isChecked());
1234     font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1235     QColor color = fontColorButton->color();
1236     color.setAlpha(textAlpha->value());
1237
1238     QGraphicsTextItem* item = NULL;
1239     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1240     if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1241         item = static_cast <QGraphicsTextItem *>(l.at(0));
1242     }
1243     if (!item) return;
1244     //if (item->textCursor().selection ().isEmpty())
1245     QTextCursor cur = item->textCursor();
1246     QTextBlockFormat format = cur.blockFormat();
1247     if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1248         item->setTextWidth(item->boundingRect().width());
1249         if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1250         else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1251         else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1252     } else {
1253         format.setAlignment(Qt::AlignLeft);
1254         item->setTextWidth(-1);
1255     }
1256
1257     {
1258         item->setFont(font);
1259         item->setDefaultTextColor(color);
1260         cur.select(QTextCursor::Document);
1261         cur.setBlockFormat(format);
1262         item->setTextCursor(cur);
1263         cur.clearSelection();
1264         item->setTextCursor(cur);
1265
1266     }
1267 }
1268
1269 void TitleWidget::rectChanged()
1270 {
1271     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1272     if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1273         QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1274         QColor f = rectFColor->color();
1275         f.setAlpha(rectFAlpha->value());
1276         QPen penf(f);
1277         penf.setWidth(rectLineWidth->value());
1278         rec->setPen(penf);
1279         QColor b = rectBColor->color();
1280         b.setAlpha(rectBAlpha->value());
1281         rec->setBrush(QBrush(b));
1282     }
1283 }
1284
1285 void TitleWidget::itemScaled(int val)
1286 {
1287     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1288     if (l.size() == 1) {
1289         Transform x = m_transformations.value(l.at(0));
1290         x.scalex = (double)val / 100.0;
1291         x.scaley = (double)val / 100.0;
1292         QTransform qtrans;
1293         qtrans.scale(x.scalex, x.scaley);
1294         qtrans.rotate(x.rotate);
1295         l[0]->setTransform(qtrans);
1296         m_transformations[l.at(0)] = x;
1297         updateDimension(l.at(0));
1298     }
1299 }
1300
1301 void TitleWidget::itemRotate(int val)
1302 {
1303     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1304     if (l.size() == 1) {
1305         Transform x = m_transformations[l.at(0)];
1306         x.rotate = (double)val;
1307         QTransform qtrans;
1308         qtrans.scale(x.scalex, x.scaley);
1309         qtrans.rotate(x.rotate);
1310         l[0]->setTransform(qtrans);
1311         m_transformations[l.at(0)] = x;
1312         updateDimension(l.at(0));
1313     }
1314 }
1315
1316 void TitleWidget::itemHCenter()
1317 {
1318     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1319     if (l.size() == 1) {
1320         QGraphicsItem *item = l.at(0);
1321         QRectF br = item->sceneBoundingRect();
1322         int width = (int)br.width();
1323         int newPos = (int)((m_frameWidth - width) / 2);
1324         newPos += item->pos().x() - br.left(); // Check item transformation
1325         item->setPos(newPos, item->pos().y());
1326         updateCoordinates(item);
1327     }
1328 }
1329
1330 void TitleWidget::itemVCenter()
1331 {
1332     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1333     if (l.size() == 1) {
1334         QGraphicsItem *item = l.at(0);
1335         QRectF br = item->sceneBoundingRect();
1336         int height = (int)br.height();
1337         int newPos = (int)((m_frameHeight - height) / 2);
1338         newPos += item->pos().y() - br.top(); // Check item transformation
1339         item->setPos(item->pos().x(), newPos);
1340         updateCoordinates(item);
1341     }
1342 }
1343
1344 void TitleWidget::itemTop()
1345 {
1346     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1347     if (l.size() == 1) {
1348         QGraphicsItem *item = l.at(0);
1349         QRectF br = item->sceneBoundingRect();
1350         double diff;
1351         if (br.top() > 0) diff = -br.top();
1352         else diff = -br.bottom();
1353         item->moveBy(0, diff);
1354         updateCoordinates(item);
1355     }
1356 }
1357
1358 void TitleWidget::itemBottom()
1359 {
1360     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1361     if (l.size() == 1) {
1362         QGraphicsItem *item = l.at(0);
1363         QRectF br = item->sceneBoundingRect();
1364         double diff;
1365         if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1366         else diff = m_frameHeight - br.bottom();
1367         item->moveBy(0, diff);
1368         updateCoordinates(item);
1369     }
1370 }
1371
1372 void TitleWidget::itemLeft()
1373 {
1374     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1375     if (l.size() == 1) {
1376         QGraphicsItem *item = l.at(0);
1377         QRectF br = item->sceneBoundingRect();
1378         double diff;
1379         if (br.left() > 0) diff = -br.left();
1380         else diff = -br.right();
1381         item->moveBy(diff, 0);
1382         updateCoordinates(item);
1383     }
1384 }
1385
1386 void TitleWidget::itemRight()
1387 {
1388     QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1389     if (l.size() == 1) {
1390         QGraphicsItem *item = l.at(0);
1391         QRectF br = item->sceneBoundingRect();
1392         double diff;
1393         if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1394         else diff = m_frameWidth - br.left();
1395         item->moveBy(diff, 0);
1396         updateCoordinates(item);
1397     }
1398 }
1399
1400 void TitleWidget::setupViewports()
1401 {
1402     //double aspect_ratio = 4.0 / 3.0;//read from project
1403     //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1404     /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1405     QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1406     // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1407     QPolygonF spoly(sp);
1408     QPolygonF epoly(ep);
1409     spoly.translate(startViewportX->value(), startViewportY->value());
1410     epoly.translate(endViewportX->value(), endViewportY->value());
1411     m_startViewport->setPolygon(spoly);
1412     m_endViewport->setPolygon(epoly);
1413     if (! insertingValues) {
1414         m_startViewport->setData(0, startViewportX->value());
1415         m_startViewport->setData(1, startViewportY->value());
1416         m_startViewport->setData(2, startViewportSize->value());
1417
1418         m_endViewport->setData(0, endViewportX->value());
1419         m_endViewport->setData(1, endViewportY->value());
1420         m_endViewport->setData(2, endViewportSize->value());
1421     }*/
1422 }
1423
1424 void TitleWidget::loadTitle(KUrl url)
1425 {
1426     if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1427     if (!url.isEmpty()) {
1428         QList<QGraphicsItem *> items = m_scene->items();
1429         for (int i = 0; i < items.size(); i++) {
1430             if (items.at(i)->zValue() > -1000) delete items.at(i);
1431         }
1432         m_scene->clearTextSelection();
1433         QDomDocument doc;
1434         QString tmpfile;
1435
1436         if (KIO::NetAccess::download(url, tmpfile, 0)) {
1437             QFile file(tmpfile);
1438             if (file.open(QIODevice::ReadOnly)) {
1439                 doc.setContent(&file, false);
1440                 file.close();
1441             } else return;
1442             KIO::NetAccess::removeTempFile(tmpfile);
1443         }
1444         setXml(doc);
1445
1446         /*int out;
1447         m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1448         adjustFrameSize();
1449         title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1450         insertingValues = true;
1451         startViewportX->setValue(m_startViewport->data(0).toInt());
1452         startViewportY->setValue(m_startViewport->data(1).toInt());
1453         startViewportSize->setValue(m_startViewport->data(2).toInt());
1454         endViewportX->setValue(m_endViewport->data(0).toInt());
1455         endViewportY->setValue(m_endViewport->data(1).toInt());
1456         endViewportSize->setValue(m_endViewport->data(2).toInt());
1457
1458         insertingValues = false;
1459         slotSelectTool();
1460         slotAdjustZoom();*/
1461     }
1462 }
1463
1464 void TitleWidget::saveTitle(KUrl url)
1465 {
1466     if (anim_start->isChecked()) slotAnimStart(false);
1467     if (anim_end->isChecked()) slotAnimEnd(false);
1468     if (url.isEmpty()) {
1469         KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1470         fs->setOperationMode(KFileDialog::Saving);
1471         fs->setMode(KFile::File);
1472 #if KDE_IS_VERSION(4,2,0)
1473         fs->setConfirmOverwrite(true);
1474 #endif
1475         fs->setKeepLocation(true);
1476         fs->exec();
1477         url = fs->selectedUrl();
1478         delete fs;
1479     }
1480     if (!url.isEmpty()) {
1481         if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text())) == false)
1482             KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1483     }
1484 }
1485
1486 QDomDocument TitleWidget::xml()
1487 {
1488     QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1489     doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1490     return doc;
1491 }
1492
1493 int TitleWidget::duration() const
1494 {
1495     return m_tc.getFrameCount(title_duration->text());
1496 }
1497
1498 void TitleWidget::setXml(QDomDocument doc)
1499 {
1500     int out;
1501     m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
1502     adjustFrameSize();
1503     title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1504     /*if (doc.documentElement().hasAttribute("out")) {
1505     GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1506     title_duration->setText(m_tc.getTimecode(duration));
1507     }
1508     else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1509
1510     QDomElement e = doc.documentElement();
1511     m_transformations.clear();
1512     QList <QGraphicsItem *> items = graphicsView->scene()->items();
1513     const double PI = 4.0 * atan(1.0);
1514     for (int i = 0; i < items.count(); i++) {
1515         QTransform t = items.at(i)->transform();
1516         Transform x;
1517         x.scalex = t.m11();
1518         x.scaley = t.m22();
1519         x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1520         m_transformations[items.at(i)] = x;
1521     }
1522     // mbd: Update the GUI color selectors to match the stuff from the loaded document
1523     QColor background_color = m_titledocument.getBackgroundColor();
1524     horizontalSlider->blockSignals(true);
1525     kcolorbutton->blockSignals(true);
1526     horizontalSlider->setValue(background_color.alpha());
1527     background_color.setAlpha(255);
1528     kcolorbutton->setColor(background_color);
1529     horizontalSlider->blockSignals(false);
1530     kcolorbutton->blockSignals(false);
1531
1532     /*startViewportX->setValue(m_startViewport->data(0).toInt());
1533     startViewportY->setValue(m_startViewport->data(1).toInt());
1534     startViewportSize->setValue(m_startViewport->data(2).toInt());
1535     endViewportX->setValue(m_endViewport->data(0).toInt());
1536     endViewportY->setValue(m_endViewport->data(1).toInt());
1537     endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1538
1539     QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1540     slotSelectTool();
1541 }
1542
1543 /** \brief Connected to the accepted signal - calls writeChoices */
1544 void TitleWidget::slotAccepted()
1545 {
1546     if (anim_start->isChecked()) slotAnimStart(false);
1547     if (anim_end->isChecked()) slotAnimEnd(false);
1548     writeChoices();
1549 }
1550
1551 /** \brief Store the current choices of font, background and rect values */
1552 void TitleWidget::writeChoices()
1553 {
1554     // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1555     KSharedConfigPtr config = KGlobal::config();
1556     KConfigGroup titleConfig(config, "TitleWidget");
1557     // Write the entries
1558     titleConfig.writeEntry("font_family", font_family->currentFont());
1559     //titleConfig.writeEntry("font_size", font_size->value());
1560     titleConfig.writeEntry("font_pixel_size", font_size->value());
1561     titleConfig.writeEntry("font_color", fontColorButton->color());
1562     titleConfig.writeEntry("font_alpha", textAlpha->value());
1563     titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1564     titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1565     titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1566
1567     titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1568     titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1569     titleConfig.writeEntry("rect_background_color", rectBColor->color());
1570     titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1571     titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1572
1573     titleConfig.writeEntry("background_color", kcolorbutton->color());
1574     titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1575
1576     //! \todo Not sure if I should sync - it is probably safe to do it
1577     config->sync();
1578
1579 }
1580
1581 /** \brief Read the last stored choices into the dialog */
1582 void TitleWidget::readChoices()
1583 {
1584     // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1585     KSharedConfigPtr config = KGlobal::config();
1586     KConfigGroup titleConfig(config, "TitleWidget");
1587     // read the entries
1588     font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1589     font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1590     fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1591     textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1592     int weight;
1593     if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1594     else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1595     setFontBoxWeight(weight);
1596     buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1597     buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1598
1599     rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1600     rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1601     rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1602     rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1603     rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1604
1605     kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1606     horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1607 }
1608
1609 void TitleWidget::adjustFrameSize()
1610 {
1611     m_frameWidth = m_titledocument.frameWidth();
1612     m_frameHeight = m_titledocument.frameHeight();
1613     m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1614     displayBackgroundFrame();
1615 }
1616
1617 void TitleWidget::slotAnimStart(bool anim)
1618 {
1619     if (anim && anim_end->isChecked()) {
1620         anim_end->setChecked(false);
1621         m_endViewport->setZValue(-1000);
1622         m_endViewport->setBrush(QBrush());
1623     }
1624     slotSelectTool();
1625     QList<QGraphicsItem *> list = m_scene->items();
1626     for (int i = 0; i < list.count(); i++) {
1627         if (list.at(i)->zValue() > -1000) {
1628             list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1629             list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1630         }
1631     }
1632     align_box->setEnabled(anim);
1633     itemzoom->setEnabled(!anim);
1634     itemrotate->setEnabled(!anim);
1635     frame_toolbar->setEnabled(!anim);
1636     rect_properties->setEnabled(!anim);
1637     if (anim) {
1638         keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1639         m_startViewport->setZValue(1100);
1640         QColor col = m_startViewport->pen().color();
1641         col.setAlpha(100);
1642         m_startViewport->setBrush(col);
1643         m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1644         m_startViewport->setSelected(true);
1645         selectionChanged();
1646         slotSelectTool();
1647         if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
1648     } else {
1649         m_startViewport->setZValue(-1000);
1650         m_startViewport->setBrush(QBrush());
1651         m_startViewport->setFlags(0);
1652         if (!anim_end->isChecked()) deleteAnimInfoText();
1653     }
1654
1655 }
1656
1657 void TitleWidget::slotAnimEnd(bool anim)
1658 {
1659     if (anim && anim_start->isChecked()) {
1660         anim_start->setChecked(false);
1661         m_startViewport->setZValue(-1000);
1662         m_startViewport->setBrush(QBrush());
1663     }
1664     slotSelectTool();
1665     QList<QGraphicsItem *> list = m_scene->items();
1666     for (int i = 0; i < list.count(); i++) {
1667         if (list.at(i)->zValue() > -1000) {
1668             list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1669             list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1670         }
1671     }
1672     align_box->setEnabled(anim);
1673     itemzoom->setEnabled(!anim);
1674     itemrotate->setEnabled(!anim);
1675     frame_toolbar->setEnabled(!anim);
1676     rect_properties->setEnabled(!anim);
1677     if (anim) {
1678         keep_aspect->setChecked(!m_endViewport->data(0).isNull());
1679         m_endViewport->setZValue(1100);
1680         QColor col = m_endViewport->pen().color();
1681         col.setAlpha(100);
1682         m_endViewport->setBrush(col);
1683         m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
1684         m_endViewport->setSelected(true);
1685         selectionChanged();
1686         slotSelectTool();
1687         if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
1688     } else {
1689         m_endViewport->setZValue(-1000);
1690         m_endViewport->setBrush(QBrush());
1691         m_endViewport->setFlags(0);
1692         if (!anim_start->isChecked()) deleteAnimInfoText();
1693     }
1694 }
1695
1696 void TitleWidget::addAnimInfoText()
1697 {
1698     // add text to anim viewport
1699     QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
1700     QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
1701     QFont font = t->font();
1702     font.setPixelSize(m_startViewport->rect().width() / 10);
1703     QColor col = m_startViewport->pen().color();
1704     col.setAlpha(255);
1705     t->setDefaultTextColor(col);
1706     t->setFont(font);
1707     font.setPixelSize(m_endViewport->rect().width() / 10);
1708     col = m_endViewport->pen().color();
1709     col.setAlpha(255);
1710     t2->setDefaultTextColor(col);
1711     t2->setFont(font);
1712 }
1713
1714 void TitleWidget::updateInfoText()
1715 {
1716     // update info text font
1717     if (!m_startViewport->childItems().isEmpty()) {
1718         QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
1719         if (item) {
1720             QFont font = item->font();
1721             font.setPixelSize(m_startViewport->rect().width() / 10);
1722             item->setFont(font);
1723         }
1724     }
1725     if (!m_endViewport->childItems().isEmpty()) {
1726         QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
1727         if (item) {
1728             QFont font = item->font();
1729             font.setPixelSize(m_endViewport->rect().width() / 10);
1730             item->setFont(font);
1731         }
1732     }
1733 }
1734
1735 void TitleWidget::deleteAnimInfoText()
1736 {
1737     // end animation editing, remove info text
1738     while (!m_startViewport->childItems().isEmpty()) {
1739         QGraphicsItem *item = m_startViewport->childItems().at(0);
1740         m_scene->removeItem(item);
1741         delete item;
1742     }
1743     while (!m_endViewport->childItems().isEmpty()) {
1744         QGraphicsItem *item = m_endViewport->childItems().at(0);
1745         m_scene->removeItem(item);
1746         delete item;
1747     }
1748 }
1749
1750
1751 void TitleWidget::slotKeepAspect(bool keep)
1752 {
1753     if (m_endViewport->zValue() == 1100) {
1754         m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1755         m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1756     } else {
1757         m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
1758         m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
1759     }
1760 }
1761
1762 void TitleWidget::slotResize50()
1763 {
1764     if (m_endViewport->zValue() == 1100) {
1765         m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1766     } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
1767 }
1768
1769 void TitleWidget::slotResize100()
1770 {
1771     if (m_endViewport->zValue() == 1100) {
1772         m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1773     } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
1774 }
1775
1776 void TitleWidget::slotResize200()
1777 {
1778     if (m_endViewport->zValue() == 1100) {
1779         m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1780     } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
1781 }
1782
1783
1784