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()));
72 connect(font_weight_box, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateText()));
74 connect(rectFAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
75 connect(rectBAlpha, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
76 connect(rectFColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
77 connect(rectBColor, SIGNAL(clicked()), this, SLOT(rectChanged()));
78 connect(rectLineWidth, SIGNAL(valueChanged(int)), this, SLOT(rectChanged()));
80 connect(startViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
81 connect(startViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
82 connect(startViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
83 connect(endViewportX, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
84 connect(endViewportY, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
85 connect(endViewportSize, SIGNAL(valueChanged(int)), this, SLOT(setupViewports()));
87 connect(zValue, SIGNAL(valueChanged(int)), this, SLOT(zIndexChanged(int)));
88 connect(itemzoom, SIGNAL(valueChanged(int)), this, SLOT(itemScaled(int)));
89 connect(itemrotate, SIGNAL(valueChanged(int)), this, SLOT(itemRotate(int)));
90 connect(itemhcenter, SIGNAL(clicked()), this, SLOT(itemHCenter()));
91 connect(itemvcenter, SIGNAL(clicked()), this, SLOT(itemVCenter()));
93 connect(origin_x_left, SIGNAL(clicked()), this, SLOT(slotOriginXClicked()));
94 connect(origin_y_top, SIGNAL(clicked()), this, SLOT(slotOriginYClicked()));
96 m_signalMapper = new QSignalMapper(this);
97 m_signalMapper->setMapping(value_w, ValueWidth);
98 m_signalMapper->setMapping(value_h, ValueHeight);
99 connect(value_w, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
100 connect(value_h, SIGNAL(valueChanged(int)), m_signalMapper, SLOT(map()));
101 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(slotValueChanged(int)));
103 connect(value_x, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
104 connect(value_y, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
105 connect(value_w, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
106 connect(value_h, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustSelectedItem()));
107 connect(buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotAdjustZoom()));
108 connect(buttonRealSize, SIGNAL(clicked()), this, SLOT(slotZoomOneToOne()));
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 font_weight_box->blockSignals(true);
124 font_weight_box->addItem(i18nc("Font style", "Light"), QFont::Light);
125 font_weight_box->addItem(i18nc("Font style", "Normal"), QFont::Normal);
126 font_weight_box->addItem(i18nc("Font style", "Demi-Bold"), QFont::DemiBold);
127 font_weight_box->addItem(i18nc("Font style", "Bold"), QFont::Bold);
128 font_weight_box->addItem(i18nc("Font style", "Black"), QFont::Black);
129 font_weight_box->setToolTip(i18n("Font weight"));
130 font_weight_box->setCurrentIndex(1);
131 font_weight_box->blockSignals(false);
133 buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
134 buttonRealSize->setIcon(KIcon("zoom-original"));
135 buttonItalic->setIcon(KIcon("format-text-italic"));
136 buttonUnder->setIcon(KIcon("format-text-underline"));
137 buttonAlignCenter->setIcon(KIcon("format-justify-center"));
138 buttonAlignLeft->setIcon(KIcon("format-justify-left"));
139 buttonAlignRight->setIcon(KIcon("format-justify-right"));
140 buttonAlignNone->setIcon(KIcon("kdenlive-align-none"));
142 buttonAlignNone->setToolTip(i18n("No alignment"));
143 buttonAlignRight->setToolTip(i18n("Align right"));
144 buttonAlignLeft->setToolTip(i18n("Align left"));
145 buttonAlignCenter->setToolTip(i18n("Align center"));
147 m_unicodeAction = new QAction(KIcon("kdenlive-insert-unicode"), QString(), this);
148 m_unicodeAction->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
149 m_unicodeAction->setToolTip(i18n("Insert Unicode character") + ' ' + m_unicodeAction->shortcut().toString());
150 connect(m_unicodeAction, SIGNAL(triggered()), this, SLOT(slotInsertUnicode()));
151 buttonInsertUnicode->setDefaultAction(m_unicodeAction);
153 origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
154 origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
155 rectBColor->setToolTip(i18n("Select fill color"));
156 rectFColor->setToolTip(i18n("Select border color"));
157 rectBAlpha->setToolTip(i18n("Fill transparency"));
158 rectFAlpha->setToolTip(i18n("Border transparency"));
159 zoom_slider->setToolTip(i18n("Zoom"));
160 buttonRealSize->setToolTip(i18n("Original size (1:1)"));
161 buttonFitZoom->setToolTip(i18n("Fit zoom"));
162 kcolorbutton->setToolTip(i18n("Select background color"));
163 horizontalSlider->setToolTip(i18n("Background Transparency"));
165 itemhcenter->setIcon(KIcon("kdenlive-align-hor"));
166 itemhcenter->setToolTip(i18n("Align item horizontally"));
167 itemvcenter->setIcon(KIcon("kdenlive-align-vert"));
168 itemvcenter->setToolTip(i18n("Align item vertically"));
170 QHBoxLayout *layout = new QHBoxLayout;
171 frame_toolbar->setLayout(layout);
172 layout->setContentsMargins(2, 2, 2, 2);
173 QToolBar *m_toolbar = new QToolBar("titleToolBar", this);
175 m_buttonCursor = m_toolbar->addAction(KIcon("transform-move"), QString());
176 m_buttonCursor->setCheckable(true);
177 m_buttonCursor->setShortcut(Qt::ALT + Qt::Key_S);
178 m_buttonCursor->setToolTip(i18n("Selection Tool") + ' ' + m_buttonCursor->shortcut().toString());
179 connect(m_buttonCursor, SIGNAL(triggered()), this, SLOT(slotSelectTool()));
181 m_buttonText = m_toolbar->addAction(KIcon("insert-text"), QString());
182 m_buttonText->setCheckable(true);
183 m_buttonText->setShortcut(Qt::ALT + Qt::Key_T);
184 m_buttonText->setToolTip(i18n("Add Text") + ' ' + m_buttonText->shortcut().toString());
185 connect(m_buttonText, SIGNAL(triggered()), this, SLOT(slotTextTool()));
187 m_buttonRect = m_toolbar->addAction(KIcon("kdenlive-insert-rect"), QString());
188 m_buttonRect->setCheckable(true);
189 m_buttonRect->setShortcut(Qt::ALT + Qt::Key_R);
190 m_buttonRect->setToolTip(i18n("Add Rectangle") + ' ' + m_buttonRect->shortcut().toString());
191 connect(m_buttonRect, SIGNAL(triggered()), this, SLOT(slotRectTool()));
193 m_buttonImage = m_toolbar->addAction(KIcon("insert-image"), QString());
194 m_buttonImage->setCheckable(false);
195 m_buttonImage->setShortcut(Qt::ALT + Qt::Key_I);
196 m_buttonImage->setToolTip(i18n("Add Image") + ' ' + m_buttonImage->shortcut().toString());
197 connect(m_buttonImage, SIGNAL(triggered()), this, SLOT(slotImageTool()));
199 m_toolbar->addSeparator();
201 m_buttonLoad = m_toolbar->addAction(KIcon("document-open"), i18n("Open Document"));
202 m_buttonLoad->setCheckable(false);
203 m_buttonLoad->setShortcut(Qt::CTRL + Qt::Key_O);
204 connect(m_buttonLoad, SIGNAL(triggered()), this, SLOT(loadTitle()));
206 m_buttonSave = m_toolbar->addAction(KIcon("document-save-as"), i18n("Save As"));
207 m_buttonSave->setCheckable(false);
208 m_buttonSave->setShortcut(Qt::CTRL + Qt::Key_S);
209 connect(m_buttonSave, SIGNAL(triggered()), this, SLOT(saveTitle()));
211 layout->addWidget(m_toolbar);
213 // initialize graphic scene
214 m_scene = new GraphicsSceneRectMove(this);
215 graphicsView->setScene(m_scene);
216 m_titledocument.setScene(m_scene);
217 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(slotChanged()));
219 // a gradient background
220 /*QRadialGradient *gradient = new QRadialGradient(0, 0, 10);
221 gradient->setSpread(QGradient::ReflectSpread);
222 scene->setBackgroundBrush(*gradient);*/
224 m_frameImage = new QGraphicsPixmapItem();
226 qtrans.scale(2.0, 2.0);
227 m_frameImage->setTransform(qtrans);
228 m_frameImage->setZValue(-1200);
229 m_frameImage->setFlags(QGraphicsItem::ItemClipsToShape);
230 displayBackgroundFrame();
231 graphicsView->scene()->addItem(m_frameImage);
233 connect(m_scene, SIGNAL(selectionChanged()), this , SLOT(selectionChanged()));
234 connect(m_scene, SIGNAL(itemMoved()), this , SLOT(selectionChanged()));
235 connect(m_scene, SIGNAL(sceneZoom(bool)), this , SLOT(slotZoom(bool)));
236 connect(m_scene, SIGNAL(actionFinished()), this , SLOT(slotSelectTool()));
237 //connect(m_scene, SIGNAL(actionFinished()), this , SLOT(selectionChanged()));
238 connect(m_scene, SIGNAL(newRect(QGraphicsRectItem *)), this , SLOT(slotNewRect(QGraphicsRectItem *)));
239 connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
240 connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
242 QPen framepen(Qt::DotLine);
243 framepen.setColor(Qt::red);
245 m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
246 m_frameBorder->setPen(framepen);
247 m_frameBorder->setZValue(-1100);
248 m_frameBorder->setBrush(Qt::transparent);
249 m_frameBorder->setFlags(QGraphicsItem::ItemClipsToShape);
250 graphicsView->scene()->addItem(m_frameBorder);
252 // mbd: load saved settings
256 QTimer::singleShot(500, this, SLOT(slotAdjustZoom()));
257 graphicsView->show();
258 //graphicsView->setRenderHint(QPainter::Antialiasing);
259 graphicsView->setInteractive(true);
260 //graphicsView->resize(400, 300);
261 kDebug() << "// TITLE WIDGWT: " << graphicsView->viewport()->width() << "x" << graphicsView->viewport()->height();
262 //toolBox->setItemEnabled(2, false);
263 if (!url.isEmpty()) {
264 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
270 showToolbars(TITLE_NONE);
273 TitleWidget::~TitleWidget()
277 delete m_buttonImage;
278 delete m_buttonCursor;
281 delete m_unicodeAction;
283 delete m_unicodeDialog;
284 delete m_frameBorder;
286 delete m_startViewport;
287 delete m_endViewport;
289 delete m_signalMapper;
293 QStringList TitleWidget::getFreeTitleInfo(const KUrl &projectUrl, bool isClone)
296 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
297 KStandardDirs::makeDir(titlePath);
298 titlePath.append((isClone == false) ? "title" : "clone");
301 while (path.isEmpty() || QFile::exists(path)) {
303 path = titlePath + QString::number(counter).rightJustified(3, '0', false) + ".png";
305 result.append(((isClone == false) ? i18n("Title") : i18n("Clone")) + ' ' + QString::number(counter).rightJustified(3, '0', false));
310 QString TitleWidget::getTitleResourceFromName(const KUrl &projectUrl, const QString &titleName)
313 QString titlePath = projectUrl.path(KUrl::AddTrailingSlash) + "titles/";
314 KStandardDirs::makeDir(titlePath);
315 return titlePath + titleName + ".png";
319 void TitleWidget::resizeEvent(QResizeEvent * /*event*/)
324 void TitleWidget::slotTextTool()
326 m_scene->setTool(TITLE_TEXT);
327 showToolbars(TITLE_TEXT);
328 checkButton(TITLE_TEXT);
331 void TitleWidget::slotRectTool()
333 m_scene->setTool(TITLE_RECTANGLE);
334 showToolbars(TITLE_RECTANGLE);
335 checkButton(TITLE_RECTANGLE);
338 void TitleWidget::slotSelectTool()
340 m_scene->setTool(TITLE_SELECT);
342 // Find out which toolbars need to be shown, depending on selected item
343 TITLETOOL t = TITLE_SELECT;
344 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
346 switch (l.at(0)->type()) {
362 updateCoordinates(l.at(0));
363 updateDimension(l.at(0));
364 updateRotZoom(l.at(0));
367 checkButton(TITLE_SELECT);
370 void TitleWidget::slotImageTool()
372 KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.svg *.png *.jpg *.jpeg *.gif *.raw", this, i18n("Load Image"));
373 if (!url.isEmpty()) {
374 if (url.path().endsWith(".svg")) {
375 QGraphicsSvgItem *svg = new QGraphicsSvgItem(url.toLocalFile());
376 svg->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
377 svg->setZValue(m_count++);
378 svg->setData(Qt::UserRole, url.path());
379 graphicsView->scene()->addItem(svg);
381 QPixmap pix(url.path());
382 QGraphicsPixmapItem *image = new QGraphicsPixmapItem(pix);
383 image->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
384 image->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
385 image->setData(Qt::UserRole, url.path());
386 image->setZValue(m_count++);
387 graphicsView->scene()->addItem(image);
390 m_scene->setTool(TITLE_SELECT);
391 showToolbars(TITLE_SELECT);
392 checkButton(TITLE_NONE);
395 void TitleWidget::showToolbars(TITLETOOL toolType)
406 case TITLE_RECTANGLE:
416 text_properties->setHidden(!bText);
417 rect_properties->setHidden(!bRect);
418 image_properties->setHidden(!bImage);
419 no_properties->setHidden(!bNone);
422 void TitleWidget::enableToolbars(TITLETOOL toolType)
424 // TITLETOOL is defined in graphicsscenerectmove.h
429 bool bValue_w = false;
430 bool bValue_h = false;
439 case TITLE_RECTANGLE:
454 frame_properties->setEnabled(bFrame);
455 text_properties->setEnabled(bText);
456 rect_properties->setEnabled(bRect);
457 image_properties->setEnabled(bImage);
458 value_w->setEnabled(bValue_w);
459 value_h->setEnabled(bValue_h);
462 void TitleWidget::checkButton(TITLETOOL toolType)
464 bool bSelect = false;
476 case TITLE_RECTANGLE:
486 m_buttonCursor->setChecked(bSelect);
487 m_buttonText->setChecked(bText);
488 m_buttonRect->setChecked(bRect);
489 m_buttonImage->setChecked(bImage);
492 void TitleWidget::displayBackgroundFrame()
494 if (!displayBg->isChecked()) {
495 QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
496 QPixmap pattern(20, 20);
500 p.fillRect(QRect(0, 0, 10, 10), QColor(210, 210, 210));
501 p.fillRect(QRect(10, 10, 20, 20), QColor(210, 210, 210));
506 p.fillRect(bg.rect(), br);
508 m_frameImage->setPixmap(bg);
510 m_frameImage->setPixmap(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2));
514 void TitleWidget::initViewports()
516 m_startViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
517 m_endViewport = new QGraphicsPolygonItem(QPolygonF(QRectF(0, 0, 0, 0)));
519 QPen startpen(Qt::DotLine);
520 QPen endpen(Qt::DashDotLine);
521 startpen.setColor(QColor(100, 200, 100, 140));
522 endpen.setColor(QColor(200, 100, 100, 140));
524 m_startViewport->setPen(startpen);
525 m_endViewport->setPen(endpen);
527 startViewportSize->setValue(100);
528 endViewportSize->setValue(100);
530 m_startViewport->setZValue(-1000);
531 m_endViewport->setZValue(-1000);
533 m_startViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
534 m_endViewport->setFlags(/*QGraphicsItem::ItemIsMovable|*/QGraphicsItem::ItemIsSelectable);
536 graphicsView->scene()->addItem(m_startViewport);
537 graphicsView->scene()->addItem(m_endViewport);
540 void TitleWidget::slotUpdateZoom(int pos)
542 m_scene->setZoom((double) pos / 100);
543 zoom_label->setText(QString::number(pos) + '%');
546 void TitleWidget::slotZoom(bool up)
548 int pos = zoom_slider->value();
551 zoom_slider->setValue(pos);
554 void TitleWidget::slotAdjustZoom()
556 /*double scalex = graphicsView->width() / (double)(m_frameWidth * 1.2);
557 double scaley = graphicsView->height() / (double)(m_frameHeight * 1.2);
558 if (scalex > scaley) scalex = scaley;
559 int zoompos = (int)(scalex * 7 + 0.5);*/
560 graphicsView->fitInView(m_frameBorder, Qt::KeepAspectRatio);
561 int zoompos = graphicsView->matrix().m11() * 100;
562 zoom_slider->setValue(zoompos);
563 graphicsView->centerOn(m_frameBorder);
566 void TitleWidget::slotZoomOneToOne()
568 zoom_slider->setValue(100);
569 graphicsView->centerOn(m_frameBorder);
572 void TitleWidget::slotNewRect(QGraphicsRectItem * rect)
574 updateAxisButtons(rect); // back to default
576 QColor f = rectFColor->color();
577 f.setAlpha(rectFAlpha->value());
579 penf.setWidth(rectLineWidth->value());
581 QColor b = rectBColor->color();
582 b.setAlpha(rectBAlpha->value());
583 rect->setBrush(QBrush(b));
584 rect->setZValue(m_count++);
585 //setCurrentItem(rect);
586 //graphicsView->setFocus();
589 void TitleWidget::slotNewText(QGraphicsTextItem *tt)
591 updateAxisButtons(tt); // back to default
593 QFont font = font_family->currentFont();
594 font.setPixelSize(font_size->value());
596 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
597 font.setItalic(buttonItalic->isChecked());
598 font.setUnderline(buttonUnder->isChecked());
601 QColor color = fontColorButton->color();
602 color.setAlpha(textAlpha->value());
603 tt->setDefaultTextColor(color);
604 tt->setZValue(m_count++);
608 void TitleWidget::setFontBoxWeight(int weight)
610 int index = font_weight_box->findData(weight);
612 index = font_weight_box->findData(QFont::Normal);
614 font_weight_box->setCurrentIndex(index);
617 void TitleWidget::setCurrentItem(QGraphicsItem *item)
619 m_scene->setSelectedItem(item);
622 void TitleWidget::zIndexChanged(int v)
624 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
630 void TitleWidget::selectionChanged()
632 if (m_scene->tool() != TITLE_SELECT) return;
633 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
634 //toolBox->setItemEnabled(2, false);
635 //toolBox->setItemEnabled(3, false);
636 value_x->blockSignals(true);
637 value_y->blockSignals(true);
638 value_w->blockSignals(true);
639 value_h->blockSignals(true);
640 itemzoom->blockSignals(true);
641 itemrotate->blockSignals(true);
643 bool blockX = !origin_x_left->signalsBlocked();
644 bool blockY = !origin_y_top->signalsBlocked();
645 if (blockX) origin_x_left->blockSignals(true);
646 if (blockY) origin_y_top->blockSignals(true);
647 origin_x_left->setChecked(false);
648 origin_y_top->setChecked(false);
651 enableToolbars(TITLE_NONE);
652 if (blockX) origin_x_left->blockSignals(false);
653 if (blockY) origin_y_top->blockSignals(false);
654 } else if (l.size() == 1) {
655 if (l.at(0)->type() == TEXTITEM) {
656 showToolbars(TITLE_TEXT);
657 QGraphicsTextItem* i = static_cast <QGraphicsTextItem *>(l.at(0));
658 //if (l[0]->hasFocus())
659 toolBox->setCurrentIndex(0);
660 //toolBox->setItemEnabled(2, true);
661 font_size->blockSignals(true);
662 font_family->blockSignals(true);
663 font_weight_box->blockSignals(true);
664 buttonItalic->blockSignals(true);
665 buttonUnder->blockSignals(true);
666 fontColorButton->blockSignals(true);
667 textAlpha->blockSignals(true);
668 buttonAlignLeft->blockSignals(true);
669 buttonAlignRight->blockSignals(true);
670 buttonAlignNone->blockSignals(true);
671 buttonAlignCenter->blockSignals(true);
673 QFont font = i->font();
674 font_family->setCurrentFont(font);
675 font_size->setValue(font.pixelSize());
676 buttonItalic->setChecked(font.italic());
677 buttonUnder->setChecked(font.underline());
678 setFontBoxWeight(font.weight());
680 QColor color = i->defaultTextColor();
681 fontColorButton->setColor(color);
682 textAlpha->setValue(color.alpha());
684 QTextCursor cur = i->textCursor();
685 QTextBlockFormat format = cur.blockFormat();
686 if (i->textWidth() == -1) buttonAlignNone->setChecked(true);
687 else if (format.alignment() == Qt::AlignHCenter) buttonAlignCenter->setChecked(true);
688 else if (format.alignment() == Qt::AlignRight) buttonAlignRight->setChecked(true);
689 else if (format.alignment() == Qt::AlignLeft) buttonAlignLeft->setChecked(true);
691 font_size->blockSignals(false);
692 font_family->blockSignals(false);
693 font_weight_box->blockSignals(false);
694 buttonItalic->blockSignals(false);
695 buttonUnder->blockSignals(false);
696 fontColorButton->blockSignals(false);
697 textAlpha->blockSignals(false);
698 buttonAlignLeft->blockSignals(false);
699 buttonAlignRight->blockSignals(false);
700 buttonAlignNone->blockSignals(false);
701 buttonAlignCenter->blockSignals(false);
703 updateAxisButtons(i);
704 updateCoordinates(i);
706 enableToolbars(TITLE_TEXT);
708 } else if ((l.at(0))->type() == RECTITEM) {
709 showToolbars(TITLE_RECTANGLE);
711 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
712 toolBox->setCurrentIndex(0);
713 //toolBox->setItemEnabled(3, true);
714 rectFAlpha->setValue(rec->pen().color().alpha());
715 rectBAlpha->setValue(rec->brush().color().alpha());
716 //kDebug() << rec->brush().color().alpha();
717 QColor fcol = rec->pen().color();
718 QColor bcol = rec->brush().color();
719 //fcol.setAlpha(255);
720 //bcol.setAlpha(255);
721 rectFColor->setColor(fcol);
722 rectBColor->setColor(bcol);
724 rectLineWidth->setValue(rec->pen().width());
726 updateAxisButtons(l.at(0));
727 updateCoordinates(rec);
728 updateDimension(rec);
729 enableToolbars(TITLE_RECTANGLE);
731 } else if (l.at(0)->type() == IMAGEITEM) {
732 showToolbars(TITLE_IMAGE);
734 updateCoordinates(l.at(0));
735 updateDimension(l.at(0));
737 enableToolbars(TITLE_IMAGE);
740 //toolBox->setCurrentIndex(0);
741 showToolbars(TITLE_NONE);
742 enableToolbars(TITLE_NONE);
743 /*frame_properties->setEnabled(false);
744 text_properties->setEnabled(false);
745 rect_properties->setEnabled(false);*/
747 zValue->setValue((int)l.at(0)->zValue());
748 itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
749 itemrotate->setValue((int)(m_transformations.value(l.at(0)).rotate));
750 value_x->blockSignals(false);
751 value_y->blockSignals(false);
752 value_w->blockSignals(false);
753 value_h->blockSignals(false);
754 itemzoom->blockSignals(false);
755 itemrotate->blockSignals(false);
759 void TitleWidget::slotValueChanged(int type)
761 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
762 if (l.size() > 0 && l.at(0)->type() == IMAGEITEM) {
767 val = value_w->value();
770 val = value_h->value();
774 QGraphicsItem *i = l.at(0);
775 Transform t = m_transformations.value(i);
777 // Ratio width:height
778 double phi = (double) i->boundingRect().width() / i->boundingRect().height();
779 double alpha = (double) t.rotate / 180.0 * M_PI;
789 // Add 0.5 because otherwise incrementing by 1 might have no effect
790 length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
791 scale = length / i->boundingRect().width();
794 length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
795 scale = length / i->boundingRect().height();
802 qtrans.scale(scale, scale);
803 qtrans.rotate(t.rotate);
804 i->setTransform(qtrans);
805 m_transformations[i] = t;
812 /** \brief Updates position/size of the selected item when a value
813 * of an item (coordinates, size) has changed */
814 void TitleWidget::slotAdjustSelectedItem()
816 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
818 if (l.at(0)->type() == RECTITEM) {
820 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(l.at(0));
822 rec->setRect(QRect(0, 0, value_w->value(), value_h->value()));
823 } else if (l.at(0)->type() == TEXTITEM) {
825 updatePosition(l.at(0));
826 } else if (l.at(0)->type() == IMAGEITEM) {
828 updatePosition(l.at(0));
833 /** \brief Updates width/height int the text fields, regarding transformation matrix */
834 void TitleWidget::updateDimension(QGraphicsItem *i)
836 value_w->blockSignals(true);
837 value_h->blockSignals(true);
840 if (i->type() == IMAGEITEM) {
841 // Get multipliers for rotation/scaling
843 /*Transform t = m_transformations.value(i);
844 QRectF r = i->boundingRect();
845 int width = (int) ( abs(r.width()*t.scalex * cos(t.rotate/180.0*M_PI))
846 + abs(r.height()*t.scaley * sin(t.rotate/180.0*M_PI)) );
847 int height = (int) ( abs(r.height()*t.scaley * cos(t.rotate/180*M_PI))
848 + abs(r.width()*t.scalex * sin(t.rotate/180*M_PI)) );*/
850 value_w->setValue(i->sceneBoundingRect().width());
851 value_h->setValue(i->sceneBoundingRect().height());
852 } else if (i->type() == RECTITEM) {
853 QGraphicsRectItem *r = static_cast <QGraphicsRectItem *>(i);
854 value_w->setValue((int) r->rect().width());
855 value_h->setValue((int) r->rect().height());
856 } else if (i->type() == TEXTITEM) {
857 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(i);
858 value_w->setValue((int) t->boundingRect().width());
859 value_h->setValue((int) t->boundingRect().height());
862 value_w->blockSignals(false);
863 value_h->blockSignals(false);
866 /** \brief Updates the coordinates in the text fields from the item */
867 void TitleWidget::updateCoordinates(QGraphicsItem *i)
869 // Block signals emitted by this method
870 value_x->blockSignals(true);
871 value_y->blockSignals(true);
873 if (i->type() == TEXTITEM) {
875 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
877 // Set the correct x coordinate value
878 if (origin_x_left->isChecked()) {
879 // Origin (0 point) is at m_frameWidth, coordinate axis is inverted
880 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->boundingRect().width()));
882 // Origin is at 0 (default)
883 value_x->setValue((int) rec->pos().x());
887 if (origin_y_top->isChecked()) {
888 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->boundingRect().height()));
890 value_y->setValue((int) rec->pos().y());
893 } else if (i->type() == RECTITEM) {
895 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
897 if (origin_x_left->isChecked()) {
898 // Origin (0 point) is at m_frameWidth
899 value_x->setValue((int)(m_frameWidth - rec->pos().x() - rec->rect().width()));
901 // Origin is at 0 (default)
902 value_x->setValue((int) rec->pos().x());
905 if (origin_y_top->isChecked()) {
906 value_y->setValue((int)(m_frameHeight - rec->pos().y() - rec->rect().height()));
908 value_y->setValue((int) rec->pos().y());
911 } else if (i->type() == IMAGEITEM) {
913 if (origin_x_left->isChecked()) {
914 value_x->setValue((int)(m_frameWidth - i->pos().x() - i->sceneBoundingRect().width()));
916 value_x->setValue((int) i->pos().x());
919 if (origin_y_top->isChecked()) {
920 value_y->setValue((int)(m_frameHeight - i->pos().y() - i->sceneBoundingRect().height()));
922 value_y->setValue((int) i->pos().y());
927 // Stop blocking signals now
928 value_x->blockSignals(false);
929 value_y->blockSignals(false);
932 void TitleWidget::updateRotZoom(QGraphicsItem *i)
934 itemzoom->blockSignals(true);
935 itemrotate->blockSignals(false);
937 Transform t = m_transformations.value(i);
938 itemzoom->setValue((int)(t.scalex * 100.0 + 0.5));
939 itemrotate->setValue((int)(t.rotate));
941 itemzoom->blockSignals(false);
942 itemrotate->blockSignals(false);
945 /** \brief Updates the position of an item by reading coordinates from the text fields */
946 void TitleWidget::updatePosition(QGraphicsItem *i)
948 if (i->type() == TEXTITEM) {
949 QGraphicsTextItem *rec = static_cast <QGraphicsTextItem *>(i);
952 if (origin_x_left->isChecked()) {
953 /* Origin of the x axis is at m_frameWidth,
954 * and distance from right border of the item to the right
955 * border of the frame is taken.
956 * See comment to slotOriginXClicked().
958 posX = m_frameWidth - value_x->value() - rec->boundingRect().width();
960 posX = value_x->value();
964 if (origin_y_top->isChecked()) {
965 /* Same for y axis */
966 posY = m_frameHeight - value_y->value() - rec->boundingRect().height();
968 posY = value_y->value();
971 rec->setPos(posX, posY);
973 } else if (i->type() == RECTITEM) {
975 QGraphicsRectItem *rec = static_cast <QGraphicsRectItem *>(i);
978 if (origin_x_left->isChecked()) {
979 posX = m_frameWidth - value_x->value() - rec->rect().width();
981 posX = value_x->value();
985 if (origin_y_top->isChecked()) {
986 posY = m_frameHeight - value_y->value() - rec->rect().height();
988 posY = value_y->value();
991 rec->setPos(posX, posY);
993 } else if (i->type() == IMAGEITEM) {
995 if (origin_x_left->isChecked()) {
996 // Use the sceneBoundingRect because this also regards transformations like zoom
997 posX = m_frameWidth - value_x->value() - i->sceneBoundingRect().width();
999 posX = value_x->value();
1003 if (origin_y_top->isChecked()) {
1004 posY = m_frameHeight - value_y->value() - i->sceneBoundingRect().height();
1006 posY = value_y->value();
1009 i->setPos(posX, posY);
1015 void TitleWidget::updateTextOriginX()
1017 if (origin_x_left->isChecked()) {
1018 origin_x_left->setText(i18n("\u2212X"));
1020 origin_x_left->setText(i18n("+X"));
1024 void TitleWidget::slotOriginXClicked()
1026 // Update the text displayed on the button.
1027 updateTextOriginX();
1029 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1030 if (l.size() >= 1) {
1031 updateCoordinates(l.at(0));
1033 // Remember x axis setting
1034 l.at(0)->setData(TitleDocument::OriginXLeft, origin_x_left->isChecked() ?
1035 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1037 graphicsView->setFocus();
1040 void TitleWidget::updateTextOriginY()
1042 if (origin_y_top->isChecked()) {
1043 origin_y_top->setText(i18n("\u2212Y"));
1045 origin_y_top->setText(i18n("+Y"));
1049 void TitleWidget::slotOriginYClicked()
1051 // Update the text displayed on the button.
1052 updateTextOriginY();
1054 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1055 if (l.size() >= 1) {
1056 updateCoordinates(l.at(0));
1058 l.at(0)->setData(TitleDocument::OriginYTop, origin_y_top->isChecked() ?
1059 TitleDocument::AxisInverted : TitleDocument::AxisDefault);
1062 graphicsView->setFocus();
1065 void TitleWidget::updateAxisButtons(QGraphicsItem *i)
1067 int xAxis = i->data(TitleDocument::OriginXLeft).toInt();
1068 int yAxis = i->data(TitleDocument::OriginYTop).toInt();
1069 origin_x_left->blockSignals(true);
1070 origin_y_top->blockSignals(true);
1072 if (xAxis == TitleDocument::AxisInverted) {
1073 origin_x_left->setChecked(true);
1075 origin_x_left->setChecked(false);
1077 updateTextOriginX();
1079 if (yAxis == TitleDocument::AxisInverted) {
1080 origin_y_top->setChecked(true);
1082 origin_y_top->setChecked(false);
1084 updateTextOriginY();
1086 origin_x_left->blockSignals(false);
1087 origin_y_top->blockSignals(false);
1090 void TitleWidget::slotChangeBackground()
1092 QColor color = kcolorbutton->color();
1093 color.setAlpha(horizontalSlider->value());
1094 m_frameBorder->setBrush(QBrush(color));
1098 * Something (yeah) has changed in our QGraphicsScene.
1100 void TitleWidget::slotChanged()
1102 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1103 if (l.size() >= 1 && l.at(0)->type() == TEXTITEM) {
1104 textChanged(static_cast <QGraphicsTextItem *>(l.at(0)));
1109 * If the user has set origin_x_left (everything also for y),
1110 * we need to look whether a text element has been selected. If yes,
1111 * we need to ensure that the right border of the text field
1112 * remains fixed also when some text has been entered.
1114 * This is also known as right-justified, with the difference that
1115 * it is not valid for text but for its boundingRect. Text may still
1116 * be left-justified.
1118 void TitleWidget::textChanged(QGraphicsTextItem *i)
1123 if (origin_x_left->isChecked() || origin_y_top->isChecked()) {
1125 if (!i->toPlainText().isEmpty()) {
1129 * Don't do anything if the string is empty. If the position
1130 * would be updated here, a newly created text field would
1131 * be set to the position of the last selected text field.
1137 void TitleWidget::slotInsertUnicode()
1139 m_unicodeDialog->exec();
1142 void TitleWidget::slotInsertUnicodeString(QString text)
1144 QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
1146 if (l.at(0)->type() == TEXTITEM) {
1147 QGraphicsTextItem *t = static_cast <QGraphicsTextItem *>(l.at(0));
1148 t->textCursor().insertText(text);
1153 void TitleWidget::slotUpdateText()
1155 QFont font = font_family->currentFont();
1156 font.setPixelSize(font_size->value());
1157 font.setItalic(buttonItalic->isChecked());
1158 font.setUnderline(buttonUnder->isChecked());
1159 font.setWeight(font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1160 QColor color = fontColorButton->color();
1161 color.setAlpha(textAlpha->value());
1163 QGraphicsTextItem* item = NULL;
1164 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1165 if (l.size() == 1 && l.at(0)->type() == TEXTITEM) {
1166 item = static_cast <QGraphicsTextItem *>(l.at(0));
1169 //if (item->textCursor().selection ().isEmpty())
1170 QTextCursor cur = item->textCursor();
1171 QTextBlockFormat format = cur.blockFormat();
1172 if (buttonAlignLeft->isChecked() || buttonAlignCenter->isChecked() || buttonAlignRight->isChecked()) {
1173 item->setTextWidth(item->boundingRect().width());
1174 if (buttonAlignCenter->isChecked()) format.setAlignment(Qt::AlignHCenter);
1175 else if (buttonAlignRight->isChecked()) format.setAlignment(Qt::AlignRight);
1176 else if (buttonAlignLeft->isChecked()) format.setAlignment(Qt::AlignLeft);
1178 format.setAlignment(Qt::AlignLeft);
1179 item->setTextWidth(-1);
1183 item->setFont(font);
1184 item->setDefaultTextColor(color);
1185 cur.select(QTextCursor::Document);
1186 cur.setBlockFormat(format);
1187 item->setTextCursor(cur);
1188 cur.clearSelection();
1189 item->setTextCursor(cur);
1194 void TitleWidget::rectChanged()
1196 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1197 if (l.size() == 1 && l.at(0)->type() == RECTITEM && !settingUp) {
1198 QGraphicsRectItem *rec = static_cast<QGraphicsRectItem *>(l.at(0));
1199 QColor f = rectFColor->color();
1200 f.setAlpha(rectFAlpha->value());
1202 penf.setWidth(rectLineWidth->value());
1204 QColor b = rectBColor->color();
1205 b.setAlpha(rectBAlpha->value());
1206 rec->setBrush(QBrush(b));
1210 void TitleWidget::itemScaled(int val)
1212 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1213 if (l.size() == 1) {
1214 Transform x = m_transformations.value(l.at(0));
1215 x.scalex = (double)val / 100.0;
1216 x.scaley = (double)val / 100.0;
1218 qtrans.scale(x.scalex, x.scaley);
1219 qtrans.rotate(x.rotate);
1220 l[0]->setTransform(qtrans);
1221 m_transformations[l.at(0)] = x;
1222 updateDimension(l.at(0));
1226 void TitleWidget::itemRotate(int val)
1228 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1229 if (l.size() == 1) {
1230 Transform x = m_transformations[l.at(0)];
1231 x.rotate = (double)val;
1233 qtrans.scale(x.scalex, x.scaley);
1234 qtrans.rotate(x.rotate);
1235 l[0]->setTransform(qtrans);
1236 m_transformations[l.at(0)] = x;
1237 updateDimension(l.at(0));
1241 void TitleWidget::itemHCenter()
1243 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1244 if (l.size() == 1) {
1245 QGraphicsItem *item = l.at(0);
1247 br = item->sceneBoundingRect();
1248 int width = (int)br.width();
1249 int newPos = (int)((m_frameWidth - width) / 2);
1250 newPos += item->pos().x() - br.left(); // Check item transformation
1251 item->setPos(newPos, item->pos().y());
1252 updateCoordinates(item);
1256 void TitleWidget::itemVCenter()
1258 QList<QGraphicsItem*> l = graphicsView->scene()->selectedItems();
1259 if (l.size() == 1) {
1260 QGraphicsItem *item = l.at(0);
1262 br = item->sceneBoundingRect();
1263 int height = (int)br.height();
1264 int newPos = (int)((m_frameHeight - height) / 2);
1265 newPos += item->pos().y() - br.top(); // Check item transformation
1266 item->setPos(item->pos().x(), newPos);
1267 updateCoordinates(item);
1271 void TitleWidget::setupViewports()
1273 //double aspect_ratio = 4.0 / 3.0;//read from project
1274 //better zoom centered, but render uses only the created rect, so no problem to change the zoom function
1275 QRectF sp(0, 0, startViewportSize->value() * m_frameWidth / 100.0 , startViewportSize->value()* m_frameHeight / 100.0);
1276 QRectF ep(0, 0, endViewportSize->value() * m_frameWidth / 100.0, endViewportSize->value() * m_frameHeight / 100.0);
1277 // use a polygon thiat uses 16:9 and 4:3 rects forpreview the size in all aspect ratios ?
1278 QPolygonF spoly(sp);
1279 QPolygonF epoly(ep);
1280 spoly.translate(startViewportX->value(), startViewportY->value());
1281 epoly.translate(endViewportX->value(), endViewportY->value());
1282 m_startViewport->setPolygon(spoly);
1283 m_endViewport->setPolygon(epoly);
1284 if (! insertingValues) {
1285 m_startViewport->setData(0, startViewportX->value());
1286 m_startViewport->setData(1, startViewportY->value());
1287 m_startViewport->setData(2, startViewportSize->value());
1289 m_endViewport->setData(0, endViewportX->value());
1290 m_endViewport->setData(1, endViewportY->value());
1291 m_endViewport->setData(2, endViewportSize->value());
1295 void TitleWidget::loadTitle()
1297 KUrl url = KFileDialog::getOpenUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Load Title"));
1298 if (!url.isEmpty()) {
1299 QList<QGraphicsItem *> items = m_scene->items();
1300 for (int i = 0; i < items.size(); i++) {
1301 if (items.at(i)->zValue() > -1000) delete items.at(i);
1303 m_scene->clearTextSelection();
1304 m_count = m_titledocument.loadDocument(url, m_startViewport, m_endViewport) + 1;
1305 insertingValues = true;
1306 startViewportX->setValue(m_startViewport->data(0).toInt());
1307 startViewportY->setValue(m_startViewport->data(1).toInt());
1308 startViewportSize->setValue(m_startViewport->data(2).toInt());
1309 endViewportX->setValue(m_endViewport->data(0).toInt());
1310 endViewportY->setValue(m_endViewport->data(1).toInt());
1311 endViewportSize->setValue(m_endViewport->data(2).toInt());
1312 insertingValues = false;
1317 void TitleWidget::saveTitle(KUrl url)
1319 if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectTitlePath), "*.kdenlivetitle", this, i18n("Save Title"));
1320 if (!url.isEmpty()) {
1321 if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport) == false)
1322 KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
1326 QDomDocument TitleWidget::xml()
1328 QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
1329 if (cropImage->isChecked()) {
1330 doc.documentElement().setAttribute("crop", 1);
1335 void TitleWidget::setXml(QDomDocument doc)
1337 m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport);
1338 QDomElement e = doc.documentElement();
1339 cropImage->setChecked(e.hasAttribute("crop"));
1340 m_transformations.clear();
1341 QList <QGraphicsItem *> items = graphicsView->scene()->items();
1342 const double PI = 4.0 * atan(1.0);
1343 for (int i = 0; i < items.count(); i++) {
1344 QTransform t = items.at(i)->transform();
1348 x.rotate = 180. / PI * atan2(-t.m21(), t.m11());
1349 m_transformations[items.at(i)] = x;
1351 // mbd: Update the GUI color selectors to match the stuff from the loaded document
1352 QColor background_color = m_titledocument.getBackgroundColor();
1353 horizontalSlider->blockSignals(true);
1354 kcolorbutton->blockSignals(true);
1355 horizontalSlider->setValue(background_color.alpha());
1356 background_color.setAlpha(255);
1357 kcolorbutton->setColor(background_color);
1358 horizontalSlider->blockSignals(false);
1359 kcolorbutton->blockSignals(false);
1364 const QRect TitleWidget::renderedRect()
1368 int maxX = m_frameWidth;
1369 int maxY = m_frameHeight;
1370 if (!cropImage->isChecked()) {
1371 m_scene->removeItem(m_startViewport);
1372 m_scene->removeItem(m_endViewport);
1373 QRect boundingRect = m_scene->itemsBoundingRect().toRect();
1374 if (boundingRect.left() < 0) minX = boundingRect.left();
1375 if (boundingRect.top() < 0) minY = boundingRect.top();
1376 if (boundingRect.right() > maxX) maxX = boundingRect.right();
1377 if (boundingRect.bottom() > maxY) maxY = boundingRect.bottom();
1385 QRect rect(minX, minY, maxX, maxY);
1389 QImage TitleWidget::renderedPixmap()
1391 QRect rect = renderedRect();
1392 QImage pix(rect.width(), rect.height(), QImage::Format_ARGB32);
1393 pix.fill(Qt::transparent);
1394 QPainter painter(&pix);
1395 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing);
1396 m_scene->clearTextSelection();
1397 QPen framepen = m_frameBorder->pen();
1398 m_frameBorder->setPen(Qt::NoPen);
1399 m_startViewport->setVisible(false);
1400 m_endViewport->setVisible(false);
1401 m_frameImage->setVisible(false);
1403 m_scene->render(&painter, QRectF(), rect); //QRectF(minX, minY, maxX - minX, maxY - minY));
1405 m_frameBorder->setPen(framepen);
1406 m_startViewport->setVisible(true);
1407 m_endViewport->setVisible(true);
1408 m_frameImage->setVisible(true);
1412 /** \brief Connected to the accepted signal - calls writeChoices */
1413 void TitleWidget::slotAccepted()
1418 /** \brief Store the current choices of font, background and rect values */
1419 void TitleWidget::writeChoices()
1421 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1422 KSharedConfigPtr config = KGlobal::config();
1423 KConfigGroup titleConfig(config, "TitleWidget");
1424 // Write the entries
1425 titleConfig.writeEntry("font_family", font_family->currentFont());
1426 //titleConfig.writeEntry("font_size", font_size->value());
1427 titleConfig.writeEntry("font_pixel_size", font_size->value());
1428 titleConfig.writeEntry("font_color", fontColorButton->color());
1429 titleConfig.writeEntry("font_alpha", textAlpha->value());
1430 titleConfig.writeEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1431 titleConfig.writeEntry("font_italic", buttonItalic->isChecked());
1432 titleConfig.writeEntry("font_underlined", buttonUnder->isChecked());
1434 titleConfig.writeEntry("rect_foreground_color", rectFColor->color());
1435 titleConfig.writeEntry("rect_foreground_alpha", rectFAlpha->value());
1436 titleConfig.writeEntry("rect_background_color", rectBColor->color());
1437 titleConfig.writeEntry("rect_background_alpha", rectBAlpha->value());
1438 titleConfig.writeEntry("rect_line_width", rectLineWidth->value());
1440 titleConfig.writeEntry("background_color", kcolorbutton->color());
1441 titleConfig.writeEntry("background_alpha", horizontalSlider->value());
1443 titleConfig.writeEntry("crop_image", cropImage->isChecked());
1445 //! \todo Not sure if I should sync - it is probably safe to do it
1450 /** \brief Read the last stored choices into the dialog */
1451 void TitleWidget::readChoices()
1453 // Get a pointer to a shared configuration instance, then get the TitleWidget group.
1454 KSharedConfigPtr config = KGlobal::config();
1455 KConfigGroup titleConfig(config, "TitleWidget");
1457 font_family->setCurrentFont(titleConfig.readEntry("font_family", font_family->currentFont()));
1458 font_size->setValue(titleConfig.readEntry("font_pixel_size", font_size->value()));
1459 fontColorButton->setColor(titleConfig.readEntry("font_color", fontColorButton->color()));
1460 textAlpha->setValue(titleConfig.readEntry("font_alpha", textAlpha->value()));
1462 if (titleConfig.readEntry("font_bold", false)) weight = QFont::Bold;
1463 else weight = titleConfig.readEntry("font_weight", font_weight_box->itemData(font_weight_box->currentIndex()).toInt());
1464 setFontBoxWeight(weight);
1465 buttonItalic->setChecked(titleConfig.readEntry("font_italic", buttonItalic->isChecked()));
1466 buttonUnder->setChecked(titleConfig.readEntry("font_underlined", buttonUnder->isChecked()));
1468 rectFColor->setColor(titleConfig.readEntry("rect_foreground_color", rectFColor->color()));
1469 rectFAlpha->setValue(titleConfig.readEntry("rect_foreground_alpha", rectFAlpha->value()));
1470 rectBColor->setColor(titleConfig.readEntry("rect_background_color", rectBColor->color()));
1471 rectBAlpha->setValue(titleConfig.readEntry("rect_background_alpha", rectBAlpha->value()));
1472 rectLineWidth->setValue(titleConfig.readEntry("rect_line_width", rectLineWidth->value()));
1474 kcolorbutton->setColor(titleConfig.readEntry("background_color", kcolorbutton->color()));
1475 horizontalSlider->setValue(titleConfig.readEntry("background_alpha", horizontalSlider->value()));
1477 cropImage->setChecked(titleConfig.readEntry("crop_image", cropImage->isChecked()));