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>
45 #if QT_VERSION >= 0x040600
46 #include <QGraphicsEffect>
47 #include <QGraphicsBlurEffect>
48 #include <QGraphicsDropShadowEffect>
53 static QList<TitleTemplate> titletemplates;
55 // What exactly is this variable good for?
56 int settingUp = false;
58 const int IMAGEITEM = 7;
59 const int RECTITEM = 3;
60 const int TEXTITEM = 8;
62 const int NOEFFECT = 0;
63 const int BLUREFFECT = 1;
64 const int SHADOWEFFECT = 2;
65 const int TYPEWRITEREFFECT = 3;
67 TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render *render, QWidget *parent) :
70 m_startViewport(NULL),
74 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
75 m_projectTitlePath(projectTitlePath),
79 setFont(KGlobalSettings::toolBarFont());
80 frame_properties->setEnabled(false);
81 frame_properties->setFixedHeight(frame_toolbar->height());
82 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
83 QSize iconSize(size, size);
85 #if KDE_IS_VERSION(4,5,0)
86 rectBColor->setAlphaChannelEnabled(true);
88 rectFColor->setAlphaChannelEnabled(true);
90 fontColorButton->setAlphaChannelEnabled(true);
92 textOutlineColor->setAlphaChannelEnabled(true);
93 delete textOutlineAlpha;
96 rectBAlpha->setMinimum(0);
97 rectBAlpha->setMaximum(255);
98 rectBAlpha->setDecimals(0);
99 rectBAlpha->setValue(255);
100 rectBAlpha->setToolTip(i18n("Color opacity"));
102 rectFAlpha->setMinimum(0);
103 rectFAlpha->setMaximum(255);
104 rectFAlpha->setDecimals(0);
105 rectFAlpha->setValue(255);
106 rectFAlpha->setToolTip(i18n("Border opacity"));
107 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
108 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
110 // Set combo sliders values
111 textAlpha->setMinimum(0);
112 textAlpha->setMaximum(255);
113 textAlpha->setDecimals(0);
114 textAlpha->setValue(255);
115 textAlpha->setToolTip(i18n("Font color opacity"));
117 textOutlineAlpha->setMinimum(0);
118 textOutlineAlpha->setMaximum(255);
119 textOutlineAlpha->setDecimals(0);
120 textOutlineAlpha->setValue(255);
121 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
122 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
123 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
126 textOutline->setMinimum(0);
127 textOutline->setMaximum(200);
128 textOutline->setDecimals(0);
129 textOutline->setValue(0);
130 textOutline->setToolTip(i18n("Outline width"));
132 backgroundAlpha->setMinimum(0);
133 backgroundAlpha->setMaximum(255);
134 backgroundAlpha->setDecimals(0);
135 backgroundAlpha->setValue(0);
136 backgroundAlpha->setToolTip(i18n("Background color opacity"));
138 itemrotatex->setMinimum(-360);
139 itemrotatex->setMaximum(360);
140 itemrotatex->setDecimals(0);
141 itemrotatex->setValue(0);
142 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
144 itemrotatey->setMinimum(-360);
145 itemrotatey->setMaximum(360);
146 itemrotatey->setDecimals(0);
147 itemrotatey->setValue(0);
148 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
150 itemrotatez->setMinimum(-360);
151 itemrotatez->setMaximum(360);
152 itemrotatez->setDecimals(0);
153 itemrotatez->setValue(0);
154 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
156 rectLineWidth->setMinimum(0);
157 rectLineWidth->setMaximum(100);
158 rectLineWidth->setDecimals(0);
159 rectLineWidth->setValue(0);
160 rectLineWidth->setToolTip(i18n("Border width"));
162 itemzoom->setSuffix(i18n("%"));
163 m_frameWidth = render->renderWidth();
164 m_frameHeight = render->renderHeight();
165 showToolbars(TITLE_SELECT);
167 splitter->setStretchFactor(0, 20);
169 //If project is drop frame, set the input mask as such.
170 title_duration->setInputMask(m_tc.mask());
171 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
173 connect(backgroundColor, SIGNAL(changed(const QColor &)), this, SLOT(slotChangeBackground())) ;
174 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
176 connect(fontColorButton, SIGNAL(changed(const QColor &)), this, SLOT(slotUpdateText())) ;
177 connect(textOutlineColor, SIGNAL(changed(const QColor &)), this, SLOT(slotUpdateText())) ;
178 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
179 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
180 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
181 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
183 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
185 connect(rectFColor, SIGNAL(changed(const QColor &)), this, SLOT(rectChanged()));
186 connect(rectBColor, SIGNAL(changed(const QColor &)), this, SLOT(rectChanged()));
187 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
189 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
190 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
191 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
192 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
193 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
194 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
197 effect_list->addItem(i18n("None"), NOEFFECT);
198 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
199 effect_list->addItem(i18n("Blur"), BLUREFFECT);
202 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
203 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
204 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
205 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
206 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
207 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
208 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
209 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
210 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
211 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
212 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
213 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
214 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
215 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
216 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
217 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
218 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
219 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
220 effect_stack->setHidden(true);
221 effect_frame->setEnabled(false);
223 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
224 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
227 m_signalMapper = new QSignalMapper(this);
228 m_signalMapper->setMapping(value_w, ValueWidth);
229 m_signalMapper->setMapping(value_h, ValueHeight);
230 m_signalMapper->setMapping(value_x, ValueX);
231 m_signalMapper->setMapping(value_y, ValueY);
232 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
233 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
234 connect(value_x, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
235 connect(value_y, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
236 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
238 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
239 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
240 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
241 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
242 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
243 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
244 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
245 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
246 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
248 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
251 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
253 font_weight_box->blockSignals(true);
254 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
255 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
256 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
257 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
258 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
259 font_weight_box->setToolTip(i18n("Font weight"));
260 font_weight_box->setCurrentIndex(1);
261 font_weight_box->blockSignals(false);
263 buttonFitZoom->setIconSize(iconSize);
264 buttonRealSize->setIconSize(iconSize);
265 buttonItalic->setIconSize(iconSize);
266 buttonUnder->setIconSize(iconSize);
267 buttonAlignCenter->setIconSize(iconSize);
268 buttonAlignLeft->setIconSize(iconSize);
269 buttonAlignRight->setIconSize(iconSize);
270 buttonAlignNone->setIconSize(iconSize);
272 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
273 buttonRealSize->setIcon(KIcon("zoom-original"));
274 buttonItalic->setIcon(KIcon("format-text-italic"));
275 buttonUnder->setIcon(KIcon("format-text-underline"));
276 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
277 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
278 buttonAlignRight->setIcon(KIcon("format-justify-right"));
279 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
281 buttonAlignNone->setToolTip(i18n("No alignment"));
282 buttonAlignRight->setToolTip(i18n("Align right"));
283 buttonAlignLeft->setToolTip(i18n("Align left"));
284 buttonAlignCenter->setToolTip(i18n("Align center"));
286 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
287 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
288 m_unicodeAction->setToolTip(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
289 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
290 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
292 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
293 m_zUp->setShortcut(Qt::Key_PageUp);
294 m_zUp->setToolTip(i18n("Raise object"));
295 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
296 zUp->setDefaultAction(m_zUp);
298 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
299 m_zDown->setShortcut(Qt::Key_PageDown);
300 m_zDown->setToolTip(i18n("Lower object"));
301 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
302 zDown->setDefaultAction(m_zDown);
304 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
305 // TODO mbt 1414: Shortcut should change z index only if
306 // cursor is NOT in a text field ...
307 //m_zTop->setShortcut(Qt::Key_Home);
308 m_zTop->setToolTip(i18n("Raise object to top"));
309 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
310 zTop->setDefaultAction(m_zTop);
312 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
314 //m_zBottom->setShortcut(Qt::Key_End);
315 m_zBottom->setToolTip(i18n("Lower object to bottom"));
316 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
317 zBottom->setDefaultAction(m_zBottom);
319 m_selectAll = new QAction(KIcon("kdenlive-select-all"), QString(), this);
320 m_selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
321 connect(m_selectAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
322 buttonSelectAll->setDefaultAction(m_selectAll);
324 m_selectText = new QAction(KIcon("kdenlive-select-texts"), QString(), this);
325 m_selectText->setShortcut(Qt::CTRL + Qt::Key_T);
326 connect(m_selectText, SIGNAL(triggered()), this, SLOT(slotSelectText()));
327 buttonSelectText->setDefaultAction(m_selectText);
328 buttonSelectText->setEnabled(false);
330 m_selectRects = new QAction(KIcon("kdenlive-select-rects"), QString(), this);
331 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
332 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
333 buttonSelectRects->setDefaultAction(m_selectRects);
334 buttonSelectRects->setEnabled(false);
336 m_selectImages = new QAction(KIcon("kdenlive-select-images"), QString(), this);
337 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
338 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
339 buttonSelectImages->setDefaultAction(m_selectImages);
340 buttonSelectImages->setEnabled(false);
342 m_unselectAll = new QAction(KIcon("kdenlive-unselect-all"), QString(), this);
343 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
344 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
345 buttonUnselectAll->setDefaultAction(m_unselectAll);
346 buttonUnselectAll->setEnabled(false);
348 zDown->setIconSize(iconSize);
349 zTop->setIconSize(iconSize);
350 zBottom->setIconSize(iconSize);
352 zDown->setIcon(KIcon("kdenlive-zindex-down"));
353 zTop->setIcon(KIcon("kdenlive-zindex-top"));
354 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
355 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
356 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
357 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
359 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
360 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
361 rectBColor->setToolTip(i18n("Select fill color"));
362 rectFColor->setToolTip(i18n("Select border color"));
363 zoom_slider->setToolTip(i18n("Zoom"));
364 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
365 buttonFitZoom->setToolTip(i18n("Fit zoom"));
366 backgroundColor->setToolTip(i18n("Select background color"));
367 backgroundAlpha->setToolTip(i18n("Background opacity"));
368 buttonSelectAll->setToolTip(getTooltipWithShortcut(i18n("Select all"), m_selectAll));
369 buttonSelectText->setToolTip(getTooltipWithShortcut(i18n("Select text items in current selection"), m_selectText));
370 buttonSelectRects->setToolTip(getTooltipWithShortcut(i18n("Select rect items in current selection"), m_selectRects));
371 buttonSelectImages->setToolTip(getTooltipWithShortcut(i18n("Select image items in current selection"), m_selectImages));
372 buttonUnselectAll->setToolTip(getTooltipWithShortcut(i18n("Unselect all"), m_unselectAll));
374 itemhcenter->setIconSize(iconSize);
375 itemvcenter->setIconSize(iconSize);
376 itemtop->setIconSize(iconSize);
377 itembottom->setIconSize(iconSize);
378 itemright->setIconSize(iconSize);
379 itemleft->setIconSize(iconSize);
381 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
382 itemhcenter->setToolTip(i18n("Align item horizontally"));
383 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
384 itemvcenter->setToolTip(i18n("Align item vertically"));
385 itemtop->setIcon(KIcon("kdenlive-align-top"));
386 itemtop->setToolTip(i18n("Align item to top"));
387 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
388 itembottom->setToolTip(i18n("Align item to bottom"));
389 itemright->setIcon(KIcon("kdenlive-align-right"));
390 itemright->setToolTip(i18n("Align item to right"));
391 itemleft->setIcon(KIcon("kdenlive-align-left"));
392 itemleft->setToolTip(i18n("Align item to left"));
395 QHBoxLayout *layout = new QHBoxLayout;
396 frame_toolbar->setLayout(layout);
397 layout->setContentsMargins(0, 0, 0, 0);
398 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
399 m_toolbar->setIconSize(iconSize);
401 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), i18n("Selection Tool"));
402 m_buttonCursor->setCheckable(true);
403 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
404 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
405 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
407 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), i18n("Add Text"));
408 m_buttonText->setCheckable(true);
409 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
410 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
411 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
413 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), i18n("Add Rectangle"));
414 m_buttonRect->setCheckable(true);
415 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
416 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
417 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
419 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image"));
420 m_buttonImage->setCheckable(false);
421 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
422 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
423 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
425 m_toolbar->addSeparator();
427 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
428 m_buttonLoad->setCheckable(false);
429 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
430 m_buttonLoad->setToolTip(i18n("Open Document") + ' ' + m_buttonImage->shortcut().toString());
431 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
433 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
434 m_buttonSave->setCheckable(false);
435 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
436 m_buttonSave->setToolTip(i18n("Save As") + ' ' + m_buttonImage->shortcut().toString());
437 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
439 layout->addWidget(m_toolbar);
441 // initialize graphic scene
442 m_scene = new GraphicsSceneRectMove(this);
443 graphicsView->setScene(m_scene);
444 graphicsView->setMouseTracking(true);
445 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
446 graphicsView->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);
447 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
448 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
449 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
451 // a gradient background
452 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
453 gradient->setSpread(QGradient::ReflectSpread);
454 scene->setBackgroundBrush(*gradient);*/
456 QPen framepen(Qt::DotLine);
457 framepen.setColor(Qt::red);
459 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
460 m_frameBorder->setPen(framepen);
461 m_frameBorder->setZValue(-1100);
462 m_frameBorder->setBrush(Qt::transparent);
463 m_frameBorder->setFlags(0);
464 graphicsView->scene()->addItem(m_frameBorder);
466 m_frameImage = new QGraphicsPixmapItem();
468 qtrans.scale(2.0, 2.0);
469 m_frameImage->setTransform(qtrans);
470 m_frameImage->setZValue(-1200);
471 m_frameImage->setFlags(0);
472 displayBackgroundFrame();
473 graphicsView->scene()->addItem(m_frameImage);
475 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
476 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
477 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
478 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
479 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
480 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
481 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
482 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
485 // mbd: load saved settings
488 graphicsView->show();
489 //graphicsView->setRenderHint(QPainter::Antialiasing);
490 graphicsView->setInteractive(true);
491 //graphicsView->resize(400, 300);
492 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
493 //toolBox->setItemEnabled(2, false);
494 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
495 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
496 m_startViewport->setData(0, m_frameWidth);
497 m_startViewport->setData(1, m_frameHeight);
498 m_endViewport->setData(0, m_frameWidth);
499 m_endViewport->setData(1, m_frameHeight);
501 // scale the view so that the title widget is not too big at startup
502 graphicsView->scale(.5, .5);
503 if (!url.isEmpty()) loadTitle(url);
506 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
509 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
510 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
511 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
513 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
514 refreshTitleTemplates();
515 //templateBox->setIconSize(QSize(60,60));
516 templateBox->clear();
517 templateBox->addItem("");
518 foreach(const TitleTemplate &t, titletemplates) {
519 templateBox->addItem(t.icon, t.name, t.file);
521 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
525 TitleWidget::~TitleWidget()
529 delete m_buttonImage;
530 delete m_buttonCursor;
533 delete m_unicodeAction;
540 delete m_selectRects;
541 delete m_selectImages;
542 delete m_unselectAll;
544 delete m_unicodeDialog;
545 delete m_frameBorder;
547 delete m_startViewport;
548 delete m_endViewport;
550 delete m_signalMapper;
553 QSize TitleWidget::sizeHint() const
555 // Make sure the widget has minimum size on opening
556 return QSize(200, 200);
560 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
563 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
564 KStandardDirs::makeDir(titlePath);
565 titlePath.append((isClone == false) ? "title" : "clone");
568 while (path.isEmpty() || QFile::exists(path)) {
570 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
572 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
578 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
581 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
582 KStandardDirs::makeDir(titlePath);
583 return titlePath + titleName + ".png";
587 QStringList TitleWidget::extractImageList(QString xml)
590 if (xml.isEmpty()) return result;
593 QDomNodeList images = doc.elementsByTagName("content");
594 for (int i = 0; i < images.count(); i++) {
595 if (images.at(i).toElement().hasAttribute("url"))
596 result.append(images.at(i).toElement().attribute("url"));
602 QStringList TitleWidget::extractFontList(QString xml)
605 if (xml.isEmpty()) return result;
608 QDomNodeList images = doc.elementsByTagName("content");
609 for (int i = 0; i < images.count(); i++) {
610 if (images.at(i).toElement().hasAttribute("font"))
611 result.append(images.at(i).toElement().attribute("font"));
616 void TitleWidget::refreshTitleTemplates()
618 QStringList titlenamelist = QStringList() << i18n("None");
619 QStringList titlefiles = QStringList() << QString();
621 filters << "*.kdenlivetitle" ;
622 titletemplates.clear();
623 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
624 foreach(const QString & folder, titleTemplates) {
625 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
626 foreach(const QString & fname, filesnames) {
627 //titlenamelist.append(fname);
628 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
631 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
632 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
633 titletemplates.append(t);
636 kDebug() << titlenamelist << titlefiles;
638 void TitleWidget::templateIndexChanged(int index)
640 QString item = templateBox->itemData(index).toString();
641 if (!item.isEmpty()) {
642 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
643 if (KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
647 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
648 // Text of unchanged template titles should be selected when clicked.
649 QList<QGraphicsItem *> list = graphicsView->scene()->items();
650 foreach(QGraphicsItem * qgItem, list) {
651 if (qgItem->type() == TEXTITEM) {
652 QGraphicsTextItem *i;
653 i = static_cast<QGraphicsTextItem *>(qgItem);
654 i->setProperty("isTemplate", "true");
655 i->setProperty("templateText", i->toHtml());
659 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
663 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
668 void TitleWidget::keyPressEvent(QKeyEvent *e){
669 if(e->key()!=Qt::Key_Escape && e->key()!=Qt::Key_Return && e->key()!=Qt::Key_Enter) QDialog::keyPressEvent(e);
671 void TitleWidget::slotTextTool()
673 m_scene->setTool(TITLE_TEXT);
674 showToolbars(TITLE_TEXT);
675 checkButton(TITLE_TEXT);
678 void TitleWidget::slotRectTool()
680 m_scene->setTool(TITLE_RECTANGLE);
681 showToolbars(TITLE_RECTANGLE);
682 checkButton(TITLE_RECTANGLE);
684 // Disable dragging mode, would make dragging a rect impossible otherwise ;)
685 graphicsView->setDragMode(QGraphicsView::NoDrag);
688 void TitleWidget::slotSelectTool()
690 m_scene->setTool(TITLE_SELECT);
692 // Enable rubberband selecting mode.
693 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
695 // Find out which toolbars need to be shown, depending on selected item
696 TITLETOOL t = TITLE_SELECT;
697 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
699 switch (l.at(0)->type()) {
713 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
714 //graphicsView->centerOn(l.at(0));
720 updateCoordinates(l.at(0));
721 updateDimension(l.at(0));
722 updateRotZoom(l.at(0));
725 checkButton(TITLE_SELECT);
728 void TitleWidget::slotImageTool()
730 // TODO: find a way to get a list of all supported image types...
731 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";
732 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
733 if (!url.isEmpty()) {
734 if (url.path().endsWith(".svg")) {
735 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
736 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
737 svg->setZValue(m_count++);
738 svg->setData(Qt::UserRole, url.path());
739 graphicsView->scene()->addItem(svg);
741 QPixmap pix(url.path());
742 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
743 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
744 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
745 image->setData(Qt::UserRole, url.path());
746 image->setZValue(m_count++);
747 graphicsView->scene()->addItem(image);
750 m_scene->setTool(TITLE_SELECT);
751 showToolbars(TITLE_SELECT);
752 checkButton(TITLE_SELECT);
755 void TitleWidget::showToolbars(TITLETOOL toolType)
759 toolbar_stack->setCurrentIndex(0);
762 toolbar_stack->setCurrentIndex(3);
764 case TITLE_RECTANGLE:
765 toolbar_stack->setCurrentIndex(1);
768 toolbar_stack->setCurrentIndex(2);
773 void TitleWidget::enableToolbars(TITLETOOL toolType)
775 // TITLETOOL is defined in graphicsscenerectmove.h
777 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
778 value_w->setEnabled(enable);
779 value_h->setEnabled(enable);
782 void TitleWidget::checkButton(TITLETOOL toolType)
784 bool bSelect = false;
796 case TITLE_RECTANGLE:
806 m_buttonCursor->setChecked(bSelect);
807 m_buttonText->setChecked(bText);
808 m_buttonRect->setChecked(bRect);
809 m_buttonImage->setChecked(bImage);
812 void TitleWidget::displayBackgroundFrame()
814 QRectF r = m_frameBorder->sceneBoundingRect();
815 if (!displayBg->isChecked()) {
816 QPixmap pattern(20, 20);
818 QColor bgcolor(210, 210, 210);
819 QPainter p(&pattern);
820 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
821 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
824 QPixmap bg((int) (r.width() / 2), (int) (r.height()/ 2));
826 p2.fillRect(bg.rect(), br);
828 m_frameImage->setPixmap(bg);
830 QImage img = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), QString(), m_render->frameRenderWidth() / 2, m_render->renderHeight() / 2);
831 m_frameImage->setPixmap(QPixmap::fromImage(img.scaled(r.width() / 2, r.height() / 2)));
835 void TitleWidget::initAnimation()
837 align_box->setEnabled(false);
838 QPen startpen(Qt::DotLine);
839 QPen endpen(Qt::DashDotLine);
840 startpen.setColor(QColor(100, 200, 100, 140));
841 endpen.setColor(QColor(200, 100, 100, 140));
843 m_startViewport->setPen(startpen);
844 m_endViewport->setPen(endpen);
846 m_startViewport->setZValue(-1000);
847 m_endViewport->setZValue(-1000);
849 m_startViewport->setFlags(0);
850 m_endViewport->setFlags(0);
852 graphicsView->scene()->addItem(m_startViewport);
853 graphicsView->scene()->addItem(m_endViewport);
855 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
856 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
857 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
858 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
861 void TitleWidget::slotUpdateZoom(int pos)
863 m_scene->setZoom((double) pos / 100);
864 zoom_label->setText(QString::number(pos) + '%');
867 void TitleWidget::slotZoom(bool up)
869 int pos = zoom_slider->value();
872 zoom_slider->setValue(pos);
875 void TitleWidget::slotAdjustZoom()
877 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
878 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
879 if (scalex > scaley) scalex = scaley;
880 int zoompos = (int)(scalex * 7 + 0.5);*/
881 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
882 int zoompos = graphicsView->matrix().m11() * 100;
883 zoom_slider->setValue(zoompos);
884 graphicsView->centerOn(m_frameBorder);
887 void TitleWidget::slotZoomOneToOne()
889 zoom_slider->setValue(100);
890 graphicsView->centerOn(m_frameBorder);
893 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
895 updateAxisButtons(rect); // back to default
897 QColor f = rectFColor->color();
898 #if not KDE_IS_VERSION(4,5,0)
899 f.setAlpha(rectFAlpha->value());
902 penf.setWidth(rectLineWidth->value());
903 penf.setJoinStyle(Qt::RoundJoin);
905 QColor b = rectBColor->color();
906 #if not KDE_IS_VERSION(4,5,0)
907 b.setAlpha(rectBAlpha->value());
909 rect->setBrush(QBrush(b));
910 rect->setZValue(m_count++);
911 rect->setData(ZOOMFACTOR, 100);
912 //setCurrentItem(rect);
913 //graphicsView->setFocus();
916 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
918 updateAxisButtons(tt); // back to default
920 QFont font = font_family->currentFont();
921 font.setPixelSize(font_size->value());
923 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
924 font.setItalic(buttonItalic->isChecked());
925 font.setUnderline(buttonUnder->isChecked());
928 QColor color = fontColorButton->color();
929 QColor outlineColor = textOutlineColor->color();
930 #if not KDE_IS_VERSION(4,5,0)
931 color.setAlpha(textAlpha->value());
932 outlineColor.setAlpha(textOutlineAlpha->value());
934 tt->setDefaultTextColor(color);
936 QTextCursor cur(tt->document());
937 cur.select(QTextCursor::Document);
938 QTextBlockFormat format = cur.blockFormat();
939 QTextCharFormat cformat = cur.charFormat();
940 double outlineWidth = textOutline->value() / 10.0;
942 tt->setData(101, outlineWidth);
943 tt->setData(102, outlineColor);
944 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
946 cformat.setForeground(QBrush(color));
947 cur.setCharFormat(cformat);
948 cur.setBlockFormat(format);
949 tt->setTextCursor(cur);
950 tt->setZValue(m_count++);
954 void TitleWidget::setFontBoxWeight(int weight)
956 int index = font_weight_box->findData(weight);
958 index = font_weight_box->findData(QFont::Normal);
960 font_weight_box->setCurrentIndex(index);
963 void TitleWidget::setCurrentItem(QGraphicsItem *item)
965 m_scene->setSelectedItem(item);
968 void TitleWidget::zIndexChanged(int v)
970 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
971 for (int i = 0; i < l.size(); i++) {
976 void TitleWidget::selectionChanged()
978 if (m_scene->tool() != TITLE_SELECT) return;
980 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
982 QList<QGraphicsItem *> l;
984 // mbt 1607: One text item might have grabbed the keyboard.
985 // Ungrab it for all items that are not selected, otherwise
986 // text input would only work for the text item that grabbed
987 // the keyboard last.
988 l = graphicsView->scene()->items();
989 foreach(QGraphicsItem * item, l) {
990 if (item->type() == TEXTITEM && !item->isSelected()) {
991 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
996 l = graphicsView->scene()->selectedItems();
999 buttonUnselectAll->setEnabled(true);
1000 // Enable all z index buttons if items selected.
1001 // We can selectively disable them later.
1002 zUp->setEnabled(true);
1003 zDown->setEnabled(true);
1004 zTop->setEnabled(true);
1005 zBottom->setEnabled(true);
1007 buttonUnselectAll->setEnabled(false);
1009 if (l.size() >= 2) {
1010 buttonSelectText->setEnabled(true);
1011 buttonSelectRects->setEnabled(true);
1012 buttonSelectImages->setEnabled(true);
1014 buttonSelectText->setEnabled(false);
1015 buttonSelectRects->setEnabled(false);
1016 buttonSelectImages->setEnabled(false);
1019 if (l.size() == 0) {
1021 } else if (l.size() == 1) {
1022 prepareTools(l.at(0));
1025 For multiple selected objects we need to decide which tools to show.
1027 int firstType = l.at(0)->type();
1028 bool allEqual = true;
1029 for (int i = 0; i < l.size(); i++) {
1030 if (l.at(i)->type() != firstType) {
1035 std::cout << "All equal? " << allEqual << ".\n";
1037 prepareTools(l.at(0));
1039 // Get the default toolset, but enable the property frame (x,y,w,h)
1041 frame_properties->setEnabled(true);
1043 // Enable x/y/w/h if it makes sense.
1044 value_x->setEnabled(true);
1045 value_y->setEnabled(true);
1046 bool containsTextitem = false;
1047 for (int i = 0; i < l.size(); i++) {
1048 if (l.at(i)->type() == TEXTITEM) {
1049 containsTextitem = true;
1053 if (!containsTextitem) {
1054 value_w->setEnabled(true);
1055 value_h->setEnabled(true);
1059 // Disable z index buttons if they don't make sense for the current selection
1060 int firstZindex = l.at(0)->zValue();
1062 for (int i = 0; i < l.size(); i++) {
1063 if (l[i]->zValue() != firstZindex) {
1069 zUp->setEnabled(false);
1070 zDown->setEnabled(false);
1078 void TitleWidget::slotValueChanged(int type)
1081 type tells us which QSpinBox value has changed.
1084 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1085 std::cout << l.size() << " items to be resized\n";
1087 // Get the updated value here already to do less coding afterwards
1091 val = value_w->value();
1094 val = value_h->value();
1097 val = value_x->value();
1100 val = value_y->value();
1104 for (int k = 0; k < l.size(); k++) {
1105 std::cout << "Type of item " << k << ": " << l.at(k)->type() << "\n";
1107 if (l.at(k)->type() == TEXTITEM) {
1108 // Just update the position. We don't allow setting width/height for text items yet.
1111 updatePosition(l.at(k), val, l.at(k)->pos().y());
1114 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1118 } else if (l.at(k)->type() == RECTITEM) {
1119 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(k));
1122 updatePosition(l.at(k), val, l.at(k)->pos().y());
1125 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1128 rec->setRect(QRect(0, 0, val, rec->rect().height()));
1131 rec->setRect(QRect(0, 0, rec->rect().width(), val));
1135 } else if (l.at(k)->type() == IMAGEITEM) {
1138 if (type == ValueX) {
1139 updatePosition(l.at(k), val, l.at(k)->pos().y());
1141 } else if (type == ValueY) {
1142 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1145 // Width/height has changed. This is more complex.
1147 QGraphicsItem *i = l.at(k);
1148 Transform t = m_transformations.value(i);
1150 // Ratio width:height
1151 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1152 // TODO: proper calculation for rotation around 3 axes
1153 double alpha = (double) t.rotatez / 180.0 * M_PI;
1156 double length = val;
1161 // We want to keep the aspect ratio of the image as the user does not yet have the possibility
1162 // to restore the original ratio. You rarely want to change it anyway.
1165 // Add 0.5 because otherwise incrementing by 1 might have no effect
1166 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1167 scale = length / i->boundingRect().width();
1170 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1171 scale = length / i->boundingRect().height();
1178 qtrans.scale(scale, scale);
1179 qtrans.rotate(t.rotatex, Qt::XAxis);
1180 qtrans.rotate(t.rotatey, Qt::YAxis);
1181 qtrans.rotate(t.rotatez, Qt::ZAxis);
1182 i->setTransform(qtrans);
1183 std::cout << "scale is: " << scale << "\n";
1184 std::cout << i->boundingRect().width() << ": new width\n";
1185 m_transformations[i] = t;
1187 if (l.size() == 1) {
1188 // Only update the w/h values if the selection contains just one item.
1189 // Otherwise, what should we do? ;)
1190 // (Use the values of the first item? Of the second? Of the x-th?)
1192 // Update rotation/zoom values.
1193 // These values are not yet able to handle multiple items!
1204 void TitleWidget::updateDimension(QGraphicsItem *i)
1206 bool wBlocked = value_w->signalsBlocked();
1207 bool hBlocked = value_h->signalsBlocked();
1208 bool zBlocked = zValue->signalsBlocked();
1209 value_w->blockSignals(true);
1210 value_h->blockSignals(true);
1211 zValue->blockSignals(true);
1213 zValue->setValue((int) i->zValue());
1214 if (i->type() == IMAGEITEM) {
1215 // Get multipliers for rotation/scaling
1217 /*Transform t = m_transformations.value(i);
1218 QRectF r = i->boundingRect();
1219 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1220 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1221 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1222 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1224 value_w->setValue(i->sceneBoundingRect().width());
1225 value_h->setValue(i->sceneBoundingRect().height());
1226 } else if (i->type() == RECTITEM) {
1227 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1228 std::cout << "Rect width is: " << r->rect().width() << ", was: " << value_w->value() << "\n";
1229 value_w->setValue((int) r->rect().width());
1230 value_h->setValue((int) r->rect().height());
1231 } else if (i->type() == TEXTITEM) {
1232 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1233 value_w->setValue((int) t->boundingRect().width());
1234 value_h->setValue((int) t->boundingRect().height());
1237 zValue->blockSignals(zBlocked);
1238 value_w->blockSignals(wBlocked);
1239 value_h->blockSignals(hBlocked);
1242 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1244 // Block signals emitted by this method
1245 value_x->blockSignals(true);
1246 value_y->blockSignals(true);
1248 if (i->type() == TEXTITEM) {
1250 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1252 // Set the correct x coordinate value
1253 if (origin_x_left->isChecked()) {
1254 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1255 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1257 // Origin is at 0 (default)
1258 value_x->setValue((int) rec->pos().x());
1262 if (origin_y_top->isChecked()) {
1263 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1265 value_y->setValue((int) rec->pos().y());
1268 } else if (i->type() == RECTITEM) {
1270 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1272 if (origin_x_left->isChecked()) {
1273 // Origin (0 point) is at m_frameWidth
1274 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1276 // Origin is at 0 (default)
1277 value_x->setValue((int) rec->pos().x());
1280 if (origin_y_top->isChecked()) {
1281 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1283 value_y->setValue((int) rec->pos().y());
1286 } else if (i->type() == IMAGEITEM) {
1288 if (origin_x_left->isChecked()) {
1289 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1291 value_x->setValue((int) i->pos().x());
1294 if (origin_y_top->isChecked()) {
1295 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1297 value_y->setValue((int) i->pos().y());
1302 // Stop blocking signals now
1303 value_x->blockSignals(false);
1304 value_y->blockSignals(false);
1307 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1309 itemzoom->blockSignals(true);
1310 itemrotatex->blockSignals(true);
1311 itemrotatey->blockSignals(true);
1312 itemrotatez->blockSignals(true);
1314 Transform t = m_transformations.value(i);
1316 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1317 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1319 itemrotatex->setValue((int)(t.rotatex));
1320 itemrotatey->setValue((int)(t.rotatey));
1321 itemrotatez->setValue((int)(t.rotatez));
1323 itemzoom->blockSignals(false);
1324 itemrotatex->blockSignals(false);
1325 itemrotatey->blockSignals(false);
1326 itemrotatez->blockSignals(false);
1329 void TitleWidget::updatePosition(QGraphicsItem *i)
1331 updatePosition(i, value_x->value(), value_y->value());
1334 void TitleWidget::updatePosition(QGraphicsItem *i, int x, int y)
1336 if (i->type() == TEXTITEM) {
1337 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1340 if (origin_x_left->isChecked()) {
1342 * Origin of the X axis is at m_frameWidth, and distance from right
1343 * border of the item to the right border of the frame is taken. See
1344 * comment to slotOriginXClicked().
1346 posX = m_frameWidth - x - rec->boundingRect().width();
1352 if (origin_y_top->isChecked()) {
1353 /* Same for y axis */
1354 posY = m_frameHeight - y - rec->boundingRect().height();
1359 rec->setPos(posX, posY);
1361 } else if (i->type() == RECTITEM) {
1363 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1366 if (origin_x_left->isChecked()) {
1367 posX = m_frameWidth - x - rec->rect().width();
1373 if (origin_y_top->isChecked()) {
1374 posY = m_frameHeight - y - rec->rect().height();
1379 rec->setPos(posX, posY);
1381 } else if (i->type() == IMAGEITEM) {
1383 if (origin_x_left->isChecked()) {
1384 // Use the sceneBoundingRect because this also regards transformations like zoom
1385 posX = m_frameWidth - x - i->sceneBoundingRect().width();
1391 if (origin_y_top->isChecked()) {
1392 posY = m_frameHeight - y - i->sceneBoundingRect().height();
1397 i->setPos(posX, posY);
1403 void TitleWidget::updateTextOriginX()
1405 if (origin_x_left->isChecked()) {
1406 origin_x_left->setText(i18n("\u2212X"));
1408 origin_x_left->setText(i18n("+X"));
1412 void TitleWidget::slotOriginXClicked()
1414 // Update the text displayed on the button.
1415 updateTextOriginX();
1417 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1418 if (l.size() >= 1) {
1419 updateCoordinates(l.at(0));
1421 // Remember x axis setting
1422 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1423 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1425 graphicsView->setFocus();
1428 void TitleWidget::updateTextOriginY()
1430 if (origin_y_top->isChecked()) {
1431 origin_y_top->setText(i18n("\u2212Y"));
1433 origin_y_top->setText(i18n("+Y"));
1437 void TitleWidget::slotOriginYClicked()
1439 // Update the text displayed on the button.
1440 updateTextOriginY();
1442 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1443 if (l.size() >= 1) {
1444 updateCoordinates(l.at(0));
1446 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1447 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1450 graphicsView->setFocus();
1453 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1455 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1456 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1457 origin_x_left->blockSignals(true);
1458 origin_y_top->blockSignals(true);
1460 if (xAxis == TitleDocument::AxisInverted) {
1461 origin_x_left->setChecked(true);
1463 origin_x_left->setChecked(false);
1465 updateTextOriginX();
1467 if (yAxis == TitleDocument::AxisInverted) {
1468 origin_y_top->setChecked(true);
1470 origin_y_top->setChecked(false);
1472 updateTextOriginY();
1474 origin_x_left->blockSignals(false);
1475 origin_y_top->blockSignals(false);
1478 void TitleWidget::slotChangeBackground()
1480 QColor color = backgroundColor->color();
1481 m_scene->setBackgroundBrush(QBrush(color));
1482 color.setAlpha(backgroundAlpha->value());
1483 m_frameBorder->setBrush(QBrush(color));
1486 void TitleWidget::slotChanged()
1488 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1489 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1490 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1494 void TitleWidget::textChanged(QGraphicsTextItem *i)
1497 * If the user has set origin_x_left (the same for y), we need to look
1498 * whether a text element has been selected. If yes, we need to ensure that
1499 * the right border of the text field remains fixed also when some text has
1502 * This is also known as right-justified, with the difference that it is not
1503 * valid for text but for its boundingRect. Text may still be
1508 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1509 if (!i->toPlainText().isEmpty())
1513 * Don't do anything if the string is empty. If the position were
1514 * updated here, a newly created text field would be set to the
1515 * position of the last selected text field.
1520 // mbt 1607: Template text has changed; don't auto-select content anymore.
1521 if (i->property("isTemplate").isValid()) {
1522 if (i->property("templateText").isValid()) {
1523 if (i->property("templateText") == i->toHtml()) {
1524 // Unchanged, do nothing.
1526 i->setProperty("isTemplate", QVariant::Invalid);
1527 i->setProperty("templateText", QVariant::Invalid);
1533 void TitleWidget::slotInsertUnicode()
1535 m_unicodeDialog->exec();
1538 void TitleWidget::slotInsertUnicodeString(QString text)
1540 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1542 if (l.at(0)->type() == TEXTITEM) {
1543 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1544 t->textCursor().insertText(text);
1549 void TitleWidget::slotUpdateText()
1551 QFont font = font_family->currentFont();
1552 font.setPixelSize(font_size->value());
1553 font.setItalic(buttonItalic->isChecked());
1554 font.setUnderline(buttonUnder->isChecked());
1555 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1556 QColor color = fontColorButton->color();
1557 QColor outlineColor = textOutlineColor->color();
1558 #if not KDE_IS_VERSION(4,5,0)
1559 color.setAlpha(textAlpha->value());
1560 outlineColor.setAlpha(textOutlineAlpha->value());
1563 double outlineWidth = textOutline->value() / 10.0;
1566 for (i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1567 QGraphicsTextItem* item = NULL;
1568 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1569 if (l.at(i)->type() == TEXTITEM) {
1570 item = static_cast <QGraphicsTextItem *>(l.at(i));
1573 // No text item, try next one.
1577 // Set alignment of all text in the text item
1578 QTextCursor cur(item->document());
1579 cur.select(QTextCursor::Document);
1580 QTextBlockFormat format = cur.blockFormat();
1581 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1582 item->setTextWidth(item->boundingRect().width());
1583 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1584 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1585 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1587 format.setAlignment(Qt::AlignLeft);
1588 item->setTextWidth(-1);
1591 // Set font properties
1592 item->setFont(font);
1593 QTextCharFormat cformat = cur.charFormat();
1595 item->setData(101, outlineWidth);
1596 item->setData(102, outlineColor);
1597 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1599 cformat.setForeground(QBrush(color));
1600 cur.setCharFormat(cformat);
1601 cur.setBlockFormat(format);
1602 // item->setTextCursor(cur);
1603 cur.clearSelection();
1604 item->setTextCursor(cur);
1605 item->setDefaultTextColor(color);
1609 void TitleWidget::rectChanged()
1611 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1613 for (i = 0; i < l.length(); i++) {
1614 if (l.at(i)->type() == RECTITEM && !settingUp) {
1615 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1616 QColor f = rectFColor->color();
1617 #if not KDE_IS_VERSION(4,5,0)
1618 f.setAlpha(rectFAlpha->value());
1621 penf.setWidth(rectLineWidth->value());
1622 penf.setJoinStyle(Qt::RoundJoin);
1624 QColor b = rectBColor->color();
1625 #if not KDE_IS_VERSION(4,5,0)
1626 b.setAlpha(rectBAlpha->value());
1628 rec->setBrush(QBrush(b));
1633 void TitleWidget::itemScaled(int val)
1635 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1636 if (l.size() == 1) {
1637 Transform x = m_transformations.value(l.at(0));
1638 x.scalex = (double)val / 100.0;
1639 x.scaley = (double)val / 100.0;
1641 qtrans.scale(x.scalex, x.scaley);
1642 qtrans.rotate(x.rotatex, Qt::XAxis);
1643 qtrans.rotate(x.rotatey, Qt::YAxis);
1644 qtrans.rotate(x.rotatez, Qt::ZAxis);
1645 l[0]->setTransform(qtrans);
1646 l[0]->setData(ZOOMFACTOR, val);
1647 m_transformations[l.at(0)] = x;
1648 updateDimension(l.at(0));
1652 void TitleWidget::itemRotateX(qreal val)
1657 void TitleWidget::itemRotateY(qreal val)
1662 void TitleWidget::itemRotateZ(qreal val)
1667 void TitleWidget::itemRotate(qreal val, int axis)
1669 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1670 if (l.size() == 1) {
1671 Transform x = m_transformations[l.at(0)];
1684 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1687 qtrans.scale(x.scalex, x.scaley);
1688 qtrans.rotate(x.rotatex, Qt::XAxis);
1689 qtrans.rotate(x.rotatey, Qt::YAxis);
1690 qtrans.rotate(x.rotatez, Qt::ZAxis);
1691 l[0]->setTransform(qtrans);
1692 m_transformations[l.at(0)] = x;
1693 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1694 updateDimension(l.at(0));
1698 void TitleWidget::itemHCenter()
1700 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1701 if (l.size() == 1) {
1702 QGraphicsItem *item = l.at(0);
1703 QRectF br = item->sceneBoundingRect();
1704 int width = (int)br.width();
1705 int newPos = (int)((m_frameWidth - width) / 2);
1706 newPos += item->pos().x() - br.left(); // Check item transformation
1707 item->setPos(newPos, item->pos().y());
1708 updateCoordinates(item);
1712 void TitleWidget::itemVCenter()
1714 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1715 if (l.size() == 1) {
1716 QGraphicsItem *item = l.at(0);
1717 QRectF br = item->sceneBoundingRect();
1718 int height = (int)br.height();
1719 int newPos = (int)((m_frameHeight - height) / 2);
1720 newPos += item->pos().y() - br.top(); // Check item transformation
1721 item->setPos(item->pos().x(), newPos);
1722 updateCoordinates(item);
1726 void TitleWidget::itemTop()
1728 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1729 if (l.size() == 1) {
1730 QGraphicsItem *item = l.at(0);
1731 QRectF br = item->sceneBoundingRect();
1733 if (br.top() > 0) diff = -br.top();
1734 else diff = -br.bottom();
1735 item->moveBy(0, diff);
1736 updateCoordinates(item);
1740 void TitleWidget::itemBottom()
1742 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1743 if (l.size() == 1) {
1744 QGraphicsItem *item = l.at(0);
1745 QRectF br = item->sceneBoundingRect();
1747 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1748 else diff = m_frameHeight - br.bottom();
1749 item->moveBy(0, diff);
1750 updateCoordinates(item);
1754 void TitleWidget::itemLeft()
1756 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1757 if (l.size() == 1) {
1758 QGraphicsItem *item = l.at(0);
1759 QRectF br = item->sceneBoundingRect();
1761 if (br.left() > 0) diff = -br.left();
1762 else diff = -br.right();
1763 item->moveBy(diff, 0);
1764 updateCoordinates(item);
1768 void TitleWidget::itemRight()
1770 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1771 if (l.size() == 1) {
1772 QGraphicsItem *item = l.at(0);
1773 QRectF br = item->sceneBoundingRect();
1775 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1776 else diff = m_frameWidth - br.left();
1777 item->moveBy(diff, 0);
1778 updateCoordinates(item);
1782 void TitleWidget::setupViewports()
1784 //double aspect_ratio = 4.0 / 3.0;//read from project
1785 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1786 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1787 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1788 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1789 QPolygonF spoly(sp);
1790 QPolygonF epoly(ep);
1791 spoly.translate(startViewportX->value(), startViewportY->value());
1792 epoly.translate(endViewportX->value(), endViewportY->value());
1793 m_startViewport->setPolygon(spoly);
1794 m_endViewport->setPolygon(epoly);
1795 if (! insertingValues) {
1796 m_startViewport->setData(0, startViewportX->value());
1797 m_startViewport->setData(1, startViewportY->value());
1798 m_startViewport->setData(2, startViewportSize->value());
1800 m_endViewport->setData(0, endViewportX->value());
1801 m_endViewport->setData(1, endViewportY->value());
1802 m_endViewport->setData(2, endViewportSize->value());
1806 void TitleWidget::loadTitle(KUrl url)
1808 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1809 if (!url.isEmpty()) {
1810 QList<QGraphicsItem *> items = m_scene->items();
1811 for (int i = 0; i < items.size(); i++) {
1812 if (items.at(i)->zValue() > -1000) delete items.at(i);
1814 m_scene->clearTextSelection();
1818 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1819 QFile file(tmpfile);
1820 if (file.open(QIODevice::ReadOnly)) {
1821 doc.setContent(&file, false);
1824 KIO::NetAccess::removeTempFile(tmpfile);
1829 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1831 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1832 insertingValues = true;
1833 startViewportX->setValue(m_startViewport->data(0).toInt());
1834 startViewportY->setValue(m_startViewport->data(1).toInt());
1835 startViewportSize->setValue(m_startViewport->data(2).toInt());
1836 endViewportX->setValue(m_endViewport->data(0).toInt());
1837 endViewportY->setValue(m_endViewport->data(1).toInt());
1838 endViewportSize->setValue(m_endViewport->data(2).toInt());
1840 insertingValues = false;
1846 void TitleWidget::saveTitle(KUrl url)
1848 if (anim_start->isChecked()) slotAnimStart(false);
1849 if (anim_end->isChecked()) slotAnimEnd(false);
1850 bool embed_image=false;
1851 if (KMessageBox::questionYesNo(this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::No)
1855 if (url.isEmpty()) {
1856 QPointer<KFileDialog> fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1857 fs->setOperationMode(KFileDialog::Saving);
1858 fs->setMode(KFile::File);
1859 fs->setConfirmOverwrite(true);
1860 fs->setKeepLocation(true);
1862 if (fs) url = fs->selectedUrl();
1865 if (!url.isEmpty()) {
1866 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
1867 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1871 QDomDocument TitleWidget::xml()
1873 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1874 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1878 int TitleWidget::outPoint() const
1880 return m_tc.getFrameCount(title_duration->text());
1883 void TitleWidget::setXml(QDomDocument doc)
1886 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out, m_projectTitlePath);
1888 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1889 /*if (doc.documentElement().hasAttribute("out")) {
1890 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1891 title_duration->setText(m_tc.getTimecode(duration));
1893 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1895 QDomElement e = doc.documentElement();
1896 m_transformations.clear();
1897 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1898 const double PI = 4.0 * atan(1.0);
1899 for (int i = 0; i < items.count(); i++) {
1900 QTransform t = items.at(i)->transform();
1904 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1905 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1906 if (rotlist.count() >= 3) {
1907 x.rotatex = rotlist[0].toDouble();
1908 x.rotatey = rotlist[1].toDouble();
1909 x.rotatez = rotlist[2].toDouble();
1911 // Try to adjust zoom
1912 t.rotate(x.rotatex *(-1), Qt::XAxis);
1913 t.rotate(x.rotatey *(-1), Qt::YAxis);
1914 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1925 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1927 m_transformations[items.at(i)] = x;
1929 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1930 QColor background_color = m_titledocument.getBackgroundColor();
1931 backgroundAlpha->blockSignals(true);
1932 backgroundColor->blockSignals(true);
1933 backgroundAlpha->setValue(background_color.alpha());
1934 background_color.setAlpha(255);
1935 backgroundColor->setColor(background_color);
1936 backgroundAlpha->blockSignals(false);
1937 backgroundColor->blockSignals(false);
1939 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1940 startViewportY->setValue(m_startViewport->data(1).toInt());
1941 startViewportSize->setValue(m_startViewport->data(2).toInt());
1942 endViewportX->setValue(m_endViewport->data(0).toInt());
1943 endViewportY->setValue(m_endViewport->data(1).toInt());
1944 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1946 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1951 void TitleWidget::slotAccepted()
1953 if (anim_start->isChecked()) slotAnimStart(false);
1954 if (anim_end->isChecked()) slotAnimEnd(false);
1958 void TitleWidget::writeChoices()
1960 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1961 KSharedConfigPtr config = KGlobal::config();
1962 KConfigGroup titleConfig(config, "TitleWidget");
1963 // Write the entries
1964 titleConfig.writeEntry("font_family", font_family->currentFont());
1965 //titleConfig.writeEntry("font_size", font_size->value());
1966 titleConfig.writeEntry("font_pixel_size", font_size->value());
1967 titleConfig.writeEntry("font_color", fontColorButton->color());
1968 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1969 #if KDE_IS_VERSION(4,5,0)
1970 titleConfig.writeEntry("font_alpha", fontColorButton->color().alpha());
1971 titleConfig.writeEntry("font_outline_alpha", textOutlineColor->color().alpha());
1973 titleConfig.writeEntry("font_alpha", textAlpha->value());
1974 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1977 titleConfig.writeEntry("font_outline", textOutline->value());
1978 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1979 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1980 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1982 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1983 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1985 #if KDE_IS_VERSION(4,5,0)
1986 titleConfig.writeEntry("rect_background_alpha", rectBColor->color().alpha());
1987 titleConfig.writeEntry("rect_foreground_alpha", rectFColor->color().alpha());
1989 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1990 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1993 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1995 titleConfig.writeEntry("background_color", backgroundColor->color());
1996 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1998 //! \todo Not sure if I should sync - it is probably safe to do it
2003 void TitleWidget::readChoices()
2005 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
2006 KSharedConfigPtr config = KGlobal::config();
2007 KConfigGroup titleConfig(config, "TitleWidget");
2009 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
2010 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
2011 m_scene->slotUpdateFontSize(font_size->value());
2012 QColor fontColor = QColor(titleConfig.readEntry("font_color", fontColorButton->color()));
2013 QColor outlineColor = QColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
2014 #if KDE_IS_VERSION(4,5,0)
2015 fontColor.setAlpha(titleConfig.readEntry("font_alpha", fontColor.alpha()));
2016 outlineColor.setAlpha(titleConfig.readEntry("font_outline_alpha", outlineColor.alpha()));
2018 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
2019 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
2021 fontColorButton->setColor(fontColor);
2022 textOutlineColor->setColor(outlineColor);
2023 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
2026 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
2027 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
2028 setFontBoxWeight(weight);
2029 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
2030 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
2032 QColor fgColor = QColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
2033 QColor bgColor = QColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
2035 #if KDE_IS_VERSION(4,5,0)
2036 fgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", fgColor.alpha()));
2037 bgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", bgColor.alpha()));
2039 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
2040 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
2042 rectFColor->setColor(fgColor);
2043 rectBColor->setColor(bgColor);
2045 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
2047 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
2048 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
2051 void TitleWidget::adjustFrameSize()
2053 m_frameWidth = m_titledocument.frameWidth();
2054 m_frameHeight = m_titledocument.frameHeight();
2055 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
2056 displayBackgroundFrame();
2059 void TitleWidget::slotAnimStart(bool anim)
2061 if (anim && anim_end->isChecked()) {
2062 anim_end->setChecked(false);
2063 m_endViewport->setZValue(-1000);
2064 m_endViewport->setBrush(QBrush());
2067 QList<QGraphicsItem *> list = m_scene->items();
2068 for (int i = 0; i < list.count(); i++) {
2069 if (list.at(i)->zValue() > -1000) {
2070 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2071 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2074 align_box->setEnabled(anim);
2075 itemzoom->setEnabled(!anim);
2076 itemrotatex->setEnabled(!anim);
2077 itemrotatey->setEnabled(!anim);
2078 itemrotatez->setEnabled(!anim);
2079 frame_toolbar->setEnabled(!anim);
2080 toolbar_stack->setEnabled(!anim);
2082 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
2083 m_startViewport->setZValue(1100);
2084 QColor col = m_startViewport->pen().color();
2086 m_startViewport->setBrush(col);
2087 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2088 m_startViewport->setSelected(true);
2091 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
2093 m_startViewport->setZValue(-1000);
2094 m_startViewport->setBrush(QBrush());
2095 m_startViewport->setFlags(0);
2096 if (!anim_end->isChecked()) deleteAnimInfoText();
2101 void TitleWidget::slotAnimEnd(bool anim)
2103 if (anim && anim_start->isChecked()) {
2104 anim_start->setChecked(false);
2105 m_startViewport->setZValue(-1000);
2106 m_startViewport->setBrush(QBrush());
2109 QList<QGraphicsItem *> list = m_scene->items();
2110 for (int i = 0; i < list.count(); i++) {
2111 if (list.at(i)->zValue() > -1000) {
2112 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2113 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2116 align_box->setEnabled(anim);
2117 itemzoom->setEnabled(!anim);
2118 itemrotatex->setEnabled(!anim);
2119 itemrotatey->setEnabled(!anim);
2120 itemrotatez->setEnabled(!anim);
2121 frame_toolbar->setEnabled(!anim);
2122 toolbar_stack->setEnabled(!anim);
2124 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2125 m_endViewport->setZValue(1100);
2126 QColor col = m_endViewport->pen().color();
2128 m_endViewport->setBrush(col);
2129 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2130 m_endViewport->setSelected(true);
2133 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2135 m_endViewport->setZValue(-1000);
2136 m_endViewport->setBrush(QBrush());
2137 m_endViewport->setFlags(0);
2138 if (!anim_start->isChecked()) deleteAnimInfoText();
2142 void TitleWidget::addAnimInfoText()
2144 // add text to anim viewport
2145 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2146 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2147 QFont font = t->font();
2148 font.setPixelSize(m_startViewport->rect().width() / 10);
2149 QColor col = m_startViewport->pen().color();
2151 t->setDefaultTextColor(col);
2153 font.setPixelSize(m_endViewport->rect().width() / 10);
2154 col = m_endViewport->pen().color();
2156 t2->setDefaultTextColor(col);
2160 void TitleWidget::updateInfoText()
2162 // update info text font
2163 if (!m_startViewport->childItems().isEmpty()) {
2164 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2166 QFont font = item->font();
2167 font.setPixelSize(m_startViewport->rect().width() / 10);
2168 item->setFont(font);
2171 if (!m_endViewport->childItems().isEmpty()) {
2172 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2174 QFont font = item->font();
2175 font.setPixelSize(m_endViewport->rect().width() / 10);
2176 item->setFont(font);
2181 void TitleWidget::deleteAnimInfoText()
2183 // end animation editing, remove info text
2184 while (!m_startViewport->childItems().isEmpty()) {
2185 QGraphicsItem *item = m_startViewport->childItems().at(0);
2186 m_scene->removeItem(item);
2189 while (!m_endViewport->childItems().isEmpty()) {
2190 QGraphicsItem *item = m_endViewport->childItems().at(0);
2191 m_scene->removeItem(item);
2196 void TitleWidget::slotKeepAspect(bool keep)
2198 if (m_endViewport->zValue() == 1100) {
2199 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2200 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2202 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2203 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2207 void TitleWidget::slotResize50()
2209 if (m_endViewport->zValue() == 1100) {
2210 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2211 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2214 void TitleWidget::slotResize100()
2216 if (m_endViewport->zValue() == 1100) {
2217 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2218 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2221 void TitleWidget::slotResize200()
2223 if (m_endViewport->zValue() == 1100) {
2224 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2225 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2228 void TitleWidget::slotAddEffect(int ix)
2230 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2231 int effect = effect_list->itemData(ix).toInt();
2233 if (list.size() == 1) {
2234 if (effect == NOEFFECT)
2235 effect_stack->setHidden(true);
2237 effect_stack->setCurrentIndex(effect - 1);
2238 effect_stack->setHidden(false);
2240 } else // Hide the effects stack when more than one element is selected.
2241 effect_stack->setHidden(true);
2243 foreach(QGraphicsItem * item, list) {
2246 item->setData(100, QVariant());
2247 #if QT_VERSION >= 0x040600
2248 item->setGraphicsEffect(0);
2251 case TYPEWRITEREFFECT:
2253 * Allow the user to set the typewriter effect to more than one
2254 * element, but do not add it to non-text elements.
2256 if (item->type() == TEXTITEM) {
2257 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ';' + QString::number(typewriter_start->value());
2258 item->setData(100, effdata);
2261 #if QT_VERSION >= 0x040600
2262 // Do not remove the non-QGraphicsEffects.
2264 item->setGraphicsEffect(new QGraphicsBlurEffect());
2267 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2274 void TitleWidget::slotFontText(const QString& s)
2277 if (f.exactMatch()) {
2278 // Font really exists (could also just be a «d» if the user
2279 // starts typing «dejavu» for example).
2280 font_family->setCurrentFont(f);
2282 // Note: Typing dejavu serif does not recognize the font (takes sans)
2283 // in older Qt versions. Case must match there (except for first letter)
2286 void TitleWidget::slotEditTypewriter(int /*ix*/)
2288 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2289 if (l.size() == 1) {
2290 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ';' + QString::number(typewriter_start->value());
2291 l[0]->setData(100, effdata);
2295 void TitleWidget::slotEditBlur(int ix)
2297 #if QT_VERSION < 0x040600
2300 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2301 if (l.size() == 1) {
2302 QGraphicsEffect *eff = l[0]->graphicsEffect();
2303 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2304 if (blur) blur->setBlurRadius(ix);
2309 void TitleWidget::slotEditShadow()
2311 #if QT_VERSION < 0x040600
2314 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2315 if (l.size() == 1) {
2316 QGraphicsEffect *eff = l[0]->graphicsEffect();
2317 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2319 shadow->setBlurRadius(shadow_radius->value());
2320 shadow->setOffset(shadow_x->value(), shadow_y->value());
2326 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2328 qreal bound = maxBound ? -99 : 99;
2329 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2331 QList<QGraphicsItem*> lItems;
2332 // Get items (all or intersecting only)
2333 if (intersectingOnly) {
2334 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2336 lItems = graphicsView->scene()->items();
2338 if (lItems.size() > 0) {
2339 int n = lItems.size();
2342 for (int i = 0; i < n; i++) {
2343 z = lItems[i]->zValue();
2344 if (z > bound && !lItems[i]->isSelected()) {
2346 } else if (z - 1 > bound) {
2347 // To get the maximum index even if it is of an item of the current selection.
2348 // Used when updating multiple items, to get all to the same level.
2349 // Otherwise, the maximum would stay at -99 if the highest item is in the selection.
2354 // Get minimum z index.
2355 for (int i = 0; i < n; i++) {
2356 z = lItems[i]->zValue();
2357 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2358 // There are items at the very bottom (background e.g.) with z-index < -1000.
2360 } else if (z + 1 < bound && z > -999) {
2370 void TitleWidget::slotZIndexUp()
2372 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2373 if (l.size() >= 1) {
2374 qreal currentZ = l[0]->zValue();
2375 qreal max = zIndexBounds(true, true);
2376 if (currentZ <= max) {
2377 l[0]->setZValue(currentZ + 1);
2378 updateDimension(l[0]);
2383 void TitleWidget::slotZIndexTop()
2385 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2386 qreal max = zIndexBounds(true, false);
2387 std::cout << "Max z-index is " << max << ".\n";
2388 for (int i = 0; i < l.size(); i++) {
2389 qreal currentZ = l[i]->zValue();
2390 if (currentZ <= max) {
2391 std::cout << "Updating item " << i << ", is " << currentZ << ".\n";
2392 l[i]->setZValue(max + 1);
2394 std::cout << "Not updating " << i << ", is " << currentZ << ".\n";
2397 // Update the z index value in the GUI
2399 updateDimension(l[0]);
2403 void TitleWidget::slotZIndexDown()
2405 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2406 if (l.size() >= 1) {
2407 qreal currentZ = l[0]->zValue();
2408 qreal min = zIndexBounds(false, true);
2409 if (currentZ >= min) {
2410 l[0]->setZValue(currentZ - 1);
2411 updateDimension(l[0]);
2416 void TitleWidget::slotZIndexBottom()
2418 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2419 qreal min = zIndexBounds(false, false);
2420 for (int i = 0; i < l.size(); i++) {
2421 qreal currentZ = l[i]->zValue();
2422 if (currentZ >= min) {
2423 l[i]->setZValue(min - 1);
2426 // Update the z index value in the GUI
2428 updateDimension(l[0]);
2432 void TitleWidget::slotSelectAll()
2434 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2435 for (int i = 0; i < l.size(); i++) {
2436 l.at(i)->setSelected(true);
2440 void TitleWidget::selectItems(int itemType)
2442 QList<QGraphicsItem*> l;
2443 if (graphicsView->scene()->selectedItems().size() > 0) {
2444 l = graphicsView->scene()->selectedItems();
2445 for (int i = 0; i < l.size(); i++) {
2446 if (l.at(i)->type() != itemType) {
2447 l.at(i)->setSelected(false);
2451 l = graphicsView->scene()->items();
2452 for (int i = 0; i < l.size(); i++) {
2453 if (l.at(i)->type() == itemType) {
2454 l.at(i)->setSelected(true);
2460 void TitleWidget::slotSelectText()
2462 selectItems(TEXTITEM);
2465 void TitleWidget::slotSelectRects()
2467 selectItems(RECTITEM);
2470 void TitleWidget::slotSelectImages()
2472 selectItems(IMAGEITEM);
2475 void TitleWidget::slotSelectNone()
2477 graphicsView->blockSignals(true);
2478 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2479 for (int i = 0; i < l.size(); i++) {
2480 l.at(i)->setSelected(false);
2482 graphicsView->blockSignals(false);
2486 QString TitleWidget::getTooltipWithShortcut(const QString &text, QAction *button)
2488 return text + " <b>" + button->shortcut().toString() + "</b>";
2491 void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
2493 // Let some GUI elements block signals. We may want to change their values without any sideeffects.
2494 // Additionally, store the previous blocking state to avoid side effects when this function is called from within another one.
2495 // Note: Disabling an element also blocks signals. So disabled elements don't need to be set to blocking too.
2496 bool blockOX = origin_x_left->signalsBlocked();
2497 bool blockOY = origin_y_top->signalsBlocked();
2498 bool blockEff = effect_list->signalsBlocked();
2499 bool blockRX = itemrotatex->signalsBlocked();
2500 bool blockRY = itemrotatey->signalsBlocked();
2501 bool blockRZ = itemrotatez->signalsBlocked();
2502 bool blockZoom = itemzoom->signalsBlocked();
2503 bool blockX = value_x->signalsBlocked();
2504 bool blockY = value_y->signalsBlocked();
2505 bool blockW = value_w->signalsBlocked();
2506 bool blockH = value_h->signalsBlocked();
2507 origin_x_left->blockSignals(true);
2508 origin_y_top->blockSignals(true);
2509 effect_list->blockSignals(true);
2510 itemrotatex->blockSignals(true);
2511 itemrotatey->blockSignals(true);
2512 itemrotatez->blockSignals(true);
2513 itemzoom->blockSignals(true);
2514 value_x->blockSignals(true);
2515 value_y->blockSignals(true);
2516 value_w->blockSignals(true);
2517 value_h->blockSignals(true);
2519 if (referenceItem == NULL) {
2520 std::cout << "NULL item.\n";
2521 effect_stack->setHidden(true);
2522 effect_frame->setEnabled(false);
2523 effect_list->setCurrentIndex(0);
2524 origin_x_left->setChecked(false);
2525 origin_y_top->setChecked(false);
2526 updateTextOriginX();
2527 updateTextOriginY();
2528 enableToolbars(TITLE_SELECT);
2529 showToolbars(TITLE_SELECT);
2531 itemzoom->setEnabled(false);
2532 itemrotatex->setEnabled(false);
2533 itemrotatey->setEnabled(false);
2534 itemrotatez->setEnabled(false);
2535 frame_properties->setEnabled(false);
2537 effect_frame->setEnabled(true);
2538 frame_properties->setEnabled(true);
2539 if (referenceItem != m_startViewport && referenceItem != m_endViewport) {
2540 itemzoom->setEnabled(true);
2541 itemrotatex->setEnabled(true);
2542 itemrotatey->setEnabled(true);
2543 itemrotatez->setEnabled(true);
2545 itemzoom->setEnabled(false);
2546 itemrotatex->setEnabled(false);
2547 itemrotatey->setEnabled(false);
2548 itemrotatez->setEnabled(false);
2551 if (referenceItem->type() == TEXTITEM) {
2552 showToolbars(TITLE_TEXT);
2553 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(referenceItem);
2554 if (!i->data(100).isNull()) {
2555 // Item has an effect
2556 QStringList effdata = i->data(100).toStringList();
2557 QString effectName = effdata.takeFirst();
2558 if (effectName == "typewriter") {
2559 QStringList params = effdata.at(0).split(';');
2560 typewriter_delay->setValue(params.at(0).toInt());
2561 typewriter_start->setValue(params.at(1).toInt());
2562 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
2563 effect_stack->setHidden(false);
2566 #if QT_VERSION >= 0x040600
2567 if (i->graphicsEffect()) {
2568 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
2570 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
2571 int rad = (int) blur->blurRadius();
2572 blur_radius->setValue(rad);
2573 effect_stack->setHidden(false);
2575 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
2577 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
2578 shadow_radius->setValue(shad->blurRadius());
2579 shadow_x->setValue(shad->xOffset());
2580 shadow_y->setValue(shad->yOffset());
2581 effect_stack->setHidden(false);
2585 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2586 effect_stack->setHidden(true);
2589 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2590 effect_stack->setHidden(true);
2593 font_size->blockSignals(true);
2594 font_family->blockSignals(true);
2595 font_weight_box->blockSignals(true);
2596 buttonItalic->blockSignals(true);
2597 buttonUnder->blockSignals(true);
2598 fontColorButton->blockSignals(true);
2599 #if not KDE_IS_VERSION(4,5,0)
2600 textAlpha->blockSignals(true);
2602 buttonAlignLeft->blockSignals(true);
2603 buttonAlignRight->blockSignals(true);
2604 buttonAlignNone->blockSignals(true);
2605 buttonAlignCenter->blockSignals(true);
2607 QFont font = i->font();
2608 font_family->setCurrentFont(font);
2609 font_size->setValue(font.pixelSize());
2610 m_scene->slotUpdateFontSize(font.pixelSize());
2611 buttonItalic->setChecked(font.italic());
2612 buttonUnder->setChecked(font.underline());
2613 setFontBoxWeight(font.weight());
2615 QTextCursor cursor(i->document());
2616 cursor.select(QTextCursor::Document);
2617 QColor color = cursor.charFormat().foreground().color();
2618 #if not KDE_IS_VERSION(4,5,0)
2619 textAlpha->setValue(color.alpha());
2620 color.setAlpha(255);
2622 fontColorButton->setColor(color);
2624 if (!i->data(101).isNull()) {
2625 textOutline->blockSignals(true);
2626 textOutline->setValue(i->data(101).toDouble() * 10);
2627 textOutline->blockSignals(false);
2629 if (!i->data(102).isNull()) {
2630 textOutlineColor->blockSignals(true);
2631 QVariant variant = i->data(102);
2632 color = variant.value<QColor>();
2633 #if not KDE_IS_VERSION(4,5,0)
2634 textOutlineAlpha->blockSignals(true);
2635 textOutlineAlpha->setValue(color.alpha());
2636 color.setAlpha(255);
2637 textOutlineAlpha->blockSignals(false);
2639 textOutlineColor->setColor(color);
2640 textOutlineColor->blockSignals(false);
2642 QTextCursor cur = i->textCursor();
2643 QTextBlockFormat format = cur.blockFormat();
2644 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
2645 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
2646 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
2647 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
2649 font_size->blockSignals(false);
2650 font_family->blockSignals(false);
2651 font_weight_box->blockSignals(false);
2652 buttonItalic->blockSignals(false);
2653 buttonUnder->blockSignals(false);
2654 fontColorButton->blockSignals(false);
2655 #if not KDE_IS_VERSION(4,5,0)
2656 textAlpha->blockSignals(false);
2658 buttonAlignLeft->blockSignals(false);
2659 buttonAlignRight->blockSignals(false);
2660 buttonAlignNone->blockSignals(false);
2661 buttonAlignCenter->blockSignals(false);
2663 // mbt 1607: Select text if the text item is an unchanged template item.
2664 if (i->property("isTemplate").isValid()) {
2665 cur.setPosition(0, QTextCursor::MoveAnchor);
2666 cur.select(QTextCursor::Document);
2667 i->setTextCursor(cur);
2668 // Make text editable now.
2670 i->setTextInteractionFlags(Qt::TextEditorInteraction);
2673 updateAxisButtons(i);
2674 updateCoordinates(i);
2676 enableToolbars(TITLE_TEXT);
2678 } else if ((referenceItem)->type() == RECTITEM) {
2679 showToolbars(TITLE_RECTANGLE);
2681 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(referenceItem);
2682 if (rec == m_startViewport || rec == m_endViewport) {
2683 /*toolBox->setCurrentIndex(3);
2684 toolBox->widget(0)->setEnabled(false);
2685 toolBox->widget(1)->setEnabled(false);*/
2686 enableToolbars(TITLE_SELECT);
2688 /*toolBox->widget(0)->setEnabled(true);
2689 toolBox->widget(1)->setEnabled(true);
2690 toolBox->setCurrentIndex(0);*/
2691 //toolBox->setItemEnabled(3, true);
2692 #if not KDE_IS_VERSION(4,5,0)
2693 rectFAlpha->setValue(rec->pen().color().alpha());
2694 rectBAlpha->setValue(rec->brush().color().alpha());
2696 //kDebug() << rec->brush().color().alpha();
2697 QColor fcol = rec->pen().color();
2698 QColor bcol = rec->brush().color();
2699 //fcol.setAlpha(255);
2700 //bcol.setAlpha(255);
2701 rectFColor->setColor(fcol);
2702 rectBColor->setColor(bcol);
2704 rectLineWidth->setValue(rec->pen().width());
2705 enableToolbars(TITLE_RECTANGLE);
2708 updateAxisButtons(referenceItem);
2709 updateCoordinates(rec);
2710 updateDimension(rec);
2712 } else if (referenceItem->type() == IMAGEITEM) {
2713 showToolbars(TITLE_IMAGE);
2715 updateCoordinates(referenceItem);
2716 updateDimension(referenceItem);
2718 enableToolbars(TITLE_IMAGE);
2721 //toolBox->setCurrentIndex(0);
2722 showToolbars(TITLE_SELECT);
2723 enableToolbars(TITLE_SELECT);
2724 frame_properties->setEnabled(false);
2726 zValue->setValue((int)referenceItem->zValue());
2727 if (!referenceItem->data(ZOOMFACTOR).isNull()) itemzoom->setValue(referenceItem->data(ZOOMFACTOR).toInt());
2728 else itemzoom->setValue((int)(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
2729 itemrotatex->setValue((int)(m_transformations.value(referenceItem).rotatex));
2730 itemrotatey->setValue((int)(m_transformations.value(referenceItem).rotatey));
2731 itemrotatez->setValue((int)(m_transformations.value(referenceItem).rotatez));
2735 effect_list->blockSignals(blockEff);
2736 itemrotatex->blockSignals(blockRX);
2737 itemrotatey->blockSignals(blockRY);
2738 itemrotatez->blockSignals(blockRZ);
2739 itemzoom->blockSignals(blockZoom);
2740 origin_x_left->blockSignals(blockOX);
2741 origin_y_top->blockSignals(blockOY);
2742 value_x->blockSignals(blockX);
2743 value_y->blockSignals(blockY);
2744 value_w->blockSignals(blockW);
2745 value_h->blockSignals(blockH);