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 text_properties->setFixedHeight(frame_properties->height() + 4);
62 m_frameWidth = render->renderWidth();
63 m_frameHeight = render->renderHeight();
65 connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
66 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
68 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
69 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
70 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
71 connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
73 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
74 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
75 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
76 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
77 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
79 connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
80 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
81 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
82 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
83 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
84 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
86 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
87 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
88 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
89 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
90 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
92 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
93 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
95 m_signalMapper = new QSignalMapper(this);
96 m_signalMapper->setMapping(value_w, ValueWidth);
97 m_signalMapper->setMapping(value_h, ValueHeight);
98 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
99 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
100 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
102 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
103 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
104 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
105 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
106 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
107 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
108 connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
109 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
110 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
111 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
112 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
113 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
114 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
115 //connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
116 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
118 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
121 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
123 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
124 buttonRealSize->setIcon(KIcon("zoom-original"));
125 buttonBold->setIcon(KIcon("format-text-bold"));
126 buttonItalic->setIcon(KIcon("format-text-italic"));
127 buttonUnder->setIcon(KIcon("format-text-underline"));
128 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
129 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
130 buttonAlignRight->setIcon(KIcon("format-justify-right"));
131 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
133 buttonAlignNone->setToolTip(i18n("No alignment"));
134 buttonAlignRight->setToolTip(i18n("Align right"));
135 buttonAlignLeft->setToolTip(i18n("Align left"));
136 buttonAlignCenter->setToolTip(i18n("Align center"));
138 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
139 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
140 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
141 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
142 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
144 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
145 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
146 rectBColor->setToolTip(i18n("Select fill color"));
147 rectFColor->setToolTip(i18n("Select border color"));
148 rectBAlpha->setToolTip(i18n("Fill transparency"));
149 rectFAlpha->setToolTip(i18n("Border transparency"));
150 zoom_slider->setToolTip(i18n("Zoom"));
151 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
152 buttonFitZoom->setToolTip(i18n("Fit zoom"));
153 kcolorbutton->setToolTip(i18n("Select background color"));
154 horizontalSlider->setToolTip(i18n("Background Transparency"));
156 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
157 itemhcenter->setToolTip(i18n("Align item horizontally"));
158 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
159 itemvcenter->setToolTip(i18n("Align item vertically"));
161 QHBoxLayout *layout = new QHBoxLayout;
162 frame_toolbar->setLayout(layout);
163 layout->setContentsMargins(2, 2, 2, 2);
164 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
166 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
167 m_buttonCursor->setCheckable(true);
168 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
169 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
170 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
172 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
173 m_buttonText->setCheckable(true);
174 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
175 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
176 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
178 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
179 m_buttonRect->setCheckable(true);
180 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
181 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
182 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
184 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
185 m_buttonImage->setCheckable(false);
186 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
187 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
188 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
190 m_toolbar->addSeparator();
192 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
193 m_buttonLoad->setCheckable(false);
194 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
195 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
197 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
198 m_buttonSave->setCheckable(false);
199 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
200 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
202 layout->addWidget(m_toolbar);
204 // initialize graphic scene
205 m_scene = new GraphicsSceneRectMove(this);
206 graphicsView->setScene(m_scene);
207 m_titledocument.setScene(m_scene);
208 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
210 // a gradient background
211 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
212 gradient->setSpread(QGradient::ReflectSpread);
213 scene->setBackgroundBrush(*gradient);*/
215 m_frameImage = new QGraphicsPixmapItem();
217 qtrans.scale(2.0, 2.0);
218 m_frameImage->setTransform(qtrans);
219 m_frameImage->setZValue(-1200);
220 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
221 displayBackgroundFrame();
222 graphicsView->scene()->addItem(m_frameImage);
224 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
225 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
226 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
227 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
228 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
229 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
230 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
231 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
233 QPen framepen(Qt::DotLine);
234 framepen.setColor(Qt::red);
236 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
237 m_frameBorder->setPen(framepen);
238 m_frameBorder->setZValue(-1100);
239 m_frameBorder->setBrush(Qt::transparent);
240 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
241 graphicsView->scene()->addItem(m_frameBorder);
243 // mbd: load saved settings
247 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
248 graphicsView->show();
249 //graphicsView->setRenderHint(QPainter::Antialiasing);
250 graphicsView->setInteractive(true);
251 //graphicsView->resize(400, 300);
252 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
253 //toolBox->setItemEnabled(2, false);
254 if (!url.isEmpty()) {
255 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
261 showToolbars(TITLE_NONE);
264 TitleWidget::~TitleWidget()
268 delete m_buttonImage;
269 delete m_buttonCursor;
272 delete m_unicodeAction;
274 delete m_unicodeDialog;
275 delete m_frameBorder;
277 delete m_startViewport;
278 delete m_endViewport;
280 delete m_signalMapper;
284 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
287 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
288 KStandardDirs::makeDir(titlePath);
289 titlePath.append((isClone == false) ? "title" : "clone");
292 while (path.isEmpty() || QFile::exists(path)) {
294 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
296 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
301 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
304 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
305 KStandardDirs::makeDir(titlePath);
306 return titlePath + titleName + ".png";
310 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
315 void TitleWidget::slotTextTool()
317 m_scene->setTool(TITLE_TEXT);
318 showToolbars(TITLE_TEXT);
319 checkButton(TITLE_TEXT);
322 void TitleWidget::slotRectTool()
324 m_scene->setTool(TITLE_RECTANGLE);
325 showToolbars(TITLE_RECTANGLE);
326 checkButton(TITLE_RECTANGLE);
329 void TitleWidget::slotSelectTool()
331 m_scene->setTool(TITLE_SELECT);
333 // Find out which toolbars need to be shown, depending on selected item
334 TITLETOOL t = TITLE_SELECT;
335 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
337 switch (l.at(0)->type()) {
353 updateCoordinates(l.at(0));
354 updateDimension(l.at(0));
355 updateRotZoom(l.at(0));
358 checkButton(TITLE_SELECT);
361 void TitleWidget::slotImageTool()
363 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
364 if (!url.isEmpty()) {
365 if (url.path().endsWith(".svg")) {
366 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
367 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
368 svg->setZValue(m_count++);
369 svg->setData(Qt::UserRole, url.path());
370 graphicsView->scene()->addItem(svg);
372 QPixmap pix(url.path());
373 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
374 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
375 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
376 image->setData(Qt::UserRole, url.path());
377 image->setZValue(m_count++);
378 graphicsView->scene()->addItem(image);
381 m_scene->setTool(TITLE_SELECT);
382 showToolbars(TITLE_SELECT);
383 checkButton(TITLE_NONE);
386 void TitleWidget::showToolbars(TITLETOOL toolType)
397 case TITLE_RECTANGLE:
407 text_properties->setHidden(!bText);
408 rect_properties->setHidden(!bRect);
409 image_properties->setHidden(!bImage);
410 no_properties->setHidden(!bNone);
413 void TitleWidget::enableToolbars(TITLETOOL toolType)
415 // TITLETOOL is defined in graphicsscenerectmove.h
420 bool bValue_w = false;
421 bool bValue_h = false;
430 case TITLE_RECTANGLE:
445 frame_properties->setEnabled(bFrame);
446 text_properties->setEnabled(bText);
447 rect_properties->setEnabled(bRect);
448 image_properties->setEnabled(bImage);
449 value_w->setEnabled(bValue_w);
450 value_h->setEnabled(bValue_h);
453 void TitleWidget::checkButton(TITLETOOL toolType)
455 bool bSelect = false;
467 case TITLE_RECTANGLE:
477 m_buttonCursor->setChecked(bSelect);
478 m_buttonText->setChecked(bText);
479 m_buttonRect->setChecked(bRect);
480 m_buttonImage->setChecked(bImage);
483 void TitleWidget::displayBackgroundFrame()
485 if (!displayBg->isChecked()) {
486 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
487 QPixmap pattern(20, 20);
491 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
492 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
497 p.fillRect(bg.rect(), br);
499 m_frameImage->setPixmap(bg);
501 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
505 void TitleWidget::initViewports()
507 m_startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
508 m_endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
510 QPen startpen(Qt::DotLine);
511 QPen endpen(Qt::DashDotLine);
512 startpen.setColor(QColor(100, 200, 100, 140));
513 endpen.setColor(QColor(200, 100, 100, 140));
515 m_startViewport->setPen(startpen);
516 m_endViewport->setPen(endpen);
518 startViewportSize->setValue(100);
519 endViewportSize->setValue(100);
521 m_startViewport->setZValue(-1000);
522 m_endViewport->setZValue(-1000);
524 m_startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
525 m_endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
527 graphicsView->scene()->addItem(m_startViewport);
528 graphicsView->scene()->addItem(m_endViewport);
531 void TitleWidget::slotUpdateZoom(int pos)
533 m_scene->setZoom((double) pos / 100);
534 zoom_label->setText(QString::number(pos) + '%');
537 void TitleWidget::slotZoom(bool up)
539 int pos = zoom_slider->value();
542 zoom_slider->setValue(pos);
545 void TitleWidget::slotAdjustZoom()
547 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
548 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
549 if (scalex > scaley) scalex = scaley;
550 int zoompos = (int)(scalex * 7 + 0.5);*/
551 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
552 int zoompos = graphicsView->matrix().m11() * 100;
553 zoom_slider->setValue(zoompos);
554 graphicsView->centerOn(m_frameBorder);
557 void TitleWidget::slotZoomOneToOne()
559 zoom_slider->setValue(100);
560 graphicsView->centerOn(m_frameBorder);
563 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
565 updateAxisButtons(rect); // back to default
567 QColor f = rectFColor->color();
568 f.setAlpha(rectFAlpha->value());
570 penf.setWidth(rectLineWidth->value());
572 QColor b = rectBColor->color();
573 b.setAlpha(rectBAlpha->value());
574 rect->setBrush(QBrush(b));
575 rect->setZValue(m_count++);
576 //setCurrentItem(rect);
577 //graphicsView->setFocus();
580 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
582 updateAxisButtons(tt); // back to default
584 QFont font = font_family->currentFont();
585 font.setPixelSize(font_size->value());
587 font.setBold(buttonBold->isChecked());
588 font.setItalic(buttonItalic->isChecked());
589 font.setUnderline(buttonUnder->isChecked());
592 QColor color = fontColorButton->color();
593 color.setAlpha(textAlpha->value());
594 tt->setDefaultTextColor(color);
595 tt->setZValue(m_count++);
599 void TitleWidget::setCurrentItem(QGraphicsItem *item)
601 m_scene->setSelectedItem(item);
604 void TitleWidget::zIndexChanged(int v)
606 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
612 void TitleWidget::selectionChanged()
614 if (m_scene->tool() != TITLE_SELECT) return;
615 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
616 //toolBox->setItemEnabled(2, false);
617 //toolBox->setItemEnabled(3, false);
618 value_x->blockSignals(true);
619 value_y->blockSignals(true);
620 value_w->blockSignals(true);
621 value_h->blockSignals(true);
622 itemzoom->blockSignals(true);
623 itemrotate->blockSignals(true);
625 bool blockX = !origin_x_left->signalsBlocked();
626 bool blockY = !origin_y_top->signalsBlocked();
627 if (blockX) origin_x_left->blockSignals(true);
628 if (blockY) origin_y_top->blockSignals(true);
629 origin_x_left->setChecked(false);
630 origin_y_top->setChecked(false);
633 enableToolbars(TITLE_NONE);
634 if (blockX) origin_x_left->blockSignals(false);
635 if (blockY) origin_y_top->blockSignals(false);
636 } else if (l.size() == 1) {
637 if (l.at(0)->type() == TEXTITEM) {
638 showToolbars(TITLE_TEXT);
639 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
640 //if (l[0]->hasFocus())
641 toolBox->setCurrentIndex(0);
642 //toolBox->setItemEnabled(2, true);
643 font_size->blockSignals(true);
644 font_family->blockSignals(true);
645 buttonBold->blockSignals(true);
646 buttonItalic->blockSignals(true);
647 buttonUnder->blockSignals(true);
648 fontColorButton->blockSignals(true);
649 textAlpha->blockSignals(true);
650 buttonAlignLeft->blockSignals(true);
651 buttonAlignRight->blockSignals(true);
652 buttonAlignNone->blockSignals(true);
653 buttonAlignCenter->blockSignals(true);
655 QFont font = i->font();
656 font_family->setCurrentFont(font);
657 font_size->setValue(font.pixelSize());
658 buttonBold->setChecked(font.bold());
659 buttonItalic->setChecked(font.italic());
660 buttonUnder->setChecked(font.underline());
662 QColor color = i->defaultTextColor();
663 fontColorButton->setColor(color);
664 textAlpha->setValue(color.alpha());
666 QTextCursor cur = i->textCursor();
667 QTextBlockFormat format = cur.blockFormat();
668 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
669 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
670 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
671 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
673 font_size->blockSignals(false);
674 font_family->blockSignals(false);
675 buttonBold->blockSignals(false);
676 buttonItalic->blockSignals(false);
677 buttonUnder->blockSignals(false);
678 fontColorButton->blockSignals(false);
679 textAlpha->blockSignals(false);
680 buttonAlignLeft->blockSignals(false);
681 buttonAlignRight->blockSignals(false);
682 buttonAlignNone->blockSignals(false);
683 buttonAlignCenter->blockSignals(false);
685 updateAxisButtons(i);
686 updateCoordinates(i);
688 enableToolbars(TITLE_TEXT);
690 } else if ((l.at(0))->type() == RECTITEM) {
691 showToolbars(TITLE_RECTANGLE);
693 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
694 toolBox->setCurrentIndex(0);
695 //toolBox->setItemEnabled(3, true);
696 rectFAlpha->setValue(rec->pen().color().alpha());
697 rectBAlpha->setValue(rec->brush().color().alpha());
698 //kDebug() << rec->brush().color().alpha();
699 QColor fcol = rec->pen().color();
700 QColor bcol = rec->brush().color();
701 //fcol.setAlpha(255);
702 //bcol.setAlpha(255);
703 rectFColor->setColor(fcol);
704 rectBColor->setColor(bcol);
706 rectLineWidth->setValue(rec->pen().width());
708 updateAxisButtons(l.at(0));
709 updateCoordinates(rec);
710 updateDimension(rec);
711 enableToolbars(TITLE_RECTANGLE);
713 } else if (l.at(0)->type() == IMAGEITEM) {
714 showToolbars(TITLE_IMAGE);
716 updateCoordinates(l.at(0));
717 updateDimension(l.at(0));
719 enableToolbars(TITLE_IMAGE);
722 //toolBox->setCurrentIndex(0);
723 showToolbars(TITLE_NONE);
724 enableToolbars(TITLE_NONE);
725 /*frame_properties->setEnabled(false);
726 text_properties->setEnabled(false);
727 rect_properties->setEnabled(false);*/
729 zValue->setValue((int)l.at(0)->zValue());
730 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
731 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
732 value_x->blockSignals(false);
733 value_y->blockSignals(false);
734 value_w->blockSignals(false);
735 value_h->blockSignals(false);
736 itemzoom->blockSignals(false);
737 itemrotate->blockSignals(false);
741 void TitleWidget::slotValueChanged(int type)
743 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
744 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
749 val = value_w->value();
752 val = value_h->value();
756 QGraphicsItem *i = l.at(0);
757 Transform t = m_transformations.value(i);
759 // Ratio width:height
760 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
761 double alpha = (double) t.rotate / 180.0 * M_PI;
771 // Add 0.5 because otherwise incrementing by 1 might have no effect
772 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
773 scale = length / i->boundingRect().width();
776 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
777 scale = length / i->boundingRect().height();
784 qtrans.scale(scale, scale);
785 qtrans.rotate(t.rotate);
786 i->setTransform(qtrans);
787 m_transformations[i] = t;
794 /** \brief Updates position/size of the selected item when a value
795 * of an item (coordinates, size) has changed */
796 void TitleWidget::slotAdjustSelectedItem()
798 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
800 if (l.at(0)->type() == RECTITEM) {
802 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
804 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
805 } else if (l.at(0)->type() == TEXTITEM) {
807 updatePosition(l.at(0));
808 } else if (l.at(0)->type() == IMAGEITEM) {
810 updatePosition(l.at(0));
815 /** \brief Updates width/height int the text fields, regarding transformation matrix */
816 void TitleWidget::updateDimension(QGraphicsItem *i)
818 value_w->blockSignals(true);
819 value_h->blockSignals(true);
822 if (i->type() == IMAGEITEM) {
823 // Get multipliers for rotation/scaling
825 /*Transform t = m_transformations.value(i);
826 QRectF r = i->boundingRect();
827 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
828 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
829 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
830 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
832 value_w->setValue(i->sceneBoundingRect().width());
833 value_h->setValue(i->sceneBoundingRect().height());
834 } else if (i->type() == RECTITEM) {
835 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
836 value_w->setValue((int) r->rect().width());
837 value_h->setValue((int) r->rect().height());
838 } else if (i->type() == TEXTITEM) {
839 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
840 value_w->setValue((int) t->boundingRect().width());
841 value_h->setValue((int) t->boundingRect().height());
844 value_w->blockSignals(false);
845 value_h->blockSignals(false);
848 /** \brief Updates the coordinates in the text fields from the item */
849 void TitleWidget::updateCoordinates(QGraphicsItem *i)
851 // Block signals emitted by this method
852 value_x->blockSignals(true);
853 value_y->blockSignals(true);
855 if (i->type() == TEXTITEM) {
857 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
859 // Set the correct x coordinate value
860 if (origin_x_left->isChecked()) {
861 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
862 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
864 // Origin is at 0 (default)
865 value_x->setValue((int) rec->pos().x());
869 if (origin_y_top->isChecked()) {
870 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
872 value_y->setValue((int) rec->pos().y());
875 } else if (i->type() == RECTITEM) {
877 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
879 if (origin_x_left->isChecked()) {
880 // Origin (0 point) is at m_frameWidth
881 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
883 // Origin is at 0 (default)
884 value_x->setValue((int) rec->pos().x());
887 if (origin_y_top->isChecked()) {
888 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
890 value_y->setValue((int) rec->pos().y());
893 } else if (i->type() == IMAGEITEM) {
895 if (origin_x_left->isChecked()) {
896 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
898 value_x->setValue((int) i->pos().x());
901 if (origin_y_top->isChecked()) {
902 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
904 value_y->setValue((int) i->pos().y());
909 // Stop blocking signals now
910 value_x->blockSignals(false);
911 value_y->blockSignals(false);
914 void TitleWidget::updateRotZoom(QGraphicsItem *i)
916 itemzoom->blockSignals(true);
917 itemrotate->blockSignals(false);
919 Transform t = m_transformations.value(i);
920 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
921 itemrotate->setValue((int)(t.rotate));
923 itemzoom->blockSignals(false);
924 itemrotate->blockSignals(false);
927 /** \brief Updates the position of an item by reading coordinates from the text fields */
928 void TitleWidget::updatePosition(QGraphicsItem *i)
930 if (i->type() == TEXTITEM) {
931 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
934 if (origin_x_left->isChecked()) {
935 /* Origin of the x axis is at m_frameWidth,
936 * and distance from right border of the item to the right
937 * border of the frame is taken.
938 * See comment to slotOriginXClicked().
940 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
942 posX = value_x->value();
946 if (origin_y_top->isChecked()) {
947 /* Same for y axis */
948 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
950 posY = value_y->value();
953 rec->setPos(posX, posY);
955 } else if (i->type() == RECTITEM) {
957 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
960 if (origin_x_left->isChecked()) {
961 posX = m_frameWidth - value_x->value() - rec->rect().width();
963 posX = value_x->value();
967 if (origin_y_top->isChecked()) {
968 posY = m_frameHeight - value_y->value() - rec->rect().height();
970 posY = value_y->value();
973 rec->setPos(posX, posY);
975 } else if (i->type() == IMAGEITEM) {
977 if (origin_x_left->isChecked()) {
978 // Use the sceneBoundingRect because this also regards transformations like zoom
979 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
981 posX = value_x->value();
985 if (origin_y_top->isChecked()) {
986 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
988 posY = value_y->value();
991 i->setPos(posX, posY);
997 void TitleWidget::updateTextOriginX()
999 if (origin_x_left->isChecked()) {
1000 origin_x_left->setText(i18n("\u2212X"));
1002 origin_x_left->setText(i18n("+X"));
1006 void TitleWidget::slotOriginXClicked()
1008 // Update the text displayed on the button.
1009 updateTextOriginX();
1011 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1012 if (l.size() >= 1) {
1013 updateCoordinates(l.at(0));
1015 // Remember x axis setting
1016 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1017 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1019 graphicsView->setFocus();
1022 void TitleWidget::updateTextOriginY()
1024 if (origin_y_top->isChecked()) {
1025 origin_y_top->setText(i18n("\u2212Y"));
1027 origin_y_top->setText(i18n("+Y"));
1031 void TitleWidget::slotOriginYClicked()
1033 // Update the text displayed on the button.
1034 updateTextOriginY();
1036 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1037 if (l.size() >= 1) {
1038 updateCoordinates(l.at(0));
1040 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1041 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1044 graphicsView->setFocus();
1047 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1049 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1050 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1051 origin_x_left->blockSignals(true);
1052 origin_y_top->blockSignals(true);
1054 if (xAxis == TitleDocument::AxisInverted) {
1055 origin_x_left->setChecked(true);
1057 origin_x_left->setChecked(false);
1059 updateTextOriginX();
1061 if (yAxis == TitleDocument::AxisInverted) {
1062 origin_y_top->setChecked(true);
1064 origin_y_top->setChecked(false);
1066 updateTextOriginY();
1068 origin_x_left->blockSignals(false);
1069 origin_y_top->blockSignals(false);
1072 void TitleWidget::slotChangeBackground()
1074 QColor color = kcolorbutton->color();
1075 color.setAlpha(horizontalSlider->value());
1076 m_frameBorder->setBrush(QBrush(color));
1080 * Something (yeah) has changed in our QGraphicsScene.
1082 void TitleWidget::slotChanged()
1084 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1085 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1086 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1091 * If the user has set origin_x_left (everything also for y),
1092 * we need to look whether a text element has been selected. If yes,
1093 * we need to ensure that the right border of the text field
1094 * remains fixed also when some text has been entered.
1096 * This is also known as right-justified, with the difference that
1097 * it is not valid for text but for its boundingRect. Text may still
1098 * be left-justified.
1100 void TitleWidget::textChanged(QGraphicsTextItem *i)
1105 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1107 if (!i->toPlainText().isEmpty()) {
1111 * Don't do anything if the string is empty. If the position
1112 * would be updated here, a newly created text field would
1113 * be set to the position of the last selected text field.
1119 void TitleWidget::slotInsertUnicode()
1121 m_unicodeDialog->exec();
1124 void TitleWidget::slotInsertUnicodeString(QString text)
1126 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1128 if (l.at(0)->type() == TEXTITEM) {
1129 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1130 t->textCursor().insertText(text);
1135 void TitleWidget::slotUpdateText()
1137 QFont font = font_family->currentFont();
1138 font.setPixelSize(font_size->value());
1139 font.setBold(buttonBold->isChecked());
1140 font.setItalic(buttonItalic->isChecked());
1141 font.setUnderline(buttonUnder->isChecked());
1142 QColor color = fontColorButton->color();
1143 color.setAlpha(textAlpha->value());
1145 QGraphicsTextItem* item = NULL;
1146 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1147 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1148 item = static_cast <QGraphicsTextItem *>(l.at(0));
1151 //if (item->textCursor().selection ().isEmpty())
1152 QTextCursor cur = item->textCursor();
1153 QTextBlockFormat format = cur.blockFormat();
1154 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1155 item->setTextWidth(item->boundingRect().width());
1156 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1157 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1158 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1160 format.setAlignment(Qt::AlignLeft);
1161 item->setTextWidth(-1);
1165 item->setFont(font);
1166 item->setDefaultTextColor(color);
1167 cur.select(QTextCursor::Document);
1168 cur.setBlockFormat(format);
1169 item->setTextCursor(cur);
1170 cur.clearSelection();
1171 item->setTextCursor(cur);
1176 void TitleWidget::rectChanged()
1178 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1179 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1180 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1181 QColor f = rectFColor->color();
1182 f.setAlpha(rectFAlpha->value());
1184 penf.setWidth(rectLineWidth->value());
1186 QColor b = rectBColor->color();
1187 b.setAlpha(rectBAlpha->value());
1188 rec->setBrush(QBrush(b));
1192 void TitleWidget::itemScaled(int val)
1194 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1195 if (l.size() == 1) {
1196 Transform x = m_transformations.value(l.at(0));
1197 x.scalex = (double)val / 100.0;
1198 x.scaley = (double)val / 100.0;
1200 qtrans.scale(x.scalex, x.scaley);
1201 qtrans.rotate(x.rotate);
1202 l[0]->setTransform(qtrans);
1203 m_transformations[l.at(0)] = x;
1204 updateDimension(l.at(0));
1208 void TitleWidget::itemRotate(int val)
1210 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1211 if (l.size() == 1) {
1212 Transform x = m_transformations[l.at(0)];
1213 x.rotate = (double)val;
1215 qtrans.scale(x.scalex, x.scaley);
1216 qtrans.rotate(x.rotate);
1217 l[0]->setTransform(qtrans);
1218 m_transformations[l.at(0)] = x;
1219 updateDimension(l.at(0));
1223 void TitleWidget::itemHCenter()
1225 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1226 if (l.size() == 1) {
1227 QGraphicsItem *item = l.at(0);
1229 br = item->sceneBoundingRect();
1230 int width = (int)br.width();
1231 int newPos = (int)((m_frameWidth - width) / 2);
1232 newPos += item->pos().x() - br.left(); // Check item transformation
1233 item->setPos(newPos, item->pos().y());
1234 updateCoordinates(item);
1238 void TitleWidget::itemVCenter()
1240 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1241 if (l.size() == 1) {
1242 QGraphicsItem *item = l.at(0);
1244 br = item->sceneBoundingRect();
1245 int height = (int)br.height();
1246 int newPos = (int)((m_frameHeight - height) / 2);
1247 newPos += item->pos().y() - br.top(); // Check item transformation
1248 item->setPos(item->pos().x(), newPos);
1249 updateCoordinates(item);
1253 void TitleWidget::setupViewports()
1255 //double aspect_ratio = 4.0 / 3.0;//read from project
1256 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1257 QRectF sp(0, 0, startViewportSize->value() * m_frameWidth/100.0 ,startViewportSize->value()* m_frameHeight/100.0);
1258 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth/100.0,endViewportSize->value() * m_frameHeight/100.0);
1259 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1260 QPolygonF spoly(sp);
1261 QPolygonF epoly(ep);
1262 spoly.translate( startViewportX->value(), startViewportY->value() );
1263 epoly.translate( endViewportX->value(), endViewportY->value() );
1264 m_startViewport->setPolygon(spoly);
1265 m_endViewport->setPolygon(epoly);
1266 if (! insertingValues){
1267 m_startViewport->setData(0,startViewportX->value());
1268 m_startViewport->setData(1,startViewportY->value());
1269 m_startViewport->setData(2,startViewportSize->value());
1271 m_endViewport->setData(0,endViewportX->value());
1272 m_endViewport->setData(1,endViewportY->value());
1273 m_endViewport->setData(2,endViewportSize->value());
1277 void TitleWidget::loadTitle()
1279 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Load Title"));
1280 if (!url.isEmpty()) {
1281 QList<QGraphicsItem *> items = m_scene->items();
1282 for (int i = 0; i < items.size(); i++) {
1283 if (items.at(i)->zValue() > -1000) delete items.at(i);
1285 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
1286 insertingValues=true;
1287 startViewportX->setValue(m_startViewport->data(0).toInt());
1288 startViewportY->setValue(m_startViewport->data(1).toInt());
1289 startViewportSize->setValue(m_startViewport->data(2).toInt());
1290 endViewportX->setValue(m_endViewport->data(0).toInt());
1291 endViewportY->setValue(m_endViewport->data(1).toInt());
1292 endViewportSize->setValue(m_endViewport->data(2).toInt());
1293 insertingValues=false;
1298 void TitleWidget::saveTitle(KUrl url)
1300 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Save Title"));
1301 if (!url.isEmpty()) {
1302 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport) == false)
1303 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1307 QDomDocument TitleWidget::xml()
1309 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1310 if (cropImage->isChecked()) {
1311 doc.documentElement().setAttribute("crop", 1);
1316 void TitleWidget::setXml(QDomDocument doc)
1318 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport);
1319 QDomElement e = doc.documentElement();
1320 cropImage->setChecked(e.hasAttribute("crop"));
1321 m_transformations.clear();
1322 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1323 const double PI = 4.0 * atan(1.0);
1324 for (int i = 0; i < items.count(); i++) {
1325 QTransform t = items.at(i)->transform();
1329 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1330 m_transformations[items.at(i)] = x;
1332 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1333 QColor background_color = m_titledocument.getBackgroundColor();
1334 horizontalSlider->blockSignals(true);
1335 kcolorbutton->blockSignals(true);
1336 horizontalSlider->setValue(background_color.alpha());
1337 background_color.setAlpha(255);
1338 kcolorbutton->setColor(background_color);
1339 horizontalSlider->blockSignals(false);
1340 kcolorbutton->blockSignals(false);
1345 const QRect TitleWidget::renderedRect()
1349 int maxX = m_frameWidth;
1350 int maxY = m_frameHeight;
1351 if (!cropImage->isChecked()) {
1352 m_scene->removeItem(m_startViewport);
1353 m_scene->removeItem(m_endViewport);
1354 QRect boundingRect = m_scene->itemsBoundingRect().toRect();
1355 if (boundingRect.left() < 0) minX = boundingRect.left();
1356 if (boundingRect.top() < 0) minY = boundingRect.top();
1357 if (boundingRect.right() > maxX) maxX = boundingRect.right();
1358 if (boundingRect.bottom() > maxY) maxY = boundingRect.bottom();
1366 QRect rect(minX, minY, maxX, maxY);
1370 QImage TitleWidget::renderedPixmap()
1372 QRect rect = renderedRect();
1373 QImage pix(rect.width(), rect.height(), QImage::Format_ARGB32);
1374 pix.fill(Qt::transparent);
1375 QPainter painter(&pix);
1376 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing);
1377 m_scene->clearTextSelection();
1378 QPen framepen = m_frameBorder->pen();
1379 m_frameBorder->setPen(Qt::NoPen);
1380 m_startViewport->setVisible(false);
1381 m_endViewport->setVisible(false);
1382 m_frameImage->setVisible(false);
1384 m_scene->render(&painter, QRectF(), rect); //QRectF(minX, minY, maxX - minX, maxY - minY));
1386 m_frameBorder->setPen(framepen);
1387 m_startViewport->setVisible(true);
1388 m_endViewport->setVisible(true);
1389 m_frameImage->setVisible(true);
1393 /** \brief Connected to the accepted signal - calls writeChoices */
1394 void TitleWidget::slotAccepted()
1399 /** \brief Store the current choices of font, background and rect values */
1400 void TitleWidget::writeChoices()
1402 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1403 KSharedConfigPtr config = KGlobal::config();
1404 KConfigGroup titleConfig(config, "TitleWidget");
1405 // Write the entries
1406 titleConfig.writeEntry("font_family", font_family->currentFont());
1407 //titleConfig.writeEntry("font_size", font_size->value());
1408 titleConfig.writeEntry("font_pixel_size", font_size->value());
1409 titleConfig.writeEntry("font_color", fontColorButton->color());
1410 titleConfig.writeEntry("font_alpha", textAlpha->value());
1411 titleConfig.writeEntry("font_bold", buttonBold->isChecked());
1412 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1413 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1415 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1416 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1417 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1418 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1419 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1421 titleConfig.writeEntry("background_color", kcolorbutton->color());
1422 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1424 titleConfig.writeEntry("crop_image", cropImage->isChecked());
1426 //! \todo Not sure if I should sync - it is probably safe to do it
1431 /** \brief Read the last stored choices into the dialog */
1432 void TitleWidget::readChoices()
1434 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1435 KSharedConfigPtr config = KGlobal::config();
1436 KConfigGroup titleConfig(config, "TitleWidget");
1438 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1439 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1440 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1441 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1442 buttonBold->setChecked(titleConfig.readEntry("font_bold", buttonBold->isChecked()));
1443 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1444 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1446 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1447 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1448 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1449 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1450 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1452 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1453 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1455 cropImage->setChecked(titleConfig.readEntry("crop_image", cropImage->isChecked()));