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