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