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"));
132 buttonAlignNone->setToolTip(i18n("No alignment"));
133 buttonAlignRight->setToolTip(i18n("Align right"));
134 buttonAlignLeft->setToolTip(i18n("Align left"));
135 buttonAlignCenter->setToolTip(i18n("Align center"));
137 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
138 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
139 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
140 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
141 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
143 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
144 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
145 rectBColor->setToolTip(i18n("Select fill color"));
146 rectFColor->setToolTip(i18n("Select border color"));
147 rectBAlpha->setToolTip(i18n("Fill transparency"));
148 rectFAlpha->setToolTip(i18n("Border transparency"));
149 zoom_slider->setToolTip(i18n("Zoom"));
150 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
151 buttonFitZoom->setToolTip(i18n("Fit zoom"));
152 kcolorbutton->setToolTip(i18n("Select background color"));
153 horizontalSlider->setToolTip(i18n("Background Transparency"));
155 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
156 itemhcenter->setToolTip(i18n("Align item horizontally"));
157 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
158 itemvcenter->setToolTip(i18n("Align item vertically"));
160 QHBoxLayout *layout = new QHBoxLayout;
161 frame_toolbar->setLayout(layout);
162 layout->setContentsMargins(2, 2, 2, 2);
163 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
165 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
166 m_buttonCursor->setCheckable(true);
167 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
168 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
169 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
171 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
172 m_buttonText->setCheckable(true);
173 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
174 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
175 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
177 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
178 m_buttonRect->setCheckable(true);
179 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
180 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
181 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
183 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
184 m_buttonImage->setCheckable(false);
185 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
186 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
187 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
189 m_toolbar->addSeparator();
191 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
192 m_buttonLoad->setCheckable(false);
193 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
194 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
196 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
197 m_buttonSave->setCheckable(false);
198 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
199 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
201 layout->addWidget(m_toolbar);
203 // initialize graphic scene
204 m_scene = new GraphicsSceneRectMove(this);
205 graphicsView->setScene(m_scene);
206 m_titledocument.setScene(m_scene);
207 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
209 // a gradient background
210 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
211 gradient->setSpread(QGradient::ReflectSpread);
212 scene->setBackgroundBrush(*gradient);*/
214 m_frameImage = new QGraphicsPixmapItem();
216 qtrans.scale(2.0, 2.0);
217 m_frameImage->setTransform(qtrans);
218 m_frameImage->setZValue(-1200);
219 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
220 displayBackgroundFrame();
221 graphicsView->scene()->addItem(m_frameImage);
223 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
224 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
225 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
226 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
227 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
228 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
229 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
230 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
232 QPen framepen(Qt::DotLine);
233 framepen.setColor(Qt::red);
235 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
236 m_frameBorder->setPen(framepen);
237 m_frameBorder->setZValue(-1100);
238 m_frameBorder->setBrush(Qt::transparent);
239 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
240 graphicsView->scene()->addItem(m_frameBorder);
242 // mbd: load saved settings
246 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
247 graphicsView->show();
248 //graphicsView->setRenderHint(QPainter::Antialiasing);
249 graphicsView->setInteractive(true);
250 //graphicsView->resize(400, 300);
251 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
252 toolBox->setItemEnabled(2, false);
253 if (!url.isEmpty()) {
254 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
260 showToolbars(TITLE_NONE);
263 TitleWidget::~TitleWidget()
267 delete m_buttonImage;
268 delete m_buttonCursor;
271 delete m_unicodeAction;
273 delete m_unicodeDialog;
274 delete m_frameBorder;
276 delete m_startViewport;
277 delete m_endViewport;
279 delete m_signalMapper;
283 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
286 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
287 KStandardDirs::makeDir(titlePath);
288 titlePath.append((isClone == false) ? "title" : "clone");
291 while (path.isEmpty() || QFile::exists(path)) {
293 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
295 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
300 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
303 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
304 KStandardDirs::makeDir(titlePath);
305 return titlePath + titleName + ".png";
309 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
314 void TitleWidget::slotTextTool()
316 m_scene->setTool(TITLE_TEXT);
317 showToolbars(TITLE_TEXT);
318 m_buttonRect->setChecked(false);
319 m_buttonCursor->setChecked(false);
322 void TitleWidget::slotRectTool()
324 m_scene->setTool(TITLE_RECTANGLE);
325 showToolbars(TITLE_RECTANGLE);
326 m_buttonText->setChecked(false);
327 m_buttonCursor->setChecked(false);
328 m_buttonRect->setChecked(true);
331 void TitleWidget::slotSelectTool()
333 m_scene->setTool(TITLE_SELECT);
335 // Find out which toolbars need to be shown, depending on selected item
336 TITLETOOL t = TITLE_SELECT;
337 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
339 switch (l.at(0)->type()) {
355 updateCoordinates(l.at(0));
356 updateDimension(l.at(0));
357 updateRotZoom(l.at(0));
360 m_buttonCursor->setChecked(true);
361 m_buttonText->setChecked(false);
362 m_buttonRect->setChecked(false);
365 void TitleWidget::slotImageTool()
367 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
368 if (!url.isEmpty()) {
369 if (url.path().endsWith(".svg")) {
370 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
371 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
372 svg->setZValue(m_count++);
373 svg->setData(Qt::UserRole, url.path());
374 graphicsView->scene()->addItem(svg);
376 QPixmap pix(url.path());
377 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
378 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
379 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
380 image->setData(Qt::UserRole, url.path());
381 image->setZValue(m_count++);
382 graphicsView->scene()->addItem(image);
385 m_scene->setTool(TITLE_SELECT);
386 showToolbars(TITLE_SELECT);
387 m_buttonRect->setChecked(false);
388 m_buttonCursor->setChecked(true);
389 m_buttonText->setChecked(false);
392 void TitleWidget::showToolbars(TITLETOOL toolType)
402 case TITLE_RECTANGLE:
405 case TITLE_IMAGE: //fall through
410 text_properties->setHidden(!bText);
411 rect_properties->setHidden(!bRect);
412 no_properties->setHidden(!bNone);
415 void TitleWidget::enableToolbars(TITLETOOL toolType)
417 // TITLETOOL is defined in graphicsscenerectmove.h
421 bool bValue_w = false;
422 bool bValue_h = false;
431 case TITLE_RECTANGLE:
445 frame_properties->setEnabled(bFrame);
446 text_properties->setEnabled(bText);
447 rect_properties->setEnabled(bRect);
448 value_w->setEnabled(bValue_w);
449 value_h->setEnabled(bValue_h);
452 void TitleWidget::displayBackgroundFrame()
454 if (!displayBg->isChecked()) {
455 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
456 QPixmap pattern(20, 20);
460 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
461 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
466 p.fillRect(bg.rect(), br);
468 m_frameImage->setPixmap(bg);
470 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
474 void TitleWidget::initViewports()
476 m_startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
477 m_endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
479 QPen startpen(Qt::DotLine);
480 QPen endpen(Qt::DashDotLine);
481 startpen.setColor(QColor(100, 200, 100, 140));
482 endpen.setColor(QColor(200, 100, 100, 140));
484 m_startViewport->setPen(startpen);
485 m_endViewport->setPen(endpen);
487 startViewportSize->setValue(40);
488 endViewportSize->setValue(40);
490 m_startViewport->setZValue(-1000);
491 m_endViewport->setZValue(-1000);
493 m_startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
494 m_endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
496 graphicsView->scene()->addItem(m_startViewport);
497 graphicsView->scene()->addItem(m_endViewport);
500 void TitleWidget::slotUpdateZoom(int pos)
502 m_scene->setZoom((double) pos / 100);
503 zoom_label->setText(QString::number(pos) + '%');
506 void TitleWidget::slotZoom(bool up)
508 int pos = zoom_slider->value();
511 zoom_slider->setValue(pos);
514 void TitleWidget::slotAdjustZoom()
516 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
517 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
518 if (scalex > scaley) scalex = scaley;
519 int zoompos = (int)(scalex * 7 + 0.5);*/
520 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
521 int zoompos = graphicsView->matrix().m11() * 100;
522 zoom_slider->setValue(zoompos);
523 graphicsView->centerOn(m_frameBorder);
526 void TitleWidget::slotZoomOneToOne()
528 zoom_slider->setValue(100);
529 graphicsView->centerOn(m_frameBorder);
532 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
534 QColor f = rectFColor->color();
535 f.setAlpha(rectFAlpha->value());
537 penf.setWidth(rectLineWidth->value());
539 QColor b = rectBColor->color();
540 b.setAlpha(rectBAlpha->value());
541 rect->setBrush(QBrush(b));
542 rect->setZValue(m_count++);
543 //setCurrentItem(rect);
544 //graphicsView->setFocus();
547 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
549 QFont font = font_family->currentFont();
550 font.setPixelSize(font_size->value());
552 font.setBold(buttonBold->isChecked());
553 font.setItalic(buttonItalic->isChecked());
554 font.setUnderline(buttonUnder->isChecked());
557 QColor color = fontColorButton->color();
558 color.setAlpha(textAlpha->value());
559 tt->setDefaultTextColor(color);
560 tt->setZValue(m_count++);
564 void TitleWidget::setCurrentItem(QGraphicsItem *item)
566 m_scene->setSelectedItem(item);
569 void TitleWidget::zIndexChanged(int v)
571 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
577 void TitleWidget::selectionChanged()
579 if (m_scene->tool() != TITLE_SELECT) return;
580 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
581 //toolBox->setItemEnabled(2, false);
582 //toolBox->setItemEnabled(3, false);
583 value_x->blockSignals(true);
584 value_y->blockSignals(true);
585 value_w->blockSignals(true);
586 value_h->blockSignals(true);
587 itemzoom->blockSignals(true);
588 itemrotate->blockSignals(true);
590 bool blockX = !origin_x_left->signalsBlocked();
591 bool blockY = !origin_y_top->signalsBlocked();
592 if (blockX) origin_x_left->blockSignals(true);
593 if (blockY) origin_y_top->blockSignals(true);
594 origin_x_left->setChecked(false);
595 origin_y_top->setChecked(false);
598 enableToolbars(TITLE_NONE);
599 if (blockX) origin_x_left->blockSignals(false);
600 if (blockY) origin_y_top->blockSignals(false);
601 } else if (l.size() == 1) {
602 if (l.at(0)->type() == TEXTITEM) {
603 showToolbars(TITLE_TEXT);
604 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
605 //if (l[0]->hasFocus())
606 toolBox->setCurrentIndex(0);
607 //toolBox->setItemEnabled(2, true);
608 font_size->blockSignals(true);
609 font_family->blockSignals(true);
610 buttonBold->blockSignals(true);
611 buttonItalic->blockSignals(true);
612 buttonUnder->blockSignals(true);
613 fontColorButton->blockSignals(true);
614 textAlpha->blockSignals(true);
615 buttonAlignLeft->blockSignals(true);
616 buttonAlignRight->blockSignals(true);
617 buttonAlignNone->blockSignals(true);
618 buttonAlignCenter->blockSignals(true);
620 QFont font = i->font();
621 font_family->setCurrentFont(font);
622 font_size->setValue(font.pixelSize());
623 buttonBold->setChecked(font.bold());
624 buttonItalic->setChecked(font.italic());
625 buttonUnder->setChecked(font.underline());
627 QColor color = i->defaultTextColor();
628 fontColorButton->setColor(color);
629 textAlpha->setValue(color.alpha());
631 QTextCursor cur = i->textCursor();
632 QTextBlockFormat format = cur.blockFormat();
633 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
634 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
635 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
636 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
638 font_size->blockSignals(false);
639 font_family->blockSignals(false);
640 buttonBold->blockSignals(false);
641 buttonItalic->blockSignals(false);
642 buttonUnder->blockSignals(false);
643 fontColorButton->blockSignals(false);
644 textAlpha->blockSignals(false);
645 buttonAlignLeft->blockSignals(false);
646 buttonAlignRight->blockSignals(false);
647 buttonAlignNone->blockSignals(false);
648 buttonAlignCenter->blockSignals(false);
650 updateAxisButtons(i);
651 updateCoordinates(i);
653 enableToolbars(TITLE_TEXT);
655 } else if ((l.at(0))->type() == RECTITEM) {
656 showToolbars(TITLE_RECTANGLE);
658 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
659 toolBox->setCurrentIndex(0);
660 //toolBox->setItemEnabled(3, true);
661 rectFAlpha->setValue(rec->pen().color().alpha());
662 rectBAlpha->setValue(rec->brush().color().alpha());
663 //kDebug() << rec->brush().color().alpha();
664 QColor fcol = rec->pen().color();
665 QColor bcol = rec->brush().color();
666 //fcol.setAlpha(255);
667 //bcol.setAlpha(255);
668 rectFColor->setColor(fcol);
669 rectBColor->setColor(bcol);
671 rectLineWidth->setValue(rec->pen().width());
673 updateAxisButtons(l.at(0));
674 updateCoordinates(rec);
675 updateDimension(rec);
676 enableToolbars(TITLE_RECTANGLE);
678 } else if (l.at(0)->type() == IMAGEITEM) {
679 updateCoordinates(l.at(0));
680 updateDimension(l.at(0));
682 enableToolbars(TITLE_IMAGE);
685 //toolBox->setCurrentIndex(0);
686 enableToolbars(TITLE_NONE);
687 /*frame_properties->setEnabled(false);
688 text_properties->setEnabled(false);
689 rect_properties->setEnabled(false);*/
691 zValue->setValue((int)l.at(0)->zValue());
692 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
693 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
694 value_x->blockSignals(false);
695 value_y->blockSignals(false);
696 value_w->blockSignals(false);
697 value_h->blockSignals(false);
698 itemzoom->blockSignals(false);
699 itemrotate->blockSignals(false);
703 void TitleWidget::slotValueChanged(int type)
705 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
706 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
711 val = value_w->value();
714 val = value_h->value();
718 QGraphicsItem *i = l.at(0);
719 Transform t = m_transformations.value(i);
721 // Ratio width:height
722 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
723 double alpha = (double) t.rotate / 180.0 * M_PI;
733 // Add 0.5 because otherwise incrementing by 1 might have no effect
734 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
735 scale = length / i->boundingRect().width();
738 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
739 scale = length / i->boundingRect().height();
746 qtrans.scale(scale, scale);
747 qtrans.rotate(t.rotate);
748 i->setTransform(qtrans);
749 m_transformations[i] = t;
756 /** \brief Updates position/size of the selected item when a value
757 * of an item (coordinates, size) has changed */
758 void TitleWidget::slotAdjustSelectedItem()
760 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
762 if (l.at(0)->type() == RECTITEM) {
764 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
766 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
767 } else if (l.at(0)->type() == TEXTITEM) {
769 updatePosition(l.at(0));
770 } else if (l.at(0)->type() == IMAGEITEM) {
772 updatePosition(l.at(0));
777 /** \brief Updates width/height int the text fields, regarding transformation matrix */
778 void TitleWidget::updateDimension(QGraphicsItem *i)
780 value_w->blockSignals(true);
781 value_h->blockSignals(true);
784 if (i->type() == IMAGEITEM) {
785 // Get multipliers for rotation/scaling
787 /*Transform t = m_transformations.value(i);
788 QRectF r = i->boundingRect();
789 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
790 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
791 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
792 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
794 value_w->setValue(i->sceneBoundingRect().width());
795 value_h->setValue(i->sceneBoundingRect().height());
796 } else if (i->type() == RECTITEM) {
797 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
798 value_w->setValue((int) r->rect().width());
799 value_h->setValue((int) r->rect().height());
800 } else if (i->type() == TEXTITEM) {
801 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
802 value_w->setValue((int) t->boundingRect().width());
803 value_h->setValue((int) t->boundingRect().height());
806 value_w->blockSignals(false);
807 value_h->blockSignals(false);
810 /** \brief Updates the coordinates in the text fields from the item */
811 void TitleWidget::updateCoordinates(QGraphicsItem *i)
813 // Block signals emitted by this method
814 value_x->blockSignals(true);
815 value_y->blockSignals(true);
817 if (i->type() == TEXTITEM) {
819 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
821 // Set the correct x coordinate value
822 if (origin_x_left->isChecked()) {
823 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
824 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
826 // Origin is at 0 (default)
827 value_x->setValue((int) rec->pos().x());
831 if (origin_y_top->isChecked()) {
832 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
834 value_y->setValue((int) rec->pos().y());
837 } else if (i->type() == RECTITEM) {
839 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
841 if (origin_x_left->isChecked()) {
842 // Origin (0 point) is at m_frameWidth
843 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
845 // Origin is at 0 (default)
846 value_x->setValue((int) rec->pos().x());
849 if (origin_y_top->isChecked()) {
850 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
852 value_y->setValue((int) rec->pos().y());
855 } else if (i->type() == IMAGEITEM) {
857 if (origin_x_left->isChecked()) {
858 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
860 value_x->setValue((int) i->pos().x());
863 if (origin_y_top->isChecked()) {
864 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
866 value_y->setValue((int) i->pos().y());
871 // Stop blocking signals now
872 value_x->blockSignals(false);
873 value_y->blockSignals(false);
876 void TitleWidget::updateRotZoom(QGraphicsItem *i)
878 itemzoom->blockSignals(true);
879 itemrotate->blockSignals(false);
881 Transform t = m_transformations.value(i);
882 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
883 itemrotate->setValue((int)(t.rotate));
885 itemzoom->blockSignals(false);
886 itemrotate->blockSignals(false);
889 /** \brief Updates the position of an item by reading coordinates from the text fields */
890 void TitleWidget::updatePosition(QGraphicsItem *i)
892 if (i->type() == TEXTITEM) {
893 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
896 if (origin_x_left->isChecked()) {
897 /* Origin of the x axis is at m_frameWidth,
898 * and distance from right border of the item to the right
899 * border of the frame is taken.
900 * See comment to slotOriginXClicked().
902 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
904 posX = value_x->value();
908 if (origin_y_top->isChecked()) {
909 /* Same for y axis */
910 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
912 posY = value_y->value();
915 rec->setPos(posX, posY);
917 } else if (i->type() == RECTITEM) {
919 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
922 if (origin_x_left->isChecked()) {
923 posX = m_frameWidth - value_x->value() - rec->rect().width();
925 posX = value_x->value();
929 if (origin_y_top->isChecked()) {
930 posY = m_frameHeight - value_y->value() - rec->rect().height();
932 posY = value_y->value();
935 rec->setPos(posX, posY);
937 } else if (i->type() == IMAGEITEM) {
939 if (origin_x_left->isChecked()) {
940 // Use the sceneBoundingRect because this also regards transformations like zoom
941 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
943 posX = value_x->value();
947 if (origin_y_top->isChecked()) {
948 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
950 posY = value_y->value();
953 i->setPos(posX, posY);
959 void TitleWidget::updateTextOriginX()
961 if (origin_x_left->isChecked()) {
962 origin_x_left->setText(i18n("\u2212X"));
964 origin_x_left->setText(i18n("+X"));
968 void TitleWidget::slotOriginXClicked()
970 // Update the text displayed on the button.
973 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
975 updateCoordinates(l.at(0));
977 // Remember x axis setting
978 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
979 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
981 graphicsView->setFocus();
984 void TitleWidget::updateTextOriginY()
986 if (origin_y_top->isChecked()) {
987 origin_y_top->setText(i18n("\u2212Y"));
989 origin_y_top->setText(i18n("+Y"));
993 void TitleWidget::slotOriginYClicked()
995 // Update the text displayed on the button.
998 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1000 updateCoordinates(l.at(0));
1002 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1003 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1006 graphicsView->setFocus();
1009 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1011 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1012 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1013 origin_x_left->blockSignals(true);
1014 origin_y_top->blockSignals(true);
1016 if (xAxis == TitleDocument::AxisInverted) {
1017 origin_x_left->setChecked(true);
1019 origin_x_left->setChecked(false);
1021 updateTextOriginX();
1023 if (yAxis == TitleDocument::AxisInverted) {
1024 origin_y_top->setChecked(true);
1026 origin_y_top->setChecked(false);
1028 updateTextOriginY();
1030 origin_x_left->blockSignals(false);
1031 origin_y_top->blockSignals(false);
1034 void TitleWidget::slotChangeBackground()
1036 QColor color = kcolorbutton->color();
1037 color.setAlpha(horizontalSlider->value());
1038 m_frameBorder->setBrush(QBrush(color));
1042 * Something (yeah) has changed in our QGraphicsScene.
1044 void TitleWidget::slotChanged()
1046 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1047 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1048 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1053 * If the user has set origin_x_left (everything also for y),
1054 * we need to look whether a text element has been selected. If yes,
1055 * we need to ensure that the right border of the text field
1056 * remains fixed also when some text has been entered.
1058 * This is also known as right-justified, with the difference that
1059 * it is not valid for text but for its boundingRect. Text may still
1060 * be left-justified.
1062 void TitleWidget::textChanged(QGraphicsTextItem *i)
1067 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1069 if (!i->toPlainText().isEmpty()) {
1073 * Don't do anything if the string is empty. If the position
1074 * would be updated here, a newly created text field would
1075 * be set to the position of the last selected text field.
1081 void TitleWidget::slotInsertUnicode()
1083 m_unicodeDialog->exec();
1086 void TitleWidget::slotInsertUnicodeString(QString text)
1088 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1090 if (l.at(0)->type() == TEXTITEM) {
1091 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1092 t->textCursor().insertText(text);
1097 void TitleWidget::slotUpdateText()
1099 QFont font = font_family->currentFont();
1100 font.setPixelSize(font_size->value());
1101 font.setBold(buttonBold->isChecked());
1102 font.setItalic(buttonItalic->isChecked());
1103 font.setUnderline(buttonUnder->isChecked());
1104 QColor color = fontColorButton->color();
1105 color.setAlpha(textAlpha->value());
1107 QGraphicsTextItem* item = NULL;
1108 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1109 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1110 item = static_cast <QGraphicsTextItem *>(l.at(0));
1113 //if (item->textCursor().selection ().isEmpty())
1114 QTextCursor cur = item->textCursor();
1115 QTextBlockFormat format = cur.blockFormat();
1116 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1117 item->setTextWidth(item->boundingRect().width());
1118 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1119 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1120 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1122 format.setAlignment(Qt::AlignLeft);
1123 item->setTextWidth(-1);
1127 item->setFont(font);
1128 item->setDefaultTextColor(color);
1129 cur.select(QTextCursor::Document);
1130 cur.setBlockFormat(format);
1131 item->setTextCursor(cur);
1132 cur.clearSelection();
1133 item->setTextCursor(cur);
1138 void TitleWidget::rectChanged()
1140 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1141 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1142 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1143 QColor f = rectFColor->color();
1144 f.setAlpha(rectFAlpha->value());
1146 penf.setWidth(rectLineWidth->value());
1148 QColor b = rectBColor->color();
1149 b.setAlpha(rectBAlpha->value());
1150 rec->setBrush(QBrush(b));
1154 void TitleWidget::itemScaled(int val)
1156 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1157 if (l.size() == 1) {
1158 Transform x = m_transformations.value(l.at(0));
1159 x.scalex = (double)val / 100.0;
1160 x.scaley = (double)val / 100.0;
1162 qtrans.scale(x.scalex, x.scaley);
1163 qtrans.rotate(x.rotate);
1164 l[0]->setTransform(qtrans);
1165 m_transformations[l.at(0)] = x;
1166 updateDimension(l.at(0));
1170 void TitleWidget::itemRotate(int val)
1172 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1173 if (l.size() == 1) {
1174 Transform x = m_transformations[l.at(0)];
1175 x.rotate = (double)val;
1177 qtrans.scale(x.scalex, x.scaley);
1178 qtrans.rotate(x.rotate);
1179 l[0]->setTransform(qtrans);
1180 m_transformations[l.at(0)] = x;
1181 updateDimension(l.at(0));
1185 void TitleWidget::itemHCenter()
1187 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1188 if (l.size() == 1) {
1189 QGraphicsItem *item = l.at(0);
1191 br = item->sceneBoundingRect();
1192 int width = (int)br.width();
1193 int newPos = (int)((m_frameWidth - width) / 2);
1194 newPos += item->pos().x() - br.left(); // Check item transformation
1195 item->setPos(newPos, item->pos().y());
1196 updateCoordinates(item);
1200 void TitleWidget::itemVCenter()
1202 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1203 if (l.size() == 1) {
1204 QGraphicsItem *item = l.at(0);
1206 br = item->sceneBoundingRect();
1207 int height = (int)br.height();
1208 int newPos = (int)((m_frameHeight - height) / 2);
1209 newPos += item->pos().y() - br.top(); // Check item transformation
1210 item->setPos(item->pos().x(), newPos);
1211 updateCoordinates(item);
1215 void TitleWidget::setupViewports()
1217 double aspect_ratio = 4.0 / 3.0;//read from project
1219 QRectF sp(0, 0, 0, 0);
1220 QRectF ep(0, 0, 0, 0);
1222 double sv_size = startViewportSize->value();
1223 double ev_size = endViewportSize->value();
1224 sp.adjust(-sv_size, -sv_size / aspect_ratio, sv_size, sv_size / aspect_ratio);
1225 ep.adjust(-ev_size, -ev_size / aspect_ratio, ev_size, ev_size / aspect_ratio);
1227 m_startViewport->setPos(startViewportX->value(), startViewportY->value());
1228 m_endViewport->setPos(endViewportX->value(), endViewportY->value());
1230 m_startViewport->setPolygon(QPolygonF(sp));
1231 m_endViewport->setPolygon(QPolygonF(ep));
1235 void TitleWidget::loadTitle()
1237 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Load Title"));
1238 if (!url.isEmpty()) {
1239 QList<QGraphicsItem *> items = m_scene->items();
1240 for (int i = 0; i < items.size(); i++) {
1241 if (items.at(i)->zValue() > -1000) delete items.at(i);
1243 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
1248 void TitleWidget::saveTitle(KUrl url)
1250 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Save Title"));
1251 if (!url.isEmpty()) {
1252 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport) == false)
1253 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1257 QDomDocument TitleWidget::xml()
1259 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1260 if (cropImage->isChecked()) {
1261 doc.documentElement().setAttribute("crop", 1);
1266 void TitleWidget::setXml(QDomDocument doc)
1268 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport);
1269 QDomElement e = doc.documentElement();
1270 cropImage->setChecked(e.hasAttribute("crop"));
1271 m_transformations.clear();
1272 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1273 const double PI = 4.0 * atan(1.0);
1274 for (int i = 0; i < items.count(); i++) {
1275 QTransform t = items.at(i)->transform();
1279 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1280 m_transformations[items.at(i)] = x;
1282 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1283 QColor background_color = m_titledocument.getBackgroundColor();
1284 horizontalSlider->blockSignals(true);
1285 kcolorbutton->blockSignals(true);
1286 horizontalSlider->setValue(background_color.alpha());
1287 background_color.setAlpha(255);
1288 kcolorbutton->setColor(background_color);
1289 horizontalSlider->blockSignals(false);
1290 kcolorbutton->blockSignals(false);
1295 const QRect TitleWidget::renderedRect()
1299 int maxX = m_frameWidth;
1300 int maxY = m_frameHeight;
1301 if (!cropImage->isChecked()) {
1302 m_scene->removeItem(m_startViewport);
1303 m_scene->removeItem(m_endViewport);
1304 QRect boundingRect = m_scene->itemsBoundingRect().toRect();
1305 if (boundingRect.left() < 0) minX = boundingRect.left();
1306 if (boundingRect.top() < 0) minY = boundingRect.top();
1307 if (boundingRect.right() > maxX) maxX = boundingRect.right();
1308 if (boundingRect.bottom() > maxY) maxY = boundingRect.bottom();
1316 QRect rect(minX, minY, maxX, maxY);
1320 QImage TitleWidget::renderedPixmap()
1322 QRect rect = renderedRect();
1323 QImage pix(rect.width(), rect.height(), QImage::Format_ARGB32);
1324 pix.fill(Qt::transparent);
1325 QPainter painter(&pix);
1326 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing);
1327 m_scene->clearTextSelection();
1328 QPen framepen = m_frameBorder->pen();
1329 m_frameBorder->setPen(Qt::NoPen);
1330 m_startViewport->setVisible(false);
1331 m_endViewport->setVisible(false);
1332 m_frameImage->setVisible(false);
1334 m_scene->render(&painter, QRectF(), rect); //QRectF(minX, minY, maxX - minX, maxY - minY));
1336 m_frameBorder->setPen(framepen);
1337 m_startViewport->setVisible(true);
1338 m_endViewport->setVisible(true);
1339 m_frameImage->setVisible(true);
1343 /** \brief Connected to the accepted signal - calls writeChoices */
1344 void TitleWidget::slotAccepted()
1349 /** \brief Store the current choices of font, background and rect values */
1350 void TitleWidget::writeChoices()
1352 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1353 KSharedConfigPtr config = KGlobal::config();
1354 KConfigGroup titleConfig(config, "TitleWidget");
1355 // Write the entries
1356 titleConfig.writeEntry("font_family", font_family->currentFont());
1357 //titleConfig.writeEntry("font_size", font_size->value());
1358 titleConfig.writeEntry("font_pixel_size", font_size->value());
1359 titleConfig.writeEntry("font_color", fontColorButton->color());
1360 titleConfig.writeEntry("font_alpha", textAlpha->value());
1361 titleConfig.writeEntry("font_bold", buttonBold->isChecked());
1362 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1363 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1365 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1366 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1367 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1368 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1369 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1371 titleConfig.writeEntry("background_color", kcolorbutton->color());
1372 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1374 titleConfig.writeEntry("crop_image", cropImage->isChecked());
1376 //! \todo Not sure if I should sync - it is probably safe to do it
1381 /** \brief Read the last stored choices into the dialog */
1382 void TitleWidget::readChoices()
1384 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1385 KSharedConfigPtr config = KGlobal::config();
1386 KConfigGroup titleConfig(config, "TitleWidget");
1388 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1389 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1390 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1391 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1392 buttonBold->setChecked(titleConfig.readEntry("font_bold", buttonBold->isChecked()));
1393 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1394 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1396 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1397 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1398 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1399 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1400 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1402 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1403 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1405 cropImage->setChecked(titleConfig.readEntry("crop_image", cropImage->isChecked()));