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