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;
45 TitleWidget::TitleWidget(KUrl url, QString projectTitlePath, Render *render, QWidget *parent) :
48 m_startViewport(NULL),
52 m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
53 m_projectTitlePath(projectTitlePath)
56 setFont(KGlobalSettings::toolBarFont());
57 //toolBox->setFont(KGlobalSettings::toolBarFont());
58 frame_properties->setEnabled(false);
59 rect_properties->setFixedHeight(frame_properties->height() + 4);
60 text_properties->setFixedHeight(frame_properties->height() + 4);
61 m_frameWidth = render->renderWidth();
62 m_frameHeight = render->renderHeight();
64 connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
65 connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
67 connect(fontColorButton, SIGNAL(clicked()), this, SLOT(slotUpdateText())) ;
68 connect(font_family, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(slotUpdateText())) ;
69 connect(font_size, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText())) ;
70 connect(textAlpha, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateText()));
72 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
73 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
74 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
75 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
76 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
78 connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
79 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
80 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
81 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
82 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
83 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
85 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
86 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
87 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
88 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
89 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
91 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
92 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
94 m_signalMapper = new QSignalMapper(this);
95 m_signalMapper->setMapping(value_w, ValueWidth);
96 m_signalMapper->setMapping(value_h, ValueHeight);
97 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
98 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
99 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
101 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
102 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
103 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
104 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
105 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
106 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
107 connect(buttonBold, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
108 connect(buttonItalic, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
109 connect(buttonUnder, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
110 connect(buttonAlignLeft, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
111 connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
112 connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
113 connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
114 connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
115 connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
117 connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
120 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
122 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
123 buttonRealSize->setIcon(KIcon("zoom-original"));
124 buttonBold->setIcon(KIcon("format-text-bold"));
125 buttonItalic->setIcon(KIcon("format-text-italic"));
126 buttonUnder->setIcon(KIcon("format-text-underline"));
127 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
128 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
129 buttonAlignRight->setIcon(KIcon("format-justify-right"));
130 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
131 buttonInsertUnicode->setIcon(KIcon("kdenlive-insert-unicode"));
133 buttonAlignNone->setToolTip(i18n("No alignment"));
134 buttonAlignRight->setToolTip(i18n("Align right"));
135 buttonAlignLeft->setToolTip(i18n("Align left"));
136 buttonAlignCenter->setToolTip(i18n("Align center"));
137 buttonInsertUnicode->setToolTip(i18n("Insert Unicode character (Shift+Ctrl+U)"));
138 buttonInsertUnicode->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
139 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
140 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
141 rectBColor->setToolTip(i18n("Select fill color"));
142 rectFColor->setToolTip(i18n("Select border color"));
143 rectBAlpha->setToolTip(i18n("Fill transparency"));
144 rectFAlpha->setToolTip(i18n("Border transparency"));
145 zoom_slider->setToolTip(i18n("Zoom"));
146 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
147 buttonFitZoom->setToolTip(i18n("Fit zoom"));
148 kcolorbutton->setToolTip(i18n("Select background color"));
149 horizontalSlider->setToolTip(i18n("Background Transparency"));
151 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
152 itemhcenter->setToolTip(i18n("Align item horizontally"));
153 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
154 itemvcenter->setToolTip(i18n("Align item vertically"));
156 QHBoxLayout *layout = new QHBoxLayout;
157 frame_toolbar->setLayout(layout);
158 layout->setContentsMargins(2, 2, 2, 2);
159 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
161 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), i18n("Selection Tool (Alt+S)"));
162 m_buttonCursor->setCheckable(true);
163 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
164 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
166 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), i18n("Add Text (Alt+T)"));
167 m_buttonText->setCheckable(true);
168 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
169 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
171 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), i18n("Add Rectangle (Alt+R)"));
172 m_buttonRect->setCheckable(true);
173 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
174 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
176 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), i18n("Add Image (Alt+I)"));
177 m_buttonImage->setCheckable(false);
178 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
179 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
181 m_toolbar->addSeparator();
183 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
184 m_buttonLoad->setCheckable(false);
185 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
186 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
188 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
189 m_buttonSave->setCheckable(false);
190 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
191 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
193 layout->addWidget(m_toolbar);
195 // initialize graphic scene
196 m_scene = new GraphicsSceneRectMove(this);
197 graphicsView->setScene(m_scene);
198 m_titledocument.setScene(m_scene);
199 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
201 // a gradient background
202 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
203 gradient->setSpread(QGradient::ReflectSpread);
204 scene->setBackgroundBrush(*gradient);*/
206 m_frameImage = new QGraphicsPixmapItem();
208 qtrans.scale(2.0, 2.0);
209 m_frameImage->setTransform(qtrans);
210 m_frameImage->setZValue(-1200);
211 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
212 displayBackgroundFrame();
213 graphicsView->scene()->addItem(m_frameImage);
215 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
216 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
217 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
218 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
219 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
220 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
221 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
222 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
224 QPen framepen(Qt::DotLine);
225 framepen.setColor(Qt::red);
227 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
228 m_frameBorder->setPen(framepen);
229 m_frameBorder->setZValue(-1100);
230 m_frameBorder->setBrush(Qt::transparent);
231 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
232 graphicsView->scene()->addItem(m_frameBorder);
234 // mbd: load saved settings
238 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
239 graphicsView->show();
240 //graphicsView->setRenderHint(QPainter::Antialiasing);
241 graphicsView->setInteractive(true);
242 //graphicsView->resize(400, 300);
243 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
244 toolBox->setItemEnabled(2, false);
245 if (!url.isEmpty()) {
246 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
252 showToolbars(TITLE_NONE);
255 TitleWidget::~TitleWidget()
259 delete m_buttonImage;
260 delete m_buttonCursor;
264 delete m_unicodeDialog;
265 delete m_frameBorder;
267 delete m_startViewport;
268 delete m_endViewport;
270 delete m_signalMapper;
274 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
277 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
278 KStandardDirs::makeDir(titlePath);
279 titlePath.append((isClone == false) ? "title" : "clone");
282 while (path.isEmpty() || QFile::exists(path)) {
284 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
286 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
291 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
294 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
295 KStandardDirs::makeDir(titlePath);
296 return titlePath + titleName + ".png";
300 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
305 void TitleWidget::slotTextTool()
307 m_scene->setTool(TITLE_TEXT);
308 showToolbars(TITLE_TEXT);
309 m_buttonRect->setChecked(false);
310 m_buttonCursor->setChecked(false);
313 void TitleWidget::slotRectTool()
315 m_scene->setTool(TITLE_RECTANGLE);
316 showToolbars(TITLE_RECTANGLE);
317 m_buttonText->setChecked(false);
318 m_buttonCursor->setChecked(false);
319 m_buttonRect->setChecked(true);
322 void TitleWidget::slotSelectTool()
324 m_scene->setTool(TITLE_SELECT);
326 // Find out which toolbars need to be shown, depending on selected item
327 TITLETOOL t = TITLE_SELECT;
328 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
330 switch (l.at(0)->type()) {
346 updateCoordinates(l.at(0));
347 updateDimension(l.at(0));
348 updateRotZoom(l.at(0));
351 m_buttonCursor->setChecked(true);
352 m_buttonText->setChecked(false);
353 m_buttonRect->setChecked(false);
356 void TitleWidget::slotImageTool()
358 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
359 if (!url.isEmpty()) {
360 if (url.path().endsWith(".svg")) {
361 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
362 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
363 svg->setZValue(m_count++);
364 svg->setData(Qt::UserRole, url.path());
365 graphicsView->scene()->addItem(svg);
367 QPixmap pix(url.path());
368 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
369 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
370 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
371 image->setData(Qt::UserRole, url.path());
372 image->setZValue(m_count++);
373 graphicsView->scene()->addItem(image);
376 m_scene->setTool(TITLE_SELECT);
377 showToolbars(TITLE_SELECT);
378 m_buttonRect->setChecked(false);
379 m_buttonCursor->setChecked(true);
380 m_buttonText->setChecked(false);
383 void TitleWidget::showToolbars(TITLETOOL toolType)
393 case TITLE_RECTANGLE:
396 case TITLE_IMAGE: //fall through
401 text_properties->setHidden(!bText);
402 rect_properties->setHidden(!bRect);
403 no_properties->setHidden(!bNone);
406 void TitleWidget::enableToolbars(TITLETOOL toolType)
408 // TITLETOOL is defined in graphicsscenerectmove.h
412 bool bValue_w = false;
413 bool bValue_h = false;
422 case TITLE_RECTANGLE:
436 frame_properties->setEnabled(bFrame);
437 text_properties->setEnabled(bText);
438 rect_properties->setEnabled(bRect);
439 value_w->setEnabled(bValue_w);
440 value_h->setEnabled(bValue_h);
443 void TitleWidget::displayBackgroundFrame()
445 if (!displayBg->isChecked()) {
446 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
447 QPixmap pattern(20, 20);
451 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
452 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
457 p.fillRect(bg.rect(), br);
459 m_frameImage->setPixmap(bg);
461 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
465 void TitleWidget::initViewports()
467 m_startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
468 m_endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
470 QPen startpen(Qt::DotLine);
471 QPen endpen(Qt::DashDotLine);
472 startpen.setColor(QColor(100, 200, 100, 140));
473 endpen.setColor(QColor(200, 100, 100, 140));
475 m_startViewport->setPen(startpen);
476 m_endViewport->setPen(endpen);
478 startViewportSize->setValue(40);
479 endViewportSize->setValue(40);
481 m_startViewport->setZValue(-1000);
482 m_endViewport->setZValue(-1000);
484 m_startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
485 m_endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
487 graphicsView->scene()->addItem(m_startViewport);
488 graphicsView->scene()->addItem(m_endViewport);
491 void TitleWidget::slotUpdateZoom(int pos)
493 m_scene->setZoom((double) pos / 100);
494 zoom_label->setText(QString::number(pos) + '%');
497 void TitleWidget::slotZoom(bool up)
499 int pos = zoom_slider->value();
502 zoom_slider->setValue(pos);
505 void TitleWidget::slotAdjustZoom()
507 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
508 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
509 if (scalex > scaley) scalex = scaley;
510 int zoompos = (int)(scalex * 7 + 0.5);*/
511 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
512 int zoompos = graphicsView->matrix().m11() * 100;
513 zoom_slider->setValue(zoompos);
514 graphicsView->centerOn(m_frameBorder);
517 void TitleWidget::slotZoomOneToOne()
519 zoom_slider->setValue(100);
520 graphicsView->centerOn(m_frameBorder);
523 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
525 QColor f = rectFColor->color();
526 f.setAlpha(rectFAlpha->value());
528 penf.setWidth(rectLineWidth->value());
530 QColor b = rectBColor->color();
531 b.setAlpha(rectBAlpha->value());
532 rect->setBrush(QBrush(b));
533 rect->setZValue(m_count++);
534 //setCurrentItem(rect);
535 //graphicsView->setFocus();
538 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
540 QFont font = font_family->currentFont();
541 font.setPixelSize(font_size->value());
543 font.setBold(buttonBold->isChecked());
544 font.setItalic(buttonItalic->isChecked());
545 font.setUnderline(buttonUnder->isChecked());
548 QColor color = fontColorButton->color();
549 color.setAlpha(textAlpha->value());
550 tt->setDefaultTextColor(color);
551 tt->setZValue(m_count++);
555 void TitleWidget::setCurrentItem(QGraphicsItem *item)
557 m_scene->setSelectedItem(item);
560 void TitleWidget::zIndexChanged(int v)
562 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
568 void TitleWidget::selectionChanged()
570 if (m_scene->tool() != TITLE_SELECT) return;
571 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
572 //toolBox->setItemEnabled(2, false);
573 //toolBox->setItemEnabled(3, false);
574 value_x->blockSignals(true);
575 value_y->blockSignals(true);
576 value_w->blockSignals(true);
577 value_h->blockSignals(true);
578 itemzoom->blockSignals(true);
579 itemrotate->blockSignals(true);
581 bool blockX = !origin_x_left->signalsBlocked();
582 bool blockY = !origin_y_top->signalsBlocked();
583 if (blockX) origin_x_left->blockSignals(true);
584 if (blockY) origin_y_top->blockSignals(true);
585 origin_x_left->setChecked(false);
586 origin_y_top->setChecked(false);
589 enableToolbars(TITLE_NONE);
590 if (blockX) origin_x_left->blockSignals(false);
591 if (blockY) origin_y_top->blockSignals(false);
592 } else if (l.size() == 1) {
593 if (l.at(0)->type() == TEXTITEM) {
594 showToolbars(TITLE_TEXT);
595 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
596 //if (l[0]->hasFocus())
597 toolBox->setCurrentIndex(0);
598 //toolBox->setItemEnabled(2, true);
599 font_size->blockSignals(true);
600 font_family->blockSignals(true);
601 buttonBold->blockSignals(true);
602 buttonItalic->blockSignals(true);
603 buttonUnder->blockSignals(true);
604 fontColorButton->blockSignals(true);
605 textAlpha->blockSignals(true);
606 buttonAlignLeft->blockSignals(true);
607 buttonAlignRight->blockSignals(true);
608 buttonAlignNone->blockSignals(true);
609 buttonAlignCenter->blockSignals(true);
611 QFont font = i->font();
612 font_family->setCurrentFont(font);
613 font_size->setValue(font.pixelSize());
614 buttonBold->setChecked(font.bold());
615 buttonItalic->setChecked(font.italic());
616 buttonUnder->setChecked(font.underline());
618 QColor color = i->defaultTextColor();
619 fontColorButton->setColor(color);
620 textAlpha->setValue(color.alpha());
622 QTextCursor cur = i->textCursor();
623 QTextBlockFormat format = cur.blockFormat();
624 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
625 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
626 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
627 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
629 font_size->blockSignals(false);
630 font_family->blockSignals(false);
631 buttonBold->blockSignals(false);
632 buttonItalic->blockSignals(false);
633 buttonUnder->blockSignals(false);
634 fontColorButton->blockSignals(false);
635 textAlpha->blockSignals(false);
636 buttonAlignLeft->blockSignals(false);
637 buttonAlignRight->blockSignals(false);
638 buttonAlignNone->blockSignals(false);
639 buttonAlignCenter->blockSignals(false);
641 updateAxisButtons(i);
642 updateCoordinates(i);
644 enableToolbars(TITLE_TEXT);
646 } else if ((l.at(0))->type() == RECTITEM) {
647 showToolbars(TITLE_RECTANGLE);
649 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
650 toolBox->setCurrentIndex(0);
651 //toolBox->setItemEnabled(3, true);
652 rectFAlpha->setValue(rec->pen().color().alpha());
653 rectBAlpha->setValue(rec->brush().color().alpha());
654 //kDebug() << rec->brush().color().alpha();
655 QColor fcol = rec->pen().color();
656 QColor bcol = rec->brush().color();
657 //fcol.setAlpha(255);
658 //bcol.setAlpha(255);
659 rectFColor->setColor(fcol);
660 rectBColor->setColor(bcol);
662 rectLineWidth->setValue(rec->pen().width());
664 updateAxisButtons(l.at(0));
665 updateCoordinates(rec);
666 updateDimension(rec);
667 enableToolbars(TITLE_RECTANGLE);
669 } else if (l.at(0)->type() == IMAGEITEM) {
670 updateCoordinates(l.at(0));
671 updateDimension(l.at(0));
673 enableToolbars(TITLE_IMAGE);
676 //toolBox->setCurrentIndex(0);
677 enableToolbars(TITLE_NONE);
678 /*frame_properties->setEnabled(false);
679 text_properties->setEnabled(false);
680 rect_properties->setEnabled(false);*/
682 zValue->setValue((int)l.at(0)->zValue());
683 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
684 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
685 value_x->blockSignals(false);
686 value_y->blockSignals(false);
687 value_w->blockSignals(false);
688 value_h->blockSignals(false);
689 itemzoom->blockSignals(false);
690 itemrotate->blockSignals(false);
694 void TitleWidget::slotValueChanged(int type)
696 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
697 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
702 val = value_w->value();
705 val = value_h->value();
709 QGraphicsItem *i = l.at(0);
710 Transform t = m_transformations.value(i);
712 // Ratio width:height
713 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
714 double alpha = (double) t.rotate / 180.0 * M_PI;
724 // Add 0.5 because otherwise incrementing by 1 might have no effect
725 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
726 scale = length / i->boundingRect().width();
729 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
730 scale = length / i->boundingRect().height();
737 qtrans.scale(scale, scale);
738 qtrans.rotate(t.rotate);
739 i->setTransform(qtrans);
740 m_transformations[i] = t;
747 /** \brief Updates position/size of the selected item when a value
748 * of an item (coordinates, size) has changed */
749 void TitleWidget::slotAdjustSelectedItem()
751 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
753 if (l.at(0)->type() == RECTITEM) {
755 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
757 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
758 } else if (l.at(0)->type() == TEXTITEM) {
760 updatePosition(l.at(0));
761 } else if (l.at(0)->type() == IMAGEITEM) {
763 updatePosition(l.at(0));
768 /** \brief Updates width/height int the text fields, regarding transformation matrix */
769 void TitleWidget::updateDimension(QGraphicsItem *i)
771 value_w->blockSignals(true);
772 value_h->blockSignals(true);
775 if (i->type() == IMAGEITEM) {
776 // Get multipliers for rotation/scaling
778 /*Transform t = m_transformations.value(i);
779 QRectF r = i->boundingRect();
780 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
781 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
782 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
783 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
785 value_w->setValue(i->sceneBoundingRect().width());
786 value_h->setValue(i->sceneBoundingRect().height());
787 } else if (i->type() == RECTITEM) {
788 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
789 value_w->setValue((int) r->rect().width());
790 value_h->setValue((int) r->rect().height());
791 } else if (i->type() == TEXTITEM) {
792 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
793 value_w->setValue((int) t->boundingRect().width());
794 value_h->setValue((int) t->boundingRect().height());
797 value_w->blockSignals(false);
798 value_h->blockSignals(false);
801 /** \brief Updates the coordinates in the text fields from the item */
802 void TitleWidget::updateCoordinates(QGraphicsItem *i)
804 // Block signals emitted by this method
805 value_x->blockSignals(true);
806 value_y->blockSignals(true);
808 if (i->type() == TEXTITEM) {
810 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
812 // Set the correct x coordinate value
813 if (origin_x_left->isChecked()) {
814 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
815 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
817 // Origin is at 0 (default)
818 value_x->setValue((int) rec->pos().x());
822 if (origin_y_top->isChecked()) {
823 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
825 value_y->setValue((int) rec->pos().y());
828 } else if (i->type() == RECTITEM) {
830 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
832 if (origin_x_left->isChecked()) {
833 // Origin (0 point) is at m_frameWidth
834 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
836 // Origin is at 0 (default)
837 value_x->setValue((int) rec->pos().x());
840 if (origin_y_top->isChecked()) {
841 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
843 value_y->setValue((int) rec->pos().y());
846 } else if (i->type() == IMAGEITEM) {
848 if (origin_x_left->isChecked()) {
849 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
851 value_x->setValue((int) i->pos().x());
854 if (origin_y_top->isChecked()) {
855 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
857 value_y->setValue((int) i->pos().y());
862 // Stop blocking signals now
863 value_x->blockSignals(false);
864 value_y->blockSignals(false);
867 void TitleWidget::updateRotZoom(QGraphicsItem *i)
869 itemzoom->blockSignals(true);
870 itemrotate->blockSignals(false);
872 Transform t = m_transformations.value(i);
873 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
874 itemrotate->setValue((int)(t.rotate));
876 itemzoom->blockSignals(false);
877 itemrotate->blockSignals(false);
880 /** \brief Updates the position of an item by reading coordinates from the text fields */
881 void TitleWidget::updatePosition(QGraphicsItem *i)
883 if (i->type() == TEXTITEM) {
884 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
887 if (origin_x_left->isChecked()) {
888 /* Origin of the x axis is at m_frameWidth,
889 * and distance from right border of the item to the right
890 * border of the frame is taken.
891 * See comment to slotOriginXClicked().
893 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
895 posX = value_x->value();
899 if (origin_y_top->isChecked()) {
900 /* Same for y axis */
901 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
903 posY = value_y->value();
906 rec->setPos(posX, posY);
908 } else if (i->type() == RECTITEM) {
910 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
913 if (origin_x_left->isChecked()) {
914 posX = m_frameWidth - value_x->value() - rec->rect().width();
916 posX = value_x->value();
920 if (origin_y_top->isChecked()) {
921 posY = m_frameHeight - value_y->value() - rec->rect().height();
923 posY = value_y->value();
926 rec->setPos(posX, posY);
928 } else if (i->type() == IMAGEITEM) {
930 if (origin_x_left->isChecked()) {
931 // Use the sceneBoundingRect because this also regards transformations like zoom
932 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
934 posX = value_x->value();
938 if (origin_y_top->isChecked()) {
939 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
941 posY = value_y->value();
944 i->setPos(posX, posY);
950 void TitleWidget::updateTextOriginX()
952 if (origin_x_left->isChecked()) {
953 origin_x_left->setText(i18n("\u2212X"));
955 origin_x_left->setText(i18n("+X"));
959 void TitleWidget::slotOriginXClicked()
961 // Update the text displayed on the button.
964 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
966 updateCoordinates(l.at(0));
968 // Remember x axis setting
969 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
970 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
972 graphicsView->setFocus();
975 void TitleWidget::updateTextOriginY()
977 if (origin_y_top->isChecked()) {
978 origin_y_top->setText(i18n("\u2212Y"));
980 origin_y_top->setText(i18n("+Y"));
984 void TitleWidget::slotOriginYClicked()
986 // Update the text displayed on the button.
989 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
991 updateCoordinates(l.at(0));
993 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
994 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
997 graphicsView->setFocus();
1000 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1002 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1003 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1004 origin_x_left->blockSignals(true);
1005 origin_y_top->blockSignals(true);
1007 if (xAxis == TitleDocument::AxisInverted) {
1008 origin_x_left->setChecked(true);
1010 origin_x_left->setChecked(false);
1012 updateTextOriginX();
1014 if (yAxis == TitleDocument::AxisInverted) {
1015 origin_y_top->setChecked(true);
1017 origin_y_top->setChecked(false);
1019 updateTextOriginY();
1021 origin_x_left->blockSignals(false);
1022 origin_y_top->blockSignals(false);
1025 void TitleWidget::slotChangeBackground()
1027 QColor color = kcolorbutton->color();
1028 color.setAlpha(horizontalSlider->value());
1029 m_frameBorder->setBrush(QBrush(color));
1033 * Something (yeah) has changed in our QGraphicsScene.
1035 void TitleWidget::slotChanged()
1037 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1038 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1039 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1044 * If the user has set origin_x_left (everything also for y),
1045 * we need to look whether a text element has been selected. If yes,
1046 * we need to ensure that the right border of the text field
1047 * remains fixed also when some text has been entered.
1049 * This is also known as right-justified, with the difference that
1050 * it is not valid for text but for its boundingRect. Text may still
1051 * be left-justified.
1053 void TitleWidget::textChanged(QGraphicsTextItem *i)
1058 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1060 if (!i->toPlainText().isEmpty()) {
1064 * Don't do anything if the string is empty. If the position
1065 * would be updated here, a newly created text field would
1066 * be set to the position of the last selected text field.
1072 void TitleWidget::slotInsertUnicode()
1074 m_unicodeDialog->exec();
1077 void TitleWidget::slotInsertUnicodeString(QString text)
1079 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1081 if (l.at(0)->type() == TEXTITEM) {
1082 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1083 t->textCursor().insertText(text);
1088 void TitleWidget::slotUpdateText()
1090 QFont font = font_family->currentFont();
1091 font.setPixelSize(font_size->value());
1092 font.setBold(buttonBold->isChecked());
1093 font.setItalic(buttonItalic->isChecked());
1094 font.setUnderline(buttonUnder->isChecked());
1095 QColor color = fontColorButton->color();
1096 color.setAlpha(textAlpha->value());
1098 QGraphicsTextItem* item = NULL;
1099 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1100 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1101 item = static_cast <QGraphicsTextItem *>(l.at(0));
1104 //if (item->textCursor().selection ().isEmpty())
1105 QTextCursor cur = item->textCursor();
1106 QTextBlockFormat format = cur.blockFormat();
1107 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1108 item->setTextWidth(item->boundingRect().width());
1109 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1110 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1111 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1113 format.setAlignment(Qt::AlignLeft);
1114 item->setTextWidth(-1);
1118 item->setFont(font);
1119 item->setDefaultTextColor(color);
1120 cur.select(QTextCursor::Document);
1121 cur.setBlockFormat(format);
1122 item->setTextCursor(cur);
1123 cur.clearSelection();
1124 item->setTextCursor(cur);
1129 void TitleWidget::rectChanged()
1131 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1132 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1133 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1134 QColor f = rectFColor->color();
1135 f.setAlpha(rectFAlpha->value());
1137 penf.setWidth(rectLineWidth->value());
1139 QColor b = rectBColor->color();
1140 b.setAlpha(rectBAlpha->value());
1141 rec->setBrush(QBrush(b));
1145 void TitleWidget::itemScaled(int val)
1147 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1148 if (l.size() == 1) {
1149 Transform x = m_transformations.value(l.at(0));
1150 x.scalex = (double)val / 100.0;
1151 x.scaley = (double)val / 100.0;
1153 qtrans.scale(x.scalex, x.scaley);
1154 qtrans.rotate(x.rotate);
1155 l[0]->setTransform(qtrans);
1156 m_transformations[l.at(0)] = x;
1157 updateDimension(l.at(0));
1161 void TitleWidget::itemRotate(int val)
1163 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1164 if (l.size() == 1) {
1165 Transform x = m_transformations[l.at(0)];
1166 x.rotate = (double)val;
1168 qtrans.scale(x.scalex, x.scaley);
1169 qtrans.rotate(x.rotate);
1170 l[0]->setTransform(qtrans);
1171 m_transformations[l.at(0)] = x;
1172 updateDimension(l.at(0));
1176 void TitleWidget::itemHCenter()
1178 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1179 if (l.size() == 1) {
1180 QGraphicsItem *item = l.at(0);
1182 br = item->sceneBoundingRect();
1183 int width = (int)br.width();
1184 int newPos = (int)((m_frameWidth - width) / 2);
1185 newPos += item->pos().x() - br.left(); // Check item transformation
1186 item->setPos(newPos, item->pos().y());
1187 updateCoordinates(item);
1191 void TitleWidget::itemVCenter()
1193 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1194 if (l.size() == 1) {
1195 QGraphicsItem *item = l.at(0);
1197 br = item->sceneBoundingRect();
1198 int height = (int)br.height();
1199 int newPos = (int)((m_frameHeight - height) / 2);
1200 newPos += item->pos().y() - br.top(); // Check item transformation
1201 item->setPos(item->pos().x(), newPos);
1202 updateCoordinates(item);
1206 void TitleWidget::setupViewports()
1208 double aspect_ratio = 4.0 / 3.0;//read from project
1210 QRectF sp(0, 0, 0, 0);
1211 QRectF ep(0, 0, 0, 0);
1213 double sv_size = startViewportSize->value();
1214 double ev_size = endViewportSize->value();
1215 sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio);
1216 ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio);
1218 m_startViewport->setPos(startViewportX->value(), startViewportY->value());
1219 m_endViewport->setPos(endViewportX->value(), endViewportY->value());
1221 m_startViewport->setPolygon(QPolygonF(sp));
1222 m_endViewport->setPolygon(QPolygonF(ep));
1226 void TitleWidget::loadTitle()
1228 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Load Title"));
1229 if (!url.isEmpty()) {
1230 QList<QGraphicsItem *> items = m_scene->items();
1231 for (int i = 0; i < items.size(); i++) {
1232 if (items.at(i)->zValue() > -1000) delete items.at(i);
1234 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
1239 void TitleWidget::saveTitle(KUrl url)
1241 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Save Title"));
1242 if (!url.isEmpty()) {
1243 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport) == false)
1244 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1248 QDomDocument TitleWidget::xml()
1250 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1251 if (cropImage->isChecked()) {
1252 doc.documentElement().setAttribute("crop", 1);
1257 void TitleWidget::setXml(QDomDocument doc)
1259 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport);
1260 QDomElement e = doc.documentElement();
1261 cropImage->setChecked(e.hasAttribute("crop"));
1262 m_transformations.clear();
1263 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1264 const double PI = 4.0 * atan(1.0);
1265 for (int i = 0; i < items.count(); i++) {
1266 QTransform t = items.at(i)->transform();
1270 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1271 m_transformations[items.at(i)] = x;
1273 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1274 QColor background_color = m_titledocument.getBackgroundColor();
1275 horizontalSlider->blockSignals(true);
1276 kcolorbutton->blockSignals(true);
1277 horizontalSlider->setValue(background_color.alpha());
1278 background_color.setAlpha(255);
1279 kcolorbutton->setColor(background_color);
1280 horizontalSlider->blockSignals(false);
1281 kcolorbutton->blockSignals(false);
1286 const QRect TitleWidget::renderedRect()
1290 int maxX = m_frameWidth;
1291 int maxY = m_frameHeight;
1292 if (!cropImage->isChecked()) {
1293 m_scene->removeItem(m_startViewport);
1294 m_scene->removeItem(m_endViewport);
1295 QRect boundingRect = m_scene->itemsBoundingRect().toRect();
1296 if (boundingRect.left() < 0) minX = boundingRect.left();
1297 if (boundingRect.top() < 0) minY = boundingRect.top();
1298 if (boundingRect.right() > maxX) maxX = boundingRect.right();
1299 if (boundingRect.bottom() > maxY) maxY = boundingRect.bottom();
1307 QRect rect(minX, minY, maxX, maxY);
1311 QImage TitleWidget::renderedPixmap()
1313 QRect rect = renderedRect();
1314 QImage pix(rect.width(), rect.height(), QImage::Format_ARGB32);
1315 pix.fill(Qt::transparent);
1316 QPainter painter(&pix);
1317 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing);
1318 m_scene->clearTextSelection();
1319 QPen framepen = m_frameBorder->pen();
1320 m_frameBorder->setPen(Qt::NoPen);
1321 m_startViewport->setVisible(false);
1322 m_endViewport->setVisible(false);
1323 m_frameImage->setVisible(false);
1325 m_scene->render(&painter, QRectF(), rect); //QRectF(minX, minY, maxX - minX, maxY - minY));
1327 m_frameBorder->setPen(framepen);
1328 m_startViewport->setVisible(true);
1329 m_endViewport->setVisible(true);
1330 m_frameImage->setVisible(true);
1334 /** \brief Connected to the accepted signal - calls writeChoices */
1335 void TitleWidget::slotAccepted()
1340 /** \brief Store the current choices of font, background and rect values */
1341 void TitleWidget::writeChoices()
1343 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1344 KSharedConfigPtr config = KGlobal::config();
1345 KConfigGroup titleConfig(config, "TitleWidget");
1346 // Write the entries
1347 titleConfig.writeEntry("font_family", font_family->currentFont());
1348 //titleConfig.writeEntry("font_size", font_size->value());
1349 titleConfig.writeEntry("font_pixel_size", font_size->value());
1350 titleConfig.writeEntry("font_color", fontColorButton->color());
1351 titleConfig.writeEntry("font_alpha", textAlpha->value());
1352 titleConfig.writeEntry("font_bold", buttonBold->isChecked());
1353 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1354 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1356 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1357 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1358 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1359 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1360 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1362 titleConfig.writeEntry("background_color", kcolorbutton->color());
1363 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1365 titleConfig.writeEntry("crop_image", cropImage->isChecked());
1367 //! \todo Not sure if I should sync - it is probably safe to do it
1372 /** \brief Read the last stored choices into the dialog */
1373 void TitleWidget::readChoices()
1375 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1376 KSharedConfigPtr config = KGlobal::config();
1377 KConfigGroup titleConfig(config, "TitleWidget");
1379 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1380 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1381 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1382 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1383 buttonBold->setChecked(titleConfig.readEntry("font_bold", buttonBold->isChecked()));
1384 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1385 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1387 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1388 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1389 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1390 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1391 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1393 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1394 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1396 cropImage->setChecked(titleConfig.readEntry("crop_image", cropImage->isChecked()));