]> git.sesse.net Git - kdenlive/blobdiff - src/titlewidget.cpp
Drop support for KDE 4.3.
[kdenlive] / src / titlewidget.cpp
index 4822cba2082de468296277dc752bc78a61bdedb5..5a00bd44077f27038df4f335e848c44fc9fc666a 100644 (file)
@@ -145,6 +145,8 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     m_frameHeight = render->renderHeight();
     showToolbars(TITLE_SELECT);
 
+    splitter->setStretchFactor(0, 20);
+
     //If project is drop frame, set the input mask as such.
     title_duration->setInputMask("");
     title_duration->setValidator(m_tc.validator());
@@ -418,6 +420,16 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     gradient->setSpread(QGradient::ReflectSpread);
     scene->setBackgroundBrush(*gradient);*/
 
+    QPen framepen(Qt::DotLine);
+    framepen.setColor(Qt::red);
+
+    m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
+    m_frameBorder->setPen(framepen);
+    m_frameBorder->setZValue(-1100);
+    m_frameBorder->setBrush(Qt::transparent);
+    m_frameBorder->setFlags(0);
+    graphicsView->scene()->addItem(m_frameBorder);
+    
     m_frameImage = new QGraphicsPixmapItem();
     QTransform qtrans;
     qtrans.scale(2.0, 2.0);
@@ -436,15 +448,6 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     connect(m_scene, SIGNAL(newText(QGraphicsTextItem *)), this , SLOT(slotNewText(QGraphicsTextItem *)));
     connect(zoom_slider, SIGNAL(valueChanged(int)), this , SLOT(slotUpdateZoom(int)));
 
-    QPen framepen(Qt::DotLine);
-    framepen.setColor(Qt::red);
-
-    m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_frameWidth, m_frameHeight));
-    m_frameBorder->setPen(framepen);
-    m_frameBorder->setZValue(-1100);
-    m_frameBorder->setBrush(Qt::transparent);
-    m_frameBorder->setFlags(0);
-    graphicsView->scene()->addItem(m_frameBorder);
 
     // mbd: load saved settings
     readChoices();
@@ -462,6 +465,8 @@ TitleWidget::TitleWidget(KUrl url, Timecode tc, QString projectTitlePath, Render
     m_endViewport->setData(0, m_frameWidth);
     m_endViewport->setData(1, m_frameHeight);
 
+    // scale the view so that the title widget is not too big at startup
+    graphicsView->scale(.5, .5);
     if (!url.isEmpty()) loadTitle(url);
     else {
         slotTextTool();
@@ -763,24 +768,24 @@ void TitleWidget::checkButton(TITLETOOL toolType)
 
 void TitleWidget::displayBackgroundFrame()
 {
+    QRectF r = m_frameBorder->sceneBoundingRect();
     if (!displayBg->isChecked()) {
-        QPixmap bg(m_frameWidth / 2, m_frameHeight / 2);
         QPixmap pattern(20, 20);
         pattern.fill();
         QColor bgcolor(210, 210, 210);
-        QPainter p;
-        p.begin(&pattern);
+        QPainter p(&pattern);
         p.fillRect(QRect(0, 0, 10, 10), bgcolor);
         p.fillRect(QRect(10, 10, 20, 20), bgcolor);
         p.end();
         QBrush br(pattern);
-
-        p.begin(&bg);
-        p.fillRect(bg.rect(), br);
-        p.end();
+        QPixmap bg((int) (r.width() / 2), (int) (r.height()/ 2));
+        QPainter p2(&bg);
+        p2.fillRect(bg.rect(), br);
+        p2.end();
         m_frameImage->setPixmap(bg);
     } else {
-        m_frameImage->setPixmap(QPixmap::fromImage(m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), m_frameWidth / 2, m_frameHeight / 2)));
+        QImage img = m_render->extractFrame((int) m_render->seekPosition().frames(m_render->fps()), QString(), m_render->frameRenderWidth() / 2, m_render->renderHeight() / 2);
+        m_frameImage->setPixmap(QPixmap::fromImage(img.scaled(r.width() / 2, r.height() / 2)));
     }
 }
 
@@ -1545,6 +1550,7 @@ void TitleWidget::slotUpdateText()
 //  item->setTextCursor(cur);
         cur.clearSelection();
         item->setTextCursor(cur);
+        item->setDefaultTextColor(color);
     }
 }
 
@@ -1785,20 +1791,23 @@ void TitleWidget::saveTitle(KUrl url)
 {
     if (anim_start->isChecked()) slotAnimStart(false);
     if (anim_end->isChecked()) slotAnimEnd(false);
+    bool embed_image=false;
+    if (KMessageBox::questionYesNo(this, i18n("Do you want to embed Images into this TitleDocument?\nThis is most needed for sharing Titles.")) != KMessageBox::No)
+    {
+        embed_image=true;      
+    }
     if (url.isEmpty()) {
         KFileDialog *fs = new KFileDialog(KUrl(m_projectTitlePath), "application/x-kdenlivetitle", this);
         fs->setOperationMode(KFileDialog::Saving);
         fs->setMode(KFile::File);
-#if KDE_IS_VERSION(4,2,0)
         fs->setConfirmOverwrite(true);
-#endif
         fs->setKeepLocation(true);
         fs->exec();
         url = fs->selectedUrl();
         delete fs;
     }
     if (!url.isEmpty()) {
-        if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()) - 1) == false)
+        if (m_titledocument.saveDocument(url, m_startViewport, m_endViewport, m_tc.getFrameCount(title_duration->text()), embed_image) == false)
             KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
     }
 }
@@ -1806,21 +1815,21 @@ void TitleWidget::saveTitle(KUrl url)
 QDomDocument TitleWidget::xml()
 {
     QDomDocument doc = m_titledocument.xml(m_startViewport, m_endViewport);
-    doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()) - 1);
+    doc.documentElement().setAttribute("out", m_tc.getFrameCount(title_duration->text()));
     return doc;
 }
 
 int TitleWidget::outPoint() const
 {
-    return m_tc.getFrameCount(title_duration->text()) - 1;
+    return m_tc.getFrameCount(title_duration->text());
 }
 
 void TitleWidget::setXml(QDomDocument doc)
 {
     int out;
-    m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out);
+    m_count = m_titledocument.loadFromXml(doc, m_startViewport, m_endViewport, &out, m_projectTitlePath);
     adjustFrameSize();
-    title_duration->setText(m_tc.getTimecode(GenTime(out + 1, m_render->fps())));
+    title_duration->setText(m_tc.getTimecode(GenTime(out, m_render->fps())));
     /*if (doc.documentElement().hasAttribute("out")) {
     GenTime duration = GenTime(doc.documentElement().attribute("out").toDouble() / 1000.0);
     title_duration->setText(m_tc.getTimecode(duration));
@@ -2390,7 +2399,7 @@ void TitleWidget::slotSelectNone()
     selectionChanged();
 }
 
-QString TitleWidget::getTooltipWithShortcut(const QString text, QAction *button)
+QString TitleWidget::getTooltipWithShortcut(const QString &text, QAction *button)
 {
     return text + "  <b>" + button->shortcut().toString() + "</b>";
 }