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"
24 #include <KGlobalSettings>
25 #include <KFileDialog>
26 #include <KStandardDirs>
27 #include <KMessageBox>
29 #include <QDomDocument>
30 #include <QGraphicsItem>
31 #include <QGraphicsSvgItem>
35 #include <QSignalMapper>
36 #include <QTextBlockFormat>
37 #include <QTextCursor>
39 int settingUp = false;
41 const int IMAGEITEM = 7;
42 const int RECTITEM = 3;
43 const int TEXTITEM = 8;
44 static bool insertingValues = false;
46 TitleWidget::TitleWidget(KUrl url, QString projectTitlePath, Render *render, QWidget *parent) :
49 m_startViewport(NULL),
53 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
54 m_projectTitlePath(projectTitlePath)
57 setFont(KGlobalSettings::toolBarFont());
58 //toolBox->setFont(KGlobalSettings::toolBarFont());
59 frame_properties->setEnabled(false);
60 rect_properties->setFixedHeight(frame_properties->height() + 4);
61 no_properties->setFixedHeight(frame_properties->height() + 4);
62 image_properties->setFixedHeight(frame_properties->height() + 4);
63 text_properties->setFixedHeight(frame_properties->height() + 4);
64 frame_properties->setFixedHeight(frame_toolbar->height());
65 m_frameWidth = render->renderWidth();
66 m_frameHeight = render->renderHeight();
67 showToolbars(TITLE_NONE);
69 connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
70 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
72 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
73 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
74 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
75 connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
76 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
78 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
79 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
80 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
81 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
82 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
84 connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
85 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
86 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
87 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
88 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
89 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
91 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
92 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
93 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
94 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
95 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
97 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
98 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
100 m_signalMapper = new QSignalMapper(this);
101 m_signalMapper->setMapping(value_w, ValueWidth);
102 m_signalMapper->setMapping(value_h, ValueHeight);
103 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
104 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
105 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
107 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
108 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
109 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
110 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
111 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
112 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
113 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
114 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
115 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
116 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
117 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
118 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
119 //connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
120 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
122 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
125 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
127 font_weight_box->blockSignals(true);
128 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
129 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
130 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
131 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
132 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
133 font_weight_box->setToolTip(i18n("Font weight"));
134 font_weight_box->setCurrentIndex(1);
135 font_weight_box->blockSignals(false);
137 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
138 buttonRealSize->setIcon(KIcon("zoom-original"));
139 buttonItalic->setIcon(KIcon("format-text-italic"));
140 buttonUnder->setIcon(KIcon("format-text-underline"));
141 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
142 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
143 buttonAlignRight->setIcon(KIcon("format-justify-right"));
144 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
146 buttonAlignNone->setToolTip(i18n("No alignment"));
147 buttonAlignRight->setToolTip(i18n("Align right"));
148 buttonAlignLeft->setToolTip(i18n("Align left"));
149 buttonAlignCenter->setToolTip(i18n("Align center"));
151 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
152 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
153 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
154 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
155 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
157 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
158 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
159 rectBColor->setToolTip(i18n("Select fill color"));
160 rectFColor->setToolTip(i18n("Select border color"));
161 rectBAlpha->setToolTip(i18n("Fill transparency"));
162 rectFAlpha->setToolTip(i18n("Border transparency"));
163 zoom_slider->setToolTip(i18n("Zoom"));
164 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
165 buttonFitZoom->setToolTip(i18n("Fit zoom"));
166 kcolorbutton->setToolTip(i18n("Select background color"));
167 horizontalSlider->setToolTip(i18n("Background Transparency"));
169 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
170 itemhcenter->setToolTip(i18n("Align item horizontally"));
171 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
172 itemvcenter->setToolTip(i18n("Align item vertically"));
174 QHBoxLayout *layout = new QHBoxLayout;
175 frame_toolbar->setLayout(layout);
176 layout->setContentsMargins(2, 2, 2, 2);
177 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
179 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
180 m_buttonCursor->setCheckable(true);
181 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
182 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
183 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
185 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
186 m_buttonText->setCheckable(true);
187 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
188 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
189 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
191 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
192 m_buttonRect->setCheckable(true);
193 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
194 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
195 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
197 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
198 m_buttonImage->setCheckable(false);
199 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
200 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
201 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
203 m_toolbar->addSeparator();
205 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
206 m_buttonLoad->setCheckable(false);
207 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
208 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
210 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
211 m_buttonSave->setCheckable(false);
212 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
213 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
215 layout->addWidget(m_toolbar);
217 // initialize graphic scene
218 m_scene = new GraphicsSceneRectMove(this);
219 graphicsView->setScene(m_scene);
220 m_titledocument.setScene(m_scene);
221 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
223 // a gradient background
224 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
225 gradient->setSpread(QGradient::ReflectSpread);
226 scene->setBackgroundBrush(*gradient);*/
228 m_frameImage = new QGraphicsPixmapItem();
230 qtrans.scale(2.0, 2.0);
231 m_frameImage->setTransform(qtrans);
232 m_frameImage->setZValue(-1200);
233 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
234 displayBackgroundFrame();
235 graphicsView->scene()->addItem(m_frameImage);
237 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
238 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
239 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
240 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
241 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
242 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
243 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
244 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
246 QPen framepen(Qt::DotLine);
247 framepen.setColor(Qt::red);
249 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
250 m_frameBorder->setPen(framepen);
251 m_frameBorder->setZValue(-1100);
252 m_frameBorder->setBrush(Qt::transparent);
253 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
254 graphicsView->scene()->addItem(m_frameBorder);
256 // mbd: load saved settings
260 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
261 graphicsView->show();
262 //graphicsView->setRenderHint(QPainter::Antialiasing);
263 graphicsView->setInteractive(true);
264 //graphicsView->resize(400, 300);
265 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
266 //toolBox->setItemEnabled(2, false);
267 if (!url.isEmpty()) {
268 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
275 TitleWidget::~TitleWidget()
279 delete m_buttonImage;
280 delete m_buttonCursor;
283 delete m_unicodeAction;
285 delete m_unicodeDialog;
286 delete m_frameBorder;
288 delete m_startViewport;
289 delete m_endViewport;
291 delete m_signalMapper;
295 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
298 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
299 KStandardDirs::makeDir(titlePath);
300 titlePath.append((isClone == false) ? "title" : "clone");
303 while (path.isEmpty() || QFile::exists(path)) {
305 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
307 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
312 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
315 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
316 KStandardDirs::makeDir(titlePath);
317 return titlePath + titleName + ".png";
321 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
326 void TitleWidget::slotTextTool()
328 m_scene->setTool(TITLE_TEXT);
329 showToolbars(TITLE_TEXT);
330 checkButton(TITLE_TEXT);
333 void TitleWidget::slotRectTool()
335 m_scene->setTool(TITLE_RECTANGLE);
336 showToolbars(TITLE_RECTANGLE);
337 checkButton(TITLE_RECTANGLE);
340 void TitleWidget::slotSelectTool()
342 m_scene->setTool(TITLE_SELECT);
344 // Find out which toolbars need to be shown, depending on selected item
345 TITLETOOL t = TITLE_SELECT;
346 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
348 switch (l.at(0)->type()) {
364 updateCoordinates(l.at(0));
365 updateDimension(l.at(0));
366 updateRotZoom(l.at(0));
369 checkButton(TITLE_SELECT);
372 void TitleWidget::slotImageTool()
374 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
375 if (!url.isEmpty()) {
376 if (url.path().endsWith(".svg")) {
377 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
378 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
379 svg->setZValue(m_count++);
380 svg->setData(Qt::UserRole, url.path());
381 graphicsView->scene()->addItem(svg);
383 QPixmap pix(url.path());
384 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
385 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
386 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
387 image->setData(Qt::UserRole, url.path());
388 image->setZValue(m_count++);
389 graphicsView->scene()->addItem(image);
392 m_scene->setTool(TITLE_SELECT);
393 showToolbars(TITLE_SELECT);
394 checkButton(TITLE_NONE);
397 void TitleWidget::showToolbars(TITLETOOL toolType)
401 rect_properties->setHidden(true);
402 image_properties->setHidden(true);
403 no_properties->setHidden(true);
404 text_properties->setHidden(false);
406 case TITLE_RECTANGLE:
407 image_properties->setHidden(true);
408 no_properties->setHidden(true);
409 text_properties->setHidden(true);
410 rect_properties->setHidden(false);
413 no_properties->setHidden(true);
414 text_properties->setHidden(true);
415 rect_properties->setHidden(true);
416 image_properties->setHidden(false);
419 text_properties->setHidden(true);
420 rect_properties->setHidden(true);
421 image_properties->setHidden(true);
422 no_properties->setHidden(false);
427 void TitleWidget::enableToolbars(TITLETOOL toolType)
429 // TITLETOOL is defined in graphicsscenerectmove.h
434 bool bValue_w = false;
435 bool bValue_h = false;
444 case TITLE_RECTANGLE:
459 frame_properties->setEnabled(bFrame);
460 text_properties->setEnabled(bText);
461 rect_properties->setEnabled(bRect);
462 image_properties->setEnabled(bImage);
463 value_w->setEnabled(bValue_w);
464 value_h->setEnabled(bValue_h);
467 void TitleWidget::checkButton(TITLETOOL toolType)
469 bool bSelect = false;
481 case TITLE_RECTANGLE:
491 m_buttonCursor->setChecked(bSelect);
492 m_buttonText->setChecked(bText);
493 m_buttonRect->setChecked(bRect);
494 m_buttonImage->setChecked(bImage);
497 void TitleWidget::displayBackgroundFrame()
499 if (!displayBg->isChecked()) {
500 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
501 QPixmap pattern(20, 20);
505 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
506 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
511 p.fillRect(bg.rect(), br);
513 m_frameImage->setPixmap(bg);
515 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
519 void TitleWidget::initViewports()
521 m_startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
522 m_endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
524 QPen startpen(Qt::DotLine);
525 QPen endpen(Qt::DashDotLine);
526 startpen.setColor(QColor(100, 200, 100, 140));
527 endpen.setColor(QColor(200, 100, 100, 140));
529 m_startViewport->setPen(startpen);
530 m_endViewport->setPen(endpen);
532 startViewportSize->setValue(100);
533 endViewportSize->setValue(100);
535 m_startViewport->setZValue(-1000);
536 m_endViewport->setZValue(-1000);
538 m_startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
539 m_endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
541 graphicsView->scene()->addItem(m_startViewport);
542 graphicsView->scene()->addItem(m_endViewport);
545 void TitleWidget::slotUpdateZoom(int pos)
547 m_scene->setZoom((double) pos / 100);
548 zoom_label->setText(QString::number(pos) + '%');
551 void TitleWidget::slotZoom(bool up)
553 int pos = zoom_slider->value();
556 zoom_slider->setValue(pos);
559 void TitleWidget::slotAdjustZoom()
561 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
562 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
563 if (scalex > scaley) scalex = scaley;
564 int zoompos = (int)(scalex * 7 + 0.5);*/
565 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
566 int zoompos = graphicsView->matrix().m11() * 100;
567 zoom_slider->setValue(zoompos);
568 graphicsView->centerOn(m_frameBorder);
571 void TitleWidget::slotZoomOneToOne()
573 zoom_slider->setValue(100);
574 graphicsView->centerOn(m_frameBorder);
577 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
579 updateAxisButtons(rect); // back to default
581 QColor f = rectFColor->color();
582 f.setAlpha(rectFAlpha->value());
584 penf.setWidth(rectLineWidth->value());
586 QColor b = rectBColor->color();
587 b.setAlpha(rectBAlpha->value());
588 rect->setBrush(QBrush(b));
589 rect->setZValue(m_count++);
590 //setCurrentItem(rect);
591 //graphicsView->setFocus();
594 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
596 updateAxisButtons(tt); // back to default
598 QFont font = font_family->currentFont();
599 font.setPixelSize(font_size->value());
601 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
602 font.setItalic(buttonItalic->isChecked());
603 font.setUnderline(buttonUnder->isChecked());
606 QColor color = fontColorButton->color();
607 color.setAlpha(textAlpha->value());
608 tt->setDefaultTextColor(color);
609 tt->setZValue(m_count++);
613 void TitleWidget::setFontBoxWeight(int weight)
615 int index = font_weight_box->findData(weight);
617 index = font_weight_box->findData(QFont::Normal);
619 font_weight_box->setCurrentIndex(index);
622 void TitleWidget::setCurrentItem(QGraphicsItem *item)
624 m_scene->setSelectedItem(item);
627 void TitleWidget::zIndexChanged(int v)
629 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
635 void TitleWidget::selectionChanged()
637 if (m_scene->tool() != TITLE_SELECT) return;
638 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
639 //toolBox->setItemEnabled(2, false);
640 //toolBox->setItemEnabled(3, false);
641 value_x->blockSignals(true);
642 value_y->blockSignals(true);
643 value_w->blockSignals(true);
644 value_h->blockSignals(true);
645 itemzoom->blockSignals(true);
646 itemrotate->blockSignals(true);
648 bool blockX = !origin_x_left->signalsBlocked();
649 bool blockY = !origin_y_top->signalsBlocked();
650 if (blockX) origin_x_left->blockSignals(true);
651 if (blockY) origin_y_top->blockSignals(true);
652 origin_x_left->setChecked(false);
653 origin_y_top->setChecked(false);
656 enableToolbars(TITLE_NONE);
657 if (blockX) origin_x_left->blockSignals(false);
658 if (blockY) origin_y_top->blockSignals(false);
659 } else if (l.size() == 1) {
660 if (l.at(0)->type() == TEXTITEM) {
661 showToolbars(TITLE_TEXT);
662 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
663 //if (l[0]->hasFocus())
664 toolBox->setCurrentIndex(0);
665 //toolBox->setItemEnabled(2, true);
666 font_size->blockSignals(true);
667 font_family->blockSignals(true);
668 font_weight_box->blockSignals(true);
669 buttonItalic->blockSignals(true);
670 buttonUnder->blockSignals(true);
671 fontColorButton->blockSignals(true);
672 textAlpha->blockSignals(true);
673 buttonAlignLeft->blockSignals(true);
674 buttonAlignRight->blockSignals(true);
675 buttonAlignNone->blockSignals(true);
676 buttonAlignCenter->blockSignals(true);
678 QFont font = i->font();
679 font_family->setCurrentFont(font);
680 font_size->setValue(font.pixelSize());
681 buttonItalic->setChecked(font.italic());
682 buttonUnder->setChecked(font.underline());
683 setFontBoxWeight(font.weight());
685 QColor color = i->defaultTextColor();
686 fontColorButton->setColor(color);
687 textAlpha->setValue(color.alpha());
689 QTextCursor cur = i->textCursor();
690 QTextBlockFormat format = cur.blockFormat();
691 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
692 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
693 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
694 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
696 font_size->blockSignals(false);
697 font_family->blockSignals(false);
698 font_weight_box->blockSignals(false);
699 buttonItalic->blockSignals(false);
700 buttonUnder->blockSignals(false);
701 fontColorButton->blockSignals(false);
702 textAlpha->blockSignals(false);
703 buttonAlignLeft->blockSignals(false);
704 buttonAlignRight->blockSignals(false);
705 buttonAlignNone->blockSignals(false);
706 buttonAlignCenter->blockSignals(false);
708 updateAxisButtons(i);
709 updateCoordinates(i);
711 enableToolbars(TITLE_TEXT);
713 } else if ((l.at(0))->type() == RECTITEM) {
714 showToolbars(TITLE_RECTANGLE);
716 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
717 toolBox->setCurrentIndex(0);
718 //toolBox->setItemEnabled(3, true);
719 rectFAlpha->setValue(rec->pen().color().alpha());
720 rectBAlpha->setValue(rec->brush().color().alpha());
721 //kDebug() << rec->brush().color().alpha();
722 QColor fcol = rec->pen().color();
723 QColor bcol = rec->brush().color();
724 //fcol.setAlpha(255);
725 //bcol.setAlpha(255);
726 rectFColor->setColor(fcol);
727 rectBColor->setColor(bcol);
729 rectLineWidth->setValue(rec->pen().width());
731 updateAxisButtons(l.at(0));
732 updateCoordinates(rec);
733 updateDimension(rec);
734 enableToolbars(TITLE_RECTANGLE);
736 } else if (l.at(0)->type() == IMAGEITEM) {
737 showToolbars(TITLE_IMAGE);
739 updateCoordinates(l.at(0));
740 updateDimension(l.at(0));
742 enableToolbars(TITLE_IMAGE);
745 //toolBox->setCurrentIndex(0);
746 showToolbars(TITLE_NONE);
747 enableToolbars(TITLE_NONE);
748 /*frame_properties->setEnabled(false);
749 text_properties->setEnabled(false);
750 rect_properties->setEnabled(false);*/
752 zValue->setValue((int)l.at(0)->zValue());
753 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
754 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
755 value_x->blockSignals(false);
756 value_y->blockSignals(false);
757 value_w->blockSignals(false);
758 value_h->blockSignals(false);
759 itemzoom->blockSignals(false);
760 itemrotate->blockSignals(false);
764 void TitleWidget::slotValueChanged(int type)
766 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
767 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
772 val = value_w->value();
775 val = value_h->value();
779 QGraphicsItem *i = l.at(0);
780 Transform t = m_transformations.value(i);
782 // Ratio width:height
783 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
784 double alpha = (double) t.rotate / 180.0 * M_PI;
794 // Add 0.5 because otherwise incrementing by 1 might have no effect
795 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
796 scale = length / i->boundingRect().width();
799 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
800 scale = length / i->boundingRect().height();
807 qtrans.scale(scale, scale);
808 qtrans.rotate(t.rotate);
809 i->setTransform(qtrans);
810 m_transformations[i] = t;
817 /** \brief Updates position/size of the selected item when a value
818 * of an item (coordinates, size) has changed */
819 void TitleWidget::slotAdjustSelectedItem()
821 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
823 if (l.at(0)->type() == RECTITEM) {
825 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
827 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
828 } else if (l.at(0)->type() == TEXTITEM) {
830 updatePosition(l.at(0));
831 } else if (l.at(0)->type() == IMAGEITEM) {
833 updatePosition(l.at(0));
838 /** \brief Updates width/height int the text fields, regarding transformation matrix */
839 void TitleWidget::updateDimension(QGraphicsItem *i)
841 value_w->blockSignals(true);
842 value_h->blockSignals(true);
845 if (i->type() == IMAGEITEM) {
846 // Get multipliers for rotation/scaling
848 /*Transform t = m_transformations.value(i);
849 QRectF r = i->boundingRect();
850 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
851 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
852 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
853 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
855 value_w->setValue(i->sceneBoundingRect().width());
856 value_h->setValue(i->sceneBoundingRect().height());
857 } else if (i->type() == RECTITEM) {
858 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
859 value_w->setValue((int) r->rect().width());
860 value_h->setValue((int) r->rect().height());
861 } else if (i->type() == TEXTITEM) {
862 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
863 value_w->setValue((int) t->boundingRect().width());
864 value_h->setValue((int) t->boundingRect().height());
867 value_w->blockSignals(false);
868 value_h->blockSignals(false);
871 /** \brief Updates the coordinates in the text fields from the item */
872 void TitleWidget::updateCoordinates(QGraphicsItem *i)
874 // Block signals emitted by this method
875 value_x->blockSignals(true);
876 value_y->blockSignals(true);
878 if (i->type() == TEXTITEM) {
880 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
882 // Set the correct x coordinate value
883 if (origin_x_left->isChecked()) {
884 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
885 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
887 // Origin is at 0 (default)
888 value_x->setValue((int) rec->pos().x());
892 if (origin_y_top->isChecked()) {
893 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
895 value_y->setValue((int) rec->pos().y());
898 } else if (i->type() == RECTITEM) {
900 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
902 if (origin_x_left->isChecked()) {
903 // Origin (0 point) is at m_frameWidth
904 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
906 // Origin is at 0 (default)
907 value_x->setValue((int) rec->pos().x());
910 if (origin_y_top->isChecked()) {
911 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
913 value_y->setValue((int) rec->pos().y());
916 } else if (i->type() == IMAGEITEM) {
918 if (origin_x_left->isChecked()) {
919 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
921 value_x->setValue((int) i->pos().x());
924 if (origin_y_top->isChecked()) {
925 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
927 value_y->setValue((int) i->pos().y());
932 // Stop blocking signals now
933 value_x->blockSignals(false);
934 value_y->blockSignals(false);
937 void TitleWidget::updateRotZoom(QGraphicsItem *i)
939 itemzoom->blockSignals(true);
940 itemrotate->blockSignals(false);
942 Transform t = m_transformations.value(i);
943 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
944 itemrotate->setValue((int)(t.rotate));
946 itemzoom->blockSignals(false);
947 itemrotate->blockSignals(false);
950 /** \brief Updates the position of an item by reading coordinates from the text fields */
951 void TitleWidget::updatePosition(QGraphicsItem *i)
953 if (i->type() == TEXTITEM) {
954 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
957 if (origin_x_left->isChecked()) {
958 /* Origin of the x axis is at m_frameWidth,
959 * and distance from right border of the item to the right
960 * border of the frame is taken.
961 * See comment to slotOriginXClicked().
963 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
965 posX = value_x->value();
969 if (origin_y_top->isChecked()) {
970 /* Same for y axis */
971 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
973 posY = value_y->value();
976 rec->setPos(posX, posY);
978 } else if (i->type() == RECTITEM) {
980 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
983 if (origin_x_left->isChecked()) {
984 posX = m_frameWidth - value_x->value() - rec->rect().width();
986 posX = value_x->value();
990 if (origin_y_top->isChecked()) {
991 posY = m_frameHeight - value_y->value() - rec->rect().height();
993 posY = value_y->value();
996 rec->setPos(posX, posY);
998 } else if (i->type() == IMAGEITEM) {
1000 if (origin_x_left->isChecked()) {
1001 // Use the sceneBoundingRect because this also regards transformations like zoom
1002 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
1004 posX = value_x->value();
1008 if (origin_y_top->isChecked()) {
1009 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1011 posY = value_y->value();
1014 i->setPos(posX, posY);
1020 void TitleWidget::updateTextOriginX()
1022 if (origin_x_left->isChecked()) {
1023 origin_x_left->setText(i18n("\u2212X"));
1025 origin_x_left->setText(i18n("+X"));
1029 void TitleWidget::slotOriginXClicked()
1031 // Update the text displayed on the button.
1032 updateTextOriginX();
1034 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1035 if (l.size() >= 1) {
1036 updateCoordinates(l.at(0));
1038 // Remember x axis setting
1039 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1040 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1042 graphicsView->setFocus();
1045 void TitleWidget::updateTextOriginY()
1047 if (origin_y_top->isChecked()) {
1048 origin_y_top->setText(i18n("\u2212Y"));
1050 origin_y_top->setText(i18n("+Y"));
1054 void TitleWidget::slotOriginYClicked()
1056 // Update the text displayed on the button.
1057 updateTextOriginY();
1059 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1060 if (l.size() >= 1) {
1061 updateCoordinates(l.at(0));
1063 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1064 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1067 graphicsView->setFocus();
1070 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1072 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1073 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1074 origin_x_left->blockSignals(true);
1075 origin_y_top->blockSignals(true);
1077 if (xAxis == TitleDocument::AxisInverted) {
1078 origin_x_left->setChecked(true);
1080 origin_x_left->setChecked(false);
1082 updateTextOriginX();
1084 if (yAxis == TitleDocument::AxisInverted) {
1085 origin_y_top->setChecked(true);
1087 origin_y_top->setChecked(false);
1089 updateTextOriginY();
1091 origin_x_left->blockSignals(false);
1092 origin_y_top->blockSignals(false);
1095 void TitleWidget::slotChangeBackground()
1097 QColor color = kcolorbutton->color();
1098 color.setAlpha(horizontalSlider->value());
1099 m_frameBorder->setBrush(QBrush(color));
1103 * Something (yeah) has changed in our QGraphicsScene.
1105 void TitleWidget::slotChanged()
1107 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1108 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1109 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1114 * If the user has set origin_x_left (everything also for y),
1115 * we need to look whether a text element has been selected. If yes,
1116 * we need to ensure that the right border of the text field
1117 * remains fixed also when some text has been entered.
1119 * This is also known as right-justified, with the difference that
1120 * it is not valid for text but for its boundingRect. Text may still
1121 * be left-justified.
1123 void TitleWidget::textChanged(QGraphicsTextItem *i)
1128 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1130 if (!i->toPlainText().isEmpty()) {
1134 * Don't do anything if the string is empty. If the position
1135 * would be updated here, a newly created text field would
1136 * be set to the position of the last selected text field.
1142 void TitleWidget::slotInsertUnicode()
1144 m_unicodeDialog->exec();
1147 void TitleWidget::slotInsertUnicodeString(QString text)
1149 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1151 if (l.at(0)->type() == TEXTITEM) {
1152 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1153 t->textCursor().insertText(text);
1158 void TitleWidget::slotUpdateText()
1160 QFont font = font_family->currentFont();
1161 font.setPixelSize(font_size->value());
1162 font.setItalic(buttonItalic->isChecked());
1163 font.setUnderline(buttonUnder->isChecked());
1164 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1165 QColor color = fontColorButton->color();
1166 color.setAlpha(textAlpha->value());
1168 QGraphicsTextItem* item = NULL;
1169 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1170 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1171 item = static_cast <QGraphicsTextItem *>(l.at(0));
1174 //if (item->textCursor().selection ().isEmpty())
1175 QTextCursor cur = item->textCursor();
1176 QTextBlockFormat format = cur.blockFormat();
1177 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1178 item->setTextWidth(item->boundingRect().width());
1179 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1180 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1181 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1183 format.setAlignment(Qt::AlignLeft);
1184 item->setTextWidth(-1);
1188 item->setFont(font);
1189 item->setDefaultTextColor(color);
1190 cur.select(QTextCursor::Document);
1191 cur.setBlockFormat(format);
1192 item->setTextCursor(cur);
1193 cur.clearSelection();
1194 item->setTextCursor(cur);
1199 void TitleWidget::rectChanged()
1201 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1202 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1203 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1204 QColor f = rectFColor->color();
1205 f.setAlpha(rectFAlpha->value());
1207 penf.setWidth(rectLineWidth->value());
1209 QColor b = rectBColor->color();
1210 b.setAlpha(rectBAlpha->value());
1211 rec->setBrush(QBrush(b));
1215 void TitleWidget::itemScaled(int val)
1217 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1218 if (l.size() == 1) {
1219 Transform x = m_transformations.value(l.at(0));
1220 x.scalex = (double)val / 100.0;
1221 x.scaley = (double)val / 100.0;
1223 qtrans.scale(x.scalex, x.scaley);
1224 qtrans.rotate(x.rotate);
1225 l[0]->setTransform(qtrans);
1226 m_transformations[l.at(0)] = x;
1227 updateDimension(l.at(0));
1231 void TitleWidget::itemRotate(int val)
1233 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1234 if (l.size() == 1) {
1235 Transform x = m_transformations[l.at(0)];
1236 x.rotate = (double)val;
1238 qtrans.scale(x.scalex, x.scaley);
1239 qtrans.rotate(x.rotate);
1240 l[0]->setTransform(qtrans);
1241 m_transformations[l.at(0)] = x;
1242 updateDimension(l.at(0));
1246 void TitleWidget::itemHCenter()
1248 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1249 if (l.size() == 1) {
1250 QGraphicsItem *item = l.at(0);
1252 br = item->sceneBoundingRect();
1253 int width = (int)br.width();
1254 int newPos = (int)((m_frameWidth - width) / 2);
1255 newPos += item->pos().x() - br.left(); // Check item transformation
1256 item->setPos(newPos, item->pos().y());
1257 updateCoordinates(item);
1261 void TitleWidget::itemVCenter()
1263 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1264 if (l.size() == 1) {
1265 QGraphicsItem *item = l.at(0);
1267 br = item->sceneBoundingRect();
1268 int height = (int)br.height();
1269 int newPos = (int)((m_frameHeight - height) / 2);
1270 newPos += item->pos().y() - br.top(); // Check item transformation
1271 item->setPos(item->pos().x(), newPos);
1272 updateCoordinates(item);
1276 void TitleWidget::setupViewports()
1278 //double aspect_ratio = 4.0 / 3.0;//read from project
1279 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1280 QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1281 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1282 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1283 QPolygonF spoly(sp);
1284 QPolygonF epoly(ep);
1285 spoly.translate(startViewportX->value(), startViewportY->value());
1286 epoly.translate(endViewportX->value(), endViewportY->value());
1287 m_startViewport->setPolygon(spoly);
1288 m_endViewport->setPolygon(epoly);
1289 if (! insertingValues) {
1290 m_startViewport->setData(0, startViewportX->value());
1291 m_startViewport->setData(1, startViewportY->value());
1292 m_startViewport->setData(2, startViewportSize->value());
1294 m_endViewport->setData(0, endViewportX->value());
1295 m_endViewport->setData(1, endViewportY->value());
1296 m_endViewport->setData(2, endViewportSize->value());
1300 void TitleWidget::loadTitle()
1302 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Load Title"));
1303 if (!url.isEmpty()) {
1304 QList<QGraphicsItem *> items = m_scene->items();
1305 for (int i = 0; i < items.size(); i++) {
1306 if (items.at(i)->zValue() > -1000) delete items.at(i);
1308 m_scene->clearTextSelection();
1309 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
1310 insertingValues = true;
1311 startViewportX->setValue(m_startViewport->data(0).toInt());
1312 startViewportY->setValue(m_startViewport->data(1).toInt());
1313 startViewportSize->setValue(m_startViewport->data(2).toInt());
1314 endViewportX->setValue(m_endViewport->data(0).toInt());
1315 endViewportY->setValue(m_endViewport->data(1).toInt());
1316 endViewportSize->setValue(m_endViewport->data(2).toInt());
1317 insertingValues = false;
1322 void TitleWidget::saveTitle(KUrl url)
1324 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Save Title"));
1325 if (!url.isEmpty()) {
1326 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport) == false)
1327 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1331 QDomDocument TitleWidget::xml()
1333 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1334 if (cropImage->isChecked()) {
1335 doc.documentElement().setAttribute("crop", 1);
1340 void TitleWidget::setXml(QDomDocument doc)
1342 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport);
1343 QDomElement e = doc.documentElement();
1344 cropImage->setChecked(e.hasAttribute("crop"));
1345 m_transformations.clear();
1346 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1347 const double PI = 4.0 * atan(1.0);
1348 for (int i = 0; i < items.count(); i++) {
1349 QTransform t = items.at(i)->transform();
1353 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1354 m_transformations[items.at(i)] = x;
1356 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1357 QColor background_color = m_titledocument.getBackgroundColor();
1358 horizontalSlider->blockSignals(true);
1359 kcolorbutton->blockSignals(true);
1360 horizontalSlider->setValue(background_color.alpha());
1361 background_color.setAlpha(255);
1362 kcolorbutton->setColor(background_color);
1363 horizontalSlider->blockSignals(false);
1364 kcolorbutton->blockSignals(false);
1369 const QRect TitleWidget::renderedRect()
1373 int maxX = m_frameWidth;
1374 int maxY = m_frameHeight;
1375 if (!cropImage->isChecked()) {
1376 m_scene->removeItem(m_startViewport);
1377 m_scene->removeItem(m_endViewport);
1378 QRect boundingRect = m_scene->itemsBoundingRect().toRect();
1379 if (boundingRect.left() < 0) minX = boundingRect.left();
1380 if (boundingRect.top() < 0) minY = boundingRect.top();
1381 if (boundingRect.right() > maxX) maxX = boundingRect.right();
1382 if (boundingRect.bottom() > maxY) maxY = boundingRect.bottom();
1390 QRect rect(minX, minY, maxX, maxY);
1394 QImage TitleWidget::renderedPixmap()
1396 QRect rect = renderedRect();
1397 QImage pix(rect.width(), rect.height(), QImage::Format_ARGB32);
1398 pix.fill(Qt::transparent);
1399 QPainter painter(&pix);
1400 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing);
1401 m_scene->clearTextSelection();
1402 QPen framepen = m_frameBorder->pen();
1403 m_frameBorder->setPen(Qt::NoPen);
1404 m_startViewport->setVisible(false);
1405 m_endViewport->setVisible(false);
1406 m_frameImage->setVisible(false);
1408 m_scene->render(&painter, QRectF(), rect); //QRectF(minX, minY, maxX - minX, maxY - minY));
1410 m_frameBorder->setPen(framepen);
1411 m_startViewport->setVisible(true);
1412 m_endViewport->setVisible(true);
1413 m_frameImage->setVisible(true);
1417 /** \brief Connected to the accepted signal - calls writeChoices */
1418 void TitleWidget::slotAccepted()
1423 /** \brief Store the current choices of font, background and rect values */
1424 void TitleWidget::writeChoices()
1426 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1427 KSharedConfigPtr config = KGlobal::config();
1428 KConfigGroup titleConfig(config, "TitleWidget");
1429 // Write the entries
1430 titleConfig.writeEntry("font_family", font_family->currentFont());
1431 //titleConfig.writeEntry("font_size", font_size->value());
1432 titleConfig.writeEntry("font_pixel_size", font_size->value());
1433 titleConfig.writeEntry("font_color", fontColorButton->color());
1434 titleConfig.writeEntry("font_alpha", textAlpha->value());
1435 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1436 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1437 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1439 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1440 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1441 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1442 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1443 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1445 titleConfig.writeEntry("background_color", kcolorbutton->color());
1446 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1448 titleConfig.writeEntry("crop_image", cropImage->isChecked());
1450 //! \todo Not sure if I should sync - it is probably safe to do it
1455 /** \brief Read the last stored choices into the dialog */
1456 void TitleWidget::readChoices()
1458 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1459 KSharedConfigPtr config = KGlobal::config();
1460 KConfigGroup titleConfig(config, "TitleWidget");
1462 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1463 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1464 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1465 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1467 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1468 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1469 setFontBoxWeight(weight);
1470 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1471 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1473 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1474 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1475 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1476 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1477 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1479 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1480 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1482 cropImage->setChecked(titleConfig.readEntry("crop_image", cropImage->isChecked()));