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());
82 #if KDE_IS_VERSION(4,5,0)
83 rectBColor->setAlphaChannelEnabled(true);
85 rectFColor->setAlphaChannelEnabled(true);
87 fontColorButton->setAlphaChannelEnabled(true);
89 textOutlineColor->setAlphaChannelEnabled(true);
90 delete textOutlineAlpha;
93 rectBColor->setAlphaChannelEnabled(false);
94 rectFColor->setAlphaChannelEnabled(false);
95 fontColorButton->setAlphaChannelEnabled(false);
96 textOutlineColor->setAlphaChannelEnabled(false);
98 rectBAlpha->setMinimum(0);
99 rectBAlpha->setMaximum(255);
100 rectBAlpha->setDecimals(0);
101 rectBAlpha->setValue(255);
102 rectBAlpha->setToolTip(i18n("Color opacity"));
104 rectFAlpha->setMinimum(0);
105 rectFAlpha->setMaximum(255);
106 rectFAlpha->setDecimals(0);
107 rectFAlpha->setValue(255);
108 rectFAlpha->setToolTip(i18n("Border opacity"));
109 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
110 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
112 // Set combo sliders values
113 textAlpha->setMinimum(0);
114 textAlpha->setMaximum(255);
115 textAlpha->setDecimals(0);
116 textAlpha->setValue(255);
117 textAlpha->setToolTip(i18n("Font color opacity"));
119 textOutlineAlpha->setMinimum(0);
120 textOutlineAlpha->setMaximum(255);
121 textOutlineAlpha->setDecimals(0);
122 textOutlineAlpha->setValue(255);
123 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
124 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
125 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
128 textOutline->setMinimum(0);
129 textOutline->setMaximum(200);
130 textOutline->setDecimals(0);
131 textOutline->setValue(0);
132 textOutline->setToolTip(i18n("Outline width"));
134 backgroundAlpha->setMinimum(0);
135 backgroundAlpha->setMaximum(255);
136 backgroundAlpha->setDecimals(0);
137 backgroundAlpha->setValue(0);
138 backgroundAlpha->setToolTip(i18n("Background color opacity"));
140 itemrotatex->setMinimum(-360);
141 itemrotatex->setMaximum(360);
142 itemrotatex->setDecimals(0);
143 itemrotatex->setValue(0);
144 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
146 itemrotatey->setMinimum(-360);
147 itemrotatey->setMaximum(360);
148 itemrotatey->setDecimals(0);
149 itemrotatey->setValue(0);
150 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
152 itemrotatez->setMinimum(-360);
153 itemrotatez->setMaximum(360);
154 itemrotatez->setDecimals(0);
155 itemrotatez->setValue(0);
156 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
158 rectLineWidth->setMinimum(0);
159 rectLineWidth->setMaximum(100);
160 rectLineWidth->setDecimals(0);
161 rectLineWidth->setValue(0);
162 rectLineWidth->setToolTip(i18n("Border width"));
164 itemzoom->setSuffix(i18n("%"));
165 m_frameWidth = render->renderWidth();
166 m_frameHeight = render->renderHeight();
167 showToolbars(TITLE_SELECT);
169 splitter->setStretchFactor(0, 20);
171 //If project is drop frame, set the input mask as such.
172 title_duration->setInputMask(m_tc.mask());
173 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
175 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
176 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
178 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
179 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
180 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
181 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
182 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
183 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
185 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
187 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
188 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
189 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
191 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
192 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
193 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
194 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
195 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
196 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
199 effect_list->addItem(i18n("None"), NOEFFECT);
200 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
201 effect_list->addItem(i18n("Blur"), BLUREFFECT);
204 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
205 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
206 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
207 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
208 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
209 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
210 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
211 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
212 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
213 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
214 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
215 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
216 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
217 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
218 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
219 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
220 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
221 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
222 effect_stack->setHidden(true);
223 effect_frame->setEnabled(false);
225 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
226 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
229 m_signalMapper = new QSignalMapper(this);
230 m_signalMapper->setMapping(value_w, ValueWidth);
231 m_signalMapper->setMapping(value_h, ValueHeight);
232 m_signalMapper->setMapping(value_x, ValueX);
233 m_signalMapper->setMapping(value_y, ValueY);
234 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
235 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
236 connect(value_x, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
237 connect(value_y, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
238 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
240 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
241 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
242 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
243 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
244 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
245 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
246 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
247 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
248 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
250 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
253 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
255 font_weight_box->blockSignals(true);
256 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
257 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
258 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
259 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
260 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
261 font_weight_box->setToolTip(i18n("Font weight"));
262 font_weight_box->setCurrentIndex(1);
263 font_weight_box->blockSignals(false);
265 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
266 buttonRealSize->setIcon(KIcon("zoom-original"));
267 buttonItalic->setIcon(KIcon("format-text-italic"));
268 buttonUnder->setIcon(KIcon("format-text-underline"));
269 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
270 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
271 buttonAlignRight->setIcon(KIcon("format-justify-right"));
272 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
274 buttonAlignNone->setToolTip(i18n("No alignment"));
275 buttonAlignRight->setToolTip(i18n("Align right"));
276 buttonAlignLeft->setToolTip(i18n("Align left"));
277 buttonAlignCenter->setToolTip(i18n("Align center"));
279 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
280 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
281 m_unicodeAction->setToolTip(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
282 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
283 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
285 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
286 m_zUp->setShortcut(Qt::Key_PageUp);
287 m_zUp->setToolTip(i18n("Raise object"));
288 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
289 zUp->setDefaultAction(m_zUp);
291 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
292 m_zDown->setShortcut(Qt::Key_PageDown);
293 m_zDown->setToolTip(i18n("Lower object"));
294 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
295 zDown->setDefaultAction(m_zDown);
297 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
298 // TODO mbt 1414: Shortcut should change z index only if
299 // cursor is NOT in a text field ...
300 //m_zTop->setShortcut(Qt::Key_Home);
301 m_zTop->setToolTip(i18n("Raise object to top"));
302 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
303 zTop->setDefaultAction(m_zTop);
305 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
307 //m_zBottom->setShortcut(Qt::Key_End);
308 m_zBottom->setToolTip(i18n("Lower object to bottom"));
309 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
310 zBottom->setDefaultAction(m_zBottom);
312 m_selectAll = new QAction(KIcon("kdenlive-select-all"), QString(), this);
313 m_selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
314 connect(m_selectAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
315 buttonSelectAll->setDefaultAction(m_selectAll);
317 m_selectText = new QAction(KIcon("kdenlive-select-texts"), QString(), this);
318 m_selectText->setShortcut(Qt::CTRL + Qt::Key_T);
319 connect(m_selectText, SIGNAL(triggered()), this, SLOT(slotSelectText()));
320 buttonSelectText->setDefaultAction(m_selectText);
321 buttonSelectText->setEnabled(false);
323 m_selectRects = new QAction(KIcon("kdenlive-select-rects"), QString(), this);
324 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
325 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
326 buttonSelectRects->setDefaultAction(m_selectRects);
327 buttonSelectRects->setEnabled(false);
329 m_selectImages = new QAction(KIcon("kdenlive-select-images"), QString(), this);
330 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
331 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
332 buttonSelectImages->setDefaultAction(m_selectImages);
333 buttonSelectImages->setEnabled(false);
335 m_unselectAll = new QAction(KIcon("kdenlive-unselect-all"), QString(), this);
336 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
337 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
338 buttonUnselectAll->setDefaultAction(m_unselectAll);
339 buttonUnselectAll->setEnabled(false);
341 zDown->setIcon(KIcon("kdenlive-zindex-down"));
342 zTop->setIcon(KIcon("kdenlive-zindex-top"));
343 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
344 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
345 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
346 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
348 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
349 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
350 rectBColor->setToolTip(i18n("Select fill color"));
351 rectFColor->setToolTip(i18n("Select border color"));
352 zoom_slider->setToolTip(i18n("Zoom"));
353 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
354 buttonFitZoom->setToolTip(i18n("Fit zoom"));
355 backgroundColor->setToolTip(i18n("Select background color"));
356 backgroundAlpha->setToolTip(i18n("Background opacity"));
357 buttonSelectAll->setToolTip(getTooltipWithShortcut(i18n("Select all"), m_selectAll));
358 buttonSelectText->setToolTip(getTooltipWithShortcut(i18n("Select text items in current selection"), m_selectText));
359 buttonSelectRects->setToolTip(getTooltipWithShortcut(i18n("Select rect items in current selection"), m_selectRects));
360 buttonSelectImages->setToolTip(getTooltipWithShortcut(i18n("Select image items in current selection"), m_selectImages));
361 buttonUnselectAll->setToolTip(getTooltipWithShortcut(i18n("Unselect all"), m_unselectAll));
363 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
364 itemhcenter->setToolTip(i18n("Align item horizontally"));
365 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
366 itemvcenter->setToolTip(i18n("Align item vertically"));
367 itemtop->setIcon(KIcon("kdenlive-align-top"));
368 itemtop->setToolTip(i18n("Align item to top"));
369 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
370 itembottom->setToolTip(i18n("Align item to bottom"));
371 itemright->setIcon(KIcon("kdenlive-align-right"));
372 itemright->setToolTip(i18n("Align item to right"));
373 itemleft->setIcon(KIcon("kdenlive-align-left"));
374 itemleft->setToolTip(i18n("Align item to left"));
377 QHBoxLayout *layout = new QHBoxLayout;
378 frame_toolbar->setLayout(layout);
379 layout->setContentsMargins(0, 0, 0, 0);
380 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
381 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
382 m_toolbar->setIconSize(QSize(s, s));
384 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
385 m_buttonCursor->setCheckable(true);
386 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
387 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
388 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
390 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
391 m_buttonText->setCheckable(true);
392 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
393 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
394 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
396 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
397 m_buttonRect->setCheckable(true);
398 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
399 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
400 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
402 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
403 m_buttonImage->setCheckable(false);
404 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
405 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
406 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
408 m_toolbar->addSeparator();
410 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
411 m_buttonLoad->setCheckable(false);
412 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
413 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
415 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
416 m_buttonSave->setCheckable(false);
417 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
418 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
420 layout->addWidget(m_toolbar);
422 // initialize graphic scene
423 m_scene = new GraphicsSceneRectMove(this);
424 graphicsView->setScene(m_scene);
425 graphicsView->setMouseTracking(true);
426 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
427 graphicsView->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);
428 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
429 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
430 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
432 // a gradient background
433 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
434 gradient->setSpread(QGradient::ReflectSpread);
435 scene->setBackgroundBrush(*gradient);*/
437 QPen framepen(Qt::DotLine);
438 framepen.setColor(Qt::red);
440 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
441 m_frameBorder->setPen(framepen);
442 m_frameBorder->setZValue(-1100);
443 m_frameBorder->setBrush(Qt::transparent);
444 m_frameBorder->setFlags(0);
445 graphicsView->scene()->addItem(m_frameBorder);
447 m_frameImage = new QGraphicsPixmapItem();
449 qtrans.scale(2.0, 2.0);
450 m_frameImage->setTransform(qtrans);
451 m_frameImage->setZValue(-1200);
452 m_frameImage->setFlags(0);
453 displayBackgroundFrame();
454 graphicsView->scene()->addItem(m_frameImage);
456 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
457 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
458 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
459 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
460 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
461 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
462 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
463 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
466 // mbd: load saved settings
469 graphicsView->show();
470 //graphicsView->setRenderHint(QPainter::Antialiasing);
471 graphicsView->setInteractive(true);
472 //graphicsView->resize(400, 300);
473 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
474 //toolBox->setItemEnabled(2, false);
475 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
476 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
477 m_startViewport->setData(0, m_frameWidth);
478 m_startViewport->setData(1, m_frameHeight);
479 m_endViewport->setData(0, m_frameWidth);
480 m_endViewport->setData(1, m_frameHeight);
482 // scale the view so that the title widget is not too big at startup
483 graphicsView->scale(.5, .5);
484 if (!url.isEmpty()) loadTitle(url);
487 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
490 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
491 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
492 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
494 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
495 refreshTitleTemplates();
496 //templateBox->setIconSize(QSize(60,60));
497 templateBox->clear();
498 templateBox->addItem("");
499 foreach(TitleTemplate t, titletemplates) {
500 templateBox->addItem(t.icon, t.name, t.file);
502 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
505 TitleWidget::~TitleWidget()
509 delete m_buttonImage;
510 delete m_buttonCursor;
513 delete m_unicodeAction;
520 delete m_selectRects;
521 delete m_selectImages;
522 delete m_unselectAll;
524 delete m_unicodeDialog;
525 delete m_frameBorder;
527 delete m_startViewport;
528 delete m_endViewport;
530 delete m_signalMapper;
534 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
537 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
538 KStandardDirs::makeDir(titlePath);
539 titlePath.append((isClone == false) ? "title" : "clone");
542 while (path.isEmpty() || QFile::exists(path)) {
544 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
546 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
552 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
555 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
556 KStandardDirs::makeDir(titlePath);
557 return titlePath + titleName + ".png";
561 QStringList TitleWidget::extractImageList(QString xml)
564 if (xml.isEmpty()) return result;
567 QDomNodeList images = doc.elementsByTagName("content");
568 for (int i = 0; i < images.count(); i++) {
569 if (images.at(i).toElement().hasAttribute("url"))
570 result.append(images.at(i).toElement().attribute("url"));
576 QStringList TitleWidget::extractFontList(QString xml)
579 if (xml.isEmpty()) return result;
582 QDomNodeList images = doc.elementsByTagName("content");
583 for (int i = 0; i < images.count(); i++) {
584 if (images.at(i).toElement().hasAttribute("font"))
585 result.append(images.at(i).toElement().attribute("font"));
590 void TitleWidget::refreshTitleTemplates()
592 QStringList titlenamelist = QStringList() << i18n("None");
593 QStringList titlefiles = QStringList() << QString();
595 filters << "*.kdenlivetitle" ;
596 titletemplates.clear();
597 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
598 foreach(const QString & folder, titleTemplates) {
599 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
600 foreach(const QString & fname, filesnames) {
601 //titlenamelist.append(fname);
602 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
605 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
606 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
607 titletemplates.append(t);
610 kDebug() << titlenamelist << titlefiles;
612 void TitleWidget::templateIndexChanged(int index)
614 QString item = templateBox->itemData(index).toString();
616 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
617 if (KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
621 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
622 // Text of unchanged template titles should be selected when clicked.
623 QList<QGraphicsItem *> list = graphicsView->scene()->items();
624 foreach(QGraphicsItem * qgItem, list) {
625 if (qgItem->type() == TEXTITEM) {
626 QGraphicsTextItem *i;
627 i = static_cast<QGraphicsTextItem *>(qgItem);
628 i->setProperty("isTemplate", "true");
629 i->setProperty("templateText", i->toHtml());
633 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
637 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
642 void TitleWidget::slotTextTool()
644 m_scene->setTool(TITLE_TEXT);
645 showToolbars(TITLE_TEXT);
646 checkButton(TITLE_TEXT);
649 void TitleWidget::slotRectTool()
651 m_scene->setTool(TITLE_RECTANGLE);
652 showToolbars(TITLE_RECTANGLE);
653 checkButton(TITLE_RECTANGLE);
655 // Disable dragging mode, would make dragging a rect impossible otherwise ;)
656 graphicsView->setDragMode(QGraphicsView::NoDrag);
659 void TitleWidget::slotSelectTool()
661 m_scene->setTool(TITLE_SELECT);
663 // Enable rubberband selecting mode.
664 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
666 // Find out which toolbars need to be shown, depending on selected item
667 TITLETOOL t = TITLE_SELECT;
668 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
670 switch (l.at(0)->type()) {
684 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
685 //graphicsView->centerOn(l.at(0));
691 updateCoordinates(l.at(0));
692 updateDimension(l.at(0));
693 updateRotZoom(l.at(0));
696 checkButton(TITLE_SELECT);
699 void TitleWidget::slotImageTool()
701 // TODO: find a way to get a list of all supported image types...
702 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";
703 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
704 if (!url.isEmpty()) {
705 if (url.path().endsWith(".svg")) {
706 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
707 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
708 svg->setZValue(m_count++);
709 svg->setData(Qt::UserRole, url.path());
710 graphicsView->scene()->addItem(svg);
712 QPixmap pix(url.path());
713 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
714 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
715 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
716 image->setData(Qt::UserRole, url.path());
717 image->setZValue(m_count++);
718 graphicsView->scene()->addItem(image);
721 m_scene->setTool(TITLE_SELECT);
722 showToolbars(TITLE_SELECT);
723 checkButton(TITLE_SELECT);
726 void TitleWidget::showToolbars(TITLETOOL toolType)
730 toolbar_stack->setCurrentIndex(0);
733 toolbar_stack->setCurrentIndex(3);
735 case TITLE_RECTANGLE:
736 toolbar_stack->setCurrentIndex(1);
739 toolbar_stack->setCurrentIndex(2);
744 void TitleWidget::enableToolbars(TITLETOOL toolType)
746 // TITLETOOL is defined in graphicsscenerectmove.h
748 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
749 value_w->setEnabled(enable);
750 value_h->setEnabled(enable);
753 void TitleWidget::checkButton(TITLETOOL toolType)
755 bool bSelect = false;
767 case TITLE_RECTANGLE:
777 m_buttonCursor->setChecked(bSelect);
778 m_buttonText->setChecked(bText);
779 m_buttonRect->setChecked(bRect);
780 m_buttonImage->setChecked(bImage);
783 void TitleWidget::displayBackgroundFrame()
785 QRectF r = m_frameBorder->sceneBoundingRect();
786 if (!displayBg->isChecked()) {
787 QPixmap pattern(20, 20);
789 QColor bgcolor(210, 210, 210);
790 QPainter p(&pattern);
791 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
792 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
795 QPixmap bg((int) (r.width() / 2), (int) (r.height()/ 2));
797 p2.fillRect(bg.rect(), br);
799 m_frameImage->setPixmap(bg);
801 QImage img = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), QString(), m_render->frameRenderWidth() / 2, m_render->renderHeight() / 2);
802 m_frameImage->setPixmap(QPixmap::fromImage(img.scaled(r.width() / 2, r.height() / 2)));
806 void TitleWidget::initAnimation()
808 align_box->setEnabled(false);
809 QPen startpen(Qt::DotLine);
810 QPen endpen(Qt::DashDotLine);
811 startpen.setColor(QColor(100, 200, 100, 140));
812 endpen.setColor(QColor(200, 100, 100, 140));
814 m_startViewport->setPen(startpen);
815 m_endViewport->setPen(endpen);
817 m_startViewport->setZValue(-1000);
818 m_endViewport->setZValue(-1000);
820 m_startViewport->setFlags(0);
821 m_endViewport->setFlags(0);
823 graphicsView->scene()->addItem(m_startViewport);
824 graphicsView->scene()->addItem(m_endViewport);
826 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
827 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
828 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
829 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
832 void TitleWidget::slotUpdateZoom(int pos)
834 m_scene->setZoom((double) pos / 100);
835 zoom_label->setText(QString::number(pos) + '%');
838 void TitleWidget::slotZoom(bool up)
840 int pos = zoom_slider->value();
843 zoom_slider->setValue(pos);
846 void TitleWidget::slotAdjustZoom()
848 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
849 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
850 if (scalex > scaley) scalex = scaley;
851 int zoompos = (int)(scalex * 7 + 0.5);*/
852 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
853 int zoompos = graphicsView->matrix().m11() * 100;
854 zoom_slider->setValue(zoompos);
855 graphicsView->centerOn(m_frameBorder);
858 void TitleWidget::slotZoomOneToOne()
860 zoom_slider->setValue(100);
861 graphicsView->centerOn(m_frameBorder);
864 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
866 updateAxisButtons(rect); // back to default
868 QColor f = rectFColor->color();
869 #if not KDE_IS_VERSION(4,5,0)
870 f.setAlpha(rectFAlpha->value());
873 penf.setWidth(rectLineWidth->value());
874 penf.setJoinStyle(Qt::RoundJoin);
876 QColor b = rectBColor->color();
877 #if not KDE_IS_VERSION(4,5,0)
878 b.setAlpha(rectBAlpha->value());
880 rect->setBrush(QBrush(b));
881 rect->setZValue(m_count++);
882 rect->setData(ZOOMFACTOR, 100);
883 //setCurrentItem(rect);
884 //graphicsView->setFocus();
887 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
889 updateAxisButtons(tt); // back to default
891 QFont font = font_family->currentFont();
892 font.setPixelSize(font_size->value());
894 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
895 font.setItalic(buttonItalic->isChecked());
896 font.setUnderline(buttonUnder->isChecked());
899 QColor color = fontColorButton->color();
900 QColor outlineColor = textOutlineColor->color();
901 #if not KDE_IS_VERSION(4,5,0)
902 color.setAlpha(textAlpha->value());
903 outlineColor.setAlpha(textOutlineAlpha->value());
905 tt->setDefaultTextColor(color);
907 QTextCursor cur(tt->document());
908 cur.select(QTextCursor::Document);
909 QTextBlockFormat format = cur.blockFormat();
910 QTextCharFormat cformat = cur.charFormat();
911 double outlineWidth = textOutline->value() / 10.0;
913 tt->setData(101, outlineWidth);
914 tt->setData(102, outlineColor);
915 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
917 cformat.setForeground(QBrush(color));
918 cur.setCharFormat(cformat);
919 cur.setBlockFormat(format);
920 tt->setTextCursor(cur);
921 tt->setZValue(m_count++);
925 void TitleWidget::setFontBoxWeight(int weight)
927 int index = font_weight_box->findData(weight);
929 index = font_weight_box->findData(QFont::Normal);
931 font_weight_box->setCurrentIndex(index);
934 void TitleWidget::setCurrentItem(QGraphicsItem *item)
936 m_scene->setSelectedItem(item);
939 void TitleWidget::zIndexChanged(int v)
941 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
942 for (int i = 0; i < l.size(); i++) {
947 void TitleWidget::selectionChanged()
949 if (m_scene->tool() != TITLE_SELECT) return;
951 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
953 QList<QGraphicsItem *> l;
955 // mbt 1607: One text item might have grabbed the keyboard.
956 // Ungrab it for all items that are not selected, otherwise
957 // text input would only work for the text item that grabbed
958 // the keyboard last.
959 l = graphicsView->scene()->items();
960 foreach(QGraphicsItem * item, l) {
961 if (item->type() == TEXTITEM && !item->isSelected()) {
962 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
967 l = graphicsView->scene()->selectedItems();
970 buttonUnselectAll->setEnabled(true);
971 // Enable all z index buttons if items selected.
972 // We can selectively disable them later.
973 zUp->setEnabled(true);
974 zDown->setEnabled(true);
975 zTop->setEnabled(true);
976 zBottom->setEnabled(true);
978 buttonUnselectAll->setEnabled(false);
981 buttonSelectText->setEnabled(true);
982 buttonSelectRects->setEnabled(true);
983 buttonSelectImages->setEnabled(true);
985 buttonSelectText->setEnabled(false);
986 buttonSelectRects->setEnabled(false);
987 buttonSelectImages->setEnabled(false);
992 } else if (l.size() == 1) {
993 prepareTools(l.at(0));
996 For multiple selected objects we need to decide which tools to show.
998 int firstType = l.at(0)->type();
999 bool allEqual = true;
1000 for (int i = 0; i < l.size(); i++) {
1001 if (l.at(i)->type() != firstType) {
1006 std::cout << "All equal? " << allEqual << ".\n";
1008 prepareTools(l.at(0));
1010 // Get the default toolset, but enable the property frame (x,y,w,h)
1012 frame_properties->setEnabled(true);
1014 // Enable x/y/w/h if it makes sense.
1015 value_x->setEnabled(true);
1016 value_y->setEnabled(true);
1017 bool containsTextitem = false;
1018 for (int i = 0; i < l.size(); i++) {
1019 if (l.at(i)->type() == TEXTITEM) {
1020 containsTextitem = true;
1024 if (!containsTextitem) {
1025 value_w->setEnabled(true);
1026 value_h->setEnabled(true);
1030 // Disable z index buttons if they don't make sense for the current selection
1031 int firstZindex = l.at(0)->zValue();
1033 for (int i = 0; i < l.size(); i++) {
1034 if (l[i]->zValue() != firstZindex) {
1040 zUp->setEnabled(false);
1041 zDown->setEnabled(false);
1049 void TitleWidget::slotValueChanged(int type)
1052 type tells us which QSpinBox value has changed.
1055 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1056 std::cout << l.size() << " items to be resized\n";
1058 // Get the updated value here already to do less coding afterwards
1062 val = value_w->value();
1065 val = value_h->value();
1068 val = value_x->value();
1071 val = value_y->value();
1075 for (int k = 0; k < l.size(); k++) {
1076 std::cout << "Type of item " << k << ": " << l.at(k)->type() << "\n";
1078 if (l.at(k)->type() == TEXTITEM) {
1079 // Just update the position. We don't allow setting width/height for text items yet.
1082 updatePosition(l.at(k), val, l.at(k)->pos().y());
1085 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1089 } else if (l.at(k)->type() == RECTITEM) {
1090 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(k));
1093 updatePosition(l.at(k), val, l.at(k)->pos().y());
1096 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1099 rec->setRect(QRect(0, 0, val, rec->rect().height()));
1102 rec->setRect(QRect(0, 0, rec->rect().width(), val));
1106 } else if (l.at(k)->type() == IMAGEITEM) {
1109 if (type == ValueX) {
1110 updatePosition(l.at(k), val, l.at(k)->pos().y());
1112 } else if (type == ValueY) {
1113 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1116 // Width/height has changed. This is more complex.
1118 QGraphicsItem *i = l.at(k);
1119 Transform t = m_transformations.value(i);
1121 // Ratio width:height
1122 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1123 // TODO: proper calculation for rotation around 3 axes
1124 double alpha = (double) t.rotatez / 180.0 * M_PI;
1127 double length = val;
1132 // We want to keep the aspect ratio of the image as the user does not yet have the possibility
1133 // to restore the original ratio. You rarely want to change it anyway.
1136 // Add 0.5 because otherwise incrementing by 1 might have no effect
1137 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1138 scale = length / i->boundingRect().width();
1141 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1142 scale = length / i->boundingRect().height();
1149 qtrans.scale(scale, scale);
1150 qtrans.rotate(t.rotatex, Qt::XAxis);
1151 qtrans.rotate(t.rotatey, Qt::YAxis);
1152 qtrans.rotate(t.rotatez, Qt::ZAxis);
1153 i->setTransform(qtrans);
1154 std::cout << "scale is: " << scale << "\n";
1155 std::cout << i->boundingRect().width() << ": new width\n";
1156 m_transformations[i] = t;
1158 if (l.size() == 1) {
1159 // Only update the w/h values if the selection contains just one item.
1160 // Otherwise, what should we do? ;)
1161 // (Use the values of the first item? Of the second? Of the x-th?)
1163 // Update rotation/zoom values.
1164 // These values are not yet able to handle multiple items!
1175 void TitleWidget::updateDimension(QGraphicsItem *i)
1177 bool wBlocked = value_w->signalsBlocked();
1178 bool hBlocked = value_h->signalsBlocked();
1179 bool zBlocked = zValue->signalsBlocked();
1180 value_w->blockSignals(true);
1181 value_h->blockSignals(true);
1182 zValue->blockSignals(true);
1184 zValue->setValue((int) i->zValue());
1185 if (i->type() == IMAGEITEM) {
1186 // Get multipliers for rotation/scaling
1188 /*Transform t = m_transformations.value(i);
1189 QRectF r = i->boundingRect();
1190 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1191 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1192 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1193 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1195 value_w->setValue(i->sceneBoundingRect().width());
1196 value_h->setValue(i->sceneBoundingRect().height());
1197 } else if (i->type() == RECTITEM) {
1198 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1199 std::cout << "Rect width is: " << r->rect().width() << ", was: " << value_w->value() << "\n";
1200 value_w->setValue((int) r->rect().width());
1201 value_h->setValue((int) r->rect().height());
1202 } else if (i->type() == TEXTITEM) {
1203 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1204 value_w->setValue((int) t->boundingRect().width());
1205 value_h->setValue((int) t->boundingRect().height());
1208 zValue->blockSignals(zBlocked);
1209 value_w->blockSignals(wBlocked);
1210 value_h->blockSignals(hBlocked);
1213 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1215 // Block signals emitted by this method
1216 value_x->blockSignals(true);
1217 value_y->blockSignals(true);
1219 if (i->type() == TEXTITEM) {
1221 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1223 // Set the correct x coordinate value
1224 if (origin_x_left->isChecked()) {
1225 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1226 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1228 // Origin is at 0 (default)
1229 value_x->setValue((int) rec->pos().x());
1233 if (origin_y_top->isChecked()) {
1234 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1236 value_y->setValue((int) rec->pos().y());
1239 } else if (i->type() == RECTITEM) {
1241 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1243 if (origin_x_left->isChecked()) {
1244 // Origin (0 point) is at m_frameWidth
1245 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1247 // Origin is at 0 (default)
1248 value_x->setValue((int) rec->pos().x());
1251 if (origin_y_top->isChecked()) {
1252 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1254 value_y->setValue((int) rec->pos().y());
1257 } else if (i->type() == IMAGEITEM) {
1259 if (origin_x_left->isChecked()) {
1260 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1262 value_x->setValue((int) i->pos().x());
1265 if (origin_y_top->isChecked()) {
1266 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1268 value_y->setValue((int) i->pos().y());
1273 // Stop blocking signals now
1274 value_x->blockSignals(false);
1275 value_y->blockSignals(false);
1278 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1280 itemzoom->blockSignals(true);
1281 itemrotatex->blockSignals(true);
1282 itemrotatey->blockSignals(true);
1283 itemrotatez->blockSignals(true);
1285 Transform t = m_transformations.value(i);
1287 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1288 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1290 itemrotatex->setValue((int)(t.rotatex));
1291 itemrotatey->setValue((int)(t.rotatey));
1292 itemrotatez->setValue((int)(t.rotatez));
1294 itemzoom->blockSignals(false);
1295 itemrotatex->blockSignals(false);
1296 itemrotatey->blockSignals(false);
1297 itemrotatez->blockSignals(false);
1300 void TitleWidget::updatePosition(QGraphicsItem *i)
1302 updatePosition(i, value_x->value(), value_y->value());
1305 void TitleWidget::updatePosition(QGraphicsItem *i, int x, int y)
1307 if (i->type() == TEXTITEM) {
1308 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1311 if (origin_x_left->isChecked()) {
1313 * Origin of the X axis is at m_frameWidth, and distance from right
1314 * border of the item to the right border of the frame is taken. See
1315 * comment to slotOriginXClicked().
1317 posX = m_frameWidth - x - rec->boundingRect().width();
1323 if (origin_y_top->isChecked()) {
1324 /* Same for y axis */
1325 posY = m_frameHeight - y - rec->boundingRect().height();
1330 rec->setPos(posX, posY);
1332 } else if (i->type() == RECTITEM) {
1334 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1337 if (origin_x_left->isChecked()) {
1338 posX = m_frameWidth - x - rec->rect().width();
1344 if (origin_y_top->isChecked()) {
1345 posY = m_frameHeight - y - rec->rect().height();
1350 rec->setPos(posX, posY);
1352 } else if (i->type() == IMAGEITEM) {
1354 if (origin_x_left->isChecked()) {
1355 // Use the sceneBoundingRect because this also regards transformations like zoom
1356 posX = m_frameWidth - x - i->sceneBoundingRect().width();
1362 if (origin_y_top->isChecked()) {
1363 posY = m_frameHeight - y - i->sceneBoundingRect().height();
1368 i->setPos(posX, posY);
1374 void TitleWidget::updateTextOriginX()
1376 if (origin_x_left->isChecked()) {
1377 origin_x_left->setText(i18n("\u2212X"));
1379 origin_x_left->setText(i18n("+X"));
1383 void TitleWidget::slotOriginXClicked()
1385 // Update the text displayed on the button.
1386 updateTextOriginX();
1388 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1389 if (l.size() >= 1) {
1390 updateCoordinates(l.at(0));
1392 // Remember x axis setting
1393 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1394 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1396 graphicsView->setFocus();
1399 void TitleWidget::updateTextOriginY()
1401 if (origin_y_top->isChecked()) {
1402 origin_y_top->setText(i18n("\u2212Y"));
1404 origin_y_top->setText(i18n("+Y"));
1408 void TitleWidget::slotOriginYClicked()
1410 // Update the text displayed on the button.
1411 updateTextOriginY();
1413 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1414 if (l.size() >= 1) {
1415 updateCoordinates(l.at(0));
1417 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1418 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1421 graphicsView->setFocus();
1424 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1426 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1427 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1428 origin_x_left->blockSignals(true);
1429 origin_y_top->blockSignals(true);
1431 if (xAxis == TitleDocument::AxisInverted) {
1432 origin_x_left->setChecked(true);
1434 origin_x_left->setChecked(false);
1436 updateTextOriginX();
1438 if (yAxis == TitleDocument::AxisInverted) {
1439 origin_y_top->setChecked(true);
1441 origin_y_top->setChecked(false);
1443 updateTextOriginY();
1445 origin_x_left->blockSignals(false);
1446 origin_y_top->blockSignals(false);
1449 void TitleWidget::slotChangeBackground()
1451 QColor color = backgroundColor->color();
1452 color.setAlpha(backgroundAlpha->value());
1453 m_frameBorder->setBrush(QBrush(color));
1456 void TitleWidget::slotChanged()
1458 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1459 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1460 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1464 void TitleWidget::textChanged(QGraphicsTextItem *i)
1467 * If the user has set origin_x_left (the same for y), we need to look
1468 * whether a text element has been selected. If yes, we need to ensure that
1469 * the right border of the text field remains fixed also when some text has
1472 * This is also known as right-justified, with the difference that it is not
1473 * valid for text but for its boundingRect. Text may still be
1478 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1479 if (!i->toPlainText().isEmpty())
1483 * Don't do anything if the string is empty. If the position were
1484 * updated here, a newly created text field would be set to the
1485 * position of the last selected text field.
1490 // mbt 1607: Template text has changed; don't auto-select content anymore.
1491 if (i->property("isTemplate").isValid()) {
1492 if (i->property("templateText").isValid()) {
1493 if (i->property("templateText") == i->toHtml()) {
1494 // Unchanged, do nothing.
1496 i->setProperty("isTemplate", QVariant::Invalid);
1497 i->setProperty("templateText", QVariant::Invalid);
1503 void TitleWidget::slotInsertUnicode()
1505 m_unicodeDialog->exec();
1508 void TitleWidget::slotInsertUnicodeString(QString text)
1510 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1512 if (l.at(0)->type() == TEXTITEM) {
1513 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1514 t->textCursor().insertText(text);
1519 void TitleWidget::slotUpdateText()
1521 QFont font = font_family->currentFont();
1522 font.setPixelSize(font_size->value());
1523 font.setItalic(buttonItalic->isChecked());
1524 font.setUnderline(buttonUnder->isChecked());
1525 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1526 QColor color = fontColorButton->color();
1527 QColor outlineColor = textOutlineColor->color();
1528 #if not KDE_IS_VERSION(4,5,0)
1529 color.setAlpha(textAlpha->value());
1530 outlineColor.setAlpha(textOutlineAlpha->value());
1533 double outlineWidth = textOutline->value() / 10.0;
1536 for (i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1537 QGraphicsTextItem* item = NULL;
1538 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1539 if (l.at(i)->type() == TEXTITEM) {
1540 item = static_cast <QGraphicsTextItem *>(l.at(i));
1543 // No text item, try next one.
1547 // Set alignment of all text in the text item
1548 QTextCursor cur(item->document());
1549 cur.select(QTextCursor::Document);
1550 QTextBlockFormat format = cur.blockFormat();
1551 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1552 item->setTextWidth(item->boundingRect().width());
1553 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1554 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1555 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1557 format.setAlignment(Qt::AlignLeft);
1558 item->setTextWidth(-1);
1561 // Set font properties
1562 item->setFont(font);
1563 QTextCharFormat cformat = cur.charFormat();
1565 item->setData(101, outlineWidth);
1566 item->setData(102, outlineColor);
1567 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1569 cformat.setForeground(QBrush(color));
1570 cur.setCharFormat(cformat);
1571 cur.setBlockFormat(format);
1572 // item->setTextCursor(cur);
1573 cur.clearSelection();
1574 item->setTextCursor(cur);
1575 item->setDefaultTextColor(color);
1579 void TitleWidget::rectChanged()
1581 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1583 for (i = 0; i < l.length(); i++) {
1584 if (l.at(i)->type() == RECTITEM && !settingUp) {
1585 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1586 QColor f = rectFColor->color();
1587 #if not KDE_IS_VERSION(4,5,0)
1588 f.setAlpha(rectFAlpha->value());
1591 penf.setWidth(rectLineWidth->value());
1592 penf.setJoinStyle(Qt::RoundJoin);
1594 QColor b = rectBColor->color();
1595 #if not KDE_IS_VERSION(4,5,0)
1596 b.setAlpha(rectBAlpha->value());
1598 rec->setBrush(QBrush(b));
1603 void TitleWidget::itemScaled(int val)
1605 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1606 if (l.size() == 1) {
1607 Transform x = m_transformations.value(l.at(0));
1608 x.scalex = (double)val / 100.0;
1609 x.scaley = (double)val / 100.0;
1611 qtrans.scale(x.scalex, x.scaley);
1612 qtrans.rotate(x.rotatex, Qt::XAxis);
1613 qtrans.rotate(x.rotatey, Qt::YAxis);
1614 qtrans.rotate(x.rotatez, Qt::ZAxis);
1615 l[0]->setTransform(qtrans);
1616 l[0]->setData(ZOOMFACTOR, val);
1617 m_transformations[l.at(0)] = x;
1618 updateDimension(l.at(0));
1622 void TitleWidget::itemRotateX(qreal val)
1627 void TitleWidget::itemRotateY(qreal val)
1632 void TitleWidget::itemRotateZ(qreal val)
1637 void TitleWidget::itemRotate(qreal val, int axis)
1639 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1640 if (l.size() == 1) {
1641 Transform x = m_transformations[l.at(0)];
1654 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1657 qtrans.scale(x.scalex, x.scaley);
1658 qtrans.rotate(x.rotatex, Qt::XAxis);
1659 qtrans.rotate(x.rotatey, Qt::YAxis);
1660 qtrans.rotate(x.rotatez, Qt::ZAxis);
1661 l[0]->setTransform(qtrans);
1662 m_transformations[l.at(0)] = x;
1663 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1664 updateDimension(l.at(0));
1668 void TitleWidget::itemHCenter()
1670 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1671 if (l.size() == 1) {
1672 QGraphicsItem *item = l.at(0);
1673 QRectF br = item->sceneBoundingRect();
1674 int width = (int)br.width();
1675 int newPos = (int)((m_frameWidth - width) / 2);
1676 newPos += item->pos().x() - br.left(); // Check item transformation
1677 item->setPos(newPos, item->pos().y());
1678 updateCoordinates(item);
1682 void TitleWidget::itemVCenter()
1684 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1685 if (l.size() == 1) {
1686 QGraphicsItem *item = l.at(0);
1687 QRectF br = item->sceneBoundingRect();
1688 int height = (int)br.height();
1689 int newPos = (int)((m_frameHeight - height) / 2);
1690 newPos += item->pos().y() - br.top(); // Check item transformation
1691 item->setPos(item->pos().x(), newPos);
1692 updateCoordinates(item);
1696 void TitleWidget::itemTop()
1698 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1699 if (l.size() == 1) {
1700 QGraphicsItem *item = l.at(0);
1701 QRectF br = item->sceneBoundingRect();
1703 if (br.top() > 0) diff = -br.top();
1704 else diff = -br.bottom();
1705 item->moveBy(0, diff);
1706 updateCoordinates(item);
1710 void TitleWidget::itemBottom()
1712 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1713 if (l.size() == 1) {
1714 QGraphicsItem *item = l.at(0);
1715 QRectF br = item->sceneBoundingRect();
1717 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1718 else diff = m_frameHeight - br.bottom();
1719 item->moveBy(0, diff);
1720 updateCoordinates(item);
1724 void TitleWidget::itemLeft()
1726 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1727 if (l.size() == 1) {
1728 QGraphicsItem *item = l.at(0);
1729 QRectF br = item->sceneBoundingRect();
1731 if (br.left() > 0) diff = -br.left();
1732 else diff = -br.right();
1733 item->moveBy(diff, 0);
1734 updateCoordinates(item);
1738 void TitleWidget::itemRight()
1740 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1741 if (l.size() == 1) {
1742 QGraphicsItem *item = l.at(0);
1743 QRectF br = item->sceneBoundingRect();
1745 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1746 else diff = m_frameWidth - br.left();
1747 item->moveBy(diff, 0);
1748 updateCoordinates(item);
1752 void TitleWidget::setupViewports()
1754 //double aspect_ratio = 4.0 / 3.0;//read from project
1755 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1756 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1757 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1758 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1759 QPolygonF spoly(sp);
1760 QPolygonF epoly(ep);
1761 spoly.translate(startViewportX->value(), startViewportY->value());
1762 epoly.translate(endViewportX->value(), endViewportY->value());
1763 m_startViewport->setPolygon(spoly);
1764 m_endViewport->setPolygon(epoly);
1765 if (! insertingValues) {
1766 m_startViewport->setData(0, startViewportX->value());
1767 m_startViewport->setData(1, startViewportY->value());
1768 m_startViewport->setData(2, startViewportSize->value());
1770 m_endViewport->setData(0, endViewportX->value());
1771 m_endViewport->setData(1, endViewportY->value());
1772 m_endViewport->setData(2, endViewportSize->value());
1776 void TitleWidget::loadTitle(KUrl url)
1778 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1779 if (!url.isEmpty()) {
1780 QList<QGraphicsItem *> items = m_scene->items();
1781 for (int i = 0; i < items.size(); i++) {
1782 if (items.at(i)->zValue() > -1000) delete items.at(i);
1784 m_scene->clearTextSelection();
1788 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1789 QFile file(tmpfile);
1790 if (file.open(QIODevice::ReadOnly)) {
1791 doc.setContent(&file, false);
1794 KIO::NetAccess::removeTempFile(tmpfile);
1799 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1801 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1802 insertingValues = true;
1803 startViewportX->setValue(m_startViewport->data(0).toInt());
1804 startViewportY->setValue(m_startViewport->data(1).toInt());
1805 startViewportSize->setValue(m_startViewport->data(2).toInt());
1806 endViewportX->setValue(m_endViewport->data(0).toInt());
1807 endViewportY->setValue(m_endViewport->data(1).toInt());
1808 endViewportSize->setValue(m_endViewport->data(2).toInt());
1810 insertingValues = false;
1816 void TitleWidget::saveTitle(KUrl url)
1818 if (anim_start->isChecked()) slotAnimStart(false);
1819 if (anim_end->isChecked()) slotAnimEnd(false);
1820 bool embed_image=false;
1821 if (KMessageBox::questionYesNo(this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::No)
1825 if (url.isEmpty()) {
1826 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1827 fs->setOperationMode(KFileDialog::Saving);
1828 fs->setMode(KFile::File);
1829 fs->setConfirmOverwrite(true);
1830 fs->setKeepLocation(true);
1832 url = fs->selectedUrl();
1835 if (!url.isEmpty()) {
1836 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
1837 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1841 QDomDocument TitleWidget::xml()
1843 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1844 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1848 int TitleWidget::outPoint() const
1850 return m_tc.getFrameCount(title_duration->text());
1853 void TitleWidget::setXml(QDomDocument doc)
1856 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out, m_projectTitlePath);
1858 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1859 /*if (doc.documentElement().hasAttribute("out")) {
1860 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1861 title_duration->setText(m_tc.getTimecode(duration));
1863 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1865 QDomElement e = doc.documentElement();
1866 m_transformations.clear();
1867 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1868 const double PI = 4.0 * atan(1.0);
1869 for (int i = 0; i < items.count(); i++) {
1870 QTransform t = items.at(i)->transform();
1874 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1875 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1876 if (rotlist.count() >= 3) {
1877 x.rotatex = rotlist[0].toDouble();
1878 x.rotatey = rotlist[1].toDouble();
1879 x.rotatez = rotlist[2].toDouble();
1881 // Try to adjust zoom
1882 t.rotate(x.rotatex *(-1), Qt::XAxis);
1883 t.rotate(x.rotatey *(-1), Qt::YAxis);
1884 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1895 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1897 m_transformations[items.at(i)] = x;
1899 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1900 QColor background_color = m_titledocument.getBackgroundColor();
1901 backgroundAlpha->blockSignals(true);
1902 backgroundColor->blockSignals(true);
1903 backgroundAlpha->setValue(background_color.alpha());
1904 background_color.setAlpha(255);
1905 backgroundColor->setColor(background_color);
1906 backgroundAlpha->blockSignals(false);
1907 backgroundColor->blockSignals(false);
1909 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1910 startViewportY->setValue(m_startViewport->data(1).toInt());
1911 startViewportSize->setValue(m_startViewport->data(2).toInt());
1912 endViewportX->setValue(m_endViewport->data(0).toInt());
1913 endViewportY->setValue(m_endViewport->data(1).toInt());
1914 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1916 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1921 void TitleWidget::slotAccepted()
1923 if (anim_start->isChecked()) slotAnimStart(false);
1924 if (anim_end->isChecked()) slotAnimEnd(false);
1928 void TitleWidget::writeChoices()
1930 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1931 KSharedConfigPtr config = KGlobal::config();
1932 KConfigGroup titleConfig(config, "TitleWidget");
1933 // Write the entries
1934 titleConfig.writeEntry("font_family", font_family->currentFont());
1935 //titleConfig.writeEntry("font_size", font_size->value());
1936 titleConfig.writeEntry("font_pixel_size", font_size->value());
1937 titleConfig.writeEntry("font_color", fontColorButton->color());
1938 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1939 #if KDE_IS_VERSION(4,5,0)
1940 titleConfig.writeEntry("font_alpha", fontColorButton->color().alpha());
1941 titleConfig.writeEntry("font_outline_alpha", textOutlineColor->color().alpha());
1943 titleConfig.writeEntry("font_alpha", textAlpha->value());
1944 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1946 titleConfig.writeEntry("font_outline", textOutline->value());
1947 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1948 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1949 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1951 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1952 #if KDE_IS_VERSION(4,5,0)
1953 titleConfig.writeEntry("rect_foreground_alpha", rectFColor->color().alpha());
1955 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1957 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1958 #if KDE_IS_VERSION(4,5,0)
1959 titleConfig.writeEntry("rect_background_alpha", rectBColor->color().alpha());
1961 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1963 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1965 titleConfig.writeEntry("background_color", backgroundColor->color());
1966 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1968 //! \todo Not sure if I should sync - it is probably safe to do it
1973 void TitleWidget::readChoices()
1975 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1976 KSharedConfigPtr config = KGlobal::config();
1977 KConfigGroup titleConfig(config, "TitleWidget");
1979 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1980 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1981 m_scene->slotUpdateFontSize(font_size->value());
1982 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1983 #if not KDE_IS_VERSION(4,5,0)
1984 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1985 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
1987 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
1988 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
1991 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1992 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1993 setFontBoxWeight(weight);
1994 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1995 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1997 QColor fgColor = QColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1998 #if KDE_IS_VERSION(4,5,0)
1999 fgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", rectFColor->color().alpha()));
2001 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
2003 rectFColor->setColor(fgColor);
2005 QColor bgColor = QColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
2006 #if KDE_IS_VERSION(4,5,0)
2007 bgColor.setAlpha(titleConfig.readEntry("rect_background_alpha", rectBColor->color().alpha()));
2009 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
2011 rectBColor->setColor(bgColor);
2012 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
2014 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
2015 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
2018 void TitleWidget::adjustFrameSize()
2020 m_frameWidth = m_titledocument.frameWidth();
2021 m_frameHeight = m_titledocument.frameHeight();
2022 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
2023 displayBackgroundFrame();
2026 void TitleWidget::slotAnimStart(bool anim)
2028 if (anim && anim_end->isChecked()) {
2029 anim_end->setChecked(false);
2030 m_endViewport->setZValue(-1000);
2031 m_endViewport->setBrush(QBrush());
2034 QList<QGraphicsItem *> list = m_scene->items();
2035 for (int i = 0; i < list.count(); i++) {
2036 if (list.at(i)->zValue() > -1000) {
2037 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2038 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2041 align_box->setEnabled(anim);
2042 itemzoom->setEnabled(!anim);
2043 itemrotatex->setEnabled(!anim);
2044 itemrotatey->setEnabled(!anim);
2045 itemrotatez->setEnabled(!anim);
2046 frame_toolbar->setEnabled(!anim);
2047 toolbar_stack->setEnabled(!anim);
2049 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
2050 m_startViewport->setZValue(1100);
2051 QColor col = m_startViewport->pen().color();
2053 m_startViewport->setBrush(col);
2054 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2055 m_startViewport->setSelected(true);
2058 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
2060 m_startViewport->setZValue(-1000);
2061 m_startViewport->setBrush(QBrush());
2062 m_startViewport->setFlags(0);
2063 if (!anim_end->isChecked()) deleteAnimInfoText();
2068 void TitleWidget::slotAnimEnd(bool anim)
2070 if (anim && anim_start->isChecked()) {
2071 anim_start->setChecked(false);
2072 m_startViewport->setZValue(-1000);
2073 m_startViewport->setBrush(QBrush());
2076 QList<QGraphicsItem *> list = m_scene->items();
2077 for (int i = 0; i < list.count(); i++) {
2078 if (list.at(i)->zValue() > -1000) {
2079 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2080 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2083 align_box->setEnabled(anim);
2084 itemzoom->setEnabled(!anim);
2085 itemrotatex->setEnabled(!anim);
2086 itemrotatey->setEnabled(!anim);
2087 itemrotatez->setEnabled(!anim);
2088 frame_toolbar->setEnabled(!anim);
2089 toolbar_stack->setEnabled(!anim);
2091 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2092 m_endViewport->setZValue(1100);
2093 QColor col = m_endViewport->pen().color();
2095 m_endViewport->setBrush(col);
2096 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2097 m_endViewport->setSelected(true);
2100 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2102 m_endViewport->setZValue(-1000);
2103 m_endViewport->setBrush(QBrush());
2104 m_endViewport->setFlags(0);
2105 if (!anim_start->isChecked()) deleteAnimInfoText();
2109 void TitleWidget::addAnimInfoText()
2111 // add text to anim viewport
2112 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2113 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2114 QFont font = t->font();
2115 font.setPixelSize(m_startViewport->rect().width() / 10);
2116 QColor col = m_startViewport->pen().color();
2118 t->setDefaultTextColor(col);
2120 font.setPixelSize(m_endViewport->rect().width() / 10);
2121 col = m_endViewport->pen().color();
2123 t2->setDefaultTextColor(col);
2127 void TitleWidget::updateInfoText()
2129 // update info text font
2130 if (!m_startViewport->childItems().isEmpty()) {
2131 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2133 QFont font = item->font();
2134 font.setPixelSize(m_startViewport->rect().width() / 10);
2135 item->setFont(font);
2138 if (!m_endViewport->childItems().isEmpty()) {
2139 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2141 QFont font = item->font();
2142 font.setPixelSize(m_endViewport->rect().width() / 10);
2143 item->setFont(font);
2148 void TitleWidget::deleteAnimInfoText()
2150 // end animation editing, remove info text
2151 while (!m_startViewport->childItems().isEmpty()) {
2152 QGraphicsItem *item = m_startViewport->childItems().at(0);
2153 m_scene->removeItem(item);
2156 while (!m_endViewport->childItems().isEmpty()) {
2157 QGraphicsItem *item = m_endViewport->childItems().at(0);
2158 m_scene->removeItem(item);
2163 void TitleWidget::slotKeepAspect(bool keep)
2165 if (m_endViewport->zValue() == 1100) {
2166 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2167 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2169 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2170 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2174 void TitleWidget::slotResize50()
2176 if (m_endViewport->zValue() == 1100) {
2177 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2178 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2181 void TitleWidget::slotResize100()
2183 if (m_endViewport->zValue() == 1100) {
2184 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2185 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2188 void TitleWidget::slotResize200()
2190 if (m_endViewport->zValue() == 1100) {
2191 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2192 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2195 void TitleWidget::slotAddEffect(int ix)
2197 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2198 int effect = effect_list->itemData(ix).toInt();
2200 if (list.size() == 1) {
2201 if (effect == NOEFFECT)
2202 effect_stack->setHidden(true);
2204 effect_stack->setCurrentIndex(effect - 1);
2205 effect_stack->setHidden(false);
2207 } else // Hide the effects stack when more than one element is selected.
2208 effect_stack->setHidden(true);
2210 foreach(QGraphicsItem * item, list) {
2213 item->setData(100, QVariant());
2214 #if QT_VERSION >= 0x040600
2215 item->setGraphicsEffect(0);
2218 case TYPEWRITEREFFECT:
2220 * Allow the user to set the typewriter effect to more than one
2221 * element, but do not add it to non-text elements.
2223 if (item->type() == TEXTITEM) {
2224 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2225 item->setData(100, effdata);
2228 #if QT_VERSION >= 0x040600
2229 // Do not remove the non-QGraphicsEffects.
2231 item->setGraphicsEffect(new QGraphicsBlurEffect());
2234 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2241 void TitleWidget::slotFontText(const QString& s)
2244 if (f.exactMatch()) {
2245 // Font really exists (could also just be a «d» if the user
2246 // starts typing «dejavu» for example).
2247 font_family->setCurrentFont(f);
2249 // Note: Typing dejavu serif does not recognize the font (takes sans)
2250 // in older Qt versions. Case must match there (except for first letter)
2253 void TitleWidget::slotEditTypewriter(int /*ix*/)
2255 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2256 if (l.size() == 1) {
2257 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2258 l[0]->setData(100, effdata);
2262 void TitleWidget::slotEditBlur(int ix)
2264 #if QT_VERSION < 0x040600
2267 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2268 if (l.size() == 1) {
2269 QGraphicsEffect *eff = l[0]->graphicsEffect();
2270 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2271 if (blur) blur->setBlurRadius(ix);
2276 void TitleWidget::slotEditShadow()
2278 #if QT_VERSION < 0x040600
2281 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2282 if (l.size() == 1) {
2283 QGraphicsEffect *eff = l[0]->graphicsEffect();
2284 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2286 shadow->setBlurRadius(shadow_radius->value());
2287 shadow->setOffset(shadow_x->value(), shadow_y->value());
2293 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2295 qreal bound = maxBound ? -99 : 99;
2296 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2298 QList<QGraphicsItem*> lItems;
2299 // Get items (all or intersecting only)
2300 if (intersectingOnly) {
2301 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2303 lItems = graphicsView->scene()->items();
2305 if (lItems.size() > 0) {
2306 int n = lItems.size();
2309 for (int i = 0; i < n; i++) {
2310 z = lItems[i]->zValue();
2311 if (z > bound && !lItems[i]->isSelected()) {
2313 } else if (z - 1 > bound) {
2314 // To get the maximum index even if it is of an item of the current selection.
2315 // Used when updating multiple items, to get all to the same level.
2316 // Otherwise, the maximum would stay at -99 if the highest item is in the selection.
2321 // Get minimum z index.
2322 for (int i = 0; i < n; i++) {
2323 z = lItems[i]->zValue();
2324 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2325 // There are items at the very bottom (background e.g.) with z-index < -1000.
2327 } else if (z + 1 < bound && z > -999) {
2337 void TitleWidget::slotZIndexUp()
2339 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2340 if (l.size() >= 1) {
2341 qreal currentZ = l[0]->zValue();
2342 qreal max = zIndexBounds(true, true);
2343 if (currentZ <= max) {
2344 l[0]->setZValue(currentZ + 1);
2345 updateDimension(l[0]);
2350 void TitleWidget::slotZIndexTop()
2352 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2353 qreal max = zIndexBounds(true, false);
2354 std::cout << "Max z-index is " << max << ".\n";
2355 for (int i = 0; i < l.size(); i++) {
2356 qreal currentZ = l[i]->zValue();
2357 if (currentZ <= max) {
2358 std::cout << "Updating item " << i << ", is " << currentZ << ".\n";
2359 l[i]->setZValue(max + 1);
2361 std::cout << "Not updating " << i << ", is " << currentZ << ".\n";
2364 // Update the z index value in the GUI
2366 updateDimension(l[0]);
2370 void TitleWidget::slotZIndexDown()
2372 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2373 if (l.size() >= 1) {
2374 qreal currentZ = l[0]->zValue();
2375 qreal min = zIndexBounds(false, true);
2376 if (currentZ >= min) {
2377 l[0]->setZValue(currentZ - 1);
2378 updateDimension(l[0]);
2383 void TitleWidget::slotZIndexBottom()
2385 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2386 qreal min = zIndexBounds(false, false);
2387 for (int i = 0; i < l.size(); i++) {
2388 qreal currentZ = l[i]->zValue();
2389 if (currentZ >= min) {
2390 l[i]->setZValue(min - 1);
2393 // Update the z index value in the GUI
2395 updateDimension(l[0]);
2399 void TitleWidget::slotSelectAll()
2401 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2402 for (int i = 0; i < l.size(); i++) {
2403 l.at(i)->setSelected(true);
2407 void TitleWidget::selectItems(int itemType)
2409 QList<QGraphicsItem*> l;
2410 if (graphicsView->scene()->selectedItems().size() > 0) {
2411 l = graphicsView->scene()->selectedItems();
2412 for (int i = 0; i < l.size(); i++) {
2413 if (l.at(i)->type() != itemType) {
2414 l.at(i)->setSelected(false);
2418 l = graphicsView->scene()->items();
2419 for (int i = 0; i < l.size(); i++) {
2420 if (l.at(i)->type() == itemType) {
2421 l.at(i)->setSelected(true);
2427 void TitleWidget::slotSelectText()
2429 selectItems(TEXTITEM);
2432 void TitleWidget::slotSelectRects()
2434 selectItems(RECTITEM);
2437 void TitleWidget::slotSelectImages()
2439 selectItems(IMAGEITEM);
2442 void TitleWidget::slotSelectNone()
2444 graphicsView->blockSignals(true);
2445 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2446 for (int i = 0; i < l.size(); i++) {
2447 l.at(i)->setSelected(false);
2449 graphicsView->blockSignals(false);
2453 QString TitleWidget::getTooltipWithShortcut(const QString &text, QAction *button)
2455 return text + " <b>" + button->shortcut().toString() + "</b>";
2458 void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
2460 // Let some GUI elements block signals. We may want to change their values without any sideeffects.
2461 // Additionally, store the previous blocking state to avoid side effects when this function is called from within another one.
2462 // Note: Disabling an element also blocks signals. So disabled elements don't need to be set to blocking too.
2463 bool blockOX = origin_x_left->signalsBlocked();
2464 bool blockOY = origin_y_top->signalsBlocked();
2465 bool blockEff = effect_list->signalsBlocked();
2466 bool blockRX = itemrotatex->signalsBlocked();
2467 bool blockRY = itemrotatey->signalsBlocked();
2468 bool blockRZ = itemrotatez->signalsBlocked();
2469 bool blockZoom = itemzoom->signalsBlocked();
2470 bool blockX = value_x->signalsBlocked();
2471 bool blockY = value_y->signalsBlocked();
2472 bool blockW = value_w->signalsBlocked();
2473 bool blockH = value_h->signalsBlocked();
2474 origin_x_left->blockSignals(true);
2475 origin_y_top->blockSignals(true);
2476 effect_list->blockSignals(true);
2477 itemrotatex->blockSignals(true);
2478 itemrotatey->blockSignals(true);
2479 itemrotatez->blockSignals(true);
2480 itemzoom->blockSignals(true);
2481 value_x->blockSignals(true);
2482 value_y->blockSignals(true);
2483 value_w->blockSignals(true);
2484 value_h->blockSignals(true);
2486 if (referenceItem == NULL) {
2487 std::cout << "NULL item.\n";
2488 effect_stack->setHidden(true);
2489 effect_frame->setEnabled(false);
2490 effect_list->setCurrentIndex(0);
2491 origin_x_left->setChecked(false);
2492 origin_y_top->setChecked(false);
2493 updateTextOriginX();
2494 updateTextOriginY();
2495 enableToolbars(TITLE_SELECT);
2496 showToolbars(TITLE_SELECT);
2498 itemzoom->setEnabled(false);
2499 itemrotatex->setEnabled(false);
2500 itemrotatey->setEnabled(false);
2501 itemrotatez->setEnabled(false);
2502 frame_properties->setEnabled(false);
2504 effect_frame->setEnabled(true);
2505 frame_properties->setEnabled(true);
2506 if (referenceItem != m_startViewport && referenceItem != m_endViewport) {
2507 itemzoom->setEnabled(true);
2508 itemrotatex->setEnabled(true);
2509 itemrotatey->setEnabled(true);
2510 itemrotatez->setEnabled(true);
2512 itemzoom->setEnabled(false);
2513 itemrotatex->setEnabled(false);
2514 itemrotatey->setEnabled(false);
2515 itemrotatez->setEnabled(false);
2518 if (referenceItem->type() == TEXTITEM) {
2519 showToolbars(TITLE_TEXT);
2520 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(referenceItem);
2521 if (!i->data(100).isNull()) {
2522 // Item has an effect
2523 QStringList effdata = i->data(100).toStringList();
2524 QString effectName = effdata.takeFirst();
2525 if (effectName == "typewriter") {
2526 QStringList params = effdata.at(0).split(';');
2527 typewriter_delay->setValue(params.at(0).toInt());
2528 typewriter_start->setValue(params.at(1).toInt());
2529 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
2530 effect_stack->setHidden(false);
2533 #if QT_VERSION >= 0x040600
2534 if (i->graphicsEffect()) {
2535 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
2537 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
2538 int rad = (int) blur->blurRadius();
2539 blur_radius->setValue(rad);
2540 effect_stack->setHidden(false);
2542 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
2544 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
2545 shadow_radius->setValue(shad->blurRadius());
2546 shadow_x->setValue(shad->xOffset());
2547 shadow_y->setValue(shad->yOffset());
2548 effect_stack->setHidden(false);
2552 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2553 effect_stack->setHidden(true);
2556 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2557 effect_stack->setHidden(true);
2560 font_size->blockSignals(true);
2561 font_family->blockSignals(true);
2562 font_weight_box->blockSignals(true);
2563 buttonItalic->blockSignals(true);
2564 buttonUnder->blockSignals(true);
2565 fontColorButton->blockSignals(true);
2566 #if not KDE_IS_VERSION(4,5,0)
2567 textAlpha->blockSignals(true);
2569 buttonAlignLeft->blockSignals(true);
2570 buttonAlignRight->blockSignals(true);
2571 buttonAlignNone->blockSignals(true);
2572 buttonAlignCenter->blockSignals(true);
2574 QFont font = i->font();
2575 font_family->setCurrentFont(font);
2576 font_size->setValue(font.pixelSize());
2577 m_scene->slotUpdateFontSize(font.pixelSize());
2578 buttonItalic->setChecked(font.italic());
2579 buttonUnder->setChecked(font.underline());
2580 setFontBoxWeight(font.weight());
2582 QTextCursor cursor(i->document());
2583 cursor.select(QTextCursor::Document);
2584 QColor color = cursor.charFormat().foreground().color();
2585 #if not KDE_IS_VERSION(4,5,0)
2586 textAlpha->setValue(color.alpha());
2587 color.setAlpha(255);
2589 fontColorButton->setColor(color);
2591 if (!i->data(101).isNull()) {
2592 textOutline->blockSignals(true);
2593 textOutline->setValue(i->data(101).toDouble() * 10);
2594 textOutline->blockSignals(false);
2596 if (!i->data(102).isNull()) {
2597 textOutlineColor->blockSignals(true);
2598 color = QColor(i->data(102).toString());
2599 #if not KDE_IS_VERSION(4,5,0)
2600 textOutlineAlpha->blockSignals(true);
2601 textOutlineAlpha->setValue(color.alpha());
2602 color.setAlpha(255);
2603 textOutlineAlpha->blockSignals(false);
2605 textOutlineColor->setColor(color);
2606 textOutlineColor->blockSignals(false);
2608 QTextCursor cur = i->textCursor();
2609 QTextBlockFormat format = cur.blockFormat();
2610 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
2611 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
2612 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
2613 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
2615 font_size->blockSignals(false);
2616 font_family->blockSignals(false);
2617 font_weight_box->blockSignals(false);
2618 buttonItalic->blockSignals(false);
2619 buttonUnder->blockSignals(false);
2620 fontColorButton->blockSignals(false);
2621 #if not KDE_IS_VERSION(4,5,0)
2622 textAlpha->blockSignals(false);
2624 buttonAlignLeft->blockSignals(false);
2625 buttonAlignRight->blockSignals(false);
2626 buttonAlignNone->blockSignals(false);
2627 buttonAlignCenter->blockSignals(false);
2629 // mbt 1607: Select text if the text item is an unchanged template item.
2630 if (i->property("isTemplate").isValid()) {
2631 cur.setPosition(0, QTextCursor::MoveAnchor);
2632 cur.select(QTextCursor::Document);
2633 i->setTextCursor(cur);
2634 // Make text editable now.
2636 i->setTextInteractionFlags(Qt::TextEditorInteraction);
2639 updateAxisButtons(i);
2640 updateCoordinates(i);
2642 enableToolbars(TITLE_TEXT);
2644 } else if ((referenceItem)->type() == RECTITEM) {
2645 showToolbars(TITLE_RECTANGLE);
2647 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(referenceItem);
2648 if (rec == m_startViewport || rec == m_endViewport) {
2649 /*toolBox->setCurrentIndex(3);
2650 toolBox->widget(0)->setEnabled(false);
2651 toolBox->widget(1)->setEnabled(false);*/
2652 enableToolbars(TITLE_SELECT);
2654 /*toolBox->widget(0)->setEnabled(true);
2655 toolBox->widget(1)->setEnabled(true);
2656 toolBox->setCurrentIndex(0);*/
2657 //toolBox->setItemEnabled(3, true);
2658 #if not KDE_IS_VERSION(4,5,0)
2659 rectFAlpha->setValue(rec->pen().color().alpha());
2660 rectBAlpha->setValue(rec->brush().color().alpha());
2662 //kDebug() << rec->brush().color().alpha();
2663 QColor fcol = rec->pen().color();
2664 QColor bcol = rec->brush().color();
2665 //fcol.setAlpha(255);
2666 //bcol.setAlpha(255);
2667 rectFColor->setColor(fcol);
2668 rectBColor->setColor(bcol);
2670 rectLineWidth->setValue(rec->pen().width());
2671 enableToolbars(TITLE_RECTANGLE);
2674 updateAxisButtons(referenceItem);
2675 updateCoordinates(rec);
2676 updateDimension(rec);
2678 } else if (referenceItem->type() == IMAGEITEM) {
2679 showToolbars(TITLE_IMAGE);
2681 updateCoordinates(referenceItem);
2682 updateDimension(referenceItem);
2684 enableToolbars(TITLE_IMAGE);
2687 //toolBox->setCurrentIndex(0);
2688 showToolbars(TITLE_SELECT);
2689 enableToolbars(TITLE_SELECT);
2690 frame_properties->setEnabled(false);
2692 zValue->setValue((int)referenceItem->zValue());
2693 if (!referenceItem->data(ZOOMFACTOR).isNull()) itemzoom->setValue(referenceItem->data(ZOOMFACTOR).toInt());
2694 else itemzoom->setValue((int)(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
2695 itemrotatex->setValue((int)(m_transformations.value(referenceItem).rotatex));
2696 itemrotatey->setValue((int)(m_transformations.value(referenceItem).rotatey));
2697 itemrotatez->setValue((int)(m_transformations.value(referenceItem).rotatez));
2701 effect_list->blockSignals(blockEff);
2702 itemrotatex->blockSignals(blockRX);
2703 itemrotatey->blockSignals(blockRY);
2704 itemrotatez->blockSignals(blockRZ);
2705 itemzoom->blockSignals(blockZoom);
2706 origin_x_left->blockSignals(blockOX);
2707 origin_y_top->blockSignals(blockOY);
2708 value_x->blockSignals(blockX);
2709 value_y->blockSignals(blockY);
2710 value_w->blockSignals(blockW);
2711 value_h->blockSignals(blockH);