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 rectBAlpha->setMinimum(0);
96 rectBAlpha->setMaximum(255);
97 rectBAlpha->setDecimals(0);
98 rectBAlpha->setValue(255);
99 rectBAlpha->setToolTip(i18n("Color opacity"));
101 rectFAlpha->setMinimum(0);
102 rectFAlpha->setMaximum(255);
103 rectFAlpha->setDecimals(0);
104 rectFAlpha->setValue(255);
105 rectFAlpha->setToolTip(i18n("Border opacity"));
106 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
107 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
109 // Set combo sliders values
110 textAlpha->setMinimum(0);
111 textAlpha->setMaximum(255);
112 textAlpha->setDecimals(0);
113 textAlpha->setValue(255);
114 textAlpha->setToolTip(i18n("Font color opacity"));
116 textOutlineAlpha->setMinimum(0);
117 textOutlineAlpha->setMaximum(255);
118 textOutlineAlpha->setDecimals(0);
119 textOutlineAlpha->setValue(255);
120 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
121 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
122 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
125 textOutline->setMinimum(0);
126 textOutline->setMaximum(200);
127 textOutline->setDecimals(0);
128 textOutline->setValue(0);
129 textOutline->setToolTip(i18n("Outline width"));
131 backgroundAlpha->setMinimum(0);
132 backgroundAlpha->setMaximum(255);
133 backgroundAlpha->setDecimals(0);
134 backgroundAlpha->setValue(0);
135 backgroundAlpha->setToolTip(i18n("Background color opacity"));
137 itemrotatex->setMinimum(-360);
138 itemrotatex->setMaximum(360);
139 itemrotatex->setDecimals(0);
140 itemrotatex->setValue(0);
141 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
143 itemrotatey->setMinimum(-360);
144 itemrotatey->setMaximum(360);
145 itemrotatey->setDecimals(0);
146 itemrotatey->setValue(0);
147 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
149 itemrotatez->setMinimum(-360);
150 itemrotatez->setMaximum(360);
151 itemrotatez->setDecimals(0);
152 itemrotatez->setValue(0);
153 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
155 rectLineWidth->setMinimum(0);
156 rectLineWidth->setMaximum(100);
157 rectLineWidth->setDecimals(0);
158 rectLineWidth->setValue(0);
159 rectLineWidth->setToolTip(i18n("Border width"));
161 itemzoom->setSuffix(i18n("%"));
162 m_frameWidth = render->renderWidth();
163 m_frameHeight = render->renderHeight();
164 showToolbars(TITLE_SELECT);
166 splitter->setStretchFactor(0, 20);
168 //If project is drop frame, set the input mask as such.
169 title_duration->setInputMask(m_tc.mask());
170 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
172 connect(backgroundColor, SIGNAL(changed(const QColor &)), this, SLOT(slotChangeBackground())) ;
173 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
175 connect(fontColorButton, SIGNAL(changed(const QColor &)), this, SLOT(slotUpdateText())) ;
176 connect(textOutlineColor, SIGNAL(changed(const QColor &)), this, SLOT(slotUpdateText())) ;
177 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
178 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
179 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
180 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
182 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
184 connect(rectFColor, SIGNAL(changed(const QColor &)), this, SLOT(rectChanged()));
185 connect(rectBColor, SIGNAL(changed(const QColor &)), this, SLOT(rectChanged()));
186 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
188 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
189 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
190 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
191 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
192 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
193 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
196 effect_list->addItem(i18n("None"), NOEFFECT);
197 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
198 effect_list->addItem(i18n("Blur"), BLUREFFECT);
201 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
202 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
203 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
204 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
205 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
206 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
207 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
208 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
209 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
210 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
211 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
212 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
213 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
214 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
215 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
216 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
217 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
218 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
219 effect_stack->setHidden(true);
220 effect_frame->setEnabled(false);
222 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
223 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
226 m_signalMapper = new QSignalMapper(this);
227 m_signalMapper->setMapping(value_w, ValueWidth);
228 m_signalMapper->setMapping(value_h, ValueHeight);
229 m_signalMapper->setMapping(value_x, ValueX);
230 m_signalMapper->setMapping(value_y, ValueY);
231 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
232 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
233 connect(value_x, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
234 connect(value_y, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
235 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
237 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
238 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
239 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
240 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
241 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
242 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
243 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
244 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
245 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
247 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
250 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
252 font_weight_box->blockSignals(true);
253 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
254 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
255 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
256 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
257 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
258 font_weight_box->setToolTip(i18n("Font weight"));
259 font_weight_box->setCurrentIndex(1);
260 font_weight_box->blockSignals(false);
262 buttonFitZoom->setIconSize(iconSize);
263 buttonRealSize->setIconSize(iconSize);
264 buttonItalic->setIconSize(iconSize);
265 buttonUnder->setIconSize(iconSize);
266 buttonAlignCenter->setIconSize(iconSize);
267 buttonAlignLeft->setIconSize(iconSize);
268 buttonAlignRight->setIconSize(iconSize);
269 buttonAlignNone->setIconSize(iconSize);
271 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
272 buttonRealSize->setIcon(KIcon("zoom-original"));
273 buttonItalic->setIcon(KIcon("format-text-italic"));
274 buttonUnder->setIcon(KIcon("format-text-underline"));
275 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
276 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
277 buttonAlignRight->setIcon(KIcon("format-justify-right"));
278 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
280 buttonAlignNone->setToolTip(i18n("No alignment"));
281 buttonAlignRight->setToolTip(i18n("Align right"));
282 buttonAlignLeft->setToolTip(i18n("Align left"));
283 buttonAlignCenter->setToolTip(i18n("Align center"));
285 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
286 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
287 m_unicodeAction->setToolTip(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
288 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
289 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
291 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
292 m_zUp->setShortcut(Qt::Key_PageUp);
293 m_zUp->setToolTip(i18n("Raise object"));
294 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
295 zUp->setDefaultAction(m_zUp);
297 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
298 m_zDown->setShortcut(Qt::Key_PageDown);
299 m_zDown->setToolTip(i18n("Lower object"));
300 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
301 zDown->setDefaultAction(m_zDown);
303 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
304 // TODO mbt 1414: Shortcut should change z index only if
305 // cursor is NOT in a text field ...
306 //m_zTop->setShortcut(Qt::Key_Home);
307 m_zTop->setToolTip(i18n("Raise object to top"));
308 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
309 zTop->setDefaultAction(m_zTop);
311 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
313 //m_zBottom->setShortcut(Qt::Key_End);
314 m_zBottom->setToolTip(i18n("Lower object to bottom"));
315 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
316 zBottom->setDefaultAction(m_zBottom);
318 m_selectAll = new QAction(KIcon("kdenlive-select-all"), QString(), this);
319 m_selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
320 connect(m_selectAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
321 buttonSelectAll->setDefaultAction(m_selectAll);
323 m_selectText = new QAction(KIcon("kdenlive-select-texts"), QString(), this);
324 m_selectText->setShortcut(Qt::CTRL + Qt::Key_T);
325 connect(m_selectText, SIGNAL(triggered()), this, SLOT(slotSelectText()));
326 buttonSelectText->setDefaultAction(m_selectText);
327 buttonSelectText->setEnabled(false);
329 m_selectRects = new QAction(KIcon("kdenlive-select-rects"), QString(), this);
330 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
331 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
332 buttonSelectRects->setDefaultAction(m_selectRects);
333 buttonSelectRects->setEnabled(false);
335 m_selectImages = new QAction(KIcon("kdenlive-select-images"), QString(), this);
336 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
337 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
338 buttonSelectImages->setDefaultAction(m_selectImages);
339 buttonSelectImages->setEnabled(false);
341 m_unselectAll = new QAction(KIcon("kdenlive-unselect-all"), QString(), this);
342 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
343 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
344 buttonUnselectAll->setDefaultAction(m_unselectAll);
345 buttonUnselectAll->setEnabled(false);
347 zDown->setIconSize(iconSize);
348 zTop->setIconSize(iconSize);
349 zBottom->setIconSize(iconSize);
351 zDown->setIcon(KIcon("kdenlive-zindex-down"));
352 zTop->setIcon(KIcon("kdenlive-zindex-top"));
353 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
354 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
355 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
356 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
358 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
359 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
360 rectBColor->setToolTip(i18n("Select fill color"));
361 rectFColor->setToolTip(i18n("Select border color"));
362 zoom_slider->setToolTip(i18n("Zoom"));
363 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
364 buttonFitZoom->setToolTip(i18n("Fit zoom"));
365 backgroundColor->setToolTip(i18n("Select background color"));
366 backgroundAlpha->setToolTip(i18n("Background opacity"));
367 buttonSelectAll->setToolTip(getTooltipWithShortcut(i18n("Select all"), m_selectAll));
368 buttonSelectText->setToolTip(getTooltipWithShortcut(i18n("Select text items in current selection"), m_selectText));
369 buttonSelectRects->setToolTip(getTooltipWithShortcut(i18n("Select rect items in current selection"), m_selectRects));
370 buttonSelectImages->setToolTip(getTooltipWithShortcut(i18n("Select image items in current selection"), m_selectImages));
371 buttonUnselectAll->setToolTip(getTooltipWithShortcut(i18n("Unselect all"), m_unselectAll));
373 itemhcenter->setIconSize(iconSize);
374 itemvcenter->setIconSize(iconSize);
375 itemtop->setIconSize(iconSize);
376 itembottom->setIconSize(iconSize);
377 itemright->setIconSize(iconSize);
378 itemleft->setIconSize(iconSize);
380 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
381 itemhcenter->setToolTip(i18n("Align item horizontally"));
382 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
383 itemvcenter->setToolTip(i18n("Align item vertically"));
384 itemtop->setIcon(KIcon("kdenlive-align-top"));
385 itemtop->setToolTip(i18n("Align item to top"));
386 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
387 itembottom->setToolTip(i18n("Align item to bottom"));
388 itemright->setIcon(KIcon("kdenlive-align-right"));
389 itemright->setToolTip(i18n("Align item to right"));
390 itemleft->setIcon(KIcon("kdenlive-align-left"));
391 itemleft->setToolTip(i18n("Align item to left"));
394 QHBoxLayout *layout = new QHBoxLayout;
395 frame_toolbar->setLayout(layout);
396 layout->setContentsMargins(0, 0, 0, 0);
397 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
398 m_toolbar->setIconSize(iconSize);
400 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
401 m_buttonCursor->setCheckable(true);
402 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
403 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
404 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
406 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
407 m_buttonText->setCheckable(true);
408 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
409 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
410 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
412 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
413 m_buttonRect->setCheckable(true);
414 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
415 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
416 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
418 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
419 m_buttonImage->setCheckable(false);
420 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
421 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
422 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
424 m_toolbar->addSeparator();
426 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
427 m_buttonLoad->setCheckable(false);
428 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
429 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
431 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
432 m_buttonSave->setCheckable(false);
433 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
434 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
436 layout->addWidget(m_toolbar);
438 // initialize graphic scene
439 m_scene = new GraphicsSceneRectMove(this);
440 graphicsView->setScene(m_scene);
441 graphicsView->setMouseTracking(true);
442 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
443 graphicsView->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);
444 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
445 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
446 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
448 // a gradient background
449 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
450 gradient->setSpread(QGradient::ReflectSpread);
451 scene->setBackgroundBrush(*gradient);*/
453 QPen framepen(Qt::DotLine);
454 framepen.setColor(Qt::red);
456 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
457 m_frameBorder->setPen(framepen);
458 m_frameBorder->setZValue(-1100);
459 m_frameBorder->setBrush(Qt::transparent);
460 m_frameBorder->setFlags(0);
461 graphicsView->scene()->addItem(m_frameBorder);
463 m_frameImage = new QGraphicsPixmapItem();
465 qtrans.scale(2.0, 2.0);
466 m_frameImage->setTransform(qtrans);
467 m_frameImage->setZValue(-1200);
468 m_frameImage->setFlags(0);
469 displayBackgroundFrame();
470 graphicsView->scene()->addItem(m_frameImage);
472 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
473 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
474 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
475 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
476 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
477 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
478 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
479 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
482 // mbd: load saved settings
485 graphicsView->show();
486 //graphicsView->setRenderHint(QPainter::Antialiasing);
487 graphicsView->setInteractive(true);
488 //graphicsView->resize(400, 300);
489 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
490 //toolBox->setItemEnabled(2, false);
491 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
492 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
493 m_startViewport->setData(0, m_frameWidth);
494 m_startViewport->setData(1, m_frameHeight);
495 m_endViewport->setData(0, m_frameWidth);
496 m_endViewport->setData(1, m_frameHeight);
498 // scale the view so that the title widget is not too big at startup
499 graphicsView->scale(.5, .5);
500 if (!url.isEmpty()) loadTitle(url);
503 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
506 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
507 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
508 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
510 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
511 refreshTitleTemplates();
512 //templateBox->setIconSize(QSize(60,60));
513 templateBox->clear();
514 templateBox->addItem("");
515 foreach(TitleTemplate t, titletemplates) {
516 templateBox->addItem(t.icon, t.name, t.file);
518 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
522 TitleWidget::~TitleWidget()
526 delete m_buttonImage;
527 delete m_buttonCursor;
530 delete m_unicodeAction;
537 delete m_selectRects;
538 delete m_selectImages;
539 delete m_unselectAll;
541 delete m_unicodeDialog;
542 delete m_frameBorder;
544 delete m_startViewport;
545 delete m_endViewport;
547 delete m_signalMapper;
550 QSize TitleWidget::sizeHint() const
552 // Make sure the widget has minimum size on opening
553 return QSize(200, 200);
557 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
560 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
561 KStandardDirs::makeDir(titlePath);
562 titlePath.append((isClone == false) ? "title" : "clone");
565 while (path.isEmpty() || QFile::exists(path)) {
567 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
569 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
575 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
578 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
579 KStandardDirs::makeDir(titlePath);
580 return titlePath + titleName + ".png";
584 QStringList TitleWidget::extractImageList(QString xml)
587 if (xml.isEmpty()) return result;
590 QDomNodeList images = doc.elementsByTagName("content");
591 for (int i = 0; i < images.count(); i++) {
592 if (images.at(i).toElement().hasAttribute("url"))
593 result.append(images.at(i).toElement().attribute("url"));
599 QStringList TitleWidget::extractFontList(QString xml)
602 if (xml.isEmpty()) return result;
605 QDomNodeList images = doc.elementsByTagName("content");
606 for (int i = 0; i < images.count(); i++) {
607 if (images.at(i).toElement().hasAttribute("font"))
608 result.append(images.at(i).toElement().attribute("font"));
613 void TitleWidget::refreshTitleTemplates()
615 QStringList titlenamelist = QStringList() << i18n("None");
616 QStringList titlefiles = QStringList() << QString();
618 filters << "*.kdenlivetitle" ;
619 titletemplates.clear();
620 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
621 foreach(const QString & folder, titleTemplates) {
622 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
623 foreach(const QString & fname, filesnames) {
624 //titlenamelist.append(fname);
625 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
628 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
629 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
630 titletemplates.append(t);
633 kDebug() << titlenamelist << titlefiles;
635 void TitleWidget::templateIndexChanged(int index)
637 QString item = templateBox->itemData(index).toString();
639 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
640 if (KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
644 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
645 // Text of unchanged template titles should be selected when clicked.
646 QList<QGraphicsItem *> list = graphicsView->scene()->items();
647 foreach(QGraphicsItem * qgItem, list) {
648 if (qgItem->type() == TEXTITEM) {
649 QGraphicsTextItem *i;
650 i = static_cast<QGraphicsTextItem *>(qgItem);
651 i->setProperty("isTemplate", "true");
652 i->setProperty("templateText", i->toHtml());
656 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
660 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
665 void TitleWidget::slotTextTool()
667 m_scene->setTool(TITLE_TEXT);
668 showToolbars(TITLE_TEXT);
669 checkButton(TITLE_TEXT);
672 void TitleWidget::slotRectTool()
674 m_scene->setTool(TITLE_RECTANGLE);
675 showToolbars(TITLE_RECTANGLE);
676 checkButton(TITLE_RECTANGLE);
678 // Disable dragging mode, would make dragging a rect impossible otherwise ;)
679 graphicsView->setDragMode(QGraphicsView::NoDrag);
682 void TitleWidget::slotSelectTool()
684 m_scene->setTool(TITLE_SELECT);
686 // Enable rubberband selecting mode.
687 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
689 // Find out which toolbars need to be shown, depending on selected item
690 TITLETOOL t = TITLE_SELECT;
691 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
693 switch (l.at(0)->type()) {
707 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
708 //graphicsView->centerOn(l.at(0));
714 updateCoordinates(l.at(0));
715 updateDimension(l.at(0));
716 updateRotZoom(l.at(0));
719 checkButton(TITLE_SELECT);
722 void TitleWidget::slotImageTool()
724 // TODO: find a way to get a list of all supported image types...
725 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";
726 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
727 if (!url.isEmpty()) {
728 if (url.path().endsWith(".svg")) {
729 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
730 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
731 svg->setZValue(m_count++);
732 svg->setData(Qt::UserRole, url.path());
733 graphicsView->scene()->addItem(svg);
735 QPixmap pix(url.path());
736 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
737 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
738 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
739 image->setData(Qt::UserRole, url.path());
740 image->setZValue(m_count++);
741 graphicsView->scene()->addItem(image);
744 m_scene->setTool(TITLE_SELECT);
745 showToolbars(TITLE_SELECT);
746 checkButton(TITLE_SELECT);
749 void TitleWidget::showToolbars(TITLETOOL toolType)
753 toolbar_stack->setCurrentIndex(0);
756 toolbar_stack->setCurrentIndex(3);
758 case TITLE_RECTANGLE:
759 toolbar_stack->setCurrentIndex(1);
762 toolbar_stack->setCurrentIndex(2);
767 void TitleWidget::enableToolbars(TITLETOOL toolType)
769 // TITLETOOL is defined in graphicsscenerectmove.h
771 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
772 value_w->setEnabled(enable);
773 value_h->setEnabled(enable);
776 void TitleWidget::checkButton(TITLETOOL toolType)
778 bool bSelect = false;
790 case TITLE_RECTANGLE:
800 m_buttonCursor->setChecked(bSelect);
801 m_buttonText->setChecked(bText);
802 m_buttonRect->setChecked(bRect);
803 m_buttonImage->setChecked(bImage);
806 void TitleWidget::displayBackgroundFrame()
808 QRectF r = m_frameBorder->sceneBoundingRect();
809 if (!displayBg->isChecked()) {
810 QPixmap pattern(20, 20);
812 QColor bgcolor(210, 210, 210);
813 QPainter p(&pattern);
814 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
815 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
818 QPixmap bg((int) (r.width() / 2), (int) (r.height()/ 2));
820 p2.fillRect(bg.rect(), br);
822 m_frameImage->setPixmap(bg);
824 QImage img = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), QString(), m_render->frameRenderWidth() / 2, m_render->renderHeight() / 2);
825 m_frameImage->setPixmap(QPixmap::fromImage(img.scaled(r.width() / 2, r.height() / 2)));
829 void TitleWidget::initAnimation()
831 align_box->setEnabled(false);
832 QPen startpen(Qt::DotLine);
833 QPen endpen(Qt::DashDotLine);
834 startpen.setColor(QColor(100, 200, 100, 140));
835 endpen.setColor(QColor(200, 100, 100, 140));
837 m_startViewport->setPen(startpen);
838 m_endViewport->setPen(endpen);
840 m_startViewport->setZValue(-1000);
841 m_endViewport->setZValue(-1000);
843 m_startViewport->setFlags(0);
844 m_endViewport->setFlags(0);
846 graphicsView->scene()->addItem(m_startViewport);
847 graphicsView->scene()->addItem(m_endViewport);
849 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
850 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
851 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
852 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
855 void TitleWidget::slotUpdateZoom(int pos)
857 m_scene->setZoom((double) pos / 100);
858 zoom_label->setText(QString::number(pos) + '%');
861 void TitleWidget::slotZoom(bool up)
863 int pos = zoom_slider->value();
866 zoom_slider->setValue(pos);
869 void TitleWidget::slotAdjustZoom()
871 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
872 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
873 if (scalex > scaley) scalex = scaley;
874 int zoompos = (int)(scalex * 7 + 0.5);*/
875 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
876 int zoompos = graphicsView->matrix().m11() * 100;
877 zoom_slider->setValue(zoompos);
878 graphicsView->centerOn(m_frameBorder);
881 void TitleWidget::slotZoomOneToOne()
883 zoom_slider->setValue(100);
884 graphicsView->centerOn(m_frameBorder);
887 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
889 updateAxisButtons(rect); // back to default
891 QColor f = rectFColor->color();
892 #if not KDE_IS_VERSION(4,5,0)
893 f.setAlpha(rectFAlpha->value());
896 penf.setWidth(rectLineWidth->value());
897 penf.setJoinStyle(Qt::RoundJoin);
899 QColor b = rectBColor->color();
900 #if not KDE_IS_VERSION(4,5,0)
901 b.setAlpha(rectBAlpha->value());
903 rect->setBrush(QBrush(b));
904 rect->setZValue(m_count++);
905 rect->setData(ZOOMFACTOR, 100);
906 //setCurrentItem(rect);
907 //graphicsView->setFocus();
910 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
912 updateAxisButtons(tt); // back to default
914 QFont font = font_family->currentFont();
915 font.setPixelSize(font_size->value());
917 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
918 font.setItalic(buttonItalic->isChecked());
919 font.setUnderline(buttonUnder->isChecked());
922 QColor color = fontColorButton->color();
923 QColor outlineColor = textOutlineColor->color();
924 #if not KDE_IS_VERSION(4,5,0)
925 color.setAlpha(textAlpha->value());
926 outlineColor.setAlpha(textOutlineAlpha->value());
928 tt->setDefaultTextColor(color);
930 QTextCursor cur(tt->document());
931 cur.select(QTextCursor::Document);
932 QTextBlockFormat format = cur.blockFormat();
933 QTextCharFormat cformat = cur.charFormat();
934 double outlineWidth = textOutline->value() / 10.0;
936 tt->setData(101, outlineWidth);
937 tt->setData(102, outlineColor);
938 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
940 cformat.setForeground(QBrush(color));
941 cur.setCharFormat(cformat);
942 cur.setBlockFormat(format);
943 tt->setTextCursor(cur);
944 tt->setZValue(m_count++);
948 void TitleWidget::setFontBoxWeight(int weight)
950 int index = font_weight_box->findData(weight);
952 index = font_weight_box->findData(QFont::Normal);
954 font_weight_box->setCurrentIndex(index);
957 void TitleWidget::setCurrentItem(QGraphicsItem *item)
959 m_scene->setSelectedItem(item);
962 void TitleWidget::zIndexChanged(int v)
964 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
965 for (int i = 0; i < l.size(); i++) {
970 void TitleWidget::selectionChanged()
972 if (m_scene->tool() != TITLE_SELECT) return;
974 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
976 QList<QGraphicsItem *> l;
978 // mbt 1607: One text item might have grabbed the keyboard.
979 // Ungrab it for all items that are not selected, otherwise
980 // text input would only work for the text item that grabbed
981 // the keyboard last.
982 l = graphicsView->scene()->items();
983 foreach(QGraphicsItem * item, l) {
984 if (item->type() == TEXTITEM && !item->isSelected()) {
985 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
990 l = graphicsView->scene()->selectedItems();
993 buttonUnselectAll->setEnabled(true);
994 // Enable all z index buttons if items selected.
995 // We can selectively disable them later.
996 zUp->setEnabled(true);
997 zDown->setEnabled(true);
998 zTop->setEnabled(true);
999 zBottom->setEnabled(true);
1001 buttonUnselectAll->setEnabled(false);
1003 if (l.size() >= 2) {
1004 buttonSelectText->setEnabled(true);
1005 buttonSelectRects->setEnabled(true);
1006 buttonSelectImages->setEnabled(true);
1008 buttonSelectText->setEnabled(false);
1009 buttonSelectRects->setEnabled(false);
1010 buttonSelectImages->setEnabled(false);
1013 if (l.size() == 0) {
1015 } else if (l.size() == 1) {
1016 prepareTools(l.at(0));
1019 For multiple selected objects we need to decide which tools to show.
1021 int firstType = l.at(0)->type();
1022 bool allEqual = true;
1023 for (int i = 0; i < l.size(); i++) {
1024 if (l.at(i)->type() != firstType) {
1029 std::cout << "All equal? " << allEqual << ".\n";
1031 prepareTools(l.at(0));
1033 // Get the default toolset, but enable the property frame (x,y,w,h)
1035 frame_properties->setEnabled(true);
1037 // Enable x/y/w/h if it makes sense.
1038 value_x->setEnabled(true);
1039 value_y->setEnabled(true);
1040 bool containsTextitem = false;
1041 for (int i = 0; i < l.size(); i++) {
1042 if (l.at(i)->type() == TEXTITEM) {
1043 containsTextitem = true;
1047 if (!containsTextitem) {
1048 value_w->setEnabled(true);
1049 value_h->setEnabled(true);
1053 // Disable z index buttons if they don't make sense for the current selection
1054 int firstZindex = l.at(0)->zValue();
1056 for (int i = 0; i < l.size(); i++) {
1057 if (l[i]->zValue() != firstZindex) {
1063 zUp->setEnabled(false);
1064 zDown->setEnabled(false);
1072 void TitleWidget::slotValueChanged(int type)
1075 type tells us which QSpinBox value has changed.
1078 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1079 std::cout << l.size() << " items to be resized\n";
1081 // Get the updated value here already to do less coding afterwards
1085 val = value_w->value();
1088 val = value_h->value();
1091 val = value_x->value();
1094 val = value_y->value();
1098 for (int k = 0; k < l.size(); k++) {
1099 std::cout << "Type of item " << k << ": " << l.at(k)->type() << "\n";
1101 if (l.at(k)->type() == TEXTITEM) {
1102 // Just update the position. We don't allow setting width/height for text items yet.
1105 updatePosition(l.at(k), val, l.at(k)->pos().y());
1108 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1112 } else if (l.at(k)->type() == RECTITEM) {
1113 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(k));
1116 updatePosition(l.at(k), val, l.at(k)->pos().y());
1119 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1122 rec->setRect(QRect(0, 0, val, rec->rect().height()));
1125 rec->setRect(QRect(0, 0, rec->rect().width(), val));
1129 } else if (l.at(k)->type() == IMAGEITEM) {
1132 if (type == ValueX) {
1133 updatePosition(l.at(k), val, l.at(k)->pos().y());
1135 } else if (type == ValueY) {
1136 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1139 // Width/height has changed. This is more complex.
1141 QGraphicsItem *i = l.at(k);
1142 Transform t = m_transformations.value(i);
1144 // Ratio width:height
1145 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1146 // TODO: proper calculation for rotation around 3 axes
1147 double alpha = (double) t.rotatez / 180.0 * M_PI;
1150 double length = val;
1155 // We want to keep the aspect ratio of the image as the user does not yet have the possibility
1156 // to restore the original ratio. You rarely want to change it anyway.
1159 // Add 0.5 because otherwise incrementing by 1 might have no effect
1160 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1161 scale = length / i->boundingRect().width();
1164 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1165 scale = length / i->boundingRect().height();
1172 qtrans.scale(scale, scale);
1173 qtrans.rotate(t.rotatex, Qt::XAxis);
1174 qtrans.rotate(t.rotatey, Qt::YAxis);
1175 qtrans.rotate(t.rotatez, Qt::ZAxis);
1176 i->setTransform(qtrans);
1177 std::cout << "scale is: " << scale << "\n";
1178 std::cout << i->boundingRect().width() << ": new width\n";
1179 m_transformations[i] = t;
1181 if (l.size() == 1) {
1182 // Only update the w/h values if the selection contains just one item.
1183 // Otherwise, what should we do? ;)
1184 // (Use the values of the first item? Of the second? Of the x-th?)
1186 // Update rotation/zoom values.
1187 // These values are not yet able to handle multiple items!
1198 void TitleWidget::updateDimension(QGraphicsItem *i)
1200 bool wBlocked = value_w->signalsBlocked();
1201 bool hBlocked = value_h->signalsBlocked();
1202 bool zBlocked = zValue->signalsBlocked();
1203 value_w->blockSignals(true);
1204 value_h->blockSignals(true);
1205 zValue->blockSignals(true);
1207 zValue->setValue((int) i->zValue());
1208 if (i->type() == IMAGEITEM) {
1209 // Get multipliers for rotation/scaling
1211 /*Transform t = m_transformations.value(i);
1212 QRectF r = i->boundingRect();
1213 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1214 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1215 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1216 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1218 value_w->setValue(i->sceneBoundingRect().width());
1219 value_h->setValue(i->sceneBoundingRect().height());
1220 } else if (i->type() == RECTITEM) {
1221 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1222 std::cout << "Rect width is: " << r->rect().width() << ", was: " << value_w->value() << "\n";
1223 value_w->setValue((int) r->rect().width());
1224 value_h->setValue((int) r->rect().height());
1225 } else if (i->type() == TEXTITEM) {
1226 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1227 value_w->setValue((int) t->boundingRect().width());
1228 value_h->setValue((int) t->boundingRect().height());
1231 zValue->blockSignals(zBlocked);
1232 value_w->blockSignals(wBlocked);
1233 value_h->blockSignals(hBlocked);
1236 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1238 // Block signals emitted by this method
1239 value_x->blockSignals(true);
1240 value_y->blockSignals(true);
1242 if (i->type() == TEXTITEM) {
1244 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1246 // Set the correct x coordinate value
1247 if (origin_x_left->isChecked()) {
1248 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1249 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1251 // Origin is at 0 (default)
1252 value_x->setValue((int) rec->pos().x());
1256 if (origin_y_top->isChecked()) {
1257 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1259 value_y->setValue((int) rec->pos().y());
1262 } else if (i->type() == RECTITEM) {
1264 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1266 if (origin_x_left->isChecked()) {
1267 // Origin (0 point) is at m_frameWidth
1268 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1270 // Origin is at 0 (default)
1271 value_x->setValue((int) rec->pos().x());
1274 if (origin_y_top->isChecked()) {
1275 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1277 value_y->setValue((int) rec->pos().y());
1280 } else if (i->type() == IMAGEITEM) {
1282 if (origin_x_left->isChecked()) {
1283 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1285 value_x->setValue((int) i->pos().x());
1288 if (origin_y_top->isChecked()) {
1289 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1291 value_y->setValue((int) i->pos().y());
1296 // Stop blocking signals now
1297 value_x->blockSignals(false);
1298 value_y->blockSignals(false);
1301 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1303 itemzoom->blockSignals(true);
1304 itemrotatex->blockSignals(true);
1305 itemrotatey->blockSignals(true);
1306 itemrotatez->blockSignals(true);
1308 Transform t = m_transformations.value(i);
1310 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1311 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1313 itemrotatex->setValue((int)(t.rotatex));
1314 itemrotatey->setValue((int)(t.rotatey));
1315 itemrotatez->setValue((int)(t.rotatez));
1317 itemzoom->blockSignals(false);
1318 itemrotatex->blockSignals(false);
1319 itemrotatey->blockSignals(false);
1320 itemrotatez->blockSignals(false);
1323 void TitleWidget::updatePosition(QGraphicsItem *i)
1325 updatePosition(i, value_x->value(), value_y->value());
1328 void TitleWidget::updatePosition(QGraphicsItem *i, int x, int y)
1330 if (i->type() == TEXTITEM) {
1331 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1334 if (origin_x_left->isChecked()) {
1336 * Origin of the X axis is at m_frameWidth, and distance from right
1337 * border of the item to the right border of the frame is taken. See
1338 * comment to slotOriginXClicked().
1340 posX = m_frameWidth - x - rec->boundingRect().width();
1346 if (origin_y_top->isChecked()) {
1347 /* Same for y axis */
1348 posY = m_frameHeight - y - rec->boundingRect().height();
1353 rec->setPos(posX, posY);
1355 } else if (i->type() == RECTITEM) {
1357 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1360 if (origin_x_left->isChecked()) {
1361 posX = m_frameWidth - x - rec->rect().width();
1367 if (origin_y_top->isChecked()) {
1368 posY = m_frameHeight - y - rec->rect().height();
1373 rec->setPos(posX, posY);
1375 } else if (i->type() == IMAGEITEM) {
1377 if (origin_x_left->isChecked()) {
1378 // Use the sceneBoundingRect because this also regards transformations like zoom
1379 posX = m_frameWidth - x - i->sceneBoundingRect().width();
1385 if (origin_y_top->isChecked()) {
1386 posY = m_frameHeight - y - i->sceneBoundingRect().height();
1391 i->setPos(posX, posY);
1397 void TitleWidget::updateTextOriginX()
1399 if (origin_x_left->isChecked()) {
1400 origin_x_left->setText(i18n("\u2212X"));
1402 origin_x_left->setText(i18n("+X"));
1406 void TitleWidget::slotOriginXClicked()
1408 // Update the text displayed on the button.
1409 updateTextOriginX();
1411 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1412 if (l.size() >= 1) {
1413 updateCoordinates(l.at(0));
1415 // Remember x axis setting
1416 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1417 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1419 graphicsView->setFocus();
1422 void TitleWidget::updateTextOriginY()
1424 if (origin_y_top->isChecked()) {
1425 origin_y_top->setText(i18n("\u2212Y"));
1427 origin_y_top->setText(i18n("+Y"));
1431 void TitleWidget::slotOriginYClicked()
1433 // Update the text displayed on the button.
1434 updateTextOriginY();
1436 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1437 if (l.size() >= 1) {
1438 updateCoordinates(l.at(0));
1440 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1441 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1444 graphicsView->setFocus();
1447 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1449 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1450 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1451 origin_x_left->blockSignals(true);
1452 origin_y_top->blockSignals(true);
1454 if (xAxis == TitleDocument::AxisInverted) {
1455 origin_x_left->setChecked(true);
1457 origin_x_left->setChecked(false);
1459 updateTextOriginX();
1461 if (yAxis == TitleDocument::AxisInverted) {
1462 origin_y_top->setChecked(true);
1464 origin_y_top->setChecked(false);
1466 updateTextOriginY();
1468 origin_x_left->blockSignals(false);
1469 origin_y_top->blockSignals(false);
1472 void TitleWidget::slotChangeBackground()
1474 QColor color = backgroundColor->color();
1475 m_scene->setBackgroundBrush(QBrush(color));
1476 color.setAlpha(backgroundAlpha->value());
1477 m_frameBorder->setBrush(QBrush(color));
1480 void TitleWidget::slotChanged()
1482 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1483 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1484 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1488 void TitleWidget::textChanged(QGraphicsTextItem *i)
1491 * If the user has set origin_x_left (the same for y), we need to look
1492 * whether a text element has been selected. If yes, we need to ensure that
1493 * the right border of the text field remains fixed also when some text has
1496 * This is also known as right-justified, with the difference that it is not
1497 * valid for text but for its boundingRect. Text may still be
1502 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1503 if (!i->toPlainText().isEmpty())
1507 * Don't do anything if the string is empty. If the position were
1508 * updated here, a newly created text field would be set to the
1509 * position of the last selected text field.
1514 // mbt 1607: Template text has changed; don't auto-select content anymore.
1515 if (i->property("isTemplate").isValid()) {
1516 if (i->property("templateText").isValid()) {
1517 if (i->property("templateText") == i->toHtml()) {
1518 // Unchanged, do nothing.
1520 i->setProperty("isTemplate", QVariant::Invalid);
1521 i->setProperty("templateText", QVariant::Invalid);
1527 void TitleWidget::slotInsertUnicode()
1529 m_unicodeDialog->exec();
1532 void TitleWidget::slotInsertUnicodeString(QString text)
1534 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1536 if (l.at(0)->type() == TEXTITEM) {
1537 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1538 t->textCursor().insertText(text);
1543 void TitleWidget::slotUpdateText()
1545 QFont font = font_family->currentFont();
1546 font.setPixelSize(font_size->value());
1547 font.setItalic(buttonItalic->isChecked());
1548 font.setUnderline(buttonUnder->isChecked());
1549 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1550 QColor color = fontColorButton->color();
1551 QColor outlineColor = textOutlineColor->color();
1552 #if not KDE_IS_VERSION(4,5,0)
1553 color.setAlpha(textAlpha->value());
1554 outlineColor.setAlpha(textOutlineAlpha->value());
1557 double outlineWidth = textOutline->value() / 10.0;
1560 for (i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1561 QGraphicsTextItem* item = NULL;
1562 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1563 if (l.at(i)->type() == TEXTITEM) {
1564 item = static_cast <QGraphicsTextItem *>(l.at(i));
1567 // No text item, try next one.
1571 // Set alignment of all text in the text item
1572 QTextCursor cur(item->document());
1573 cur.select(QTextCursor::Document);
1574 QTextBlockFormat format = cur.blockFormat();
1575 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1576 item->setTextWidth(item->boundingRect().width());
1577 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1578 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1579 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1581 format.setAlignment(Qt::AlignLeft);
1582 item->setTextWidth(-1);
1585 // Set font properties
1586 item->setFont(font);
1587 QTextCharFormat cformat = cur.charFormat();
1589 item->setData(101, outlineWidth);
1590 item->setData(102, outlineColor);
1591 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1593 cformat.setForeground(QBrush(color));
1594 cur.setCharFormat(cformat);
1595 cur.setBlockFormat(format);
1596 // item->setTextCursor(cur);
1597 cur.clearSelection();
1598 item->setTextCursor(cur);
1599 item->setDefaultTextColor(color);
1603 void TitleWidget::rectChanged()
1605 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1607 for (i = 0; i < l.length(); i++) {
1608 if (l.at(i)->type() == RECTITEM && !settingUp) {
1609 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1610 QColor f = rectFColor->color();
1611 #if not KDE_IS_VERSION(4,5,0)
1612 f.setAlpha(rectFAlpha->value());
1615 penf.setWidth(rectLineWidth->value());
1616 penf.setJoinStyle(Qt::RoundJoin);
1618 QColor b = rectBColor->color();
1619 #if not KDE_IS_VERSION(4,5,0)
1620 b.setAlpha(rectBAlpha->value());
1622 rec->setBrush(QBrush(b));
1627 void TitleWidget::itemScaled(int val)
1629 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1630 if (l.size() == 1) {
1631 Transform x = m_transformations.value(l.at(0));
1632 x.scalex = (double)val / 100.0;
1633 x.scaley = (double)val / 100.0;
1635 qtrans.scale(x.scalex, x.scaley);
1636 qtrans.rotate(x.rotatex, Qt::XAxis);
1637 qtrans.rotate(x.rotatey, Qt::YAxis);
1638 qtrans.rotate(x.rotatez, Qt::ZAxis);
1639 l[0]->setTransform(qtrans);
1640 l[0]->setData(ZOOMFACTOR, val);
1641 m_transformations[l.at(0)] = x;
1642 updateDimension(l.at(0));
1646 void TitleWidget::itemRotateX(qreal val)
1651 void TitleWidget::itemRotateY(qreal val)
1656 void TitleWidget::itemRotateZ(qreal val)
1661 void TitleWidget::itemRotate(qreal val, int axis)
1663 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1664 if (l.size() == 1) {
1665 Transform x = m_transformations[l.at(0)];
1678 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1681 qtrans.scale(x.scalex, x.scaley);
1682 qtrans.rotate(x.rotatex, Qt::XAxis);
1683 qtrans.rotate(x.rotatey, Qt::YAxis);
1684 qtrans.rotate(x.rotatez, Qt::ZAxis);
1685 l[0]->setTransform(qtrans);
1686 m_transformations[l.at(0)] = x;
1687 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1688 updateDimension(l.at(0));
1692 void TitleWidget::itemHCenter()
1694 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1695 if (l.size() == 1) {
1696 QGraphicsItem *item = l.at(0);
1697 QRectF br = item->sceneBoundingRect();
1698 int width = (int)br.width();
1699 int newPos = (int)((m_frameWidth - width) / 2);
1700 newPos += item->pos().x() - br.left(); // Check item transformation
1701 item->setPos(newPos, item->pos().y());
1702 updateCoordinates(item);
1706 void TitleWidget::itemVCenter()
1708 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1709 if (l.size() == 1) {
1710 QGraphicsItem *item = l.at(0);
1711 QRectF br = item->sceneBoundingRect();
1712 int height = (int)br.height();
1713 int newPos = (int)((m_frameHeight - height) / 2);
1714 newPos += item->pos().y() - br.top(); // Check item transformation
1715 item->setPos(item->pos().x(), newPos);
1716 updateCoordinates(item);
1720 void TitleWidget::itemTop()
1722 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1723 if (l.size() == 1) {
1724 QGraphicsItem *item = l.at(0);
1725 QRectF br = item->sceneBoundingRect();
1727 if (br.top() > 0) diff = -br.top();
1728 else diff = -br.bottom();
1729 item->moveBy(0, diff);
1730 updateCoordinates(item);
1734 void TitleWidget::itemBottom()
1736 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1737 if (l.size() == 1) {
1738 QGraphicsItem *item = l.at(0);
1739 QRectF br = item->sceneBoundingRect();
1741 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1742 else diff = m_frameHeight - br.bottom();
1743 item->moveBy(0, diff);
1744 updateCoordinates(item);
1748 void TitleWidget::itemLeft()
1750 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1751 if (l.size() == 1) {
1752 QGraphicsItem *item = l.at(0);
1753 QRectF br = item->sceneBoundingRect();
1755 if (br.left() > 0) diff = -br.left();
1756 else diff = -br.right();
1757 item->moveBy(diff, 0);
1758 updateCoordinates(item);
1762 void TitleWidget::itemRight()
1764 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1765 if (l.size() == 1) {
1766 QGraphicsItem *item = l.at(0);
1767 QRectF br = item->sceneBoundingRect();
1769 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1770 else diff = m_frameWidth - br.left();
1771 item->moveBy(diff, 0);
1772 updateCoordinates(item);
1776 void TitleWidget::setupViewports()
1778 //double aspect_ratio = 4.0 / 3.0;//read from project
1779 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1780 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1781 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1782 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1783 QPolygonF spoly(sp);
1784 QPolygonF epoly(ep);
1785 spoly.translate(startViewportX->value(), startViewportY->value());
1786 epoly.translate(endViewportX->value(), endViewportY->value());
1787 m_startViewport->setPolygon(spoly);
1788 m_endViewport->setPolygon(epoly);
1789 if (! insertingValues) {
1790 m_startViewport->setData(0, startViewportX->value());
1791 m_startViewport->setData(1, startViewportY->value());
1792 m_startViewport->setData(2, startViewportSize->value());
1794 m_endViewport->setData(0, endViewportX->value());
1795 m_endViewport->setData(1, endViewportY->value());
1796 m_endViewport->setData(2, endViewportSize->value());
1800 void TitleWidget::loadTitle(KUrl url)
1802 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1803 if (!url.isEmpty()) {
1804 QList<QGraphicsItem *> items = m_scene->items();
1805 for (int i = 0; i < items.size(); i++) {
1806 if (items.at(i)->zValue() > -1000) delete items.at(i);
1808 m_scene->clearTextSelection();
1812 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1813 QFile file(tmpfile);
1814 if (file.open(QIODevice::ReadOnly)) {
1815 doc.setContent(&file, false);
1818 KIO::NetAccess::removeTempFile(tmpfile);
1823 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1825 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1826 insertingValues = true;
1827 startViewportX->setValue(m_startViewport->data(0).toInt());
1828 startViewportY->setValue(m_startViewport->data(1).toInt());
1829 startViewportSize->setValue(m_startViewport->data(2).toInt());
1830 endViewportX->setValue(m_endViewport->data(0).toInt());
1831 endViewportY->setValue(m_endViewport->data(1).toInt());
1832 endViewportSize->setValue(m_endViewport->data(2).toInt());
1834 insertingValues = false;
1840 void TitleWidget::saveTitle(KUrl url)
1842 if (anim_start->isChecked()) slotAnimStart(false);
1843 if (anim_end->isChecked()) slotAnimEnd(false);
1844 bool embed_image=false;
1845 if (KMessageBox::questionYesNo(this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::No)
1849 if (url.isEmpty()) {
1850 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1851 fs->setOperationMode(KFileDialog::Saving);
1852 fs->setMode(KFile::File);
1853 fs->setConfirmOverwrite(true);
1854 fs->setKeepLocation(true);
1856 url = fs->selectedUrl();
1859 if (!url.isEmpty()) {
1860 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
1861 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1865 QDomDocument TitleWidget::xml()
1867 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1868 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1872 int TitleWidget::outPoint() const
1874 return m_tc.getFrameCount(title_duration->text());
1877 void TitleWidget::setXml(QDomDocument doc)
1880 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out, m_projectTitlePath);
1882 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1883 /*if (doc.documentElement().hasAttribute("out")) {
1884 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1885 title_duration->setText(m_tc.getTimecode(duration));
1887 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1889 QDomElement e = doc.documentElement();
1890 m_transformations.clear();
1891 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1892 const double PI = 4.0 * atan(1.0);
1893 for (int i = 0; i < items.count(); i++) {
1894 QTransform t = items.at(i)->transform();
1898 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1899 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1900 if (rotlist.count() >= 3) {
1901 x.rotatex = rotlist[0].toDouble();
1902 x.rotatey = rotlist[1].toDouble();
1903 x.rotatez = rotlist[2].toDouble();
1905 // Try to adjust zoom
1906 t.rotate(x.rotatex *(-1), Qt::XAxis);
1907 t.rotate(x.rotatey *(-1), Qt::YAxis);
1908 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1919 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1921 m_transformations[items.at(i)] = x;
1923 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1924 QColor background_color = m_titledocument.getBackgroundColor();
1925 backgroundAlpha->blockSignals(true);
1926 backgroundColor->blockSignals(true);
1927 backgroundAlpha->setValue(background_color.alpha());
1928 background_color.setAlpha(255);
1929 backgroundColor->setColor(background_color);
1930 backgroundAlpha->blockSignals(false);
1931 backgroundColor->blockSignals(false);
1933 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1934 startViewportY->setValue(m_startViewport->data(1).toInt());
1935 startViewportSize->setValue(m_startViewport->data(2).toInt());
1936 endViewportX->setValue(m_endViewport->data(0).toInt());
1937 endViewportY->setValue(m_endViewport->data(1).toInt());
1938 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1940 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1945 void TitleWidget::slotAccepted()
1947 if (anim_start->isChecked()) slotAnimStart(false);
1948 if (anim_end->isChecked()) slotAnimEnd(false);
1952 void TitleWidget::writeChoices()
1954 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1955 KSharedConfigPtr config = KGlobal::config();
1956 KConfigGroup titleConfig(config, "TitleWidget");
1957 // Write the entries
1958 titleConfig.writeEntry("font_family", font_family->currentFont());
1959 //titleConfig.writeEntry("font_size", font_size->value());
1960 titleConfig.writeEntry("font_pixel_size", font_size->value());
1961 titleConfig.writeEntry("font_color", fontColorButton->color());
1962 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1963 #if KDE_IS_VERSION(4,5,0)
1964 titleConfig.writeEntry("font_alpha", fontColorButton->color().alpha());
1965 titleConfig.writeEntry("font_outline_alpha", textOutlineColor->color().alpha());
1967 titleConfig.writeEntry("font_alpha", textAlpha->value());
1968 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1971 titleConfig.writeEntry("font_outline", textOutline->value());
1972 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1973 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1974 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1976 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1977 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1979 #if KDE_IS_VERSION(4,5,0)
1980 titleConfig.writeEntry("rect_background_alpha", rectBColor->color().alpha());
1981 titleConfig.writeEntry("rect_foreground_alpha", rectFColor->color().alpha());
1983 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1984 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1987 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1989 titleConfig.writeEntry("background_color", backgroundColor->color());
1990 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1992 //! \todo Not sure if I should sync - it is probably safe to do it
1997 void TitleWidget::readChoices()
1999 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
2000 KSharedConfigPtr config = KGlobal::config();
2001 KConfigGroup titleConfig(config, "TitleWidget");
2003 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
2004 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
2005 m_scene->slotUpdateFontSize(font_size->value());
2006 QColor fontColor = QColor(titleConfig.readEntry("font_color", fontColorButton->color()));
2007 QColor outlineColor = QColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
2008 #if KDE_IS_VERSION(4,5,0)
2009 fontColor.setAlpha(titleConfig.readEntry("font_alpha", fontColor.alpha()));
2010 outlineColor.setAlpha(titleConfig.readEntry("font_outline_alpha", outlineColor.alpha()));
2012 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
2013 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
2015 fontColorButton->setColor(fontColor);
2016 textOutlineColor->setColor(outlineColor);
2017 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
2020 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
2021 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
2022 setFontBoxWeight(weight);
2023 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
2024 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
2026 QColor fgColor = QColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
2027 QColor bgColor = QColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
2029 #if KDE_IS_VERSION(4,5,0)
2030 fgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", fgColor.alpha()));
2031 bgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", bgColor.alpha()));
2033 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
2034 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
2036 rectFColor->setColor(fgColor);
2037 rectBColor->setColor(bgColor);
2039 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
2041 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
2042 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
2045 void TitleWidget::adjustFrameSize()
2047 m_frameWidth = m_titledocument.frameWidth();
2048 m_frameHeight = m_titledocument.frameHeight();
2049 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
2050 displayBackgroundFrame();
2053 void TitleWidget::slotAnimStart(bool anim)
2055 if (anim && anim_end->isChecked()) {
2056 anim_end->setChecked(false);
2057 m_endViewport->setZValue(-1000);
2058 m_endViewport->setBrush(QBrush());
2061 QList<QGraphicsItem *> list = m_scene->items();
2062 for (int i = 0; i < list.count(); i++) {
2063 if (list.at(i)->zValue() > -1000) {
2064 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2065 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2068 align_box->setEnabled(anim);
2069 itemzoom->setEnabled(!anim);
2070 itemrotatex->setEnabled(!anim);
2071 itemrotatey->setEnabled(!anim);
2072 itemrotatez->setEnabled(!anim);
2073 frame_toolbar->setEnabled(!anim);
2074 toolbar_stack->setEnabled(!anim);
2076 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
2077 m_startViewport->setZValue(1100);
2078 QColor col = m_startViewport->pen().color();
2080 m_startViewport->setBrush(col);
2081 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2082 m_startViewport->setSelected(true);
2085 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
2087 m_startViewport->setZValue(-1000);
2088 m_startViewport->setBrush(QBrush());
2089 m_startViewport->setFlags(0);
2090 if (!anim_end->isChecked()) deleteAnimInfoText();
2095 void TitleWidget::slotAnimEnd(bool anim)
2097 if (anim && anim_start->isChecked()) {
2098 anim_start->setChecked(false);
2099 m_startViewport->setZValue(-1000);
2100 m_startViewport->setBrush(QBrush());
2103 QList<QGraphicsItem *> list = m_scene->items();
2104 for (int i = 0; i < list.count(); i++) {
2105 if (list.at(i)->zValue() > -1000) {
2106 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2107 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2110 align_box->setEnabled(anim);
2111 itemzoom->setEnabled(!anim);
2112 itemrotatex->setEnabled(!anim);
2113 itemrotatey->setEnabled(!anim);
2114 itemrotatez->setEnabled(!anim);
2115 frame_toolbar->setEnabled(!anim);
2116 toolbar_stack->setEnabled(!anim);
2118 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2119 m_endViewport->setZValue(1100);
2120 QColor col = m_endViewport->pen().color();
2122 m_endViewport->setBrush(col);
2123 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2124 m_endViewport->setSelected(true);
2127 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2129 m_endViewport->setZValue(-1000);
2130 m_endViewport->setBrush(QBrush());
2131 m_endViewport->setFlags(0);
2132 if (!anim_start->isChecked()) deleteAnimInfoText();
2136 void TitleWidget::addAnimInfoText()
2138 // add text to anim viewport
2139 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2140 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2141 QFont font = t->font();
2142 font.setPixelSize(m_startViewport->rect().width() / 10);
2143 QColor col = m_startViewport->pen().color();
2145 t->setDefaultTextColor(col);
2147 font.setPixelSize(m_endViewport->rect().width() / 10);
2148 col = m_endViewport->pen().color();
2150 t2->setDefaultTextColor(col);
2154 void TitleWidget::updateInfoText()
2156 // update info text font
2157 if (!m_startViewport->childItems().isEmpty()) {
2158 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2160 QFont font = item->font();
2161 font.setPixelSize(m_startViewport->rect().width() / 10);
2162 item->setFont(font);
2165 if (!m_endViewport->childItems().isEmpty()) {
2166 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2168 QFont font = item->font();
2169 font.setPixelSize(m_endViewport->rect().width() / 10);
2170 item->setFont(font);
2175 void TitleWidget::deleteAnimInfoText()
2177 // end animation editing, remove info text
2178 while (!m_startViewport->childItems().isEmpty()) {
2179 QGraphicsItem *item = m_startViewport->childItems().at(0);
2180 m_scene->removeItem(item);
2183 while (!m_endViewport->childItems().isEmpty()) {
2184 QGraphicsItem *item = m_endViewport->childItems().at(0);
2185 m_scene->removeItem(item);
2190 void TitleWidget::slotKeepAspect(bool keep)
2192 if (m_endViewport->zValue() == 1100) {
2193 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2194 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2196 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2197 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2201 void TitleWidget::slotResize50()
2203 if (m_endViewport->zValue() == 1100) {
2204 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2205 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2208 void TitleWidget::slotResize100()
2210 if (m_endViewport->zValue() == 1100) {
2211 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2212 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2215 void TitleWidget::slotResize200()
2217 if (m_endViewport->zValue() == 1100) {
2218 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2219 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2222 void TitleWidget::slotAddEffect(int ix)
2224 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2225 int effect = effect_list->itemData(ix).toInt();
2227 if (list.size() == 1) {
2228 if (effect == NOEFFECT)
2229 effect_stack->setHidden(true);
2231 effect_stack->setCurrentIndex(effect - 1);
2232 effect_stack->setHidden(false);
2234 } else // Hide the effects stack when more than one element is selected.
2235 effect_stack->setHidden(true);
2237 foreach(QGraphicsItem * item, list) {
2240 item->setData(100, QVariant());
2241 #if QT_VERSION >= 0x040600
2242 item->setGraphicsEffect(0);
2245 case TYPEWRITEREFFECT:
2247 * Allow the user to set the typewriter effect to more than one
2248 * element, but do not add it to non-text elements.
2250 if (item->type() == TEXTITEM) {
2251 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2252 item->setData(100, effdata);
2255 #if QT_VERSION >= 0x040600
2256 // Do not remove the non-QGraphicsEffects.
2258 item->setGraphicsEffect(new QGraphicsBlurEffect());
2261 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2268 void TitleWidget::slotFontText(const QString& s)
2271 if (f.exactMatch()) {
2272 // Font really exists (could also just be a «d» if the user
2273 // starts typing «dejavu» for example).
2274 font_family->setCurrentFont(f);
2276 // Note: Typing dejavu serif does not recognize the font (takes sans)
2277 // in older Qt versions. Case must match there (except for first letter)
2280 void TitleWidget::slotEditTypewriter(int /*ix*/)
2282 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2283 if (l.size() == 1) {
2284 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2285 l[0]->setData(100, effdata);
2289 void TitleWidget::slotEditBlur(int ix)
2291 #if QT_VERSION < 0x040600
2294 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2295 if (l.size() == 1) {
2296 QGraphicsEffect *eff = l[0]->graphicsEffect();
2297 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2298 if (blur) blur->setBlurRadius(ix);
2303 void TitleWidget::slotEditShadow()
2305 #if QT_VERSION < 0x040600
2308 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2309 if (l.size() == 1) {
2310 QGraphicsEffect *eff = l[0]->graphicsEffect();
2311 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2313 shadow->setBlurRadius(shadow_radius->value());
2314 shadow->setOffset(shadow_x->value(), shadow_y->value());
2320 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2322 qreal bound = maxBound ? -99 : 99;
2323 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2325 QList<QGraphicsItem*> lItems;
2326 // Get items (all or intersecting only)
2327 if (intersectingOnly) {
2328 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2330 lItems = graphicsView->scene()->items();
2332 if (lItems.size() > 0) {
2333 int n = lItems.size();
2336 for (int i = 0; i < n; i++) {
2337 z = lItems[i]->zValue();
2338 if (z > bound && !lItems[i]->isSelected()) {
2340 } else if (z - 1 > bound) {
2341 // To get the maximum index even if it is of an item of the current selection.
2342 // Used when updating multiple items, to get all to the same level.
2343 // Otherwise, the maximum would stay at -99 if the highest item is in the selection.
2348 // Get minimum z index.
2349 for (int i = 0; i < n; i++) {
2350 z = lItems[i]->zValue();
2351 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2352 // There are items at the very bottom (background e.g.) with z-index < -1000.
2354 } else if (z + 1 < bound && z > -999) {
2364 void TitleWidget::slotZIndexUp()
2366 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2367 if (l.size() >= 1) {
2368 qreal currentZ = l[0]->zValue();
2369 qreal max = zIndexBounds(true, true);
2370 if (currentZ <= max) {
2371 l[0]->setZValue(currentZ + 1);
2372 updateDimension(l[0]);
2377 void TitleWidget::slotZIndexTop()
2379 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2380 qreal max = zIndexBounds(true, false);
2381 std::cout << "Max z-index is " << max << ".\n";
2382 for (int i = 0; i < l.size(); i++) {
2383 qreal currentZ = l[i]->zValue();
2384 if (currentZ <= max) {
2385 std::cout << "Updating item " << i << ", is " << currentZ << ".\n";
2386 l[i]->setZValue(max + 1);
2388 std::cout << "Not updating " << i << ", is " << currentZ << ".\n";
2391 // Update the z index value in the GUI
2393 updateDimension(l[0]);
2397 void TitleWidget::slotZIndexDown()
2399 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2400 if (l.size() >= 1) {
2401 qreal currentZ = l[0]->zValue();
2402 qreal min = zIndexBounds(false, true);
2403 if (currentZ >= min) {
2404 l[0]->setZValue(currentZ - 1);
2405 updateDimension(l[0]);
2410 void TitleWidget::slotZIndexBottom()
2412 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2413 qreal min = zIndexBounds(false, false);
2414 for (int i = 0; i < l.size(); i++) {
2415 qreal currentZ = l[i]->zValue();
2416 if (currentZ >= min) {
2417 l[i]->setZValue(min - 1);
2420 // Update the z index value in the GUI
2422 updateDimension(l[0]);
2426 void TitleWidget::slotSelectAll()
2428 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2429 for (int i = 0; i < l.size(); i++) {
2430 l.at(i)->setSelected(true);
2434 void TitleWidget::selectItems(int itemType)
2436 QList<QGraphicsItem*> l;
2437 if (graphicsView->scene()->selectedItems().size() > 0) {
2438 l = graphicsView->scene()->selectedItems();
2439 for (int i = 0; i < l.size(); i++) {
2440 if (l.at(i)->type() != itemType) {
2441 l.at(i)->setSelected(false);
2445 l = graphicsView->scene()->items();
2446 for (int i = 0; i < l.size(); i++) {
2447 if (l.at(i)->type() == itemType) {
2448 l.at(i)->setSelected(true);
2454 void TitleWidget::slotSelectText()
2456 selectItems(TEXTITEM);
2459 void TitleWidget::slotSelectRects()
2461 selectItems(RECTITEM);
2464 void TitleWidget::slotSelectImages()
2466 selectItems(IMAGEITEM);
2469 void TitleWidget::slotSelectNone()
2471 graphicsView->blockSignals(true);
2472 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2473 for (int i = 0; i < l.size(); i++) {
2474 l.at(i)->setSelected(false);
2476 graphicsView->blockSignals(false);
2480 QString TitleWidget::getTooltipWithShortcut(const QString &text, QAction *button)
2482 return text + " <b>" + button->shortcut().toString() + "</b>";
2485 void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
2487 // Let some GUI elements block signals. We may want to change their values without any sideeffects.
2488 // Additionally, store the previous blocking state to avoid side effects when this function is called from within another one.
2489 // Note: Disabling an element also blocks signals. So disabled elements don't need to be set to blocking too.
2490 bool blockOX = origin_x_left->signalsBlocked();
2491 bool blockOY = origin_y_top->signalsBlocked();
2492 bool blockEff = effect_list->signalsBlocked();
2493 bool blockRX = itemrotatex->signalsBlocked();
2494 bool blockRY = itemrotatey->signalsBlocked();
2495 bool blockRZ = itemrotatez->signalsBlocked();
2496 bool blockZoom = itemzoom->signalsBlocked();
2497 bool blockX = value_x->signalsBlocked();
2498 bool blockY = value_y->signalsBlocked();
2499 bool blockW = value_w->signalsBlocked();
2500 bool blockH = value_h->signalsBlocked();
2501 origin_x_left->blockSignals(true);
2502 origin_y_top->blockSignals(true);
2503 effect_list->blockSignals(true);
2504 itemrotatex->blockSignals(true);
2505 itemrotatey->blockSignals(true);
2506 itemrotatez->blockSignals(true);
2507 itemzoom->blockSignals(true);
2508 value_x->blockSignals(true);
2509 value_y->blockSignals(true);
2510 value_w->blockSignals(true);
2511 value_h->blockSignals(true);
2513 if (referenceItem == NULL) {
2514 std::cout << "NULL item.\n";
2515 effect_stack->setHidden(true);
2516 effect_frame->setEnabled(false);
2517 effect_list->setCurrentIndex(0);
2518 origin_x_left->setChecked(false);
2519 origin_y_top->setChecked(false);
2520 updateTextOriginX();
2521 updateTextOriginY();
2522 enableToolbars(TITLE_SELECT);
2523 showToolbars(TITLE_SELECT);
2525 itemzoom->setEnabled(false);
2526 itemrotatex->setEnabled(false);
2527 itemrotatey->setEnabled(false);
2528 itemrotatez->setEnabled(false);
2529 frame_properties->setEnabled(false);
2531 effect_frame->setEnabled(true);
2532 frame_properties->setEnabled(true);
2533 if (referenceItem != m_startViewport && referenceItem != m_endViewport) {
2534 itemzoom->setEnabled(true);
2535 itemrotatex->setEnabled(true);
2536 itemrotatey->setEnabled(true);
2537 itemrotatez->setEnabled(true);
2539 itemzoom->setEnabled(false);
2540 itemrotatex->setEnabled(false);
2541 itemrotatey->setEnabled(false);
2542 itemrotatez->setEnabled(false);
2545 if (referenceItem->type() == TEXTITEM) {
2546 showToolbars(TITLE_TEXT);
2547 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(referenceItem);
2548 if (!i->data(100).isNull()) {
2549 // Item has an effect
2550 QStringList effdata = i->data(100).toStringList();
2551 QString effectName = effdata.takeFirst();
2552 if (effectName == "typewriter") {
2553 QStringList params = effdata.at(0).split(';');
2554 typewriter_delay->setValue(params.at(0).toInt());
2555 typewriter_start->setValue(params.at(1).toInt());
2556 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
2557 effect_stack->setHidden(false);
2560 #if QT_VERSION >= 0x040600
2561 if (i->graphicsEffect()) {
2562 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
2564 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
2565 int rad = (int) blur->blurRadius();
2566 blur_radius->setValue(rad);
2567 effect_stack->setHidden(false);
2569 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
2571 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
2572 shadow_radius->setValue(shad->blurRadius());
2573 shadow_x->setValue(shad->xOffset());
2574 shadow_y->setValue(shad->yOffset());
2575 effect_stack->setHidden(false);
2579 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2580 effect_stack->setHidden(true);
2583 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2584 effect_stack->setHidden(true);
2587 font_size->blockSignals(true);
2588 font_family->blockSignals(true);
2589 font_weight_box->blockSignals(true);
2590 buttonItalic->blockSignals(true);
2591 buttonUnder->blockSignals(true);
2592 fontColorButton->blockSignals(true);
2593 #if not KDE_IS_VERSION(4,5,0)
2594 textAlpha->blockSignals(true);
2596 buttonAlignLeft->blockSignals(true);
2597 buttonAlignRight->blockSignals(true);
2598 buttonAlignNone->blockSignals(true);
2599 buttonAlignCenter->blockSignals(true);
2601 QFont font = i->font();
2602 font_family->setCurrentFont(font);
2603 font_size->setValue(font.pixelSize());
2604 m_scene->slotUpdateFontSize(font.pixelSize());
2605 buttonItalic->setChecked(font.italic());
2606 buttonUnder->setChecked(font.underline());
2607 setFontBoxWeight(font.weight());
2609 QTextCursor cursor(i->document());
2610 cursor.select(QTextCursor::Document);
2611 QColor color = cursor.charFormat().foreground().color();
2612 #if not KDE_IS_VERSION(4,5,0)
2613 textAlpha->setValue(color.alpha());
2614 color.setAlpha(255);
2616 fontColorButton->setColor(color);
2618 if (!i->data(101).isNull()) {
2619 textOutline->blockSignals(true);
2620 textOutline->setValue(i->data(101).toDouble() * 10);
2621 textOutline->blockSignals(false);
2623 if (!i->data(102).isNull()) {
2624 textOutlineColor->blockSignals(true);
2625 QVariant variant = i->data(102);
2626 color = variant.value<QColor>();
2627 #if not KDE_IS_VERSION(4,5,0)
2628 textOutlineAlpha->blockSignals(true);
2629 textOutlineAlpha->setValue(color.alpha());
2630 color.setAlpha(255);
2631 textOutlineAlpha->blockSignals(false);
2633 textOutlineColor->setColor(color);
2634 textOutlineColor->blockSignals(false);
2636 QTextCursor cur = i->textCursor();
2637 QTextBlockFormat format = cur.blockFormat();
2638 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
2639 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
2640 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
2641 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
2643 font_size->blockSignals(false);
2644 font_family->blockSignals(false);
2645 font_weight_box->blockSignals(false);
2646 buttonItalic->blockSignals(false);
2647 buttonUnder->blockSignals(false);
2648 fontColorButton->blockSignals(false);
2649 #if not KDE_IS_VERSION(4,5,0)
2650 textAlpha->blockSignals(false);
2652 buttonAlignLeft->blockSignals(false);
2653 buttonAlignRight->blockSignals(false);
2654 buttonAlignNone->blockSignals(false);
2655 buttonAlignCenter->blockSignals(false);
2657 // mbt 1607: Select text if the text item is an unchanged template item.
2658 if (i->property("isTemplate").isValid()) {
2659 cur.setPosition(0, QTextCursor::MoveAnchor);
2660 cur.select(QTextCursor::Document);
2661 i->setTextCursor(cur);
2662 // Make text editable now.
2664 i->setTextInteractionFlags(Qt::TextEditorInteraction);
2667 updateAxisButtons(i);
2668 updateCoordinates(i);
2670 enableToolbars(TITLE_TEXT);
2672 } else if ((referenceItem)->type() == RECTITEM) {
2673 showToolbars(TITLE_RECTANGLE);
2675 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(referenceItem);
2676 if (rec == m_startViewport || rec == m_endViewport) {
2677 /*toolBox->setCurrentIndex(3);
2678 toolBox->widget(0)->setEnabled(false);
2679 toolBox->widget(1)->setEnabled(false);*/
2680 enableToolbars(TITLE_SELECT);
2682 /*toolBox->widget(0)->setEnabled(true);
2683 toolBox->widget(1)->setEnabled(true);
2684 toolBox->setCurrentIndex(0);*/
2685 //toolBox->setItemEnabled(3, true);
2686 #if not KDE_IS_VERSION(4,5,0)
2687 rectFAlpha->setValue(rec->pen().color().alpha());
2688 rectBAlpha->setValue(rec->brush().color().alpha());
2690 //kDebug() << rec->brush().color().alpha();
2691 QColor fcol = rec->pen().color();
2692 QColor bcol = rec->brush().color();
2693 //fcol.setAlpha(255);
2694 //bcol.setAlpha(255);
2695 rectFColor->setColor(fcol);
2696 rectBColor->setColor(bcol);
2698 rectLineWidth->setValue(rec->pen().width());
2699 enableToolbars(TITLE_RECTANGLE);
2702 updateAxisButtons(referenceItem);
2703 updateCoordinates(rec);
2704 updateDimension(rec);
2706 } else if (referenceItem->type() == IMAGEITEM) {
2707 showToolbars(TITLE_IMAGE);
2709 updateCoordinates(referenceItem);
2710 updateDimension(referenceItem);
2712 enableToolbars(TITLE_IMAGE);
2715 //toolBox->setCurrentIndex(0);
2716 showToolbars(TITLE_SELECT);
2717 enableToolbars(TITLE_SELECT);
2718 frame_properties->setEnabled(false);
2720 zValue->setValue((int)referenceItem->zValue());
2721 if (!referenceItem->data(ZOOMFACTOR).isNull()) itemzoom->setValue(referenceItem->data(ZOOMFACTOR).toInt());
2722 else itemzoom->setValue((int)(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
2723 itemrotatex->setValue((int)(m_transformations.value(referenceItem).rotatex));
2724 itemrotatey->setValue((int)(m_transformations.value(referenceItem).rotatey));
2725 itemrotatez->setValue((int)(m_transformations.value(referenceItem).rotatez));
2729 effect_list->blockSignals(blockEff);
2730 itemrotatex->blockSignals(blockRX);
2731 itemrotatey->blockSignals(blockRY);
2732 itemrotatez->blockSignals(blockRZ);
2733 itemzoom->blockSignals(blockZoom);
2734 origin_x_left->blockSignals(blockOX);
2735 origin_y_top->blockSignals(blockOY);
2736 value_x->blockSignals(blockX);
2737 value_y->blockSignals(blockY);
2738 value_w->blockSignals(blockW);
2739 value_h->blockSignals(blockH);