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 // Set combo sliders values
83 textAlpha->setMinimum(0);
84 textAlpha->setMaximum(255);
85 textAlpha->setDecimals(0);
86 textAlpha->setValue(255);
87 textAlpha->setToolTip(i18n("Font color opacity"));
89 textOutlineAlpha->setMinimum(0);
90 textOutlineAlpha->setMaximum(255);
91 textOutlineAlpha->setDecimals(0);
92 textOutlineAlpha->setValue(255);
93 textOutlineAlpha->setToolTip(i18n("Outline color opacity"));
95 textOutline->setMinimum(0);
96 textOutline->setMaximum(200);
97 textOutline->setDecimals(0);
98 textOutline->setValue(0);
99 textOutline->setToolTip(i18n("Outline width"));
101 backgroundAlpha->setMinimum(0);
102 backgroundAlpha->setMaximum(255);
103 backgroundAlpha->setDecimals(0);
104 backgroundAlpha->setValue(0);
105 backgroundAlpha->setToolTip(i18n("Background color opacity"));
107 itemrotatex->setMinimum(-360);
108 itemrotatex->setMaximum(360);
109 itemrotatex->setDecimals(0);
110 itemrotatex->setValue(0);
111 itemrotatex->setToolTip(i18n("Rotation around the X axis"));
113 itemrotatey->setMinimum(-360);
114 itemrotatey->setMaximum(360);
115 itemrotatey->setDecimals(0);
116 itemrotatey->setValue(0);
117 itemrotatey->setToolTip(i18n("Rotation around the Y axis"));
119 itemrotatez->setMinimum(-360);
120 itemrotatez->setMaximum(360);
121 itemrotatez->setDecimals(0);
122 itemrotatez->setValue(0);
123 itemrotatez->setToolTip(i18n("Rotation around the Z axis"));
125 rectBAlpha->setMinimum(0);
126 rectBAlpha->setMaximum(255);
127 rectBAlpha->setDecimals(0);
128 rectBAlpha->setValue(255);
129 rectBAlpha->setToolTip(i18n("Color opacity"));
131 rectFAlpha->setMinimum(0);
132 rectFAlpha->setMaximum(255);
133 rectFAlpha->setDecimals(0);
134 rectFAlpha->setValue(255);
135 rectFAlpha->setToolTip(i18n("Border opacity"));
137 rectLineWidth->setMinimum(0);
138 rectLineWidth->setMaximum(100);
139 rectLineWidth->setDecimals(0);
140 rectLineWidth->setValue(0);
141 rectLineWidth->setToolTip(i18n("Border width"));
143 itemzoom->setSuffix(i18n("%"));
144 m_frameWidth = render->renderWidth();
145 m_frameHeight = render->renderHeight();
146 showToolbars(TITLE_SELECT);
148 splitter->setStretchFactor(0, 20);
150 //If project is drop frame, set the input mask as such.
151 title_duration->setInputMask("");
152 title_duration->setValidator(m_tc.validator());
153 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
155 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
156 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
158 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
159 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
160 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
161 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
162 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
163 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
164 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
165 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
167 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
169 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
170 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
171 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
172 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
173 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
175 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
176 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
177 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
178 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
179 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
180 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
183 effect_list->addItem(i18n("None"), NOEFFECT);
184 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
185 effect_list->addItem(i18n("Blur"), BLUREFFECT);
188 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
189 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
190 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
191 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
192 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
193 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
194 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
195 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
196 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
197 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
198 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
199 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
200 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
201 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
202 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
203 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
204 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
205 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
206 effect_stack->setHidden(true);
207 effect_frame->setEnabled(false);
209 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
210 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
213 m_signalMapper = new QSignalMapper(this);
214 m_signalMapper->setMapping(value_w, ValueWidth);
215 m_signalMapper->setMapping(value_h, ValueHeight);
216 m_signalMapper->setMapping(value_x, ValueX);
217 m_signalMapper->setMapping(value_y, ValueY);
218 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
219 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
220 connect(value_x, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
221 connect(value_y, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
222 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
224 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
225 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
226 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
227 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
228 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
229 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
230 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
231 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
232 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
234 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
237 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
239 font_weight_box->blockSignals(true);
240 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
241 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
242 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
243 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
244 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
245 font_weight_box->setToolTip(i18n("Font weight"));
246 font_weight_box->setCurrentIndex(1);
247 font_weight_box->blockSignals(false);
249 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
250 buttonRealSize->setIcon(KIcon("zoom-original"));
251 buttonItalic->setIcon(KIcon("format-text-italic"));
252 buttonUnder->setIcon(KIcon("format-text-underline"));
253 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
254 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
255 buttonAlignRight->setIcon(KIcon("format-justify-right"));
256 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
258 buttonAlignNone->setToolTip(i18n("No alignment"));
259 buttonAlignRight->setToolTip(i18n("Align right"));
260 buttonAlignLeft->setToolTip(i18n("Align left"));
261 buttonAlignCenter->setToolTip(i18n("Align center"));
263 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
264 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
265 m_unicodeAction->setToolTip(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
266 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
267 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
269 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
270 m_zUp->setShortcut(Qt::Key_PageUp);
271 m_zUp->setToolTip(i18n("Raise object"));
272 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
273 zUp->setDefaultAction(m_zUp);
275 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
276 m_zDown->setShortcut(Qt::Key_PageDown);
277 m_zDown->setToolTip(i18n("Lower object"));
278 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
279 zDown->setDefaultAction(m_zDown);
281 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
282 // TODO mbt 1414: Shortcut should change z index only if
283 // cursor is NOT in a text field ...
284 //m_zTop->setShortcut(Qt::Key_Home);
285 m_zTop->setToolTip(i18n("Raise object to top"));
286 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
287 zTop->setDefaultAction(m_zTop);
289 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
291 //m_zBottom->setShortcut(Qt::Key_End);
292 m_zBottom->setToolTip(i18n("Lower object to bottom"));
293 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
294 zBottom->setDefaultAction(m_zBottom);
296 m_selectAll = new QAction(KIcon("kdenlive-select-all"), QString(), this);
297 m_selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
298 connect(m_selectAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
299 buttonSelectAll->setDefaultAction(m_selectAll);
301 m_selectText = new QAction(KIcon("kdenlive-select-texts"), QString(), this);
302 m_selectText->setShortcut(Qt::CTRL + Qt::Key_T);
303 connect(m_selectText, SIGNAL(triggered()), this, SLOT(slotSelectText()));
304 buttonSelectText->setDefaultAction(m_selectText);
305 buttonSelectText->setEnabled(false);
307 m_selectRects = new QAction(KIcon("kdenlive-select-rects"), QString(), this);
308 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
309 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
310 buttonSelectRects->setDefaultAction(m_selectRects);
311 buttonSelectRects->setEnabled(false);
313 m_selectImages = new QAction(KIcon("kdenlive-select-images"), QString(), this);
314 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
315 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
316 buttonSelectImages->setDefaultAction(m_selectImages);
317 buttonSelectImages->setEnabled(false);
319 m_unselectAll = new QAction(KIcon("kdenlive-unselect-all"), QString(), this);
320 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
321 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
322 buttonUnselectAll->setDefaultAction(m_unselectAll);
323 buttonUnselectAll->setEnabled(false);
325 zDown->setIcon(KIcon("kdenlive-zindex-down"));
326 zTop->setIcon(KIcon("kdenlive-zindex-top"));
327 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
328 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
329 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
330 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
332 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
333 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
334 rectBColor->setToolTip(i18n("Select fill color"));
335 rectFColor->setToolTip(i18n("Select border color"));
336 rectBAlpha->setToolTip(i18n("Fill opacity"));
337 rectFAlpha->setToolTip(i18n("Border opacity"));
338 zoom_slider->setToolTip(i18n("Zoom"));
339 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
340 buttonFitZoom->setToolTip(i18n("Fit zoom"));
341 backgroundColor->setToolTip(i18n("Select background color"));
342 backgroundAlpha->setToolTip(i18n("Background opacity"));
343 buttonSelectAll->setToolTip(getTooltipWithShortcut(i18n("Select all"), m_selectAll));
344 buttonSelectText->setToolTip(getTooltipWithShortcut(i18n("Select text items in current selection"), m_selectText));
345 buttonSelectRects->setToolTip(getTooltipWithShortcut(i18n("Select rect items in current selection"), m_selectRects));
346 buttonSelectImages->setToolTip(getTooltipWithShortcut(i18n("Select image items in current selection"), m_selectImages));
347 buttonUnselectAll->setToolTip(getTooltipWithShortcut(i18n("Unselect all"), m_unselectAll));
349 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
350 itemhcenter->setToolTip(i18n("Align item horizontally"));
351 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
352 itemvcenter->setToolTip(i18n("Align item vertically"));
353 itemtop->setIcon(KIcon("kdenlive-align-top"));
354 itemtop->setToolTip(i18n("Align item to top"));
355 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
356 itembottom->setToolTip(i18n("Align item to bottom"));
357 itemright->setIcon(KIcon("kdenlive-align-right"));
358 itemright->setToolTip(i18n("Align item to right"));
359 itemleft->setIcon(KIcon("kdenlive-align-left"));
360 itemleft->setToolTip(i18n("Align item to left"));
363 QHBoxLayout *layout = new QHBoxLayout;
364 frame_toolbar->setLayout(layout);
365 layout->setContentsMargins(0, 0, 0, 0);
366 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
367 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
368 m_toolbar->setIconSize(QSize(s, s));
370 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
371 m_buttonCursor->setCheckable(true);
372 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
373 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
374 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
376 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
377 m_buttonText->setCheckable(true);
378 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
379 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
380 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
382 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
383 m_buttonRect->setCheckable(true);
384 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
385 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
386 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
388 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
389 m_buttonImage->setCheckable(false);
390 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
391 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
392 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
394 m_toolbar->addSeparator();
396 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
397 m_buttonLoad->setCheckable(false);
398 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
399 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
401 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
402 m_buttonSave->setCheckable(false);
403 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
404 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
406 layout->addWidget(m_toolbar);
408 // initialize graphic scene
409 m_scene = new GraphicsSceneRectMove(this);
410 graphicsView->setScene(m_scene);
411 graphicsView->setMouseTracking(true);
412 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
413 graphicsView->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);
414 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
415 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
416 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
418 // a gradient background
419 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
420 gradient->setSpread(QGradient::ReflectSpread);
421 scene->setBackgroundBrush(*gradient);*/
423 QPen framepen(Qt::DotLine);
424 framepen.setColor(Qt::red);
426 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
427 m_frameBorder->setPen(framepen);
428 m_frameBorder->setZValue(-1100);
429 m_frameBorder->setBrush(Qt::transparent);
430 m_frameBorder->setFlags(0);
431 graphicsView->scene()->addItem(m_frameBorder);
433 m_frameImage = new QGraphicsPixmapItem();
435 qtrans.scale(2.0, 2.0);
436 m_frameImage->setTransform(qtrans);
437 m_frameImage->setZValue(-1200);
438 m_frameImage->setFlags(0);
439 displayBackgroundFrame();
440 graphicsView->scene()->addItem(m_frameImage);
442 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
443 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
444 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
445 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
446 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
447 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
448 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
449 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
452 // mbd: load saved settings
455 graphicsView->show();
456 //graphicsView->setRenderHint(QPainter::Antialiasing);
457 graphicsView->setInteractive(true);
458 //graphicsView->resize(400, 300);
459 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
460 //toolBox->setItemEnabled(2, false);
461 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
462 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
463 m_startViewport->setData(0, m_frameWidth);
464 m_startViewport->setData(1, m_frameHeight);
465 m_endViewport->setData(0, m_frameWidth);
466 m_endViewport->setData(1, m_frameHeight);
468 // scale the view so that the title widget is not too big at startup
469 graphicsView->scale(.5, .5);
470 if (!url.isEmpty()) loadTitle(url);
473 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
476 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
477 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
478 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
480 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
481 refreshTitleTemplates();
482 //templateBox->setIconSize(QSize(60,60));
483 templateBox->clear();
484 templateBox->addItem("");
485 foreach(TitleTemplate t, titletemplates) {
486 templateBox->addItem(t.icon, t.name, t.file);
488 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
491 TitleWidget::~TitleWidget()
495 delete m_buttonImage;
496 delete m_buttonCursor;
499 delete m_unicodeAction;
506 delete m_selectRects;
507 delete m_selectImages;
508 delete m_unselectAll;
510 delete m_unicodeDialog;
511 delete m_frameBorder;
513 delete m_startViewport;
514 delete m_endViewport;
516 delete m_signalMapper;
520 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
523 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
524 KStandardDirs::makeDir(titlePath);
525 titlePath.append((isClone == false) ? "title" : "clone");
528 while (path.isEmpty() || QFile::exists(path)) {
530 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
532 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
538 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
541 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
542 KStandardDirs::makeDir(titlePath);
543 return titlePath + titleName + ".png";
547 QStringList TitleWidget::extractImageList(QString xml)
550 if (xml.isEmpty()) return result;
553 QDomNodeList images = doc.elementsByTagName("content");
554 for (int i = 0; i < images.count(); i++) {
555 if (images.at(i).toElement().hasAttribute("url"))
556 result.append(images.at(i).toElement().attribute("url"));
562 QStringList TitleWidget::extractFontList(QString xml)
565 if (xml.isEmpty()) return result;
568 QDomNodeList images = doc.elementsByTagName("content");
569 for (int i = 0; i < images.count(); i++) {
570 if (images.at(i).toElement().hasAttribute("font"))
571 result.append(images.at(i).toElement().attribute("font"));
576 void TitleWidget::refreshTitleTemplates()
578 QStringList titlenamelist = QStringList() << i18n("None");
579 QStringList titlefiles = QStringList() << QString();
581 filters << "*.kdenlivetitle" ;
582 titletemplates.clear();
583 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
584 foreach(const QString & folder, titleTemplates) {
585 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
586 foreach(const QString & fname, filesnames) {
587 //titlenamelist.append(fname);
588 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
591 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
592 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
593 titletemplates.append(t);
596 kDebug() << titlenamelist << titlefiles;
598 void TitleWidget::templateIndexChanged(int index)
600 QString item = templateBox->itemData(index).toString();
602 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
603 if (KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
607 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
608 // Text of unchanged template titles should be selected when clicked.
609 QList<QGraphicsItem *> list = graphicsView->scene()->items();
610 foreach(QGraphicsItem * qgItem, list) {
611 if (qgItem->type() == TEXTITEM) {
612 QGraphicsTextItem *i;
613 i = static_cast<QGraphicsTextItem *>(qgItem);
614 i->setProperty("isTemplate", "true");
615 i->setProperty("templateText", i->toHtml());
619 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
623 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
628 void TitleWidget::slotTextTool()
630 m_scene->setTool(TITLE_TEXT);
631 showToolbars(TITLE_TEXT);
632 checkButton(TITLE_TEXT);
635 void TitleWidget::slotRectTool()
637 m_scene->setTool(TITLE_RECTANGLE);
638 showToolbars(TITLE_RECTANGLE);
639 checkButton(TITLE_RECTANGLE);
641 // Disable dragging mode, would make dragging a rect impossible otherwise ;)
642 graphicsView->setDragMode(QGraphicsView::NoDrag);
645 void TitleWidget::slotSelectTool()
647 m_scene->setTool(TITLE_SELECT);
649 // Enable rubberband selecting mode.
650 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
652 // Find out which toolbars need to be shown, depending on selected item
653 TITLETOOL t = TITLE_SELECT;
654 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
656 switch (l.at(0)->type()) {
670 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
671 //graphicsView->centerOn(l.at(0));
677 updateCoordinates(l.at(0));
678 updateDimension(l.at(0));
679 updateRotZoom(l.at(0));
682 checkButton(TITLE_SELECT);
685 void TitleWidget::slotImageTool()
687 // TODO: find a way to get a list of all supported image types...
688 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";
689 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
690 if (!url.isEmpty()) {
691 if (url.path().endsWith(".svg")) {
692 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
693 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
694 svg->setZValue(m_count++);
695 svg->setData(Qt::UserRole, url.path());
696 graphicsView->scene()->addItem(svg);
698 QPixmap pix(url.path());
699 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
700 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
701 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
702 image->setData(Qt::UserRole, url.path());
703 image->setZValue(m_count++);
704 graphicsView->scene()->addItem(image);
707 m_scene->setTool(TITLE_SELECT);
708 showToolbars(TITLE_SELECT);
709 checkButton(TITLE_SELECT);
712 void TitleWidget::showToolbars(TITLETOOL toolType)
716 toolbar_stack->setCurrentIndex(0);
719 toolbar_stack->setCurrentIndex(3);
721 case TITLE_RECTANGLE:
722 toolbar_stack->setCurrentIndex(1);
725 toolbar_stack->setCurrentIndex(2);
730 void TitleWidget::enableToolbars(TITLETOOL toolType)
732 // TITLETOOL is defined in graphicsscenerectmove.h
734 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
735 value_w->setEnabled(enable);
736 value_h->setEnabled(enable);
739 void TitleWidget::checkButton(TITLETOOL toolType)
741 bool bSelect = false;
753 case TITLE_RECTANGLE:
763 m_buttonCursor->setChecked(bSelect);
764 m_buttonText->setChecked(bText);
765 m_buttonRect->setChecked(bRect);
766 m_buttonImage->setChecked(bImage);
769 void TitleWidget::displayBackgroundFrame()
771 QRectF r = m_frameBorder->sceneBoundingRect();
772 if (!displayBg->isChecked()) {
773 QPixmap pattern(20, 20);
775 QColor bgcolor(210, 210, 210);
776 QPainter p(&pattern);
777 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
778 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
781 QPixmap bg((int) (r.width() / 2), (int) (r.height()/ 2));
783 p2.fillRect(bg.rect(), br);
785 m_frameImage->setPixmap(bg);
787 QImage img = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), QString(), m_render->frameRenderWidth() / 2, m_render->renderHeight() / 2);
788 m_frameImage->setPixmap(QPixmap::fromImage(img.scaled(r.width() / 2, r.height() / 2)));
792 void TitleWidget::initAnimation()
794 align_box->setEnabled(false);
795 QPen startpen(Qt::DotLine);
796 QPen endpen(Qt::DashDotLine);
797 startpen.setColor(QColor(100, 200, 100, 140));
798 endpen.setColor(QColor(200, 100, 100, 140));
800 m_startViewport->setPen(startpen);
801 m_endViewport->setPen(endpen);
803 m_startViewport->setZValue(-1000);
804 m_endViewport->setZValue(-1000);
806 m_startViewport->setFlags(0);
807 m_endViewport->setFlags(0);
809 graphicsView->scene()->addItem(m_startViewport);
810 graphicsView->scene()->addItem(m_endViewport);
812 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
813 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
814 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
815 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
818 void TitleWidget::slotUpdateZoom(int pos)
820 m_scene->setZoom((double) pos / 100);
821 zoom_label->setText(QString::number(pos) + '%');
824 void TitleWidget::slotZoom(bool up)
826 int pos = zoom_slider->value();
829 zoom_slider->setValue(pos);
832 void TitleWidget::slotAdjustZoom()
834 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
835 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
836 if (scalex > scaley) scalex = scaley;
837 int zoompos = (int)(scalex * 7 + 0.5);*/
838 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
839 int zoompos = graphicsView->matrix().m11() * 100;
840 zoom_slider->setValue(zoompos);
841 graphicsView->centerOn(m_frameBorder);
844 void TitleWidget::slotZoomOneToOne()
846 zoom_slider->setValue(100);
847 graphicsView->centerOn(m_frameBorder);
850 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
852 updateAxisButtons(rect); // back to default
854 QColor f = rectFColor->color();
855 f.setAlpha(rectFAlpha->value());
857 penf.setWidth(rectLineWidth->value());
858 penf.setJoinStyle(Qt::RoundJoin);
860 QColor b = rectBColor->color();
861 b.setAlpha(rectBAlpha->value());
862 rect->setBrush(QBrush(b));
863 rect->setZValue(m_count++);
864 rect->setData(ZOOMFACTOR, 100);
865 //setCurrentItem(rect);
866 //graphicsView->setFocus();
869 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
871 updateAxisButtons(tt); // back to default
873 QFont font = font_family->currentFont();
874 font.setPixelSize(font_size->value());
876 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
877 font.setItalic(buttonItalic->isChecked());
878 font.setUnderline(buttonUnder->isChecked());
881 QColor color = fontColorButton->color();
882 color.setAlpha(textAlpha->value());
883 tt->setDefaultTextColor(color);
885 QTextCursor cur(tt->document());
886 cur.select(QTextCursor::Document);
887 QTextBlockFormat format = cur.blockFormat();
888 QTextCharFormat cformat = cur.charFormat();
889 QColor outlineColor = textOutlineColor->color();
890 outlineColor.setAlpha(textOutlineAlpha->value());
891 double outlineWidth = textOutline->value() / 10.0;
893 tt->setData(101, outlineWidth);
894 tt->setData(102, outlineColor);
895 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
897 cformat.setForeground(QBrush(color));
898 cur.setCharFormat(cformat);
899 cur.setBlockFormat(format);
900 tt->setTextCursor(cur);
901 tt->setZValue(m_count++);
905 void TitleWidget::setFontBoxWeight(int weight)
907 int index = font_weight_box->findData(weight);
909 index = font_weight_box->findData(QFont::Normal);
911 font_weight_box->setCurrentIndex(index);
914 void TitleWidget::setCurrentItem(QGraphicsItem *item)
916 m_scene->setSelectedItem(item);
919 void TitleWidget::zIndexChanged(int v)
921 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
922 for (int i = 0; i < l.size(); i++) {
927 void TitleWidget::selectionChanged()
929 if (m_scene->tool() != TITLE_SELECT) return;
931 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
933 QList<QGraphicsItem *> l;
935 // mbt 1607: One text item might have grabbed the keyboard.
936 // Ungrab it for all items that are not selected, otherwise
937 // text input would only work for the text item that grabbed
938 // the keyboard last.
939 l = graphicsView->scene()->items();
940 foreach(QGraphicsItem * item, l) {
941 if (item->type() == TEXTITEM && !item->isSelected()) {
942 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
947 l = graphicsView->scene()->selectedItems();
950 buttonUnselectAll->setEnabled(true);
951 // Enable all z index buttons if items selected.
952 // We can selectively disable them later.
953 zUp->setEnabled(true);
954 zDown->setEnabled(true);
955 zTop->setEnabled(true);
956 zBottom->setEnabled(true);
958 buttonUnselectAll->setEnabled(false);
961 buttonSelectText->setEnabled(true);
962 buttonSelectRects->setEnabled(true);
963 buttonSelectImages->setEnabled(true);
965 buttonSelectText->setEnabled(false);
966 buttonSelectRects->setEnabled(false);
967 buttonSelectImages->setEnabled(false);
972 } else if (l.size() == 1) {
973 prepareTools(l.at(0));
976 For multiple selected objects we need to decide which tools to show.
978 int firstType = l.at(0)->type();
979 bool allEqual = true;
980 for (int i = 0; i < l.size(); i++) {
981 if (l.at(i)->type() != firstType) {
986 std::cout << "All equal? " << allEqual << ".\n";
988 prepareTools(l.at(0));
990 // Get the default toolset, but enable the property frame (x,y,w,h)
992 frame_properties->setEnabled(true);
994 // Enable x/y/w/h if it makes sense.
995 value_x->setEnabled(true);
996 value_y->setEnabled(true);
997 bool containsTextitem = false;
998 for (int i = 0; i < l.size(); i++) {
999 if (l.at(i)->type() == TEXTITEM) {
1000 containsTextitem = true;
1004 if (!containsTextitem) {
1005 value_w->setEnabled(true);
1006 value_h->setEnabled(true);
1010 // Disable z index buttons if they don't make sense for the current selection
1011 int firstZindex = l.at(0)->zValue();
1013 for (int i = 0; i < l.size(); i++) {
1014 if (l[i]->zValue() != firstZindex) {
1020 zUp->setEnabled(false);
1021 zDown->setEnabled(false);
1029 void TitleWidget::slotValueChanged(int type)
1032 type tells us which QSpinBox value has changed.
1035 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1036 std::cout << l.size() << " items to be resized\n";
1038 // Get the updated value here already to do less coding afterwards
1042 val = value_w->value();
1045 val = value_h->value();
1048 val = value_x->value();
1051 val = value_y->value();
1055 for (int k = 0; k < l.size(); k++) {
1056 std::cout << "Type of item " << k << ": " << l.at(k)->type() << "\n";
1058 if (l.at(k)->type() == TEXTITEM) {
1059 // Just update the position. We don't allow setting width/height for text items yet.
1062 updatePosition(l.at(k), val, l.at(k)->pos().y());
1065 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1069 } else if (l.at(k)->type() == RECTITEM) {
1070 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(k));
1073 updatePosition(l.at(k), val, l.at(k)->pos().y());
1076 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1079 rec->setRect(QRect(0, 0, val, rec->rect().height()));
1082 rec->setRect(QRect(0, 0, rec->rect().width(), val));
1086 } else if (l.at(k)->type() == IMAGEITEM) {
1089 if (type == ValueX) {
1090 updatePosition(l.at(k), val, l.at(k)->pos().y());
1092 } else if (type == ValueY) {
1093 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1096 // Width/height has changed. This is more complex.
1098 QGraphicsItem *i = l.at(k);
1099 Transform t = m_transformations.value(i);
1101 // Ratio width:height
1102 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1103 // TODO: proper calculation for rotation around 3 axes
1104 double alpha = (double) t.rotatez / 180.0 * M_PI;
1107 double length = val;
1112 // We want to keep the aspect ratio of the image as the user does not yet have the possibility
1113 // to restore the original ratio. You rarely want to change it anyway.
1116 // Add 0.5 because otherwise incrementing by 1 might have no effect
1117 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1118 scale = length / i->boundingRect().width();
1121 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1122 scale = length / i->boundingRect().height();
1129 qtrans.scale(scale, scale);
1130 qtrans.rotate(t.rotatex, Qt::XAxis);
1131 qtrans.rotate(t.rotatey, Qt::YAxis);
1132 qtrans.rotate(t.rotatez, Qt::ZAxis);
1133 i->setTransform(qtrans);
1134 std::cout << "scale is: " << scale << "\n";
1135 std::cout << i->boundingRect().width() << ": new width\n";
1136 m_transformations[i] = t;
1138 if (l.size() == 1) {
1139 // Only update the w/h values if the selection contains just one item.
1140 // Otherwise, what should we do? ;)
1141 // (Use the values of the first item? Of the second? Of the x-th?)
1143 // Update rotation/zoom values.
1144 // These values are not yet able to handle multiple items!
1155 void TitleWidget::updateDimension(QGraphicsItem *i)
1157 bool wBlocked = value_w->signalsBlocked();
1158 bool hBlocked = value_h->signalsBlocked();
1159 bool zBlocked = zValue->signalsBlocked();
1160 value_w->blockSignals(true);
1161 value_h->blockSignals(true);
1162 zValue->blockSignals(true);
1164 zValue->setValue((int) i->zValue());
1165 if (i->type() == IMAGEITEM) {
1166 // Get multipliers for rotation/scaling
1168 /*Transform t = m_transformations.value(i);
1169 QRectF r = i->boundingRect();
1170 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1171 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1172 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1173 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1175 value_w->setValue(i->sceneBoundingRect().width());
1176 value_h->setValue(i->sceneBoundingRect().height());
1177 } else if (i->type() == RECTITEM) {
1178 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1179 std::cout << "Rect width is: " << r->rect().width() << ", was: " << value_w->value() << "\n";
1180 value_w->setValue((int) r->rect().width());
1181 value_h->setValue((int) r->rect().height());
1182 } else if (i->type() == TEXTITEM) {
1183 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1184 value_w->setValue((int) t->boundingRect().width());
1185 value_h->setValue((int) t->boundingRect().height());
1188 zValue->blockSignals(zBlocked);
1189 value_w->blockSignals(wBlocked);
1190 value_h->blockSignals(hBlocked);
1193 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1195 // Block signals emitted by this method
1196 value_x->blockSignals(true);
1197 value_y->blockSignals(true);
1199 if (i->type() == TEXTITEM) {
1201 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1203 // Set the correct x coordinate value
1204 if (origin_x_left->isChecked()) {
1205 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1206 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1208 // Origin is at 0 (default)
1209 value_x->setValue((int) rec->pos().x());
1213 if (origin_y_top->isChecked()) {
1214 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1216 value_y->setValue((int) rec->pos().y());
1219 } else if (i->type() == RECTITEM) {
1221 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1223 if (origin_x_left->isChecked()) {
1224 // Origin (0 point) is at m_frameWidth
1225 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1227 // Origin is at 0 (default)
1228 value_x->setValue((int) rec->pos().x());
1231 if (origin_y_top->isChecked()) {
1232 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1234 value_y->setValue((int) rec->pos().y());
1237 } else if (i->type() == IMAGEITEM) {
1239 if (origin_x_left->isChecked()) {
1240 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1242 value_x->setValue((int) i->pos().x());
1245 if (origin_y_top->isChecked()) {
1246 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1248 value_y->setValue((int) i->pos().y());
1253 // Stop blocking signals now
1254 value_x->blockSignals(false);
1255 value_y->blockSignals(false);
1258 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1260 itemzoom->blockSignals(true);
1261 itemrotatex->blockSignals(true);
1262 itemrotatey->blockSignals(true);
1263 itemrotatez->blockSignals(true);
1265 Transform t = m_transformations.value(i);
1267 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1268 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1270 itemrotatex->setValue((int)(t.rotatex));
1271 itemrotatey->setValue((int)(t.rotatey));
1272 itemrotatez->setValue((int)(t.rotatez));
1274 itemzoom->blockSignals(false);
1275 itemrotatex->blockSignals(false);
1276 itemrotatey->blockSignals(false);
1277 itemrotatez->blockSignals(false);
1280 void TitleWidget::updatePosition(QGraphicsItem *i)
1282 updatePosition(i, value_x->value(), value_y->value());
1285 void TitleWidget::updatePosition(QGraphicsItem *i, int x, int y)
1287 if (i->type() == TEXTITEM) {
1288 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1291 if (origin_x_left->isChecked()) {
1293 * Origin of the X axis is at m_frameWidth, and distance from right
1294 * border of the item to the right border of the frame is taken. See
1295 * comment to slotOriginXClicked().
1297 posX = m_frameWidth - x - rec->boundingRect().width();
1303 if (origin_y_top->isChecked()) {
1304 /* Same for y axis */
1305 posY = m_frameHeight - y - rec->boundingRect().height();
1310 rec->setPos(posX, posY);
1312 } else if (i->type() == RECTITEM) {
1314 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1317 if (origin_x_left->isChecked()) {
1318 posX = m_frameWidth - x - rec->rect().width();
1324 if (origin_y_top->isChecked()) {
1325 posY = m_frameHeight - y - rec->rect().height();
1330 rec->setPos(posX, posY);
1332 } else if (i->type() == IMAGEITEM) {
1334 if (origin_x_left->isChecked()) {
1335 // Use the sceneBoundingRect because this also regards transformations like zoom
1336 posX = m_frameWidth - x - i->sceneBoundingRect().width();
1342 if (origin_y_top->isChecked()) {
1343 posY = m_frameHeight - y - i->sceneBoundingRect().height();
1348 i->setPos(posX, posY);
1354 void TitleWidget::updateTextOriginX()
1356 if (origin_x_left->isChecked()) {
1357 origin_x_left->setText(i18n("\u2212X"));
1359 origin_x_left->setText(i18n("+X"));
1363 void TitleWidget::slotOriginXClicked()
1365 // Update the text displayed on the button.
1366 updateTextOriginX();
1368 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1369 if (l.size() >= 1) {
1370 updateCoordinates(l.at(0));
1372 // Remember x axis setting
1373 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1374 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1376 graphicsView->setFocus();
1379 void TitleWidget::updateTextOriginY()
1381 if (origin_y_top->isChecked()) {
1382 origin_y_top->setText(i18n("\u2212Y"));
1384 origin_y_top->setText(i18n("+Y"));
1388 void TitleWidget::slotOriginYClicked()
1390 // Update the text displayed on the button.
1391 updateTextOriginY();
1393 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1394 if (l.size() >= 1) {
1395 updateCoordinates(l.at(0));
1397 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1398 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1401 graphicsView->setFocus();
1404 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1406 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1407 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1408 origin_x_left->blockSignals(true);
1409 origin_y_top->blockSignals(true);
1411 if (xAxis == TitleDocument::AxisInverted) {
1412 origin_x_left->setChecked(true);
1414 origin_x_left->setChecked(false);
1416 updateTextOriginX();
1418 if (yAxis == TitleDocument::AxisInverted) {
1419 origin_y_top->setChecked(true);
1421 origin_y_top->setChecked(false);
1423 updateTextOriginY();
1425 origin_x_left->blockSignals(false);
1426 origin_y_top->blockSignals(false);
1429 void TitleWidget::slotChangeBackground()
1431 QColor color = backgroundColor->color();
1432 color.setAlpha(backgroundAlpha->value());
1433 m_frameBorder->setBrush(QBrush(color));
1436 void TitleWidget::slotChanged()
1438 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1439 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1440 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1444 void TitleWidget::textChanged(QGraphicsTextItem *i)
1447 * If the user has set origin_x_left (the same for y), we need to look
1448 * whether a text element has been selected. If yes, we need to ensure that
1449 * the right border of the text field remains fixed also when some text has
1452 * This is also known as right-justified, with the difference that it is not
1453 * valid for text but for its boundingRect. Text may still be
1458 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1459 if (!i->toPlainText().isEmpty())
1463 * Don't do anything if the string is empty. If the position were
1464 * updated here, a newly created text field would be set to the
1465 * position of the last selected text field.
1470 // mbt 1607: Template text has changed; don't auto-select content anymore.
1471 if (i->property("isTemplate").isValid()) {
1472 if (i->property("templateText").isValid()) {
1473 if (i->property("templateText") == i->toHtml()) {
1474 // Unchanged, do nothing.
1476 i->setProperty("isTemplate", QVariant::Invalid);
1477 i->setProperty("templateText", QVariant::Invalid);
1483 void TitleWidget::slotInsertUnicode()
1485 m_unicodeDialog->exec();
1488 void TitleWidget::slotInsertUnicodeString(QString text)
1490 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1492 if (l.at(0)->type() == TEXTITEM) {
1493 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1494 t->textCursor().insertText(text);
1499 void TitleWidget::slotUpdateText()
1501 QFont font = font_family->currentFont();
1502 font.setPixelSize(font_size->value());
1503 font.setItalic(buttonItalic->isChecked());
1504 font.setUnderline(buttonUnder->isChecked());
1505 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1506 QColor color = fontColorButton->color();
1507 color.setAlpha(textAlpha->value());
1509 QColor outlineColor = textOutlineColor->color();
1510 outlineColor.setAlpha(textOutlineAlpha->value());
1511 double outlineWidth = textOutline->value() / 10.0;
1514 for (i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1515 QGraphicsTextItem* item = NULL;
1516 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1517 if (l.at(i)->type() == TEXTITEM) {
1518 item = static_cast <QGraphicsTextItem *>(l.at(i));
1521 // No text item, try next one.
1525 // Set alignment of all text in the text item
1526 QTextCursor cur(item->document());
1527 cur.select(QTextCursor::Document);
1528 QTextBlockFormat format = cur.blockFormat();
1529 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1530 item->setTextWidth(item->boundingRect().width());
1531 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1532 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1533 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1535 format.setAlignment(Qt::AlignLeft);
1536 item->setTextWidth(-1);
1539 // Set font properties
1540 item->setFont(font);
1541 QTextCharFormat cformat = cur.charFormat();
1543 item->setData(101, outlineWidth);
1544 item->setData(102, outlineColor);
1545 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1547 cformat.setForeground(QBrush(color));
1548 cur.setCharFormat(cformat);
1549 cur.setBlockFormat(format);
1550 // item->setTextCursor(cur);
1551 cur.clearSelection();
1552 item->setTextCursor(cur);
1553 item->setDefaultTextColor(color);
1557 void TitleWidget::rectChanged()
1559 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1561 for (i = 0; i < l.length(); i++) {
1562 if (l.at(i)->type() == RECTITEM && !settingUp) {
1563 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1564 QColor f = rectFColor->color();
1565 f.setAlpha(rectFAlpha->value());
1567 penf.setWidth(rectLineWidth->value());
1568 penf.setJoinStyle(Qt::RoundJoin);
1570 QColor b = rectBColor->color();
1571 b.setAlpha(rectBAlpha->value());
1572 rec->setBrush(QBrush(b));
1577 void TitleWidget::itemScaled(int val)
1579 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1580 if (l.size() == 1) {
1581 Transform x = m_transformations.value(l.at(0));
1582 x.scalex = (double)val / 100.0;
1583 x.scaley = (double)val / 100.0;
1585 qtrans.scale(x.scalex, x.scaley);
1586 qtrans.rotate(x.rotatex, Qt::XAxis);
1587 qtrans.rotate(x.rotatey, Qt::YAxis);
1588 qtrans.rotate(x.rotatez, Qt::ZAxis);
1589 l[0]->setTransform(qtrans);
1590 l[0]->setData(ZOOMFACTOR, val);
1591 m_transformations[l.at(0)] = x;
1592 updateDimension(l.at(0));
1596 void TitleWidget::itemRotateX(qreal val)
1601 void TitleWidget::itemRotateY(qreal val)
1606 void TitleWidget::itemRotateZ(qreal val)
1611 void TitleWidget::itemRotate(qreal val, int axis)
1613 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1614 if (l.size() == 1) {
1615 Transform x = m_transformations[l.at(0)];
1628 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1631 qtrans.scale(x.scalex, x.scaley);
1632 qtrans.rotate(x.rotatex, Qt::XAxis);
1633 qtrans.rotate(x.rotatey, Qt::YAxis);
1634 qtrans.rotate(x.rotatez, Qt::ZAxis);
1635 l[0]->setTransform(qtrans);
1636 m_transformations[l.at(0)] = x;
1637 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1638 updateDimension(l.at(0));
1642 void TitleWidget::itemHCenter()
1644 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1645 if (l.size() == 1) {
1646 QGraphicsItem *item = l.at(0);
1647 QRectF br = item->sceneBoundingRect();
1648 int width = (int)br.width();
1649 int newPos = (int)((m_frameWidth - width) / 2);
1650 newPos += item->pos().x() - br.left(); // Check item transformation
1651 item->setPos(newPos, item->pos().y());
1652 updateCoordinates(item);
1656 void TitleWidget::itemVCenter()
1658 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1659 if (l.size() == 1) {
1660 QGraphicsItem *item = l.at(0);
1661 QRectF br = item->sceneBoundingRect();
1662 int height = (int)br.height();
1663 int newPos = (int)((m_frameHeight - height) / 2);
1664 newPos += item->pos().y() - br.top(); // Check item transformation
1665 item->setPos(item->pos().x(), newPos);
1666 updateCoordinates(item);
1670 void TitleWidget::itemTop()
1672 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1673 if (l.size() == 1) {
1674 QGraphicsItem *item = l.at(0);
1675 QRectF br = item->sceneBoundingRect();
1677 if (br.top() > 0) diff = -br.top();
1678 else diff = -br.bottom();
1679 item->moveBy(0, diff);
1680 updateCoordinates(item);
1684 void TitleWidget::itemBottom()
1686 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1687 if (l.size() == 1) {
1688 QGraphicsItem *item = l.at(0);
1689 QRectF br = item->sceneBoundingRect();
1691 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1692 else diff = m_frameHeight - br.bottom();
1693 item->moveBy(0, diff);
1694 updateCoordinates(item);
1698 void TitleWidget::itemLeft()
1700 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1701 if (l.size() == 1) {
1702 QGraphicsItem *item = l.at(0);
1703 QRectF br = item->sceneBoundingRect();
1705 if (br.left() > 0) diff = -br.left();
1706 else diff = -br.right();
1707 item->moveBy(diff, 0);
1708 updateCoordinates(item);
1712 void TitleWidget::itemRight()
1714 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1715 if (l.size() == 1) {
1716 QGraphicsItem *item = l.at(0);
1717 QRectF br = item->sceneBoundingRect();
1719 if (br.right() < m_frameWidth) diff = m_frameWidth - br.right();
1720 else diff = m_frameWidth - br.left();
1721 item->moveBy(diff, 0);
1722 updateCoordinates(item);
1726 void TitleWidget::setupViewports()
1728 //double aspect_ratio = 4.0 / 3.0;//read from project
1729 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1730 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1731 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1732 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1733 QPolygonF spoly(sp);
1734 QPolygonF epoly(ep);
1735 spoly.translate(startViewportX->value(), startViewportY->value());
1736 epoly.translate(endViewportX->value(), endViewportY->value());
1737 m_startViewport->setPolygon(spoly);
1738 m_endViewport->setPolygon(epoly);
1739 if (! insertingValues) {
1740 m_startViewport->setData(0, startViewportX->value());
1741 m_startViewport->setData(1, startViewportY->value());
1742 m_startViewport->setData(2, startViewportSize->value());
1744 m_endViewport->setData(0, endViewportX->value());
1745 m_endViewport->setData(1, endViewportY->value());
1746 m_endViewport->setData(2, endViewportSize->value());
1750 void TitleWidget::loadTitle(KUrl url)
1752 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1753 if (!url.isEmpty()) {
1754 QList<QGraphicsItem *> items = m_scene->items();
1755 for (int i = 0; i < items.size(); i++) {
1756 if (items.at(i)->zValue() > -1000) delete items.at(i);
1758 m_scene->clearTextSelection();
1762 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1763 QFile file(tmpfile);
1764 if (file.open(QIODevice::ReadOnly)) {
1765 doc.setContent(&file, false);
1768 KIO::NetAccess::removeTempFile(tmpfile);
1773 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1775 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1776 insertingValues = true;
1777 startViewportX->setValue(m_startViewport->data(0).toInt());
1778 startViewportY->setValue(m_startViewport->data(1).toInt());
1779 startViewportSize->setValue(m_startViewport->data(2).toInt());
1780 endViewportX->setValue(m_endViewport->data(0).toInt());
1781 endViewportY->setValue(m_endViewport->data(1).toInt());
1782 endViewportSize->setValue(m_endViewport->data(2).toInt());
1784 insertingValues = false;
1790 void TitleWidget::saveTitle(KUrl url)
1792 if (anim_start->isChecked()) slotAnimStart(false);
1793 if (anim_end->isChecked()) slotAnimEnd(false);
1794 bool embed_image=false;
1795 if (KMessageBox::questionYesNo(this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::No)
1799 if (url.isEmpty()) {
1800 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1801 fs->setOperationMode(KFileDialog::Saving);
1802 fs->setMode(KFile::File);
1803 #if KDE_IS_VERSION(4,2,0)
1804 fs->setConfirmOverwrite(true);
1806 fs->setKeepLocation(true);
1808 url = fs->selectedUrl();
1811 if (!url.isEmpty()) {
1812 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
1813 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1817 QDomDocument TitleWidget::xml()
1819 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1820 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1824 int TitleWidget::outPoint() const
1826 return m_tc.getFrameCount(title_duration->text());
1829 void TitleWidget::setXml(QDomDocument doc)
1832 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out, m_projectTitlePath);
1834 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1835 /*if (doc.documentElement().hasAttribute("out")) {
1836 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1837 title_duration->setText(m_tc.getTimecode(duration));
1839 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1841 QDomElement e = doc.documentElement();
1842 m_transformations.clear();
1843 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1844 const double PI = 4.0 * atan(1.0);
1845 for (int i = 0; i < items.count(); i++) {
1846 QTransform t = items.at(i)->transform();
1850 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1851 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1852 if (rotlist.count() >= 3) {
1853 x.rotatex = rotlist[0].toDouble();
1854 x.rotatey = rotlist[1].toDouble();
1855 x.rotatez = rotlist[2].toDouble();
1857 // Try to adjust zoom
1858 t.rotate(x.rotatex *(-1), Qt::XAxis);
1859 t.rotate(x.rotatey *(-1), Qt::YAxis);
1860 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1871 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1873 m_transformations[items.at(i)] = x;
1875 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1876 QColor background_color = m_titledocument.getBackgroundColor();
1877 backgroundAlpha->blockSignals(true);
1878 backgroundColor->blockSignals(true);
1879 backgroundAlpha->setValue(background_color.alpha());
1880 background_color.setAlpha(255);
1881 backgroundColor->setColor(background_color);
1882 backgroundAlpha->blockSignals(false);
1883 backgroundColor->blockSignals(false);
1885 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1886 startViewportY->setValue(m_startViewport->data(1).toInt());
1887 startViewportSize->setValue(m_startViewport->data(2).toInt());
1888 endViewportX->setValue(m_endViewport->data(0).toInt());
1889 endViewportY->setValue(m_endViewport->data(1).toInt());
1890 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1892 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1897 void TitleWidget::slotAccepted()
1899 if (anim_start->isChecked()) slotAnimStart(false);
1900 if (anim_end->isChecked()) slotAnimEnd(false);
1904 void TitleWidget::writeChoices()
1906 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1907 KSharedConfigPtr config = KGlobal::config();
1908 KConfigGroup titleConfig(config, "TitleWidget");
1909 // Write the entries
1910 titleConfig.writeEntry("font_family", font_family->currentFont());
1911 //titleConfig.writeEntry("font_size", font_size->value());
1912 titleConfig.writeEntry("font_pixel_size", font_size->value());
1913 titleConfig.writeEntry("font_color", fontColorButton->color());
1914 titleConfig.writeEntry("font_alpha", textAlpha->value());
1915 titleConfig.writeEntry("font_outline", textOutline->value());
1916 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1917 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1918 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1919 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1920 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1922 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1923 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1924 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1925 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1926 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1928 titleConfig.writeEntry("background_color", backgroundColor->color());
1929 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1931 //! \todo Not sure if I should sync - it is probably safe to do it
1936 void TitleWidget::readChoices()
1938 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1939 KSharedConfigPtr config = KGlobal::config();
1940 KConfigGroup titleConfig(config, "TitleWidget");
1942 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1943 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1944 m_scene->slotUpdateFontSize(font_size->value());
1945 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1946 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1948 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
1949 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
1950 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
1953 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1954 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1955 setFontBoxWeight(weight);
1956 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1957 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1959 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1960 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1961 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1962 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1963 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1965 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
1966 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
1969 void TitleWidget::adjustFrameSize()
1971 m_frameWidth = m_titledocument.frameWidth();
1972 m_frameHeight = m_titledocument.frameHeight();
1973 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1974 displayBackgroundFrame();
1977 void TitleWidget::slotAnimStart(bool anim)
1979 if (anim && anim_end->isChecked()) {
1980 anim_end->setChecked(false);
1981 m_endViewport->setZValue(-1000);
1982 m_endViewport->setBrush(QBrush());
1985 QList<QGraphicsItem *> list = m_scene->items();
1986 for (int i = 0; i < list.count(); i++) {
1987 if (list.at(i)->zValue() > -1000) {
1988 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1989 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1992 align_box->setEnabled(anim);
1993 itemzoom->setEnabled(!anim);
1994 itemrotatex->setEnabled(!anim);
1995 itemrotatey->setEnabled(!anim);
1996 itemrotatez->setEnabled(!anim);
1997 frame_toolbar->setEnabled(!anim);
1998 toolbar_stack->setEnabled(!anim);
2000 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
2001 m_startViewport->setZValue(1100);
2002 QColor col = m_startViewport->pen().color();
2004 m_startViewport->setBrush(col);
2005 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2006 m_startViewport->setSelected(true);
2009 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
2011 m_startViewport->setZValue(-1000);
2012 m_startViewport->setBrush(QBrush());
2013 m_startViewport->setFlags(0);
2014 if (!anim_end->isChecked()) deleteAnimInfoText();
2019 void TitleWidget::slotAnimEnd(bool anim)
2021 if (anim && anim_start->isChecked()) {
2022 anim_start->setChecked(false);
2023 m_startViewport->setZValue(-1000);
2024 m_startViewport->setBrush(QBrush());
2027 QList<QGraphicsItem *> list = m_scene->items();
2028 for (int i = 0; i < list.count(); i++) {
2029 if (list.at(i)->zValue() > -1000) {
2030 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2031 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2034 align_box->setEnabled(anim);
2035 itemzoom->setEnabled(!anim);
2036 itemrotatex->setEnabled(!anim);
2037 itemrotatey->setEnabled(!anim);
2038 itemrotatez->setEnabled(!anim);
2039 frame_toolbar->setEnabled(!anim);
2040 toolbar_stack->setEnabled(!anim);
2042 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2043 m_endViewport->setZValue(1100);
2044 QColor col = m_endViewport->pen().color();
2046 m_endViewport->setBrush(col);
2047 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2048 m_endViewport->setSelected(true);
2051 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2053 m_endViewport->setZValue(-1000);
2054 m_endViewport->setBrush(QBrush());
2055 m_endViewport->setFlags(0);
2056 if (!anim_start->isChecked()) deleteAnimInfoText();
2060 void TitleWidget::addAnimInfoText()
2062 // add text to anim viewport
2063 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2064 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2065 QFont font = t->font();
2066 font.setPixelSize(m_startViewport->rect().width() / 10);
2067 QColor col = m_startViewport->pen().color();
2069 t->setDefaultTextColor(col);
2071 font.setPixelSize(m_endViewport->rect().width() / 10);
2072 col = m_endViewport->pen().color();
2074 t2->setDefaultTextColor(col);
2078 void TitleWidget::updateInfoText()
2080 // update info text font
2081 if (!m_startViewport->childItems().isEmpty()) {
2082 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2084 QFont font = item->font();
2085 font.setPixelSize(m_startViewport->rect().width() / 10);
2086 item->setFont(font);
2089 if (!m_endViewport->childItems().isEmpty()) {
2090 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2092 QFont font = item->font();
2093 font.setPixelSize(m_endViewport->rect().width() / 10);
2094 item->setFont(font);
2099 void TitleWidget::deleteAnimInfoText()
2101 // end animation editing, remove info text
2102 while (!m_startViewport->childItems().isEmpty()) {
2103 QGraphicsItem *item = m_startViewport->childItems().at(0);
2104 m_scene->removeItem(item);
2107 while (!m_endViewport->childItems().isEmpty()) {
2108 QGraphicsItem *item = m_endViewport->childItems().at(0);
2109 m_scene->removeItem(item);
2114 void TitleWidget::slotKeepAspect(bool keep)
2116 if (m_endViewport->zValue() == 1100) {
2117 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2118 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2120 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2121 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2125 void TitleWidget::slotResize50()
2127 if (m_endViewport->zValue() == 1100) {
2128 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2129 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2132 void TitleWidget::slotResize100()
2134 if (m_endViewport->zValue() == 1100) {
2135 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2136 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2139 void TitleWidget::slotResize200()
2141 if (m_endViewport->zValue() == 1100) {
2142 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2143 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2146 void TitleWidget::slotAddEffect(int ix)
2148 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2149 int effect = effect_list->itemData(ix).toInt();
2151 if (list.size() == 1) {
2152 if (effect == NOEFFECT)
2153 effect_stack->setHidden(true);
2155 effect_stack->setCurrentIndex(effect - 1);
2156 effect_stack->setHidden(false);
2158 } else // Hide the effects stack when more than one element is selected.
2159 effect_stack->setHidden(true);
2161 foreach(QGraphicsItem * item, list) {
2164 item->setData(100, QVariant());
2165 #if QT_VERSION >= 0x040600
2166 item->setGraphicsEffect(0);
2169 case TYPEWRITEREFFECT:
2171 * Allow the user to set the typewriter effect to more than one
2172 * element, but do not add it to non-text elements.
2174 if (item->type() == TEXTITEM) {
2175 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2176 item->setData(100, effdata);
2179 #if QT_VERSION >= 0x040600
2180 // Do not remove the non-QGraphicsEffects.
2182 item->setGraphicsEffect(new QGraphicsBlurEffect());
2185 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2192 void TitleWidget::slotFontText(const QString& s)
2195 if (f.exactMatch()) {
2196 // Font really exists (could also just be a «d» if the user
2197 // starts typing «dejavu» for example).
2198 font_family->setCurrentFont(f);
2200 // Note: Typing dejavu serif does not recognize the font (takes sans)
2201 // in older Qt versions. Case must match there (except for first letter)
2204 void TitleWidget::slotEditTypewriter(int /*ix*/)
2206 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2207 if (l.size() == 1) {
2208 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2209 l[0]->setData(100, effdata);
2213 void TitleWidget::slotEditBlur(int ix)
2215 #if QT_VERSION < 0x040600
2218 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2219 if (l.size() == 1) {
2220 QGraphicsEffect *eff = l[0]->graphicsEffect();
2221 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2222 if (blur) blur->setBlurRadius(ix);
2227 void TitleWidget::slotEditShadow()
2229 #if QT_VERSION < 0x040600
2232 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2233 if (l.size() == 1) {
2234 QGraphicsEffect *eff = l[0]->graphicsEffect();
2235 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2237 shadow->setBlurRadius(shadow_radius->value());
2238 shadow->setOffset(shadow_x->value(), shadow_y->value());
2244 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2246 qreal bound = maxBound ? -99 : 99;
2247 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2249 QList<QGraphicsItem*> lItems;
2250 // Get items (all or intersecting only)
2251 if (intersectingOnly) {
2252 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2254 lItems = graphicsView->scene()->items();
2256 if (lItems.size() > 0) {
2257 int n = lItems.size();
2260 for (int i = 0; i < n; i++) {
2261 z = lItems[i]->zValue();
2262 if (z > bound && !lItems[i]->isSelected()) {
2264 } else if (z - 1 > bound) {
2265 // To get the maximum index even if it is of an item of the current selection.
2266 // Used when updating multiple items, to get all to the same level.
2267 // Otherwise, the maximum would stay at -99 if the highest item is in the selection.
2272 // Get minimum z index.
2273 for (int i = 0; i < n; i++) {
2274 z = lItems[i]->zValue();
2275 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2276 // There are items at the very bottom (background e.g.) with z-index < -1000.
2278 } else if (z + 1 < bound && z > -999) {
2288 void TitleWidget::slotZIndexUp()
2290 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2291 if (l.size() >= 1) {
2292 qreal currentZ = l[0]->zValue();
2293 qreal max = zIndexBounds(true, true);
2294 if (currentZ <= max) {
2295 l[0]->setZValue(currentZ + 1);
2296 updateDimension(l[0]);
2301 void TitleWidget::slotZIndexTop()
2303 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2304 qreal max = zIndexBounds(true, false);
2305 std::cout << "Max z-index is " << max << ".\n";
2306 for (int i = 0; i < l.size(); i++) {
2307 qreal currentZ = l[i]->zValue();
2308 if (currentZ <= max) {
2309 std::cout << "Updating item " << i << ", is " << currentZ << ".\n";
2310 l[i]->setZValue(max + 1);
2312 std::cout << "Not updating " << i << ", is " << currentZ << ".\n";
2315 // Update the z index value in the GUI
2317 updateDimension(l[0]);
2321 void TitleWidget::slotZIndexDown()
2323 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2324 if (l.size() >= 1) {
2325 qreal currentZ = l[0]->zValue();
2326 qreal min = zIndexBounds(false, true);
2327 if (currentZ >= min) {
2328 l[0]->setZValue(currentZ - 1);
2329 updateDimension(l[0]);
2334 void TitleWidget::slotZIndexBottom()
2336 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2337 qreal min = zIndexBounds(false, false);
2338 for (int i = 0; i < l.size(); i++) {
2339 qreal currentZ = l[i]->zValue();
2340 if (currentZ >= min) {
2341 l[i]->setZValue(min - 1);
2344 // Update the z index value in the GUI
2346 updateDimension(l[0]);
2350 void TitleWidget::slotSelectAll()
2352 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2353 for (int i = 0; i < l.size(); i++) {
2354 l.at(i)->setSelected(true);
2358 void TitleWidget::selectItems(int itemType)
2360 QList<QGraphicsItem*> l;
2361 if (graphicsView->scene()->selectedItems().size() > 0) {
2362 l = graphicsView->scene()->selectedItems();
2363 for (int i = 0; i < l.size(); i++) {
2364 if (l.at(i)->type() != itemType) {
2365 l.at(i)->setSelected(false);
2369 l = graphicsView->scene()->items();
2370 for (int i = 0; i < l.size(); i++) {
2371 if (l.at(i)->type() == itemType) {
2372 l.at(i)->setSelected(true);
2378 void TitleWidget::slotSelectText()
2380 selectItems(TEXTITEM);
2383 void TitleWidget::slotSelectRects()
2385 selectItems(RECTITEM);
2388 void TitleWidget::slotSelectImages()
2390 selectItems(IMAGEITEM);
2393 void TitleWidget::slotSelectNone()
2395 graphicsView->blockSignals(true);
2396 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2397 for (int i = 0; i < l.size(); i++) {
2398 l.at(i)->setSelected(false);
2400 graphicsView->blockSignals(false);
2404 QString TitleWidget::getTooltipWithShortcut(const QString &text, QAction *button)
2406 return text + " <b>" + button->shortcut().toString() + "</b>";
2409 void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
2411 // Let some GUI elements block signals. We may want to change their values without any sideeffects.
2412 // Additionally, store the previous blocking state to avoid side effects when this function is called from within another one.
2413 // Note: Disabling an element also blocks signals. So disabled elements don't need to be set to blocking too.
2414 bool blockOX = origin_x_left->signalsBlocked();
2415 bool blockOY = origin_y_top->signalsBlocked();
2416 bool blockEff = effect_list->signalsBlocked();
2417 bool blockRX = itemrotatex->signalsBlocked();
2418 bool blockRY = itemrotatey->signalsBlocked();
2419 bool blockRZ = itemrotatez->signalsBlocked();
2420 bool blockZoom = itemzoom->signalsBlocked();
2421 bool blockX = value_x->signalsBlocked();
2422 bool blockY = value_y->signalsBlocked();
2423 bool blockW = value_w->signalsBlocked();
2424 bool blockH = value_h->signalsBlocked();
2425 origin_x_left->blockSignals(true);
2426 origin_y_top->blockSignals(true);
2427 effect_list->blockSignals(true);
2428 itemrotatex->blockSignals(true);
2429 itemrotatey->blockSignals(true);
2430 itemrotatez->blockSignals(true);
2431 itemzoom->blockSignals(true);
2432 value_x->blockSignals(true);
2433 value_y->blockSignals(true);
2434 value_w->blockSignals(true);
2435 value_h->blockSignals(true);
2437 if (referenceItem == NULL) {
2438 std::cout << "NULL item.\n";
2439 effect_stack->setHidden(true);
2440 effect_frame->setEnabled(false);
2441 effect_list->setCurrentIndex(0);
2442 origin_x_left->setChecked(false);
2443 origin_y_top->setChecked(false);
2444 updateTextOriginX();
2445 updateTextOriginY();
2446 enableToolbars(TITLE_SELECT);
2447 showToolbars(TITLE_SELECT);
2449 itemzoom->setEnabled(false);
2450 itemrotatex->setEnabled(false);
2451 itemrotatey->setEnabled(false);
2452 itemrotatez->setEnabled(false);
2453 frame_properties->setEnabled(false);
2455 effect_frame->setEnabled(true);
2456 frame_properties->setEnabled(true);
2457 if (referenceItem != m_startViewport && referenceItem != m_endViewport) {
2458 itemzoom->setEnabled(true);
2459 itemrotatex->setEnabled(true);
2460 itemrotatey->setEnabled(true);
2461 itemrotatez->setEnabled(true);
2463 itemzoom->setEnabled(false);
2464 itemrotatex->setEnabled(false);
2465 itemrotatey->setEnabled(false);
2466 itemrotatez->setEnabled(false);
2469 if (referenceItem->type() == TEXTITEM) {
2470 showToolbars(TITLE_TEXT);
2471 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(referenceItem);
2472 if (!i->data(100).isNull()) {
2473 // Item has an effect
2474 QStringList effdata = i->data(100).toStringList();
2475 QString effectName = effdata.takeFirst();
2476 if (effectName == "typewriter") {
2477 QStringList params = effdata.at(0).split(';');
2478 typewriter_delay->setValue(params.at(0).toInt());
2479 typewriter_start->setValue(params.at(1).toInt());
2480 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
2481 effect_stack->setHidden(false);
2484 #if QT_VERSION >= 0x040600
2485 if (i->graphicsEffect()) {
2486 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
2488 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
2489 int rad = (int) blur->blurRadius();
2490 blur_radius->setValue(rad);
2491 effect_stack->setHidden(false);
2493 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
2495 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
2496 shadow_radius->setValue(shad->blurRadius());
2497 shadow_x->setValue(shad->xOffset());
2498 shadow_y->setValue(shad->yOffset());
2499 effect_stack->setHidden(false);
2503 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2504 effect_stack->setHidden(true);
2507 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2508 effect_stack->setHidden(true);
2511 font_size->blockSignals(true);
2512 font_family->blockSignals(true);
2513 font_weight_box->blockSignals(true);
2514 buttonItalic->blockSignals(true);
2515 buttonUnder->blockSignals(true);
2516 fontColorButton->blockSignals(true);
2517 textAlpha->blockSignals(true);
2518 buttonAlignLeft->blockSignals(true);
2519 buttonAlignRight->blockSignals(true);
2520 buttonAlignNone->blockSignals(true);
2521 buttonAlignCenter->blockSignals(true);
2523 QFont font = i->font();
2524 font_family->setCurrentFont(font);
2525 font_size->setValue(font.pixelSize());
2526 m_scene->slotUpdateFontSize(font.pixelSize());
2527 buttonItalic->setChecked(font.italic());
2528 buttonUnder->setChecked(font.underline());
2529 setFontBoxWeight(font.weight());
2531 QTextCursor cursor(i->document());
2532 cursor.select(QTextCursor::Document);
2533 QColor color = cursor.charFormat().foreground().color();
2534 textAlpha->setValue(color.alpha());
2535 color.setAlpha(255);
2536 fontColorButton->setColor(color);
2538 if (!i->data(101).isNull()) {
2539 textOutline->blockSignals(true);
2540 textOutline->setValue(i->data(101).toDouble() * 10);
2541 textOutline->blockSignals(false);
2543 if (!i->data(102).isNull()) {
2544 textOutlineColor->blockSignals(true);
2545 textOutlineAlpha->blockSignals(true);
2546 color = QColor(i->data(102).toString());
2547 textOutlineAlpha->setValue(color.alpha());
2548 color.setAlpha(255);
2549 textOutlineColor->setColor(color);
2550 textOutlineColor->blockSignals(false);
2551 textOutlineAlpha->blockSignals(false);
2553 QTextCursor cur = i->textCursor();
2554 QTextBlockFormat format = cur.blockFormat();
2555 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
2556 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
2557 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
2558 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
2560 font_size->blockSignals(false);
2561 font_family->blockSignals(false);
2562 font_weight_box->blockSignals(false);
2563 buttonItalic->blockSignals(false);
2564 buttonUnder->blockSignals(false);
2565 fontColorButton->blockSignals(false);
2566 textAlpha->blockSignals(false);
2567 buttonAlignLeft->blockSignals(false);
2568 buttonAlignRight->blockSignals(false);
2569 buttonAlignNone->blockSignals(false);
2570 buttonAlignCenter->blockSignals(false);
2572 // mbt 1607: Select text if the text item is an unchanged template item.
2573 if (i->property("isTemplate").isValid()) {
2574 cur.setPosition(0, QTextCursor::MoveAnchor);
2575 cur.select(QTextCursor::Document);
2576 i->setTextCursor(cur);
2577 // Make text editable now.
2579 i->setTextInteractionFlags(Qt::TextEditorInteraction);
2582 updateAxisButtons(i);
2583 updateCoordinates(i);
2585 enableToolbars(TITLE_TEXT);
2587 } else if ((referenceItem)->type() == RECTITEM) {
2588 showToolbars(TITLE_RECTANGLE);
2590 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(referenceItem);
2591 if (rec == m_startViewport || rec == m_endViewport) {
2592 /*toolBox->setCurrentIndex(3);
2593 toolBox->widget(0)->setEnabled(false);
2594 toolBox->widget(1)->setEnabled(false);*/
2595 enableToolbars(TITLE_SELECT);
2597 /*toolBox->widget(0)->setEnabled(true);
2598 toolBox->widget(1)->setEnabled(true);
2599 toolBox->setCurrentIndex(0);*/
2600 //toolBox->setItemEnabled(3, true);
2601 rectFAlpha->setValue(rec->pen().color().alpha());
2602 rectBAlpha->setValue(rec->brush().color().alpha());
2603 //kDebug() << rec->brush().color().alpha();
2604 QColor fcol = rec->pen().color();
2605 QColor bcol = rec->brush().color();
2606 //fcol.setAlpha(255);
2607 //bcol.setAlpha(255);
2608 rectFColor->setColor(fcol);
2609 rectBColor->setColor(bcol);
2611 rectLineWidth->setValue(rec->pen().width());
2612 enableToolbars(TITLE_RECTANGLE);
2615 updateAxisButtons(referenceItem);
2616 updateCoordinates(rec);
2617 updateDimension(rec);
2619 } else if (referenceItem->type() == IMAGEITEM) {
2620 showToolbars(TITLE_IMAGE);
2622 updateCoordinates(referenceItem);
2623 updateDimension(referenceItem);
2625 enableToolbars(TITLE_IMAGE);
2628 //toolBox->setCurrentIndex(0);
2629 showToolbars(TITLE_SELECT);
2630 enableToolbars(TITLE_SELECT);
2631 frame_properties->setEnabled(false);
2633 zValue->setValue((int)referenceItem->zValue());
2634 if (!referenceItem->data(ZOOMFACTOR).isNull()) itemzoom->setValue(referenceItem->data(ZOOMFACTOR).toInt());
2635 else itemzoom->setValue((int)(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
2636 itemrotatex->setValue((int)(m_transformations.value(referenceItem).rotatex));
2637 itemrotatey->setValue((int)(m_transformations.value(referenceItem).rotatey));
2638 itemrotatez->setValue((int)(m_transformations.value(referenceItem).rotatez));
2642 effect_list->blockSignals(blockEff);
2643 itemrotatex->blockSignals(blockRX);
2644 itemrotatey->blockSignals(blockRY);
2645 itemrotatez->blockSignals(blockRZ);
2646 itemzoom->blockSignals(blockZoom);
2647 origin_x_left->blockSignals(blockOX);
2648 origin_y_top->blockSignals(blockOY);
2649 value_x->blockSignals(blockX);
2650 value_y->blockSignals(blockY);
2651 value_w->blockSignals(blockW);
2652 value_h->blockSignals(blockH);