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 //If project is drop frame, set the input mask as such.
149 title_duration->setInputMask("");
150 title_duration->setValidator(m_tc.validator());
151 title_duration->setText(m_tc.reformatSeparators(KdenliveSettings::title_duration()));
153 connect(backgroundColor, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
154 connect(backgroundAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotChangeBackground())) ;
156 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
157 connect(textOutlineColor, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
158 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
159 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
160 connect(textAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
161 connect(textOutline, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
162 connect(textOutlineAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotUpdateText()));
163 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
165 connect(font_family, SIGNAL(editTextChanged(const QString &)), this, SLOT(slotFontText(const QString&)));
167 connect(rectFAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
168 connect(rectBAlpha, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
169 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
170 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
171 connect(rectLineWidth, SIGNAL(valueChanged(qreal, bool)), this, SLOT(rectChanged()));
173 /*connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
174 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
175 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
176 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
177 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
178 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));*/
181 effect_list->addItem(i18n("None"), NOEFFECT);
182 effect_list->addItem(i18n("Typewriter"), TYPEWRITEREFFECT);
183 effect_list->addItem(i18n("Blur"), BLUREFFECT);
186 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
187 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
188 connect(itemrotatex, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateX(qreal)));
189 connect(itemrotatey, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateY(qreal)));
190 connect(itemrotatez, SIGNAL(valueChanged(qreal, bool)), this, SLOT(itemRotateZ(qreal)));
191 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
192 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
193 connect(itemtop, SIGNAL(clicked()), this, SLOT(itemTop()));
194 connect(itembottom, SIGNAL(clicked()), this, SLOT(itemBottom()));
195 connect(itemleft, SIGNAL(clicked()), this, SLOT(itemLeft()));
196 connect(itemright, SIGNAL(clicked()), this, SLOT(itemRight()));
197 connect(effect_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotAddEffect(int)));
198 connect(typewriter_delay, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
199 connect(typewriter_start, SIGNAL(valueChanged(int)), this, SLOT(slotEditTypewriter(int)));
200 connect(blur_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditBlur(int)));
201 connect(shadow_radius, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
202 connect(shadow_x, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
203 connect(shadow_y, SIGNAL(valueChanged(int)), this, SLOT(slotEditShadow()));
204 effect_stack->setHidden(true);
205 effect_frame->setEnabled(false);
207 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
208 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
211 m_signalMapper = new QSignalMapper(this);
212 m_signalMapper->setMapping(value_w, ValueWidth);
213 m_signalMapper->setMapping(value_h, ValueHeight);
214 m_signalMapper->setMapping(value_x, ValueX);
215 m_signalMapper->setMapping(value_y, ValueY);
216 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
217 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
218 connect(value_x, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
219 connect(value_y, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
220 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
222 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
223 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
224 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
225 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
226 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
227 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
228 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
229 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
230 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
232 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
235 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
237 font_weight_box->blockSignals(true);
238 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
239 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
240 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
241 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
242 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
243 font_weight_box->setToolTip(i18n("Font weight"));
244 font_weight_box->setCurrentIndex(1);
245 font_weight_box->blockSignals(false);
247 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
248 buttonRealSize->setIcon(KIcon("zoom-original"));
249 buttonItalic->setIcon(KIcon("format-text-italic"));
250 buttonUnder->setIcon(KIcon("format-text-underline"));
251 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
252 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
253 buttonAlignRight->setIcon(KIcon("format-justify-right"));
254 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
256 buttonAlignNone->setToolTip(i18n("No alignment"));
257 buttonAlignRight->setToolTip(i18n("Align right"));
258 buttonAlignLeft->setToolTip(i18n("Align left"));
259 buttonAlignCenter->setToolTip(i18n("Align center"));
261 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
262 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
263 m_unicodeAction->setToolTip(getTooltipWithShortcut(i18n("Insert Unicode character"), m_unicodeAction));
264 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
265 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
267 m_zUp = new QAction(KIcon("kdenlive-zindex-up"), QString(), this);
268 m_zUp->setShortcut(Qt::Key_PageUp);
269 m_zUp->setToolTip(i18n("Raise object"));
270 connect(m_zUp, SIGNAL(triggered()), this, SLOT(slotZIndexUp()));
271 zUp->setDefaultAction(m_zUp);
273 m_zDown = new QAction(KIcon("kdenlive-zindex-down"), QString(), this);
274 m_zDown->setShortcut(Qt::Key_PageDown);
275 m_zDown->setToolTip(i18n("Lower object"));
276 connect(m_zDown, SIGNAL(triggered()), this, SLOT(slotZIndexDown()));
277 zDown->setDefaultAction(m_zDown);
279 m_zTop = new QAction(KIcon("kdenlive-zindex-top"), QString(), this);
280 // TODO mbt 1414: Shortcut should change z index only if
281 // cursor is NOT in a text field ...
282 //m_zTop->setShortcut(Qt::Key_Home);
283 m_zTop->setToolTip(i18n("Raise object to top"));
284 connect(m_zTop, SIGNAL(triggered()), this, SLOT(slotZIndexTop()));
285 zTop->setDefaultAction(m_zTop);
287 m_zBottom = new QAction(KIcon("kdenlive-zindex-bottom"), QString(), this);
289 //m_zBottom->setShortcut(Qt::Key_End);
290 m_zBottom->setToolTip(i18n("Lower object to bottom"));
291 connect(m_zBottom, SIGNAL(triggered()), this, SLOT(slotZIndexBottom()));
292 zBottom->setDefaultAction(m_zBottom);
294 m_selectAll = new QAction(KIcon("kdenlive-select-all"), QString(), this);
295 m_selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
296 connect(m_selectAll, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
297 buttonSelectAll->setDefaultAction(m_selectAll);
299 m_selectText = new QAction(KIcon("kdenlive-select-texts"), QString(), this);
300 m_selectText->setShortcut(Qt::CTRL + Qt::Key_T);
301 connect(m_selectText, SIGNAL(triggered()), this, SLOT(slotSelectText()));
302 buttonSelectText->setDefaultAction(m_selectText);
303 buttonSelectText->setEnabled(false);
305 m_selectRects = new QAction(KIcon("kdenlive-select-rects"), QString(), this);
306 m_selectRects->setShortcut(Qt::CTRL + Qt::Key_R);
307 connect(m_selectRects, SIGNAL(triggered()), this, SLOT(slotSelectRects()));
308 buttonSelectRects->setDefaultAction(m_selectRects);
309 buttonSelectRects->setEnabled(false);
311 m_selectImages = new QAction(KIcon("kdenlive-select-images"), QString(), this);
312 m_selectImages->setShortcut(Qt::CTRL + Qt::Key_I);
313 connect(m_selectImages, SIGNAL(triggered()), this, SLOT(slotSelectImages()));
314 buttonSelectImages->setDefaultAction(m_selectImages);
315 buttonSelectImages->setEnabled(false);
317 m_unselectAll = new QAction(KIcon("kdenlive-unselect-all"), QString(), this);
318 m_unselectAll->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
319 connect(m_unselectAll, SIGNAL(triggered()), this, SLOT(slotSelectNone()));
320 buttonUnselectAll->setDefaultAction(m_unselectAll);
321 buttonUnselectAll->setEnabled(false);
323 zDown->setIcon(KIcon("kdenlive-zindex-down"));
324 zTop->setIcon(KIcon("kdenlive-zindex-top"));
325 zBottom->setIcon(KIcon("kdenlive-zindex-bottom"));
326 connect(zDown, SIGNAL(clicked()), this, SLOT(slotZIndexDown()));
327 connect(zTop, SIGNAL(clicked()), this, SLOT(slotZIndexTop()));
328 connect(zBottom, SIGNAL(clicked()), this, SLOT(slotZIndexBottom()));
330 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
331 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
332 rectBColor->setToolTip(i18n("Select fill color"));
333 rectFColor->setToolTip(i18n("Select border color"));
334 rectBAlpha->setToolTip(i18n("Fill opacity"));
335 rectFAlpha->setToolTip(i18n("Border opacity"));
336 zoom_slider->setToolTip(i18n("Zoom"));
337 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
338 buttonFitZoom->setToolTip(i18n("Fit zoom"));
339 backgroundColor->setToolTip(i18n("Select background color"));
340 backgroundAlpha->setToolTip(i18n("Background opacity"));
341 buttonSelectAll->setToolTip(getTooltipWithShortcut(i18n("Select all"), m_selectAll));
342 buttonSelectText->setToolTip(getTooltipWithShortcut(i18n("Select text items in current selection"), m_selectText));
343 buttonSelectRects->setToolTip(getTooltipWithShortcut(i18n("Select rect items in current selection"), m_selectRects));
344 buttonSelectImages->setToolTip(getTooltipWithShortcut(i18n("Select image items in current selection"), m_selectImages));
345 buttonUnselectAll->setToolTip(getTooltipWithShortcut(i18n("Unselect all"), m_unselectAll));
347 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
348 itemhcenter->setToolTip(i18n("Align item horizontally"));
349 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
350 itemvcenter->setToolTip(i18n("Align item vertically"));
351 itemtop->setIcon(KIcon("kdenlive-align-top"));
352 itemtop->setToolTip(i18n("Align item to top"));
353 itembottom->setIcon(KIcon("kdenlive-align-bottom"));
354 itembottom->setToolTip(i18n("Align item to bottom"));
355 itemright->setIcon(KIcon("kdenlive-align-right"));
356 itemright->setToolTip(i18n("Align item to right"));
357 itemleft->setIcon(KIcon("kdenlive-align-left"));
358 itemleft->setToolTip(i18n("Align item to left"));
361 QHBoxLayout *layout = new QHBoxLayout;
362 frame_toolbar->setLayout(layout);
363 layout->setContentsMargins(0, 0, 0, 0);
364 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
365 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
366 m_toolbar->setIconSize(QSize(s, s));
368 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
369 m_buttonCursor->setCheckable(true);
370 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
371 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
372 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
374 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
375 m_buttonText->setCheckable(true);
376 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
377 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
378 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
380 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
381 m_buttonRect->setCheckable(true);
382 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
383 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
384 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
386 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
387 m_buttonImage->setCheckable(false);
388 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
389 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
390 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
392 m_toolbar->addSeparator();
394 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
395 m_buttonLoad->setCheckable(false);
396 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
397 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
399 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
400 m_buttonSave->setCheckable(false);
401 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
402 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
404 layout->addWidget(m_toolbar);
406 // initialize graphic scene
407 m_scene = new GraphicsSceneRectMove(this);
408 graphicsView->setScene(m_scene);
409 graphicsView->setMouseTracking(true);
410 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
411 graphicsView->setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);
412 m_titledocument.setScene(m_scene, m_frameWidth, m_frameHeight);
413 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
414 connect(font_size, SIGNAL(valueChanged(int)), m_scene, SLOT(slotUpdateFontSize(int)));
416 // a gradient background
417 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
418 gradient->setSpread(QGradient::ReflectSpread);
419 scene->setBackgroundBrush(*gradient);*/
421 QPen framepen(Qt::DotLine);
422 framepen.setColor(Qt::red);
424 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
425 m_frameBorder->setPen(framepen);
426 m_frameBorder->setZValue(-1100);
427 m_frameBorder->setBrush(Qt::transparent);
428 m_frameBorder->setFlags(0);
429 graphicsView->scene()->addItem(m_frameBorder);
431 m_frameImage = new QGraphicsPixmapItem();
433 qtrans.scale(2.0, 2.0);
434 m_frameImage->setTransform(qtrans);
435 m_frameImage->setZValue(-1200);
436 m_frameImage->setFlags(0);
437 displayBackgroundFrame();
438 graphicsView->scene()->addItem(m_frameImage);
440 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
441 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
442 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
443 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
444 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
445 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
446 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
447 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
450 // mbd: load saved settings
453 graphicsView->show();
454 //graphicsView->setRenderHint(QPainter::Antialiasing);
455 graphicsView->setInteractive(true);
456 //graphicsView->resize(400, 300);
457 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
458 //toolBox->setItemEnabled(2, false);
459 m_startViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
460 m_endViewport = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
461 m_startViewport->setData(0, m_frameWidth);
462 m_startViewport->setData(1, m_frameHeight);
463 m_endViewport->setData(0, m_frameWidth);
464 m_endViewport->setData(1, m_frameHeight);
466 // scale the view so that the title widget is not too big at startup
467 graphicsView->scale(.5, .5);
468 if (!url.isEmpty()) loadTitle(url);
471 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
474 connect(anim_start, SIGNAL(toggled(bool)), this, SLOT(slotAnimStart(bool)));
475 connect(anim_end, SIGNAL(toggled(bool)), this, SLOT(slotAnimEnd(bool)));
476 connect(templateBox, SIGNAL(currentIndexChanged(int)), this, SLOT(templateIndexChanged(int)));
478 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(KdenliveSettings::hastitleproducer());
479 refreshTitleTemplates();
480 //templateBox->setIconSize(QSize(60,60));
481 templateBox->clear();
482 templateBox->addItem("");
483 foreach(TitleTemplate t, titletemplates) {
484 templateBox->addItem(t.icon, t.name, t.file);
486 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
489 TitleWidget::~TitleWidget()
493 delete m_buttonImage;
494 delete m_buttonCursor;
497 delete m_unicodeAction;
504 delete m_selectRects;
505 delete m_selectImages;
506 delete m_unselectAll;
508 delete m_unicodeDialog;
509 delete m_frameBorder;
511 delete m_startViewport;
512 delete m_endViewport;
514 delete m_signalMapper;
518 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
521 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
522 KStandardDirs::makeDir(titlePath);
523 titlePath.append((isClone == false) ? "title" : "clone");
526 while (path.isEmpty() || QFile::exists(path)) {
528 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
530 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
536 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
539 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
540 KStandardDirs::makeDir(titlePath);
541 return titlePath + titleName + ".png";
545 QStringList TitleWidget::extractImageList(QString xml)
548 if (xml.isEmpty()) return result;
551 QDomNodeList images = doc.elementsByTagName("content");
552 for (int i = 0; i < images.count(); i++) {
553 if (images.at(i).toElement().hasAttribute("url"))
554 result.append(images.at(i).toElement().attribute("url"));
560 QStringList TitleWidget::extractFontList(QString xml)
563 if (xml.isEmpty()) return result;
566 QDomNodeList images = doc.elementsByTagName("content");
567 for (int i = 0; i < images.count(); i++) {
568 if (images.at(i).toElement().hasAttribute("font"))
569 result.append(images.at(i).toElement().attribute("font"));
574 void TitleWidget::refreshTitleTemplates()
576 QStringList titlenamelist = QStringList() << i18n("None");
577 QStringList titlefiles = QStringList() << QString();
579 filters << "*.kdenlivetitle" ;
580 titletemplates.clear();
581 QStringList titleTemplates = KGlobal::dirs()->findDirs("appdata", "titles");
582 foreach(const QString & folder, titleTemplates) {
583 QStringList filesnames = QDir(folder).entryList(filters, QDir::Files);
584 foreach(const QString & fname, filesnames) {
585 //titlenamelist.append(fname);
586 //titlefiles.append(KUrl(folder).path(KUrl::AddTrailingSlash) + fname);
589 t.file = KUrl(folder).path(KUrl::AddTrailingSlash) + fname;
590 t.icon = QIcon(KThumb::getImage(t.file, 0, 60, 60));
591 titletemplates.append(t);
594 kDebug() << titlenamelist << titlefiles;
596 void TitleWidget::templateIndexChanged(int index)
598 QString item = templateBox->itemData(index).toString();
600 if (lastDocumentHash != QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex()) {
601 if (KMessageBox::questionYesNo(this, i18n("Do you really want to load a new template? Changes in this title will be lost!")) == KMessageBox::No) return;
605 // mbt 1607: Add property to distinguish between unchanged template titles and user titles.
606 // Text of unchanged template titles should be selected when clicked.
607 QList<QGraphicsItem *> list = graphicsView->scene()->items();
608 foreach(QGraphicsItem * qgItem, list) {
609 if (qgItem->type() == TEXTITEM) {
610 QGraphicsTextItem *i;
611 i = static_cast<QGraphicsTextItem *>(qgItem);
612 i->setProperty("isTemplate", "true");
613 i->setProperty("templateText", i->toHtml());
617 lastDocumentHash = QCryptographicHash::hash(xml().toString().toAscii(), QCryptographicHash::Md5).toHex();
621 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
626 void TitleWidget::slotTextTool()
628 m_scene->setTool(TITLE_TEXT);
629 showToolbars(TITLE_TEXT);
630 checkButton(TITLE_TEXT);
633 void TitleWidget::slotRectTool()
635 m_scene->setTool(TITLE_RECTANGLE);
636 showToolbars(TITLE_RECTANGLE);
637 checkButton(TITLE_RECTANGLE);
639 // Disable dragging mode, would make dragging a rect impossible otherwise ;)
640 graphicsView->setDragMode(QGraphicsView::NoDrag);
643 void TitleWidget::slotSelectTool()
645 m_scene->setTool(TITLE_SELECT);
647 // Enable rubberband selecting mode.
648 graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
650 // Find out which toolbars need to be shown, depending on selected item
651 TITLETOOL t = TITLE_SELECT;
652 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
654 switch (l.at(0)->type()) {
668 if (t == TITLE_RECTANGLE && (l.at(0) == m_endViewport || l.at(0) == m_startViewport)) {
669 //graphicsView->centerOn(l.at(0));
675 updateCoordinates(l.at(0));
676 updateDimension(l.at(0));
677 updateRotZoom(l.at(0));
680 checkButton(TITLE_SELECT);
683 void TitleWidget::slotImageTool()
685 // TODO: find a way to get a list of all supported image types...
686 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";
687 KUrl url = KFileDialog::getOpenUrl(KUrl(), allExtensions, this, i18n("Load Image")); //"*.svg *.png *.jpg *.jpeg *.gif *.raw"
688 if (!url.isEmpty()) {
689 if (url.path().endsWith(".svg")) {
690 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
691 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
692 svg->setZValue(m_count++);
693 svg->setData(Qt::UserRole, url.path());
694 graphicsView->scene()->addItem(svg);
696 QPixmap pix(url.path());
697 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
698 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
699 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
700 image->setData(Qt::UserRole, url.path());
701 image->setZValue(m_count++);
702 graphicsView->scene()->addItem(image);
705 m_scene->setTool(TITLE_SELECT);
706 showToolbars(TITLE_SELECT);
707 checkButton(TITLE_SELECT);
710 void TitleWidget::showToolbars(TITLETOOL toolType)
714 toolbar_stack->setCurrentIndex(0);
717 toolbar_stack->setCurrentIndex(3);
719 case TITLE_RECTANGLE:
720 toolbar_stack->setCurrentIndex(1);
723 toolbar_stack->setCurrentIndex(2);
728 void TitleWidget::enableToolbars(TITLETOOL toolType)
730 // TITLETOOL is defined in graphicsscenerectmove.h
732 if (toolType == TITLE_RECTANGLE || toolType == TITLE_IMAGE) enable = true;
733 value_w->setEnabled(enable);
734 value_h->setEnabled(enable);
737 void TitleWidget::checkButton(TITLETOOL toolType)
739 bool bSelect = false;
751 case TITLE_RECTANGLE:
761 m_buttonCursor->setChecked(bSelect);
762 m_buttonText->setChecked(bText);
763 m_buttonRect->setChecked(bRect);
764 m_buttonImage->setChecked(bImage);
767 void TitleWidget::displayBackgroundFrame()
769 QRectF r = m_frameBorder->sceneBoundingRect();
770 if (!displayBg->isChecked()) {
771 QPixmap pattern(20, 20);
773 QColor bgcolor(210, 210, 210);
774 QPainter p(&pattern);
775 p.fillRect(QRect(0, 0, 10, 10), bgcolor);
776 p.fillRect(QRect(10, 10, 20, 20), bgcolor);
779 QPixmap bg((int) (r.width() / 2), (int) (r.height()/ 2));
781 p2.fillRect(bg.rect(), br);
783 m_frameImage->setPixmap(bg);
785 QImage img = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), QString(), m_render->frameRenderWidth() / 2, m_render->renderHeight() / 2);
786 m_frameImage->setPixmap(QPixmap::fromImage(img.scaled(r.width() / 2, r.height() / 2)));
790 void TitleWidget::initAnimation()
792 align_box->setEnabled(false);
793 QPen startpen(Qt::DotLine);
794 QPen endpen(Qt::DashDotLine);
795 startpen.setColor(QColor(100, 200, 100, 140));
796 endpen.setColor(QColor(200, 100, 100, 140));
798 m_startViewport->setPen(startpen);
799 m_endViewport->setPen(endpen);
801 m_startViewport->setZValue(-1000);
802 m_endViewport->setZValue(-1000);
804 m_startViewport->setFlags(0);
805 m_endViewport->setFlags(0);
807 graphicsView->scene()->addItem(m_startViewport);
808 graphicsView->scene()->addItem(m_endViewport);
810 connect(keep_aspect, SIGNAL(toggled(bool)), this, SLOT(slotKeepAspect(bool)));
811 connect(resize50, SIGNAL(clicked()), this, SLOT(slotResize50()));
812 connect(resize100, SIGNAL(clicked()), this, SLOT(slotResize100()));
813 connect(resize200, SIGNAL(clicked()), this, SLOT(slotResize200()));
816 void TitleWidget::slotUpdateZoom(int pos)
818 m_scene->setZoom((double) pos / 100);
819 zoom_label->setText(QString::number(pos) + '%');
822 void TitleWidget::slotZoom(bool up)
824 int pos = zoom_slider->value();
827 zoom_slider->setValue(pos);
830 void TitleWidget::slotAdjustZoom()
832 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
833 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
834 if (scalex > scaley) scalex = scaley;
835 int zoompos = (int)(scalex * 7 + 0.5);*/
836 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
837 int zoompos = graphicsView->matrix().m11() * 100;
838 zoom_slider->setValue(zoompos);
839 graphicsView->centerOn(m_frameBorder);
842 void TitleWidget::slotZoomOneToOne()
844 zoom_slider->setValue(100);
845 graphicsView->centerOn(m_frameBorder);
848 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
850 updateAxisButtons(rect); // back to default
852 QColor f = rectFColor->color();
853 f.setAlpha(rectFAlpha->value());
855 penf.setWidth(rectLineWidth->value());
856 penf.setJoinStyle(Qt::RoundJoin);
858 QColor b = rectBColor->color();
859 b.setAlpha(rectBAlpha->value());
860 rect->setBrush(QBrush(b));
861 rect->setZValue(m_count++);
862 rect->setData(ZOOMFACTOR, 100);
863 //setCurrentItem(rect);
864 //graphicsView->setFocus();
867 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
869 updateAxisButtons(tt); // back to default
871 QFont font = font_family->currentFont();
872 font.setPixelSize(font_size->value());
874 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
875 font.setItalic(buttonItalic->isChecked());
876 font.setUnderline(buttonUnder->isChecked());
879 QColor color = fontColorButton->color();
880 color.setAlpha(textAlpha->value());
881 tt->setDefaultTextColor(color);
883 QTextCursor cur(tt->document());
884 cur.select(QTextCursor::Document);
885 QTextBlockFormat format = cur.blockFormat();
886 QTextCharFormat cformat = cur.charFormat();
887 QColor outlineColor = textOutlineColor->color();
888 outlineColor.setAlpha(textOutlineAlpha->value());
889 double outlineWidth = textOutline->value() / 10.0;
891 tt->setData(101, outlineWidth);
892 tt->setData(102, outlineColor);
893 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth));
895 cformat.setForeground(QBrush(color));
896 cur.setCharFormat(cformat);
897 cur.setBlockFormat(format);
898 tt->setTextCursor(cur);
899 tt->setZValue(m_count++);
903 void TitleWidget::setFontBoxWeight(int weight)
905 int index = font_weight_box->findData(weight);
907 index = font_weight_box->findData(QFont::Normal);
909 font_weight_box->setCurrentIndex(index);
912 void TitleWidget::setCurrentItem(QGraphicsItem *item)
914 m_scene->setSelectedItem(item);
917 void TitleWidget::zIndexChanged(int v)
919 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
920 for (int i = 0; i < l.size(); i++) {
925 void TitleWidget::selectionChanged()
927 if (m_scene->tool() != TITLE_SELECT) return;
929 std::cout << "Number of selected items: " << graphicsView->scene()->selectedItems().length() << "\n";
931 QList<QGraphicsItem *> l;
933 // mbt 1607: One text item might have grabbed the keyboard.
934 // Ungrab it for all items that are not selected, otherwise
935 // text input would only work for the text item that grabbed
936 // the keyboard last.
937 l = graphicsView->scene()->items();
938 foreach(QGraphicsItem * item, l) {
939 if (item->type() == TEXTITEM && !item->isSelected()) {
940 QGraphicsTextItem *i = static_cast<QGraphicsTextItem *>(item);
945 l = graphicsView->scene()->selectedItems();
948 buttonUnselectAll->setEnabled(true);
949 // Enable all z index buttons if items selected.
950 // We can selectively disable them later.
951 zUp->setEnabled(true);
952 zDown->setEnabled(true);
953 zTop->setEnabled(true);
954 zBottom->setEnabled(true);
956 buttonUnselectAll->setEnabled(false);
959 buttonSelectText->setEnabled(true);
960 buttonSelectRects->setEnabled(true);
961 buttonSelectImages->setEnabled(true);
963 buttonSelectText->setEnabled(false);
964 buttonSelectRects->setEnabled(false);
965 buttonSelectImages->setEnabled(false);
970 } else if (l.size() == 1) {
971 prepareTools(l.at(0));
974 For multiple selected objects we need to decide which tools to show.
976 int firstType = l.at(0)->type();
977 bool allEqual = true;
978 for (int i = 0; i < l.size(); i++) {
979 if (l.at(i)->type() != firstType) {
984 std::cout << "All equal? " << allEqual << ".\n";
986 prepareTools(l.at(0));
988 // Get the default toolset, but enable the property frame (x,y,w,h)
990 frame_properties->setEnabled(true);
992 // Enable x/y/w/h if it makes sense.
993 value_x->setEnabled(true);
994 value_y->setEnabled(true);
995 bool containsTextitem = false;
996 for (int i = 0; i < l.size(); i++) {
997 if (l.at(i)->type() == TEXTITEM) {
998 containsTextitem = true;
1002 if (!containsTextitem) {
1003 value_w->setEnabled(true);
1004 value_h->setEnabled(true);
1008 // Disable z index buttons if they don't make sense for the current selection
1009 int firstZindex = l.at(0)->zValue();
1011 for (int i = 0; i < l.size(); i++) {
1012 if (l[i]->zValue() != firstZindex) {
1018 zUp->setEnabled(false);
1019 zDown->setEnabled(false);
1027 void TitleWidget::slotValueChanged(int type)
1030 type tells us which QSpinBox value has changed.
1033 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1034 std::cout << l.size() << " items to be resized\n";
1036 // Get the updated value here already to do less coding afterwards
1040 val = value_w->value();
1043 val = value_h->value();
1046 val = value_x->value();
1049 val = value_y->value();
1053 for (int k = 0; k < l.size(); k++) {
1054 std::cout << "Type of item " << k << ": " << l.at(k)->type() << "\n";
1056 if (l.at(k)->type() == TEXTITEM) {
1057 // Just update the position. We don't allow setting width/height for text items yet.
1060 updatePosition(l.at(k), val, l.at(k)->pos().y());
1063 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1067 } else if (l.at(k)->type() == RECTITEM) {
1068 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(k));
1071 updatePosition(l.at(k), val, l.at(k)->pos().y());
1074 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1077 rec->setRect(QRect(0, 0, val, rec->rect().height()));
1080 rec->setRect(QRect(0, 0, rec->rect().width(), val));
1084 } else if (l.at(k)->type() == IMAGEITEM) {
1087 if (type == ValueX) {
1088 updatePosition(l.at(k), val, l.at(k)->pos().y());
1090 } else if (type == ValueY) {
1091 updatePosition(l.at(k), l.at(k)->pos().x(), val);
1094 // Width/height has changed. This is more complex.
1096 QGraphicsItem *i = l.at(k);
1097 Transform t = m_transformations.value(i);
1099 // Ratio width:height
1100 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
1101 // TODO: proper calculation for rotation around 3 axes
1102 double alpha = (double) t.rotatez / 180.0 * M_PI;
1105 double length = val;
1110 // We want to keep the aspect ratio of the image as the user does not yet have the possibility
1111 // to restore the original ratio. You rarely want to change it anyway.
1114 // Add 0.5 because otherwise incrementing by 1 might have no effect
1115 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
1116 scale = length / i->boundingRect().width();
1119 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
1120 scale = length / i->boundingRect().height();
1127 qtrans.scale(scale, scale);
1128 qtrans.rotate(t.rotatex, Qt::XAxis);
1129 qtrans.rotate(t.rotatey, Qt::YAxis);
1130 qtrans.rotate(t.rotatez, Qt::ZAxis);
1131 i->setTransform(qtrans);
1132 std::cout << "scale is: " << scale << "\n";
1133 std::cout << i->boundingRect().width() << ": new width\n";
1134 m_transformations[i] = t;
1136 if (l.size() == 1) {
1137 // Only update the w/h values if the selection contains just one item.
1138 // Otherwise, what should we do? ;)
1139 // (Use the values of the first item? Of the second? Of the x-th?)
1141 // Update rotation/zoom values.
1142 // These values are not yet able to handle multiple items!
1153 void TitleWidget::updateDimension(QGraphicsItem *i)
1155 bool wBlocked = value_w->signalsBlocked();
1156 bool hBlocked = value_h->signalsBlocked();
1157 bool zBlocked = zValue->signalsBlocked();
1158 value_w->blockSignals(true);
1159 value_h->blockSignals(true);
1160 zValue->blockSignals(true);
1162 zValue->setValue((int) i->zValue());
1163 if (i->type() == IMAGEITEM) {
1164 // Get multipliers for rotation/scaling
1166 /*Transform t = m_transformations.value(i);
1167 QRectF r = i->boundingRect();
1168 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
1169 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
1170 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
1171 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
1173 value_w->setValue(i->sceneBoundingRect().width());
1174 value_h->setValue(i->sceneBoundingRect().height());
1175 } else if (i->type() == RECTITEM) {
1176 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
1177 std::cout << "Rect width is: " << r->rect().width() << ", was: " << value_w->value() << "\n";
1178 value_w->setValue((int) r->rect().width());
1179 value_h->setValue((int) r->rect().height());
1180 } else if (i->type() == TEXTITEM) {
1181 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
1182 value_w->setValue((int) t->boundingRect().width());
1183 value_h->setValue((int) t->boundingRect().height());
1186 zValue->blockSignals(zBlocked);
1187 value_w->blockSignals(wBlocked);
1188 value_h->blockSignals(hBlocked);
1191 void TitleWidget::updateCoordinates(QGraphicsItem *i)
1193 // Block signals emitted by this method
1194 value_x->blockSignals(true);
1195 value_y->blockSignals(true);
1197 if (i->type() == TEXTITEM) {
1199 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1201 // Set the correct x coordinate value
1202 if (origin_x_left->isChecked()) {
1203 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
1204 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
1206 // Origin is at 0 (default)
1207 value_x->setValue((int) rec->pos().x());
1211 if (origin_y_top->isChecked()) {
1212 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
1214 value_y->setValue((int) rec->pos().y());
1217 } else if (i->type() == RECTITEM) {
1219 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1221 if (origin_x_left->isChecked()) {
1222 // Origin (0 point) is at m_frameWidth
1223 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
1225 // Origin is at 0 (default)
1226 value_x->setValue((int) rec->pos().x());
1229 if (origin_y_top->isChecked()) {
1230 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
1232 value_y->setValue((int) rec->pos().y());
1235 } else if (i->type() == IMAGEITEM) {
1237 if (origin_x_left->isChecked()) {
1238 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
1240 value_x->setValue((int) i->pos().x());
1243 if (origin_y_top->isChecked()) {
1244 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
1246 value_y->setValue((int) i->pos().y());
1251 // Stop blocking signals now
1252 value_x->blockSignals(false);
1253 value_y->blockSignals(false);
1256 void TitleWidget::updateRotZoom(QGraphicsItem *i)
1258 itemzoom->blockSignals(true);
1259 itemrotatex->blockSignals(true);
1260 itemrotatey->blockSignals(true);
1261 itemrotatez->blockSignals(true);
1263 Transform t = m_transformations.value(i);
1265 if (!i->data(ZOOMFACTOR).isNull()) itemzoom->setValue(i->data(ZOOMFACTOR).toInt());
1266 else itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
1268 itemrotatex->setValue((int)(t.rotatex));
1269 itemrotatey->setValue((int)(t.rotatey));
1270 itemrotatez->setValue((int)(t.rotatez));
1272 itemzoom->blockSignals(false);
1273 itemrotatex->blockSignals(false);
1274 itemrotatey->blockSignals(false);
1275 itemrotatez->blockSignals(false);
1278 void TitleWidget::updatePosition(QGraphicsItem *i)
1280 updatePosition(i, value_x->value(), value_y->value());
1283 void TitleWidget::updatePosition(QGraphicsItem *i, int x, int y)
1285 if (i->type() == TEXTITEM) {
1286 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
1289 if (origin_x_left->isChecked()) {
1291 * Origin of the X axis is at m_frameWidth, and distance from right
1292 * border of the item to the right border of the frame is taken. See
1293 * comment to slotOriginXClicked().
1295 posX = m_frameWidth - x - rec->boundingRect().width();
1301 if (origin_y_top->isChecked()) {
1302 /* Same for y axis */
1303 posY = m_frameHeight - y - rec->boundingRect().height();
1308 rec->setPos(posX, posY);
1310 } else if (i->type() == RECTITEM) {
1312 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
1315 if (origin_x_left->isChecked()) {
1316 posX = m_frameWidth - x - rec->rect().width();
1322 if (origin_y_top->isChecked()) {
1323 posY = m_frameHeight - y - rec->rect().height();
1328 rec->setPos(posX, posY);
1330 } else if (i->type() == IMAGEITEM) {
1332 if (origin_x_left->isChecked()) {
1333 // Use the sceneBoundingRect because this also regards transformations like zoom
1334 posX = m_frameWidth - x - i->sceneBoundingRect().width();
1340 if (origin_y_top->isChecked()) {
1341 posY = m_frameHeight - y - i->sceneBoundingRect().height();
1346 i->setPos(posX, posY);
1352 void TitleWidget::updateTextOriginX()
1354 if (origin_x_left->isChecked()) {
1355 origin_x_left->setText(i18n("\u2212X"));
1357 origin_x_left->setText(i18n("+X"));
1361 void TitleWidget::slotOriginXClicked()
1363 // Update the text displayed on the button.
1364 updateTextOriginX();
1366 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1367 if (l.size() >= 1) {
1368 updateCoordinates(l.at(0));
1370 // Remember x axis setting
1371 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1372 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1374 graphicsView->setFocus();
1377 void TitleWidget::updateTextOriginY()
1379 if (origin_y_top->isChecked()) {
1380 origin_y_top->setText(i18n("\u2212Y"));
1382 origin_y_top->setText(i18n("+Y"));
1386 void TitleWidget::slotOriginYClicked()
1388 // Update the text displayed on the button.
1389 updateTextOriginY();
1391 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1392 if (l.size() >= 1) {
1393 updateCoordinates(l.at(0));
1395 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1396 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1399 graphicsView->setFocus();
1402 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1404 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1405 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1406 origin_x_left->blockSignals(true);
1407 origin_y_top->blockSignals(true);
1409 if (xAxis == TitleDocument::AxisInverted) {
1410 origin_x_left->setChecked(true);
1412 origin_x_left->setChecked(false);
1414 updateTextOriginX();
1416 if (yAxis == TitleDocument::AxisInverted) {
1417 origin_y_top->setChecked(true);
1419 origin_y_top->setChecked(false);
1421 updateTextOriginY();
1423 origin_x_left->blockSignals(false);
1424 origin_y_top->blockSignals(false);
1427 void TitleWidget::slotChangeBackground()
1429 QColor color = backgroundColor->color();
1430 color.setAlpha(backgroundAlpha->value());
1431 m_frameBorder->setBrush(QBrush(color));
1434 void TitleWidget::slotChanged()
1436 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1437 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1438 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1442 void TitleWidget::textChanged(QGraphicsTextItem *i)
1445 * If the user has set origin_x_left (the same for y), we need to look
1446 * whether a text element has been selected. If yes, we need to ensure that
1447 * the right border of the text field remains fixed also when some text has
1450 * This is also known as right-justified, with the difference that it is not
1451 * valid for text but for its boundingRect. Text may still be
1456 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1457 if (!i->toPlainText().isEmpty())
1461 * Don't do anything if the string is empty. If the position were
1462 * updated here, a newly created text field would be set to the
1463 * position of the last selected text field.
1468 // mbt 1607: Template text has changed; don't auto-select content anymore.
1469 if (i->property("isTemplate").isValid()) {
1470 if (i->property("templateText").isValid()) {
1471 if (i->property("templateText") == i->toHtml()) {
1472 // Unchanged, do nothing.
1474 i->setProperty("isTemplate", QVariant::Invalid);
1475 i->setProperty("templateText", QVariant::Invalid);
1481 void TitleWidget::slotInsertUnicode()
1483 m_unicodeDialog->exec();
1486 void TitleWidget::slotInsertUnicodeString(QString text)
1488 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1490 if (l.at(0)->type() == TEXTITEM) {
1491 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1492 t->textCursor().insertText(text);
1497 void TitleWidget::slotUpdateText()
1499 QFont font = font_family->currentFont();
1500 font.setPixelSize(font_size->value());
1501 font.setItalic(buttonItalic->isChecked());
1502 font.setUnderline(buttonUnder->isChecked());
1503 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1504 QColor color = fontColorButton->color();
1505 color.setAlpha(textAlpha->value());
1507 QColor outlineColor = textOutlineColor->color();
1508 outlineColor.setAlpha(textOutlineAlpha->value());
1509 double outlineWidth = textOutline->value() / 10.0;
1512 for (i = 0; i < graphicsView->scene()->selectedItems().length(); i++) {
1513 QGraphicsTextItem* item = NULL;
1514 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1515 if (l.at(i)->type() == TEXTITEM) {
1516 item = static_cast <QGraphicsTextItem *>(l.at(i));
1519 // No text item, try next one.
1523 // Set alignment of all text in the text item
1524 QTextCursor cur(item->document());
1525 cur.select(QTextCursor::Document);
1526 QTextBlockFormat format = cur.blockFormat();
1527 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1528 item->setTextWidth(item->boundingRect().width());
1529 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1530 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1531 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1533 format.setAlignment(Qt::AlignLeft);
1534 item->setTextWidth(-1);
1537 // Set font properties
1538 item->setFont(font);
1539 QTextCharFormat cformat = cur.charFormat();
1541 item->setData(101, outlineWidth);
1542 item->setData(102, outlineColor);
1543 if (outlineWidth > 0.0) cformat.setTextOutline(QPen(outlineColor, outlineWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
1545 cformat.setForeground(QBrush(color));
1546 cur.setCharFormat(cformat);
1547 cur.setBlockFormat(format);
1548 // item->setTextCursor(cur);
1549 cur.clearSelection();
1550 item->setTextCursor(cur);
1551 item->setDefaultTextColor(color);
1555 void TitleWidget::rectChanged()
1557 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1559 for (i = 0; i < l.length(); i++) {
1560 if (l.at(i)->type() == RECTITEM && !settingUp) {
1561 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(i));
1562 QColor f = rectFColor->color();
1563 f.setAlpha(rectFAlpha->value());
1565 penf.setWidth(rectLineWidth->value());
1566 penf.setJoinStyle(Qt::RoundJoin);
1568 QColor b = rectBColor->color();
1569 b.setAlpha(rectBAlpha->value());
1570 rec->setBrush(QBrush(b));
1575 void TitleWidget::itemScaled(int val)
1577 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1578 if (l.size() == 1) {
1579 Transform x = m_transformations.value(l.at(0));
1580 x.scalex = (double)val / 100.0;
1581 x.scaley = (double)val / 100.0;
1583 qtrans.scale(x.scalex, x.scaley);
1584 qtrans.rotate(x.rotatex, Qt::XAxis);
1585 qtrans.rotate(x.rotatey, Qt::YAxis);
1586 qtrans.rotate(x.rotatez, Qt::ZAxis);
1587 l[0]->setTransform(qtrans);
1588 l[0]->setData(ZOOMFACTOR, val);
1589 m_transformations[l.at(0)] = x;
1590 updateDimension(l.at(0));
1594 void TitleWidget::itemRotateX(qreal val)
1599 void TitleWidget::itemRotateY(qreal val)
1604 void TitleWidget::itemRotateZ(qreal val)
1609 void TitleWidget::itemRotate(qreal val, int axis)
1611 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1612 if (l.size() == 1) {
1613 Transform x = m_transformations[l.at(0)];
1626 l[0]->setData(ROTATEFACTOR, QList<QVariant>() << QVariant(x.rotatex) << QVariant(x.rotatey) << QVariant(x.rotatez));
1629 qtrans.scale(x.scalex, x.scaley);
1630 qtrans.rotate(x.rotatex, Qt::XAxis);
1631 qtrans.rotate(x.rotatey, Qt::YAxis);
1632 qtrans.rotate(x.rotatez, Qt::ZAxis);
1633 l[0]->setTransform(qtrans);
1634 m_transformations[l.at(0)] = x;
1635 if (l[0]->data(ZOOMFACTOR).isNull()) l[0]->setData(ZOOMFACTOR, 100);
1636 updateDimension(l.at(0));
1640 void TitleWidget::itemHCenter()
1642 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1643 if (l.size() == 1) {
1644 QGraphicsItem *item = l.at(0);
1645 QRectF br = item->sceneBoundingRect();
1646 int width = (int)br.width();
1647 int newPos = (int)((m_frameWidth - width) / 2);
1648 newPos += item->pos().x() - br.left(); // Check item transformation
1649 item->setPos(newPos, item->pos().y());
1650 updateCoordinates(item);
1654 void TitleWidget::itemVCenter()
1656 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1657 if (l.size() == 1) {
1658 QGraphicsItem *item = l.at(0);
1659 QRectF br = item->sceneBoundingRect();
1660 int height = (int)br.height();
1661 int newPos = (int)((m_frameHeight - height) / 2);
1662 newPos += item->pos().y() - br.top(); // Check item transformation
1663 item->setPos(item->pos().x(), newPos);
1664 updateCoordinates(item);
1668 void TitleWidget::itemTop()
1670 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1671 if (l.size() == 1) {
1672 QGraphicsItem *item = l.at(0);
1673 QRectF br = item->sceneBoundingRect();
1675 if (br.top() > 0) diff = -br.top();
1676 else diff = -br.bottom();
1677 item->moveBy(0, diff);
1678 updateCoordinates(item);
1682 void TitleWidget::itemBottom()
1684 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1685 if (l.size() == 1) {
1686 QGraphicsItem *item = l.at(0);
1687 QRectF br = item->sceneBoundingRect();
1689 if (br.bottom() > m_frameHeight) diff = m_frameHeight - br.top();
1690 else diff = m_frameHeight - br.bottom();
1691 item->moveBy(0, diff);
1692 updateCoordinates(item);
1696 void TitleWidget::itemLeft()
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.left() > 0) diff = -br.left();
1704 else diff = -br.right();
1705 item->moveBy(diff, 0);
1706 updateCoordinates(item);
1710 void TitleWidget::itemRight()
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.right() < m_frameWidth) diff = m_frameWidth - br.right();
1718 else diff = m_frameWidth - br.left();
1719 item->moveBy(diff, 0);
1720 updateCoordinates(item);
1724 void TitleWidget::setupViewports()
1726 //double aspect_ratio = 4.0 / 3.0;//read from project
1727 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1728 /*QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1729 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1730 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1731 QPolygonF spoly(sp);
1732 QPolygonF epoly(ep);
1733 spoly.translate(startViewportX->value(), startViewportY->value());
1734 epoly.translate(endViewportX->value(), endViewportY->value());
1735 m_startViewport->setPolygon(spoly);
1736 m_endViewport->setPolygon(epoly);
1737 if (! insertingValues) {
1738 m_startViewport->setData(0, startViewportX->value());
1739 m_startViewport->setData(1, startViewportY->value());
1740 m_startViewport->setData(2, startViewportSize->value());
1742 m_endViewport->setData(0, endViewportX->value());
1743 m_endViewport->setData(1, endViewportY->value());
1744 m_endViewport->setData(2, endViewportSize->value());
1748 void TitleWidget::loadTitle(KUrl url)
1750 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this, i18n("Load Title"));
1751 if (!url.isEmpty()) {
1752 QList<QGraphicsItem *> items = m_scene->items();
1753 for (int i = 0; i < items.size(); i++) {
1754 if (items.at(i)->zValue() > -1000) delete items.at(i);
1756 m_scene->clearTextSelection();
1760 if (KIO::NetAccess::download(url, tmpfile, 0)) {
1761 QFile file(tmpfile);
1762 if (file.open(QIODevice::ReadOnly)) {
1763 doc.setContent(&file, false);
1766 KIO::NetAccess::removeTempFile(tmpfile);
1771 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport, &out) + 1;
1773 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1774 insertingValues = true;
1775 startViewportX->setValue(m_startViewport->data(0).toInt());
1776 startViewportY->setValue(m_startViewport->data(1).toInt());
1777 startViewportSize->setValue(m_startViewport->data(2).toInt());
1778 endViewportX->setValue(m_endViewport->data(0).toInt());
1779 endViewportY->setValue(m_endViewport->data(1).toInt());
1780 endViewportSize->setValue(m_endViewport->data(2).toInt());
1782 insertingValues = false;
1788 void TitleWidget::saveTitle(KUrl url)
1790 if (anim_start->isChecked()) slotAnimStart(false);
1791 if (anim_end->isChecked()) slotAnimEnd(false);
1792 bool embed_image=false;
1793 if (KMessageBox::questionYesNo(this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::No)
1797 if (url.isEmpty()) {
1798 KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
1799 fs->setOperationMode(KFileDialog::Saving);
1800 fs->setMode(KFile::File);
1801 #if KDE_IS_VERSION(4,2,0)
1802 fs->setConfirmOverwrite(true);
1804 fs->setKeepLocation(true);
1806 url = fs->selectedUrl();
1809 if (!url.isEmpty()) {
1810 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
1811 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1815 QDomDocument TitleWidget::xml()
1817 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1818 doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
1822 int TitleWidget::outPoint() const
1824 return m_tc.getFrameCount(title_duration->text());
1827 void TitleWidget::setXml(QDomDocument doc)
1830 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out, m_projectTitlePath);
1832 title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
1833 /*if (doc.documentElement().hasAttribute("out")) {
1834 GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
1835 title_duration->setText(m_tc.getTimecode(duration));
1837 else title_duration->setText(m_tc.getTimecode(GenTime(5000)));*/
1839 QDomElement e = doc.documentElement();
1840 m_transformations.clear();
1841 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1842 const double PI = 4.0 * atan(1.0);
1843 for (int i = 0; i < items.count(); i++) {
1844 QTransform t = items.at(i)->transform();
1848 if (!items.at(i)->data(ROTATEFACTOR).isNull()) {
1849 QList<QVariant> rotlist = items.at(i)->data(ROTATEFACTOR).toList();
1850 if (rotlist.count() >= 3) {
1851 x.rotatex = rotlist[0].toDouble();
1852 x.rotatey = rotlist[1].toDouble();
1853 x.rotatez = rotlist[2].toDouble();
1855 // Try to adjust zoom
1856 t.rotate(x.rotatex *(-1), Qt::XAxis);
1857 t.rotate(x.rotatey *(-1), Qt::YAxis);
1858 t.rotate(x.rotatez *(-1), Qt::ZAxis);
1869 x.rotatez = 180. / PI * atan2(-t.m21(), t.m11());
1871 m_transformations[items.at(i)] = x;
1873 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1874 QColor background_color = m_titledocument.getBackgroundColor();
1875 backgroundAlpha->blockSignals(true);
1876 backgroundColor->blockSignals(true);
1877 backgroundAlpha->setValue(background_color.alpha());
1878 background_color.setAlpha(255);
1879 backgroundColor->setColor(background_color);
1880 backgroundAlpha->blockSignals(false);
1881 backgroundColor->blockSignals(false);
1883 /*startViewportX->setValue(m_startViewport->data(0).toInt());
1884 startViewportY->setValue(m_startViewport->data(1).toInt());
1885 startViewportSize->setValue(m_startViewport->data(2).toInt());
1886 endViewportX->setValue(m_endViewport->data(0).toInt());
1887 endViewportY->setValue(m_endViewport->data(1).toInt());
1888 endViewportSize->setValue(m_endViewport->data(2).toInt());*/
1890 QTimer::singleShot(200, this, SLOT(slotAdjustZoom()));
1895 void TitleWidget::slotAccepted()
1897 if (anim_start->isChecked()) slotAnimStart(false);
1898 if (anim_end->isChecked()) slotAnimEnd(false);
1902 void TitleWidget::writeChoices()
1904 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1905 KSharedConfigPtr config = KGlobal::config();
1906 KConfigGroup titleConfig(config, "TitleWidget");
1907 // Write the entries
1908 titleConfig.writeEntry("font_family", font_family->currentFont());
1909 //titleConfig.writeEntry("font_size", font_size->value());
1910 titleConfig.writeEntry("font_pixel_size", font_size->value());
1911 titleConfig.writeEntry("font_color", fontColorButton->color());
1912 titleConfig.writeEntry("font_alpha", textAlpha->value());
1913 titleConfig.writeEntry("font_outline", textOutline->value());
1914 titleConfig.writeEntry("font_outline_color", textOutlineColor->color());
1915 titleConfig.writeEntry("font_outline_alpha", textOutlineAlpha->value());
1916 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1917 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1918 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1920 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1921 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1922 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1923 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1924 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1926 titleConfig.writeEntry("background_color", backgroundColor->color());
1927 titleConfig.writeEntry("background_alpha", backgroundAlpha->value());
1929 //! \todo Not sure if I should sync - it is probably safe to do it
1934 void TitleWidget::readChoices()
1936 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1937 KSharedConfigPtr config = KGlobal::config();
1938 KConfigGroup titleConfig(config, "TitleWidget");
1940 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1941 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1942 m_scene->slotUpdateFontSize(font_size->value());
1943 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1944 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1946 textOutlineColor->setColor(titleConfig.readEntry("font_outline_color", textOutlineColor->color()));
1947 textOutlineAlpha->setValue(titleConfig.readEntry("font_outline_alpha", textOutlineAlpha->value()));
1948 textOutline->setValue(titleConfig.readEntry("font_outline", textOutline->value()));
1951 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1952 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1953 setFontBoxWeight(weight);
1954 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1955 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1957 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1958 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1959 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1960 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1961 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1963 backgroundColor->setColor(titleConfig.readEntry("background_color", backgroundColor->color()));
1964 backgroundAlpha->setValue(titleConfig.readEntry("background_alpha", backgroundAlpha->value()));
1967 void TitleWidget::adjustFrameSize()
1969 m_frameWidth = m_titledocument.frameWidth();
1970 m_frameHeight = m_titledocument.frameHeight();
1971 m_frameBorder->setRect(0, 0, m_frameWidth, m_frameHeight);
1972 displayBackgroundFrame();
1975 void TitleWidget::slotAnimStart(bool anim)
1977 if (anim && anim_end->isChecked()) {
1978 anim_end->setChecked(false);
1979 m_endViewport->setZValue(-1000);
1980 m_endViewport->setBrush(QBrush());
1983 QList<QGraphicsItem *> list = m_scene->items();
1984 for (int i = 0; i < list.count(); i++) {
1985 if (list.at(i)->zValue() > -1000) {
1986 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
1987 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
1990 align_box->setEnabled(anim);
1991 itemzoom->setEnabled(!anim);
1992 itemrotatex->setEnabled(!anim);
1993 itemrotatey->setEnabled(!anim);
1994 itemrotatez->setEnabled(!anim);
1995 frame_toolbar->setEnabled(!anim);
1996 toolbar_stack->setEnabled(!anim);
1998 keep_aspect->setChecked(!m_startViewport->data(0).isNull());
1999 m_startViewport->setZValue(1100);
2000 QColor col = m_startViewport->pen().color();
2002 m_startViewport->setBrush(col);
2003 m_startViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2004 m_startViewport->setSelected(true);
2007 if (m_startViewport->childItems().isEmpty()) addAnimInfoText();
2009 m_startViewport->setZValue(-1000);
2010 m_startViewport->setBrush(QBrush());
2011 m_startViewport->setFlags(0);
2012 if (!anim_end->isChecked()) deleteAnimInfoText();
2017 void TitleWidget::slotAnimEnd(bool anim)
2019 if (anim && anim_start->isChecked()) {
2020 anim_start->setChecked(false);
2021 m_startViewport->setZValue(-1000);
2022 m_startViewport->setBrush(QBrush());
2025 QList<QGraphicsItem *> list = m_scene->items();
2026 for (int i = 0; i < list.count(); i++) {
2027 if (list.at(i)->zValue() > -1000) {
2028 list.at(i)->setFlag(QGraphicsItem::ItemIsMovable, !anim);
2029 list.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, !anim);
2032 align_box->setEnabled(anim);
2033 itemzoom->setEnabled(!anim);
2034 itemrotatex->setEnabled(!anim);
2035 itemrotatey->setEnabled(!anim);
2036 itemrotatez->setEnabled(!anim);
2037 frame_toolbar->setEnabled(!anim);
2038 toolbar_stack->setEnabled(!anim);
2040 keep_aspect->setChecked(!m_endViewport->data(0).isNull());
2041 m_endViewport->setZValue(1100);
2042 QColor col = m_endViewport->pen().color();
2044 m_endViewport->setBrush(col);
2045 m_endViewport->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
2046 m_endViewport->setSelected(true);
2049 if (m_endViewport->childItems().isEmpty()) addAnimInfoText();
2051 m_endViewport->setZValue(-1000);
2052 m_endViewport->setBrush(QBrush());
2053 m_endViewport->setFlags(0);
2054 if (!anim_start->isChecked()) deleteAnimInfoText();
2058 void TitleWidget::addAnimInfoText()
2060 // add text to anim viewport
2061 QGraphicsTextItem *t = new QGraphicsTextItem(i18n("Start"), m_startViewport);
2062 QGraphicsTextItem *t2 = new QGraphicsTextItem(i18n("End"), m_endViewport);
2063 QFont font = t->font();
2064 font.setPixelSize(m_startViewport->rect().width() / 10);
2065 QColor col = m_startViewport->pen().color();
2067 t->setDefaultTextColor(col);
2069 font.setPixelSize(m_endViewport->rect().width() / 10);
2070 col = m_endViewport->pen().color();
2072 t2->setDefaultTextColor(col);
2076 void TitleWidget::updateInfoText()
2078 // update info text font
2079 if (!m_startViewport->childItems().isEmpty()) {
2080 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_startViewport->childItems().at(0));
2082 QFont font = item->font();
2083 font.setPixelSize(m_startViewport->rect().width() / 10);
2084 item->setFont(font);
2087 if (!m_endViewport->childItems().isEmpty()) {
2088 QGraphicsTextItem *item = static_cast <QGraphicsTextItem *>(m_endViewport->childItems().at(0));
2090 QFont font = item->font();
2091 font.setPixelSize(m_endViewport->rect().width() / 10);
2092 item->setFont(font);
2097 void TitleWidget::deleteAnimInfoText()
2099 // end animation editing, remove info text
2100 while (!m_startViewport->childItems().isEmpty()) {
2101 QGraphicsItem *item = m_startViewport->childItems().at(0);
2102 m_scene->removeItem(item);
2105 while (!m_endViewport->childItems().isEmpty()) {
2106 QGraphicsItem *item = m_endViewport->childItems().at(0);
2107 m_scene->removeItem(item);
2112 void TitleWidget::slotKeepAspect(bool keep)
2114 if (m_endViewport->zValue() == 1100) {
2115 m_endViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2116 m_endViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2118 m_startViewport->setData(0, keep == true ? m_frameWidth : QVariant());
2119 m_startViewport->setData(1, keep == true ? m_frameHeight : QVariant());
2123 void TitleWidget::slotResize50()
2125 if (m_endViewport->zValue() == 1100) {
2126 m_endViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2127 } else m_startViewport->setRect(0, 0, m_frameWidth / 2, m_frameHeight / 2);
2130 void TitleWidget::slotResize100()
2132 if (m_endViewport->zValue() == 1100) {
2133 m_endViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2134 } else m_startViewport->setRect(0, 0, m_frameWidth, m_frameHeight);
2137 void TitleWidget::slotResize200()
2139 if (m_endViewport->zValue() == 1100) {
2140 m_endViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2141 } else m_startViewport->setRect(0, 0, m_frameWidth * 2, m_frameHeight * 2);
2144 void TitleWidget::slotAddEffect(int ix)
2146 QList<QGraphicsItem *> list = graphicsView->scene()->selectedItems();
2147 int effect = effect_list->itemData(ix).toInt();
2149 if (list.size() == 1) {
2150 if (effect == NOEFFECT)
2151 effect_stack->setHidden(true);
2153 effect_stack->setCurrentIndex(effect - 1);
2154 effect_stack->setHidden(false);
2156 } else // Hide the effects stack when more than one element is selected.
2157 effect_stack->setHidden(true);
2159 foreach(QGraphicsItem * item, list) {
2162 item->setData(100, QVariant());
2163 #if QT_VERSION >= 0x040600
2164 item->setGraphicsEffect(0);
2167 case TYPEWRITEREFFECT:
2169 * Allow the user to set the typewriter effect to more than one
2170 * element, but do not add it to non-text elements.
2172 if (item->type() == TEXTITEM) {
2173 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2174 item->setData(100, effdata);
2177 #if QT_VERSION >= 0x040600
2178 // Do not remove the non-QGraphicsEffects.
2180 item->setGraphicsEffect(new QGraphicsBlurEffect());
2183 item->setGraphicsEffect(new QGraphicsDropShadowEffect());
2190 void TitleWidget::slotFontText(const QString& s)
2193 if (f.exactMatch()) {
2194 // Font really exists (could also just be a «d» if the user
2195 // starts typing «dejavu» for example).
2196 font_family->setCurrentFont(f);
2198 // Note: Typing dejavu serif does not recognize the font (takes sans)
2199 // in older Qt versions. Case must match there (except for first letter)
2202 void TitleWidget::slotEditTypewriter(int /*ix*/)
2204 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2205 if (l.size() == 1) {
2206 QStringList effdata = QStringList() << "typewriter" << QString::number(typewriter_delay->value()) + ";" + QString::number(typewriter_start->value());
2207 l[0]->setData(100, effdata);
2211 void TitleWidget::slotEditBlur(int ix)
2213 #if QT_VERSION < 0x040600
2216 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2217 if (l.size() == 1) {
2218 QGraphicsEffect *eff = l[0]->graphicsEffect();
2219 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(eff);
2220 if (blur) blur->setBlurRadius(ix);
2225 void TitleWidget::slotEditShadow()
2227 #if QT_VERSION < 0x040600
2230 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2231 if (l.size() == 1) {
2232 QGraphicsEffect *eff = l[0]->graphicsEffect();
2233 QGraphicsDropShadowEffect *shadow = static_cast <QGraphicsDropShadowEffect *>(eff);
2235 shadow->setBlurRadius(shadow_radius->value());
2236 shadow->setOffset(shadow_x->value(), shadow_y->value());
2242 qreal TitleWidget::zIndexBounds(bool maxBound, bool intersectingOnly)
2244 qreal bound = maxBound ? -99 : 99;
2245 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2247 QList<QGraphicsItem*> lItems;
2248 // Get items (all or intersecting only)
2249 if (intersectingOnly) {
2250 lItems = graphicsView->scene()->items(l[0]->sceneBoundingRect(), Qt::IntersectsItemShape);
2252 lItems = graphicsView->scene()->items();
2254 if (lItems.size() > 0) {
2255 int n = lItems.size();
2258 for (int i = 0; i < n; i++) {
2259 z = lItems[i]->zValue();
2260 if (z > bound && !lItems[i]->isSelected()) {
2262 } else if (z - 1 > bound) {
2263 // To get the maximum index even if it is of an item of the current selection.
2264 // Used when updating multiple items, to get all to the same level.
2265 // Otherwise, the maximum would stay at -99 if the highest item is in the selection.
2270 // Get minimum z index.
2271 for (int i = 0; i < n; i++) {
2272 z = lItems[i]->zValue();
2273 if (z < bound && !lItems[i]->isSelected() && z > -999) {
2274 // There are items at the very bottom (background e.g.) with z-index < -1000.
2276 } else if (z + 1 < bound && z > -999) {
2286 void TitleWidget::slotZIndexUp()
2288 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2289 if (l.size() >= 1) {
2290 qreal currentZ = l[0]->zValue();
2291 qreal max = zIndexBounds(true, true);
2292 if (currentZ <= max) {
2293 l[0]->setZValue(currentZ + 1);
2294 updateDimension(l[0]);
2299 void TitleWidget::slotZIndexTop()
2301 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2302 qreal max = zIndexBounds(true, false);
2303 std::cout << "Max z-index is " << max << ".\n";
2304 for (int i = 0; i < l.size(); i++) {
2305 qreal currentZ = l[i]->zValue();
2306 if (currentZ <= max) {
2307 std::cout << "Updating item " << i << ", is " << currentZ << ".\n";
2308 l[i]->setZValue(max + 1);
2310 std::cout << "Not updating " << i << ", is " << currentZ << ".\n";
2313 // Update the z index value in the GUI
2315 updateDimension(l[0]);
2319 void TitleWidget::slotZIndexDown()
2321 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2322 if (l.size() >= 1) {
2323 qreal currentZ = l[0]->zValue();
2324 qreal min = zIndexBounds(false, true);
2325 if (currentZ >= min) {
2326 l[0]->setZValue(currentZ - 1);
2327 updateDimension(l[0]);
2332 void TitleWidget::slotZIndexBottom()
2334 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
2335 qreal min = zIndexBounds(false, false);
2336 for (int i = 0; i < l.size(); i++) {
2337 qreal currentZ = l[i]->zValue();
2338 if (currentZ >= min) {
2339 l[i]->setZValue(min - 1);
2342 // Update the z index value in the GUI
2344 updateDimension(l[0]);
2348 void TitleWidget::slotSelectAll()
2350 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2351 for (int i = 0; i < l.size(); i++) {
2352 l.at(i)->setSelected(true);
2356 void TitleWidget::selectItems(int itemType)
2358 QList<QGraphicsItem*> l;
2359 if (graphicsView->scene()->selectedItems().size() > 0) {
2360 l = graphicsView->scene()->selectedItems();
2361 for (int i = 0; i < l.size(); i++) {
2362 if (l.at(i)->type() != itemType) {
2363 l.at(i)->setSelected(false);
2367 l = graphicsView->scene()->items();
2368 for (int i = 0; i < l.size(); i++) {
2369 if (l.at(i)->type() == itemType) {
2370 l.at(i)->setSelected(true);
2376 void TitleWidget::slotSelectText()
2378 selectItems(TEXTITEM);
2381 void TitleWidget::slotSelectRects()
2383 selectItems(RECTITEM);
2386 void TitleWidget::slotSelectImages()
2388 selectItems(IMAGEITEM);
2391 void TitleWidget::slotSelectNone()
2393 graphicsView->blockSignals(true);
2394 QList<QGraphicsItem*> l = graphicsView->scene()->items();
2395 for (int i = 0; i < l.size(); i++) {
2396 l.at(i)->setSelected(false);
2398 graphicsView->blockSignals(false);
2402 QString TitleWidget::getTooltipWithShortcut(const QString text, QAction *button)
2404 return text + " <b>" + button->shortcut().toString() + "</b>";
2407 void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
2409 // Let some GUI elements block signals. We may want to change their values without any sideeffects.
2410 // Additionally, store the previous blocking state to avoid side effects when this function is called from within another one.
2411 // Note: Disabling an element also blocks signals. So disabled elements don't need to be set to blocking too.
2412 bool blockOX = origin_x_left->signalsBlocked();
2413 bool blockOY = origin_y_top->signalsBlocked();
2414 bool blockEff = effect_list->signalsBlocked();
2415 bool blockRX = itemrotatex->signalsBlocked();
2416 bool blockRY = itemrotatey->signalsBlocked();
2417 bool blockRZ = itemrotatez->signalsBlocked();
2418 bool blockZoom = itemzoom->signalsBlocked();
2419 bool blockX = value_x->signalsBlocked();
2420 bool blockY = value_y->signalsBlocked();
2421 bool blockW = value_w->signalsBlocked();
2422 bool blockH = value_h->signalsBlocked();
2423 origin_x_left->blockSignals(true);
2424 origin_y_top->blockSignals(true);
2425 effect_list->blockSignals(true);
2426 itemrotatex->blockSignals(true);
2427 itemrotatey->blockSignals(true);
2428 itemrotatez->blockSignals(true);
2429 itemzoom->blockSignals(true);
2430 value_x->blockSignals(true);
2431 value_y->blockSignals(true);
2432 value_w->blockSignals(true);
2433 value_h->blockSignals(true);
2435 if (referenceItem == NULL) {
2436 std::cout << "NULL item.\n";
2437 effect_stack->setHidden(true);
2438 effect_frame->setEnabled(false);
2439 effect_list->setCurrentIndex(0);
2440 origin_x_left->setChecked(false);
2441 origin_y_top->setChecked(false);
2442 updateTextOriginX();
2443 updateTextOriginY();
2444 enableToolbars(TITLE_SELECT);
2445 showToolbars(TITLE_SELECT);
2447 itemzoom->setEnabled(false);
2448 itemrotatex->setEnabled(false);
2449 itemrotatey->setEnabled(false);
2450 itemrotatez->setEnabled(false);
2451 frame_properties->setEnabled(false);
2453 effect_frame->setEnabled(true);
2454 frame_properties->setEnabled(true);
2455 if (referenceItem != m_startViewport && referenceItem != m_endViewport) {
2456 itemzoom->setEnabled(true);
2457 itemrotatex->setEnabled(true);
2458 itemrotatey->setEnabled(true);
2459 itemrotatez->setEnabled(true);
2461 itemzoom->setEnabled(false);
2462 itemrotatex->setEnabled(false);
2463 itemrotatey->setEnabled(false);
2464 itemrotatez->setEnabled(false);
2467 if (referenceItem->type() == TEXTITEM) {
2468 showToolbars(TITLE_TEXT);
2469 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(referenceItem);
2470 if (!i->data(100).isNull()) {
2471 // Item has an effect
2472 QStringList effdata = i->data(100).toStringList();
2473 QString effectName = effdata.takeFirst();
2474 if (effectName == "typewriter") {
2475 QStringList params = effdata.at(0).split(';');
2476 typewriter_delay->setValue(params.at(0).toInt());
2477 typewriter_start->setValue(params.at(1).toInt());
2478 effect_list->setCurrentIndex(effect_list->findData((int) TYPEWRITEREFFECT));
2479 effect_stack->setHidden(false);
2482 #if QT_VERSION >= 0x040600
2483 if (i->graphicsEffect()) {
2484 QGraphicsBlurEffect *blur = static_cast <QGraphicsBlurEffect *>(i->graphicsEffect());
2486 effect_list->setCurrentIndex(effect_list->findData((int) BLUREFFECT));
2487 int rad = (int) blur->blurRadius();
2488 blur_radius->setValue(rad);
2489 effect_stack->setHidden(false);
2491 QGraphicsDropShadowEffect *shad = static_cast <QGraphicsDropShadowEffect *>(i->graphicsEffect());
2493 effect_list->setCurrentIndex(effect_list->findData((int) SHADOWEFFECT));
2494 shadow_radius->setValue(shad->blurRadius());
2495 shadow_x->setValue(shad->xOffset());
2496 shadow_y->setValue(shad->yOffset());
2497 effect_stack->setHidden(false);
2501 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2502 effect_stack->setHidden(true);
2505 effect_list->setCurrentIndex(effect_list->findData((int) NOEFFECT));
2506 effect_stack->setHidden(true);
2509 font_size->blockSignals(true);
2510 font_family->blockSignals(true);
2511 font_weight_box->blockSignals(true);
2512 buttonItalic->blockSignals(true);
2513 buttonUnder->blockSignals(true);
2514 fontColorButton->blockSignals(true);
2515 textAlpha->blockSignals(true);
2516 buttonAlignLeft->blockSignals(true);
2517 buttonAlignRight->blockSignals(true);
2518 buttonAlignNone->blockSignals(true);
2519 buttonAlignCenter->blockSignals(true);
2521 QFont font = i->font();
2522 font_family->setCurrentFont(font);
2523 font_size->setValue(font.pixelSize());
2524 m_scene->slotUpdateFontSize(font.pixelSize());
2525 buttonItalic->setChecked(font.italic());
2526 buttonUnder->setChecked(font.underline());
2527 setFontBoxWeight(font.weight());
2529 QTextCursor cursor(i->document());
2530 cursor.select(QTextCursor::Document);
2531 QColor color = cursor.charFormat().foreground().color();
2532 textAlpha->setValue(color.alpha());
2533 color.setAlpha(255);
2534 fontColorButton->setColor(color);
2536 if (!i->data(101).isNull()) {
2537 textOutline->blockSignals(true);
2538 textOutline->setValue(i->data(101).toDouble() * 10);
2539 textOutline->blockSignals(false);
2541 if (!i->data(102).isNull()) {
2542 textOutlineColor->blockSignals(true);
2543 textOutlineAlpha->blockSignals(true);
2544 color = QColor(i->data(102).toString());
2545 textOutlineAlpha->setValue(color.alpha());
2546 color.setAlpha(255);
2547 textOutlineColor->setColor(color);
2548 textOutlineColor->blockSignals(false);
2549 textOutlineAlpha->blockSignals(false);
2551 QTextCursor cur = i->textCursor();
2552 QTextBlockFormat format = cur.blockFormat();
2553 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
2554 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
2555 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
2556 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
2558 font_size->blockSignals(false);
2559 font_family->blockSignals(false);
2560 font_weight_box->blockSignals(false);
2561 buttonItalic->blockSignals(false);
2562 buttonUnder->blockSignals(false);
2563 fontColorButton->blockSignals(false);
2564 textAlpha->blockSignals(false);
2565 buttonAlignLeft->blockSignals(false);
2566 buttonAlignRight->blockSignals(false);
2567 buttonAlignNone->blockSignals(false);
2568 buttonAlignCenter->blockSignals(false);
2570 // mbt 1607: Select text if the text item is an unchanged template item.
2571 if (i->property("isTemplate").isValid()) {
2572 cur.setPosition(0, QTextCursor::MoveAnchor);
2573 cur.select(QTextCursor::Document);
2574 i->setTextCursor(cur);
2575 // Make text editable now.
2577 i->setTextInteractionFlags(Qt::TextEditorInteraction);
2580 updateAxisButtons(i);
2581 updateCoordinates(i);
2583 enableToolbars(TITLE_TEXT);
2585 } else if ((referenceItem)->type() == RECTITEM) {
2586 showToolbars(TITLE_RECTANGLE);
2588 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(referenceItem);
2589 if (rec == m_startViewport || rec == m_endViewport) {
2590 /*toolBox->setCurrentIndex(3);
2591 toolBox->widget(0)->setEnabled(false);
2592 toolBox->widget(1)->setEnabled(false);*/
2593 enableToolbars(TITLE_SELECT);
2595 /*toolBox->widget(0)->setEnabled(true);
2596 toolBox->widget(1)->setEnabled(true);
2597 toolBox->setCurrentIndex(0);*/
2598 //toolBox->setItemEnabled(3, true);
2599 rectFAlpha->setValue(rec->pen().color().alpha());
2600 rectBAlpha->setValue(rec->brush().color().alpha());
2601 //kDebug() << rec->brush().color().alpha();
2602 QColor fcol = rec->pen().color();
2603 QColor bcol = rec->brush().color();
2604 //fcol.setAlpha(255);
2605 //bcol.setAlpha(255);
2606 rectFColor->setColor(fcol);
2607 rectBColor->setColor(bcol);
2609 rectLineWidth->setValue(rec->pen().width());
2610 enableToolbars(TITLE_RECTANGLE);
2613 updateAxisButtons(referenceItem);
2614 updateCoordinates(rec);
2615 updateDimension(rec);
2617 } else if (referenceItem->type() == IMAGEITEM) {
2618 showToolbars(TITLE_IMAGE);
2620 updateCoordinates(referenceItem);
2621 updateDimension(referenceItem);
2623 enableToolbars(TITLE_IMAGE);
2626 //toolBox->setCurrentIndex(0);
2627 showToolbars(TITLE_SELECT);
2628 enableToolbars(TITLE_SELECT);
2629 frame_properties->setEnabled(false);
2631 zValue->setValue((int)referenceItem->zValue());
2632 if (!referenceItem->data(ZOOMFACTOR).isNull()) itemzoom->setValue(referenceItem->data(ZOOMFACTOR).toInt());
2633 else itemzoom->setValue((int)(m_transformations.value(referenceItem).scalex * 100.0 + 0.5));
2634 itemrotatex->setValue((int)(m_transformations.value(referenceItem).rotatex));
2635 itemrotatey->setValue((int)(m_transformations.value(referenceItem).rotatey));
2636 itemrotatez->setValue((int)(m_transformations.value(referenceItem).rotatez));
2640 effect_list->blockSignals(blockEff);
2641 itemrotatex->blockSignals(blockRX);
2642 itemrotatey->blockSignals(blockRY);
2643 itemrotatez->blockSignals(blockRZ);
2644 itemzoom->blockSignals(blockZoom);
2645 origin_x_left->blockSignals(blockOX);
2646 origin_y_top->blockSignals(blockOY);
2647 value_x->blockSignals(blockX);
2648 value_y->blockSignals(blockY);
2649 value_w->blockSignals(blockW);
2650 value_h->blockSignals(blockH);