1 /***************************************************************************
2 titlewidget.cpp - description
5 copyright : (C) 2008 by Marco Gittler
6 email : g.marco@freenet.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "titlewidget.h"
19 #include "kdenlivesettings.h"
20 #include "KoSliderCombo.h"
25 #include <KGlobalSettings>
26 #include <KFileDialog>
27 #include <KStandardDirs>
28 #include <KMessageBox>
29 #include <kio/netaccess.h>
30 #include <kdeversion.h>
32 #include <QDomDocument>
33 #include <QGraphicsItem>
34 #include <QGraphicsSvgItem>
38 #include <QSignalMapper>
39 #include <QTextBlockFormat>
40 #include <QTextCursor>
42 #include <QCryptographicHash>
44 #if QT_VERSION >= 0x040600
45 #include <QGraphicsEffect>
46 #include <QGraphicsBlurEffect>
47 #include <QGraphicsDropShadowEffect>
52 static QList<TitleTemplate> titletemplates;
54 // What exactly is this variable good for?
55 int settingUp = false;
57 const int IMAGEITEM = 7;
58 const int RECTITEM = 3;
59 const int TEXTITEM = 8;
61 const int NOEFFECT = 0;
62 const int BLUREFFECT = 1;
63 const int SHADOWEFFECT = 2;
64 const int TYPEWRITEREFFECT = 3;
66 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
69 m_startViewport(NULL),
73 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
74 m_projectTitlePath(projectTitlePath),
78 setFont(KGlobalSettings::toolBarFont());
79 frame_properties->setEnabled(false);
80 frame_properties->setFixedHeight(frame_toolbar->height());
81 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
82 QSize iconSize(size, size);
84 #if KDE_IS_VERSION(4,5,0)
85 rectBColor->setAlphaChannelEnabled(true);
87 rectFColor->setAlphaChannelEnabled(true);
89 fontColorButton->setAlphaChannelEnabled(true);
91 textOutlineColor->setAlphaChannelEnabled(true);
92 delete textOutlineAlpha;
95 rectBColor->setAlphaChannelEnabled(false);
96 rectFColor->setAlphaChannelEnabled(false);
97 fontColorButton->setAlphaChannelEnabled(false);
98 textOutlineColor->setAlphaChannelEnabled(false);
100 rectBAlpha->setMinimum(0);
101 rectBAlpha->setMaximum(255);
102 rectBAlpha->setDecimals(0);
103 rectBAlpha->setValue(255);
104 rectBAlpha->setToolTip(i18n("Color opacity"));
106 rectFAlpha->setMinimum(0);
107 rectFAlpha->setMaximum(255);
108 rectFAlpha->setDecimals(0);
109 rectFAlpha->setValue(255);
110 rectFAlpha->setToolTip(i18n("Border opacity"));
111 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
112 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
114 // Set combo sliders values
115 textAlpha->setMinimum(0);
116 textAlpha->setMaximum(255);
117 textAlpha->setDecimals(0);
118 textAlpha->setValue(255);
119 textAlpha->setToolTip(i18n("Font color opacity"));
121 textOutlineAlpha->setMinimum(0);
122 textOutlineAlpha->setMaximum(255);
123 textOutlineAlpha->setDecimals(0);
124 textOutlineAlpha->setValue(255);
125 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
126 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
127 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
130 textOutline->setMinimum(0);
131 textOutline->setMaximum(200);
132 textOutline->setDecimals(0);
133 textOutline->setValue(0);
134 textOutline->setToolTip(i18n("Outline width"));
136 backgroundAlpha->setMinimum(0);
137 backgroundAlpha->setMaximum(255);
138 backgroundAlpha->setDecimals(0);
139 backgroundAlpha->setValue(0);
140 backgroundAlpha->setToolTip(i18n("Background color opacity"));
142 itemrotatex->setMinimum(-360);
143 itemrotatex->setMaximum(360);
144 itemrotatex->setDecimals(0);
145 itemrotatex->setValue(0);
146 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
148 itemrotatey->setMinimum(-360);
149 itemrotatey->setMaximum(360);
150 itemrotatey->setDecimals(0);
151 itemrotatey->setValue(0);
152 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
154 itemrotatez->setMinimum(-360);
155 itemrotatez->setMaximum(360);
156 itemrotatez->setDecimals(0);
157 itemrotatez->setValue(0);
158 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
160 rectLineWidth->setMinimum(0);
161 rectLineWidth->setMaximum(100);
162 rectLineWidth->setDecimals(0);
163 rectLineWidth->setValue(0);
164 rectLineWidth->setToolTip(i18n("Border width"));
166 itemzoom->setSuffix(i18n("%"));
167 m_frameWidth = render->renderWidth();
168 m_frameHeight = render->renderHeight();
169 showToolbars(TITLE_SELECT);
171 splitter->setStretchFactor(0, 20);
173 //If project is drop frame, set the input mask as such.
174 title_duration->setInputMask(m_tc.mask());
175 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
177 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
178 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
180 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
181 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
182 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
183 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
184 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
185 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
187 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
189 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
190 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
191 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
193 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
194 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
195 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
196 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
197 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
198 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
201 effect_list->addItem(i18n("None"), NOEFFECT);
202 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
203 effect_list->addItem(i18n("Blur"), BLUREFFECT);
206 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
207 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
208 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
209 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
210 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
211 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
212 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
213 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
214 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
215 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
216 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
217 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
218 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
219 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
220 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
221 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
222 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
223 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
224 effect_stack->setHidden(true);
225 effect_frame->setEnabled(false);
227 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
228 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
231 m_signalMapper = new QSignalMapper(this);
232 m_signalMapper->setMapping(value_w, ValueWidth);
233 m_signalMapper->setMapping(value_h, ValueHeight);
234 m_signalMapper->setMapping(value_x, ValueX);
235 m_signalMapper->setMapping(value_y, ValueY);
236 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
237 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
238 connect(value_x, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
239 connect(value_y, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
240 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
242 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
243 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
244 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
245 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
246 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
247 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
248 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
249 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
250 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
252 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
255 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
257 font_weight_box->blockSignals(true);
258 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
259 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
260 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
261 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
262 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
263 font_weight_box->setToolTip(i18n("Font weight"));
264 font_weight_box->setCurrentIndex(1);
265 font_weight_box->blockSignals(false);
267 buttonFitZoom->setIconSize(iconSize);
268 buttonRealSize->setIconSize(iconSize);
269 buttonItalic->setIconSize(iconSize);
270 buttonUnder->setIconSize(iconSize);
271 buttonAlignCenter->setIconSize(iconSize);
272 buttonAlignLeft->setIconSize(iconSize);
273 buttonAlignRight->setIconSize(iconSize);
274 buttonAlignNone->setIconSize(iconSize);
276 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
277 buttonRealSize->setIcon(KIcon("zoom-original"));
278 buttonItalic->setIcon(KIcon("format-text-italic"));
279 buttonUnder->setIcon(KIcon("format-text-underline"));
280 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
281 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
282 buttonAlignRight->setIcon(KIcon("format-justify-right"));
283 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
285 buttonAlignNone->setToolTip(i18n("No alignment"));
286 buttonAlignRight->setToolTip(i18n("Align right"));
287 buttonAlignLeft->setToolTip(i18n("Align left"));
288 buttonAlignCenter->setToolTip(i18n("Align center"));
290 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
291 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
292 m_unicodeAction->setToolTip(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
293 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
294 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
296 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
297 m_zUp->setShortcut(Qt::Key_PageUp);
298 m_zUp->setToolTip(i18n("Raise object"));
299 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
300 zUp->setDefaultAction(m_zUp);
302 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
303 m_zDown->setShortcut(Qt::Key_PageDown);
304 m_zDown->setToolTip(i18n("Lower object"));
305 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
306 zDown->setDefaultAction(m_zDown);
308 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
309 // TODO mbt 1414: Shortcut should change z index only if
310 // cursor is NOT in a text field ...
311 //m_zTop->setShortcut(Qt::Key_Home);
312 m_zTop->setToolTip(i18n("Raise object to top"));
313 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
314 zTop->setDefaultAction(m_zTop);
316 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
318 //m_zBottom->setShortcut(Qt::Key_End);
319 m_zBottom->setToolTip(i18n("Lower object to bottom"));
320 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
321 zBottom->setDefaultAction(m_zBottom);
323 m_selectAll = new QAction(KIcon("kdenlive-select-all"), QString(), this);
324 m_selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
325 connect(m_selectAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
326 buttonSelectAll->setDefaultAction(m_selectAll);
328 m_selectText = new QAction(KIcon("kdenlive-select-texts"), QString(), this);
329 m_selectText->setShortcut(Qt::CTRL + Qt::Key_T);
330 connect(m_selectText, SIGNAL(triggered()), this, SLOT(slotSelectText()));
331 buttonSelectText->setDefaultAction(m_selectText);
332 buttonSelectText->setEnabled(false);
334 m_selectRects = new QAction(KIcon("kdenlive-select-rects"), QString(), this);
335 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
336 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
337 buttonSelectRects->setDefaultAction(m_selectRects);
338 buttonSelectRects->setEnabled(false);
340 m_selectImages = new QAction(KIcon("kdenlive-select-images"), QString(), this);
341 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
342 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
343 buttonSelectImages->setDefaultAction(m_selectImages);
344 buttonSelectImages->setEnabled(false);
346 m_unselectAll = new QAction(KIcon("kdenlive-unselect-all"), QString(), this);
347 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
348 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
349 buttonUnselectAll->setDefaultAction(m_unselectAll);
350 buttonUnselectAll->setEnabled(false);
352 zDown->setIconSize(iconSize);
353 zTop->setIconSize(iconSize);
354 zBottom->setIconSize(iconSize);
356 zDown->setIcon(KIcon("kdenlive-zindex-down"));
357 zTop->setIcon(KIcon("kdenlive-zindex-top"));
358 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
359 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
360 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
361 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
363 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
364 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
365 rectBColor->setToolTip(i18n("Select fill color"));
366 rectFColor->setToolTip(i18n("Select border color"));
367 zoom_slider->setToolTip(i18n("Zoom"));
368 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
369 buttonFitZoom->setToolTip(i18n("Fit zoom"));
370 backgroundColor->setToolTip(i18n("Select background color"));
371 backgroundAlpha->setToolTip(i18n("Background opacity"));
372 buttonSelectAll->setToolTip(getTooltipWithShortcut(i18n("Select all"), m_selectAll));
373 buttonSelectText->setToolTip(getTooltipWithShortcut(i18n("Select text items in current selection"), m_selectText));
374 buttonSelectRects->setToolTip(getTooltipWithShortcut(i18n("Select rect items in current selection"), m_selectRects));
375 buttonSelectImages->setToolTip(getTooltipWithShortcut(i18n("Select image items in current selection"), m_selectImages));
376 buttonUnselectAll->setToolTip(getTooltipWithShortcut(i18n("Unselect all"), m_unselectAll));
378 itemhcenter->setIconSize(iconSize);
379 itemvcenter->setIconSize(iconSize);
380 itemtop->setIconSize(iconSize);
381 itembottom->setIconSize(iconSize);
382 itemright->setIconSize(iconSize);
383 itemleft->setIconSize(iconSize);
385 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
386 itemhcenter->setToolTip(i18n("Align item horizontally"));
387 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
388 itemvcenter->setToolTip(i18n("Align item vertically"));
389 itemtop->setIcon(KIcon("kdenlive-align-top"));
390 itemtop->setToolTip(i18n("Align item to top"));
391 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
392 itembottom->setToolTip(i18n("Align item to bottom"));
393 itemright->setIcon(KIcon("kdenlive-align-right"));
394 itemright->setToolTip(i18n("Align item to right"));
395 itemleft->setIcon(KIcon("kdenlive-align-left"));
396 itemleft->setToolTip(i18n("Align item to left"));
399 QHBoxLayout *layout = new QHBoxLayout;
400 frame_toolbar->setLayout(layout);
401 layout->setContentsMargins(0, 0, 0, 0);
402 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
403 m_toolbar->setIconSize(iconSize);
405 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
406 m_buttonCursor->setCheckable(true);
407 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
408 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
409 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
411 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
412 m_buttonText->setCheckable(true);
413 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
414 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
415 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
417 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
418 m_buttonRect->setCheckable(true);
419 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
420 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
421 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
423 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
424 m_buttonImage->setCheckable(false);
425 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
426 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
427 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
429 m_toolbar->addSeparator();
431 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
432 m_buttonLoad->setCheckable(false);
433 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
434 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
436 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
437 m_buttonSave->setCheckable(false);
438 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
439 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
441 layout->addWidget(m_toolbar);
443 // initialize graphic scene
444 m_scene = new GraphicsSceneRectMove(this);
445 graphicsView->setScene(m_scene);
446 graphicsView->setMouseTracking(true);
447 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
448 graphicsView->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);
449 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
450 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
451 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
453 // a gradient background
454 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
455 gradient->setSpread(QGradient::ReflectSpread);
456 scene->setBackgroundBrush(*gradient);*/
458 QPen framepen(Qt::DotLine);
459 framepen.setColor(Qt::red);
461 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
462 m_frameBorder->setPen(framepen);
463 m_frameBorder->setZValue(-1100);
464 m_frameBorder->setBrush(Qt::transparent);
465 m_frameBorder->setFlags(0);
466 graphicsView->scene()->addItem(m_frameBorder);
468 m_frameImage = new QGraphicsPixmapItem();
470 qtrans.scale(2.0, 2.0);
471 m_frameImage->setTransform(qtrans);
472 m_frameImage->setZValue(-1200);
473 m_frameImage->setFlags(0);
474 displayBackgroundFrame();
475 graphicsView->scene()->addItem(m_frameImage);
477 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
478 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
479 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
480 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
481 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
482 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
483 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
484 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
487 // mbd: load saved settings
490 graphicsView->show();
491 //graphicsView->setRenderHint(QPainter::Antialiasing);
492 graphicsView->setInteractive(true);
493 //graphicsView->resize(400, 300);
494 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
495 //toolBox->setItemEnabled(2, false);
496 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
497 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
498 m_startViewport->setData(0, m_frameWidth);
499 m_startViewport->setData(1, m_frameHeight);
500 m_endViewport->setData(0, m_frameWidth);
501 m_endViewport->setData(1, m_frameHeight);
503 // scale the view so that the title widget is not too big at startup
504 graphicsView->scale(.5, .5);
505 if (!url.isEmpty()) loadTitle(url);
508 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
511 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
512 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
513 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
515 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
516 refreshTitleTemplates();
517 //templateBox->setIconSize(QSize(60,60));
518 templateBox->clear();
519 templateBox->addItem("");
520 foreach(TitleTemplate t, titletemplates) {
521 templateBox->addItem(t.icon, t.name, t.file);
523 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
526 TitleWidget::~TitleWidget()
530 delete m_buttonImage;
531 delete m_buttonCursor;
534 delete m_unicodeAction;
541 delete m_selectRects;
542 delete m_selectImages;
543 delete m_unselectAll;
545 delete m_unicodeDialog;
546 delete m_frameBorder;
548 delete m_startViewport;
549 delete m_endViewport;
551 delete m_signalMapper;
555 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
558 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
559 KStandardDirs::makeDir(titlePath);
560 titlePath.append((isClone == false) ? "title" : "clone");
563 while (path.isEmpty() || QFile::exists(path)) {
565 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
567 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
573 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
576 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
577 KStandardDirs::makeDir(titlePath);
578 return titlePath + titleName + ".png";
582 QStringList TitleWidget::extractImageList(QString xml)
585 if (xml.isEmpty()) return result;
588 QDomNodeList images = doc.elementsByTagName("content");
589 for (int i = 0; i < images.count(); i++) {
590 if (images.at(i).toElement().hasAttribute("url"))
591 result.append(images.at(i).toElement().attribute("url"));
597 QStringList TitleWidget::extractFontList(QString xml)
600 if (xml.isEmpty()) return result;
603 QDomNodeList images = doc.elementsByTagName("content");
604 for (int i = 0; i < images.count(); i++) {
605 if (images.at(i).toElement().hasAttribute("font"))
606 result.append(images.at(i).toElement().attribute("font"));
611 void TitleWidget::refreshTitleTemplates()
613 QStringList titlenamelist = QStringList() << i18n("None");
614 QStringList titlefiles = QStringList() << QString();
616 filters << "*.kdenlivetitle" ;
617 titletemplates.clear();
618 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
619 foreach(const QString & folder, titleTemplates) {
620 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
621 foreach(const QString & fname, filesnames) {
622 //titlenamelist.append(fname);
623 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
626 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
627 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
628 titletemplates.append(t);
631 kDebug() << titlenamelist << titlefiles;
633 void TitleWidget::templateIndexChanged(int index)
635 QString item = templateBox->itemData(index).toString();
637 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
638 if (KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
642 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
643 // Text of unchanged template titles should be selected when clicked.
644 QList<QGraphicsItem *> list = graphicsView->scene()->items();
645 foreach(QGraphicsItem * qgItem, list) {
646 if (qgItem->type() == TEXTITEM) {
647 QGraphicsTextItem *i;
648 i = static_cast<QGraphicsTextItem *>(qgItem);
649 i->setProperty("isTemplate", "true");
650 i->setProperty("templateText", i->toHtml());
654 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
658 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
663 void TitleWidget::slotTextTool()
665 m_scene->setTool(TITLE_TEXT);
666 showToolbars(TITLE_TEXT);
667 checkButton(TITLE_TEXT);
670 void TitleWidget::slotRectTool()
672 m_scene->setTool(TITLE_RECTANGLE);
673 showToolbars(TITLE_RECTANGLE);
674 checkButton(TITLE_RECTANGLE);
676 // Disable dragging mode, would make dragging a rect impossible otherwise ;)
677 graphicsView->setDragMode(QGraphicsView::NoDrag);
680 void TitleWidget::slotSelectTool()
682 m_scene->setTool(TITLE_SELECT);
684 // Enable rubberband selecting mode.
685 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
687 // Find out which toolbars need to be shown, depending on selected item
688 TITLETOOL t = TITLE_SELECT;
689 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
691 switch (l.at(0)->type()) {
705 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
706 //graphicsView->centerOn(l.at(0));
712 updateCoordinates(l.at(0));
713 updateDimension(l.at(0));
714 updateRotZoom(l.at(0));
717 checkButton(TITLE_SELECT);
720 void TitleWidget::slotImageTool()
722 // TODO: find a way to get a list of all supported image types...
723 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";
724 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
725 if (!url.isEmpty()) {
726 if (url.path().endsWith(".svg")) {
727 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
728 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
729 svg->setZValue(m_count++);
730 svg->setData(Qt::UserRole, url.path());
731 graphicsView->scene()->addItem(svg);
733 QPixmap pix(url.path());
734 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
735 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
736 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
737 image->setData(Qt::UserRole, url.path());
738 image->setZValue(m_count++);
739 graphicsView->scene()->addItem(image);
742 m_scene->setTool(TITLE_SELECT);
743 showToolbars(TITLE_SELECT);
744 checkButton(TITLE_SELECT);
747 void TitleWidget::showToolbars(TITLETOOL toolType)
751 toolbar_stack->setCurrentIndex(0);
754 toolbar_stack->setCurrentIndex(3);
756 case TITLE_RECTANGLE:
757 toolbar_stack->setCurrentIndex(1);
760 toolbar_stack->setCurrentIndex(2);
765 void TitleWidget::enableToolbars(TITLETOOL toolType)
767 // TITLETOOL is defined in graphicsscenerectmove.h
769 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
770 value_w->setEnabled(enable);
771 value_h->setEnabled(enable);
774 void TitleWidget::checkButton(TITLETOOL toolType)
776 bool bSelect = false;
788 case TITLE_RECTANGLE:
798 m_buttonCursor->setChecked(bSelect);
799 m_buttonText->setChecked(bText);
800 m_buttonRect->setChecked(bRect);
801 m_buttonImage->setChecked(bImage);
804 void TitleWidget::displayBackgroundFrame()
806 QRectF r = m_frameBorder->sceneBoundingRect();
807 if (!displayBg->isChecked()) {
808 QPixmap pattern(20, 20);
810 QColor bgcolor(210, 210, 210);
811 QPainter p(&pattern);
812 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
813 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
816 QPixmap bg((int) (r.width() / 2), (int) (r.height()/ 2));
818 p2.fillRect(bg.rect(), br);
820 m_frameImage->setPixmap(bg);
822 QImage img = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), QString(), m_render->frameRenderWidth() / 2, m_render->renderHeight() / 2);
823 m_frameImage->setPixmap(QPixmap::fromImage(img.scaled(r.width() / 2, r.height() / 2)));
827 void TitleWidget::initAnimation()
829 align_box->setEnabled(false);
830 QPen startpen(Qt::DotLine);
831 QPen endpen(Qt::DashDotLine);
832 startpen.setColor(QColor(100, 200, 100, 140));
833 endpen.setColor(QColor(200, 100, 100, 140));
835 m_startViewport->setPen(startpen);
836 m_endViewport->setPen(endpen);
838 m_startViewport->setZValue(-1000);
839 m_endViewport->setZValue(-1000);
841 m_startViewport->setFlags(0);
842 m_endViewport->setFlags(0);
844 graphicsView->scene()->addItem(m_startViewport);
845 graphicsView->scene()->addItem(m_endViewport);
847 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
848 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
849 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
850 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
853 void TitleWidget::slotUpdateZoom(int pos)
855 m_scene->setZoom((double) pos / 100);
856 zoom_label->setText(QString::number(pos) + '%');
859 void TitleWidget::slotZoom(bool up)
861 int pos = zoom_slider->value();
864 zoom_slider->setValue(pos);
867 void TitleWidget::slotAdjustZoom()
869 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
870 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
871 if (scalex > scaley) scalex = scaley;
872 int zoompos = (int)(scalex * 7 + 0.5);*/
873 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
874 int zoompos = graphicsView->matrix().m11() * 100;
875 zoom_slider->setValue(zoompos);
876 graphicsView->centerOn(m_frameBorder);
879 void TitleWidget::slotZoomOneToOne()
881 zoom_slider->setValue(100);
882 graphicsView->centerOn(m_frameBorder);
885 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
887 updateAxisButtons(rect); // back to default
889 QColor f = rectFColor->color();
890 #if not KDE_IS_VERSION(4,5,0)
891 f.setAlpha(rectFAlpha->value());
894 penf.setWidth(rectLineWidth->value());
895 penf.setJoinStyle(Qt::RoundJoin);
897 QColor b = rectBColor->color();
898 #if not KDE_IS_VERSION(4,5,0)
899 b.setAlpha(rectBAlpha->value());
901 rect->setBrush(QBrush(b));
902 rect->setZValue(m_count++);
903 rect->setData(ZOOMFACTOR, 100);
904 //setCurrentItem(rect);
905 //graphicsView->setFocus();
908 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
910 updateAxisButtons(tt); // back to default
912 QFont font = font_family->currentFont();
913 font.setPixelSize(font_size->value());
915 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
916 font.setItalic(buttonItalic->isChecked());
917 font.setUnderline(buttonUnder->isChecked());
920 QColor color = fontColorButton->color();
921 QColor outlineColor = textOutlineColor->color();
922 #if not KDE_IS_VERSION(4,5,0)
923 color.setAlpha(textAlpha->value());
924 outlineColor.setAlpha(textOutlineAlpha->value());
926 tt->setDefaultTextColor(color);
928 QTextCursor cur(tt->document());
929 cur.select(QTextCursor::Document);
930 QTextBlockFormat format = cur.blockFormat();
931 QTextCharFormat cformat = cur.charFormat();
932 double outlineWidth = textOutline->value() / 10.0;
934 tt->setData(101, outlineWidth);
935 tt->setData(102, outlineColor);
936 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
938 cformat.setForeground(QBrush(color));
939 cur.setCharFormat(cformat);
940 cur.setBlockFormat(format);
941 tt->setTextCursor(cur);
942 tt->setZValue(m_count++);
946 void TitleWidget::setFontBoxWeight(int weight)
948 int index = font_weight_box->findData(weight);
950 index = font_weight_box->findData(QFont::Normal);
952 font_weight_box->setCurrentIndex(index);
955 void TitleWidget::setCurrentItem(QGraphicsItem *item)
957 m_scene->setSelectedItem(item);
960 void TitleWidget::zIndexChanged(int v)
962 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
963 for (int i = 0; i < l.size(); i++) {
968 void TitleWidget::selectionChanged()
970 if (m_scene->tool() != TITLE_SELECT) return;
972 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
974 QList<QGraphicsItem *> l;
976 // mbt 1607: One text item might have grabbed the keyboard.
977 // Ungrab it for all items that are not selected, otherwise
978 // text input would only work for the text item that grabbed
979 // the keyboard last.
980 l = graphicsView->scene()->items();
981 foreach(QGraphicsItem * item, l) {
982 if (item->type() == TEXTITEM && !item->isSelected()) {
983 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
988 l = graphicsView->scene()->selectedItems();
991 buttonUnselectAll->setEnabled(true);
992 // Enable all z index buttons if items selected.
993 // We can selectively disable them later.
994 zUp->setEnabled(true);
995 zDown->setEnabled(true);
996 zTop->setEnabled(true);
997 zBottom->setEnabled(true);
999 buttonUnselectAll->setEnabled(false);
1001 if (l.size() >= 2) {
1002 buttonSelectText->setEnabled(true);
1003 buttonSelectRects->setEnabled(true);
1004 buttonSelectImages->setEnabled(true);
1006 buttonSelectText->setEnabled(false);
1007 buttonSelectRects->setEnabled(false);
1008 buttonSelectImages->setEnabled(false);
1011 if (l.size() == 0) {
1013 } else if (l.size() == 1) {
1014 prepareTools(l.at(0));
1017 For multiple selected objects we need to decide which tools to show.
1019 int firstType = l.at(0)->type();
1020 bool allEqual = true;
1021 for (int i = 0; i < l.size(); i++) {
1022 if (l.at(i)->type() != firstType) {
1027 std::cout << "All equal? " << allEqual << ".\n";
1029 prepareTools(l.at(0));
1031 // Get the default toolset, but enable the property frame (x,y,w,h)
1033 frame_properties->setEnabled(true);
1035 // Enable x/y/w/h if it makes sense.
1036 value_x->setEnabled(true);
1037 value_y->setEnabled(true);
1038 bool containsTextitem = false;
1039 for (int i = 0; i < l.size(); i++) {
1040 if (l.at(i)->type() == TEXTITEM) {
1041 containsTextitem = true;
1045 if (!containsTextitem) {
1046 value_w->setEnabled(true);
1047 value_h->setEnabled(true);
1051 // Disable z index buttons if they don't make sense for the current selection
1052 int firstZindex = l.at(0)->zValue();
1054 for (int i = 0; i < l.size(); i++) {
1055 if (l[i]->zValue() != firstZindex) {
1061 zUp->setEnabled(false);
1062 zDown->setEnabled(false);
1070 void TitleWidget::slotValueChanged(int type)
1073 type tells us which QSpinBox value has changed.
1076 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1077 std::cout << l.size() << " items to be resized\n";
1079 // Get the updated value here already to do less coding afterwards
1083 val = value_w->value();
1086 val = value_h->value();
1089 val = value_x->value();
1092 val = value_y->value();
1096 for (int k = 0; k < l.size(); k++) {
1097 std::cout << "Type of item " << k << ": " << l.at(k)->type() << "\n";
1099 if (l.at(k)->type() == TEXTITEM) {
1100 // Just update the position. We don't allow setting width/height for text items yet.
1103 updatePosition(l.at(k), val, l.at(k)->pos().y());
1106 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1110 } else if (l.at(k)->type() == RECTITEM) {
1111 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(k));
1114 updatePosition(l.at(k), val, l.at(k)->pos().y());
1117 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1120 rec->setRect(QRect(0, 0, val, rec->rect().height()));
1123 rec->setRect(QRect(0, 0, rec->rect().width(), val));
1127 } else if (l.at(k)->type() == IMAGEITEM) {
1130 if (type == ValueX) {
1131 updatePosition(l.at(k), val, l.at(k)->pos().y());
1133 } else if (type == ValueY) {
1134 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1137 // Width/height has changed. This is more complex.
1139 QGraphicsItem *i = l.at(k);
1140 Transform t = m_transformations.value(i);
1142 // Ratio width:height
1143 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1144 // TODO: proper calculation for rotation around 3 axes
1145 double alpha = (double) t.rotatez / 180.0 * M_PI;
1148 double length = val;
1153 // We want to keep the aspect ratio of the image as the user does not yet have the possibility
1154 // to restore the original ratio. You rarely want to change it anyway.
1157 // Add 0.5 because otherwise incrementing by 1 might have no effect
1158 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1159 scale = length / i->boundingRect().width();
1162 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1163 scale = length / i->boundingRect().height();
1170 qtrans.scale(scale, scale);
1171 qtrans.rotate(t.rotatex, Qt::XAxis);
1172 qtrans.rotate(t.rotatey, Qt::YAxis);
1173 qtrans.rotate(t.rotatez, Qt::ZAxis);
1174 i->setTransform(qtrans);
1175 std::cout << "scale is: " << scale << "\n";
1176 std::cout << i->boundingRect().width() << ": new width\n";
1177 m_transformations[i] = t;
1179 if (l.size() == 1) {
1180 // Only update the w/h values if the selection contains just one item.
1181 // Otherwise, what should we do? ;)
1182 // (Use the values of the first item? Of the second? Of the x-th?)
1184 // Update rotation/zoom values.
1185 // These values are not yet able to handle multiple items!
1196 void TitleWidget::updateDimension(QGraphicsItem *i)
1198 bool wBlocked = value_w->signalsBlocked();
1199 bool hBlocked = value_h->signalsBlocked();
1200 bool zBlocked = zValue->signalsBlocked();
1201 value_w->blockSignals(true);
1202 value_h->blockSignals(true);
1203 zValue->blockSignals(true);
1205 zValue->setValue((int) i->zValue());
1206 if (i->type() == IMAGEITEM) {
1207 // Get multipliers for rotation/scaling
1209 /*Transform t = m_transformations.value(i);
1210 QRectF r = i->boundingRect();
1211 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1212 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1213 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1214 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1216 value_w->setValue(i->sceneBoundingRect().width());
1217 value_h->setValue(i->sceneBoundingRect().height());
1218 } else if (i->type() == RECTITEM) {
1219 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1220 std::cout << "Rect width is: " << r->rect().width() << ", was: " << value_w->value() << "\n";
1221 value_w->setValue((int) r->rect().width());
1222 value_h->setValue((int) r->rect().height());
1223 } else if (i->type() == TEXTITEM) {
1224 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1225 value_w->setValue((int) t->boundingRect().width());
1226 value_h->setValue((int) t->boundingRect().height());
1229 zValue->blockSignals(zBlocked);
1230 value_w->blockSignals(wBlocked);
1231 value_h->blockSignals(hBlocked);
1234 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1236 // Block signals emitted by this method
1237 value_x->blockSignals(true);
1238 value_y->blockSignals(true);
1240 if (i->type() == TEXTITEM) {
1242 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1244 // Set the correct x coordinate value
1245 if (origin_x_left->isChecked()) {
1246 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1247 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1249 // Origin is at 0 (default)
1250 value_x->setValue((int) rec->pos().x());
1254 if (origin_y_top->isChecked()) {
1255 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1257 value_y->setValue((int) rec->pos().y());
1260 } else if (i->type() == RECTITEM) {
1262 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1264 if (origin_x_left->isChecked()) {
1265 // Origin (0 point) is at m_frameWidth
1266 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1268 // Origin is at 0 (default)
1269 value_x->setValue((int) rec->pos().x());
1272 if (origin_y_top->isChecked()) {
1273 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1275 value_y->setValue((int) rec->pos().y());
1278 } else if (i->type() == IMAGEITEM) {
1280 if (origin_x_left->isChecked()) {
1281 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1283 value_x->setValue((int) i->pos().x());
1286 if (origin_y_top->isChecked()) {
1287 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1289 value_y->setValue((int) i->pos().y());
1294 // Stop blocking signals now
1295 value_x->blockSignals(false);
1296 value_y->blockSignals(false);
1299 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1301 itemzoom->blockSignals(true);
1302 itemrotatex->blockSignals(true);
1303 itemrotatey->blockSignals(true);
1304 itemrotatez->blockSignals(true);
1306 Transform t = m_transformations.value(i);
1308 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1309 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1311 itemrotatex->setValue((int)(t.rotatex));
1312 itemrotatey->setValue((int)(t.rotatey));
1313 itemrotatez->setValue((int)(t.rotatez));
1315 itemzoom->blockSignals(false);
1316 itemrotatex->blockSignals(false);
1317 itemrotatey->blockSignals(false);
1318 itemrotatez->blockSignals(false);
1321 void TitleWidget::updatePosition(QGraphicsItem *i)
1323 updatePosition(i, value_x->value(), value_y->value());
1326 void TitleWidget::updatePosition(QGraphicsItem *i, int x, int y)
1328 if (i->type() == TEXTITEM) {
1329 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1332 if (origin_x_left->isChecked()) {
1334 * Origin of the X axis is at m_frameWidth, and distance from right
1335 * border of the item to the right border of the frame is taken. See
1336 * comment to slotOriginXClicked().
1338 posX = m_frameWidth - x - rec->boundingRect().width();
1344 if (origin_y_top->isChecked()) {
1345 /* Same for y axis */
1346 posY = m_frameHeight - y - rec->boundingRect().height();
1351 rec->setPos(posX, posY);
1353 } else if (i->type() == RECTITEM) {
1355 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1358 if (origin_x_left->isChecked()) {
1359 posX = m_frameWidth - x - rec->rect().width();
1365 if (origin_y_top->isChecked()) {
1366 posY = m_frameHeight - y - rec->rect().height();
1371 rec->setPos(posX, posY);
1373 } else if (i->type() == IMAGEITEM) {
1375 if (origin_x_left->isChecked()) {
1376 // Use the sceneBoundingRect because this also regards transformations like zoom
1377 posX = m_frameWidth - x - i->sceneBoundingRect().width();
1383 if (origin_y_top->isChecked()) {
1384 posY = m_frameHeight - y - i->sceneBoundingRect().height();
1389 i->setPos(posX, posY);
1395 void TitleWidget::updateTextOriginX()
1397 if (origin_x_left->isChecked()) {
1398 origin_x_left->setText(i18n("\u2212X"));
1400 origin_x_left->setText(i18n("+X"));
1404 void TitleWidget::slotOriginXClicked()
1406 // Update the text displayed on the button.
1407 updateTextOriginX();
1409 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1410 if (l.size() >= 1) {
1411 updateCoordinates(l.at(0));
1413 // Remember x axis setting
1414 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1415 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1417 graphicsView->setFocus();
1420 void TitleWidget::updateTextOriginY()
1422 if (origin_y_top->isChecked()) {
1423 origin_y_top->setText(i18n("\u2212Y"));
1425 origin_y_top->setText(i18n("+Y"));
1429 void TitleWidget::slotOriginYClicked()
1431 // Update the text displayed on the button.
1432 updateTextOriginY();
1434 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1435 if (l.size() >= 1) {
1436 updateCoordinates(l.at(0));
1438 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1439 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1442 graphicsView->setFocus();
1445 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1447 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1448 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1449 origin_x_left->blockSignals(true);
1450 origin_y_top->blockSignals(true);
1452 if (xAxis == TitleDocument::AxisInverted) {
1453 origin_x_left->setChecked(true);
1455 origin_x_left->setChecked(false);
1457 updateTextOriginX();
1459 if (yAxis == TitleDocument::AxisInverted) {
1460 origin_y_top->setChecked(true);
1462 origin_y_top->setChecked(false);
1464 updateTextOriginY();
1466 origin_x_left->blockSignals(false);
1467 origin_y_top->blockSignals(false);
1470 void TitleWidget::slotChangeBackground()
1472 QColor color = backgroundColor->color();
1473 color.setAlpha(backgroundAlpha->value());
1474 m_frameBorder->setBrush(QBrush(color));
1477 void TitleWidget::slotChanged()
1479 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1480 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1481 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1485 void TitleWidget::textChanged(QGraphicsTextItem *i)
1488 * If the user has set origin_x_left (the same for y), we need to look
1489 * whether a text element has been selected. If yes, we need to ensure that
1490 * the right border of the text field remains fixed also when some text has
1493 * This is also known as right-justified, with the difference that it is not
1494 * valid for text but for its boundingRect. Text may still be
1499 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1500 if (!i->toPlainText().isEmpty())
1504 * Don't do anything if the string is empty. If the position were
1505 * updated here, a newly created text field would be set to the
1506 * position of the last selected text field.
1511 // mbt 1607: Template text has changed; don't auto-select content anymore.
1512 if (i->property("isTemplate").isValid()) {
1513 if (i->property("templateText").isValid()) {
1514 if (i->property("templateText") == i->toHtml()) {
1515 // Unchanged, do nothing.
1517 i->setProperty("isTemplate", QVariant::Invalid);
1518 i->setProperty("templateText", QVariant::Invalid);
1524 void TitleWidget::slotInsertUnicode()
1526 m_unicodeDialog->exec();
1529 void TitleWidget::slotInsertUnicodeString(QString text)
1531 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1533 if (l.at(0)->type() == TEXTITEM) {
1534 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1535 t->textCursor().insertText(text);
1540 void TitleWidget::slotUpdateText()
1542 QFont font = font_family->currentFont();
1543 font.setPixelSize(font_size->value());
1544 font.setItalic(buttonItalic->isChecked());
1545 font.setUnderline(buttonUnder->isChecked());
1546 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1547 QColor color = fontColorButton->color();
1548 QColor outlineColor = textOutlineColor->color();
1549 #if not KDE_IS_VERSION(4,5,0)
1550 color.setAlpha(textAlpha->value());
1551 outlineColor.setAlpha(textOutlineAlpha->value());
1554 double outlineWidth = textOutline->value() / 10.0;
1557 for (i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1558 QGraphicsTextItem* item = NULL;
1559 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1560 if (l.at(i)->type() == TEXTITEM) {
1561 item = static_cast <QGraphicsTextItem *>(l.at(i));
1564 // No text item, try next one.
1568 // Set alignment of all text in the text item
1569 QTextCursor cur(item->document());
1570 cur.select(QTextCursor::Document);
1571 QTextBlockFormat format = cur.blockFormat();
1572 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1573 item->setTextWidth(item->boundingRect().width());
1574 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1575 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1576 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1578 format.setAlignment(Qt::AlignLeft);
1579 item->setTextWidth(-1);
1582 // Set font properties
1583 item->setFont(font);
1584 QTextCharFormat cformat = cur.charFormat();
1586 item->setData(101, outlineWidth);
1587 item->setData(102, outlineColor);
1588 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1590 cformat.setForeground(QBrush(color));
1591 cur.setCharFormat(cformat);
1592 cur.setBlockFormat(format);
1593 // item->setTextCursor(cur);
1594 cur.clearSelection();
1595 item->setTextCursor(cur);
1596 item->setDefaultTextColor(color);
1600 void TitleWidget::rectChanged()
1602 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1604 for (i = 0; i < l.length(); i++) {
1605 if (l.at(i)->type() == RECTITEM && !settingUp) {
1606 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1607 QColor f = rectFColor->color();
1608 #if not KDE_IS_VERSION(4,5,0)
1609 f.setAlpha(rectFAlpha->value());
1612 penf.setWidth(rectLineWidth->value());
1613 penf.setJoinStyle(Qt::RoundJoin);
1615 QColor b = rectBColor->color();
1616 #if not KDE_IS_VERSION(4,5,0)
1617 b.setAlpha(rectBAlpha->value());
1619 rec->setBrush(QBrush(b));
1624 void TitleWidget::itemScaled(int val)
1626 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1627 if (l.size() == 1) {
1628 Transform x = m_transformations.value(l.at(0));
1629 x.scalex = (double)val / 100.0;
1630 x.scaley = (double)val / 100.0;
1632 qtrans.scale(x.scalex, x.scaley);
1633 qtrans.rotate(x.rotatex, Qt::XAxis);
1634 qtrans.rotate(x.rotatey, Qt::YAxis);
1635 qtrans.rotate(x.rotatez, Qt::ZAxis);
1636 l[0]->setTransform(qtrans);
1637 l[0]->setData(ZOOMFACTOR, val);
1638 m_transformations[l.at(0)] = x;
1639 updateDimension(l.at(0));
1643 void TitleWidget::itemRotateX(qreal val)
1648 void TitleWidget::itemRotateY(qreal val)
1653 void TitleWidget::itemRotateZ(qreal val)
1658 void TitleWidget::itemRotate(qreal val, int axis)
1660 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1661 if (l.size() == 1) {
1662 Transform x = m_transformations[l.at(0)];
1675 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1678 qtrans.scale(x.scalex, x.scaley);
1679 qtrans.rotate(x.rotatex, Qt::XAxis);
1680 qtrans.rotate(x.rotatey, Qt::YAxis);
1681 qtrans.rotate(x.rotatez, Qt::ZAxis);
1682 l[0]->setTransform(qtrans);
1683 m_transformations[l.at(0)] = x;
1684 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1685 updateDimension(l.at(0));
1689 void TitleWidget::itemHCenter()
1691 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1692 if (l.size() == 1) {
1693 QGraphicsItem *item = l.at(0);
1694 QRectF br = item->sceneBoundingRect();
1695 int width = (int)br.width();
1696 int newPos = (int)((m_frameWidth - width) / 2);
1697 newPos += item->pos().x() - br.left(); // Check item transformation
1698 item->setPos(newPos, item->pos().y());
1699 updateCoordinates(item);
1703 void TitleWidget::itemVCenter()
1705 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1706 if (l.size() == 1) {
1707 QGraphicsItem *item = l.at(0);
1708 QRectF br = item->sceneBoundingRect();
1709 int height = (int)br.height();
1710 int newPos = (int)((m_frameHeight - height) / 2);
1711 newPos += item->pos().y() - br.top(); // Check item transformation
1712 item->setPos(item->pos().x(), newPos);
1713 updateCoordinates(item);
1717 void TitleWidget::itemTop()
1719 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1720 if (l.size() == 1) {
1721 QGraphicsItem *item = l.at(0);
1722 QRectF br = item->sceneBoundingRect();
1724 if (br.top() > 0) diff = -br.top();
1725 else diff = -br.bottom();
1726 item->moveBy(0, diff);
1727 updateCoordinates(item);
1731 void TitleWidget::itemBottom()
1733 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1734 if (l.size() == 1) {
1735 QGraphicsItem *item = l.at(0);
1736 QRectF br = item->sceneBoundingRect();
1738 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1739 else diff = m_frameHeight - br.bottom();
1740 item->moveBy(0, diff);
1741 updateCoordinates(item);
1745 void TitleWidget::itemLeft()
1747 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1748 if (l.size() == 1) {
1749 QGraphicsItem *item = l.at(0);
1750 QRectF br = item->sceneBoundingRect();
1752 if (br.left() > 0) diff = -br.left();
1753 else diff = -br.right();
1754 item->moveBy(diff, 0);
1755 updateCoordinates(item);
1759 void TitleWidget::itemRight()
1761 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1762 if (l.size() == 1) {
1763 QGraphicsItem *item = l.at(0);
1764 QRectF br = item->sceneBoundingRect();
1766 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1767 else diff = m_frameWidth - br.left();
1768 item->moveBy(diff, 0);
1769 updateCoordinates(item);
1773 void TitleWidget::setupViewports()
1775 //double aspect_ratio = 4.0 / 3.0;//read from project
1776 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1777 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1778 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1779 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1780 QPolygonF spoly(sp);
1781 QPolygonF epoly(ep);
1782 spoly.translate(startViewportX->value(), startViewportY->value());
1783 epoly.translate(endViewportX->value(), endViewportY->value());
1784 m_startViewport->setPolygon(spoly);
1785 m_endViewport->setPolygon(epoly);
1786 if (! insertingValues) {
1787 m_startViewport->setData(0, startViewportX->value());
1788 m_startViewport->setData(1, startViewportY->value());
1789 m_startViewport->setData(2, startViewportSize->value());
1791 m_endViewport->setData(0, endViewportX->value());
1792 m_endViewport->setData(1, endViewportY->value());
1793 m_endViewport->setData(2, endViewportSize->value());
1797 void TitleWidget::loadTitle(KUrl url)
1799 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1800 if (!url.isEmpty()) {
1801 QList<QGraphicsItem *> items = m_scene->items();
1802 for (int i = 0; i < items.size(); i++) {
1803 if (items.at(i)->zValue() > -1000) delete items.at(i);
1805 m_scene->clearTextSelection();
1809 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1810 QFile file(tmpfile);
1811 if (file.open(QIODevice::ReadOnly)) {
1812 doc.setContent(&file, false);
1815 KIO::NetAccess::removeTempFile(tmpfile);
1820 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1822 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1823 insertingValues = true;
1824 startViewportX->setValue(m_startViewport->data(0).toInt());
1825 startViewportY->setValue(m_startViewport->data(1).toInt());
1826 startViewportSize->setValue(m_startViewport->data(2).toInt());
1827 endViewportX->setValue(m_endViewport->data(0).toInt());
1828 endViewportY->setValue(m_endViewport->data(1).toInt());
1829 endViewportSize->setValue(m_endViewport->data(2).toInt());
1831 insertingValues = false;
1837 void TitleWidget::saveTitle(KUrl url)
1839 if (anim_start->isChecked()) slotAnimStart(false);
1840 if (anim_end->isChecked()) slotAnimEnd(false);
1841 bool embed_image=false;
1842 if (KMessageBox::questionYesNo(this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::No)
1846 if (url.isEmpty()) {
1847 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1848 fs->setOperationMode(KFileDialog::Saving);
1849 fs->setMode(KFile::File);
1850 fs->setConfirmOverwrite(true);
1851 fs->setKeepLocation(true);
1853 url = fs->selectedUrl();
1856 if (!url.isEmpty()) {
1857 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
1858 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1862 QDomDocument TitleWidget::xml()
1864 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1865 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1869 int TitleWidget::outPoint() const
1871 return m_tc.getFrameCount(title_duration->text());
1874 void TitleWidget::setXml(QDomDocument doc)
1877 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out, m_projectTitlePath);
1879 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1880 /*if (doc.documentElement().hasAttribute("out")) {
1881 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1882 title_duration->setText(m_tc.getTimecode(duration));
1884 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1886 QDomElement e = doc.documentElement();
1887 m_transformations.clear();
1888 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1889 const double PI = 4.0 * atan(1.0);
1890 for (int i = 0; i < items.count(); i++) {
1891 QTransform t = items.at(i)->transform();
1895 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1896 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1897 if (rotlist.count() >= 3) {
1898 x.rotatex = rotlist[0].toDouble();
1899 x.rotatey = rotlist[1].toDouble();
1900 x.rotatez = rotlist[2].toDouble();
1902 // Try to adjust zoom
1903 t.rotate(x.rotatex *(-1), Qt::XAxis);
1904 t.rotate(x.rotatey *(-1), Qt::YAxis);
1905 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1916 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1918 m_transformations[items.at(i)] = x;
1920 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1921 QColor background_color = m_titledocument.getBackgroundColor();
1922 backgroundAlpha->blockSignals(true);
1923 backgroundColor->blockSignals(true);
1924 backgroundAlpha->setValue(background_color.alpha());
1925 background_color.setAlpha(255);
1926 backgroundColor->setColor(background_color);
1927 backgroundAlpha->blockSignals(false);
1928 backgroundColor->blockSignals(false);
1930 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1931 startViewportY->setValue(m_startViewport->data(1).toInt());
1932 startViewportSize->setValue(m_startViewport->data(2).toInt());
1933 endViewportX->setValue(m_endViewport->data(0).toInt());
1934 endViewportY->setValue(m_endViewport->data(1).toInt());
1935 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1937 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1942 void TitleWidget::slotAccepted()
1944 if (anim_start->isChecked()) slotAnimStart(false);
1945 if (anim_end->isChecked()) slotAnimEnd(false);
1949 void TitleWidget::writeChoices()
1951 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1952 KSharedConfigPtr config = KGlobal::config();
1953 KConfigGroup titleConfig(config, "TitleWidget");
1954 // Write the entries
1955 titleConfig.writeEntry("font_family", font_family->currentFont());
1956 //titleConfig.writeEntry("font_size", font_size->value());
1957 titleConfig.writeEntry("font_pixel_size", font_size->value());
1958 titleConfig.writeEntry("font_color", fontColorButton->color());
1959 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1960 #if KDE_IS_VERSION(4,5,0)
1961 titleConfig.writeEntry("font_alpha", fontColorButton->color().alpha());
1962 titleConfig.writeEntry("font_outline_alpha", textOutlineColor->color().alpha());
1964 titleConfig.writeEntry("font_alpha", textAlpha->value());
1965 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1967 titleConfig.writeEntry("font_outline", textOutline->value());
1968 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1969 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1970 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1972 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1973 #if KDE_IS_VERSION(4,5,0)
1974 titleConfig.writeEntry("rect_foreground_alpha", rectFColor->color().alpha());
1976 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1978 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1979 #if KDE_IS_VERSION(4,5,0)
1980 titleConfig.writeEntry("rect_background_alpha", rectBColor->color().alpha());
1982 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1984 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1986 titleConfig.writeEntry("background_color", backgroundColor->color());
1987 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1989 //! \todo Not sure if I should sync - it is probably safe to do it
1994 void TitleWidget::readChoices()
1996 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1997 KSharedConfigPtr config = KGlobal::config();
1998 KConfigGroup titleConfig(config, "TitleWidget");
2000 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
2001 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
2002 m_scene->slotUpdateFontSize(font_size->value());
2003 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
2004 #if not KDE_IS_VERSION(4,5,0)
2005 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
2006 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
2008 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
2009 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
2012 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
2013 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
2014 setFontBoxWeight(weight);
2015 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
2016 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
2018 QColor fgColor = QColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
2019 #if KDE_IS_VERSION(4,5,0)
2020 fgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", rectFColor->color().alpha()));
2022 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
2024 rectFColor->setColor(fgColor);
2026 QColor bgColor = QColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
2027 #if KDE_IS_VERSION(4,5,0)
2028 bgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", rectBColor->color().alpha()));
2030 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
2032 rectBColor->setColor(bgColor);
2033 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
2035 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
2036 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
2039 void TitleWidget::adjustFrameSize()
2041 m_frameWidth = m_titledocument.frameWidth();
2042 m_frameHeight = m_titledocument.frameHeight();
2043 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
2044 displayBackgroundFrame();
2047 void TitleWidget::slotAnimStart(bool anim)
2049 if (anim && anim_end->isChecked()) {
2050 anim_end->setChecked(false);
2051 m_endViewport->setZValue(-1000);
2052 m_endViewport->setBrush(QBrush());
2055 QList<QGraphicsItem *> list = m_scene->items();
2056 for (int i = 0; i < list.count(); i++) {
2057 if (list.at(i)->zValue() > -1000) {
2058 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2059 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2062 align_box->setEnabled(anim);
2063 itemzoom->setEnabled(!anim);
2064 itemrotatex->setEnabled(!anim);
2065 itemrotatey->setEnabled(!anim);
2066 itemrotatez->setEnabled(!anim);
2067 frame_toolbar->setEnabled(!anim);
2068 toolbar_stack->setEnabled(!anim);
2070 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
2071 m_startViewport->setZValue(1100);
2072 QColor col = m_startViewport->pen().color();
2074 m_startViewport->setBrush(col);
2075 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2076 m_startViewport->setSelected(true);
2079 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
2081 m_startViewport->setZValue(-1000);
2082 m_startViewport->setBrush(QBrush());
2083 m_startViewport->setFlags(0);
2084 if (!anim_end->isChecked()) deleteAnimInfoText();
2089 void TitleWidget::slotAnimEnd(bool anim)
2091 if (anim && anim_start->isChecked()) {
2092 anim_start->setChecked(false);
2093 m_startViewport->setZValue(-1000);
2094 m_startViewport->setBrush(QBrush());
2097 QList<QGraphicsItem *> list = m_scene->items();
2098 for (int i = 0; i < list.count(); i++) {
2099 if (list.at(i)->zValue() > -1000) {
2100 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2101 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2104 align_box->setEnabled(anim);
2105 itemzoom->setEnabled(!anim);
2106 itemrotatex->setEnabled(!anim);
2107 itemrotatey->setEnabled(!anim);
2108 itemrotatez->setEnabled(!anim);
2109 frame_toolbar->setEnabled(!anim);
2110 toolbar_stack->setEnabled(!anim);
2112 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2113 m_endViewport->setZValue(1100);
2114 QColor col = m_endViewport->pen().color();
2116 m_endViewport->setBrush(col);
2117 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2118 m_endViewport->setSelected(true);
2121 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2123 m_endViewport->setZValue(-1000);
2124 m_endViewport->setBrush(QBrush());
2125 m_endViewport->setFlags(0);
2126 if (!anim_start->isChecked()) deleteAnimInfoText();
2130 void TitleWidget::addAnimInfoText()
2132 // add text to anim viewport
2133 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2134 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2135 QFont font = t->font();
2136 font.setPixelSize(m_startViewport->rect().width() / 10);
2137 QColor col = m_startViewport->pen().color();
2139 t->setDefaultTextColor(col);
2141 font.setPixelSize(m_endViewport->rect().width() / 10);
2142 col = m_endViewport->pen().color();
2144 t2->setDefaultTextColor(col);
2148 void TitleWidget::updateInfoText()
2150 // update info text font
2151 if (!m_startViewport->childItems().isEmpty()) {
2152 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2154 QFont font = item->font();
2155 font.setPixelSize(m_startViewport->rect().width() / 10);
2156 item->setFont(font);
2159 if (!m_endViewport->childItems().isEmpty()) {
2160 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2162 QFont font = item->font();
2163 font.setPixelSize(m_endViewport->rect().width() / 10);
2164 item->setFont(font);
2169 void TitleWidget::deleteAnimInfoText()
2171 // end animation editing, remove info text
2172 while (!m_startViewport->childItems().isEmpty()) {
2173 QGraphicsItem *item = m_startViewport->childItems().at(0);
2174 m_scene->removeItem(item);
2177 while (!m_endViewport->childItems().isEmpty()) {
2178 QGraphicsItem *item = m_endViewport->childItems().at(0);
2179 m_scene->removeItem(item);
2184 void TitleWidget::slotKeepAspect(bool keep)
2186 if (m_endViewport->zValue() == 1100) {
2187 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2188 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2190 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2191 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2195 void TitleWidget::slotResize50()
2197 if (m_endViewport->zValue() == 1100) {
2198 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2199 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2202 void TitleWidget::slotResize100()
2204 if (m_endViewport->zValue() == 1100) {
2205 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2206 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2209 void TitleWidget::slotResize200()
2211 if (m_endViewport->zValue() == 1100) {
2212 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2213 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2216 void TitleWidget::slotAddEffect(int ix)
2218 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2219 int effect = effect_list->itemData(ix).toInt();
2221 if (list.size() == 1) {
2222 if (effect == NOEFFECT)
2223 effect_stack->setHidden(true);
2225 effect_stack->setCurrentIndex(effect - 1);
2226 effect_stack->setHidden(false);
2228 } else // Hide the effects stack when more than one element is selected.
2229 effect_stack->setHidden(true);
2231 foreach(QGraphicsItem * item, list) {
2234 item->setData(100, QVariant());
2235 #if QT_VERSION >= 0x040600
2236 item->setGraphicsEffect(0);
2239 case TYPEWRITEREFFECT:
2241 * Allow the user to set the typewriter effect to more than one
2242 * element, but do not add it to non-text elements.
2244 if (item->type() == TEXTITEM) {
2245 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2246 item->setData(100, effdata);
2249 #if QT_VERSION >= 0x040600
2250 // Do not remove the non-QGraphicsEffects.
2252 item->setGraphicsEffect(new QGraphicsBlurEffect());
2255 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2262 void TitleWidget::slotFontText(const QString& s)
2265 if (f.exactMatch()) {
2266 // Font really exists (could also just be a «d» if the user
2267 // starts typing «dejavu» for example).
2268 font_family->setCurrentFont(f);
2270 // Note: Typing dejavu serif does not recognize the font (takes sans)
2271 // in older Qt versions. Case must match there (except for first letter)
2274 void TitleWidget::slotEditTypewriter(int /*ix*/)
2276 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2277 if (l.size() == 1) {
2278 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2279 l[0]->setData(100, effdata);
2283 void TitleWidget::slotEditBlur(int ix)
2285 #if QT_VERSION < 0x040600
2288 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2289 if (l.size() == 1) {
2290 QGraphicsEffect *eff = l[0]->graphicsEffect();
2291 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2292 if (blur) blur->setBlurRadius(ix);
2297 void TitleWidget::slotEditShadow()
2299 #if QT_VERSION < 0x040600
2302 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2303 if (l.size() == 1) {
2304 QGraphicsEffect *eff = l[0]->graphicsEffect();
2305 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2307 shadow->setBlurRadius(shadow_radius->value());
2308 shadow->setOffset(shadow_x->value(), shadow_y->value());
2314 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2316 qreal bound = maxBound ? -99 : 99;
2317 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2319 QList<QGraphicsItem*> lItems;
2320 // Get items (all or intersecting only)
2321 if (intersectingOnly) {
2322 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2324 lItems = graphicsView->scene()->items();
2326 if (lItems.size() > 0) {
2327 int n = lItems.size();
2330 for (int i = 0; i < n; i++) {
2331 z = lItems[i]->zValue();
2332 if (z > bound && !lItems[i]->isSelected()) {
2334 } else if (z - 1 > bound) {
2335 // To get the maximum index even if it is of an item of the current selection.
2336 // Used when updating multiple items, to get all to the same level.
2337 // Otherwise, the maximum would stay at -99 if the highest item is in the selection.
2342 // Get minimum z index.
2343 for (int i = 0; i < n; i++) {
2344 z = lItems[i]->zValue();
2345 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2346 // There are items at the very bottom (background e.g.) with z-index < -1000.
2348 } else if (z + 1 < bound && z > -999) {
2358 void TitleWidget::slotZIndexUp()
2360 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2361 if (l.size() >= 1) {
2362 qreal currentZ = l[0]->zValue();
2363 qreal max = zIndexBounds(true, true);
2364 if (currentZ <= max) {
2365 l[0]->setZValue(currentZ + 1);
2366 updateDimension(l[0]);
2371 void TitleWidget::slotZIndexTop()
2373 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2374 qreal max = zIndexBounds(true, false);
2375 std::cout << "Max z-index is " << max << ".\n";
2376 for (int i = 0; i < l.size(); i++) {
2377 qreal currentZ = l[i]->zValue();
2378 if (currentZ <= max) {
2379 std::cout << "Updating item " << i << ", is " << currentZ << ".\n";
2380 l[i]->setZValue(max + 1);
2382 std::cout << "Not updating " << i << ", is " << currentZ << ".\n";
2385 // Update the z index value in the GUI
2387 updateDimension(l[0]);
2391 void TitleWidget::slotZIndexDown()
2393 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2394 if (l.size() >= 1) {
2395 qreal currentZ = l[0]->zValue();
2396 qreal min = zIndexBounds(false, true);
2397 if (currentZ >= min) {
2398 l[0]->setZValue(currentZ - 1);
2399 updateDimension(l[0]);
2404 void TitleWidget::slotZIndexBottom()
2406 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2407 qreal min = zIndexBounds(false, false);
2408 for (int i = 0; i < l.size(); i++) {
2409 qreal currentZ = l[i]->zValue();
2410 if (currentZ >= min) {
2411 l[i]->setZValue(min - 1);
2414 // Update the z index value in the GUI
2416 updateDimension(l[0]);
2420 void TitleWidget::slotSelectAll()
2422 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2423 for (int i = 0; i < l.size(); i++) {
2424 l.at(i)->setSelected(true);
2428 void TitleWidget::selectItems(int itemType)
2430 QList<QGraphicsItem*> l;
2431 if (graphicsView->scene()->selectedItems().size() > 0) {
2432 l = graphicsView->scene()->selectedItems();
2433 for (int i = 0; i < l.size(); i++) {
2434 if (l.at(i)->type() != itemType) {
2435 l.at(i)->setSelected(false);
2439 l = graphicsView->scene()->items();
2440 for (int i = 0; i < l.size(); i++) {
2441 if (l.at(i)->type() == itemType) {
2442 l.at(i)->setSelected(true);
2448 void TitleWidget::slotSelectText()
2450 selectItems(TEXTITEM);
2453 void TitleWidget::slotSelectRects()
2455 selectItems(RECTITEM);
2458 void TitleWidget::slotSelectImages()
2460 selectItems(IMAGEITEM);
2463 void TitleWidget::slotSelectNone()
2465 graphicsView->blockSignals(true);
2466 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2467 for (int i = 0; i < l.size(); i++) {
2468 l.at(i)->setSelected(false);
2470 graphicsView->blockSignals(false);
2474 QString TitleWidget::getTooltipWithShortcut(const QString &text, QAction *button)
2476 return text + " <b>" + button->shortcut().toString() + "</b>";
2479 void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
2481 // Let some GUI elements block signals. We may want to change their values without any sideeffects.
2482 // Additionally, store the previous blocking state to avoid side effects when this function is called from within another one.
2483 // Note: Disabling an element also blocks signals. So disabled elements don't need to be set to blocking too.
2484 bool blockOX = origin_x_left->signalsBlocked();
2485 bool blockOY = origin_y_top->signalsBlocked();
2486 bool blockEff = effect_list->signalsBlocked();
2487 bool blockRX = itemrotatex->signalsBlocked();
2488 bool blockRY = itemrotatey->signalsBlocked();
2489 bool blockRZ = itemrotatez->signalsBlocked();
2490 bool blockZoom = itemzoom->signalsBlocked();
2491 bool blockX = value_x->signalsBlocked();
2492 bool blockY = value_y->signalsBlocked();
2493 bool blockW = value_w->signalsBlocked();
2494 bool blockH = value_h->signalsBlocked();
2495 origin_x_left->blockSignals(true);
2496 origin_y_top->blockSignals(true);
2497 effect_list->blockSignals(true);
2498 itemrotatex->blockSignals(true);
2499 itemrotatey->blockSignals(true);
2500 itemrotatez->blockSignals(true);
2501 itemzoom->blockSignals(true);
2502 value_x->blockSignals(true);
2503 value_y->blockSignals(true);
2504 value_w->blockSignals(true);
2505 value_h->blockSignals(true);
2507 if (referenceItem == NULL) {
2508 std::cout << "NULL item.\n";
2509 effect_stack->setHidden(true);
2510 effect_frame->setEnabled(false);
2511 effect_list->setCurrentIndex(0);
2512 origin_x_left->setChecked(false);
2513 origin_y_top->setChecked(false);
2514 updateTextOriginX();
2515 updateTextOriginY();
2516 enableToolbars(TITLE_SELECT);
2517 showToolbars(TITLE_SELECT);
2519 itemzoom->setEnabled(false);
2520 itemrotatex->setEnabled(false);
2521 itemrotatey->setEnabled(false);
2522 itemrotatez->setEnabled(false);
2523 frame_properties->setEnabled(false);
2525 effect_frame->setEnabled(true);
2526 frame_properties->setEnabled(true);
2527 if (referenceItem != m_startViewport && referenceItem != m_endViewport) {
2528 itemzoom->setEnabled(true);
2529 itemrotatex->setEnabled(true);
2530 itemrotatey->setEnabled(true);
2531 itemrotatez->setEnabled(true);
2533 itemzoom->setEnabled(false);
2534 itemrotatex->setEnabled(false);
2535 itemrotatey->setEnabled(false);
2536 itemrotatez->setEnabled(false);
2539 if (referenceItem->type() == TEXTITEM) {
2540 showToolbars(TITLE_TEXT);
2541 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(referenceItem);
2542 if (!i->data(100).isNull()) {
2543 // Item has an effect
2544 QStringList effdata = i->data(100).toStringList();
2545 QString effectName = effdata.takeFirst();
2546 if (effectName == "typewriter") {
2547 QStringList params = effdata.at(0).split(';');
2548 typewriter_delay->setValue(params.at(0).toInt());
2549 typewriter_start->setValue(params.at(1).toInt());
2550 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
2551 effect_stack->setHidden(false);
2554 #if QT_VERSION >= 0x040600
2555 if (i->graphicsEffect()) {
2556 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
2558 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
2559 int rad = (int) blur->blurRadius();
2560 blur_radius->setValue(rad);
2561 effect_stack->setHidden(false);
2563 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
2565 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
2566 shadow_radius->setValue(shad->blurRadius());
2567 shadow_x->setValue(shad->xOffset());
2568 shadow_y->setValue(shad->yOffset());
2569 effect_stack->setHidden(false);
2573 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2574 effect_stack->setHidden(true);
2577 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2578 effect_stack->setHidden(true);
2581 font_size->blockSignals(true);
2582 font_family->blockSignals(true);
2583 font_weight_box->blockSignals(true);
2584 buttonItalic->blockSignals(true);
2585 buttonUnder->blockSignals(true);
2586 fontColorButton->blockSignals(true);
2587 #if not KDE_IS_VERSION(4,5,0)
2588 textAlpha->blockSignals(true);
2590 buttonAlignLeft->blockSignals(true);
2591 buttonAlignRight->blockSignals(true);
2592 buttonAlignNone->blockSignals(true);
2593 buttonAlignCenter->blockSignals(true);
2595 QFont font = i->font();
2596 font_family->setCurrentFont(font);
2597 font_size->setValue(font.pixelSize());
2598 m_scene->slotUpdateFontSize(font.pixelSize());
2599 buttonItalic->setChecked(font.italic());
2600 buttonUnder->setChecked(font.underline());
2601 setFontBoxWeight(font.weight());
2603 QTextCursor cursor(i->document());
2604 cursor.select(QTextCursor::Document);
2605 QColor color = cursor.charFormat().foreground().color();
2606 #if not KDE_IS_VERSION(4,5,0)
2607 textAlpha->setValue(color.alpha());
2608 color.setAlpha(255);
2610 fontColorButton->setColor(color);
2612 if (!i->data(101).isNull()) {
2613 textOutline->blockSignals(true);
2614 textOutline->setValue(i->data(101).toDouble() * 10);
2615 textOutline->blockSignals(false);
2617 if (!i->data(102).isNull()) {
2618 textOutlineColor->blockSignals(true);
2619 color = QColor(i->data(102).toString());
2620 #if not KDE_IS_VERSION(4,5,0)
2621 textOutlineAlpha->blockSignals(true);
2622 textOutlineAlpha->setValue(color.alpha());
2623 color.setAlpha(255);
2624 textOutlineAlpha->blockSignals(false);
2626 textOutlineColor->setColor(color);
2627 textOutlineColor->blockSignals(false);
2629 QTextCursor cur = i->textCursor();
2630 QTextBlockFormat format = cur.blockFormat();
2631 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
2632 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
2633 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
2634 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
2636 font_size->blockSignals(false);
2637 font_family->blockSignals(false);
2638 font_weight_box->blockSignals(false);
2639 buttonItalic->blockSignals(false);
2640 buttonUnder->blockSignals(false);
2641 fontColorButton->blockSignals(false);
2642 #if not KDE_IS_VERSION(4,5,0)
2643 textAlpha->blockSignals(false);
2645 buttonAlignLeft->blockSignals(false);
2646 buttonAlignRight->blockSignals(false);
2647 buttonAlignNone->blockSignals(false);
2648 buttonAlignCenter->blockSignals(false);
2650 // mbt 1607: Select text if the text item is an unchanged template item.
2651 if (i->property("isTemplate").isValid()) {
2652 cur.setPosition(0, QTextCursor::MoveAnchor);
2653 cur.select(QTextCursor::Document);
2654 i->setTextCursor(cur);
2655 // Make text editable now.
2657 i->setTextInteractionFlags(Qt::TextEditorInteraction);
2660 updateAxisButtons(i);
2661 updateCoordinates(i);
2663 enableToolbars(TITLE_TEXT);
2665 } else if ((referenceItem)->type() == RECTITEM) {
2666 showToolbars(TITLE_RECTANGLE);
2668 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(referenceItem);
2669 if (rec == m_startViewport || rec == m_endViewport) {
2670 /*toolBox->setCurrentIndex(3);
2671 toolBox->widget(0)->setEnabled(false);
2672 toolBox->widget(1)->setEnabled(false);*/
2673 enableToolbars(TITLE_SELECT);
2675 /*toolBox->widget(0)->setEnabled(true);
2676 toolBox->widget(1)->setEnabled(true);
2677 toolBox->setCurrentIndex(0);*/
2678 //toolBox->setItemEnabled(3, true);
2679 #if not KDE_IS_VERSION(4,5,0)
2680 rectFAlpha->setValue(rec->pen().color().alpha());
2681 rectBAlpha->setValue(rec->brush().color().alpha());
2683 //kDebug() << rec->brush().color().alpha();
2684 QColor fcol = rec->pen().color();
2685 QColor bcol = rec->brush().color();
2686 //fcol.setAlpha(255);
2687 //bcol.setAlpha(255);
2688 rectFColor->setColor(fcol);
2689 rectBColor->setColor(bcol);
2691 rectLineWidth->setValue(rec->pen().width());
2692 enableToolbars(TITLE_RECTANGLE);
2695 updateAxisButtons(referenceItem);
2696 updateCoordinates(rec);
2697 updateDimension(rec);
2699 } else if (referenceItem->type() == IMAGEITEM) {
2700 showToolbars(TITLE_IMAGE);
2702 updateCoordinates(referenceItem);
2703 updateDimension(referenceItem);
2705 enableToolbars(TITLE_IMAGE);
2708 //toolBox->setCurrentIndex(0);
2709 showToolbars(TITLE_SELECT);
2710 enableToolbars(TITLE_SELECT);
2711 frame_properties->setEnabled(false);
2713 zValue->setValue((int)referenceItem->zValue());
2714 if (!referenceItem->data(ZOOMFACTOR).isNull()) itemzoom->setValue(referenceItem->data(ZOOMFACTOR).toInt());
2715 else itemzoom->setValue((int)(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
2716 itemrotatex->setValue((int)(m_transformations.value(referenceItem).rotatex));
2717 itemrotatey->setValue((int)(m_transformations.value(referenceItem).rotatey));
2718 itemrotatez->setValue((int)(m_transformations.value(referenceItem).rotatez));
2722 effect_list->blockSignals(blockEff);
2723 itemrotatex->blockSignals(blockRX);
2724 itemrotatey->blockSignals(blockRY);
2725 itemrotatez->blockSignals(blockRZ);
2726 itemzoom->blockSignals(blockZoom);
2727 origin_x_left->blockSignals(blockOX);
2728 origin_y_top->blockSignals(blockOY);
2729 value_x->blockSignals(blockX);
2730 value_y->blockSignals(blockY);
2731 value_w->blockSignals(blockW);
2732 value_h->blockSignals(blockH);